@wildshard/engine 0.1.15 → 0.1.17

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.
Files changed (207) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/index.html +157 -11
  3. package/lint/engine-sides.json +16 -0
  4. package/lint/host-register.json +496 -0
  5. package/lint/ratchet.json +2 -2
  6. package/lint/shard-imports.d.mts +1 -0
  7. package/lint/shard-imports.mjs +56 -8
  8. package/lint/wildshard-plugin.js +22 -4
  9. package/package.json +16 -5
  10. package/scripts/app-build/buildIdentity.d.mts +3 -1
  11. package/scripts/app-build/buildIdentity.mjs +25 -5
  12. package/scripts/app-build/builtAt.d.mts +4 -0
  13. package/scripts/app-build/builtAt.mjs +21 -0
  14. package/scripts/app-build/serviceWorker.ts +16 -2
  15. package/scripts/app-build/versionFiles.ts +2 -1
  16. package/scripts/app-build-pipeline.mjs +4 -1
  17. package/scripts/audio-download-proof.mjs +843 -0
  18. package/scripts/build-app.mjs +4 -0
  19. package/scripts/build-mirror.d.mts +2 -0
  20. package/scripts/build-mirror.mjs +5 -4
  21. package/scripts/built-product.mjs +3 -3
  22. package/scripts/cell-mem/metrics-preload.mjs +65 -0
  23. package/scripts/cell-mem-bench.mjs +130 -0
  24. package/scripts/check-chunks.mjs +2 -1
  25. package/scripts/devserver-client.d.mts +5 -0
  26. package/scripts/devserver-client.mjs +68 -0
  27. package/scripts/engine-ci-budget.ts +7 -1
  28. package/scripts/format-lock.mjs +20 -11
  29. package/scripts/generate-title-launch.mjs +3 -2
  30. package/scripts/grid-crossing-walk-proof.mjs +16 -8
  31. package/scripts/heavy-lane.py +25 -1
  32. package/scripts/host-ruler/register-migrate.mjs +242 -0
  33. package/scripts/host-ruler/register.d.mts +36 -0
  34. package/scripts/host-ruler/register.mjs +116 -0
  35. package/scripts/host-ruler/roots.d.mts +29 -0
  36. package/scripts/host-ruler/roots.mjs +333 -0
  37. package/scripts/host-ruler/server-roots.d.mts +23 -0
  38. package/scripts/host-ruler/server-roots.mjs +272 -0
  39. package/scripts/main-watch.d.mts +1 -1
  40. package/scripts/main-watch.mjs +10 -6
  41. package/scripts/map-hash.mjs +3 -6
  42. package/scripts/mmo-bots.mjs +2 -2
  43. package/scripts/offline-proof-rules.d.mts +1 -0
  44. package/scripts/offline-proof-rules.mjs +22 -1
  45. package/scripts/online-rig.mjs +4 -4
  46. package/scripts/page-release/flow.d.mts +1 -0
  47. package/scripts/page-release/flow.mjs +6 -2
  48. package/scripts/page-release.mjs +5 -1
  49. package/scripts/physics-route.json +0 -71
  50. package/scripts/pins-catalogue.ts +103 -0
  51. package/scripts/pins-reuse.mjs +3 -1
  52. package/scripts/pins.ts +22 -14
  53. package/scripts/preview-grid.ts +203 -0
  54. package/scripts/road-preload-proof.mjs +167 -0
  55. package/scripts/server-release/publish.mjs +2 -2
  56. package/scripts/server-release/served-slug.d.mts +2 -0
  57. package/scripts/server-release/served-slug.mjs +10 -0
  58. package/scripts/server-release/sign.d.mts +1 -0
  59. package/scripts/server-release/sign.mjs +3 -7
  60. package/scripts/shard-components.mjs +0 -2
  61. package/scripts/shard-outputs.d.mts +8 -0
  62. package/scripts/shard-outputs.mjs +45 -11
  63. package/scripts/side-parity.d.mts +2 -1
  64. package/scripts/side-parity.mjs +25 -4
  65. package/scripts/test-amber.d.mts +1 -0
  66. package/scripts/test-amber.mjs +10 -0
  67. package/scripts/test-products.json +3 -3
  68. package/scripts/tracked-public.d.mts +1 -0
  69. package/scripts/tracked-public.mjs +17 -0
  70. package/src/cli/engine.mjs +8 -0
  71. package/src/client/app/bootRoute.ts +4 -1
  72. package/src/client/app/dropModal.ts +15 -2
  73. package/src/client/app/entry.ts +67 -11
  74. package/src/client/app/slugPath.ts +5 -0
  75. package/src/client/engine/audio/Audio.ts +20 -2
  76. package/src/client/engine/boot/bakedTextures.ts +3 -2
  77. package/src/client/engine/boot/bootTrace.ts +6 -1
  78. package/src/client/engine/boot/bytes.ts +4 -3
  79. package/src/client/engine/boot/clearDownloads.ts +1 -1
  80. package/src/client/engine/boot/contentRead.ts +4 -0
  81. package/src/client/engine/boot/dropNotice.ts +20 -6
  82. package/src/client/engine/boot/gpuFiles.ts +25 -2
  83. package/src/client/engine/boot/lastEnd.ts +8 -2
  84. package/src/client/engine/boot/shardPrefetch.ts +7 -1
  85. package/src/client/engine/boot/sw.ts +19 -0
  86. package/src/client/engine/core/Game.ts +11 -3
  87. package/src/client/engine/core/GpuRecovery.ts +7 -0
  88. package/src/client/engine/core/Volumetrics.ts +5 -0
  89. package/src/client/engine/core/assets.ts +27 -20
  90. package/src/client/engine/core/bootstrap.ts +1 -2
  91. package/src/client/engine/core/ktx2.ts +84 -11
  92. package/src/client/engine/explore/Compare.ts +2 -2
  93. package/src/client/engine/explore/TouchFly.ts +3 -5
  94. package/src/client/engine/input/dom.ts +12 -0
  95. package/src/client/engine/net/predictor.ts +6 -2
  96. package/src/client/engine/player/Player.ts +10 -2
  97. package/src/client/engine/player/TouchControls.ts +12 -4
  98. package/src/client/engine/pwa/sw.js +47 -8
  99. package/src/client/engine/render/drawCheck.ts +96 -0
  100. package/src/client/engine/saves/staleBuildNote.ts +46 -0
  101. package/src/client/engine/telemetry/browserErrors.ts +157 -20
  102. package/src/client/engine/telemetry/screenOutbox.ts +61 -0
  103. package/src/client/engine/telemetry/staleBuildReport.ts +12 -0
  104. package/src/client/engine/ui/DeathFade.ts +99 -11
  105. package/src/client/engine/ui/ErrorModal.ts +13 -6
  106. package/src/client/engine/ui/Feedback.ts +2 -1
  107. package/src/client/engine/ui/Loading.ts +10 -6
  108. package/src/client/engine/ui/Map.ts +2 -1
  109. package/src/client/engine/ui/WeaponStrip.ts +2 -1
  110. package/src/client/engine/ui/backGuard.ts +104 -0
  111. package/src/client/engine/ui/hudAdapters.ts +30 -4
  112. package/src/client/engine/ui/loading.css +17 -0
  113. package/src/client/engine/ui/namePrompt.ts +6 -5
  114. package/src/client/engine/ui/styles/combat.css +12 -0
  115. package/src/client/engine/ui/styles/namePrompt.css +4 -2
  116. package/src/client/game/boot/audio.generated.ts +0 -294
  117. package/src/client/game/boot/bytes.generated.ts +0 -11
  118. package/src/client/game/boot/versions.generated.ts +0 -11
  119. package/src/client/game/compendium/keepsakes.ts +16 -6
  120. package/src/client/game/grapple/tool.ts +10 -7
  121. package/src/client/game/grid/cellLoading.ts +23 -12
  122. package/src/client/game/grid/cellScreens.ts +39 -74
  123. package/src/client/game/grid/liveSession.ts +40 -7
  124. package/src/client/game/grid/nearPlaceholderPlan.ts +8 -0
  125. package/src/client/game/grid/nearPlaceholderView.ts +9 -3
  126. package/src/client/game/grid/oneWayIn.ts +92 -27
  127. package/src/client/game/grid/pageEntry.ts +19 -0
  128. package/src/client/game/grid/pageShell.ts +1 -1
  129. package/src/client/game/grid/plotAudio.ts +114 -0
  130. package/src/client/game/grid/products.ts +55 -5
  131. package/src/client/game/grid/roadLookPlatform.ts +2 -2
  132. package/src/client/game/grid/session.ts +38 -22
  133. package/src/client/game/grid/spawnGround.ts +68 -0
  134. package/src/client/game/grid/voidLook.ts +29 -23
  135. package/src/client/game/loot/runtime.ts +3 -1
  136. package/src/client/game/mainMenu.ts +14 -6
  137. package/src/client/game/riding/hud.ts +6 -4
  138. package/src/client/game/session/finish.ts +17 -3
  139. package/src/client/game/session/play.ts +8 -2
  140. package/src/client/game/session/session.ts +4 -1
  141. package/src/client/game/shardfile/clientWorker.ts +41 -12
  142. package/src/client/game/shardfile/serverRoute.ts +10 -22
  143. package/src/client/game/slugPage.css +11 -0
  144. package/src/client/game/slugPage.ts +84 -0
  145. package/src/client/game/systems/viewmodel/heldView.ts +6 -3
  146. package/src/client/game/titleDeck.ts +55 -32
  147. package/src/client/host/online/doctor.ts +7 -6
  148. package/src/client/host/online/linkScreens.ts +16 -0
  149. package/src/client/host/online/release.ts +51 -5
  150. package/src/client/host/online/shell.ts +48 -27
  151. package/src/client/host/standalone/shell.ts +7 -3
  152. package/src/cook/game/audioReport.ts +57 -0
  153. package/src/cook/game/entryTotals.ts +26 -6
  154. package/src/cook/game/installedRuntimeReads.ts +3 -0
  155. package/src/server/engine/sim/respawn.ts +6 -1
  156. package/src/server/engine/sim.ts +3 -0
  157. package/src/server/game/grid/simulation.ts +35 -0
  158. package/src/server/game/loot/harvest.ts +2 -0
  159. package/src/server/game/loot/keepsakeProgression.ts +40 -0
  160. package/src/server/game/loot/playerOwned.ts +5 -1
  161. package/src/server/game/plugin/simulation.ts +4 -0
  162. package/src/server/game/population/nativeBake.ts +2 -1
  163. package/src/server/game/quest/chapterRecords.ts +2 -0
  164. package/src/server/game/quest/serverChapters.ts +4 -0
  165. package/src/server/game/quest/serverDoors.ts +11 -5
  166. package/src/server/game/roomRespawn.ts +4 -0
  167. package/src/server/game/shardfile/installedSides.ts +18 -0
  168. package/src/server/game/shardfile/nativeAssemblyHosts.ts +19 -10
  169. package/src/server/game/shardfile/nativeAssemblyInput.ts +1 -4
  170. package/src/server/host/bake/headlessWorker.ts +5 -1
  171. package/src/server/host/dedicated/cellHost.ts +98 -29
  172. package/src/server/host/dedicated/cellProtocol.ts +11 -1
  173. package/src/server/host/dedicated/cellWorker.ts +9 -3
  174. package/src/server/host/dedicated/crossing.ts +6 -2
  175. package/src/server/host/dedicated/dedicatedRoom.ts +21 -8
  176. package/src/server/host/dedicated/gridCells.ts +52 -9
  177. package/src/server/host/dedicated/main.ts +31 -12
  178. package/src/server/host/dedicated/placementFile.ts +72 -0
  179. package/src/server/host/dedicated/releaseFile.ts +17 -10
  180. package/src/server/host/dedicated/roadRoom.ts +21 -5
  181. package/src/server/host/dedicated/workerTable.ts +13 -1
  182. package/src/server/host/dedicated/world.ts +81 -9
  183. package/src/server/host/headlessRuntime.ts +10 -5
  184. package/src/server/host/installers.ts +62 -0
  185. package/src/server/host/openWorld.ts +59 -0
  186. package/src/server/host/ropeDecks.ts +2 -0
  187. package/src/server/host/standalone/cellWorld.ts +25 -19
  188. package/src/server/host/standalone/fallFloor.ts +2 -2
  189. package/src/server/host/standalone/gridServer.ts +7 -4
  190. package/src/server/host/standalone/roadWorld.ts +41 -4
  191. package/src/shared/engine/audio/bootAudio.ts +33 -0
  192. package/src/shared/engine/level/spec.ts +3 -3
  193. package/src/shared/engine/net/acts.ts +3 -0
  194. package/src/shared/engine/physics/query.ts +27 -0
  195. package/src/shared/engine/physics/terrain.ts +19 -28
  196. package/src/shared/engine/saves/saves.lock.json +15 -0
  197. package/src/shared/engine/sim/actRoutes.ts +2 -0
  198. package/src/shared/game/compendium/keepsakeProgression.ts +24 -0
  199. package/src/shared/game/grid/catalogue.ts +12 -5
  200. package/src/shared/game/grid/catalogueSlot.ts +11 -0
  201. package/src/shared/game/grid/farProxy.ts +6 -5
  202. package/src/shared/game/grid/pageMode.ts +1 -1
  203. package/src/shared/game/grid/roadLayout.ts +26 -3
  204. package/src/shared/game/grid/singleplayer.json +0 -13
  205. package/src/shared/game/grid/voidFloor.ts +122 -0
  206. package/src/shared/game/strings.ts +15 -0
  207. package/src/shared/host/standalone/netInput.ts +2 -1
