mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-25 02:58:54 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user