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