예제 #1
0
  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;
  }
예제 #2
0
  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);
      }
    }
  }
예제 #3
0
  void StateManager::cleanup(void)
  {
    // Always call our cleanup events with our pointer when this method is called
    mCleanupEvents.doEvents();

    // Remove one of our dead states
    if(!mDead.empty())
    {
      // Retrieve the dead state
      IState* anState = mDead.back();
      assert(NULL != anState && "StateManager::handleCleanup() invalid dropped state pointer");

      // Pop the dead state off the stack
      mDead.pop_back();

      // Call the DeInit if it hasn't been called yet
      if(anState->isInitComplete())
      {
        anState->deInit();
      }

      // Handle the cleanup before we delete anState
      anState->cleanup();

      // Just delete the state now
      delete anState;

      // Don't keep pointers around we don't need
      anState = NULL;
    }

    // Make sure we still have an active state
    if(NULL == mStack.back())
    {
      // There are no states on the stack, exit the program
      if(NULL != mApp)
      {
        mApp->quit(StatusAppOK);
      }
    }
  }
예제 #4
0
  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);
      }
    }
  }