All you need to do is save enough data so that you can properly reconstruct the game world back to the way it was at the save point.
I would highly recommend you make your class objects streamable as this will greatly facilitate your efforts. However you can just create a save function that will write out the pertinent data.
Since you cannot write pointers (you can but itis ugly during reconstruction) and/or variable length strings easily you will have to account for these. What I normally do is write enough data so that I know what type of object im working with and enough state data to re-create it just as it was during the save.
I would not attempt to write out a load function that messed with pointers and offsets from class base addresses b/c you can gain the same functionality by being smart with your data.
A simple interface might be:
Code:
class ISerializeable
{
virtual ~ISerializable() { }
virtual void LoadFromFile(std::string filename) = 0;
virtual void LoadFromOffset(unsigned __int64 fileoffset) = 0;
virtual void SaveToFile(std::string filename) = 0;
virtual void SaveAtOffset(unsigned __int64 fileoffset) = 0;
};
class IGameObject
{
...
...
};
class GameObject:public IGameObject, public ISerializable
{
public:
virtual void LoadFromFile(std::string filename);
virtual void LoadFromOffset(unsigned __int64 fileoffset);
virtual void SaveToFile(std::string filename);
virtual void SaveAtOffset(unsigned __int64 fileoffset);
};
Your GameObject class then would implement the functions provided by the ISerializable interface.
You would then be able to iterate your list of game objects and call the appropriate Save/Load function for each. This should create the game world correctly.