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,131 @@
1
+ // Earned items (contract §11, v1.53): the second wearable slot. A hub game
2
+ // declares the small things it gives for a stated deed in its castle.json
3
+ // (`hub.unlocks`), gives one with `hub.unlock(playerId, id)`, and the town
4
+ // alone chooses which one a player shows. Each player shows at most one, drawn
5
+ // beside whatever the Look slot (`hub.wear`) puts on the head: a badge or pin
6
+ // on the chest, a belt round the waist, a sash across the torso, or a small
7
+ // thing held in the right hand.
8
+ //
9
+ // The place sends playerId -> `{ class, shape, color, name }` (`hubEarned`, and
10
+ // `hub-earned` alone for a hidden pair, as `hubWear` / `hub-wear`), and
11
+ // `makeEarned` draws each under the avatar's own node, as `wear.js` draws a
12
+ // hat: so it moves, turns and hides with the avatar, and nothing is sent or
13
+ // made as an actor. Nothing here runs for a place where nobody shows one.
14
+ //
15
+ // The shapes are the kit's models, `models/earned/<shape>.pxmodel`
16
+ // (scripts/gen-earned.mjs), with the avatars' outline look. The item's colour
17
+ // takes the place of the model's main colour (`EARNED_MAIN`, which only main
18
+ // materials carry); trims keep theirs. A shape this kit has no model of, or a
19
+ // shape drawn for another class than the item's, is kept and not drawn.
20
+ //
21
+ // The lists below import nothing, so a place's server may read them
22
+ // (`@imports/castle.hub-game/code/client/earned.js`) to check a declaration
23
+ // against exactly what every client can draw, as it reads `hats.js` `HATS`.
24
+
25
+ export const EARNED_CLASSES = ['badge', 'pin', 'belt', 'sash', 'held'];
26
+
27
+ // Each shape and the class it is drawn for. A badge's shape may be pinned and
28
+ // a pin's worn as a badge: both sit on the chest.
29
+ export const EARNED_SHAPE_CLASS = {
30
+ 'badge-round': 'badge',
31
+ 'badge-star': 'badge',
32
+ 'badge-shield': 'badge',
33
+ 'pin-round': 'pin',
34
+ 'belt-plain': 'belt',
35
+ 'sash-plain': 'sash',
36
+ 'held-lantern': 'held',
37
+ 'held-trophy': 'held',
38
+ 'held-net': 'held',
39
+ 'held-ball': 'held',
40
+ };
41
+
42
+ export const EARNED_SHAPES = Object.keys(EARNED_SHAPE_CLASS);
43
+
44
+ // The colour the models' main materials are written in, replaced by the item's.
45
+ export const EARNED_MAIN = '#3aa0d8';
46
+
47
+ export const earnedFile = (shape, square = false) => `models/earned/${square ? 'square/' : ''}${shape}.pxmodel`;
48
+ // The ring shapes that have a square model for a boxy body.
49
+ export const SQUARE_SHAPES = ['belt-plain', 'sash-plain'];
50
+
51
+ const COLOR = /^#[0-9a-f]{6}$/i;
52
+ const CHEST = new Set(['badge', 'pin']);
53
+ // The model's feet stand this far under the avatar's origin (wear.js).
54
+ const MODEL_FEET_Y = -0.7;
55
+ // Each ring model (a belt, a sash) is made 0.2 m out from its middle and
56
+ // stretched to the body it goes round.
57
+ const RING_R = 0.2;
58
+ // Badges are drawn this much bigger than their models and pins this much, so
59
+ // they read across a street as the halos they replace did.
60
+ export const BADGE_SCALE = 2.6;
61
+ export const PIN_SCALE = 2.1;
62
+ // A badge has a soft glow in its colour behind it (`wear.js` draws it), this
63
+ // far out from its middle: light under the badge fading to nothing.
64
+ export const BADGE_GLOW_R = 0.32;
65
+ // And held things this much bigger, about their grip.
66
+ export const HELD_SCALE = 1.2;
67
+
68
+ // Where an earned item sits on an avatar this kit has no fit for (`avatar.js`
69
+ // `earnedFit` gives null): a body about toon's.
70
+ const DEFAULT_FIT = {
71
+ chest: [0.09, 0.6, 0.2, 20],
72
+ waist: [0.37, 0.23, 0.23],
73
+ sash: [0.51, 0.35, 0.26, 45],
74
+ hand: [-0.33, 0.34, 0.01],
75
+ };
76
+
77
+ const mm = (n) => Math.round(n * 1000) / 1000;
78
+
79
+ // Whether `shape` is drawn for class `cls`.
80
+ export function drawnFor(shape, cls) {
81
+ const own = EARNED_SHAPE_CLASS[shape];
82
+ if (!own) {
83
+ return false;
84
+ }
85
+ return own === cls || (CHEST.has(own) && CHEST.has(cls));
86
+ }
87
+
88
+ // What to draw for an earned item `{ class, shape, color }` on an avatar with
89
+ // earned fit `fit` (`avatar.js`): a plain description, the same every time for
90
+ // the same arguments, or null for nothing (an unknown shape, a shape of
91
+ // another class, no colour).
92
+ // { shape, file, color, position: [x, y, z], yaw, tilt, scale: [x, y, z], glow? }
93
+ // in metres over the avatar's origin and degrees: the model is scaled, then
94
+ // tilted about z (a sash, rising to the wearer's right shoulder), then turned
95
+ // `yaw` about y, then moved to `position`. `glow` (a badge) is the radius of
96
+ // its soft glow.
97
+ export function earnedLook(item, fit = null) {
98
+ const cls = item?.class;
99
+ const shape = item?.shape;
100
+ const color = typeof item?.color === 'string' && COLOR.test(item.color) ? item.color.toLowerCase() : null;
101
+ if (!color || !EARNED_CLASSES.includes(cls) || !drawnFor(shape, cls)) {
102
+ return null;
103
+ }
104
+ const f = fit ?? DEFAULT_FIT;
105
+ const square = f.square === true && SQUARE_SHAPES.includes(shape);
106
+ const base = { shape, file: earnedFile(shape, square), color };
107
+ if (CHEST.has(cls)) {
108
+ // The shape says how big it is drawn: a badge's shape pinned is a badge.
109
+ const [x, y, z, yaw, size = 1] = f.chest;
110
+ const badge = EARNED_SHAPE_CLASS[shape] === 'badge';
111
+ const k = mm((badge ? BADGE_SCALE : PIN_SCALE) * size);
112
+ return { ...base, position: [x, mm(MODEL_FEET_Y + y), z], yaw, tilt: 0, scale: [k, k, k], ...(badge ? { glow: mm(BADGE_GLOW_R * size) } : {}) };
113
+ }
114
+ if (cls === 'belt') {
115
+ const [y, rx, rz] = f.waist;
116
+ return { ...base, position: [0, mm(MODEL_FEET_Y + y), 0], yaw: 0, tilt: 0, scale: [mm(rx / RING_R), 1, mm(rz / RING_R)] };
117
+ }
118
+ if (cls === 'sash') {
119
+ // `a` is the half length of the ring in its tilted plane.
120
+ const [y, a, rz, tilt] = f.sash;
121
+ return { ...base, position: [0, mm(MODEL_FEET_Y + y), 0], yaw: 0, tilt: -tilt, scale: [mm(a / RING_R), 1, mm(rz / RING_R)] };
122
+ }
123
+ const [x, y, z] = f.hand;
124
+ return { ...base, position: [x, mm(MODEL_FEET_Y + y), z], yaw: 0, tilt: 0, scale: [HELD_SCALE, HELD_SCALE, HELD_SCALE] };
125
+ }
126
+
127
+ // The model text an item is built from: the shape's model with its main
128
+ // colour made the item's. Trims never carry `EARNED_MAIN`.
129
+ export function tinted(text, color) {
130
+ return text.split(`"${EARNED_MAIN}"`).join(JSON.stringify(color.toLowerCase()));
131
+ }
@@ -0,0 +1,75 @@
1
+ // Where an emote's emoji is drawn: on the head it belongs to, never under
2
+ // the top chrome (the HUD's box, a question card, Back, the sound button).
3
+ // In a portrait phone with the camera looking down, a fixed height over the
4
+ // body projects far up the screen, into the HUD's lines or the sky, and the
5
+ // player never reads it as their own wave. No DOM here, so
6
+ // `scripts/test-emote-bubble.mjs` can hold it; the client projects the head
7
+ // (`idle.js` `labels`) and the chrome (`chrome.js` `setLabels`) measures and
8
+ // moves.
9
+ //
10
+ // The rule (`placeEmoteBubble`): just above the head's top, centred on it;
11
+ // where that leaves the view's top edge or meets a band, beside the head on
12
+ // the side with more room, centred on it; kept on the view; and last, from
13
+ // under any band it still meets (`emoteBubbleShift`).
14
+
15
+ // Pixels between a bubble beside the head and the head, a moved bubble and
16
+ // the band it was moved under, and kept off every side of the view.
17
+ export const BUBBLE_GAP = 8;
18
+ export const BUBBLE_EDGE = 6;
19
+ // Over the head, the emoji's own glyph leaves a little air: it sits right on
20
+ // the model's box (whose top, ears and hats included, is often above what
21
+ // reads as the head).
22
+ export const HEAD_GAP = 0;
23
+
24
+ const overlaps = (a, b) => a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;
25
+ const clamp = (v, lo, hi) => Math.max(lo, Math.min(v, Math.max(lo, hi)));
26
+
27
+ // `rect` and `bands` are `{ left, right, top, bottom }` in CSS pixels;
28
+ // `viewW` the view's width. Returns `{ dx, dy }`, both 0 when nothing is in
29
+ // the way: a bubble over a band goes to just under the lowest band it meets,
30
+ // a bubble's width to the right, and again under any band it then meets.
31
+ export function emoteBubbleShift(rect, bands, viewW) {
32
+ const w = rect.right - rect.left;
33
+ let r = rect;
34
+ let moved = false;
35
+ for (let i = 0; i <= bands.length; i += 1) {
36
+ const hit = bands.filter((b) => overlaps(r, b));
37
+ if (!hit.length) {
38
+ break;
39
+ }
40
+ const down = Math.max(...hit.map((b) => b.bottom)) + BUBBLE_GAP - r.top;
41
+ let left = r.left;
42
+ if (!moved) {
43
+ moved = true;
44
+ left = clamp(rect.left + w, BUBBLE_EDGE, viewW - BUBBLE_EDGE - w);
45
+ }
46
+ r = { left, right: left + w, top: r.top + down, bottom: r.bottom + down };
47
+ }
48
+ return { dx: r.left - rect.left, dy: r.top - rect.top };
49
+ }
50
+
51
+ // `head` is the head's rect on screen, `size` the bubble's `{ w, h }`, `view`
52
+ // `{ w, h }`, `lift` pixels more above the head (its rise). The placed rect,
53
+ // or null for a head wholly off the view: its bubble is not drawn, as an off-
54
+ // screen label never was, rather than clamped beside someone else.
55
+ export function placeEmoteBubble(head, size, bands, view, lift = 0) {
56
+ if (head.right <= 0 || head.left >= view.w || head.bottom <= 0 || head.top >= view.h) {
57
+ return null;
58
+ }
59
+ const { w, h } = size;
60
+ const cx = (head.left + head.right) / 2;
61
+ const left = clamp(cx - w / 2, BUBBLE_EDGE, view.w - BUBBLE_EDGE - w);
62
+ const bottom = head.top - HEAD_GAP - lift;
63
+ let r = { left, right: left + w, top: bottom - h, bottom };
64
+ if (r.top < BUBBLE_EDGE || bands.some((b) => overlaps(r, b))) {
65
+ // Beside the head, on its open side, centred on it.
66
+ const roomRight = view.w - head.right;
67
+ const roomLeft = head.left;
68
+ const x = roomRight >= roomLeft ? head.right + BUBBLE_GAP : head.left - BUBBLE_GAP - w;
69
+ const bx = clamp(x, BUBBLE_EDGE, view.w - BUBBLE_EDGE - w);
70
+ const by = clamp((head.top + head.bottom) / 2 - h / 2, BUBBLE_EDGE, view.h - BUBBLE_EDGE - h);
71
+ r = { left: bx, right: bx + w, top: by, bottom: by + h };
72
+ }
73
+ const { dx, dy } = emoteBubbleShift(r, bands, view.w);
74
+ return { left: r.left + dx, right: r.right + dx, top: r.top + dy, bottom: r.bottom + dy };
75
+ }
@@ -14,6 +14,16 @@
14
14
  // A place may ask for a steadier offer (v1.22, `grab.reach` and
