From bbb199c2a29378331befabed23271684b1481d5a Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Tue, 3 Mar 2026 00:31:47 +0800 Subject: feat(timer): improve high-FPS timing with high-resolution Windows clock --- Minecraft.World/system.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Minecraft.World/system.cpp') diff --git a/Minecraft.World/system.cpp b/Minecraft.World/system.cpp index 72727e20..cce04bdc 100644 --- a/Minecraft.World/system.cpp +++ b/Minecraft.World/system.cpp @@ -52,7 +52,22 @@ void System::arraycopy(arrayWithLength src, unsigned int srcPos, arrayWithL //The current value of the system timer, in nanoseconds. __int64 System::nanoTime() { +#if defined _WINDOWS64 || defined _XBOX || defined _WIN32 + static LARGE_INTEGER s_frequency = { 0 }; + if (s_frequency.QuadPart == 0) + { + QueryPerformanceFrequency(&s_frequency); + } + + LARGE_INTEGER counter; + QueryPerformanceCounter(&counter); + + // Using double to avoid 64-bit overflow during multiplication for long uptime + // Precision is sufficient for ~100 days of uptime. + return (__int64)((double)counter.QuadPart * 1000000000.0 / (double)s_frequency.QuadPart); +#else return GetTickCount() * 1000000LL; +#endif } //Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, -- cgit v1.2.3