Sodium Reloaded (Unofficial)

Sodium Reloaded (Unofficial)

0 Downloads

Improve frame synchronization

theyareonit opened this issue ยท 6 comments

commented

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.

commented

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.

commented

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.

commented

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.

commented

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.

commented

If I understand correctly, this bug is quite useful for me.

commented

Yeah, so true. Just hope that one day modern screen formats support in Minecraft will be better.