Skip to content

Commit 61a8efc

Browse files
committed
Added a reset time for counting slowly drawn frames.
1 parent d330af5 commit 61a8efc

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/app/svc/generic-view.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export enum ADDITIONALS {NONE, ALL_ASTEROIDS, ALL_COMETS, ALL}
4040
const FLICK_REJECTION_THRESHOLD = 250;
4141
const SLOW_DRAWING_THRESHOLD = 125;
4242
const MAX_SLOW_FRAMES = 3;
43+
const SLOW_FRAME_COUNT_RESET_TIME = 3000;
44+
const FULL_REDRAW_DELAY = 1500;
4345

4446
export interface DrawingContext {
4547
context: CanvasRenderingContext2D;
@@ -93,6 +95,7 @@ export abstract class GenericView implements AfterViewInit {
9395
protected lastMoveY = -1;
9496
protected lastDrawingContext: DrawingContext;
9597
protected slowFrameCount = 0;
98+
protected lastSlowFrameTime = 0;
9699
protected planetsToDraw: number[] = [];
97100
protected additional: ADDITIONALS | string = ADDITIONALS.NONE;
98101

@@ -135,7 +138,7 @@ export abstract class GenericView implements AfterViewInit {
135138

136139
this.debouncedFullRedraw = _.debounce(() => {
137140
this.draw(true);
138-
}, 1500);
141+
}, FULL_REDRAW_DELAY);
139142

140143
this.throttledResize = _.throttle(() => {
141144
this.doResize();
@@ -375,6 +378,9 @@ export abstract class GenericView implements AfterViewInit {
375378
if (!this.canvas || dc.w < 0 || dc.h < 0)
376379
return;
377380

381+
if (startTime > this.lastSlowFrameTime + SLOW_FRAME_COUNT_RESET_TIME)
382+
this.slowFrameCount = 0;
383+
378384
dc.fullDraw = (forceFullDraw || GenericView.printing || this.slowFrameCount < MAX_SLOW_FRAMES);
379385

380386
if (this.lastWidth !== dc.w || this.lastHeight !== dc.h) {
@@ -403,17 +409,23 @@ export abstract class GenericView implements AfterViewInit {
403409

404410
this.lastDrawingContext = dc;
405411

412+
const now = performance.now();
413+
406414
if (dc.fullDraw) {
407-
const fullDrawingTime = performance.now() - startTime;
415+
const fullDrawingTime = now - startTime;
408416

409417
if (forceFullDraw)
410418
this.slowFrameCount = 0;
411419

412-
if (fullDrawingTime > SLOW_DRAWING_THRESHOLD)
420+
if (fullDrawingTime > SLOW_DRAWING_THRESHOLD) {
413421
++this.slowFrameCount;
422+
this.lastSlowFrameTime = now;
423+
}
414424
}
415-
else
425+
else {
416426
this.debouncedFullRedraw();
427+
this.lastSlowFrameTime = now;
428+
}
417429
}
418430

419431
protected additionalDrawingSetup(dc: DrawingContext): void {

0 commit comments

Comments
 (0)