Sign in to follow this  
HellRiZZer

Optional Values in Save/Load

Recommended Posts

Hi all, I've got a question I couldn't solve yet, it drives me nuts :) For example, I have an archive file that I use to serialize data into. But for example, I leave it to the user to either have or not some member attributes. For example, they may choose to have no texture or no material in some class, but how do I will know if they exist when I load data from file? I mean, if its all written in binary, theres no way to tell when I'm loading whats the next chunk of data represents, right? So, what should I do? One way is to create a 'weak' or 'null' object like in Game Programming Gems, but that would require every object that is serializable to have one of them. Please suggest what should I do. Thanks.

Share this post


Link to post
Share on other sites
Here is what i would try.

Break the system down to a more general level.
You have
Objects
-Graphical properties
--texture
--material
--color
-physical properties
--sound
--solidity
--mass
...

So that you serialize a "graphics property" attribute on every object, instead of
worring about updating all your object members when you change the graphical end.
You just have to update your GraphicsProperty structure/class with the new data.

I can only think to use NULL value markers for all items not used.
And chunk ID's would make the easiest solution if you ever want to add functionality to your Objects.
But, if you don't anticipate changing the Objects property list that much, use bitmarkers.
When writing/reading a file load each property in some set order. In the file you can then store a '0' or '1' bit to represent if a field is there. So read a bit, check for a 1, if so start reading the chunk, otherwise move on.

Maybe that will give you some ideas.

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