Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 30, 2009, 2:22:00 AM (15 years ago)
Author:
rgrieder
Message:

Merged resource2 branch back to trunk.

IMPORTANT NOTE:
Upon this merge you need to specifically call your data directory "data_extern" when checking it out (when you don't provide a name, it will be just called 'trunk').
The new CMake variable is EXTERNAL_DATA_DIRECTORY. DATA_DIRECTORY now points to the one the source part of the repository.
UPDATE YOUR DATA DIRECTORY AS WELL!!!

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r5693 r5695  
    4242#include <boost/version.hpp>
    4343#include <boost/filesystem.hpp>
    44 #include <OgreRenderWindow.h>
    4544
    4645#ifdef ORXONOX_PLATFORM_WINDOWS
     
    7675#include "Identifier.h"
    7776#include "Language.h"
    78 #include "LuaBind.h"
     77#include "LuaState.h"
    7978#include "Shell.h"
    8079#include "TclBind.h"
     
    9493    Core* Core::singletonPtr_s  = 0;
    9594
    96     SetCommandLineArgument(mediaPath, "").information("Path to the media/data files");
     95    SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
    9796    SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
    9897    SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
     
    119118            this->setConfigValues();
    120119
    121             // Possible media path override by the command line
    122             if (!CommandLine::getArgument("mediaPath")->hasDefaultValue())
    123                 tsetMediaPath(CommandLine::getValue("mediaPath"));
     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            }
    124127        }
    125128
     
    154157                .description("If true, all random actions are different each time you start the game")
    155158                .callback(this, &CoreConfiguration::initializeRandomNumberGenerator);
    156 
    157             // Only show this config value for development builds
    158             if (Core::isDevelopmentRun())
    159             {
    160                 SetConfigValue(mediaPathString_, mediaPath_.string())
    161                     .description("Relative path to the game data.")
    162                     .callback(this, &CoreConfiguration::mediaPathChanged);
    163             }
    164159        }
    165160
     
    192187
    193188        /**
    194         @brief
    195             Callback function if the media path has changed.
    196         */
    197         void mediaPathChanged()
    198         {
    199             mediaPath_ = boost::filesystem::path(this->mediaPathString_);
    200         }
    201 
    202         /**
    203189            @brief Sets the language in the config-file back to the default.
    204190        */
     
    210196        /**
    211197        @brief
    212             Temporary sets the media path
     198            Temporary sets the data path
    213199        @param path
    214             The new media path
     200            The new data path
    215201        */
    216         void tsetMediaPath(const std::string& path)
    217         {
    218             if (Core::isDevelopmentRun())
    219             {
    220                 ModifyConfigValue(mediaPathString_, tset, path);
    221             }
    222             else
    223             {
    224                 // Manual 'config' value without the file entry
    225                 mediaPathString_ = path;
    226                 this->mediaPathChanged();
    227             }
     202        void tsetExternalDataPath(const std::string& path)
     203        {
     204            dataPath_ = boost::filesystem::path(path);
    228205        }
    229206
     
    245222        std::string language_;                          //!< The language
    246223        bool bInitializeRandomNumberGenerator_;         //!< If true, srand(time(0)) is called
    247         std::string mediaPathString_;                   //!< Path to the data/media file folder as string
    248224
    249225        //! Path to the parent directory of the ones above if program was installed with relativ pahts
     
    251227        boost::filesystem::path executablePath_;        //!< Path to the executable
    252228        boost::filesystem::path modulePath_;            //!< Path to the modules
    253         boost::filesystem::path mediaPath_;             //!< Path to the media file folder
     229        boost::filesystem::path dataPath_;              //!< Path to the data file folder
     230        boost::filesystem::path externalDataPath_;      //!< Path to the external data file folder
    254231        boost::filesystem::path configPath_;            //!< Path to the config file folder
    255232        boost::filesystem::path logPath_;               //!< Path to the log file folder
     
    276253        {
    277254            // We search for helper files with the following extension
    278             std::string moduleextension = ORXONOX_MODULE_EXTENSION;
     255            std::string moduleextension = specialConfig::moduleExtension;
    279256            size_t moduleextensionlength = moduleextension.size();
    280257
     
    364341        this->languageInstance_.reset(new Language());
    365342
     343        // creates the class hierarchy for all classes with factories
     344        Factory::createClassHierarchy();
     345
    366346        // Do this soon after the ConfigFileManager has been created to open up the
    367347        // possibility to configure everything below here
    368348        this->configuration_->initialise();
    369349
    370         // Create the lua interface
    371         this->luaBind_.reset(new LuaBind());
     350        // Load OGRE excluding the renderer and the render window
     351        this->graphicsManager_.reset(new GraphicsManager(false));
    372352
    373353        // initialise Tcl
    374         this->tclBind_.reset(new TclBind(Core::getMediaPathString()));
     354        this->tclBind_.reset(new TclBind(Core::getDataPathString()));
    375355        this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter()));
    376356
    377357        // create a shell
    378358        this->shell_.reset(new Shell());
    379 
    380         // creates the class hierarchy for all classes with factories
    381         Factory::createClassHierarchy();
    382359    }
    383360
    384361    /**
    385362    @brief
    386         All destruction code is handled by scoped_ptrs and SimpleScopeGuards.
     363        All destruction code is handled by scoped_ptrs and ScopeGuards.
    387364    */
    388365    Core::~Core()
     
    392369    void Core::loadGraphics()
    393370    {
    394         if (bGraphicsLoaded_)
    395             return;
    396 
    397         // Load OGRE including the render window
    398         scoped_ptr<GraphicsManager> graphicsManager(new GraphicsManager());
    399 
    400         // The render window width and height are used to set up the mouse movement.
    401         size_t windowHnd = 0;
    402         graphicsManager->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd);
     371        // Any exception should trigger this, even in upgradeToGraphics (see its remarks)
     372        Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics);
     373
     374        // Upgrade OGRE to receive a render window
     375        graphicsManager_->upgradeToGraphics();
    403376
    404377        // Calls the InputManager which sets up the input devices.
    405         scoped_ptr<InputManager> inputManager(new InputManager(windowHnd));
     378        inputManager_.reset(new InputManager());
    406379
    407380        // load the CEGUI interface
    408         guiManager_.reset(new GUIManager(graphicsManager->getRenderWindow()));
    409 
    410         // Dismiss scoped pointers
    411         graphicsManager_.swap(graphicsManager);
    412         inputManager_.swap(inputManager);
     381        guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(),
     382            inputManager_->getMousePosition(), graphicsManager_->isFullScreen()));
     383
     384        unloader.Dismiss();
    413385
    414386        bGraphicsLoaded_ = true;
     
    417389    void Core::unloadGraphics()
    418390    {
    419         if (!bGraphicsLoaded_)
    420             return;
    421 
    422391        this->guiManager_.reset();;
    423392        this->inputManager_.reset();;
    424393        this->graphicsManager_.reset();
     394
     395        // Load Ogre::Root again, but without the render system
     396        try
     397            { this->graphicsManager_.reset(new GraphicsManager(false)); }
     398        catch (...)
     399        {
     400            COUT(0) << "An exception occurred during 'new GraphicsManager' while "
     401                    << "another exception was being handled. This will lead to undefined behaviour!" << std::endl
     402                    << "Terminating the program." << std::endl;
     403            abort();
     404        }
    425405
    426406        bGraphicsLoaded_ = false;
     
    485465    }
    486466
    487     /*static*/ void Core::tsetMediaPath(const std::string& path)
    488     {
    489         getInstance().configuration_->tsetMediaPath(path);
    490     }
    491 
    492     /*static*/ const boost::filesystem::path& Core::getMediaPath()
    493     {
    494         return getInstance().configuration_->mediaPath_;
    495     }
    496     /*static*/ std::string Core::getMediaPathString()
    497     {
    498         return getInstance().configuration_->mediaPath_.string() + '/';
     467    /*static*/ void Core::tsetExternalDataPath(const std::string& path)
     468    {
     469        getInstance().configuration_->tsetExternalDataPath(path);
     470    }
     471
     472    /*static*/ const boost::filesystem::path& Core::getDataPath()
     473    {
     474        return getInstance().configuration_->dataPath_;
     475    }
     476    /*static*/ std::string Core::getDataPathString()
     477    {
     478        return getInstance().configuration_->dataPath_.string() + '/';
     479    }
     480
     481    /*static*/ const boost::filesystem::path& Core::getExternalDataPath()
     482    {
     483        return getInstance().configuration_->externalDataPath_;
     484    }
     485    /*static*/ std::string Core::getExternalDataPathString()
     486    {
     487        return getInstance().configuration_->externalDataPath_.string() + '/';
    499488    }
    500489
     
    638627            COUT(1) << "Running from the build tree." << std::endl;
    639628            Core::bDevRun_ = true;
    640             configuration_->modulePath_ = ORXONOX_MODULE_DEV_PATH;
     629            configuration_->modulePath_ = specialConfig::moduleDevDirectory;
    641630        }
    642631        else
     
    646635
    647636            // Also set the root path
    648             boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH);
     637            boost::filesystem::path relativeExecutablePath(specialConfig::defaultRuntimePath);
    649638            configuration_->rootPath_ = configuration_->executablePath_;
    650639            while (!boost::filesystem::equivalent(configuration_->rootPath_ / relativeExecutablePath, configuration_->executablePath_)
     
    655644
    656645            // Module path is fixed as well
    657             configuration_->modulePath_ = configuration_->rootPath_ / ORXONOX_MODULE_INSTALL_PATH;
     646            configuration_->modulePath_ = configuration_->rootPath_ / specialConfig::defaultModulePath;
    658647
    659648#else
     
    661650            // There is no root path, so don't set it at all
    662651            // Module path is fixed as well
    663             configuration_->modulePath_ = ORXONOX_MODULE_INSTALL_PATH;
     652            configuration_->modulePath_ = specialConfig::moduleInstallDirectory;
    664653
    665654#endif
     
    677666        if (Core::isDevelopmentRun())
    678667        {
    679             configuration_->mediaPath_  = ORXONOX_MEDIA_DEV_PATH;
    680             configuration_->configPath_ = ORXONOX_CONFIG_DEV_PATH;
    681             configuration_->logPath_    = ORXONOX_LOG_DEV_PATH;
     668            configuration_->dataPath_  = specialConfig::dataDevDirectory;
     669            configuration_->externalDataPath_ = specialConfig::externalDataDevDirectory;
     670            configuration_->configPath_ = specialConfig::configDevDirectory;
     671            configuration_->logPath_    = specialConfig::logDevDirectory;
    682672        }
    683673        else
     
    687677
    688678            // Using paths relative to the install prefix, complete them
    689             configuration_->mediaPath_  = configuration_->rootPath_ / ORXONOX_MEDIA_INSTALL_PATH;
    690             configuration_->configPath_ = configuration_->rootPath_ / ORXONOX_CONFIG_INSTALL_PATH;
    691             configuration_->logPath_    = configuration_->rootPath_ / ORXONOX_LOG_INSTALL_PATH;
     679            configuration_->dataPath_   = configuration_->rootPath_ / specialConfig::defaultDataPath;
     680            configuration_->configPath_ = configuration_->rootPath_ / specialConfig::defaultConfigPath;
     681            configuration_->logPath_    = configuration_->rootPath_ / specialConfig::defaultLogPath;
    692682
    693683#else
    694684
    695             configuration_->mediaPath_  = ORXONOX_MEDIA_INSTALL_PATH;
     685            configuration_->dataPath_  = specialConfig::dataInstallDirectory;
    696686
    697687            // Get user directory
     
    706696            userDataPath /= ".orxonox";
    707697
    708             configuration_->configPath_ = userDataPath / ORXONOX_CONFIG_INSTALL_PATH;
    709             configuration_->logPath_    = userDataPath / ORXONOX_LOG_INSTALL_PATH;
     698            configuration_->configPath_ = userDataPath / specialConfig::defaultConfigPath;
     699            configuration_->logPath_    = userDataPath / specialConfig::defaultLogPath;
    710700
    711701#endif
     
    741731    }
    742732
    743     bool Core::preUpdate(const Clock& time) throw()
    744     {
    745         std::string exceptionMessage;
    746         try
    747         {
    748             if (this->bGraphicsLoaded_)
    749             {
    750                 // process input events
    751                 this->inputManager_->update(time);
    752                 // process gui events
    753                 this->guiManager_->update(time);
    754             }
    755             // process thread commands
    756             this->tclThreadManager_->update(time);
    757         }
    758         catch (const std::exception& ex)
    759         { exceptionMessage = ex.what(); }
    760         catch (...)
    761         { exceptionMessage = "Unknown exception"; }
    762         if (!exceptionMessage.empty())
    763         {
    764             COUT(0) << "An exception occurred in the Core preUpdate: " << exceptionMessage << std::endl;
    765             COUT(0) << "This should really never happen! Closing the program." << std::endl;
    766             return false;
    767         }
    768         return true;
    769     }
    770 
    771     bool Core::postUpdate(const Clock& time) throw()
    772     {
    773         std::string exceptionMessage;
    774         try
    775         {
    776             if (this->bGraphicsLoaded_)
    777             {
    778                 // Render (doesn't throw)
    779                 this->graphicsManager_->update(time);
    780             }
    781         }
    782         catch (const std::exception& ex)
    783         { exceptionMessage = ex.what(); }
    784         catch (...)
    785         { exceptionMessage = "Unknown exception"; }
    786         if (!exceptionMessage.empty())
    787         {
    788             COUT(0) << "An exception occurred in the Core postUpdate: " << exceptionMessage << std::endl;
    789             COUT(0) << "This should really never happen! Closing the program." << std::endl;
    790             return false;
    791         }
    792         return true;
     733    void Core::preUpdate(const Clock& time)
     734    {
     735        if (this->bGraphicsLoaded_)
     736        {
     737            // process input events
     738            this->inputManager_->update(time);
     739            // process gui events
     740            this->guiManager_->update(time);
     741        }
     742        // process thread commands
     743        this->tclThreadManager_->update(time);
     744    }
     745
     746    void Core::postUpdate(const Clock& time)
     747    {
     748        if (this->bGraphicsLoaded_)
     749        {
     750            // Render (doesn't throw)
     751            this->graphicsManager_->update(time);
     752        }
    793753    }
    794754}
Note: See TracChangeset for help on using the changeset viewer.