Changeset 1688 for code/branches/gui/src/core
- Timestamp:
- Aug 31, 2008, 5:50:42 PM (16 years ago)
- Location:
- code/branches/gui/src/core
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/CorePrereqs.h
r1674 r1688 163 163 // game states 164 164 class GameState; 165 template <class ParentType> 166 class GameStateTyped; 165 167 class RootGameState; 166 168 -
code/branches/gui/src/core/GameState.cc
r1674 r1688 45 45 GameState::GameState(const std::string& name) 46 46 : name_(name) 47 , parent_(0)47 //, parent_(0) 48 48 , activeChild_(0) 49 //, bPause Parent_(false)49 //, bPausegetParent()(false) 50 50 { 51 51 Operations temp = {false, false, false, false, false}; … … 103 103 104 104 // mark us as parent 105 state-> parent_ = this;105 state->setParent(this); 106 106 } 107 107 … … 178 178 this->allChildren_[grandchild->getName()] = grandchild; 179 179 this->grandchildrenToChildren_[grandchild] = child; 180 if (this-> parent_)181 this-> parent_->grandchildAdded(this, grandchild);180 if (this->getParent()) 181 this->getParent()->grandchildAdded(this, grandchild); 182 182 } 183 183 … … 196 196 this->allChildren_.erase(grandchild->getName()); 197 197 this->grandchildrenToChildren_.erase(grandchild); 198 if (this-> parent_)199 this-> parent_->grandchildRemoved(grandchild);198 if (this->getParent()) 199 this->getParent()->grandchildRemoved(grandchild); 200 200 } 201 201 … … 208 208 GameState* GameState::getState(const std::string& name) 209 209 { 210 if (this-> parent_)211 return this-> parent_->getState(name);210 if (this->getParent()) 211 return this->getParent()->getState(name); 212 212 else 213 213 { … … 227 227 GameState* GameState::getRoot() 228 228 { 229 if (this-> parent_)230 return this-> parent_->getRoot();229 if (this->getParent()) 230 return this->getParent()->getRoot(); 231 231 else 232 232 return this; -
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 -
code/branches/gui/src/core/RootGameState.cc
r1674 r1688 39 39 40 40 RootGameState::RootGameState(const std::string& name) 41 : GameState (name)41 : GameStateTyped<GameState>(name) 42 42 , stateRequest_("") 43 43 { -
code/branches/gui/src/core/RootGameState.h
r1674 r1688 35 35 namespace orxonox 36 36 { 37 class _CoreExport RootGameState : public GameState 37 class _CoreExport RootGameState : public GameStateTyped<GameState> 38 38 { 39 39 public:
Note: See TracChangeset
for help on using the changeset viewer.