libecs-cpp 2.1.0
Entity Component System library in C++
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ecs::Timing Class Reference

A repeating schedule: says when the next update is due. More...

#include <Timing.hpp>

Public Member Functions

 Timing (std::chrono::microseconds interval=DEFAULT_INTERVAL)
 Creates a schedule with the given interval, first due one full interval from now.
 
 Timing (uint32_t frequency)
 Creates a schedule from a bare number, which is the interval in microseconds.
 
bool ShouldUpdate (std::chrono::microseconds now)
 Says whether an update is due at the given instant and, when it is, moves the schedule on.
 
bool ShouldUpdate ()
 Says whether an update is due now by the real steady clock and, when it is, moves the schedule on.
 
void Restart (std::chrono::microseconds now)
 Starts a new schedule at the given instant: the first update is due one full interval later.
 
void SetInterval (std::chrono::microseconds interval)
 Changes the interval.
 
std::chrono::microseconds GetInterval () const
 Returns the interval between updates.
 
void SetFrequency (uint32_t frequency)
 Changes the interval to a bare number of microseconds, without a range check.
 
uint32_t GetFrequency () const
 Returns the interval in microseconds, or 4 294 967 295 if it is longer than that number can hold.
 

Detailed Description

A repeating schedule: says when the next update is due.

The interval is the time between updates, in microseconds. A larger interval means updates happen less often. An interval of zero means due on every call. The longest interval is MAX_INTERVAL; anything below zero or above it is rejected with std::runtime_error.

A new schedule is first due one full interval after it was created (or after Restart()). When a call finds that one or more whole intervals have passed, the schedule moves forward by exactly those whole intervals, so the average rate stays exact however unevenly it is asked. If more than MAX_CATCHUP whole intervals have passed, which happens after a long stall, it fires once and starts counting again from that moment instead of catching up.

Thread: container thread only.

Constructor & Destructor Documentation

◆ Timing() [1/2]

ecs::Timing::Timing ( std::chrono::microseconds  interval = DEFAULT_INTERVAL)
inline

Creates a schedule with the given interval, first due one full interval from now.

Throws std::runtime_error for an interval below zero or above MAX_INTERVAL.

◆ Timing() [2/2]

ecs::Timing::Timing ( uint32_t  frequency)
inline

Creates a schedule from a bare number, which is the interval in microseconds.

Deprecated since 1.8.0; no removal is scheduled, and a removal will be announced in the release notes first.

Member Function Documentation

◆ GetFrequency()

uint32_t ecs::Timing::GetFrequency ( ) const
inline

Returns the interval in microseconds, or 4 294 967 295 if it is longer than that number can hold.

Use GetInterval() instead. Deprecated since 1.8.0; no removal is scheduled, and a removal will be announced in the release notes first.

◆ GetInterval()

std::chrono::microseconds ecs::Timing::GetInterval ( ) const
inline

Returns the interval between updates.

◆ Restart()

void ecs::Timing::Restart ( std::chrono::microseconds  now)
inline

Starts a new schedule at the given instant: the first update is due one full interval later.

◆ SetFrequency()

void ecs::Timing::SetFrequency ( uint32_t  frequency)
inline

Changes the interval to a bare number of microseconds, without a range check.

Deprecated since 1.8.0; no removal is scheduled, and a removal will be announced in the release notes first.

◆ SetInterval()

void ecs::Timing::SetInterval ( std::chrono::microseconds  interval)
inline

Changes the interval.

The next due time carries on from the last one, so nothing is skipped and nothing bursts. Throws std::runtime_error, changing nothing, outside 0 to MAX_INTERVAL.

◆ ShouldUpdate() [1/2]

bool ecs::Timing::ShouldUpdate ( )
inline

Says whether an update is due now by the real steady clock and, when it is, moves the schedule on.

◆ ShouldUpdate() [2/2]

bool ecs::Timing::ShouldUpdate ( std::chrono::microseconds  now)
inline

Says whether an update is due at the given instant and, when it is, moves the schedule on.

The instant comes from the clock the caller uses; an instant earlier than the last one counts as no time having passed. An interval of zero is always due and leaves the schedule alone.


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