Changeset 2549 for code/branches/presentation/src
- Timestamp:
- Dec 30, 2008, 3:27:39 PM (16 years ago)
- Location:
- code/branches/presentation/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/core/RootGameState.cc
r2485 r2549 122 122 /** 123 123 @brief 124 Main loop of the orxonox game. 124 125 Starts the game. The little 'while' denotes the main loop. 125 126 Whenever the root state is selected, the game ends. 126 127 @param name 127 128 State to start with (usually main menu or specified by command line) 129 @note 130 We use the Ogre::Timer to measure time since it uses the most precise 131 method an a platform (however the windows timer lacks time when under 132 heavy kernel load!). 128 133 */ 129 134 void RootGameState::start() -
code/branches/presentation/src/orxonox/gamestates/GSDedicated.cc
r2415 r2549 74 74 void GSDedicated::ticked(const Clock& time) 75 75 { 76 // static float startTime = time.getSecondsPrecise(); 77 // static int nrOfTicks = 0; 78 timeSinceLastUpdate_+=time.getDeltaTime(); 79 if(timeSinceLastUpdate_>=NETWORK_PERIOD){ 80 // ++nrOfTicks; 81 // COUT(0) << "estimated ticks/sec: " << nrOfTicks/(time.getSecondsPrecise()-startTime) << endl; 82 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 76 // static float startTime = time.getSecondsPrecise(); 77 // static int nrOfTicks = 0; 78 timeSinceLastUpdate_ += time.getDeltaTime(); 79 if (timeSinceLastUpdate_ >= NETWORK_PERIOD) 80 { 81 // ++nrOfTicks; 82 // COUT(0) << "estimated ticks/sec: " << nrOfTicks/(time.getSecondsPrecise()-startTime) << endl; 83 timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD; 83 84 GSLevel::ticked(time); 84 85 server_->tick(time.getDeltaTime()); … … 87 88 else 88 89 { 89 usleep( (int)( (NETWORK_PERIOD - timeSinceLastUpdate_)*1000*1000 ));90 // COUT(0) << "sleeping for " << (int)( (NETWORK_PERIOD - timeSinceLastUpdate_)*1000*1000) << " usec" << endl;90 usleep((int)((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000)); 91 // COUT(0) << "sleeping for " << (int)((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000) << " usec" << endl; 91 92 } 92 93 } -
code/branches/presentation/src/orxonox/gamestates/GSGraphics.cc
r2548 r2549 76 76 , graphicsEngine_(0) 77 77 , masterKeyBinder_(0) 78 , frameCount_(0)79 , statisticsRefreshCycle_(0)80 , statisticsStartTime_(0)81 , statisticsStartCount_(0)82 , tickTime_(0)83 78 , debugOverlay_(0) 84 79 { … … 107 102 SetConfigValue(ogreLogLevelCritical_, 2) 108 103 .description("Corresponding orxonox debug level for ogre Critical"); 109 SetConfigValue(statisticsRefreshCycle_, 250000)110 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");111 SetConfigValue(statisticsAvgLength_, 1000000)112 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");113 104 SetConfigValue(defaultMasterKeybindings_, "def_masterKeybindings.ini") 114 105 .description("Filename of default master keybindings."); … … 158 149 guiManager_->initialise(this->renderWindow_); 159 150 160 // reset frame counter161 this->frameCount_ = 0;162 this->tickTime_ = 0;163 statisticsStartTime_ = 0;164 statisticsStartCount_ = 0;165 166 151 // add console commands 167 152 FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen); … … 228 213 229 214 /** 230 Main loop of the orxonox game. 231 We use the Ogre::Timer to measure time since it uses the most precise 232 method an a platform (however the windows timer lacks time when under 233 heavy kernel load!). 234 There is a simple mechanism to measure the average time spent in our 235 ticks as it may indicate performance issues. 215 @note 236 216 A note about the Ogre::FrameListener: Even though we don't use them, 237 217 they still get called. However, the delta times are not correct (except … … 243 223 { 244 224 uint64_t timeBeforeTick = time.getRealMicroseconds(); 225 245 226 float dt = time.getDeltaTime(); 246 227 … … 259 240 uint64_t timeAfterTick = time.getRealMicroseconds(); 260 241 261 statisticsTickInfo tickInfo = {timeAfterTick, timeAfterTick-timeBeforeTick}; 262 statisticsTickTimes_.push_front( tickInfo ); 263 tickTime_ += (unsigned int)(timeAfterTick - timeBeforeTick); 264 if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_) 265 { 266 while( (statisticsTickTimes_.size()!=0) && (statisticsTickTimes_.back().tickTime < timeAfterTick - statisticsAvgLength_ ) ) 267 statisticsTickTimes_.pop_back(); 268 std::deque<statisticsTickInfo>::iterator it = statisticsTickTimes_.begin(); 269 uint32_t periodTickTime = 0; 270 unsigned int periodNrOfTicks = 0; 271 while ( it!=statisticsTickTimes_.end() ) 272 { 273 periodTickTime += it->tickLength; 274 periodNrOfTicks++; 275 ++it; 276 } 277 float avgFPS = (float)periodNrOfTicks/(statisticsTickTimes_.front().tickTime - statisticsTickTimes_.back().tickTime)*1000000.0; 278 float avgTickTime = (float)periodTickTime/periodNrOfTicks/1000.0; 279 //float avgFPS = (float)statisticsTickTimes_.size()/statisticsAvgLength_*1000000.0; 280 GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS); 281 //GraphicsEngine::getInstance().setAverageTickTime( 282 //(float)tickTime_ * 0.001f / (frameCount_ - statisticsStartCount_)); 283 GraphicsEngine::getInstance().setAverageTickTime( avgTickTime ); 284 285 tickTime_ = 0; 286 statisticsStartCount_ = frameCount_; 287 statisticsStartTime_ = timeAfterTick; 288 } 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()); 289 248 290 249 // don't forget to call _fireFrameStarted in ogre to make sure … … 307 266 // again, just to be sure ogre works fine 308 267 ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 309 310 ++frameCount_;311 268 } 312 269 -
code/branches/presentation/src/orxonox/gamestates/GSGraphics.h
r2548 r2549 37 37 #include "GSRoot.h" 38 38 39 #include <deque>40 41 39 namespace orxonox 42 40 { 43 struct statisticsTickInfo{44 uint64_t tickTime;45 uint32_t tickLength;46 };47 48 41 class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass, 49 42 public Ogre::WindowEventListener, public Ogre::LogListener … … 100 93 101 94 KeyBinder* masterKeyBinder_; 102 103 // variables for time statistics104 unsigned long frameCount_;105 unsigned int statisticsRefreshCycle_;106 unsigned int statisticsAvgLength_;107 unsigned long long statisticsStartTime_;108 unsigned long statisticsStartCount_;109 std::deque<statisticsTickInfo>110 statisticsTickTimes_;111 unsigned int tickTime_;112 95 XMLFile* debugOverlay_; 113 96 … … 120 103 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL 121 104 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL 122 unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)123 105 std::string defaultMasterKeybindings_; //!< Filename of default master keybindings. 124 106 -
code/branches/presentation/src/orxonox/gamestates/GSLevel.h
r2485 r2549 33 33 #include <OgrePrerequisites.h> 34 34 #include "core/GameState.h" 35 #include "GSGraphics.h"36 35 37 36 namespace orxonox 38 37 { 39 class _OrxonoxExport GSLevel : public OrxonoxClass //,public GameState<GSGraphics>38 class _OrxonoxExport GSLevel : public OrxonoxClass 40 39 { 41 40 friend class ClassIdentifier<GSLevel>; -
code/branches/presentation/src/orxonox/gamestates/GSRoot.cc
r2485 r2549 89 89 void GSRoot::setConfigValues() 90 90 { 91 SetConfigValue(statisticsRefreshCycle_, 250000) 92 .description("Sets the time in microseconds interval at which average fps, etc. get updated."); 93 SetConfigValue(statisticsAvgLength_, 1000000) 94 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated."); 91 95 } 92 96 … … 98 102 // reset game speed to normal 99 103 timeFactor_ = 1.0f; 104 105 // reset frame counter 106 this->frameCount_ = 0; 107 this->statisticsStartTime_ = 0; 108 this->statisticsTickTimes_.clear(); 109 this->periodTickTime_ = 0; 110 this->avgFPS_ = 0.0f; 111 this->avgTickTime_ = 0.0f; 100 112 101 113 // Create the lua interface … … 189 201 void GSRoot::ticked(const Clock& time) 190 202 { 203 uint64_t timeBeforeTick = time.getRealMicroseconds(); 204 191 205 TclThreadManager::getInstance().tick(time.getDeltaTime()); 192 206 … … 206 220 /*** HACK *** HACK ***/ 207 221 222 uint64_t timeAfterTick = time.getRealMicroseconds(); 223 224 // STATISTICS 225 statisticsTickInfo tickInfo = {timeAfterTick, timeAfterTick - timeBeforeTick}; 226 statisticsTickTimes_.push_back(tickInfo); 227 228 // Ticks GSGraphics or GSDedicated 208 229 this->tickChild(time); 230 231 // Note: tickInfo.tickLength is modified by GSGraphics or GSDedicated! 232 this->periodTickTime_ += tickInfo.tickLength; 233 if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_) 234 { 235 while (statisticsTickTimes_.front().tickTime < timeAfterTick - statisticsAvgLength_) 236 { 237 this->periodTickTime_ -= this->statisticsTickTimes_.front().tickLength; 238 this->statisticsTickTimes_.pop_front(); 239 } 240 241 uint32_t framesPerPeriod = this->statisticsTickTimes_.size(); 242 this->avgFPS_ = (float)framesPerPeriod / (tickInfo.tickTime - this->statisticsTickTimes_.front().tickTime) * 1000000.0; 243 this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0; 244 245 statisticsStartTime_ = timeAfterTick; 246 } 247 248 ++this->frameCount_; 209 249 } 210 250 -
code/branches/presentation/src/orxonox/gamestates/GSRoot.h
r2485 r2549 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include <list> 33 35 #include <OgreLog.h> 34 36 #include "core/RootGameState.h" … … 40 42 { 41 43 friend class ClassIdentifier<GSRoot>; 44 45 public: 46 struct statisticsTickInfo 47 { 48 uint64_t tickTime; 49 uint32_t tickLength; 50 }; 51 42 52 public: 43 53 GSRoot(); … … 52 62 void pause(); 53 63 float getTimeFactor() { return this->timeFactor_; } 64 65 float getAvgTickTime() { return this->avgTickTime_; } 66 float getAvgFPS() { return this->avgFPS_; } 67 68 inline void addTickTime(uint32_t length) 69 { assert(!this->statisticsTickTimes_.empty()); this->statisticsTickTimes_.back().tickLength += length; } 54 70 55 71 private: … … 69 85 Shell* shell_; 70 86 LuaBind* luaBind_; 87 88 // variables for time statistics 89 uint32_t frameCount_; 90 uint64_t statisticsStartTime_; 91 std::list<statisticsTickInfo> 92 statisticsTickTimes_; 93 uint32_t periodTickTime_; 94 float avgFPS_; 95 float avgTickTime_; 96 97 // config values 98 unsigned int statisticsRefreshCycle_; 99 unsigned int statisticsAvgLength_; 71 100 72 101 // console commands
Note: See TracChangeset
for help on using the changeset viewer.