void Base::Update() { while(!m_events->IsClosingApp() && !m_shouldExit) { m_events->Update(); if(m_currentState == MainMenu_State) { m_mainMenu->Update(); if(m_mainMenu->ShouldStart()) { SwitchToState(Game_State); } m_shouldExit = m_mainMenu->ShouldExit(); } else if(m_currentState == Game_State) { m_game->Update(); if(ScoreManager::Instance->IsGameOver()) { m_lastScore = ScoreManager::Instance->GetScore(); SwitchToState(GameOver_State); } else if(m_game->GotoMenu()) { SwitchToState(MainMenu_State); } } else if(m_currentState == GameOver_State) { m_gameOver->Update(); if(m_gameOver->IsDone()) { SwitchToState(MainMenu_State); } } m_renderer->Update(); Time::UpdateDeltaTime(); } }
void StateManager::Update(unsigned long int time, unsigned long int diff, Context& context) { if (m_shutdown) { if (m_pCurrentState != 0) { m_pCurrentState->OnLeave(); } delete m_pCurrentState; m_nextState.clear(); if(m_nextConstructionContext) { delete m_nextConstructionContext; m_nextConstructionContext = 0; } m_pCurrentState = 0; m_Done = true; return; } if (m_nextState.size() != 0) { SwitchToState(m_nextState, context, m_nextConstructionContext); if(m_nextConstructionContext) { delete m_nextConstructionContext; m_nextConstructionContext = 0; } } if (m_pCurrentState) m_pCurrentState->Update(time, diff); }
//----------------------------------------------------------------------------- // Purpose: Check for completion while migrating a session //----------------------------------------------------------------------------- void CSession::UpdateMigrating() { DWORD ret = g_pXboxSystem->GetOverlappedResult( m_hMigrateHandle, NULL, false ); if ( ret == ERROR_IO_INCOMPLETE ) { // Still waiting return; } else { SESSION_STATE nextState = SESSION_STATE_IDLE; // Operation completed SESSION_NOTIFY notification = SESSION_NOTIFY_MIGRATION_COMPLETED; if ( ret != ERROR_SUCCESS ) { Warning( "CSession: MigrateSession failed. Error %d\n", ret ); nextState = SESSION_STATE_NONE; notification = SESSION_NOTIFY_FAIL_MIGRATE; } g_pXboxSystem->ReleaseAsyncHandle( m_hMigrateHandle ); SendNotification( notification ); SwitchToState( nextState ); } }
//--------------------------------------------------------------------- //void CPhantom::Hit (float P, Fvector &dir, CObject* who, s16 element,Fvector p_in_object_space, float impulse, ALife::EHitType hit_type) void CPhantom::Hit (SHit* pHDS) { if (m_TgtState==stFly) SwitchToState(stShoot); if (g_Alive()){ SetfHealth (-1.f); // inherited::Hit (P,dir,who,element,p_in_object_space,impulse/100.f, hit_type); inherited::Hit (pHDS); } }
bool CFSM<T>::Reverse() { bool result = false; if (m_pPrevState != NULL) { SwitchToState(m_pPrevState); result = true; } return result; }
BOOL CPhantom::net_Spawn(CSE_Abstract* DC) { CSE_ALifeCreaturePhantom* OBJ = smart_cast<CSE_ALifeCreaturePhantom*>(DC); VERIFY(OBJ); // select visual at first LPCSTR vis_name = OBJ->get_visual(); if (!(vis_name&&vis_name[0])){ LPCSTR visuals = pSettings->r_string(cNameSect(),"visuals"); u32 cnt = _GetItemCount(visuals); string256 tmp; OBJ->set_visual (_GetItem(visuals,Random.randI(cnt),tmp)); // inform server NET_Packet P; u_EventGen (P, GE_CHANGE_VISUAL, OBJ->ID); P.w_stringZ (tmp); u_EventSend (P); } SwitchToState (stBirth); // initial state (changed on load method in inherited::) // inherited if (!inherited::net_Spawn(DC)) return FALSE; m_enemy = Level().CurrentEntity(); VERIFY (m_enemy); // default init m_fly_particles = 0; SetfHealth (0.001f); // orientate to enemy XFORM().k.sub (m_enemy->Position(),Position()).normalize(); XFORM().j.set (0,1,0); XFORM().i.crossproduct (XFORM().j,XFORM().k); XFORM().k.getHP (vHP.x,vHP.y); // set animation IKinematicsAnimated *K = smart_cast<IKinematicsAnimated*>(Visual()); m_state_data[stBirth].motion = K->ID_Cycle("birth_0"); m_state_data[stFly].motion = K->ID_Cycle("fly_0"); m_state_data[stContact].motion = K->ID_Cycle("contact_0"); m_state_data[stShoot].motion = K->ID_Cycle("shoot_0"); VERIFY(K->LL_GetMotionDef(m_state_data[stBirth].motion)->flags&esmStopAtEnd); VERIFY(K->LL_GetMotionDef(m_state_data[stContact].motion)->flags&esmStopAtEnd); VERIFY(K->LL_GetMotionDef(m_state_data[stShoot].motion)->flags&esmStopAtEnd); // set state SwitchToState_internal(m_TgtState); setVisible (m_CurState>stIdle?TRUE:FALSE); setEnabled (TRUE); return TRUE; }
void GameStateManager::Initialise(void) { m_titleScreen = new TitleScreenState(); m_game = new Game(); // Initialise with start state SwitchToState(startStateID); // Start the timer, for frame rate functions m_FPSTimer.start(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CMatchmaking::SwitchToNewHost() { // Set a timer to wait for the host to contact us m_fWaitTimer = GetTime(); // Get rid of the current host net channel MarkChannelForRemoval( &m_Host.m_adr ); AddRemoteChannel( &m_pNewHost->m_adr ); SwitchToState( MMSTATE_HOSTMIGRATE_WAITINGFORHOST ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CMatchmaking::StartHostMigration() { SwitchToState( MMSTATE_HOSTMIGRATE_STARTINGMIGRATION ); m_pNewHost = SelectNewHost(); if ( m_pNewHost == &m_Local ) { // We're the new host, so start hosting Msg( "Starting new host" ); BeginHosting(); } else { Msg( "Waiting for a new host" ); SwitchToNewHost(); } }
void CPhantom::OnFlyState() { UpdateFlyMedia (); if (g_Alive()){ Fvector vE,vP; m_enemy->Center (vE); Center (vP); if (vP.distance_to_sqr(vE)<_sqr(Radius()+m_enemy->Radius())){ SwitchToState (stContact); // Hit (1000.f,Fvector().set(0,0,1),this,-1,Fvector().set(0,0,0),100.f,ALife::eHitTypeFireWound); float power = 1000.0f; float power_critical = 0.0f; float impulse = 100.0f; SHit HDS(power,power_critical,Fvector().set(0,0,1),this,BI_NONE,Fvector().set(0,0,0),impulse,ALife::eHitTypeFireWound); Hit(&HDS); } } }
//----------------------------------------------------------------------------- // Purpose: Create a new session //----------------------------------------------------------------------------- bool CSession::CreateSession() { if( INVALID_HANDLE_VALUE != m_hSession ) { Warning( "CreateSession called on existing session!" ); DestroySession(); m_hSession = INVALID_HANDLE_VALUE; } uint flags = m_nSessionFlags; if( m_bIsHost ) { flags |= XSESSION_CREATE_HOST; } if ( flags & XSESSION_CREATE_USES_ARBITRATION ) { m_bIsArbitrated = true; } m_hCreateHandle = g_pXboxSystem->CreateAsyncHandle(); // Create the session uint ret = g_pXboxSystem->CreateSession( flags, XBX_GetPrimaryUserId(), m_nPlayerSlots[SLOTS_TOTALPUBLIC], m_nPlayerSlots[SLOTS_TOTALPRIVATE], &m_SessionNonce, &m_SessionInfo, &m_hSession, true, &m_hCreateHandle ); if( ret != ERROR_SUCCESS && ret != ERROR_IO_PENDING ) { Warning( "XSessionCreate failed with error %d\n", ret ); return false; } SwitchToState( SESSION_STATE_CREATING ); return true; }
//----------------------------------------------------------------------------- // Purpose: Migrate the session to a new host //----------------------------------------------------------------------------- bool CSession::MigrateHost() { if ( IsHost() ) { // Migrate call will fill this in for us Q_memcpy( &m_NewSessionInfo, &m_SessionInfo, sizeof( m_NewSessionInfo ) ); } m_hMigrateHandle = g_pXboxSystem->CreateAsyncHandle(); int ret = g_pXboxSystem->SessionMigrate( m_hSession, m_nOwnerId, &m_NewSessionInfo, true, &m_hMigrateHandle ); if ( ret != ERROR_IO_PENDING ) { return false; } SwitchToState( SESSION_STATE_MIGRATING ); return true; }
//----------------------------------------------------------------------------- // Purpose: Reset a session to it's initial state //----------------------------------------------------------------------------- void CSession::ResetSession() { // Cleanup first switch( m_SessionState ) { case SESSION_STATE_CREATING: CancelCreateSession(); break; case SESSION_STATE_MIGRATING: // X360TBD: break; } if ( m_hSession != INVALID_HANDLE_VALUE ) { Msg( "ResetSession: Destroying current session.\n" ); DestroySession(); m_hSession = INVALID_HANDLE_VALUE; } SwitchToState( SESSION_STATE_NONE ); m_bIsHost = false; m_bIsArbitrated = false; m_bUsingQoS = false; m_bIsSystemLink = false; Q_memset( &m_nPlayerSlots, 0, sizeof( m_nPlayerSlots ) ); Q_memset( &m_SessionInfo, 0, sizeof( m_SessionInfo ) ); if ( m_pRegistrationResults ) { delete m_pRegistrationResults; } m_nSessionFlags = 0; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CMatchmaking::BeginHosting() { m_Session.SetIsHost( true ); m_Host = m_Local; // Move into private slots if ( !m_Local.m_bInvited ) { RemovePlayersFromSession( &m_Local ); m_Local.m_bInvited = true; AddPlayersToSession( &m_Local ); } if ( !m_Session.MigrateHost() ) { Warning( "Session migrate failed!\n" ); SessionNotification( SESSION_NOTIFY_FAIL_MIGRATE ); return; } SwitchToState( MMSTATE_HOSTMIGRATE_MIGRATING ); }
void CPhantom::load(IReader &input_packet) { SwitchToState (EState(input_packet.r_s32())); }
//----------------------------------------------------------------------------- // Purpose: Handle a migration message from our new host //----------------------------------------------------------------------------- bool CMatchmaking::ProcessMigrate( MM_Migrate *pMsg ) { MM_Migrate reply; int type = pMsg->m_MsgType; if ( m_CurrentState == MMSTATE_HOSTMIGRATE_WAITINGFORHOST ) { if ( type == MM_Migrate::MESSAGE_HOSTING ) { // Make sure this is the host we were expecting if ( !Q_memcmp( &pMsg->m_xnaddr, &m_Host.m_xnaddr, sizeof( m_Host.m_xnaddr ) ) ) { // Reply to the host reply.m_MsgType = MM_Migrate::MESSAGE_MIGRATED; reply.m_xnaddr = m_Local.m_xnaddr; SendMessage( &reply, &m_Host.m_adr ); XSESSION_INFO info; info.sessionID = pMsg->m_sessionId; info.hostAddress = pMsg->m_xnaddr; info.keyExchangeKey = pMsg->m_key; m_Session.SetNewSessionInfo( &info ); m_Session.SetOwnerId( XUSER_INDEX_NONE ); if ( !m_Session.MigrateHost() ) { Warning( "Session migrate failed!\n" ); SessionNotification( SESSION_NOTIFY_FAIL_MIGRATE ); return true; } SwitchToState( MMSTATE_HOSTMIGRATE_MIGRATING ); } else { // Someone else is trying to host reply.m_MsgType = MM_Migrate::MESSAGE_STANDBY; SendMessage( &reply, &m_Host.m_adr ); } } } else if ( m_CurrentState == MMSTATE_HOSTMIGRATE_WAITINGFORCLIENTS ) { if ( type == MM_Migrate::MESSAGE_MIGRATED ) { // Flag the client as having migrated bool bClientsOutstanding = false; for ( int i = 0; i < m_Remote.Count(); ++i ) { if ( m_Remote[i]->m_id == pMsg->m_Id ) { m_Remote[i]->m_bMigrated = true; } bClientsOutstanding = bClientsOutstanding && m_Remote[i]->m_bMigrated; } if ( !bClientsOutstanding ) { // Everyone's migrated! EndMigration(); } } if ( type == MM_Migrate::MESSAGE_STANDBY ) { // Someone requested a standby --m_nSendCount; } } return true; }