Changeset 3363 for code/branches/resource/src/core/Game.h
- Timestamp:
- Jul 29, 2009, 5:24:39 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource/src/core/Game.h
r3356 r3363 44 44 #include <vector> 45 45 #include <boost/shared_ptr.hpp> 46 #include <boost/scoped_ptr.hpp> 46 47 #include <boost/preprocessor/cat.hpp> 47 48 … … 59 60 { 60 61 class GameConfiguration; 62 using boost::scoped_ptr; 63 using boost::shared_ptr; 61 64 62 65 //! Helper object required before GameStates are being constructed … … 75 78 class _CoreExport Game 76 79 { 80 typedef std::vector<shared_ptr<GameState> > GameStateVector; 81 typedef std::map<std::string, shared_ptr<GameState> > GameStateMap; 77 82 typedef boost::shared_ptr<GameStateTreeNode> GameStateTreeNodePtr; 78 83 public: … … 81 86 82 87 void setStateHierarchy(const std::string& str); 83 GameState*getState(const std::string& name);88 shared_ptr<GameState> getState(const std::string& name); 84 89 85 90 void run(); … … 106 111 public: 107 112 virtual ~GameStateFactory() { } 108 static GameState*fabricate(const GameStateInfo& info);113 static shared_ptr<GameState> fabricate(const GameStateInfo& info); 109 114 template <class T> 110 115 static void createFactory(const std::string& className) 111 { factories_s[className] = new TemplateGameStateFactory<T>(); } 112 static void destroyFactories(); 116 { factories_s[className].reset(new TemplateGameStateFactory<T>()); } 113 117 private: 114 virtual GameState*fabricateInternal(const GameStateInfo& info) = 0;115 static std::map<std::string, GameStateFactory*> factories_s;118 virtual shared_ptr<GameState> fabricateInternal(const GameStateInfo& info) = 0; 119 static std::map<std::string, shared_ptr<GameStateFactory> > factories_s; 116 120 }; 117 121 template <class T> … … 119 123 { 120 124 public: 121 GameState*fabricateInternal(const GameStateInfo& info)122 { return new T(info); }125 shared_ptr<GameState> fabricateInternal(const GameStateInfo& info) 126 { return shared_ptr<GameState>(new T(info)); } 123 127 }; 124 128 … … 144 148 void updateFPSLimiter(); 145 149 146 std::map<std::string, GameState*> constructedStates_; 147 std::vector<GameState*> loadedStates_; 150 // ScopeGuard helper function 151 void resetChangingState() { this->bChangingState_ = false; } 152 153 scoped_ptr<Clock> gameClock_; 154 scoped_ptr<Core> core_; 155 scoped_ptr<GameConfiguration> configuration_; 156 157 GameStateMap constructedStates_; 158 GameStateVector loadedStates_; 148 159 GameStateTreeNodePtr rootStateNode_; 149 160 GameStateTreeNodePtr loadedTopStateNode_; 150 std::vector<GameStateTreeNodePtr > requestedStateNodes_; 151 152 Core* core_; 153 Clock* gameClock_; 154 GameConfiguration* configuration_; 161 std::vector<GameStateTreeNodePtr> requestedStateNodes_; 155 162 156 163 bool bChangingState_;
Note: See TracChangeset
for help on using the changeset viewer.