Sign in to follow this  

[C++] Tile maps storage and usage

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

Hi, What would be the best way to store a tile based map? The maps can get quite big and only a small part is shown on-screen, depending where the user is. Each tile has values like the texture to be used, walkability, objects, special things etc etc. Should the map be stored on disc, or compiled with the program (so: an array or something like that is just in the sourcecode)? If the first option: should it be streamed or loaded into memory? If the second option: if I had a struct containing the data per tile, would I have to fill one for each tile? Just wondering how you guys solved this :) Thanks in advance, Decrius

Share this post


Link to post
Share on other sites
Store where? In between executions of your app you are going to want to store them in a separate file you don't want to recompile every time the map changes. During execution I would more than likely just load it all at once into ram.

For a begining file format I would start with a list of tiles(graphics plus any relevant info), then a big grid of numbers that reference the tiles listed above. It will be difficult to do large maps in it by hand but is easy enough to work with for small maps, or with a tool. In memory each tile should hold a reference to the resources it uses not copies of them.

Share this post


Link to post
Share on other sites
In a seperate file, possibly multiple files, depending how big you want the map to be, and how much of it is viewable at anyone time (by map editors as well players).

Remember to instance anything that multiple tiles use (like textures), in other words, don't make a copy for each tile, just 1 and then point to it per tile.

Share this post


Link to post
Share on other sites
you dont want to have something that will change often in your app...
I have found that a bit based format gave me the smallest size when I was working on a tile, basicly the map started off with a small header saying, this file contains x,y to x2,y2 and all tiles have base values of... after that the tiles where stored with 16bits for the tile ID after that followed a small flag which told it what to check for after the flag for those options, like a velocity flag which would change the speed of the player when on the tile. I belive this made the map take a minimal 32bits a tile.. might have been 24bit (was done a while ago) only 'hard' thing of it was getting used to bit manipulation..

Share this post


Link to post
Share on other sites
Quote:
Original post by Decrius
Hi,

What would be the best way to store a tile based map?

The maps can get quite big and only a small part is shown on-screen, depending where the user is. Each tile has values like the texture to be used, walkability, objects, special things etc etc.

Should the map be stored on disc, or compiled with the program (so: an array or something like that is just in the sourcecode)? If the first option: should it be streamed or loaded into memory? If the second option: if I had a struct containing the data per tile, would I have to fill one for each tile?

Just wondering how you guys solved this :)

Thanks in advance,
Decrius


Check these articles out:
Tile Graphics Techniques 1.0
Tile Based Games FAQ
The Continuous World of Dungeon Siege

You'll note the time difference between the original writing of the articles, and the remarkable resemblence the later ones have to the earlier ones. :)

Share this post


Link to post
Share on other sites

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