PDA

View Full Version : Saving: how do it works



Bhazor
12-10-2012, 10:15 PM
Now I know nothing about game programming but one particular aspect has always puzzled me. How does saving work? Now I can understand how it would work in a simple game (a NES platformer say) . It's basically a password referring to a level with a bit of data for lives/score. But what about in a game like Morrowind/Skyrim where there are thousands of objects and AI characters. Where I leave a muffin on top of a mountain. Save the game. Reload the next day and find the exact same muffin looking at me. The only thing I could think of is saving a snapshot of the whole world Dwarf Fortress style but that would take hundreds of megs and the average Morrowind/Skyrim save is generally less than 500kb.

Heliocentric
12-10-2012, 10:29 PM
There are 2 kinds of save, the literal store where save files get monstrously big, and abstractions. In both cases the game merely needs to log "accurate" details of the world and then the loading system reads the notes and replicates the details.

In halflife where you are, what enemies exist at the moment, how much ammo you have etc. Of course things get dropped when its not a complete memory dump. Maybe the enemy's gun is loaded to full, or all physics objects lose momentum.

These detail errors like enemies getting bored of following you on a reload are highly common in real games and vary widely, obviously this is why games love "jumping off points" where you cant go back so the game doesn't need to remember that you stacked up 5 drink cans because you cant go back anymore.

edit: for example, in oblivion where someone is doesn't need to be saved if they are on schedule. so someone where they are meant to be can just be drawn from the regular game data. Whereas a guard you have killed will need to be logged where he is and that he'd dead, probably some rough ragdoll data. When you leave, he'll get scrubbed from existence and thus not be a priority for saving.

Remember, there is nothing stopping save files being compressed compare a JPG to a literal BMP, it can be 100 times smaller and contain almost exactly the same picture.

caljohnston
12-10-2012, 10:36 PM
To save a game, you take all the relevant game state (for Morrowind that might be the position and orientation of actors, quest variables, etc) and write them to a file in some format. To load a game, you read the file and parse its content into a valid game state.

CaptainWaffles
12-10-2012, 11:00 PM
A Skyrim save can be really small because it doesn't need to track every object. It just needs to keep track of objects that have moved from where the map files dictate they start, or have been added during play. Every such object is just a dozen or so bytes really, so unless you're spawning millions of cheese wheels or something it'll be pretty small.

Heliocentric
12-10-2012, 11:18 PM
http://www.youtube.com/watch?v=UyHiIeBsc9E

Sakkura
12-10-2012, 11:23 PM
A Skyrim save can be really small because it doesn't need to track every object. It just needs to keep track of objects that have moved from where the map files dictate they start, or have been added during play. Every such object is just a dozen or so bytes really, so unless you're spawning millions of cheese wheels or something it'll be pretty small.
It needs to save other stuff like quest state and non-respawned container contents (including merchant inventories, which are stored in inaccessible chests). So a Skyrim save does tend to end up at a few megabytes. Still manageable.

Some games, like Paradox grand strategy games, can end up with pretty big save files. There's just a lot to store in those cases (eg. CKII - the state of every person that ever existed in the game, plus data on infrastructure, technology and available levies in every single province holding, and size and composition of armies, siege progress, yada yada yada).

Kodeen
12-10-2012, 11:31 PM
Where I leave a muffin on top of a mountain. Save the game. Reload the next day and find the exact same muffin looking at me.

For this example, all you need to store is the type of object in question, the x/y/z coordinates, and maybe the angle of rotation if you want to be able to load it on its side or something like that. Just a few bytes if you do it efficiently. Do that a few thousand times and a 500kb save is not that unreasonable.

archonsod
12-10-2012, 11:34 PM
The only thing I could think of is saving a snapshot of the whole world Dwarf Fortress style but that would take hundreds of megs and the average Morrowind/Skyrim save is generally less than 500kb.

Thing to remember about storage is ultimately it all comes down to single binary blocks. There's numerous ways to exploit that to save space. Particularly when saving something like a game state, because what individual blocks contain isn't usually that important.

Bhazor
12-10-2012, 11:49 PM
So it's an incremental save that records whats changed and applying it a "model world" rather than taking a snap shot of everything?

That actually makes a lot of sense. It also explains why Skyrim had a game breaking glitch where saves would become too big to load as the player reached high levels because the game was having to record more and more data with each save.
http://www.geek.com/articles/games/skyrim-ps3-save-bug-renders-game-unplayable-20111117/

Mohorovicic
13-10-2012, 06:31 AM
In case of Skyrim specifically you can catch a glimpse of the saving system by looking at quest flags.

http://www.uesp.net/wiki/Skyrim:Unbound#Quest_Stages

As such, the game only needs to use one double(why not integer? Don't ask me) to save quite a lot, since the quest stages decide item placements, location markers, NPC position/dialogues, etc. and are all static.

Still, saving in a game is usually quite the dump. In an FPS it usually is almost 1:1 for example, complete with saving position and momentum of objects flying through the air and whatnot.

karthink
13-10-2012, 08:43 AM
I guess this thread explains why Deus Ex saves took up to ten megabytes each. By the time I finished the game, the save folder was larger than the install.

Or maybe they just didn't compress it.

I wonder if this is a common trend with immersive sims.