HoverRace  2.0
Public Types | Public Member Functions | Private Attributes | List of all members
HoverRace::Util::Clock Class Reference

A game clock that manages the current time in the simulation. More...

#include <Clock.h>

+ Inheritance diagram for HoverRace::Util::Clock:

Public Types

using alarmSignal_t = boost::signals2::signal< void()>
 

Public Member Functions

 Clock ()
 Constructor. More...
 
 Clock (const Duration &init)
 Constructor. More...
 
 Clock (const Clock &)=delete
 
 Clock (Clock &&)=default
 
virtual ~Clock ()
 
Duration Advance ()
 Advance the clock to the current time. More...
 
template<class Fn >
boost::signals2::connection At (const Duration &duration, Fn &&fn)
 Set a one-shot alarm to run at a specific time. More...
 
void ClearAlarms () noexcept
 Remove all alarms. More...
 
std::string FmtLong () const
 
std::string FmtShort () const
 
const DurationGetTime () const noexcept
 Retrieve the time of the last call to Advance(). More...
 
Clockoperator= (const Clock &)=delete
 
Clockoperator= (Clock &&)=default
 
void SetTime (const Duration &duration={}) noexcept
 

Private Attributes

std::map< Duration, std::unique_ptr< alarmSignal_t > > alarms
 
Duration lastRead
 
Duration offset
 
Duration start
 

Detailed Description

A game clock that manages the current time in the simulation.

Author
Michael Imamura

Member Typedef Documentation

using HoverRace::Util::Clock::alarmSignal_t = boost::signals2::signal<void()>

Constructor & Destructor Documentation

HoverRace::Util::Clock::Clock ( )

Constructor.

The initial simulation time will be zero.

HoverRace::Util::Clock::Clock ( const Duration init)

Constructor.

Parameters
initThe initial simulation time.
HoverRace::Util::Clock::Clock ( const Clock )
delete
HoverRace::Util::Clock::Clock ( Clock &&  )
default
virtual HoverRace::Util::Clock::~Clock ( )
inlinevirtual

Member Function Documentation

Duration HoverRace::Util::Clock::Advance ( )

Advance the clock to the current time.

Returns
The elapsed time since the last time the clock was advanced.
template<class Fn >
boost::signals2::connection HoverRace::Util::Clock::At ( const Duration duration,
Fn &&  fn 
)
inline

Set a one-shot alarm to run at a specific time.

It's not guaranteed that the alarm will be fired at the exact time since alarms are only fired when Advance() is called; however, an alarm will never be fired before it's timestamp.

Parameters
durationThe clock timestamp.
fnThe function to invoke.
Returns
The signal connection; use this to cancel the alarm by disconnecting it.
void HoverRace::Util::Clock::ClearAlarms ( )
inlinenoexcept

Remove all alarms.

std::string HoverRace::Util::Clock::FmtLong ( ) const
inline
std::string HoverRace::Util::Clock::FmtShort ( ) const
inline
const Duration& HoverRace::Util::Clock::GetTime ( ) const
inlinenoexcept

Retrieve the time of the last call to Advance().

Clock& HoverRace::Util::Clock::operator= ( const Clock )
delete
Clock& HoverRace::Util::Clock::operator= ( Clock &&  )
default
void HoverRace::Util::Clock::SetTime ( const Duration duration = {})
noexcept

Member Data Documentation

std::map<Duration, std::unique_ptr<alarmSignal_t> > HoverRace::Util::Clock::alarms
private
Duration HoverRace::Util::Clock::lastRead
private
Duration HoverRace::Util::Clock::offset
private
Duration HoverRace::Util::Clock::start
private

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