Changeset 5789 for sandbox_light/src/libraries/core
- Timestamp:
- Sep 26, 2009, 12:44:49 AM (15 years ago)
- Location:
- sandbox_light/src/libraries/core
- Files:
-
- 40 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox_light/src/libraries/core/CMakeLists.txt
r5782 r5789 20 20 SET_SOURCE_FILES(CORE_SRC_FILES 21 21 Clock.cc 22 ConfigFileManager.cc 23 ConfigValueContainer.cc 22 CommandLine.cc 24 23 Core.cc 25 DynLib.cc26 DynLibManager.cc27 Game.cc28 GameState.cc29 Language.cc30 24 LuaState.cc 31 ObjectListBase.cc32 OrxonoxClass.cc33 34 # command35 CommandLine.cc36 Executor.cc37 38 # hierarchy39 Factory.cc40 Identifier.cc41 MetaObjectList.cc42 43 # level44 BaseObject.cc45 46 # multithreading47 Thread.cc48 ThreadPool.cc49 25 ) 50 26 … … 55 31 DEFINE_SYMBOL 56 32 "CORE_SHARED_BUILD" 57 PCH_FILE58 CorePrecompiledHeaders.h59 33 LINK_LIBRARIES 60 ${OGRE_LIBRARY}61 34 ${Boost_FILESYSTEM_LIBRARY} 62 35 ${Boost_SYSTEM_LIBRARY} # Filesystem dependency 63 ${Boost_THREAD_LIBRARY}64 ${Boost_DATE_TIME_LIBRARY} # Thread dependency65 36 ${LUA_LIBRARIES} 37 ogremath_orxonox 66 38 tolua++_orxonox 67 39 util -
sandbox_light/src/libraries/core/Clock.cc
r5738 r5789 33 33 34 34 #include "Clock.h" 35 #include < OgreTimer.h>35 #include <ogremath/OgreTimer.h> 36 36 37 37 namespace orxonox -
sandbox_light/src/libraries/core/CommandLine.cc
r5738 r5789 31 31 #include <algorithm> 32 32 #include <sstream> 33 #include <boost/filesystem.hpp>34 33 35 34 #include "util/Convert.h" … … 348 347 { 349 348 std::string filename = CommandLine::getValue("optionsFile").getString(); 350 boost::filesystem::path filepath(Core::getConfigPath() / filename);351 349 352 350 // look for additional arguments in given file or start.ini as default 353 351 // They will not overwrite the arguments given directly 354 352 std::ifstream file; 355 file.open( filepath.string().c_str());353 file.open((Core::getConfigPathString() + filename).c_str()); 356 354 std::vector<std::string> args; 357 355 if (file) -
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 } -
sandbox_light/src/libraries/core/Core.h
r5782 r5789 65 65 typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard; 66 66 friend class Singleton<Core>; 67 friend class Game;68 67 69 68 public: … … 82 81 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); 83 82 static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level); 84 static const std::string& getLanguage();85 static void resetLanguage();86 83 87 84 //! Returns the path to the data files as boost::filesystem::path … … 107 104 Core(const Core&); //!< Don't use (undefined symbol) 108 105 109 void preUpdate(const Clock& time);110 void postUpdate(const Clock& time);111 112 106 void setFixedPaths(); 113 107 void setConfigurablePaths(); … … 115 109 116 110 // Mind the order for the destruction! 117 scoped_ptr<DynLibManager> dynLibManager_;118 111 scoped_ptr<SignalHandler> signalHandler_; 119 SimpleScopeGuard identifierDestroyer_;120 scoped_ptr<ConfigFileManager> configFileManager_;121 scoped_ptr<Language> languageInstance_;122 112 scoped_ptr<CoreConfiguration> configuration_; 123 113
Note: See TracChangeset
for help on using the changeset viewer.