Changeset 7421 for sandbox_qt/src/libraries/core/Core.cc
- Timestamp:
- Sep 12, 2010, 12:47:30 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox_qt/src/libraries/core/Core.cc
r7401 r7421 31 31 @file 32 32 @brief 33 Implementation of the Core singleton with its global variables (avoids boost include)33 Implementation of the Core singleton 34 34 */ 35 35 … … 37 37 38 38 #include <cassert> 39 #include <ctime> 39 40 #include <fstream> 40 41 #include <vector> … … 49 50 #endif 50 51 51 #include "util/Clock.h"52 52 #include "util/Debug.h" 53 53 #include "util/Exception.h" 54 #include "util/Scope.h"55 #include "util/ScopedSingletonManager.h"56 #include "util/SignalHandler.h"57 54 #include "PathConfig.h" 58 #include "CommandLineParser.h"59 #include "ConfigFileManager.h"60 #include "ConfigValueIncludes.h"61 #include "CoreIncludes.h"62 #include "DynLibManager.h"63 #include "GameMode.h"64 #include "GraphicsManager.h"65 #include "GUIManager.h"66 #include "Identifier.h"67 #include "Language.h"68 #include "LuaState.h"69 #include "command/ConsoleCommand.h"70 #include "command/IOConsole.h"71 #include "command/TclBind.h"72 #include "command/TclThreadManager.h"73 #include "input/InputManager.h"74 55 75 56 namespace orxonox … … 78 59 Core* Core::singletonPtr_s = 0; 79 60 80 SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");81 SetCommandLineSwitch(noIOConsole).information("Use this if you don't want to use the IOConsole (for instance for Lua debugging)");82 83 #ifdef ORXONOX_PLATFORM_WINDOWS84 SetCommandLineArgument(limitToCPU, 1).information("Limits the program to one CPU/core (1, 2, 3, etc.). Default is the first core (faster than off)");85 #endif86 87 61 Core::Core(const std::string& cmdLine) 88 // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands)89 : identifierDestroyer_(Identifier::destroyAllIdentifiers)90 // Cleanup guard for external console commands that don't belong to an Identifier91 , consoleCommandDestroyer_(ConsoleCommand::destroyAll)92 , bGraphicsLoaded_(false)93 , bStartIOConsole_(true)94 62 { 95 63 // Set the hard coded fixed paths 96 64 this->pathConfig_.reset(new PathConfig()); 97 65 98 // Create a new dynamic library manager99 this->dynLibManager_.reset(new DynLibManager());100 101 // Load modules102 const std::vector<std::string>& modulePaths = this->pathConfig_->getModulePaths();103 for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it)104 {105 try106 {107 this->dynLibManager_->load(*it);108 }109 catch (...)110 {111 COUT(1) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << std::endl;112 }113 }114 115 // Parse command line arguments AFTER the modules have been loaded (static code!)116 CommandLineParser::parseCommandLine(cmdLine);117 118 66 // Set configurable paths like log, config and media 119 67 this->pathConfig_->setConfigurablePaths(); 120 121 // create a signal handler (only active for Linux)122 // This call is placed as soon as possible, but after the directories are set123 this->signalHandler_.reset(new SignalHandler());124 this->signalHandler_->doCatch(PathConfig::getExecutablePathString(), PathConfig::getLogPathString() + "orxonox_crash.log");125 68 126 69 // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% (Windows) was used 127 70 OutputHandler::getInstance().setLogPath(PathConfig::getLogPathString()); 128 71 129 // Parse additional options file now that we know its path130 CommandLineParser::parseFile();131 132 72 #ifdef ORXONOX_PLATFORM_WINDOWS 133 73 // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump 134 // do this after ogre has initialised. Somehow Ogre changes the settings again (not through 135 // the timer though). 136 int limitToCPU = CommandLineParser::getValue("limitToCPU"); 74 int limitToCPU = 0;//CommandLineParser::getValue("limitToCPU"); 137 75 if (limitToCPU > 0) 138 76 setThreadAffinity(static_cast<unsigned int>(limitToCPU)); 139 77 #endif 140 78 141 // Manage ini files and set the default settings file (usually orxonox.ini)142 this->configFileManager_.reset(new ConfigFileManager());143 this->configFileManager_->setFilename(ConfigFileType::Settings,144 CommandLineParser::getValue("settingsFile").getString());145 146 // Required as well for the config values147 this->languageInstance_.reset(new Language());148 149 // Do this soon after the ConfigFileManager has been created to open up the150 // possibility to configure everything below here151 ClassIdentifier<Core>::getIdentifier("Core")->initialiseObject(this, "Core", true);152 this->setConfigValues();153 154 // create persistent io console155 if (CommandLineParser::getValue("noIOConsole").getBool())156 {157 ModifyConfigValue(bStartIOConsole_, tset, false);158 }159 if (this->bStartIOConsole_)160 this->ioConsole_.reset(new IOConsole());161 162 // creates the class hierarchy for all classes with factories163 Identifier::createClassHierarchy();164 165 // Load OGRE excluding the renderer and the render window166 this->graphicsManager_.reset(new GraphicsManager(false));167 168 // initialise Tcl169 this->tclBind_.reset(new TclBind(PathConfig::getDataPathString()));170 this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter()));171 172 // Create singletons that always exist (in other libraries)173 this->rootScope_.reset(new Scope<ScopeID::Root>());174 175 79 // Generate documentation instead of normal run? 176 80 std::string docFilename; 177 CommandLineParser::getValue("generateDoc", &docFilename);81 //CommandLineParser::getValue("generateDoc", &docFilename); 178 82 if (!docFilename.empty()) 179 83 { … … 181 85 if (docFile.is_open()) 182 86 { 183 CommandLineParser::generateDoc(docFile);87 //CommandLineParser::generateDoc(docFile); 184 88 docFile.close(); 185 89 } … … 191 95 /** 192 96 @brief 193 All destruction code is handled by scoped_ptrs and ScopeGuards.97 All destruction code is handled by QScopedPointers 194 98 */ 195 99 Core::~Core() 196 100 { 197 // Remove us from the object lists again to avoid problems when destroying them198 this->unregisterObject();199 101 } 200 102 … … 207 109 const unsigned int defaultLevelLogFile = 4; 208 110 #endif 111 /* 209 112 SetConfigValueExternal(softDebugLevelLogFile_, "OutputHandler", "softDebugLevelLogFile", defaultLevelLogFile) 210 113 .description("The maximum level of debug output shown in the log file"); … … 219 122 SetConfigValue(bStartIOConsole_, true) 220 123 .description("Set to false if you don't want to use the IOConsole (for Lua debugging for instance)"); 221 } 222 223 //! Callback function if the language has changed. 224 void Core::languageChanged() 225 { 226 // Read the translation file after the language was configured 227 Language::getInstance().readTranslatedLanguageFile(); 124 */ 228 125 } 229 126 … … 237 134 bInitialized = true; 238 135 } 239 }240 241 void Core::loadGraphics()242 {243 // Any exception should trigger this, even in upgradeToGraphics (see its remarks)244 Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics);245 246 // Upgrade OGRE to receive a render window247 try248 {249 graphicsManager_->upgradeToGraphics();250 }251 catch (...)252 {253 // Recovery from this is very difficult. It requires to completely254 // destroy Ogre related objects and load again (without graphics).255 // However since Ogre 1.7 there seems to be a problem when Ogre256 // throws an exception and the graphics engine then gets destroyed257 // and reloaded between throw and catch (access violation in MSVC).258 // That's why we abort completely and only display the exception.259 COUT(0) << "An exception occurred during upgrade to graphics. "260 << "That is unrecoverable. The message was:" << endl261 << Exception::handleMessage() << endl;262 abort();263 }264 265 // Calls the InputManager which sets up the input devices.266 inputManager_.reset(new InputManager());267 268 // Load the CEGUI interface269 guiManager_.reset(new GUIManager(inputManager_->getMousePosition()));270 271 bGraphicsLoaded_ = true;272 GameMode::bShowsGraphics_s = true;273 274 // Load some sort of a debug overlay (only denoted by its name, "debug.oxo")275 graphicsManager_->loadDebugOverlay();276 277 // Create singletons associated with graphics (in other libraries)278 graphicsScope_.reset(new Scope<ScopeID::Graphics>());279 280 unloader.Dismiss();281 }282 283 void Core::unloadGraphics()284 {285 this->graphicsScope_.reset();286 this->guiManager_.reset();287 this->inputManager_.reset();288 this->graphicsManager_.reset();289 290 // Load Ogre::Root again, but without the render system291 try292 { this->graphicsManager_.reset(new GraphicsManager(false)); }293 catch (...)294 {295 COUT(0) << "An exception occurred during 'unloadGraphics':" << Exception::handleMessage() << std::endl296 << "Another exception might be being handled which may lead to undefined behaviour!" << std::endl297 << "Terminating the program." << std::endl;298 abort();299 }300 301 bGraphicsLoaded_ = false;302 GameMode::bShowsGraphics_s = false;303 }304 305 //! Sets the language in the config-file back to the default.306 void Core::resetLanguage()307 {308 ResetConfigValue(language_);309 136 } 310 137 … … 354 181 #endif 355 182 } 356 357 void Core::preUpdate(const Clock& time)358 {359 // Update singletons before general ticking360 ScopedSingletonManager::preUpdate<ScopeID::Root>(time);361 if (this->bGraphicsLoaded_)362 {363 // Process input events364 this->inputManager_->preUpdate(time);365 // Update GUI366 this->guiManager_->preUpdate(time);367 // Update singletons before general ticking368 ScopedSingletonManager::preUpdate<ScopeID::Graphics>(time);369 }370 // Process console events and status line371 if (this->ioConsole_ != NULL)372 this->ioConsole_->preUpdate(time);373 // Process thread commands374 this->tclThreadManager_->preUpdate(time);375 }376 377 void Core::postUpdate(const Clock& time)378 {379 // Update singletons just before rendering380 ScopedSingletonManager::postUpdate<ScopeID::Root>(time);381 if (this->bGraphicsLoaded_)382 {383 // Update singletons just before rendering384 ScopedSingletonManager::postUpdate<ScopeID::Graphics>(time);385 // Render (doesn't throw)386 this->graphicsManager_->postUpdate(time);387 }388 }389 183 }
Note: See TracChangeset
for help on using the changeset viewer.