@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
@@ -0,0 +1,276 @@
1
+ /** S12 (J330): cook-side tier masters, first slice. A shard holds one master per texture at the largest size any tier
2
+ * wants; the cook gives each tier its own size by dropping the KTX2 mip levels above that tier's largest. No re-encode:
3
+ * every level a tier keeps is the master's own bytes, so a phone draws the master's own pixels at every distance where
4
+ * the master's top level was minified anyway, which is most of what a phone draws.
5
+ *
6
+ * Cuttable: UASTC (`vkFormat` 0) and raw ASTC, with Zstandard or no supercompression, whose levels stand alone.
7
+ * BasisLZ (ETC1S) shares a codebook across levels, so it stays as it is until the cook re-encodes (S12c).
8
+ *
9
+ * GLBs carry their images inside (57 of Pine's 102 MB of `.glb`). `glbImages` takes them out, and `tierGlb` puts each
10
+ * back at the tier's size, moving every other buffer view and meshopt stream by whole 16-byte steps so no alignment
11
+ * changes. Pure bytes in, bytes out: no file system, no shardfile. `phoneTier` (S12b) gives a shard's KTX2 table its phone
12
+ * files, which `shardHalf` lists in the phone manifests. */
13
+ // oxlint-disable-next-line import/no-nodejs-modules -- The cook is a Node process (J28).
14
+ import {createHash} from 'node:crypto';
15
+
16
+ const KTX2_ID = [0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a];
17
+ const LEVEL_INDEX = 80;
18
+ const BASIS_LZ = 1;
19
+ const GLB_MAGIC = 0x46546c67, JSON_CHUNK = 0x4e4f534a, BIN_CHUNK = 0x004e4942;
20
+
21
+ /** Vulkan ASTC formats (UNORM and SRGB pairs) to their block size. */
22
+ const ASTC_BLOCKS: Readonly<Record<number, readonly [number, number]>> = {
23
+ 157: [4, 4], 158: [4, 4], 159: [5, 4], 160: [5, 4], 161: [5, 5], 162: [5, 5], 163: [6, 5], 164: [6, 5],
24
+ 165: [6, 6], 166: [6, 6], 167: [8, 5], 168: [8, 5], 169: [8, 6], 170: [8, 6], 171: [8, 8], 172: [8, 8],
25
+ };
26
+
27
+ export interface Ktx2Info {
28
+ readonly vkFormat: number;
29
+ readonly width: number;
30
+ readonly height: number;
31
+ readonly levels: number;
32
+ readonly scheme: number;
33
+ }
34
+
35
+ const viewOf = (bytes: Uint8Array): DataView => new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
36
+
37
+ export function isKtx2(bytes: Uint8Array): boolean {
38
+ return bytes.length >= LEVEL_INDEX && KTX2_ID.every((byte, at) => bytes[at] === byte);
39
+ }
40
+
41
+ export function ktx2Info(bytes: Uint8Array): Ktx2Info {
42
+ if (!isKtx2(bytes)) throw new Error('Not a KTX2 file');
43
+ const view = viewOf(bytes);
44
+ return {vkFormat: view.getUint32(12, true), width: view.getUint32(20, true), height: view.getUint32(24, true), levels: view.getUint32(40, true), scheme: view.getUint32(44, true)};
45
+ }
46
+
47
+ /** The same texture with its largest side at most `maxSize`, or the same bytes when there is nothing it can cut. */
48
+ export function trimKtx2(bytes: Uint8Array, maxSize: number): Uint8Array {
49
+ if (!isKtx2(bytes)) return bytes;
50
+ const view = viewOf(bytes), info = ktx2Info(bytes);
51
+ const depth = view.getUint32(28, true), layers = view.getUint32(32, true), faces = view.getUint32(36, true);
52
+ // Only block formats whose 16-byte blocks keep a level's alignment: UASTC (`vkFormat` 0) and ASTC.
53
+ if ((info.vkFormat !== 0 && ASTC_BLOCKS[info.vkFormat] === undefined) || info.scheme === BASIS_LZ || info.levels <= 1 || depth > 1 || layers > 1 || faces !== 1) return bytes;
54
+ let drop = 0;
55
+ while (drop < info.levels - 1 && Math.max(info.width >> drop, info.height >> drop) > maxSize) drop++;
56
+ if (drop === 0) return bytes;
57
+
58
+ const levels = info.levels - drop, dfdAt = view.getUint32(48, true), dfdLength = view.getUint32(52, true);
59
+ const kvdAt = view.getUint32(56, true), kvdLength = view.getUint32(60, true);
60
+ const sgdAt = Number(view.getBigUint64(64, true)), sgdLength = Number(view.getBigUint64(72, true));
61
+ const kept = Array.from({length: levels}, (_, level) => {
62
+ const entry = LEVEL_INDEX + 24 * (level + drop);
63
+ const at = Number(view.getBigUint64(entry, true)), length = Number(view.getBigUint64(entry + 8, true));
64
+ return {body: bytes.subarray(at, at + length), uncompressed: view.getBigUint64(entry + 16, true)};
65
+ });
66
+ // Unsupercompressed levels sit on 16 bytes (every cuttable block is 16 bytes, and 16 is a multiple of 4); compressed ones on 1.
67
+ const levelAlign = info.scheme === 0 ? 16 : 1;
68
+ const align = (at: number, to: number): number => Math.ceil(at / to) * to;
69
+ const newDfd = LEVEL_INDEX + 24 * levels, newKvd = kvdLength === 0 ? 0 : newDfd + dfdLength;
70
+ let at = newDfd + dfdLength + kvdLength;
71
+ const newSgd = sgdLength === 0 ? 0 : align(at, 8);
72
+ if (sgdLength > 0) at = newSgd + sgdLength;
73
+ const offsets: number[] = [];
74
+ for (let level = levels - 1; level >= 0; level--) { at = align(at, levelAlign); offsets[level] = at; at += kept[level]?.body.length ?? 0; }
75
+
76
+ const out = new Uint8Array(at), write = viewOf(out);
77
+ out.set(bytes.subarray(0, LEVEL_INDEX));
78
+ write.setUint32(20, Math.max(1, info.width >> drop), true);
79
+ write.setUint32(24, info.height === 0 ? 0 : Math.max(1, info.height >> drop), true);
80
+ write.setUint32(40, levels, true);
81
+ write.setUint32(48, newDfd, true);
82
+ write.setUint32(56, newKvd, true);
83
+ write.setBigUint64(64, BigInt(newSgd), true);
84
+ out.set(bytes.subarray(dfdAt, dfdAt + dfdLength), newDfd);
85
+ if (kvdLength > 0) out.set(bytes.subarray(kvdAt, kvdAt + kvdLength), newKvd);
86
+ if (sgdLength > 0) out.set(bytes.subarray(sgdAt, sgdAt + sgdLength), newSgd);
87
+ kept.forEach(({body, uncompressed}, level) => {
88
+ const entry = LEVEL_INDEX + 24 * level, offset = offsets[level] ?? 0;
89
+ write.setBigUint64(entry, BigInt(offset), true);
90
+ write.setBigUint64(entry + 8, BigInt(body.length), true);
91
+ write.setBigUint64(entry + 16, uncompressed, true);
92
+ out.set(body, offset);
93
+ });
94
+ return out;
95
+ }
96
+
97
+ interface GltfView {buffer: number; byteOffset?: number; byteLength: number; extensions?: {EXT_meshopt_compression?: {buffer: number; byteOffset?: number; byteLength: number}}}
98
+ interface Gltf {accessors?: {bufferView?: number; sparse?: {indices: {bufferView: number}; values: {bufferView: number}}}[]; bufferViews?: GltfView[]; buffers?: {byteLength: number; uri?: string}[]; images?: {bufferView?: number; mimeType?: string; uri?: string}[]}
99
+ interface Glb {readonly json: Gltf; readonly bin: Uint8Array}
100
+
101
+ function readGlb(bytes: Uint8Array): Glb | undefined {
102
+ if (bytes.length < 20) return undefined;
103
+ const view = viewOf(bytes);
104
+ if (view.getUint32(0, true) !== GLB_MAGIC || view.getUint32(16, true) !== JSON_CHUNK) return undefined;
105
+ const jsonLength = view.getUint32(12, true), json = JSON.parse(new TextDecoder().decode(bytes.subarray(20, 20 + jsonLength))) as Gltf;
106
+ const binAt = 20 + jsonLength;
107
+ if (binAt + 8 > bytes.length || view.getUint32(binAt + 4, true) !== BIN_CHUNK) return {json, bin: new Uint8Array()};
108
+ return {json, bin: bytes.subarray(binAt + 8, binAt + 8 + view.getUint32(binAt, true))};
109
+ }
110
+
111
+ function writeGlb(json: Gltf, bin: Uint8Array): Uint8Array {
112
+ const text = new TextEncoder().encode(JSON.stringify(json)), jsonLength = Math.ceil(text.length / 4) * 4, binLength = Math.ceil(bin.length / 4) * 4;
113
+ const out = new Uint8Array(12 + 8 + jsonLength + (binLength > 0 ? 8 + binLength : 0)), view = viewOf(out);
114
+ view.setUint32(0, GLB_MAGIC, true); view.setUint32(4, 2, true); view.setUint32(8, out.length, true);
115
+ view.setUint32(12, jsonLength, true); view.setUint32(16, JSON_CHUNK, true);
116
+ out.fill(0x20, 20, 20 + jsonLength); out.set(text, 20);
117
+ if (binLength > 0) { view.setUint32(20 + jsonLength, binLength, true); view.setUint32(24 + jsonLength, BIN_CHUNK, true); out.set(bin, 28 + jsonLength); }
118
+ return out;
119
+ }
120
+
121
+ export interface GlbImage {readonly index: number; readonly mimeType: string; readonly bytes: Uint8Array}
122
+
123
+ /** Every image a GLB carries in its own buffer, in image order. */
124
+ export function glbImages(bytes: Uint8Array): readonly GlbImage[] {
125
+ const glb = readGlb(bytes);
126
+ if (glb === undefined) return [];
127
+ return (glb.json.images ?? []).flatMap((image, index) => {
128
+ const view = image.bufferView === undefined ? undefined : glb.json.bufferViews?.[image.bufferView];
129
+ if (view?.buffer !== 0) return [];
130
+ const at = view.byteOffset ?? 0;
131
+ return [{index, mimeType: image.mimeType ?? '', bytes: glb.bin.subarray(at, at + view.byteLength)}];
132
+ });
133
+ }
134
+
135
+ /** The GLB with each embedded image swapped for `replace`'s answer (the same image when it answers the same bytes). Every
136
+ * other range of the buffer keeps its bytes and moves down by whole 16-byte steps. Overlapping or shared image views
137
+ * are left alone: the same bytes come back. */
138
+ export function withImages(bytes: Uint8Array, replace: (image: GlbImage) => Uint8Array): Uint8Array {
139
+ const glb = readGlb(bytes);
140
+ if (glb === undefined) return bytes;
141
+ const views = glb.json.bufferViews ?? [];
142
+ const cuts = new Map<number, Uint8Array>();
143
+ for (const image of glbImages(bytes)) {
144
+ const viewIndex = glb.json.images?.[image.index]?.bufferView;
145
+ if (viewIndex === undefined) continue;
146
+ const next = replace(image);
147
+ if (next !== image.bytes && next.length < image.bytes.length) cuts.set(viewIndex, next);
148
+ }
149
+ if (cuts.size === 0) return bytes;
150
+ // A cut view must be used by images alone and overlap nothing else in buffer 0, or moving the rest would tear it.
151
+ const ranges = views.flatMap((view, index) => {
152
+ const own = view.buffer === 0 ? [{index, at: view.byteOffset ?? 0, end: (view.byteOffset ?? 0) + view.byteLength}] : [];
153
+ const meshopt = view.extensions?.EXT_meshopt_compression;
154
+ return meshopt?.buffer === 0 ? [...own, {index: -1, at: meshopt.byteOffset ?? 0, end: (meshopt.byteOffset ?? 0) + meshopt.byteLength}] : own;
155
+ });
156
+ const imageViews = (glb.json.images ?? []).map(image => image.bufferView);
157
+ for (const viewIndex of cuts.keys()) {
158
+ const cut = ranges.find(range => range.index === viewIndex);
159
+ const shared = imageViews.filter(view => view === viewIndex).length > 1
160
+ || (glb.json.accessors ?? []).some(accessor => accessor.bufferView === viewIndex || accessor.sparse?.indices.bufferView === viewIndex || accessor.sparse?.values.bufferView === viewIndex);
161
+ if (cut === undefined || shared || ranges.some(range => range !== cut && range.at < cut.end && cut.at < range.end)) cuts.delete(viewIndex);
162
+ }
163
+ if (cuts.size === 0) return bytes;
164
+
165
+ const order = [...cuts.keys()].sort((a, b) => (views[a]?.byteOffset ?? 0) - (views[b]?.byteOffset ?? 0));
166
+ const parts: Uint8Array[] = [];
167
+ const moves: {at: number; shift: number}[] = [];
168
+ let read = 0, shift = 0;
169
+ for (const viewIndex of order) {
170
+ const view = views[viewIndex], next = cuts.get(viewIndex);
171
+ if (view === undefined || next === undefined) continue;
172
+ const at = view.byteOffset ?? 0, end = at + view.byteLength;
173
+ // Shrink by whole 16-byte steps, so every later range keeps its alignment; the tail of the last step is zeros.
174
+ const removed = Math.floor((view.byteLength - next.length) / 16) * 16, padded = new Uint8Array(view.byteLength - removed);
175
+ padded.set(next);
176
+ parts.push(glb.bin.subarray(read, at), padded);
177
+ view.byteOffset = at - shift;
178
+ view.byteLength = next.length;
179
+ shift += removed;
180
+ moves.push({at: end, shift});
181
+ read = end;
182
+ }
183
+ parts.push(glb.bin.subarray(read));
184
+ const shiftAt = (offset: number): number => moves.reduce((total, move) => (offset >= move.at ? move.shift : total), 0);
185
+ views.forEach((view, index) => {
186
+ if (view.buffer === 0 && !cuts.has(index)) view.byteOffset = (view.byteOffset ?? 0) - shiftAt(view.byteOffset ?? 0);
187
+ const meshopt = view.extensions?.EXT_meshopt_compression;
188
+ if (meshopt?.buffer === 0) meshopt.byteOffset = (meshopt.byteOffset ?? 0) - shiftAt(meshopt.byteOffset ?? 0);
189
+ });
190
+ const bin = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
191
+ let at = 0;
192
+ for (const part of parts) { bin.set(part, at); at += part.length; }
193
+ const buffer = glb.json.buffers?.[0];
194
+ if (buffer !== undefined) buffer.byteLength = bin.length;
195
+ return writeGlb(glb.json, bin);
196
+ }
197
+
198
+ /** A GLB at one tier: each embedded KTX2 image at most `maxSize` on its largest side. */
199
+ export function tierGlb(bytes: Uint8Array, maxSize: number): Uint8Array {
200
+ return withImages(bytes, image => (image.mimeType === 'image/ktx2' ? trimKtx2(image.bytes, maxSize) : image.bytes));
201
+ }
202
+
203
+ /** GPU memory a KTX2 takes once transcoded, mips included: ASTC 4×4 or BC7 for UASTC (1 byte a texel), its own block
204
+ * size for raw ASTC, ETC2/BC1 for ETC1S (half a byte). An estimate for reports, never a gate's only input. */
205
+ export function ktx2GpuBytes(bytes: Uint8Array): number {
206
+ const info = ktx2Info(bytes);
207
+ const block = ASTC_BLOCKS[info.vkFormat];
208
+ let total = 0;
209
+ for (let level = 0; level < Math.max(1, info.levels); level++) {
210
+ const width = Math.max(1, info.width >> level), height = Math.max(1, info.height >> level);
211
+ total += block === undefined ? Math.ceil(width / 4) * Math.ceil(height / 4) * (info.scheme === BASIS_LZ ? 8 : 16) : Math.ceil(width / block[0]) * Math.ceil(height / block[1]) * 16;
212
+ }
213
+ return total;
214
+ }
215
+
216
+ /** S12b: the largest side a phone draws from one KTX2 table row, or undefined to keep the file as it is. The table's source
217
+ * key is the author's hint (D5): a `#layer` twin (a terrain layer, tiled at a texel a metre) and a horizon strip are S4's
218
+ * 1024 rows, kept on purpose; every other row is 512 on a phone. */
219
+ export const PHONE_TIER_MAX = 512;
220
+ export function phoneTierSize(source: string): number | undefined {
221
+ return source.endsWith('#layer') || /\/horizon\//u.test(source) ? undefined : PHONE_TIER_MAX;
222
+ }
223
+
224
+ /** One phone file the cook made: `from` is the table target it stands in for, `url` its own content-named URL. */
225
+ export interface TierFile {readonly from: string; readonly url: string; readonly bytes: Uint8Array}
226
+ export interface PhoneTier {
227
+ /** The discovery document with each trimmed row's phone target moved to its phone file; desktop maps keep their bytes. */
228
+ readonly discovery: Uint8Array;
229
+ /** Each table target the phone reads at another size: its phone files (one a size, nearly always one). */
230
+ readonly files: ReadonlyMap<string, readonly TierFile[]>;
231
+ /** Table targets a phone row still names as they are (kept by size, unchanged, or not this shard's file), so a phone list keeps them. */
232
+ readonly kept: ReadonlySet<string>;
233
+ }
234
+
235
+ type Json = null | boolean | number | string | readonly Json[] | {readonly [key: string]: Json};
236
+ const isMap = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null && !Array.isArray(value);
237
+ const hex8 = (bytes: Uint8Array): string => createHash('sha256').update(bytes).digest('hex').slice(0, 8);
238
+
239
+ /** The phone tier of a shard's KTX2 table (`discovery.json` `native.ktx2`, any shape: `pageModeKtx2` args, `GPU_FILES`, a bare
240
+ * tier map). Every `phone` map's GLB and KTX2 target that `read` can read is trimmed to its row's size; a target that gets
241
+ * smaller moves to `<name>.t<size>-<hash8>.<ext>` beside it. Undefined when nothing gets smaller, so the cook keeps every
242
+ * byte of today's product. */
243
+ export function phoneTier(discovery: Uint8Array, read: (url: string) => Uint8Array | undefined, size: (source: string) => number | undefined = phoneTierSize): PhoneTier | undefined {
244
+ const document = JSON.parse(new TextDecoder().decode(discovery)) as Json;
245
+ const native = isMap(document) && isMap(document['native']) ? document['native'] : undefined;
246
+ if (native?.['ktx2'] === undefined) return undefined;
247
+ const phoneMaps: Record<string, unknown>[] = [];
248
+ const walk = (value: unknown): void => {
249
+ if (Array.isArray(value)) { for (const item of value) walk(item); return; }
250
+ if (!isMap(value)) return;
251
+ for (const [key, item] of Object.entries(value)) {
252
+ if (key === 'phone' && isMap(item) && Object.values(item).every(target => typeof target === 'string')) phoneMaps.push(item);
253
+ else walk(item);
254
+ }
255
+ };
256
+ walk(native['ktx2']);
257
+ const made = new Map<string, TierFile | null>(), files = new Map<string, TierFile[]>(), kept = new Set<string>();
258
+ for (const map of phoneMaps) for (const [source, target] of Object.entries(map)) {
259
+ if (typeof target !== 'string') continue;
260
+ const max = size(source), match = /^(.*?)(?:-[a-f0-9]{8})?\.(glb|ktx2)$/u.exec(target), bytes = max === undefined || match === null ? undefined : read(target);
261
+ if (max === undefined || match === null || bytes === undefined) { kept.add(target); continue; }
262
+ const key = `${target}@${max}`;
263
+ let file = made.get(key);
264
+ if (file === undefined) {
265
+ // A file the trim can't read keeps today's bytes: one odd texture never stops a cook.
266
+ let trimmed = bytes;
267
+ try { trimmed = match[2] === 'glb' ? tierGlb(bytes, max) : trimKtx2(bytes, max); } catch { trimmed = bytes; }
268
+ file = trimmed.length < bytes.length ? {from: target, url: `${match[1] ?? ''}.t${max}-${hex8(trimmed)}.${match[2] ?? ''}`, bytes: trimmed} : null;
269
+ made.set(key, file);
270
+ if (file !== null) files.set(target, [...files.get(target) ?? [], file]);
271
+ }
272
+ if (file === null) kept.add(target); else map[source] = file.url;
273
+ }
274
+ if (files.size === 0) return undefined;
275
+ return {discovery: new TextEncoder().encode(JSON.stringify(document)), files, kept};
276
+ }
@@ -73,22 +73,26 @@ async function snapshot(page: Page): Promise<Snapshot> {
73
73
  if (probe === undefined) {
74
74
  throw new Error('no game probe')
75
75
  }
76
- const state = probe.state()
76
+ const area = probe.area()
77
77
  return {
78
- pos: state.player.pos,
78
+ pos: probe.state().player.pos,
79
79
  door: globalThis.__workerClientRow?.('blender.door.open'),
80
- solid:
81
- probe.shard.shardfile
82
- ?.targets()
83
- .some((target): boolean => target.solid) ?? false,
84
- flags: state.quest.adventure?.quest ?? [],
80
+ solid: area?.targets.some((target): boolean => target.solid) ?? false,
81
+ flags: area?.flags ?? [],
85
82
  }
86
83
  })
