Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2015, 7:20:21 PM (9 years ago)
Author:
landauf
Message:

moved config values and all related functions from Game and Core to GameConfig and CoreConfig respectively. this ensures that no framework features are used by Game and Core before Core itself initialized the framework.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/Game.cc

    r10380 r10479  
    4545#include "util/SubString.h"
    4646#include "Core.h"
    47 #include "CoreIncludes.h"
    4847#include "commandline/CommandLineParser.h"
    49 #include "config/ConfigValueIncludes.h"
     48#include "GameConfig.h"
    5049#include "GameMode.h"
    5150#include "GameState.h"
     
    7776    };
    7877
    79     RegisterAbstractClass(Game).inheritsFrom<Configurable>();
    80 
    8178    Game::Game(const std::string& cmdLine)
    8279        : gameClock_(NULL)
     
    8481        , bChangingState_(false)
    8582        , bAbort_(false)
     83        , config_(NULL)
    8684        , destructionHelper_(this)
    8785    {
     
    114112
    115113        // Do this after the Core creation!
    116         RegisterObject(Game);
    117         this->setConfigValues();
     114        this->config_ = new GameConfig();
    118115
    119116        // After the core has been created, we can safely instantiate the GameStates that don't require graphics
     
    138135        orxout(internal_status) << "destroying Game object..." << endl;
    139136
    140         // Remove us from the object lists again to avoid problems when destroying them
    141         this->unregisterObject();
    142 
    143137        assert(loadedStates_.size() <= 1); // Just empty root GameState
    144138        // Destroy all GameStates (shared_ptrs take care of actual destruction)
     
    146140
    147141        GameStateFactory::getFactories().clear();
     142        safeObjectDelete(&config_);
    148143        safeObjectDelete(&core_);
    149144        safeObjectDelete(&gameClock_);
    150145
    151146        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).");
    163147    }
    164148
     
    231215            // Limit frame rate
    232216            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)
    234218                this->updateFPSLimiter();
    235219        }
     
    313297        this->statisticsTickTimes_.back().tickLength += (uint32_t)(currentRealTime - currentTime);
    314298        this->periodTickTime_ += (uint32_t)(currentRealTime - currentTime);
    315         if (this->periodTime_ > this->statisticsRefreshCycle_)
     299        if (this->periodTime_ > this->config_->getStatisticsRefreshCycle())
    316300        {
    317301            std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
    318302            assert(it != this->statisticsTickTimes_.end());
    319             int64_t lastTime = currentTime - this->statisticsAvgLength_;
     303            int64_t lastTime = currentTime - this->config_->getStatisticsAvgLength();
    320304            if (static_cast<int64_t>(it->tickTime) < lastTime)
    321305            {
     
    335319            this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f;
    336320
    337             this->periodTime_ -= this->statisticsRefreshCycle_;
     321            this->periodTime_ -= this->config_->getStatisticsRefreshCycle();
    338322        }
    339323    }
     
    341325    void Game::updateFPSLimiter()
    342326    {
    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());
    344328        uint64_t currentRealTime = gameClock_->getRealMicroseconds();
    345329        while (currentRealTime < nextTime - minimumSleepTime_)
Note: See TracChangeset for help on using the changeset viewer.