Changeset 3370 for code/trunk/src/core/Core.cc
- Timestamp:
- Jul 30, 2009, 2:10:44 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/resource (added) merged: 3328,3336-3340,3342-3350,3352-3366
- Property svn:mergeinfo changed
-
code/trunk/src/core/Core.cc
r3323 r3370 41 41 #include <cstdio> 42 42 #include <boost/filesystem.hpp> 43 #include <OgreRenderWindow.h> 43 44 44 45 #ifdef ORXONOX_PLATFORM_WINDOWS … … 68 69 #include "CoreIncludes.h" 69 70 #include "Factory.h" 71 #include "GameMode.h" 72 #include "GraphicsManager.h" 73 #include "GUIManager.h" 70 74 #include "Identifier.h" 71 75 #include "Language.h" … … 74 78 #include "TclBind.h" 75 79 #include "TclThreadManager.h" 80 #include "input/InputManager.h" 76 81 77 82 namespace orxonox 78 83 { 79 84 //! Static pointer to the singleton 80 Core* Core::singleton Ref_s = 0;85 Core* Core::singletonPtr_s = 0; 81 86 82 87 SetCommandLineArgument(mediaPath, "").information("Path to the media/data files"); … … 134 139 .callback(this, &CoreConfiguration::debugLevelChanged); 135 140 136 SetConfigValue(language_, Language::get Language().defaultLanguage_)141 SetConfigValue(language_, Language::getInstance().defaultLanguage_) 137 142 .description("The language of the ingame text") 138 143 .callback(this, &CoreConfiguration::languageChanged); … … 141 146 .callback(this, &CoreConfiguration::initializeRandomNumberGenerator); 142 147 143 SetConfigValue(mediaPathString_, mediaPath_.string()) 144 .description("Relative path to the game data.") 145 .callback(this, &CoreConfiguration::mediaPathChanged); 148 // Only show this config value for development builds 149 if (Core::isDevelopmentRun()) 150 { 151 SetConfigValue(mediaPathString_, mediaPath_.string()) 152 .description("Relative path to the game data.") 153 .callback(this, &CoreConfiguration::mediaPathChanged); 154 } 146 155 } 147 156 … … 170 179 { 171 180 // Read the translation file after the language was configured 172 Language::get Language().readTranslatedLanguageFile();181 Language::getInstance().readTranslatedLanguageFile(); 173 182 } 174 183 … … 198 207 void tsetMediaPath(const std::string& path) 199 208 { 200 ModifyConfigValue(mediaPathString_, tset, path); 209 if (Core::isDevelopmentRun()) 210 { 211 ModifyConfigValue(mediaPathString_, tset, path); 212 } 213 else 214 { 215 // Manual 'config' value without the file entry 216 mediaPathString_ = path; 217 this->mediaPathChanged(); 218 } 201 219 } 202 220 … … 230 248 231 249 Core::Core(const std::string& cmdLine) 232 { 233 if (singletonRef_s != 0) 234 { 235 COUT(0) << "Error: The Core singleton cannot be recreated! Shutting down." << std::endl; 236 abort(); 237 } 238 Core::singletonRef_s = this; 239 240 // We need the variables very soon. But don't configure them yet! 241 this->configuration_ = new CoreConfiguration(); 242 250 // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands) 251 : identifierDestroyer_(Identifier::destroyAllIdentifiers) 252 // Cleanup guard for external console commands that don't belong to an Identifier 253 , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands) 254 , configuration_(new CoreConfiguration()) // Don't yet create config values! 255 , bDevRun_(false) 256 , bGraphicsLoaded_(false) 257 { 243 258 // Parse command line arguments first 244 259 CommandLine::parseCommandLine(cmdLine); … … 256 271 // create a signal handler (only active for linux) 257 272 // This call is placed as soon as possible, but after the directories are set 258 this->signalHandler_ = new SignalHandler();273 this->signalHandler_.reset(new SignalHandler()); 259 274 this->signalHandler_->doCatch(configuration_->executablePath_.string(), Core::getLogPathString() + "orxonox_crash.log"); 260 275 … … 275 290 276 291 // Manage ini files and set the default settings file (usually orxonox.ini) 277 this->configFileManager_ = new ConfigFileManager();292 this->configFileManager_.reset(new ConfigFileManager()); 278 293 this->configFileManager_->setFilename(ConfigFileType::Settings, 279 294 CommandLine::getValue("settingsFile").getString()); 280 295 281 296 // Required as well for the config values 282 this->languageInstance_ = new Language();297 this->languageInstance_.reset(new Language()); 283 298 284 299 // Do this soon after the ConfigFileManager has been created to open up the … … 287 302 288 303 // Create the lua interface 289 this->luaBind_ = new LuaBind();304 this->luaBind_.reset(new LuaBind()); 290 305 291 306 // initialise Tcl 292 this->tclBind_ = new TclBind(Core::getMediaPathString());293 this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter());307 this->tclBind_.reset(new TclBind(Core::getMediaPathString())); 308 this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter())); 294 309 295 310 // create a shell 296 this->shell_ = new Shell();311 this->shell_.reset(new Shell()); 297 312 298 313 // creates the class hierarchy for all classes with factories … … 301 316 302 317 /** 303 @brief Sets the bool to true to avoid static functions accessing a deleted object. 318 @brief 319 All destruction code is handled by scoped_ptrs and SimpleScopeGuards. 304 320 */ 305 321 Core::~Core() 306 322 { 307 delete this->shell_; 308 delete this->tclThreadManager_; 309 delete this->tclBind_; 310 delete this->luaBind_; 311 delete this->configuration_; 312 delete this->languageInstance_; 313 delete this->configFileManager_; 314 315 // Destroy command line arguments 316 CommandLine::destroyAllArguments(); 317 // Also delete external console command that don't belong to an Identifier 318 CommandExecutor::destroyExternalCommands(); 319 // Clean up class hierarchy stuff (identifiers, XMLPort, configValues, consoleCommand) 320 Identifier::destroyAllIdentifiers(); 321 322 delete this->signalHandler_; 323 324 // Don't assign singletonRef_s with NULL! Recreation is not supported 323 } 324 325 void Core::loadGraphics() 326 { 327 if (bGraphicsLoaded_) 328 return; 329 330 // Load OGRE including the render window 331 scoped_ptr<GraphicsManager> graphicsManager(new GraphicsManager()); 332 333 // The render window width and height are used to set up the mouse movement. 334 size_t windowHnd = 0; 335 graphicsManager->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd); 336 337 // Calls the InputManager which sets up the input devices. 338 scoped_ptr<InputManager> inputManager(new InputManager(windowHnd)); 339 340 // load the CEGUI interface 341 guiManager_.reset(new GUIManager(graphicsManager->getRenderWindow())); 342 343 // Dismiss scoped pointers 344 graphicsManager_.swap(graphicsManager); 345 inputManager_.swap(inputManager); 346 347 bGraphicsLoaded_ = true; 348 } 349 350 void Core::unloadGraphics() 351 { 352 if (!bGraphicsLoaded_) 353 return; 354 355 this->guiManager_.reset();; 356 this->inputManager_.reset();; 357 this->graphicsManager_.reset(); 358 359 bGraphicsLoaded_ = false; 325 360 } 326 361 … … 415 450 } 416 451 452 /*static*/ const boost::filesystem::path& Core::getRootPath() 453 { 454 return getInstance().configuration_->rootPath_; 455 } 456 /*static*/ std::string Core::getRootPathString() 457 { 458 return getInstance().configuration_->rootPath_.string() + '/'; 459 } 460 417 461 /** 418 462 @note … … 524 568 { 525 569 COUT(1) << "Running from the build tree." << std::endl; 526 Core:: isDevBuild_ = true;570 Core::bDevRun_ = true; 527 571 configuration_->mediaPath_ = ORXONOX_MEDIA_DEV_PATH; 528 572 configuration_->configPath_ = ORXONOX_CONFIG_DEV_PATH; … … 603 647 } 604 648 605 void Core::update(const Clock& time) 606 { 607 this->tclThreadManager_->update(time); 649 bool Core::preUpdate(const Clock& time) throw() 650 { 651 std::string exceptionMessage; 652 try 653 { 654 if (this->bGraphicsLoaded_) 655 { 656 // process input events 657 this->inputManager_->update(time); 658 // process gui events 659 this->guiManager_->update(time); 660 } 661 // process thread commands 662 this->tclThreadManager_->update(time); 663 } 664 catch (const std::exception& ex) 665 { exceptionMessage = ex.what(); } 666 catch (...) 667 { exceptionMessage = "Unknown exception"; } 668 if (!exceptionMessage.empty()) 669 { 670 COUT(0) << "An exception occurred in the Core preUpdate: " << exceptionMessage << std::endl; 671 COUT(0) << "This should really never happen! Closing the program." << std::endl; 672 return false; 673 } 674 return true; 675 } 676 677 bool Core::postUpdate(const Clock& time) throw() 678 { 679 std::string exceptionMessage; 680 try 681 { 682 if (this->bGraphicsLoaded_) 683 { 684 // Render (doesn't throw) 685 this->graphicsManager_->update(time); 686 } 687 } 688 catch (const std::exception& ex) 689 { exceptionMessage = ex.what(); } 690 catch (...) 691 { exceptionMessage = "Unknown exception"; } 692 if (!exceptionMessage.empty()) 693 { 694 COUT(0) << "An exception occurred in the Core postUpdate: " << exceptionMessage << std::endl; 695 COUT(0) << "This should really never happen! Closing the program." << std::endl; 696 return false; 697 } 698 return true; 608 699 } 609 700 }
Note: See TracChangeset
for help on using the changeset viewer.