00001 #ifndef HEADER_GAMESTATE_H 00002 #define HEADER_GAMESTATE_H 00003 00004 class StateManager; 00005 class InputHandler; 00006 class InputProvider; 00007 class MultiDrawer; 00008 class Drawable; 00009 00010 #include "NoCopy.h" 00011 #include "BaseListener.h" 00012 00013 /** 00014 * Game state. 00015 * GameState installs own InputHandler in init phase. 00016 * 00017 * To change state, 00018 * use m_manager->pushState(topState) or 00019 * m_manager->changeState(newState) 00020 */ 00021 class GameState : public BaseListener, public NoCopy { 00022 private: 00023 bool m_active; 00024 bool m_onBg; 00025 GameState *m_nextState; 00026 InputHandler *m_handler; 00027 MultiDrawer *m_drawer; 00028 StateManager *m_manager; 00029 protected: 00030 void takeHandler(InputHandler *new_handler); 00031 const InputProvider *getInput(); 00032 00033 virtual void own_initState() = 0; 00034 virtual void own_updateState() = 0; 00035 virtual void own_pauseState() = 0; 00036 virtual void own_resumeState() = 0; 00037 virtual void own_cleanState() = 0; 00038 00039 virtual void own_noteBg() {} 00040 virtual void own_noteFg() {} 00041 00042 void changeState(GameState *new_state); 00043 void registerDrawable(Drawable *drawable); 00044 void deregisterDrawable(const Drawable *drawable); 00045 public: 00046 GameState(); 00047 virtual ~GameState(); 00048 virtual bool allowBg() const { return false; } 00049 bool isRunning() const { return m_active; } 00050 bool isOnBg() const { return m_onBg; } 00051 void setNextState(GameState *nextState) { m_nextState = nextState; } 00052 00053 void initState(StateManager *manager); 00054 void updateState(); 00055 void pauseState(); 00056 void resumeState(); 00057 void cleanState(); 00058 00059 void quitState(); 00060 void pushState(GameState *new_state); 00061 00062 void noteBg(); 00063 void noteFg(); 00064 void installHandlers(); 00065 void unHandlers(); 00066 00067 void receiveSimple(const SimpleMsg *msg); 00068 }; 00069 00070 #endif