Sign in to follow this  
DontPanic

C++ program serialization

Recommended Posts

To be honest I'm not sure the title of this thread is correct. In my game I would ideally like to have the ability for the player to save anywhere. While I could presumably write all the variables too a save file and read them all back in on loading, that would be very ugly to put code everywhere and looking at it, very fiddly too. Hence my thought of saving the program and then reloading it's state on loading. I doubt this will result in too large a file for my game and I guess it could be compressed too so it in theory seems good. So after plenty of searching I think I'm on the right track with serialization. Save the game state and restore it, can act as the quick save I want. Allowing the player to leave the game at any time because sometimes real life does that to all of us. Looking into it I've checked out libraries for c++ implementing serialization and looked around the forums and net. Doesn't seem to be the best of languages too do this with but language choice is something that cannot be changed now. The way I see it, I would in effect pause the program at any time for an indefinite amount of time and the restore it at any time. Make a binary file that can be read in later to restore the program. I'm not savvy to serialization as you can tell so I might be picking the wrong thing for my purposes. The question is, is there a programming trick people know to "save" the programs entire state in c++? Or am I in for a heavy amount of research to get this going? Or is there another way of doing this that is perhaps simpler? (Dispite lots of talk about my game, I think this comes down to a question about c++ and not game programming. Apologies if this is in the wrong area however)

Share this post


Link to post
Share on other sites
You are essentially correct in how you would go about achieving the desired quicksave/load functionality however C++ doesn't really help you with being serialization friendly, apart from supplying stream's to work with.

I would recommend you look into the Boost Serialization stuff.

A quick side note. This is one of the benefits of having an embedded scripting language - e.g. my engine has stackless python 2.5.x which has pickling (serialization) support which means I don't have to waste time writing serialization methods for classes which are not involved with the python game code and there are less C++ classes which still need the serialization because most of the actual game related classes like Enemyies, Vehicles and NPC's can be implemented with straight Python.

Share this post


Link to post
Share on other sites

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

Sign in to follow this