Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 17, 2011, 5:47:22 AM (13 years ago)
Author:
rgrieder
Message:

Stripped down trunk to form a new light sandbox.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/forks/sandbox_light/src/libraries/core/Core.cc

    r7872 r7908  
    5151#endif
    5252
    53 #include "util/Clock.h"
    5453#include "util/Debug.h"
    55 #include "util/Exception.h"
    56 #include "util/Scope.h"
    57 #include "util/ScopedSingletonManager.h"
    5854#include "util/SignalHandler.h"
    5955#include "PathConfig.h"
    6056#include "CommandLineParser.h"
    61 #include "ConfigFileManager.h"
    62 #include "ConfigValueIncludes.h"
    63 #include "CoreIncludes.h"
    64 #include "DynLibManager.h"
    65 #include "GameMode.h"
    66 #include "GraphicsManager.h"
    67 #include "GUIManager.h"
    68 #include "Identifier.h"
    69 #include "Language.h"
    70 #include "LuaState.h"
    71 #include "command/ConsoleCommand.h"
    72 #include "command/IOConsole.h"
    73 #include "command/TclBind.h"
    74 #include "command/TclThreadManager.h"
    75 #include "input/InputManager.h"
    7657
    7758namespace orxonox
     
    8061    Core* Core::singletonPtr_s  = 0;
    8162
    82     SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
    83     SetCommandLineSwitch(noIOConsole).information("Use this if you don't want to use the IOConsole (for instance for Lua debugging)");
    84 
    8563#ifdef ORXONOX_PLATFORM_WINDOWS
    8664    SetCommandLineArgument(limitToCPU, 1).information("Limits the program to one CPU/core (1, 2, 3, etc.). Default is the first core (faster than off)");
     
    8866
    8967    Core::Core(const std::string& cmdLine)
    90         // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands)
    91         : identifierDestroyer_(Identifier::destroyAllIdentifiers)
    92         // Cleanup guard for external console commands that don't belong to an Identifier
    93         , consoleCommandDestroyer_(ConsoleCommand::destroyAll)
    94         , bGraphicsLoaded_(false)
    95         , bStartIOConsole_(true)
    96         , lastLevelTimestamp_(0)
    97         , ogreConfigTimestamp_(0)
    9868    {
    9969        // Set the hard coded fixed paths
    10070        this->pathConfig_.reset(new PathConfig());
    101 
    102         // Create a new dynamic library manager
    103         this->dynLibManager_.reset(new DynLibManager());
    104 
    105         // Load modules
    106         const std::vector<std::string>& modulePaths = this->pathConfig_->getModulePaths();
    107         for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it)
    108         {
    109             try
    110             {
    111                 this->dynLibManager_->load(*it);
    112             }
    113             catch (...)
    114             {
    115                 COUT(1) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << std::endl;
    116             }
    117         }
    11871
    11972        // Parse command line arguments AFTER the modules have been loaded (static code!)
     
    14396#endif
    14497
    145         // Manage ini files and set the default settings file (usually orxonox.ini)
    146         this->configFileManager_.reset(new ConfigFileManager());
    147         this->configFileManager_->setFilename(ConfigFileType::Settings,
    148             CommandLineParser::getValue("settingsFile").getString());
    149 
    150         // Required as well for the config values
    151         this->languageInstance_.reset(new Language());
    152 
    153         // Do this soon after the ConfigFileManager has been created to open up the
    154         // possibility to configure everything below here
    155         ClassIdentifier<Core>::getIdentifier("Core")->initialiseObject(this, "Core", true);
    156         this->setConfigValues();
    157 
    158         // create persistent io console
    159         if (CommandLineParser::getValue("noIOConsole").getBool())
    160         {
    161             ModifyConfigValue(bStartIOConsole_, tset, false);
    162         }
    163         if (this->bStartIOConsole_)
    164             this->ioConsole_.reset(new IOConsole());
    165 
    166         // creates the class hierarchy for all classes with factories
    167         Identifier::createClassHierarchy();
    168 
    169         // Load OGRE excluding the renderer and the render window
    170         this->graphicsManager_.reset(new GraphicsManager(false));
    171 
    172         // initialise Tcl
    173         this->tclBind_.reset(new TclBind(PathConfig::getDataPathString()));
    174         this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter()));
    175 
    176         // Create singletons that always exist (in other libraries)
    177         this->rootScope_.reset(new Scope<ScopeID::Root>());
    178 
    17998        // Generate documentation instead of normal run?
    18099        std::string docFilename;
     
    199118    Core::~Core()
    200119    {
    201         // Remove us from the object lists again to avoid problems when destroying them
    202         this->unregisterObject();
    203     }
    204 
    205     //! Function to collect the SetConfigValue-macro calls.
    206     void Core::setConfigValues()
    207     {
    208 #ifdef ORXONOX_RELEASE
    209         const unsigned int defaultLevelLogFile = 3;
    210 #else
    211         const unsigned int defaultLevelLogFile = 4;
    212 #endif
    213         SetConfigValueExternal(softDebugLevelLogFile_, "OutputHandler", "softDebugLevelLogFile", defaultLevelLogFile)
    214             .description("The maximum level of debug output shown in the log file");
    215         OutputHandler::getInstance().setSoftDebugLevel(OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_);
    216 
    217         SetConfigValue(language_, Language::getInstance().defaultLanguage_)
    218             .description("The language of the in game text")
    219             .callback(this, &Core::languageChanged);
    220         SetConfigValue(bInitRandomNumberGenerator_, true)
    221             .description("If true, all random actions are different each time you start the game")
    222             .callback(this, &Core::initRandomNumberGenerator);
    223         SetConfigValue(bStartIOConsole_, true)
    224             .description("Set to false if you don't want to use the IOConsole (for Lua debugging for instance)");
    225         SetConfigValue(lastLevelTimestamp_, 0)
    226             .description("Timestamp when the last level was started.");
    227         SetConfigValue(ogreConfigTimestamp_, 0)
    228             .description("Timestamp when the ogre config file was changed.");
    229     }
    230 
    231     //! Callback function if the language has changed.
    232     void Core::languageChanged()
    233     {
    234         // Read the translation file after the language was configured
    235         Language::getInstance().readTranslatedLanguageFile();
    236120    }
    237121
     
    245129            bInitialized = true;
    246130        }
    247     }
    248 
    249     void Core::loadGraphics()
    250     {
    251         // Any exception should trigger this, even in upgradeToGraphics (see its remarks)
    252         Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics);
    253 
    254         // Upgrade OGRE to receive a render window
    255         try
    256         {
    257             graphicsManager_->upgradeToGraphics();
    258         }
    259         catch (const InitialisationFailedException&)
    260         {
    261             // Exit the application if the Ogre config dialog was canceled
    262             COUT(1) << Exception::handleMessage() << std::endl;
    263             exit(EXIT_FAILURE);
    264         }
    265         catch (...)
    266         {
    267             // Recovery from this is very difficult. It requires to completely
    268             // destroy Ogre related objects and load again (without graphics).
    269             // However since Ogre 1.7 there seems to be a problem when Ogre
    270             // throws an exception and the graphics engine then gets destroyed
    271             // and reloaded between throw and catch (access violation in MSVC).
    272             // That's why we abort completely and only display the exception.
    273             COUT(1) << "An exception occurred during upgrade to graphics. "
    274                     << "That is unrecoverable. The message was:" << endl
    275                     << Exception::handleMessage() << endl;
    276             abort();
    277         }
    278 
    279         // Calls the InputManager which sets up the input devices.
    280         inputManager_.reset(new InputManager());
    281 
    282         // Load the CEGUI interface
    283         guiManager_.reset(new GUIManager(inputManager_->getMousePosition()));
    284 
    285         bGraphicsLoaded_ = true;
    286         GameMode::bShowsGraphics_s = true;
    287 
    288         // Load some sort of a debug overlay (only denoted by its name, "debug.oxo")
    289         graphicsManager_->loadDebugOverlay();
    290 
    291         // Create singletons associated with graphics (in other libraries)
    292         graphicsScope_.reset(new Scope<ScopeID::Graphics>());
    293 
    294         unloader.Dismiss();
    295     }
    296 
    297     void Core::unloadGraphics()
    298     {
    299         this->graphicsScope_.reset();
    300         this->guiManager_.reset();
    301         this->inputManager_.reset();
    302         this->graphicsManager_.reset();
    303 
    304         // Load Ogre::Root again, but without the render system
    305         try
    306             { this->graphicsManager_.reset(new GraphicsManager(false)); }
    307         catch (...)
    308         {
    309             COUT(0) << "An exception occurred during 'unloadGraphics':" << Exception::handleMessage() << std::endl
    310                     << "Another exception might be being handled which may lead to undefined behaviour!" << std::endl
    311                     << "Terminating the program." << std::endl;
    312             abort();
    313         }
    314 
    315         bGraphicsLoaded_ = false;
    316         GameMode::bShowsGraphics_s = false;
    317     }
    318 
    319     //! Sets the language in the config-file back to the default.
    320     void Core::resetLanguage()
    321     {
    322         ResetConfigValue(language_);
    323131    }
    324132
     
    368176#endif
    369177    }
    370 
    371     void Core::preUpdate(const Clock& time)
    372     {
    373         // Update singletons before general ticking
    374         ScopedSingletonManager::preUpdate<ScopeID::Root>(time);
    375         if (this->bGraphicsLoaded_)
    376         {
    377             // Process input events
    378             this->inputManager_->preUpdate(time);
    379             // Update GUI
    380             this->guiManager_->preUpdate(time);
    381             // Update singletons before general ticking
    382             ScopedSingletonManager::preUpdate<ScopeID::Graphics>(time);
    383         }
    384         // Process console events and status line
    385         if (this->ioConsole_ != NULL)
    386             this->ioConsole_->preUpdate(time);
    387         // Process thread commands
    388         this->tclThreadManager_->preUpdate(time);
    389     }
    390 
    391     void Core::postUpdate(const Clock& time)
    392     {
    393         // Update singletons just before rendering
    394         ScopedSingletonManager::postUpdate<ScopeID::Root>(time);
    395         if (this->bGraphicsLoaded_)
    396         {
    397             // Update singletons just before rendering
    398             ScopedSingletonManager::postUpdate<ScopeID::Graphics>(time);
    399             // Render (doesn't throw)
    400             this->graphicsManager_->postUpdate(time);
    401         }
    402     }
    403 
    404     void Core::updateLastLevelTimestamp()
    405     {
    406         ModifyConfigValue(lastLevelTimestamp_, set, static_cast<long long>(time(NULL)));
    407     }
    408 
    409     void Core::updateOgreConfigTimestamp()
    410     {
    411         ModifyConfigValue(ogreConfigTimestamp_, set, static_cast<long long>(time(NULL)));
    412     }
    413178}
Note: See TracChangeset for help on using the changeset viewer.