Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

As the title state, I have a large tilemap 400 x 400 x 26. Which currently just about fairs when using it. Saving takes a couple of seconds and it saves to a .ser file which is okay at the moment however when re-loading the map it takes a couple of minutes and is painful.

I'm wondering how I can improve my saving/loading and also if possible improve the way the maps are used eg: using a 2D array instead of a 3D array but still with the z-level.

share|improve this question
    
How big is your file? Even if it's a few megs, loading the file should not take minutes. –  Vaughan Hilts Aug 3 '12 at 22:55
    
Agreed, @Smallbro could your show your code as to how you are loading the file? –  AbstractChaos Aug 3 '12 at 23:06
    
Try making the texture dimensions power of 2 (512x512) and disable mipmap creation if you don't need it, that might help. –  Darcara Aug 4 '12 at 1:24
    
@Darcara This is not texture, but tilemap - level :) –  Miro Aug 4 '12 at 16:46
add comment

3 Answers 3

up vote 1 down vote accepted

There are many things you can do.

First off, you can try compressing the data, which might and probably will help in many situations.

Another thing that might help is using chunks - dividing the map into smaller pieces (16x16, 32x32 or whatever you find to work best for you).
You can either use multiple files for this and load only the chunks that you need(or load them in order if you need all of them but not immediately) or, if your map is fixed in size, save them uncompressed in one big file with an index telling you which chunks are where and otherwise doing it the same as with multi-file solution.
Chunks have an additional advantage of not having to rewrite everything every time you modify something - just open the relevant file(s) or seek and write data at given locations in the file.

You should also investigate your loading/saving code because loading something that took seconds to save shouldn't be taking minutes. A good first guess would be to make sure you're not resizing an array thousands of times - if that's the case then either preallocate it or use a list and then convert it to an array.

Hope this helps.

share|improve this answer
add comment

Aside from the fact that even loading a file with some data of this dimension shouldn't take minutes (could you post your loading and tile filling algorithm?) you should try to load only what is instantly needed by your game and load the rest while the player is playing your game.

You could take your loading code and the fields that it fills and put it in an seperate thread that notifies the game if there is enough data ready for the player to start.

I'm writing a small 2D RTS Engine in Java and I use 2DArrays (ArrayList>) while every Entity has its own z value (they wont change in my game). So it breaks 3 nested for loops down to 2 nested for loops. Even that approach isn't the most efficient way I think.

share|improve this answer
    
Its odd. On a 300x 300 x30 array it takesover a minute. What my tilemap is doing is serializing the three tilemaps and then unserilizing them for loading. –  Smallbro Aug 8 '12 at 11:50
add comment

Map chunks is the key to optimize maps: loading, saving, drawing, processing etc.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.