Changeset 2799 for code/branches/gui/src/core
- Timestamp:
- Mar 18, 2009, 9:15:39 PM (16 years ago)
- Location:
- code/branches/gui/src/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/Core.cc
r2759 r2799 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 … … 73 87 bool Core::bIsMaster_s = false; 74 88 75 bool Core::isDevBuild_s = false;76 89 Core* Core::singletonRef_s = 0; 77 90 78 91 SetCommandLineArgument(mediaPath, "").information("PATH"); 79 SetCommandLineArgument(directory, "").information("DIR"); 92 SetCommandLineArgument(writingPathSuffix, "").information("DIR"); 93 SetCommandLineArgument(settingsFile, "orxonox.ini"); 94 SetCommandLineArgument(limitToCPU, 0).information("0: off | #cpu"); 80 95 81 96 /** … … 83 98 @param A reference to a global variable, used to avoid an infinite recursion in getSoftDebugLevel() 84 99 */ 85 Core::Core( )100 Core::Core(int argc, char** argv) 86 101 { 87 102 RegisterRootObject(Core); … … 90 105 Core::singletonRef_s = this; 91 106 92 this->bInitializeRandomNumberGenerator_ = false; 93 this->setConfigValues(); 107 // Parse command line arguments fist 108 try 109 { 110 CommandLine::parseAll(argc, argv); 111 } 112 catch (ArgumentException& ex) 113 { 114 COUT(1) << ex.what() << std::endl; 115 COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl; 116 } 117 118 // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump 119 // do this after ogre has initialised. Somehow Ogre changes the settings again (not through 120 // the timer though). 121 int limitToCPU = CommandLine::getValue("limitToCPU"); 122 if (limitToCPU > 0) 123 setThreadAffinity((unsigned int)limitToCPU); 124 125 // Determine and set the location of the executable 126 setExecutablePath(); 127 128 // Determine whether we have an installed or a binary dir run 129 // The latter occurs when simply running from the build directory 130 checkDevBuild(); 131 132 // Make sure the directories we write in exist or else make them 133 createDirectories(); 134 135 // create a signal handler (only active for linux) 136 // This call is placed as soon as possible, but after the directories are set 137 this->signalHandler_ = new SignalHandler(); 138 this->signalHandler_->doCatch(executablePath_g.string(), Core::getLogPathString() + "orxonox_crash.log"); 94 139 95 140 // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used 96 141 OutputHandler::getOutStream().setLogPath(Core::getLogPathString()); 97 142 143 // Manage ini files and set the default settings file (usually orxonox.ini) 144 this->configFileManager_ = new ConfigFileManager(); 145 this->configFileManager_->setFilename(ConfigFileType::Settings, 146 CommandLine::getValue("settingsFile").getString()); 147 148 this->languageInstance_ = new Language(); 149 150 // Do this soon after the ConfigFileManager has been created to open up the 151 // possibility to configure everything below here 152 this->setConfigValues(); 153 98 154 // Possible media path override by the command line 99 155 if (!CommandLine::getArgument("mediaPath")->hasDefaultValue()) … … 102 158 Core::tsetMediaPath(CommandLine::getValue("mediaPath")); 103 159 } 160 161 // Create the lua interface 162 this->luaBind_ = new LuaBind(); 163 164 // initialise Tcl 165 this->tclBind_ = new TclBind(Core::getMediaPathString()); 166 this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter()); 167 168 // create a shell 169 this->shell_ = new Shell(); 170 171 // creates the class hierarchy for all classes with factories 172 Factory::createClassHierarchy(); 173 174 this->loaded_ = true; 104 175 } 105 176 … … 109 180 Core::~Core() 110 181 { 182 this->loaded_ = false; 183 184 delete this->shell_; 185 delete this->tclThreadManager_; 186 delete this->tclBind_; 187 delete this->luaBind_; 188 delete this->languageInstance_; 189 delete this->configFileManager_; 190 delete this->signalHandler_; 191 192 // Destroy command line arguments 193 CommandLine::destroyAllArguments(); 194 // Also delete external console command that don't belong to an Identifier 195 CommandExecutor::destroyExternalCommands(); 196 111 197 assert(Core::singletonRef_s); 112 198 Core::singletonRef_s = 0; … … 292 378 } 293 379 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(); 380 381 /** 382 @note 383 The code of this function has been copied and adjusted from OGRE, an open source graphics engine. 384 (Object-oriented Graphics Rendering Engine) 385 For the latest info, see http://www.ogre3d.org/ 386 387 Copyright (c) 2000-2008 Torus Knot Software Ltd 388 389 OGRE is licensed under the LGPL. For more info, see OGRE license. 390 */ 391 void Core::setThreadAffinity(int limitToCPU) 392 { 393 if (limitToCPU <= 0) 394 return; 395 396 unsigned int coreNr = limitToCPU - 1; 397 #ifdef ORXONOX_PLATFORM_WINDOWS 398 // Get the current process core mask 399 DWORD procMask; 400 DWORD sysMask; 401 # if _MSC_VER >= 1400 && defined (_M_X64) 402 GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask); 403 # else 404 GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask); 405 # endif 406 407 // If procMask is 0, consider there is only one core available 408 // (using 0 as procMask will cause an infinite loop below) 409 if (procMask == 0) 410 procMask = 1; 411 412 // if the core specified with coreNr is not available, take the lowest one 413 if (!(procMask & (1 << coreNr))) 414 coreNr = 0; 415 416 // Find the lowest core that this process uses and coreNr suggests 417 DWORD threadMask = 1; 418 while ((threadMask & procMask) == 0 || (threadMask < (1u << coreNr))) 419 threadMask <<= 1; 420 421 // Set affinity to the first core 422 SetThreadAffinityMask(GetCurrentThread(), threadMask); 423 #endif 313 424 } 314 425 … … 317 428 Compares the executable path with the working directory 318 429 */ 319 /*static*/void Core::setExecutablePath()430 void Core::setExecutablePath() 320 431 { 321 432 #ifdef ORXONOX_PLATFORM_WINDOWS … … 369 480 don't write the logs and config files to ~/.orxonox 370 481 */ 371 /*static*/void Core::checkDevBuild()482 void Core::checkDevBuild() 372 483 { 373 484 if (boost::filesystem::exists(executablePath_g / "orxonox_dev_build.keep_me")) 374 485 { 375 486 COUT(1) << "Running from the build tree." << std::endl; 376 Core::isDevBuild_ s= true;487 Core::isDevBuild_ = true; 377 488 mediaPath_g = ORXONOX_MEDIA_DEV_PATH; 378 489 configPath_g = ORXONOX_CONFIG_DEV_PATH; … … 416 527 417 528 // 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());529 if (!CommandLine::getArgument("writingPathSuffix")->hasDefaultValue()) 530 { 531 std::string directory(CommandLine::getValue("writingPathSuffix").getString()); 421 532 configPath_g = configPath_g / directory; 422 533 logPath_g = logPath_g / directory; … … 429 540 if necessary. Otherwise me might have problems opening those files. 430 541 */ 431 /*static*/void Core::createDirectories()542 void Core::createDirectories() 432 543 { 433 544 std::vector<std::pair<boost::filesystem::path, std::string> > directories; … … 451 562 } 452 563 } 564 565 void Core::tick(const Clock& time) 566 { 567 this->tclThreadManager_->tick(time.getDeltaTime()); 568 } 453 569 } -
code/branches/gui/src/core/Core.h
r2759 r2799 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder 24 25 * Co-authors: 25 * Reto Grieder26 * ... 26 27 * 27 28 */ … … 59 60 class _CoreExport Core : public OrxonoxClass 60 61 { 61 friend int ::main(int, char**); // sets isDevBuild_s62 63 62 public: 64 Core( );63 Core(int argc, char** argv); 65 64 ~Core(); 66 65 void setConfigValues(); 66 67 bool isLoaded() { return this->loaded_; } 68 void tick(const Clock& time); 67 69 68 70 static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; } … … 72 74 static const std::string& getLanguage(); 73 75 static void resetLanguage(); 74 75 static bool isDevBuild() { return Core::isDevBuild_s; }76 76 77 77 static void tsetMediaPath(const std::string& path) … … 98 98 private: 99 99 Core(const Core&); 100 101 void checkDevBuild(); 102 void setExecutablePath(); 103 void createDirectories(); 104 void setThreadAffinity(int limitToCPU); 105 100 106 void resetLanguageIntern(); 101 107 void initializeRandomNumberGenerator(); … … 105 111 void _tsetMediaPath(const std::string& path); 106 112 107 static void postMainInitialisation(); 108 static void checkDevBuild(); 109 static void setExecutablePath(); 110 static void createDirectories(); 113 // Singletons 114 ConfigFileManager* configFileManager_; 115 Language* languageInstance_; 116 LuaBind* luaBind_; 117 Shell* shell_; 118 SignalHandler* signalHandler_; 119 TclBind* tclBind_; 120 TclThreadManager* tclThreadManager_; 111 121 112 122 int softDebugLevel_; //!< The debug level … … 117 127 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 118 128 std::string mediaPathString_; //!< Path to the data/media file folder as string 129 bool isDevBuild_; //!< True for builds in the build directory (not installed) 130 bool loaded_; //!< Only true if constructor was interrupted 119 131 120 132 static bool bShowsGraphics_s; //!< global variable that tells whether to show graphics … … 124 136 static bool bIsMaster_s; 125 137 126 static bool isDevBuild_s; //!< True for builds in the build directory (not installed)127 128 138 static Core* singletonRef_s; 129 139 };
Note: See TracChangeset
for help on using the changeset viewer.