Changeset 1891 for code/trunk/src/orxonox
- Timestamp:
- Oct 6, 2008, 7:39:38 PM (16 years ago)
- Location:
- code/trunk/src/orxonox
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/Main.cc
r1755 r1891 39 39 40 40 #include "util/OrxonoxPlatform.h" 41 #include "util/Debug.h" 42 #include "core/ConfigFileManager.h" 41 43 #include "SignalHandler.h" 42 #include "util/Debug.h"43 44 44 45 #include "gamestates/GSRoot.h" … … 90 91 SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log"); 91 92 93 // Specifiy config file before creating the GameStates in order to have 94 // setConfigValues() in the constructor (required). 95 #if ORXONOX_DEBUG_MODE == 1 96 ConfigFileManager::getInstance().setFile(CFT_Settings, "orxonox_d.ini"); 97 #else 98 ConfigFileManager::getInstance().setFile(CFT_Settings, "orxonox.ini"); 99 #endif 100 101 // create the gamestates 92 102 GSRoot root; 93 103 GSGraphics graphics; … … 99 109 GSIOConsole ioConsole; 100 110 111 // make the hierarchy 101 112 root.addChild(&graphics); 102 113 graphics.addChild(&standalone); … … 104 115 graphics.addChild(&client); 105 116 graphics.addChild(&gui); 106 107 117 root.addChild(&ioConsole); 108 118 root.addChild(&dedicated); 109 119 120 // Here happens the game 110 121 root.start(argc, argv); 111 122 -
code/trunk/src/orxonox/gamestates/GSGraphics.cc
r1887 r1891 34 34 #include <OgreFrameListener.h> 35 35 #include <OgreRoot.h> 36 #include <OgreLogManager.h> 36 37 #include <OgreException.h> 37 38 #include <OgreRenderWindow.h> … … 61 62 GSGraphics::GSGraphics() 62 63 : GameState<GSRoot>("graphics") 63 , ogreRoot_(0) 64 , renderWindow_(0) 65 , viewport_(0) 64 66 , inputManager_(0) 65 67 , console_(0) 66 68 , guiManager_(0) 69 , ogreRoot_(0) 70 , ogreLogger_(0) 71 , graphicsEngine_(0) 67 72 , masterKeyBinder_(0) 68 73 , frameCount_(0) … … 73 78 { 74 79 RegisterRootObject(GSGraphics); 80 setConfigValues(); 75 81 } 76 82 … … 82 88 { 83 89 SetConfigValue(resourceFile_, "resources.cfg").description("Location of the resources file in the data path."); 84 SetConfigValue(statisticsRefreshCycle_, 200000).description("Sets the time in microseconds interval at which average fps, etc. get updated."); 90 SetConfigValue(ogreConfigFile_, "ogre.cfg").description("Location of the Ogre config file"); 91 SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file"); 92 SetConfigValue(ogreLogFile_, "ogre.log").description("Logfile for messages from Ogre. \ 93 Use \"\" to suppress log file creation."); 94 SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial"); 95 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 96 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 97 SetConfigValue(statisticsRefreshCycle_, 200000).description("Sets the time in microseconds interval at \ 98 which average fps, etc. get updated."); 85 99 } 86 100 … … 89 103 Settings::_getInstance().bShowsGraphics_ = true; 90 104 91 setConfigValues(); 92 93 this->ogreRoot_ = getParent()->getOgreRoot(); 94 105 // initialise graphics engine. Doesn't load the render window yet! 106 graphicsEngine_ = new GraphicsEngine(); 107 108 // Ogre setup procedure 109 setupOgre(); 95 110 this->declareResources(); 96 111 this->loadRenderer(); // creates the render window … … 100 115 101 116 // HACK: temporary: 102 GraphicsEngine* graphicsEngine = getParent()->getGraphicsEngine(); 103 graphicsEngine->renderWindow_ = this->renderWindow_; 104 graphicsEngine->root_ = this->ogreRoot_; 105 graphicsEngine->viewport_ = this->viewport_; 117 graphicsEngine_->renderWindow_ = this->renderWindow_; 118 graphicsEngine_->root_ = this->ogreRoot_; 119 graphicsEngine_->viewport_ = this->viewport_; 106 120 107 121 … … 141 155 using namespace Ogre; 142 156 143 // remove our WindowEventListener first to avoid bad calls in the procedures157 // remove our WindowEventListener first to avoid bad calls after the window has been destroyed 144 158 Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this); 145 159 … … 156 170 renderer->destroyRenderWindow("Orxonox"); 157 171 172 /*** CODE SNIPPET, UNUSED ***/ 158 173 // Does the opposite of initialise() 159 ogreRoot_->shutdown(); 160 174 //ogreRoot_->shutdown(); 161 175 // Remove all resources and resource groups 162 176 //StringVector groups = ResourceGroupManager::getSingleton().getResourceGroups(); … … 170 184 // Shutdown the render system 171 185 //this->ogreRoot_->setRenderSystem(0); 186 187 delete this->ogreRoot_; 188 189 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 190 // delete the ogre log and the logManager (since we have created it). 191 this->ogreLogger_->getDefaultLog()->removeListener(this); 192 this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog()); 193 delete this->ogreLogger_; 194 #endif 195 196 delete graphicsEngine_; 172 197 173 198 Settings::_getInstance().bShowsGraphics_ = false; … … 234 259 235 260 ++frameCount_; 261 } 262 263 /** 264 @brief 265 Creates the Ogre Root object and sets up the ogre log. 266 */ 267 void GSGraphics::setupOgre() 268 { 269 COUT(3) << "Setting up Ogre..." << std::endl; 270 271 // TODO: LogManager doesn't work on oli platform. The why is yet unknown. 272 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 273 // create a new logManager 274 ogreLogger_ = new Ogre::LogManager(); 275 COUT(4) << "Ogre LogManager created" << std::endl; 276 277 // create our own log that we can listen to 278 Ogre::Log *myLog; 279 if (this->ogreLogFile_ == "") 280 myLog = ogreLogger_->createLog("ogre.log", true, false, true); 281 else 282 myLog = ogreLogger_->createLog(this->ogreLogFile_, true, false, false); 283 COUT(4) << "Ogre Log created" << std::endl; 284 285 myLog->setLogDetail(Ogre::LL_BOREME); 286 myLog->addListener(this); 287 #endif 288 289 // Root will detect that we've already created a Log 290 COUT(4) << "Creating Ogre Root..." << std::endl; 291 292 if (ogrePluginsFile_ == "") 293 { 294 COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl; 295 ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg"); 296 } 297 if (ogreConfigFile_ == "") 298 { 299 COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl; 300 ModifyConfigValue(ogreConfigFile_, tset, "config.cfg"); 301 } 302 if (ogreLogFile_ == "") 303 { 304 COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl; 305 ModifyConfigValue(ogreLogFile_, tset, "ogre.log"); 306 } 307 308 // check for config file existence because Ogre displays (caught) exceptions if not 309 std::ifstream probe; 310 probe.open(ogreConfigFile_.c_str()); 311 if (!probe) 312 { 313 // create a zero sized file 314 std::ofstream creator; 315 creator.open(ogreConfigFile_.c_str()); 316 creator.close(); 317 } 318 else 319 probe.close(); 320 321 ogreRoot_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_); 322 323 #if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.) 324 #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32 325 // tame the ogre ouput so we don't get all the mess in the console 326 Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog(); 327 defaultLog->setDebugOutputEnabled(false); 328 defaultLog->setLogDetail(Ogre::LL_BOREME); 329 defaultLog->addListener(this); 330 #endif 331 #endif 332 333 COUT(3) << "Ogre set up done." << std::endl; 236 334 } 237 335 … … 328 426 } 329 427 428 /** 429 @brief 430 Method called by the LogListener interface from Ogre. 431 We use it to capture Ogre log messages and handle it ourselves. 432 @param message 433 The message to be logged 434 @param lml 435 The message level the log is using 436 @param maskDebug 437 If we are printing to the console or not 438 @param logName 439 The name of this log (so you can have several listeners 440 for different logs, and identify them) 441 */ 442 void GSGraphics::messageLogged(const std::string& message, 443 Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName) 444 { 445 int orxonoxLevel; 446 switch (lml) 447 { 448 case Ogre::LML_TRIVIAL: 449 orxonoxLevel = this->ogreLogLevelTrivial_; 450 break; 451 case Ogre::LML_NORMAL: 452 orxonoxLevel = this->ogreLogLevelNormal_; 453 break; 454 case Ogre::LML_CRITICAL: 455 orxonoxLevel = this->ogreLogLevelCritical_; 456 break; 457 default: 458 orxonoxLevel = 0; 459 } 460 OutputHandler::getOutStream().setOutputLevel(orxonoxLevel) 461 << "Ogre: " << message << std::endl; 462 } 330 463 331 464 /** -
code/trunk/src/orxonox/gamestates/GSGraphics.h
r1878 r1891 39 39 namespace orxonox 40 40 { 41 class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass, public Ogre::WindowEventListener 41 class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass, 42 public Ogre::WindowEventListener, public Ogre::LogListener 42 43 { 43 44 friend class ClassIdentifier<GSGraphics>; 45 44 46 public: 45 47 GSGraphics(); 46 48 ~GSGraphics(); 47 49 48 Ogre::Viewport* getViewport() { return this->viewport_; } 49 GUIManager* getGUIManager() { return this->guiManager_; } 50 Ogre::Root* getOgreRoot() { return this->ogreRoot_ ; } 51 Ogre::Viewport* getViewport() { return this->viewport_ ; } 52 GUIManager* getGUIManager() { return this->guiManager_; } 50 53 51 private: 54 private: // functions 52 55 void enter(); 53 56 void leave(); … … 56 59 void setConfigValues(); 57 60 61 void setupOgre(); 58 62 void declareResources(); 59 63 void loadRenderer(); 60 64 void initialiseResources(); 61 65 66 // console commands 62 67 void printScreen(); 68 69 // event from Ogre::LogListener 70 void messageLogged(const std::string& message, Ogre::LogMessageLevel lml, 71 bool maskDebug, const std::string& logName); 63 72 64 73 // window events from Ogre::WindowEventListener … … 68 77 void windowClosed (Ogre::RenderWindow* rw); 69 78 70 Ogre::Root* ogreRoot_;79 private: // variables 71 80 Ogre::RenderWindow* renderWindow_; //!< the current render window 72 81 Ogre::Viewport* viewport_; //!< default full size viewport … … 76 85 InGameConsole* console_; 77 86 GUIManager* guiManager_; 87 Ogre::Root* ogreRoot_; //!< Ogre's root 88 Ogre::LogManager* ogreLogger_; 89 GraphicsEngine* graphicsEngine_; //!< Interface to Ogre 78 90 79 91 KeyBinder* masterKeyBinder_; … … 88 100 // config values 89 101 std::string resourceFile_; //!< resources file name 102 std::string ogreConfigFile_; //!< ogre config file name 103 std::string ogrePluginsFile_; //!< ogre plugins file name 104 std::string ogreLogFile_; //!< log file name for Ogre log messages 105 int ogreLogLevelTrivial_; //!< Corresponding Orxonx debug level for LL_TRIVIAL 106 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL 107 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL 90 108 unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high) 91 109 }; -
code/trunk/src/orxonox/gamestates/GSRoot.cc
r1826 r1891 30 30 #include "GSRoot.h" 31 31 32 #include <OgreLogManager.h>33 #include <OgreRoot.h>34 35 32 #include "util/Exception.h" 36 33 #include "util/Debug.h" 37 34 #include "core/Factory.h" 38 #include "core/ConfigFileManager.h"39 35 #include "core/ConfigValueIncludes.h" 40 36 #include "core/CoreIncludes.h" … … 71 67 : RootGameState("root") 72 68 , settings_(0) 73 , ogreRoot_(0)74 , ogreLogger_(0)75 , graphicsEngine_(0)76 69 , tclBind_(0) 77 70 , tclThreadManager_(0) … … 79 72 { 80 73 RegisterRootObject(GSRoot); 74 setConfigValues(); 81 75 } 82 76 … … 87 81 void GSRoot::setConfigValues() 88 82 { 89 SetConfigValue(ogreConfigFile_, "ogre.cfg").description("Location of the Ogre config file");90 SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file");91 SetConfigValue(ogreLogFile_, "ogre.log").description("Logfile for messages from Ogre. \92 Use \"\" to suppress log file creation.");93 SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial");94 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal");95 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical");96 83 } 97 84 98 85 void GSRoot::enter() 99 86 { 100 #if ORXONOX_DEBUG_MODE == 1101 ConfigFileManager::getInstance().setFile(CFT_Settings, "orxonox_d.ini");102 #else103 ConfigFileManager::getInstance().setFile(CFT_Settings, "orxonox.ini");104 #endif105 106 // do this after the previous call..107 setConfigValues();108 109 87 // creates the class hierarchy for all classes with factories 110 88 Factory::createClassHierarchy(); … … 130 108 this->shell_ = new Shell(); 131 109 132 setupOgre();133 134 // initialise graphics engine. Doesn't load the render window yet!135 graphicsEngine_ = new GraphicsEngine();136 137 110 // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump 138 111 // do this after ogre has initialised. Somehow Ogre changes the settings again (not through … … 157 130 { 158 131 // TODO: remove and destroy console commands 159 160 delete graphicsEngine_;161 162 delete this->ogreRoot_;163 164 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32165 // delete the ogre log and the logManager (since we have created it).166 this->ogreLogger_->getDefaultLog()->removeListener(this);167 this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());168 delete this->ogreLogger_;169 #endif170 132 171 133 delete this->shell_; … … 203 165 DWORD procMask; 204 166 DWORD sysMask; 205 # if _MSC_VER >= 1400 && defined (_M_X64)167 # if _MSC_VER >= 1400 && defined (_M_X64) 206 168 GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask); 207 # else169 # else 208 170 GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask); 209 # endif171 # endif 210 172 211 173 // If procMask is 0, consider there is only one core available … … 227 189 #endif 228 190 } 229 230 /**231 @brief232 Creates the Ogre Root object and sets up the ogre log.233 */234 void GSRoot::setupOgre()235 {236 COUT(3) << "Setting up Ogre..." << std::endl;237 238 // TODO: LogManager doesn't work on oli platform. The why is yet unknown.239 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32240 // create a new logManager241 ogreLogger_ = new Ogre::LogManager();242 COUT(4) << "Ogre LogManager created" << std::endl;243 244 // create our own log that we can listen to245 Ogre::Log *myLog;246 if (this->ogreLogFile_ == "")247 myLog = ogreLogger_->createLog("ogre.log", true, false, true);248 else249 myLog = ogreLogger_->createLog(this->ogreLogFile_, true, false, false);250 COUT(4) << "Ogre Log created" << std::endl;251 252 myLog->setLogDetail(Ogre::LL_BOREME);253 myLog->addListener(this);254 #endif255 256 // Root will detect that we've already created a Log257 COUT(4) << "Creating Ogre Root..." << std::endl;258 259 if (ogrePluginsFile_ == "")260 {261 COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl;262 ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg");263 }264 if (ogreConfigFile_ == "")265 {266 COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;267 ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");268 }269 if (ogreLogFile_ == "")270 {271 COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;272 ModifyConfigValue(ogreLogFile_, tset, "ogre.log");273 }274 275 // check for config file existence because Ogre displays (caught) exceptions if not276 std::ifstream probe;277 probe.open(ogreConfigFile_.c_str());278 if (!probe)279 {280 // create a zero sized file281 std::ofstream creator;282 creator.open(ogreConfigFile_.c_str());283 creator.close();284 }285 else286 probe.close();287 288 ogreRoot_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_);289 290 #if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.)291 #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32292 // tame the ogre ouput so we don't get all the mess in the console293 Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog();294 defaultLog->setDebugOutputEnabled(false);295 defaultLog->setLogDetail(Ogre::LL_BOREME);296 defaultLog->addListener(this);297 #endif298 #endif299 300 COUT(3) << "Ogre set up done." << std::endl;301 }302 303 /**304 @brief305 Method called by the LogListener interface from Ogre.306 We use it to capture Ogre log messages and handle it ourselves.307 @param message308 The message to be logged309 @param lml310 The message level the log is using311 @param maskDebug312 If we are printing to the console or not313 @param logName314 The name of this log (so you can have several listeners315 for different logs, and identify them)316 */317 void GSRoot::messageLogged(const std::string& message,318 Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName)319 {320 int orxonoxLevel;321 switch (lml)322 {323 case Ogre::LML_TRIVIAL:324 orxonoxLevel = this->ogreLogLevelTrivial_;325 break;326 case Ogre::LML_NORMAL:327 orxonoxLevel = this->ogreLogLevelNormal_;328 break;329 case Ogre::LML_CRITICAL:330 orxonoxLevel = this->ogreLogLevelCritical_;331 break;332 default:333 orxonoxLevel = 0;334 }335 OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)336 << "Ogre: " << message << std::endl;337 }338 191 } -
code/trunk/src/orxonox/gamestates/GSRoot.h
r1792 r1891 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport GSRoot : public RootGameState, public O gre::LogListener, public OrxonoxClass39 class _OrxonoxExport GSRoot : public RootGameState, public OrxonoxClass 40 40 { 41 41 friend class ClassIdentifier<GSRoot>; … … 47 47 { requestState("root"); } 48 48 49 Ogre::Root* getOgreRoot() { return this->ogreRoot_; }50 GraphicsEngine* getGraphicsEngine() { return this->graphicsEngine_; }51 52 49 private: 53 50 void enter(); … … 56 53 57 54 void setConfigValues(); 58 void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,59 bool maskDebug, const std::string& logName);60 55 void setThreadAffinity(unsigned int limitToCPU); 61 void setupOgre();62 56 63 57 Settings* settings_; 64 Ogre::Root* ogreRoot_; //!< Ogre's root65 Ogre::LogManager* ogreLogger_;66 GraphicsEngine* graphicsEngine_; //!< Interface to Ogre67 58 TclBind* tclBind_; 68 59 TclThreadManager* tclThreadManager_; 69 60 Shell* shell_; 70 71 std::string ogreConfigFile_; //!< ogre config file name72 std::string ogrePluginsFile_; //!< ogre plugins file name73 std::string ogreLogFile_; //!< log file name for Ogre log messages74 int ogreLogLevelTrivial_; //!< Corresponding Orxonx debug level for LL_TRIVIAL75 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL76 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL77 61 }; 78 62 }
Note: See TracChangeset
for help on using the changeset viewer.