Skip to content

gdmp.time

Call What it does
now() milliseconds on this host’s clock (monotonic)
after(ms, fn) → id run fn once, ms from now
every(ms, fn) → id run fn every ms
cancel(id) → bool stop a timer
onTick(fn) fn({now, dt}) on every engine tick (the server: ~30 / s; a client: every game frame batch): now = now(), dt = milliseconds since the previous tick

The declarations from the GDMP types (namespace GDMP), comments included:

interface Time {
/** Milliseconds on this host's monotonic clock. */
now(): number;
after(ms: number, fn: () => void): TimerId;
every(ms: number, fn: () => void): TimerId;
cancel(id: TimerId): boolean;
/** On every engine tick (the server ~30 / s; a client every game frame batch): `now` = `gdmp.time.now()`,
* `dt` = milliseconds since the previous tick. */
onTick(fn: Callback<[tick: { readonly now: number; readonly dt: number }]>): void;
}