Jump to content
  • Advertisement
Sign in to follow this  
MarlboroKing

Using tilesets quickly and effeciently for maps

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

Alright, so I want to jump into the big leage. I am attempting to create a 2D Role Playing Game, using existing external data (sounds/graphics/etc. from previous game titles). However I am kinda stumped on a suffecient way of loading tiles based from a tilesheet.

My first implementation was INCREDIBLY slow on parsing, which of course, was XML. The file reached 7984 tiles based on 32x32-each-tile (from 1 tilesheet, fyi, so this is a no go). My previous idea was just to cut out the area of the 32x32 tile I need and then store the raw binary data into the file while the map was being made. I received quite some negative feedback about this, so I am trying to find a new way. But this is my exact problem, I can't think of a new way. I mean, I COULD just store the "owner name" (file name) and x/y pos of the tile, but that is resource heavy and is a deffenent no go.

So, I guess what I am asking is, what would be a good solution for this?
(I've been up for about 49 hours, I'm sorry if there's any spelling mistakes :])

Edit; thought I was in the Game Programming section, sorry! If this could be moved to their, I'd greately appreciate it. Edited by MarlboroKing

Share this post


Link to post
Share on other sites
Advertisement
My first implementation was INCREDIBLY slow on parsing, which of course, was XML. The file reached 7984 tiles based on 32x32-each-tile (from 1 tilesheet, fyi, so this is a no go). My previous idea was just to cut out the area of the 32x32 tile I need and then store the raw binary data into the file while the map was being made. I received quite some negative feedback about this, so I am trying to find a new way.
I agree with them - assuming I correctly understand - storing binary blobs in XML is a bad idea. However, I am a strong supporter of pure binary formats. No matter how fast a parser is, it will never be as fast as no parsing at all. A binary 7K tiles file will possibly require as little as 7-14-28 KiB, with straightforward mapping to runtime representation.


So, I guess what I am asking is, what would be a good solution for this?
(I've been up for about 49 hours, I'm sorry if there's any spelling mistakes :])
This is very bad dude. Don't mess up with your sleep. There have been a few threads about that in the lounge and nobody is ever happy with it. No doubt you cannot figure it!

Here's a stupid and effective high-level way to turn most resources in binary files.

  1. Collect a list of unique tiles (say, by file name).
  2. Dump the list obtained in (1) to the header.
  3. Walk the map representation. For each tile, associate to the unique resource and then to its file name. This will result in a resource->id mapping as dumped in the file.
  4. You now have a list of integers which is a set of indices to the header list of tiles. Dump this as "level data".
  5. You're done!

Share this post


Link to post
Share on other sites
haha, it's a big club i guess this 2d work. i'm just getting into it myself and i'm also using 32x32 tiles. the problem for me is i'm also moving up into c# because i don't want to be laughed at by my friends. happy.png here is something i was considering and less solution and more problems to be worked out, .. hopefully together, hehe

-tiles have graphics
-tiles have travel properties (walk, no walk, slow walk?, little water=swim, medium water (canoe ftw!), deep water(ship?!), fly (maybe)!, no fly! (buhahah),
-tiles can have random encounters OR spawn that either move or stay static.
-tiles can hold interactive items either hidden or after a kill (perhaps).
-tiles have neighbors / regions (a 100x100 map would have a neighbor on 4 sides likely)
-tiles are inside or outside, perhaps night or day.. (but outside you won't see inside tiles and vs versa?)
-a object tile on a tile, perhaps a tree on a grass tile.
-special titles that exit/enter
-lastly where is the PC.

so now, it seems like each title has about 5-10 pieces of vital information, give or take REGION information.

the question in my mind is, is it required or even beneficial to try to group all data into a single class per tile and write an multidimensional array of class
or use various data types to create the map. i keep pausing this post to research on google, i'm going to go back to that and hope someone takes interest in this thread.

Share this post


Link to post
Share on other sites

I agree with them - assuming I correctly understand - storing binary blobs in XML is a bad idea. However, I am a strong supporter of pure binary formats. No matter how fast a parser is, it will never be as fast as no parsing at all. A binary 7K tiles file will possibly require as little as 7-14-28 KiB, with straightforward mapping to runtime representation.


No, I meant storing the raw binary image in a custom file format. Essentially, I am looking for a route to quickly locate and use said tile. Looking through (let's say, a vector) with 7k+ tiles just seems like a horrible idea, and well, it is a horrible idea. :P


This is very bad dude. Don't mess up with your sleep. There have been a few threads about that in the lounge and nobody is ever happy with it. No doubt you cannot figure it!

Here's a stupid and effective high-level way to turn most resources in binary files.

  1. Collect a list of unique tiles (say, by file name).
  2. Dump the list obtained in (1) to the header.
  3. Walk the map representation. For each tile, associate to the unique resource and then to its file name. This will result in a resource->id mapping as dumped in the file.
  4. You now have a list of integers which is a set of indices to the header list of tiles. Dump this as "level data".
  5. You're done!



My sleepless-ness has nothing to do with this project, or even programming at all; it's personal matters.
I am a bit confused on what you mean by #3: "associate to the unique resource and then to its file name."


haha, it's a big club i guess this 2d work. i'm just getting into it myself and i'm also using 32x32 tiles. the problem for me is i'm also moving up into c# because i don't want to be laughed at by my friends. happy.png here is something i was considering and less solution and more problems to be worked out, .. hopefully together, hehe

[Snip]
[/Snip]

so now, it seems like each title has about 5-10 pieces of vital information, give or take REGION information.

the question in my mind is, is it required or even beneficial to try to group all data into a single class per tile and write an multidimensional array of class
or use various data types to create the map. i keep pausing this post to research on google, i'm going to go back to that and hope someone takes interest in this thread.


Dragonalumni, I have the majority of the map file format figured out, that isn't the issue. My issue is that I can't think of a reasonable way to store and/or locate tiles to be used when parsing the map file.

Arrays would probably be better (less memory usage, but not by much depending on how you code it since vectors tend to increase its size by a determined amount to prevent constant resizing) but imo, that just seems even less effecient. I'm not so sure about List<>'s in C# as I've rarely touched the language.

--

It'd appear the most obvious and sensable choice is to rip and store the 32x32 from the tileset into my map file, associate a unique ID with it (to prevent the same tile from being riped and stored, as well as to grab the tile quickly). If this is the same as Krohm's suggestion (kinda seems like it's on the same route, I'll take a peek at his answer tomorrow), then well..... :P

Share this post


Link to post
Share on other sites
Here's how I do it in my game:
The map file is binary. Very fast to load, as much as possible is pre-calculated.

My tile files are actually each an individual file (unless it belongs to a set, like a piece of furniture composed of 4 tiles would be a single image).

(I really haven't yet found that storing my tiles in individual files is a huge bottleneck... definitely not as big a bottleneck as was parsing the map file itself. However, if it becomes a bottleneck in the future, I can easily change it)

My game world is divided into ‘areas’, and an area is broken up into chunks that are 20 by 20 tiles (and as many layers of tiles as desired). An area can have as many chunks as it likes. The player is always at the center of a 3 by 3 grid of chunks. Any chunk outside of the 3-by-3 grid is unloaded from memory. The chunks share tile images (this is important!).



[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]When a chunk is loaded, it says, "I want the tile [/font][color=#008080][font=helvetica, arial, verdana, tahoma, sans-serif]'blah/blah/blah/myTile.png'[/font]".


It says that to the tile manager class. The tile manager has a list of all the images currently loaded, and if the tile image is already loaded, it passes a pointer to the already-loaded image back to the chunk. If the image is not already loaded, the tile manager loads it, and passes the pointer back to the chunk. It is the tile manager's responsability to 'own' that image (own = Responsible to load when needed, and the responsible to free it when no longer needed).



Instead of having to load (and hold in RAM) [color=#a52a2a]20 * 20 * numberOfLayers * numberOfChunks images, we only load and store in RAM each unique image. This means instead of tens of thousands of images we have to load, we just load maybe two hundred or so at any given time. This is probably where your stuff slows down.

My map files basically look the same (logically) as your map files. "For each tile, use the image 'blah'."
The difference is, I share the images if they are identical, by having a seperate class to handle ownership of the images. It owns them. Chunks don't care. They say, "Give me the image [color=#008080]blah.png". The image manager gives them a pointer to the shared image, and loads it if it's not already loaded.

My world basically looks the same as your world. The only difference is, I'm only loading the chunks of the world that is visible to the player (the chunk the player is currently on, and the ones immediately around it).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!