Open
Description
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.