Advertisement

[C++] Loading next map file TinyXML

Started by June 19, 2016 04:21 AM
0 comments, last by Alberth 8 years, 6 months ago

So I am currently using TinyXML to load in a map and I was curious if there is a nice easy way to load in another map file after the last one is complete? I tried doing this in my Update function but that just lags my program due to it loading over and over. I can't do it in Setup function either due to it not updating level 2 file. Any ideas on how I can get around this?

I think we are going to need a little more context, as I don't really understand what you're saying.

I was curious if there is a nice easy way to load in another map file after the last one is complete?

What does "complete" mean here? loading is complete, or the player has reached the end of the level, or reached the edge of the current map?
- "loading is complete" -> So you're loading new map files constantly? Why?
- "reached end of level" -> Why do you use Update? Doing it after the 'finished' screen would be easier?
- "reached edge of map" -> ok, seems a valid use-case at first sight.

I tried doing this in my Update function but that just lags my program due to it loading over and over.

Well, yeah, Update gets called lots of times.
The problem here is that it loads too often, or that it loads when needed, but the time to perform the load itself takes too long?

If the former, do you skip loading when you have already loaded the map into memory?

If the latter, there are several options.
- Loading XML can be done with DOM (load entire blob in one call), or with SAX (load small parts). Latter is more complicated, so it may not be worth while to try
- Make the map files smaller. You'll have more files to load, but each one loads quicker.
- Don't use XML. XML is a text-based format, which you have to convert to binary format. That takes CPU time, which you don't have. Instead, make a binary file with fixed size map-tiles in a known order. This means you can seek to an arbitrary map-tile in the file, and load just the 'fixed size' bytes to get a new map tile. Before you run the game, you'll have to convert your XML data to this mapfile format, but you can do that off-line, where you have plenty of CPU time.


I can't do it in Setup function either due to it not updating level 2 file. Any ideas on how I can get around this?

Sorry, but I have no idea what you mean here. Please elaborate.

This topic is closed to new replies.

Advertisement