Question

Yesterday when I was playing a video game a question suddenly comes to me, how is game save mechanism implemented?

Mostly, a save requires all data of the game. In this case, doesn't the programmer have to make a god object that has reference to EVERY single piece of game data?

I post the question here at SO rather than game development because I want an answer based on software design rather than game development itself.

Was it helpful?

Solution

One thing you should keep in mind is that you only need to store the data that matters. For instance, this might include inventory contents (a list of IDs and quantities perhaps), player position, and key quest bits (did you already get the enchanted celery from the forbidden fridge?). This can be implemented with something like the Memento pattern, though in practice it's typically just a struct (or equivalent) that is serialized out to disk.

You don't need to save the entire world state, as a level loader will typically take care of item / entity placement within the world. If you look carefully, you will notice that restoring a save doesn't necessary restore the exact state of everything in the world - only the important bits. This is a kind of psychology hack that one uses often in games.

Some other considerations with save files might include a hash or checksum to detect save file tampering, or storing seed values that a runtime RNG would use to create the same series of events / entities after a game load.

Basically, you don't actually need to save every bit of world state - just the parts the player is likely to care about :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top