Use SharedArrayBuffer tile state and ring buffer for worker updates

- Share GameMapImpl tile state between worker and main via SharedArrayBuffer
- Add SAB-backed tile update ring buffer to stream tile changes instead of postMessage payloads
- Wire shared state/ring through WorkerClient, Worker.worker, GameRunner, and ClientGameRunner
- Update GameView to skip updateTile when shared state is enabled and consume tile refs from the ring
This commit is contained in:
scamiv
2025-11-26 00:45:06 +01:00
parent 05181d7479
commit 314d8ef25a
8 changed files with 75 additions and 9 deletions
+7
View File
@@ -199,6 +199,11 @@ async function createClientGame(
typeof SharedArrayBuffer !== "undefined" &&
typeof Atomics !== "undefined" &&
isIsolated;
const sharedStateBuffer =
canUseSharedBuffers && gameMap.sharedStateBuffer
? gameMap.sharedStateBuffer
: undefined;
const usesSharedTileState = !!sharedStateBuffer;
if (canUseSharedBuffers) {
// Capacity is number of tile updates that can be queued.
@@ -212,6 +217,7 @@ async function createClientGame(
lobbyConfig.gameStartInfo,
lobbyConfig.clientID,
sharedTileRingBuffers,
sharedStateBuffer,
);
await worker.initialize();
const gameView = new GameView(
@@ -221,6 +227,7 @@ async function createClientGame(
lobbyConfig.clientID,
lobbyConfig.gameStartInfo.gameID,
lobbyConfig.gameStartInfo.players,
usesSharedTileState,
);
const canvas = createCanvas();