Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 30, 2008, 3:27:39 PM (15 years ago)
Author:
rgrieder
Message:

Moved tick time measurement to GSRoot. The values get combined with the one from GSGraphics.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/orxonox/gamestates/GSRoot.cc

    r2485 r2549  
    8989    void GSRoot::setConfigValues()
    9090    {
     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.");
    9195    }
    9296
     
    98102        // reset game speed to normal
    99103        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;
    100112
    101113        // Create the lua interface
     
    189201    void GSRoot::ticked(const Clock& time)
    190202    {
     203        uint64_t timeBeforeTick = time.getRealMicroseconds();
     204
    191205        TclThreadManager::getInstance().tick(time.getDeltaTime());
    192206
     
    206220        /*** HACK *** HACK ***/
    207221
     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
    208229        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_;
    209249    }
    210250
Note: See TracChangeset for help on using the changeset viewer.