Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6121


Ignore:
Timestamp:
Nov 23, 2009, 6:19:58 PM (14 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".

Location:
code/branches/presentation2/src/libraries/core
Files:
8 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
  • code/branches/presentation2/src/libraries/core/Core.h

    r6105 r6121  
    3535#include <cassert>
    3636#include <boost/scoped_ptr.hpp>
    37 #include "util/OutputHandler.h"
    38 #include "util/Scope.h"
    3937#include "util/ScopeGuard.h"
    4038#include "util/Singleton.h"
     39#include "core/OrxonoxClass.h"
    4140
    4241namespace orxonox
    4342{
    44     class CoreConfiguration;
    45 
    4643    /**
    4744    @brief
     
    5047        You should only create this singleton once because it destroys the identifiers!
    5148    */
    52     class _CoreExport Core : public Singleton<Core>
     49    class _CoreExport Core : public Singleton<Core>, public OrxonoxClass
    5350    {
    5451        typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard;
     
    6966            void setConfigValues();
    7067
    71             static const std::string& getLanguage();
    72             static void  resetLanguage();
     68            //! Returns the configured language.
     69            const std::string& getLanguage()
     70                { return this->language_; }
     71            void resetLanguage();
    7372
    7473        private:
    7574            Core(const Core&); //!< Don't use (undefined symbol)
     75
     76            void languageChanged();
     77            void initRandomNumberGenerator();
    7678
    7779            void preUpdate(const Clock& time);
     
    8284
    8385            void setThreadAffinity(int limitToCPU);
    84 
     86            // MANAGED SINGLETONS/OBJECTS
    8587            // Mind the order for the destruction!
    8688            scoped_ptr<PathConfig>        pathConfig_;
     
    9294            scoped_ptr<Language>          languageInstance_;
    9395            scoped_ptr<IOConsole>         ioConsole_;
    94             scoped_ptr<CoreConfiguration> configuration_;
    9596            scoped_ptr<TclBind>           tclBind_;
    9697            scoped_ptr<TclThreadManager>  tclThreadManager_;
     98            scoped_ptr<Scope<ScopeID::Root> >     rootScope_;
    9799            // graphical
    98100            scoped_ptr<GraphicsManager>   graphicsManager_;     //!< Interface to OGRE
    99101            scoped_ptr<InputManager>      inputManager_;        //!< Interface to OIS
    100102            scoped_ptr<GUIManager>        guiManager_;          //!< Interface to GUI
    101             scoped_ptr<Scope<ScopeID::Root> >     rootScope_;
    102103            scoped_ptr<Scope<ScopeID::Graphics> > graphicsScope_;
    103104
    104105            bool                          bGraphicsLoaded_;
    105             static Core* singletonPtr_s;
     106            int                           softDebugLevelLogFile_;      //!< The debug level for the log file (belongs to OutputHandler)
     107            std::string                   language_;                   //!< The language
     108            bool                          bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called
     109
     110            static Core*                  singletonPtr_s;
    106111    };
    107112}
  • code/branches/presentation2/src/libraries/core/Game.cc

    r6021 r6121  
    6767    Game* Game::singletonPtr_s = 0;
    6868
    69 
    70     /**
    71     @brief
    72         Represents one node of the game state tree.
    73     */
     69    //! Represents one node of the game state tree.
    7470    struct GameStateTreeNode
    7571    {
     
    7975    };
    8076
    81 
    82     /**
    83     @brief
    84         Another helper class for the Game singleton: we cannot derive
    85         Game from OrxonoxClass because we need to handle the Identifier
    86         destruction in the Core destructor.
    87     */
    88     class GameConfiguration : public OrxonoxClass
    89     {
    90     public:
    91         GameConfiguration()
    92         {
    93             RegisterRootObject(GameConfiguration);
    94             this->setConfigValues();
    95         }
    96 
    97         void setConfigValues()
    98         {
    99             SetConfigValue(statisticsRefreshCycle_, 250000)
    100                 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
    101             SetConfigValue(statisticsAvgLength_, 1000000)
    102                 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
    103             SetConfigValue(fpsLimit_, 50)
    104                 .description("Sets the desired framerate (0 for no limit).");
    105         }
    106 
    107         unsigned int statisticsRefreshCycle_;
    108         unsigned int statisticsAvgLength_;
    109         unsigned int fpsLimit_;
    110     };
    111 
    112 
    113     /**
    114     @brief
    115         Non-initialising constructor.
    116     */
    11777    Game::Game(const std::string& cmdLine)
    11878        // Destroy factories before the Core!
     
    13797        this->core_.reset(new Core(cmdLine));
    13898
     99        // Do this after the Core creation!
     100        ClassIdentifier<Game>::getIdentifier("Game")->initialiseObject(this, "Game", true);
     101        // Remove us from the object lists again to avoid problems when destroying the Game
     102        this->unregisterObject();
     103        this->setConfigValues();
     104
    139105        // After the core has been created, we can safely instantiate the GameStates that don't require graphics
    140106        for (std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.begin();
     
    150116        this->loadedTopStateNode_ = this->rootStateNode_;
    151117        this->loadedStates_.push_back(this->getState(rootStateNode_->name_));
    152 
    153         // Do this after the Core creation!
    154         this->configuration_.reset(new GameConfiguration());
    155118    }
    156119
     
    161124    Game::~Game()
    162125    {
     126    }
     127
     128    void Game::setConfigValues()
     129    {
     130        SetConfigValue(statisticsRefreshCycle_, 250000)
     131            .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
     132        SetConfigValue(statisticsAvgLength_, 1000000)
     133            .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
     134        SetConfigValue(fpsLimit_, 50)
     135            .description("Sets the desired framerate (0 for no limit).");
    163136    }
    164137
     
    312285        this->statisticsTickTimes_.back().tickLength += currentRealTime - currentTime;
    313286        this->periodTickTime_ += currentRealTime - currentTime;
    314         if (this->periodTime_ > this->configuration_->statisticsRefreshCycle_)
     287        if (this->periodTime_ > this->statisticsRefreshCycle_)
    315288        {
    316289            std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
    317290            assert(it != this->statisticsTickTimes_.end());
    318             int64_t lastTime = currentTime - this->configuration_->statisticsAvgLength_;
     291            int64_t lastTime = currentTime - this->statisticsAvgLength_;
    319292            if (static_cast<int64_t>(it->tickTime) < lastTime)
    320293            {
     
    333306            this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f;
    334307
    335             this->periodTime_ -= this->configuration_->statisticsRefreshCycle_;
     308            this->periodTime_ -= this->statisticsRefreshCycle_;
    336309        }
    337310    }
     
    339312    void Game::updateFPSLimiter()
    340313    {
    341         // Why configuration_->fpsLimit_ - 1? No idea, but otherwise the fps rate is always (from 10 to 200!) one frame too high
    342         uint32_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / (configuration_->fpsLimit_ - 1));
     314        // Why fpsLimit_ - 1? No idea, but otherwise the fps rate is always (from 10 to 200!) one frame too high
     315        uint32_t nextTime = gameClock_->getMicroseconds() - excessSleepTime_ + static_cast<uint32_t>(1000000.0f / (fpsLimit_ - 1));
    343316        uint64_t currentRealTime = gameClock_->getRealMicroseconds();
    344317        while (currentRealTime < nextTime - minimumSleepTime_)
  • code/branches/presentation2/src/libraries/core/Game.h

    r5929 r6121  
    5050#include "util/ScopeGuard.h"
    5151#include "util/Singleton.h"
     52#include "core/OrxonoxClass.h"
    5253
    5354/**
     
    6162namespace orxonox
    6263{
    63     class GameConfiguration;
    64 
    6564    //! Helper object required before GameStates are being constructed
    6665    struct GameStateInfo
     
    7877        You should only create this singleton once because it owns the Core class! (see remark there)
    7978    */
    80     class _CoreExport Game : public Singleton<Game>
     79    class _CoreExport Game : public Singleton<Game>, public OrxonoxClass
    8180    {
    8281        friend class Singleton<Game>;
     
    8887        Game(const std::string& cmdLine);
    8988        ~Game();
     89
     90        void setConfigValues();
    9091
    9192        void setStateHierarchy(const std::string& str);
     
    160161        scoped_ptr<Core>                   core_;
    161162        ObjScopeGuard                      gsFactoryDestroyer_;
    162         scoped_ptr<GameConfiguration>      configuration_;
    163163
    164164        GameStateMap                       constructedStates_;
     
    181181        unsigned int                       minimumSleepTime_;
    182182
     183        // config values
     184        unsigned int                       statisticsRefreshCycle_;
     185        unsigned int                       statisticsAvgLength_;
     186        unsigned int                       fpsLimit_;
     187
    183188        static std::map<std::string, GameStateInfo> gameStateDeclarations_s;
    184189        static Game* singletonPtr_s;        //!< Pointer to the Singleton
  • code/branches/presentation2/src/libraries/core/Language.cc

    r5929 r6121  
    246246    void Language::readTranslatedLanguageFile()
    247247    {
    248         COUT(4) << "Read translated language file (" << Core::getLanguage() << ")." << std::endl;
    249 
    250         std::string filepath = PathConfig::getConfigPathString() + getFilename(Core::getLanguage());
     248        COUT(4) << "Read translated language file (" << Core::getInstance().getLanguage() << ")." << std::endl;
     249
     250        std::string filepath = PathConfig::getConfigPathString() + getFilename(Core::getInstance().getLanguage());
    251251
    252252        // Open the file
     
    257257        {
    258258            COUT(1) << "An error occurred in Language.cc:" << std::endl;
    259             COUT(1) << "Error: Couldn't open file " << getFilename(Core::getLanguage()) << " to read the translated language entries!" << std::endl;
    260             Core::resetLanguage();
     259            COUT(1) << "Error: Couldn't open file " << getFilename(Core::getInstance().getLanguage()) << " to read the translated language entries!" << std::endl;
     260            Core::getInstance().resetLanguage();
    261261            COUT(3) << "Info: Reset language to " << this->defaultLanguage_ << "." << std::endl;
    262262            return;
     
    287287                else
    288288                {
    289                     COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFilename(Core::getLanguage()) << std::endl;
     289                    COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFilename(Core::getInstance().getLanguage()) << std::endl;
    290290                }
    291291            }
  • code/branches/presentation2/src/libraries/core/Language.h

    r5738 r6121  
    116116    {
    117117        friend class Singleton<Language>;
    118         friend class CoreConfiguration;
     118        friend class Core;
    119119
    120120        public:
  • code/branches/presentation2/src/libraries/core/OrxonoxClass.cc

    r6105 r6121  
    5959        assert(this->referenceCount_ <= 0);
    6060
    61         delete this->metaList_;
     61        this->unregisterObject();
    6262
    6363        // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class
    6464        if (this->parents_)
    6565            delete this->parents_;
    66            
     66
    6767        // reset all weak pointers pointing to this object
    6868        for (std::set<WeakPtr<OrxonoxClass>*>::iterator it = this->weakPointers_.begin(); it != this->weakPointers_.end(); )
     
    7777        if (this->referenceCount_ == 0)
    7878            delete this;
     79    }
     80
     81    void OrxonoxClass::unregisterObject()
     82    {
     83        if (this->metaList_)
     84            delete this->metaList_;
     85        this->metaList_ = 0;
    7986    }
    8087
  • code/branches/presentation2/src/libraries/core/OrxonoxClass.h

    r6105 r6121  
    7373
    7474            void destroy();
     75            void unregisterObject();
    7576
    7677            /** @brief Function to collect the SetConfigValue-macro calls. */
Note: See TracChangeset for help on using the changeset viewer.