How can i send from server to client a large amount of tile data? Having chunks of almost 2MB of data seems prohibitive to send this information just like that. Minecraft compress each chunk and Terraria uses RLE, but im not sure if they send so much information.
There's a few strategies you can employ:
- Break the data into chunks. This allows you to only send what's needed by the client (as mentioned in Elviss's answer). This will also be useful to implement for many other aspects of the terrain.
- Use the organization of the data to your benefit. You don't need to have labels for all your data. The client should always be expecting the data in the same order, so it knows what the next bytes belong to. For example, the client should always expect two bytes for tile type, two bytes for lighting information and then two bytes for extra info. So it knows that after 6 bytes, it's time to move onto the next tile.
- Don't send position information, it should be implied in the tile order. Always send the tile information in chunks, one column at a time (or one row at a time). This allows your client to know the position of the next tile, without needing to read it from the byte stream. You send the starting position of the chunk, then the first tile is placed at the position. The client then knows the second tile will be placed at the chunk position plus one in the Y direction (if sending column per column).
You can divide your map into regions, generate them procedurally and send only the parameters of each of them to clients. For example, if there is a mountain somewhere on terrain that is being seen by player, you can send parameters of the mountain (like height, radius, angle of slopes etc.). This is a little bit tricky to manage (you will have to modify your terrain editor to allow creating terrain that can be generated procedurally), but will reduce the amount of data needed to generate the terrain on clients' machines.