Changeset 3280 for code/trunk/src/core/Game.h
- Timestamp:
- Jul 12, 2009, 11:58:01 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core4 (added) merged: 3235-3237,3245-3250,3253-3254,3260-3261,3265,3270
- Property svn:mergeinfo changed
-
code/trunk/src/core/Game.h
r3196 r3280 46 46 #include <boost/preprocessor/cat.hpp> 47 47 48 #include "OrxonoxClass.h" 48 #include "util/Debug.h" 49 #include "util/StringUtils.h" 49 50 50 51 /** … … 53 54 and every following paramter is a constructor argument (which is usually non existent) 54 55 */ 55 #define AddGameState(classname, ...) \56 static bool BOOST_PP_CAT(bGameStateDummy_##class name, __LINE__) = orxonox::Game::addGameState(new classname(__VA_ARGS__))56 #define DeclareGameState(className, stateName, bIgnoreTickTime, bGraphicsMode) \ 57 static bool BOOST_PP_CAT(bGameStateDummy_##className, __LINE__) = orxonox::Game::declareGameState<className>(#className, stateName, bIgnoreTickTime, bGraphicsMode) 57 58 58 // tolua_begin59 59 namespace orxonox 60 60 { 61 class GameConfiguration; 62 61 63 /** 62 64 @brief … … 64 66 */ 65 67 class _CoreExport Game 66 // tolua_end67 : public OrxonoxClass68 // tolua_begin69 68 { 70 //tolua_end71 69 public: 72 70 Game(int argc, char** argv); 73 71 ~Game(); 74 void setConfigValues();75 72 76 73 void setStateHierarchy(const std::string& str); … … 91 88 void addTickTime(uint32_t length); 92 89 93 static bool addGameState(GameState* state); 94 static void destroyStates(); 95 static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; } //tolua_export 96 97 void setLevel(std::string levelName); //tolua_export 98 std::string getLevel(); //tolua_export 90 template <class T> 91 static bool declareGameState(const std::string& className, const std::string& stateName, bool bIgnoreTickTime, bool bConsoleMode); 92 static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 99 93 100 94 private: 101 struct statisticsTickInfo 95 class _CoreExport GameStateFactory 96 { 97 public: 98 virtual ~GameStateFactory() { } 99 static GameState* fabricate(const std::string& className, const GameStateConstrParams& params); 100 template <class T> 101 static void createFactory(const std::string& className) 102 { factories_s[className] = new TemplateGameStateFactory<T>(); } 103 static void destroyFactories(); 104 private: 105 virtual GameState* fabricate(const GameStateConstrParams& params) = 0; 106 static std::map<std::string, GameStateFactory*> factories_s; 107 }; 108 template <class T> 109 class TemplateGameStateFactory : public GameStateFactory 110 { 111 public: 112 GameState* fabricate(const GameStateConstrParams& params) 113 { return new T(params); } 114 }; 115 116 struct GameStateInfo 117 { 118 std::string stateName; 119 std::string className; 120 bool bIgnoreTickTime; 121 bool bGraphicsMode; 122 }; 123 124 struct StatisticsTickInfo 102 125 { 103 126 uint64_t tickTime; … … 110 133 void unloadState(GameState* state); 111 134 112 std::vector<GameState*> activeStates_; 135 std::map<std::string, GameState*> gameStates_; 136 std::vector<GameState*> activeStates_; 113 137 boost::shared_ptr<GameStateTreeNode> rootStateNode_; 114 138 boost::shared_ptr<GameStateTreeNode> activeStateNode_; … … 117 141 Core* core_; 118 142 Clock* gameClock_; 143 GameConfiguration* configuration_; 119 144 120 bool abort_; 145 bool bChangingState_; 146 bool bAbort_; 121 147 122 148 // variables for time statistics 123 149 uint64_t statisticsStartTime_; 124 std::list< statisticsTickInfo> statisticsTickTimes_;150 std::list<StatisticsTickInfo> statisticsTickTimes_; 125 151 uint32_t periodTime_; 126 152 uint32_t periodTickTime_; … … 128 154 float avgTickTime_; 129 155 130 // config values 131 unsigned int statisticsRefreshCycle_; 132 unsigned int statisticsAvgLength_; 133 std::string levelName_; 156 static std::map<std::string, GameStateInfo> gameStateDeclarations_s; 157 static Game* singletonRef_s; //!< Pointer to the Singleton 158 }; 134 159 135 static std::map<std::string, GameState*> allStates_s; 136 static Game* singletonRef_s; //!< Pointer to the Singleton 137 // tolua_begin 138 }; 160 template <class T> 161 /*static*/ bool Game::declareGameState(const std::string& className, const std::string& stateName, bool bIgnoreTickTime, bool bGraphicsMode) 162 { 163 std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.find(getLowercase(stateName)); 164 if (it == gameStateDeclarations_s.end()) 165 { 166 GameStateInfo& info = gameStateDeclarations_s[getLowercase(stateName)]; 167 info.stateName = stateName; 168 info.className = className; 169 info.bIgnoreTickTime = bIgnoreTickTime; 170 info.bGraphicsMode = bGraphicsMode; 171 } 172 else 173 { 174 COUT(0) << "Error: Cannot declare two GameStates with the same name." << std::endl; 175 COUT(0) << " Ignoring second one ('" << stateName << "')." << std::endl; 176 } 177 178 // Create a factory to delay GameState creation 179 GameStateFactory::createFactory<T>(className); 180 181 // just a required dummy return value 182 return true; 183 } 139 184 } 140 //tolua_end 185 141 186 #endif /* _Game_H__ */
Note: See TracChangeset
for help on using the changeset viewer.