Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 26, 2009, 12:44:49 AM (15 years ago)
Author:
rgrieder
Message:

Stripped sandbox further down to get a light version that excludes almost all core features.
Also, the Ogre dependency has been removed and a little ogremath library been added.

File:
1 edited

Legend:

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

    r5782 r5789  
    6464#include "Clock.h"
    6565#include "CommandLine.h"
    66 #include "ConfigFileManager.h"
    67 #include "ConfigValueIncludes.h"
    68 #include "CoreIncludes.h"
    69 #include "DynLibManager.h"
    70 #include "Factory.h"
    71 #include "Identifier.h"
    72 #include "Language.h"
    7366#include "LuaState.h"
    7467
     
    8578    Core* Core::singletonPtr_s  = 0;
    8679
    87     SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
    8880    SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
    8981    SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
     
    9890        destruction in the Core destructor.
    9991    */
    100     class CoreConfiguration : public OrxonoxClass
     92    class CoreConfiguration
    10193    {
    10294    public:
     
    10698
    10799        void initialise()
    108         {
    109             RegisterRootObject(CoreConfiguration);
    110             this->setConfigValues();
    111         }
    112 
    113         /**
    114             @brief Function to collect the SetConfigValue-macro calls.
    115         */
    116         void setConfigValues()
    117100        {
    118101#ifdef NDEBUG
     
    125108            const unsigned int defaultLevelShell   = 3;
    126109#endif
    127             SetConfigValue(softDebugLevelConsole_, defaultLevelConsole)
    128                 .description("The maximal level of debug output shown in the console")
    129                 .callback(this, &CoreConfiguration::debugLevelChanged);
    130             SetConfigValue(softDebugLevelLogfile_, defaultLevelLogfile)
    131                 .description("The maximal level of debug output shown in the logfile")
    132                 .callback(this, &CoreConfiguration::debugLevelChanged);
    133             SetConfigValue(softDebugLevelShell_, defaultLevelShell)
    134                 .description("The maximal level of debug output shown in the ingame shell")
    135                 .callback(this, &CoreConfiguration::debugLevelChanged);
    136 
    137             SetConfigValue(language_, Language::getInstance().defaultLanguage_)
    138                 .description("The language of the ingame text")
    139                 .callback(this, &CoreConfiguration::languageChanged);
    140             SetConfigValue(bInitializeRandomNumberGenerator_, true)
    141                 .description("If true, all random actions are different each time you start the game")
    142                 .callback(this, &CoreConfiguration::initializeRandomNumberGenerator);
     110            softDebugLevelConsole_ = defaultLevelConsole;
     111            softDebugLevelLogfile_ = defaultLevelLogfile;
     112            softDebugLevelShell_   = defaultLevelShell;
     113            this->debugLevelChanged();
     114
     115            bInitializeRandomNumberGenerator_ = true;
     116            this->initializeRandomNumberGenerator();
    143117        }
    144118
     
    159133            OutputHandler::setSoftDebugLevel(OutputHandler::LD_Logfile, this->softDebugLevelLogfile_);
    160134            OutputHandler::setSoftDebugLevel(OutputHandler::LD_Shell,   this->softDebugLevelShell_);
    161         }
    162 
    163         /**
    164             @brief Callback function if the language has changed.
    165         */
    166         void languageChanged()
    167         {
    168             // Read the translation file after the language was configured
    169             Language::getInstance().readTranslatedLanguageFile();
    170         }
    171 
    172         /**
    173             @brief Sets the language in the config-file back to the default.
    174         */
    175         void resetLanguage()
    176         {
    177             ResetConfigValue(language_);
    178135        }
    179136
     
    193150        int softDebugLevelLogfile_;                     //!< The debug level for the logfile
    194151        int softDebugLevelShell_;                       //!< The debug level for the ingame shell
    195         std::string language_;                          //!< The language
    196152        bool bInitializeRandomNumberGenerator_;         //!< If true, srand(time(0)) is called
    197153
     
    199155        boost::filesystem::path rootPath_;
    200156        boost::filesystem::path executablePath_;        //!< Path to the executable
    201         boost::filesystem::path modulePath_;            //!< Path to the modules
    202157        boost::filesystem::path dataPath_;              //!< Path to the data file folder
    203158        boost::filesystem::path configPath_;            //!< Path to the config file folder
     
    208163    Core::Core(const std::string& cmdLine)
    209164        // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands)
    210         : identifierDestroyer_(Identifier::destroyAllIdentifiers)
    211         , configuration_(new CoreConfiguration()) // Don't yet create config values!
     165        : configuration_(new CoreConfiguration()) // Don't yet create config values!
    212166        , bDevRun_(false)
    213167    {
    214168        // Set the hard coded fixed paths
    215169        this->setFixedPaths();
    216 
    217         // Create a new dynamic library manager
    218         this->dynLibManager_.reset(new DynLibManager());
    219 
    220         // Load modules
    221         try
    222         {
    223             // We search for helper files with the following extension
    224             std::string moduleextension = specialConfig::moduleExtension;
    225             size_t moduleextensionlength = moduleextension.size();
    226 
    227             // Search in the directory of our executable
    228             boost::filesystem::path searchpath = this->configuration_->modulePath_;
    229 
    230             // Add that path to the PATH variable in case a module depends on another one
    231             std::string pathVariable = getenv("PATH");
    232             putenv(const_cast<char*>(("PATH=" + pathVariable + ";" + configuration_->modulePath_.string()).c_str()));
    233 
    234             boost::filesystem::directory_iterator file(searchpath);
    235             boost::filesystem::directory_iterator end;
    236 
    237             // Iterate through all files
    238             while (file != end)
    239             {
    240                 std::string filename = file->BOOST_LEAF_FUNCTION();
    241 
    242                 // Check if the file ends with the exension in question
    243                 if (filename.size() > moduleextensionlength)
    244                 {
    245                     if (filename.substr(filename.size() - moduleextensionlength) == moduleextension)
    246                     {
    247                         // We've found a helper file - now load the library with the same name
    248                         std::string library = filename.substr(0, filename.size() - moduleextensionlength);
    249                         boost::filesystem::path librarypath = searchpath / library;
    250 
    251                         try
    252                         {
    253                             DynLibManager::getInstance().load(librarypath.string());
    254                         }
    255                         catch (...)
    256                         {
    257                             COUT(1) << "Couldn't load module \"" << librarypath.string() << "\": " << Exception::handleMessage() << std::endl;
    258                         }
    259                     }
    260                 }
    261 
    262                 ++file;
    263             }
    264         }
    265         catch (...)
    266         {
    267             COUT(1) << "An error occurred while loading modules: " << Exception::handleMessage() << std::endl;
    268         }
    269170
    270171        // Parse command line arguments AFTER the modules have been loaded (static code!)
     
    293194            setThreadAffinity(static_cast<unsigned int>(limitToCPU));
    294195#endif
    295 
    296         // Manage ini files and set the default settings file (usually orxonox.ini)
    297         this->configFileManager_.reset(new ConfigFileManager());
    298         this->configFileManager_->setFilename(ConfigFileType::Settings,
    299             CommandLine::getValue("settingsFile").getString());
    300 
    301         // Required as well for the config values
    302         this->languageInstance_.reset(new Language());
    303 
    304         // creates the class hierarchy for all classes with factories
    305         Factory::createClassHierarchy();
    306196
    307197        // Do this soon after the ConfigFileManager has been created to open up the
     
    360250    }
    361251
    362     /**
    363         @brief Returns the configured language.
    364     */
    365     /*static*/ const std::string& Core::getLanguage()
    366     {
    367         return Core::getInstance().configuration_->language_;
    368     }
    369 
    370     /**
    371         @brief Sets the language in the config-file back to the default.
    372     */
    373     /*static*/ void Core::resetLanguage()
    374     {
    375         Core::getInstance().configuration_->resetLanguage();
    376     }
    377 
    378252    /*static*/ const boost::filesystem::path& Core::getDataPath()
    379253    {
     
    524398            COUT(1) << "Running from the build tree." << std::endl;
    525399            Core::bDevRun_ = true;
    526             configuration_->modulePath_ = specialConfig::moduleDevDirectory;
    527400        }
    528401        else
     
    539412            if (configuration_->rootPath_.empty())
    540413                ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
    541 
    542             // Module path is fixed as well
    543             configuration_->modulePath_ = configuration_->rootPath_ / specialConfig::defaultModulePath;
    544 
    545 #else
    546 
    547             // There is no root path, so don't set it at all
    548             // Module path is fixed as well
    549             configuration_->modulePath_ = specialConfig::moduleInstallDirectory;
    550414
    551415#endif
     
    626490        }
    627491    }
    628 
    629     void Core::preUpdate(const Clock& time)
    630     {
    631     }
    632 
    633     void Core::postUpdate(const Clock& time)
    634     {
    635     }
    636492}
Note: See TracChangeset for help on using the changeset viewer.