castle-web-cli 0.4.231 → 0.4.233

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 (368) hide show
  1. package/dist/agent-failures.d.ts +8 -0
  2. package/dist/agent-failures.js +19 -2
  3. package/dist/agent-prompts.d.ts +1 -1
  4. package/dist/agent-prompts.js +10 -3
  5. package/dist/agent.d.ts +64 -3
  6. package/dist/agent.js +170 -81
  7. package/dist/castle-host/host.d.ts +1 -0
  8. package/dist/castle-host/host.js +51 -3
  9. package/dist/castleJson.d.ts +4 -2
  10. package/dist/castleJson.js +2 -0
  11. package/dist/check.d.ts +3 -1
  12. package/dist/check.js +11 -1
  13. package/dist/devSessionStorage.js +47 -1
  14. package/dist/importPinMismatch.d.ts +22 -0
  15. package/dist/importPinMismatch.js +77 -0
  16. package/dist/importRegression.js +3 -15
  17. package/dist/imports.d.ts +10 -3
  18. package/dist/imports.js +88 -20
  19. package/dist/index.js +5 -4
  20. package/dist/init.js +1 -1
  21. package/dist/platformDoc.js +22 -0
  22. package/dist/routerFences.d.ts +5 -0
  23. package/dist/routerFences.js +12 -2
  24. package/dist/save-deck.d.ts +5 -0
  25. package/dist/save-deck.js +37 -4
  26. package/dist/serve.js +3 -0
  27. package/dist/serverBundle.js +5 -3
  28. package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
  29. package/dist/shell/assets/index-MVLfNYd9.css +1 -0
  30. package/dist/shell/index.html +2 -2
  31. package/dist/taskSteer.d.ts +13 -0
  32. package/dist/taskSteer.js +22 -2
  33. package/kits/base/castle.json +1 -1
  34. package/kits/base/package-lock.json +1 -1
  35. package/kits/base/sdk/README.md +79 -2
  36. package/kits/base/sdk/avatar.d.ts +6 -2
  37. package/kits/base/sdk/avatar.js +12 -4
  38. package/kits/base/sdk/castle.d.ts +1 -1
  39. package/kits/base/sdk/commands.d.ts +14 -0
  40. package/kits/base/sdk/hub.d.ts +6 -2
  41. package/kits/base/sdk/hub.js +13 -0
  42. package/kits/base/sdk/multiplayer.js +17 -1
  43. package/kits/base/sdk/save.js +2 -1
  44. package/kits/base/sdk/server/hub.d.ts +87 -0
  45. package/kits/base/sdk/server/hub.js +70 -0
  46. package/kits/base/sdk/server/platformHandle.d.ts +31 -1
  47. package/kits/base/sdk/server/storage.d.ts +13 -0
  48. package/kits/base/sdk/server/storage.js +46 -0
  49. package/kits/base/sdk/server/wrapper.d.ts +36 -5
  50. package/kits/base/sdk/server/wrapper.js +83 -8
  51. package/kits/hub-game/CLAUDE.md +352 -12
  52. package/kits/hub-game/blueprints/avatar-10.scene +28 -0
  53. package/kits/hub-game/blueprints/avatar-11.scene +28 -0
  54. package/kits/hub-game/blueprints/avatar-12.scene +28 -0
  55. package/kits/hub-game/blueprints/avatar-13.scene +28 -0
  56. package/kits/hub-game/blueprints/avatar-14.scene +28 -0
  57. package/kits/hub-game/blueprints/avatar-15.scene +28 -0
  58. package/kits/hub-game/blueprints/avatar-4.scene +28 -0
  59. package/kits/hub-game/blueprints/avatar-5.scene +28 -0
  60. package/kits/hub-game/blueprints/avatar-6.scene +28 -0
  61. package/kits/hub-game/blueprints/avatar-7.scene +28 -0
  62. package/kits/hub-game/blueprints/avatar-8.scene +28 -0
  63. package/kits/hub-game/blueprints/avatar-9.scene +28 -0
  64. package/kits/hub-game/code/client/actorBudget.js +47 -0
  65. package/kits/hub-game/code/client/attention.js +11 -2
  66. package/kits/hub-game/code/client/avatar.js +345 -32
  67. package/kits/hub-game/code/client/avatarCap.js +228 -0
  68. package/kits/hub-game/code/client/avatarColors.js +70 -0
  69. package/kits/hub-game/code/client/avatarFaces.js +21 -0
  70. package/kits/hub-game/code/client/avatarShare.js +251 -0
  71. package/kits/hub-game/code/client/ballot.js +467 -0
  72. package/kits/hub-game/code/client/build.js +22 -0
  73. package/kits/hub-game/code/client/chat.js +12 -0
  74. package/kits/hub-game/code/client/chrome.js +1334 -50
  75. package/kits/hub-game/code/client/companion.js +716 -0
  76. package/kits/hub-game/code/client/companionDress.js +99 -0
  77. package/kits/hub-game/code/client/decor.js +509 -0
  78. package/kits/hub-game/code/client/earned.js +131 -0
  79. package/kits/hub-game/code/client/emoteBubble.js +75 -0
  80. package/kits/hub-game/code/client/grab.js +363 -20
  81. package/kits/hub-game/code/client/hats.js +26 -0
  82. package/kits/hub-game/code/client/hookLayer.js +328 -15
  83. package/kits/hub-game/code/client/hudClear.js +126 -0
  84. package/kits/hub-game/code/client/idle.js +163 -22
  85. package/kits/hub-game/code/client/interestCap.js +81 -0
  86. package/kits/hub-game/code/client/keys.js +36 -0
  87. package/kits/hub-game/code/client/labelsNear.js +205 -0
  88. package/kits/hub-game/code/client/menuIcons.js +34 -0
  89. package/kits/hub-game/code/client/pack.js +6 -2
  90. package/kits/hub-game/code/client/packFormat.js +3 -3
  91. package/kits/hub-game/code/client/rehello.js +167 -0
  92. package/kits/hub-game/code/client/shot.js +92 -0
  93. package/kits/hub-game/code/client/sound.js +63 -8
  94. package/kits/hub-game/code/client/soundscape.js +1151 -0
  95. package/kits/hub-game/code/client/soundscapeActions.js +99 -0
  96. package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
  97. package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
  98. package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
  99. package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
  100. package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
  101. package/kits/hub-game/code/client/soundscapeCues.js +362 -0
  102. package/kits/hub-game/code/client/soundscapeMap.js +181 -0
  103. package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
  104. package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
  105. package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
  106. package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
  107. package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
  108. package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
  109. package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
  110. package/kits/hub-game/code/client/soundscapeUi.js +211 -0
  111. package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
  112. package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
  113. package/kits/hub-game/code/client/spin.js +101 -0
  114. package/kits/hub-game/code/client/state.js +131 -1
  115. package/kits/hub-game/code/client/stuck.js +259 -0
  116. package/kits/hub-game/code/client/talk.js +538 -47
  117. package/kits/hub-game/code/client/tiers.js +541 -27
  118. package/kits/hub-game/code/client/toastBand.js +37 -0
  119. package/kits/hub-game/code/client/together.js +98 -1
  120. package/kits/hub-game/code/client/visibility.js +43 -0
  121. package/kits/hub-game/code/client/wear.js +470 -97
  122. package/kits/hub-game/code/client/yours.js +199 -0
  123. package/kits/hub-game/code/companionSpec.js +45 -0
  124. package/kits/hub-game/code/privateText.js +7 -0
  125. package/kits/hub-game/code/server/actions.js +133 -0
  126. package/kits/hub-game/code/server/actors.js +14 -1
  127. package/kits/hub-game/code/server/ask.js +155 -0
  128. package/kits/hub-game/code/server/ballot.js +539 -0
  129. package/kits/hub-game/code/server/cells.js +100 -0
  130. package/kits/hub-game/code/server/companion.js +82 -0
  131. package/kits/hub-game/code/server/cues.js +70 -0
  132. package/kits/hub-game/code/server/decor.js +269 -0
  133. package/kits/hub-game/code/server/earned.js +461 -0
  134. package/kits/hub-game/code/server/friendBests.js +166 -0
  135. package/kits/hub-game/code/server/friendsAmong.js +232 -0
  136. package/kits/hub-game/code/server/grab.js +296 -11
  137. package/kits/hub-game/code/server/history.js +5 -0
  138. package/kits/hub-game/code/server/hub.js +1317 -52
  139. package/kits/hub-game/code/server/idle.js +30 -11
  140. package/kits/hub-game/code/server/index.js +2 -2
  141. package/kits/hub-game/code/server/labels.js +28 -2
  142. package/kits/hub-game/code/server/manifest.js +424 -8
  143. package/kits/hub-game/code/server/menu.js +133 -0
  144. package/kits/hub-game/code/server/npcs.js +830 -80
  145. package/kits/hub-game/code/server/party.js +13 -2
  146. package/kits/hub-game/code/server/players.js +22 -0
  147. package/kits/hub-game/code/server/say.js +8 -2
  148. package/kits/hub-game/code/server/shot.js +110 -0
  149. package/kits/hub-game/code/server/standing.js +124 -0
  150. package/kits/hub-game/code/server/vis.js +113 -0
  151. package/kits/hub-game/code/server/wear.js +128 -11
  152. package/kits/hub-game/code/server/yours.js +59 -0
  153. package/kits/hub-game/code/shared/cues.js +9 -0
  154. package/kits/hub-game/code/shared/decor.js +41 -0
  155. package/kits/hub-game/code/shared/shot.js +19 -0
  156. package/kits/hub-game/code/shared/spin.js +57 -0
  157. package/kits/hub-game/code/systems/hub.js +1083 -85
  158. package/kits/hub-game/docs/content-pack.md +1 -1
  159. package/kits/hub-game/docs/contract.md +2440 -61
  160. package/kits/hub-game/docs/home-pieces.md +64 -0
  161. package/kits/hub-game/models/avatar-10.pxmodel +28 -0
  162. package/kits/hub-game/models/avatar-11.pxmodel +28 -0
  163. package/kits/hub-game/models/avatar-12.pxmodel +27 -0
  164. package/kits/hub-game/models/avatar-13.pxmodel +24 -0
  165. package/kits/hub-game/models/avatar-14.pxmodel +29 -0
  166. package/kits/hub-game/models/avatar-15.pxmodel +24 -0
  167. package/kits/hub-game/models/avatar-4.pxmodel +29 -0
  168. package/kits/hub-game/models/avatar-5.pxmodel +27 -0
  169. package/kits/hub-game/models/avatar-6.pxmodel +26 -0
  170. package/kits/hub-game/models/avatar-7.pxmodel +25 -0
  171. package/kits/hub-game/models/avatar-8.pxmodel +24 -0
  172. package/kits/hub-game/models/avatar-9.pxmodel +30 -0
  173. package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
  174. package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
  175. package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
  176. package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
  177. package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
  178. package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
  179. package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
  180. package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
  181. package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
  182. package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
  183. package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
  184. package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
  185. package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
  186. package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
  187. package/kits/hub-game/models/hats/cap.pxmodel +162 -0
  188. package/kits/hub-game/models/hats/captain.pxmodel +178 -0
  189. package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
  190. package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
  191. package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
  192. package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
  193. package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
  194. package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
  195. package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
  196. package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
  197. package/kits/hub-game/models/hats/straw.pxmodel +139 -0
  198. package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
  199. package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
  200. package/kits/hub-game/models/hats/witch.pxmodel +147 -0
  201. package/kits/hub-game/package-lock.json +2 -0
  202. package/kits/hub-game/package.json +2 -1
  203. package/kits/hub-game/scripts/check.mjs +78 -11
  204. package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
  205. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
  206. package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
  207. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
  208. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
  209. package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
  210. package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
  211. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
  212. package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
  213. package/kits/hub-game/scripts/gen-earned.mjs +285 -0
  214. package/kits/hub-game/scripts/gen-hats.mjs +827 -0
  215. package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
  216. package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
  217. package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
  218. package/kits/hub-game/scripts/test-actions.mjs +298 -0
  219. package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
  220. package/kits/hub-game/scripts/test-actors.mjs +19 -17
  221. package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
  222. package/kits/hub-game/scripts/test-ask.mjs +269 -0
  223. package/kits/hub-game/scripts/test-attention.mjs +10 -1
  224. package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
  225. package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
  226. package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
  227. package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
  228. package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
  229. package/kits/hub-game/scripts/test-avatar.mjs +540 -7
  230. package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
  231. package/kits/hub-game/scripts/test-build.mjs +31 -0
  232. package/kits/hub-game/scripts/test-cells.mjs +71 -0
  233. package/kits/hub-game/scripts/test-chat.mjs +694 -0
  234. package/kits/hub-game/scripts/test-classic.mjs +2 -0
  235. package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
  236. package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
  237. package/kits/hub-game/scripts/test-companion.mjs +259 -0
  238. package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
  239. package/kits/hub-game/scripts/test-decor.mjs +457 -0
  240. package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
  241. package/kits/hub-game/scripts/test-earned.mjs +1194 -0
  242. package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
  243. package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
  244. package/kits/hub-game/scripts/test-grab-client.mjs +186 -3
  245. package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
  246. package/kits/hub-game/scripts/test-grab.mjs +864 -3
  247. package/kits/hub-game/scripts/test-hats.mjs +483 -0
  248. package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
  249. package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
  250. package/kits/hub-game/scripts/test-hub-trip.mjs +1228 -1
  251. package/kits/hub-game/scripts/test-hud-clear.mjs +1000 -0
  252. package/kits/hub-game/scripts/test-idle.mjs +361 -1
  253. package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
  254. package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
  255. package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
  256. package/kits/hub-game/scripts/test-keys.mjs +46 -1
  257. package/kits/hub-game/scripts/test-labels.mjs +596 -0
  258. package/kits/hub-game/scripts/test-manifest.mjs +282 -0
  259. package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
  260. package/kits/hub-game/scripts/test-menu.mjs +296 -0
  261. package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
  262. package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
  263. package/kits/hub-game/scripts/test-pack.mjs +7 -0
  264. package/kits/hub-game/scripts/test-party.mjs +22 -1
  265. package/kits/hub-game/scripts/test-picker.mjs +314 -0
  266. package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
  267. package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
  268. package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
  269. package/kits/hub-game/scripts/test-say.mjs +59 -2
  270. package/kits/hub-game/scripts/test-shot.mjs +756 -0
  271. package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
  272. package/kits/hub-game/scripts/test-spin.mjs +314 -0
  273. package/kits/hub-game/scripts/test-standing.mjs +416 -0
  274. package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
  275. package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
  276. package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
  277. package/kits/hub-game/scripts/test-tiers.mjs +666 -3
  278. package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
  279. package/kits/hub-game/scripts/test-try-on.mjs +940 -0
  280. package/kits/hub-game/scripts/test-vis.mjs +343 -0
  281. package/kits/hub-game/scripts/test-visibility.mjs +134 -0
  282. package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
  283. package/kits/hub-game/scripts/test-yours.mjs +372 -0
  284. package/kits/multiplayer-3d/CLAUDE.md +50 -0
  285. package/kits/multiplayer-3d/castle.json +5 -5
  286. package/kits/multiplayer-3d/code/client/avatars.js +7 -0
  287. package/kits/multiplayer-3d/code/client/gait.js +65 -0
  288. package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
  289. package/kits/multiplayer-3d/code/options.js +5 -0
  290. package/kits/multiplayer-3d/code/server/ownership.js +10 -2
  291. package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
  292. package/kits/multiplayer-3d/code/server/world.js +7 -0
  293. package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
  294. package/kits/multiplayer-3d/package.json +2 -1
  295. package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
  296. package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
  297. package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
  298. package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
  299. package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
  300. package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
  301. package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
  302. package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
  303. package/kits/physics-2d/CLAUDE.md +9 -0
  304. package/kits/physics-2d/castle.json +2 -2
  305. package/kits/physics-2d/engine/scene.js +288 -1
  306. package/kits/physics-2d/engine/skyKey.js +129 -0
  307. package/kits/physics-2d/engine/stillClock.js +106 -0
  308. package/kits/physics-2d/engine/updateBudget.js +21 -0
  309. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +370 -1
  310. package/kits/physics-3d/CLAUDE.md +1391 -0
  311. package/kits/physics-3d/behaviors/Player.jsx +921 -3
  312. package/kits/physics-3d/castle.json +3 -3
  313. package/kits/physics-3d/docs/pxmodel-format.md +12 -0
  314. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +98 -10
  315. package/kits/physics-3d/engine3d/actornode.js +86 -0
  316. package/kits/physics-3d/engine3d/animationBudget.js +23 -0
  317. package/kits/physics-3d/engine3d/editorWorld.js +6 -0
  318. package/kits/physics-3d/engine3d/emptynodes.js +232 -0
  319. package/kits/physics-3d/engine3d/framecap.js +96 -0
  320. package/kits/physics-3d/engine3d/gait.js +118 -0
  321. package/kits/physics-3d/engine3d/kithooks.js +47 -0
  322. package/kits/physics-3d/engine3d/look.js +507 -48
  323. package/kits/physics-3d/engine3d/lookbake.js +208 -0
  324. package/kits/physics-3d/engine3d/materialpresets.js +2 -0
  325. package/kits/physics-3d/engine3d/motion.js +39 -10
  326. package/kits/physics-3d/engine3d/nearshadows.js +37 -19
  327. package/kits/physics-3d/engine3d/optimize.js +58 -5
  328. package/kits/physics-3d/engine3d/orbitinput.js +755 -0
  329. package/kits/physics-3d/engine3d/orbitlens.js +48 -0
  330. package/kits/physics-3d/engine3d/ownmodel.js +213 -0
  331. package/kits/physics-3d/engine3d/pxmodel.js +42 -11
  332. package/kits/physics-3d/engine3d/shadowfade.js +882 -0
  333. package/kits/physics-3d/engine3d/sky.js +547 -0
  334. package/kits/physics-3d/engine3d/skylife.js +306 -0
  335. package/kits/physics-3d/engine3d/unchanged.js +11 -0
  336. package/kits/physics-3d/engine3d/viewrange.js +52 -0
  337. package/kits/physics-3d/engine3d/world3d.js +870 -87
  338. package/kits/physics-3d/main.jsx +5 -0
  339. package/kits/physics-3d/package.json +1 -1
  340. package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
  341. package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
  342. package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
  343. package/kits/physics-3d/scripts/test-camera-follow.mjs +12 -2
  344. package/kits/physics-3d/scripts/test-camera-orbit.mjs +4588 -0
  345. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
  346. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
  347. package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
  348. package/kits/physics-3d/scripts/test-gait.mjs +387 -0
  349. package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
  350. package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
  351. package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
  352. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
  353. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
  354. package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
  355. package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
  356. package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
  357. package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
  358. package/kits/physics-3d/scripts/test-static-actors.mjs +13 -1
  359. package/kits/physics-3d/scripts/test-static-passes.mjs +1 -1
  360. package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
  361. package/kits/physics-3d/scripts/test-steady-hover.mjs +635 -0
  362. package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
  363. package/kits/physics-3d/systems/physics3d.js +474 -12
  364. package/kits/real-time/castle.json +2 -2
  365. package/kits/real-time/code/server/gameHooks.js +7 -0
  366. package/kits/real-time/code/server/session.js +97 -19
  367. package/package.json +2 -2
  368. package/dist/shell/assets/index-Cf61cNfT.css +0 -1
