Reverting screen optimization to use SetInterval and didChange
This commit is contained in:
		@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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<SVGSVGElement> {
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user