Changeset 2896 for code/trunk/src/core/GameState.h
- Timestamp:
- Apr 6, 2009, 1:59:00 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/gui merged: 2796,2798-2801,2805,2807-2808,2811,2814-2817,2834,2840-2850,2853-2854,2859,2862-2863,2869,2875,2887,2892
- Property svn:mergeinfo changed
-
code/trunk/src/core/GameState.h
r1755 r2896 39 39 40 40 #include <string> 41 #include <vector>42 41 #include <map> 43 #include <cassert> 44 #include "Clock.h" 42 #include "CorePrereqs.h" 45 43 46 44 namespace orxonox … … 60 58 Then Bar stores Foo in map by its name. The other one then maps Foo to Foofoo. 61 59 */ 62 class _CoreExport GameState Base60 class _CoreExport GameState 63 61 { 64 friend class RootGameState; 65 template <class ParentType> 66 friend class GameState; 62 friend class Game; 67 63 68 64 public: … … 71 67 Gives information about what the GameState is currently doing 72 68 */ 73 struct Operations69 struct State 74 70 { 75 unsigned active : 1; 76 unsigned entering : 1; 77 unsigned leaving : 1; 78 unsigned running : 1; 79 unsigned suspended : 1; 71 unsigned active : 1; 72 unsigned activating : 1; 73 unsigned deactivating : 1; 74 unsigned updating : 1; 75 unsigned suspended : 1; 76 unsigned topState : 1; 80 77 }; 81 78 82 79 public: 83 virtual ~GameStateBase(); 80 GameState(const std::string& name); 81 virtual ~GameState(); 84 82 85 83 const std::string& getName() const { return name_; } 86 const Operations getOperation() const { return this->operation_; }87 bool isInSubtree(GameStateBase* state) const;84 State getActivity() const { return this->activity_; } 85 GameState* getParent() const { return this->parent_; } 88 86 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); 87 void addChild(GameState* state); 88 void removeChild(GameState* state); 99 89 100 90 protected: 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; 91 virtual void activate() = 0; 92 virtual void deactivate() = 0; 93 virtual void update(const Clock& time) = 0; 111 94 112 95 private: 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(); 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); 126 101 127 102 const std::string name_; 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_; 103 State activity_; 104 GameState* parent_; 105 std::map<std::string, GameState*> children_; 158 106 }; 159 107 }
Note: See TracChangeset
for help on using the changeset viewer.