// State control funcs void CStateModule::Switch_State( DC_ID StateID ) { if( StateID <= DC_INVALID_ID ) { Log(LOG_STATE, "Invalid State ID to Switch_State(): %d\n", StateID); return; } // Get the State obj CState* pNewState = Create_State( StateID ); if( !pNewState ) { Log(LOG_STATE, "Could not create State: %d\n", StateID); return; } DLog(LOG_STATE, "Switching to State: %d\n", StateID); // If we have a current State, stop it CState* pCurState = Get_Current_State(); if( pCurState ) { pCurState->Stop(); // Pop it from the stack m_StateStack.pop_back(); // Delete the State obj delete pCurState; } // Push the new State on top m_StateStack.push_back( pNewState ); // Start the new State pNewState->Start(); }
void CStateModule::Pop_State() { // Get the State obj CState* pCurState = Get_Current_State(); if( !pCurState ) { Log(LOG_STATE, "No current state to pop in Pop_State()\n"); return; } DLog(LOG_STATE, "Popping State %d\n", pCurState->GetStateID()); // Stop the current State pCurState->Stop(); // Pop it from the stack and delete m_StateStack.pop_back(); delete pCurState; // Get the new current State pCurState = Get_Current_State(); // Resume it pCurState->Resume(); }