Changeset 2896 for code/trunk/src/core/Core.cc
- Timestamp:
- Apr 6, 2009, 1:59:00 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/gui merged: 2796,2798-2801,2805,2807-2808,2811,2814-2817,2834,2840-2850,2853-2854,2859,2862-2863,2869,2875,2887,2892
- Property svn:mergeinfo changed
-
code/trunk/src/core/Core.cc
r2759 r2896 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder 24 25 * Co-authors: 25 * Reto Grieder26 * ... 26 27 * 27 28 */ … … 41 42 42 43 #ifdef ORXONOX_PLATFORM_WINDOWS 44 # ifndef WIN32_LEAN_AND_MEAN 45 # define WIN32_LEAN_AND_MEAN 46 # endif 43 47 # include <windows.h> 44 48 #elif defined(ORXONOX_PLATFORM_APPLE) … … 51 55 52 56 #include "SpecialConfig.h" 57 #include "util/Debug.h" 53 58 #include "util/Exception.h" 59 #include "util/SignalHandler.h" 60 #include "Clock.h" 61 #include "CommandExecutor.h" 62 #include "CommandLine.h" 63 #include "ConfigFileManager.h" 64 #include "ConfigValueIncludes.h" 65 #include "CoreIncludes.h" 66 #include "Factory.h" 67 #include "Identifier.h" 54 68 #include "Language.h" 55 #include "CoreIncludes.h"56 #include "ConfigValueIncludes.h"57 69 #include "LuaBind.h" 58 #include "CommandLine.h" 70 #include "Shell.h" 71 #include "TclBind.h" 72 #include "TclThreadManager.h" 59 73 60 74 namespace orxonox … … 67 81 static boost::filesystem::path logPath_g; //!< Path to the log file folder 68 82 69 bool Core::bShowsGraphics_s = false;70 bool Core::bHasServer_s = false;71 bool Core::bIsClient_s = false;72 bool Core::bIsStandalone_s = false;73 bool Core::bIsMaster_s = false;74 75 bool Core::isDevBuild_s = false;76 83 Core* Core::singletonRef_s = 0; 77 84 78 85 SetCommandLineArgument(mediaPath, "").information("PATH"); 79 SetCommandLineArgument(directory, "").information("DIR"); 80 81 /** 82 @brief Constructor: Registers the object and sets the config-values. 83 @param A reference to a global variable, used to avoid an infinite recursion in getSoftDebugLevel() 84 */ 86 SetCommandLineArgument(writingPathSuffix, "").information("DIR"); 87 SetCommandLineArgument(settingsFile, "orxonox.ini"); 88 SetCommandLineArgument(limitToCPU, 0).information("0: off | #cpu"); 89 85 90 Core::Core() 86 91 { … … 89 94 assert(Core::singletonRef_s == 0); 90 95 Core::singletonRef_s = this; 91 92 this->bInitializeRandomNumberGenerator_ = false; 93 this->setConfigValues(); 96 } 97 98 void Core::initialise(int argc, char** argv) 99 { 100 // Parse command line arguments fist 101 try 102 { 103 CommandLine::parseAll(argc, argv); 104 } 105 catch (ArgumentException& ex) 106 { 107 COUT(1) << ex.what() << std::endl; 108 COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl; 109 } 110 111 // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump 112 // do this after ogre has initialised. Somehow Ogre changes the settings again (not through 113 // the timer though). 114 int limitToCPU = CommandLine::getValue("limitToCPU"); 115 if (limitToCPU > 0) 116 setThreadAffinity((unsigned int)limitToCPU); 117 118 // Determine and set the location of the executable 119 setExecutablePath(); 120 121 // Determine whether we have an installed or a binary dir run 122 // The latter occurs when simply running from the build directory 123 checkDevBuild(); 124 125 // Make sure the directories we write in exist or else make them 126 createDirectories(); 127 128 // create a signal handler (only active for linux) 129 // This call is placed as soon as possible, but after the directories are set 130 this->signalHandler_ = new SignalHandler(); 131 this->signalHandler_->doCatch(executablePath_g.string(), Core::getLogPathString() + "orxonox_crash.log"); 94 132 95 133 // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used 96 134 OutputHandler::getOutStream().setLogPath(Core::getLogPathString()); 97 135 136 // Manage ini files and set the default settings file (usually orxonox.ini) 137 this->configFileManager_ = new ConfigFileManager(); 138 this->configFileManager_->setFilename(ConfigFileType::Settings, 139 CommandLine::getValue("settingsFile").getString()); 140 141 this->languageInstance_ = new Language(); 142 143 // Do this soon after the ConfigFileManager has been created to open up the 144 // possibility to configure everything below here 145 this->setConfigValues(); 146 98 147 // Possible media path override by the command line 99 148 if (!CommandLine::getArgument("mediaPath")->hasDefaultValue()) … … 102 151 Core::tsetMediaPath(CommandLine::getValue("mediaPath")); 103 152 } 153 154 // Create the lua interface 155 this->luaBind_ = new LuaBind(); 156 157 // initialise Tcl 158 this->tclBind_ = new TclBind(Core::getMediaPathString()); 159 this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter()); 160 161 // create a shell 162 this->shell_ = new Shell(); 163 164 // creates the class hierarchy for all classes with factories 165 Factory::createClassHierarchy(); 166 167 this->loaded_ = true; 104 168 } 105 169 … … 109 173 Core::~Core() 110 174 { 175 this->loaded_ = false; 176 177 delete this->shell_; 178 delete this->tclThreadManager_; 179 delete this->tclBind_; 180 delete this->luaBind_; 181 delete this->languageInstance_; 182 delete this->configFileManager_; 183 delete this->signalHandler_; 184 185 // Destroy command line arguments 186 CommandLine::destroyAllArguments(); 187 // Also delete external console command that don't belong to an Identifier 188 CommandExecutor::destroyExternalCommands(); 189 111 190 assert(Core::singletonRef_s); 112 191 Core::singletonRef_s = 0; … … 292 371 } 293 372 294 /** 295 @brief 296 Performs the rather lower level operations just after 297 int main() has been called. 298 @remarks 299 This gets called AFTER pre-main stuff like AddFactory, 300 SetConsoleCommand, etc. 301 */ 302 /*static*/ void Core::postMainInitialisation() 303 { 304 // set location of the executable 305 Core::setExecutablePath(); 306 307 // Determine whether we have an installed or a binary dir run 308 // The latter occurs when simply running from the build directory 309 Core::checkDevBuild(); 310 311 // Make sure the directories we write in exist or else make them 312 Core::createDirectories(); 373 374 /** 375 @note 376 The code of this function has been copied and adjusted from OGRE, an open source graphics engine. 377 (Object-oriented Graphics Rendering Engine) 378 For the latest info, see http://www.ogre3d.org/ 379 380 Copyright (c) 2000-2008 Torus Knot Software Ltd 381 382 OGRE is licensed under the LGPL. For more info, see OGRE license. 383 */ 384 void Core::setThreadAffinity(int limitToCPU) 385 { 386 if (limitToCPU <= 0) 387 return; 388 389 #ifdef ORXONOX_PLATFORM_WINDOWS 390 unsigned int coreNr = limitToCPU - 1; 391 // Get the current process core mask 392 DWORD procMask; 393 DWORD sysMask; 394 # if _MSC_VER >= 1400 && defined (_M_X64) 395 GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask); 396 # else 397 GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask); 398 # endif 399 400 // If procMask is 0, consider there is only one core available 401 // (using 0 as procMask will cause an infinite loop below) 402 if (procMask == 0) 403 procMask = 1; 404 405 // if the core specified with coreNr is not available, take the lowest one 406 if (!(procMask & (1 << coreNr))) 407 coreNr = 0; 408 409 // Find the lowest core that this process uses and coreNr suggests 410 DWORD threadMask = 1; 411 while ((threadMask & procMask) == 0 || (threadMask < (1u << coreNr))) 412 threadMask <<= 1; 413 414 // Set affinity to the first core 415 SetThreadAffinityMask(GetCurrentThread(), threadMask); 416 #endif 313 417 } 314 418 … … 317 421 Compares the executable path with the working directory 318 422 */ 319 /*static*/void Core::setExecutablePath()423 void Core::setExecutablePath() 320 424 { 321 425 #ifdef ORXONOX_PLATFORM_WINDOWS … … 369 473 don't write the logs and config files to ~/.orxonox 370 474 */ 371 /*static*/void Core::checkDevBuild()475 void Core::checkDevBuild() 372 476 { 373 477 if (boost::filesystem::exists(executablePath_g / "orxonox_dev_build.keep_me")) 374 478 { 375 479 COUT(1) << "Running from the build tree." << std::endl; 376 Core::isDevBuild_ s= true;480 Core::isDevBuild_ = true; 377 481 mediaPath_g = ORXONOX_MEDIA_DEV_PATH; 378 482 configPath_g = ORXONOX_CONFIG_DEV_PATH; … … 385 489 boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH); 386 490 rootPath_g = executablePath_g; 387 while (!boost::filesystem::equivalent(rootPath_g / relativeExecutablePath, executablePath_g) ||rootPath_g.empty())491 while (!boost::filesystem::equivalent(rootPath_g / relativeExecutablePath, executablePath_g) && !rootPath_g.empty()) 388 492 rootPath_g = rootPath_g.branch_path(); 389 493 if (rootPath_g.empty()) … … 416 520 417 521 // Option to put all the config and log files in a separate folder 418 if (!CommandLine::getArgument(" directory")->hasDefaultValue())419 { 420 std::string directory(CommandLine::getValue(" directory").getString());522 if (!CommandLine::getArgument("writingPathSuffix")->hasDefaultValue()) 523 { 524 std::string directory(CommandLine::getValue("writingPathSuffix").getString()); 421 525 configPath_g = configPath_g / directory; 422 526 logPath_g = logPath_g / directory; … … 429 533 if necessary. Otherwise me might have problems opening those files. 430 534 */ 431 /*static*/void Core::createDirectories()535 void Core::createDirectories() 432 536 { 433 537 std::vector<std::pair<boost::filesystem::path, std::string> > directories; … … 451 555 } 452 556 } 557 558 void Core::update(const Clock& time) 559 { 560 this->tclThreadManager_->update(time); 561 } 453 562 }
Note: See TracChangeset
for help on using the changeset viewer.