HoverRace
2.0
|
A game clock that manages the current time in the simulation. More...
#include <Clock.h>
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 Duration & | GetTime () const noexcept |
Retrieve the time of the last call to Advance(). More... | |
Clock & | operator= (const Clock &)=delete |
Clock & | operator= (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 |
A game clock that manages the current time in the simulation.
using HoverRace::Util::Clock::alarmSignal_t = boost::signals2::signal<void()> |
HoverRace::Util::Clock::Clock | ( | ) |
Constructor.
The initial simulation time will be zero.
HoverRace::Util::Clock::Clock | ( | const Duration & | init | ) |
Constructor.
init | The initial simulation time. |
|
delete |
|
default |
|
inlinevirtual |
Duration HoverRace::Util::Clock::Advance | ( | ) |
Advance the clock to the current time.
|
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.
duration | The clock timestamp. |
fn | The function to invoke. |
|
inlinenoexcept |
Remove all alarms.
|
inline |
|
inline |
|
inlinenoexcept |
Retrieve the time of the last call to Advance().
|
noexcept |
|
private |
|
private |
|
private |
|
private |