Changeset 10624 for code/trunk/src/libraries/core/Game.cc
- Timestamp:
- Oct 4, 2015, 9:12:21 PM (10 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
code/trunk/src/libraries/core/Game.cc
r9667 r10624 45 45 #include "util/SubString.h" 46 46 #include "Core.h" 47 #include "CoreIncludes.h" 48 #include "config/CommandLineParser.h" 49 #include "config/ConfigValueIncludes.h" 47 #include "commandline/CommandLineParser.h" 48 #include "GameConfig.h" 50 49 #include "GameMode.h" 51 50 #include "GameState.h" 52 51 #include "GraphicsManager.h" 53 52 #include "GUIManager.h" 54 #include "command/ConsoleCommand .h"53 #include "command/ConsoleCommandIncludes.h" 55 54 56 55 namespace orxonox … … 82 81 , bChangingState_(false) 83 82 , bAbort_(false) 83 , config_(NULL) 84 84 , destructionHelper_(this) 85 85 { … … 110 110 orxout(internal_info) << "creating Core object:" << endl; 111 111 this->core_ = new Core(cmdLine); 112 this->core_->loadModules(); 112 113 113 114 // Do this after the Core creation! 114 RegisterObject(Game); 115 this->setConfigValues(); 115 this->config_ = new GameConfig(); 116 116 117 117 // After the core has been created, we can safely instantiate the GameStates that don't require graphics … … 136 136 orxout(internal_status) << "destroying Game object..." << endl; 137 137 138 // Remove us from the object lists again to avoid problems when destroying them139 this->unregisterObject();140 141 138 assert(loadedStates_.size() <= 1); // Just empty root GameState 142 139 // Destroy all GameStates (shared_ptrs take care of actual destruction) … … 144 141 145 142 GameStateFactory::getFactories().clear(); 143 safeObjectDelete(&config_); 144 if (this->core_) 145 this->core_->unloadModules(); 146 146 safeObjectDelete(&core_); 147 147 safeObjectDelete(&gameClock_); 148 148 149 149 orxout(internal_status) << "finished destroying Game object..." << endl; 150 }151 152 void Game::setConfigValues()153 {154 SetConfigValue(statisticsRefreshCycle_, 250000)155 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");156 SetConfigValue(statisticsAvgLength_, 1000000)157 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");158 159 SetConfigValueExternal(fpsLimit_, "GraphicsSettings", "fpsLimit", 50)160 .description("Sets the desired frame rate (0 for no limit).");161 150 } 162 151 … … 229 218 // Limit frame rate 230 219 static bool hasVSync = GameMode::showsGraphics() && GraphicsManager::getInstance().hasVSyncEnabled(); // can be static since changes of VSync currently require a restart 231 if (this-> fpsLimit_> 0 && !hasVSync)220 if (this->config_->getFpsLimit() > 0 && !hasVSync) 232 221 this->updateFPSLimiter(); 233 222 } … … 311 300 this->statisticsTickTimes_.back().tickLength += (uint32_t)(currentRealTime - currentTime); 312 301 this->periodTickTime_ += (uint32_t)(currentRealTime - currentTime); 313 if (this->periodTime_ > this-> statisticsRefreshCycle_)302 if (this->periodTime_ > this->config_->getStatisticsRefreshCycle()) 314 303 { 315 304 std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin(); 316 305 assert(it != this->statisticsTickTimes_.end()); 317 int64_t lastTime = currentTime - this-> statisticsAvgLength_;306 int64_t lastTime = currentTime - this->config_->getStatisticsAvgLength(); 318 307 if (static_cast<int64_t>(it->tickTime) < lastTime) 319 308 { … … 333 322 this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f; 334 323 335 this->periodTime_ -= this-> statisticsRefreshCycle_;324 this->periodTime_ -= this->config_->getStatisticsRefreshCycle(); 336 325 } 337 326 } … … 339 328 void Game::updateFPSLimiter() 340 329 { 341 uint64_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / fpsLimit_);330 uint64_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / this->config_->getFpsLimit()); 342 331 uint64_t currentRealTime = gameClock_->getRealMicroseconds(); 343 332 while (currentRealTime < nextTime - minimumSleepTime_) … … 529 518 530 519 core_->loadGraphics(); 531 Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics );520 Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics, true); 532 521 533 522 // Construct all the GameStates that require graphics … … 550 539 } 551 540 552 void Game::unloadGraphics( )541 void Game::unloadGraphics(bool loadGraphicsManagerWithoutRenderer) 553 542 { 554 543 if (GameMode::showsGraphics()) … … 566 555 } 567 556 568 core_->unloadGraphics( );557 core_->unloadGraphics(loadGraphicsManagerWithoutRenderer); 569 558 } 570 559 } … … 587 576 588 577 // If state requires graphics, load it 589 Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics );578 Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics, true); 590 579 if (gameStateDeclarations_s[name].bGraphicsMode && !GameMode::showsGraphics()) 591 580 this->loadGraphics(); … … 623 612 } 624 613 // Check if graphics is still required 625 if (!bAbort_) 626 { 627 bool graphicsRequired = false; 628 for (unsigned i = 0; i < loadedStates_.size(); ++i) 629 graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode; 630 if (!graphicsRequired) 631 this->unloadGraphics(); 632 } 614 bool graphicsRequired = false; 615 for (unsigned i = 0; i < loadedStates_.size(); ++i) 616 graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode; 617 if (!graphicsRequired) 618 this->unloadGraphics(!this->bAbort_); // if abort is false, that means the game is still running while unloading graphics. in this case we load a graphics manager without renderer (to keep all necessary ogre instances alive) 633 619 this->bChangingState_ = false; 634 620 }
Note: See TracChangeset
for help on using the changeset viewer.