[PATCH] Uxn5: fix uxn screen evaluating too fast on high refresh rate devices
Export this patch
---
src/app.js | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/app.js b/src/app.js
index 216bff7..d741749 100644
--- a/src/app.js
+++ b/src/app.js
@@ -15,6 +15,9 @@ const emulator = new Emu()
const share = new ShareView(document.getElementById("share"));
+var frametime = 0;
+const TARGET_FPS = 60;
+
emulator.init().then(() => {
emulator.console.write_el = document.getElementById("console_std")
emulator.console.error_el = document.getElementById("console_err")
@@ -42,7 +45,15 @@ emulator.init().then(() => {
// Animation callback
function step() {
- emulator.screen_callback();
+
+ var current = performance.now();
+ var delta = current - frametime;
+
+ if (delta > 1000 / TARGET_FPS) {
+ emulator.screen_callback();
+ frametime = current;
+ }
+
window.requestAnimationFrame(step)
}
--
2.42.0