Changeset 2908 for code/branches/questsystem5/src/core/GameState.h
- Timestamp:
- Apr 8, 2009, 12:58:47 AM (16 years ago)
- Location:
- code/branches/questsystem5
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem5
- Property svn:mergeinfo changed
-
code/branches/questsystem5/src/core/GameState.h
r2907 r2908 39 39 40 40 #include <string> 41 #include <vector> 41 42 #include <map> 42 #include "CorePrereqs.h" 43 #include <cassert> 44 #include "Clock.h" 43 45 44 46 namespace orxonox … … 58 60 Then Bar stores Foo in map by its name. The other one then maps Foo to Foofoo. 59 61 */ 60 class _CoreExport GameState 62 class _CoreExport GameStateBase 61 63 { 62 friend class Game; 64 friend class RootGameState; 65 template <class ParentType> 66 friend class GameState; 63 67 64 68 public: … … 67 71 Gives information about what the GameState is currently doing 68 72 */ 69 struct State73 struct Operations 70 74 { 71 unsigned active : 1; 72 unsigned activating : 1; 73 unsigned deactivating : 1; 74 unsigned updating : 1; 75 unsigned suspended : 1; 76 unsigned topState : 1; 75 unsigned active : 1; 76 unsigned entering : 1; 77 unsigned leaving : 1; 78 unsigned running : 1; 79 unsigned suspended : 1; 77 80 }; 78 81 79 82 public: 80 GameState(const std::string& name); 81 virtual ~GameState(); 83 virtual ~GameStateBase(); 82 84 83 85 const std::string& getName() const { return name_; } 84 State getActivity() const { return this->activity_; }85 GameState* getParent() const { return this->parent_; }86 const Operations getOperation() const { return this->operation_; } 87 bool isInSubtree(GameStateBase* state) const; 86 88 87 void addChild(GameState* state); 88 void removeChild(GameState* state); 89 GameStateBase* getState(const std::string& name); 90 GameStateBase* getRoot(); 91 //! Returns the currently active game state 92 virtual GameStateBase* getCurrentState(); 93 94 virtual void requestState(const std::string& name); 95 96 void addChild(GameStateBase* state); 97 void removeChild(GameStateBase* state); 98 void removeChild(const std::string& name); 89 99 90 100 protected: 91 virtual void activate() = 0; 92 virtual void deactivate() = 0; 93 virtual void update(const Clock& time) = 0; 101 virtual void enter() = 0; 102 virtual void leave() = 0; 103 virtual void ticked(const Clock& time) = 0; 104 105 GameStateBase* getActiveChild() { return this->activeChild_; } 106 107 void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); } 108 109 virtual GameStateBase* getParent() const = 0; 110 virtual void setParent(GameStateBase* state) = 0; 94 111 95 112 private: 96 void setParent(GameState* state) { this->parent_ = state; } 97 void setActivity(State activity); 98 void activateInternal(); 99 void deactivateInternal(); 100 void updateInternal(const Clock& time); 113 // Making the constructor private ensures that game states 114 // are always derivates of GameState<T>. Note the friend declaration above. 115 GameStateBase(const std::string& name); 116 117 //! Performs a transition to 'destination' 118 virtual void makeTransition(GameStateBase* source, GameStateBase* destination); 119 120 void grandchildAdded(GameStateBase* child, GameStateBase* grandchild); 121 void grandchildRemoved(GameStateBase* grandchild); 122 123 void tick(const Clock& time); 124 void activate(); 125 void deactivate(); 101 126 102 127 const std::string name_; 103 State activity_; 104 GameState* parent_; 105 std::map<std::string, GameState*> children_; 128 Operations operation_; 129 GameStateBase* activeChild_; 130 //bool bPauseParent_; 131 std::map<std::string, GameStateBase*> allChildren_; 132 std::map<GameStateBase*, GameStateBase*> grandchildrenToChildren_; 133 }; 134 135 136 template <class ParentType> 137 class GameState : public GameStateBase 138 { 139 public: 140 GameState(const std::string& name) 141 : GameStateBase(name) 142 , parent_(0) 143 { } 144 virtual ~GameState() { } 145 146 ParentType* getParent() const 147 { return parent_; } 148 149 protected: 150 void setParent(GameStateBase* state) 151 { 152 assert(dynamic_cast<ParentType*>(state) != 0); 153 this->parent_ = dynamic_cast<ParentType*>(state); 154 } 155 156 private: 157 ParentType* parent_; 106 158 }; 107 159 }
Note: See TracChangeset
for help on using the changeset viewer.