FPS in C
.c
internal void wl_init(void)
{
_wl_core_state.frame_prev_time = os_now_us();
}
internal void wl_update_events(void)
{
// ak: update FPS
_wl_core_state.frame_count++;
uint64_t frame_current_time = os_now_us();
uint64_t delta = frame_current_time - _wl_core_state.frame_prev_time;
if (delta >= Million(1))
{
_wl_core_state.fps = _wl_core_state.frame_count;
_wl_core_state.frame_count = 0;
_wl_core_state.frame_prev_time = frame_current_time;
}
}
internal uint32_t wl_get_fps(void)
{
return _wl_core_state.fps;
}
internal void wl_set_fps(uint32_t fps)
{
os_sleep_ms(Million(1)/fps);
}