87
84
  }
88
85
 
89
- /** Title, Shard Select, Blender Template, Enter: the way a player starts (J233). */
86
+ /** Title, Shard Select, Blender Template, Enter: the way a player starts (J233). A preview's Shard Select enters the grid
87
+ * (J311), so the page is `platform.grid` and the probe's area is the cell the player is in (T2E-1b). */
90
88
  async function enter(page: Page): Promise<void> {
91
89
  await page.locator('.ws-main-select').waitFor()
90
+ // A reload in play lands on the title under the drop card ("Unexpectedly back at the title", dropModal.ts): a player
91
+ // dismisses it, as here
92
+ const dismiss = page.locator('#wsdrop .dismiss')
93
+ if ((await dismiss.count()) > 0) {
94
+ await dismiss.click()
95
+ }
92
96
  // Blender Template is a Developer shard. The switch is remembered across a reload.
93
97
  const developer = page.locator('.ws-main-dev')
94
98
  if ((await developer.getAttribute('aria-checked')) !== 'true') {
@@ -119,7 +123,9 @@ async function enter(page: Page): Promise<void> {
119
123
  await page.waitForFunction((): boolean => {
120
124
  const probe = globalThis.__wildshard
121
125
  return (
122
- probe?.shard.slug === 'blender-template' &&
126
+ probe?.area()?.slug === 'blender-template' &&
127
+ // The cell's door panels are drawn: its targets are what steps 2, 3 and 7 read
128
+ (probe.area()?.targets.length ?? 0) > 0 &&
123
129
  probe.app.state === 'play' &&
124
130
  (probe.world?.game.frameCount ?? 0) > 5
125
131
  )
@@ -160,9 +166,9 @@ async function doorOpens(page: Page): Promise<void> {
160
166
  await page.waitForFunction(
161
167
  (): boolean =>
162
168
  globalThis.__workerClientRow?.('blender.door.open') === 1 &&
163
- globalThis.__wildshard?.shard.shardfile
164
- ?.targets()
165
- .every((target): boolean => !target.solid) === true,
169
+ globalThis.__wildshard
170
+ ?.area()
171
+ ?.targets.every((target): boolean => !target.solid) === true,
166
172
  undefined,
167
173
  STEP,
168
174
  )
@@ -172,8 +178,7 @@ async function doorOpens(page: Page): Promise<void> {
172
178
  async function earned(page: Page, flag: string): Promise<void> {
173
179
  await page.waitForFunction(
174
180
  (name): boolean =>
175
- globalThis.__wildshard?.state().quest.adventure?.quest?.includes(name) ===
176
- true,
181
+ globalThis.__wildshard?.area()?.flags.includes(name) === true,
177
182
  flag,
178
183
  STEP,
179
184
  )
@@ -5,19 +5,20 @@
5
5
  type SmokeVec3 = Readonly<Record<'x' | 'y' | 'z', number>>
6
6
 
7
7
  interface SmokeProbe {
8
- readonly shard: {
8
+ /** The area the player is in: on a grid page the current cell (T2E-1b), null between cells. */
9
+ readonly area: () => {
9
10
  readonly slug: string
10
- readonly shardfile?: {
11
- readonly targets: () => readonly { readonly solid: boolean }[]
12
- }
13
- }
11
+ readonly instance: string | null
12
+ readonly targets: readonly {
13
+ readonly panel: string
14
+ readonly solid: boolean
15
+ }[]
16
+ readonly flags: readonly string[]
17
+ } | null
14
18
  readonly app: { readonly state: string }
15
19
  readonly world?: { readonly game: { readonly frameCount: number } }
16
20
  readonly state: () => {
17
21
  readonly player: { readonly pos: SmokeVec3; readonly health: number }
18
- readonly quest: {
19
- readonly adventure?: { readonly quest?: readonly string[] }
20
- }
21
22
  }
22
23
  }
23
24
 
@@ -115,16 +115,17 @@ test('Template 2: title, walk, door, guardian, reload', async ({
115
115
  await hideAndSave(page)
116
116
  await page.reload()
117
117
  await enter(page)
118
+ // The server's flags reach the page with its first frames
119
+ await Promise.all(
120
+ ['blender.door', 'blender.guardian', 'blender.complete'].map(
121
+ async (flag): Promise<void> => {
122
+ await earned(page, flag)
123
+ },
124
+ ),
125
+ )
118
126
  const back = await snapshot(page)
119
127
  expect(back.door).toBe(1)
120
128
  expect(back.solid).toBe(false)
121
- expect(back.flags).toEqual(
122
- expect.arrayContaining([
123
- 'blender.door',
124
- 'blender.guardian',
125
- 'blender.complete',
126
- ]),
127
- )
128
129
  lap('reload')
129
130
  })
130
131
 
@@ -2,7 +2,7 @@ import { LastPlace, type Feet, type LastPlaceSaved, type PlaceArea, type Stand }
2
2
  import type { PlayerHealth } from '../../../shared/engine/combat/health';
3
3
 
4
4
  /** The page's death fade (ui/DeathFade: dark, then the fade back): no blow lands on the fallen until then. */
5
- export const FALL_FADE = 1.8;
5
+ export const FALL_FADE = 1.35;
6
6
  /** One player's record. A save holds a player only once they have one. */
7
7
  export type RespawnRow = readonly [id: string, last: LastPlaceSaved, fade: number, falls: number];
8
8
 
@@ -35,6 +35,11 @@ export class RespawnBook {
35
35
  falls(id: string): number { return this.seats.get(id)?.falls ?? 0; }
36
36
  /** True while `id`'s return is still fading in. */
37
37
  fading(id: string): boolean { return (this.seats.get(id)?.fade ?? 0) > 0; }
38
+ /** Respawn now (QA 11-13): `id`'s fade ends at once, so their commands move them again. Nothing else changes. */
39
+ skipFade(id: string): void {
40
+ const seat = this.seats.get(id);
41
+ if (seat !== undefined) seat.fade = 0;
42
+ }
38
43
  /** Count a fall and start the fade its owner's health reads. */
39
44
  fell(id: string, health: PlayerHealth): void {
40
45
  const seat = this.seat(id);
@@ -538,6 +538,9 @@ export class SimHost {
538
538
  }
539
539
  /** Preflight a fixed-step registration without installing a callback or consuming any simulation state. */
540
540
  hasStep(id: string): boolean { return this.callbacks.has(id) || this.afterCallbacks.has(id); }
541
+ /** SERVER-PARITY HS1: every fixed-step owner, in registration order (before bodies, then after), so two hosts built from one
542
+ * product can be compared owner for owner. */
543
+ stepIds(): readonly string[] { return [...this.callbacks.keys(), ...this.afterCallbacks.keys()]; }
541
544
  /** Scoped fixed-step work before bodies by default; afterBodies matches equipment following creature contact.
542
545
  * Removing a registration releases its future snapshot adapter. Registration order remains snapshot order. */
543
546
  onStep(id: string, run: (dt: number, host: SimHost) => void, adapter?: SimStateAdapter, phase: 'beforeBodies' | 'afterBodies' = 'beforeBodies'): () => void {
@@ -4,6 +4,8 @@ import { CharacterMotor } from '@wildshard/engine/physics/CharacterMotor';
4
4
  import { snapshotSimHost, type SimSnapshot } from '@wildshard/engine/sim/snapshot';
5
5
  import { prepareFrameMotors, type FrameMember } from '@wildshard/engine/physics/frame';
6
6
  import { CHUNK_HALF } from '@wildshard/engine/core/config';
7
+ import { entrywayStands } from '@wildshard/engine/physics/query';
8
+ import { mountedPlayerOf } from '@wildshard/engine/game/riding/native';
7
9
  import type { GridAssembly, GridCell, GridPoint } from '../../../shared/game/grid/assembly';
8
10
  import type { ResidencyAllocator } from '../../../shared/game/grid/allocator';
9
11
  import { GridContinuationCache, GRID_CONTINUATION_CACHE_BYTES } from '../../../shared/game/grid/continuations';
@@ -44,6 +46,18 @@ export interface PreparedGridFrame { commit: () => void; cancel: () => void }
44
46
  export interface PreparedGridUnload { commit: () => void; abort: () => void }
45
47
  interface Resident { value: GridResident; touched: number; reservations: number; retained: boolean; evicting: boolean; lease: GridSimLease | undefined }
46
48
 
49
+ /** GRID-CROSSING GC34, ROAD-PRELOAD RP4: a crossing hands the walker to the destination's seat with the speed and the mode (foot,
50
+ * board, swim) they had, so a walk across the line never stops (it started from rest: RP1's ~0.3 s stop at x -260 while the page
51
+ * caught it up), and an owner's seat parked in that cell never mixes the new speed with the mode it was left in. The dedicated server's
52
+ * handover (`CrossTarget.admit`) carries the same. */
53
+ export function carryMotion(from: PlayerSim, to: PlayerSim): void {
54
+ if (to.board.on !== from.board.on) to.setBoard(from.board.on);
55
+ to.board.hoverAir = from.board.hoverAir; to.board.hoverBob = from.board.hoverBob;
56
+ Object.assign(to.swim, from.swim); Object.assign(to.footing, from.footing); to.moveScale = from.moveScale;
57
+ to.velocity.copy(from.velocity); to.impulse.copy(from.impulse); to.fall.grounded = from.fall.grounded;
58
+ Object.assign(to.shove, from.shove); Object.assign(to.dash, from.dash); Object.assign(to.dodge, from.dodge); Object.assign(to.jump, from.jump);
59
+ }
60
+
47
61
  /**
48
62
  * Independent local physics worlds; only a world with a player in it advances, while visible neighbours remain frozen.
49
63
  * Each player crosses on their own (P1-E3.9). `owner` is the player this session was built around, the lead of every host:
@@ -262,6 +276,8 @@ export class GridSimulation {
262
276
  arrival.health.restore({ ...health, lastHurt: health.lastHurt + (destination.clock.now - source.clock.now) * 1000 });
263
277
  transaction.commit(); traveller.releaseMotor(); arrival.attachMotor(rider.motor);
264
278
  arrival.position.copy(rider.position); arrival.yaw = traveller.yaw;
279
+ if (arrival !== traveller) carryMotion(traveller, arrival);
280
+ if (to !== null) landOnGround(destination, arrival);
265
281
  this.sites.set(player, to);
266
282
  if (player !== this.owner) source.removePlayer(player);
267
283
  if (this.occupied(from)) { if (player === this.owner) this.parkOwner(source); } else this.unparkOwner(source);
@@ -343,3 +359,22 @@ export class GridSimulation {
343
359
  if (this.cleanupIssues.length > 0) throw new AggregateError(this.cleanupIssues, 'Grid simulation disposal failed');
344
360
  }
345
361
  }
362
+
363
+ /**
364
+ * GRID-CROSSING GC30b (QA-FEEDBACK-2026-11-13 row 11, J322 "there should never be any walls"): a walker who crosses into a cell whose
365
+ * entryway on that side has no ground of its own (Far Reach's sky islands: Jake walked south off the road at y 0 and fell) is set down
366
+ * on the first ground they can stand on, the cell's own spawn, never left hanging in the air. Its solids may be held near its lead
367
+ * (`NearColliders`), so they are brought up at the entryway before the probe and at the spawn after the move.
368
+ */
369
+ export function landOnGround(host: SimHost, seat: PlayerSim): boolean {
370
+ const { position } = seat, near = host.physics.near;
371
+ // only a walker at the cell's edge, off the road: an `enter` sets down a saved pose inside the cell, where it stood before
372
+ if (Math.max(Math.abs(position.x), Math.abs(position.z)) < CHUNK_HALF - 10) return false;
373
+ near?.update(position.x, position.z);
374
+ if (entrywayStands(host.physics, position.x, position.z)) return false;
375
+ const { at, yaw } = host.level.player, mounted = mountedPlayerOf(host, seat.id);
376
+ // a rider and their horse go together, as a harness's `place` moves them
377
+ if (mounted?.mounted === true) mounted.teleport(at.x, at.z, yaw); else seat.resetPose(at, yaw);
378
+ near?.update(at.x, at.z);
379
+ return true;
380
+ }
@@ -4,6 +4,7 @@ import { actRoutes } from '@wildshard/engine/sim/actRoutes';
4
4
  import { publishOwned, sayFightView } from '@wildshard/engine/sim/shardRows';
5
5
  import { hasNativeInventory, nativeInventoryKeeps, creditNativeInventory } from '../../../shared/game/inventoryLaw';
6
6
  import { harvestDrops } from '../../../shared/game/harvest';
7
+ import { registerInstalled } from '../shardfile/installedSides';
7
8
 
8
9
  const finite = v.pipe(v.number(), v.finite());
9
10
  const corpse = v.strictObject({ id: v.string(), kind: v.string(), variant: v.string(), x: finite, y: finite, z: finite });
@@ -11,6 +12,7 @@ const corpse = v.strictObject({ id: v.string(), kind: v.string(), variant: v.str
11
12
  * Pending carcasses survive a world save; consumed claims are absent from it. */
12
13
  export function installNativeHarvest(host: SimHost): void {
13
14
  if(!hasNativeInventory(host,'pack'))return;
15
+ registerInstalled(host, 'harvest'); // SS3: the page's ambient life drops carcasses the server pays out
14
16
  publishOwned(host,'harvest',(_player,out)=>{out.set('harvest.enabled',1);});
15
17
  const pending = new Map<string, v.InferOutput<typeof corpse>>(), routes = actRoutes(host);
16
18
  const bind = (row: v.InferOutput<typeof corpse>): void => {
@@ -0,0 +1,40 @@
1
+ // SERVER-PARITY SS3b (meta docs/plans/SERVER-PARITY-PLAN.md): the server half of `quest.continuation`'s keepsakes. The page's
2
+ // keepsakes (client/game/compendium/keepsakes.ts) grant each progression state's rewards (Driftwood's sea glass charms: +10 max
3
+ // health at 5 glass) as the flags count up; a room's player held only what the page granted itself, so the server's owned book,
4
+ // the one its effects read, never had them. The room now pays each seated player off their own book's flags, by the same law.
5
+ import * as v from 'valibot';
6
+ import { LootProgressionSchema } from '@wildshard/format/lootBag';
7
+ import type { Shardfile } from '@wildshard/format/shardSchema';
8
+ import type { SimHost } from '@wildshard/engine/sim';
9
+ import { questBooks } from '@wildshard/engine/quest/players';
10
+ import { progressionState } from '../../../shared/game/compendium/keepsakeProgression';
11
+ import { isOwnedId, type Owned, type OwnedId } from '../../../shared/game/loot/Owned';
12
+ import { registerInstalled } from '../shardfile/installedSides';
13
+
14
+ /**
15
+ * Each step, grant every seated player (`seated`: the players whose goods are already open) the progression rewards their
16
+ * book's flags have earned, whenever that book moved: a flag, a restore or an imported save each move it. It never opens a
17
+ * seat itself, so a room's parked lead body is paid only once someone sits in it. Returns a player's release (they left: the
18
+ * next occupant is paid afresh), or null on a shard with no progression.
19
+ */
20
+ export function installKeepsakeProgression(host: SimHost, source: Shardfile, seated: () => Iterable<readonly [string, Owned]>): ((player: string) => void) | null {
21
+ // a barter economy (Pine's) has no progression; a loot economy's is read by its own admitted schema
22
+ const raw = source.rows.loot.find(row => row.economy !== undefined)?.economy, declared = raw === undefined || !('progression' in raw) ? undefined : raw.progression;
23
+ const rows = declared === undefined ? undefined : v.parse(LootProgressionSchema, declared);
24
+ if (rows === undefined || rows.flags.length === 0) return null;
25
+ // the page's declaredLootEconomy refuses an unknown reward id; so does the room, at install
26
+ const states = rows.states.map(state => state.earned.map(reward => { if (!isOwnedId(reward.id)) throw new Error(`Unknown progression reward ${reward.id}`); return reward.id; }));
27
+ const progression: { readonly flags: readonly string[]; readonly states: readonly (readonly OwnedId[])[] } = { flags: rows.flags, states };
28
+ const books = questBooks(host), paid = new Map<string, number>();
29
+ host.onStep('owned.keepsakes', () => {
30
+ for (const [player, owned] of seated()) {
31
+ if (!host.players.has(player)) continue;
32
+ const book = books.of(player);
33
+ if (paid.get(player) === book.version) continue;
34
+ paid.set(player, book.version);
35
+ for (const id of progressionState(progression, flag => book.flags.has(flag))) owned.grant(id);
36
+ }
37
+ });
38
+ registerInstalled(host, 'keepsakes');
39
+ return player => { paid.delete(player); };
40
+ }
@@ -12,6 +12,7 @@ import { Exchange } from '../../../shared/game/loot/exchange';
12
12
  import { isCosmetic, isOwnedId, Owned } from '../../../shared/game/loot/Owned';
13
13
  import { Purse } from '../../../shared/game/loot/Purse';
14
14
  import { installOwnedEffects } from '../loadout/ownedEffects';
15
+ import { installKeepsakeProgression } from './keepsakeProgression';
15
16
  import { OWNED_ROW, WORN_LINE } from '../../../shared/game/loot/ownedRows';
16
17
  import { inventorySave, ownedSave, purseSave, skinSave, compendiumSave, finishPickupSave, saveSlug, CreatureRewardSchema, creatureRewardSave, type CreatureRewardState } from '../../../shared/game/saves';
17
18
 
@@ -228,8 +229,11 @@ export function installPlayerOwned(host: SimHost, shard: string, economy: unknow
228
229
  }
229
230
  return seat;
230
231
  };
232
+ // SS3b: the keepsakes' progression rewards (sea glass charms) land in the same book its effects read
233
+ const keepsakes = source === undefined ? null : installKeepsakeProgression(host, source, () => session !== null
234
+ ? [[questBooks(host).lead.player, session.owned] as const] : [...seats].map(([player, seat]) => [player, seat.owned] as const));
231
235
  publishOwned(host, 'player', (player, out) => { of(player).read(out, pack); });
232
236
  routes.wear = (player, id) => { const { owned } = of(player); if (isOwnedId(id) && isCosmetic(id) && owned.has(id)) owned.toggleWorn(id); };
233
237
  if (shopped) routes.buy = (player, good) => { of(player).buy(good); };
234
- return { of, drop: player => { effects.get(player)?.(); effects.delete(player); seats.delete(player); } };
238
+ return { of, drop: player => { keepsakes?.(player); effects.get(player)?.(); effects.delete(player); seats.delete(player); } };
235
239
  }
@@ -83,6 +83,7 @@ import { installEntrySockets } from "@wildshard/engine/physics/entrySockets";
83
83
  import { addPiece, type AddedPiece } from "@wildshard/engine/physics/pieces";
84
84
  import { leadCommands } from '@wildshard/engine/sim/leadPlayer';
85
85
  import { scriptSeats, type ScriptSeats } from './scriptSeats';
86
+ import { registerInstalled } from '../shardfile/installedSides';
86
87
 
87
88
  type Physics = SimHost['physics'];
88
89
  type PropColliderPort = NonNullable<ReturnType<ReturnType<typeof installShardfileColliders>['get']>>;
@@ -274,6 +275,9 @@ export async function prepareRuntimePlan(shard: Shardfile, assets: ReadonlyMap<s
274
275
  encounters: new Map([[parseBossOwnerRow(recipe.population.owner).actor, encounter]]) },
275
276
  });
276
277
  if (ownsTargets) bindNativeWorldTargets(host, melee, questRuntime, targets, context.emit);
278
+ // SS3: the runtime plan's world holds the scenes' solids and the boss; its held melee and quest host are the page's halves.
279
+ // Its one-slot loadout is no catalogue kit, so it registers no `loadout`.
280
+ for (const key of ['collision', 'heldBoss', 'melee', 'questHost'] as const) registerInstalled(host, key);
277
281
  if (row.columns) bindPlayerColumns(host, shard.modes?.traverse ?? []);
278
282
  keeper.settle();
279
283
  } };
@@ -5,6 +5,7 @@ import type { Collider } from '@dimforge/rapier3d-simd';
5
5
  import { withOwner } from '@wildshard/engine/app/ownership';
6
6
  import { solidReach } from '@wildshard/engine/physics/nearColliders';
7
7
  import type { Physics } from '@wildshard/engine/physics/Physics';
8
+ import { isChunkEdgeWall } from '@wildshard/engine/physics/terrain';
8
9
  import { tagCollider, tagOf, type Material } from '@wildshard/engine/physics/surface';
9
10
  import type { SimHost } from '@wildshard/engine/sim';
10
11
 
@@ -70,7 +71,7 @@ export function installNativeCollision(host:Pick<SimHost,'physics'|'scope'|'onSt
70
71
  options:{readonly resolution:number;readonly omit?:readonly Material[];
71
72
  readonly provenance?:{readonly field:string;readonly step:string;readonly fallback:Material}}):ReadonlyMap<string,object|string> {
72
73
  const owners=new Map<string,object|string>(),policy=options.provenance,omit=new Set(options.omit);
73
- const omitted=(solid:NativeCollisionSolid):boolean=>solid.material!==undefined&&omit.has(solid.material);
74
+ const omitted=(solid:NativeCollisionSolid):boolean=>solid.material!==undefined&&omit.has(solid.material)||omit.has('edge')&&solid.shape===1&&solid.half!==undefined&&(solid.material===undefined||solid.material==='edge')&&isChunkEdgeWall(solid.at,solid.half,solid.rot[3]);
74
75
  if(policy!==undefined){
75
76
  if(!/^[a-z][a-zA-Z0-9]{0,63}$/u.test(policy.field))throw new Error('Invalid native owner field');
76
77
  bake.solids.forEach(solid=>{const id=solid.ownerId;if(omitted(solid)||id===undefined||owners.has(id))return;
@@ -7,6 +7,7 @@ import {installRuntimeState,pageStateOf} from '../../../shared/game/shardfile/ru
7
7
  import type {ObservedRecords} from '../../../shared/game/quest/questObservation';
8
8
  import {featOutcome,witnessSavedFeats} from '../../../shared/game/quest/featCounters';
9
9
  import {nativeQuestInputs,type NativeQuestInputs} from './nativeInputs';
10
+ import {registerInstalled} from '../shardfile/installedSides';
10
11
 
11
12
  interface BossRecord { defeated:boolean;rewardTaken:boolean;kills:number }
12
13
  /** The actual declared boss field and the existing elite continuation, borrowed
@@ -86,6 +87,7 @@ export async function prepareChapterRecords(product:Pick<ShardProduct,'json'|'sh
86
87
  live();return v.parse(elites,eliteOwner.snapshot()).records;
87
88
  }},outcomes:{kill:(kind,variant)=>{featOutcome(counterRows,counterPorts,'kill',kind,variant);},
88
89
  feat:(event,total)=>{featOutcome(counterRows,counterPorts,'event',event,undefined,total);}}};
90
+ registerInstalled(host,'saves'); // SS3b: the boss record and feat counts of quests/persistence.json, in the room's continuation
89
91
  host.onStep(ids.step,()=>{/* Encounters own all writes; this adapter adds no tick work. */}, {
90
92
  snapshot:()=>JSON.stringify({version:1,bosses:read(),counts:readCounts()}),restore:value=>{
91
93
  if(typeof value!=='string')throw new Error('Chapter boss continuation requires its JSON wire');