Improve frame synchronization
theyareonit opened this issue ยท 6 comments
Request Description
The function RenderSystem.limitDisplayFPS() in vanilla Minecraft currently looks something like this:
public static void limitDisplayFPS(int fps) {
double target = lastDrawTime + 1.0 / (double)fps;
double now;
for (now = GLFW.glfwGetTime(); now < target; now = GLFW.glfwGetTime()) {
GLFW.glfwWaitEventsTimeout(target - now);
}
lastDrawTime = now;
}
However, this is a flawed implementation. For example, if you set 240FPS as your cap, it will result in an actual frame limit of around ~235FPS, due to the fact that glfwWaitEventsTimeout() and glfwGetTime() do not return instantly, resulting in the now
timestamp differing from the target
timestamp by enough to cause significant desync.
The solution is simply to replace the line lastDrawTime = now;
with lastDrawTime = target;
, which results in a smoother experience when using capped FPS. However, this leads to an incorrect frame limit for the first few seconds after joining a server or tabbing into the game, so some more work may be needed.
That's curious. Since you appear to have figured this out already, we would not be opposed to a pull request to address this problem. Maybe we can also look into further improvements since the original Minecraft code seems rather naive.
Alright. I found some places where I can improve it (and fixed the issue of getting the wrong FPS value after tabbing in), so I'll try to make a PR soon.
If I understand correctly, this bug is quite useful for me. My laptop supports a screen refresh rate of up to 144 Hz, but in Minecraft I can only use a 150 FPS limit to make the game smooth. Due to this effect, I get โ144 FPS on average.
If I understand correctly, this bug is quite useful for me. My laptop supports a screen refresh rate of up to 144 Hz, but in Minecraft I can only use a 150 FPS limit to make the game smooth. Due to this effect, I get โ144 FPS on average.
I think that just means some mod needs to allow the user to input any FPS value instead, lol.