- Timestamp:
- Jun 29, 2009, 2:01:51 PM (15 years ago)
- Location:
- code/branches/core4/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core4/src/core/Core.cc
r3246 r3247 77 77 namespace orxonox 78 78 { 79 //! Path to the parent directory of the ones above if program was installed with relativ pahts80 static boost::filesystem::path rootPath_g;81 static boost::filesystem::path executablePath_g; //!< Path to the executable82 static boost::filesystem::path mediaPath_g; //!< Path to the media file folder83 static boost::filesystem::path configPath_g; //!< Path to the config file folder84 static boost::filesystem::path logPath_g; //!< Path to the log file folder85 86 79 //! Static pointer to the singleton 87 80 Core* Core::singletonRef_s = 0; … … 92 85 SetCommandLineArgument(limitToCPU, 0).information("0: off | #cpu"); 93 86 94 Core::Core() 95 { 96 RegisterRootObject(Core); 97 87 /** 88 @brief 89 Helper class for the Core singleton: we cannot derive 90 Core from OrxonoxClass because we need to handle the Identifier 91 destruction in the Core destructor. 92 */ 93 class CoreConfiguration : public OrxonoxClass 94 { 95 public: 96 CoreConfiguration() 97 { 98 } 99 100 void CoreConfiguration::initialise() 101 { 102 RegisterRootObject(CoreConfiguration); 103 this->setConfigValues(); 104 105 // Possible media path override by the command line 106 if (!CommandLine::getArgument("mediaPath")->hasDefaultValue()) 107 tsetMediaPath(CommandLine::getValue("mediaPath")); 108 } 109 110 /** 111 @brief Function to collect the SetConfigValue-macro calls. 112 */ 113 void setConfigValues() 114 { 115 #ifdef NDEBUG 116 const unsigned int defaultLevelConsole = 1; 117 const unsigned int defaultLevelLogfile = 3; 118 const unsigned int defaultLevelShell = 1; 119 #else 120 const unsigned int defaultLevelConsole = 3; 121 const unsigned int defaultLevelLogfile = 4; 122 const unsigned int defaultLevelShell = 3; 123 #endif 124 SetConfigValue(softDebugLevelConsole_, defaultLevelConsole) 125 .description("The maximal level of debug output shown in the console") 126 .callback(this, &CoreConfiguration::debugLevelChanged); 127 SetConfigValue(softDebugLevelLogfile_, defaultLevelLogfile) 128 .description("The maximal level of debug output shown in the logfile") 129 .callback(this, &CoreConfiguration::debugLevelChanged); 130 SetConfigValue(softDebugLevelShell_, defaultLevelShell) 131 .description("The maximal level of debug output shown in the ingame shell") 132 .callback(this, &CoreConfiguration::debugLevelChanged); 133 134 SetConfigValue(language_, Language::getLanguage().defaultLanguage_) 135 .description("The language of the ingame text") 136 .callback(this, &CoreConfiguration::languageChanged); 137 SetConfigValue(bInitializeRandomNumberGenerator_, true) 138 .description("If true, all random actions are different each time you start the game") 139 .callback(this, &CoreConfiguration::initializeRandomNumberGenerator); 140 141 SetConfigValue(mediaPathString_, mediaPath_.string()) 142 .description("Relative path to the game data.") 143 .callback(this, &CoreConfiguration::mediaPathChanged); 144 } 145 146 /** 147 @brief Callback function if the debug level has changed. 148 */ 149 void debugLevelChanged() 150 { 151 // softDebugLevel_ is the maximum of the 3 variables 152 this->softDebugLevel_ = this->softDebugLevelConsole_; 153 if (this->softDebugLevelLogfile_ > this->softDebugLevel_) 154 this->softDebugLevel_ = this->softDebugLevelLogfile_; 155 if (this->softDebugLevelShell_ > this->softDebugLevel_) 156 this->softDebugLevel_ = this->softDebugLevelShell_; 157 158 OutputHandler::setSoftDebugLevel(OutputHandler::LD_All, this->softDebugLevel_); 159 OutputHandler::setSoftDebugLevel(OutputHandler::LD_Console, this->softDebugLevelConsole_); 160 OutputHandler::setSoftDebugLevel(OutputHandler::LD_Logfile, this->softDebugLevelLogfile_); 161 OutputHandler::setSoftDebugLevel(OutputHandler::LD_Shell, this->softDebugLevelShell_); 162 } 163 164 /** 165 @brief Callback function if the language has changed. 166 */ 167 void languageChanged() 168 { 169 // Read the translation file after the language was configured 170 Language::getLanguage().readTranslatedLanguageFile(); 171 } 172 173 /** 174 @brief 175 Callback function if the media path has changed. 176 */ 177 void mediaPathChanged() 178 { 179 mediaPath_ = boost::filesystem::path(this->mediaPathString_); 180 } 181 182 /** 183 @brief Sets the language in the config-file back to the default. 184 */ 185 void resetLanguage() 186 { 187 ResetConfigValue(language_); 188 } 189 190 /** 191 @brief 192 Temporary sets the media path 193 @param path 194 The new media path 195 */ 196 void tsetMediaPath(const std::string& path) 197 { 198 ModifyConfigValue(mediaPathString_, tset, path); 199 } 200 201 void initializeRandomNumberGenerator() 202 { 203 static bool bInitialized = false; 204 if (!bInitialized && this->bInitializeRandomNumberGenerator_) 205 { 206 srand(static_cast<unsigned int>(time(0))); 207 rand(); 208 bInitialized = true; 209 } 210 } 211 212 int softDebugLevel_; //!< The debug level 213 int softDebugLevelConsole_; //!< The debug level for the console 214 int softDebugLevelLogfile_; //!< The debug level for the logfile 215 int softDebugLevelShell_; //!< The debug level for the ingame shell 216 std::string language_; //!< The language 217 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 218 std::string mediaPathString_; //!< Path to the data/media file folder as string 219 220 //! Path to the parent directory of the ones above if program was installed with relativ pahts 221 boost::filesystem::path rootPath_; 222 boost::filesystem::path executablePath_; //!< Path to the executable 223 boost::filesystem::path mediaPath_; //!< Path to the media file folder 224 boost::filesystem::path configPath_; //!< Path to the config file folder 225 boost::filesystem::path logPath_; //!< Path to the log file folder 226 }; 227 228 229 Core::Core(int argc, char** argv) 230 { 98 231 assert(Core::singletonRef_s == 0); 99 232 Core::singletonRef_s = this; 100 } 101 102 void Core::initialise(int argc, char** argv)103 { 104 // Parse command line arguments fi st233 234 // We need the variables very soon. But don't configure them yet! 235 this->configuration_ = new CoreConfiguration(); 236 237 // Parse command line arguments first 105 238 CommandLine::parseCommandLine(argc, argv); 239 240 // Determine and set the location of the executable 241 setExecutablePath(); 242 243 // Determine whether we have an installed or a binary dir run 244 // The latter occurs when simply running from the build directory 245 checkDevBuild(); 246 247 // Make sure the directories we write in exist or else make them 248 createDirectories(); 249 250 // create a signal handler (only active for linux) 251 // This call is placed as soon as possible, but after the directories are set 252 this->signalHandler_ = new SignalHandler(); 253 this->signalHandler_->doCatch(configuration_->executablePath_.string(), Core::getLogPathString() + "orxonox_crash.log"); 254 255 // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used 256 OutputHandler::getOutStream().setLogPath(Core::getLogPathString()); 257 258 // Parse additional options file now that we know its path 259 CommandLine::parseFile(); 106 260 107 261 // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump … … 112 266 setThreadAffinity((unsigned int)limitToCPU); 113 267 114 // Determine and set the location of the executable115 setExecutablePath();116 117 // Determine whether we have an installed or a binary dir run118 // The latter occurs when simply running from the build directory119 checkDevBuild();120 121 // Make sure the directories we write in exist or else make them122 createDirectories();123 124 // create a signal handler (only active for linux)125 // This call is placed as soon as possible, but after the directories are set126 this->signalHandler_ = new SignalHandler();127 this->signalHandler_->doCatch(executablePath_g.string(), Core::getLogPathString() + "orxonox_crash.log");128 129 // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used130 OutputHandler::getOutStream().setLogPath(Core::getLogPathString());131 132 CommandLine::parseFile();133 134 268 // Manage ini files and set the default settings file (usually orxonox.ini) 135 269 this->configFileManager_ = new ConfigFileManager(); … … 141 275 // Do this soon after the ConfigFileManager has been created to open up the 142 276 // possibility to configure everything below here 143 this->setConfigValues(); 144 145 // Possible media path override by the command line 146 if (!CommandLine::getArgument("mediaPath")->hasDefaultValue()) 147 { 148 //std::string mediaPath = CommandLine::getValue("mediaPath"); 149 Core::tsetMediaPath(CommandLine::getValue("mediaPath")); 150 } 277 this->configuration_->initialise(); 151 278 152 279 // Create the lua interface … … 162 289 // creates the class hierarchy for all classes with factories 163 290 Factory::createClassHierarchy(); 164 165 this->loaded_ = true;166 291 } 167 292 … … 171 296 Core::~Core() 172 297 { 173 this->loaded_ = false;174 175 298 delete this->shell_; 176 299 delete this->tclThreadManager_; 177 300 delete this->tclBind_; 178 301 delete this->luaBind_; 302 delete this->configuration_; 179 303 delete this->languageInstance_; 180 304 delete this->configFileManager_; … … 185 309 CommandExecutor::destroyExternalCommands(); 186 310 311 // Clean up class hierarchy stuff (identifiers, XMLPort, configValues, consoleCommand) 312 Identifier::destroyAllIdentifiers(); 313 187 314 assert(Core::singletonRef_s); 188 315 Core::singletonRef_s = 0; … … 191 318 192 319 /** 193 @brief Function to collect the SetConfigValue-macro calls. 194 */ 195 void Core::setConfigValues() 196 { 197 #ifdef NDEBUG 198 const unsigned int defaultLevelConsole = 1; 199 const unsigned int defaultLevelLogfile = 3; 200 const unsigned int defaultLevelShell = 1; 201 #else 202 const unsigned int defaultLevelConsole = 3; 203 const unsigned int defaultLevelLogfile = 4; 204 const unsigned int defaultLevelShell = 3; 205 #endif 206 SetConfigValue(softDebugLevelConsole_, defaultLevelConsole) 207 .description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged); 208 SetConfigValue(softDebugLevelLogfile_, defaultLevelLogfile) 209 .description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged); 210 SetConfigValue(softDebugLevelShell_, defaultLevelShell) 211 .description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged); 212 213 SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged); 214 SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator); 215 216 SetConfigValue(mediaPathString_, mediaPath_g.string()) 217 .description("Relative path to the game data.").callback(this, &Core::mediaPathChanged); 218 } 219 220 /** 221 @brief Callback function if the debug level has changed. 222 */ 223 void Core::debugLevelChanged() 224 { 225 // softDebugLevel_ is the maximum of the 3 variables 226 this->softDebugLevel_ = this->softDebugLevelConsole_; 227 if (this->softDebugLevelLogfile_ > this->softDebugLevel_) 228 this->softDebugLevel_ = this->softDebugLevelLogfile_; 229 if (this->softDebugLevelShell_ > this->softDebugLevel_) 230 this->softDebugLevel_ = this->softDebugLevelShell_; 231 232 OutputHandler::setSoftDebugLevel(OutputHandler::LD_All, this->softDebugLevel_); 233 OutputHandler::setSoftDebugLevel(OutputHandler::LD_Console, this->softDebugLevelConsole_); 234 OutputHandler::setSoftDebugLevel(OutputHandler::LD_Logfile, this->softDebugLevelLogfile_); 235 OutputHandler::setSoftDebugLevel(OutputHandler::LD_Shell, this->softDebugLevelShell_); 236 } 237 238 /** 239 @brief Callback function if the language has changed. 240 */ 241 void Core::languageChanged() 242 { 243 // Read the translation file after the language was configured 244 Language::getLanguage().readTranslatedLanguageFile(); 245 } 246 247 /** 248 @brief 249 Callback function if the media path has changed. 250 */ 251 void Core::mediaPathChanged() 252 { 253 mediaPath_g = boost::filesystem::path(this->mediaPathString_); 254 } 255 256 /** 257 @brief Returns the softDebugLevel for the given device (returns a default-value if the class ist right about to be created). 320 @brief Returns the softDebugLevel for the given device (returns a default-value if the class is right about to be created). 258 321 @param device The device 259 322 @return The softDebugLevel 260 323 */ 261 int Core::getSoftDebugLevel(OutputHandler::OutputDevice device)324 /*static*/ int Core::getSoftDebugLevel(OutputHandler::OutputDevice device) 262 325 { 263 326 switch (device) 264 327 { 265 328 case OutputHandler::LD_All: 266 return Core::getInstance(). softDebugLevel_;329 return Core::getInstance().configuration_->softDebugLevel_; 267 330 case OutputHandler::LD_Console: 268 return Core::getInstance(). softDebugLevelConsole_;331 return Core::getInstance().configuration_->softDebugLevelConsole_; 269 332 case OutputHandler::LD_Logfile: 270 return Core::getInstance(). softDebugLevelLogfile_;333 return Core::getInstance().configuration_->softDebugLevelLogfile_; 271 334 case OutputHandler::LD_Shell: 272 return Core::getInstance(). softDebugLevelShell_;335 return Core::getInstance().configuration_->softDebugLevelShell_; 273 336 default: 274 337 assert(0); … … 282 345 @param level The level 283 346 */ 284 void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)285 347 /*static*/ void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level) 348 { 286 349 if (device == OutputHandler::LD_All) 287 Core::getInstance(). softDebugLevel_ = level;350 Core::getInstance().configuration_->softDebugLevel_ = level; 288 351 else if (device == OutputHandler::LD_Console) 289 Core::getInstance(). softDebugLevelConsole_ = level;352 Core::getInstance().configuration_->softDebugLevelConsole_ = level; 290 353 else if (device == OutputHandler::LD_Logfile) 291 Core::getInstance(). softDebugLevelLogfile_ = level;354 Core::getInstance().configuration_->softDebugLevelLogfile_ = level; 292 355 else if (device == OutputHandler::LD_Shell) 293 Core::getInstance(). softDebugLevelShell_ = level;356 Core::getInstance().configuration_->softDebugLevelShell_ = level; 294 357 295 358 OutputHandler::setSoftDebugLevel(device, level); 296 359 } 297 360 298 361 /** 299 362 @brief Returns the configured language. 300 363 */ 301 const std::string& Core::getLanguage()302 { 303 return Core::getInstance(). language_;364 /*static*/ const std::string& Core::getLanguage() 365 { 366 return Core::getInstance().configuration_->language_; 304 367 } 305 368 … … 307 370 @brief Sets the language in the config-file back to the default. 308 371 */ 309 void Core::resetLanguage() 310 { 311 Core::getInstance().resetLanguageIntern(); 312 } 313 314 /** 315 @brief Sets the language in the config-file back to the default. 316 */ 317 void Core::resetLanguageIntern() 318 { 319 ResetConfigValue(language_); 320 } 321 322 /** 323 @brief 324 Temporary sets the media path 325 @param path 326 The new media path 327 */ 328 void Core::_tsetMediaPath(const std::string& path) 329 { 330 ModifyConfigValue(mediaPathString_, tset, path); 372 /*static*/ void Core::resetLanguage() 373 { 374 Core::getInstance().configuration_->resetLanguage(); 375 } 376 377 /*static*/ void Core::tsetMediaPath(const std::string& path) 378 { 379 getInstance().configuration_->tsetMediaPath(path); 331 380 } 332 381 333 382 /*static*/ const boost::filesystem::path& Core::getMediaPath() 334 383 { 335 return mediaPath_g;384 return getInstance().configuration_->mediaPath_; 336 385 } 337 386 /*static*/ std::string Core::getMediaPathString() 338 387 { 339 return mediaPath_g.string() + '/';388 return getInstance().configuration_->mediaPath_.string() + '/'; 340 389 } 341 390 342 391 /*static*/ const boost::filesystem::path& Core::getConfigPath() 343 392 { 344 return configPath_g;393 return getInstance().configuration_->configPath_; 345 394 } 346 395 /*static*/ std::string Core::getConfigPathString() 347 396 { 348 return configPath_g.string() + '/';397 return getInstance().configuration_->configPath_.string() + '/'; 349 398 } 350 399 351 400 /*static*/ const boost::filesystem::path& Core::getLogPath() 352 401 { 353 return logPath_g;402 return getInstance().configuration_->logPath_; 354 403 } 355 404 /*static*/ std::string Core::getLogPathString() 356 405 { 357 return logPath_g.string() + '/'; 358 } 359 360 void Core::initializeRandomNumberGenerator() 361 { 362 static bool bInitialized = false; 363 if (!bInitialized && this->bInitializeRandomNumberGenerator_) 364 { 365 srand(static_cast<unsigned int>(time(0))); 366 rand(); 367 bInitialized = true; 368 } 369 } 370 406 return getInstance().configuration_->logPath_.string() + '/'; 407 } 371 408 372 409 /** … … 459 496 #endif 460 497 461 executablePath_g= boost::filesystem::path(buffer);498 configuration_->executablePath_ = boost::filesystem::path(buffer); 462 499 #ifndef ORXONOX_PLATFORM_APPLE 463 executablePath_g = executablePath_g.branch_path(); // remove executable name500 configuration_->executablePath_ = configuration_->executablePath_.branch_path(); // remove executable name 464 501 #endif 465 502 } … … 475 512 void Core::checkDevBuild() 476 513 { 477 if (boost::filesystem::exists( executablePath_g/ "orxonox_dev_build.keep_me"))514 if (boost::filesystem::exists(configuration_->executablePath_ / "orxonox_dev_build.keep_me")) 478 515 { 479 516 COUT(1) << "Running from the build tree." << std::endl; 480 517 Core::isDevBuild_ = true; 481 mediaPath_g= ORXONOX_MEDIA_DEV_PATH;482 config Path_g= ORXONOX_CONFIG_DEV_PATH;483 logPath_g= ORXONOX_LOG_DEV_PATH;518 configuration_->mediaPath_ = ORXONOX_MEDIA_DEV_PATH; 519 configuration_->configPath_ = ORXONOX_CONFIG_DEV_PATH; 520 configuration_->logPath_ = ORXONOX_LOG_DEV_PATH; 484 521 } 485 522 else … … 488 525 // Also set the root path 489 526 boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH); 490 rootPath_g = executablePath_g; 491 while (!boost::filesystem::equivalent(rootPath_g / relativeExecutablePath, executablePath_g) && !rootPath_g.empty()) 492 rootPath_g = rootPath_g.branch_path(); 493 if (rootPath_g.empty()) 527 configuration_->rootPath_ = configuration_->executablePath_; 528 while (!boost::filesystem::equivalent(configuration_->rootPath_ / relativeExecutablePath, configuration_->executablePath_) 529 && !configuration_->rootPath_.empty()) 530 configuration_->rootPath_ = configuration_->rootPath_.branch_path(); 531 if (configuration_->rootPath_.empty()) 494 532 ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?"); 495 533 496 534 // Using paths relative to the install prefix, complete them 497 mediaPath_g = rootPath_g/ ORXONOX_MEDIA_INSTALL_PATH;498 config Path_g = rootPath_g/ ORXONOX_CONFIG_INSTALL_PATH;499 logPath_g = rootPath_g/ ORXONOX_LOG_INSTALL_PATH;535 configuration_->mediaPath_ = configuration_->rootPath_ / ORXONOX_MEDIA_INSTALL_PATH; 536 configuration_->configPath_ = configuration_->rootPath_ / ORXONOX_CONFIG_INSTALL_PATH; 537 configuration_->logPath_ = configuration_->rootPath_ / ORXONOX_LOG_INSTALL_PATH; 500 538 #else 501 539 // There is no root path, so don't set it at all 502 540 503 mediaPath_g= ORXONOX_MEDIA_INSTALL_PATH;541 configuration_->mediaPath_ = ORXONOX_MEDIA_INSTALL_PATH; 504 542 505 543 // Get user directory … … 514 552 userDataPath /= ".orxonox"; 515 553 516 config Path_g= userDataPath / ORXONOX_CONFIG_INSTALL_PATH;517 logPath_g= userDataPath / ORXONOX_LOG_INSTALL_PATH;554 configuration_->configPath_ = userDataPath / ORXONOX_CONFIG_INSTALL_PATH; 555 configuration_->logPath_ = userDataPath / ORXONOX_LOG_INSTALL_PATH; 518 556 #endif 519 557 } … … 523 561 { 524 562 std::string directory(CommandLine::getValue("writingPathSuffix").getString()); 525 config Path_g = configPath_g/ directory;526 logPath_g = logPath_g/ directory;563 configuration_->configPath_ = configuration_->configPath_ / directory; 564 configuration_->logPath_ = configuration_->logPath_ / directory; 527 565 } 528 566 } … … 538 576 { 539 577 std::vector<std::pair<boost::filesystem::path, std::string> > directories; 540 directories.push_back(std::make_pair(boost::filesystem::path(config Path_g), "config"));541 directories.push_back(std::make_pair(boost::filesystem::path( logPath_g), "log"));578 directories.push_back(std::make_pair(boost::filesystem::path(configuration_->configPath_), "config")); 579 directories.push_back(std::make_pair(boost::filesystem::path(configuration_->logPath_), "log")); 542 580 543 581 for (std::vector<std::pair<boost::filesystem::path, std::string> >::iterator it = directories.begin(); -
code/branches/core4/src/core/Core.h
r3196 r3247 43 43 44 44 #include <cassert> 45 #include "OrxonoxClass.h"46 45 #include "util/OutputHandler.h" 47 46 48 47 namespace orxonox 49 48 { 49 class CoreConfiguration; 50 50 51 /** 51 52 @brief … … 55 56 It determines those by the use of platform specific functions. 56 57 */ 57 class _CoreExport Core : public OrxonoxClass58 class _CoreExport Core 58 59 { 59 60 public: … … 65 66 GeneralException 66 67 */ 67 Core( );68 Core(int argc, char** argv); 68 69 ~Core(); 69 70 70 void initialise(int argc, char** argv);71 71 void setConfigValues(); 72 72 … … 80 80 static void resetLanguage(); 81 81 82 static void tsetMediaPath(const std::string& path) 83 { assert(singletonRef_s); singletonRef_s->_tsetMediaPath(path); } 82 static void tsetMediaPath(const std::string& path); 84 83 //! Returns the path to the config files as boost::filesystem::path 85 84 static const boost::filesystem::path& getMediaPath(); … … 103 102 void setThreadAffinity(int limitToCPU); 104 103 105 void resetLanguageIntern();106 void initializeRandomNumberGenerator();107 void debugLevelChanged();108 void languageChanged();109 void mediaPathChanged();110 void _tsetMediaPath(const std::string& path);111 112 104 // Singletons 113 105 ConfigFileManager* configFileManager_; … … 119 111 TclThreadManager* tclThreadManager_; 120 112 121 int softDebugLevel_; //!< The debug level122 int softDebugLevelConsole_; //!< The debug level for the console123 int softDebugLevelLogfile_; //!< The debug level for the logfile124 int softDebugLevelShell_; //!< The debug level for the ingame shell125 std::string language_; //!< The language126 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called127 std::string mediaPathString_; //!< Path to the data/media file folder as string128 113 bool isDevBuild_; //!< True for builds in the build directory (not installed) 129 bool loaded_; //!< Only true if constructor was interrupted114 CoreConfiguration* configuration_; 130 115 131 116 static Core* singletonRef_s; -
code/branches/core4/src/core/Game.cc
r3245 r3247 58 58 SetConsoleCommandShortcutExternAlias(stop_game, "exit"); 59 59 60 struct _CoreExport GameStateTreeNode 60 std::map<std::string, Game::GameStateInfo> Game::gameStateDeclarations_s; 61 Game* Game::singletonRef_s = 0; 62 63 64 /** 65 @brief 66 Represents one node of the game state tree. 67 */ 68 struct GameStateTreeNode 61 69 { 62 70 GameState* state_; … … 65 73 }; 66 74 67 std::map<std::string, Game::GameStateInfo> Game::gameStateDeclarations_s; 68 Game* Game::singletonRef_s = 0; 75 76 /** 77 @brief 78 Another helper class for the Game singleton: we cannot derive 79 Game from OrxonoxClass because we need to handle the Identifier 80 destruction in the Core destructor. 81 */ 82 class GameConfiguration : public OrxonoxClass 83 { 84 public: 85 GameConfiguration() 86 { 87 RegisterRootObject(GameConfiguration); 88 this->setConfigValues(); 89 } 90 91 void setConfigValues() 92 { 93 SetConfigValue(statisticsRefreshCycle_, 250000) 94 .description("Sets the time in microseconds interval at which average fps, etc. get updated."); 95 SetConfigValue(statisticsAvgLength_, 1000000) 96 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated."); 97 } 98 99 unsigned int statisticsRefreshCycle_; 100 unsigned int statisticsAvgLength_; 101 }; 102 69 103 70 104 /** … … 99 133 100 134 // Create the Core 101 this->core_ = new orxonox::Core(); 102 this->core_->initialise(argc, argv); 135 this->core_ = new Core(argc, argv); 103 136 104 137 // After the core has been created, we can safely instantiate the GameStates … … 118 151 this->activeStates_.push_back(this->rootStateNode_->state_); 119 152 120 // Do this after Core creation! 121 RegisterRootObject(Game); 122 this->setConfigValues(); 153 // Do this after the Core creation! 154 this->configuration_ = new GameConfiguration(); 123 155 } 124 156 … … 128 160 Game::~Game() 129 161 { 162 // Destroy the configuration helper class instance 163 delete this->configuration_; 164 130 165 // Destroy the GameStates (note that the nodes still point to them, but doesn't matter) 131 166 for (std::map<std::string, GameState*>::const_iterator it = gameStates_.begin(); … … 137 172 delete this->gameClock_; 138 173 139 // Also, take care of the GameStateFactories174 // Take care of the GameStateFactories 140 175 GameStateFactory::destroyFactories(); 141 176 142 177 // Don't assign singletonRef_s with NULL! Recreation is not supported 143 }144 145 void Game::setConfigValues()146 {147 SetConfigValue(statisticsRefreshCycle_, 250000)148 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");149 SetConfigValue(statisticsAvgLength_, 1000000)150 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");151 178 } 152 179 … … 245 272 246 273 // STATISTICS 247 if (this->periodTime_ > statisticsRefreshCycle_)274 if (this->periodTime_ > this->configuration_->statisticsRefreshCycle_) 248 275 { 249 276 std::list<StatisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin(); 250 277 assert(it != this->statisticsTickTimes_.end()); 251 int64_t lastTime = currentTime - this-> statisticsAvgLength_;278 int64_t lastTime = currentTime - this->configuration_->statisticsAvgLength_; 252 279 if ((int64_t)it->tickTime < lastTime) 253 280 { … … 266 293 this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f; 267 294 268 this->periodTime_ -= this-> statisticsRefreshCycle_;295 this->periodTime_ -= this->configuration_->statisticsRefreshCycle_; 269 296 } 270 297 } -
code/branches/core4/src/core/Game.h
r3245 r3247 47 47 48 48 #include "util/Debug.h" 49 #include " OrxonoxClass.h"49 #include "util/String.h" 50 50 51 51 /** … … 57 57 static bool BOOST_PP_CAT(bGameStateDummy_##className, __LINE__) = orxonox::Game::declareGameState<className>(#className, stateName, bIgnoreTickTime, bGraphicsMode) 58 58 59 // tolua_begin60 59 namespace orxonox 61 60 { 61 class GameConfiguration; 62 62 63 /** 63 64 @brief 64 65 Main class responsible for running the game. 65 66 */ 66 class _CoreExport Game : public OrxonoxClass67 class _CoreExport Game 67 68 { 68 69 public: 69 70 Game(int argc, char** argv); 70 71 ~Game(); 71 void setConfigValues();72 72 73 73 void setStateHierarchy(const std::string& str); … … 141 141 Core* core_; 142 142 Clock* gameClock_; 143 GameConfiguration* configuration_; 143 144 144 145 bool bChangingState_; … … 152 153 float avgFPS_; 153 154 float avgTickTime_; 154 155 // config values156 unsigned int statisticsRefreshCycle_;157 unsigned int statisticsAvgLength_;158 155 159 156 static std::map<std::string, GameStateInfo> gameStateDeclarations_s; -
code/branches/core4/src/core/Language.cc
r3198 r3247 194 194 @return The filename 195 195 */ 196 conststd::string Language::getFilename(const std::string& language)196 std::string Language::getFilename(const std::string& language) 197 197 { 198 198 return std::string("translation_" + language + ".lang"); -
code/branches/core4/src/core/Language.h
r2662 r3247 114 114 class _CoreExport Language 115 115 { 116 friend class Core ;116 friend class CoreConfiguration; 117 117 118 118 public: … … 130 130 void readTranslatedLanguageFile(); 131 131 void writeDefaultLanguageFile() const; 132 static conststd::string getFilename(const std::string& language);132 static std::string getFilename(const std::string& language); 133 133 LanguageEntry* createEntry(const LanguageEntryLabel& label, const std::string& entry); 134 134 -
code/branches/core4/src/orxonox/Main.cc
r3243 r3247 37 37 38 38 #include "util/Debug.h" 39 #include " core/Identifier.h"39 #include "util/Exception.h" 40 40 #include "core/Game.h" 41 41 … … 50 50 #endif 51 51 { 52 using namespace orxonox; 53 54 Game* game = 0; 55 try 52 56 { 53 orxonox::Game orxonox(argc, argv);57 game = new Game(argc, argv); 54 58 55 orxonox.setStateHierarchy(59 game->setStateHierarchy( 56 60 "root" 57 61 " graphics" … … 68 72 ); 69 73 70 orxonox.requestState("root"); 71 orxonox.run(); 74 game->requestState("root"); 75 } 76 catch (const std::exception& ex) 77 { 78 COUT(0) << "Orxonox failed to initialise: " << ex.what() << std::endl; 79 COUT(0) << "Terminating program." << std::endl; 80 return 1; 81 } 82 catch (...) 83 { 84 COUT(0) << "Orxonox failed to initialise: " << std::endl; 85 COUT(0) << "Terminating program." << std::endl; 86 return 1; 72 87 } 73 88 74 // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand) 75 // Needs to be done after Game destructor because of ~OrxonoxClass 76 orxonox::Identifier::destroyAllIdentifiers(); 89 game->run(); 77 90 78 91 return 0;
Note: See TracChangeset
for help on using the changeset viewer.