@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.
Files changed (262) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/index.html +157 -11
  3. package/lint/engine-sides.json +23 -0
  4. package/lint/host-callback-syntax.mjs +2 -1
  5. package/lint/host-callbacks.mjs +3 -3
  6. package/lint/host-files.mjs +5 -4
  7. package/lint/host-register.json +496 -0
  8. package/lint/no-base64.mjs +3 -1
  9. package/lint/ratchet.json +2 -2
  10. package/lint/shard-imports.d.mts +1 -0
  11. package/lint/shard-imports.mjs +60 -13
  12. package/lint/shard-source.d.mts +9 -0
  13. package/lint/shard-source.mjs +91 -0
  14. package/lint/shardfile-boundaries.mjs +10 -8
  15. package/lint/sim-closure.mjs +6 -3
  16. package/lint/wildshard-plugin.d.ts +4 -0
  17. package/lint/wildshard-plugin.js +44 -27
  18. package/package.json +24 -6
  19. package/scripts/app-build/buildIdentity.d.mts +3 -1
  20. package/scripts/app-build/buildIdentity.mjs +25 -5
  21. package/scripts/app-build/builtAt.d.mts +4 -0
  22. package/scripts/app-build/builtAt.mjs +21 -0
  23. package/scripts/app-build/outputProducts.d.mts +3 -0
  24. package/scripts/app-build/outputProducts.mjs +31 -0
  25. package/scripts/app-build/serviceWorker.ts +16 -2
  26. package/scripts/app-build/versionFiles.ts +2 -1
  27. package/scripts/app-build-pipeline.mjs +7 -1
  28. package/scripts/audio-download-proof.mjs +843 -0
  29. package/scripts/build-app.mjs +4 -0
  30. package/scripts/build-mirror.d.mts +2 -0
  31. package/scripts/build-mirror.mjs +5 -4
  32. package/scripts/built-product.mjs +3 -3
  33. package/scripts/cell-mem/metrics-preload.mjs +65 -0
  34. package/scripts/cell-mem-bench.mjs +130 -0
  35. package/scripts/check-chunks.mjs +2 -1
  36. package/scripts/check-devserver.mjs +1 -1
  37. package/scripts/chromium-keychain-check.mjs +4 -2
  38. package/scripts/chromium-keychain.mjs +3 -1
  39. package/scripts/cook.mjs +7 -3
  40. package/scripts/devices.d.mts +4 -0
  41. package/scripts/devices.mjs +39 -0
  42. package/scripts/devserver-client.d.mts +7 -0
  43. package/scripts/devserver-client.mjs +85 -0
  44. package/scripts/doctor-proof.mjs +1 -1
  45. package/scripts/e2e-faults.mjs +159 -0
  46. package/scripts/engine-ci-budget.ts +7 -1
  47. package/scripts/format-lock.mjs +20 -11
  48. package/scripts/generate-title-launch.mjs +3 -2
  49. package/scripts/grid-crossing-walk-proof.mjs +30 -11
  50. package/scripts/heavy-lane.py +25 -1
  51. package/scripts/host-ruler/register-migrate.mjs +242 -0
  52. package/scripts/host-ruler/register.d.mts +36 -0
  53. package/scripts/host-ruler/register.mjs +116 -0
  54. package/scripts/host-ruler/roots.d.mts +29 -0
  55. package/scripts/host-ruler/roots.mjs +333 -0
  56. package/scripts/host-ruler/server-roots.d.mts +23 -0
  57. package/scripts/host-ruler/server-roots.mjs +272 -0
  58. package/scripts/main-watch.d.mts +1 -1
  59. package/scripts/main-watch.mjs +10 -6
  60. package/scripts/map-hash.mjs +3 -6
  61. package/scripts/memory-proof.mjs +158 -0
  62. package/scripts/mmo-bots.mjs +2 -2
  63. package/scripts/offline-proof-rules.d.mts +5 -2
  64. package/scripts/offline-proof-rules.mjs +43 -6
  65. package/scripts/offline-proof.mjs +15 -6
  66. package/scripts/online-rig.mjs +4 -4
  67. package/scripts/page-release/flow.d.mts +1 -0
  68. package/scripts/page-release/flow.mjs +6 -2
  69. package/scripts/page-release.mjs +5 -1
  70. package/scripts/physics-route.json +0 -71
  71. package/scripts/pins-catalogue.ts +103 -0
  72. package/scripts/pins-reuse.mjs +3 -1
  73. package/scripts/pins.ts +22 -14
  74. package/scripts/preview-grid.ts +203 -0
  75. package/scripts/road-preload-proof.mjs +167 -0
  76. package/scripts/server-release/publish.mjs +2 -2
  77. package/scripts/server-release/served-slug.d.mts +2 -0
  78. package/scripts/server-release/served-slug.mjs +10 -0
  79. package/scripts/server-release/sign.d.mts +1 -0
  80. package/scripts/server-release/sign.mjs +3 -7
  81. package/scripts/shard-components.mjs +0 -2
  82. package/scripts/shard-outputs.d.mts +8 -0
  83. package/scripts/shard-outputs.mjs +45 -11
  84. package/scripts/side-parity.d.mts +2 -1
  85. package/scripts/side-parity.mjs +25 -4
  86. package/scripts/test-amber.d.mts +1 -0
  87. package/scripts/test-amber.mjs +10 -0
  88. package/scripts/test-products.json +3 -3
  89. package/scripts/tier-textures-proof.mjs +101 -0
  90. package/scripts/tier-textures.mjs +60 -0
  91. package/scripts/tracked-public.d.mts +1 -0
  92. package/scripts/tracked-public.mjs +17 -0
  93. package/scripts/tsconfig.json +1 -0
  94. package/scripts/vps/wildshard-config +79 -23
  95. package/scripts/worker-client-play.mjs +1 -0
  96. package/scripts/worker-client-proof.mjs +1 -1
  97. package/scripts/worker-client-slug.mjs +44 -0
  98. package/src/cli/engine.mjs +8 -0
  99. package/src/client/app/bootRoute.ts +4 -1
  100. package/src/client/app/dropModal.ts +15 -2
  101. package/src/client/app/entry.ts +96 -13
  102. package/src/client/app/slugPath.ts +5 -0
  103. package/src/client/engine/audio/Audio.ts +20 -2
  104. package/src/client/engine/boot/bakedTextures.ts +3 -2
  105. package/src/client/engine/boot/bootTrace.ts +6 -1
  106. package/src/client/engine/boot/bytes.ts +4 -3
  107. package/src/client/engine/boot/clearDownloads.ts +1 -1
  108. package/src/client/engine/boot/contentRead.ts +4 -0
  109. package/src/client/engine/boot/dropNotice.ts +20 -6
  110. package/src/client/engine/boot/gpuFiles.ts +25 -2
  111. package/src/client/engine/boot/lastEnd.ts +8 -2
  112. package/src/client/engine/boot/parsedPages.ts +127 -58
  113. package/src/client/engine/boot/shardPrefetch.ts +7 -1
  114. package/src/client/engine/boot/sw.ts +19 -0
  115. package/src/client/engine/build.d.ts +2 -0
  116. package/src/client/engine/core/Game.ts +29 -3
  117. package/src/client/engine/core/GpuRecovery.ts +7 -0
  118. package/src/client/engine/core/Volumetrics.ts +5 -0
  119. package/src/client/engine/core/assets.ts +27 -20
  120. package/src/client/engine/core/bootstrap.ts +5 -3
  121. package/src/client/engine/core/ktx2.ts +84 -11
  122. package/src/client/engine/debug/probe.ts +18 -1
  123. package/src/client/engine/explore/Compare.ts +2 -2
  124. package/src/client/engine/explore/TouchFly.ts +3 -5
  125. package/src/client/engine/fx/LightPool.ts +41 -1
  126. package/src/client/engine/input/dom.ts +12 -0
  127. package/src/client/engine/net/predictor.ts +6 -2
  128. package/src/client/engine/player/Player.ts +10 -2
  129. package/src/client/engine/player/TouchControls.ts +12 -4
  130. package/src/client/engine/pwa/sw.js +59 -11
  131. package/src/client/engine/render/drawCheck.ts +96 -0
  132. package/src/client/engine/render/precompile.ts +20 -14
  133. package/src/client/engine/saves/staleBuildNote.ts +46 -0
  134. package/src/client/engine/telemetry/browserErrors.ts +161 -21
  135. package/src/client/engine/telemetry/deviceSnapshot.ts +155 -0
  136. package/src/client/engine/telemetry/screenOutbox.ts +61 -0
  137. package/src/client/engine/telemetry/staleBuildReport.ts +12 -0
  138. package/src/client/engine/ui/DeathFade.ts +99 -11
  139. package/src/client/engine/ui/ErrorModal.ts +13 -6
  140. package/src/client/engine/ui/Feedback.ts +2 -1
  141. package/src/client/engine/ui/Loading.ts +10 -6
  142. package/src/client/engine/ui/Map.ts +2 -1
  143. package/src/client/engine/ui/WeaponStrip.ts +2 -1
  144. package/src/client/engine/ui/backGuard.ts +104 -0
  145. package/src/client/engine/ui/hudAdapters.ts +30 -4
  146. package/src/client/engine/ui/loading.css +17 -0
  147. package/src/client/engine/ui/namePrompt.ts +6 -5
  148. package/src/client/engine/ui/styles/combat.css +12 -0
  149. package/src/client/engine/ui/styles/namePrompt.css +4 -2
  150. package/src/client/game/boot/audio.generated.ts +0 -396
  151. package/src/client/game/boot/bytes.generated.ts +42 -71
  152. package/src/client/game/boot/versions.generated.ts +0 -13
  153. package/src/client/game/compendium/keepsakes.ts +16 -6
  154. package/src/client/game/grapple/tool.ts +10 -7
  155. package/src/client/game/grid/area.ts +38 -0
  156. package/src/client/game/grid/cellLoading.ts +23 -12
  157. package/src/client/game/grid/cellScreens.ts +39 -74
  158. package/src/client/game/grid/live.ts +28 -2
  159. package/src/client/game/grid/liveSession.ts +54 -10
  160. package/src/client/game/grid/menu.ts +4 -0
  161. package/src/client/game/grid/nearPlaceholderPlan.ts +8 -0
  162. package/src/client/game/grid/nearPlaceholderView.ts +9 -3
  163. package/src/client/game/grid/neighbourPanels.ts +10 -1
  164. package/src/client/game/grid/oneWayIn.ts +92 -27
  165. package/src/client/game/grid/pageEntry.ts +19 -0
  166. package/src/client/game/grid/pageShell.ts +1 -1
  167. package/src/client/game/grid/placedCards.ts +55 -0
  168. package/src/client/game/grid/placedCells.ts +131 -0
  169. package/src/client/game/grid/plotAudio.ts +114 -0
  170. package/src/client/game/grid/products.ts +55 -5
  171. package/src/client/game/grid/regionalRuntime.ts +6 -0
  172. package/src/client/game/grid/regionalWorld.ts +15 -2
  173. package/src/client/game/grid/roadCull.ts +44 -14
  174. package/src/client/game/grid/roadLookPlatform.ts +2 -2
  175. package/src/client/game/grid/roadTileBacking.ts +13 -3
  176. package/src/client/game/grid/session.ts +47 -22
  177. package/src/client/game/grid/shardfileFar.ts +9 -3
  178. package/src/client/game/grid/spawnGround.ts +68 -0
  179. package/src/client/game/grid/voidLook.ts +29 -23
  180. package/src/client/game/loot/runtime.ts +3 -1
  181. package/src/client/game/mainMenu.ts +14 -6
  182. package/src/client/game/riding/hud.ts +6 -4
  183. package/src/client/game/session/finish.ts +22 -4
  184. package/src/client/game/session/play.ts +8 -2
  185. package/src/client/game/session/session.ts +4 -1
  186. package/src/client/game/shard/titleList.ts +6 -2
  187. package/src/client/game/shardfile/clientWorker.ts +43 -13
  188. package/src/client/game/shardfile/serverRoute.ts +10 -22
  189. package/src/client/game/slugPage.css +11 -0
  190. package/src/client/game/slugPage.ts +84 -0
  191. package/src/client/game/systems/viewmodel/heldView.ts +6 -3
  192. package/src/client/game/titleDeck.ts +56 -32
  193. package/src/client/host/online/doctor.ts +7 -6
  194. package/src/client/host/online/linkScreens.ts +16 -0
  195. package/src/client/host/online/release.ts +51 -5
  196. package/src/client/host/online/shell.ts +62 -27
  197. package/src/client/host/standalone/shell.ts +7 -3
  198. package/src/cook/game/audioReport.ts +57 -0
  199. package/src/cook/game/entryTotals.ts +26 -6
  200. package/src/cook/game/installedRuntimeReads.ts +3 -0
  201. package/src/cook/game/shardCook.ts +38 -8
  202. package/src/cook/game/tierTextures.ts +276 -0
  203. package/src/e2e/smoke/game.ts +19 -14
  204. package/src/e2e/smoke/page-globals.d.ts +9 -8
  205. package/src/e2e/smoke/template2.spec.ts +8 -7
  206. package/src/server/engine/sim/respawn.ts +6 -1
  207. package/src/server/engine/sim.ts +3 -0
  208. package/src/server/game/grid/simulation.ts +35 -0
  209. package/src/server/game/loot/harvest.ts +2 -0
  210. package/src/server/game/loot/keepsakeProgression.ts +40 -0
  211. package/src/server/game/loot/playerOwned.ts +5 -1
  212. package/src/server/game/plugin/simulation.ts +4 -0
  213. package/src/server/game/population/nativeBake.ts +2 -1
  214. package/src/server/game/quest/chapterRecords.ts +2 -0
  215. package/src/server/game/quest/serverChapters.ts +4 -0
  216. package/src/server/game/quest/serverDoors.ts +11 -5
  217. package/src/server/game/roomRespawn.ts +4 -0
  218. package/src/server/game/shardfile/installedSides.ts +18 -0
  219. package/src/server/game/shardfile/nativeAssemblyHosts.ts +19 -10
  220. package/src/server/game/shardfile/nativeAssemblyInput.ts +1 -4
  221. package/src/server/host/bake/headlessWorker.ts +5 -1
  222. package/src/server/host/dedicated/cellHost.ts +98 -29
  223. package/src/server/host/dedicated/cellProtocol.ts +11 -1
  224. package/src/server/host/dedicated/cellWorker.ts +9 -3
  225. package/src/server/host/dedicated/crossing.ts +6 -2
  226. package/src/server/host/dedicated/dedicatedRoom.ts +21 -8
  227. package/src/server/host/dedicated/gridCells.ts +52 -9
  228. package/src/server/host/dedicated/main.ts +31 -12
  229. package/src/server/host/dedicated/placementFile.ts +56 -0
  230. package/src/server/host/dedicated/releaseFile.ts +17 -10
  231. package/src/server/host/dedicated/roadRoom.ts +21 -5
  232. package/src/server/host/dedicated/socketTransport.ts +2 -1
  233. package/src/server/host/dedicated/workerTable.ts +13 -1
  234. package/src/server/host/dedicated/world.ts +111 -10
  235. package/src/server/host/headlessRuntime.ts +10 -5
  236. package/src/server/host/installers.ts +62 -0
  237. package/src/server/host/openWorld.ts +59 -0
  238. package/src/server/host/ropeDecks.ts +2 -0
  239. package/src/server/host/standalone/cellWorld.ts +25 -19
  240. package/src/server/host/standalone/fallFloor.ts +2 -2
  241. package/src/server/host/standalone/gridServer.ts +7 -4
  242. package/src/server/host/standalone/roadWorld.ts +41 -4
  243. package/src/shared/engine/audio/bootAudio.ts +33 -0
  244. package/src/shared/engine/level/spec.ts +3 -3
  245. package/src/shared/engine/net/acts.ts +3 -0
  246. package/src/shared/engine/net/deviceWord.ts +138 -0
  247. package/src/shared/engine/net/socketFrames.ts +7 -4
  248. package/src/shared/engine/physics/query.ts +27 -0
  249. package/src/shared/engine/physics/terrain.ts +19 -28
  250. package/src/shared/engine/saves/saves.lock.json +15 -0
  251. package/src/shared/engine/sim/actRoutes.ts +2 -0
  252. package/src/shared/game/compendium/keepsakeProgression.ts +24 -0
  253. package/src/shared/game/grid/catalogue.ts +12 -5
  254. package/src/shared/game/grid/catalogueSlot.ts +18 -0
  255. package/src/shared/game/grid/farProxy.ts +6 -5
  256. package/src/shared/game/grid/pageMode.ts +1 -1
  257. package/src/shared/game/grid/placementRows.ts +33 -0
  258. package/src/shared/game/grid/roadLayout.ts +26 -3
  259. package/src/shared/game/grid/singleplayer.json +0 -13
  260. package/src/shared/game/grid/voidFloor.ts +122 -0
  261. package/src/shared/game/strings.ts +15 -0
  262. package/src/shared/host/standalone/netInput.ts +2 -1
