MAGE  v0.171.0
Matthias Advanced Game Engine
mage::Timer< ClockT > Class Template Reference

#include <timer.hpp>

Public Member Functions

 Timer () noexcept
 
 Timer (const Timer &timer) noexcept=default
 
 Timer (Timer &&timer) noexcept=default
 
 ~Timer ()=default
 
Timeroperator= (const Timer &timer) noexcept=default
 
Timeroperator= (Timer &&timer) noexcept=default
 
void Start () noexcept
 
void Stop () noexcept
 
void Restart () noexcept
 
void Resume () noexcept
 
TimeIntervalSeconds GetDeltaTime () noexcept
 
TimeIntervalSeconds GetTotalDeltaTime () noexcept
 
const std::pair< TimeIntervalSeconds, TimeIntervalSecondsGetTime () noexcept
 

Private Types

using TimeStamp = typename ClockT::time_point
 
using TimeInterval = typename ClockT::duration
 

Private Member Functions

void ResetDeltaTime () noexcept
 
void UpdateDeltaTime () noexcept
 

Private Attributes

ClockT m_clock
 
TimeStamp m_last_timestamp
 
TimeInterval m_delta_time
 
TimeInterval m_total_delta_time
 
bool m_running
 

Detailed Description

template<typename ClockT>
class mage::Timer< ClockT >

A class of timers.

Template Parameters
ClockTThe clock type.

Member Typedef Documentation

◆ TimeInterval

template<typename ClockT>
using mage::Timer< ClockT >::TimeInterval = typename ClockT::duration
private

The time interval type representing the interval between time points of timers.

◆ TimeStamp

template<typename ClockT>
using mage::Timer< ClockT >::TimeStamp = typename ClockT::time_point
private

The time stamp type representing the time points of timers.

Constructor & Destructor Documentation

◆ Timer() [1/3]

template<typename ClockT>
mage::Timer< ClockT >::Timer ( )
noexcept

Constructs a timer.

◆ Timer() [2/3]

template<typename ClockT>
mage::Timer< ClockT >::Timer ( const Timer< ClockT > &  timer)
defaultnoexcept

Constructs a timer from the given timer.

Parameters
[in]timerA reference to the timer to copy.

◆ Timer() [3/3]

template<typename ClockT>
mage::Timer< ClockT >::Timer ( Timer< ClockT > &&  timer)
defaultnoexcept

Constructs a timer by moving the given timer.

Parameters
[in]timerA reference to the timer to move.

◆ ~Timer()

template<typename ClockT>
mage::Timer< ClockT >::~Timer ( )
default

Destructs this timer.

Member Function Documentation

◆ GetDeltaTime()

template<typename ClockT>
TimeIntervalSeconds mage::Timer< ClockT >::GetDeltaTime ( )
noexcept

Returns the delta time (in seconds) of this timer.

Returns
The delta time (in seconds) of this timer.

◆ GetTime()

template<typename ClockT>
const std::pair< TimeIntervalSeconds, TimeIntervalSeconds > mage::Timer< ClockT >::GetTime ( )
noexcept

Returns the delta and total delta time (in seconds) of this timer.

Returns
A pair containing the the delta and total delta time (in seconds) of this timer.

◆ GetTotalDeltaTime()

template<typename ClockT>
TimeIntervalSeconds mage::Timer< ClockT >::GetTotalDeltaTime ( )
noexcept

Returns the total delta time (in seconds) of this timer.

Returns
The total delta time (in seconds) of this timer.

◆ operator=() [1/2]

template<typename ClockT>
Timer& mage::Timer< ClockT >::operator= ( const Timer< ClockT > &  timer)
defaultnoexcept

Copies the given timer to this timer.

Parameters
[in]timerA reference to the timer to copy.
Returns
A reference to the copy of the given timer (i.e. this timer).

◆ operator=() [2/2]

template<typename ClockT>
Timer& mage::Timer< ClockT >::operator= ( Timer< ClockT > &&  timer)
defaultnoexcept

Moves the given timer to this timer.

Parameters
[in]timerA reference to the timer to move.
Returns
A reference to the moved timer (i.e. this timer).

◆ ResetDeltaTime()

template<typename ClockT>
void mage::Timer< ClockT >::ResetDeltaTime ( )
privatenoexcept

Resets the delta time, total delta time and last timestamp of this timer.

◆ Restart()

template<typename ClockT>
void mage::Timer< ClockT >::Restart ( )
noexcept

Restarts this timer.

◆ Resume()

template<typename ClockT>
void mage::Timer< ClockT >::Resume ( )
noexcept

Resumes this timer.

◆ Start()

template<typename ClockT>
void mage::Timer< ClockT >::Start ( )
noexcept

Starts this timer.

◆ Stop()

template<typename ClockT>
void mage::Timer< ClockT >::Stop ( )
noexcept

Stops this timer.

◆ UpdateDeltaTime()

template<typename ClockT>
void mage::Timer< ClockT >::UpdateDeltaTime ( )
privatenoexcept

Updates the delta time, total delta time and last timestamp of this timer.

Member Data Documentation

◆ m_clock

template<typename ClockT>
ClockT mage::Timer< ClockT >::m_clock
private

The clock of this timer.

◆ m_delta_time

template<typename ClockT>
TimeInterval mage::Timer< ClockT >::m_delta_time
private

The delta time of this timer.

◆ m_last_timestamp

template<typename ClockT>
TimeStamp mage::Timer< ClockT >::m_last_timestamp
private

The last timestamp of this timer.

◆ m_running

template<typename ClockT>
bool mage::Timer< ClockT >::m_running
private

Flag indicating whether this timer is running.

◆ m_total_delta_time

template<typename ClockT>
TimeInterval mage::Timer< ClockT >::m_total_delta_time
private

The total delta time of this timer.