@wildshard/engine 0.1.18 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/budgets/shard-size-baseline.json +10 -4
- package/index.html +6 -4
- package/lint/engine-sides.json +14 -0
- package/lint/ratchet.json +0 -68
- package/lint/ratchet.mjs +1 -4
- package/package.json +17 -15
- package/scripts/agent-sync.mjs +27 -8
- package/scripts/app-build/appCook.ts +8 -2
- package/scripts/app-build/catalogue.ts +10 -7
- package/scripts/app-build/gen.ts +22 -2
- package/scripts/app-build/isolation.d.mts +10 -0
- package/scripts/app-build/isolation.mjs +47 -0
- package/scripts/app-build/outputProducts.mjs +4 -0
- package/scripts/app-build/previousDeploy.d.mts +2 -0
- package/scripts/app-build/previousDeploy.mjs +10 -1
- package/scripts/app-build/serviceWorker.ts +10 -3
- package/scripts/app-build/splitOutput.mjs +4 -2
- package/scripts/app-build/standaloneOutput.d.mts +1 -1
- package/scripts/app-build/standaloneOutput.mjs +5 -3
- package/scripts/app-build/titlePreloads.d.mts +8 -0
- package/scripts/app-build/titlePreloads.mjs +69 -0
- package/scripts/app-build/worldMapAtlas.ts +10 -6
- package/scripts/app-build-pipeline.mjs +31 -3
- package/scripts/built-product.mjs +1 -1
- package/scripts/cell-mem-bench.mjs +81 -23
- package/scripts/check-custom-sections-zero.mjs +1 -1
- package/scripts/check-devserver.mjs +2 -0
- package/scripts/check-models.mjs +2 -0
- package/scripts/check-paths.allow.json +0 -115
- package/scripts/check-paths.mjs +2 -2
- package/scripts/check-platform-ratchets.mjs +2 -3
- package/scripts/chromium-keychain.d.mts +1 -1
- package/scripts/ci-static.sh +1 -1
- package/scripts/committed-fast-checks.mjs +0 -2
- package/scripts/content-sw-proof.mjs +2 -1
- package/scripts/cook-worker.mjs +9 -3
- package/scripts/cook.mjs +18 -5
- package/scripts/docs-inputs-proof.mjs +6 -6
- package/scripts/e7-voice-staging-proof.mjs +1 -1
- package/scripts/gate-related-tests.mjs +1 -1
- package/scripts/git-source-view.mjs +1 -1
- package/scripts/goldens/capture.mjs +17 -5
- package/scripts/grid-crossing-nightly.mjs +59 -0
- package/scripts/grid-crossing-qa.mjs +44 -0
- package/scripts/grid-crossing-ratchet.d.mts +6 -0
- package/scripts/grid-crossing-ratchet.mjs +52 -0
- package/scripts/grid-crossing-report.mjs +122 -0
- package/scripts/grid-crossing-stages.mjs +47 -0
- package/scripts/grid-crossing-tour.mjs +277 -0
- package/scripts/grid-crossing-walk-proof.mjs +124 -17
- package/scripts/host-ruler/roots.mjs +2 -2
- package/scripts/host-ruler.d.mts +91 -0
- package/scripts/host-ruler.mjs +565 -0
- package/scripts/live-prepush.py +3 -5
- package/scripts/loading-flow/benchmax.mjs +3 -1
- package/scripts/look-loop/test_look_loop.py +1 -38
- package/scripts/memory-proof.mjs +61 -6
- package/scripts/mmo-bots.mjs +8 -2
- package/scripts/net-lag-proof.mjs +219 -0
- package/scripts/night-market-kit-budget.mjs +2 -2
- package/scripts/offline-proof-rules.d.mts +2 -2
- package/scripts/offline-proof-rules.mjs +15 -4
- package/scripts/offline-proof.mjs +74 -13
- package/scripts/{shard-platform-output.mjs → output-reader.mjs} +1 -1
- package/scripts/page-release/content.d.mts +9 -1
- package/scripts/page-release/content.mjs +131 -17
- package/scripts/page-release/flow.mjs +36 -10
- package/scripts/page-release/stamp-content.mjs +24 -0
- package/scripts/page-release.mjs +28 -6
- package/scripts/page-size.mjs +2 -1
- package/scripts/pin-packs.ts +1 -1
- package/scripts/pins.ts +4 -4
- package/scripts/precommit-checks.mjs +1 -7
- package/scripts/precommit-jobs.mjs +0 -1
- package/scripts/precommit-source.py +1 -9
- package/scripts/program-discovery.mjs +1 -1
- package/scripts/ring-cook.mjs +2 -1
- package/scripts/ring-step.ts +1 -1
- package/scripts/script-scenario-metrics.mjs +1 -1
- package/scripts/shard-output-content.d.mts +1 -1
- package/scripts/shard-output-content.mjs +2 -2
- package/scripts/shard-outputs.mjs +1 -1
- package/scripts/shard-public.mjs +1 -1
- package/scripts/shard-wire-meter.mjs +24 -9
- package/scripts/side-parity.mjs +4 -2
- package/scripts/standalone-smoke.mjs +8 -3
- package/scripts/tier-textures.mjs +22 -4
- package/scripts/tile-bake-report.mjs +1 -1
- package/scripts/tile-bakes.mjs +1 -1
- package/scripts/title-assets.generated.json +2 -0
- package/scripts/tsconfig.json +0 -2
- package/scripts/vendor/basisu/LICENSE +201 -0
- package/scripts/vendor/basisu/basis_encoder.cjs +2 -0
- package/scripts/vendor/basisu/basis_encoder.wasm +0 -0
- package/scripts/vitest-push-guards.config.ts +1 -1
- package/scripts/vps/harden-apply.sh +4 -1
- package/scripts/vps/harden-prometheus.sh +176 -0
- package/scripts/vps/harden.sh +16 -0
- package/scripts/vps/rebuild.sh +18 -0
- package/scripts/vps/wildshard-config +6 -2
- package/scripts/worker-client-play.mjs +6 -2
- package/scripts/worktree-reap.mjs +5 -5
- package/src/.oxlintrc.json +3 -182
- package/src/client/app/entry.ts +10 -2
- package/src/client/engine/boot/bootCache.ts +2 -2
- package/src/client/engine/boot/bootTrace.ts +12 -4
- package/src/client/engine/boot/browserChunkRecovery.ts +4 -0
- package/src/client/engine/boot/clearDownloads.ts +5 -2
- package/src/client/engine/boot/contentRead.ts +11 -0
- package/src/client/engine/boot/gpuFiles.ts +4 -2
- package/src/client/engine/boot/lastEnd.ts +99 -12
- package/src/client/engine/boot/texturePack.ts +2 -2
- package/src/client/engine/net/netPlayer.ts +19 -2
- package/src/client/engine/net/otherPlayers.ts +55 -8
- package/src/client/engine/net/predictor.ts +33 -9
- package/src/client/engine/net/redial.ts +29 -6
- package/src/client/engine/pwa/cacheNames.ts +58 -1
- package/src/client/engine/pwa/sw.js +41 -11
- package/src/client/engine/render/dataLook.ts +152 -40
- package/src/client/engine/render/families/detail.ts +89 -0
- package/src/client/engine/render/families/pbr.ts +7 -1
- package/src/client/engine/render/look.ts +6 -0
- package/src/client/engine/render/lookLight.ts +103 -11
- package/src/client/engine/render/lookRender.ts +105 -0
- package/src/client/engine/saves/indexed.ts +2 -2
- package/src/client/engine/telemetry/browserErrors.ts +24 -3
- package/src/client/engine/telemetry/staleBuildReport.ts +22 -1
- package/src/client/engine/ui/debugOptions.ts +1 -1
- package/src/client/engine/ui/lookLightOption.ts +10 -6
- package/src/client/engine/ui/namePrompt.ts +7 -0
- package/src/client/game/boot/audio.generated.ts +114 -114
- package/src/client/game/boot/bytes.generated.ts +118 -220
- package/src/client/game/boot/placedSpawn.ts +35 -0
- package/src/client/game/boot/spawnDownload.ts +25 -6
- package/src/client/game/boot/versions.generated.ts +7 -5
- package/src/client/game/devScene/hook.ts +291 -0
- package/src/client/game/grid/cellLoading.ts +12 -2
- package/src/client/game/grid/live.ts +112 -16
- package/src/client/game/grid/liveSession.ts +33 -2
- package/src/client/game/grid/mapAtlas.ts +18 -4
- package/src/client/game/grid/minimapBlend.ts +15 -5
- package/src/client/game/grid/oneWayIn.ts +5 -1
- package/src/client/game/grid/placedCells.ts +114 -12
- package/src/client/game/grid/placedContent.ts +85 -0
- package/src/client/game/grid/prefetch.ts +9 -1
- package/src/client/game/grid/productInputs.ts +3 -1
- package/src/client/game/grid/productLeases.ts +4 -1
- package/src/client/game/grid/products.ts +8 -4
- package/src/client/game/grid/roadLook.ts +24 -15
- package/src/client/game/grid/roadLookPlatform.ts +4 -2
- package/src/client/game/grid/roadResources.ts +24 -0
- package/src/client/game/grid/roadSign.worker.ts +4 -3
- package/src/client/game/grid/roadSignPaint.ts +16 -5
- package/src/client/game/grid/roadSignPreparation.ts +4 -3
- package/src/client/game/grid/roadSignScale.ts +8 -0
- package/src/client/game/grid/roadTileCapture.worker.ts +3 -1
- package/src/client/game/grid/roadTileCaptureWorker.ts +2 -1
- package/src/client/game/grid/roadTileWrite.worker.ts +4 -2
- package/src/client/game/grid/roadTileWriter.ts +2 -1
- package/src/client/game/grid/screenReports.ts +39 -0
- package/src/client/game/grid/session.ts +20 -4
- package/src/client/game/grid/softWallLook.ts +25 -8
- package/src/client/game/mainMenu.ts +6 -2
- package/src/client/game/plugin/context.ts +2 -1
- package/src/client/game/plugin/followedMovers.ts +7 -1
- package/src/client/game/quest/figures.ts +2 -0
- package/src/client/game/session/finish.ts +6 -0
- package/src/client/game/shardfile/assetCache.ts +4 -4
- package/src/client/game/shardfile/client.ts +4 -1
- package/src/client/game/shardfile/clientAssets.ts +9 -5
- package/src/client/game/shardfile/clientLibrary.ts +1 -1
- package/src/client/game/shardfile/clientWater.ts +51 -9
- package/src/client/game/shardfile/clientWorker.ts +19 -7
- package/src/client/game/shardfile/look.ts +8 -3
- package/src/client/game/shardfile/product.ts +34 -7
- package/src/client/game/shardfile/productChecks.ts +2 -2
- package/src/client/game/shardfile/productCost.ts +2 -2
- package/src/client/game/shardfile/readAsset.ts +2 -2
- package/src/client/game/shardfile/reflectingWater.ts +73 -0
- package/src/client/game/shardfile/seatGrace.ts +9 -0
- package/src/client/game/shardfile/skinPlayback.ts +1 -1
- package/src/client/game/systems/npc/figureRows.ts +9 -0
- package/src/client/host/online/doctor.ts +2 -0
- package/src/client/host/online/linkScreens.ts +30 -4
- package/src/client/host/standalone/shell.ts +4 -0
- package/src/cook/game/astc6Encode.ts +55 -0
- package/src/cook/game/astc6Wasm.ts +176 -0
- package/src/cook/game/cookJob.ts +30 -6
- package/src/cook/game/cookWorker.ts +38 -11
- package/src/cook/game/entryTotals.ts +51 -24
- package/src/cook/game/shardCook.ts +35 -7
- package/src/cook/game/spawnParts.ts +33 -8
- package/src/cook/game/tierTextures.ts +87 -14
- package/src/server/engine/ai/bossContenders.ts +27 -3
- package/src/server/engine/ai/phases.ts +1 -1
- package/src/server/engine/entities/creatureRefill.ts +9 -2
- package/src/server/engine/net/ledgerBook.ts +2 -0
- package/src/server/engine/net/room.ts +15 -0
- package/src/server/engine/sim/respawn.ts +8 -0
- package/src/server/game/boss/arenaRoomEntry.ts +5 -1
- package/src/server/game/boss/arenaRoomNative.ts +2 -0
- package/src/server/game/boss/native.ts +2 -1
- package/src/server/game/boss/nativeWake.ts +9 -5
- package/src/server/game/boss/openArenaNative.ts +2 -2
- package/src/server/game/boss/openArenaRoom.ts +3 -1
- package/src/server/game/grid/room.ts +44 -3
- package/src/server/game/grid/simulation.ts +23 -0
- package/src/server/game/population/mixedRoster.ts +11 -3
- package/src/server/game/population/nativeBake.ts +8 -3
- package/src/server/game/population/nativeReturns.ts +6 -3
- package/src/server/game/population/roster.ts +5 -3
- package/src/server/game/quest/eliteDrops.ts +15 -4
- package/src/server/game/quest/nativeChapter.ts +1 -1
- package/src/server/game/quest/nativeComposition.ts +5 -1
- package/src/server/game/riding/nativeTaming.ts +10 -6
- package/src/server/game/riding/wildRefill.ts +3 -2
- package/src/server/game/shardfile/bossRow.ts +4 -2
- package/src/server/game/shardfile/homeKeeper.ts +4 -2
- package/src/server/host/bake/headlessWorker.ts +1 -1
- package/src/server/host/dedicated/cellHost.ts +98 -16
- package/src/server/host/dedicated/cellProtocol.ts +16 -1
- package/src/server/host/dedicated/cellWorker.ts +8 -5
- package/src/server/host/dedicated/dedicatedRoom.ts +16 -6
- package/src/server/host/dedicated/gridCells.ts +15 -6
- package/src/server/host/dedicated/loopLag.ts +21 -0
- package/src/server/host/dedicated/main.ts +13 -5
- package/src/server/host/dedicated/packReader.ts +3 -3
- package/src/server/host/dedicated/placementFile.ts +3 -2
- package/src/server/host/dedicated/roadRoom.ts +34 -4
- package/src/server/host/dedicated/serverMetrics.ts +126 -0
- package/src/server/host/dedicated/socketPump.ts +21 -4
- package/src/server/host/dedicated/workerTable.ts +15 -4
- package/src/server/host/dedicated/world.ts +65 -7
- package/src/server/host/headless.ts +1 -1
- package/src/server/host/headlessRuntime.ts +1 -1
- package/src/server/host/standalone/roadWorld.ts +15 -3
- package/src/server/host/standalone/serverHost.ts +4 -1
- package/src/server/host/standalone/serverProduct.ts +41 -11
- package/src/shared/engine/ai/BossBrain.ts +8 -0
- package/src/shared/game/boss/wake.ts +6 -0
- package/src/shared/game/devColliders.ts +47 -0
- package/src/shared/game/eliteSystem.ts +8 -0
- package/src/shared/game/grid/allocator.ts +3 -0
- package/src/shared/game/grid/placementRows.ts +5 -2
- package/src/shared/game/plugin/bossRecord.ts +3 -2
- package/src/shared/game/shardfile/ktx2Targets.ts +23 -3
- package/src/shared/game/shardfile/outputDescriptor.ts +9 -5
- package/src/shared/game/shardfile/packReads.ts +28 -3
- package/src/shared/game/shardfile/serverPack.ts +9 -0
- package/src/shared/game/systems/looks/trampleField.ts +2 -0
- package/src/shared/host/formatJsonSchema.ts +2 -2
- package/src/tsconfig.json +1 -27
- package/lint/host-reviews.json +0 -14
- package/lint/listed-view-code.json +0 -13
- package/lint/platform-pending-users.json +0 -2520
- package/lint/platform-pending-users.md +0 -18
- package/scripts/cell-mem/metrics-preload.mjs +0 -65
- package/scripts/check-closed-components.d.mts +0 -7
- package/scripts/check-closed-components.mjs +0 -87
- package/scripts/g571-hosts.d.mts +0 -3
- package/scripts/g571-hosts.mjs +0 -54
- package/scripts/host-ruler/register-migrate.mjs +0 -242
- package/scripts/listed-view-code.d.mts +0 -7
- package/scripts/listed-view-code.mjs +0 -93
- package/scripts/look-loop/fit-lut.py +0 -142
- package/scripts/look-loop/palette-delta.py +0 -183
- package/scripts/look-loop/regions/driftwood-isle.json +0 -25
- package/scripts/look-loop/regions/far-reach.json +0 -225
- package/scripts/look-loop/regions/open-plot-night-market.json +0 -855
- package/scripts/look-loop/regions/pine-hollow.json +0 -22
- package/scripts/look-loop/regions/sunscar-dunes.json +0 -281
- package/scripts/platform-chargebacks.d.mts +0 -9
- package/scripts/platform-chargebacks.mjs +0 -135
- package/scripts/shard-component-spans.d.mts +0 -15
- package/scripts/shard-component-spans.mjs +0 -18
- package/scripts/shard-components.d.mts +0 -16
- package/scripts/shard-components.mjs +0 -363
- package/scripts/shard-platform-hosts.d.mts +0 -2
- package/scripts/shard-platform-hosts.mjs +0 -93
- package/scripts/shard-platform-sections.d.mts +0 -2
- package/scripts/shard-platform-sections.mjs +0 -9
- package/scripts/shard-platform.d.mts +0 -76
- package/scripts/shard-platform.mjs +0 -1072
- package/src/.oxfmtrc.json +0 -48
- package/src/scripts/ask-new.sh +0 -29
- package/src/scripts/asks.mjs +0 -142
- package/src/scripts/herdr-prompt.sh +0 -34
- package/src/scripts/herdr-question-open.sh +0 -67
- package/src/scripts/md-wrap.mjs +0 -229
- /package/scripts/{shard-platform-format.d.mts → node-format.d.mts} +0 -0
- /package/scripts/{shard-platform-format.mjs → node-format.mjs} +0 -0
- /package/scripts/{shard-platform-output.d.mts → output-reader.d.mts} +0 -0
|
@@ -7,7 +7,7 @@ import { SimNetWorld } from '@wildshard/engine/net/simWorld';
|
|
|
7
7
|
import type { Transport } from '@wildshard/engine/net/transport';
|
|
8
8
|
import type { SimHost } from '@wildshard/engine/sim';
|
|
9
9
|
import type { PlayerSim } from '@wildshard/engine/sim/playerSim';
|
|
10
|
-
import { carryMotion } from '@wildshard/engine/game/grid/simulation';
|
|
10
|
+
import { carryMotion, motionOf } from '@wildshard/engine/game/grid/simulation';
|
|
11
11
|
import type { GridAssembly, GridCell } from '@wildshard/engine/game/grid/assembly';
|
|
12
12
|
import type { GridCollisionStrip } from '@wildshard/engine/game/grid/gridCollision';
|
|
13
13
|
import { mountedPlayerOf } from '@wildshard/engine/game/riding/native';
|
|
@@ -16,8 +16,9 @@ import { LEAD_SEAT } from '../standalone/cellWorld';
|
|
|
16
16
|
import { HOLD_MS, type ResumeAt, type RoomNews, type SeatEntry } from './cellProtocol';
|
|
17
17
|
import { crossedTo, finite, type CrossArrival, type CrossTarget } from './crossing';
|
|
18
18
|
import { FallFloor } from '../standalone/fallFloor';
|
|
19
|
-
import { placeOnRoad } from '../standalone/roadWorld';
|
|
20
|
-
import { LEFT } from './socketPump';
|
|
19
|
+
import { openCellWalls, placeOnRoad } from '../standalone/roadWorld';
|
|
20
|
+
import { LEFT, SeatTransport } from './socketPump';
|
|
21
|
+
import { cellFrame } from './gridCells';
|
|
21
22
|
|
|
22
23
|
/** How often a seat whose crossing is asked for asks again, and how often holds are looked at, in ticks. */
|
|
23
24
|
const ASK_TICKS = 30;
|
|
@@ -54,6 +55,8 @@ export class RoadRoom implements CrossTarget {
|
|
|
54
55
|
readonly host: SimHost;
|
|
55
56
|
private readonly options: RoadRoomOptions;
|
|
56
57
|
private readonly seats = new Map<string, RoadSeat>();
|
|
58
|
+
/** GC15 (3): cells on other workers this road crosses into (`open`), their walls down. */
|
|
59
|
+
private readonly opened = new Set<string>();
|
|
57
60
|
/** The grid the trigger reads: the options' until a placement grows it (SA34a). */
|
|
58
61
|
private assembly: GridAssembly;
|
|
59
62
|
constructor(options: RoadRoomOptions) {
|
|
@@ -73,6 +76,11 @@ export class RoadRoom implements CrossTarget {
|
|
|
73
76
|
get holding(): number { let held = 0; for (const seat of this.seats.values()) if (seat.transport === null) held++; return held; }
|
|
74
77
|
holds(device: string): boolean { return this.seats.has(device); }
|
|
75
78
|
bodyId(device: string): string | undefined { return this.seats.get(device)?.body; }
|
|
79
|
+
/** GC4: someone on this road stands within `reach` of `origin` on both axes (a cell's square grown by how near counts). */
|
|
80
|
+
near(origin: { readonly x: number; readonly z: number }, reach: number): boolean {
|
|
81
|
+
for (const seat of this.seats.values()) { const at = this.host.players.get(seat.body)?.position; if (at !== undefined && Math.abs(at.x - origin.x) <= reach && Math.abs(at.z - origin.z) <= reach) return true; }
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
76
84
|
bodyOf(device: string): PlayerSim | undefined { const seat = this.seats.get(device); return seat === undefined ? undefined : this.host.players.get(seat.body); }
|
|
77
85
|
|
|
78
86
|
admit(entry: SeatEntry, transport: Transport, at: ResumeAt, motion?: PlayerSim): CrossArrival | string {
|
|
@@ -100,6 +108,28 @@ export class RoadRoom implements CrossTarget {
|
|
|
100
108
|
hello();
|
|
101
109
|
this.options.post({ kind: 'seated', device: seat.device, body: seat.body, seats: this.seats.size });
|
|
102
110
|
}
|
|
111
|
+
/** GC15 (3): cells on other workers whose entryways stand: their walls on this road come down and a walker crosses into them. */
|
|
112
|
+
open(cells: readonly string[]): void {
|
|
113
|
+
const fresh = cells.filter(cell => !this.options.hosts(cell) && !this.opened.has(cell));
|
|
114
|
+
openCellWalls(this.host, fresh);
|
|
115
|
+
for (const cell of fresh) this.opened.add(cell);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* GC15 (3): the seat walks off the road into `to`, a cell on another worker. Its client hears `travel` (`NetRoom.handOut`), the seat goes
|
|
119
|
+
* from here with no hold, and its port says `out` with the walker's motion, after everything else it was sent: the door moves the socket.
|
|
120
|
+
* False when nothing went (no live link here).
|
|
121
|
+
*/
|
|
122
|
+
handOut(device: string, to: string): boolean {
|
|
123
|
+
const seat = this.seats.get(device), transport = seat?.transport ?? null, player = seat === undefined ? undefined : this.host.players.get(seat.body);
|
|
124
|
+
if (seat === undefined || !(transport instanceof SeatTransport) || seat.client === null || player === undefined || !this.opened.has(to)) return false;
|
|
125
|
+
const motion = mountedPlayerOf(this.host, seat.body)?.mounted === true ? null : motionOf(player);
|
|
126
|
+
if (!this.net.handOut(seat.client, cellFrame(to))) return false;
|
|
127
|
+
mountedPlayerOf(this.host, seat.body)?.dismount();
|
|
128
|
+
seat.closeOff?.(); seat.closeOff = null; seat.transport = null; seat.client = null;
|
|
129
|
+
transport.handOut(motion);
|
|
130
|
+
this.release(seat);
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
103
133
|
/** The seat walks off the road into `target`, a cell on this worker: its body there first, then its link (`DedicatedRoom.handOver`'s order). */
|
|
104
134
|
handOver(device: string, target: CrossTarget, entry: SeatEntry, at: ResumeAt): boolean {
|
|
105
135
|
const seat = this.seats.get(device), transport = seat?.transport ?? null;
|
|
@@ -155,7 +185,7 @@ export class RoadRoom implements CrossTarget {
|
|
|
155
185
|
if (seat.transport === null || player === undefined || !finite(player.position)) continue;
|
|
156
186
|
const crossed = crossedTo(this.assembly, null, player.position);
|
|
157
187
|
const to = crossed?.cell?.instance ?? null;
|
|
158
|
-
if (crossed === undefined || to === null || !this.options.hosts(to)) { seat.asked = null; continue; }
|
|
188
|
+
if (crossed === undefined || to === null || (!this.options.hosts(to) && !this.opened.has(to))) { seat.asked = null; continue; }
|
|
159
189
|
if (seat.asked === to && this.host.state.tick - seat.askedAt < ASK_TICKS) continue;
|
|
160
190
|
seat.asked = to; seat.askedAt = this.host.state.tick;
|
|
161
191
|
this.options.post({ kind: 'crossing', device: seat.device, to, at: { ...crossed.at, yaw: player.yaw } });
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// SERVER-CELLS SC1 (J328): the dedicated server's `/metrics`, Prometheus text on 127.0.0.1 only, on `METRICS_PORT` (unset: off). The
|
|
2
|
+
// process's own numbers come from the metrics client's defaults; the rest is read from what the door already hears: each worker's 10 s
|
|
3
|
+
// reading (tick times, ticks per second, drops, cells awake, players, its heap and its event-loop lag), each `cell.booted`, each crossing,
|
|
4
|
+
// and `/health`'s table for the cells each worker holds. Nothing here alters a reply or a tick, and nothing leaves loopback.
|
|
5
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Its own loopback port.
|
|
6
|
+
import { createServer, type Server, type ServerResponse } from 'node:http';
|
|
7
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The port it ended up on.
|
|
8
|
+
import type { AddressInfo } from 'node:net';
|
|
9
|
+
import { Scope } from '@wildshard/engine/app/scope';
|
|
10
|
+
import { Counter, Gauge, Histogram, Registry, collectDefaultMetrics } from '@prometheus-io/client';
|
|
11
|
+
import type { WorkerReading } from './cellProtocol';
|
|
12
|
+
import { loopLag, type LoopLag } from './loopLag';
|
|
13
|
+
|
|
14
|
+
/** Only loopback: the box's Prometheus scrapes it there (SC2), and nothing else may. */
|
|
15
|
+
const HOST = '127.0.0.1';
|
|
16
|
+
/** The main thread's lag window, as long as a worker's reading, so a second scraper never shortens it. */
|
|
17
|
+
const LAG_MS = 10_000;
|
|
18
|
+
|
|
19
|
+
/** `METRICS_PORT`: unset or blank is off; 0 asks for any free port (a proof's); anything else must be a port, or the server refuses to start. */
|
|
20
|
+
export function metricsPort(env: Readonly<Record<string, string | undefined>>): number | undefined {
|
|
21
|
+
const value = env['METRICS_PORT'];
|
|
22
|
+
if (value === undefined || value.trim() === '') return undefined;
|
|
23
|
+
const port = Number(value);
|
|
24
|
+
if (!Number.isInteger(port) || port < 0 || port > 65_535) throw new Error(`METRICS_PORT ${value} is not a port`);
|
|
25
|
+
return port;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** What `/metrics` reads of the world when scraped: `/health`'s table, each open cell and the worker it runs on. */
|
|
29
|
+
export interface MetricsWorld { health: () => { readonly table: Readonly<Record<string, number>> } }
|
|
30
|
+
|
|
31
|
+
/** The server's metrics: fed by the door's callbacks, served on loopback once `listen` is called. */
|
|
32
|
+
export class ServerMetrics {
|
|
33
|
+
readonly registry: Registry = new Registry();
|
|
34
|
+
private world: MetricsWorld | undefined;
|
|
35
|
+
private server: Server | undefined;
|
|
36
|
+
private readonly log: (line: Record<string, unknown>) => void;
|
|
37
|
+
/** The main thread's lag over its last whole window. */
|
|
38
|
+
private mainLag: LoopLag = { p50: 0, p99: 0, max: 0 };
|
|
39
|
+
private readonly scope = new Scope('dedicated.metrics');
|
|
40
|
+
private readonly lag: Gauge<'thread' | 'quantile'>;
|
|
41
|
+
private readonly memory: Gauge<'thread' | 'kind'>;
|
|
42
|
+
private readonly tick: Gauge<'worker' | 'quantile'>;
|
|
43
|
+
private readonly rate: Gauge<'worker'>;
|
|
44
|
+
private readonly drops: Counter<'worker'>;
|
|
45
|
+
private readonly awake: Gauge<'worker'>;
|
|
46
|
+
private readonly players: Gauge<'worker'>;
|
|
47
|
+
private readonly held: Gauge<'worker'>;
|
|
48
|
+
private readonly boots: Histogram;
|
|
49
|
+
private readonly crossings: Histogram<'moved'>;
|
|
50
|
+
|
|
51
|
+
constructor(log: (line: Record<string, unknown>) => void) {
|
|
52
|
+
this.log = log;
|
|
53
|
+
const registers = [this.registry], readLag = loopLag();
|
|
54
|
+
this.scope.interval(LAG_MS, () => { this.mainLag = readLag(); });
|
|
55
|
+
collectDefaultMetrics({ register: this.registry });
|
|
56
|
+
// A metric's `collect` runs with the metric as `this`: these read the server's own state.
|
|
57
|
+
const mainLag = (): LoopLag => this.mainLag, table = (): Readonly<Record<string, number>> => this.world?.health().table ?? {};
|
|
58
|
+
this.lag = new Gauge({ name: 'wildshard_eventloop_lag_seconds', help: 'Event-loop lag per thread over its last 10 s window.', labelNames: ['thread', 'quantile'], registers,
|
|
59
|
+
collect() { const { p50, p99, max } = mainLag(); this.set({ thread: 'main', quantile: '0.5' }, p50 / 1000); this.set({ thread: 'main', quantile: '0.99' }, p99 / 1000); this.set({ thread: 'main', quantile: '1' }, max / 1000); } });
|
|
60
|
+
this.memory = new Gauge({ name: 'wildshard_thread_memory_bytes', help: 'Each thread\'s own heap, external and array-buffer bytes (a worker\'s from its last reading).', labelNames: ['thread', 'kind'], registers,
|
|
61
|
+
collect() { const own = process.memoryUsage(); this.set({ thread: 'main', kind: 'heap' }, own.heapUsed); this.set({ thread: 'main', kind: 'external' }, own.external); this.set({ thread: 'main', kind: 'arrayBuffers' }, own.arrayBuffers); } });
|
|
62
|
+
this.tick = new Gauge({ name: 'wildshard_tick_seconds', help: 'Tick time per worker over its last 10 s reading.', labelNames: ['worker', 'quantile'], registers });
|
|
63
|
+
this.rate = new Gauge({ name: 'wildshard_ticks_per_second', help: 'Ticks per second per worker over its last 10 s reading.', labelNames: ['worker'], registers });
|
|
64
|
+
this.drops = new Counter({ name: 'wildshard_tick_drops_total', help: 'Ticks a worker\'s clock dropped to catch up.', labelNames: ['worker'], registers });
|
|
65
|
+
this.registry.registerMetric(new Gauge({ name: 'wildshard_cells_resident', help: 'Cells open in memory, per worker (from /health\'s table).', labelNames: ['worker'], registers: [],
|
|
66
|
+
collect() {
|
|
67
|
+
this.reset();
|
|
68
|
+
const counts = new Map<number, number>();
|
|
69
|
+
for (const index of Object.values(table())) counts.set(index, (counts.get(index) ?? 0) + 1);
|
|
70
|
+
for (const [index, count] of counts) this.set({ worker: String(index) }, count);
|
|
71
|
+
} }));
|
|
72
|
+
this.awake = new Gauge({ name: 'wildshard_cells_awake', help: 'Cells with someone in them, ticking, per worker.', labelNames: ['worker'], registers });
|
|
73
|
+
this.players = new Gauge({ name: 'wildshard_players', help: 'Players seated, per worker.', labelNames: ['worker'], registers });
|
|
74
|
+
this.held = new Gauge({ name: 'wildshard_players_held', help: 'Bodies held for a dropped player, per worker.', labelNames: ['worker'], registers });
|
|
75
|
+
this.boots = new Histogram({ name: 'wildshard_cell_boot_seconds', help: 'How long a cell (or a worker\'s road) took to open: each `cell.booted`.', buckets: [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8, 16], registers });
|
|
76
|
+
this.crossings = new Histogram({ name: 'wildshard_crossing_seconds', help: 'A crossing, from the source\'s ask to the worker\'s answer, by whether the seat moved.', labelNames: ['moved'], buckets: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2], registers });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The world whose table says which cells each worker holds. */
|
|
80
|
+
watch(world: MetricsWorld): void { this.world = world; }
|
|
81
|
+
/** One worker's 10 s reading. */
|
|
82
|
+
reading(index: number, row: WorkerReading): void {
|
|
83
|
+
const worker = String(index);
|
|
84
|
+
for (const [quantile, ms] of [['0.5', row.p50], ['0.95', row.p95], ['0.99', row.p99], ['1', row.max]] as const) this.tick.set({ worker, quantile }, ms / 1000);
|
|
85
|
+
this.rate.set({ worker }, row.ticksPerSecond);
|
|
86
|
+
this.drops.inc({ worker }, Math.max(0, row.drops));
|
|
87
|
+
this.awake.set({ worker }, row.awake);
|
|
88
|
+
this.players.set({ worker }, row.players);
|
|
89
|
+
this.held.set({ worker }, row.held);
|
|
90
|
+
const thread = `worker-${worker}`;
|
|
91
|
+
this.memory.set({ thread, kind: 'heap' }, row.heap);
|
|
92
|
+
if (row.external !== undefined) this.memory.set({ thread, kind: 'external' }, row.external);
|
|
93
|
+
if (row.arrayBuffers !== undefined) this.memory.set({ thread, kind: 'arrayBuffers' }, row.arrayBuffers);
|
|
94
|
+
if (row.lag !== undefined) for (const [quantile, ms] of [['0.5', row.lag.p50], ['0.99', row.lag.p99], ['1', row.lag.max]] as const) this.lag.set({ thread, quantile }, ms / 1000);
|
|
95
|
+
}
|
|
96
|
+
/** A cell, or a worker's road, opened in `ms`. */
|
|
97
|
+
booted(ms: number): void { this.boots.observe(ms / 1000); }
|
|
98
|
+
/** A crossing took `ms`, and the seat moved or stayed. */
|
|
99
|
+
crossed(ms: number, moved: boolean): void { this.crossings.observe({ moved: String(moved) }, ms / 1000); }
|
|
100
|
+
/** The scrape. */
|
|
101
|
+
text(): Promise<string> { return this.registry.metrics(); }
|
|
102
|
+
/** One `/metrics` answer: a scrape that fails says why, and the game never hears of it. */
|
|
103
|
+
private async answer(response: ServerResponse): Promise<void> {
|
|
104
|
+
try { const text = await this.text(); response.writeHead(200, { 'content-type': this.registry.contentType }).end(text); }
|
|
105
|
+
catch (error) { response.writeHead(500).end(String(error)); }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Serve `/metrics` on 127.0.0.1:`port`; answers the port it listens on. */
|
|
109
|
+
async listen(port: number): Promise<number> {
|
|
110
|
+
const server = this.server = createServer((request, response) => {
|
|
111
|
+
if (request.method !== 'GET' || request.url !== '/metrics') { response.writeHead(404).end(); return; }
|
|
112
|
+
void this.answer(response);
|
|
113
|
+
});
|
|
114
|
+
await new Promise<void>((resolve, reject) => { server.once('error', reject); server.listen(port, HOST, () => { server.off('error', reject); resolve(); }); });
|
|
115
|
+
// Once up, a failure on this side port is a line, never a crash of the game; and it never keeps the process alive.
|
|
116
|
+
server.on('error', error => { this.log({ at: 'metrics.error', error: String(error) }); });
|
|
117
|
+
server.unref();
|
|
118
|
+
return (server.address() as AddressInfo).port;
|
|
119
|
+
}
|
|
120
|
+
async close(): Promise<void> {
|
|
121
|
+
this.scope.dispose();
|
|
122
|
+
const server = this.server;
|
|
123
|
+
this.server = undefined;
|
|
124
|
+
if (server !== undefined) await new Promise<void>(resolve => { server.closeAllConnections(); server.close(() => { resolve(); }); });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -7,15 +7,17 @@ export const LEFT = 'left';
|
|
|
7
7
|
/** The byte a `ready` carries to say so. */
|
|
8
8
|
export const LEAVE_FLAG = 1;
|
|
9
9
|
/** What crosses between a socket's thread and its room's. */
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// GC15 (3): `out`, from the room's end: this seat left for a cell on another worker. Everything the room said before it went first, on
|
|
11
|
+
// this same port, so the door moves the socket to the target's port only once the `travel` is on its way to the client.
|
|
12
|
+
type Pumped = { readonly channel: NetChannel; readonly bytes: ArrayBuffer } | { readonly close: string; readonly silentMs: number } | { readonly out: true; readonly motion: unknown };
|
|
13
|
+
const pumped = (value: unknown): Pumped | null => typeof value === 'object' && value !== null && ('close' in value || 'bytes' in value || 'out' in value) ? value as Pumped : null;
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* J182: the socket lives on the main thread and its cell in a worker, and this is all that joins them. `end` keeps backpressure, the
|
|
15
17
|
* silence check and the keepalive, because those need the socket; the room hears the same bytes it would on any Transport. The port
|
|
16
18
|
* closes with the socket, and what the room says after that goes nowhere.
|
|
17
19
|
*/
|
|
18
|
-
export function pumpSocket(end: SocketTransport, port: MessagePort, now: () => number = diagnosticNow): void {
|
|
20
|
+
export function pumpSocket(end: SocketTransport, port: MessagePort, now: () => number = diagnosticNow, out?: (motion: unknown) => void): void {
|
|
19
21
|
const off = end.onMessage((channel, bytes) => { port.postMessage({ channel, bytes }, [bytes]); });
|
|
20
22
|
// E7.3: a clean quit from the menu: `ready` again, with a flag. The body goes at once.
|
|
21
23
|
const quit = end.onControl((control, bytes) => { if (control === 'ready' && new Uint8Array(bytes)[0] === LEAVE_FLAG) end.close(LEFT); });
|
|
@@ -23,7 +25,11 @@ export function pumpSocket(end: SocketTransport, port: MessagePort, now: () => n
|
|
|
23
25
|
port.onmessage = (event: MessageEvent<unknown>): void => {
|
|
24
26
|
const message = pumped(event.data);
|
|
25
27
|
if (message === null) return;
|
|
26
|
-
if ('
|
|
28
|
+
if ('out' in message) {
|
|
29
|
+
// GC15 (3): the room let this seat go to another worker: the socket stays open and the door points it at the target's port
|
|
30
|
+
off(); quit(); closed(); port.close();
|
|
31
|
+
if (out === undefined) end.close('retry'); else out(message.motion);
|
|
32
|
+
} else if ('close' in message) { off(); quit(); closed(); end.close(message.close); port.close(); } else end.send(message.channel, message.bytes);
|
|
27
33
|
};
|
|
28
34
|
}
|
|
29
35
|
|
|
@@ -42,6 +48,7 @@ export class SeatTransport implements Transport {
|
|
|
42
48
|
port.onmessage = (event: MessageEvent<unknown>): void => {
|
|
43
49
|
const message = pumped(event.data);
|
|
44
50
|
if (message === null) return;
|
|
51
|
+
if ('out' in message) return;
|
|
45
52
|
if ('close' in message) { this.silentMs = message.silentMs; this.ended(message.close); } else this.deliver(message.channel, message.bytes);
|
|
46
53
|
};
|
|
47
54
|
}
|
|
@@ -57,6 +64,16 @@ export class SeatTransport implements Transport {
|
|
|
57
64
|
this.port.postMessage({ channel, bytes }, [bytes]);
|
|
58
65
|
}
|
|
59
66
|
onMessage(listener: (channel: NetChannel, bytes: ArrayBuffer) => void): () => void { this.messages.add(listener); return () => { this.messages.delete(listener); }; }
|
|
67
|
+
/**
|
|
68
|
+
* GC15 (3): this seat walks on to a cell on another worker. After everything already sent (the `travel`), the door hears `out` and
|
|
69
|
+
* moves the socket; this end is done, and its close listeners never hear of it: nothing closed.
|
|
70
|
+
*/
|
|
71
|
+
handOut(motion: unknown): void {
|
|
72
|
+
if (!this.open) return;
|
|
73
|
+
// oxlint-disable-next-line unicorn/require-post-message-target-origin -- A MessagePort has no origin.
|
|
74
|
+
this.port.postMessage({ out: true, motion });
|
|
75
|
+
this.open = false; this.closes.clear(); this.messages.clear();
|
|
76
|
+
}
|
|
60
77
|
onClose(listener: (reason: string) => void): () => void { this.closes.add(listener); return () => { this.closes.delete(listener); }; }
|
|
61
78
|
close(reason = 'closed'): void {
|
|
62
79
|
if (!this.open) return;
|
|
@@ -27,15 +27,26 @@ export function worldCrossing(value: string | undefined): boolean {
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* The table for the cells this server opens: one row a worker, at most `workers` rows. Only an open cell takes a row, so one cell is one
|
|
30
|
-
* worker. Named rows go first; the rest are shared, and if the count runs out the last row takes
|
|
30
|
+
* worker. Named rows go first; the rest are shared, and if the count runs out the last row takes the named cells left over.
|
|
31
|
+
* GC13: the unnamed cells then move from that last row to the rows holding fewest, so no worker holds more than its share plus one.
|
|
32
|
+
* (Before, the last row kept them all: staging's 2 workers held Nalati alone and the other 25 cells together.) A named cell stays
|
|
33
|
+
* where it was, so Driftwood's crossings to Sunscar and Sky Reach stay on one worker; a crossing between workers is GC15's move.
|
|
31
34
|
*/
|
|
32
35
|
export function workerTable(cells: readonly string[], workers: number): readonly (readonly string[])[] {
|
|
33
36
|
const open = new Set(cells), named = new Set([...DEDICATED, ...SHARED.flat()]), rest = cells.filter(slug => !named.has(slug)).sort();
|
|
34
37
|
const rows = [...DEDICATED.map(slug => [slug]), ...SHARED].map(row => row.filter(slug => open.has(slug))).filter(row => row.length > 0);
|
|
35
38
|
const room = Math.max(1, workers - rows.length), share = Array.from({ length: room }, (): string[] => []);
|
|
36
39
|
rest.forEach((slug, index) => { share[index % room]?.push(slug); });
|
|
37
|
-
const table = [...rows, ...share.filter(row => row.length > 0)]
|
|
40
|
+
const table = [...rows, ...share.filter(row => row.length > 0)];
|
|
38
41
|
if (table.length <= workers) return table;
|
|
39
|
-
// GC31: one worker is one row, so a crossing reaches every cell
|
|
40
|
-
|
|
42
|
+
// GC31: one worker is one row, so a crossing reaches every cell.
|
|
43
|
+
if (workers <= 1) return [table.flat()];
|
|
44
|
+
const kept = rows.slice(0, workers - 1).map(row => row.slice()), over = [...rows.slice(workers - 1).flat(), ...rest];
|
|
45
|
+
// the unnamed cells sit at the end of `over`, so the last cell is the one to move while it is unnamed
|
|
46
|
+
for (let moving = over.at(-1); moving !== undefined && !named.has(moving); moving = over.at(-1)) {
|
|
47
|
+
const lightest = kept.reduce((best, row) => (row.length < best.length ? row : best));
|
|
48
|
+
if (over.length <= lightest.length + 1) break;
|
|
49
|
+
over.pop(); lightest.push(moving);
|
|
50
|
+
}
|
|
51
|
+
return [...kept, over];
|
|
41
52
|
}
|
|
@@ -21,6 +21,7 @@ import {CorrectionSchema} from '@wildshard/engine/net/measurements';
|
|
|
21
21
|
import type {PlaytestRow} from './playtest';
|
|
22
22
|
import type { ChatReport } from '@wildshard/engine/net/chat';
|
|
23
23
|
import type { CellOrder, ResumeAt, SavedCheckpoint, SeatEntry, WorkerNews, WorkerReading, WorkerResident } from './cellProtocol';
|
|
24
|
+
import type { MotionSnapshot } from '@wildshard/engine/game/grid/simulation';
|
|
24
25
|
import { bodyId } from './seats';
|
|
25
26
|
import { SaveNewerError, type PlayerDoc } from './playerDoc';
|
|
26
27
|
import { LEAVE_FLAG, LEFT, pumpSocket } from './socketPump';
|
|
@@ -107,8 +108,12 @@ export interface WorldOptions {
|
|
|
107
108
|
readonly crashed: (error: unknown) => void;
|
|
108
109
|
/** The grace ran out: stop, and let systemd start what is on disk. */
|
|
109
110
|
readonly restart: () => void;
|
|
110
|
-
/** One worker's 10 s reading, for what leaves the box (E7.8a). */
|
|
111
|
+
/** One worker's 10 s reading, for what leaves the box (E7.8a) and `/metrics` (SC1). */
|
|
111
112
|
readonly reading?: (index: number, reading: WorkerReading) => void;
|
|
113
|
+
/** SERVER-CELLS SC1: a cell (or a worker's road) opened in `ms`, as `cell.booted` logs it. */
|
|
114
|
+
readonly booted?: (index: number, slug: string, ms: number) => void;
|
|
115
|
+
/** SC1: a crossing's time from its source's ask to its worker's answer, and whether the seat moved. */
|
|
116
|
+
readonly crossed?: (ms: number, moved: boolean) => void;
|
|
112
117
|
readonly playtest?:(row:PlaytestRow)=>void;
|
|
113
118
|
/** J218: the ICE servers voice chat hands a player who joins; public STUN when absent. */
|
|
114
119
|
readonly voiceIce?: () => Promise<readonly VoiceIceServer[]>;
|
|
@@ -158,8 +163,14 @@ export class World {
|
|
|
158
163
|
private readonly voiceBodies = new Map<string, (body: string) => void>();
|
|
159
164
|
private readonly finds = new Map<number, (found: { held: boolean; spawn: ResumeAt }) => void>();
|
|
160
165
|
private readonly drains = new Map<number, () => void>();
|
|
161
|
-
/** GC15: devices whose crossing the door is reading a save for, or whose `cross` order a worker has not answered. */
|
|
162
|
-
private readonly crossings = new
|
|
166
|
+
/** GC15: devices whose crossing the door is reading a save for, or whose `cross` order a worker has not answered, and when it began (SC1). */
|
|
167
|
+
private readonly crossings = new Map<string, number>();
|
|
168
|
+
/** GC15 (3): each seated device's socket and a copy of the hello it was seated with, so a crossing onto another worker can move both. */
|
|
169
|
+
private readonly seatSockets = new Map<string, { readonly end: SocketTransport; readonly hello: ArrayBuffer }>();
|
|
170
|
+
/** GC15 (3): a crossing onto another worker, between the source's `handOut` and the socket's `out`: where it arrives and with what save. */
|
|
171
|
+
private readonly outs = new Map<string, { readonly from: string; readonly to: string; readonly at: ResumeAt; readonly entry: SeatEntry }>();
|
|
172
|
+
/** GC15 (3): each worker's grid cells whose entryways stand, as its `booted` said. */
|
|
173
|
+
private readonly stands = new Map<WorkerLink, readonly string[]>();
|
|
163
174
|
/** GC15: devices whose source said `left` while their crossing was in flight: applied if the crossing is abandoned before `cross`. */
|
|
164
175
|
private readonly leftCrossing = new Set<string>();
|
|
165
176
|
private asked = 0;
|
|
@@ -201,7 +212,7 @@ export class World {
|
|
|
201
212
|
this.options.crashed(new Error(reason));
|
|
202
213
|
};
|
|
203
214
|
link.listen(news => {
|
|
204
|
-
if (news.kind === 'booted') { up = true; this.up.add(link); if (news.resident !== undefined) this.resident.set(link, news.resident); if (late) for (const slug of slugs) this.links.set(slug, link); this.options.log({ at: 'worker.booted', index, slugs, ms: news.ms }); resolve(); }
|
|
215
|
+
if (news.kind === 'booted') { up = true; this.up.add(link); if (news.resident !== undefined) this.resident.set(link, news.resident); if (news.stands !== undefined) { this.stands.set(link, news.stands); this.openRoads(); } if (late) for (const slug of slugs) this.links.set(slug, link); this.options.log({ at: 'worker.booted', index, slugs, ms: news.ms }); resolve(); }
|
|
205
216
|
else if (news.kind === 'failed') ended(news.reason); else this.heard(index, news);
|
|
206
217
|
}, ended);
|
|
207
218
|
});
|
|
@@ -256,7 +267,7 @@ export class World {
|
|
|
256
267
|
else if (news.kind === 'report') { if (!this.options.saves.report(news.report, cellShard(news.slug))) this.refuse('report-backlog'); }
|
|
257
268
|
else if (news.kind === 'chat') { for (const link of this.workers) link.send({ kind: 'chat', from: news.slug, line: news.line }); }
|
|
258
269
|
else if(news.kind==='playtest')this.options.playtest?.(news.row);
|
|
259
|
-
else if (news.kind === 'cell') this.options.log({ at: 'cell.booted', index, slug: news.slug, ms: news.ms });
|
|
270
|
+
else if (news.kind === 'cell') { this.options.log({ at: 'cell.booted', index, slug: news.slug, ms: news.ms }); this.options.booted?.(index, news.slug, news.ms); }
|
|
260
271
|
else if (news.kind === 'reading') { this.options.log({ at: 'worker', index, ...news.reading, refusals: this.refusals, connections: this.connectionStats, saves: this.options.saves.stats?.() }); this.options.reading?.(index, news.reading); }
|
|
261
272
|
else if (news.kind === 'placed') {
|
|
262
273
|
const link = this.workers[index];
|
|
@@ -267,7 +278,10 @@ export class World {
|
|
|
267
278
|
}
|
|
268
279
|
else if (news.kind === 'drained') { this.drains.get(index)?.(); this.drains.delete(index); }
|
|
269
280
|
else if (news.kind === 'crossing') void this.crossing(news.slug, news.device, news.to, news.at);
|
|
281
|
+
else if (news.kind === 'handedOut') { if (!news.out && this.outs.get(news.device)?.from === news.from) { this.outs.delete(news.device); this.abandon(news.device, news.from); } }
|
|
270
282
|
else if (news.kind === 'crossed') {
|
|
283
|
+
const begun = this.crossings.get(news.device);
|
|
284
|
+
if (begun !== undefined) this.options.crossed?.(diagnosticNow() - begun, news.moved);
|
|
271
285
|
this.crossings.delete(news.device); this.leftCrossing.delete(news.device);
|
|
272
286
|
// A moved seat stands in the target, on the same link; one the target refused after the source let it go is in neither.
|
|
273
287
|
if (this.seated.get(news.device) === news.from) {
|
|
@@ -363,6 +377,13 @@ export class World {
|
|
|
363
377
|
/** Everyone in the grid or on their way: the cap counts all of them, whichever cell they stand in (J182). */
|
|
364
378
|
private get taken(): number { return this.seated.size + this.pending.size; }
|
|
365
379
|
/** The worker a cell runs on, or (GC15) whose road a name is. */
|
|
380
|
+
/** GC15 (3): every worker's road hears which cells on the other workers a walker can stand in, and drops its walls round them. */
|
|
381
|
+
private openRoads(): void {
|
|
382
|
+
for (const link of this.up) {
|
|
383
|
+
const cells = [...this.stands].filter(([other]) => other !== link && this.up.has(other)).flatMap(([, list]) => list);
|
|
384
|
+
if (cells.length > 0) link.send({ kind: 'open', cells });
|
|
385
|
+
}
|
|
386
|
+
}
|
|
366
387
|
private linkOf(slug: string): WorkerLink | undefined { return this.links.get(roadHome(slug) ?? slug); }
|
|
367
388
|
private link(slug: string): WorkerLink {
|
|
368
389
|
const link = this.linkOf(slug);
|
|
@@ -443,8 +464,10 @@ export class World {
|
|
|
443
464
|
*/
|
|
444
465
|
private async crossing(from: string, device: string, to: string, at: ResumeAt): Promise<void> {
|
|
445
466
|
const link = this.linkOf(to), name = this.names.get(device);
|
|
467
|
+
// GC15 (3): from a worker's road into a cell another worker hosts
|
|
468
|
+
if (link !== undefined && link !== this.linkOf(from) && roadHome(from) !== null && roadHome(to) === null) { await this.crossWorkers(from, device, to, at); return; }
|
|
446
469
|
if (link === undefined || link !== this.linkOf(from) || this.seated.get(device) !== from || name === undefined || this.draining || this.crossings.has(device)) return;
|
|
447
|
-
this.crossings.
|
|
470
|
+
this.crossings.set(device, diagnosticNow());
|
|
448
471
|
try {
|
|
449
472
|
// The road keeps no progress: a seat walks onto it with nothing to read.
|
|
450
473
|
const saved: SavedPlayer = roadHome(to) === null ? await this.options.saves.read(device, cellShard(to)) : { doc: null, seq: 0 };
|
|
@@ -453,6 +476,32 @@ export class World {
|
|
|
453
476
|
...(saved.recovery === undefined ? {} : { recovery: saved.recovery }), ...(saved.previous === undefined ? {} : { previous: saved.previous }) });
|
|
454
477
|
} catch (error) { this.abandon(device, from); this.options.log({ at: 'cell.cross-refused', device, from, to, reason: String(error) }); }
|
|
455
478
|
}
|
|
479
|
+
/**
|
|
480
|
+
* GC15 (3): a seat on one worker's road walks into a cell on another worker. The door reads their save on that cell's shard, the road
|
|
481
|
+
* sends the client `travel` and lets the seat go (`handOut`), and when its port says `out` the door points the same socket at a new port
|
|
482
|
+
* into the target's worker, which seats them at `at` and hears their hello again (`arrive`). The socket never closes.
|
|
483
|
+
*/
|
|
484
|
+
private async crossWorkers(from: string, device: string, to: string, at: ResumeAt): Promise<void> {
|
|
485
|
+
const source = this.linkOf(from), name = this.names.get(device);
|
|
486
|
+
if (source === undefined || this.seated.get(device) !== from || name === undefined || this.draining || this.crossings.has(device) || !this.seatSockets.has(device)) return;
|
|
487
|
+
this.crossings.set(device, diagnosticNow());
|
|
488
|
+
try {
|
|
489
|
+
const saved = await this.options.saves.read(device, cellShard(to));
|
|
490
|
+
if (this.seated.get(device) !== from || this.draining || !this.seatSockets.has(device)) { this.abandon(device, from); return; }
|
|
491
|
+
this.outs.set(device, { from, to, at, entry: { device, name, body: bodyId(this.options.secret, device), doc: saved.doc, seq: saved.seq,
|
|
492
|
+
...(saved.recovery === undefined ? {} : { recovery: saved.recovery }), ...(saved.previous === undefined ? {} : { previous: saved.previous }) } });
|
|
493
|
+
source.send({ kind: 'handOut', from, device, to });
|
|
494
|
+
} catch (error) { this.outs.delete(device); this.abandon(device, from); this.options.log({ at: 'cell.cross-refused', device, from, to, reason: String(error) }); }
|
|
495
|
+
}
|
|
496
|
+
/** GC15 (3): the source let the seat go and everything it said is on its way: the socket now pumps into the target's worker. */
|
|
497
|
+
private movedOut(device: string, end: SocketTransport, motion: unknown): void {
|
|
498
|
+
const out = this.outs.get(device), kept = this.seatSockets.get(device), link = out === undefined ? undefined : this.linkOf(out.to);
|
|
499
|
+
this.outs.delete(device);
|
|
500
|
+
if (out === undefined || kept?.end !== end || link === undefined || !end.isOpen || this.draining) { this.abandon(device, out?.from ?? ''); end.close(this.draining ? 'restart' : 'retry'); return; }
|
|
501
|
+
const { port1, port2 } = new MessageChannel(), hello = kept.hello.slice(0);
|
|
502
|
+
pumpSocket(end, port1, undefined, next => { this.movedOut(device, end, next); });
|
|
503
|
+
link.send({ kind: 'arrive', from: out.from, to: out.to, at: out.at, port: port2, hello, motion: motion as MotionSnapshot | null, ...out.entry }, [port2, hello]);
|
|
504
|
+
}
|
|
456
505
|
/** A crossing that never reached its worker: a `left` the source said meanwhile counts now. */
|
|
457
506
|
private abandon(device: string, from: string): void {
|
|
458
507
|
this.crossings.delete(device);
|
|
@@ -479,7 +528,16 @@ export class World {
|
|
|
479
528
|
});
|
|
480
529
|
end.onClose(off);end.control('playtest');
|
|
481
530
|
}
|
|
482
|
-
|
|
531
|
+
this.seatSockets.set(entry.device, { end, hello: hello.slice(0) });
|
|
532
|
+
end.onClose(() => {
|
|
533
|
+
if (this.seatSockets.get(entry.device)?.end !== end) return;
|
|
534
|
+
this.seatSockets.delete(entry.device);
|
|
535
|
+
// GC15 (3), review MUST: the socket went while a crossing onto another worker waited for its `out`, which this close swallowed:
|
|
536
|
+
// the crossing is off, and a `left` the road said (or says next) frees the seat
|
|
537
|
+
const out = this.outs.get(entry.device);
|
|
538
|
+
if (out !== undefined) { this.outs.delete(entry.device); this.abandon(entry.device, out.from); }
|
|
539
|
+
});
|
|
540
|
+
pumpSocket(end, port1, undefined, motion => { this.movedOut(entry.device, end, motion); });
|
|
483
541
|
const rebody = this.voice.attach(end, slug, entry.name, entry.body);
|
|
484
542
|
this.voiceBodies.set(entry.device, rebody);
|
|
485
543
|
end.onClose(() => { if (this.voiceBodies.get(entry.device) === rebody) this.voiceBodies.delete(entry.device); });
|
|
@@ -14,7 +14,7 @@ import { createHash } from 'node:crypto';
|
|
|
14
14
|
import { pathToFileURL } from 'node:url';
|
|
15
15
|
import { validateShardfileAssets } from '@wildshard/format/assetAdmission';
|
|
16
16
|
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
17
|
-
import { offlineMemoryAdmission, prepareAssetDecoders } from '@wildshard/format/
|
|
17
|
+
import { offlineMemoryAdmission, prepareAssetDecoders } from '@wildshard/format/shardfileAssets';
|
|
18
18
|
import { TickWorkerHost } from './tickWorkerHost';
|
|
19
19
|
import { AuthorProofPlanSchema, TickCommandSchema, type HeadlessCommand, type AuthorProofPlan, type AuthorProofReport, type HeadlessCommandSource, type HeadlessTickCommit, type HeadlessTapePartReport } from '../../shared/host/tickProtocol';
|
|
20
20
|
import * as v from 'valibot';
|
|
@@ -3,7 +3,7 @@ import * as v from 'valibot';
|
|
|
3
3
|
import { runHeadlessJourney } from '../../shared/host/headlessJourney';
|
|
4
4
|
import { registerNativeQuestInputs } from '@wildshard/engine/game/quest/nativeInputs';
|
|
5
5
|
import { hasDeclaredClientPage } from '@wildshard/format/runtimeBinds';
|
|
6
|
-
import { prepareAssetDecoders } from '@wildshard/format/
|
|
6
|
+
import { prepareAssetDecoders } from '@wildshard/format/shardfileAssets';
|
|
7
7
|
import { parseNativeRuntimePlan } from '@wildshard/format/nativeRuntimePlan';
|
|
8
8
|
import { MoverScriptDriver, type MoverRuntime } from '@wildshard/engine/game/plugin/mover';
|
|
9
9
|
import { installRopeDecks } from './ropeDecks';
|
|
@@ -23,19 +23,31 @@ const WALL = 0.5, WALL_HEIGHT = 30;
|
|
|
23
23
|
const WALL_OFF = 2;
|
|
24
24
|
export const ROAD: SimLevel = { version: SIM_API_VERSION, id: 'grid-road', seed: 1, ground: { size: ROAD_HALF_SIZE * 2, height: FALL_FLOOR }, player: { at: { x: 0, y: 0, z: 0 }, yaw: 0, speed: ROAD_SPEED }, entities: [], quests: [], weapon: HOST_PROBE };
|
|
25
25
|
|
|
26
|
+
/** Each road world's cell walls, by the cell they stand round, so GC15 (3) can open one a walker can now cross into. */
|
|
27
|
+
const walls = new WeakMap<SimHost, Map<string, Collider[]>>();
|
|
26
28
|
/**
|
|
27
29
|
* A wall around every cell in the road's own world, as the page's readiness walls are while a cell loads. A player stops just short of
|
|
28
30
|
* a cell until its world is ready and the crossing takes them in, 6 m out at most; the road never runs on under a cell's own
|
|
29
31
|
* hills, where a late hand-off would set them down inside one. A cell's terrain can end in a bank above road level at its very edge,
|
|
30
32
|
* and a capsule set down touching that bank stays stuck in it, so the wall stands clear of it.
|
|
31
33
|
*/
|
|
32
|
-
export function addCellWalls(road: SimHost, cells: readonly Pick<GridCell, 'origin'>[]): void {
|
|
34
|
+
export function addCellWalls(road: SimHost, cells: readonly (Pick<GridCell, 'origin'> & { readonly instance?: string })[]): void {
|
|
33
35
|
const { R, world } = road.physics, reach = CHUNK_HALF + WALL_OFF + WALL / 2, long = reach + WALL / 2;
|
|
36
|
+
const kept = walls.get(road) ?? new Map<string, Collider[]>();
|
|
37
|
+
walls.set(road, kept);
|
|
34
38
|
withOwner(road.scope, () => {
|
|
35
|
-
for (const { origin } of cells) for (const [x, z, hx, hz] of [[reach, 0, WALL / 2, long], [-reach, 0, WALL / 2, long], [0, reach, long, WALL / 2], [0, -reach, long, WALL / 2]] as const)
|
|
36
|
-
world.createCollider(R.ColliderDesc.cuboid(hx, WALL_HEIGHT, hz).setTranslation(origin.x + x, WALL_HEIGHT, origin.z + z).setCollisionGroups(groups('WORLD')));
|
|
39
|
+
for (const { origin, instance } of cells) for (const [x, z, hx, hz] of [[reach, 0, WALL / 2, long], [-reach, 0, WALL / 2, long], [0, reach, long, WALL / 2], [0, -reach, long, WALL / 2]] as const) {
|
|
40
|
+
const collider = world.createCollider(R.ColliderDesc.cuboid(hx, WALL_HEIGHT, hz).setTranslation(origin.x + x, WALL_HEIGHT, origin.z + z).setCollisionGroups(groups('WORLD')));
|
|
41
|
+
if (instance !== undefined) kept.set(instance, [...kept.get(instance) ?? [], collider]);
|
|
42
|
+
}
|
|
37
43
|
});
|
|
38
44
|
}
|
|
45
|
+
/** GC15 (3): take down the walls round these cells (on another worker, their entryways standing): the road crosses into them now. */
|
|
46
|
+
export function openCellWalls(road: SimHost, instances: readonly string[]): void {
|
|
47
|
+
const kept = walls.get(road);
|
|
48
|
+
if (kept === undefined) return;
|
|
49
|
+
for (const instance of instances) { for (const collider of kept.get(instance) ?? []) if (collider.isValid()) road.physics.world.removeCollider(collider, false); kept.delete(instance); }
|
|
50
|
+
}
|
|
39
51
|
/** Each road world's void floor colliders, so a placement can lift them (SA34a). */
|
|
40
52
|
const floors = new WeakMap<SimHost, readonly Collider[]>();
|
|
41
53
|
/** SA34: the 7 × 7's void, walkable: a road-level floor over every empty cell and out to the rail, and the rim on the rail. */
|
|
@@ -20,6 +20,7 @@ import type { HeadlessRuntimeInput } from '../headlessRuntime';
|
|
|
20
20
|
import { StandaloneGrid } from './gridServer';
|
|
21
21
|
import { isHarnessFlag, isHarnessGod, isHarnessHits, isHarnessJoin, isHarnessMove, isHarnessPlace } from '../../../shared/host/standalone/harnessPlace';
|
|
22
22
|
import { WorkerLoopback } from '../../../shared/host/standalone/workerLoopback';
|
|
23
|
+
import { isDevColliders, swapDevBoxes } from '@wildshard/engine/game/devColliders';
|
|
23
24
|
import { ProgressSaves, ProgressWatch } from './progressWatch';
|
|
24
25
|
|
|
25
26
|
type Boot = Extract<ShellMessage, { kind: 'boot' }>;
|
|
@@ -98,7 +99,9 @@ export function runStandaloneServer(options: StandaloneServerOptions): { dispose
|
|
|
98
99
|
if (restored?.ledger !== undefined) book.restore(restored.ledger);
|
|
99
100
|
server.connect(new WorkerLoopback(game));
|
|
100
101
|
watch.look(server.host, book.filed); // where the world stands before its first tick: what that tick moves is progress
|
|
101
|
-
|
|
102
|
+
// SHARD-SOURCE AP5: `wildshard watch`'s part colliders, in this world as in the page's (DEVSERVER only: the define folds it away)
|
|
103
|
+
const devBoxes = new Map<string, Scope>();
|
|
104
|
+
if (options.harness !== undefined) options.harness.onmessage = (event: MessageEvent<unknown>): void => { const [port] = event.ports; if (typeof __DEVSERVER__ === 'boolean' && __DEVSERVER__ && isDevColliders(event.data)) swapDevBoxes(server.host.physics, server.host.scope, devBoxes, event.data.wildshardDevColliders, event.data.boxes); else if (isHarnessJoin(event.data) && port !== undefined) server.join(event.data, new WorkerLoopback(port)); else if (isHarnessFlag(event.data)) server.raise(event.data.flag); else if (isHarnessMove(event.data)) server.place(event.data, event.data.move); else if (isHarnessPlace(event.data)) server.place(event.data); else if (isHarnessHits(event.data)) server.hardHits(event.data.hits); else if (isHarnessGod(event.data)) server.bossGod(); };
|
|
102
105
|
clock = new ServerClock({ now: diagnosticNow, wait: (ms, run) => { const timer = scope.timeout(ms, run); return () => { scope.cancelTimer(timer); }; },
|
|
103
106
|
step: () => { try { server.tick(); progress(server); } catch (error) { fail(error); } } });
|
|
104
107
|
options.proof?.booted?.(server);
|
|
@@ -7,7 +7,7 @@ import { nodeNamedJsonCheck, nodeOutputDescriptorChecks } from '@wildshard/engin
|
|
|
7
7
|
import { carryOutputDescriptor, isBuildValidatedOutput, outputDescriptor, resolveOutputDescriptor, serverReadsFile } from '@wildshard/engine/game/shardfile/outputDescriptor';
|
|
8
8
|
import { shardProductData } from '@wildshard/engine/game/shardfile/productData';
|
|
9
9
|
import { GRID_COLLISION_BODY, GRID_COLLISION_HEADER, readGridCollision, type GridCollisionStrip } from '@wildshard/engine/game/grid/gridCollision';
|
|
10
|
-
import { readServerPackBook, serverPackBookPath, serverPackFile, serverPackPart, type ServerPackBook, type ServerPackPart } from '@wildshard/engine/game/shardfile/serverPack';
|
|
10
|
+
import { cookIndexPath, readCookedServerIndex, readServerPack, readServerPackBook, serverPackBookPath, serverPackFile, serverPackPart, type ServerPack, type ServerPackBook, type ServerPackPart } from '@wildshard/engine/game/shardfile/serverPack';
|
|
11
11
|
import type { HeadlessRuntimeInput } from '../headlessRuntime';
|
|
12
12
|
import type { HeldRead } from '../../../shared/host/standalone/heldReads';
|
|
13
13
|
|
|
@@ -51,10 +51,29 @@ function besideShard(path: string, root: string): URL {
|
|
|
51
51
|
if (!path.startsWith('/') || path.startsWith('//') || at === -1) return new URL(path, base);
|
|
52
52
|
return new URL(`.${path}`, new URL(base.pathname.slice(0, at + 1), base));
|
|
53
53
|
}
|
|
54
|
+
/** A JSON file beside a shard's base, by its path from the origin's root. `fresh` asks past any cache with a query of its own: a CDN keeps a
|
|
55
|
+
* 404 for a while, and a cook index that is missing now may be written a minute later. A `file:` origin reads `path` and ignores it. */
|
|
56
|
+
async function originJson(root: string, path: string, read: ServerRead, fresh = false): Promise<unknown> {
|
|
57
|
+
const url = besideShard(`/${path}`, root);
|
|
58
|
+
if (fresh) url.search = `?t=${String(Date.now())}`;
|
|
59
|
+
return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(await read(url, path)));
|
|
60
|
+
}
|
|
54
61
|
/** This build's server book. */
|
|
55
62
|
async function serverBook(root: string, build: string, read: ServerRead): Promise<ServerPackBook> {
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
return readServerPackBook(await originJson(root, serverPackBookPath(build), read));
|
|
64
|
+
}
|
|
65
|
+
/** The leading `_` a grid slug may carry is not the shard's (shard-format `shardSlugOf`). */
|
|
66
|
+
const shardOf = (slug: string): string => slug.replace(/^_/u, '');
|
|
67
|
+
/**
|
|
68
|
+
* SA47: a placed slug this build's book has no row for (a new author's, uploaded after the build), from the cook's index for this build
|
|
69
|
+
* and these bytes (MMO-SERVER MS2.4): `index/<build>/<hash>.json` names the pack the cook wrote beside its parts. The parts are read by
|
|
70
|
+
* their hash as a book's are, so the index only says where they are. A missing index throws, as a missing row does.
|
|
71
|
+
*/
|
|
72
|
+
async function cookedPack(root: string, slug: string, cooked: Readonly<{ build: string; hash: string }>, read: ServerRead): Promise<ServerPack> {
|
|
73
|
+
const { build, hash } = cooked, path = cookIndexPath(build, hash), index = readCookedServerIndex(await originJson(root, path, read, true));
|
|
74
|
+
if (index.build !== build || index.hash !== hash || shardOf(index.slug) !== shardOf(slug)) throw new Error(`The cook's ${path} is not ${slug}'s`);
|
|
75
|
+
if (index.serverPack === undefined) throw new Error(`No server pack for ${slug} in the cook's ${path}`);
|
|
76
|
+
return readServerPack(await originJson(root, index.serverPack.index.slice(1), read));
|
|
58
77
|
}
|
|
59
78
|
|
|
60
79
|
/** C2: the road's collision from this build's grid pack: nothing a page reads, and no shard's. */
|
|
@@ -79,9 +98,21 @@ export async function readGridCollisionPack(root: string, build: string, read: S
|
|
|
79
98
|
/** C2: reads a server file from its product's pack, fetching the book once and a part only for a file it holds. The browser
|
|
80
99
|
* undoes `br`. A read file is copied out and its part left to the collector: a phone's worker shouldn't hold a level's worth
|
|
81
100
|
* of them, and reading one again is a cache hit. */
|
|
82
|
-
function serverPackReader(root: string, slug: string, build: () => string, source: ServerRead): (path: string) => Promise<Uint8Array> {
|
|
101
|
+
function serverPackReader(root: string, slug: string, build: () => string, source: ServerRead, hash?: string): (path: string) => Promise<Uint8Array> {
|
|
83
102
|
const opening = new Map<string, Promise<Uint8Array>>(), opened = new Map<string, WeakRef<Uint8Array>>();
|
|
84
|
-
let book: Promise<ServerPackBook> | undefined;
|
|
103
|
+
let pack: Promise<ServerPack> | undefined, book: Promise<ServerPackBook> | undefined;
|
|
104
|
+
// SA47: the book wins; only a slug it has no row for, with the shardfile hash its placement names, reads the cook's index. The book
|
|
105
|
+
// is read once, as before SA47; only a refused index is asked again (review)
|
|
106
|
+
const packOf = async (): Promise<ServerPack> => {
|
|
107
|
+
const row = (await (book ??= serverBook(root, build(), source))).shards[slug];
|
|
108
|
+
if (row !== undefined) return row;
|
|
109
|
+
if (hash === undefined) throw new Error(`No server pack for ${slug}`);
|
|
110
|
+
return cookedPack(root, slug, { build: build(), hash }, source);
|
|
111
|
+
};
|
|
112
|
+
// A refusal is not kept: the next read (the next look, SA33) asks again.
|
|
113
|
+
const packOnce = async (): Promise<ServerPack> => {
|
|
114
|
+
try { return await packOf(); } catch (error) { pack = undefined; throw error; }
|
|
115
|
+
};
|
|
85
116
|
const body = (part: ServerPackPart): Promise<Uint8Array> => {
|
|
86
117
|
const kept = opened.get(part.url)?.deref();
|
|
87
118
|
if (kept !== undefined) return Promise.resolve(kept);
|
|
@@ -92,9 +123,7 @@ function serverPackReader(root: string, slug: string, build: () => string, sourc
|
|
|
92
123
|
return read;
|
|
93
124
|
};
|
|
94
125
|
return async path => {
|
|
95
|
-
const
|
|
96
|
-
if (pack === undefined) throw new Error(`No server pack for ${slug}`);
|
|
97
|
-
const part = serverPackPart(pack, path), bytes = part === undefined ? undefined : serverPackFile(part, await body(part), path);
|
|
126
|
+
const part = serverPackPart(await (pack ??= packOnce()), path), bytes = part === undefined ? undefined : serverPackFile(part, await body(part), path);
|
|
98
127
|
if (bytes === undefined) throw new Error(`Missing server input ${path}`);
|
|
99
128
|
return bytes.slice();
|
|
100
129
|
};
|
|
@@ -107,12 +136,13 @@ function serverPackReader(root: string, slug: string, build: () => string, sourc
|
|
|
107
136
|
export function fetchServerProduct(base: string, rapier: Rapier, held?: HeldRead): Promise<HeadlessRuntimeInput> {
|
|
108
137
|
return readServerProduct(new URL(base, globalThis.location.href).href, workerBuild, serverBytes, rapier, held);
|
|
109
138
|
}
|
|
110
|
-
/** A shard's server inputs under `root`, whichever server is reading: `source` is what differs.
|
|
111
|
-
|
|
139
|
+
/** A shard's server inputs under `root`, whichever server is reading: `source` is what differs. `hash`, a placed slug's shardfile (SA47),
|
|
140
|
+
* lets a slug the build's book lacks open from the cook's index. */
|
|
141
|
+
export async function readServerProduct(root: string, build: () => string, source: ServerRead, rapier: Rapier, held?: HeldRead, hash?: string): Promise<HeadlessRuntimeInput> {
|
|
112
142
|
const slug = new URL('.', root).pathname.split('/').at(-2) ?? '';
|
|
113
143
|
// C2: all of it is in the pack this build's book names, the server class only there (J91). The page lends what it holds
|
|
114
144
|
// (DL25), so that moves no bytes. A host with no book, or one offline after a new build, reads what the device kept.
|
|
115
|
-
const serverFile = serverPackReader(root, slug, build, source);
|
|
145
|
+
const serverFile = serverPackReader(root, slug, build, source, hash);
|
|
116
146
|
const read = async (path: string): Promise<Uint8Array> => {
|
|
117
147
|
if (path.startsWith('server/')) return serverFile(path);
|
|
118
148
|
const url = new URL(path, root), lent = await held?.(url.href);
|