Tuesday, January 8, 2013

further optimized saving and loading + bugfixes

I was able to further optimize my saving and loading routines for my platformer engine I'm working on.


In particular I made it so every time you save the following takes place:


  1. The array that holds the current level structure is bubble sorted to move all the 'deleted' items to the top
  2. The save routine skips over the deleted elements
  3. The save routine re-numbers the items as they are saved out to have a new in-order numeral  (this is important because I am limiting my levels to 20,000 sprites at the moment, therefore I need to make sure there are not gaps in the order, nor a jump in numbers)
  4. Once saved out the current level is deleted from memory and the screen.
  5. The array that holds the level is zeroed out
  6. The save routine calls the load routine to load the freshly saved , newly ordered level into memory.
There were a few bugs , such as when I was deleting sprites manually I was not zeroing the array # that held the sprite; therefore I had 'magic' blocks that would come back all by themselves! 

That was a fun one to figure out!

Also because I was bubble sorting, the zeroed out "empty' blocks were getting bubble sorted to the top of the array ( position 0,1,2,3 if there were 4 0's for example) and I had to do a function to count how many zeroes there actually were and subtract that from the total before saving. 

- punchy out

No comments:

Post a Comment