aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaoge_cmd <3523206925@qq.com>2026-03-03 00:31:47 +0800
committerdaoge_cmd <3523206925@qq.com>2026-03-03 00:31:47 +0800
commitbbb199c2a29378331befabed23271684b1481d5a (patch)
treeaaa247e090680b01b378482adbb0ae894c23dd69
parenta4691f58e8e4d51908199135a226efc9aab85d6b (diff)
feat(timer): improve high-FPS timing with high-resolution Windows clock
-rw-r--r--Minecraft.Client/Timer.cpp9
-rw-r--r--Minecraft.World/system.cpp15
-rw-r--r--README.md1
3 files changed, 21 insertions, 4 deletions
diff --git a/Minecraft.Client/Timer.cpp b/Minecraft.Client/Timer.cpp
index b451c034..15a2c2f1 100644
--- a/Minecraft.Client/Timer.cpp
+++ b/Minecraft.Client/Timer.cpp
@@ -22,8 +22,9 @@ void Timer::advanceTime()
{
__int64 nowMs = System::currentTimeMillis();
__int64 passedMs = nowMs - lastMs;
- __int64 msSysTime = System::nanoTime() / 1000000;
- double now = msSysTime / 1000.0;
+
+ // 4J - Use high-resolution timer for 'now' in seconds
+ double now = System::nanoTime() / 1000000000.0;
if (passedMs > 1000)
@@ -39,6 +40,7 @@ void Timer::advanceTime()
accumMs += passedMs;
if (accumMs > 1000)
{
+ __int64 msSysTime = (__int64)(now * 1000.0);
__int64 passedMsSysTime = msSysTime - lastMsSysTime;
double adjustTimeT = accumMs / (double) passedMsSysTime;
@@ -49,7 +51,7 @@ void Timer::advanceTime()
}
if (accumMs < 0)
{
- lastMsSysTime = msSysTime;
+ lastMsSysTime = (__int64)(now * 1000.0);
}
}
lastMs = nowMs;
@@ -68,7 +70,6 @@ void Timer::advanceTime()
if (ticks > MAX_TICKS_PER_UPDATE) ticks = MAX_TICKS_PER_UPDATE;
a = passedTime;
-
}
void Timer::advanceTimeQuickly()
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<int> 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,
diff --git a/README.md b/README.md
index be3e745b..f32b11fc 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,7 @@ This project contains the source code of Minecraft Legacy Console Edition v1.3.0
- Added support for keyboard and mouse input
- Added fullscreen mode support (toggle using F11)
- Disabled V-Sync for better performance
+- Added a high-resolution timer path on Windows for smoother high-FPS gameplay timing
- Device's screen resolution will be used as the game resolution instead of using a fixed resolution (1920x1080)
## Controls (Keyboard & Mouse)