Pages

Sunday, August 15, 2010

gzip!

I spent a couple of hours today implementing the basics of map saving/loading. It was clear from the beginning that I would have to come up with a better system for saving map data. Even though each tile in the map array just needed a byte, in order to save them I needed to use 2-4 bytes. Simply saving each byte as the corresponding character in the text file was out of the question, because a lot of those characters were special ones that screwed up the file, so I had to save them as 1-3 digit numbers separated by semicolons. (e.g. 128:24:1:35) As you can see, that takes up a lot of extra space, and resulted in 63x38 maps taking up over 9 kb for their arrays alone.

After several frustrating hours today, I managed to implement a system that compresses the raw map arrays using gzip. Then it takes that data and applies 64 bit encoding so that it won't mess up the save file or require a lot of extra space. As a result, the compressed map data will still fit nicely in the text-based save files, but editing actual map layout data will be near impossible (not that it was very easy to do in the old version anyway).

Was this extra work worth it? Well, I'm able to store the arrays for a 120x80 sized map in around 2 kb now as opposed to the 9 kb it took before (for smaller maps too)! When you have thousands of potential map files, that really makes a difference.

Let me know if I'm posting too much boring stuff...

No comments:

Post a Comment