Spinlocking does not feel good and std::this_thread::sleep_for() is too inaccurate
void spin_for_target_fps()
{
static auto curr_time = std::chrono::high_resolution_clock::now();
static auto new_time = std::chrono::high_resolution_clock::now();
u64 target_dt_ns = 1'000'000'000 / win.get_spec().target_fps;
u64 curr_dt_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(new_time - curr_time).count();
{
KAWA_PROFILE("target fps spinning");
while (curr_dt_ns < target_dt_ns)
{
new_time = std::chrono::high_resolution_clock::now();
curr_dt_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(new_time - curr_time).count();
}
}
curr_time = new_time;
new_time = std::chrono::high_resolution_clock::now();
}