Changeset 3247 for code/branches/core4/src/core/Game.cc
- Timestamp:
- Jun 29, 2009, 2:01:51 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core4/src/core/Game.cc
r3245 r3247 58 58 SetConsoleCommandShortcutExternAlias(stop_game, "exit"); 59 59 60 struct _CoreExport GameStateTreeNode 60 std::map<std::string, Game::GameStateInfo> Game::gameStateDeclarations_s; 61 Game* Game::singletonRef_s = 0; 62 63 64 /** 65 @brief 66 Represents one node of the game state tree. 67 */ 68 struct GameStateTreeNode 61 69 { 62 70 GameState* state_; … … 65 73 }; 66 74 67 std::map<std::string, Game::GameStateInfo> Game::gameStateDeclarations_s; 68 Game* Game::singletonRef_s = 0; 75 76 /** 77 @brief 78 Another helper class for the Game singleton: we cannot derive 79 Game from OrxonoxClass because we need to handle the Identifier 80 destruction in the Core destructor. 81 */ 82 class GameConfiguration : public OrxonoxClass 83 { 84 public: 85 GameConfiguration() 86 { 87 RegisterRootObject(GameConfiguration); 88 this->setConfigValues(); 89 } 90 91 void setConfigValues() 92 { 93 SetConfigValue(statisticsRefreshCycle_, 250000) 94 .description("Sets the time in microseconds interval at which average fps, etc. get updated."); 95 SetConfigValue(statisticsAvgLength_, 1000000) 96 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated."); 97 } 98 99 unsigned int statisticsRefreshCycle_; 100 unsigned int statisticsAvgLength_; 101 }; 102 69 103 70 104 /** … … 99 133 100 134 // Create the Core 101 this->core_ = new orxonox::Core(); 102 this->core_->initialise(argc, argv); 135 this->core_ = new Core(argc, argv); 103 136 104 137 // After the core has been created, we can safely instantiate the GameStates … … 118 151 this->activeStates_.push_back(this->rootStateNode_->state_); 119 152 120 // Do this after Core creation! 121 RegisterRootObject(Game); 122 this->setConfigValues(); 153 // Do this after the Core creation! 154 this->configuration_ = new GameConfiguration(); 123 155 } 124 156 … … 128 160 Game::~Game() 129 161 { 162 // Destroy the configuration helper class instance 163 delete this->configuration_; 164 130 165 // Destroy the GameStates (note that the nodes still point to them, but doesn't matter) 131 166 for (std::map<std::string, GameState*>::const_iterator it = gameStates_.begin(); … … 137 172 delete this->gameClock_; 138 173 139 // Also, take care of the GameStateFactories174 // Take care of the GameStateFactories 140 175 GameStateFactory::destroyFactories(); 141 176 142 177 // Don't assign singletonRef_s with NULL! Recreation is not supported 143 }144 145 void Game::setConfigValues()146 {147 SetConfigValue(statisticsRefreshCycle_, 250000)148 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");149 SetConfigValue(statisticsAvgLength_, 1000000)150 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");151 178 } 152 179 … … 245 272 246 273 // STATISTICS 247 if (this->periodTime_ > statisticsRefreshCycle_)274 if (this->periodTime_ > this->configuration_->statisticsRefreshCycle_) 248 275 { 249 276 std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin(); 250 277 assert(it != this->statisticsTickTimes_.end()); 251 int64_t lastTime = currentTime - this-> statisticsAvgLength_;278 int64_t lastTime = currentTime - this->configuration_->statisticsAvgLength_; 252 279 if ((int64_t)it->tickTime < lastTime) 253 280 { … … 266 293 this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f; 267 294 268 this->periodTime_ -= this-> statisticsRefreshCycle_;295 this->periodTime_ -= this->configuration_->statisticsRefreshCycle_; 269 296 } 270 297 }
Note: See TracChangeset
for help on using the changeset viewer.