コード例 #1
0
void SerializedGameData::PushObject_(const GameObject* go, const bool known)
{
    RTTR_Assert(!isReading);

    // Gibts das Objekt gar nich?
    if (!go)
    {
        // Null draufschreiben
        PushUnsignedInt(0);
        return;
    }

    const unsigned objId = go->GetObjId();

    RTTR_Assert(objId < GameObject::GetObjIDCounter());
    if(objId >= GameObject::GetObjIDCounter())
    {
        LOG.write("%s\n") % _("An error occured while saving which was suppressed!");
        PushUnsignedInt(0);
        return;
    }

    PushUnsignedInt(objId);

    // If the object was already serialized skip the data
    if(IsObjectSerialized(objId))
    {
        if (debugMode)
            LOG.writeToFile("Saved known objId %u\n") % objId;
        return;
    }

    if (debugMode)
        LOG.writeToFile("Saving objId %u, obj#=%u\n") % objId % objectsCount;

    // Objekt merken
    writtenObjIds.insert(objId);

    objectsCount++;
    RTTR_Assert(objectsCount < GameObject::GetObjCount());

    // Objekt nich bekannt? Dann Type-ID noch mit drauf
    if(!known)
        PushUnsignedShort(go->GetGOT());

    // Objekt serialisieren
    if (debugMode)
        LOG.writeToFile("Start serializing %u\n") % objId;
    go->Serialize(*this);

    // Sicherheitscode reinschreiben
    PushUnsignedShort(GetSafetyCode(*go));
}
コード例 #2
0
void SerializedGameData::PushObject(const GameObject* go, const bool known)
{
    if(go)
    {
        //assert(go->GetObjId() < GameObject::GetObjIDCounter());
        if(go->GetObjId() >= GameObject::GetObjIDCounter())
        {
            LOG.lprintf("%s\n", _("An error occured while saving which was suppressed!"));
            go = NULL;
        }
    }

    // Gibts das Objekt gar nich?
    if(!go)
    {
        // Null draufschreiben
        PushUnsignedInt(0);
    }
    // Ist das Objekt schon vorhanden?
    else if(GetConstGameObject(go->GetObjId()))
    {
        // Dann nur die Obj-ID draufpushen
        PushUnsignedInt(go->GetObjId());
    }
    else
    {
        // Obj-ID
        PushUnsignedInt(go->GetObjId());

        // Objekt nich bekannt? Dann Type-ID noch mit drauf
        if(!known)
            PushUnsignedShort(go->GetGOT());

        // Objekt merken
        objects_write[objects_count++] = go;

        assert(objects_count <= GameObject::GetObjCount());

        // Objekt serialisieren
        go->Serialize(this);

        // Sicherheitscode reinschreiben
        PushUnsignedShort(0xFFFF);
    }
}
コード例 #3
0
void SerializedGameData::PushObject(const GameObject* go, const bool known)
{
    assert(!isReading);
    if(go)
    {
        //assert(go->GetObjId() < GameObject::GetObjIDCounter());
        if(go->GetObjId() >= GameObject::GetObjIDCounter())
        {
            LOG.lprintf("%s\n", _("An error occured while saving which was suppressed!"));
            go = NULL;
        }
    }

    // Gibts das Objekt gar nich?
    if(!go)
    {
        // Null draufschreiben
        PushUnsignedInt(0);
        return;
    }

    PushUnsignedInt(go->GetObjId());

    // If the object was already serialized skip the data
    if(IsObjectSerialized(go->GetObjId()))
        return;

    // Objekt nich bekannt? Dann Type-ID noch mit drauf
    if(!known)
        PushUnsignedShort(go->GetGOT());

    // Objekt merken
    writtenObjIds.insert(go->GetObjId());

    objectsCount++;
    assert(objectsCount <= GameObject::GetObjCount());

    // Objekt serialisieren
    go->Serialize(*this);

    // Sicherheitscode reinschreiben
    PushUnsignedShort(0xFFFF);
}
コード例 #4
0
void SerializedGameData::MakeSnapshot(GameWorld& gw, EventManager& evMgr)
{
    Prepare(false);

    // Anzahl Objekte reinschreiben
    PushUnsignedInt(GameObject::GetObjCount());

    // Objektmanager serialisieren
    gw.Serialize(*this);
    // EventManager serialisieren
    evMgr.Serialize(*this);
    // Spieler serialisieren
    for(unsigned i = 0; i < GAMECLIENT.GetPlayerCount(); ++i)
        GAMECLIENT.GetPlayer(i).Serialize(*this);

    writtenObjIds.clear();
}
コード例 #5
0
void SerializedGameData::MakeSnapshot(GameWorld* const gw, EventManager* const em)
{
    // Buffer erzeugen
    Clear();

    // Objektreferenzen reservieren
    objects_write = new const GameObject*[GameObject::GetObjCount()];
    memset(objects_write, 0, GameObject::GetObjCount()*sizeof(GameObject*));

    // Anzahl Objekte reinschreiben
    PushUnsignedInt(GameObject::GetObjCount());

    // Objektmanager serialisieren
    gw->Serialize(this);
    // EventManager serialisieren
    em->Serialize(this);
    // Spieler serialisieren
    for(unsigned i = 0; i < GAMECLIENT.GetPlayerCount(); ++i)
        GAMECLIENT.GetPlayer(i)->Serialize(this);

    delete [] objects_write;
}
コード例 #6
0
void SerializedGameData::MakeSnapshot(GameWorld& gw)
{
    Prepare(false);

    // Anzahl Objekte reinschreiben
    expectedObjectsCount = GameObject::GetObjCount();
    PushUnsignedInt(expectedObjectsCount);

    // Objektmanager serialisieren
    gw.Serialize(*this);
    // EventManager serialisieren
    gw.GetEvMgr().Serialize(*this);
    // Spieler serialisieren
    for(unsigned i = 0; i < gw.GetPlayerCount(); ++i)
        gw.GetPlayer(i).Serialize(*this);

    // If this check fails, we missed some objects or some objects were destroyed without decreasing the obj count
    RTTR_Assert(writtenObjIds.size() == objectsCount);
    RTTR_Assert(expectedObjectsCount == objectsCount + 1); // "Nothing" nodeObj does not get serialized

    writtenObjIds.clear();
}