15
15
  // `grab.steady`): a longer reach, and an offer that does not flicker at its
16
16
  // edges. A place that asks for neither runs exactly the code it always did.
17
+ //
18
+ // A place may keep an object for one player (v1.27, `hub.keepFor`): it is
19
+ // never offered to anyone else, so the nearest object a player may take is
20
+ // the one offered. Where nothing is kept the offer is exactly what it was.
21
+ //
22
+ // Under the engine's orbit camera key (a scene whose `engine.camera` is
23
+ // `{ "follow": "rigid", "control": "orbit" }`, `scene.cameraControl ===
24
+ // 'orbit'`) the camera and the character turn apart, so a throw goes where
25
+ // the camera looks rather than where the character happens to face: see
26
+ // `aimThrow`. Without the key every throw runs the code it always did.
17
27
 
18
28
  import { hub } from './state.js';
19
29
 
@@ -71,6 +81,38 @@ export const KEEP_MARGIN_M = 0.4;
71
81
  const KEEP_COS = 0;
72
82
  export const STEADY_GRACE_MS = 600;
73
83
  export const PRESS_WAIT_MS = 500;
84
+ // v1.25 `grab.keepHeld`: how often the server is told a hold goes on (its
85
+ // pin on the held object lasts 2.5 s past the last word).
86
+ export const KEEP_TELL_MS = 1000;
87
+ // Under the orbit camera key: a throw waits for the character to face the
88
+ // camera's way and for a movement report saying so to have gone out, at most
89
+ // AIM_WAIT_MS; and for the held object to swing round to the hold point along
90
+ // the throw, which takes no time at all when the camera already looks the way
91
+ // the character faces, and otherwise as long as the server takes to hear the
92
+ // swing (AIM_SLACK_M, below). Nothing waits past AIM_GIVE_UP_MS: a throw is
93
+ // never lost. The server judges a throw from the pose it last heard.
94
+ export const AIM_WAIT_MS = 150;
95
+ export const AIM_GIVE_UP_MS = 2000;
96
+ // How far (metres, in a straight line) the swing may put the held object
97
+ // from anywhere the server's body for it may be. multiplayer-3d checks each
98
+ // owned-object report against where its kinematic body is when the report
99
+ // arrives: no farther than MAX_OBJECT_SPEED (40 m/s) times the server time
100
+ // since the last report, plus MOVE_SLACK (0.6 m); a report past that takes
101
+ // the object away and ends the hold. Reports bunched by the network between
102
+ // two physics steps get no time at all, only the 0.6 m, and the body moves
103
+ // only at a step, to the newest report applied before it. So the swing never
104
+ // counts on time, and puts the object within this of every position this
105
+ // client has reported since the one the body is sure to have reached (see
106
+ // `reach`): wherever among them the body is, the next report is inside the
107
+ // bound. The report carries exactly where the swing put the object (the
108
+ // client's physics runs before this system, the report after it); the rest
109
+ // of the 0.6 m is margin.
110
+ export const AIM_SLACK_M = 0.5;
111
+ // How near the character's facing must be to the throw's to count as facing
112
+ // it (radians). The Player takes a facing request exactly, so standing still
113
+ // it is met the frame after the request; walking, the Player eases the
114
+ // facing toward the walk at once and the wait runs out instead.
115
+ const AIM_FACE_RAD = 1 * DEG;
74
116
  // Where the walk preset's capsule stands (physics-3d `Player`): its radius and
