warn if tick or render takes to long

This commit is contained in:
Evan
2024-12-21 20:15:52 -08:00
parent 361b1f7d6c
commit 65ff9cfe19
2 changed files with 11 additions and 0 deletions
+5
View File
@@ -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)
+6
View File
@@ -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() {