Saving and Loading

January 03, 2013 | Filed under: programming

How I envy developers working on arcade games, or anything that has a very simple game ‘state’ that can be easily saved and loaded with no grief. For the game I am currently working on (announcement later this month), it’s a bit of a pain, because the actual game ‘state’ is horrendously involved, and every single byte of it has to be loaded and saved perfectly. The problem is mainly due to my tendency to code systems that have a huge number of objects that all have pointers to each other, in complex and arcane ways.

In theory, stitching everything back together after a load is fairly easy, but in practice, it’s a bit of a pain, and the REAL pain is to know that it has all worked perfectly. if 99% of the pointers are right, and 1 isn’t, then I have a horrible dangling bug somewhere…

My current process for preventing this is to have the game completely save out it’s state and load it’s state back in every turn (it’s a turn based game). At the moment, due to arcane debugging issues this is horribly slow, but eventually will be super fast. At least doing it this way means that during development I’ll spot any save/load inconsistencies really quickly.

I’m aching to get on with some GUI stuff to make it look nice, but I’ve learned the hard way that I have to put that off until the foundations work better. Better to have it stable now, rather than fix it later.

6 Responses to “Saving and Loading”

  1. Kevin Peter says:

    If you think that’s fun, try dealing with software that can load various versions of a binary save file. Older versions contain different information than newer versions. Ick. XML can definitely help alleviate versioning issues, but it isn’t a cureall. No matter how you save it, you still have to reconstruct everything in memory when you load it back in.

  2. cliffski says:

    indeed, the actual XML parsing bit of this stuff is the trivial bit.

  3. Michael says:

    Turn based? Curious now… looking forward to finding out what it is.

  4. Damian says:

    What would happen if you created a hash of the game state, saved and loaded it back in, then re-hashed it. Would that catch any difference? RTSs can use this when running network games to detect any difference in clients

  5. cliffski says:

    indeed, might be worth a try.