Sunday, September 18, 2011

Persisting objects

Hey..

It's time to take better look at my object serialization. When I designed the structure for the game I made serialization interface for every object I wanted to load and save. The interface is mearly few virtual functions which have to be implemented in every class which inherits this interface. I wish making persisting objects would be as easy as just: file.write( reinterpret_cast<char *>(&x), sizeof (x) ); where x is something we wanna save. But it's not. You could do that for chars, ints and such but when there's pointers involve and objects within objects, reconstructing the object from file would be impossible.

Therefore I had to do this interface for serialization. In my code I have  serialize and deserialize. In serialize I save every variable separatly into file and in deserialize I load the variables one by one in same order I saved them. That doesn't sound too bad, and it's not, but one must be really really careful not to make mistakes since when objects serialize themselves within other objects, finding mistakes can be really really hard. Even more difficult in my case since I use gzip to compress the data.

well I gotta get to work.. its gonna be a pain but it has to be done to get saving/loading working again...

No comments:

Post a Comment