Size SAB ring buffer by world tile count

This commit is contained in:
scamiv
2025-11-26 18:41:47 +01:00
parent ecabf3577e
commit ea7d5089b8
+4 -5
View File
@@ -190,10 +190,9 @@ async function createClientGame(
const usesSharedTileState = !!sharedStateBuffer;
if (canUseSharedBuffers) {
// Capacity is number of tile updates that can be queued.
// This is a compromise between memory usage and backlog tolerance.
const TILE_RING_CAPACITY = 262144;
const numTiles = gameMap.gameMap.width() * gameMap.gameMap.height();
// Ring capacity scales with world size: at most one entry per tile.
const TILE_RING_CAPACITY = numTiles;
sharedTileRingBuffers = createSharedTileRingBuffers(
TILE_RING_CAPACITY,
numTiles,
@@ -701,8 +700,8 @@ export class ClientGameRunner {
uniqueTiles.add(ref);
}
// Calculate ring buffer utilization and overflow
const TILE_RING_CAPACITY = 262144;
// Calculate ring buffer utilization and overflow using dynamic capacity
const TILE_RING_CAPACITY = this.tileRingViews.capacity;
const utilization = (uniqueTiles.size / TILE_RING_CAPACITY) * 100;
const overflow = Atomics.load(
this.tileRingViews.header,