Changeset 1688 for code/branches/gui/src/core/GameState.h
- Timestamp:
- Aug 31, 2008, 5:50:42 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/GameState.h
r1686 r1688 41 41 #include <vector> 42 42 #include <map> 43 #include <cassert> 43 44 #include "util/Integers.h" 44 45 #include "Clock.h" … … 63 64 { 64 65 friend class RootGameState; 66 template <class ParentType> 67 friend class GameStateTyped; 65 68 66 69 public: … … 79 82 80 83 public: 81 GameState(const std::string& name);82 84 virtual ~GameState(); 83 85 … … 88 90 GameState* getState(const std::string& name); 89 91 GameState* getRoot(); 90 GameState* getParent() const { return this->parent_; }91 92 //! Returns the currently active game state 92 93 virtual GameState* getCurrentState(); … … 107 108 void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); } 108 109 110 virtual GameState* getParent() const = 0; 111 virtual void setParent(GameState* state) = 0; 112 109 113 private: 114 // Making the constructor private ensures that game states 115 // are always derivates of GameStateTyped<T>. Note the friend declaration above. 116 GameState(const std::string& name); 117 110 118 //! Performs a transition to 'destination' 111 119 virtual void makeTransition(GameState* source, GameState* destination); … … 120 128 const std::string name_; 121 129 Operations operation_; 122 GameState* parent_;123 130 GameState* activeChild_; 124 131 //bool bPauseParent_; … … 126 133 std::map<GameState*, GameState*> grandchildrenToChildren_; 127 134 }; 135 136 template <class ParentType> 137 class GameStateTyped : public GameState 138 { 139 public: 140 GameStateTyped(const std::string& name) : GameState(name) { } 141 virtual ~GameStateTyped() { } 142 143 ParentType* getParent() const 144 { return parent_; } 145 146 protected: 147 void setParent(GameState* state) 148 { 149 assert(dynamic_cast<ParentType*>(state) != 0); 150 this->parent_ = dynamic_cast<ParentType*>(state); 151 } 152 153 private: 154 ParentType* parent_; 155 }; 128 156 } 129 157
Note: See TracChangeset
for help on using the changeset viewer.