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
Diff: StateManager.h
- Revision:
- 10:f2488a0ecab7
- Parent:
- 8:9ac6a428fa26
- Child:
- 17:d6a3b29cab31
--- a/StateManager.h Sun May 03 11:48:42 2015 +0000 +++ b/StateManager.h Fri May 08 14:39:36 2015 +0000 @@ -6,30 +6,52 @@ #include "Game.h" #include "TitleScreen.h" -// Main Finite State Machine - controls the flow between the main states +/** @file StateManager.h +* @author Andreas Garmannslund +* @date April 2015 +*/ + +/// Finite State Machine for program flow class StateManager { public: + /** Creates a new finite state machine. The states are defined in State.h + * @param lcd Pointer to the lcd + * @param input Pointer to the InputManager which is controlling user input. + * @param firstState The initial state of the finite state machine. + */ StateManager(N5110 *lcd, InputManager* input, MainState firstState) : lcd(lcd), input(input){currentState = 0; nextState = NO_STATE; changeState(firstState);} + + /// Frees allocated memory ~StateManager() {if (currentState != 0) delete currentState;} + /// Update logic of the current state void update(float dt); + + /// Draw the current state to the lcd void render(); + /** Can be used to request the fsm to switch state. + * @param newState The requested state + */ void requestStateChange(MainState newState); - void processRequest(); // See if any request to change the state have been made + /// Sees if any requests to change the state have been made + void processRequest(); private: - void changeState(MainState newState); // Deletes the current main state and creates a new one + /** Deletes the current state and create a new one + * @param newState The state which the finite state machine switches to + */ + void changeState(MainState newState); - // Variables + // Variables private: N5110 *lcd; InputManager *input; State* currentState; // Current state object - MainState nextState; + MainState nextState; // requested state, NONE if no state is requested }; #endif \ No newline at end of file