Jump to content
  • Advertisement
Sign in to follow this  

RPG Save Game State

This topic is 2862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,
I'm developing an RPG game on iOS platform using the Cocos2d engine with my own layer on top of it for isometric graphic. Currently i'm looking for a way to efficently save the game state and i need some opinions. English is not my native language so please bear with me.

The game's assets is in the form of a TMX tiled maps with objects(NPCs, items, etc) defined in it and also .plist files to define the default state of those objects (their level, items / loots they carry, is dead or is alive, etc)

since the game is an open world type of RPG, i'm giving the player some freedom where they can kill any NPC they want, steal their inventory, etc. I soon found out that saving the state of this kind of game is not simple since i can't directly alter the original .plist files.

My current approach is to store the changes made by player into SQL every time something is altered (NPC killed, quest cleared, treasure chest emptied, etc), so then the flow is:
- every time a map is loaded, the game first load the original assets (the TMX map and the .plist files), and then check for changes in the SQL database, if there are changes, apply it to the object.
- when the player save the game, the SQL content is then dumped to a binary file, everytime player load a save, the current table content is cleared, and then loaded back with appropriate SQL dump file.
in essence, the SQL database only store the "difference" of objects from the default state, so if there's no changes made yet, it wont appear in the database. In this case, the save file's size will be dynamic (size expected to increase as the game progress).

is there other approach for this? maybe one with simpler method or offer better performance? please give me some insight :)

Share this post

Link to post
Share on other sites
Usually with an RPG, you end up keeping track of flags and variables.

flags can be things like "Door 1 is open" and are usually used to keep track of quest line progress
variables are usually things like "how much gold do I have?"

When saving the game, you'd dump flags and variables into your format of choice (plist, xml, etc...) and when you load, you'd create everything, load the default values, then load your save file to restore the flags and variables.

Of course, the more open you make the game the more complicated the entire thing gets (not just save files).

The important thing to remember is that even an open game needs limitations; it is still a game.

Share this post

Link to post
Share on other sites
You can keep track of all the changes, saving them on demand.
If the default is A and the player changed it to B you save that. If the game is loaded with B and by saving time it is still B, no reason to save that again even if it's not the default value, reducing the overhead.
Other way to reduce performance problems is saving often, as it would reduce the number of changes that needed to be stored on each save.
Yet another worth mention is to keep track of the last save game. If your game allows the player to save in different slots you can keep track of all save games he's using for that character, but that's too much of a headache. If you keep track of the last saved game file instance (multiple files or not), when he saves on the same slot you'll just alter what you know that has changed, reducing a lot overhead of saving on the same slot. When he saves on another slot, you make a copy of the last one but with the updated state (again, only what has changed), this'll allow you to decrease complexity since you'll not need to compare the actual game state with the slot being saved:
If it's the last saved game, it'll need to save only the changes
If it's not the last saved game, you won't know what has changed between both, so why not just copy the last save, if any (or in some cases the loaded game, if the player hasn't saved yet).
Forgive me if I'm being confuse!

Still, the best way to optimize your save performance/size is a good game state model, knowing what really needs to be tracked and how. eg, why save all npcs current health if most of them aren't really important since they're miles distant from the player?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!