@@ -0,0 +1,72 @@
1
+ // SA33 (meta SHARD-AUTHORING, J314): a new slug's cell reaches a running server with no engine release. The API places a new slug (SA30) and
2
+ // writes this file, signed with its own placement key; the release key stays engine CI's, because it vouches for the server bundle the box
3
+ // runs. A placement can only add a cell on an empty spot, for a shard whose server pack this build's book already holds: it never moves the
4
+ // build, the bundle or the save epoch, and a new serial here starts no grace, so players in every other cell stay connected.
5
+ import * as v from 'valibot';
6
+ import { Scope } from '@wildshard/engine/app/scope';
7
+ import { fetchSignedText, readSigned } from './releaseFile';
8
+ import type { PlacedCell } from './gridCells';
9
+
10
+ /** How often the server looks, in ms: the release file's minute, so a placement is open inside SA33's two minutes. */
11
+ const POLL_MS = 60_000;
12
+ const WHAT = 'placement file';
13
+ const id = v.pipe(v.string(), v.regex(/^_?[a-z0-9]+(?:-[a-z0-9]+)*$/u), v.maxLength(64));
14
+ const spot = v.pipe(v.number(), v.integer());
15
+
16
+ /** What a placement file says: every cell the API placed on one channel, in its grid's order. */
17
+ export interface PlacementFile {
18
+ /** Which kind of signed file this is, so a body can never be read as another kind's. */
19
+ readonly kind: 'placement';
20
+ readonly channel: 'production' | 'staging';
21
+ /** Rises with every write; an older file is never believed (J179). */
22
+ readonly serial: number;
23
+ readonly cells: readonly PlacedCell[];
24
+ }
25
+ /** A placement file's body, once its signature has held. The spot's bounds are `placeCell`'s. */
26
+ export const PlacementSchema: v.GenericSchema<PlacementFile> = v.object({ kind: v.literal('placement'), channel: v.picklist(['production', 'staging']), serial: v.pipe(v.number(), v.integer(), v.minValue(0)),
27
+ cells: v.pipe(v.array(v.object({ instance: id, slug: id, cell: v.tuple([spot, spot]) })), v.maxLength(49)) });
28
+
29
+ /** The file's text as what it says, under the placement key (SPKI DER in hex). */
30
+ export function readPlacementFile(text: string, publicKey: string): PlacementFile { return readSigned(text, publicKey, PlacementSchema, WHAT); }
31
+ /** The placement file at `url`, an `https:` bucket or a `file:` path. */
32
+ export async function fetchPlacementFile(url: string, publicKey: string): Promise<PlacementFile> { return readPlacementFile(await fetchSignedText(url, WHAT), publicKey); }
33
+
34
+ /** How a placement watch is built. */
35
+ export interface PlacementWatchOptions {
36
+ readonly read: () => Promise<PlacementFile>;
37
+ /** The channel this server plays. */
38
+ readonly channel: string;
39
+ /** Open these cells, the ones this server hasn't opened yet; answer the instances that opened. A cell left out is asked for again next look. */
40
+ readonly open: (cells: readonly PlacedCell[]) => Promise<readonly string[]>;
41
+ /** A look that failed. The server plays on with the cells it has. */
42
+ readonly failed: (error: unknown) => void;
43
+ readonly everyMs?: number;
44
+ }
45
+ /** SA33: a running server's cells grow when the placement file names one it hasn't opened. It never closes one: delete is SA31's, at a restart. */
46
+ export class PlacementWatch {
47
+ private readonly options: PlacementWatchOptions;
48
+ private readonly scope = new Scope('dedicated.placement');
49
+ private readonly opened = new Set<string>();
50
+ private looking = false;
51
+ private seen = -1;
52
+ constructor(options: PlacementWatchOptions) {
53
+ this.options = options;
54
+ this.scope.interval(options.everyMs ?? POLL_MS, () => { void this.look(); });
55
+ }
56
+ /** The newest serial this server has believed, or -1. */
57
+ get serial(): number { return this.seen; }
58
+ /** One look. An older file than one already believed changes nothing. */
59
+ async look(): Promise<void> {
60
+ if (this.looking) return;
61
+ this.looking = true;
62
+ try {
63
+ const file = await this.options.read();
64
+ if (file.channel !== this.options.channel) throw new Error(`A ${file.channel} placement file on a ${this.options.channel} server`);
65
+ if (file.serial < this.seen) throw new Error(`Placement serial ${String(file.serial)} is older than ${String(this.seen)}`);
66
+ this.seen = file.serial;
67
+ const fresh = file.cells.filter(cell => !this.opened.has(cell.instance));
68
+ if (fresh.length > 0) for (const instance of await this.options.open(fresh)) this.opened.add(instance);
69
+ } catch (error) { this.options.failed(error); } finally { this.looking = false; }
70
+ }
71
+ dispose(): void { this.scope.dispose(); }
72
+ }
@@ -10,19 +10,26 @@ import { ReleaseSchema, SignedSchema, type ReleaseFile } from '../../../shared/h
10
10
 
