diff options
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); |