Changeset 2799 for code/branches/gui/src
- Timestamp:
- Mar 18, 2009, 9:15:39 PM (16 years ago)
- Location:
- code/branches/gui/src
- Files:
-
- 8 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 }; -
code/branches/gui/src/orxonox/Main.cc
r2716 r2799 34 34 35 35 #include "OrxonoxStableHeaders.h" 36 #include "OrxonoxConfig.h" 36 37 37 38 #include <exception> 38 39 #include <cassert> 39 40 40 #include "OrxonoxConfig.h"41 41 #include "util/Debug.h" 42 #include "util/SignalHandler.h" 43 #include "core/ConfigFileManager.h" 44 #include "core/CommandLine.h" 45 #include "core/CommandExecutor.h" 42 #include "core/Core.h" 46 43 #include "core/Identifier.h" 47 #include "core/Core.h"48 #include "core/Language.h"49 44 50 45 #include "gamestates/GSRoot.h" … … 85 80 86 81 87 SetCommandLineArgument(settingsFile, "orxonox.ini");88 SetCommandLineArgument(configFileDirectory, "");89 82 90 83 int main(int argc, char** argv) 91 84 { 92 using namespace orxonox; 93 94 // Parse command line arguments 95 try 85 orxonox::Core* core = new orxonox::Core(argc, argv); 86 if (!core->isLoaded()) 96 87 { 97 CommandLine::parseAll(argc, argv); 88 COUT(0) << "Core was not fully loaded, probably an exception occurred during consruction. Aborting" << std::endl; 89 abort(); 98 90 } 99 catch (ArgumentException& ex)100 {101 COUT(1) << ex.what() << std::endl;102 COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;103 }104 105 // Do this after parsing the command line to allow customisation106 Core::postMainInitialisation();107 108 // create a signal handler (only active for linux)109 SignalHandler signalHandler;110 signalHandler.doCatch(argv[0], Core::getLogPathString() + "orxonox_crash.log");111 112 // Create the ConfigFileManager before creating the GameStates in order to have113 // setConfigValues() in the constructor (required).114 ConfigFileManager* configFileManager = new ConfigFileManager();115 configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString());116 // create the Core settings to configure the output level117 Language* language = new Language();118 Core* core = new Core();119 91 120 92 // put GameStates in its own scope so we can destroy the identifiers at the end of main(). 121 93 { 94 using namespace orxonox; 122 95 // create the gamestates 123 96 GSRoot root; … … 143 116 } 144 117 145 // destroy singletons118 // Destroy pretty much everyhting left 146 119 delete core; 147 delete language;148 delete configFileManager;149 120 150 121 // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand) 151 Identifier::destroyAllIdentifiers(); 152 // destroy command line arguments 153 CommandLine::destroyAllArguments(); 154 // Also delete external console command that don't belong to an Identifier 155 CommandExecutor::destroyExternalCommands(); 122 // Needs to be done after 'delete core' because of ~OrxonoxClass 123 orxonox::Identifier::destroyAllIdentifiers(); 156 124 157 125 return 0; -
code/branches/gui/src/orxonox/gamestates/GSGraphics.h
r2756 r2799 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include <OgrePrerequisites.h>34 33 #define NOMINMAX // required to stop windows.h screwing up std::min definition 35 34 #include <OgreWindowEventUtilities.h> 35 #include <OgreLog.h> 36 36 #include "core/GameState.h" 37 37 #include "core/OrxonoxClass.h" -
code/branches/gui/src/orxonox/gamestates/GSRoot.cc
r2759 r2799 33 33 #include "util/Debug.h" 34 34 #include "core/Core.h" 35 #include "core/Factory.h"36 35 #include "core/ConfigValueIncludes.h" 37 36 #include "core/CoreIncludes.h" 38 37 #include "core/ConsoleCommand.h" 39 #include "core/CommandLine.h"40 #include "core/Shell.h"41 #include "core/TclBind.h"42 #include "core/TclThreadManager.h"43 #include "core/LuaBind.h"44 38 #include "tools/Timer.h" 45 39 #include "objects/Tickable.h" 46 40 47 #ifdef ORXONOX_PLATFORM_WINDOWS48 # ifndef WIN32_LEAN_AND_MEAN49 # define WIN32_LEAN_AND_MEAN50 # endif51 # define NOMINMAX // required to stop windows.h screwing up std::min definition52 # include "windows.h"53 #endif54 55 41 namespace orxonox 56 42 { 57 SetCommandLineArgument(limitToCPU, 1).information("0: off | #cpu");58 59 43 GSRoot::GSRoot() 60 44 : RootGameState("root") … … 62 46 , bPaused_(false) 63 47 , timeFactorPauseBackup_(1.0f) 64 , tclBind_(0)65 , tclThreadManager_(0)66 , shell_(0)67 48 { 68 49 RegisterRootObject(GSRoot); … … 87 68 void GSRoot::enter() 88 69 { 89 // creates the class hierarchy for all classes with factories90 Factory::createClassHierarchy();91 92 70 // reset game speed to normal 93 71 timeFactor_ = 1.0f; … … 100 78 this->avgTickTime_ = 0.0f; 101 79 102 // Create the lua interface103 this->luaBind_ = new LuaBind();104 105 // initialise TCL106 this->tclBind_ = new TclBind(Core::getMediaPathString());107 this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter());108 109 // create a shell110 this->shell_ = new Shell();111 112 // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump113 // do this after ogre has initialised. Somehow Ogre changes the settings again (not through114 // the timer though).115 int limitToCPU = CommandLine::getValue("limitToCPU");116 if (limitToCPU > 0)117 setThreadAffinity((unsigned int)(limitToCPU - 1));118 119 80 { 120 81 // add console commands … … 156 117 delete this->ccSelectGameState_; 157 118 158 delete this->shell_;159 delete this->tclThreadManager_;160 delete this->tclBind_;161 162 delete this->luaBind_;163 164 119 if (this->ccSetTimeFactor_) 165 120 { … … 179 134 uint64_t timeBeforeTick = time.getRealMicroseconds(); 180 135 181 TclThreadManager::getInstance().tick(time.getDeltaTime());136 Core::getInstance().tick(time); 182 137 183 138 for (ObjectList<TimerBase>::iterator it = ObjectList<TimerBase>::begin(); it; ++it) … … 235 190 236 191 /** 237 @note238 The code of this function has been copied and adjusted from OGRE, an open source graphics engine.239 (Object-oriented Graphics Rendering Engine)240 For the latest info, see http://www.ogre3d.org/241 242 Copyright (c) 2000-2008 Torus Knot Software Ltd243 244 OGRE is licensed under the LGPL. For more info, see OGRE license.245 */246 void GSRoot::setThreadAffinity(unsigned int limitToCPU)247 {248 #ifdef ORXONOX_PLATFORM_WINDOWS249 // Get the current process core mask250 DWORD procMask;251 DWORD sysMask;252 # if _MSC_VER >= 1400 && defined (_M_X64)253 GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);254 # else255 GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);256 # endif257 258 // If procMask is 0, consider there is only one core available259 // (using 0 as procMask will cause an infinite loop below)260 if (procMask == 0)261 procMask = 1;262 263 // if the core specified with limitToCPU is not available, take the lowest one264 if (!(procMask & (1 << limitToCPU)))265 limitToCPU = 0;266 267 // Find the lowest core that this process uses and limitToCPU suggests268 DWORD threadMask = 1;269 while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU)))270 threadMask <<= 1;271 272 // Set affinity to the first core273 SetThreadAffinityMask(GetCurrentThread(), threadMask);274 #endif275 }276 277 /**278 192 @brief 279 193 Changes the speed of Orxonox -
code/branches/gui/src/orxonox/gamestates/GSRoot.h
r2710 r2799 33 33 34 34 #include <list> 35 #include <OgreLog.h>36 35 #include "core/RootGameState.h" 37 36 #include "core/OrxonoxClass.h" … … 76 75 77 76 void setConfigValues(); 78 void setThreadAffinity(unsigned int limitToCPU);79 77 80 78 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal. 81 79 bool bPaused_; 82 80 float timeFactorPauseBackup_; 83 TclBind* tclBind_;84 TclThreadManager* tclThreadManager_;85 Shell* shell_;86 LuaBind* luaBind_;87 81 88 82 // variables for time statistics -
code/branches/gui/src/orxonox/objects/worldentities/Model.cc
r2662 r2799 31 31 #include <OgreEntity.h> 32 32 #include "Model.h" 33 #include "core/Core.h" 33 34 #include "core/CoreIncludes.h" 34 35 #include "core/XMLPort.h" -
code/branches/gui/src/orxonox/objects/worldentities/ParticleEmitter.cc
r2662 r2799 39 39 #include "tools/ParticleInterface.h" 40 40 #include "util/Exception.h" 41 #include "core/Core.h" 41 42 #include "core/CoreIncludes.h" 42 43 #include "core/XMLPort.h"
Note: See TracChangeset
for help on using the changeset viewer.