Changeset 1689 for code/branches/gui/src/core/GameState.h
- Timestamp:
- Aug 31, 2008, 6:07:57 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/GameState.h
r1688 r1689 61 61 Then Bar stores Foo in map by its name. The other one then maps Foo to Foofoo. 62 62 */ 63 class _CoreExport GameState 63 class _CoreExport GameStateBase 64 64 { 65 65 friend class RootGameState; 66 66 template <class ParentType> 67 friend class GameState Typed;67 friend class GameState; 68 68 69 69 public: … … 82 82 83 83 public: 84 virtual ~GameState ();84 virtual ~GameStateBase(); 85 85 86 86 const std::string& getName() const { return name_; } 87 87 const Operations getOperation() const { return this->operation_; } 88 bool isInSubtree(GameState * state) const;88 bool isInSubtree(GameStateBase* state) const; 89 89 90 GameState * getState(const std::string& name);91 GameState * getRoot();90 GameStateBase* getState(const std::string& name); 91 GameStateBase* getRoot(); 92 92 //! Returns the currently active game state 93 virtual GameState * getCurrentState();93 virtual GameStateBase* getCurrentState(); 94 94 95 95 virtual void requestState(const std::string& name); 96 96 97 void addChild(GameState * state);98 void removeChild(GameState * state);97 void addChild(GameStateBase* state); 98 void removeChild(GameStateBase* state); 99 99 void removeChild(const std::string& name); 100 100 … … 104 104 virtual void ticked(const Clock& time) = 0; 105 105 106 GameState * getActiveChild() { return this->activeChild_; }106 GameStateBase* getActiveChild() { return this->activeChild_; } 107 107 108 108 void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); } 109 109 110 virtual GameState * getParent() const = 0;111 virtual void setParent(GameState * state) = 0;110 virtual GameStateBase* getParent() const = 0; 111 virtual void setParent(GameStateBase* state) = 0; 112 112 113 113 private: 114 114 // Making the constructor private ensures that game states 115 // are always derivates of GameState Typed<T>. Note the friend declaration above.116 GameState (const std::string& name);115 // are always derivates of GameState<T>. Note the friend declaration above. 116 GameStateBase(const std::string& name); 117 117 118 118 //! Performs a transition to 'destination' 119 virtual void makeTransition(GameState * source, GameState* destination);119 virtual void makeTransition(GameStateBase* source, GameStateBase* destination); 120 120 121 void grandchildAdded(GameState * child, GameState* grandchild);122 void grandchildRemoved(GameState * grandchild);121 void grandchildAdded(GameStateBase* child, GameStateBase* grandchild); 122 void grandchildRemoved(GameStateBase* grandchild); 123 123 124 124 void tick(const Clock& time); … … 126 126 void deactivate(); 127 127 128 const std::string name_;129 Operations operation_;130 GameState *activeChild_;131 //bool bPauseParent_;132 std::map<std::string, GameState *>allChildren_;133 std::map<GameState *, GameState*>grandchildrenToChildren_;128 const std::string name_; 129 Operations operation_; 130 GameStateBase* activeChild_; 131 //bool bPauseParent_; 132 std::map<std::string, GameStateBase*> allChildren_; 133 std::map<GameStateBase*, GameStateBase*> grandchildrenToChildren_; 134 134 }; 135 135 136 136 137 template <class ParentType> 137 class GameState Typed : public GameState138 class GameState : public GameStateBase 138 139 { 139 140 public: 140 GameState Typed(const std::string& name) : GameState(name) { }141 virtual ~GameState Typed() { }141 GameState(const std::string& name) : GameStateBase(name) { } 142 virtual ~GameState() { } 142 143 143 144 ParentType* getParent() const … … 145 146 146 147 protected: 147 void setParent(GameState * state)148 void setParent(GameStateBase* state) 148 149 { 149 150 assert(dynamic_cast<ParentType*>(state) != 0);
Note: See TracChangeset
for help on using the changeset viewer.