Changeset 2817 for code/branches/gui/src/orxonox/gamestates/GSRoot.cc
- Timestamp:
- Mar 21, 2009, 10:17:59 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/orxonox/gamestates/GSRoot.cc
r2805 r2817 33 33 #include "util/Debug.h" 34 34 #include "core/Core.h" 35 #include "core/ConfigValueIncludes.h"36 35 #include "core/CoreIncludes.h" 37 36 #include "core/ConsoleCommand.h" 38 37 #include "tools/Timer.h" 39 38 #include "objects/Tickable.h" 39 #include "Game.h" 40 40 41 41 namespace orxonox … … 47 47 , timeFactorPauseBackup_(1.0f) 48 48 { 49 RegisterRootObject(GSRoot);50 setConfigValues();51 52 49 this->ccSetTimeFactor_ = 0; 53 50 this->ccPause_ = 0; … … 58 55 } 59 56 60 void GSRoot::setConfigValues()61 {62 SetConfigValue(statisticsRefreshCycle_, 250000)63 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");64 SetConfigValue(statisticsAvgLength_, 1000000)65 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");66 }67 68 57 void GSRoot::enter() 69 58 { … … 71 60 timeFactor_ = 1.0f; 72 61 73 // reset frame counter74 this->statisticsStartTime_ = 0;75 this->statisticsTickTimes_.clear();76 this->periodTickTime_ = 0;77 this->avgFPS_ = 0.0f;78 this->avgTickTime_ = 0.0f;79 80 62 { 81 63 // add console commands 82 FunctorMember01<GameState Base, const std::string&>* functor = createFunctor(&GameStateBase::requestState);64 FunctorMember01<GameState, const std::string&>* functor = createFunctor(&GameState::requestState); 83 65 functor->setObject(this); 84 66 this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState"); … … 144 126 uint64_t timeAfterTick = time.getRealMicroseconds(); 145 127 146 // STATISTICS 147 assert(timeAfterTick - timeBeforeTick >= 0 ); 148 statisticsTickInfo tickInfo = {timeAfterTick, timeAfterTick - timeBeforeTick}; 149 statisticsTickTimes_.push_back(tickInfo); 150 assert(statisticsTickTimes_.back().tickLength==tickInfo.tickLength); 151 this->periodTickTime_ += tickInfo.tickLength; 128 // Also add our tick time to the list in GSRoot 129 Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick); 152 130 153 // Ticks GSGraphics or GSDedicated154 131 this->tickChild(time); 155 156 if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_)157 {158 std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();159 assert(it != this->statisticsTickTimes_.end());160 int64_t lastTime = timeAfterTick - statisticsAvgLength_;161 if ((int64_t)it->tickTime < lastTime)162 {163 do164 {165 assert(this->periodTickTime_ > it->tickLength);166 this->periodTickTime_ -= it->tickLength;167 ++it;168 assert(it != this->statisticsTickTimes_.end());169 } while ((int64_t)it->tickTime < lastTime);170 this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it);171 }172 173 uint32_t framesPerPeriod = this->statisticsTickTimes_.size();174 this->avgFPS_ = (float)framesPerPeriod / (timeAfterTick - this->statisticsTickTimes_.front().tickTime) * 1000000.0;175 this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0;176 177 statisticsStartTime_ = timeAfterTick;178 }179 180 132 } 181 133
Note: See TracChangeset
for help on using the changeset viewer.