Changeset 1686 for code/branches/gui/src/orxonox/gamestates/GSRoot.cc
- Timestamp:
- Aug 31, 2008, 2:37:00 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/orxonox/gamestates/GSRoot.cc
r1674 r1686 30 30 #include "GSRoot.h" 31 31 32 #include <OgreLogManager.h> 33 #include <OgreRoot.h> 34 32 35 //#include "util/SubString.h" 33 36 #include "core/Factory.h" 34 37 #include "core/ConfigFileManager.h" 35 38 #include "core/ConfigValueIncludes.h" 39 #include "core/CoreIncludes.h" 36 40 #include "core/ConsoleCommand.h" 37 41 #include "core/CommandLine.h" … … 65 69 : RootGameState("root") 66 70 , settings_(0) 71 , ogreRoot_(0) 72 , ogreLogger_(0) 67 73 , graphicsEngine_(0) 68 74 { 75 RegisterRootObject(GSRoot); 69 76 } 70 77 71 78 GSRoot::~GSRoot() 72 79 { 80 } 81 82 void GSRoot::setConfigValues() 83 { 84 SetConfigValue(ogreConfigFile_, "ogre.cfg").description("Location of the Ogre config file"); 85 SetConfigValue(ogrePluginsFile_, "plugins.cfg").description("Location of the Ogre plugins file"); 86 SetConfigValue(ogreLogFile_, "ogre.log").description("Logfile for messages from Ogre. \ 87 Use \"\" to suppress log file creation."); 88 SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial"); 89 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 90 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 73 91 } 74 92 … … 108 126 #endif 109 127 128 // do this after the previous call.. 129 setConfigValues(); 130 110 131 // creates the class hierarchy for all classes with factories 111 132 Factory::createClassHierarchy(); … … 128 149 TclThreadManager::getInstance(); 129 150 151 setupOgre(); 152 130 153 // initialise graphics engine. Doesn't load the render window yet! 131 154 graphicsEngine_ = new GraphicsEngine(); 132 graphicsEngine_->setup(); // creates ogre root and other essentials133 155 134 156 // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump … … 151 173 { 152 174 delete graphicsEngine_; 175 176 delete this->ogreRoot_; 177 178 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 179 // delete the ogre log and the logManager (since we have created it). 180 this->ogreLogger_->getDefaultLog()->removeListener(this); 181 this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog()); 182 delete this->ogreLogger_; 183 #endif 184 153 185 delete settings_; 154 186 … … 199 231 #endif 200 232 } 233 234 /** 235 @brief 236 Creates the Ogre Root object and sets up the ogre log. 237 */ 238 void GSRoot::setupOgre() 239 { 240 COUT(3) << "Setting up Ogre..." << std::endl; 241 242 // TODO: LogManager doesn't work on oli platform. The why is yet unknown. 243 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 244 // create a new logManager 245 ogreLogger_ = new Ogre::LogManager(); 246 COUT(4) << "Ogre LogManager created" << std::endl; 247 248 // create our own log that we can listen to 249 Ogre::Log *myLog; 250 if (this->ogreLogFile_ == "") 251 myLog = ogreLogger_->createLog("ogre.log", true, false, true); 252 else 253 myLog = ogreLogger_->createLog(this->ogreLogFile_, true, false, false); 254 COUT(4) << "Ogre Log created" << std::endl; 255 256 myLog->setLogDetail(Ogre::LL_BOREME); 257 myLog->addListener(this); 258 #endif 259 260 // Root will detect that we've already created a Log 261 COUT(4) << "Creating Ogre Root..." << std::endl; 262 263 if (ogrePluginsFile_ == "") 264 { 265 COUT(2) << "Warning: Ogre plugins file set to \"\". Defaulting to plugins.cfg" << std::endl; 266 ModifyConfigValue(ogrePluginsFile_, tset, "plugins.cfg"); 267 } 268 if (ogreConfigFile_ == "") 269 { 270 COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl; 271 ModifyConfigValue(ogreConfigFile_, tset, "config.cfg"); 272 } 273 if (ogreLogFile_ == "") 274 { 275 COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl; 276 ModifyConfigValue(ogreLogFile_, tset, "ogre.log"); 277 } 278 279 // check for config file existence because Ogre displays (caught) exceptions if not 280 std::ifstream probe; 281 probe.open(ogreConfigFile_.c_str()); 282 if (!probe) 283 { 284 // create a zero sized file 285 std::ofstream creator; 286 creator.open(ogreConfigFile_.c_str()); 287 creator.close(); 288 } 289 else 290 probe.close(); 291 292 ogreRoot_ = new Ogre::Root(ogrePluginsFile_, ogreConfigFile_, ogreLogFile_); 293 294 #if 0 // Ogre 1.4.3 doesn't yet support setDebugOutputEnabled(.) 295 #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32 296 // tame the ogre ouput so we don't get all the mess in the console 297 Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog(); 298 defaultLog->setDebugOutputEnabled(false); 299 defaultLog->setLogDetail(Ogre::LL_BOREME); 300 defaultLog->addListener(this); 301 #endif 302 #endif 303 304 COUT(3) << "Ogre set up done." << std::endl; 305 } 306 307 /** 308 @brief 309 Method called by the LogListener interface from Ogre. 310 We use it to capture Ogre log messages and handle it ourselves. 311 @param message 312 The message to be logged 313 @param lml 314 The message level the log is using 315 @param maskDebug 316 If we are printing to the console or not 317 @param logName 318 The name of this log (so you can have several listeners 319 for different logs, and identify them) 320 */ 321 void GSRoot::messageLogged(const std::string& message, 322 Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName) 323 { 324 int orxonoxLevel; 325 switch (lml) 326 { 327 case Ogre::LML_TRIVIAL: 328 orxonoxLevel = this->ogreLogLevelTrivial_; 329 break; 330 case Ogre::LML_NORMAL: 331 orxonoxLevel = this->ogreLogLevelNormal_; 332 break; 333 case Ogre::LML_CRITICAL: 334 orxonoxLevel = this->ogreLogLevelCritical_; 335 break; 336 default: 337 orxonoxLevel = 0; 338 } 339 OutputHandler::getOutStream().setOutputLevel(orxonoxLevel) 340 << "Ogre: " << message << std::endl; 341 } 201 342 }
Note: See TracChangeset
for help on using the changeset viewer.