@@ -16,17 +16,18 @@ import { NetIdentitySchema } from '@wildshard/engine/net/identity';
16
16
  import { decodeFirstMessage } from '@wildshard/wire/handshake';
17
17
  import { WIRE_MINOR } from '@wildshard/wire/major';
18
18
  import { encodeCountdown, type WorldWord } from '@wildshard/engine/net/socketFrames';
19
+ import { deviceLine, readDeviceWord, type DeviceSnapshot, type DeviceWho } from '@wildshard/engine/net/deviceWord';
19
20
  import {CorrectionSchema} from '@wildshard/engine/net/measurements';
20
21
  import type {PlaytestRow} from './playtest';
21
22
  import type { ChatReport } from '@wildshard/engine/net/chat';
22
- import type { CellOrder, ResumeAt, SavedCheckpoint, SeatEntry, WorkerNews, WorkerReading } from './cellProtocol';
23
+ import type { CellOrder, ResumeAt, SavedCheckpoint, SeatEntry, WorkerNews, WorkerReading, WorkerResident } from './cellProtocol';
23
24
  import { bodyId } from './seats';
24
25
  import { SaveNewerError, type PlayerDoc } from './playerDoc';
25
26
  import { LEAVE_FLAG, LEFT, pumpSocket } from './socketPump';
