diff --git a/src/sys_win32.c b/src/sys_win32.c index c943f581..7386652a 100644 --- a/src/sys_win32.c +++ b/src/sys_win32.c @@ -98,9 +98,9 @@ struct win32_window { GLOBAL struct { SYSTEM_INFO info; - i64 timer_frequency_s; - i64 timer_frequency_ns; - i64 timer_start_ns; + i64 timer_start_qpc; + i64 timer_qpc_frequency; + i64 ns_per_qpc; i32 scheduler_period_ms; DWORD thread_tls_index; u32 main_thread_id; @@ -136,20 +136,20 @@ GLOBAL struct { * Events * ========================== */ -/* https://git.rfleury.com/community/root_basic/src/commit/9b49fcd24e0c3f875b7c213e81a219bf8544bddb/code/os/gfx/win32/os_gfx_win32.c#L193 */ INTERNAL void win32_init_vk_btn_table(void) { MEMZERO_ARRAY(G.vk_btn_table); - for (u32 i = 'A', j = SYS_BTN_A; i <= 'Z'; i += 1, j += 1) { + for (u32 i = 'A', j = SYS_BTN_A; i <= 'Z'; ++i, ++j) { G.vk_btn_table[i] = (enum sys_btn)j; } - for (u32 i = '0', j = SYS_BTN_0; i <= '9'; i += 1, j += 1) { + for (u32 i = '0', j = SYS_BTN_0; i <= '9'; ++i, ++j) { G.vk_btn_table[i] = (enum sys_btn)j; } - for (u32 i = VK_F1, j = SYS_BTN_F1; i <= VK_F24; i += 1, j += 1) { + for (u32 i = VK_F1, j = SYS_BTN_F1; i <= VK_F24; ++i, ++j) { G.vk_btn_table[i] = (enum sys_btn)j; } + G.vk_btn_table[VK_ESCAPE] = SYS_BTN_ESC; G.vk_btn_table[VK_OEM_3] = SYS_BTN_GRAVE_ACCENT; G.vk_btn_table[VK_OEM_MINUS] = SYS_BTN_MINUS; @@ -248,7 +248,7 @@ i64 sys_time_ns(void) { LARGE_INTEGER qpc; QueryPerformanceCounter(&qpc); - i64 res = (qpc.QuadPart * G.timer_frequency_ns) - G.timer_start_ns; + i64 res = (qpc.QuadPart - G.timer_start_qpc) * G.ns_per_qpc; return res; } @@ -1931,7 +1931,7 @@ INTERNAL void win32_precise_sleep_timer(f64 seconds, HANDLE timer) /* TODO: Does the high frequency timer even require setting / scaling of * timeBeginPeriod/scheduler_period_ms? There isn't much documentation. */ - i64 qpc_per_second = G.timer_frequency_s; + i64 qpc_per_second = G.timer_qpc_frequency; i32 scheduler_period_ms = G.scheduler_period_ms; LARGE_INTEGER qpc; @@ -1972,7 +1972,7 @@ INTERNAL void win32_precise_sleep_timer(f64 seconds, HANDLE timer) INTERNAL void win32_precise_sleep_legacy(f64 seconds) { __prof; - i64 qpc_per_second = G.timer_frequency_s; + i64 qpc_per_second = G.timer_qpc_frequency; i32 scheduler_period_ms = G.scheduler_period_ms; LARGE_INTEGER qpc; @@ -2063,12 +2063,12 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance, LARGE_INTEGER qpf; QueryPerformanceFrequency(&qpf); - G.timer_frequency_s = qpf.QuadPart; - G.timer_frequency_ns = 1000000000 / qpf.QuadPart; + G.timer_qpc_frequency = qpf.QuadPart; + G.ns_per_qpc = 1000000000 / qpf.QuadPart; LARGE_INTEGER qpc; QueryPerformanceCounter(&qpc); - G.timer_start_ns = qpc.QuadPart * G.timer_frequency_ns; + G.timer_start_qpc = qpc.QuadPart; TIMECAPS caps; timeGetDevCaps(&caps, sizeof(caps));