75
117
  // height, and how far it hovers.
76
118
  const PLAYER = { radius: 0.35, height: 1.4, hover: 0.15 };
@@ -154,10 +196,35 @@ function frame(t, scene, mp, local, idle) {
154
196
  !scene.getActor(id)
155
197
  ) {
156
198
  t.held = null;
157
- } else if (pressed) {
158
- throwHeld(t, scene, body, local, config, net, now);
159
199
  } else {
160
- carry(t, scene, body, local, config, dt);
200
+ if (scene.cameraControl === 'orbit') {
201
+ // What this client has told the server of the hold, for a throw's
202
+ // swing to keep inside (`reach`); it changes nothing here.
203
+ listen(t.held, mp);
204
+ }
205
+ if (t.held.aim) {
206
+ aimFrame(t, scene, mp, body, local, config, net, now, dt);
207
+ } else if (pressed && scene.cameraControl === 'orbit') {
208
+ aimThrow(t, scene, mp, body, local, config, dt, now);
209
+ } else if (pressed) {
210
+ throwHeld(t, scene, body, local, config, net, now);
211
+ } else {
212
+ carry(t, scene, body, local, config, dt);
213
+ if (config.keepHeld === true) {
214
+ // v1.25: the server keeps a held object this client's only while it
215
+ // hears the hold goes on.
216
+ t.held.toldAt ??= now;
217
+ if (now - t.held.toldAt >= KEEP_TELL_MS) {
218
+ t.held.toldAt = now;
219
+ net.send({ k: 'hub-grab', actor: id, op: 'hold' });
220
+ }
221
+ }
222
+ }
223
+ if (t.held && scene.cameraControl === 'orbit') {
224
+ // Where the body is now is what the multiplayer kit's report, after
225
+ // this system, packs if one goes out this frame (`listen`).
226
+ put(t.held, body);
227
+ }
161
228
  }
