A concise framerate limiter?

Is there a proper way of limiting the framerate? I was thinking of writing my own solid implementation on top of engine.runRenderLoop then submitting a pull request to the official repo. The API may look like this:

let engine = new BABYLON.Engine(canvas);
let scene = new BABYLON.Scene(engine);

let maxFramerate = 24;
engine.runRenderLoop(() => scene.render(), maxFramerate);

engine.setMaxFramerate(60);
engine.getMaxFramerate();

There is targetFrameRate getter/setter - SceneOptimizer | Babylon.js Documentation

Also, extremely interesting article - How we improved our 3D web viewer performance

From the old forum - Limit frames per second - Questions & Answers - HTML5 Game Devs Forum
And even special limitLoop.js - Limit the frame-rate being targeted with requestAnimationFrame · GitHub

@labris I find the SceneOptimizer does not kick in very often when set at 30 FPS, 1000ms check rate. Even when users on lower end machines are getting slide-show experiences sometimes. Do you have any tips for what I could be doing wrong with it ?

Try using a check rate of 250ms.

As far as I know SceneOptimizer will try to make desired FPS but it doesn’t mean that every user will get it, especially at lower end.

Try using a check rate of 250ms.

I will give that a shot ! Edit: Wow 250ms is working way more reliably, thank you for helping me in your own thread :rocket:

As far as I know SceneOptimizer will try to make desired FPS but it doesn’t mean that every user will get it, especially at lower end.

That would be magical indeed if it could just fix anyone :slight_smile: :pray: It’s 50/50 on laggy systems wether the first/subsequent optimizations gets applied. I went about setting it up the way the docs outline with custom functions for different priority levels, including some logging in there as well.

1 Like