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: N5110 PinDetect PowerControl mbed
Diff: StateManger.cpp
- Revision:
- 7:678873947b29
- Parent:
- 5:100d960fc6d5
- Child:
- 8:9ac6a428fa26
diff -r edb48de563a9 -r 678873947b29 StateManger.cpp
--- a/StateManger.cpp Fri May 01 09:44:38 2015 +0000
+++ b/StateManger.cpp Fri May 01 18:10:59 2015 +0000
@@ -5,7 +5,7 @@
{
if (currentState != 0) // if a state exist
delete currentState; // delete the old state
-
+
// Create new state
switch (newState)
{
@@ -13,10 +13,11 @@
currentState = new MainMenu(this, lcd, input);
break;
- // TODO: Make classes for the other states, currently all than MAIN_MENU will give error
case GAME:
- //break;
+ currentState = new Game(this, lcd, input);
+ break;
+ // TODO: Make classes for the other states.
case SUBMIT_HIGHSCORE:
//break;
@@ -28,12 +29,30 @@
}
}
-void StateManager::update(time_t dt)
+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
+ }
}
\ No newline at end of file