Changeset 6417 for code/trunk/src/libraries/core/Core.cc
- Timestamp:
- Dec 25, 2009, 10:23:58 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/Core.cc
r6105 r6417 51 51 #include "util/Debug.h" 52 52 #include "util/Exception.h" 53 #include "util/Scope.h" 53 54 #include "util/SignalHandler.h" 54 55 #include "PathConfig.h" … … 78 79 SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file"); 79 80 #ifdef ORXONOX_PLATFORM_WINDOWS 80 SetCommandLineArgument(limitToCPU, 0).information("Limits the program to one cpu/core (1, 2, 3, etc.). 0 turns it off (default)"); 81 #endif 82 83 /** 84 @brief 85 Helper class for the Core singleton: we cannot derive 86 Core from OrxonoxClass because we need to handle the Identifier 87 destruction in the Core destructor. 88 */ 89 class CoreConfiguration : public OrxonoxClass 90 { 91 public: 92 CoreConfiguration() 93 { 94 } 95 96 void initialise() 97 { 98 RegisterRootObject(CoreConfiguration); 99 this->setConfigValues(); 100 } 101 102 /** 103 @brief Function to collect the SetConfigValue-macro calls. 104 */ 105 void setConfigValues() 106 { 107 #ifdef ORXONOX_RELEASE 108 const unsigned int defaultLevelLogFile = 3; 109 #else 110 const unsigned int defaultLevelLogFile = 4; 111 #endif 112 SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevelLogFile_, "softDebugLevelLogFile", "OutputHandler", defaultLevelLogFile) 113 .description("The maximum level of debug output shown in the log file"); 114 OutputHandler::getInstance().setSoftDebugLevel(OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_); 115 116 SetConfigValue(language_, Language::getInstance().defaultLanguage_) 117 .description("The language of the in game text") 118 .callback(this, &CoreConfiguration::languageChanged); 119 SetConfigValue(bInitializeRandomNumberGenerator_, true) 120 .description("If true, all random actions are different each time you start the game") 121 .callback(this, &CoreConfiguration::initializeRandomNumberGenerator); 122 } 123 124 /** 125 @brief Callback function if the language has changed. 126 */ 127 void languageChanged() 128 { 129 // Read the translation file after the language was configured 130 Language::getInstance().readTranslatedLanguageFile(); 131 } 132 133 /** 134 @brief Sets the language in the config-file back to the default. 135 */ 136 void resetLanguage() 137 { 138 ResetConfigValue(language_); 139 } 140 141 void initializeRandomNumberGenerator() 142 { 143 static bool bInitialized = false; 144 if (!bInitialized && this->bInitializeRandomNumberGenerator_) 145 { 146 srand(static_cast<unsigned int>(time(0))); 147 rand(); 148 bInitialized = true; 149 } 150 } 151 152 int softDebugLevelLogFile_; //!< The debug level for the log file (belongs to OutputHandler) 153 std::string language_; //!< The language 154 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 155 }; 156 81 SetCommandLineArgument(limitToCPU, 1).information("Limits the program to one CPU/core (1, 2, 3, etc.). Default is the first core (faster than off)"); 82 #endif 157 83 158 84 Core::Core(const std::string& cmdLine) … … 161 87 // Cleanup guard for external console commands that don't belong to an Identifier 162 88 , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands) 163 , configuration_(new CoreConfiguration()) // Don't yet create config values!164 89 , bGraphicsLoaded_(false) 165 90 { … … 218 143 this->languageInstance_.reset(new Language()); 219 144 145 // Do this soon after the ConfigFileManager has been created to open up the 146 // possibility to configure everything below here 147 ClassIdentifier<Core>::getIdentifier("Core")->initialiseObject(this, "Core", true); 148 this->setConfigValues(); 149 220 150 // create persistent io console 221 151 this->ioConsole_.reset(new IOConsole()); … … 223 153 // creates the class hierarchy for all classes with factories 224 154 Identifier::createClassHierarchy(); 225 226 // Do this soon after the ConfigFileManager has been created to open up the227 // possibility to configure everything below here228 this->configuration_->initialise();229 155 230 156 // Load OGRE excluding the renderer and the render window … … 245 171 Core::~Core() 246 172 { 173 // Remove us from the object lists again to avoid problems when destroying them 174 this->unregisterObject(); 175 } 176 177 //! Function to collect the SetConfigValue-macro calls. 178 void Core::setConfigValues() 179 { 180 #ifdef ORXONOX_RELEASE 181 const unsigned int defaultLevelLogFile = 3; 182 #else 183 const unsigned int defaultLevelLogFile = 4; 184 #endif 185 setConfigValueGeneric(this, &this->softDebugLevelLogFile_, ConfigFileType::Settings, "OutputHandler", "softDebugLevelLogFile", defaultLevelLogFile) 186 .description("The maximum level of debug output shown in the log file"); 187 OutputHandler::getInstance().setSoftDebugLevel(OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_); 188 189 SetConfigValue(language_, Language::getInstance().defaultLanguage_) 190 .description("The language of the in game text") 191 .callback(this, &Core::languageChanged); 192 SetConfigValue(bInitRandomNumberGenerator_, true) 193 .description("If true, all random actions are different each time you start the game") 194 .callback(this, &Core::initRandomNumberGenerator); 195 } 196 197 //! Callback function if the language has changed. 198 void Core::languageChanged() 199 { 200 // Read the translation file after the language was configured 201 Language::getInstance().readTranslatedLanguageFile(); 202 } 203 204 void Core::initRandomNumberGenerator() 205 { 206 static bool bInitialized = false; 207 if (!bInitialized && this->bInitRandomNumberGenerator_) 208 { 209 srand(static_cast<unsigned int>(time(0))); 210 rand(); 211 bInitialized = true; 212 } 247 213 } 248 214 … … 296 262 } 297 263 298 /** 299 @brief Returns the configured language. 300 */ 301 /*static*/ const std::string& Core::getLanguage() 302 { 303 return Core::getInstance().configuration_->language_; 304 } 305 306 /** 307 @brief Sets the language in the config-file back to the default. 308 */ 309 /*static*/ void Core::resetLanguage() 310 { 311 Core::getInstance().configuration_->resetLanguage(); 264 //! Sets the language in the config-file back to the default. 265 void Core::resetLanguage() 266 { 267 ResetConfigValue(language_); 312 268 } 313 269 … … 360 316 void Core::preUpdate(const Clock& time) 361 317 { 362 // singletons from other libraries363 ScopedSingletonManager:: update<ScopeID::Root>(time);318 // Update singletons before general ticking 319 ScopedSingletonManager::preUpdate<ScopeID::Root>(time); 364 320 if (this->bGraphicsLoaded_) 365 321 { 366 // process input events367 this->inputManager_-> update(time);368 // process gui events369 this->guiManager_-> update(time);370 // graphics singletons from other libraries371 ScopedSingletonManager:: update<ScopeID::Graphics>(time);372 } 373 // process console text374 this->ioConsole_-> update(time);375 // process thread commands376 this->tclThreadManager_-> update(time);322 // Process input events 323 this->inputManager_->preUpdate(time); 324 // Update GUI 325 this->guiManager_->preUpdate(time); 326 // Update singletons before general ticking 327 ScopedSingletonManager::preUpdate<ScopeID::Graphics>(time); 328 } 329 // Process console events and status line 330 this->ioConsole_->preUpdate(time); 331 // Process thread commands 332 this->tclThreadManager_->preUpdate(time); 377 333 } 378 334 379 335 void Core::postUpdate(const Clock& time) 380 336 { 337 // Update singletons just before rendering 338 ScopedSingletonManager::postUpdate<ScopeID::Root>(time); 381 339 if (this->bGraphicsLoaded_) 382 340 { 341 // Update singletons just before rendering 342 ScopedSingletonManager::postUpdate<ScopeID::Graphics>(time); 383 343 // Render (doesn't throw) 384 this->graphicsManager_-> update(time);344 this->graphicsManager_->postUpdate(time); 385 345 } 386 346 }
Note: See TracChangeset
for help on using the changeset viewer.