Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 23, 2009, 6:19:58 PM (15 years ago)
Author:
rgrieder
Message:

Removed CoreConfiguration and GameConfiguration workaround. I have found an easy solution that doesn't need this.
Config values for these classes can again be found under "Game" and "Core".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/libraries/core/Core.cc

    r6105 r6121  
    5151#include "util/Debug.h"
    5252#include "util/Exception.h"
     53#include "util/Scope.h"
    5354#include "util/SignalHandler.h"
    5455#include "PathConfig.h"
     
    8182#endif
    8283
    83     /**
    84     @brief
    85         Helper class for the Core singleton: we cannot derive
    86         Core from OrxonoxClass because we need to handle the Identifier
    87         destruction in the Core destructor.
    88     */
    89     class CoreConfiguration : public OrxonoxClass
    90     {
    91     public:
    92         CoreConfiguration()
    93         {
    94         }
    95 
    96         void initialise()
    97         {
    98             RegisterRootObject(CoreConfiguration);
    99             this->setConfigValues();
    100         }
    101 
    102         /**
    103             @brief Function to collect the SetConfigValue-macro calls.
    104         */
    105         void setConfigValues()
    106         {
    107 #ifdef ORXONOX_RELEASE
    108             const unsigned int defaultLevelLogFile = 3;
    109 #else
    110             const unsigned int defaultLevelLogFile = 4;
    111 #endif
    112             SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevelLogFile_, "softDebugLevelLogFile", "OutputHandler", defaultLevelLogFile)
    113                 .description("The maximum level of debug output shown in the log file");
    114             OutputHandler::getInstance().setSoftDebugLevel(OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_);
    115 
    116             SetConfigValue(language_, Language::getInstance().defaultLanguage_)
    117                 .description("The language of the in game text")
    118                 .callback(this, &CoreConfiguration::languageChanged);
    119             SetConfigValue(bInitializeRandomNumberGenerator_, true)
    120                 .description("If true, all random actions are different each time you start the game")
    121                 .callback(this, &CoreConfiguration::initializeRandomNumberGenerator);
    122         }
    123 
    124         /**
    125             @brief Callback function if the language has changed.
    126         */
    127         void languageChanged()
    128         {
    129             // Read the translation file after the language was configured
    130             Language::getInstance().readTranslatedLanguageFile();
    131         }
    132 
    133         /**
    134             @brief Sets the language in the config-file back to the default.
    135         */
    136         void resetLanguage()
    137         {
    138             ResetConfigValue(language_);
    139         }
    140 
    141         void initializeRandomNumberGenerator()
    142         {
    143             static bool bInitialized = false;
    144             if (!bInitialized && this->bInitializeRandomNumberGenerator_)
    145             {
    146                 srand(static_cast<unsigned int>(time(0)));
    147                 rand();
    148                 bInitialized = true;
    149             }
    150         }
    151 
    152         int softDebugLevelLogFile_;                     //!< The debug level for the log file (belongs to OutputHandler)
    153         std::string language_;                          //!< The language
    154         bool bInitializeRandomNumberGenerator_;         //!< If true, srand(time(0)) is called
    155     };
    156 
    157 
    15884    Core::Core(const std::string& cmdLine)
    15985        // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands)
     
    16187        // Cleanup guard for external console commands that don't belong to an Identifier
    16288        , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands)
    163         , configuration_(new CoreConfiguration()) // Don't yet create config values!
    16489        , bGraphicsLoaded_(false)
    16590    {
     
    218143        this->languageInstance_.reset(new Language());
    219144
     145        // Do this soon after the ConfigFileManager has been created to open up the
     146        // possibility to configure everything below here
     147        ClassIdentifier<Core>::getIdentifier("Core")->initialiseObject(this, "Core", true);
     148        // Remove us from the object lists again to avoid problems when destroying the Core
     149        this->unregisterObject();
     150        this->setConfigValues();
     151
    220152        // create persistent io console
    221153        this->ioConsole_.reset(new IOConsole());
     
    223155        // creates the class hierarchy for all classes with factories
    224156        Identifier::createClassHierarchy();
    225 
    226         // Do this soon after the ConfigFileManager has been created to open up the
    227         // possibility to configure everything below here
    228         this->configuration_->initialise();
    229157
    230158        // Load OGRE excluding the renderer and the render window
     
    247175    }
    248176
     177    //! Function to collect the SetConfigValue-macro calls.
     178    void Core::setConfigValues()
     179    {
     180#ifdef ORXONOX_RELEASE
     181        const unsigned int defaultLevelLogFile = 3;
     182#else
     183        const unsigned int defaultLevelLogFile = 4;
     184#endif
     185        SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevelLogFile_, "softDebugLevelLogFile", "OutputHandler", defaultLevelLogFile)
     186            .description("The maximum level of debug output shown in the log file");
     187        OutputHandler::getInstance().setSoftDebugLevel(OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_);
     188
     189        SetConfigValue(language_, Language::getInstance().defaultLanguage_)
     190            .description("The language of the in game text")
     191            .callback(this, &Core::languageChanged);
     192        SetConfigValue(bInitRandomNumberGenerator_, true)
     193            .description("If true, all random actions are different each time you start the game")
     194            .callback(this, &Core::initRandomNumberGenerator);
     195    }
     196
     197    //! Callback function if the language has changed.
     198    void Core::languageChanged()
     199    {
     200        // Read the translation file after the language was configured
     201        Language::getInstance().readTranslatedLanguageFile();
     202    }
     203
     204    void Core::initRandomNumberGenerator()
     205    {
     206        static bool bInitialized = false;
     207        if (!bInitialized && this->bInitRandomNumberGenerator_)
     208        {
     209            srand(static_cast<unsigned int>(time(0)));
     210            rand();
     211            bInitialized = true;
     212        }
     213    }
     214
    249215    void Core::loadGraphics()
    250216    {
     
    296262    }
    297263
    298     /**
    299         @brief Returns the configured language.
    300     */
    301     /*static*/ const std::string& Core::getLanguage()
    302     {
    303         return Core::getInstance().configuration_->language_;
    304     }
    305 
    306     /**
    307         @brief Sets the language in the config-file back to the default.
    308     */
    309     /*static*/ void Core::resetLanguage()
    310     {
    311         Core::getInstance().configuration_->resetLanguage();
     264    //! Sets the language in the config-file back to the default.
     265    void Core::resetLanguage()
     266    {
     267        ResetConfigValue(language_);
    312268    }
    313269
Note: See TracChangeset for help on using the changeset viewer.