Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Private Member Functions | Private Attributes | List of all members
orxonox::Clock Class Reference

Simple real time clock based on Ogre::Timer. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/util/Clock.h>

Public Member Functions

 Clock ()
 Starts the time at 0. More...
 
 ~Clock ()
 
void capture ()
 Internally captures the time and stays at that particular time. More...
 
float getDeltaTime () const
 Returns the timespan in seconds between the last two calls to capture() More...
 
long getDeltaTimeMicroseconds () const
 Returns the timespan in microseconds between the last two calls to capture() More...
 
unsigned long long getMicroseconds () const
 Returns the last captured absolute time in microseconds. More...
 
unsigned long long getMilliseconds () const
 Returns the last captured absolute time in milliseconds. More...
 
unsigned long long getRealMicroseconds () const
 Returns the current real time in microseconds. More...
 
unsigned long getSeconds () const
 Returns the last captured absolute time in seconds. More...
 
float getSecondsPrecise () const
 Returns the last captured absolute time in seconds as float. More...
 

Private Member Functions

 Clock (const Clock &)=delete
 
Clockoperator= (const Clock &)=delete
 

Private Attributes

long tickDt_
 Delta time in microseconds (cache value) More...
 
float tickDtFloat_
 Delta time in seconds (cache value) More...
 
unsigned long long tickTime_
 Currently captured time. More...
 
Ogre::Timer * timer_
 Ogre timer object. More...
 

Detailed Description

Simple real time clock based on Ogre::Timer.

The class can be used to both capture the current real time or to incrementally capture the time and then distribute that time information via Clock& references (for instance for the game tick).
Precision:

Precision
The maximum precision is given by the Ogre::Timer and that is somewhere in the microsecond range for both Windows and UNIX.
Remarks for Usage on Windows
For proper functionality this class MUST be used in the same thread!
Furthermore it might be possible that the Ogre::Timer has a performance caveat because it will only capture the time on the same CPU core. Confining the main thread to one process could speed up the game.

Constructor & Destructor Documentation

orxonox::Clock::Clock ( )

Starts the time at 0.

orxonox::Clock::~Clock ( )
orxonox::Clock::Clock ( const Clock )
privatedelete

Member Function Documentation

void orxonox::Clock::capture ( )

Internally captures the time and stays at that particular time.

Remarks
Mind the types! Ogre::Timer::getMicroseconds() will return an unsigned long, which will eventually overflow. But if you use the subtraction of the current time minus the last time the timer gave us and sum these up to a 64 bit integer, we get the desired result.
Also mind that we don't have to store the last timer's time as unsigned long as well because (unsigned long)tickTime_ will do exactly that.
float orxonox::Clock::getDeltaTime ( ) const
inline

Returns the timespan in seconds between the last two calls to capture()

long orxonox::Clock::getDeltaTimeMicroseconds ( ) const
inline

Returns the timespan in microseconds between the last two calls to capture()

unsigned long long orxonox::Clock::getMicroseconds ( ) const
inline

Returns the last captured absolute time in microseconds.

unsigned long long orxonox::Clock::getMilliseconds ( ) const
inline

Returns the last captured absolute time in milliseconds.

unsigned long long orxonox::Clock::getRealMicroseconds ( ) const

Returns the current real time in microseconds.

Note
This is especially useful to measure execution times because of the high precision.
unsigned long orxonox::Clock::getSeconds ( ) const
inline

Returns the last captured absolute time in seconds.

float orxonox::Clock::getSecondsPrecise ( ) const
inline

Returns the last captured absolute time in seconds as float.

Clock& orxonox::Clock::operator= ( const Clock )
privatedelete

Member Data Documentation

long orxonox::Clock::tickDt_
private

Delta time in microseconds (cache value)

float orxonox::Clock::tickDtFloat_
private

Delta time in seconds (cache value)

unsigned long long orxonox::Clock::tickTime_
private

Currently captured time.

Ogre::Timer* orxonox::Clock::timer_
private

Ogre timer object.


The documentation for this class was generated from the following files: