Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Best way to send a array

This topic is 5663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an array for my map that tells me what type of terrain is in each square and if there are any buildings in that square. The map can be any size so my client does not know at the beginning how large it will be. What would be the best way to send this information to the client.

Share this post

Link to post
Share on other sites
You could as well "compress" your data if there are redondance in the array.

Let''s say the next 53 tiles are grass only. You could send a packet which would look like "G50" rather than "GGGGGGGGGGGG...".

You could as well use dynamic arrays (vectors, or lists, or...), so you just have to push the newest received elements on the level container with an automatic resize.

Share this post

Link to post
Share on other sites
first byte is the X size, second is the Y size. Unless you maps can be bigger than 256x256 in which case use a short or int instead.

Next you compress your map. Zero based compression is cake to do and works rather well.

All you do is if the number is nonzero you set the value to the value of the tile. If the number is 0 you set the first value to 255 (or whatever number a valid tile will never be equal to) and then count 0s and put the number of 0s after it.

When the client recieves the message it creates and ZeroMemory''s the array based on the first 2 bytes and then starts filling in data. When it hits the 0 indicator value it doesn''t write anything for however many 0s are indicated by the next byte.

You could also do full RLE and use the first byte to indicate the tile number and the second to say how many in a row.

The reason I didn''t do RLE is because there tend to be lots of 0s in a row but for my maps it was very rare (statistically) to find two of the same tile numbers in a row. It actually compressed better just counting 0s because I had a lot of wasted counter bytes with the value 1.



KalvinB - (to Jessika) do you accept Jesus as your lord and savior

Jessika - Sure I can accept all forms of payment.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!