private void serializeState(string path)
{
// We should only serialize at the beginning of the 10 state turnphase so everything
// can be started at zero when we deserialize
while (_turnPhase != 0)
{
try
{
ProcessTurn();
}
catch (GameEngineException e)
{
// The game will throw exceptions like StateTimeOut, Blacklist, etc during process turn
// Since we are serializing, ignore them all. We will hit them again when we report again
ErrorLog.LogHandledException(e);
}
}
BinaryFormatter b = new BinaryFormatter();
FileStream stream = new FileStream(path, FileMode.Create);
try
{
b.Serialize(stream, WorldWidth);
b.Serialize(stream, WorldHeight);
b.Serialize(stream, MaxPlants);
b.Serialize(stream, MaxAnimals);
b.Serialize(stream, _plantCount);
b.Serialize(stream, AnimalCount);
b.Serialize(stream, CurrentVector);
Scheduler.SerializeOrganisms(stream);
}
finally
{
stream.Close();
}
}