goldensun_html5 icon indicating copy to clipboard operation
goldensun_html5 copied to clipboard

Limit to 60 fps in deploy

Open jjppof opened this issue 3 years ago • 1 comments

When deploying the engine, limit its fps to 60. The root of this problem are the monitors with update frequency bigger than 100Hz. requestAnimationFrame updates in sync with monitor frequency.

Found these chrome flags in google, but it's not working (these ones could be used with Electron): --disable-frame-rate-limit --disable-gpu-vsync --max-gum-fps="60" --limit-fps=60

Fixing the engine to work with any fps is also an option 😁.

Related issues: #331 #391

jjppof avatar Oct 09 '21 20:10 jjppof

Possible candidate (reference):

window.originalRequestAnimationFrame = window.requestAnimationFrame;
var fps_interval = 1000 / 60;
var then = window.performance.now();
var raf_callback;

window.raf_controller = function() {
    now = window.performance.now();
    elapsed = now - then;
    if (elapsed > fps_interval) {
        then = now - (elapsed % fps_interval);
        window.originalRequestAnimationFrame(raf_callback);
    } else {
        window.originalRequestAnimationFrame(window.raf_controller);
    }
}

window.requestAnimationFrame = function(callback) {
    raf_callback = callback;
    window.raf_controller();
}

The problem with the above is that it brings a lot of jitters, mainly when fps is higher.

Not sure whether setting the below has the same effect. I believe not.

game.forceSingleUpdate = false;
game.time.desiredFps = 60; //need to remove code section that changes it in GoldenSun.update function

jjppof avatar Apr 27 '22 16:04 jjppof

It seems --limit-fps was introduced in chromium 61 and removed after chromium 69. I'm using last electron that used chromium 69, which is 4.2.12 (yeah, a very old one). It docs.

jjppof avatar Oct 10 '22 04:10 jjppof

56c470fc59fa8139b192b4c706dc5adefea1fd44 a4a5253c734bf43ba8e6ca4f7b41cb80cada504b

jjppof avatar Oct 10 '22 16:10 jjppof