11
11
  /** How often the server looks, in ms: as the cook worker does, outbound, so the VPS opens no port (J175, Q91). */
12
12
  const POLL_MS = 60_000;
13
- /** The file's text as what it says. It throws on a bad signature, before a byte of the body is believed. `publicKey` is SPKI DER in hex, and the signature is hex. */
14
- export function readReleaseFile(text: string, publicKey: string): ReleaseFile {
13
+ /** A look that hangs would stop every later look: one minute's poll is the most it may take. */
14
+ const FETCH_MS = 30_000;
15
+ /** A signed file's text as what it says. It throws on a bad signature, before a byte of the body is believed. `publicKey` is SPKI DER in hex, and the signature is hex.
16
+ * The release file and SA33's placement file share it, each under its own key. */
17
+ export function readSigned<T>(text: string, publicKey: string, schema: v.GenericSchema<T>, what: string): T {
15
18
  const signed = v.parse(SignedSchema, JSON.parse(text)), key = createPublicKey({ key: Buffer.from(publicKey, 'hex'), format: 'der', type: 'spki' });
16
- if (!verify(null, Buffer.from(signed.body), key, Buffer.from(signed.signature, 'hex'))) throw new Error('A release file has a bad signature');
17
- return v.parse(ReleaseSchema, JSON.parse(signed.body));
19
+ if (!verify(null, Buffer.from(signed.body), key, Buffer.from(signed.signature, 'hex'))) throw new Error(`A ${what} has a bad signature`);
20
+ return v.parse(schema, JSON.parse(signed.body));
18
21
  }
19
- /** The release file at `url`, an `https:` bucket or a `file:` path. */
20
- export async function fetchReleaseFile(url: string, publicKey: string): Promise<ReleaseFile> {
21
- if (url.startsWith('file:')) return readReleaseFile(await readFile(new URL(url), 'utf8'), publicKey);
22
- const response = await fetch(url, { cache: 'no-store' });
23
- if (!response.ok) throw new Error(`No release file at ${url}: ${String(response.status)}`);
24
- return readReleaseFile(await response.text(), publicKey);
22
+ /** A signed file's text at `url`, an `https:` bucket or a `file:` path. */
23
+ export async function fetchSignedText(url: string, what: string): Promise<string> {
24
+ if (url.startsWith('file:')) return readFile(new URL(url), 'utf8');
25
+ const response = await fetch(url, { cache: 'no-store', signal: AbortSignal.timeout(FETCH_MS) });
26
+ if (!response.ok) throw new Error(`No ${what} at ${url}: ${String(response.status)}`);
27
+ return response.text();
25
28
  }
29
+ /** The release file's text as what it says. */
30
+ export function readReleaseFile(text: string, publicKey: string): ReleaseFile { return readSigned(text, publicKey, ReleaseSchema, 'release file'); }
31
+ /** The release file at `url`, an `https:` bucket or a `file:` path. */
32
+ export async function fetchReleaseFile(url: string, publicKey: string): Promise<ReleaseFile> { return readReleaseFile(await fetchSignedText(url, 'release file'), publicKey); }
26
33
 
27
34
  /** Boot from the release whose bundle passed the pull. Remote metadata alone cannot change its epoch.
28
35
  * A direct local boot without a kept file may use the signed file for its build and configured channel. */
@@ -7,13 +7,16 @@ 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 type { GridAssembly } from '@wildshard/engine/game/grid/assembly';
10
+ import { carryMotion } from '@wildshard/engine/game/grid/simulation';
11
+ import type { GridAssembly, GridCell } from '@wildshard/engine/game/grid/assembly';
12
+ import type { GridCollisionStrip } from '@wildshard/engine/game/grid/gridCollision';
11
13
  import { mountedPlayerOf } from '@wildshard/engine/game/riding/native';
12
14
  import { commandsOf } from '@wildshard/engine/game/grid/roomNet';
13
15
  import { LEAD_SEAT } from '../standalone/cellWorld';
14
16
  import { HOLD_MS, type ResumeAt, type RoomNews, type SeatEntry } from './cellProtocol';
15
17
  import { crossedTo, finite, type CrossArrival, type CrossTarget } from './crossing';
16
18
  import { FallFloor } from '../standalone/fallFloor';
19
+ import { placeOnRoad } from '../standalone/roadWorld';
17
20
  import { LEFT } from './socketPump';
18
21
 
19
22
  /** How often a seat whose crossing is asked for asks again, and how often holds are looked at, in ticks. */
@@ -51,8 +54,10 @@ export class RoadRoom implements CrossTarget {
51
54
  readonly host: SimHost;
52
55
  private readonly options: RoadRoomOptions;
53
56
  private readonly seats = new Map<string, RoadSeat>();
57
+ /** The grid the trigger reads: the options' until a placement grows it (SA34a). */
58
+ private assembly: GridAssembly;
54
59
  constructor(options: RoadRoomOptions) {
55
- this.options = options; this.host = options.host;
60
+ this.options = options; this.host = options.host; this.assembly = options.assembly;
56
61
  // The road's level has a lead seat of its own, which nobody takes: every crossing seat is a body of its own.
57
62
  const lead = this.host.players.get(LEAD_SEAT);
58
63
  if (lead !== undefined) { lead.motor.setEnabled(false); this.host.parked.add(lead.id); }
@@ -70,11 +75,12 @@ export class RoadRoom implements CrossTarget {
70
75
  bodyId(device: string): string | undefined { return this.seats.get(device)?.body; }
71
76
  bodyOf(device: string): PlayerSim | undefined { const seat = this.seats.get(device); return seat === undefined ? undefined : this.host.players.get(seat.body); }
72
77
 
73
- admit(entry: SeatEntry, transport: Transport, at: ResumeAt): CrossArrival | string {
78
+ admit(entry: SeatEntry, transport: Transport, at: ResumeAt, motion?: PlayerSim): CrossArrival | string {
74
79
  if (this.seats.has(entry.device)) return 'held';
75
80
  const player = this.host.addPlayer(entry.body, at, at.yaw);
76
81
  player.netName = entry.name;
77
82
  player.resetPose(at, at.yaw);
83
+ if (motion !== undefined) carryMotion(motion, player);
78
84
  const seat: RoadSeat = { device: entry.device, name: entry.name, body: entry.body, transport, client: null, closeOff: null, holdEnds: null, asked: null, askedAt: 0, fall: new FallFloor(ROAD_FLOOR, true, at) };
79
85
  this.seats.set(entry.device, seat);
80
86
  return { body: seat.body, land: client => {
@@ -98,7 +104,8 @@ export class RoadRoom implements CrossTarget {
98
104
  handOver(device: string, target: CrossTarget, entry: SeatEntry, at: ResumeAt): boolean {
99
105
  const seat = this.seats.get(device), transport = seat?.transport ?? null;
100
106
  if (seat === undefined || transport === null || seat.client === null || !this.net.live(seat.client) || target.holds(device)) return false;
101
- const arrived = target.admit(entry, transport, at);
107
+ // GC34: the walker's own motion goes with them; a rider's lives on the mount it leaves here, so it arrives on foot from rest
108
+ const arrived = target.admit(entry, transport, at, mountedPlayerOf(this.host, seat.body)?.mounted === true ? undefined : this.host.players.get(seat.body));
102
109
  if (typeof arrived === 'string') return false;
103
110
  mountedPlayerOf(this.host, seat.body)?.dismount();
104
111
  seat.closeOff?.(); seat.closeOff = null; seat.transport = null;
@@ -107,6 +114,15 @@ export class RoadRoom implements CrossTarget {
107
114
  this.release(seat);
108
115
  return arrived.land(client);
109
116
  }
117
+ /**
118
+ * SA34a: cells placed on the running world (SA33). The trigger reads the grown grid, so feet inside a placed cell this worker hosts ask
119
+ * to cross into it; the void floor is laid again without their squares, their strips go in, and `walled` (placed cells on other workers)
120
+ * get the walls every other worker's cell has.
121
+ */
122
+ place(assembly: GridAssembly, strips: readonly GridCollisionStrip[], walled: readonly Pick<GridCell, 'origin'>[]): void {
123
+ this.assembly = assembly;
124
+ placeOnRoad(this.host, assembly.cells, strips, walled);
125
+ }
110
126
  private bind(seat: RoadSeat, transport: Transport, client: number): void {
111
127
  seat.closeOff?.();
112
128
  seat.transport = transport; seat.client = client;
@@ -137,7 +153,7 @@ export class RoadRoom implements CrossTarget {
137
153
  for (const seat of this.seats.values()) {
138
154
  const player = this.host.players.get(seat.body);
139
155
  if (seat.transport === null || player === undefined || !finite(player.position)) continue;
140
- const crossed = crossedTo(this.options.assembly, null, player.position);
156
+ const crossed = crossedTo(this.assembly, null, player.position);
141
157
  const to = crossed?.cell?.instance ?? null;
142
158
  if (crossed === undefined || to === null || !this.options.hosts(to)) { seat.asked = null; continue; }
143
159
  if (seat.asked === to && this.host.state.tick - seat.askedAt < ASK_TICKS) continue;
@@ -15,6 +15,16 @@ export function worldSettings(channel: string, env: Readonly<Record<string, stri
15
15
  return { workers: Number(env['WORLD_WORKERS'] ?? start.workers), seats: Number(env['WORLD_SEATS'] ?? start.seats) };
16
16
  }
17
17
 
18
+ /**
19
+ * GC35 (J322, Jake 11-13: "World crossing should be on by default. There should never be any walls"): each worker hosts the road between
20
+ * its cells unless `WORLD_CROSSING=off` (a bench's lone cells). Unset, or blank, is `worker`.
21
+ */
22
+ export function worldCrossing(value: string | undefined): boolean {
23
+ if (value === undefined || value === '' || value === 'worker') return true;
24
+ if (value === 'off') return false;
25
+ throw new Error(`WORLD_CROSSING=${value}: only worker (the default) or off`);
26
+ }
27
+
18
28
  /**
19
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
20
30
  * worker. Named rows go first; the rest are shared, and if the count runs out the last row takes whatever is left.
@@ -25,5 +35,7 @@ export function workerTable(cells: readonly string[], workers: number): readonly
25
35
  const room = Math.max(1, workers - rows.length), share = Array.from({ length: room }, (): string[] => []);
26
36
  rest.forEach((slug, index) => { share[index % room]?.push(slug); });
27
37
  const table = [...rows, ...share.filter(row => row.length > 0)], kept = table.slice(0, Math.max(1, workers - 1)), over = table.slice(kept.length).flat();
28
- return table.length <= workers ? table : [...kept, over];
38
+ if (table.length <= workers) return table;
39
+ // GC31: one worker is one row, so a crossing reaches every cell (`kept` keeps a first row whenever it can).
40
+ return workers <= 1 ? [table.flat()] : [...kept, over];
29
41
  }
@@ -19,14 +19,14 @@ import { encodeCountdown, type WorldWord } from '@wildshard/engine/net/socketFra
19
19
  import {CorrectionSchema} from '@wildshard/engine/net/measurements';
20
20
  import type {PlaytestRow} from './playtest';
21
21
  import type { ChatReport } from '@wildshard/engine/net/chat';
22
- import type { CellOrder, ResumeAt, SavedCheckpoint, SeatEntry, WorkerNews, WorkerReading } from './cellProtocol';
22
+ import type { CellOrder, ResumeAt, SavedCheckpoint, SeatEntry, WorkerNews, WorkerReading, WorkerResident } from './cellProtocol';
23
23
  import { bodyId } from './seats';
24
24
  import { SaveNewerError, type PlayerDoc } from './playerDoc';
25
25
  import { LEAVE_FLAG, LEFT, pumpSocket } from './socketPump';
26
26
  import { SOCKET_SERVER_OPTIONS, SocketTransport } from './socketTransport';
27
27
  import { SaveQuarantinedError, type SaveReceipt, type SaveWrite } from './saves/saveStore';
28
28
  import { workerTable } from './workerTable';
29
- import { cellName, cellShard, roadHome } from './gridCells';
29
+ import { cellName, cellShard, gridAssembly, placedCells, roadHome } from './gridCells';
30
30
  import { VoiceRelay, type VoiceIceServer } from './voiceRelay';
31
31
  import { DEFAULT_ALLOWED_ORIGINS, DEFAULT_TRUST_PROXY, originAllowed, trustedAddress, type TrustProxy } from './doorTrust';
32
32
 
@@ -115,6 +115,11 @@ export interface WorldOptions {
115
115
  readonly trustProxy?: TrustProxy;
116
116
  /** VH10: the pages a browser may open a socket from; `null` is any. The game's own hosts when absent. */
117
117
  readonly allowedOrigins?: readonly string[] | null;
118
+ /**
119
+ * GC15 (`WORLD_CROSSING=worker`): each worker hosts a road. SA34a: a placed cell then opens on the worker of its nearest open cell, whose
120
+ * road hands a seat into it, and every worker's road is told of it; without roads it boots on a worker of its own (SA33).
121
+ */
122
+ readonly roads?: boolean;
118
123
  /** A proof's overrides. */
119
124
  readonly helloMs?: number; readonly readyMs?: number; readonly connectsPerMinute?: number; readonly socketsPerIp?: number; readonly graceMs?: number;
120
125
  /** Monotonic connection-budget clock, overridable by local boundary tests. */
@@ -155,6 +160,14 @@ export class World {
155
160
  /** GC15: devices whose source said `left` while their crossing was in flight: applied if the crossing is abandoned before `cross`. */
156
161
  private readonly leftCrossing = new Set<string>();
157
162
  private asked = 0;
163
+ /** SA33: cells whose late worker is booting, so a second open of the same cell boots nothing. */
164
+ private readonly booting = new Set<string>();
165
+ /** SA34a: workers that have said `booted`, the only ones a `place` order may reach. */
166
+ private readonly up = new Set<WorkerLink>();
167
+ /** RR2: what each booted worker holds (its `booted` news, then each `placed`), for `/health`. */
168
+ private readonly resident = new Map<WorkerLink, WorkerResident>();
169
+ /** SA34a: `place` orders waiting on the worker that opens their cells. */
170
+ private readonly placings = new Map<number, (news: { readonly opened: readonly string[]; readonly error?: string }) => void>();
158
171
  private draining = false;
159
172
  private grace: { readonly endsAt: number; readonly build: string } | null = null;
160
173
  /** J218: who is on voice in each cell, and their signalling. */
@@ -172,14 +185,61 @@ export class World {
172
185
  await Promise.all(workerTable(options.cells, options.workers).map(slugs => world.bootWorker(slugs)));
173
186
  return world;
174
187
  }
175
- private bootWorker(slugs: readonly string[]): Promise<void> {
188
+ /** A worker on its row. At startup its cells are in the table at once, and any failure ends the process (Q77). SA33: a `late` worker's cells
189
+ * join the table only once it has booted, and one that fails to boot is let go with nobody seated on it; after its boot it is like any. */
190
+ private bootWorker(slugs: readonly string[], late = false): Promise<void> {
176
191
  const link = this.options.boot(slugs), index = this.workers.push(link) - 1;
177
- for (const slug of slugs) this.links.set(slug, link);
192
+ if (!late) for (const slug of slugs) this.links.set(slug, link);
193
+ let up = false;
178
194
  return new Promise((resolve, reject) => {
179
- const ended = (reason: string): void => { this.options.log({ at: 'worker.ended', index, slugs, reason }); reject(new Error(reason)); this.options.crashed(new Error(reason)); };
180
- link.listen(news => { if (news.kind === 'booted') { this.options.log({ at: 'worker.booted', index, slugs, ms: news.ms }); resolve(); } else if (news.kind === 'failed') ended(news.reason); else this.heard(index, news); }, ended);
195
+ const ended = (reason: string): void => {
196
+ this.options.log({ at: 'worker.ended', index, slugs, reason }); reject(new Error(reason)); this.up.delete(link); this.resident.delete(link);
197
+ if (late && !up) { link.stop(); if (this.workers.at(-1) === link) this.workers.pop(); return; }
198
+ this.options.crashed(new Error(reason));
199
+ };
200
+ link.listen(news => {
201
+ 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(); }
202
+ else if (news.kind === 'failed') ended(news.reason); else this.heard(index, news);
203
+ }, ended);
181
204
  });
182
205
  }
206
+ /**
207
+ * SA33: open cells on a running world (a placement the API made, J314) on a worker of their own. No other worker is told anything, so every
208
+ * player in another cell stays where they are, and the door seats a player in a new cell only once its worker has booted. A cell this world
209
+ * already opens is skipped. Rejects, with nothing opened, when the worker fails to boot. The next restart deals them out with the rest.
210
+ */
211
+ async openCells(cells: readonly string[]): Promise<readonly string[]> {
212
+ const fresh = [...new Set(cells)].filter(cell => !this.links.has(cell) && !this.booting.has(cell));
213
+ if (fresh.length === 0 || this.draining) return [];
214
+ for (const cell of fresh) this.booting.add(cell);
215
+ let opened: readonly string[] = fresh;
216
+ try {
217
+ if (this.options.roads !== true) await this.bootWorker(fresh, true);
218
+ else { const done: string[] = []; for (const cell of fresh) done.push(...await this.placeOnRoads(cell)); opened = done; }
219
+ } finally { for (const cell of fresh) this.booting.delete(cell); }
220
+ this.options.log({ at: 'cells.opened', cells: opened, total: this.links.size });
221
+ return opened;
222
+ }
223
+ /**
224
+ * SA34a: with roads, a placed cell opens on the worker of the open cell nearest it, so that worker's road hands a seat in (GC15 crosses
225
+ * only inside one worker), and every booted worker's road lays it out. Every order carries the door's whole placed list, in its order, so
226
+ * each worker numbers the placed cells' frames as the door does. Rejects, with nothing opened, when its worker can't open it.
227
+ */
228
+ private async placeOnRoads(fresh: string): Promise<readonly string[]> {
229
+ const grid = gridAssembly(), spot = (cell: string): readonly [number, number] | undefined => grid.cells.find(row => row.instance === cell)?.cell;
230
+ const [fx, fz] = spot(fresh) ?? [0, 0];
231
+ const distance = (cell: string): number => { const at = spot(cell); return at === undefined ? Infinity : Math.abs(at[0] - fx) + Math.abs(at[1] - fz); };
232
+ const nearest = [...this.links.keys()].reduce<string | undefined>((best, cell) => best === undefined || distance(cell) < distance(best) ? cell : best, undefined);
233
+ const host = nearest === undefined ? undefined : this.links.get(nearest);
234
+ if (host === undefined) throw new Error('No worker to open a placed cell on');
235
+ const id = ++this.asked, cells = placedCells();
236
+ const answer = new Promise<{ readonly opened: readonly string[]; readonly error?: string }>(resolve => { this.placings.set(id, resolve); });
237
+ for (const link of this.up) link.send({ kind: 'place', id: link === host ? id : 0, cells, open: link === host ? [fresh] : [] });
238
+ const { opened, error } = await answer;
239
+ for (const cell of opened) this.links.set(cell, host);
240
+ if (error !== undefined) throw new Error(error);
241
+ return opened;
242
+ }
183
243
  private heard(index: number, news: WorkerNews): void {
184
244
  if (news.kind === 'found') { this.finds.get(news.id)?.(news); this.finds.delete(news.id); }
185
245
  // GO7: a late `left` from the cell a goto moved them out of must not unseat them (or free their Name) in the new one.
@@ -195,6 +255,13 @@ export class World {
195
255
  else if(news.kind==='playtest')this.options.playtest?.(news.row);
196
256
  else if (news.kind === 'cell') this.options.log({ at: 'cell.booted', index, slug: news.slug, ms: news.ms });
197
257
  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); }
258
+ else if (news.kind === 'placed') {
259
+ const link = this.workers[index];
260
+ if (news.resident !== undefined && link !== undefined) this.resident.set(link, news.resident);
261
+ const answer = this.placings.get(news.id);
262
+ if (answer !== undefined) { this.placings.delete(news.id); answer(news); }
263
+ if (news.error !== undefined) this.options.log({ at: 'cells.place-refused', index, error: news.error });
264
+ }
198
265
  else if (news.kind === 'drained') { this.drains.get(index)?.(); this.drains.delete(index); }
199
266
  else if (news.kind === 'crossing') void this.crossing(news.slug, news.device, news.to, news.at);
200
267
  else if (news.kind === 'crossed') {
@@ -408,10 +475,15 @@ export class World {
408
475
  for (const end of this.ends) this.sayCountdown(end);
409
476
  this.scope.timeout(ms, () => { this.options.restart(); });
410
477
  }
411
- /** What `/health` says: no player data. `table` is each open cell and the worker it runs on (GO3, MP1.4). */
412
- health(): { readonly build: string; readonly cells: number; readonly workers: number; readonly awake: number; readonly players: number; readonly table: Readonly<Record<string, number>> } {
478
+ /**
479
+ * What `/health` says: no player data. `table` is each open cell and the worker it runs on (GO3, MP1.4). `resident` (ROAD-RESIDENT RR2) is
480
+ * what the booted workers say they hold: cells open in memory, roads open, and the strips those roads stand on.
481
+ */
482
+ health(): { readonly build: string; readonly cells: number; readonly workers: number; readonly awake: number; readonly players: number; readonly table: Readonly<Record<string, number>>; readonly resident: { readonly cells: number; readonly roads: number; readonly strips: number } } {
413
483
  const table = Object.fromEntries([...this.links].map(([cell, link]) => [cell, this.workers.indexOf(link)]));
414
- return { build: this.options.build, cells: this.links.size, workers: this.workers.length, awake: new Set(this.seated.values()).size, players: this.seated.size, table };
484
+ const rows = [...this.resident.values()];
485
+ const resident = { cells: rows.reduce((sum, row) => sum + row.cells, 0), roads: rows.filter(row => row.road).length, strips: rows.reduce((sum, row) => sum + row.strips, 0) };
486
+ return { build: this.options.build, cells: this.links.size, workers: this.workers.length, awake: new Set(this.seated.values()).size, players: this.seated.size, table, resident };
415
487
  }
416
488
  /** Stop: everyone is saved and told `restart`, and the queue gets its time. */
417
489
  async drain(): Promise<boolean> {
@@ -7,6 +7,7 @@ import { prepareAssetDecoders } from '@wildshard/format/product';
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';
10
+ import { registerInstalled } from '@wildshard/engine/game/shardfile/installedSides';
10
11
  import type { NearColliders } from '@wildshard/engine/physics/nearColliders';
11
12
  import { installCableModes } from '@wildshard/engine/player/modes';
12
13
  import { createNativeCombatFrame, nativeRangedItem, otherCombatFrame, readNativeRangedItem, type NativeCombatFrame, type NativeRangedItem } from '@wildshard/engine/game/plugin/nativeItems';
@@ -50,8 +51,6 @@ export interface HeadlessRuntimeInstallation {
50
51
  readonly combat?: NativeCombatFrame;
51
52
  /** A net room's world, which also runs the fights a tape leaves out. */
52
53
  readonly room?: boolean;
53
- /** GC15: a grid cell open onto its worker's road; its baked page walls are left out (`NativeAssemblyContext.road`). */
54
- readonly road?: boolean;
55
54
  restoring: boolean;
56
55
  /** Strictly decoded continuation; reinstall its dynamic actor roster before native restore. Never step here. */
57
56
  snapshot?: Readonly<SimSnapshot | SimSnapshotBytes>;
@@ -201,6 +200,7 @@ export async function prepareNativeRuntime(provided: HeadlessRuntimeInput, room?
201
200
  if (plan.level.id !== identity.id || plan.level.seed !== identity.seed) throw new Error('Trusted runtime simulation identity mismatch');
202
201
  return { ...plan, install: (host, context) => {
203
202
  installRoomRespawn(host, places);
203
+ if (places.length > 0) registerInstalled(host, 'places'); // SS3: a room respawns its players at the page's named places
204
204
  installRopeDecks(host, decks, context.restoring); // NL5: the planks the page stands on
205
205
  installCableModes(host.scope, source.modes?.traverse ?? [], host.flags).bindNative(host);
206
206
  const declared = source.runtime?.binds?.includes('movers') === true || hasDeclaredClientPage(source) ? source.movers : [];
@@ -220,11 +220,13 @@ export async function prepareNativeRuntime(provided: HeadlessRuntimeInput, room?
220
220
  { id: 'movers.carried', restoring: context.restoring, restoreFlags: new Set(host.flags.all), drive: true });
221
221
  }
222
222
  plan.install(host, context);
223
+ if (carried.length > 0) registerInstalled(host, 'movers'); // SS3
223
224
  // SERVER-PARITY HS2: every other declared mover the page stands on (Driftwood's moored boat, a `platform` on the swell), when
224
225
  // the plan has no mover motion of its own. A plan that drives movers (Far Reach's recipe) owns them all, its skipped rows too.
225
226
  // Rope chains stay with the rope decks above (NL5). Its own step, joined: a room saved before HS2 has none and builds them.
226
227
  const rows = shardRows(host).bodies, planMoves = declared.some(row => rows.has(`script:${row.id}`) && row.carry === undefined);
227
228
  const moored = planMoves ? [] : declared.filter(row => row.carry === undefined && row.kind !== 'chain');
229
+ if (planMoves || moored.length > 0) registerInstalled(host, 'movers');
228
230
  if (moored.length > 0) new MoverScriptDriver(moored, host).install(host, { content: { identity: source.identity,
229
231
  sim: { ...source.sim, bindings: [] }, state: source.state }, assets: new Map(), rules: { fields: {}, archetypes: [], events: [], maxEntities: 32 } },
230
232
  { id: 'movers.moored', restoring: context.restoring, restoreFlags: new Set(host.flags.all), drive: true, joined: true });
@@ -232,7 +234,7 @@ export async function prepareNativeRuntime(provided: HeadlessRuntimeInput, room?
232
234
  }
233
235
  /** Install the selected plan into one fresh or strictly restored native host.
234
236
  * A failed install disposes its world; installation may emit no gameplay effects. */
235
- export async function createTrustedHeadlessResident(preparation: HeadlessRuntimeInput, snapshot?: string | Readonly<SimSnapshot | SimSnapshotBytes>, world?: { readonly room?: boolean; readonly road?: boolean; readonly near?: NearColliders; readonly page?: PageProgress }): Promise<TrustedHeadlessResident> {
237
+ export async function createTrustedHeadlessResident(preparation: HeadlessRuntimeInput, snapshot?: string | Readonly<SimSnapshot | SimSnapshotBytes>, world?: { readonly room?: boolean; readonly near?: NearColliders; readonly page?: PageProgress }): Promise<TrustedHeadlessResident> {
236
238
  // The roster rolls its herds while this installs, so a room opened afterwards is too late: a save from a native-Math boot
237
239
  // would hold recipes its restore on the portable table can't reproduce.
238
240
  installPortableMath();
@@ -243,7 +245,7 @@ export async function createTrustedHeadlessResident(preparation: HeadlessRuntime
243
245
  const saved = snapshot === undefined ? undefined : typeof snapshot === 'string' ? decodeSimSnapshotBytes(snapshot) : admitSimSnapshotBytes(snapshot);
244
246
  const combat = createNativeCombatFrame();
245
247
  const otherCommands = new Map<string, readonly HeadlessCommand[]>();
246
- const context: HeadlessRuntimeInstallation = { combat, ...(world?.room === true ? { room: true } : {}), ...(world?.road === true ? { road: true } : {}), restoring: saved !== undefined, ...(saved === undefined ? {} : { snapshot: saved }), commands: () => commands, playerCommands: id => otherCommands.get(id) ?? [], emit: effect => { effects.push(effect); } };
248
+ const context: HeadlessRuntimeInstallation = { combat, ...(world?.room === true ? { room: true } : {}), restoring: saved !== undefined, ...(saved === undefined ? {} : { snapshot: saved }), commands: () => commands, playerCommands: id => otherCommands.get(id) ?? [], emit: effect => { effects.push(effect); } };
247
249
  const ports = { ...plan.ports, rapier: preparation.rapier };
248
250
  let installing: SimHost | undefined;
249
251
  let host: SimHost;
@@ -259,6 +261,7 @@ export async function createTrustedHeadlessResident(preparation: HeadlessRuntime
259
261
  const lead = leadPlayer(host);
260
262
  // ENG-18: a room catches its seats' falls itself (cellWorld's FallFloor); a resident alone catches its own, or nobody does.
261
263
  const caught = world?.room === true ? null : residentFallNet(host, shardPlayArea(preparation.shard.manifest?.bounds, preparation.product), host.level.player.at);
264
+ if (caught !== null && preparation.product !== undefined) registerInstalled(host, 'fallFloor'); // SS3: the page's play area, read off its rows
262
265
  const routes = actRoutes(host), held = routes.launcher;
263
266
  routes.launcher = (slot, reload, fire) => launcherTakes(nativeRangedItem(host, slot)?.kind, reload, fire) || held?.(slot, reload, fire) === true;
264
267
  const lend = (input: readonly HeadlessCommand[]): void => {
@@ -298,7 +301,9 @@ export async function createTrustedHeadlessResident(preparation: HeadlessRuntime
298
301
  dispose: () => { host.dispose(); },
299
302
  };
300
303
  }
301
- /** Worker-side composition only: owns one trusted resident (its real SimHost, native continuation and scoped installers). */
304
+ /** Worker-side composition only: owns one trusted resident (its real SimHost, native continuation and scoped installers).
305
+ * @deprecated SERVER-PARITY HS1: the bare resident is a world no player runs. Tick `openWorldAdapter`
306
+ * (`@wildshard/engine/host/openWorld`), the room's own world; this stays only until every shard's CI has moved. */
302
307
  export async function createTrustedHeadlessAdapter(preparation: HeadlessRuntimeInput, snapshot?: string): Promise<TickWorkerAdapter> {
303
308
  const resident = await createTrustedHeadlessResident(preparation, snapshot), { host } = resident;
304
309
  const tape=createTrustedHeadlessTape(host,input=>resident.step(input),()=>resident.effects);
@@ -0,0 +1,62 @@
1
+ // SERVER-PARITY SS3 (meta docs/plans/SERVER-PARITY-PLAN.md). SS2 (shard-format `featureSides`) gives every `client/plan`
2
+ // feature kind and `world.assembly` stage kind a side, and names, for a `both` or `server` kind, the key its server installer
3
+ // registers under. Each installer that builds a server half calls `registerInstalled(host, key)` (kept in
4
+ // src/server/game/shardfile/installedSides.ts, which the game's installers may import) when it actually builds one, so a
5
+ // booted room can say which of its product's server halves ran. `missingInstallers` lists the sided kinds whose key no
6
+ // installer registered: NET-LAG NL5's rope bridge (a page-built `rope-deck` the room never built) is that shape.
7
+ import { CLIENT_FEATURE_SIDES, WORLD_ASSEMBLY_STAGE_SIDES, type SideEntry } from '@wildshard/format/featureSides';
8
+ import type { ServerInstallerKey } from '@wildshard/engine/game/shardfile/installedSides';
9
+ import type { ShardProduct } from '@wildshard/engine/game/shardfile/shardProduct';
10
+
11
+ /** Every SS2 server key, and the engine owner(s) that register it. A key SS2 adds without an entry here fails
12
+ * `test/side-installers.test.ts`. */
13
+ export const SERVER_INSTALLERS: Readonly<Record<ServerInstallerKey, string>> = Object.freeze({
14
+ arenaRoom: 'native assembly `boss.arena` (a room)',
15
+ collision: 'native assembly `collision` / `collision.pieces`, the runtime-plan world, a data cell\'s simulation when it built prop solids',
16
+ fallFloor: 'standalone/cellWorld.ts `FallFloor` over `shardPlayArea`; a lone resident\'s `residentFallNet`',
17
+ grapple: 'native assembly `grapple`',
18
+ harvest: 'native assembly `installNativeHarvest` (a pack inventory)',
19
+ heldArms: 'native assembly `held.arms` (a room), `item.swept` (the swept kit the page\'s held claims arm)',
20
+ heldBoss: 'the runtime-plan world\'s boss encounter',
21
+ heldRanged: 'native assembly `item.ranged`',
22
+ keepsakes: 'loot/keepsakeProgression.ts `installKeepsakeProgression` (each player\'s progression rewards, from installPlayerOwned)',
23
+ loadout: 'native assembly `loadout`, `held.arms` and `item.swept` (each owns the equip route)',
24
+ melee: 'the runtime-plan held melee',
25
+ movers: 'headlessRuntime.ts carried and moored movers, or the plan\'s own mover motion',
26
+ places: 'headlessRuntime.ts room respawn places, standalone/cellWorld.ts discoveries',
27
+ portalRide: 'native assembly `portal.ride`',
28
+ // one key for every `view.program` row: a page-only pose (Driftwood's bridge sway, Nine Dragon's movers) stays a KNOWN line until HS6
29
+ poseViews: 'native assembly `encounter.patrol` slots and `boss.open-arena`',
30
+ questComposition: 'native assembly `quest.composition`',
31
+ questHost: 'the runtime-plan declared quest host',
32
+ ropeDecks: 'ropeDecks.ts `installRopeDecks`',
33
+ saves: 'quest/serverChapters.ts (each player\'s feat counts and bond), quest/chapterRecords.ts (the open arena\'s boss record)',
34
+ slots: 'native assembly `encounter.patrol` slots (a room)',
35
+ stealth: 'native assembly `held.arms` stealth (a room, SS4)',
36
+ windElite: 'native assembly `encounter.patrol` wind elite (a room)',
37
+ });
38
+
39
+ /** One sided kind in a product: where it is declared, its kind, and the key of the server half it needs. */
40
+ export interface ServerSide { readonly where: 'client/plan' | 'world.assembly'; readonly kind: string; readonly key: string }
41
+ const serverKey = (entry: SideEntry | undefined): string | null => entry === undefined || entry.side === 'view' ? null : entry.server;
42
+
43
+ /** Every `both` or `server` kind a product's `client/plan` declares, once each. A product with no plan has none. */
44
+ export function serverSides(product: Pick<ShardProduct, 'has' | 'section'>): readonly ServerSide[] {
45
+ if (!product.has('client/plan')) return [];
46
+ const out = new Map<string, ServerSide>(), add = (where: ServerSide['where'], kind: string, entry: SideEntry | undefined): void => {
47
+ // admission (SS2) refuses an unsided kind, so a kind with no entry never reaches a room
48
+ if (entry === undefined) throw new Error(`Unsided ${where} kind ${kind}`);
49
+ const key = serverKey(entry);
50
+ if (key !== null) out.set(`${where} ${kind}`, { where, kind, key });
51
+ };
52
+ for (const feature of product.section('client/plan').features) {
53
+ add('client/plan', feature.kind, CLIENT_FEATURE_SIDES[feature.kind]);
54
+ if (feature.kind === 'world.assembly') for (const stage of feature.rows.stages) add('world.assembly', stage.kind, WORLD_ASSEMBLY_STAGE_SIDES[stage.kind]);
55
+ }
56
+ return [...out.values()];
57
+ }
58
+
59
+ /** Each sided kind of `product` whose server key is not in `keys` (a booted host's `installedKeys`), as `<where> <kind> (<key>)`. */
60
+ export function missingInstallers(product: Pick<ShardProduct, 'has' | 'section'>, keys: ReadonlySet<string>): readonly string[] {
61
+ return serverSides(product).filter(side => !keys.has(side.key)).map(side => `${side.where} ${side.kind} (${side.key})`);
62
+ }
@@ -0,0 +1,59 @@
1
+ // SERVER-PARITY HS1 (meta docs/plans/SERVER-PARITY-PLAN.md): one world-build entry. A dedicated room, the phone's grid worker
2
+ // (through `openCellWorld`, its per-cell form) and the headless tick adapter a shard's CI and the bake worker boot all open the
3
+ // same composition: the trusted resident, then the server's chapters, doors, discoveries, owned book, lone walls and fall floor.
4
+ // Before HS1 the tick adapter booted the bare resident, a fourth world no player runs, so a shard journey had to install
5
+ // chapters (and the rest) by hand to test what a room does.
6
+ import { createSimSnapshotSerializer, checkSimSnapshotWire, snapshotSimHostBytes, type SimSnapshot } from '@wildshard/engine/sim/snapshot';
7
+ import type { SimHost } from '@wildshard/engine/sim';
8
+ import { SaveStore } from '@wildshard/engine/saves/store';
9
+ import { createTrustedHeadlessTape } from '../../shared/host/headlessTape';
10
+ import { runHeadlessJourney } from '../../shared/host/headlessJourney';
11
+ import { MAX_TICK_SNAPSHOT_CHARS, type HeadlessCommand } from '../../shared/host/tickProtocol';
12
+ import type { HeadlessRuntimeInput } from './headlessRuntime';
13
+ import type { TickWorkerAdapter } from './tickWorkerLoop';
14
+ import { nativeCell, openCellWorld, type CellWorld, type CellWorldOptions } from './standalone/cellWorld';
15
+ import { residentFallNet, shardPlayArea } from './standalone/fallFloor';
16
+
17
+ /** How a world opens. `room`: every solid held and no page's save seeds it (a dedicated room, a CI journey). */
18
+ export interface OpenWorldOptions extends Partial<Omit<CellWorldOptions, 'wholeSolids' | 'pageless'>> {
19
+ readonly room?: boolean;
20
+ /** The grid instance it is. Left out, the shard's own slug. */
21
+ readonly cell?: string;
22
+ readonly snapshot?: string | SimSnapshot;
23
+ }
24
+
25
+ /** Open `input`'s world, native or data. Left out, the saves are this world's own (nothing persists) and the world is lone. */
26
+ export function openWorld(input: HeadlessRuntimeInput, options: OpenWorldOptions = {}): Promise<CellWorld> {
27
+ const { room = false, cell, snapshot, saves = new SaveStore({ local: null, session: null }), lone = true, ...rest } = options;
28
+ return openCellWorld({ instance: cell ?? input.shard.identity.slug }, input, snapshot, { ...rest, saves, lone, ...(room ? { wholeSolids: true, pageless: true } : {}) });
29
+ }
30
+
31
+ /** The headless tick adapter, on a room's world. */
32
+ export type WorldAdapter = TickWorkerAdapter & { readonly host: SimHost };
33
+
34
+ /** A tick adapter (a shard's CI journeys, the bake worker) on the world `openWorld` opens as a room. A data cell has no trusted
35
+ * resident to tick: the bake worker runs a data shard on its own simulation. */
36
+ export async function openWorldAdapter(input: HeadlessRuntimeInput, snapshot?: string): Promise<WorldAdapter> {
37
+ if (!nativeCell(input)) throw new Error('A tick adapter runs a native world');
38
+ const world = await openWorld(input, { room: true, ...(snapshot === undefined ? {} : { snapshot }) }), { host, resident } = world;
39
+ if (resident === undefined) { world.dispose(); throw new Error('A tick adapter runs a native world'); }
40
+ // a room's resident leaves falls to its seats (ENG-18). With no seats here, every player keeps the resident's own net: the
41
+ // page's play area, and its grace for an edge dock under the floor (Sky Reach's)
42
+ const caught = residentFallNet(host, shardPlayArea(input.shard.manifest?.bounds, input.product), host.level.player.at);
43
+ const step = (commands: readonly HeadlessCommand[]): void => { resident.step(commands); caught(); };
44
+ let tape: ReturnType<typeof createTrustedHeadlessTape>, serializer: ReturnType<typeof createSimSnapshotSerializer>;
45
+ try { tape = createTrustedHeadlessTape(host, step, () => resident.effects); serializer = createSimSnapshotSerializer(); } catch (error) { world.dispose(); throw error; }
46
+ return {
47
+ host,
48
+ step,
49
+ observe: () => {
50
+ checkSimSnapshotWire(snapshotSimHostBytes(host), MAX_TICK_SNAPSHOT_CHARS);
51
+ return { tick: host.state.tick, effects: [...resident.effects] };
52
+ },
53
+ verbTape: tape,
54
+ journey: plan => runHeadlessJourney(host, step, plan),
55
+ commit: () => ({ tick: host.state.tick, snapshot: serializer.serialize(snapshotSimHostBytes(host)), effects: [...resident.effects] }),
56
+ finish: () => ({ ticks: host.state.tick, lanes: 0, steps: 0 }),
57
+ dispose: () => { try { world.dispose(); } finally { serializer.dispose(); } },
58
+ };
59
+ }
@@ -5,6 +5,7 @@ import { rideable } from '@wildshard/engine/physics/CharacterMotor';
5
5
  import { RopeChain } from '@wildshard/engine/physics/ropeChain';
6
6
  import { tagOf } from '@wildshard/engine/physics/surface';
7
7
  import type { ShardProduct } from '@wildshard/engine/game/shardfile/shardProduct';
8
+ import { registerInstalled } from '@wildshard/engine/game/shardfile/installedSides';
8
9
 
9
10
  type RopeDeckStage = Extract<WorldAssemblyStage, { kind: 'rope-deck' }>;
10
11
  type RopeChainStage = Extract<WorldAssemblyStage, { kind: 'rope-chain' }>;
@@ -45,6 +46,7 @@ export function installRopeDecks(host: SimHost, product: ShardProduct | undefine
45
46
  const stages = ropeChainStages(product), owners = stages.map(({ deck }) => JSON.stringify(deck.site.deck.owner));
46
47
  // a saved chain is found by its planks' owner: two decks of one site would each find both chains
47
48
  if (new Set(owners).size !== owners.length) throw new Error('Native rope decks need an owner each');
49
+ if (stages.length > 0) registerInstalled(host, 'ropeDecks'); // SS3
48
50
  for (const { stage, deck, facts } of stages) {
49
51
  const rows = deck.site.deck;
50
52
  const build = (): void => {