26
27
  import { SOCKET_SERVER_OPTIONS, SocketTransport } from './socketTransport';
27
28
  import { SaveQuarantinedError, type SaveReceipt, type SaveWrite } from './saves/saveStore';
28
29
  import { workerTable } from './workerTable';
29
- import { cellName, cellShard, roadHome } from './gridCells';
30
+ import { cellName, cellShard, gridAssembly, placedCells, roadHome } from './gridCells';
30
31
  import { VoiceRelay, type VoiceIceServer } from './voiceRelay';
31
32
  import { DEFAULT_ALLOWED_ORIGINS, DEFAULT_TRUST_PROXY, originAllowed, trustedAddress, type TrustProxy } from './doorTrust';
32
33
 
@@ -115,6 +116,11 @@ export interface WorldOptions {
115
116
  readonly trustProxy?: TrustProxy;
116
117
  /** VH10: the pages a browser may open a socket from; `null` is any. The game's own hosts when absent. */
117
118
  readonly allowedOrigins?: readonly string[] | null;
119
+ /**
120
+ * GC15 (`WORLD_CROSSING=worker`): each worker hosts a road. SA34a: a placed cell then opens on the worker of its nearest open cell, whose
121
+ * 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).
122
+ */
123
+ readonly roads?: boolean;
118
124
  /** A proof's overrides. */
119
125
  readonly helloMs?: number; readonly readyMs?: number; readonly connectsPerMinute?: number; readonly socketsPerIp?: number; readonly graceMs?: number;
120
126
  /** Monotonic connection-budget clock, overridable by local boundary tests. */
@@ -140,6 +146,8 @@ export class World {
140
146
  private readonly ends = new Set<SocketTransport>();
141
147
  /** Links whose player quit (`ready` with `LEAVE_FLAG`) before a body was theirs. */
142
148
  private readonly quits = new WeakSet<SocketTransport>();
149
+ /** DEVICE-TELEMETRY DT4: each socket's device word and the player its hello named, until the one `client.device` line is written. */
150
+ private readonly devices = new WeakMap<SocketTransport, { said?: DeviceSnapshot; who?: DeviceWho; done: boolean }>();
143
151
  /** Clients loading: each holds a seat, and has no body yet. */
144
152
  private readonly pending = new Map<string, PendingSeat>();
145
153
  /** Who has a body, by link or by hold, and in which cell. */
@@ -155,6 +163,14 @@ export class World {
155
163
  /** GC15: devices whose source said `left` while their crossing was in flight: applied if the crossing is abandoned before `cross`. */
156
164
  private readonly leftCrossing = new Set<string>();
157
165
  private asked = 0;
166
+ /** SA33: cells whose late worker is booting, so a second open of the same cell boots nothing. */
167
+ private readonly booting = new Set<string>();
168
+ /** SA34a: workers that have said `booted`, the only ones a `place` order may reach. */
169
+ private readonly up = new Set<WorkerLink>();
170
+ /** RR2: what each booted worker holds (its `booted` news, then each `placed`), for `/health`. */
171
+ private readonly resident = new Map<WorkerLink, WorkerResident>();
172
+ /** SA34a: `place` orders waiting on the worker that opens their cells. */
173
+ private readonly placings = new Map<number, (news: { readonly opened: readonly string[]; readonly error?: string }) => void>();
158
174
  private draining = false;
159
175
  private grace: { readonly endsAt: number; readonly build: string } | null = null;
160
176
  /** J218: who is on voice in each cell, and their signalling. */
@@ -172,14 +188,61 @@ export class World {
172
188
  await Promise.all(workerTable(options.cells, options.workers).map(slugs => world.bootWorker(slugs)));
173
189
  return world;
174
190
  }
175
- private bootWorker(slugs: readonly string[]): Promise<void> {
191
+ /** 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
192
+ * 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. */
193
+ private bootWorker(slugs: readonly string[], late = false): Promise<void> {
176
194
  const link = this.options.boot(slugs), index = this.workers.push(link) - 1;
177
- for (const slug of slugs) this.links.set(slug, link);
195
+ if (!late) for (const slug of slugs) this.links.set(slug, link);
196
+ let up = false;
178
197
  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);
198
+ const ended = (reason: string): void => {
199
+ this.options.log({ at: 'worker.ended', index, slugs, reason }); reject(new Error(reason)); this.up.delete(link); this.resident.delete(link);
200
+ if (late && !up) { link.stop(); if (this.workers.at(-1) === link) this.workers.pop(); return; }
201
+ this.options.crashed(new Error(reason));
202
+ };
203
+ link.listen(news => {
204
+ if (news.kind === 'booted') { up = true; this.up.add(link); if (news.resident !== undefined) this.resident.set(link, news.resident); if (late) for (const slug of slugs) this.links.set(slug, link); this.options.log({ at: 'worker.booted', index, slugs, ms: news.ms }); resolve(); }
205
+ else if (news.kind === 'failed') ended(news.reason); else this.heard(index, news);
206
+ }, ended);
181
207
  });
182
208
  }
209
+ /**
210
+ * 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
211
+ * 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
212
+ * already opens is skipped. Rejects, with nothing opened, when the worker fails to boot. The next restart deals them out with the rest.
213
+ */
214
+ async openCells(cells: readonly string[]): Promise<readonly string[]> {
215
+ const fresh = [...new Set(cells)].filter(cell => !this.links.has(cell) && !this.booting.has(cell));
216
+ if (fresh.length === 0 || this.draining) return [];
217
+ for (const cell of fresh) this.booting.add(cell);
218
+ let opened: readonly string[] = fresh;
219
+ try {
220
+ if (this.options.roads !== true) await this.bootWorker(fresh, true);
221
+ else { const done: string[] = []; for (const cell of fresh) done.push(...await this.placeOnRoads(cell)); opened = done; }
222
+ } finally { for (const cell of fresh) this.booting.delete(cell); }
223
+ this.options.log({ at: 'cells.opened', cells: opened, total: this.links.size });
224
+ return opened;
225
+ }
226
+ /**
227
+ * 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
228
+ * 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
229
+ * each worker numbers the placed cells' frames as the door does. Rejects, with nothing opened, when its worker can't open it.
230
+ */
231
+ private async placeOnRoads(fresh: string): Promise<readonly string[]> {
232
+ const grid = gridAssembly(), spot = (cell: string): readonly [number, number] | undefined => grid.cells.find(row => row.instance === cell)?.cell;
233
+ const [fx, fz] = spot(fresh) ?? [0, 0];
234
+ const distance = (cell: string): number => { const at = spot(cell); return at === undefined ? Infinity : Math.abs(at[0] - fx) + Math.abs(at[1] - fz); };
235
+ const nearest = [...this.links.keys()].reduce<string | undefined>((best, cell) => best === undefined || distance(cell) < distance(best) ? cell : best, undefined);
236
+ const host = nearest === undefined ? undefined : this.links.get(nearest);
237
+ if (host === undefined) throw new Error('No worker to open a placed cell on');
238
+ const id = ++this.asked, cells = placedCells();
239
+ const answer = new Promise<{ readonly opened: readonly string[]; readonly error?: string }>(resolve => { this.placings.set(id, resolve); });
240
+ for (const link of this.up) link.send({ kind: 'place', id: link === host ? id : 0, cells, open: link === host ? [fresh] : [] });
241
+ const { opened, error } = await answer;
242
+ for (const cell of opened) this.links.set(cell, host);
243
+ if (error !== undefined) throw new Error(error);
244
+ return opened;
245
+ }
183
246
  private heard(index: number, news: WorkerNews): void {
184
247
  if (news.kind === 'found') { this.finds.get(news.id)?.(news); this.finds.delete(news.id); }
185
248
  // 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 +258,13 @@ export class World {
195
258
  else if(news.kind==='playtest')this.options.playtest?.(news.row);
196
259
  else if (news.kind === 'cell') this.options.log({ at: 'cell.booted', index, slug: news.slug, ms: news.ms });
197
260
  else if (news.kind === 'reading') { this.options.log({ at: 'worker', index, ...news.reading, refusals: this.refusals, connections: this.connectionStats, saves: this.options.saves.stats?.() }); this.options.reading?.(index, news.reading); }
261
+ else if (news.kind === 'placed') {
262
+ const link = this.workers[index];
263
+ if (news.resident !== undefined && link !== undefined) this.resident.set(link, news.resident);
264
+ const answer = this.placings.get(news.id);
265
+ if (answer !== undefined) { this.placings.delete(news.id); answer(news); }
266
+ if (news.error !== undefined) this.options.log({ at: 'cells.place-refused', index, error: news.error });
267
+ }
198
268
  else if (news.kind === 'drained') { this.drains.get(index)?.(); this.drains.delete(index); }
199
269
  else if (news.kind === 'crossing') void this.crossing(news.slug, news.device, news.to, news.at);
200
270
  else if (news.kind === 'crossed') {
@@ -257,11 +327,35 @@ export class World {
257
327
  // GO4: the door's first word, before any hello: how many cells it hosts, and (opus-route2) the shard each runs, so a one-shard
258
328
  // page joins only a world that opens its shard. D7 keeps `/health` private on the rooms address, and a
259
329
  // grid page asks this on a socket of its own (`worldWord`). No build, serial or player data.
260
- end.control('world', new TextEncoder().encode(JSON.stringify({ cells: this.links.size, shards: [...new Set([...this.links.keys()].map(cellShard))] } satisfies WorldWord)).buffer);
330
+ // DEVICE-TELEMETRY DT3: `device: 1` says this door reads the client's device word; a client sends it only then.
331
+ end.control('world', new TextEncoder().encode(JSON.stringify({ cells: this.links.size, shards: [...new Set([...this.links.keys()].map(cellShard))], device: 1 } satisfies WorldWord)).buffer);
332
+ end.onControl((control, bytes) => { if (control === 'device') this.deviceWord(end, bytes); });
261
333
  const timer = this.scope.timeout(this.options.helloMs ?? HELLO_MS, () => { this.refuse('hello-timeout'); end.close('refused'); });
262
334
  const off = end.onMessage((_channel, bytes) => { off(); this.scope.cancelTimer(timer); void this.joining(end, bytes, goto); });
263
335
  end.onClose(() => { off(); this.scope.cancelTimer(timer); });
264
336
  }
337
+ /** DT4: a client's device word, untrusted: one per socket, read and bounded by `readDeviceWord`. A junk or oversized word is counted
338
+ * and dropped, and the connect goes on. */
339
+ private deviceWord(end: SocketTransport, bytes: ArrayBuffer): void {
340
+ const seen = this.devices.get(end) ?? { done: false };
341
+ if (seen.said !== undefined || seen.done) return;
342
+ const said = readDeviceWord(bytes);
343
+ if (said === null) { this.refuse('device-word'); this.options.log({ at: 'client.device-refused', bytes: bytes.byteLength }); seen.done = true; this.devices.set(end, seen); return; }
344
+ seen.said = said; this.devices.set(end, seen); this.deviceSeen(end);
345
+ }
346
+ /** DT4: the hello named this socket's player. */
347
+ private devicePlayer(end: SocketTransport, who: DeviceWho): void {
348
+ const seen = this.devices.get(end) ?? { done: false };
349
+ seen.who ??= who; this.devices.set(end, seen); this.deviceSeen(end);
350
+ }
351
+ /** DT4: one `client.device` journal line per connect, once both the word and the hello's player are in. Privacy: the player id the
352
+ * hello already carries and device characteristics only; never the address, which the door keeps for its limits alone. */
353
+ private deviceSeen(end: SocketTransport): void {
354
+ const seen = this.devices.get(end);
355
+ if (seen === undefined || seen.done || seen.said === undefined || seen.who === undefined) return;
356
+ seen.done = true;
357
+ this.options.log(deviceLine(seen.who, seen.said));
358
+ }
265
359
  private async joining(end: SocketTransport, bytes: ArrayBuffer, goto: string | null): Promise<void> {
266
360
  try { await this.hello(end, bytes, goto); }
267
361
  catch (error) { if (!end.isOpen) return; this.options.log({ at: 'world.join', error: String(error) }); this.refuse(error instanceof SaveNewerError ? 'save-newer' : 'join-failed'); end.close(error instanceof SaveQuarantinedError ? 'refused' : 'retry'); }
@@ -301,6 +395,8 @@ export class World {
301
395
  const said = v.safeParse(NetIdentitySchema, { player: hello.player, name: hello.name });
302
396
  if (!said.success) { this.refuse('identity'); end.close('refused'); return; }
303
397
  const device = said.output.player, typed = cleanName(said.output.name), body = bodyId(this.options.secret, device), { saves } = this.options, holding = this.seated.get(device);
398
+ // DT4: the Name everyone sees and the secret-keyed body id; never the raw player id, which is a bearer credential
399
+ this.devicePlayer(end, { name: this.names.get(device) ?? typed, body });
304
400
  // GC15: a seat mid-crossing is in neither cell for the door to ask: the client dials again in a moment.
305
401
  if (this.crossings.has(device)) { end.close('retry'); return; }
306
402
  if (holding !== undefined) {
@@ -408,10 +504,15 @@ export class World {
408
504
  for (const end of this.ends) this.sayCountdown(end);
409
505
  this.scope.timeout(ms, () => { this.options.restart(); });
410
506
  }
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>> } {
507
+ /**
508
+ * 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
509
+ * what the booted workers say they hold: cells open in memory, roads open, and the strips those roads stand on.
510
+ */
511
+ 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
512
  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 };
513
+ const rows = [...this.resident.values()];
514
+ 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) };
515
+ 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
516
  }
416
517
  /** Stop: everyone is saved and told `restart`, and the queue gets its time. */
417
518
  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 => {
@@ -1,10 +1,9 @@
1
1
  // E7.3: opening one cell's world, shared by the phone's grid (`gridServer.ts`) and a dedicated room (`DedicatedRoom`). What differs
2
2
  // between them is in `CellWorldOptions`: who keeps a player's goods and facts, and whether solids stay near one player.
3
3
  import { bootTask } from '@wildshard/engine/boot/timing';
4
- import { withOwner } from '@wildshard/engine/app/ownership';
5
4
  import type { NetTickInput } from '@wildshard/engine/net/room';
6
5
  import { NearColliders } from '@wildshard/engine/physics/nearColliders';
7
- import { addEdgeWalls } from '@wildshard/engine/physics/terrain';
6
+ import { removeChunkEdgeWalls } from '@wildshard/engine/physics/terrain';
8
7
  import type { SimHost } from '@wildshard/engine/sim';
9
8
  import type { PlayerSim } from '@wildshard/engine/sim/playerSim';
10
9
  import { actRoutes } from '@wildshard/engine/sim/actRoutes';
@@ -26,7 +25,7 @@ import { QUEST_OWNED } from '@wildshard/engine/game/quest/nativeComposition';
26
25
  import { shardRows } from '@wildshard/engine/sim/shardRows';
27
26
  import { createQuestLedger } from '@wildshard/engine/game/quest/ledger';
28
27
  import { serverDiscoveries } from '@wildshard/engine/game/quest/serverPlaces';
29
- import { STORY_ACT, UNSTUCK_ACT } from '@wildshard/engine/net/acts';
28
+ import { RESPAWN_NOW_ACT, STORY_ACT, UNSTUCK_ACT } from '@wildshard/engine/net/acts';
30
29
  import { installServerChapters } from '@wildshard/engine/game/quest/serverChapters';
31
30
  import { installServerDoors } from '@wildshard/engine/game/quest/serverDoors';
32
31
  import { pageOpenDoors } from '@wildshard/engine/game/shardfile/buildingDoor';
@@ -34,7 +33,8 @@ import { pageRuntimeState } from '@wildshard/engine/game/shardfile/runtimeState'
34
33
  import { commandsOf } from '@wildshard/engine/game/grid/roomNet';
35
34
  import { pageSavedFlags } from '@wildshard/engine/world/interact/flags';
36
35
  import { installDeclaredKitItems, type DeclaredKitItems } from '@wildshard/engine/game/shardfile/declaredKitItems';
37
- import { createTrustedHeadlessResident, type HeadlessRuntimeInput } from '../headlessRuntime';
36
+ import { createTrustedHeadlessResident, type HeadlessRuntimeInput, type TrustedHeadlessResident } from '../headlessRuntime';
37
+ import { registerInstalled } from '@wildshard/engine/game/shardfile/installedSides';
38
38
  import { productHeadlessSections } from '@wildshard/engine/host/headlessSections';
39
39
  import type { HeadlessEffect } from '../../../shared/host/tickProtocol';
40
40
  import { FallFloor, shardFallFloor, shardPlayArea } from './fallFloor';
@@ -58,10 +58,14 @@ export interface CellWorld extends GridResident {
58
58
  readonly fallFloor: () => FallFloor;
59
59
  /** The first seat's. */
60
60
  readonly fall: FallFloor;
61
+ /** HS1: a native world's trusted resident, which a tick adapter steps with the lead's own commands. A data cell has none. */
62
+ readonly resident?: TrustedHeadlessResident;
61
63
  }
62
64
  /** What a host lends a cell it opens. */
63
65
  export interface CellWorldOptions {
64
66
  readonly saves: SaveStore;
67
+ /** A cell with no road around it (a one-shard page, `WORLD_CROSSING=off`): its fall floor sets a player back on the ground they last
68
+ * stood on instead of a death. It has no edge walls (GC36, J322), so past its edge a player falls to that floor. */
65
69
  readonly lone: boolean;
66
70
  /** C6: a room holds every solid, since no one list can follow every player. Left out, a native world keeps its solids near its lead. */
67
71
  readonly wholeSolids?: boolean;
@@ -83,14 +87,13 @@ const leadSeat = (host: SimHost): PlayerSim => {
83
87
  /** A cell's fall recovery, off what its shard declares. */
84
88
  /** SS6: the same area the page reads, the manifest's bounds under its `client/plan` rows. An input with no product can't read
85
89
  * those rows, so it keeps the manifest's floor alone and no x/z edge, rather than an edge the page may not have. */
86
- const fallFloorOf = (input: HeadlessRuntimeInput, host: SimHost, lone: boolean): FallFloor => new FallFloor(input.product === undefined
87
- ? shardFallFloor(input.shard.manifest?.bounds?.floor) : shardPlayArea(input.shard.manifest?.bounds, input.product), lone, host.level.player.at);
88
-
89
- /** A lone cell has the walls a shard's own page stands inside; a native bake that holds them already keeps its own (SS10). */
90
- function addLoneWalls(host: SimHost): void { withOwner(host.scope, () => { addEdgeWalls(host.physics, { reuse: true }); }); }
90
+ function fallFloorOf(input: HeadlessRuntimeInput, host: SimHost, lone: boolean): FallFloor {
91
+ if (input.product !== undefined) registerInstalled(host, 'fallFloor'); // SS3: the page's own `player.enter` / `world.runtime-hooks` area
92
+ return new FallFloor(input.product === undefined ? shardFallFloor(input.shard.manifest?.bounds?.floor) : shardPlayArea(input.shard.manifest?.bounds, input.product), lone, host.level.player.at);
93
+ }
91
94
 
92
95
  /** A cell with no native plan: a data shard, which any host can run from its output. */
93
- async function openDataCell(input: HeadlessRuntimeInput, snapshot: string | SimSnapshot | undefined, effects: HeadlessEffect[], lone: boolean): Promise<Pick<CellWorld, 'host' | 'dispose'> & { readonly sim: () => ShardfileSimulation | undefined; readonly kit: () => DeclaredKitItems | null }> {
96
+ async function openDataCell(input: HeadlessRuntimeInput, snapshot: string | SimSnapshot | undefined, effects: HeadlessEffect[]): Promise<Pick<CellWorld, 'host' | 'dispose'> & { readonly sim: () => ShardfileSimulation | undefined; readonly kit: () => DeclaredKitItems | null }> {
94
97
  await Promise.resolve();
95
98
  const { shard, assets, rapier } = input;
96
99
  // A data shard's decisions, moves and targets ride its product sections (TE-ENG1's boss rows): without them the
@@ -102,12 +105,13 @@ async function openDataCell(input: HeadlessRuntimeInput, snapshot: string | SimS
102
105
  const kitOf = (sim: ShardfileSimulation): DeclaredKitItems | null => installDeclaredKitItems(sim.host, shard, sim.itemHooks);
103
106
  if (snapshot === undefined) {
104
107
  const fresh = createShardfileSim(shard, assets, ports), kit = kitOf(fresh);
105
- if (lone) addLoneWalls(fresh.host);
108
+ // SS3: a data shard's simulation builds its declared prop solids; a shard with none built has no server half to claim
109
+ if (fresh.colliders.size > 0) registerInstalled(fresh.host, 'collision');
106
110
  return { host: fresh.host, sim: () => fresh, kit: () => kit, dispose: () => { fresh.dispose(); } };
107
111
  }
108
112
  const probe = createShardfileSim(shard, assets, ports), { level } = probe.host; probe.dispose();
109
113
  const installed: { value?: ReturnType<typeof bindShardfileSim>; kit?: DeclaredKitItems | null } = {};
110
- const host = restoreSimHost(level, { rapier }, typeof snapshot === 'string' ? decodeSimSnapshot(snapshot) : snapshot, restored => { installed.value = bindShardfileSim(restored, shard, assets, { ...ports, restoring: true }); installed.kit = kitOf(installed.value); });
114
+ const host = restoreSimHost(level, { rapier }, typeof snapshot === 'string' ? decodeSimSnapshot(snapshot) : snapshot, restored => { installed.value = bindShardfileSim(restored, shard, assets, { ...ports, restoring: true }); installed.kit = kitOf(installed.value); if (installed.value.colliders.size > 0) registerInstalled(restored, 'collision'); });
111
115
  return { host, sim: () => installed.value, kit: () => installed.kit ?? null, dispose: () => { (installed.value ?? { dispose: () => { host.dispose(); } }).dispose(); } };
112
116
  }
113
117
 
@@ -116,6 +120,7 @@ const SEEN_SLACK = 1.5;
116
120
  /** A named place is the page's to notice, and the server's to check. One the page resolves against a placed object has no world position here, so its word stands: a `seen:` flag draws a map, and pays nothing. */
117
121
  function bindDiscovery(host: SimHost, places: readonly { readonly id: string; readonly area: PlaceArea | null }[]): void {
118
122
  const areas = new Map(places.map(place => [`seen:${place.id}`, place.area]));
123
+ if (places.length > 0) registerInstalled(host, 'places'); // SS3: the server checks a player's word for each named place
119
124
  actRoutes(host).seen = (player, flag) => {
120
125
  const area = areas.get(flag), feet = host.players.get(player)?.position;
121
126
  if (area === undefined || feet === undefined || (area !== null && Math.hypot(feet.x - area.x, feet.z - area.z) > area.r * SEEN_SLACK)) return;
@@ -131,7 +136,7 @@ function ownedOf(host: SimHost, input: HeadlessRuntimeInput, stores: OwnedStores
131
136
  }
132
137
 
133
138
  /** Whether this output runs on the trusted headless owner. */
134
- const nativeCell = (input: HeadlessRuntimeInput): boolean => input.product !== undefined && (hasNativeAssembly(input.product) || input.product.has('sim/runtime-plan'));
139
+ export const nativeCell = (input: HeadlessRuntimeInput): boolean => input.product !== undefined && (hasNativeAssembly(input.product) || input.product.has('sim/runtime-plan'));
135
140
 
136
141
  /** Open `cell`'s world from `input`, at `snapshot` if there is one. */
137
142
  export async function openCellWorld(cell: Pick<GridCell, 'instance'>, input: HeadlessRuntimeInput, snapshot: string | SimSnapshot | undefined, options: CellWorldOptions, refused?: SimSnapshot): Promise<CellWorld> {
@@ -141,25 +146,25 @@ export async function openCellWorld(cell: Pick<GridCell, 'instance'>, input: Hea
141
146
  if (nativeCell(input)) {
142
147
  // J68: a native assembly keeps its ground whole and its solids as data. A saved world holds none of them, so a throwaway fresh one lists them.
143
148
  const near = options.wholeSolids !== true && input.product !== undefined && hasNativeAssembly(input.product) ? new NearColliders() : undefined;
144
- // GC15: a cell that isn't lone opens onto its worker's road, so its baked page walls don't stand at its edge either.
145
- const around = { room: true, ...(lone ? {} : { road: true }), ...(near === undefined ? {} : { near }) };
149
+ const around = { room: true, ...(near === undefined ? {} : { near }) };
146
150
  if (near !== undefined && snapshot !== undefined) (await bootTask('server:restore-collision-inventory', () => createTrustedHeadlessResident(input, undefined, around))).dispose();
147
151
  // A world with no save of its own takes the page's: the flags and records its fights read as they install.
148
152
  const seeded = snapshot === undefined && options.pageless !== true;
149
153
  const page = seeded ? { flags: [...new Set([...new Set([input.shard.identity.slug, cell.instance])].flatMap(level => pageSavedFlags(level)).concat(refused?.flags ?? []))], state: pageRuntimeState(options.saves, cell.instance) } : undefined;
150
154
  const resident = await bootTask(snapshot === undefined ? 'server:simulation-and-collision-create' : 'server:continuation-restore', () => createTrustedHeadlessResident(input, snapshot, page === undefined ? around : { ...around, page })), { host } = resident;
151
- bindDiscovery(host, input.product === undefined ? [] : await serverDiscoveries(input.product)); await installServerChapters(host, input.product, input.shard, resident.fact); await installServerDoors(host, input.product, seeded ? pageOpenDoors(options.saves, placed) : undefined);
152
- if (snapshot === undefined && lone) addLoneWalls(host);
155
+ if (snapshot !== undefined) removeChunkEdgeWalls(host.physics); // GC36: a world saved while lone cells had walls
156
+ bindDiscovery(host, input.product === undefined ? [] : await serverDiscoveries(input.product)); await installServerChapters(host, input.product, input.shard, resident.fact); await installServerDoors(host, input.product, seeded ? pageOpenDoors(options.saves, placed) : undefined, snapshot !== undefined);
153
157
  host.respawn.served = true; actRoutes(host).introLocks = true;
154
158
  const owned = ownedOf(host, input, options.owned, options.profiles), fallFloor = (): FallFloor => fallFloorOf(input, host, lone);
155
- return { host, owned, fallFloor, fall: fallFloor(), dispose: () => { resident.dispose(); }, fact, effects: () => resident.effects,
159
+ return { host, owned, fallFloor, fall: fallFloor(), resident, dispose: () => { resident.dispose(); }, fact, effects: () => resident.effects,
156
160
  adopt: () => { regionalRuntimeCheckpoint(options.saves, placed, input.shard.identity.revision).restore({ animals: [...host.entities.values()] }); return true; }, step: inputs => {
157
161
  const player = leadSeat(host);
158
162
  near?.update(player.position.x, player.position.z);
159
163
  stepResident(resident, player.id, inputs);
160
164
  } };
161
165
  }
162
- const effects: HeadlessEffect[] = [], { host, dispose, sim, kit } = await bootTask(snapshot === undefined ? 'server:data-simulation-and-collision' : 'server:data-continuation-restore', () => openDataCell(input, snapshot, effects, lone));
166
+ const effects: HeadlessEffect[] = [], { host, dispose, sim, kit } = await bootTask(snapshot === undefined ? 'server:data-simulation-and-collision' : 'server:data-continuation-restore', () => openDataCell(input, snapshot, effects));
167
+ if (snapshot !== undefined) removeChunkEdgeWalls(host.physics); // GC36: a world saved while lone cells had walls
163
168
  installRoomRespawn(host, []);
164
169
  installDeclaredClimate(host, input.shard.rows);
165
170
  bindDiscovery(host, input.product === undefined ? [] : await serverDiscoveries(input.product));
@@ -179,6 +184,7 @@ export async function openCellWorld(cell: Pick<GridCell, 'instance'>, input: Hea
179
184
  if (act.kind === 'interact' && act.id.startsWith('seen:') && routes.seen !== null) routes.seen(player, act.id);
180
185
  else if (act.kind === 'interact' && act.id.startsWith(STORY_ACT)) routes.story?.(player, act.id.slice(STORY_ACT.length));
181
186
  else if (act.kind === 'interact' && act.id === UNSTUCK_ACT && routes.unstuck !== null) routes.unstuck(player);
187
+ else if (act.kind === 'interact' && act.id === RESPAWN_NOW_ACT && routes.respawnNow !== undefined) routes.respawnNow(player);
182
188
  else if (claim !== undefined) claim(player);
183
189
  else if (act.kind === 'interact' && sim()?.selectedInteraction(player) === act.id) sim()?.interact(act.id, player);
184
190
  else if (act.kind !== 'climate' && act.kind !== 'buy' && act.kind !== 'board' && act.kind !== 'wear') routes.refused++;
@@ -30,8 +30,8 @@ export const RESIDENT_FALL_GRACE = 0.25;
30
30
 
31
31
  type Body = Pick<PlayerSim, 'yaw' | 'led' | 'resetPose'> & { readonly position: { x: number; y: number; z: number }; readonly fall: { readonly grounded: boolean }; readonly board: { readonly on: boolean } };
32
32
  /** One cell's fall recovery. `soft` takes a player back; a hard floor is a death. `start` is where they go with no safe ground yet.
33
- * The floor is the area's at the player's x/z. Its x/z edge is not enforced here: a lone cell's walls hold the player (P1-E3.9's
34
- * lone-cell test walks Dunes past its ±200 area to the wall at 250), so the page's offline x/z reset stays the page's. */
33
+ * The floor is the area's at the player's x/z. Its x/z edge is not enforced here: a lone cell has no walls (GC36, J322), so a
34
+ * player who walks off its edge falls below the floor and comes back (`standalone-grid-lone.test.ts`); the page's x/z reset stays the page's. */
35
35
  export class FallFloor {
36
36
  private since = 0;
37
37
  private spot: { x: number; y: number; z: number } | null = null;