Kode / Kha

Ultra-portable, high performance, open source multimedia framework.
http://kha.tech
zlib License
1.49k stars 174 forks source link

[HTML5] Attempt to estimate device refresh rate at startup #1279

Closed zshoals closed 3 years ago

zshoals commented 3 years ago

I'm nooby so maybe this isn't a viable approach (or perhaps it's too naive), but I figured I would try adding this feature rather than not try. Sorry if it doesn't work out.

HTML5 does not have a way to just get the device's refresh rate through some query. It can only be estimated at this time.

This code briefly collects the frametime results for successive requestAnimationFrame calls, and tries its best to make an estimate of the monitor's refresh rate before animate() begins and before the System.start callback executes. This test is run at this point so that (hopefully) nothing else important or computation intensive is happening and we get mostly accurate results.

Caveats:

RobDangerous commented 3 years ago

Oooh, super cool! Will first fix #1277 so this doesn't confuse me, then merge your pull request, then add the option to run the test while the application is already running (should work fine while on a title screen for example).