Changeset 6121 for code/branches/presentation2/src/libraries/core/Core.cc
- Timestamp:
- Nov 23, 2009, 6:19:58 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/core/Core.cc
r6105 r6121 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" … … 81 82 #endif 82 83 83 /**84 @brief85 Helper class for the Core singleton: we cannot derive86 Core from OrxonoxClass because we need to handle the Identifier87 destruction in the Core destructor.88 */89 class CoreConfiguration : public OrxonoxClass90 {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_RELEASE108 const unsigned int defaultLevelLogFile = 3;109 #else110 const unsigned int defaultLevelLogFile = 4;111 #endif112 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 configured130 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 language154 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called155 };156 157 158 84 Core::Core(const std::string& cmdLine) 159 85 // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands) … … 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 // Remove us from the object lists again to avoid problems when destroying the Core 149 this->unregisterObject(); 150 this->setConfigValues(); 151 220 152 // create persistent io console 221 153 this->ioConsole_.reset(new IOConsole()); … … 223 155 // creates the class hierarchy for all classes with factories 224 156 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 157 230 158 // Load OGRE excluding the renderer and the render window … … 247 175 } 248 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(ConfigFileType::Settings, softDebugLevelLogFile_, "softDebugLevelLogFile", "OutputHandler", 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 } 213 } 214 249 215 void Core::loadGraphics() 250 216 { … … 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
Note: See TracChangeset
for help on using the changeset viewer.