Suppose I have a game written in C/C++. For simplicity, I have:
struct masterStruct
{
Coords player1;
Weapon player1;
Gravity player1;
...
};
Suppose this struct contains 1000s of variables that relate to the player. I want to be able to create a “snapshot” of the player’s state at time t = 10s of my game with all of these variables. The snapshot should be saved in a fle.
Now, suppose my hard core developing group decided it is necessary to add a 1001th variable to the structure. Now, my game, expecting there to be 1000 variables fails to load the “snapshot” correctly (because of that last variable).
My question: how do I tackle such a dilemma? Should I create these “snapshots” with version numbers and a handshake between snapshot file and game loader so only approved version files will be loaded?
——————— Side Note:
I am using Lua as the scripting language to parse all of these data which is pretty nice. It’s just reading the variables which is a pain.
Thanks
Use a good serialization library with versioning support. Boost.Serialization is a very good library for this sort of thing.
Of specific interest to you should be this feature (quoted from the docs):