Changeset 1891 for code/trunk/src/orxonox/gamestates/GSRoot.cc
- Timestamp:
- Oct 6, 2008, 7:39:38 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.