mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 17:46:46 +00:00
5b663fae14
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()).
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { GameMapImpl } from "../../../src/core/game/GameMap";
|
|
|
|
describe("GameMap.tileStateBuffer", () => {
|
|
it("returns a Uint16Array sized to width * height", () => {
|
|
const map = new GameMapImpl(10, 8, new Uint8Array(10 * 8), 0);
|
|
const buf = map.tileStateBuffer();
|
|
expect(buf).toBeInstanceOf(Uint16Array);
|
|
expect(buf.length).toBe(80);
|
|
});
|
|
|
|
it("returns a live reference — updateTile() mutates the same buffer", () => {
|
|
const map = new GameMapImpl(4, 4, new Uint8Array(16), 0);
|
|
const buf = map.tileStateBuffer();
|
|
// Writes go through updateTile (packed uint32: high 16 bits = terrain byte, low 16 = state).
|
|
map.updateTile(5, 0x00abcd);
|
|
expect(buf[5]).toBe(0xabcd);
|
|
});
|
|
|
|
it("returns the same array on every call (zero-copy)", () => {
|
|
const map = new GameMapImpl(4, 4, new Uint8Array(16), 0);
|
|
expect(map.tileStateBuffer()).toBe(map.tileStateBuffer());
|
|
});
|
|
|
|
it("reflects ownerID writes in the low 12 bits of each cell", () => {
|
|
const map = new GameMapImpl(4, 4, new Uint8Array(16), 0);
|
|
map.setOwnerID(7, 0x123);
|
|
expect(map.tileStateBuffer()[7] & 0xfff).toBe(0x123);
|
|
});
|
|
});
|