Changeset 10479 for code/branches/core7/src/libraries/core/Game.cc
- Timestamp:
- May 25, 2015, 7:20:21 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/Game.cc
r10380 r10479 45 45 #include "util/SubString.h" 46 46 #include "Core.h" 47 #include "CoreIncludes.h"48 47 #include "commandline/CommandLineParser.h" 49 #include " config/ConfigValueIncludes.h"48 #include "GameConfig.h" 50 49 #include "GameMode.h" 51 50 #include "GameState.h" … … 77 76 }; 78 77 79 RegisterAbstractClass(Game).inheritsFrom<Configurable>();80 81 78 Game::Game(const std::string& cmdLine) 82 79 : gameClock_(NULL) … … 84 81 , bChangingState_(false) 85 82 , bAbort_(false) 83 , config_(NULL) 86 84 , destructionHelper_(this) 87 85 { … … 114 112 115 113 // Do this after the Core creation! 116 RegisterObject(Game); 117 this->setConfigValues(); 114 this->config_ = new GameConfig(); 118 115 119 116 // After the core has been created, we can safely instantiate the GameStates that don't require graphics … … 138 135 orxout(internal_status) << "destroying Game object..." << endl; 139 136 140 // Remove us from the object lists again to avoid problems when destroying them141 this->unregisterObject();142 143 137 assert(loadedStates_.size() <= 1); // Just empty root GameState 144 138 // Destroy all GameStates (shared_ptrs take care of actual destruction) … … 146 140 147 141 GameStateFactory::getFactories().clear(); 142 safeObjectDelete(&config_); 148 143 safeObjectDelete(&core_); 149 144 safeObjectDelete(&gameClock_); 150 145 151 146 orxout(internal_status) << "finished destroying Game object..." << endl; 152 }153 154 void Game::setConfigValues()155 {156 SetConfigValue(statisticsRefreshCycle_, 250000)157 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");158 SetConfigValue(statisticsAvgLength_, 1000000)159 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");160 161 SetConfigValueExternal(fpsLimit_, "GraphicsSettings", "fpsLimit", 50)162 .description("Sets the desired frame rate (0 for no limit).");163 147 } 164 148 … … 231 215 // Limit frame rate 232 216 static bool hasVSync = GameMode::showsGraphics() && GraphicsManager::getInstance().hasVSyncEnabled(); // can be static since changes of VSync currently require a restart 233 if (this-> fpsLimit_> 0 && !hasVSync)217 if (this->config_->getFpsLimit() > 0 && !hasVSync) 234 218 this->updateFPSLimiter(); 235 219 } … … 313 297 this->statisticsTickTimes_.back().tickLength += (uint32_t)(currentRealTime - currentTime); 314 298 this->periodTickTime_ += (uint32_t)(currentRealTime - currentTime); 315 if (this->periodTime_ > this-> statisticsRefreshCycle_)299 if (this->periodTime_ > this->config_->getStatisticsRefreshCycle()) 316 300 { 317 301 std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin(); 318 302 assert(it != this->statisticsTickTimes_.end()); 319 int64_t lastTime = currentTime - this-> statisticsAvgLength_;303 int64_t lastTime = currentTime - this->config_->getStatisticsAvgLength(); 320 304 if (static_cast<int64_t>(it->tickTime) < lastTime) 321 305 { … … 335 319 this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f; 336 320 337 this->periodTime_ -= this-> statisticsRefreshCycle_;321 this->periodTime_ -= this->config_->getStatisticsRefreshCycle(); 338 322 } 339 323 } … … 341 325 void Game::updateFPSLimiter() 342 326 { 343 uint64_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / fpsLimit_);327 uint64_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / this->config_->getFpsLimit()); 344 328 uint64_t currentRealTime = gameClock_->getRealMicroseconds(); 345 329 while (currentRealTime < nextTime - minimumSleepTime_)
Note: See TracChangeset
for help on using the changeset viewer.