Hugo Hu / Mbed 2 deprecated BRAVEHEART

Dependencies:   mbed N5110 ShiftReg PinDetect

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers StateManager.h Source File

StateManager.h

Go to the documentation of this file.
00001 #ifndef STATE_MANAGER_H
00002 #define STATE_MANAGER_H
00003 
00004 #include "State.h "
00005 #include "MainMenu.h "
00006 #include "Game.h "
00007 #include "CoverPage.h "
00008 #include "GameOver.h "
00009 #include "Achievement.h "
00010 
00011 /** @file StateManager.h
00012 * @author Andreas Garmannslund
00013 * @date April 2015
00014 */
00015 
00016 /// Finite State Machine for program flow
00017 class StateManager
00018 {
00019     public:
00020         /** Creates a new finite state machine. The states are defined in State.h
00021         * @param lcd Pointer to the lcd
00022         * @param input Pointer to the InputManager which is controlling user input.
00023         * @param firstState The initial state of the finite state machine.
00024         */
00025         StateManager(N5110 *lcd, InputManager* input, Sound *sound, ShiftReg *shiftreg, MainState firstState)
00026                     : lcd(lcd),  input(input), sound(sound), shiftreg(shiftreg) {currentState = 0; nextState = NO_STATE; changeState(firstState);}
00027                     
00028         /// Frees allocated memory
00029         ~StateManager() {if (currentState != 0) delete currentState;}
00030         
00031         /// Update logic of the current state
00032         void update(float dt);
00033         
00034         /// Draw the current state to the lcd
00035         void render();
00036         
00037         /** Can be used to request the fsm to switch state.
00038         * @param newState The requested state
00039         */
00040         void requestStateChange(MainState newState);
00041         
00042         /// Sees if any requests to change the state have been made
00043         void processRequest();
00044         
00045     private:
00046         /** Deletes the current state and create a new one
00047         * @param newState The state which the finite state machine switches to
00048         */
00049         void changeState(MainState newState);
00050     
00051     // Variables
00052     private:
00053         N5110 *lcd;
00054         InputManager *input;
00055         Sound *sound;
00056         ShiftReg *shiftreg;
00057         State* currentState; // Current state object
00058         MainState nextState; // requested state, NONE if no state is requested
00059 };
00060 
00061 #endif