Changeset 5693 for code/trunk/src/core
- Timestamp:
- Aug 29, 2009, 10:19:38 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 13 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/libraries (added) merged: 5612-5613,5615-5619,5621-5623,5625-5640,5642-5643,5647-5649,5665-5666,5685-5687,5692
- Property svn:mergeinfo changed
-
code/trunk/src/core/CMakeLists.txt
r3370 r5693 23 23 ConfigValueContainer.cc 24 24 Core.cc 25 DynLib.cc 26 DynLibManager.cc 25 27 Event.cc 26 28 Game.cc -
code/trunk/src/core/Core.cc
r3370 r5693 40 40 #include <cstdlib> 41 41 #include <cstdio> 42 #include <boost/version.hpp> 42 43 #include <boost/filesystem.hpp> 43 44 #include <OgreRenderWindow.h> … … 68 69 #include "ConfigValueIncludes.h" 69 70 #include "CoreIncludes.h" 71 #include "DynLibManager.h" 70 72 #include "Factory.h" 71 73 #include "GameMode.h" … … 80 82 #include "input/InputManager.h" 81 83 84 // Boost 1.36 has some issues with deprecated functions that have been omitted 85 #if (BOOST_VERSION == 103600) 86 # define BOOST_LEAF_FUNCTION filename 87 #else 88 # define BOOST_LEAF_FUNCTION leaf 89 #endif 90 82 91 namespace orxonox 83 92 { … … 241 250 boost::filesystem::path rootPath_; 242 251 boost::filesystem::path executablePath_; //!< Path to the executable 252 boost::filesystem::path modulePath_; //!< Path to the modules 243 253 boost::filesystem::path mediaPath_; //!< Path to the media file folder 244 254 boost::filesystem::path configPath_; //!< Path to the config file folder … … 256 266 , bGraphicsLoaded_(false) 257 267 { 258 // Parse command line arguments first 268 // Set the hard coded fixed paths 269 this->setFixedPaths(); 270 271 // Create a new dynamic library manager 272 this->dynLibManager_.reset(new DynLibManager()); 273 274 // Load modules 275 try 276 { 277 // We search for helper files with the following extension 278 std::string moduleextension = ORXONOX_MODULE_EXTENSION; 279 size_t moduleextensionlength = moduleextension.size(); 280 281 // Search in the directory of our executable 282 boost::filesystem::path searchpath = this->configuration_->modulePath_; 283 284 // Add that path to the PATH variable in case a module depends on another one 285 std::string pathVariable = getenv("PATH"); 286 putenv(const_cast<char*>(("PATH=" + pathVariable + ";" + configuration_->modulePath_.string()).c_str())); 287 288 boost::filesystem::directory_iterator file(searchpath); 289 boost::filesystem::directory_iterator end; 290 291 // Iterate through all files 292 while (file != end) 293 { 294 std::string filename = file->BOOST_LEAF_FUNCTION(); 295 296 // Check if the file ends with the exension in question 297 if (filename.size() > moduleextensionlength) 298 { 299 if (filename.substr(filename.size() - moduleextensionlength) == moduleextension) 300 { 301 // We've found a helper file - now load the library with the same name 302 std::string library = filename.substr(0, filename.size() - moduleextensionlength); 303 boost::filesystem::path librarypath = searchpath / library; 304 305 try 306 { 307 DynLibManager::getInstance().load(librarypath.string()); 308 } 309 catch (const std::exception& e) 310 { 311 COUT(1) << "Couldn't load module \"" << librarypath.string() << "\": " << e.what() << std::endl; 312 } 313 catch (...) 314 { 315 COUT(1) << "Couldn't load module \"" << librarypath.string() << "\"" << std::endl; 316 } 317 } 318 } 319 320 ++file; 321 } 322 } 323 catch (const std::exception& e) 324 { 325 COUT(1) << "An error occurred while loading modules: " << e.what() << std::endl; 326 } 327 catch (...) 328 { 329 COUT(1) << "An error occurred while loading modules." << std::endl; 330 } 331 332 // Parse command line arguments AFTER the modules have been loaded (static code!) 259 333 CommandLine::parseCommandLine(cmdLine); 260 334 261 // Determine and set the location of the executable 262 setExecutablePath(); 263 264 // Determine whether we have an installed or a binary dir run 265 // The latter occurs when simply running from the build directory 266 checkDevBuild(); 267 268 // Make sure the directories we write in exist or else make them 269 createDirectories(); 335 // Set configurable paths like log, config and media 336 this->setConfigurablePaths(); 270 337 271 338 // create a signal handler (only active for linux) … … 507 574 /** 508 575 @brief 509 Compares the executable path with the working directory 510 */ 511 void Core::setExecutablePath() 512 { 576 Retrievs the executable path and sets all hard coded fixed path (currently only the module path) 577 Also checks for "orxonox_dev_build.keep_me" in the executable diretory. 578 If found it means that this is not an installed run, hence we 579 don't write the logs and config files to ~/.orxonox 580 @throw 581 GeneralException 582 */ 583 void Core::setFixedPaths() 584 { 585 ////////////////////////// 586 // FIND EXECUTABLE PATH // 587 ////////////////////////// 588 513 589 #ifdef ORXONOX_PLATFORM_WINDOWS 514 590 // get executable module … … 553 629 configuration_->executablePath_ = configuration_->executablePath_.branch_path(); // remove executable name 554 630 #endif 555 } 556 557 /** 558 @brief 559 Checks for "orxonox_dev_build.keep_me" in the executable diretory. 560 If found it means that this is not an installed run, hence we 561 don't write the logs and config files to ~/.orxonox 562 @throws 563 GeneralException 564 */ 565 void Core::checkDevBuild() 566 { 631 632 ///////////////////// 633 // SET MODULE PATH // 634 ///////////////////// 635 567 636 if (boost::filesystem::exists(configuration_->executablePath_ / "orxonox_dev_build.keep_me")) 568 637 { 569 638 COUT(1) << "Running from the build tree." << std::endl; 570 639 Core::bDevRun_ = true; 571 configuration_->mediaPath_ = ORXONOX_MEDIA_DEV_PATH; 572 configuration_->configPath_ = ORXONOX_CONFIG_DEV_PATH; 573 configuration_->logPath_ = ORXONOX_LOG_DEV_PATH; 640 configuration_->modulePath_ = ORXONOX_MODULE_DEV_PATH; 574 641 } 575 642 else 576 643 { 644 577 645 #ifdef INSTALL_COPYABLE // --> relative paths 646 578 647 // Also set the root path 579 648 boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH); … … 585 654 ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?"); 586 655 656 // Module path is fixed as well 657 configuration_->modulePath_ = configuration_->rootPath_ / ORXONOX_MODULE_INSTALL_PATH; 658 659 #else 660 661 // There is no root path, so don't set it at all 662 // Module path is fixed as well 663 configuration_->modulePath_ = ORXONOX_MODULE_INSTALL_PATH; 664 665 #endif 666 } 667 } 668 669 /** 670 @brief 671 Sets config, log and media path and creates folders if necessary. 672 @throws 673 GeneralException 674 */ 675 void Core::setConfigurablePaths() 676 { 677 if (Core::isDevelopmentRun()) 678 { 679 configuration_->mediaPath_ = ORXONOX_MEDIA_DEV_PATH; 680 configuration_->configPath_ = ORXONOX_CONFIG_DEV_PATH; 681 configuration_->logPath_ = ORXONOX_LOG_DEV_PATH; 682 } 683 else 684 { 685 686 #ifdef INSTALL_COPYABLE // --> relative paths 687 587 688 // Using paths relative to the install prefix, complete them 588 689 configuration_->mediaPath_ = configuration_->rootPath_ / ORXONOX_MEDIA_INSTALL_PATH; 589 690 configuration_->configPath_ = configuration_->rootPath_ / ORXONOX_CONFIG_INSTALL_PATH; 590 691 configuration_->logPath_ = configuration_->rootPath_ / ORXONOX_LOG_INSTALL_PATH; 692 591 693 #else 592 // There is no root path, so don't set it at all593 694 594 695 configuration_->mediaPath_ = ORXONOX_MEDIA_INSTALL_PATH; … … 607 708 configuration_->configPath_ = userDataPath / ORXONOX_CONFIG_INSTALL_PATH; 608 709 configuration_->logPath_ = userDataPath / ORXONOX_LOG_INSTALL_PATH; 609 #endif 710 711 #endif 712 610 713 } 611 714 … … 617 720 configuration_->logPath_ = configuration_->logPath_ / directory; 618 721 } 619 } 620 621 /* 622 @brief 623 Checks for the log and the config directory and creates them 624 if necessary. Otherwise me might have problems opening those files. 625 @throws 626 orxonox::GeneralException if the directory to be created is a file. 627 */ 628 void Core::createDirectories() 629 { 722 723 // Create directories to avoid problems when opening files in non existent folders. 630 724 std::vector<std::pair<boost::filesystem::path, std::string> > directories; 631 725 directories.push_back(std::make_pair(boost::filesystem::path(configuration_->configPath_), "config")); -
code/trunk/src/core/Core.h
r3370 r5693 114 114 Core(const Core&); //!< Don't use (undefined symbol) 115 115 116 void checkDevBuild(); 117 void setExecutablePath(); 118 void createDirectories(); 116 void setFixedPaths(); 117 void setConfigurablePaths(); 119 118 void setThreadAffinity(int limitToCPU); 120 119 121 120 // Mind the order for the destruction! 121 scoped_ptr<DynLibManager> dynLibManager_; 122 122 scoped_ptr<SignalHandler> signalHandler_; 123 123 SimpleScopeGuard identifierDestroyer_; -
code/trunk/src/core/CorePrereqs.h
r3370 r5693 112 112 class ConsoleCommand; 113 113 class Core; 114 class DynLib; 115 class DynLibManager; 114 116 struct Event; 115 117 class EventContainer; -
code/trunk/src/core/GUIManager.h
r3370 r5693 50 50 namespace orxonox 51 51 { 52 class PlayerInfo; // Forward declaration 53 52 54 /** 53 55 @class GUIManager … … 77 79 static GUIManager* getInstancePtr() { return singletonPtr_s; } 78 80 81 inline void setPlayer(const std::string& guiname, PlayerInfo* player) 82 { this->players_[guiname] = player; } 83 inline PlayerInfo* getPlayer(const std::string& guiname) const 84 { std::map<std::string, PlayerInfo*>::const_iterator it = this->players_.find(guiname); return (it != this->players_.end()) ? it->second : 0; } 85 79 86 private: 80 87 GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class) … … 92 99 void mouseScrolled (int abs, int rel); 93 100 94 boost::scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_; //!< CEGUI's interface to the Ogre Engine 95 boost::scoped_ptr<CEGUI::LuaScriptModule> scriptModule_; //!< CEGUI's script module to use Lua 96 boost::scoped_ptr<CEGUI::System> guiSystem_; //!< CEGUI's main system 97 Ogre::RenderWindow* renderWindow_; //!< Ogre's render window to give CEGUI access to it 98 CEGUI::ResourceProvider* resourceProvider_; //!< CEGUI's resource provider 99 CEGUI::Logger* ceguiLogger_; //!< CEGUI's logger to be able to log CEGUI errors in our log 100 lua_State* luaState_; //!< Lua state, access point to the Lua engine 101 boost::scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_; //!< CEGUI's interface to the Ogre Engine 102 boost::scoped_ptr<CEGUI::LuaScriptModule> scriptModule_; //!< CEGUI's script module to use Lua 103 boost::scoped_ptr<CEGUI::System> guiSystem_; //!< CEGUI's main system 104 Ogre::RenderWindow* renderWindow_; //!< Ogre's render window to give CEGUI access to it 105 CEGUI::ResourceProvider* resourceProvider_; //!< CEGUI's resource provider 106 CEGUI::Logger* ceguiLogger_; //!< CEGUI's logger to be able to log CEGUI errors in our log 107 lua_State* luaState_; //!< Lua state, access point to the Lua engine 108 std::map<std::string, PlayerInfo*> players_; //!< Stores the player (owner) for each gui 101 109 102 static GUIManager* singletonPtr_s;//!< Singleton reference to GUIManager110 static GUIManager* singletonPtr_s; //!< Singleton reference to GUIManager 103 111 104 112 }; -
code/trunk/src/core/Game.cc
r3370 r5693 113 113 */ 114 114 Game::Game(const std::string& cmdLine) 115 // Destroy factories before the Core! 116 : gsFactoryDestroyer_(Game::GameStateFactory::factories_s, &std::map<std::string, shared_ptr<GameStateFactory> >::clear) 115 117 { 116 118 this->bAbort_ = false; -
code/trunk/src/core/Game.h
r3370 r5693 48 48 49 49 #include "util/Debug.h" 50 #include "util/ScopeGuard.h" 50 51 #include "util/Singleton.h" 51 52 … … 85 86 typedef std::map<std::string, shared_ptr<GameState> > GameStateMap; 86 87 typedef boost::shared_ptr<GameStateTreeNode> GameStateTreeNodePtr; 88 87 89 public: 88 90 Game(const std::string& cmdLine); … … 118 120 static void createFactory(const std::string& className) 119 121 { factories_s[className].reset(new TemplateGameStateFactory<T>()); } 120 private: 122 121 123 virtual shared_ptr<GameState> fabricateInternal(const GameStateInfo& info) = 0; 122 124 static std::map<std::string, shared_ptr<GameStateFactory> > factories_s; … … 129 131 { return shared_ptr<GameState>(new T(info)); } 130 132 }; 133 // For the factory destruction 134 typedef Loki::ObjScopeGuardImpl0<std::map<std::string, shared_ptr<GameStateFactory> >, void (std::map<std::string, shared_ptr<GameStateFactory> >::*)()> ObjScopeGuard; 131 135 132 136 struct StatisticsTickInfo … … 156 160 scoped_ptr<Clock> gameClock_; 157 161 scoped_ptr<Core> core_; 162 ObjScopeGuard gsFactoryDestroyer_; 158 163 scoped_ptr<GameConfiguration> configuration_; 159 164 -
code/trunk/src/core/TclThreadList.h
- Property svn:eol-style set to native
-
code/trunk/src/core/Thread.cc
- Property svn:eol-style set to native
-
code/trunk/src/core/Thread.h
- Property svn:eol-style set to native
-
code/trunk/src/core/ThreadPool.cc
- Property svn:eol-style set to native
-
code/trunk/src/core/ThreadPool.h
- Property svn:eol-style set to native
Note: See TracChangeset
for help on using the changeset viewer.