Gorgon Game Engine
Timer Class Reference

Millisecond based timer. More...

Public Member Functions

 Timer (unsigned passed=0)
 Default constructor. More...
 
unsigned Get () const
 Returns total time passed. More...
 
 operator unsigned () const
 Returns total time passed. More...
 
void Reset ()
 Resets the passed time. Adjusts starting time of the timer. More...
 
void Set (unsigned passed)
 Changes the passed time. Adjusts starting time of the timer. More...
 
void ShowDialog (const std::string &name="Time passed", const std::string &title="Performance timer") const
 Shows a UI dialog displaying the amount of time passed. More...
 
void Start ()
 Starts the timer from this instant. More...
 
TimerTick ()
 Counts the time since the last Start, Tick, Set, Reset or from the contruction of the timer and adds this duration to time passed. More...
 

Detailed Description

Millisecond based timer.

This class allows performance calculations. Constructing a new timer effectively starts it. However, explicit start might be used to exclude the time passed from the Timer construction or last Tick. All output functions are constant and do not modify the timer. Because of this, a Tick method might be necessary. The display functions will always report the time passed at the last tick. Pause function is not required and not included. Pause can be performed by issuing a Tick and using Start at the end of the pause. This class has a very low memory and processing overhead.

Example:

// Counts the time passed in longoperation functions
Timer timer;
longoperation();
std::cout<<timer.Tick()<<std::endl;
anotheroperation();
timer.Start();
longoperation();
timer.Tick().ShowDialog(); //Tick function can be cascaded

Constructor & Destructor Documentation

◆ Timer()

Timer ( unsigned  passed = 0)

Default constructor.

Starts the timer right away. If another start point is required, issuing a Start method before calling Tick will over ride previous starting point.

Parameters
passedcan be specified to start the timer from the given duration.

References Gorgon::Time::GetTime().

Member Function Documentation

◆ Get()

unsigned Get ( ) const

Returns total time passed.

This value updates only when Tick method is called. Therefore, to get a recent value, Tick method should be called prior to this method.

◆ operator unsigned()

operator unsigned ( ) const

Returns total time passed.

This value updates only when Tick method is called. Therefore, to get a recent value, Tick method should be called prior to this method.

◆ Reset()

void Reset ( )

Resets the passed time. Adjusts starting time of the timer.

References Timer::Set().

◆ Set()

void Set ( unsigned  passed)

Changes the passed time. Adjusts starting time of the timer.

References Gorgon::Time::GetTime().

◆ ShowDialog()

void ShowDialog ( const std::string &  name = "Time passed",
const std::string &  title = "Performance timer" 
) const

Shows a UI dialog displaying the amount of time passed.

Like Get method, this method does not update the time passed. Therefore, to get a recent value, Tick method should be called prior to this method.

Parameters
namethat will be used to label the timer. It will be displayed within the window dialog.
titleof the dialog window.

◆ Start()

void Start ( )

Starts the timer from this instant.

Any progress since the last Tick will be ignored. This allows pausing and starting the timer after construction.

References Gorgon::Time::GetTime().

◆ Tick()

Timer& Tick ( )

Counts the time since the last Start, Tick, Set, Reset or from the contruction of the timer and adds this duration to time passed.

Use Get method to retrieve total ellapsed time.

Returns
Returns back the timer itself. This allows cascaded calling.
See also
Timer

References Gorgon::Time::GetTime().


The documentation for this class was generated from the following files:
Gorgon::Time::Timer::Timer
Timer(unsigned passed=0)
Default constructor.
Definition: Timer.h:40