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
StateManager.h@17:d6a3b29cab31, 2015-05-11 (annotated)
- Committer:
- Siriagus
- Date:
- Mon May 11 03:52:18 2015 +0000
- Revision:
- 17:d6a3b29cab31
- Parent:
- 10:f2488a0ecab7
Added sound effects ++
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Siriagus | 4:d6661b976359 | 1 | #ifndef STATE_MANAGER_H |
| Siriagus | 4:d6661b976359 | 2 | #define STATE_MANAGER_H |
| Siriagus | 4:d6661b976359 | 3 | |
| Siriagus | 4:d6661b976359 | 4 | #include "State.h" |
| Siriagus | 5:100d960fc6d5 | 5 | #include "MainMenu.h" |
| Siriagus | 7:678873947b29 | 6 | #include "Game.h" |
| Siriagus | 8:9ac6a428fa26 | 7 | #include "TitleScreen.h" |
| Siriagus | 17:d6a3b29cab31 | 8 | #include "GameOver.h" |
| Siriagus | 17:d6a3b29cab31 | 9 | #include "SubmitHighscore.h" |
| Siriagus | 4:d6661b976359 | 10 | |
| Siriagus | 10:f2488a0ecab7 | 11 | /** @file StateManager.h |
| Siriagus | 10:f2488a0ecab7 | 12 | * @author Andreas Garmannslund |
| Siriagus | 10:f2488a0ecab7 | 13 | * @date April 2015 |
| Siriagus | 10:f2488a0ecab7 | 14 | */ |
| Siriagus | 10:f2488a0ecab7 | 15 | |
| Siriagus | 10:f2488a0ecab7 | 16 | /// Finite State Machine for program flow |
| Siriagus | 4:d6661b976359 | 17 | class StateManager |
| Siriagus | 4:d6661b976359 | 18 | { |
| Siriagus | 4:d6661b976359 | 19 | public: |
| Siriagus | 10:f2488a0ecab7 | 20 | /** Creates a new finite state machine. The states are defined in State.h |
| Siriagus | 10:f2488a0ecab7 | 21 | * @param lcd Pointer to the lcd |
| Siriagus | 10:f2488a0ecab7 | 22 | * @param input Pointer to the InputManager which is controlling user input. |
| Siriagus | 10:f2488a0ecab7 | 23 | * @param firstState The initial state of the finite state machine. |
| Siriagus | 10:f2488a0ecab7 | 24 | */ |
| Siriagus | 17:d6a3b29cab31 | 25 | StateManager(N5110 *lcd, InputManager* input, Sound *sound, MainState firstState) |
| Siriagus | 17:d6a3b29cab31 | 26 | : lcd(lcd), input(input), sound(sound) {currentState = 0; nextState = NO_STATE; changeState(firstState);} |
| Siriagus | 10:f2488a0ecab7 | 27 | |
| Siriagus | 10:f2488a0ecab7 | 28 | /// Frees allocated memory |
| Siriagus | 5:100d960fc6d5 | 29 | ~StateManager() {if (currentState != 0) delete currentState;} |
| Siriagus | 4:d6661b976359 | 30 | |
| Siriagus | 10:f2488a0ecab7 | 31 | /// Update logic of the current state |
| Siriagus | 7:678873947b29 | 32 | void update(float dt); |
| Siriagus | 10:f2488a0ecab7 | 33 | |
| Siriagus | 10:f2488a0ecab7 | 34 | /// Draw the current state to the lcd |
| Siriagus | 4:d6661b976359 | 35 | void render(); |
| Siriagus | 4:d6661b976359 | 36 | |
| Siriagus | 10:f2488a0ecab7 | 37 | /** Can be used to request the fsm to switch state. |
| Siriagus | 10:f2488a0ecab7 | 38 | * @param newState The requested state |
| Siriagus | 10:f2488a0ecab7 | 39 | */ |
| Siriagus | 7:678873947b29 | 40 | void requestStateChange(MainState newState); |
| Siriagus | 7:678873947b29 | 41 | |
| Siriagus | 10:f2488a0ecab7 | 42 | /// Sees if any requests to change the state have been made |
| Siriagus | 10:f2488a0ecab7 | 43 | void processRequest(); |
| Siriagus | 7:678873947b29 | 44 | |
| Siriagus | 7:678873947b29 | 45 | private: |
| Siriagus | 10:f2488a0ecab7 | 46 | /** Deletes the current state and create a new one |
| Siriagus | 10:f2488a0ecab7 | 47 | * @param newState The state which the finite state machine switches to |
| Siriagus | 10:f2488a0ecab7 | 48 | */ |
| Siriagus | 10:f2488a0ecab7 | 49 | void changeState(MainState newState); |
| Siriagus | 7:678873947b29 | 50 | |
| Siriagus | 10:f2488a0ecab7 | 51 | // Variables |
| Siriagus | 4:d6661b976359 | 52 | private: |
| Siriagus | 4:d6661b976359 | 53 | N5110 *lcd; |
| Siriagus | 4:d6661b976359 | 54 | InputManager *input; |
| Siriagus | 17:d6a3b29cab31 | 55 | Sound *sound; |
| Siriagus | 4:d6661b976359 | 56 | State* currentState; // Current state object |
| Siriagus | 10:f2488a0ecab7 | 57 | MainState nextState; // requested state, NONE if no state is requested |
| Siriagus | 4:d6661b976359 | 58 | }; |
| Siriagus | 4:d6661b976359 | 59 | |
| Siriagus | 5:100d960fc6d5 | 60 | #endif |