From 785ddff7067d4bf6590c9ad53716a46b1406e3df Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Tue, 19 Dec 2017 12:53:12 -0800 Subject: [PATCH] Reverting screen optimization to use SetInterval and didChange --- sim/state/screen.ts | 13 ++++++++++--- sim/visuals/board.ts | 6 +++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sim/state/screen.ts b/sim/state/screen.ts index 342b0430..17810a6f 100644 --- a/sim/state/screen.ts +++ b/sim/state/screen.ts @@ -7,6 +7,7 @@ namespace pxsim { export class EV3ScreenState { + changed: boolean points: Uint8Array; constructor() { this.points = new Uint8Array(visuals.SCREEN_WIDTH * visuals.SCREEN_HEIGHT) @@ -23,13 +24,13 @@ namespace pxsim { setPixel(x: number, y: number, v: number) { this.applyMode(OFF(x, y), v) - runtime.queueDisplayUpdate(); + this.changed = true; } clear() { for (let i = 0; i < this.points.length; ++i) this.points[i] = 0; - runtime.queueDisplayUpdate(); + this.changed = true; } blitLineCore(x: number, y: number, w: number, buf: RefBuffer, mode: Draw, offset = 0) { @@ -58,7 +59,7 @@ namespace pxsim { } } - runtime.queueDisplayUpdate(); + this.changed = true; } clearLine(x: number, y: number, w: number) { @@ -72,6 +73,12 @@ namespace pxsim { off++ } } + + didChange() { + const res = this.changed; + this.changed = false; + return res; + } } } diff --git a/sim/visuals/board.ts b/sim/visuals/board.ts index 79be7b10..49bf13c4 100644 --- a/sim/visuals/board.ts +++ b/sim/visuals/board.ts @@ -136,6 +136,10 @@ namespace pxsim.visuals { this.board.updateSubscribers.push(() => this.updateState()); this.updateState(); } + let that = this; + window.setInterval(function(){ + that.updateScreen(); + }, 30); } public getView(): SVGAndSize { @@ -169,7 +173,6 @@ namespace pxsim.visuals { public updateState() { this.updateVisibleNodes(); - this.updateScreen(); } private updateVisibleNodes() { @@ -396,6 +399,7 @@ namespace pxsim.visuals { private updateScreen() { let state = ev3board().screenState; + if (!state.didChange()) return; const bBox = this.layoutView.getBrick().getScreenBBox(); if (!bBox || bBox.width == 0) return;