readd seconds stuff

This commit is contained in:
Krzosa Karol
2025-01-05 10:23:41 +01:00
parent 489c8c413e
commit 67f654f72e
6 changed files with 55 additions and 22 deletions

View File

@@ -40,6 +40,20 @@ fn f64 w32_get_dpr(HWND window_handle) {
return result;
}
fn f64 w32_seconds_now(void) {
static int64_t counts_per_second;
if (counts_per_second == 0) {
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
counts_per_second = freq.QuadPart;
}
LARGE_INTEGER time;
QueryPerformanceCounter(&time);
f64 result = (f64)time.QuadPart / (f64)counts_per_second;
return result;
}
///////////////////////////////
// event processing
@@ -240,20 +254,6 @@ void w32_try_resizing_canvas(w32_canvas_t *canvas, HWND window_handle) {
}
}
fn f64 os_seconds_now(void) {
static int64_t counts_per_second;
if (counts_per_second == 0) {
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
counts_per_second = freq.QuadPart;
}
LARGE_INTEGER time;
QueryPerformanceCounter(&time);
f64 result = (f64)time.QuadPart / (f64)counts_per_second;
return result;
}
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
tcx.temp = ma_create(ma_default_reserve_size);
@@ -339,7 +339,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
refresh_rate = (f64)devmodew.dmDisplayFrequency;
}
f64 time_frame_start = os_seconds_now();
f64 time_frame_start = w32_seconds_now();
f64 time_delta = 1.0 / refresh_rate;
f64 time_total = 0.0;
f64 time_update = 0.0;
@@ -373,7 +373,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
///////////////////////////////
// end of frame timings
f64 time_update_partial = os_seconds_now() - time_frame_start;
f64 time_update_partial = w32_seconds_now() - time_frame_start;
time_update = time_update_partial;
if (time_update < time_delta) {
consecutive_missed_frames = 0;
@@ -393,9 +393,9 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
// busy loop if we dont have good scheduling
// or we woke up early
time_update = os_seconds_now() - time_frame_start;
time_update = w32_seconds_now() - time_frame_start;
while (time_update < time_delta) {
time_update = os_seconds_now() - time_frame_start;
time_update = w32_seconds_now() - time_frame_start;
}
} else {
missed_frames += 1;
@@ -409,7 +409,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
// probably want the locked frame rate and total should reflect that, so choosing
// time_delta seems the correct choice but not really sure what is correct.
time_total += time_delta;
time_frame_start = os_seconds_now();
time_frame_start = w32_seconds_now();
}
return 0;