From 65ff9cfe194d829b8da3e4d88f2809f368265b9a Mon Sep 17 00:00:00 2001 From: Evan Date: Sat, 21 Dec 2024 20:15:52 -0800 Subject: [PATCH] warn if tick or render takes to long --- src/client/GameRunner.ts | 5 +++++ src/client/graphics/GameRenderer.ts | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/client/GameRunner.ts b/src/client/GameRunner.ts index e739fb031..512ddffde 100644 --- a/src/client/GameRunner.ts +++ b/src/client/GameRunner.ts @@ -180,7 +180,12 @@ export class GameRunner { this.isProcessingTurn = true this.gs.addExecution(...this.executor.createExecs(this.turns[this.currTurn])) try { + const start = performance.now() this.gs.executeNextTick() + const duration = performance.now() - start + if (duration > 100) { + console.warn(`tick ${this.gs.ticks() - 1} took ${duration}ms to execute`) + } } catch (error) { const errorText = `Error: ${error.message}\nStack: ${error.stack}`; consolex.error(errorText) diff --git a/src/client/graphics/GameRenderer.ts b/src/client/graphics/GameRenderer.ts index e3b0d1f18..513ee2c48 100644 --- a/src/client/graphics/GameRenderer.ts +++ b/src/client/graphics/GameRenderer.ts @@ -116,6 +116,7 @@ export class GameRenderer { } renderGame() { + const start = performance.now() // Set background this.context.fillStyle = this.game.config().theme().backgroundColor().toHex(); this.context.fillRect(0, 0, this.canvas.width, this.canvas.height); @@ -140,6 +141,11 @@ export class GameRenderer { }) requestAnimationFrame(() => this.renderGame()); + + const duration = performance.now() - start + if (duration > 10) { + console.warn(`tick ${this.game.ticks()} took ${duration}ms to render frame`) + } } tick() {