162
229
  }
163
230
  if (t.held) {
@@ -213,10 +280,10 @@ function steadyFrame(t, scene, mp, local, config, net, active, pressed, now, dt)
213
280
  grabbable(scene, mp, local, reach, FRONT_COS, capFor(scene, local));
214
281
  if (ready) {
215
282
  t.offer = { id: ready.id, okAt: now };
216
- } else if (kept && (now - kept.okAt > STEADY_GRACE_MS || !stillThere(scene, kept.id))) {
283
+ } else if (kept && (now - kept.okAt > STEADY_GRACE_MS || !stillThere(scene, kept.id, mp))) {
217
284
  t.offer = null;
218
285
  }
219
- if (t.waiting && (now > t.waiting.until || !stillThere(scene, t.waiting.id))) {
286
+ if (t.waiting && (now > t.waiting.until || !stillThere(scene, t.waiting.id, mp))) {
220
287
  t.waiting = null;
221
288
  }
222
289
  if (pressed && (ready || t.offer)) {
@@ -243,12 +310,20 @@ function steadyFrame(t, scene, mp, local, config, net, active, pressed, now, dt)
243
310
  }
244
311
 
245
312
  // Whether an object kept on offer can still come back: in the scene, not
246
- // hidden by the place. Anything else may change within a grace.
247
- function stillThere(scene, id) {
248
- return Boolean(scene.getActor(id)) && !hub.hidden.has(id);
313
+ // hidden by the place, not kept for someone else (v1.27). Anything else may
314
+ // change within a grace.
315
+ function stillThere(scene, id, mp) {
316
+ return Boolean(scene.getActor(id)) && !hub.hidden.has(id) && !keptFromMe(mp, id);
317
+ }
318
+
319
+ // v1.27 `hub.keepFor`: whether the place keeps this object for another player.
320
+ // False for every object where nothing is kept.
321
+ function keptFromMe(mp, id) {
322
+ return hub.keptFor.size > 0 && hub.keptFor.has(id) && hub.keptFor.get(id) !== mp.net?.selfId?.();
249
323
  }
250
324
 
251
- // The nearest object this client owns in front of the player, or null. With
325
+ // The nearest object this client owns in front of the player, or null; one the
326
+ // place keeps for someone else (v1.27) is passed over for the next nearest. With
252
327
  // no more arguments it is the test every place had before v1.22; `reach`,
253
328
  // `cos` and `centre` (the farthest an object's centre may be from the
254
329
  // player's) carry a place's `grab.reach` and `grab.steady`, and `only` limits
@@ -272,7 +347,7 @@ function grabbable(
272
347
  const fz = Math.cos(f);
273
348
  let best = null;
274
349
  for (const [id, at] of mp.claimable(scene)) {
275
- if ((only !== null && id !== only) || !mine.has(id) || hub.hidden.has(id)) {
350
+ if ((only !== null && id !== only) || !mine.has(id) || hub.hidden.has(id) || keptFromMe(mp, id)) {
276
351
  continue;
277
352
  }
278
353
  const actor = scene.getActor(id);
@@ -317,14 +392,14 @@ function sizeOf(shape) {
317
392
 
318
393
  // Where a held object goes: `holdDistance` in front of the player (never so
319
394
  // close that it touches them) and `holdHeight` above their feet (never so low
320
- // that it is in the ground).
321
- function holdPoint(local, config, held) {
395
+ // that it is in the ground). `f`, radians, is the way it is in front along:
396
+ // the player's facing unless an aimed throw (below) says otherwise.
397
+ function holdPoint(local, config, held, f = (local.components.Transform.rotationY ?? 0) * DEG) {
322
398
  const t = local.components.Transform;
323
399
  const shape = local.components.Shape;
324
400
  const radius = typeof shape?.radius === 'number' ? shape.radius : PLAYER.radius;
325
401
  const height = typeof shape?.height === 'number' ? shape.height : PLAYER.height;
326
402
  const feet = t.y - (height / 2 + PLAYER.hover);
327
- const f = (t.rotationY ?? 0) * DEG;
328
403
  const distance = Math.max(config.holdDistance, radius + held.extent + 0.15);
329
404
  return {
330
405
  x: t.x + Math.sin(f) * distance,
@@ -335,16 +410,25 @@ function holdPoint(local, config, held) {
335
410
 
336
411
  // Move the held object toward its hold point, at most CARRY_SPEED. It keeps
337
412
  // the velocity it is carried at, which the multiplayer kit reports with its
338
- // pose, so other players draw it moving smoothly.
339
- function carry(t, scene, body, local, config, dt) {
413
+ // pose, so other players draw it moving smoothly. `to` is where it goes: the
414
+ // hold point unless an aimed throw says otherwise, and `most` how far it may
415
+ // go this frame. Returns whether it got there this frame.
416
+ function carry(
417
+ t,
418
+ scene,
419
+ body,
420
+ local,
421
+ config,
422
+ dt,
423
+ to = holdPoint(local, config, t.held),
424
+ most = CARRY_SPEED * dt,
425
+ ) {
340
426
  const held = t.held;
341
- const to = holdPoint(local, config, held);
342
427
  const from = held.at;
343
428
  const dx = to.x - from.x;
344
429
  const dy = to.y - from.y;
345
430
  const dz = to.z - from.z;
346
431
  const d = Math.hypot(dx, dy, dz);
347
- const most = CARRY_SPEED * dt;
348
432
  const k = d > most && d > 0 ? most / d : 1;
349
433
  const next = { x: from.x + dx * k, y: from.y + dy * k, z: from.z + dz * k };
350
434
  body.setTranslation(next, true);
@@ -363,14 +447,273 @@ function carry(t, scene, body, local, config, dt) {
363
447
  transform.y = next.y;
364
448
  transform.z = next.z;
365
449
  }
450
+ return k === 1;
366
451
  }
367
452
 
368
- // Let go along the player's facing at `throwSpeed`, a little upward.
369
- function throwHeld(t, scene, body, local, config, net, now) {
370
- const f = (local.components.Transform.rotationY ?? 0) * DEG;
453
+ // Let go along the player's facing at `throwSpeed`, a little upward (or
454
+ // along `f`, radians, for an aimed throw).
455
+ function throwHeld(
456
+ t,
457
+ scene,
458
+ body,
459
+ local,
460
+ config,
461
+ net,
462
+ now,
463
+ f = (local.components.Transform.rotationY ?? 0) * DEG,
464
+ ) {
371
465
  const speed = config.throwSpeed;
372
466
  body.setLinvel({ x: Math.sin(f) * speed, y: speed * THROW_UP, z: Math.cos(f) * speed }, true);
373
467
  net.send({ k: 'hub-grab', actor: t.held.id, op: 'throw' });
374
468
  t.held = null;
375
469
  t.quietUntil = now + REGRAB_MS;
376
470
  }
471
+
472
+ // ---- Under the orbit camera key only ------------------------------------------
473
+ //
474
+ // Throw where the camera looks: along f = PI - camAngle, the camera's forward
475
+ // on the ground (the facing the character always has without the key; Player
476
+ // keyless: `rt.facing = Math.PI - per.camAngle`). The press does not let go at
477
+ // once. It asks the Player to turn the character to f (`scene.faceRequest`,
478
+ // taken by the Player's next update), and from then on the held object swings
479
+ // round the player, at the hold distance and no faster than it is carried, to
480
+ // the hold point along f, so a throw toward the camera does not start inside
481
+ // the player. The swing goes only as fast as the server hears it: never more
482
+ // than AIM_SLACK_M, in a straight line, from any position this client has
483
+ // reported since the one the server's body is sure to have reached (`reach`,
484
+ // from multiplayer-3d's `acks` and the broadcasts' simulation time), carry
485
+ // reports from before the press included, so no bunch of its reports and no
486
+ // tick without a physics step can break the owned-object move bound and take
487
+ // the object away mid-throw. The throw is let go -- the velocity and the
488
+ // `hub-grab` throw -- on the first frame where:
489
+ // - the object is at that hold point, and
490
+ // - the character has faced f on every frame since some frame F (its
491
+ // Transform.rotationY, which the multiplayer kit packs into each movement
492
+ // report), and a movement report went out after F's: the multiplayer
493
+ // kit's `moveSeq` counts reports sent, and it reports after this system
494
+ // every frame, so a count that moved on since F means a report carrying
495
+ // f is on the wire before the throw, on the same connection.
496
+ // Past AIM_WAIT_MS after the press the object's place is enough, whatever the
497
+ // facing: a throw is not held up by a facing the Player did not take (a walk
498
+ // eases the facing toward it at once) or a report that never went out. The
499
+ // swing always gets there (it turns at the carry speed round a player who
500
+ // is placed every frame), unless the player outruns the carry (a tune far
501
+ // past the walk) or the server stops acknowledging (a stalled connection):
502
+ // AIM_GIVE_UP_MS after the press the throw goes from wherever the object is.
503
+ // A multiplayer kit without acknowledgements or report numbers swings at the
504
+ // carry speed, unbounded, as before.
505
+ // Meanwhile the object stays held: carried (at rest where it is put, under
506
+ // the acknowledgement bound; at the carry's velocity without it), the
507
+ // v1.25 `keepHeld` word still said; another press does nothing; anything that
508
+ // ends a hold (a drop, a refusal, the object handed on or hidden, the player
509
+ // unable to act, a new session or scene) ends it with no throw sent, as it
510
+ // ends any hold.
511
+
512
+ function aimThrow(t, scene, mp, body, local, config, dt, now) {
513
+ const me = local.components.Transform;
514
+ const cam = scene.persistent?.camAngle;
515
+ const f = Number.isFinite(cam) ? Math.PI - cam : (me.rotationY ?? 0) * DEG;
516
+ const at = t.held.at;
517
+ t.held.aim = {
518
+ f,
519
+ until: now + AIM_WAIT_MS,
520
+ last: now + AIM_GIVE_UP_MS,
521
+ // The object's bearing round the player, swung toward f.
522
+ a: Math.atan2(at.x - me.x, at.z - me.z),
523
+ facedSeq: null,
524
+ local,
525
+ };
526
+ scene.faceRequest = f;
527
+ swing(t, scene, mp, body, local, config, dt);
528
+ }
529
+
530
+ function aimFrame(t, scene, mp, body, local, config, net, now, dt) {
531
+ const aim = t.held.aim;
532
+ if (aim.local !== local) {
533
+ // A scene load: the request was dropped with the scene, and the hold
534
+ // ends as one across a load does.
535
+ t.held = null;
536
+ return;
537
+ }
538
+ if (config.keepHeld === true) {
539
+ t.held.toldAt ??= now;
540
+ if (now - t.held.toldAt >= KEEP_TELL_MS) {
541
+ t.held.toldAt = now;
542
+ net.send({ k: 'hub-grab', actor: t.held.id, op: 'hold' });
543
+ }
544
+ }
545
+ const there = swing(t, scene, mp, body, local, config, dt);
546
+ const seq = Number.isFinite(mp.moveSeq) ? mp.moveSeq : null;
547
+ const reported = aim.facedSeq !== null && seq !== aim.facedSeq;
548
+ if ((there && (reported || now >= aim.until)) || now >= aim.last) {
549
+ throwHeld(t, scene, body, local, config, net, now, aim.f);
550
+ return;
551
+ }
552
+ const faced =
553
+ Math.abs(turn((local.components.Transform.rotationY ?? 0) * DEG - aim.f)) <= AIM_FACE_RAD;
554
+ aim.facedSeq = faced && seq !== null ? (aim.facedSeq ?? seq) : null;
555
+ // Asked again each frame it waits: a request is taken once.
556
+ scene.faceRequest = aim.f;
557
+ }
558
+
559
+ // One frame of the swing: the bearing turns toward f by what `most` metres
560
+ // covers at the hold distance, and the object goes at most `most` toward the
561
+ // hold point on that bearing. `most` is what the carry speed covers, or, where
562
+ // the server's acknowledgements bound the swing, the most of that which keeps
563
+ // the object within AIM_SLACK_M of every place `reach` says the server's body
564
+ // may be (none at all while it cannot say). Returns whether the object is at
565
+ // the hold point along f.
566
+ function swing(t, scene, mp, body, local, config, dt) {
567
+ const held = t.held;
568
+ const aim = held.aim;
569
+ const shape = local.components.Shape;
570
+ const radius = typeof shape?.radius === 'number' ? shape.radius : PLAYER.radius;
571
+ const distance = Math.max(config.holdDistance, radius + held.extent + 0.15);
572
+ const step = (most) => {
573
+ const by = most / distance;
574
+ const left = turn(aim.f - aim.a);
575
+ const a = Math.abs(left) <= by ? aim.f : aim.a + Math.sign(left) * by;
576
+ const to = holdPoint(local, config, held, a);
577
+ const from = held.at;
578
+ const d = Math.hypot(to.x - from.x, to.y - from.y, to.z - from.z);
579
+ const k = d > most && d > 0 ? most / d : 1;
580
+ const next = {
581
+ x: from.x + (to.x - from.x) * k,
582
+ y: from.y + (to.y - from.y) * k,
583
+ z: from.z + (to.z - from.z) * k,
584
+ };
585
+ return { a, to, next };
586
+ };
587
+ const full = CARRY_SPEED * dt;
588
+ const places = reach(held, mp);
589
+ let most = full;
590
+ if (places === false) {
591
+ most = 0;
592
+ } else if (places !== null) {
593
+ const fits = (p) =>
594
+ places.every((q) => Math.hypot(p.x - q.x, p.y - q.y, p.z - q.z) <= AIM_SLACK_M);
595
+ if (!fits(step(full).next)) {
596
+ // The farthest that fits, to well under a millimetre; none, when even a
597
+ // little way does not (the object stays where it was last reported).
598
+ let lo = 0;
599
+ let hi = full;
600
+ for (let i = 0; i < 24; i += 1) {
601
+ const mid = (lo + hi) / 2;
602
+ if (fits(step(mid).next)) {
603
+ lo = mid;
604
+ } else {
605
+ hi = mid;
606
+ }
607
+ }
608
+ most = lo;
609
+ }
610
+ }
611
+ const { a, to } = step(most);
612
+ aim.a = a;
613
+ const reached = carry(t, scene, body, local, config, dt, to, most);
614
+ if (places !== null) {
615
+ // Reported at rest where it is put: the swing's own pace is the
616
+ // acknowledgements', not a velocity the next physics step carries on.
617
+ body.setLinvel({ x: 0, y: 0, z: 0 }, true);
618
+ }
619
+ return reached && aim.a === aim.f;
620
+ }
621
+
622
+ // What this client has told the server about a held object, kept frame by
623
+ // frame under the orbit key while it is held: `trail`, `[report number,
624
+ // position]` for each movement report since the hold began (carry and swing
625
+ // alike), known from report number `from` on; and `sure`, the newest report
626
+ // the server's body is sure to have reached (`reach`). The position is the one
627
+ // the report carried: the body where this system left it the frame the report
628
+ // went out (`put`), which the multiplayer kit reads straight after, before the
629
+ // next frame's physics moves it on at its velocity. Never the body read back a
630
+ // frame later, which is not where it was reported. Without acknowledgements or
631
+ // report numbers there is nothing to keep.
632
+ function listen(held, mp) {
633
+ if (!(mp.acks instanceof Map) || !Number.isFinite(mp.moveSeq)) {
634
+ return;
635
+ }
636
+ const epoch = mp.handed?.get?.(held.id)?.epoch;
637
+ let sent = held.sent;
638
+ if (!sent || sent.epoch !== epoch) {
639
+ // Reports up to now are of an object not yet held here (or under another
640
+ // grant): where they put it is not known.
641
+ sent = held.sent = {
642
+ epoch,
643
+ seq: mp.moveSeq,
644
+ from: mp.moveSeq + 1,
645
+ trail: [],
646
+ sure: -Infinity,
647
+ put: null,
648
+ };
649
+ }
650
+ if (mp.moveSeq !== sent.seq) {
651
+ if (mp.moveSeq === sent.seq + 1 && sent.put) {
652
+ sent.trail.push([mp.moveSeq, sent.put]);
653
+ } else {
654
+ // Reports went out unseen, or after a frame that left nothing put:
655
+ // what they carried is not known.
656
+ sent.from = mp.moveSeq + 1;
657
+ }
658
+ sent.seq = mp.moveSeq;
659
+ }
660
+ sent.put = null;
661
+ // multiplayer-3d's acknowledgement is `[epoch, lastSeq, tAck, ...]`: the
662
+ // newest report applied, and the simulation time it was applied at.
663
+ const ack = mp.acks.get(held.id);
664
+ if (
665
+ Array.isArray(ack) &&
666
+ Number.isFinite(ack[1]) &&
667
+ Number.isFinite(ack[2]) &&
668
+ (!Number.isFinite(epoch) || ack[0] === epoch) &&
669
+ hub.lastT > ack[2]
670
+ ) {
671
+ sent.sure = Math.max(sent.sure, ack[1]);
672
+ }
673
+ }
674
+
675
+ // The body of a held object where this system leaves it this frame: the
676
+ // position a movement report going out this frame carries (`listen`).
677
+ function put(held, body) {
678
+ if (held.sent) {
679
+ const p = body.translation();
680
+ held.sent.put = { x: p.x, y: p.y, z: p.z };
681
+ }
682
+ }
683
+
684
+ // Every place the server's body for a held object may be when the next
685
+ // report reaches it: the reported positions from the newest one it is sure to
686
+ // have reached on. null when the multiplayer kit gives no acknowledgements
687
+ // or report numbers (the swing is unbounded, as before them); false when no
688
+ // such report is known yet.
689
+ //
690
+ // An acknowledgement alone is not a body moved. multiplayer-3d applies a
691
+ // report as it arrives (its kinematic target, stamped with the simulation
692
+ // time, `tAck`), moves the body to the newest applied target at each physics
693
+ // step, and acknowledges in the broadcast after a tick's steps; but a tick may
694
+ // run no step (its elapsed time short of one) and acknowledge all the same,
695
+ // leaving the body where the last step put it. The simulation time advances
696
+ // only by physics steps (a tick that falls behind skips time only after its
697
+ // full four), so a broadcast whose time (`msg.t`, which the hub's state hook
698
+ // keeps as `hub.lastT`) is past a report's `tAck` comes after a step that
699
+ // moved the body to that report or a later one. Later reports are ordered
700
+ // after it on the one connection, so the body may be at any of them, and
701
+ // never back before it.
702
+ function reach(held, mp) {
703
+ if (!(mp.acks instanceof Map) || !Number.isFinite(mp.moveSeq)) {
704
+ return null;
705
+ }
706
+ const sent = held.sent;
707
+ if (!sent || sent.sure < sent.from) {
708
+ return false;
709
+ }
710
+ while (sent.trail.length > 0 && sent.trail[0][0] < sent.sure) {
711
+ sent.trail.shift();
712
+ }
713
+ return sent.trail.length > 0 ? sent.trail.map(([, p]) => p) : false;
714
+ }
715
+
716
+ // An angle as the shortest way round: -PI..PI.
717
+ function turn(angle) {
718
+ return angle - 2 * Math.PI * Math.floor((angle + Math.PI) / (2 * Math.PI));
719
+ }