refactor: share renderer state shapes between game and WebGL renderer

PlayerView/UnitView now wrap renderer-shaped state objects (PlayerState,
PlayerStatic, UnitState) directly instead of holding engine wire types.
GameView owns a long-lived FrameData object kept in sync each tick:
players/units/tiles/trail/railroad are mutated in place; derived buffers
(playerStatus, relationMatrix, allianceClusters, nukeTelegraphs,
attackRings) and events are recomputed in a final populateFrame() pass.

The renderer reads gameView.frameData() and the same byte-identical
state objects PlayerView/UnitView wrap. WebGLFrameBuilder shrinks from
~270 to ~70 LOC: palette management + a single uploadFrameData() call,
no per-frame UnitState allocation on the hot path.

Wiring: maxPlayers=1024 on RendererConfig (pre-sizes NamePass/palette/
relation matrix textures); NamePass disabled so HTML NameLayer remains
the only on-screen player names.

Also: 39 new tests covering PlayerView/GameView/FrameData behavior;
replace .data field access in three layer call sites with accessor
methods (betrayals(), type(), getTraitorRemainingTicks()).
This commit is contained in:
evanpelle
2026-05-16 13:27:31 -07:00
parent 53cf2d43f8
commit 5b663fae14
15 changed files with 3278 additions and 1619 deletions
+3
View File
@@ -1174,6 +1174,9 @@ export class GameImpl implements Game {
tileState(tile: TileRef): number {
return this._map.tileState(tile);
}
tileStateBuffer(): Uint16Array {
return this._map.tileStateBuffer();
}
updateTile(tile: TileRef, state: number): boolean {
return this._map.updateTile(tile, state);
}
+18
View File
@@ -72,6 +72,20 @@ export interface GameMap {
*/
updateTile(tile: TileRef, state: number): boolean;
/**
* Direct access to the per-tile state buffer for zero-copy consumers
* (e.g. WebGL renderer uploading to a R16UI texture).
*
* The returned array is a live reference — it is mutated by `updateTile()`
* each tick. Callers must not write to it.
*
* The bit layout of each `uint16` matches the renderer's tile state:
* bits 0-11: ownerID
* bit 13: fallout
* bit 14: defense bonus
*/
tileStateBuffer(): Uint16Array;
numTilesWithFallout(): number;
}
@@ -401,6 +415,10 @@ export class GameMapImpl implements GameMap {
return this.state[tile];
}
tileStateBuffer(): Uint16Array {
return this.state;
}
/**
* Update a tile from a packed uint32:
* bits 0-15: tile state (owner, fallout, etc.)
+12 -1417
View File
File diff suppressed because it is too large Load Diff