Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2549


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.

Location:
code/branches/presentation/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/core/RootGameState.cc

    r2485 r2549  
    122122    /**
    123123    @brief
     124        Main loop of the orxonox game.
    124125        Starts the game. The little 'while' denotes the main loop.
    125126        Whenever the root state is selected, the game ends.
    126127    @param name
    127128        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!).
    128133    */
    129134    void RootGameState::start()
  • code/branches/presentation/src/orxonox/gamestates/GSDedicated.cc

    r2415 r2549  
    7474    void GSDedicated::ticked(const Clock& time)
    7575    {
    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;
    8384            GSLevel::ticked(time);
    8485            server_->tick(time.getDeltaTime());
     
    8788        else
    8889        {
    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;
    9192        }
    9293    }
  • code/branches/presentation/src/orxonox/gamestates/GSGraphics.cc

    r2548 r2549  
    7676        , graphicsEngine_(0)
    7777        , masterKeyBinder_(0)
    78         , frameCount_(0)
    79         , statisticsRefreshCycle_(0)
    80         , statisticsStartTime_(0)
    81         , statisticsStartCount_(0)
    82         , tickTime_(0)
    8378        , debugOverlay_(0)
    8479    {
     
    107102        SetConfigValue(ogreLogLevelCritical_, 2)
    108103            .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.");
    113104        SetConfigValue(defaultMasterKeybindings_, "def_masterKeybindings.ini")
    114105            .description("Filename of default master keybindings.");
     
    158149        guiManager_->initialise(this->renderWindow_);
    159150
    160         // reset frame counter
    161         this->frameCount_ = 0;
    162         this->tickTime_ = 0;
    163         statisticsStartTime_ = 0;
    164         statisticsStartCount_ = 0;
    165 
    166151        // add console commands
    167152        FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen);
     
    228213
    229214    /**
    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
    236216        A note about the Ogre::FrameListener: Even though we don't use them,
    237217        they still get called. However, the delta times are not correct (except
     
    243223    {
    244224        uint64_t timeBeforeTick = time.getRealMicroseconds();
     225
    245226        float dt = time.getDeltaTime();
    246227
     
    259240        uint64_t timeAfterTick = time.getRealMicroseconds();
    260241
    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());
    289248
    290249        // don't forget to call _fireFrameStarted in ogre to make sure
     
    307266        // again, just to be sure ogre works fine
    308267        ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
    309 
    310         ++frameCount_;
    311268    }
    312269
  • code/branches/presentation/src/orxonox/gamestates/GSGraphics.h

    r2548 r2549  
    3737#include "GSRoot.h"
    3838
    39 #include <deque>
    40 
    4139namespace orxonox
    4240{
    43     struct statisticsTickInfo{
    44         uint64_t    tickTime;
    45         uint32_t    tickLength;
    46     };
    47    
    4841    class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass,
    4942                                      public Ogre::WindowEventListener, public Ogre::LogListener
     
    10093
    10194        KeyBinder*            masterKeyBinder_;
    102 
    103         // variables for time statistics
    104         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_;
    11295        XMLFile*              debugOverlay_;
    11396
     
    120103        int                   ogreLogLevelNormal_;       //!< Corresponding Orxonx debug level for LL_NORMAL
    121104        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)
    123105        std::string           defaultMasterKeybindings_; //!< Filename of default master keybindings.
    124106
  • code/branches/presentation/src/orxonox/gamestates/GSLevel.h

    r2485 r2549  
    3333#include <OgrePrerequisites.h>
    3434#include "core/GameState.h"
    35 #include "GSGraphics.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport GSLevel : public OrxonoxClass //,public GameState<GSGraphics>
     38    class _OrxonoxExport GSLevel : public OrxonoxClass
    4039    {
    4140        friend class ClassIdentifier<GSLevel>;
  • 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
  • code/branches/presentation/src/orxonox/gamestates/GSRoot.h

    r2485 r2549  
    3131
    3232#include "OrxonoxPrereqs.h"
     33
     34#include <list>
    3335#include <OgreLog.h>
    3436#include "core/RootGameState.h"
     
    4042    {
    4143        friend class ClassIdentifier<GSRoot>;
     44
     45    public:
     46        struct statisticsTickInfo
     47        {
     48            uint64_t    tickTime;
     49            uint32_t    tickLength;
     50        };
     51   
    4252    public:
    4353        GSRoot();
     
    5262        void pause();
    5363        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; }
    5470
    5571    private:
     
    6985        Shell*                shell_;
    7086        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_;
    71100
    72101        // console commands
Note: See TracChangeset for help on using the changeset viewer.