1
\$\begingroup\$

I have 1000*1000 (1,000,000 tiles) fixed size map composed of 3 layers (3,000,000 tiles) every tile has 4 values X,Y,Z and ID (12,000,000 values). When a client connects and requests map data, server has to send 10x10(100 tiles) tiles in a packet and every time the player moves server sends map buffer which is a row of tiles data (X,Y,Z and ID) in a packet too. All these values needed to be loaded on server startup and that's without mentions other variables. Am i on the right path? Is there is any better method?

Additional info: I'm using C# server, map is made by Tiled exported to XML file with CSV format. Client is supposed to be on GameMaker Studio (not yet made)

\$\endgroup\$
  • 2
    \$\begingroup\$ I would really recommend you to start your client development early. It is impossible to develop a working server application when you have no client application to test it properly. We tried that once. We thought we had a great-working server and when we started to develop the client we started to realize what a buggy, inperformant, ill-designed mess it was. \$\endgroup\$ – Philipp Feb 18 '18 at 10:22
  • 1
    \$\begingroup\$ Yeah i think you're right, it's better to do parallel development for the client and the server. I was so stressed about the server and i left the client, yeah i'll do parallel dev. thanks! \$\endgroup\$ – Med. A. Feb 18 '18 at 10:43
2
\$\begingroup\$

It is usually not required for each tile to know its own x, y and z coordinates. These are usually inferred from their position in the data-structure which stores the tiles. But there are a few situations where it actually can be useful, so I am giving you the benefit of a doubt.

When your map is static (does not change during the game, or at least doesn't change much), then you might want to consider to add a complete copy of your map as an asset to your game client. That way the server doesn't need to send any map data to the clients (except maybe through the pre-game auto updater).

If your game has a dynamic map (it is altered during gameplay), then you might want to send it to the player in form of chunks (rectangular cells of map data). When you send the client a chunk, you don't need to send the x, y and z coordinate of every single tile. You just need to tell the coordinates where the chunk starts, its width and height (number of layers will likely be constant) and then a long list of id's. You might be able to save some more bandwidth by running the id collection through a stock compression algorithm like Deflate or LZW. Check which algorithm gives the best results for your particular mapping style.

Also make sure you don't send any map data the client already knows. When the client walks back and forth between two points, and the terrain doesn't change, you don't need to tell it how it looks over and over again. You could solve this by either having the server remember which client already got which version of which chunk. Or you could turn it around and use a request-model where the client asks the server when it wants a chunk by telling the server the chunk-coordinates and the latest version it got. The server then either replies with a new version of that chunk or with a "chunk didn't change" message.

\$\endgroup\$
  • \$\begingroup\$ I like the chunks idea, i'm going to start thinking about it. still the main problem i fear is loading the map in the server with all these data.. \$\endgroup\$ – Med. A. Feb 18 '18 at 10:26
  • \$\begingroup\$ @MohamedAmmar 12 million values with 4 bytes each (assuming 32 bit integers, although you could get away with 16 bit in this case) is 48 MB of data. That's nothing. Current servers can fit that in their CPU cache. \$\endgroup\$ – Philipp Feb 18 '18 at 10:31
  • \$\begingroup\$ I thought i would face memory problems.Anyway after reading your response again i think it's possible to stick the map with client and the server just send/check collision layer. Just i need to encrypt map data in the client so it can't be cracked because the gameplay based on the map unseen parts (like puzzle etc..). your answer is really helpful, Thanks. \$\endgroup\$ – Med. A. Feb 18 '18 at 10:40
  • 3
    \$\begingroup\$ @MohamedAmmar You are likely wasting your time with encrypting assets client-sided. You can't do that without putting the decryption key in the client where the hackers can find it. Also, all the puzzles in your game will have their solutions posted on the unofficial fan wiki the moment someone solves them for the first time. You can't keep secrets in an MMO. \$\endgroup\$ – Philipp Feb 18 '18 at 10:42

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.