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/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}
Note: See TracChangeset for help on using the changeset viewer.