From 939761fc76cfb7b084a1ab38c560fbfbda87acdd Mon Sep 17 00:00:00 2001 From: Evan Date: Thu, 12 Dec 2024 20:31:08 -0800 Subject: [PATCH] bugfix: when checking last tile update in calculate clusters and name layer --- TODO.txt | 4 +-- src/client/graphics/layers/NameLayer.ts | 34 +++++++++++++------------ src/core/configuration/DevConfig.ts | 4 +-- src/core/execution/PlayerExecution.ts | 4 +-- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/TODO.txt b/TODO.txt index 5637c09ad..c16cb6fb1 100644 --- a/TODO.txt +++ b/TODO.txt @@ -234,12 +234,12 @@ * bug: transport display event when it lands DONE 12/11/2024 * have crash print stacktrace DONE 12/11/2024 * bug: name not updating location in spawn phase -* allow longer names and allow them to be displayed in the Rank UI not be cut * make boats work on oceania +* add panama canal NA +* allow longer names and allow them to be displayed in the Rank UI not be cut * make boats work on lakes * record game winner * record player ip in bigquery -* add panama canal NA * repaint canvas after tab away to prevent blank screen * on mobile can't click away from build menu * replay stored games diff --git a/src/client/graphics/layers/NameLayer.ts b/src/client/graphics/layers/NameLayer.ts index f9ec68216..3873a2043 100644 --- a/src/client/graphics/layers/NameLayer.ts +++ b/src/client/graphics/layers/NameLayer.ts @@ -1,4 +1,4 @@ -import { AllPlayers, Cell, Game, Player, PlayerType } from "../../../core/game/Game" +import { AllPlayers, Cell, Game, Player, PlayerType, Tick } from "../../../core/game/Game" import { PseudoRandom } from "../../../core/PseudoRandom" import { calculateBoundingBox } from "../../../core/Util" import { Theme } from "../../../core/configuration/Config" @@ -17,8 +17,8 @@ class RenderInfo { public isVisible = true constructor( public player: Player, - public lastRenderCalc: number, - public lastBoundingCalculated: number, + public lastRenderCalcTick: Tick, + public lastBoundingCalculatedTick: Tick, public boundingBox: { min: Cell, max: Cell }, public location: Cell, public fontSize: number @@ -87,21 +87,20 @@ export class NameLayer implements Layer { } } } - const tickRefreshRate = Math.floor(this.refreshRate / 100) // 10 ticks + const currTick = this.game.ticks() + const recalcRate = this.game.inSpawnPhase() ? 2 : 10 for (const render of this.renders) { - const shouldRecalc = render.boundingBox == null || this.game.ticks() - render.player.lastTileChange() < tickRefreshRate - const now = Date.now() - if (now - render.lastBoundingCalculated > this.refreshRate) { - render.lastBoundingCalculated = now - if (shouldRecalc) { - render.boundingBox = calculateBoundingBox(render.player.borderTiles()); - } + const territoryUpdated = render.boundingBox == null || render.player.lastTileChange() > render.lastBoundingCalculatedTick + if (!territoryUpdated) { + continue } - if (render.isVisible && now - render.lastRenderCalc > this.refreshRate) { - render.lastRenderCalc = Date.now() + this.rand.nextInt(0, 100) - if (shouldRecalc) { - this.calculateRenderInfo(render) - } + if (currTick - render.lastBoundingCalculatedTick > recalcRate) { + render.lastBoundingCalculatedTick = currTick + render.boundingBox = calculateBoundingBox(render.player.borderTiles()); + } + if (render.isVisible && currTick - render.lastRenderCalcTick > recalcRate) { + render.lastRenderCalcTick = currTick + this.calculateRenderInfo(render) } } } @@ -117,6 +116,9 @@ export class NameLayer implements Layer { } isVisible(render: RenderInfo, min: Cell, max: Cell): boolean { + if (render.boundingBox == null) { + return false + } const ratio = (max.x - min.x) / Math.max(20, (render.boundingBox.max.x - render.boundingBox.min.x)) if (render.player.type() == PlayerType.Bot) { if (ratio > 35) { diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index 5ef7f905f..c76dcf429 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -13,8 +13,8 @@ export const devConfig = new class extends DefaultConfig { return 95 } numSpawnPhaseTurns(gameType: GameType): number { - // return 40 - return 1000 + return 40 + // return 100 } gameCreationRate(): number { return 10 * 1000 diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index 4f091a8ba..c86f7942c 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -65,8 +65,8 @@ export class PlayerExecution implements Execution { if (ticks - this.lastCalc > this.ticksPerClusterCalc) { - this.lastCalc = ticks - if (ticks - this.player.lastTileChange() < this.ticksPerClusterCalc) { + if (this.player.lastTileChange() > this.lastCalc) { + this.lastCalc = ticks const start = performance.now() this.removeClusters() const end = performance.now()