diff --git a/src/client/graphics/NameBoxCalculator.ts b/src/client/graphics/NameBoxCalculator.ts index a79cb0d58..ce1de94e3 100644 --- a/src/client/graphics/NameBoxCalculator.ts +++ b/src/client/graphics/NameBoxCalculator.ts @@ -1,4 +1,4 @@ -import { Game, Player, Cell, NameViewData } from '../../core/game/Game'; +import { Game, Player, Cell, NameViewData, MutablePlayer } from '../../core/game/Game'; import { calculateBoundingBox, within } from '../../core/Util'; export interface Point { @@ -15,12 +15,32 @@ export interface Rectangle { -export function placeName(game: Game, player: Player): NameViewData { - const boundingBox = calculateBoundingBox(game, player.borderTiles()); +export function placeName(game: Game, player: MutablePlayer): NameViewData { + const boundingBox = player.largestClusterBoundingBox ?? calculateBoundingBox(game, player.borderTiles()); - const rawScalingFactor = (boundingBox.max.x - boundingBox.min.x) / 100 - const scalingFactor = within(Math.floor(rawScalingFactor), 1, 1000) + let scalingFactor = 1 + const width = boundingBox.max.x - boundingBox.min.x + const height = boundingBox.max.y - boundingBox.min.y + const size = Math.min(width, height) + if (size < 25) { + scalingFactor = 1 + } else if (size < 50) { + scalingFactor = 2 + } else if (size < 100) { + scalingFactor = 4 + } else if (size < 250) { + scalingFactor = 8 + } else if (size < 500) { + scalingFactor = 16 + } else { + scalingFactor = 32 + } + + console.log(`for player ${player.name()}, got scaling factor ${scalingFactor}}`) + + // const rawScalingFactor = (boundingBox.max.x - boundingBox.min.x) / 1000 + // const scalingFactor = within(Math.floor(rawScalingFactor), .1, 1) const grid = createGrid(game, player, boundingBox, scalingFactor); const largestRectangle = findLargestInscribedRectangle(grid); diff --git a/src/core/GameRunner.ts b/src/core/GameRunner.ts index eb261c1f5..e79357265 100644 --- a/src/core/GameRunner.ts +++ b/src/core/GameRunner.ts @@ -8,7 +8,7 @@ import { Cell, DisplayMessageUpdate, Game, GameUpdateType, MessageType, MutableG import { createGame } from "./game/GameImpl"; import { loadTerrainMap as loadGameMap } from "./game/TerrainMapLoader"; import { GameConfig, Turn } from "./Schemas"; -import { GameUpdateViewData} from "./GameView"; +import { GameUpdateViewData } from "./GameView"; import { andFN, manhattanDistFN, TileRef } from "./game/GameMap"; import { targetTransportTile } from "./Util"; @@ -62,8 +62,8 @@ export class GameRunner { this.game.addExecution(...this.execManager.createExecs(this.turns[this.currTurn])) this.currTurn++ const updates = this.game.executeNextTick() - - if (this.game.inSpawnPhase() || this.game.ticks() % 20 == 0) { + // TODO: make name rendering more efficient in spawn phase. + if (this.game.inSpawnPhase() || this.game.ticks() % 30 == 0) { this.game.players().forEach(p => { this.playerViewData[p.id()] = placeName(this.game, p) }) diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index ed5097d6a..f3ecfaea3 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -95,6 +95,7 @@ export class PlayerExecution implements Execution { clusters.sort((a, b) => b.size - a.size); const main = clusters.shift() + this.player.largestClusterBoundingBox = calculateBoundingBox(this.mg, main) const surroundedBy = this.surroundedBySamePlayer(main) if (surroundedBy && !this.player.isAlliedWith(surroundedBy)) { this.removeCluster(main) diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index c97524993..6038de35f 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -259,6 +259,7 @@ export interface Player { } export interface MutablePlayer extends Player { + largestClusterBoundingBox: { min: Cell, max: Cell } | null // Targets for this player targets(): Player[] // Targets of player and all allies. diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index 67a72b849..ba6bdbea5 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -56,6 +56,9 @@ export class PlayerImpl implements MutablePlayer { this._displayName = this._name // processName(this._name) } + + largestClusterBoundingBox: { min: Cell, max: Cell } | null + toUpdate(): PlayerUpdate { return { type: GameUpdateType.Player,