I'm using Boost Serialization for saving and loading my game's overall state as well as storing map and creature data externally.
I have two programs. The first runs the game itself, creating new objects as necessary based on the data saved in the external files. It also produces savefiles of its own state. These all work so far.
The second, I am creating as a dedicated editor. I want to use it to create and manipulate said files to be used by the game program.
So I made mirror images in the second program of all the classes that require external files, but with different functions for the purposes of editing. All the data in the
void serialize(AreaArchive & aar, const unsigned int version)
{...}
part of either program's class is the same.
I use this to create the file:
areaGen.push_back(new Area("area1"));
std::string fileName;
for(std::vector<Area*>::iterator it = areaGen.begin(); it != areaGen.end(); ++it)
{
fileName = (*it)->name + ".areabase";
std::ofstream areafile(fileName);
boost::archive::text_oarchive outArchive(areafile);
outArchive << *it;
}
The file, let's say "area1.areabase" is produced perfectly AFAIK. I move it to the directory of my first program, execute the function as
bool LoadAreaState(std::string areaName, Area *target, bool baseState)
{
std::cout << "Debug: entered area loading function..." << std::endl;
std::string fileName;
if(baseState)
fileName = areaName + ".areabase";
else
fileName = areaName + ".areafile";
std::ifstream areafile(fileName);
...
std::cout << "Debug: file opened sucessfully..." << std::endl;
boost::archive::text_iarchive inArchive(areafile);
std::cout << "Debug: inarchive to target..." << std::endl;
inArchive >> *target; // The step at which it fails - Terminate by boost::serialization's exception
std::cout << "Debug: target Area object restored..." << std::endl;
return true;
}
And of course it doesn't work. The member object of the class in the first and second programs couldn't be the same anyway. Could it? But the serialize blocks contain the exact same type data.
I hope this example expresses what I'm trying to do. But is there a way I can make it work?
Thanks very much.