Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 4, 2015, 9:12:21 PM (9 years ago)
Author:
landauf
Message:

merged branch core7 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/Game.cc

    r9667 r10624  
    4545#include "util/SubString.h"
    4646#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"
    5049#include "GameMode.h"
    5150#include "GameState.h"
    5251#include "GraphicsManager.h"
    5352#include "GUIManager.h"
    54 #include "command/ConsoleCommand.h"
     53#include "command/ConsoleCommandIncludes.h"
    5554
    5655namespace orxonox
     
    8281        , bChangingState_(false)
    8382        , bAbort_(false)
     83        , config_(NULL)
    8484        , destructionHelper_(this)
    8585    {
     
    110110        orxout(internal_info) << "creating Core object:" << endl;
    111111        this->core_ = new Core(cmdLine);
     112        this->core_->loadModules();
    112113
    113114        // Do this after the Core creation!
    114         RegisterObject(Game);
    115         this->setConfigValues();
     115        this->config_ = new GameConfig();
    116116
    117117        // After the core has been created, we can safely instantiate the GameStates that don't require graphics
     
    136136        orxout(internal_status) << "destroying Game object..." << endl;
    137137
    138         // Remove us from the object lists again to avoid problems when destroying them
    139         this->unregisterObject();
    140 
    141138        assert(loadedStates_.size() <= 1); // Just empty root GameState
    142139        // Destroy all GameStates (shared_ptrs take care of actual destruction)
     
    144141
    145142        GameStateFactory::getFactories().clear();
     143        safeObjectDelete(&config_);
     144        if (this->core_)
     145            this->core_->unloadModules();
    146146        safeObjectDelete(&core_);
    147147        safeObjectDelete(&gameClock_);
    148148
    149149        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).");
    161150    }
    162151
     
    229218            // Limit frame rate
    230219            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)
    232221                this->updateFPSLimiter();
    233222        }
     
    311300        this->statisticsTickTimes_.back().tickLength += (uint32_t)(currentRealTime - currentTime);
    312301        this->periodTickTime_ += (uint32_t)(currentRealTime - currentTime);
    313         if (this->periodTime_ > this->statisticsRefreshCycle_)
     302        if (this->periodTime_ > this->config_->getStatisticsRefreshCycle())
    314303        {
    315304            std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
    316305            assert(it != this->statisticsTickTimes_.end());
    317             int64_t lastTime = currentTime - this->statisticsAvgLength_;
     306            int64_t lastTime = currentTime - this->config_->getStatisticsAvgLength();
    318307            if (static_cast<int64_t>(it->tickTime) < lastTime)
    319308            {
     
    333322            this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f;
    334323
    335             this->periodTime_ -= this->statisticsRefreshCycle_;
     324            this->periodTime_ -= this->config_->getStatisticsRefreshCycle();
    336325        }
    337326    }
     
    339328    void Game::updateFPSLimiter()
    340329    {
    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());
    342331        uint64_t currentRealTime = gameClock_->getRealMicroseconds();
    343332        while (currentRealTime < nextTime - minimumSleepTime_)
     
    529518
    530519            core_->loadGraphics();
    531             Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics);
     520            Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics, true);
    532521
    533522            // Construct all the GameStates that require graphics
     
    550539    }
    551540
    552     void Game::unloadGraphics()
     541    void Game::unloadGraphics(bool loadGraphicsManagerWithoutRenderer)
    553542    {
    554543        if (GameMode::showsGraphics())
     
    566555            }
    567556
    568             core_->unloadGraphics();
     557            core_->unloadGraphics(loadGraphicsManagerWithoutRenderer);
    569558        }
    570559    }
     
    587576
    588577        // 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);
    590579        if (gameStateDeclarations_s[name].bGraphicsMode && !GameMode::showsGraphics())
    591580            this->loadGraphics();
     
    623612        }
    624613        // 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)
    633619        this->bChangingState_ = false;
    634620    }
Note: See TracChangeset for help on using the changeset viewer.