Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 25, 2009, 10:23:58 PM (14 years ago)
Author:
rgrieder
Message:

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/Core.cc

    r6105 r6417  
    5151#include "util/Debug.h"
    5252#include "util/Exception.h"
     53#include "util/Scope.h"
    5354#include "util/SignalHandler.h"
    5455#include "PathConfig.h"
     
    7879    SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
    7980#ifdef ORXONOX_PLATFORM_WINDOWS
    80     SetCommandLineArgument(limitToCPU, 0).information("Limits the program to one cpu/core (1, 2, 3, etc.). 0 turns it off (default)");
    81 #endif
    82 
    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 
     81    SetCommandLineArgument(limitToCPU, 1).information("Limits the program to one CPU/core (1, 2, 3, etc.). Default is the first core (faster than off)");
     82#endif
    15783
    15884    Core::Core(const std::string& cmdLine)
     
    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        this->setConfigValues();
     149
    220150        // create persistent io console
    221151        this->ioConsole_.reset(new IOConsole());
     
    223153        // creates the class hierarchy for all classes with factories
    224154        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();
    229155
    230156        // Load OGRE excluding the renderer and the render window
     
    245171    Core::~Core()
    246172    {
     173        // Remove us from the object lists again to avoid problems when destroying them
     174        this->unregisterObject();
     175    }
     176
     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(this, &this->softDebugLevelLogFile_, ConfigFileType::Settings, "OutputHandler", "softDebugLevelLogFile", 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        }
    247213    }
    248214
     
    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
     
    360316    void Core::preUpdate(const Clock& time)
    361317    {
    362         // singletons from other libraries
    363         ScopedSingletonManager::update<ScopeID::Root>(time);
     318        // Update singletons before general ticking
     319        ScopedSingletonManager::preUpdate<ScopeID::Root>(time);
    364320        if (this->bGraphicsLoaded_)
    365321        {
    366             // process input events
    367             this->inputManager_->update(time);
    368             // process gui events
    369             this->guiManager_->update(time);
    370             // graphics singletons from other libraries
    371             ScopedSingletonManager::update<ScopeID::Graphics>(time);
    372         }
    373         // process console text
    374         this->ioConsole_->update(time);
    375         // process thread commands
    376         this->tclThreadManager_->update(time);
     322            // Process input events
     323            this->inputManager_->preUpdate(time);
     324            // Update GUI
     325            this->guiManager_->preUpdate(time);
     326            // Update singletons before general ticking
     327            ScopedSingletonManager::preUpdate<ScopeID::Graphics>(time);
     328        }
     329        // Process console events and status line
     330        this->ioConsole_->preUpdate(time);
     331        // Process thread commands
     332        this->tclThreadManager_->preUpdate(time);
    377333    }
    378334
    379335    void Core::postUpdate(const Clock& time)
    380336    {
     337        // Update singletons just before rendering
     338        ScopedSingletonManager::postUpdate<ScopeID::Root>(time);
    381339        if (this->bGraphicsLoaded_)
    382340        {
     341            // Update singletons just before rendering
     342            ScopedSingletonManager::postUpdate<ScopeID::Graphics>(time);
    383343            // Render (doesn't throw)
    384             this->graphicsManager_->update(time);
     344            this->graphicsManager_->postUpdate(time);
    385345        }
    386346    }
Note: See TracChangeset for help on using the changeset viewer.