Keeping scenes states/saving game

Started by
1 comment, last by Shaarigan 4 years, 6 months ago

Im trying to create a system to keep the states of the scenes in an RPG, and my first approach was to have all entities (NPCs, containers, etc) of non active scene in memory, to restore them when its scene gets loaded again. But somebody told me that such idea was not optimal, because of memory consumption, and that the best way was to serialize the scene state to disk when exiting, and restoring from disk when loading again. But that gives me some doubts, because it would require an intensive use of disk (consuming SSD write cycles) and arises the problem of what to do with saved scene states when exiting the game: keep them and reference thos files from global savegame archive (with all possible derived problems), or delete them and saving the state to the saved game. Whats the best choice in this case? I have been looking at the savegames of AAA games and none of them seems to keep any serialized scenes outside the main saved game file.

Advertisement

As you already pointed out, persiting anything to disk is time consuming and that is the reason why even AAA games don't do this. Nowdays the player is custom with having automatic progres saving systems and most players starting an old game even don't know about the concept of managing saves by your own ?

Someone playing Doom 3 for the first time in the past forgot to save the game and has had to restart it. It is funny but sad on the other siede...

However, it depends. If you are driving your own game engine or at least have access to the memory management of your game, you can propably control where values are saved. This way you have the chance to put exactly this piece of memory to disk where all of your important game states/ objects live. This is the most easy and fastest approach you can get.

The alternative would be to serialize everything you want to persist with a serializer solution, I think this is most common because Unity or Unreal don't allow to access the raw memory of your game.

But in the end it dosen't matter what you serialize, it matters how many you serialize. Saving is the time critical part of modern games because players expect the process to be very quick so they can return to play the game fast while loading is a more accepted process to last at least so much time that you have the chance to display a loading screen. Don't miss the difference between loading a game and have reset points in your game like if you fall down a cliff and will be resetted to your previous position for example in Mario Kart.

My opinion to this topic is: Save whatever is needed to restore the state at the time you saved it. This means that you don't save anything you can restore from saved information. Player position, player gold, player exp: all have to be saved, player character animation state dosen't.

One last thing to target your doubts, if you feel like you are interacting with disk too much, you can swap to memory mapped files. They are persited by the OS and stored to disk on demand when the OS schedules pages in/ out of your program scope. They are also very time efficient because you write to a pointer provided by the OS and don't have to manage file I/O by your own (I stay apart from targeting page misses and whatever can make memory mapped I/O slow because it counts as one of the best general approaches to handle with continious data I/O in games, so it has it's bad circumstances like every technology)

This topic is closed to new replies.

Advertisement