Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 28, 2008, 8:30:25 PM (17 years ago)
Author:
rgrieder
Message:
  • Wrote Clock() class: It starts an internal clock when GSRoot starts and gets handed to all GameState ticks as reference. You can then either query the ticked time or the real time (for instance for statistical measurements)
  • general clean up in all the game states
File:
1 edited

Legend:

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

    r1673 r1674  
    3232#include <OgreFrameListener.h>
    3333#include <OgreRoot.h>
    34 #include <OgreTimer.h>
    3534#include <OgreWindowEventUtilities.h>
    3635#include <OgreRenderWindow.h>
     
    3938#include "core/ConfigValueIncludes.h"
    4039#include "core/input/InputManager.h"
    41 //#include "core/Core.h"
    4240#include "overlays/console/InGameConsole.h"
    4341#include "gui/GUIManager.h"
     
    4846    GSGraphics::GSGraphics()
    4947        : GameState("graphics")
    50         , debugRefreshTime_(0.0f)
     48        , ogreRoot_(0)
     49        , graphicsEngine_(0)
    5150        , inputManager_(0)
    5251        , console_(0)
    5352        , guiManager_(0)
    5453        , frameCount_(0)
     54        , statisticsRefreshCycle_(0)
     55        , statisticsStartTime_(0)
     56        , statisticsStartCount_(0)
     57        , tickTime_(0)
    5558    {
    5659    }
     
    6265    void GSGraphics::setConfigValues()
    6366    {
    64         SetConfigValue(debugRefreshTime_, 0.2).description("Sets the time interval at which average fps, etc. get updated.");
     67        SetConfigValue(statisticsRefreshCycle_, 200000).description("Sets the time in microseconds interval at which average fps, etc. get updated.");
    6568    }
    6669
    6770    void GSGraphics::enter()
    6871    {
     72        setConfigValues();
     73
    6974        this->ogreRoot_ = Ogre::Root::getSingletonPtr();
    7075        this->graphicsEngine_ = GraphicsEngine::getInstancePtr();
     
    8893        guiManager_ = new GUIManager();
    8994        guiManager_->initialise();
     95
     96        // reset frame counter
     97        this->frameCount_ = 0;
     98        this->tickTime_ = 0;
     99        statisticsStartTime_ = 0;
     100        statisticsStartCount_ = 0;
    90101    }
    91102
     
    117128        need the time. So we shouldn't run into problems.
    118129    */
    119     void GSGraphics::ticked(float dt, uint64_t time)
     130    void GSGraphics::ticked(const Clock& time)
    120131    {
     132        uint64_t timeBeforeTick = time.getRealMicroseconds();
     133        float dt = time.getDeltaTime();
     134
    121135        this->inputManager_->tick(dt);
    122 
    123         this->tickChild(dt, time);
    124 
    125136        // tick console
    126137        this->console_->tick(dt);
     138        this->tickChild(time);
     139       
     140        uint64_t timeAfterTick = time.getRealMicroseconds();
    127141
    128         //// get current time once again
    129         //timeAfterTick = timer_->getMicroseconds();
     142        tickTime_ += (unsigned int)(timeAfterTick - timeBeforeTick);
     143        if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_)
     144        {
     145            GraphicsEngine::getInstance().setAverageTickTime(
     146                (float)tickTime_ * 0.001f / (frameCount_ - statisticsStartCount_));
     147            float avgFPS = (float)(frameCount_ - statisticsStartCount_)
     148                / (timeAfterTick - statisticsStartTime_) * 1000000.0;
     149            GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS);
    130150
    131         //tickTime += timeAfterTick - timeBeforeTick;
    132         //if (timeAfterTick > refreshStartTime + refreshTime)
    133         //{
    134         //    GraphicsEngine::getInstance().setAverageTickTime(
    135         //        (float)tickTime * 0.001 / (frameCount - oldFrameCount));
    136         //    float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0;
    137         //    GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS);
    138 
    139         //    oldFrameCount = frameCount;
    140         //    tickTime = 0;
    141         //    refreshStartTime = timeAfterTick;
    142         //}
     151            tickTime_ = 0;
     152            statisticsStartCount_ = frameCount_;
     153            statisticsStartTime_  = timeAfterTick;
     154        }
    143155
    144156        // don't forget to call _fireFrameStarted in ogre to make sure
     
    163175
    164176        ++frameCount_;
    165 
    166         //}
    167         //catch (std::exception& ex)
    168         //{
    169         //    // something went wrong.
    170         //    COUT(1) << ex.what() << std::endl;
    171         //    COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl;
    172         //}
    173177    }
    174178}
Note: See TracChangeset for help on using the changeset viewer.