tile perf improvements

This commit is contained in:
Evan
2025-01-10 14:38:28 -08:00
parent 5fca2f287b
commit 818fbbdcd5
3 changed files with 22 additions and 6 deletions
+7 -1
View File
@@ -149,7 +149,13 @@ export class TerritoryLayer implements Layer {
}
}
paintTerritory(tile: Tile) {
paintTerritory(tile: Tile, isBorder: boolean = false, parent: Tile = null) {
if (isBorder && !tile.hasOwner()) {
return
}
if (!isBorder) {
tile.neighbors().forEach(t => this.paintTerritory(t, true, tile))
}
if (!tile.hasOwner()) {
if (tile.hasFallout()) {
this.paintCell(tile.cell(), this.theme.falloutColor(), 150)
+14 -4
View File
@@ -8,6 +8,8 @@ import { WorkerClient } from './worker/WorkerClient';
export class TileView {
private _neighbors: TileView[] = []
constructor(private game: GameView, public data: TileUpdate, private _terrain: TerrainTile) { }
type(): TerrainType {
@@ -23,7 +25,12 @@ export class TileView {
return this.data?.ownerID !== undefined && this.data.ownerID !== 0;
}
isBorder(): boolean {
return this.data?.isBorder
for (const n of this.neighbors()) {
if (n.data?.ownerID != this.data?.ownerID) {
return true
}
}
return false
}
cell(): Cell {
return this._terrain.cell()
@@ -35,8 +42,11 @@ export class TileView {
return this._terrain
}
neighbors(): Tile[] {
return this._terrain.neighbors().map(t => this.game.tile(t.cell()))
neighbors(): TileView[] {
if (this._neighbors.length == 0) {
this._neighbors = this._terrain.neighbors().map(t => this.game.tile(t.cell()))
}
return this._neighbors
}
hasDefenseBonus(): boolean {
@@ -303,7 +313,7 @@ export class GameView {
players(): Player[] {
return []
}
tile(cell: Cell): Tile {
tile(cell: Cell): TileView {
return this.tiles[cell.x][cell.y]
}
isOnMap(cell: Cell): boolean {
+1 -1
View File
@@ -399,7 +399,7 @@ export class GameImpl implements MutableGame {
(t.owner() as PlayerImpl)._borderTiles.delete(t);
t._isBorder = false
}
this.updates.push(t.toUpdate())
// this.updates.push(t.toUpdate())
}
}