Time helpers module


Helper methods for retrieving the current time in many forms under different precisions. It also offers a simple to use timer library.


struct zpl_timer
Timer data structure.


using zpl_timer_cb = void(*)(void*data)
using zpl_timer = struct zpl_timer
Timer data structure.
using zpl_timer_pool = zpl_timer*


auto zpl_rdtsc(void) -> u64
Return CPU timestamp.
auto zpl_time_now(void) -> f64
Return relative time since the application start.
auto zpl_utc_time_now(void) -> f64
Return time since 1601-01-01 UTC.
auto zpl_sleep_ms(u32 ms) -> void
Sleep for specified number of milliseconds.
auto zpl_timer_add(zpl_timer_pool pool) -> zpl_timer*
Add new timer to pool and return it.
auto zpl_timer_update(zpl_timer_pool pool) -> void
Perform timer pool update.
auto zpl_timer_set(zpl_timer* timer, f64 duration, i32 count, zpl_timer_cb callback) -> void
Set up timer.
auto zpl_timer_start(zpl_timer* timer, f64 delay_start) -> void
Start timer with specified delay.
auto zpl_timer_stop(zpl_timer* timer) -> void
Stop timer and prevent it from triggering.


#define zpl_timer_init(pool, allocator)
Initialize timer pool.

Function documentation

void zpl_timer_update(zpl_timer_pool pool)

Perform timer pool update.

Traverse over all timers and update them accordingly. Should be called by Main Thread in a tight loop.

void zpl_timer_set(zpl_timer* timer, f64 duration, i32 count, zpl_timer_cb callback)

Set up timer.

duration How long/often to fire a timer.
count How many times we fire a timer. Use -1 for infinity.
callback A method to execute once a timer triggers.

Set up timer with specific options.