I'm trying to figure out a way to write a save/load system for my game in C++. As of right now, I'm doing it all using binary flags. Anyone got a clue on how to do it another way? I don't mind using binary, but I want to know my options. I also want something in which it would be easy to check on the status of just one event being complete or incomplete in order to decide certain things (a lot of the items system in this game is dependent on what the player has or has not done throughout the course of the game).
|
|
Serialization would be the way to go, and as for the status-checking, you could have logic in the deserializtion method to do so. |
|||||||||||||
|
|
I've studied the DOOM source code a bit. I'll tell you how it's done in there. D_DoomMain contains all of the open/save/load functions, as well as a slew of other things. As it says at the beginning of the file,
Basically, the whole file is full of Since your question is 'How can I write?' I'm just going to paste some bits of code that refer to gamesaves, from D_DoomMain: here are the statements where that stuff gets used, at the very end of the loop.
Here's the function that accesses the strings, which you find scattered throughout the code:
You've also got a file called p_savegame.c with stuff that will save all of the user-associated data (which weapons you've got, where you are in which level, etc). And finally you've got the file which loads savegame data into a game scenario, arguably the most complex of all, because it also loads everything else. That one's called p_setup.c, and is located in the same directory. It worked well for me to |
|||
|
|
|
You could serialize the class or the data to a flat file and then read it back when you load. |
|||||||||||
|
|
I +1:ed the suggestion to use XML/JSON to structure the save games. This way you are very prepared to make the saves "cloud" based. Or at least, you'll have a structure you could use for future projects which might involve the web. As long as the files aren't stored in a way that's too easy to read they should give you loads of benefits. Like metrics! Hooray |
|||||
|