Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 24, 2009, 11:02:42 AM (15 years ago)
Author:
rgrieder
Message:

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

File:
1 edited

Legend:

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

    r5774 r5781  
    6363#include "util/SignalHandler.h"
    6464#include "Clock.h"
     65#include "CommandExecutor.h"
    6566#include "CommandLine.h"
    6667#include "ConfigFileManager.h"
     
    6970#include "DynLibManager.h"
    7071#include "Factory.h"
     72#include "GameMode.h"
     73#include "GraphicsManager.h"
     74#include "GUIManager.h"
    7175#include "Identifier.h"
    7276#include "Language.h"
    7377#include "LuaState.h"
     78#include "Shell.h"
     79#include "TclBind.h"
     80#include "TclThreadManager.h"
     81#include "input/InputManager.h"
    7482
    7583// Boost 1.36 has some issues with deprecated functions that have been omitted
     
    109117            RegisterRootObject(CoreConfiguration);
    110118            this->setConfigValues();
     119
     120            // External data directory only exists for dev runs
     121            if (Core::isDevelopmentRun())
     122            {
     123                // Possible data path override by the command line
     124                if (!CommandLine::getArgument("externalDataPath")->hasDefaultValue())
     125                    tsetExternalDataPath(CommandLine::getValue("externalDataPath"));
     126            }
    111127        }
    112128
     
    178194        }
    179195
     196        /**
     197        @brief
     198            Temporary sets the external data path
     199        @param path
     200            The new data path
     201        */
     202        void tsetExternalDataPath(const std::string& path)
     203        {
     204            externalDataPath_ = boost::filesystem::path(path);
     205        }
     206
    180207        void initializeRandomNumberGenerator()
    181208        {
     
    201228        boost::filesystem::path modulePath_;            //!< Path to the modules
    202229        boost::filesystem::path dataPath_;              //!< Path to the data file folder
     230        boost::filesystem::path externalDataPath_;      //!< Path to the external data file folder
    203231        boost::filesystem::path configPath_;            //!< Path to the config file folder
    204232        boost::filesystem::path logPath_;               //!< Path to the log file folder
     
    209237        // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands)
    210238        : identifierDestroyer_(Identifier::destroyAllIdentifiers)
     239        // Cleanup guard for external console commands that don't belong to an Identifier
     240        , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands)
    211241        , configuration_(new CoreConfiguration()) // Don't yet create config values!
    212242        , bDevRun_(false)
     243        , bGraphicsLoaded_(false)
    213244    {
    214245        // Set the hard coded fixed paths
     
    308339        // possibility to configure everything below here
    309340        this->configuration_->initialise();
     341
     342        // Load OGRE excluding the renderer and the render window
     343        this->graphicsManager_.reset(new GraphicsManager(false));
     344
     345        // initialise Tcl
     346        this->tclBind_.reset(new TclBind(Core::getDataPathString()));
     347        this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter()));
     348
     349        // create a shell
     350        this->shell_.reset(new Shell());
    310351    }
    311352
     
    316357    Core::~Core()
    317358    {
     359    }
     360
     361    void Core::loadGraphics()
     362    {
     363        // Any exception should trigger this, even in upgradeToGraphics (see its remarks)
     364        Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics);
     365
     366        // Upgrade OGRE to receive a render window
     367        graphicsManager_->upgradeToGraphics();
     368
     369        // Calls the InputManager which sets up the input devices.
     370        inputManager_.reset(new InputManager());
     371
     372        // load the CEGUI interface
     373        guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(),
     374            inputManager_->getMousePosition(), graphicsManager_->isFullScreen()));
     375
     376        unloader.Dismiss();
     377
     378        bGraphicsLoaded_ = true;
     379    }
     380
     381    void Core::unloadGraphics()
     382    {
     383        this->guiManager_.reset();;
     384        this->inputManager_.reset();;
     385        this->graphicsManager_.reset();
     386
     387        // Load Ogre::Root again, but without the render system
     388        try
     389            { this->graphicsManager_.reset(new GraphicsManager(false)); }
     390        catch (...)
     391        {
     392            COUT(0) << "An exception occurred during 'unloadGraphics':" << Exception::handleMessage() << std::endl
     393                    << "Another exception might be being handled which may lead to undefined behaviour!" << std::endl
     394                    << "Terminating the program." << std::endl;
     395            abort();
     396        }
     397
     398        bGraphicsLoaded_ = false;
    318399    }
    319400
     
    376457    }
    377458
     459    /*static*/ void Core::tsetExternalDataPath(const std::string& path)
     460    {
     461        getInstance().configuration_->tsetExternalDataPath(path);
     462    }
     463
    378464    /*static*/ const boost::filesystem::path& Core::getDataPath()
    379465    {
     
    383469    {
    384470        return getInstance().configuration_->dataPath_.string() + '/';
     471    }
     472
     473    /*static*/ const boost::filesystem::path& Core::getExternalDataPath()
     474    {
     475        return getInstance().configuration_->externalDataPath_;
     476    }
     477    /*static*/ std::string Core::getExternalDataPathString()
     478    {
     479        return getInstance().configuration_->externalDataPath_.string() + '/';
    385480    }
    386481
     
    564659        {
    565660            configuration_->dataPath_  = specialConfig::dataDevDirectory;
     661            configuration_->externalDataPath_ = specialConfig::externalDataDevDirectory;
    566662            configuration_->configPath_ = specialConfig::configDevDirectory;
    567663            configuration_->logPath_    = specialConfig::logDevDirectory;
     
    629725    void Core::preUpdate(const Clock& time)
    630726    {
     727        if (this->bGraphicsLoaded_)
     728        {
     729            // process input events
     730            this->inputManager_->update(time);
     731            // process gui events
     732            this->guiManager_->update(time);
     733        }
     734        // process thread commands
     735        this->tclThreadManager_->update(time);
    631736    }
    632737
    633738    void Core::postUpdate(const Clock& time)
    634739    {
     740        if (this->bGraphicsLoaded_)
     741        {
     742            // Render (doesn't throw)
     743            this->graphicsManager_->update(time);
     744        }
    635745    }
    636746}
Note: See TracChangeset for help on using the changeset viewer.