Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 12, 2010, 12:47:30 AM (14 years ago)
Author:
rgrieder
Message:

Basic stuff up and running for the Qt sandbox.
No GUI support yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox_qt/src/libraries/core/Core.cc

    r7401 r7421  
    3131@file
    3232@brief
    33     Implementation of the Core singleton with its global variables (avoids boost include)
     33    Implementation of the Core singleton
    3434*/
    3535
     
    3737
    3838#include <cassert>
     39#include <ctime>
    3940#include <fstream>
    4041#include <vector>
     
    4950#endif
    5051
    51 #include "util/Clock.h"
    5252#include "util/Debug.h"
    5353#include "util/Exception.h"
    54 #include "util/Scope.h"
    55 #include "util/ScopedSingletonManager.h"
    56 #include "util/SignalHandler.h"
    5754#include "PathConfig.h"
    58 #include "CommandLineParser.h"
    59 #include "ConfigFileManager.h"
    60 #include "ConfigValueIncludes.h"
    61 #include "CoreIncludes.h"
    62 #include "DynLibManager.h"
    63 #include "GameMode.h"
    64 #include "GraphicsManager.h"
    65 #include "GUIManager.h"
    66 #include "Identifier.h"
    67 #include "Language.h"
    68 #include "LuaState.h"
    69 #include "command/ConsoleCommand.h"
    70 #include "command/IOConsole.h"
    71 #include "command/TclBind.h"
    72 #include "command/TclThreadManager.h"
    73 #include "input/InputManager.h"
    7455
    7556namespace orxonox
     
    7859    Core* Core::singletonPtr_s  = 0;
    7960
    80     SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
    81     SetCommandLineSwitch(noIOConsole).information("Use this if you don't want to use the IOConsole (for instance for Lua debugging)");
    82 
    83 #ifdef ORXONOX_PLATFORM_WINDOWS
    84     SetCommandLineArgument(limitToCPU, 1).information("Limits the program to one CPU/core (1, 2, 3, etc.). Default is the first core (faster than off)");
    85 #endif
    86 
    8761    Core::Core(const std::string& cmdLine)
    88         // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands)
    89         : identifierDestroyer_(Identifier::destroyAllIdentifiers)
    90         // Cleanup guard for external console commands that don't belong to an Identifier
    91         , consoleCommandDestroyer_(ConsoleCommand::destroyAll)
    92         , bGraphicsLoaded_(false)
    93         , bStartIOConsole_(true)
    9462    {
    9563        // Set the hard coded fixed paths
    9664        this->pathConfig_.reset(new PathConfig());
    9765
    98         // Create a new dynamic library manager
    99         this->dynLibManager_.reset(new DynLibManager());
    100 
    101         // Load modules
    102         const std::vector<std::string>& modulePaths = this->pathConfig_->getModulePaths();
    103         for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it)
    104         {
    105             try
    106             {
    107                 this->dynLibManager_->load(*it);
    108             }
    109             catch (...)
    110             {
    111                 COUT(1) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << std::endl;
    112             }
    113         }
    114 
    115         // Parse command line arguments AFTER the modules have been loaded (static code!)
    116         CommandLineParser::parseCommandLine(cmdLine);
    117 
    11866        // Set configurable paths like log, config and media
    11967        this->pathConfig_->setConfigurablePaths();
    120 
    121         // create a signal handler (only active for Linux)
    122         // This call is placed as soon as possible, but after the directories are set
    123         this->signalHandler_.reset(new SignalHandler());
    124         this->signalHandler_->doCatch(PathConfig::getExecutablePathString(), PathConfig::getLogPathString() + "orxonox_crash.log");
    12568
    12669        // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% (Windows) was used
    12770        OutputHandler::getInstance().setLogPath(PathConfig::getLogPathString());
    12871
    129         // Parse additional options file now that we know its path
    130         CommandLineParser::parseFile();
    131 
    13272#ifdef ORXONOX_PLATFORM_WINDOWS
    13373        // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
    134         // do this after ogre has initialised. Somehow Ogre changes the settings again (not through
    135         // the timer though).
    136         int limitToCPU = CommandLineParser::getValue("limitToCPU");
     74        int limitToCPU = 0;//CommandLineParser::getValue("limitToCPU");
    13775        if (limitToCPU > 0)
    13876            setThreadAffinity(static_cast<unsigned int>(limitToCPU));
    13977#endif
    14078
    141         // Manage ini files and set the default settings file (usually orxonox.ini)
    142         this->configFileManager_.reset(new ConfigFileManager());
    143         this->configFileManager_->setFilename(ConfigFileType::Settings,
    144             CommandLineParser::getValue("settingsFile").getString());
    145 
    146         // Required as well for the config values
    147         this->languageInstance_.reset(new Language());
    148 
    149         // Do this soon after the ConfigFileManager has been created to open up the
    150         // possibility to configure everything below here
    151         ClassIdentifier<Core>::getIdentifier("Core")->initialiseObject(this, "Core", true);
    152         this->setConfigValues();
    153 
    154         // create persistent io console
    155         if (CommandLineParser::getValue("noIOConsole").getBool())
    156         {
    157             ModifyConfigValue(bStartIOConsole_, tset, false);
    158         }
    159         if (this->bStartIOConsole_)
    160             this->ioConsole_.reset(new IOConsole());
    161 
    162         // creates the class hierarchy for all classes with factories
    163         Identifier::createClassHierarchy();
    164 
    165         // Load OGRE excluding the renderer and the render window
    166         this->graphicsManager_.reset(new GraphicsManager(false));
    167 
    168         // initialise Tcl
    169         this->tclBind_.reset(new TclBind(PathConfig::getDataPathString()));
    170         this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter()));
    171 
    172         // Create singletons that always exist (in other libraries)
    173         this->rootScope_.reset(new Scope<ScopeID::Root>());
    174 
    17579        // Generate documentation instead of normal run?
    17680        std::string docFilename;
    177         CommandLineParser::getValue("generateDoc", &docFilename);
     81        //CommandLineParser::getValue("generateDoc", &docFilename);
    17882        if (!docFilename.empty())
    17983        {
     
    18185            if (docFile.is_open())
    18286            {
    183                 CommandLineParser::generateDoc(docFile);
     87                //CommandLineParser::generateDoc(docFile);
    18488                docFile.close();
    18589            }
     
    19195    /**
    19296    @brief
    193         All destruction code is handled by scoped_ptrs and ScopeGuards.
     97        All destruction code is handled by QScopedPointers
    19498    */
    19599    Core::~Core()
    196100    {
    197         // Remove us from the object lists again to avoid problems when destroying them
    198         this->unregisterObject();
    199101    }
    200102
     
    207109        const unsigned int defaultLevelLogFile = 4;
    208110#endif
     111        /*
    209112        SetConfigValueExternal(softDebugLevelLogFile_, "OutputHandler", "softDebugLevelLogFile", defaultLevelLogFile)
    210113            .description("The maximum level of debug output shown in the log file");
     
    219122        SetConfigValue(bStartIOConsole_, true)
    220123            .description("Set to false if you don't want to use the IOConsole (for Lua debugging for instance)");
    221     }
    222 
    223     //! Callback function if the language has changed.
    224     void Core::languageChanged()
    225     {
    226         // Read the translation file after the language was configured
    227         Language::getInstance().readTranslatedLanguageFile();
     124        */
    228125    }
    229126
     
    237134            bInitialized = true;
    238135        }
    239     }
    240 
    241     void Core::loadGraphics()
    242     {
    243         // Any exception should trigger this, even in upgradeToGraphics (see its remarks)
    244         Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics);
    245 
    246         // Upgrade OGRE to receive a render window
    247         try
    248         {
    249             graphicsManager_->upgradeToGraphics();
    250         }
    251         catch (...)
    252         {
    253             // Recovery from this is very difficult. It requires to completely
    254             // destroy Ogre related objects and load again (without graphics).
    255             // However since Ogre 1.7 there seems to be a problem when Ogre
    256             // throws an exception and the graphics engine then gets destroyed
    257             // and reloaded between throw and catch (access violation in MSVC).
    258             // That's why we abort completely and only display the exception.
    259             COUT(0) << "An exception occurred during upgrade to graphics. "
    260                     << "That is unrecoverable. The message was:" << endl
    261                     << Exception::handleMessage() << endl;
    262             abort();
    263         }
    264 
    265         // Calls the InputManager which sets up the input devices.
    266         inputManager_.reset(new InputManager());
    267 
    268         // Load the CEGUI interface
    269         guiManager_.reset(new GUIManager(inputManager_->getMousePosition()));
    270 
    271         bGraphicsLoaded_ = true;
    272         GameMode::bShowsGraphics_s = true;
    273 
    274         // Load some sort of a debug overlay (only denoted by its name, "debug.oxo")
    275         graphicsManager_->loadDebugOverlay();
    276 
    277         // Create singletons associated with graphics (in other libraries)
    278         graphicsScope_.reset(new Scope<ScopeID::Graphics>());
    279 
    280         unloader.Dismiss();
    281     }
    282 
    283     void Core::unloadGraphics()
    284     {
    285         this->graphicsScope_.reset();
    286         this->guiManager_.reset();
    287         this->inputManager_.reset();
    288         this->graphicsManager_.reset();
    289 
    290         // Load Ogre::Root again, but without the render system
    291         try
    292             { this->graphicsManager_.reset(new GraphicsManager(false)); }
    293         catch (...)
    294         {
    295             COUT(0) << "An exception occurred during 'unloadGraphics':" << Exception::handleMessage() << std::endl
    296                     << "Another exception might be being handled which may lead to undefined behaviour!" << std::endl
    297                     << "Terminating the program." << std::endl;
    298             abort();
    299         }
    300 
    301         bGraphicsLoaded_ = false;
    302         GameMode::bShowsGraphics_s = false;
    303     }
    304 
    305     //! Sets the language in the config-file back to the default.
    306     void Core::resetLanguage()
    307     {
    308         ResetConfigValue(language_);
    309136    }
    310137
     
    354181#endif
    355182    }
    356 
    357     void Core::preUpdate(const Clock& time)
    358     {
    359         // Update singletons before general ticking
    360         ScopedSingletonManager::preUpdate<ScopeID::Root>(time);
    361         if (this->bGraphicsLoaded_)
    362         {
    363             // Process input events
    364             this->inputManager_->preUpdate(time);
    365             // Update GUI
    366             this->guiManager_->preUpdate(time);
    367             // Update singletons before general ticking
    368             ScopedSingletonManager::preUpdate<ScopeID::Graphics>(time);
    369         }
    370         // Process console events and status line
    371         if (this->ioConsole_ != NULL)
    372             this->ioConsole_->preUpdate(time);
    373         // Process thread commands
    374         this->tclThreadManager_->preUpdate(time);
    375     }
    376 
    377     void Core::postUpdate(const Clock& time)
    378     {
    379         // Update singletons just before rendering
    380         ScopedSingletonManager::postUpdate<ScopeID::Root>(time);
    381         if (this->bGraphicsLoaded_)
    382         {
    383             // Update singletons just before rendering
    384             ScopedSingletonManager::postUpdate<ScopeID::Graphics>(time);
    385             // Render (doesn't throw)
    386             this->graphicsManager_->postUpdate(time);
    387         }
    388     }
    389183}
Note: See TracChangeset for help on using the changeset viewer.