Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 28, 2008, 8:30:25 PM (16 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/GSIO.cc

    r1672 r1674  
    3030#include "GSIO.h"
    3131
    32 #include <OgreFrameListener.h>
    33 #include <OgreRoot.h>
    34 #include <OgreTimer.h>
    35 
    36 #include "core/ConsoleCommand.h"
    37 #include "core/TclThreadManager.h"
    38 #include "GraphicsEngine.h"
    39 
    4032namespace orxonox
    4133{
    4234    GSIO::GSIO()
    4335        : GameState("io")
    44         //, timer_(0)
    4536    {
    4637    }
     
    5849    }
    5950
    60     void GSIO::ticked(float dt, uint64_t time)
     51    void GSIO::ticked(const Clock& time)
    6152    {
    62         this->tickChild(dt, time);
    63         //Ogre::Root& ogreRoot = Ogre::Root::getSingleton();
    64 
    65         //unsigned long frameCount = 0;
    66 
    67         //const unsigned long refreshTime = (unsigned long)(debugRefreshTime_ * 1000000.0f);
    68         //unsigned long refreshStartTime = 0;
    69         //unsigned long tickTime = 0;
    70         //unsigned long oldFrameCount = 0;
    71 
    72         //unsigned long timeBeforeTick = 0;
    73         //unsigned long timeBeforeTickOld = 0;
    74         //unsigned long timeAfterTick = 0;
    75 
    76         //// TODO: Update time in seconds every 7 seconds to avoid any overflow (7 secs is very tight)
    77 
    78         //COUT(3) << "Orxonox: Starting the main loop." << std::endl;
    79 
    80         //try
    81         //{
    82         //    timer_->reset();
    83         //    while (!this->hasScheduledTransition())
    84         //    {
    85         //        // get current time
    86         //        timeBeforeTickOld = timeBeforeTick;
    87         //        timeBeforeTick    = timer_->getMicroseconds();
    88         //        float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0;
    89 
    90         //        TclThreadManager::getInstance().tick(dt);
    91 
    92         //        this->tickChild(dt);
    93 
    94         //        // get current time once again
    95         //        timeAfterTick = timer_->getMicroseconds();
    96 
    97         //        tickTime += timeAfterTick - timeBeforeTick;
    98         //        if (timeAfterTick > refreshStartTime + refreshTime)
    99         //        {
    100         //            GraphicsEngine::getInstance().setAverageTickTime(
    101         //                (float)tickTime * 0.001 / (frameCount - oldFrameCount));
    102         //            float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0;
    103         //            GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS);
    104 
    105         //            oldFrameCount = frameCount;
    106         //            tickTime = 0;
    107         //            refreshStartTime = timeAfterTick;
    108         //        }
    109 
    110         //        // don't forget to call _fireFrameStarted in ogre to make sure
    111         //        // everything goes smoothly
    112         //        Ogre::FrameEvent evt;
    113         //        evt.timeSinceLastFrame = dt;
    114         //        evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway
    115         //        ogreRoot._fireFrameStarted(evt);
    116 
    117         //        // again, just to be sure ogre works fine
    118         //        ogreRoot._fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
    119 
    120         //        ++frameCount;
    121         //    }
    122         //}
    123         //catch (std::exception& ex)
    124         //{
    125         //    // something went wrong.
    126         //    COUT(1) << ex.what() << std::endl;
    127         //    COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl;
    128         //}
     53        this->tickChild(time);
    12954    }
    13055}
Note: See TracChangeset for help on using the changeset viewer.