Saving/Loading Game State
I'm surprised to find that there don't seem to be any GDnet articles on saving and loading game states. I mean this in the traditional sense of saving your progress and loading old savegames.
I've read a few articles about how to save and load individual POD/structs to disk and load them again using binary read/write. However, there don't seem to be any guidelines on how to apply this to an entire game state. At a guess, I'd say have some sort of "mark" on things that should and should not be saved, then iterate through all objects and write to disk, then mirror the process for loading. This means that one function has access to every saveable object...
Are there any agreed "do"s and "don't"s here?
Quote:This means that one function has access to every saveable object...
Not necessarily. Each object could know how to write itself and some function would just tell the appropriate things to write themselves.
Try searching the web for the term 'serialization'. I thought there was a gamedev article on this a while back, but if there was I can't find it.
The main difficulty is saving and restoring pointers between game objects, which isn't trivial since objects are usually in different places when they're reloaded. Other than that, you'll need some way of identifying what each object in the save file is, so that you can call the appropriate constructor.
The main difficulty is saving and restoring pointers between game objects, which isn't trivial since objects are usually in different places when they're reloaded. Other than that, you'll need some way of identifying what each object in the save file is, so that you can call the appropriate constructor.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement