Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5693 for code/trunk/src/core


Ignore:
Timestamp:
Aug 29, 2009, 10:19:38 PM (15 years ago)
Author:
landauf
Message:

merged libraries branch back to trunk

Location:
code/trunk
Files:
13 edited
4 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/CMakeLists.txt

    r3370 r5693  
    2323  ConfigValueContainer.cc
    2424  Core.cc
     25  DynLib.cc
     26  DynLibManager.cc
    2527  Event.cc
    2628  Game.cc
  • code/trunk/src/core/Core.cc

    r3370 r5693  
    4040#include <cstdlib>
    4141#include <cstdio>
     42#include <boost/version.hpp>
    4243#include <boost/filesystem.hpp>
    4344#include <OgreRenderWindow.h>
     
    6869#include "ConfigValueIncludes.h"
    6970#include "CoreIncludes.h"
     71#include "DynLibManager.h"
    7072#include "Factory.h"
    7173#include "GameMode.h"
     
    8082#include "input/InputManager.h"
    8183
     84// Boost 1.36 has some issues with deprecated functions that have been omitted
     85#if (BOOST_VERSION == 103600)
     86#  define BOOST_LEAF_FUNCTION filename
     87#else
     88#  define BOOST_LEAF_FUNCTION leaf
     89#endif
     90
    8291namespace orxonox
    8392{
     
    241250        boost::filesystem::path rootPath_;
    242251        boost::filesystem::path executablePath_;        //!< Path to the executable
     252        boost::filesystem::path modulePath_;            //!< Path to the modules
    243253        boost::filesystem::path mediaPath_;             //!< Path to the media file folder
    244254        boost::filesystem::path configPath_;            //!< Path to the config file folder
     
    256266        , bGraphicsLoaded_(false)
    257267    {
    258         // Parse command line arguments first
     268        // Set the hard coded fixed paths
     269        this->setFixedPaths();
     270
     271        // Create a new dynamic library manager
     272        this->dynLibManager_.reset(new DynLibManager());
     273
     274        // Load modules
     275        try
     276        {
     277            // We search for helper files with the following extension
     278            std::string moduleextension = ORXONOX_MODULE_EXTENSION;
     279            size_t moduleextensionlength = moduleextension.size();
     280
     281            // Search in the directory of our executable
     282            boost::filesystem::path searchpath = this->configuration_->modulePath_;
     283
     284            // Add that path to the PATH variable in case a module depends on another one
     285            std::string pathVariable = getenv("PATH");
     286            putenv(const_cast<char*>(("PATH=" + pathVariable + ";" + configuration_->modulePath_.string()).c_str()));
     287
     288            boost::filesystem::directory_iterator file(searchpath);
     289            boost::filesystem::directory_iterator end;
     290
     291            // Iterate through all files
     292            while (file != end)
     293            {
     294                std::string filename = file->BOOST_LEAF_FUNCTION();
     295
     296                // Check if the file ends with the exension in question
     297                if (filename.size() > moduleextensionlength)
     298                {
     299                    if (filename.substr(filename.size() - moduleextensionlength) == moduleextension)
     300                    {
     301                        // We've found a helper file - now load the library with the same name
     302                        std::string library = filename.substr(0, filename.size() - moduleextensionlength);
     303                        boost::filesystem::path librarypath = searchpath / library;
     304
     305                        try
     306                        {
     307                            DynLibManager::getInstance().load(librarypath.string());
     308                        }
     309                        catch (const std::exception& e)
     310                        {
     311                            COUT(1) << "Couldn't load module \"" << librarypath.string() << "\": " << e.what() << std::endl;
     312                        }
     313                        catch (...)
     314                        {
     315                            COUT(1) << "Couldn't load module \"" << librarypath.string() << "\"" << std::endl;
     316                        }
     317                    }
     318                }
     319
     320                ++file;
     321            }
     322        }
     323        catch (const std::exception& e)
     324        {
     325            COUT(1) << "An error occurred while loading modules: " << e.what() << std::endl;
     326        }
     327        catch (...)
     328        {
     329            COUT(1) << "An error occurred while loading modules." << std::endl;
     330        }
     331
     332        // Parse command line arguments AFTER the modules have been loaded (static code!)
    259333        CommandLine::parseCommandLine(cmdLine);
    260334
    261         // Determine and set the location of the executable
    262         setExecutablePath();
    263 
    264         // Determine whether we have an installed or a binary dir run
    265         // The latter occurs when simply running from the build directory
    266         checkDevBuild();
    267 
    268         // Make sure the directories we write in exist or else make them
    269         createDirectories();
     335        // Set configurable paths like log, config and media
     336        this->setConfigurablePaths();
    270337
    271338        // create a signal handler (only active for linux)
     
    507574    /**
    508575    @brief
    509         Compares the executable path with the working directory
    510     */
    511     void Core::setExecutablePath()
    512     {
     576        Retrievs the executable path and sets all hard coded fixed path (currently only the module path)
     577        Also checks for "orxonox_dev_build.keep_me" in the executable diretory.
     578        If found it means that this is not an installed run, hence we
     579        don't write the logs and config files to ~/.orxonox
     580    @throw
     581        GeneralException
     582    */
     583    void Core::setFixedPaths()
     584    {
     585        //////////////////////////
     586        // FIND EXECUTABLE PATH //
     587        //////////////////////////
     588
    513589#ifdef ORXONOX_PLATFORM_WINDOWS
    514590        // get executable module
     
    553629        configuration_->executablePath_ = configuration_->executablePath_.branch_path(); // remove executable name
    554630#endif
    555     }
    556 
    557     /**
    558     @brief
    559         Checks for "orxonox_dev_build.keep_me" in the executable diretory.
    560         If found it means that this is not an installed run, hence we
    561         don't write the logs and config files to ~/.orxonox
    562     @throws
    563         GeneralException
    564     */
    565     void Core::checkDevBuild()
    566     {
     631
     632        /////////////////////
     633        // SET MODULE PATH //
     634        /////////////////////
     635
    567636        if (boost::filesystem::exists(configuration_->executablePath_ / "orxonox_dev_build.keep_me"))
    568637        {
    569638            COUT(1) << "Running from the build tree." << std::endl;
    570639            Core::bDevRun_ = true;
    571             configuration_->mediaPath_  = ORXONOX_MEDIA_DEV_PATH;
    572             configuration_->configPath_ = ORXONOX_CONFIG_DEV_PATH;
    573             configuration_->logPath_    = ORXONOX_LOG_DEV_PATH;
     640            configuration_->modulePath_ = ORXONOX_MODULE_DEV_PATH;
    574641        }
    575642        else
    576643        {
     644
    577645#ifdef INSTALL_COPYABLE // --> relative paths
     646
    578647            // Also set the root path
    579648            boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH);
     
    585654                ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
    586655
     656            // Module path is fixed as well
     657            configuration_->modulePath_ = configuration_->rootPath_ / ORXONOX_MODULE_INSTALL_PATH;
     658
     659#else
     660
     661            // There is no root path, so don't set it at all
     662            // Module path is fixed as well
     663            configuration_->modulePath_ = ORXONOX_MODULE_INSTALL_PATH;
     664
     665#endif
     666        }
     667    }
     668
     669    /**
     670    @brief
     671        Sets config, log and media path and creates folders if necessary.
     672    @throws
     673        GeneralException
     674    */
     675    void Core::setConfigurablePaths()
     676    {
     677        if (Core::isDevelopmentRun())
     678        {
     679            configuration_->mediaPath_  = ORXONOX_MEDIA_DEV_PATH;
     680            configuration_->configPath_ = ORXONOX_CONFIG_DEV_PATH;
     681            configuration_->logPath_    = ORXONOX_LOG_DEV_PATH;
     682        }
     683        else
     684        {
     685
     686#ifdef INSTALL_COPYABLE // --> relative paths
     687
    587688            // Using paths relative to the install prefix, complete them
    588689            configuration_->mediaPath_  = configuration_->rootPath_ / ORXONOX_MEDIA_INSTALL_PATH;
    589690            configuration_->configPath_ = configuration_->rootPath_ / ORXONOX_CONFIG_INSTALL_PATH;
    590691            configuration_->logPath_    = configuration_->rootPath_ / ORXONOX_LOG_INSTALL_PATH;
     692
    591693#else
    592             // There is no root path, so don't set it at all
    593694
    594695            configuration_->mediaPath_  = ORXONOX_MEDIA_INSTALL_PATH;
     
    607708            configuration_->configPath_ = userDataPath / ORXONOX_CONFIG_INSTALL_PATH;
    608709            configuration_->logPath_    = userDataPath / ORXONOX_LOG_INSTALL_PATH;
    609 #endif
     710
     711#endif
     712
    610713        }
    611714
     
    617720            configuration_->logPath_    = configuration_->logPath_    / directory;
    618721        }
    619     }
    620 
    621     /*
    622     @brief
    623         Checks for the log and the config directory and creates them
    624         if necessary. Otherwise me might have problems opening those files.
    625     @throws
    626         orxonox::GeneralException if the directory to be created is a file.
    627     */
    628     void Core::createDirectories()
    629     {
     722
     723        // Create directories to avoid problems when opening files in non existent folders.
    630724        std::vector<std::pair<boost::filesystem::path, std::string> > directories;
    631725        directories.push_back(std::make_pair(boost::filesystem::path(configuration_->configPath_), "config"));
  • code/trunk/src/core/Core.h

    r3370 r5693  
    114114            Core(const Core&); //!< Don't use (undefined symbol)
    115115
    116             void checkDevBuild();
    117             void setExecutablePath();
    118             void createDirectories();
     116            void setFixedPaths();
     117            void setConfigurablePaths();
    119118            void setThreadAffinity(int limitToCPU);
    120119
    121120            // Mind the order for the destruction!
     121            scoped_ptr<DynLibManager>     dynLibManager_;
    122122            scoped_ptr<SignalHandler>     signalHandler_;
    123123            SimpleScopeGuard              identifierDestroyer_;
  • code/trunk/src/core/CorePrereqs.h

    r3370 r5693  
    112112    class ConsoleCommand;
    113113    class Core;
     114    class DynLib;
     115    class DynLibManager;
    114116    struct Event;
    115117    class EventContainer;
  • code/trunk/src/core/GUIManager.h

    r3370 r5693  
    5050namespace orxonox
    5151{
     52    class PlayerInfo; // Forward declaration
     53
    5254    /**
    5355    @class GUIManager
     
    7779        static GUIManager* getInstancePtr() { return singletonPtr_s; }
    7880
     81        inline void setPlayer(const std::string& guiname, PlayerInfo* player)
     82            { this->players_[guiname] = player; }
     83        inline PlayerInfo* getPlayer(const std::string& guiname) const
     84            { std::map<std::string, PlayerInfo*>::const_iterator it = this->players_.find(guiname); return (it != this->players_.end()) ? it->second : 0; }
     85
    7986    private:
    8087        GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
     
    9299        void mouseScrolled (int abs, int rel);
    93100
    94         boost::scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_;  //!< CEGUI's interface to the Ogre Engine
    95         boost::scoped_ptr<CEGUI::LuaScriptModule>   scriptModule_; //!< CEGUI's script module to use Lua
    96         boost::scoped_ptr<CEGUI::System>            guiSystem_;    //!< CEGUI's main system
    97         Ogre::RenderWindow*      renderWindow_;     //!< Ogre's render window to give CEGUI access to it
    98         CEGUI::ResourceProvider* resourceProvider_; //!< CEGUI's resource provider
    99         CEGUI::Logger*           ceguiLogger_;      //!< CEGUI's logger to be able to log CEGUI errors in our log
    100         lua_State*               luaState_;         //!< Lua state, access point to the Lua engine
     101        boost::scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_;       //!< CEGUI's interface to the Ogre Engine
     102        boost::scoped_ptr<CEGUI::LuaScriptModule>   scriptModule_;      //!< CEGUI's script module to use Lua
     103        boost::scoped_ptr<CEGUI::System>            guiSystem_;         //!< CEGUI's main system
     104        Ogre::RenderWindow*                         renderWindow_;      //!< Ogre's render window to give CEGUI access to it
     105        CEGUI::ResourceProvider*                    resourceProvider_;  //!< CEGUI's resource provider
     106        CEGUI::Logger*                              ceguiLogger_;       //!< CEGUI's logger to be able to log CEGUI errors in our log
     107        lua_State*                                  luaState_;          //!< Lua state, access point to the Lua engine
     108        std::map<std::string, PlayerInfo*>          players_;           //!< Stores the player (owner) for each gui
    101109
    102         static GUIManager*       singletonPtr_s;    //!< Singleton reference to GUIManager
     110        static GUIManager*                          singletonPtr_s;     //!< Singleton reference to GUIManager
    103111
    104112    };
  • code/trunk/src/core/Game.cc

    r3370 r5693  
    113113    */
    114114    Game::Game(const std::string& cmdLine)
     115        // Destroy factories before the Core!
     116        : gsFactoryDestroyer_(Game::GameStateFactory::factories_s, &std::map<std::string, shared_ptr<GameStateFactory> >::clear)
    115117    {
    116118        this->bAbort_ = false;
  • code/trunk/src/core/Game.h

    r3370 r5693  
    4848
    4949#include "util/Debug.h"
     50#include "util/ScopeGuard.h"
    5051#include "util/Singleton.h"
    5152
     
    8586        typedef std::map<std::string, shared_ptr<GameState> > GameStateMap;
    8687        typedef boost::shared_ptr<GameStateTreeNode> GameStateTreeNodePtr;
     88
    8789    public:
    8890        Game(const std::string& cmdLine);
     
    118120            static void createFactory(const std::string& className)
    119121                { factories_s[className].reset(new TemplateGameStateFactory<T>()); }
    120         private:
     122
    121123            virtual shared_ptr<GameState> fabricateInternal(const GameStateInfo& info) = 0;
    122124            static std::map<std::string, shared_ptr<GameStateFactory> > factories_s;
     
    129131                { return shared_ptr<GameState>(new T(info)); }
    130132        };
     133        // For the factory destruction
     134        typedef Loki::ObjScopeGuardImpl0<std::map<std::string, shared_ptr<GameStateFactory> >, void (std::map<std::string, shared_ptr<GameStateFactory> >::*)()> ObjScopeGuard;
    131135
    132136        struct StatisticsTickInfo
     
    156160        scoped_ptr<Clock>                  gameClock_;
    157161        scoped_ptr<Core>                   core_;
     162        ObjScopeGuard                      gsFactoryDestroyer_;
    158163        scoped_ptr<GameConfiguration>      configuration_;
    159164
  • code/trunk/src/core/TclThreadList.h

    • Property svn:eol-style set to native
  • code/trunk/src/core/Thread.cc

    • Property svn:eol-style set to native
  • code/trunk/src/core/Thread.h

    • Property svn:eol-style set to native
  • code/trunk/src/core/ThreadPool.cc

    • Property svn:eol-style set to native
  • code/trunk/src/core/ThreadPool.h

    • Property svn:eol-style set to native
Note: See TracChangeset for help on using the changeset viewer.