diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-07-04 23:03:09 +1200 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-07-04 23:03:49 +1200 |
commit | 2eeae95c4fed369e3be6a2100bfd591db46e0a33 (patch) | |
tree | cc26a39b320412de881c72613c6871f485113696 /bedrock.js | |
parent | 99f2686e661b87c0625053d929af211bfcc95fdc (diff) | |
download | bedrock-js-2eeae95c4fed369e3be6a2100bfd591db46e0a33.zip |
Force a render if a frame takes longer than half a second to run
Diffstat (limited to 'bedrock.js')
-rw-r--r-- | bedrock.js | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -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); |