Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10479


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.

Location:
code/branches/core7/src
Files:
4 added
14 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/core/CMakeLists.txt

    r10413 r10479  
    2626  Event.cc
    2727  Game.cc
     28  GameConfig.cc
    2829  GameMode.cc
    2930  GameState.cc
     
    4344  BaseObject.cc
    4445  Core.cc
     46  CoreConfig.cc
    4547
    4648BUILD_UNIT OgreBuildUnit.cc
  • code/branches/core7/src/libraries/core/Core.cc

    r10464 r10479  
    6262#include "commandline/CommandLineIncludes.h"
    6363#include "config/ConfigFileManager.h"
    64 #include "config/ConfigValueIncludes.h"
    65 #include "CoreIncludes.h"
    6664#include "DynLibManager.h"
    6765#include "GameMode.h"
     
    9593#endif
    9694
    97     // register Core as an abstract class to avoid problems if the class hierarchy is created within Core-constructor
    98     RegisterAbstractClass(Core).inheritsFrom<Configurable>();
    99 
    10095    Core::Core(const std::string& cmdLine)
    10196        : pathConfig_(NULL)
     
    114109        , graphicsScope_(NULL)
    115110        , bGraphicsLoaded_(false)
    116         , bStartIOConsole_(true)
    117         , lastLevelTimestamp_(0)
    118         , ogreConfigTimestamp_(0)
    119         , bDevMode_(false)
     111        , config_(NULL)
    120112        , destructionHelper_(this)
    121113    {
     
    188180        // Do this soon after the ConfigFileManager has been created to open up the
    189181        // possibility to configure everything below here
    190         RegisterObject(Core);
    191182        orxout(internal_info) << "configuring Core" << endl;
    192         this->setConfigValues();
     183        this->config_ = new CoreConfig();
     184        this->config_->setConfigValues(); // TODO: move this into CoreConfig constructor (but resolve dependency to Language)
    193185
    194186        // Set the correct log path and rewrite the log file with the correct log levels
     
    197189#if !defined(ORXONOX_PLATFORM_APPLE) && !defined(ORXONOX_USE_WINMAIN)
    198190        // Create persistent IO console
    199         if (CommandLineParser::getValue("noIOConsole").get<bool>())
    200         {
    201             ModifyConfigValue(bStartIOConsole_, tset, false);
    202         }
    203         if (this->bStartIOConsole_)
     191        if (CommandLineParser::getValue("noIOConsole").get<bool>() == false && this->config_->getStartIOConsole())
    204192        {
    205193            orxout(internal_info) << "creating IO console" << endl;
     
    248236    {
    249237        orxout(internal_status) << "destroying Core object..." << endl;
    250 
    251         // Remove us from the object lists again to avoid problems when destroying them
    252         this->unregisterObject();
    253238
    254239        safeObjectDelete(&graphicsScope_);
     
    261246        safeObjectDelete(&ioConsole_);
    262247        safeObjectDelete(&loaderInstance_);
     248        safeObjectDelete(&config_);
    263249        safeObjectDelete(&languageInstance_);
    264250        safeObjectDelete(&configFileManager_);
     
    271257
    272258        orxout(internal_status) << "finished destroying Core object" << endl;
    273     }
    274 
    275     //! Function to collect the SetConfigValue-macro calls.
    276     void Core::setConfigValues()
    277     {
    278         SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableMaxLevel_,
    279                                OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),
    280                                OutputManager::getInstance().getLogWriter()->getConfigurableMaxLevelName(),
    281                                OutputManager::getInstance().getLogWriter()->configurableMaxLevel_)
    282             .description("The maximum level of output shown in the log file")
    283             .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableLevel);
    284         SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableAdditionalContextsMaxLevel_,
    285                                OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),
    286                                OutputManager::getInstance().getLogWriter()->getConfigurableAdditionalContextsMaxLevelName(),
    287                                OutputManager::getInstance().getLogWriter()->configurableAdditionalContextsMaxLevel_)
    288             .description("The maximum level of output shown in the log file for additional contexts")
    289             .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContextsLevel);
    290         SetConfigValueExternal(OutputManager::getInstance().getLogWriter()->configurableAdditionalContexts_,
    291                                OutputManager::getInstance().getLogWriter()->getConfigurableSectionName(),
    292                                OutputManager::getInstance().getLogWriter()->getConfigurableAdditionalContextsName(),
    293                                OutputManager::getInstance().getLogWriter()->configurableAdditionalContexts_)
    294             .description("Additional output contexts shown in the log file")
    295             .callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContexts);
    296 
    297         SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())
    298             .description("Developer mode. If not set, hides some things from the user to not confuse him.")
    299             .callback(this, &Core::devModeChanged);
    300         SetConfigValue(language_, Language::getInstance().defaultLanguage_)
    301             .description("The language of the in game text")
    302             .callback(this, &Core::languageChanged);
    303         SetConfigValue(bInitRandomNumberGenerator_, true)
    304             .description("If true, all random actions are different each time you start the game")
    305             .callback(this, &Core::initRandomNumberGenerator);
    306         SetConfigValue(bStartIOConsole_, true)
    307             .description("Set to false if you don't want to use the IOConsole (for Lua debugging for instance)");
    308         SetConfigValue(lastLevelTimestamp_, 0)
    309             .description("Timestamp when the last level was started.");
    310         SetConfigValue(ogreConfigTimestamp_, 0)
    311             .description("Timestamp when the ogre config file was changed.");
    312     }
    313 
    314     /** Callback function for changes in the dev mode that affect debug levels.
    315         The function behaves according to these rules:
    316         - 'normal' mode is defined based on where the program was launched: if
    317           the launch path was the build directory, development mode \c on is
    318           normal, otherwise normal means development mode \c off.
    319         - Debug levels should not be hard configured (\c config instead of
    320           \c tconfig) in non 'normal' mode to avoid strange behaviour.
    321         - Changing the development mode from 'normal' to the other state will
    322           immediately change the debug levels to predefined values which can be
    323           reconfigured with \c tconfig.
    324     @note
    325         The debug levels for the IOConsole and the InGameConsole can be found
    326         in the Shell class. The same rules apply.
    327     */
    328     void Core::devModeChanged()
    329     {
    330         // Inform listeners
    331         ObjectList<DevModeListener>::iterator it = ObjectList<DevModeListener>::begin();
    332         for (; it != ObjectList<DevModeListener>::end(); ++it)
    333             it->devModeChanged(bDevMode_);
    334     }
    335 
    336     //! Callback function if the language has changed.
    337     void Core::languageChanged()
    338     {
    339         // Read the translation file after the language was configured
    340         Language::getInstance().readTranslatedLanguageFile();
    341     }
    342 
    343     void Core::initRandomNumberGenerator()
    344     {
    345         static bool bInitialized = false;
    346         if (!bInitialized && this->bInitRandomNumberGenerator_)
    347         {
    348             srand(static_cast<unsigned int>(time(0)));
    349             rand();
    350             bInitialized = true;
    351         }
    352259    }
    353260
     
    429336    }
    430337
    431     //! Sets the language in the config-file back to the default.
    432     void Core::resetLanguage()
    433     {
    434         ResetConfigValue(language_);
    435     }
    436 
    437338    /**
    438339    @note
     
    511412        }
    512413    }
    513 
    514     void Core::updateLastLevelTimestamp()
    515     {
    516         ModifyConfigValue(lastLevelTimestamp_, set, static_cast<long long>(time(NULL)));
    517     }
    518 
    519     void Core::updateOgreConfigTimestamp()
    520     {
    521         ModifyConfigValue(ogreConfigTimestamp_, set, static_cast<long long>(time(NULL)));
    522     }
    523 
    524 
    525     RegisterAbstractClass(DevModeListener).inheritsFrom<Listable>();
    526 
    527     DevModeListener::DevModeListener()
    528     {
    529         RegisterObject(DevModeListener);
    530     }
    531414}
  • code/branches/core7/src/libraries/core/Core.h

    r10464 r10479  
    4747#include "util/DestructionHelper.h"
    4848#include "util/Singleton.h"
    49 #include "config/Configurable.h"
     49#include "CoreConfig.h"
    5050
    5151namespace orxonox
    5252{
    53     //! Informs about changes in the Development Mode.
    54     class DevModeListener : virtual public Listable
    55     {
    56     public:
    57         DevModeListener();
    58         virtual ~DevModeListener() {}
    59         virtual void devModeChanged(bool value) = 0;
    60     };
    61 
    6253    /**
    6354    @brief
     
    6657        You should only create this singleton once because it destroys the identifiers!
    6758    */
    68     class _CoreExport Core : public Singleton<Core>, public Configurable
     59    class _CoreExport Core : public Singleton<Core>
    6960    {
    7061        friend class Singleton<Core>;
     
    8677            void destroy();
    8778
    88             void setConfigValues();
    89 
    90             //! Returns the configured language.
    91             const std::string& getLanguage()
    92                 { return this->language_; }
    93             void resetLanguage();
    94 
    95             void updateLastLevelTimestamp();
    96             inline long long getLastLevelTimestamp() const
    97                 { return this->lastLevelTimestamp_; }
    98 
    99             void updateOgreConfigTimestamp();
    100             inline long long getOgreConfigTimestamp() const
    101                 { return this->ogreConfigTimestamp_; }
    102 
    103             //! Developers bit. If returns false, some options are not available as to not confuse the normal user.
    104             inline bool inDevMode(void) const
    105                 { return this->bDevMode_; }
     79            inline CoreConfig* getConfig() const
     80                { return this->config_; }
    10681
    10782        private:
    10883            Core(const Core&); //!< Don't use (undefined symbol)
    109 
    110             void devModeChanged();
    111             void languageChanged();
    112             void initRandomNumberGenerator();
    11384
    11485            void preUpdate(const Clock& time);
     
    135106            GUIManager*               guiManager_;                 //!< Interface to GUI
    136107            Scope<ScopeID::GRAPHICS>* graphicsScope_;
     108            bool                      bGraphicsLoaded_;
    137109
    138             bool                      bGraphicsLoaded_;
    139             std::string               language_;                   //!< The language
    140             bool                      bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called
    141             bool                      bStartIOConsole_;            //!< Set to false if you don't want to use the IOConsole
    142             long long                 lastLevelTimestamp_;         ///< Timestamp when the last level was started
    143             long long                 ogreConfigTimestamp_;        ///< Timestamp wehen the ogre config level was modified
    144             bool                      bDevMode_;                   //!< Developers bit. If set to false, some options are not available as to not confuse the normal user.
     110            /// Helper object that stores the config values
     111            CoreConfig*               config_;
    145112
    146113            /// Helper object that executes the surrogate destructor destroy()
  • code/branches/core7/src/libraries/core/CorePrereqs.h

    r10464 r10479  
    155155    class Context;
    156156    class Core;
     157    class CoreConfig;
    157158    class Destroyable;
    158159    class DestroyLaterManager;
     
    164165    class Factory;
    165166    class Game;
     167    class GameConfig;
    166168    class GameState;
    167169    struct GameStateInfo;
  • code/branches/core7/src/libraries/core/GUIManager.cc

    r10380 r10479  
    835835    /*static*/ bool GUIManager::inDevMode()
    836836    {
    837          return Core::getInstance().inDevMode();
     837         return Core::getInstance().getConfig()->inDevMode();
    838838    }
    839839
  • 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_)
  • code/branches/core7/src/libraries/core/Game.h

    r9667 r10479  
    5050#include "util/DestructionHelper.h"
    5151#include "util/Singleton.h"
    52 #include "config/Configurable.h"
    5352
    5453/**
     
    8281    class _CoreExport Game
    8382// tolua_end
    84         : public Singleton<Game>, public Configurable
     83        : public Singleton<Game>
    8584    { // tolua_export
    8685        friend class Singleton<Game>;
     
    9695        /// Destructor that also executes when object fails to construct
    9796        void destroy();
    98 
    99         void setConfigValues();
    10097
    10198        void setStateHierarchy(const std::string& str);
     
    189186        unsigned int                       minimumSleepTime_;
    190187
    191         // config values
    192         unsigned int                       statisticsRefreshCycle_;
    193         unsigned int                       statisticsAvgLength_;
    194         unsigned int                       fpsLimit_;
     188        /// Helper object that stores the config values
     189        GameConfig*                        config_;
    195190
    196191        /// Helper object that executes the surrogate destructor destroy()
  • code/branches/core7/src/libraries/core/GraphicsManager.cc

    r10392 r10479  
    281281        orxout(internal_info) << "GraphicsManager: Configuring Renderer" << endl;
    282282
    283         bool updatedConfig = Core::getInstance().getOgreConfigTimestamp() > Core::getInstance().getLastLevelTimestamp();
     283        bool updatedConfig = Core::getInstance().getConfig()->getOgreConfigTimestamp() > Core::getInstance().getConfig()->getLastLevelTimestamp();
    284284        if (updatedConfig)
    285285            orxout(user_info)<< "Ogre config file has changed, but no level was started since then. Displaying config dialogue again to verify the changes." << endl;
     
    290290                ThrowException(InitialisationFailed, "OGRE graphics configuration dialogue canceled.");
    291291            else
    292                 Core::getInstance().updateOgreConfigTimestamp();
     292                Core::getInstance().getConfig()->updateOgreConfigTimestamp();
    293293        }
    294294
     
    516516            GraphicsManager::getInstance().getRenderWindow()->setFullscreen(fullscreen, width, height);
    517517            this->ogreRoot_->saveConfig();
    518             Core::getInstance().updateOgreConfigTimestamp();
     518            Core::getInstance().getConfig()->updateOgreConfigTimestamp();
    519519            // Also reload the input devices
    520520            InputManager::getInstance().reload();
     
    534534            //this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_
    535535            this->ogreRoot_->saveConfig();
    536             Core::getInstance().updateOgreConfigTimestamp();
     536            Core::getInstance().getConfig()->updateOgreConfigTimestamp();
    537537        }
    538538
     
    550550            //this->ogreRoot_->getRenderSystem()->reinitialise(); // can't use this that easily, because it recreates the render window, invalidating renderWindow_
    551551            this->ogreRoot_->saveConfig();
    552             Core::getInstance().updateOgreConfigTimestamp();
     552            Core::getInstance().getConfig()->updateOgreConfigTimestamp();
    553553        }
    554554
  • code/branches/core7/src/libraries/core/Language.cc

    r8858 r10479  
    250250    void Language::readTranslatedLanguageFile()
    251251    {
    252         orxout(internal_info, context::language) << "Read translated language file (" << Core::getInstance().getLanguage() << ")." << endl;
    253 
    254         const std::string& filepath = PathConfig::getConfigPathString() + getFilename(Core::getInstance().getLanguage());
     252        orxout(internal_info, context::language) << "Read translated language file (" << Core::getInstance().getConfig()->getLanguage() << ")." << endl;
     253
     254        const std::string& filepath = PathConfig::getConfigPathString() + getFilename(Core::getInstance().getConfig()->getLanguage());
    255255
    256256        // Open the file
     
    261261        {
    262262            orxout(internal_error, context::language) << "An error occurred in Language.cc:" << endl;
    263             orxout(internal_error, context::language) << "Couldn't open file " << getFilename(Core::getInstance().getLanguage()) << " to read the translated language entries!" << endl;
    264             Core::getInstance().resetLanguage();
     263            orxout(internal_error, context::language) << "Couldn't open file " << getFilename(Core::getInstance().getConfig()->getLanguage()) << " to read the translated language entries!" << endl;
     264            Core::getInstance().getConfig()->resetLanguage();
    265265            orxout(internal_info, context::language) << "Reset language to " << this->defaultLanguage_ << '.' << endl;
    266266            return;
     
    291291                else
    292292                {
    293                     orxout(internal_warning, context::language) << "Invalid language entry \"" << lineString << "\" in " << getFilename(Core::getInstance().getLanguage()) << endl;
     293                    orxout(internal_warning, context::language) << "Invalid language entry \"" << lineString << "\" in " << getFilename(Core::getInstance().getConfig()->getLanguage()) << endl;
    294294                }
    295295            }
  • code/branches/core7/src/libraries/core/Language.h

    r8858 r10479  
    161161    {
    162162        friend class Singleton<Language>;
    163         friend class Core;
     163        friend class CoreConfig;
    164164
    165165        public:
  • code/branches/core7/src/libraries/core/class/IdentifierManager.cc

    r10403 r10479  
    130130
    131131        // only check class hierarchy in dev mode because it's an expensive operation and it requires a developer to fix detected problems anyway.
    132         if (!Core::exists() || Core::getInstance().inDevMode())
     132        if (!Core::exists() || Core::getInstance().getConfig()->inDevMode())
    133133            this->verifyClassHierarchy();
    134134
  • code/branches/core7/src/libraries/core/command/Shell.h

    r9667 r10479  
    4949
    5050#include "util/output/BaseWriter.h"
    51 #include "core/Core.h"
     51#include "core/CoreConfig.h"
    5252
    5353namespace orxonox
  • code/branches/core7/src/orxonox/gamestates/GSLevel.cc

    r10392 r10479  
    170170        bool loaded = Loader::getInstance().open(startFile_);
    171171
    172         Core::getInstance().updateLastLevelTimestamp();
     172        Core::getInstance().getConfig()->updateLastLevelTimestamp();
    173173        if(!loaded)
    174174            GSRoot::delayedStartMainMenu();
  • code/branches/core7/src/orxonox/gametypes/Gametype.cc

    r10349 r10479  
    409409                    {
    410410                        // If in developer's mode, there is no start countdown.
    411                         if(Core::getInstance().inDevMode())
     411                        if(Core::getInstance().getConfig()->inDevMode())
    412412                            this->start();
    413413                        else
Note: See TracChangeset for help on using the changeset viewer.