From 2eeae95c4fed369e3be6a2100bfd591db46e0a33 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Fri, 4 Jul 2025 23:03:09 +1200 Subject: Force a render if a frame takes longer than half a second to run --- bedrock.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'bedrock.js') diff --git a/bedrock.js b/bedrock.js index bdb4062..3db4372 100644 --- a/bedrock.js +++ b/bedrock.js @@ -1118,6 +1118,7 @@ function Bedrock(e) { this.paused = true; // true when program is paused for the user. this.asleep = false; // true when program is waiting for input. this.halted = false; // true when program has halted. + this.frameLag = 0; // time since runLoop started } // Reset the emulator and load in a new program. @@ -1194,6 +1195,7 @@ function Bedrock(e) { let image = new ImageData(scr.pixels, scr.width, scr.height); scr.ctx.putImageData(image, 0, 0, scr.dx0, scr.dy0, scr.dx1, scr.dy1); scr.unmark(); + this.frameLag = performance.now(); } } @@ -1212,12 +1214,16 @@ function Bedrock(e) { default: // NORMAL } this.update(); + // Force a render if the frame has been running for >500ms. + if (performance.now() - this.frameLag > 500) { + this.render(); } setTimeout(this.runLoop.bind(this), 0); } } } this.sleepLoop = () => { + this.frameLag = performance.now(); if (!this.halted) { if (!this.asleep) { setTimeout(this.runLoop.bind(this), 0); -- cgit v1.2.3-70-g09d2