Index: code/branches/gui/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/branches/gui/src/orxonox/gamestates/GSGraphics.cc	(revision 1673)
+++ code/branches/gui/src/orxonox/gamestates/GSGraphics.cc	(revision 1674)
@@ -32,5 +32,4 @@
 #include <OgreFrameListener.h>
 #include <OgreRoot.h>
-#include <OgreTimer.h>
 #include <OgreWindowEventUtilities.h>
 #include <OgreRenderWindow.h>
@@ -39,5 +38,4 @@
 #include "core/ConfigValueIncludes.h"
 #include "core/input/InputManager.h"
-//#include "core/Core.h"
 #include "overlays/console/InGameConsole.h"
 #include "gui/GUIManager.h"
@@ -48,9 +46,14 @@
     GSGraphics::GSGraphics()
         : GameState("graphics")
-        , debugRefreshTime_(0.0f)
+        , ogreRoot_(0)
+        , graphicsEngine_(0)
         , inputManager_(0)
         , console_(0)
         , guiManager_(0)
         , frameCount_(0)
+        , statisticsRefreshCycle_(0)
+        , statisticsStartTime_(0)
+        , statisticsStartCount_(0)
+        , tickTime_(0)
     {
     }
@@ -62,9 +65,11 @@
     void GSGraphics::setConfigValues()
     {
-        SetConfigValue(debugRefreshTime_, 0.2).description("Sets the time interval at which average fps, etc. get updated.");
+        SetConfigValue(statisticsRefreshCycle_, 200000).description("Sets the time in microseconds interval at which average fps, etc. get updated.");
     }
 
     void GSGraphics::enter()
     {
+        setConfigValues();
+
         this->ogreRoot_ = Ogre::Root::getSingletonPtr();
         this->graphicsEngine_ = GraphicsEngine::getInstancePtr();
@@ -88,4 +93,10 @@
         guiManager_ = new GUIManager();
         guiManager_->initialise();
+
+        // reset frame counter
+        this->frameCount_ = 0;
+        this->tickTime_ = 0;
+        statisticsStartTime_ = 0;
+        statisticsStartCount_ = 0;
     }
 
@@ -117,28 +128,29 @@
         need the time. So we shouldn't run into problems.
     */
-    void GSGraphics::ticked(float dt, uint64_t time)
+    void GSGraphics::ticked(const Clock& time)
     {
+        uint64_t timeBeforeTick = time.getRealMicroseconds();
+        float dt = time.getDeltaTime();
+
         this->inputManager_->tick(dt);
-
-        this->tickChild(dt, time);
-
         // tick console
         this->console_->tick(dt);
+        this->tickChild(time);
+        
+        uint64_t timeAfterTick = time.getRealMicroseconds();
 
-        //// get current time once again
-        //timeAfterTick = timer_->getMicroseconds();
+        tickTime_ += (unsigned int)(timeAfterTick - timeBeforeTick);
+        if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_)
+        {
+            GraphicsEngine::getInstance().setAverageTickTime(
+                (float)tickTime_ * 0.001f / (frameCount_ - statisticsStartCount_));
+            float avgFPS = (float)(frameCount_ - statisticsStartCount_)
+                / (timeAfterTick - statisticsStartTime_) * 1000000.0;
+            GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS);
 
-        //tickTime += timeAfterTick - timeBeforeTick;
-        //if (timeAfterTick > refreshStartTime + refreshTime)
-        //{
-        //    GraphicsEngine::getInstance().setAverageTickTime(
-        //        (float)tickTime * 0.001 / (frameCount - oldFrameCount));
-        //    float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0;
-        //    GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS);
-
-        //    oldFrameCount = frameCount;
-        //    tickTime = 0;
-        //    refreshStartTime = timeAfterTick;
-        //}
+            tickTime_ = 0;
+            statisticsStartCount_ = frameCount_;
+            statisticsStartTime_  = timeAfterTick;
+        }
 
         // don't forget to call _fireFrameStarted in ogre to make sure
@@ -163,12 +175,4 @@
 
         ++frameCount_;
-
-        //}
-        //catch (std::exception& ex)
-        //{
-        //    // something went wrong.
-        //    COUT(1) << ex.what() << std::endl;
-        //    COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl;
-        //}
     }
 }
