예제 #1
0
void Player::OnDeletedEntity(const Safir::Dob::EntityProxy entityProxy, const bool)
{
    if (entityProxy.GetTypeId()==Consoden::TankGame::GameState::ClassTypeId && entityProxy.GetInstanceId()==m_currentGameId)
    {
        if (m_myJoystickId!=Safir::Dob::Typesystem::InstanceId())
        {
            m_connection.Delete(Safir::Dob::Typesystem::EntityId(Consoden::TankGame::Joystick::ClassTypeId, m_myJoystickId), m_myHandlerId);
        }

        m_logic.reset();
        m_myJoystickId=Safir::Dob::Typesystem::InstanceId();
        m_currentGameId=Safir::Dob::Typesystem::InstanceId();
        m_currentTankId=-1;
    }
}
//-------------------------------------------------------
void
PersistenceHandler::HandleEntity(const Safir::Dob::EntityProxy& entityProxy, const bool update)
{
    auto writePeriodIt = m_writePeriod.find(entityProxy.GetTypeId());

    if (writePeriodIt != m_writePeriod.cend())
    {
        // This entity type has a write period limit

        const auto now = boost::chrono::steady_clock::now();

        const auto writePeriod = writePeriodIt->second;

        auto toBeWrittenIt = m_toBeWritten.find(entityProxy.GetEntityId());

        if (toBeWrittenIt == m_toBeWritten.cend())
        {
            // If the entity instance doesn't exist in the map then this instance has never been written.
            // Write it right away!
            Write(entityProxy, update);

            m_toBeWritten[entityProxy.GetEntityId()] = std::make_pair(now + writePeriod,
                                                                      false);  // dirty flag
            m_nextTimeout = now; // Force timeout and a recalculation of nextTimeout
        }
        else if (m_toBeWritten[entityProxy.GetEntityId()].first < now)
        {
            // This instance hasn't been written within its write period
            // Write it right away!
            Write(entityProxy, update);

            toBeWrittenIt->second.first = now + writePeriod; // next timeout
            toBeWrittenIt->second.second = false;            // dirty flag
            m_nextTimeout = now; // Force timeout and a recalculation of nextTimeout
        }
        else
        {
            // Otherwise, mark the entity as dirty and wait until the timer strikes.
            toBeWrittenIt->second.second = true;
        }
    }
    else
    {
        Write(entityProxy, update);
    }
}
예제 #3
0
void DopeApp::OnNewEntity(const Safir::Dob::EntityProxy entityProxy)
{
    if (entityProxy.GetTypeId() == Safir::Dob::PersistentDataStatus::ClassTypeId)
    {
        if (!m_persistenceStarted)
        {
            std::wcout << L"Dope is started as standby persistence. Active persistence is running on node ";
            std::wcout << entityProxy.GetInstanceId().GetRawValue() << "." << std::endl;
            m_persistenceStarted = true;

            if (Safir::Dob::PersistenceParameters::StandaloneMode())
            {
                // Start saving persistent data
                Start(false);
            }
        }
    }     
}