A tip to improve load times

There are two common cases for loading:  Starting the game fresh and loading a save file, and being inside a game already and reloading a recent save from the same game because something went wrong.  Both times, loading is a rather expensive operation, because there are a lot of things that need to be set up in memory.

Saving, on the other hand, goes a lot faster than loading.  Which suggests a potential optimization:  When loading a game that you determine to be the same game as the current game in progress, (which can be determined any number of ways; the simplest and most foolproof would be to simply put a GUID in the save file header that gets generated at New Game initialization,) save the current game to a memory stream and then run some sort of diff to determine what has to be done.

This can save a huge amount of work.  For example, unless someone's been casting land-altering spells, the entirety of the terrain can be preserved intact.  If it's a recent save, such as an Autosave, being loaded, most of the cities won't have changed too much.  And so on.

6,388 views 2 replies
Reply #1 Top

The potential for state corruption in a game not designed from the ground up with such diff-loading but having it bolted on late in development boggles the mind. There are solid reasons that most games flush most or all of their data structures that are dependent on player information before loading a game.

Reply #2 Top

Well yes, of course a lot of the game state would have to be rebuilt from the ground up.  But for stuff that remains pretty static, such as terrain and cities, there's not all that much to corrupt.  It would have to be done carefully, of course, but I think something like that could be done safely, and it would cut the load times down quite a bit.