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-11
- Revision:
- 17:d6a3b29cab31
- Parent:
- 10:f2488a0ecab7
- Child:
- 19:89c3eeb3761b
File content as of revision 17:d6a3b29cab31:
#include "StateManager.h"
/// @file StateManager.cpp
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, sound);
break;
case GAME:
currentState = new Game(this, lcd, input, sound);
break;
case TITLE_SCREEN:
currentState = new TitleScreen(this, lcd, input, sound);
break;
case SUBMIT_HIGHSCORE:
currentState = new SubmitHighscore(this, lcd, input, sound);
break;
case GAME_OVER:
currentState = new GameOver(this, lcd, input, sound);
break;
default:
; // error: this shouldn't happen
}
}
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
}
}