summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-07-04 23:03:09 +1200
committerBen Bridle <ben@derelict.engineering>2025-07-04 23:03:49 +1200
commit2eeae95c4fed369e3be6a2100bfd591db46e0a33 (patch)
treecc26a39b320412de881c72613c6871f485113696
parent99f2686e661b87c0625053d929af211bfcc95fdc (diff)
downloadbedrock-js-2eeae95c4fed369e3be6a2100bfd591db46e0a33.zip
Force a render if a frame takes longer than half a second to run
-rw-r--r--bedrock.js6
1 files changed, 6 insertions, 0 deletions
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);