mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-02 20:58:19 +00:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user