Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

GameSaveSystem - Alternate Implementation: Save & Swap

GameSaveSystem - Alternate Implementation: Save & Swap

Programmer16
Beals Software · · 1 min read
2,318 0
Github Link: https://github.com/dbeals/GameSaveSystem

The initial implementation of incremental saves is great and I'll be sticking with it for most of my games, but there are instances that it simply isn't a good fit (games that have large save files for example.) So, to get around this I have added a new implementation: save and swap. I want to point out ahead of time that the new implementation does still keep one backup copy. I'll be adding a flag to not create the backup in the next commit; I would have done so now, but I didn't think about it until afterwards. Here's the breakdown of the process, using MySave.sav as the save name:

When you save the first time, it goes directly to MySave.sav.
Every save after that creates a MySave.sav.new.
Once the save has completed, it renames MySave.sav to MySave.sav.bak.
Then it renames MySave.sav.new to MySave.sav.

The new implementation can be found in SwapSaveManagerBase and has pretty much the same interface as the incremental SaveManagerBase - SaveGame(SaveName), LoadGame(SaveName), AutoSave(), Export(ZipFilePath), and Import(ZipFilePath).

As a side note, if you're not keen on using the base classes that I've included, 99% of the work is done via the SafeSaveHelper and SwapSaveHelper static classes. You can download the library and utilize the system with those classes alone.

If there is any other implementations that you can think of, let me know!

Discussion

Loading comments...