0
\$\begingroup\$

I'm designing a game where the map has 1 M tiles. The game is simple, is a 2D game with low graphic requirements and without player movements, only change states, so I don't need to update player positions for example. But I have a doubt about how to synchronize the map.

When a client connects, the server should send him data related with proximity tiles. Each tile is represented with a different picture, so I can represent them with an id (integer). Developing in c#, each tile requires 4 bytes to store the id. So when the client connects, I have to send him (4 bytes*number of tiles). Sending data of 1000 tiles (a 30x30 grid), I'm sending 4 kb, and this is just in the first connection. When the client player moves, I have to send him more and more data, which has not a good performance.

On the other hand, if I store all the ids in the client, I will need to store 1M*4 byte = 4 mb per client. This is just to store tile ids, but it seems to be ok.

How can I design or optimize the data messaging ?

\$\endgroup\$
  • 1
    \$\begingroup\$ Please edit your question: first off, where does 1M come from? Next: 1M times 4 bytes it NOT 4 gigabyte, it is 4 megabyte, well within memory capability of clients. \$\endgroup\$ – Bram Dec 29 '18 at 21:08
  • \$\begingroup\$ @Bram thanks for your suggestions, I have edited as you told me. \$\endgroup\$ – Federico Caccia Dec 29 '18 at 22:29
  • 2
    \$\begingroup\$ 4MB of map storage on the client is pretty tiny by today's standards. In many games, just the images representing the various tile types would add up to more than that. Is there any reason you don't want to proceed with that strategy? \$\endgroup\$ – DMGregory Dec 30 '18 at 0:24
  • 2
    \$\begingroup\$ The best way to solve this problem is to not have the problem at all: ie. your client already has the map data. This is the way most installed games like this work (web games by nature tend to need to download everything) \$\endgroup\$ – DMGregory Dec 30 '18 at 14:57
  • 1
    \$\begingroup\$ Possible duplicate of Handling large 2D MMORPG map \$\endgroup\$ – Philipp Apr 1 '19 at 8:07
1
\$\begingroup\$

If you want to ensure that your players have the most up-to-date map possible, I'd start by including a version-header within each of your map files. This doesn't necessarily need to be a header per-say, it just needs to be some marker or value stored within the file that affects nothing about it in terms of game-play, but can store a value with the version number of the game that the map is supposed to be used for. This is implementable through a variety of means: If using your own map file format, just include the header as the top line and ignore it when reading; when checking if the map needs updating, instruct the client to send the map version to the server and check the version server-side. If the map is not of the correct version: send them the new map. An equivalent approach for a generic map editor would be to include a "dummy" layer or tile that stores the version number and instead get the version number from the incorporated object in the map instead of the header.

Upon receiving the packet from the server indicating that the version number was incorrect, proceed to download the map and display a loading screen to the user to indicate that the map is currently loading. Send the map file in chunks of a size you determine, re-construct the file and voila! The latest map file has been downloaded in a relatively pain-free manner.

A pseudo-code representation might go as follows (very basically):

version = version of game...
send version to server
correctVersion = server response

if version != correctVersion then
    show loading screen
    request map from server
    re-construct map file
    load map from file
    exit loading screen
    show map on screen (if necessary at this point)
else
    load map from file
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.