StateManager::~StateManager() { ILOGM("StateManager::dtor()"); // Drop all active states while(!mStack.empty()) { // Retrieve the currently active state IState* anState = mStack.back(); // Pop the currently active state off the stack mStack.pop_back(); // Pause the currently active state anState->pause(); // De-initialize the state anState->deInit(); // Handle the cleanup before we pop it off the stack anState->cleanup(); // Just delete the state now delete anState; // Don't keep pointers around we don't need anState = NULL; } // Delete all our dropped states while(!mDead.empty()) { // Retrieve the currently active state IState* anState = mDead.back(); // Pop the currently active state off the stack mDead.pop_back(); // Pause the currently active state anState->pause(); // De-initialize the state anState->deInit(); // Handle the cleanup before we pop it off the stack anState->cleanup(); // Just delete the state now delete anState; // Don't keep pointers around we don't need anState = NULL; } // Clear pointers we don't need anymore mApp = NULL; }
void StateManager::resetActiveState(void) { // Is there no currently active state to reset? if(!mStack.empty()) { // Retrieve the currently active state IState* anState = mStack.back(); // Log the resetting of an active state ILOG() << "StateManager::resetActiveState(" << anState->getID() << ")" << std::endl; // Pause the currently active state anState->pause(); // Call the ReInit method to Reset the currently active state anState->reInit(); // Resume the currently active state anState->resume(); // Don't keep pointers around we don't need anymore anState = NULL; } else { // Quit the application with an error status response if(NULL != mApp) { mApp->quit(StatusAppStackEmpty); } return; } }
void StateManager::removeActiveState(void) { // Is there no currently active state to drop? if(!mStack.empty()) { // Retrieve the currently active state IState* anState = mStack.back(); // Log the removing of an active state ILOG() << "StateManager::removeActiveState(" << anState->getID() << ")" << std::endl; // Pause the currently active state anState->pause(); // Deinitialize the currently active state before we pop it off the stack anState->deInit(); // Pop the currently active state off the stack mStack.pop_back(); // Move this state to our dropped stack mDead.push_back(anState); // Don't keep pointers around we don't need anymore anState = NULL; } else { // Quit the application with an error status response if(NULL != mApp) { mApp->quit(StatusAppStackEmpty); } return; } // Is there another state to activate? then call Resume to activate it if(!mStack.empty()) { // Has this state ever been initialized? if(mStack.back()->isInitComplete()) { // Resume the new active state mStack.back()->resume(); } else { // Initialize the new active state mStack.back()->doInit(); } } else { // There are no states on the stack, exit the program if(NULL != mApp) { mApp->quit(StatusAppOK); } } }
void StateManager::dropActiveState(void) { // Is there no currently active state to drop? if(!mStack.empty()) { // Retrieve the currently active state IState* anState = mStack.back(); // Log the dropping of an active state ILOG() << "StateManager::dropActiveState(" << anState->getID() << ")" << std::endl; // Pause the currently active state anState->pause(); // Deinit currently active state before we pop it off the stack // (handleCleanup() will be called by IState::doInit() method if this // state is ever set active again) anState->deInit(); // Pop the currently active state off the stack mStack.pop_back(); // Move this now inactive state to the absolute back of our stack mStack.insert(mStack.begin(), anState); // Don't keep pointers around we don't need anymore anState = NULL; } else { // Quit the application with an error status response if(NULL != mApp) { mApp->quit(StatusAppStackEmpty); } return; } // Is there another state to activate? then call Resume to activate it if(!mStack.empty()) { // Has this state ever been initialized? if(mStack.back()->isInitComplete()) { // Resume the new active state mStack.back()->resume(); } else { // Initialize the new active state mStack.back()->doInit(); } } else { // There are no states on the stack, exit the program if(NULL != mApp) { mApp->quit(StatusAppOK); } } }