@wildshard/engine 0.1.15 → 0.1.18
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 +23 -0
- package/index.html +157 -11
- package/lint/engine-sides.json +23 -0
- package/lint/host-callback-syntax.mjs +2 -1
- package/lint/host-callbacks.mjs +3 -3
- package/lint/host-files.mjs +5 -4
- package/lint/host-register.json +496 -0
- package/lint/no-base64.mjs +3 -1
- package/lint/ratchet.json +2 -2
- package/lint/shard-imports.d.mts +1 -0
- package/lint/shard-imports.mjs +60 -13
- package/lint/shard-source.d.mts +9 -0
- package/lint/shard-source.mjs +91 -0
- package/lint/shardfile-boundaries.mjs +10 -8
- package/lint/sim-closure.mjs +6 -3
- package/lint/wildshard-plugin.d.ts +4 -0
- package/lint/wildshard-plugin.js +44 -27
- package/package.json +24 -6
- package/scripts/app-build/buildIdentity.d.mts +3 -1
- package/scripts/app-build/buildIdentity.mjs +25 -5
- package/scripts/app-build/builtAt.d.mts +4 -0
- package/scripts/app-build/builtAt.mjs +21 -0
- package/scripts/app-build/outputProducts.d.mts +3 -0
- package/scripts/app-build/outputProducts.mjs +31 -0
- package/scripts/app-build/serviceWorker.ts +16 -2
- package/scripts/app-build/versionFiles.ts +2 -1
- package/scripts/app-build-pipeline.mjs +7 -1
- package/scripts/audio-download-proof.mjs +843 -0
- package/scripts/build-app.mjs +4 -0
- package/scripts/build-mirror.d.mts +2 -0
- package/scripts/build-mirror.mjs +5 -4
- package/scripts/built-product.mjs +3 -3
- package/scripts/cell-mem/metrics-preload.mjs +65 -0
- package/scripts/cell-mem-bench.mjs +130 -0
- package/scripts/check-chunks.mjs +2 -1
- package/scripts/check-devserver.mjs +1 -1
- package/scripts/chromium-keychain-check.mjs +4 -2
- package/scripts/chromium-keychain.mjs +3 -1
- package/scripts/cook.mjs +7 -3
- package/scripts/devices.d.mts +4 -0
- package/scripts/devices.mjs +39 -0
- package/scripts/devserver-client.d.mts +7 -0
- package/scripts/devserver-client.mjs +85 -0
- package/scripts/doctor-proof.mjs +1 -1
- package/scripts/e2e-faults.mjs +159 -0
- package/scripts/engine-ci-budget.ts +7 -1
- package/scripts/format-lock.mjs +20 -11
- package/scripts/generate-title-launch.mjs +3 -2
- package/scripts/grid-crossing-walk-proof.mjs +30 -11
- package/scripts/heavy-lane.py +25 -1
- package/scripts/host-ruler/register-migrate.mjs +242 -0
- package/scripts/host-ruler/register.d.mts +36 -0
- package/scripts/host-ruler/register.mjs +116 -0
- package/scripts/host-ruler/roots.d.mts +29 -0
- package/scripts/host-ruler/roots.mjs +333 -0
- package/scripts/host-ruler/server-roots.d.mts +23 -0
- package/scripts/host-ruler/server-roots.mjs +272 -0
- package/scripts/main-watch.d.mts +1 -1
- package/scripts/main-watch.mjs +10 -6
- package/scripts/map-hash.mjs +3 -6
- package/scripts/memory-proof.mjs +158 -0
- package/scripts/mmo-bots.mjs +2 -2
- package/scripts/offline-proof-rules.d.mts +5 -2
- package/scripts/offline-proof-rules.mjs +43 -6
- package/scripts/offline-proof.mjs +15 -6
- package/scripts/online-rig.mjs +4 -4
- package/scripts/page-release/flow.d.mts +1 -0
- package/scripts/page-release/flow.mjs +6 -2
- package/scripts/page-release.mjs +5 -1
- package/scripts/physics-route.json +0 -71
- package/scripts/pins-catalogue.ts +103 -0
- package/scripts/pins-reuse.mjs +3 -1
- package/scripts/pins.ts +22 -14
- package/scripts/preview-grid.ts +203 -0
- package/scripts/road-preload-proof.mjs +167 -0
- package/scripts/server-release/publish.mjs +2 -2
- package/scripts/server-release/served-slug.d.mts +2 -0
- package/scripts/server-release/served-slug.mjs +10 -0
- package/scripts/server-release/sign.d.mts +1 -0
- package/scripts/server-release/sign.mjs +3 -7
- package/scripts/shard-components.mjs +0 -2
- package/scripts/shard-outputs.d.mts +8 -0
- package/scripts/shard-outputs.mjs +45 -11
- package/scripts/side-parity.d.mts +2 -1
- package/scripts/side-parity.mjs +25 -4
- package/scripts/test-amber.d.mts +1 -0
- package/scripts/test-amber.mjs +10 -0
- package/scripts/test-products.json +3 -3
- package/scripts/tier-textures-proof.mjs +101 -0
- package/scripts/tier-textures.mjs +60 -0
- package/scripts/tracked-public.d.mts +1 -0
- package/scripts/tracked-public.mjs +17 -0
- package/scripts/tsconfig.json +1 -0
- package/scripts/vps/wildshard-config +79 -23
- package/scripts/worker-client-play.mjs +1 -0
- package/scripts/worker-client-proof.mjs +1 -1
- package/scripts/worker-client-slug.mjs +44 -0
- package/src/cli/engine.mjs +8 -0
- package/src/client/app/bootRoute.ts +4 -1
- package/src/client/app/dropModal.ts +15 -2
- package/src/client/app/entry.ts +96 -13
- package/src/client/app/slugPath.ts +5 -0
- package/src/client/engine/audio/Audio.ts +20 -2
- package/src/client/engine/boot/bakedTextures.ts +3 -2
- package/src/client/engine/boot/bootTrace.ts +6 -1
- package/src/client/engine/boot/bytes.ts +4 -3
- package/src/client/engine/boot/clearDownloads.ts +1 -1
- package/src/client/engine/boot/contentRead.ts +4 -0
- package/src/client/engine/boot/dropNotice.ts +20 -6
- package/src/client/engine/boot/gpuFiles.ts +25 -2
- package/src/client/engine/boot/lastEnd.ts +8 -2
- package/src/client/engine/boot/parsedPages.ts +127 -58
- package/src/client/engine/boot/shardPrefetch.ts +7 -1
- package/src/client/engine/boot/sw.ts +19 -0
- package/src/client/engine/build.d.ts +2 -0
- package/src/client/engine/core/Game.ts +29 -3
- package/src/client/engine/core/GpuRecovery.ts +7 -0
- package/src/client/engine/core/Volumetrics.ts +5 -0
- package/src/client/engine/core/assets.ts +27 -20
- package/src/client/engine/core/bootstrap.ts +5 -3
- package/src/client/engine/core/ktx2.ts +84 -11
- package/src/client/engine/debug/probe.ts +18 -1
- package/src/client/engine/explore/Compare.ts +2 -2
- package/src/client/engine/explore/TouchFly.ts +3 -5
- package/src/client/engine/fx/LightPool.ts +41 -1
- package/src/client/engine/input/dom.ts +12 -0
- package/src/client/engine/net/predictor.ts +6 -2
- package/src/client/engine/player/Player.ts +10 -2
- package/src/client/engine/player/TouchControls.ts +12 -4
- package/src/client/engine/pwa/sw.js +59 -11
- package/src/client/engine/render/drawCheck.ts +96 -0
- package/src/client/engine/render/precompile.ts +20 -14
- package/src/client/engine/saves/staleBuildNote.ts +46 -0
- package/src/client/engine/telemetry/browserErrors.ts +161 -21
- package/src/client/engine/telemetry/deviceSnapshot.ts +155 -0
- package/src/client/engine/telemetry/screenOutbox.ts +61 -0
- package/src/client/engine/telemetry/staleBuildReport.ts +12 -0
- package/src/client/engine/ui/DeathFade.ts +99 -11
- package/src/client/engine/ui/ErrorModal.ts +13 -6
- package/src/client/engine/ui/Feedback.ts +2 -1
- package/src/client/engine/ui/Loading.ts +10 -6
- package/src/client/engine/ui/Map.ts +2 -1
- package/src/client/engine/ui/WeaponStrip.ts +2 -1
- package/src/client/engine/ui/backGuard.ts +104 -0
- package/src/client/engine/ui/hudAdapters.ts +30 -4
- package/src/client/engine/ui/loading.css +17 -0
- package/src/client/engine/ui/namePrompt.ts +6 -5
- package/src/client/engine/ui/styles/combat.css +12 -0
- package/src/client/engine/ui/styles/namePrompt.css +4 -2
- package/src/client/game/boot/audio.generated.ts +0 -396
- package/src/client/game/boot/bytes.generated.ts +42 -71
- package/src/client/game/boot/versions.generated.ts +0 -13
- package/src/client/game/compendium/keepsakes.ts +16 -6
- package/src/client/game/grapple/tool.ts +10 -7
- package/src/client/game/grid/area.ts +38 -0
- package/src/client/game/grid/cellLoading.ts +23 -12
- package/src/client/game/grid/cellScreens.ts +39 -74
- package/src/client/game/grid/live.ts +28 -2
- package/src/client/game/grid/liveSession.ts +54 -10
- package/src/client/game/grid/menu.ts +4 -0
- package/src/client/game/grid/nearPlaceholderPlan.ts +8 -0
- package/src/client/game/grid/nearPlaceholderView.ts +9 -3
- package/src/client/game/grid/neighbourPanels.ts +10 -1
- package/src/client/game/grid/oneWayIn.ts +92 -27
- package/src/client/game/grid/pageEntry.ts +19 -0
- package/src/client/game/grid/pageShell.ts +1 -1
- package/src/client/game/grid/placedCards.ts +55 -0
- package/src/client/game/grid/placedCells.ts +131 -0
- package/src/client/game/grid/plotAudio.ts +114 -0
- package/src/client/game/grid/products.ts +55 -5
- package/src/client/game/grid/regionalRuntime.ts +6 -0
- package/src/client/game/grid/regionalWorld.ts +15 -2
- package/src/client/game/grid/roadCull.ts +44 -14
- package/src/client/game/grid/roadLookPlatform.ts +2 -2
- package/src/client/game/grid/roadTileBacking.ts +13 -3
- package/src/client/game/grid/session.ts +47 -22
- package/src/client/game/grid/shardfileFar.ts +9 -3
- package/src/client/game/grid/spawnGround.ts +68 -0
- package/src/client/game/grid/voidLook.ts +29 -23
- package/src/client/game/loot/runtime.ts +3 -1
- package/src/client/game/mainMenu.ts +14 -6
- package/src/client/game/riding/hud.ts +6 -4
- package/src/client/game/session/finish.ts +22 -4
- package/src/client/game/session/play.ts +8 -2
- package/src/client/game/session/session.ts +4 -1
- package/src/client/game/shard/titleList.ts +6 -2
- package/src/client/game/shardfile/clientWorker.ts +43 -13
- package/src/client/game/shardfile/serverRoute.ts +10 -22
- package/src/client/game/slugPage.css +11 -0
- package/src/client/game/slugPage.ts +84 -0
- package/src/client/game/systems/viewmodel/heldView.ts +6 -3
- package/src/client/game/titleDeck.ts +56 -32
- package/src/client/host/online/doctor.ts +7 -6
- package/src/client/host/online/linkScreens.ts +16 -0
- package/src/client/host/online/release.ts +51 -5
- package/src/client/host/online/shell.ts +62 -27
- package/src/client/host/standalone/shell.ts +7 -3
- package/src/cook/game/audioReport.ts +57 -0
- package/src/cook/game/entryTotals.ts +26 -6
- package/src/cook/game/installedRuntimeReads.ts +3 -0
- package/src/cook/game/shardCook.ts +38 -8
- package/src/cook/game/tierTextures.ts +276 -0
- package/src/e2e/smoke/game.ts +19 -14
- package/src/e2e/smoke/page-globals.d.ts +9 -8
- package/src/e2e/smoke/template2.spec.ts +8 -7
- package/src/server/engine/sim/respawn.ts +6 -1
- package/src/server/engine/sim.ts +3 -0
- package/src/server/game/grid/simulation.ts +35 -0
- package/src/server/game/loot/harvest.ts +2 -0
- package/src/server/game/loot/keepsakeProgression.ts +40 -0
- package/src/server/game/loot/playerOwned.ts +5 -1
- package/src/server/game/plugin/simulation.ts +4 -0
- package/src/server/game/population/nativeBake.ts +2 -1
- package/src/server/game/quest/chapterRecords.ts +2 -0
- package/src/server/game/quest/serverChapters.ts +4 -0
- package/src/server/game/quest/serverDoors.ts +11 -5
- package/src/server/game/roomRespawn.ts +4 -0
- package/src/server/game/shardfile/installedSides.ts +18 -0
- package/src/server/game/shardfile/nativeAssemblyHosts.ts +19 -10
- package/src/server/game/shardfile/nativeAssemblyInput.ts +1 -4
- package/src/server/host/bake/headlessWorker.ts +5 -1
- package/src/server/host/dedicated/cellHost.ts +98 -29
- package/src/server/host/dedicated/cellProtocol.ts +11 -1
- package/src/server/host/dedicated/cellWorker.ts +9 -3
- package/src/server/host/dedicated/crossing.ts +6 -2
- package/src/server/host/dedicated/dedicatedRoom.ts +21 -8
- package/src/server/host/dedicated/gridCells.ts +52 -9
- package/src/server/host/dedicated/main.ts +31 -12
- package/src/server/host/dedicated/placementFile.ts +56 -0
- package/src/server/host/dedicated/releaseFile.ts +17 -10
- package/src/server/host/dedicated/roadRoom.ts +21 -5
- package/src/server/host/dedicated/socketTransport.ts +2 -1
- package/src/server/host/dedicated/workerTable.ts +13 -1
- package/src/server/host/dedicated/world.ts +111 -10
- package/src/server/host/headlessRuntime.ts +10 -5
- package/src/server/host/installers.ts +62 -0
- package/src/server/host/openWorld.ts +59 -0
- package/src/server/host/ropeDecks.ts +2 -0
- package/src/server/host/standalone/cellWorld.ts +25 -19
- package/src/server/host/standalone/fallFloor.ts +2 -2
- package/src/server/host/standalone/gridServer.ts +7 -4
- package/src/server/host/standalone/roadWorld.ts +41 -4
- package/src/shared/engine/audio/bootAudio.ts +33 -0
- package/src/shared/engine/level/spec.ts +3 -3
- package/src/shared/engine/net/acts.ts +3 -0
- package/src/shared/engine/net/deviceWord.ts +138 -0
- package/src/shared/engine/net/socketFrames.ts +7 -4
- package/src/shared/engine/physics/query.ts +27 -0
- package/src/shared/engine/physics/terrain.ts +19 -28
- package/src/shared/engine/saves/saves.lock.json +15 -0
- package/src/shared/engine/sim/actRoutes.ts +2 -0
- package/src/shared/game/compendium/keepsakeProgression.ts +24 -0
- package/src/shared/game/grid/catalogue.ts +12 -5
- package/src/shared/game/grid/catalogueSlot.ts +18 -0
- package/src/shared/game/grid/farProxy.ts +6 -5
- package/src/shared/game/grid/pageMode.ts +1 -1
- package/src/shared/game/grid/placementRows.ts +33 -0
- package/src/shared/game/grid/roadLayout.ts +26 -3
- package/src/shared/game/grid/singleplayer.json +0 -13
- package/src/shared/game/grid/voidFloor.ts +122 -0
- package/src/shared/game/strings.ts +15 -0
- package/src/shared/host/standalone/netInput.ts +2 -1
|
@@ -28,6 +28,7 @@ import { questObservation, type ObservedRecords } from '../../../shared/game/que
|
|
|
28
28
|
import type { QuestStepEffect } from '../../../shared/game/quest/steps';
|
|
29
29
|
import type { ShardProduct } from '../../../shared/game/shardfile/shardProduct';
|
|
30
30
|
import { mountedPlayerOf } from '../riding/native';
|
|
31
|
+
import { registerInstalled } from '../shardfile/installedSides';
|
|
31
32
|
|
|
32
33
|
/** The file that says a shard's story runs on its chapters. */
|
|
33
34
|
export const CHAPTER_CONTENT = 'quests/content.json';
|
|
@@ -188,5 +189,8 @@ export async function installServerChapters(host: SimHost, product: ShardProduct
|
|
|
188
189
|
}
|
|
189
190
|
});
|
|
190
191
|
host.scope.onDispose(() => { for (const seat of seats.values()) seat.off(); seats.clear(); });
|
|
192
|
+
// SS3b: `state.adventure`'s server half: the same quests/persistence.json rows, each player's feat counts and bond kept as
|
|
193
|
+
// their own book's flags (saved with the room), where the page keeps one device's records
|
|
194
|
+
if (counters !== undefined || saved.bond !== undefined) registerInstalled(host, 'saves');
|
|
191
195
|
return true;
|
|
192
196
|
}
|
|
@@ -41,8 +41,9 @@ function pieceColliders(host: SimHost): ReadonlyMap<string, Collider> {
|
|
|
41
41
|
return found;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/** Keep the building doors of a shard that has them. False when it has none. `opened`: what a page's save left open, for a world's first boot.
|
|
45
|
-
|
|
44
|
+
/** Keep the building doors of a shard that has them. False when it has none. `opened`: what a page's save left open, for a world's first boot.
|
|
45
|
+
* `restored`: a world restored from its save, whose leaves already stand where the save put them. */
|
|
46
|
+
export async function installServerDoors(host: SimHost, product: ShardProduct | undefined, opened: ReadonlySet<string> = new Set(), restored = false): Promise<boolean> {
|
|
46
47
|
if (product === undefined || !product.hasFile(PIECES) || !product.hasFile(FOREST)) return false;
|
|
47
48
|
const [piecesInput, forestInput, compositionInput] = await Promise.all([product.json<unknown>(PIECES), product.json<unknown>(FOREST), product.hasFile(COMPOSITION) ? product.json<unknown>(COMPOSITION) : null]);
|
|
48
49
|
const look = v.parse(Forest, forestInput).buildings?.life.door, composition = compositionInput === null ? undefined : v.parse(Composition, compositionInput).door;
|
|
@@ -52,11 +53,14 @@ export async function installServerDoors(host: SimHost, product: ShardProduct |
|
|
|
52
53
|
for (const row of rows) {
|
|
53
54
|
const collider = colliders.get(row.id), matrix = row.follows?.matrix;
|
|
54
55
|
if (row.category !== 'buildings' || row.follows?.rotation !== true || matrix === undefined || collider === undefined || rows.some(other => other.id === row.id.replace(/-bar$/u, '') && other.id !== row.id)) continue;
|
|
55
|
-
const hinge = { x: matrix[12] ?? 0, y: matrix[13] ?? 0, z: matrix[14] ?? 0 }, rotation = collider.rotation(), at = collider.translation();
|
|
56
|
-
const local = turned(conjugate(rotation), { x: at.x - hinge.x, y: at.y - hinge.y, z: at.z - hinge.z });
|
|
57
56
|
const door = buildingDoor(row.id), flag = buildingDoorFlag(row.id);
|
|
58
57
|
if (opened.has(row.id)) host.flags.set(flag);
|
|
59
58
|
door.open = host.flags.has(flag); door.t = door.open ? 1 : 0;
|
|
59
|
+
// A fresh world's leaf stands shut, as baked. A restored one stands where its save put it (open, if its flag is), so its
|
|
60
|
+
// shut pose is that one turned back.
|
|
61
|
+
const hinge = { x: matrix[12] ?? 0, y: matrix[13] ?? 0, z: matrix[14] ?? 0 }, standing = collider.rotation(), at = collider.translation();
|
|
62
|
+
const rotation = restored ? times(standing, yawOf(-buildingDoorYaw(door.t, look.angle))) : standing;
|
|
63
|
+
const local = turned(conjugate(standing), { x: at.x - hinge.x, y: at.y - hinge.y, z: at.z - hinge.z });
|
|
60
64
|
leaves.push({ door, flag, collider, hinge, rotation, local, bars: bars.filter(gate => gate.target.piece === row.id).map(gate => gate as { readonly opensWhen: Parameters<typeof test>[1] }) });
|
|
61
65
|
}
|
|
62
66
|
if (leaves.length === 0) return false;
|
|
@@ -66,7 +70,9 @@ export async function installServerDoors(host: SimHost, product: ShardProduct |
|
|
|
66
70
|
leaf.collider.setRotation(q); leaf.collider.setTranslation({ x: leaf.hinge.x + at.x, y: leaf.hinge.y + at.y, z: leaf.hinge.z + at.z });
|
|
67
71
|
};
|
|
68
72
|
for (const leaf of leaves) {
|
|
69
|
-
|
|
73
|
+
// A restored leaf is left where it stands: posing it again moves it by a rounding error and re-files it in the broad
|
|
74
|
+
// phase, so the resumed world's physics would no longer match the world that never stopped (HS1).
|
|
75
|
+
if (!restored) pose(leaf);
|
|
70
76
|
routes.claims.set(leaf.door.id, player => {
|
|
71
77
|
const body = host.players.get(player);
|
|
72
78
|
if (body === undefined || Math.hypot(body.position.x - leaf.hinge.x, body.position.z - leaf.hinge.z) > DOOR_REACH + Math.hypot(leaf.local.x, leaf.local.z)) return;
|
|
@@ -57,4 +57,8 @@ export function installRoomRespawn(host: SimHost, places: readonly PlaceArea[]):
|
|
|
57
57
|
lastUnstuck.set(id, tick);
|
|
58
58
|
place(player);
|
|
59
59
|
};
|
|
60
|
+
// QA 11-13 (Jake: "It needs a button, a Respawn now button"): the death card's button. The fall already placed the player;
|
|
61
|
+
// this only ends their own fade early, so their commands move them again. It moves nobody and gives no cover: the fade is
|
|
62
|
+
// the fallen player's only shield, and they are the only one who can end it.
|
|
63
|
+
actRoutes(host).respawnNow = id => { if (host.players.has(id)) book.skipFade(id); };
|
|
60
64
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SERVER-PARITY SS3: the per-host record of which SS2 server halves an installer built. The game's installers register here
|
|
2
|
+
// (a game module can't import the host layer); src/server/host/installers.ts names each key's owners and checks a product.
|
|
3
|
+
import type { SimHost } from '@wildshard/engine/sim';
|
|
4
|
+
|
|
5
|
+
/** Every server key shard-format's SS2 side table (`featureSides`) names for a `both` or `server` kind. */
|
|
6
|
+
export type ServerInstallerKey = 'arenaRoom' | 'collision' | 'fallFloor' | 'grapple' | 'harvest' | 'heldArms' | 'heldBoss' | 'heldRanged' | 'keepsakes'
|
|
7
|
+
| 'loadout' | 'melee' | 'movers' | 'places' | 'portalRide' | 'poseViews' | 'questComposition' | 'questHost' | 'ropeDecks' | 'saves' | 'slots'
|
|
8
|
+
| 'stealth' | 'windElite';
|
|
9
|
+
|
|
10
|
+
const installed = new WeakMap<SimHost, Set<ServerInstallerKey>>();
|
|
11
|
+
|
|
12
|
+
/** An installer built `key`'s server half on `host`. Install and restore both register; the record lives as long as the host. */
|
|
13
|
+
export function registerInstalled(host: SimHost, key: ServerInstallerKey): void {
|
|
14
|
+
const keys = installed.get(host);
|
|
15
|
+
if (keys === undefined) installed.set(host, new Set([key])); else keys.add(key);
|
|
16
|
+
}
|
|
17
|
+
/** The keys whose installers ran on `host`. */
|
|
18
|
+
export function installedKeys(host: SimHost): ReadonlySet<ServerInstallerKey> { return installed.get(host) ?? new Set(); }
|
|
@@ -64,6 +64,7 @@ import { nativeDecisionAuthority } from './borrowedDecisions';
|
|
|
64
64
|
import { installNativeGroupRows } from './groupRuntime';
|
|
65
65
|
import { need, readAssemblyInput, type AssemblyPrepared, type NativeAssemblyContext } from './nativeAssemblyInput';
|
|
66
66
|
import { installBodyScripts, installCombatMotion } from './nativeRuntimeLoans';
|
|
67
|
+
import { registerInstalled } from './installedSides';
|
|
67
68
|
|
|
68
69
|
/** What one install's hosts hand each other, in the plan's order. A later host reads what an earlier one left. */
|
|
69
70
|
export interface AssemblyRun<C extends NativeAssemblyContext> {
|
|
@@ -93,7 +94,7 @@ async function prepareQuest<C extends NativeAssemblyContext>(row: Extract<Native
|
|
|
93
94
|
const props = row.props === undefined ? undefined : await read<unknown>(row.props);
|
|
94
95
|
const trades = row.barter === true ? parseBarterEconomy(need(shard.rows.loot[0], 'Missing barter row').economy).exchange : undefined;
|
|
95
96
|
const secret = content === undefined ? undefined : await readNativeQuestSecret(product);
|
|
96
|
-
return run => { run.quest = installNativeQuestComposition(run.host, { source: shard, table, rows, spots: row.readSpots === true ? readNativeQuestSpots(spots) : spots, counters: native,
|
|
97
|
+
return run => { registerInstalled(run.host, 'questComposition'); run.quest = installNativeQuestComposition(run.host, { source: shard, table, rows, spots: row.readSpots === true ? readNativeQuestSpots(spots) : spots, counters: native,
|
|
97
98
|
...(content === undefined ? {} : { steps: content.steps, deaths: content.deaths, readings: content.readings, lead: content.lead }),
|
|
98
99
|
...(contracts === undefined ? {} : { contracts: ownContractCatalogue(contracts, run.host.scope) }), ...(trades === undefined ? {} : { trades }), ...(director === undefined ? {} : { director }),
|
|
99
100
|
...(props === undefined ? {} : { props }), ...(secret === undefined ? {} : { secret }), ...(row.restoring === true ? { restoring: run.context.restoring } : {}) }); };
|
|
@@ -154,7 +155,7 @@ export async function prepareAssemblyFeature<C extends NativeAssemblyContext>(ro
|
|
|
154
155
|
}
|
|
155
156
|
case 'boss.arena': {
|
|
156
157
|
const input = await readAssemblyInput<unknown>(product, { file: row.file }), spec = arenaSpecies(await readAssemblyInput<unknown>(product, { file: 'server/arena-species.json' }));
|
|
157
|
-
return run => { if (run.context.room === true) installArenaEntry(run.host, input, row, { spec, grantItem: at.ports.grantItem(run.context), snapshot: run.context.snapshot }); };
|
|
158
|
+
return run => { if (run.context.room === true) { installArenaEntry(run.host, input, row, { spec, grantItem: at.ports.grantItem(run.context), snapshot: run.context.snapshot }); registerInstalled(run.host, 'arenaRoom'); } };
|
|
158
159
|
}
|
|
159
160
|
case 'held.arms': {
|
|
160
161
|
const arms = await prepareHeldArms(product, { ...row, weather: await readAssemblyInput<unknown>(product, row.weather) }), stealth = prepareNativeStealth(product);
|
|
@@ -163,7 +164,9 @@ export async function prepareAssemblyFeature<C extends NativeAssemblyContext>(ro
|
|
|
163
164
|
contacts: (host, from, direction, distance, hit) => patrolOf(host)?.target(from, direction, distance, hit) ?? hit });
|
|
164
165
|
// SS4: the sneak shot the page doubles, decided here from each player's own Hidden state. Installed after the arms so
|
|
165
166
|
// exportSeats keeps its indexes; a shot therefore reads the state one tick old, where the page reads the same frame's.
|
|
166
|
-
|
|
167
|
+
// SS3: the held arms own the room's equip swap, the server half of the page's catalogue kit
|
|
168
|
+
registerInstalled(run.host, 'heldArms'); registerInstalled(run.host, 'loadout');
|
|
169
|
+
if (stealth !== null) { stealth(run.host, { tick, groups: run.groups }); registerInstalled(run.host, 'stealth'); } } };
|
|
167
170
|
}
|
|
168
171
|
case 'encounter.patrol': {
|
|
169
172
|
if (at.ports.room !== true) return () => undefined;
|
|
@@ -175,12 +178,14 @@ export async function prepareAssemblyFeature<C extends NativeAssemblyContext>(ro
|
|
|
175
178
|
let captain: NativeCaptain | null = null, windElite: NativeWindElite | null = null;
|
|
176
179
|
const finish = patrol.begin(run.host, { eliteDamage: (host, actor, request) => captain?.scale(actor, request.point) ?? run.arena?.eliteDamage(host, actor, request) ?? 1, beforePatrol: (host, dt) => { slots?.advance(host, dt); captain?.advance(dt); windElite?.advance(dt); }, afterPatrol: (host, dt) => { run.arena?.advance(host, dt); } });
|
|
177
180
|
run.patrol = () => {
|
|
178
|
-
finish();
|
|
181
|
+
finish();
|
|
182
|
+
if (slots !== null) { slots.install(run.host, need(run.bindings, 'Slots need their bindings'), run.context.restoring); registerInstalled(run.host, 'slots'); registerInstalled(run.host, 'poseViews'); }
|
|
179
183
|
if (ride !== null && elites !== undefined) { captain = ride(run.host, decisions => nativeEliteCore(run.host, elites.conditions, decisions, dayOf(run), need(run.wild, 'A captain needs his environment')), `${row.step}.captain`); if (captain.lair.record !== undefined) need(run.eliteCore, 'A captain needs the world\'s lairs').share(captain.lair.id, captain.lair.record); }
|
|
180
184
|
if (fly !== null && elites !== undefined) {
|
|
181
185
|
const env = need(run.wild, 'A wind elite needs its environment'), world = need(run.eliteCore, 'A wind elite needs the world\'s lairs');
|
|
182
186
|
windElite = fly(run.host, need(run.bindings, 'A wind elite needs its bindings'), () => nativeEliteCore(run.host, elites.conditions, ReturnProgram.native(run.host, bootOf(at).admission), dayOf(run), env), `${row.step}.wind`, () => env.wind);
|
|
183
187
|
if (windElite.lair.record !== undefined) world.share(windElite.lair.id, windElite.lair.record);
|
|
188
|
+
registerInstalled(run.host, 'windElite');
|
|
184
189
|
}
|
|
185
190
|
};
|
|
186
191
|
};
|
|
@@ -192,6 +197,7 @@ export async function prepareAssemblyFeature<C extends NativeAssemblyContext>(ro
|
|
|
192
197
|
const { host, context } = run; run.arena = arena;
|
|
193
198
|
arena.observeWeather(host, need(run.weather, 'An open arena needs its weather')); arena.cover(host); need(run.patrol, 'An open arena needs its patrol')();
|
|
194
199
|
arena.install(host, { presentation: need(at.ports.arena, 'An open arena needs its presentation'), commands: at.ports.heldTick(context).commands, ledger: at.ports.ledger(context), restoring: context.restoring, grantItem: at.ports.grantItem(context) });
|
|
200
|
+
registerInstalled(host, 'poseViews');
|
|
195
201
|
};
|
|
196
202
|
}
|
|
197
203
|
case 'grapple': {
|
|
@@ -201,6 +207,7 @@ export async function prepareAssemblyFeature<C extends NativeAssemblyContext>(ro
|
|
|
201
207
|
return run => {
|
|
202
208
|
const { context } = run, guard = context.restoring ? [] : run.host.physics.world.colliders.getAll().filter(collider => tagOf(collider)?.owner === row.guard).map(collider => collider.handle);
|
|
203
209
|
installGrapple(run.host, at.ports.grappleTick(context), profile, mode, hooks, guard, row.rise === true);
|
|
210
|
+
registerInstalled(run.host, 'grapple');
|
|
204
211
|
};
|
|
205
212
|
}
|
|
206
213
|
case 'riding.taming': {
|
|
@@ -216,13 +223,14 @@ export async function prepareAssemblyFeature<C extends NativeAssemblyContext>(ro
|
|
|
216
223
|
case 'commands': return run => { run.input = at.ports.bindCommands(run.context, run.host); };
|
|
217
224
|
case 'collision': {
|
|
218
225
|
const collision = need(plan.collision, 'Native collision needs its settings'); need(plan.bake, 'Native collision needs its bake');
|
|
219
|
-
//
|
|
220
|
-
|
|
226
|
+
// GC36 (J322, no walls): an older bake still holds its page's chunk-edge walls (`edge`); no world stands them, as a cell held near
|
|
227
|
+
// its player never did (`nativeBake.ts`).
|
|
228
|
+
return run => { registerInstalled(run.host, 'collision'); if (row.skipOnRestore !== true || !run.context.restoring) installNativeCollision(run.host, at.bake, { ...collision, omit: [...(collision as { omit?: readonly string[] }).omit ?? [], 'edge'] } as Parameters<typeof installNativeCollision>[2]); };
|
|
221
229
|
}
|
|
222
|
-
case 'collision.pieces': { const pieces = await readAssemblyInput<unknown>(product, row.rows); return run => { if (!run.context.restoring) addBakedPieces(run.host.physics, pieces); }; }
|
|
230
|
+
case 'collision.pieces': { const pieces = await readAssemblyInput<unknown>(product, row.rows); return run => { registerInstalled(run.host, 'collision'); if (!run.context.restoring) addBakedPieces(run.host.physics, pieces); }; }
|
|
223
231
|
case 'portal.ride': {
|
|
224
232
|
const ride = await readAssemblyInput<PortalRideRows>(product, row.rows);
|
|
225
|
-
return run => { installHostPortalRide(run.host, row.step, shard, ride, at.ports.ledger(run.context).fact); };
|
|
233
|
+
return run => { installHostPortalRide(run.host, row.step, shard, ride, at.ports.ledger(run.context).fact); registerInstalled(run.host, 'portalRide'); };
|
|
226
234
|
}
|
|
227
235
|
case 'day.keyed-sky': { const spec = keyedSkyDaySpec(product.section('look/keyed-sky')); return run => { run.day = run.host.useDayClock(new DayCycle(spec)); }; }
|
|
228
236
|
case 'day.toon': {
|
|
@@ -248,12 +256,13 @@ export async function prepareAssemblyFeature<C extends NativeAssemblyContext>(ro
|
|
|
248
256
|
if (row.kind === 'bolt') installNativeItems(run.host, combat, { kind: 'bolt', policy, profile });
|
|
249
257
|
else if (row.kind === 'cycle') installNativeItems(run.host, combat, { kind: 'cycle', policy, profile });
|
|
250
258
|
else installNativeItems(run.host, combat, { kind: 'bow', policy, profile });
|
|
259
|
+
registerInstalled(run.host, 'heldRanged');
|
|
251
260
|
};
|
|
252
261
|
}
|
|
253
|
-
case 'item.swept': { const policy = await readAssemblyInput(product, row.policy); return run => { installNativeItems(run.host, combatOf(run), { kind: 'swept', items: shard.items.rows, policy }); }; }
|
|
262
|
+
case 'item.swept': { const policy = await readAssemblyInput(product, row.policy); return run => { installNativeItems(run.host, combatOf(run), { kind: 'swept', items: shard.items.rows, policy }); registerInstalled(run.host, 'heldArms'); registerInstalled(run.host, 'loadout'); }; }
|
|
254
263
|
case 'loadout': {
|
|
255
264
|
const policy = need(shard.items.loadout.native, 'Missing native loadout'), input = need(policy.input, 'Missing native equipment input policy');
|
|
256
|
-
return run => { const combat = combatOf(run); bindNativeLoadout(run.host, policy, { flags: run.host.flags, frame: combat,
|
|
265
|
+
return run => { const combat = combatOf(run); registerInstalled(run.host, 'loadout'); bindNativeLoadout(run.host, policy, { flags: run.host.flags, frame: combat,
|
|
257
266
|
locked: () => run.boss?.locked() === true || run.quest?.riding() === true || run.quest?.talking() === true,
|
|
258
267
|
others: { frame: player => otherCombatFrame(combat, player.id), locked: () => run.boss?.locked() === true },
|
|
259
268
|
step: { id: input.step, phase: input.phase, pick: (player, first) => {
|
|
@@ -20,10 +20,7 @@ import type { ShardProduct } from '../../../shared/game/shardfile/shardProduct';
|
|
|
20
20
|
/** What a server host hands one install. The tick protocol belongs to the SDK: `ports` adapts it. */
|
|
21
21
|
export interface NativeAssemblyContext { readonly combat?: NativeCombatFrame; readonly restoring: boolean; readonly snapshot?: Readonly<Omit<SimSnapshot, 'physics'>>;
|
|
22
22
|
/** A net room's world: it also runs the fights a page or a tape keeps to itself. */
|
|
23
|
-
readonly room?: boolean
|
|
24
|
-
/** GC15: a grid cell that opens onto its worker's road (`WORLD_CROSSING=worker`): the edge is the platform's, so the shard's
|
|
25
|
-
* own page walls in its baked collision don't stand there, as for a cell held near its player. */
|
|
26
|
-
readonly road?: boolean }
|
|
23
|
+
readonly room?: boolean }
|
|
27
24
|
/** The SDK's tick-protocol loans. No module URL or shard code crosses this boundary. */
|
|
28
25
|
export interface NativeAssemblyPorts<C extends NativeAssemblyContext> {
|
|
29
26
|
readonly rapier: Rapier;
|
|
@@ -3,6 +3,7 @@ import '@wildshard/engine/core/portableMathFirst';
|
|
|
3
3
|
import {createTrustedHeadlessTape} from '../../../shared/host/headlessTape';
|
|
4
4
|
import { runHeadlessJourney } from '../../../shared/host/headlessJourney';
|
|
5
5
|
import { proveShardfileEntries } from '@wildshard/engine/game/bake/entryways';
|
|
6
|
+
import { openWorldAdapter } from '../openWorld';
|
|
6
7
|
import { createTrustedHeadlessAdapter } from '../headlessRuntime';
|
|
7
8
|
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
8
9
|
// oxlint-disable-next-line import/no-nodejs-modules -- Only the platform-selected physics binary is read inside the isolated worker.
|
|
@@ -34,8 +35,11 @@ await runTickWorker(async raw => {
|
|
|
34
35
|
if (payload.product !== undefined) {
|
|
35
36
|
// A native assembly's server-class files live only in the built product, never in the client's sections or assets.
|
|
36
37
|
const { loadHeadlessProduct } = await import('../headlessProduct');
|
|
37
|
-
return
|
|
38
|
+
return openWorldAdapter({ shard, assets: payload.assets, rapier, product: await loadHeadlessProduct(payload.product) }, payload.snapshot);
|
|
38
39
|
}
|
|
40
|
+
// SERVER-PARITY HS1 left: a runtime plan carried as sections, with no product, still ticks the bare resident. Far Reach's and
|
|
41
|
+
// Dunes' proof witnesses build their checkpoints that way; moving it to `openWorldAdapter` re-records them.
|
|
42
|
+
// oxlint-disable-next-line typescript/no-deprecated -- HS1 left, above
|
|
39
43
|
if (sections.has('sim/runtime-plan')) return createTrustedHeadlessAdapter({ shard, assets: payload.assets, rapier, sections }, payload.snapshot);
|
|
40
44
|
let commands: ReadonlyMap<string, number> = new Map();
|
|
41
45
|
let effects: HeadlessEffect[] = [];
|
|
@@ -4,15 +4,16 @@ import { installAppIdentity } from '@wildshard/engine/app/identity';
|
|
|
4
4
|
import { Scope } from '@wildshard/engine/app/scope';
|
|
5
5
|
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
6
6
|
import { ServerClock } from '@wildshard/engine/net/serverClock';
|
|
7
|
-
import { GridAssembly } from '@wildshard/engine/game/grid/assembly';
|
|
7
|
+
import type { GridAssembly } from '@wildshard/engine/game/grid/assembly';
|
|
8
8
|
import type { GridCollisionStrip } from '@wildshard/engine/game/grid/gridCollision';
|
|
9
9
|
import type { Rapier } from '@wildshard/engine/physics/rapier';
|
|
10
10
|
import { DedicatedRoom, type DedicatedRoomRoad } from './dedicatedRoom';
|
|
11
|
-
import { cellShard, roadName } from './gridCells';
|
|
11
|
+
import { cellShard, gridAssembly, placeCell, roadName } from './gridCells';
|
|
12
12
|
import { RoadRoom } from './roadRoom';
|
|
13
|
+
import { placedStrips } from '@wildshard/engine/game/grid/voidFloor';
|
|
13
14
|
import { openRoad } from '../standalone/roadWorld';
|
|
14
15
|
import type { HeadlessRuntimeInput } from '../headlessRuntime';
|
|
15
|
-
import type { CellOrder, WorkerNews, WorkerReading } from './cellProtocol';
|
|
16
|
+
import type { CellOrder, WorkerNews, WorkerReading, WorkerResident } from './cellProtocol';
|
|
16
17
|
import { SeatTransport } from './socketPump';
|
|
17
18
|
|
|
18
19
|
/** How often a worker reads itself (E7.8). */
|
|
@@ -21,7 +22,7 @@ const READING_MS = 10_000;
|
|
|
21
22
|
const TICKS_KEPT = 720;
|
|
22
23
|
/** The save prefix a cell's stores share. Nothing outside a cell ever reads it. */
|
|
23
24
|
const SAVE_PREFIX = 'wildshard.room.';
|
|
24
|
-
/** J107: a cell left empty this long
|
|
25
|
+
/** J107: a cell everyone left starts over once it has stood empty this long, on its own timer, before anyone comes back (J320). */
|
|
25
26
|
const EMPTY_MS = 300_000;
|
|
26
27
|
|
|
27
28
|
/** A port as `worker_threads` and a `MessageChannel` both give it. */
|
|
@@ -46,12 +47,15 @@ export interface CellHostOptions {
|
|
|
46
47
|
readonly playtest?:boolean;
|
|
47
48
|
/**
|
|
48
49
|
* GC15 (`WORLD_CROSSING=worker`): the grid pack's road strips. Given, this worker hosts the road between its cells, each of its grid
|
|
49
|
-
* cells opens onto it instead of standing in lone walls, and a seat walks cell, road, cell on one socket. Left out, every cell is lone.
|
|
50
|
+
* cells opens onto it instead of standing in lone walls, and a seat walks cell, road, cell on one socket. Left out, or no strips, every cell is lone.
|
|
50
51
|
*/
|
|
51
52
|
readonly road?: () => Promise<readonly GridCollisionStrip[]>;
|
|
52
53
|
}
|
|
53
|
-
/**
|
|
54
|
-
|
|
54
|
+
/**
|
|
55
|
+
* One cell, and when it last emptied. A cell with nobody in it takes no ticks: that is all sleep is (Q80). Its world, colliders and sim stay
|
|
56
|
+
* in memory from the worker's boot (J320). `used`: someone stood in this world since it booted, so it has something to start over from.
|
|
57
|
+
*/
|
|
58
|
+
interface Cell { readonly slug: string; room: DedicatedRoom; emptySince: number; used: boolean; waking: Promise<void> | null }
|
|
55
59
|
const percentile = (sorted: readonly number[], at: number): number => sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * at))] ?? 0;
|
|
56
60
|
|
|
57
61
|
/** A worker has no page, so no app identity: all it needs of one is the save prefix. */
|
|
@@ -66,19 +70,37 @@ export function runCells(port: CellPort, options: CellHostOptions): { dispose: (
|
|
|
66
70
|
const post = (news: WorkerNews): void => { port.postMessage(news); };
|
|
67
71
|
const fail = (error: unknown): void => { clock?.pause(); post({ kind: 'failed', reason: error instanceof Error ? error.message : String(error) }); };
|
|
68
72
|
// GC15: the road this worker hosts, once its cells are open, and what its cells need of it.
|
|
69
|
-
|
|
73
|
+
// SA34a: `seams` are placed cells' own copies of the pack's strips beside them, which the pack baked with no row for a cell it never saw.
|
|
74
|
+
let road: RoadRoom | undefined, rapier: Rapier | undefined, crossing: { readonly name: string; readonly assembly: GridAssembly; readonly strips: readonly GridCollisionStrip[]; readonly seams: readonly GridCollisionStrip['duplicates'][number][] } | undefined;
|
|
70
75
|
const seams = (instance: string): DedicatedRoomRoad | undefined => {
|
|
71
76
|
if (crossing === undefined || !crossing.assembly.cells.some(cell => cell.instance === instance)) return undefined;
|
|
72
|
-
return { name: crossing.name, assembly: crossing.assembly, seams: crossing.strips.flatMap(strip => strip.duplicates.filter(row => row.instance === instance).map(row => row.mesh)
|
|
77
|
+
return { name: crossing.name, assembly: crossing.assembly, seams: [...crossing.strips.flatMap(strip => strip.duplicates), ...crossing.seams].filter(row => row.instance === instance).map(row => row.mesh) };
|
|
73
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* GC30: a cell this worker hosts and whose entryways all have ground at road height. Any other (another worker's, or Far Reach's sky
|
|
81
|
+
* islands) is walled on the road: a walker meets the wall and turns back, never falls in with no way out.
|
|
82
|
+
*/
|
|
83
|
+
const enterable = (instance: string): boolean => { const room = cells.get(instance)?.room; return room !== undefined && room.entrywaysStand(); };
|
|
74
84
|
/** A cell on this worker, or its road, by name. */
|
|
75
85
|
const named = (name: string): Cell | RoadRoom | undefined => road !== undefined && road.name === name ? road : cells.get(name);
|
|
86
|
+
const emptyMs = options.emptyMs ?? EMPTY_MS;
|
|
87
|
+
/** `startOver`, once it is made below: a start-over opens a cell, and a cell's room says when it emptied. */
|
|
88
|
+
const later = { startOver: (_cell: Cell, _since: number): void => undefined };
|
|
89
|
+
/** Someone stood in this world: it has something to start over from. A refused seat never got this far. */
|
|
90
|
+
const used = (slug: string, room: DedicatedRoom): void => { const cell = cells.get(slug); if (cell !== undefined && cell.room === room) cell.used = true; };
|
|
91
|
+
/** J107 on J320's terms: the last seat left this cell's world, so it starts over once it has stood empty `emptyMs`, nobody waiting on it. */
|
|
92
|
+
const emptied = (slug: string, room: DedicatedRoom): void => {
|
|
93
|
+
const cell = cells.get(slug);
|
|
94
|
+
if (cell === undefined || cell.room !== room || disposed) return;
|
|
95
|
+
const since = cell.emptySince = diagnosticNow();
|
|
96
|
+
if (cell.used) scope.timeout(emptyMs, () => { later.startOver(cell, since); });
|
|
97
|
+
};
|
|
76
98
|
// GO3: a row names cells by grid instance; each loads its shard's pack.
|
|
77
99
|
const open = async (slug: string): Promise<DedicatedRoom> => {
|
|
78
100
|
const shard = cellShard(slug), begun = diagnosticNow(), input = await options.load(shard), onto = seams(slug);
|
|
79
101
|
rapier ??= input.rapier;
|
|
80
|
-
const room = await DedicatedRoom.boot({ slug: shard, cell: slug, build: options.build, bootId: options.bootId(), input, now: options.roomNow ?? diagnosticNow, ...(onto === undefined ? {} : { road: onto }),
|
|
81
|
-
post: news => { if (news.kind === '
|
|
102
|
+
const room: DedicatedRoom = await DedicatedRoom.boot({ slug: shard, cell: slug, build: options.build, bootId: options.bootId(), input, now: options.roomNow ?? diagnosticNow, ...(onto === undefined ? {} : { road: onto }),
|
|
103
|
+
post: news => { if (news.kind === 'seated') used(slug, room); else if (news.kind === 'left' && news.seats === 0) emptied(slug, room); post({ ...news, slug }); },
|
|
82
104
|
reports: { file: report => { post({ kind: 'report', slug, report }); } }, ...(options.holdMs === undefined ? {} : { holdMs: options.holdMs }),...(options.playtest===true?{playtest:row=>{post({kind:'playtest',slug,row});}}:{}) });
|
|
83
105
|
post({ kind: 'cell', slug, ms: diagnosticNow() - begun });
|
|
84
106
|
options.booted?.(slug, room);
|
|
@@ -99,33 +121,77 @@ export function runCells(port: CellPort, options: CellHostOptions): { dispose: (
|
|
|
99
121
|
readAt = now; dropsAt = clock?.drops ?? 0; ticks = [];
|
|
100
122
|
post({ kind: 'reading', reading: row });
|
|
101
123
|
};
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
124
|
+
/** One start-over at a time on this worker: each boot stalls the clock of every other cell here, so they never pile up. */
|
|
125
|
+
let overs: Promise<void> = Promise.resolve();
|
|
126
|
+
/** The fresh world, swapped in while the cell is still empty. One that fails keeps the old world and says so; the worker plays on. */
|
|
127
|
+
const restart = async (cell: Cell): Promise<void> => {
|
|
128
|
+
if (disposed || cell.room.taken > 0) return;
|
|
129
|
+
try {
|
|
130
|
+
const old = cell.room, room = await open(cell.slug);
|
|
131
|
+
if (disposed) { room.dispose(); return; }
|
|
132
|
+
cell.room = room; old.dispose(); cell.used = false; cell.emptySince = diagnosticNow();
|
|
133
|
+
} catch (error) { console.warn(JSON.stringify({ at: 'cell.start-over-failed', slug: cell.slug, error: error instanceof Error ? error.message : String(error) })); }
|
|
134
|
+
};
|
|
135
|
+
/** A cell everyone left starts over. An arrival meanwhile waits for it (`settled`). A timer can fire a little early by this clock, so it looks again. */
|
|
136
|
+
later.startOver = (cell: Cell, since: number): void => {
|
|
137
|
+
if (disposed || cell.waking !== null || !cell.used || cell.room.taken > 0 || cell.emptySince !== since) return;
|
|
138
|
+
const left = emptyMs - (diagnosticNow() - since);
|
|
139
|
+
if (left > 0) { scope.timeout(left, () => { later.startOver(cell, since); }); return; }
|
|
140
|
+
const job = overs.then(() => restart(cell)).finally(() => { if (cell.waking === job) cell.waking = null; });
|
|
141
|
+
cell.waking = job; overs = job;
|
|
142
|
+
};
|
|
143
|
+
/** J320: an arrival never boots a cell. It waits only for a start-over already under way, and false when the worker closed meanwhile. */
|
|
144
|
+
const settled = async (...waiting: readonly Cell[]): Promise<boolean> => {
|
|
145
|
+
for (let busy = waiting.find(cell => cell.waking !== null); busy?.waking; busy = waiting.find(cell => cell.waking !== null)) await busy.waking;
|
|
146
|
+
return !disposed;
|
|
111
147
|
};
|
|
112
148
|
const dispose = (): void => { if (disposed) return; disposed = true; clock?.pause(); scope.dispose(); for (const { room } of cells.values()) room.dispose(); road?.dispose(); options.closed?.(); };
|
|
113
149
|
const find = async (cell: Cell | RoadRoom, id: number, device: string): Promise<void> => {
|
|
114
150
|
if (cell instanceof RoadRoom) { post({ kind: 'found', id, held: cell.holds(device), spawn: cell.spawn }); return; }
|
|
115
|
-
await
|
|
151
|
+
if (await settled(cell)) post({ kind: 'found', id, held: cell.room.holds(device), spawn: cell.room.spawn });
|
|
116
152
|
};
|
|
117
153
|
const seat = async (cell: Cell | RoadRoom, order: Extract<CellOrder, { kind: 'seat' }>): Promise<void> => {
|
|
118
154
|
// The transport starts its port: made before a wake, a close on the way would reach nobody.
|
|
119
|
-
if (!(cell instanceof RoadRoom) && cell
|
|
155
|
+
if (!(cell instanceof RoadRoom) && !await settled(cell)) return;
|
|
120
156
|
const transport = new SeatTransport(order.port), hello = (): void => { transport.deliver('reliable', order.hello); };
|
|
121
157
|
if (cell instanceof RoadRoom) cell.seat(order, transport, hello); else cell.room.seat(order, transport, hello);
|
|
122
158
|
};
|
|
123
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* SA34a: cells placed on the running world, one order at a time. The road's grid grows first (a cell opened here builds its seams from
|
|
161
|
+
* it), then this worker opens the ones it hosts, then its road lays the grown grid out, whatever opened. A failure is answered, never
|
|
162
|
+
* thrown: the other cells and the road play on.
|
|
163
|
+
*/
|
|
164
|
+
let placing: Promise<void> = Promise.resolve();
|
|
165
|
+
/** RR2: what this worker holds, for the door's `/health`: a road counts its strips only once it is open */
|
|
166
|
+
const resident = (): WorkerResident => ({ cells: cells.size, road: road !== undefined, strips: road === undefined ? 0 : crossing?.strips.length ?? 0 });
|
|
167
|
+
const place = async (order: Extract<CellOrder, { kind: 'place' }>): Promise<void> => {
|
|
168
|
+
const opened: string[] = [];
|
|
169
|
+
let laid: (() => void) | undefined;
|
|
170
|
+
try {
|
|
171
|
+
for (const row of order.cells) placeCell(row);
|
|
172
|
+
const was = crossing?.assembly, grown = gridAssembly();
|
|
173
|
+
if (crossing !== undefined && was !== undefined && was !== grown) {
|
|
174
|
+
const { strips, seams: more } = placedStrips(grown, was), fresh = grown.cells.slice(was.cells.length);
|
|
175
|
+
crossing = { name: crossing.name, assembly: grown, strips: [...crossing.strips, ...strips], seams: [...crossing.seams, ...more] };
|
|
176
|
+
laid = () => { road?.place(grown, strips, fresh.filter(cell => !enterable(cell.instance))); };
|
|
177
|
+
}
|
|
178
|
+
for (const slug of order.open) {
|
|
179
|
+
if (cells.has(slug)) continue;
|
|
180
|
+
const room = await open(slug);
|
|
181
|
+
if (disposed) { room.dispose(); post({ kind: 'placed', id: order.id, opened, error: 'The worker closed' }); return; }
|
|
182
|
+
cells.set(slug, { slug, room, emptySince: diagnosticNow(), used: false, waking: null }); opened.push(slug);
|
|
183
|
+
}
|
|
184
|
+
post({ kind: 'placed', id: order.id, opened, resident: resident() });
|
|
185
|
+
// RR2: a place that failed partway still opened `opened` and grew the road's strips, so its answer says what is resident too
|
|
186
|
+
} catch (error) { post({ kind: 'placed', id: order.id, opened, error: error instanceof Error ? error.message : String(error), resident: resident() }); }
|
|
187
|
+
finally { if (!disposed) laid?.(); }
|
|
188
|
+
};
|
|
189
|
+
/** GC15: a seat walks from one of this worker's cells into another, or onto or off its road; a target starting over is waited for (J320). */
|
|
124
190
|
const cross = async (order: Extract<CellOrder, { kind: 'cross' }>): Promise<void> => {
|
|
125
191
|
const { kind: _kind, from: fromSlug, to: toSlug, at, ...entry } = order, from = named(fromSlug), to = named(toSlug);
|
|
126
192
|
if (from === undefined || to === undefined) throw new Error(`${from === undefined ? fromSlug : toSlug} is not on this worker`);
|
|
127
|
-
|
|
128
|
-
if (!(from
|
|
193
|
+
// Both settled in one look, then read and moved with no await between: a start-over can't begin under the seat (J320).
|
|
194
|
+
if (!await settled(...[from, to].filter((cell): cell is Cell => !(cell instanceof RoadRoom)))) return;
|
|
129
195
|
const source = from instanceof RoadRoom ? from : from.room, target = to instanceof RoadRoom ? to : to.room;
|
|
130
196
|
const moved = source.handOver(entry.device, target, entry, at);
|
|
131
197
|
post({ kind: 'crossed', device: entry.device, name: entry.name, from: fromSlug, to: toSlug, moved, stays: source.holds(entry.device), body: moved ? target.bodyId(entry.device) ?? entry.body : entry.body });
|
|
@@ -142,6 +208,7 @@ export function runCells(port: CellPort, options: CellHostOptions): { dispose: (
|
|
|
142
208
|
if (!ready) { fail(new Error('A worker was told something before it booted')); return; }
|
|
143
209
|
if (order.kind === 'drain') { clock?.pause(); for (const { room } of cells.values()) room.drain(); road?.drain(); post({ kind: 'drained' }); return; }
|
|
144
210
|
if (order.kind === 'cross') { cross(order).catch(fail); return; }
|
|
211
|
+
if (order.kind === 'place') { placing = placing.then(() => place(order)); return; }
|
|
145
212
|
const cell = named(order.slug);
|
|
146
213
|
if (cell === undefined) { fail(new Error(`${order.slug} is not on this worker`)); return; }
|
|
147
214
|
(order.kind === 'find' ? find(cell, order.id, order.device) : seat(cell, order)).catch(fail);
|
|
@@ -151,11 +218,13 @@ export function runCells(port: CellPort, options: CellHostOptions): { dispose: (
|
|
|
151
218
|
installCellIdentity();
|
|
152
219
|
void (async (): Promise<void> => {
|
|
153
220
|
const first = options.slugs[0];
|
|
154
|
-
|
|
155
|
-
|
|
221
|
+
// SA34a: a worker booted after a placement (its `placed`) lays the placed cells out from the start.
|
|
222
|
+
// GC28: a book with no grid pack reads no strips: no road to stand on, so the cells open lone (the worker's `road.pack` line says 0).
|
|
223
|
+
if (options.road !== undefined && first !== undefined) { const assembly = gridAssembly(), strips = await options.road(), placed = placedStrips(assembly, gridAssembly(false)); if (strips.length > 0) crossing = { name: roadName(first), assembly, strips: [...strips, ...placed.strips], seams: placed.seams }; }
|
|
224
|
+
for (const slug of options.slugs) { const room = await open(slug); if (disposed) return; cells.set(slug, { slug, room, emptySince: diagnosticNow(), used: false, waking: null }); }
|
|
156
225
|
if (crossing !== undefined && rapier !== undefined) {
|
|
157
226
|
const { name, assembly, strips } = crossing, begun = diagnosticNow();
|
|
158
|
-
road = new RoadRoom({ name, build: options.build, assembly, host: openRoad(rapier, assembly.cells.filter(cell => !
|
|
227
|
+
road = new RoadRoom({ name, build: options.build, assembly, host: openRoad(rapier, assembly.cells.filter(cell => !enterable(cell.instance)), strips, assembly.cells), hosts: instance => cells.has(instance),
|
|
159
228
|
now: options.roomNow ?? diagnosticNow, post: news => { post({ ...news, slug: name }); }, reports: { file: report => { post({ kind: 'report', slug: name, report }); } },
|
|
160
229
|
...(options.holdMs === undefined ? {} : { holdMs: options.holdMs }) });
|
|
161
230
|
post({ kind: 'cell', slug: name, ms: diagnosticNow() - begun });
|
|
@@ -165,7 +234,7 @@ export function runCells(port: CellPort, options: CellHostOptions): { dispose: (
|
|
|
165
234
|
clock = new ServerClock({ now: diagnosticNow, wait: (ms, run) => { const timer = scope.timeout(ms, run); return () => { scope.cancelTimer(timer); }; }, step });
|
|
166
235
|
clock.start();
|
|
167
236
|
scope.interval(READING_MS, reading);
|
|
168
|
-
post({ kind: 'booted', ms: diagnosticNow() - started });
|
|
237
|
+
post({ kind: 'booted', ms: diagnosticNow() - started, resident: resident() });
|
|
169
238
|
})().catch(fail);
|
|
170
239
|
return { dispose };
|
|
171
240
|
}
|
|
@@ -2,6 +2,7 @@ import type { ChatReport, WorldLine } from '@wildshard/engine/net/chat';
|
|
|
2
2
|
import type { PlayerDoc } from './playerDoc';
|
|
3
3
|
import type { SaveReceipt, SaveWrite } from './saves/saveStore';
|
|
4
4
|
import type {PlaytestHit} from './playtest';
|
|
5
|
+
import type { PlacedCell } from './gridCells';
|
|
5
6
|
|
|
6
7
|
// J182: what the door and a cell worker say to each other. Sockets stay with the door, and a seat's bytes go through its own port.
|
|
7
8
|
|
|
@@ -30,6 +31,11 @@ export type CellOrder =
|
|
|
30
31
|
| { readonly kind: 'chat'; readonly from: string; readonly line: WorldLine }
|
|
31
32
|
/** GC15: a seat in cell `from` walks into `to` on the same worker. The entry is the door's read of their save on `to`'s shard. */
|
|
32
33
|
| ({ readonly kind: 'cross'; readonly from: string; readonly to: string; readonly at: ResumeAt } & SeatEntry)
|
|
34
|
+
/**
|
|
35
|
+
* SA34a: cells placed on the running world (SA33), told to every booted worker so its road lays them out: no void floor over their
|
|
36
|
+
* squares, their strips, and walls round any it can't hand a seat to. `open` names the ones this worker opens and hosts.
|
|
37
|
+
*/
|
|
38
|
+
| { readonly kind: 'place'; readonly id: number; readonly cells: readonly PlacedCell[]; readonly open: readonly string[] }
|
|
33
39
|
| { readonly kind: 'close' };
|
|
34
40
|
/** One 10 s reading of a worker (E7.8). */
|
|
35
41
|
export interface WorkerReading {
|
|
@@ -50,15 +56,19 @@ export type RoomNews =
|
|
|
50
56
|
| { readonly kind: 'chat'; readonly line: WorldLine }
|
|
51
57
|
/** GC15: this seat's feet left for cell `to`, standing at `at` in its frame: the door reads their save there and orders the `cross`. */
|
|
52
58
|
| { readonly kind: 'crossing'; readonly device: string; readonly to: string; readonly at: ResumeAt };
|
|
59
|
+
/** ROAD-RESIDENT RR2: what a worker holds in memory: its open cells, whether its road is open, and the strips that road stands on. */
|
|
60
|
+
export interface WorkerResident { readonly cells: number; readonly road: boolean; readonly strips: number }
|
|
53
61
|
/** What a worker says to the door. */
|
|
54
62
|
export type WorkerNews =
|
|
55
|
-
| { readonly kind: 'booted'; readonly ms: number }
|
|
63
|
+
| { readonly kind: 'booted'; readonly ms: number; readonly resident?: WorkerResident }
|
|
56
64
|
| { readonly kind: 'failed'; readonly reason: string }
|
|
57
65
|
| { readonly kind: 'found'; readonly id: number; readonly held: boolean; readonly spawn: ResumeAt }
|
|
58
66
|
| { readonly kind: 'report'; readonly slug: string; readonly report: ChatReport }
|
|
59
67
|
| { readonly kind: 'reading'; readonly reading: WorkerReading }
|
|
60
68
|
| { readonly kind: 'cell'; readonly slug: string; readonly ms: number }
|
|
61
69
|
| { readonly kind: 'drained' }
|
|
70
|
+
/** SA34a: a `place` order's end: the cells this worker opened, or why it opened none. Its other cells and its road play on either way. */
|
|
71
|
+
| { readonly kind: 'placed'; readonly id: number; readonly opened: readonly string[]; readonly error?: string; readonly resident?: WorkerResident }
|
|
62
72
|
/** GC15: a `cross` order's end. Moved, the seat and its link are in `to` (as `body`) and `from` has let it go; else it `stays` in `from`, or neither holds it. */
|
|
63
73
|
| { readonly kind: 'crossed'; readonly device: string; readonly name: string; readonly body: string; readonly from: string; readonly to: string; readonly moved: boolean; readonly stays: boolean }
|
|
64
74
|
| (RoomNews & { readonly slug: string });
|
|
@@ -10,17 +10,23 @@ import { parentPort, workerData } from 'node:worker_threads';
|
|
|
10
10
|
import { loadRapier } from '@wildshard/engine/physics/rapier';
|
|
11
11
|
import { readPackGrid, readPackProduct, type PackReads } from './packReader';
|
|
12
12
|
import { runCells, type CellPort } from './cellHost';
|
|
13
|
+
import { placeCell, type PlacedCell } from './gridCells';
|
|
13
14
|
|
|
14
15
|
/** What the door boots a worker with. */
|
|
15
16
|
export interface CellWorkerData { readonly slugs: readonly string[]; readonly build: string; readonly origin: string; readonly cache: string; readonly holdMs?: number;readonly playtest?:boolean;
|
|
17
|
+
/** J107's start-over wait, a proof's override (`EMPTY_MS`): 5 minutes when absent. */
|
|
18
|
+
readonly emptyMs?: number;
|
|
16
19
|
/** GC15: `WORLD_CROSSING=worker`, this worker hosts the road between its cells. */
|
|
17
|
-
readonly crossing?: boolean
|
|
20
|
+
readonly crossing?: boolean;
|
|
21
|
+
/** SA33: the cells the door had placed when it booted this worker; a worker's module state is its own. */
|
|
22
|
+
readonly placed?: readonly PlacedCell[] }
|
|
18
23
|
|
|
19
|
-
const { slugs, build, origin, cache, holdMs,playtest, crossing } = workerData as CellWorkerData, port = parentPort;
|
|
24
|
+
const { slugs, build, origin, cache, holdMs, emptyMs, playtest, crossing, placed } = workerData as CellWorkerData, port = parentPort;
|
|
20
25
|
if (port === null) throw new Error('A cell runs in a worker');
|
|
26
|
+
for (const row of placed ?? []) placeCell(row);
|
|
21
27
|
const reads: PackReads = { fetched: 0, fetchedBytes: 0, cached: 0, refused: 0 };
|
|
22
28
|
const rapier = await loadRapier(await readFile(new URL('rapier.wasm', import.meta.url)));
|
|
23
|
-
runCells(port as unknown as CellPort, { slugs, build, bootId: () => randomBytes(4).toString('hex'), memory: () => process.memoryUsage(), closed: () => { process.exit(0); }, ...(holdMs === undefined ? {} : { holdMs }),...(playtest===undefined?{}:{playtest}),...(crossing === true ? { road: async () => {
|
|
29
|
+
runCells(port as unknown as CellPort, { slugs, build, bootId: () => randomBytes(4).toString('hex'), memory: () => process.memoryUsage(), closed: () => { process.exit(0); }, ...(holdMs === undefined ? {} : { holdMs }), ...(emptyMs === undefined ? {} : { emptyMs }),...(playtest===undefined?{}:{playtest}),...(crossing === true ? { road: async () => {
|
|
24
30
|
// A build whose server book has no grid pack gives a road with no strips: this line says so before anyone falls through it.
|
|
25
31
|
const strips = await readPackGrid(build, { origin, cache }, reads);
|
|
26
32
|
console.info(JSON.stringify({ at: 'road.pack', strips: strips.length, ...reads }));
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// has walked. A cell and its worker's road hand a seat to each other through the door (`World.crossing`), on the same socket.
|
|
3
3
|
import { CHUNK_HALF } from '@wildshard/engine/core/config';
|
|
4
4
|
import type { NetRoom } from '@wildshard/engine/net/room';
|
|
5
|
+
import type { PlayerSim } from '@wildshard/engine/sim/playerSim';
|
|
5
6
|
import type { SimNetWorld } from '@wildshard/engine/net/simWorld';
|
|
6
7
|
import type { Transport } from '@wildshard/engine/net/transport';
|
|
7
8
|
import type { GridAssembly, GridCell, GridPoint } from '@wildshard/engine/game/grid/assembly';
|
|
@@ -20,8 +21,11 @@ export interface CrossArrival {
|
|
|
20
21
|
export interface CrossTarget {
|
|
21
22
|
readonly net: NetRoom; readonly sim: SimNetWorld;
|
|
22
23
|
holds: (device: string) => boolean;
|
|
23
|
-
/**
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Make the body first, at `at` in this room's frame; the reason when it can't, with nothing left behind. GC34: `motion` is the
|
|
26
|
+
* walker's body in the room it leaves, so the new one takes its velocity, clocks and mode (`carryMotion`) and never starts from rest.
|
|
27
|
+
*/
|
|
28
|
+
admit: (entry: SeatEntry, transport: Transport, at: ResumeAt, motion?: PlayerSim) => CrossArrival | string;
|
|
25
29
|
}
|
|
26
30
|
/** Feet the grid can place: a body gone to NaN is skipped, never thrown on, so one bad body can't end its worker. */
|
|
27
31
|
export function finite(feet: Readonly<GridPoint>): boolean { return Number.isFinite(feet.x) && Number.isFinite(feet.y) && Number.isFinite(feet.z); }
|