v0.1.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Pages
CGUL::Timer Class Reference

A timer to keep track of time, similar to a stop watch. More...

#include <Timer.hpp>

Public Member Functions

 Timer ()
 Default constructor.
 
Timeroperator= (const Timer &operand)
 Copies data from one timer into another. More...
 
void Start ()
 Starts the timer causing time to elapse. More...
 
void Stop ()
 Stops the timer, freezing it at the current time. More...
 
void Reset ()
 Resets the timer to zero without stopping or starting it. More...
 
void SetElapsedSeconds (Float64 seconds)
 
void SetElapsedMilliseconds (Float64 milliseconds)
 
Float64 GetElapsedSeconds () const
 Get the elapsed time (in seconds) from when the timer was started. More...
 
Float64 GetElapsedMilliseconds () const
 Get the elapsed time (in milliseconds) from when the timer was started. More...
 
Float64 GetDeltaTime ()
 A quick utility function for calculating delta time. More...
 

Static Public Member Functions

static void Sleep (UInt32 milliseconds)
 Causes the current thread to idle for the given amount of time (in millseconds). More...
 
static Float64 GetSeconds ()
 Get a system time in seconds. More...
 
static Float64 GetMilliseconds ()
 Get a system time in milliseconds. More...
 
static UInt64 GetRawTime ()
 Gets a high precision timestamp. More...
 

Detailed Description

A timer to keep track of time, similar to a stop watch.

Member Function Documentation

CGUL::Float64 CGUL::Timer::GetDeltaTime ( )

A quick utility function for calculating delta time.

Determines time in between calls and returns a floating point (decimal) time in seconds. It is recommended that this method be used instead of Start, Stop, and Reset for delta time calculations because it is better optimized for that purpose and will yield more accurate results. Additionally, this method will reset the timer every time it is called so the GetElapsedSeconds and GetElapsedMilliseconds methods will not give accurate results.

Note
The first time this method is called it will return the time between the creation of the Timer object and the time the method was called. For best use create the Timer immediately before it is to be used.
Returns
A floating pointer decimal number representing the time in seconds since the last call to this method.
CGUL::Float64 CGUL::Timer::GetElapsedMilliseconds ( ) const

Get the elapsed time (in milliseconds) from when the timer was started.

Represents the time currently recorded by this clock some time after a call to the Start method. If a clock has not been started this method will simply return zero.

Returns
Elapsed time in milliseconds.
CGUL::Float64 CGUL::Timer::GetElapsedSeconds ( ) const

Get the elapsed time (in seconds) from when the timer was started.

Same as GetElapsedMilliseconds method but in seconds.

See Also
GetElapsedMilliseconds
Returns
Elapsed time in seconds.
CGUL::Float64 CGUL::Timer::GetMilliseconds ( )
static

Get a system time in milliseconds.

Gets a time from the operating system in milliseconds. The time acquired is not guaranteed to represent any significance aside from being incremental from a previous GetMilliseconds or GetSeconds call. In other words, this time does not represent the current time of day, the time the operating system has been up, or any other such data. The only purpose of this method is to compare two time stamps to find a delta in time.

Returns
An undefined time in milliseconds.
CGUL::UInt64 CGUL::Timer::GetRawTime ( )
static

Gets a high precision timestamp.

The value here is practically guaranteed to be different everytime it's called. The value is primarily useful for seeding random numbers.

Returns
A high precision timestamp of little value to anyone.
CGUL::Float64 CGUL::Timer::GetSeconds ( )
static

Get a system time in seconds.

Same as the GetMilliseconds method but in seconds.

See Also
GetMilliseconds
Returns
An undefined time in seconds.
CGUL::Timer & CGUL::Timer::operator= ( const Timer operand)

Copies data from one timer into another.

Copies over whatever data is in the right-hand-side timer, including time and whether or not its running.

void CGUL::Timer::Reset ( )

Resets the timer to zero without stopping or starting it.

Acts just as the reset would on a stop watch. The current time is set to zero but the state of the clock is not changed. If the clock was running when this method was called then it will continue to run starting from zero. In order to both stop and reset the clock, the methods Stop and Reset must be called in that order. Calling the Start method after calling Reset will cause the clock to pick up the time where it left off.

See Also
Start
Stop
void CGUL::Timer::SetElapsedMilliseconds ( Float64  milliseconds)
Parameters
millisecondsNumber of milliseconds on the clock.
void CGUL::Timer::SetElapsedSeconds ( Float64  seconds)
Parameters
secondsNumber of seconds on the clock.
void CGUL::Timer::Sleep ( UInt32  milliseconds)
static

Causes the current thread to idle for the given amount of time (in millseconds).

A program that never sleeps can cause CPU thrashing so its a good idea to call sleep and let the CPU take care of other things for a short while. Sleeping will cause the currently active thread to halt for the given amount of time. As little as 1 millisecond is enough to take a huge load off of the CPU and its recommended that applications in a constant loop makes a call each tick to the Sleep method. It is not guaranteed (and in fact very unlikely) that this method will halt the program for exactly the amount of milliseconds specified.

Parameters
millisecondsThe amount of time to sleep in milliseconds.
void CGUL::Timer::Start ( )

Starts the timer causing time to elapse.

Acts just as the start would on a stop watch. If the clock is currently stopped it will resume the last time recorded. If the clock is already started, it will do nothing.

See Also
Stop
Reset
void CGUL::Timer::Stop ( )

Stops the timer, freezing it at the current time.

Acts just as the stop would on a stop watch. The current time will be recorded and the clock will stop progressing forward. This method will not reset the clock to zero, for that the Reset method must be called separately. If the clock is already stopped then this method does nothing.

See Also
Start
Reset

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