Changeset 5789 for sandbox_light/src/libraries/core/Core.cc
- Timestamp:
- Sep 26, 2009, 12:44:49 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox_light/src/libraries/core/Core.cc
r5782 r5789 64 64 #include "Clock.h" 65 65 #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"73 66 #include "LuaState.h" 74 67 … … 85 78 Core* Core::singletonPtr_s = 0; 86 79 87 SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");88 80 SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files"); 89 81 SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file"); … … 98 90 destruction in the Core destructor. 99 91 */ 100 class CoreConfiguration : public OrxonoxClass92 class CoreConfiguration 101 93 { 102 94 public: … … 106 98 107 99 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()117 100 { 118 101 #ifdef NDEBUG … … 125 108 const unsigned int defaultLevelShell = 3; 126 109 #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(); 143 117 } 144 118 … … 159 133 OutputHandler::setSoftDebugLevel(OutputHandler::LD_Logfile, this->softDebugLevelLogfile_); 160 134 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 configured169 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_);178 135 } 179 136 … … 193 150 int softDebugLevelLogfile_; //!< The debug level for the logfile 194 151 int softDebugLevelShell_; //!< The debug level for the ingame shell 195 std::string language_; //!< The language196 152 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 197 153 … … 199 155 boost::filesystem::path rootPath_; 200 156 boost::filesystem::path executablePath_; //!< Path to the executable 201 boost::filesystem::path modulePath_; //!< Path to the modules202 157 boost::filesystem::path dataPath_; //!< Path to the data file folder 203 158 boost::filesystem::path configPath_; //!< Path to the config file folder … … 208 163 Core::Core(const std::string& cmdLine) 209 164 // 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! 212 166 , bDevRun_(false) 213 167 { 214 168 // Set the hard coded fixed paths 215 169 this->setFixedPaths(); 216 217 // Create a new dynamic library manager218 this->dynLibManager_.reset(new DynLibManager());219 220 // Load modules221 try222 {223 // We search for helper files with the following extension224 std::string moduleextension = specialConfig::moduleExtension;225 size_t moduleextensionlength = moduleextension.size();226 227 // Search in the directory of our executable228 boost::filesystem::path searchpath = this->configuration_->modulePath_;229 230 // Add that path to the PATH variable in case a module depends on another one231 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 files238 while (file != end)239 {240 std::string filename = file->BOOST_LEAF_FUNCTION();241 242 // Check if the file ends with the exension in question243 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 name248 std::string library = filename.substr(0, filename.size() - moduleextensionlength);249 boost::filesystem::path librarypath = searchpath / library;250 251 try252 {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 }269 170 270 171 // Parse command line arguments AFTER the modules have been loaded (static code!) … … 293 194 setThreadAffinity(static_cast<unsigned int>(limitToCPU)); 294 195 #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 values302 this->languageInstance_.reset(new Language());303 304 // creates the class hierarchy for all classes with factories305 Factory::createClassHierarchy();306 196 307 197 // Do this soon after the ConfigFileManager has been created to open up the … … 360 250 } 361 251 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 378 252 /*static*/ const boost::filesystem::path& Core::getDataPath() 379 253 { … … 524 398 COUT(1) << "Running from the build tree." << std::endl; 525 399 Core::bDevRun_ = true; 526 configuration_->modulePath_ = specialConfig::moduleDevDirectory;527 400 } 528 401 else … … 539 412 if (configuration_->rootPath_.empty()) 540 413 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 well543 configuration_->modulePath_ = configuration_->rootPath_ / specialConfig::defaultModulePath;544 545 #else546 547 // There is no root path, so don't set it at all548 // Module path is fixed as well549 configuration_->modulePath_ = specialConfig::moduleInstallDirectory;550 414 551 415 #endif … … 626 490 } 627 491 } 628 629 void Core::preUpdate(const Clock& time)630 {631 }632 633 void Core::postUpdate(const Clock& time)634 {635 }636 492 }
Note: See TracChangeset
for help on using the changeset viewer.