I am creating a 'Minecraft clone' and the game is going to be only multiplayer. I currently have a limited world (it's not going to be infinite) that is 512 chunks.
Each chunk is 16(X) * 16(Z) * 128(Y) of blocks.
Each block is represented by a byte. This means I have a 3D array of bytes that represents which block is in which position in the chunk (0 means Air). I got to the part where I want to send the world though the TCP connection.
I am using KryoNet for my multiplayer needs. Currently what I do is I flatten the 3D array to the highest Y coordinate that is not air, making my (16 * 16 * 128) array into a (16 * 16 * less than 128) array. After doing this I take the 3D array and flatten it into a 1D array. After doing that I have a 1D array of size ~32,000. Obviously sending the entire 32KB of data through the connection at once is stupid and it also crashes KryoNet.
My question is how would I efficiently go about sending 512 chunks (512*32 KB of data) through the connection?
I thought about separating the 1D array (32,000 bytes) into 32 packets each of 1KB of data but it seems odd to send 512 * 32 packets to send the world (~16,000 packets). Is there any way to compress this data or send it in a more efficient way through my TCP connection? Obviously this is done once per session but still 16,000 seems a lot.
I have separated the chunks into 33 packets each, and I send them one after the other. It seems to be working well, but I have a slight ordering issue that is unrelated. At the times that it works it loads quite quickly and with no problem! If there is a more efficient way of going about this please do post it here!