CoarseTimer

Implements a coarse timer, that checks the time periodically (e.g. on VSYNC), then calls the delegate if the time assigned to it has been lapsed. Is fast and can effectively test for multiple elements, but is inaccurate which can even fluctuate if tests are done on VSYNC intervals. This will make the duration longer in every case (up to 16.7ms on 60Hz displays), but this still should be accurate enough for many cases. In theory, calls for test can be done separate from VSYNC intervals by running it in its own thread, but that can cause potential race issues. Delegates take the jitter argument, which is the overshoot of the time. Can be suspended for game pausing, etc., while keeping time deltas mostly accurate. Multiple instances of this class can be used to create various effects from suspending the timer.

Constructors

this
this()

CTOR (empty)

Members

Aliases

TimerReceiver
alias TimerReceiver = void delegate(Duration jitter)
Undocumented in source.

Enums

StatusFlags
enum StatusFlags
Undocumented in source.

Functions

register
void register(TimerReceiver dg, Duration delta)

Registers an entry for the timer.

resumeTimer
void resumeTimer()

Resumes timer and shifts all entries by given time delta.

suspendTimer
void suspendTimer()

Suspends the timer and saves the current timestamp to calculate timeshift caused by suspension.

test
void test()

Tests the entries. If enough time has passed, then those entries will be called and deleted.

Structs

Entry
struct Entry

A timer entry.

Variables

status
BitFlags!StatusFlags status;

Contains various status flags.

timeSuspend
MonoTime timeSuspend;

Time when suspension happened.

timerList
SortedList!Entry timerList;

The list of timer entries.

timerRegs
Entry[] timerRegs;

Secondary timer list.

Meta