Changeset 5695 for code/trunk/src/core/Core.cc
- Timestamp:
- Aug 30, 2009, 2:22:00 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/resource2 (added) merged: 3373-3374,5594,5597,5610-5611,5614,5624,5641,5644-5646,5650-5664,5667-5672,5682-5684,5688-5691,5694
- Property svn:mergeinfo changed
-
code/trunk/src/core/Core.cc
r5693 r5695 42 42 #include <boost/version.hpp> 43 43 #include <boost/filesystem.hpp> 44 #include <OgreRenderWindow.h>45 44 46 45 #ifdef ORXONOX_PLATFORM_WINDOWS … … 76 75 #include "Identifier.h" 77 76 #include "Language.h" 78 #include "Lua Bind.h"77 #include "LuaState.h" 79 78 #include "Shell.h" 80 79 #include "TclBind.h" … … 94 93 Core* Core::singletonPtr_s = 0; 95 94 96 SetCommandLineArgument( mediaPath, "").information("Path to the media/data files");95 SetCommandLineArgument(externalDataPath, "").information("Path to the external data files"); 97 96 SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files"); 98 97 SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file"); … … 119 118 this->setConfigValues(); 120 119 121 // Possible media path override by the command line 122 if (!CommandLine::getArgument("mediaPath")->hasDefaultValue()) 123 tsetMediaPath(CommandLine::getValue("mediaPath")); 120 // External data directory only exists for dev runs 121 if (Core::isDevelopmentRun()) 122 { 123 // Possible data path override by the command line 124 if (!CommandLine::getArgument("externalDataPath")->hasDefaultValue()) 125 tsetExternalDataPath(CommandLine::getValue("externalDataPath")); 126 } 124 127 } 125 128 … … 154 157 .description("If true, all random actions are different each time you start the game") 155 158 .callback(this, &CoreConfiguration::initializeRandomNumberGenerator); 156 157 // Only show this config value for development builds158 if (Core::isDevelopmentRun())159 {160 SetConfigValue(mediaPathString_, mediaPath_.string())161 .description("Relative path to the game data.")162 .callback(this, &CoreConfiguration::mediaPathChanged);163 }164 159 } 165 160 … … 192 187 193 188 /** 194 @brief195 Callback function if the media path has changed.196 */197 void mediaPathChanged()198 {199 mediaPath_ = boost::filesystem::path(this->mediaPathString_);200 }201 202 /**203 189 @brief Sets the language in the config-file back to the default. 204 190 */ … … 210 196 /** 211 197 @brief 212 Temporary sets the media path198 Temporary sets the data path 213 199 @param path 214 The new media path200 The new data path 215 201 */ 216 void tsetMediaPath(const std::string& path) 217 { 218 if (Core::isDevelopmentRun()) 219 { 220 ModifyConfigValue(mediaPathString_, tset, path); 221 } 222 else 223 { 224 // Manual 'config' value without the file entry 225 mediaPathString_ = path; 226 this->mediaPathChanged(); 227 } 202 void tsetExternalDataPath(const std::string& path) 203 { 204 dataPath_ = boost::filesystem::path(path); 228 205 } 229 206 … … 245 222 std::string language_; //!< The language 246 223 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 247 std::string mediaPathString_; //!< Path to the data/media file folder as string248 224 249 225 //! Path to the parent directory of the ones above if program was installed with relativ pahts … … 251 227 boost::filesystem::path executablePath_; //!< Path to the executable 252 228 boost::filesystem::path modulePath_; //!< Path to the modules 253 boost::filesystem::path mediaPath_; //!< Path to the media file folder 229 boost::filesystem::path dataPath_; //!< Path to the data file folder 230 boost::filesystem::path externalDataPath_; //!< Path to the external data file folder 254 231 boost::filesystem::path configPath_; //!< Path to the config file folder 255 232 boost::filesystem::path logPath_; //!< Path to the log file folder … … 276 253 { 277 254 // We search for helper files with the following extension 278 std::string moduleextension = ORXONOX_MODULE_EXTENSION;255 std::string moduleextension = specialConfig::moduleExtension; 279 256 size_t moduleextensionlength = moduleextension.size(); 280 257 … … 364 341 this->languageInstance_.reset(new Language()); 365 342 343 // creates the class hierarchy for all classes with factories 344 Factory::createClassHierarchy(); 345 366 346 // Do this soon after the ConfigFileManager has been created to open up the 367 347 // possibility to configure everything below here 368 348 this->configuration_->initialise(); 369 349 370 // Create the lua interface371 this-> luaBind_.reset(new LuaBind());350 // Load OGRE excluding the renderer and the render window 351 this->graphicsManager_.reset(new GraphicsManager(false)); 372 352 373 353 // initialise Tcl 374 this->tclBind_.reset(new TclBind(Core::get MediaPathString()));354 this->tclBind_.reset(new TclBind(Core::getDataPathString())); 375 355 this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter())); 376 356 377 357 // create a shell 378 358 this->shell_.reset(new Shell()); 379 380 // creates the class hierarchy for all classes with factories381 Factory::createClassHierarchy();382 359 } 383 360 384 361 /** 385 362 @brief 386 All destruction code is handled by scoped_ptrs and S impleScopeGuards.363 All destruction code is handled by scoped_ptrs and ScopeGuards. 387 364 */ 388 365 Core::~Core() … … 392 369 void Core::loadGraphics() 393 370 { 394 if (bGraphicsLoaded_) 395 return; 396 397 // Load OGRE including the render window 398 scoped_ptr<GraphicsManager> graphicsManager(new GraphicsManager()); 399 400 // The render window width and height are used to set up the mouse movement. 401 size_t windowHnd = 0; 402 graphicsManager->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd); 371 // Any exception should trigger this, even in upgradeToGraphics (see its remarks) 372 Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics); 373 374 // Upgrade OGRE to receive a render window 375 graphicsManager_->upgradeToGraphics(); 403 376 404 377 // Calls the InputManager which sets up the input devices. 405 scoped_ptr<InputManager> inputManager(new InputManager(windowHnd));378 inputManager_.reset(new InputManager()); 406 379 407 380 // load the CEGUI interface 408 guiManager_.reset(new GUIManager(graphicsManager->getRenderWindow())); 409 410 // Dismiss scoped pointers 411 graphicsManager_.swap(graphicsManager); 412 inputManager_.swap(inputManager); 381 guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(), 382 inputManager_->getMousePosition(), graphicsManager_->isFullScreen())); 383 384 unloader.Dismiss(); 413 385 414 386 bGraphicsLoaded_ = true; … … 417 389 void Core::unloadGraphics() 418 390 { 419 if (!bGraphicsLoaded_)420 return;421 422 391 this->guiManager_.reset();; 423 392 this->inputManager_.reset();; 424 393 this->graphicsManager_.reset(); 394 395 // Load Ogre::Root again, but without the render system 396 try 397 { this->graphicsManager_.reset(new GraphicsManager(false)); } 398 catch (...) 399 { 400 COUT(0) << "An exception occurred during 'new GraphicsManager' while " 401 << "another exception was being handled. This will lead to undefined behaviour!" << std::endl 402 << "Terminating the program." << std::endl; 403 abort(); 404 } 425 405 426 406 bGraphicsLoaded_ = false; … … 485 465 } 486 466 487 /*static*/ void Core::tsetMediaPath(const std::string& path) 488 { 489 getInstance().configuration_->tsetMediaPath(path); 490 } 491 492 /*static*/ const boost::filesystem::path& Core::getMediaPath() 493 { 494 return getInstance().configuration_->mediaPath_; 495 } 496 /*static*/ std::string Core::getMediaPathString() 497 { 498 return getInstance().configuration_->mediaPath_.string() + '/'; 467 /*static*/ void Core::tsetExternalDataPath(const std::string& path) 468 { 469 getInstance().configuration_->tsetExternalDataPath(path); 470 } 471 472 /*static*/ const boost::filesystem::path& Core::getDataPath() 473 { 474 return getInstance().configuration_->dataPath_; 475 } 476 /*static*/ std::string Core::getDataPathString() 477 { 478 return getInstance().configuration_->dataPath_.string() + '/'; 479 } 480 481 /*static*/ const boost::filesystem::path& Core::getExternalDataPath() 482 { 483 return getInstance().configuration_->externalDataPath_; 484 } 485 /*static*/ std::string Core::getExternalDataPathString() 486 { 487 return getInstance().configuration_->externalDataPath_.string() + '/'; 499 488 } 500 489 … … 638 627 COUT(1) << "Running from the build tree." << std::endl; 639 628 Core::bDevRun_ = true; 640 configuration_->modulePath_ = ORXONOX_MODULE_DEV_PATH;629 configuration_->modulePath_ = specialConfig::moduleDevDirectory; 641 630 } 642 631 else … … 646 635 647 636 // Also set the root path 648 boost::filesystem::path relativeExecutablePath( ORXONOX_RUNTIME_INSTALL_PATH);637 boost::filesystem::path relativeExecutablePath(specialConfig::defaultRuntimePath); 649 638 configuration_->rootPath_ = configuration_->executablePath_; 650 639 while (!boost::filesystem::equivalent(configuration_->rootPath_ / relativeExecutablePath, configuration_->executablePath_) … … 655 644 656 645 // Module path is fixed as well 657 configuration_->modulePath_ = configuration_->rootPath_ / ORXONOX_MODULE_INSTALL_PATH;646 configuration_->modulePath_ = configuration_->rootPath_ / specialConfig::defaultModulePath; 658 647 659 648 #else … … 661 650 // There is no root path, so don't set it at all 662 651 // Module path is fixed as well 663 configuration_->modulePath_ = ORXONOX_MODULE_INSTALL_PATH;652 configuration_->modulePath_ = specialConfig::moduleInstallDirectory; 664 653 665 654 #endif … … 677 666 if (Core::isDevelopmentRun()) 678 667 { 679 configuration_->mediaPath_ = ORXONOX_MEDIA_DEV_PATH; 680 configuration_->configPath_ = ORXONOX_CONFIG_DEV_PATH; 681 configuration_->logPath_ = ORXONOX_LOG_DEV_PATH; 668 configuration_->dataPath_ = specialConfig::dataDevDirectory; 669 configuration_->externalDataPath_ = specialConfig::externalDataDevDirectory; 670 configuration_->configPath_ = specialConfig::configDevDirectory; 671 configuration_->logPath_ = specialConfig::logDevDirectory; 682 672 } 683 673 else … … 687 677 688 678 // Using paths relative to the install prefix, complete them 689 configuration_-> mediaPath_ = configuration_->rootPath_ / ORXONOX_MEDIA_INSTALL_PATH;690 configuration_->configPath_ = configuration_->rootPath_ / ORXONOX_CONFIG_INSTALL_PATH;691 configuration_->logPath_ = configuration_->rootPath_ / ORXONOX_LOG_INSTALL_PATH;679 configuration_->dataPath_ = configuration_->rootPath_ / specialConfig::defaultDataPath; 680 configuration_->configPath_ = configuration_->rootPath_ / specialConfig::defaultConfigPath; 681 configuration_->logPath_ = configuration_->rootPath_ / specialConfig::defaultLogPath; 692 682 693 683 #else 694 684 695 configuration_-> mediaPath_ = ORXONOX_MEDIA_INSTALL_PATH;685 configuration_->dataPath_ = specialConfig::dataInstallDirectory; 696 686 697 687 // Get user directory … … 706 696 userDataPath /= ".orxonox"; 707 697 708 configuration_->configPath_ = userDataPath / ORXONOX_CONFIG_INSTALL_PATH;709 configuration_->logPath_ = userDataPath / ORXONOX_LOG_INSTALL_PATH;698 configuration_->configPath_ = userDataPath / specialConfig::defaultConfigPath; 699 configuration_->logPath_ = userDataPath / specialConfig::defaultLogPath; 710 700 711 701 #endif … … 741 731 } 742 732 743 bool Core::preUpdate(const Clock& time) throw() 744 { 745 std::string exceptionMessage; 746 try 747 { 748 if (this->bGraphicsLoaded_) 749 { 750 // process input events 751 this->inputManager_->update(time); 752 // process gui events 753 this->guiManager_->update(time); 754 } 755 // process thread commands 756 this->tclThreadManager_->update(time); 757 } 758 catch (const std::exception& ex) 759 { exceptionMessage = ex.what(); } 760 catch (...) 761 { exceptionMessage = "Unknown exception"; } 762 if (!exceptionMessage.empty()) 763 { 764 COUT(0) << "An exception occurred in the Core preUpdate: " << exceptionMessage << std::endl; 765 COUT(0) << "This should really never happen! Closing the program." << std::endl; 766 return false; 767 } 768 return true; 769 } 770 771 bool Core::postUpdate(const Clock& time) throw() 772 { 773 std::string exceptionMessage; 774 try 775 { 776 if (this->bGraphicsLoaded_) 777 { 778 // Render (doesn't throw) 779 this->graphicsManager_->update(time); 780 } 781 } 782 catch (const std::exception& ex) 783 { exceptionMessage = ex.what(); } 784 catch (...) 785 { exceptionMessage = "Unknown exception"; } 786 if (!exceptionMessage.empty()) 787 { 788 COUT(0) << "An exception occurred in the Core postUpdate: " << exceptionMessage << std::endl; 789 COUT(0) << "This should really never happen! Closing the program." << std::endl; 790 return false; 791 } 792 return true; 733 void Core::preUpdate(const Clock& time) 734 { 735 if (this->bGraphicsLoaded_) 736 { 737 // process input events 738 this->inputManager_->update(time); 739 // process gui events 740 this->guiManager_->update(time); 741 } 742 // process thread commands 743 this->tclThreadManager_->update(time); 744 } 745 746 void Core::postUpdate(const Clock& time) 747 { 748 if (this->bGraphicsLoaded_) 749 { 750 // Render (doesn't throw) 751 this->graphicsManager_->update(time); 752 } 793 753 } 794 754 }
Note: See TracChangeset
for help on using the changeset viewer.