Sign in to follow this  

Sending the map

This topic is 3662 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

Hello, first at all, I search on the web some info about sending the map to the client, but I dont found nothing interesant. I need to give to the client my map, now there is the problem. I need to send big maps, about... more than 10000 tiles without objects. I have 5 ways (that I know) 1.- Save the map in the client (not in the server) and load all the map at start. With this method the map can load faster, but its not secure, and require a good ram (isnt it?) 2.- Save the map in the client (not in the server), and load the map while character is walking. With this, its fast and require less ram than method 1, but this is more difficult to code, and is not secure. 3.- Save the map in the server (and not in the client), and send tiles id when I connect to the server. This is more secure, its less fast then method 1 and 2, and requires more ram too. This requires too a big buffer. 4.- Save the map in the server (and not in the client), and send 1 packet for 1 y eye. With this I can send all my map, this is secure, less fast, require ram, and just a few packets when the client connects. 5.- Save the map in the server (and not in the client), send just a few tiles when I connect to the server, and while the player walks, send more tiles. This is more secure, more fast, requires less ram but this is the most difficult and takes a lot of connections to the server (1 packet for 1 tile... doing maths... A LOT) Are this method true? I forgot something? What you think its the best method? Can you say me more methods to load my map in the client? See you

Share this post


Link to post
Share on other sites
Quote:
Original post by CarloSpain
If I save the map in the client the user can change the map, isnt he?

Sure, but that just means the client no longer knows what the real map is. The security issue would only arise if the server allowed the client to make moves which were incompatible with the map, like moving onto a tile where the server thinks there's a wall. The key to multiplayer security is this: don't trust the client. Let the client tell the server anything it wants, but make the server check that all actions are actually valid, and not allow actions which are not.

Share this post


Link to post
Share on other sites
Thanks you, you are helping me a lot.
Then you think save the map in the client its the best method?
What you think is better? Load all the map at the start, or load while walking?

Really thanks to you,
See you

Share this post


Link to post
Share on other sites
How is the map generated? Is it hand made or randomly generated. If it is random, you could just send the seed value for the random number generator and let the map build on the client. Anyway, what does 10000 tiles equate to in MB. I can't imagine it is more than a few megabytes. Just do what many games do, when the client connects, check to see if the client has the map, and if not have the server send it. You can make sure the client version matches the server version using a checksum.

Share this post


Link to post
Share on other sites
Just to clarify on what Sneftel said: both the server and the client should load the map themselves. The server loads the map because it needs to check if the clients actions are actually valid, and the client loads the map because it needs to display it, and check what actions it can take.

As for using a lot of memory, tile data is often pretty compact. In many cases, the data contains only image indices or references. You're only going to load every unique tile image once and reuse them for every tile that uses that image, after all. If every tile is a simple integer, then your total map data would likely be 40 KB. That's really just very little memory. Let's then say that each tile is 32x32, 32bits image... that's 4 KB per image. If your map uses 200 unique tile images, then that's 800 Kb. All in all, less then a single MB.

In other words, are you sure that your maps will use a lot of memory, or are you simply assuming that they will, because 10.000 just sounds like an awfull lot?

Share this post


Link to post
Share on other sites
I make my map by hand.
And I assuming, that this will take a lot of memory, maybe because its not just the tiles, the objects too and important points... all this information, what do you think is better? Load all at start, or load while walking?

Thanks,
See you

Share this post


Link to post
Share on other sites
Personally i think it would be better to have the map load as the player walked around. Games get really annoying when they have to load the entire map and besides, unless im very mistaken, it will take a lot of memory to store the map. The method i'm using is that the map tiles are stored on the client but the server has to send the location of the tiles and objects and the client just draws them. The tiles can be hacked it's true but the only way to prevent that that would be to send the tiles and the models over the server connection. I check the tiles by checking a number that is based on the values of several points of the tile so it cant be modified drastically without the server knowing about it. If someone beats my system good for them. If someone wants to ruin the game for themselves I dont care.

so to answer the question without a whole thing, go with the loading as the player moved, it will cut down on the overall loading as the player wont go everywhere so places he avoids wont be loaded.

Share this post


Link to post
Share on other sites
I think this too, but at the moment, I draw all the map in a auxiliar surface, and then I blit from that surface, to the primary surface, and then flip.
What is the difference between load all at start, and load while walking.
Thinking...
Load all at start: Takes a lot of memory cause I read ALL the map, not mind if I visit a part of it or not.
Load while walking: Its difficult, while a player is moving, the client is saving tiles in memory, while more steps, more memory, because I dont know how can I delete a tile saved in my auxiliar surface. If I blit a black rectangule in tiles that I dont use, this will delete some kbs of the ram?

I choose to save the map in the client too, but how can I encrypt my maps, making my own map format, to difficult the map edition?

And what about send the map from server to client while walking. This will slow the server a lot?

Thanks you,
Carlos

Share this post


Link to post
Share on other sites
It will only slow it down if it has to send a lot of information and you don't have the hardware and bandwidth to support it, and/or it is done poorly. If you have 1000 users running around at 100 tiles/second, then you're screwed. But if it is very slow-paced and the tiles consist of just a few bytes of information, you should be fine. This approach won't exactly be easy, though, since you will have to keep track of what tiles they know about (if you step right, then step left, you won't want to resend them if they don't change) and be able to not have the game crash / freeze up if they move too fast while the packets lag behind and they see tiles that.

Why don't you just keep visual (lighting, graphics, etc) / attribute (blocked, portal, etc) information on the client, and attribute / character (where NPCs are, where they spawn, etc)? When the user loads a map, you just tell them about nearby NPCs and PCs instead of the whole map. The absolute worst someone can do is either see what maps look like before going to them or modify the maps and remove graphics / modify lights to be able to have an advantage over others.

I didn't quite understand your question about encrypting the maps, but theres plenty of encryption algorithms out there. If you use your own map format and just run it through an encryption, its unlikely someone will try and bother breaking it unless its quite popular.

From what it sounds like from your concern about RAM usage is that you just have a big map for a surface and are drawing the whole map then only displaying a portion of it. If this is the case, read more about making maps, since you will never want to take this approach. RAM shouldn't be a problem, and should only be a concern in the server where you have to have a lot more loaded in often a much more costly environment. Even if each tile was using a KB per tile (which is a LOT), thats only 9 MBytes for a 100x100 map. If you have very large maps, you will want to be doing some form of dynamic loading or have each map about the size of the screen and seamlessly scroll between them and load only the map you're on and the 8 surrounding it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Spodi
From what it sounds like from your concern about RAM usage is that you just have a big map for a surface and are drawing the whole map then only displaying a portion of it.


Yes, I was doing that, but thanks for the help, I change my code to dont do that action.
So I just draw some tiles in a auxiliar surface and then blit from this surface to the primary surface?
Maybe because Im using SDL, I cant blit directly to primary surface...

Thanks you,
Carlos

Share this post


Link to post
Share on other sites
Well the most basic form of rendering a map is you have a collection of textures (or surfaces) which you draw onto the backbuffer which is typically the same size of the screen. When you finish drawing, you "flip" the backbuffer to the display. There are approaches you can use to draw the scene faster, but that shouldn't be much of a concern these days with a typical 2d game, and nothing you should worry about until you have the basics down.

Share this post


Link to post
Share on other sites

This topic is 3662 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this