@@ -0,0 +1,635 @@
1
+ // The Player's hover, with and without `"engine": { "camera": { "follow":
2
+ // "rigid" } }`. Under the key the hover spring and the fall-faster pull are
3
+ // forces, which act once per fixed physics step as gravity does; without it
4
+ // they are impulses, once per drawn frame, and a frame of no steps or of two
5
+ // kicks the player up or lets it drop.
6
+ //
7
+ // The real Player drives the real Physics3DSystem (accumulator, fixed steps,
8
+ // write-back) over a stand-in rapier that integrates a step the way rapier
9
+ // does (the push of the frame first, then gravity and forces spread over the
10
+ // solver's four sub-steps). Where `@dimforge/rapier3d-compat` is installed (a
11
+ // deck's or the kit's own node_modules) everything is run again on the real
12
+ // thing; where it is not, that half is skipped and the line printed says so.
13
+ //
14
+ // - Without the key the Player makes main's calls on `scene.physics3d`, with
15
+ // main's arguments, in main's order (`mainUpdate` is main's Player, copied),
16
+ // and never asks for a force.
17
+ // - With it the player's height does not move walking, on steady frames, on
18
+ // alternating 1/60 and 1/30, on jittered frames and on dropped ones; it
19
+ // stands as high as without the key, and jumps as high.
20
+ // - No body carries a force between frames, or on a frame the Player did not
21
+ // ask for one: disabled, despawned, another scene, the key gone, physics
22
+ // reset, a frame that never reached physics, a step that throws.
23
+ //
24
+ // test-static-actors.mjs runs it (`npm run check`).
25
+ // node scripts/test-steady-hover.mjs [--table]
26
+ import assert from 'node:assert/strict';
27
+ import { existsSync } from 'node:fs';
28
+ import { register } from 'node:module';
29
+ import { dirname, join } from 'node:path';
30
+ import { fileURLToPath, pathToFileURL } from 'node:url';
31
+
32
+ const fakeRapier = `
33
+ const SUBSTEPS = 4;
34
+ export const init = async () => {};
35
+ export const RigidBodyType = { Dynamic: 0, Fixed: 1, KinematicPositionBased: 2, KinematicVelocityBased: 3 };
36
+ export const ActiveEvents = { COLLISION_EVENTS: 1 };
37
+ export const QueryFilterFlags = { EXCLUDE_SENSORS: 1 };
38
+ class Desc {
39
+ constructor(type) { this.type = type; this.at = { x: 0, y: 0, z: 0 }; this.gravityScale = 1; }
40
+ setTranslation(x, y, z) { this.at = { x, y, z }; return this; }
41
+ setRotation() { return this; }
42
+ setGravityScale(scale) { this.gravityScale = scale; return this; }
43
+ lockRotations() { return this; }
44
+ }
45
+ export const RigidBodyDesc = { dynamic: () => new Desc(0), fixed: () => new Desc(1), kinematicPositionBased: () => new Desc(2) };
46
+ const collider = () => { const d = { setFriction: () => d, setRestitution: () => d, setSensor: () => d, setActiveEvents: () => d }; return d; };
47
+ export const ColliderDesc = { ball: collider, capsule: collider, cylinder: collider, cuboid: collider };
48
+ export class Ray { constructor(origin, dir) { this.origin = origin; this.dir = dir; } }
49
+ export class EventQueue { drainCollisionEvents() {} free() {} }
50
+ class Body {
51
+ constructor(desc) { this.type = desc.type; this.pos = { ...desc.at }; this.vel = { x: 0, y: 0, z: 0 }; this.force = { x: 0, y: 0, z: 0 }; this.gravityScale = desc.gravityScale; }
52
+ bodyType() { return this.type; }
53
+ isDynamic() { return this.type === 0; }
54
+ mass() { return 1.5; }
55
+ translation() { return { ...this.pos }; }
56
+ rotation() { return { x: 0, y: 0, z: 0, w: 1 }; }
57
+ linvel() { return { ...this.vel }; }
58
+ setLinvel(v) { this.vel = { x: v.x, y: v.y, z: v.z }; }
59
+ setTranslation(p) { this.pos = { x: p.x, y: p.y, z: p.z }; }
60
+ setRotation() {}
61
+ setNextKinematicTranslation(p) { this.pos = { x: p.x, y: p.y, z: p.z }; }
62
+ setNextKinematicRotation() {}
63
+ applyImpulse(j) { for (const k of ['x', 'y', 'z']) this.vel[k] += j[k] / this.mass(); }
64
+ addForce(f) { for (const k of ['x', 'y', 'z']) this.force[k] += f[k]; }
65
+ resetForces() { this.force = { x: 0, y: 0, z: 0 }; }
66
+ userForce() { return { ...this.force }; }
67
+ }
68
+ export class World {
69
+ constructor(gravity) { this.gravity = gravity; this.bodies = new Set(); this.timestep = 1 / 60; this.handles = 0; }
70
+ createRigidBody(desc) { const body = new Body(desc); this.bodies.add(body); return body; }
71
+ createCollider() { return { handle: (this.handles += 1) }; }
72
+ removeRigidBody(body) { this.bodies.delete(body); }
73
+ // Flat ground whose top is y 0, as the system's own ground body is.
74
+ castRay(ray, max) { const d = ray.origin.y; return d >= 0 && d <= max ? { timeOfImpact: d, collider: { handle: -1 } } : null; }
75
+ step() {
76
+ const h = this.timestep / SUBSTEPS;
77
+ for (const body of this.bodies) {
78
+ if (body.type !== 0) continue;
79
+ for (let i = 0; i < SUBSTEPS; i += 1) {
80
+ for (const k of ['x', 'y', 'z']) {
81
+ body.vel[k] += (this.gravity[k] * body.gravityScale + body.force[k] / body.mass()) * h;
82
+ body.pos[k] += body.vel[k] * h;
83
+ }
84
+ // A capsule 1.4 m tall lying on the ground.
85
+ if (body.pos.y < 0.7) { body.pos.y = 0.7; body.vel.y = Math.max(0, body.vel.y); }
86
+ }
87
+ }
88
+ }
89
+ free() {}
90
+ }
91
+ `;
92
+
93
+ // The nearest installed rapier, from this kit's directory upwards.
94
+ function findRapier() {
95
+ let dir = dirname(dirname(fileURLToPath(import.meta.url)));
96
+ for (;;) {
97
+ const file = join(dir, 'node_modules', '@dimforge', 'rapier3d-compat', 'rapier.mjs');
98
+ if (existsSync(file)) return pathToFileURL(file).href;
99
+ const up = dirname(dir);
100
+ if (up === dir) return null;
101
+ dir = up;
102
+ }
103
+ }
104
+ const realRapier = findRapier();
105
+
106
+ const hooks = `
107
+ import { existsSync, readFileSync } from 'node:fs';
108
+ import { fileURLToPath } from 'node:url';
109
+ const fake = 'data:text/javascript,' + encodeURIComponent(${JSON.stringify(fakeRapier)});
110
+ const real = ${JSON.stringify(realRapier)};
111
+ export async function resolve(specifier, context, next) {
112
+ const parent = context.parentURL ?? '';
113
+ if (specifier === '@dimforge/rapier3d-compat' && parent.endsWith('?steady-fake')) return { url: fake, shortCircuit: true };
114
+ if (specifier === '@dimforge/rapier3d-compat' && parent.endsWith('?steady-real')) return { url: real, shortCircuit: true };
115
+ // This file's own copies of the physics system, one per rapier; settled
116
+ // here so no other test's hooks rewrite the address.
117
+ if (/\\?steady-(fake|real)$/.test(specifier)) return { url: new URL(specifier, parent).href, shortCircuit: true };
118
+ if (specifier.startsWith('@imports/castle.physics-2d/')) {
119
+ specifier = parent.replace(/\\/kits\\/.*/, '/kits/physics-2d/') + specifier.slice(27);
120
+ }
121
+ if ((specifier.startsWith('.') || specifier.startsWith('file:')) && parent.includes('/kits/') && !/\\.(m?js|jsx|json)(\\?.*)?$/.test(specifier)) {
122
+ const base = new URL(specifier, parent).href;
123
+ for (const ext of ['.js', '.jsx']) if (existsSync(fileURLToPath(base + ext))) return next(base + ext, context);
124
+ }
125
+ return next(specifier, context);
126
+ }
127
+ export async function load(url, context, next) {
128
+ if (url.endsWith('/behaviors/Player.jsx')) {
129
+ return { format: 'module', source: readFileSync(fileURLToPath(url), 'utf8'), shortCircuit: true };
130
+ }
131
+ return next(url, context);
132
+ }`;
133
+ register(`data:text/javascript,${encodeURIComponent(hooks)}`);
134
+ const { Player } = await import('../behaviors/Player.jsx');
135
+
136
+ //
137
+ // main's Player, as it was before the key meant anything for the hover: what
138
+ // it asks of `scene.physics3d`, copied line for line (the camera and the hud
139
+ // are test-camera-follow.mjs's business).
140
+ //
141
+
142
+ const DEG = Math.PI / 180;
143
+ const KEY_TURN = 1.35;
144
+ const keyDown = (keys, ...codes) => codes.some((code) => keys.has(code));
145
+
146
+ function mainReadDrive(keys, stick) {
147
+ let forward = 0;
148
+ let turn = 0;
149
+ if (keyDown(keys, 'KeyW', 'ArrowUp')) forward += 1;
150
+ if (keyDown(keys, 'KeyS', 'ArrowDown')) forward -= 1;
151
+ if (keyDown(keys, 'KeyD', 'ArrowRight')) turn += KEY_TURN;
152
+ if (keyDown(keys, 'KeyA', 'ArrowLeft')) turn -= KEY_TURN;
153
+ if (forward === 0 && turn === 0 && stick?.active && Math.hypot(stick.x, stick.y) >= 0.15) {
154
+ forward = -stick.y;
155
+ turn = stick.x;
156
+ }
157
+ return { forward: Math.max(-1, Math.min(1, forward)), turn: Math.max(-KEY_TURN, Math.min(KEY_TURN, turn)) };
158
+ }
159
+
160
+ function mainApplyHover(phys, actor, t, dims, dt) {
161
+ const hit = phys.castRay({ x: t.x, y: t.y, z: t.z }, { x: 0, y: -1, z: 0 }, dims.height, actor);
162
+ const hoverHeight = dims.height / 2 + 0.15;
163
+ const grounded = Boolean(hit && hit.distance < hoverHeight + 0.25);
164
+ const vel = phys.getVelocity(actor);
165
+ if (hit && hit.distance < hoverHeight + 0.4 && vel.y <= 1) {
166
+ const accel = 160 * (hoverHeight - hit.distance) - 18 * vel.y;
167
+ phys.applyImpulse(actor, { x: 0, y: accel * phys.mass(actor) * dt, z: 0 });
168
+ }
169
+ return grounded;
170
+ }
171
+
172
+ function mainApplyMove(phys, actor, move, speed, grounded, dt) {
173
+ const mass = phys.mass(actor);
174
+ const vel = phys.getVelocity(actor);
175
+ if (move) {
176
+ const factor = Math.min(1, dt * 14) * (grounded ? 1 : 0.3);
177
+ phys.applyImpulse(actor, { x: (move.x * speed - vel.x) * mass * factor, y: 0, z: (move.z * speed - vel.z) * mass * factor });
178
+ } else if (grounded) {
179
+ const factor = Math.min(1, dt * 12);
180
+ phys.applyImpulse(actor, { x: -vel.x * mass * factor, y: 0, z: -vel.z * mass * factor });
181
+ }
182
+ }
183
+
184
+ function mainUpdate(props, actor, scene, dt) {
185
+ const phys = scene.physics3d;
186
+ if (!phys?.ready()) return;
187
+ const t = actor.components.Transform;
188
+ const per = (scene.persistent ??= {});
189
+ const rt = actor.runtime;
190
+ if (per.camAngle === undefined) per.camAngle = Math.PI / 4;
191
+ const shape = actor.components.Shape;
192
+ const dims = { radius: shape?.radius ?? 0.35, height: shape?.height ?? 1.4 };
193
+ const grounded = mainApplyHover(phys, actor, t, dims, dt);
194
+ const drive = mainReadDrive(scene.keys, scene.moveInput);
195
+ per.camAngle += drive.turn * props.turnSpeed * dt;
196
+ rt.facing = Math.PI - per.camAngle;
197
+ const move = drive.forward !== 0 ? { x: Math.sin(per.camAngle) * drive.forward, z: -Math.cos(per.camAngle) * drive.forward } : null;
198
+ mainApplyMove(phys, actor, move, props.speed, grounded, dt);
199
+ t.rotationY = rt.facing / DEG;
200
+ if (scene.moveInput?.consumeJump?.()) rt.jumpBuffer = 0.18;
201
+ else rt.jumpBuffer = Math.max(0, (rt.jumpBuffer ?? 0) - dt);
202
+ if ((keyDown(scene.keys, 'Space') || rt.jumpBuffer > 0) && grounded) {
203
+ rt.jumpBuffer = 0;
204
+ const vel = phys.getVelocity(actor);
205
+ phys.setVelocity(actor, { x: vel.x, y: props.jumpSpeed, z: vel.z });
206
+ }
207
+ if (!grounded) {
208
+ const vel = phys.getVelocity(actor);
209
+ if (vel.y < 1) phys.applyImpulse(actor, { x: 0, y: -14 * phys.mass(actor) * dt, z: 0 });
210
+ }
211
+ }
212
+
213
+ //
214
+ // A world of one player on flat ground
215
+ //
216
+
217
+ const FIXED = 1 / 60;
218
+ const PROPS = { ...Player.defaultProps };
219
+
220
+ // Frame lengths, in seconds: `steady` is a 60 Hz page, `alt` one that misses
221
+ // every other vsync, `jitter` a phone's 60 Hz with a millisecond either way,
222
+ // `drops` the same with a missed vsync about one frame in seven.
223
+ function frameLengths(pattern, n) {
224
+ let seed = 12345;
225
+ const rnd = () => (seed = (seed * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff;
226
+ const out = [];
227
+ for (let i = 0; i < n; i += 1) {
228
+ if (pattern === 'steady') out.push(FIXED);
229
+ else if (pattern === 'alt') out.push(i % 2 === 0 ? FIXED : 2 * FIXED);
230
+ else if (pattern === 'jitter') out.push(FIXED + (rnd() - 0.5) * 0.002);
231
+ else out.push((rnd() < 0.15 ? 2 * FIXED : FIXED) + (rnd() - 0.5) * 0.002);
232
+ }
233
+ return out;
234
+ }
235
+ const PATTERNS = ['steady', 'alt', 'jitter', 'drops'];
236
+
237
+ const newPlayer = (x = 0) => ({
238
+ id: 'player',
239
+ components: {
240
+ Transform: { x, y: 1, z: 0, rotationX: 0, rotationY: 0, rotationZ: 0, scaleX: 1, scaleY: 1, scaleZ: 1 },
241
+ Shape: { kind: 'capsule', radius: 0.35, height: 1.4 },
242
+ Body: { type: 'dynamic', lockRotations: true, friction: 0, gravityScale: 2 },
243
+ Solid: {},
244
+ Player: { ...PROPS },
245
+ },
246
+ runtime: {},
247
+ });
248
+
249
+ // `mode` is 'off' (no key), 'steady' (the key) or 'main' (no key, main's
250
+ // Player copied above).
251
+ async function makeWorld(Physics3DSystem, mode) {
252
+ const system = new Physics3DSystem();
253
+ const scene = {
254
+ time: 0,
255
+ keys: new Set(),
256
+ moveInput: null,
257
+ persistent: {},
258
+ three: null,
259
+ cameraFollowsRigidly: mode === 'steady',
260
+ // What SceneRuntime has without `engine.maxFps`.
261
+ maxFps: 0,
262
+ skipsUnchangedActors: false,
263
+ data: {},
264
+ actors: [newPlayer()],
265
+ actorsWith: () => [],
266
+ getActors: () => scene.actors,
267
+ getActor: (id) => scene.actors.find((a) => a.id === id),
268
+ forEachBehavior: () => {},
269
+ };
270
+ system.attach(scene);
271
+ const world = { system, scene, mode, calls: [], atStep: [], abort: false, between: null };
272
+
273
+ // Every call the Player makes on `scene.physics3d`, with what it was given
274
+ // and what it got.
275
+ const api = scene.physics3d;
276
+ scene.physics3d = Object.fromEntries(
277
+ Object.keys(api).map((name) => [
278
+ name,
279
+ (...args) => {
280
+ const result = api[name](...args);
281
+ if (name !== 'ready' && name !== 'bodyOf') {
282
+ world.calls.push(JSON.stringify([name, args.map((a) => (a?.components ? a.id : a)), result ?? null]));
283
+ }
284
+ return result;
285
+ },
286
+ ])
287
+ );
288
+ world.api = api;
289
+ world.body = () => system.bodies.get('player')?.body ?? null;
290
+ world.force = () => world.body()?.userForce().y ?? 0;
291
+
292
+ // What force each body carries at each fixed step.
293
+ const watchSteps = () => {
294
+ const rapier = system.world;
295
+ if (!rapier || rapier.watched) return;
296
+ rapier.watched = true;
297
+ const step = rapier.step.bind(rapier);
298
+ rapier.step = (queue) => {
299
+ world.atStep.push(world.force());
300
+ if (world.throwAtStep) {
301
+ world.throwAtStep = false;
302
+ throw new Error('a step that throws');
303
+ }
304
+ return step(queue);
305
+ };
306
+ };
307
+
308
+ world.frame = (dt, keys = []) => {
309
+ scene.time += dt;
310
+ scene.keys = new Set(keys);
311
+ for (const actor of scene.actors) {
312
+ const props = actor.components.Player;
313
+ if (!props || props.$enabled === false) continue;
314
+ if (mode === 'main') mainUpdate(props, actor, scene, dt);
315
+ else new Player(props).update(actor, scene, dt);
316
+ }
317
+ world.between?.();
318
+ world.between = null;
319
+ if (world.abort) return; // a frame that never reaches physics
320
+ watchSteps();
321
+ system.afterBehaviors(scene, dt);
322
+ watchSteps();
323
+ // The rule, on every frame of every run: nothing is left on a body, and
324
+ // nothing is left asked for, once the frame's physics pass is over.
325
+ assert.equal(world.force(), 0, 'no force on the body after the frame');
326
+ assert.equal(system.forces, null, 'and none still asked for');
327
+ };
328
+ // rapier's wasm loads asynchronously; frames are played until it has.
329
+ for (let i = 0; i < 200 && !api.ready(); i += 1) {
330
+ await new Promise((resolve) => setTimeout(resolve, 5));
331
+ world.frame(FIXED);
332
+ }
333
+ assert.ok(api.ready(), 'physics is ready');
334
+ world.settle = (frames = 240) => {
335
+ for (let i = 0; i < frames; i += 1) world.frame(FIXED);
336
+ return world;
337
+ };
338
+ world.y = () => world.body().translation().y;
339
+ return world;
340
+ }
341
+
342
+ const spread = (values) => Math.max(...values) - Math.min(...values);
343
+ const rms = (values) => {
344
+ const mean = values.reduce((a, b) => a + b, 0) / values.length;
345
+ return Math.sqrt(values.reduce((a, b) => a + (b - mean) ** 2, 0) / values.length);
346
+ };
347
+
348
+ // A walk forward on `pattern`'s frames after standing still: the height of
349
+ // the body and of the Transform (what is drawn) on each frame once the walk
350
+ // is up to speed, and where the player stood before it.
351
+ async function walk(Physics3DSystem, mode, pattern, { jumpAt = -1, frames = 400 } = {}) {
352
+ const world = await makeWorld(Physics3DSystem, mode);
353
+ world.settle();
354
+ const rest = world.y();
355
+ const body = [];
356
+ const drawn = [];
357
+ frameLengths(pattern, frames).forEach((dt, i) => {
358
+ world.frame(dt, i === jumpAt ? ['KeyW', 'Space'] : ['KeyW']);
359
+ if (i < 60) return;
360
+ body.push(world.y());
361
+ drawn.push(world.scene.actors[0].components.Transform.y);
362
+ });
363
+ return { world, rest, body, drawn, apex: Math.max(...body) };
364
+ }
365
+
366
+ async function runOn(Physics3DSystem, label) {
367
+ let checks = 0;
368
+ const rows = [];
369
+
370
+ // Without the key: main's calls, main's arguments, main's order, through a
371
+ // walk with turns and jumps on every pattern; and never a force.
372
+ for (const pattern of PATTERNS) {
373
+ const off = await makeWorld(Physics3DSystem, 'off');
374
+ const main = await makeWorld(Physics3DSystem, 'main');
375
+ const keysAt = (i) => (i < 60 ? [] : i % 90 === 0 ? ['KeyW', 'Space'] : i % 200 > 150 ? ['KeyW', 'KeyD'] : i % 200 > 140 ? [] : ['KeyW']);
376
+ frameLengths(pattern, 600).forEach((dt, i) => {
377
+ off.frame(dt, keysAt(i));
378
+ main.frame(dt, keysAt(i));
379
+ });
380
+ assert.ok(off.calls.length > 3000, `${label} ${pattern}: the walk made calls (${off.calls.length})`);
381
+ assert.deepEqual(off.calls, main.calls, `${label} ${pattern}: without the key the Player makes main's calls`);
382
+ assert.ok(!off.calls.some((call) => /"(addForce|resetForces)"/.test(call)), `${label} ${pattern}: and asks for no force`);
383
+ assert.ok(off.atStep.length > 500 && off.atStep.every((f) => f === 0), `${label} ${pattern}: no step sees one`);
384
+ assert.deepEqual(off.body().translation(), main.body().translation(), `${label} ${pattern}: and ends where main ends`);
385
+ checks += 1;
386
+ }
387
+
388
+ // With the key: the height does not move walking, whatever the frames, and
389
+ // it does without it (so the measure can tell).
390
+ for (const pattern of PATTERNS) {
391
+ const off = await walk(Physics3DSystem, 'off', pattern);
392
+ const steady = await walk(Physics3DSystem, 'steady', pattern);
393
+ rows.push({ pattern, off, steady });
394
+ assert.ok(spread(steady.body) < 5e-5, `${label} ${pattern}: the body's height swings ${spread(steady.body)} m with the key`);
395
+ assert.ok(spread(steady.drawn) < 5e-5, `${label} ${pattern}: and the drawn height ${spread(steady.drawn)} m`);
396
+ assert.ok(Math.abs(steady.rest - off.rest) < 1e-3, `${label} ${pattern}: it stands as high as without the key (${steady.rest} against ${off.rest})`);
397
+ assert.ok(Math.abs(steady.body.at(-1) - off.rest) < 1e-3, `${label} ${pattern}: and walks as high (${steady.body.at(-1)})`);
398
+ assert.ok(!steady.world.calls.some((call) => /"applyImpulse",\["player",\{"x":0,"y":(?!0,)/.test(call)), `${label} ${pattern}: no push up or down is an impulse`);
399
+ checks += 1;
400
+ }
401
+ const byPattern = Object.fromEntries(rows.map((row) => [row.pattern, row]));
402
+ for (const pattern of ['alt', 'drops']) {
403
+ assert.ok(spread(byPattern[pattern].off.body) > 1e-3, `${label} ${pattern}: without the key the height swings (${spread(byPattern[pattern].off.body)} m)`);
404
+ checks += 1;
405
+ }
406
+
407
+ // A jump is as high as without the key: within a centimetre. Left on, the
408
+ // frame's lift would add some eleven.
409
+ for (const pattern of PATTERNS) {
410
+ const off = await walk(Physics3DSystem, 'off', pattern, { jumpAt: 100 });
411
+ const steady = await walk(Physics3DSystem, 'steady', pattern, { jumpAt: 100 });
412
+ byPattern[pattern].apex = { off: off.apex, steady: steady.apex };
413
+ assert.ok(off.apex > 2, `${label} ${pattern}: it jumped (${off.apex})`);
414
+ assert.ok(Math.abs(steady.apex - off.apex) < 0.01, `${label} ${pattern}: a jump reaches ${steady.apex} with the key, ${off.apex} without`);
415
+ assert.ok(Math.abs(steady.body.at(-1) - off.rest) < 1e-3, `${label} ${pattern}: and lands at the same height`);
416
+ checks += 1;
417
+ }
418
+
419
+ // Nothing is left behind. (Every frame above and below also checks that no
420
+ // body carries a force once its physics pass is over.)
421
+ const standing = async () => {
422
+ const world = await makeWorld(Physics3DSystem, 'steady');
423
+ world.settle();
424
+ world.atStep.length = 0;
425
+ assert.ok(world.y() > 0.73, `${label}: the hover holds the player up (${world.y()})`);
426
+ return world;
427
+ };
428
+ const noForceSince = (world, what) => {
429
+ assert.ok(world.atStep.length > 0, `${label} ${what}: physics stepped`);
430
+ assert.ok(world.atStep.every((f) => f === 0), `${label} ${what}: no step saw a force (${world.atStep.find((f) => f !== 0)})`);
431
+ };
432
+ // The hover is a force only while it is asked for: with the key every step
433
+ // sees it.
434
+ {
435
+ const world = await standing();
436
+ world.settle(30);
437
+ assert.ok(world.atStep.every((f) => f > 0), `${label}: with the key each step has the lift on it`);
438
+ checks += 1;
439
+ }
440
+ // The Player turned off: no lift, and the capsule comes to lie on the ground.
441
+ {
442
+ const world = await standing();
443
+ world.scene.actors[0].components.Player.$enabled = false;
444
+ world.settle(60);
445
+ noForceSince(world, 'player turned off');
446
+ assert.ok(world.y() < 0.71, `${label}: a player turned off is not held up (${world.y()})`);
447
+ checks += 1;
448
+ }
449
+ // The player despawned in the frame it asked, after asking: the force goes
450
+ // with the body, and one spawned again under the same id starts with none.
451
+ {
452
+ const world = await standing();
453
+ world.between = () => {
454
+ world.scene.actors = [];
455
+ };
456
+ world.frame(FIXED);
457
+ assert.equal(world.body(), null, `${label}: the body went with the actor`);
458
+ world.scene.actors = [newPlayer(3)];
459
+ world.scene.actors[0].components.Player.$enabled = false;
460
+ world.atStep.length = 0;
461
+ world.settle(60);
462
+ noForceSince(world, 'despawned and spawned again');
463
+ assert.ok(world.y() < 0.71, `${label}: the new body is not held up by the old one's lift`);
464
+ checks += 1;
465
+ }
466
+ // Replaced in the frame it asked, between asking and physics: another actor
467
+ // under the same id, its body made anew (a different shape, so reconciling
468
+ // rebuilds it). What was asked of the old body is not put on the new one.
469
+ {
470
+ const world = await standing();
471
+ world.between = () => {
472
+ const next = newPlayer(3);
473
+ next.components.Shape = { kind: 'capsule', radius: 0.4, height: 1.5 };
474
+ next.components.Player.$enabled = false;
475
+ world.scene.actors = [next];
476
+ };
477
+ world.atStep.length = 0;
478
+ world.frame(FIXED);
479
+ world.between = null;
480
+ world.settle(60);
481
+ noForceSince(world, 'replaced under the same id');
482
+ checks += 1;
483
+ }
484
+ // A door trip from a keyed scene to one without the key: a load resets the
485
+ // system between the Player asking and physics stepping. Nothing is asked
486
+ // for any more, and the scene without the key runs as main does.
487
+ {
488
+ const world = await standing();
489
+ const main = await makeWorld(Physics3DSystem, 'main');
490
+ world.between = () => {
491
+ world.system.reset(world.scene);
492
+ assert.equal(world.system.forces, null, `${label}: a load drops what was asked for`);
493
+ world.scene.cameraFollowsRigidly = false;
494
+ world.scene.data = {};
495
+ world.scene.actors = [newPlayer()];
496
+ world.scene.persistent = {};
497
+ };
498
+ world.frame(FIXED);
499
+ world.calls.length = 0;
500
+ world.atStep.length = 0;
501
+ main.calls.length = 0;
502
+ frameLengths('alt', 200).forEach((dt, i) => {
503
+ world.frame(dt, i > 20 ? ['KeyW'] : []);
504
+ main.frame(dt, i > 20 ? ['KeyW'] : []);
505
+ });
506
+ noForceSince(world, 'after a load');
507
+ assert.deepEqual(world.calls, main.calls, `${label}: the scene without the key is main's from its first frame`);
508
+ checks += 1;
509
+ }
510
+ // The key gone with no load in between (a scene object that stops saying
511
+ // it): the next frame is main's and no step sees a force.
512
+ {
513
+ const world = await standing();
514
+ world.scene.cameraFollowsRigidly = false;
515
+ world.settle(120);
516
+ noForceSince(world, 'the key gone');
517
+ assert.ok(!world.calls.slice(-200).some((call) => /"(addForce|resetForces)"/.test(call)), `${label}: nothing asks for a force without the key`);
518
+ checks += 1;
519
+ }
520
+ // Physics reset, and disposed, with a force asked for.
521
+ for (const end of ['reset', 'dispose']) {
522
+ const world = await standing();
523
+ world.api.addForce('player', { x: 0, y: 50, z: 0 });
524
+ assert.ok(world.system.forces, 'a force was asked for');
525
+ world.system[end](world.scene);
526
+ assert.equal(world.system.forces, null, `${label}: ${end} drops it`);
527
+ checks += 1;
528
+ }
529
+ // A frame that never reaches physics (something threw after the Player
530
+ // ran), then the Player off: what was asked for in the lost frame is not
531
+ // used in a later one.
532
+ {
533
+ const world = await standing();
534
+ world.abort = true;
535
+ world.frame(FIXED);
536
+ assert.ok(world.system.forces, 'the lost frame asked for a force');
537
+ world.abort = false;
538
+ world.scene.actors[0].components.Player.$enabled = false;
539
+ world.settle(30);
540
+ noForceSince(world, 'after a frame that did not reach physics');
541
+ checks += 1;
542
+ }
543
+ // A force asked for after the frame's pass (a collision callback) is for
544
+ // that frame, which is over: it is not used in the next.
545
+ {
546
+ const world = await standing();
547
+ world.scene.actors[0].components.Player.$enabled = false;
548
+ world.api.addForce('player', { x: 0, y: 50, z: 0 });
549
+ world.atStep.length = 0;
550
+ world.between = () => assert.ok(world.system.forces, 'still asked for when the next frame starts');
551
+ world.settle(5);
552
+ noForceSince(world, 'asked for after the pass');
553
+ checks += 1;
554
+ }
555
+ // A frame of no steps (a short one): asked for, not used, not kept.
556
+ {
557
+ const world = await standing();
558
+ world.frame(FIXED / 4);
559
+ world.frame(FIXED / 4);
560
+ checks += 1;
561
+ }
562
+ // A step that throws leaves nothing on the body.
563
+ {
564
+ const world = await standing();
565
+ world.throwAtStep = true;
566
+ assert.throws(() => world.frame(FIXED), /a step that throws/);
567
+ assert.equal(world.force(), 0, `${label}: a step that throws leaves no force on the body`);
568
+ assert.equal(world.system.forces, null);
569
+ checks += 1;
570
+ }
571
+ // Something else placing the player (the hub's fall catch, a trip, the
572
+ // session's placement: body.setTranslation and a zero velocity, after
573
+ // physics): it is moved, drops back onto the hover and stands as before.
574
+ {
575
+ const world = await standing();
576
+ const rest = world.y();
577
+ const body = world.body();
578
+ body.setTranslation({ x: 20, y: 4, z: -7 }, true);
579
+ world.api.setVelocity('player', { x: 0, y: 0, z: 0 });
580
+ world.frame(FIXED);
581
+ assert.ok(Math.abs(body.translation().x - 20) < 1e-6 && world.y() > 3.9, `${label}: a placed player is where it was put`);
582
+ world.settle(240);
583
+ assert.ok(Math.abs(world.y() - rest) < 1e-3, `${label}: and stands as it did (${world.y()} against ${rest})`);
584
+ checks += 1;
585
+ }
586
+ // `addForce` adds within a frame, `resetForces` drops, and an actor with no
587
+ // body is not kept.
588
+ {
589
+ const world = await standing();
590
+ world.scene.actors[0].components.Player.$enabled = false;
591
+ world.api.addForce('nobody', { x: 0, y: 1, z: 0 });
592
+ assert.equal(world.system.forces, null, 'no body, nothing asked');
593
+ world.scene.time += FIXED;
594
+ world.api.addForce('player', { x: 1, y: 2, z: 3 });
595
+ world.api.addForce('player', { x: 1, y: 2, z: 3 });
596
+ const asked = world.system.forces.get('player');
597
+ assert.deepEqual({ x: asked.x, y: asked.y, z: asked.z }, { x: 2, y: 4, z: 6 });
598
+ assert.equal(asked.body, world.system.bodies.get('player').body, 'asked of the body there now');
599
+ world.api.resetForces('player');
600
+ assert.equal(world.system.forces, null, 'reset drops it');
601
+ checks += 1;
602
+ }
603
+ return { checks, rows };
604
+ }
605
+
606
+ export async function run({ table = false } = {}) {
607
+ const results = [];
608
+ const fake = await import('../systems/physics3d.js?steady-fake');
609
+ results.push(['stand-in', await runOn(fake.Physics3DSystem, 'stand-in rapier')]);
610
+ if (realRapier) {
611
+ const real = await import('../systems/physics3d.js?steady-real');
612
+ results.push(['rapier', await runOn(real.Physics3DSystem, 'rapier')]);
613
+ }
614
+ if (table) {
615
+ const mm = (v) => (v * 1000).toFixed(2).padStart(7);
616
+ for (const [name, { rows }] of results) {
617
+ console.log(`${name}: walking, body height p-p / rms and drawn height p-p in mm; rest height and jump apex in m`);
618
+ console.log(' pattern no key: body pp rms drawn pp | key: body pp rms drawn pp | rest: no key key | apex: no key key');
619
+ for (const { pattern, off, steady, apex } of rows) {
620
+ console.log(
621
+ ` ${pattern.padEnd(9)} ${mm(spread(off.body))}${mm(rms(off.body))} ${mm(spread(off.drawn))} | ${mm(spread(steady.body))}${mm(rms(steady.body))} ${mm(spread(steady.drawn))} | ${off.rest.toFixed(5)} ${steady.rest.toFixed(5)} | ${apex.off.toFixed(4)} ${apex.steady.toFixed(4)}`
622
+ );
623
+ }
624
+ }
625
+ }
626
+ const checks = results.reduce((sum, [, result]) => sum + result.checks, 0);
627
+ return { checks, real: Boolean(realRapier) };
628
+ }
629
+
630
+ export const summary = ({ checks, real }) =>
631
+ `${checks} steady-hover checks (${real ? 'on a stand-in rapier and on rapier itself' : 'on a stand-in rapier; rapier itself is not installed here, so that half was skipped'})`;
632
+
633
+ if (import.meta.url === `file://${process.argv[1]}`) {
634
+ console.log(summary(await run({ table: process.argv.includes('--table') })));
635
+ }