Jump to content
  • Advertisement
  • entries
  • comments
  • views

Adding loading/saving on-the-fly...hmm..not really

Sign in to follow this  


There're always topics you are aware of, but which you are ignoring most of the time until it is too late. You will thought of it as some minor feature which could be added later. Well, this could be a bad idea.

I trapped myself with one of this minor feature: loading/saving
Yes, it sounds simple. After more than 10 years of developing an engine/game I came to the conclusion that it is time to add it now. It turned out to be one of the tougher challenges of the last years.
When you got a C++ engine and lot of scripted code (whole game logic), then you have a problem here.

So, how to save your game ? There come two approaches to mind.

1. Serialisation/Deserialisation:
You serialize every object in your game to a file. You must have some special handling for associations between objects. I use a unique id for each object and save only the ids for references. Thought after loading your game data you need to reconnect the references.
A problem with this approach is, that you need a lot of post processing and you need to change class models to support it (I.e. some script languages like lua supports refering functions). You can regard this as an almost 1:1 memory copy of you game data.

The major advantage of this technique is, that you can easily add and remove data from your game. The mechnism works almost automatically. But there're some pitfalls. First your saved gamedata is really fixed to one version of your game. Reloading it with an newer version could easily lead to some disaster. This is really an issue while developing a game and when you need to release some bugfixes.

2. Export/Import
Instead of just saving a copy of the whole data to a file you export and import the data. In this case you define some kind of save-fileformat for each object, relation etc. When importing it you need some kind of special parser for each entity to create and connect the according objects in your engine.

The major advantage is, that this is a clean approach and you can change the game code while keeping the save files (just adjust the importer). But you need to put some work into it whenever you change the fileformat. But this could lead to high maintainance costs at development time.

Well, after forgetting about save files for years, I choose to go for de-/serialisation. I would have prefered the import/export approach, but it is just too expensive. To soften the negative upgrade effect (new game version makes older save files obsolete), I choose to use some kind of weak references to static content. Therefore I divided the data into permanent and persistent data. Permanent data are shared, static data which are used independendly by dynamically created content. I.e. game rules, templates etc. This static content get unique ids at design time and will not be saved to a save file. When reloading a file I can reconnect objects to this version dependent data. This allows me to upgrade and change the game to some extend without making the save files obsolete.

Once the game has been released I fear that a major game update will lead to obsolete save files, but this could happen to import/export files too. Atleast minor updates should work as long as I'm careful about changing the code and content.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!