Changeset 2662 for code/trunk/src/orxonox/gamestates/GSGraphics.cc
- Timestamp:
- Feb 14, 2009, 10:17:35 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/gamestates/GSGraphics.cc
r2171 r2662 31 31 32 32 #include <fstream> 33 #include <OgreCompositorManager.h> 33 34 #include <OgreConfigFile.h> 34 35 #include <OgreFrameListener.h> … … 75 76 , graphicsEngine_(0) 76 77 , masterKeyBinder_(0) 77 , frameCount_(0)78 , statisticsRefreshCycle_(0)79 , statisticsStartTime_(0)80 , statisticsStartCount_(0)81 , tickTime_(0)82 78 , debugOverlay_(0) 83 79 { … … 106 102 SetConfigValue(ogreLogLevelCritical_, 2) 107 103 .description("Corresponding orxonox debug level for ogre Critical"); 108 SetConfigValue(statisticsRefreshCycle_, 200000)109 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");110 104 SetConfigValue(defaultMasterKeybindings_, "def_masterKeybindings.ini") 111 105 .description("Filename of default master keybindings."); … … 155 149 guiManager_->initialise(this->renderWindow_); 156 150 157 // reset frame counter158 this->frameCount_ = 0;159 this->tickTime_ = 0;160 statisticsStartTime_ = 0;161 statisticsStartCount_ = 0;162 163 151 // add console commands 164 152 FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen); 165 153 functor1->setObject(this); 166 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "printScreen")); 154 ccPrintScreen_ = createConsoleCommand(functor1, "printScreen"); 155 CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_); 167 156 } 168 157 … … 170 159 { 171 160 using namespace Ogre; 161 162 delete this->ccPrintScreen_; 172 163 173 164 // remove our WindowEventListener first to avoid bad calls after the window has been destroyed … … 184 175 Loader::unload(this->debugOverlay_); 185 176 delete this->debugOverlay_; 177 178 // unload all compositors 179 Ogre::CompositorManager::getSingleton().removeAll(); 186 180 187 181 // destroy render window … … 206 200 delete this->ogreRoot_; 207 201 208 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32202 //#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 209 203 // delete the ogre log and the logManager (since we have created it). 210 204 this->ogreLogger_->getDefaultLog()->removeListener(this); 211 205 this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog()); 212 206 delete this->ogreLogger_; 213 #endif207 //#endif 214 208 215 209 delete graphicsEngine_; … … 219 213 220 214 /** 221 Main loop of the orxonox game. 222 We use the Ogre::Timer to measure time since it uses the most precise 223 method an a platform (however the windows timer lacks time when under 224 heavy kernel load!). 225 There is a simple mechanism to measure the average time spent in our 226 ticks as it may indicate performance issues. 215 @note 227 216 A note about the Ogre::FrameListener: Even though we don't use them, 228 217 they still get called. However, the delta times are not correct (except … … 233 222 void GSGraphics::ticked(const Clock& time) 234 223 { 235 unsigned long long timeBeforeTick = time.getRealMicroseconds(); 224 uint64_t timeBeforeTick = time.getRealMicroseconds(); 225 236 226 float dt = time.getDeltaTime(); 237 227 … … 248 238 } 249 239 250 unsigned long long timeAfterTick = time.getRealMicroseconds(); 251 252 tickTime_ += (unsigned int)(timeAfterTick - timeBeforeTick); 253 if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_) 254 { 255 GraphicsEngine::getInstance().setAverageTickTime( 256 (float)tickTime_ * 0.001f / (frameCount_ - statisticsStartCount_)); 257 float avgFPS = (float)(frameCount_ - statisticsStartCount_) 258 / (timeAfterTick - statisticsStartTime_) * 1000000.0; 259 GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS); 260 261 tickTime_ = 0; 262 statisticsStartCount_ = frameCount_; 263 statisticsStartTime_ = timeAfterTick; 264 } 240 uint64_t timeAfterTick = time.getRealMicroseconds(); 241 242 // Also add our tick time to the list in GSRoot 243 this->getParent()->addTickTime(timeAfterTick - timeBeforeTick); 244 245 // Update statistics overlay. Note that the values only change periodically in GSRoot. 246 GraphicsEngine::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS()); 247 GraphicsEngine::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime()); 265 248 266 249 // don't forget to call _fireFrameStarted in ogre to make sure … … 283 266 // again, just to be sure ogre works fine 284 267 ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 285 286 ++frameCount_;287 268 } 288 269 … … 296 277 297 278 // TODO: LogManager doesn't work on oli platform. The why is yet unknown. 298 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32279 //#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 299 280 // create a new logManager 300 281 ogreLogger_ = new Ogre::LogManager(); … … 311 292 myLog->setLogDetail(Ogre::LL_BOREME); 312 293 myLog->addListener(this); 313 #endif294 //#endif 314 295 315 296 // Root will detect that we've already created a Log … … 430 411 // create a full screen default viewport 431 412 this->viewport_ = this->renderWindow_->addViewport(0, 0); 413 414 if (this->graphicsEngine_) 415 this->graphicsEngine_->setViewport(this->viewport_); 432 416 } 433 417
Note: See TracChangeset
for help on using the changeset viewer.