Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2553


Ignore:
Timestamp:
Dec 30, 2008, 8:02:21 PM (15 years ago)
Author:
rgrieder
Message:

Little performance optimisation.

File:
1 edited

Legend:

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

    r2550 r2553  
    223223
    224224        // STATISTICS
    225         statisticsTickInfo tickInfo = {timeAfterTick, timeAfterTick - timeBeforeTick};
     225        uint32_t currentTickTime = timeAfterTick - timeBeforeTick;
     226        statisticsTickInfo tickInfo = {timeAfterTick, currentTickTime};
    226227        statisticsTickTimes_.push_back(tickInfo);
    227228
     
    233234        if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_)
    234235        {
    235             while (statisticsTickTimes_.front().tickTime < timeAfterTick - statisticsAvgLength_)
     236            std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
     237            assert(it != this->statisticsTickTimes_.end());
     238            uint64_t lastTime = timeAfterTick - statisticsAvgLength_;
     239            if (it->tickTime < lastTime)
    236240            {
    237                 this->periodTickTime_ -= this->statisticsTickTimes_.front().tickLength;
    238                 this->statisticsTickTimes_.pop_front();
     241                do
     242                {
     243                    this->periodTickTime_ -= it->tickLength;
     244                    ++it;
     245                    assert(it != this->statisticsTickTimes_.end());
     246                } while (it->tickTime < lastTime);
     247                this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), --it);
    239248            }
    240249
    241250            uint32_t framesPerPeriod = this->statisticsTickTimes_.size();
    242             this->avgFPS_ = (float)framesPerPeriod / (tickInfo.tickTime - this->statisticsTickTimes_.front().tickTime) * 1000000.0;
     251            this->avgFPS_ = (float)framesPerPeriod / (currentTickTime - this->statisticsTickTimes_.front().tickTime) * 1000000.0;
    243252            this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0;
    244253
Note: See TracChangeset for help on using the changeset viewer.