Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 21, 2009, 10:17:59 PM (15 years ago)
Author:
rgrieder
Message:

Removed GameState template and renamed GameStateBase to GameState.
Moved statistics stuff (fps and tick time) to Game and removed the remaining hacks in GSGraphics and GSRoot.

File:
1 edited

Legend:

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

    r2805 r2817  
    3333#include "util/Debug.h"
    3434#include "core/Core.h"
    35 #include "core/ConfigValueIncludes.h"
    3635#include "core/CoreIncludes.h"
    3736#include "core/ConsoleCommand.h"
    3837#include "tools/Timer.h"
    3938#include "objects/Tickable.h"
     39#include "Game.h"
    4040
    4141namespace orxonox
     
    4747        , timeFactorPauseBackup_(1.0f)
    4848    {
    49         RegisterRootObject(GSRoot);
    50         setConfigValues();
    51 
    5249        this->ccSetTimeFactor_ = 0;
    5350        this->ccPause_ = 0;
     
    5855    }
    5956
    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 
    6857    void GSRoot::enter()
    6958    {
     
    7160        timeFactor_ = 1.0f;
    7261
    73         // reset frame counter
    74         this->statisticsStartTime_ = 0;
    75         this->statisticsTickTimes_.clear();
    76         this->periodTickTime_ = 0;
    77         this->avgFPS_ = 0.0f;
    78         this->avgTickTime_ = 0.0f;
    79 
    8062        {
    8163            // add console commands
    82             FunctorMember01<GameStateBase, const std::string&>* functor = createFunctor(&GameStateBase::requestState);
     64            FunctorMember01<GameState, const std::string&>* functor = createFunctor(&GameState::requestState);
    8365            functor->setObject(this);
    8466            this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState");
     
    144126        uint64_t timeAfterTick = time.getRealMicroseconds();
    145127
    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);
    152130
    153         // Ticks GSGraphics or GSDedicated
    154131        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                 do
    164                 {
    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 
    180132    }
    181133
Note: See TracChangeset for help on using the changeset viewer.