Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed N5110 ShiftReg PinDetect
StateManger.cpp
- Committer:
- Siriagus
- Date:
- 2015-05-02
- Revision:
- 8:9ac6a428fa26
- Parent:
- 7:678873947b29
- Child:
- 10:f2488a0ecab7
File content as of revision 8:9ac6a428fa26:
#include "StateManager.h" // Delete the old state and create a new one void StateManager::changeState(MainState newState) { if (currentState != 0) // if a state exist delete currentState; // delete the old state // Create new state switch (newState) { case MAIN_MENU: currentState = new MainMenu(this, lcd, input); break; case GAME: currentState = new Game(this, lcd, input); break; case TITLE_SCREEN: currentState = new TitleScreen(this, lcd, input); break; // TODO: Make classes for the other states. case SUBMIT_HIGHSCORE: //break; case GAME_OVER: //break; default: error("Invalid state!"); } } void StateManager::requestStateChange(MainState requestedState) { if (nextState != NO_STATE) error("Invalid - can't request new state before the first request has been processed!"); nextState = requestedState; } void StateManager::update(float dt) { currentState->update(dt); } void StateManager::render() { currentState->render(); } void StateManager::processRequest() { // Check if there has been a request to change the state if (nextState != NO_STATE) { changeState(nextState); nextState = NO_STATE; // reset, state has been changed } }