| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { STATIC_CHUNK_RADIUS, VISIBLE_CHUNK_RADIUS } from "../../shared/protocol/constants.js"; |
| 4 | import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js"; |
| 5 | |
| 6 | test("thread workers speak the same protocol as in-process workers", { timeout: 20_000 }, async () => |
| 7 | { |
| 8 | const harness = makeSimulation({ workerCount: 1, workerMode: "thread" }); |
| 9 | try |
| 10 | { |
| 11 | const character = makeCharacter(harness.stateDb); |
| 12 | const entityId = harness.simulation.spawnCharacter(1, character); |
| 13 | const snapshots = harness.simulation.snapshotFor(entityId); |
| 14 | assert.equal(snapshots.length, (VISIBLE_CHUNK_RADIUS * 2 + 1) ** 2); |
| 15 | assert.ok(snapshots.some((snapshot) => snapshot.entities.some((entity) => entity.entityId === entityId))); |
| 16 | |
| 17 | const viewSnapshots = harness.simulation.snapshotsForView(entityId); |
| 18 | assert.equal(viewSnapshots.length, (STATIC_CHUNK_RADIUS * 2 + 1) ** 2); |
| 19 | const staticOnly = viewSnapshots.filter((snapshot) => snapshot.staticOnly); |
| 20 | assert.equal(staticOnly.length, viewSnapshots.length - snapshots.length); |
| 21 | for (const snapshot of staticOnly) |
| 22 | { |
| 23 | assert.deepEqual(snapshot.entities, []); |
| 24 | assert.deepEqual(snapshot.groundItems, []); |
| 25 | } |
| 26 | } |
| 27 | finally |
| 28 | { |
| 29 | await harness.simulation.shutdown(); |
| 30 | harness.worldDb.close(); |
| 31 | harness.stateDb.close(); |
| 32 | } |
| 33 | }); |