bool GameStateManager::update(const GameData& _data) { bool success = false; //if there is a state if (activeState()) { //allow states to request program end (returning false) success = activeState()->update(_data); executeActionQueue(); } return success; }
//TODO: this destroys the stack if you try to pop to a state not in it, should just use a list instead of a stack void StateManager::popToState(GameState *state) { while (state != activeState()) { if (_states.empty()) { throw std::runtime_error("Can't pop to state not in the stack."); } else { popState(); } } }
void StateManager::popState() { GameState *topState = activeState(); topState->becomeInactive(); _states.pop(); if (!_states.empty()) { _states.top()->becomeActive(); } lcl_log(lcl_cState, lcl_vTrace, "Popped a state: %ld left", _states.size()); }