Limit screen updates to once every 30ms and only if needed.
This commit is contained in:
parent
8215e8446a
commit
5ea8048f0c
@ -2,6 +2,7 @@
|
|||||||
namespace pxsim {
|
namespace pxsim {
|
||||||
|
|
||||||
export class EV3ScreenState {
|
export class EV3ScreenState {
|
||||||
|
shouldUpdate: boolean;
|
||||||
points: {[x: number]: {[y: number]: number}};
|
points: {[x: number]: {[y: number]: number}};
|
||||||
constructor() {
|
constructor() {
|
||||||
this.points = {};
|
this.points = {};
|
||||||
@ -14,6 +15,7 @@ namespace pxsim {
|
|||||||
const xPoints = this.points[x]
|
const xPoints = this.points[x]
|
||||||
if (!xPoints) this.points[x] = {};
|
if (!xPoints) this.points[x] = {};
|
||||||
this.points[x][y] = v;
|
this.points[x][y] = v;
|
||||||
|
this.shouldUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -24,7 +26,6 @@ namespace pxsim.screen {
|
|||||||
export function _setPixel(x: number, y: number, mode: Draw) {
|
export function _setPixel(x: number, y: number, mode: Draw) {
|
||||||
const screenState = (board() as DalBoard).screenState;
|
const screenState = (board() as DalBoard).screenState;
|
||||||
screenState.setPixel(x, y, mode);
|
screenState.setPixel(x, y, mode);
|
||||||
runtime.queueDisplayUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,6 +284,11 @@ namespace pxsim.visuals {
|
|||||||
this.updateState();
|
this.updateState();
|
||||||
this.attachEvents();
|
this.attachEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let board = this;
|
||||||
|
window.setInterval(function(){
|
||||||
|
board.updateScreen();
|
||||||
|
}, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getView(): SVGAndSize<SVGSVGElement> {
|
public getView(): SVGAndSize<SVGSVGElement> {
|
||||||
@ -459,6 +464,9 @@ namespace pxsim.visuals {
|
|||||||
let state = this.board;
|
let state = this.board;
|
||||||
if (!state || !state.screenState) return;
|
if (!state || !state.screenState) return;
|
||||||
|
|
||||||
|
if (!state.screenState.shouldUpdate) return;
|
||||||
|
state.screenState.shouldUpdate = false;
|
||||||
|
|
||||||
this.screenCanvasData = this.screenCanvasCtx.getImageData(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
this.screenCanvasData = this.screenCanvasCtx.getImageData(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
|
|
||||||
Object.keys(state.screenState.points).forEach(xStr => {
|
Object.keys(state.screenState.points).forEach(xStr => {
|
||||||
|
Loading…
Reference in New Issue
Block a user