Beispiel #1
0
void Player::OnNewEntity(const Safir::Dob::EntityProxy entityProxy)
{
    Consoden::TankGame::GameStatePtr gameState=boost::dynamic_pointer_cast<Consoden::TankGame::GameState>(entityProxy.GetEntity());
    if (gameState)
    {
        for (int i=0; i<gameState->TanksArraySize(); ++i)
        {
            if (!gameState->Tanks()[i].IsNull() && gameState->Tanks()[i].GetPtr()->PlayerId().GetVal()==m_myPlayerId)
            {
                //we participate in this game
                m_currentGameId=entityProxy.GetInstanceId();
                m_currentTankId=gameState->Tanks()[i].GetPtr()->TankId();
                m_myJoystickId=Safir::Dob::Typesystem::InstanceId::GenerateRandom();
                Consoden::TankGame::JoystickPtr joystick=Consoden::TankGame::Joystick::Create();
                joystick->PlayerId()=m_myPlayerId;
                joystick->GameId()=m_currentGameId;
                joystick->TankId()=m_currentTankId;
                joystick->Counter()=0;
                m_connection.SetAll(joystick, m_myJoystickId, m_myHandlerId);
                m_logic.reset(new TankLogic(m_currentTankId, boost::bind(&Player::SetJoystick, this, _1, _2, _3, _4)));
                break;
            }
        }
    }
}
Beispiel #2
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;
    }
}
Beispiel #3
0
void Player::OnUpdatedEntity(const Safir::Dob::EntityProxy entityProxy)
{
    Consoden::TankGame::GameStatePtr gameState=boost::dynamic_pointer_cast<Consoden::TankGame::GameState>(entityProxy.GetEntity());
    if (gameState && m_logic && entityProxy.GetInstanceId()==m_currentGameId)
    {
        if (gameState->Winner().GetVal() == Consoden::TankGame::Winner::Unknown) {
            try
            {
                m_logic->MakeMove(gameState);
            }
            catch(...)
            {
                std::cout<<"Caught unhandled exception in TankLogic!"<<std::endl;
            }
        }
    }
}
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);
            }
        }
    }     
}
Beispiel #5
0
void Ponger::Pong(const Safir::Dob::EntityProxy& entityProxy)
{
    const Safir::Dob::Typesystem::InstanceId instance = entityProxy.GetInstanceId();
    //    std::wcout << "Pong " << instance << std::endl;

    PingPongTable::iterator findIt = m_pingPongTable.find(instance);

    //if it is not in the table it is the first time we've seen it, so add to the table
    if (findIt == m_pingPongTable.end())
    {
        findIt = m_pingPongTable.insert(std::make_pair(instance,Safir::Dob::Typesystem::InstanceId::GenerateRandom())).first;
    }

    m_entity->Number() = boost::static_pointer_cast<DoseStressTest::Ping>(entityProxy.GetEntity())->Number();
    m_entity->WhichPing() = instance;

    m_connection.SetAll(m_entity,findIt->second,m_handler);
}
Beispiel #6
0
void Ponger::OnDeletedEntity(const Safir::Dob::EntityProxy entityProxy,
                             const bool                    /*deletedByOwner*/)
{
    const Safir::Dob::Typesystem::InstanceId instance = entityProxy.GetInstanceId();
    PingPongTable::iterator findIt = m_pingPongTable.find(instance);
    if (findIt == m_pingPongTable.end())
    {
        std::wostringstream ostr;

        ostr << "Got a delete for an instance that I haven't seen before! instanceId = " << instance;

        ErrorReporter::Log(Safir::Dob::Typesystem::Utilities::ToUtf8(ostr.str()));
        std::wcout << ostr.str() << std::endl;
        return;
    }

    m_connection.Delete(Safir::Dob::Typesystem::EntityId(DoseStressTest::Pong::ClassTypeId,findIt->second),m_handler);
    m_pingPongTable.erase(findIt);
}