castle-web-cli 0.4.239 → 0.4.240

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 (386) hide show
  1. package/dist/agent.js +5 -1
  2. package/dist/api.d.ts +20 -0
  3. package/dist/api.js +57 -0
  4. package/dist/bundle.d.ts +38 -1
  5. package/dist/bundle.js +309 -13
  6. package/dist/castle-host/host.js +163 -11
  7. package/dist/castleJson.d.ts +10 -0
  8. package/dist/castleJson.js +46 -2
  9. package/dist/check.js +5 -2
  10. package/dist/devSessionServer.js +4 -1
  11. package/dist/devSessionStorage.d.ts +1 -0
  12. package/dist/devSessionStorage.js +32 -7
  13. package/dist/importOrder.d.ts +2 -0
  14. package/dist/importOrder.js +29 -0
  15. package/dist/index.js +6 -3
  16. package/dist/init.js +24 -2
  17. package/dist/platformDoc.js +2 -1
  18. package/dist/playPagePolicy.js +5 -1
  19. package/dist/resetLeaderboards.d.ts +8 -1
  20. package/dist/resetLeaderboards.js +43 -8
  21. package/dist/save-deck.d.ts +32 -2
  22. package/dist/save-deck.js +240 -39
  23. package/kits/base/CLAUDE.md +1 -1
  24. package/kits/base/castle.json +1 -1
  25. package/kits/base/sdk/README.md +174 -6
  26. package/kits/base/sdk/analytics.d.ts +8 -0
  27. package/kits/base/sdk/analytics.js +92 -0
  28. package/kits/base/sdk/castle.d.ts +5 -1
  29. package/kits/base/sdk/castle.js +2 -0
  30. package/kits/base/sdk/commands.d.ts +48 -0
  31. package/kits/base/sdk/commands.js +1 -0
  32. package/kits/base/sdk/debugConsole.d.ts +17 -0
  33. package/kits/base/sdk/debugConsole.js +154 -0
  34. package/kits/base/sdk/experiments.js +24 -1
  35. package/kits/base/sdk/hostRetry.d.ts +7 -0
  36. package/kits/base/sdk/hostRetry.js +57 -0
  37. package/kits/base/sdk/hub.d.ts +20 -2
  38. package/kits/base/sdk/hub.js +99 -13
  39. package/kits/base/sdk/multiplayer.d.ts +2 -0
  40. package/kits/base/sdk/multiplayer.js +168 -26
  41. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  42. package/kits/base/sdk/reconnectBudget.js +41 -1
  43. package/kits/base/sdk/runtime.js +36 -19
  44. package/kits/base/sdk/server/hub.d.ts +19 -0
  45. package/kits/base/sdk/server/hub.js +12 -0
  46. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  47. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  48. package/kits/base/sdk/server/wrapper.js +26 -1
  49. package/kits/base/sdk/transport.d.ts +2 -1
  50. package/kits/base/sdk/transport.js +35 -0
  51. package/kits/hub-game/CLAUDE.md +66 -19
  52. package/kits/hub-game/code/client/act.js +9 -6
  53. package/kits/hub-game/code/client/actCore.js +26 -6
  54. package/kits/hub-game/code/client/actGateLog.js +36 -0
  55. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  56. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  57. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  58. package/kits/hub-game/code/client/askSurface.js +85 -0
  59. package/kits/hub-game/code/client/askTree.js +51 -0
  60. package/kits/hub-game/code/client/attention.js +31 -6
  61. package/kits/hub-game/code/client/ballot.js +42 -5
  62. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  63. package/kits/hub-game/code/client/ballotTree.js +180 -0
  64. package/kits/hub-game/code/client/catchingUp.js +19 -0
  65. package/kits/hub-game/code/client/celebrate.js +66 -0
  66. package/kits/hub-game/code/client/chrome.js +473 -53
  67. package/kits/hub-game/code/client/companion.js +93 -23
  68. package/kits/hub-game/code/client/companionDress.js +1 -1
  69. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  70. package/kits/hub-game/code/client/cornerTree.js +83 -0
  71. package/kits/hub-game/code/client/decor.js +20 -11
  72. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  73. package/kits/hub-game/code/client/disguise.js +23 -0
  74. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  75. package/kits/hub-game/code/client/dockSurface.js +206 -0
  76. package/kits/hub-game/code/client/dockTree.js +232 -0
  77. package/kits/hub-game/code/client/earned.js +29 -0
  78. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  79. package/kits/hub-game/code/client/emoteTree.js +264 -0
  80. package/kits/hub-game/code/client/farAvatars.js +4 -3
  81. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  82. package/kits/hub-game/code/client/grab.js +121 -50
  83. package/kits/hub-game/code/client/holdShow.js +19 -0
  84. package/kits/hub-game/code/client/hookLayer.js +96 -12
  85. package/kits/hub-game/code/client/hubControls.js +7 -1
  86. package/kits/hub-game/code/client/hudSurface.js +11 -3
  87. package/kits/hub-game/code/client/hudTree.js +7 -4
  88. package/kits/hub-game/code/client/idle.js +21 -3
  89. package/kits/hub-game/code/client/invites.js +24 -3
  90. package/kits/hub-game/code/client/keys.js +15 -0
  91. package/kits/hub-game/code/client/labelsNear.js +8 -1
  92. package/kits/hub-game/code/client/layoutCache.js +57 -8
  93. package/kits/hub-game/code/client/loadingCover.js +53 -4
  94. package/kits/hub-game/code/client/menuIcons.js +15 -0
  95. package/kits/hub-game/code/client/menuSurface.js +102 -0
  96. package/kits/hub-game/code/client/menuTree.js +135 -0
  97. package/kits/hub-game/code/client/modelLook.js +41 -0
  98. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  99. package/kits/hub-game/code/client/pickerTree.js +163 -0
  100. package/kits/hub-game/code/client/pushVisit.js +4 -2
  101. package/kits/hub-game/code/client/quality.js +188 -29
  102. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  103. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  104. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  105. package/kits/hub-game/code/client/rehello.js +75 -0
  106. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  107. package/kits/hub-game/code/client/replay.js +118 -0
  108. package/kits/hub-game/code/client/role.js +3 -0
  109. package/kits/hub-game/code/client/safeLayout.js +441 -56
  110. package/kits/hub-game/code/client/safeStyle.js +13 -10
  111. package/kits/hub-game/code/client/say.js +2 -0
  112. package/kits/hub-game/code/client/soundSurface.js +77 -0
  113. package/kits/hub-game/code/client/soundTree.js +74 -0
  114. package/kits/hub-game/code/client/soundscape.js +12 -9
  115. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  116. package/kits/hub-game/code/client/state.js +67 -1
  117. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  118. package/kits/hub-game/code/client/stuckTree.js +67 -0
  119. package/kits/hub-game/code/client/talk.js +42 -12
  120. package/kits/hub-game/code/client/talkTree.js +4 -2
  121. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  122. package/kits/hub-game/code/client/textAskTree.js +67 -0
  123. package/kits/hub-game/code/client/tiers.js +252 -27
  124. package/kits/hub-game/code/client/together.js +4 -1
  125. package/kits/hub-game/code/client/uiDom.js +86 -8
  126. package/kits/hub-game/code/client/uiTree.js +33 -4
  127. package/kits/hub-game/code/client/vehicle.js +72 -51
  128. package/kits/hub-game/code/client/weakestTier.js +75 -31
  129. package/kits/hub-game/code/client/wear.js +159 -5
  130. package/kits/hub-game/code/client/worldLabels.js +205 -25
  131. package/kits/hub-game/code/companionSpec.js +4 -2
  132. package/kits/hub-game/code/server/act.js +3 -0
  133. package/kits/hub-game/code/server/actGate.js +83 -0
  134. package/kits/hub-game/code/server/actions.js +71 -15
  135. package/kits/hub-game/code/server/actors.js +20 -5
  136. package/kits/hub-game/code/server/analytics.js +35 -3
  137. package/kits/hub-game/code/server/ask.js +39 -3
  138. package/kits/hub-game/code/server/ballot.js +167 -4
  139. package/kits/hub-game/code/server/celebrate.js +64 -0
  140. package/kits/hub-game/code/server/companion.js +17 -2
  141. package/kits/hub-game/code/server/decor.js +11 -2
  142. package/kits/hub-game/code/server/disguise.js +63 -0
  143. package/kits/hub-game/code/server/earned.js +6 -2
  144. package/kits/hub-game/code/server/friendBests.js +13 -4
  145. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  146. package/kits/hub-game/code/server/grab.js +12 -2
  147. package/kits/hub-game/code/server/heldOffers.js +142 -0
  148. package/kits/hub-game/code/server/holdShow.js +98 -0
  149. package/kits/hub-game/code/server/hub.js +851 -45
  150. package/kits/hub-game/code/server/idle.js +110 -9
  151. package/kits/hub-game/code/server/index.js +9 -0
  152. package/kits/hub-game/code/server/labels.js +13 -3
  153. package/kits/hub-game/code/server/manifest.js +94 -6
  154. package/kits/hub-game/code/server/menu.js +26 -3
  155. package/kits/hub-game/code/server/npcs.js +55 -9
  156. package/kits/hub-game/code/server/observe.js +67 -6
  157. package/kits/hub-game/code/server/players.js +8 -1
  158. package/kits/hub-game/code/server/replay.js +135 -0
  159. package/kits/hub-game/code/server/storageLimit.js +4 -1
  160. package/kits/hub-game/code/server/townDay.js +74 -0
  161. package/kits/hub-game/code/server/vehicle.js +3 -0
  162. package/kits/hub-game/code/server/vis.js +26 -4
  163. package/kits/hub-game/code/server/wallet.js +677 -0
  164. package/kits/hub-game/code/server/wear.js +13 -3
  165. package/kits/hub-game/code/server/writerLease.js +191 -0
  166. package/kits/hub-game/code/shared/act.js +1 -1
  167. package/kits/hub-game/code/shared/expression.js +6 -0
  168. package/kits/hub-game/code/shared/replay.js +37 -0
  169. package/kits/hub-game/code/systems/hub.js +427 -54
  170. package/kits/hub-game/docs/analytics.md +16 -2
  171. package/kits/hub-game/docs/contract.md +942 -99
  172. package/kits/hub-game/docs/home-pieces.md +5 -6
  173. package/kits/hub-game/docs/observed-progress.md +49 -1
  174. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  175. package/kits/hub-game/index.html +1 -0
  176. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  177. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  178. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  179. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  180. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  181. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  182. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  183. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  184. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  185. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  186. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  187. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  188. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  189. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  190. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  200. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  201. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  202. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  203. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  204. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  205. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  206. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  207. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  208. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  209. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  210. package/kits/hub-game/package-lock.json +3 -3
  211. package/kits/hub-game/package.json +4 -3
  212. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  213. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  214. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  215. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  216. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  217. package/kits/hub-game/scripts/pack.mjs +89 -23
  218. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  219. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  220. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  221. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  222. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  223. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  224. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  225. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  226. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  227. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  228. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  229. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  230. package/kits/hub-game/scripts/test-analytics.mjs +79 -0
  231. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  232. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  233. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  234. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  235. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  236. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  237. package/kits/hub-game/scripts/test-ballot.mjs +420 -3
  238. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  239. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  240. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  241. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  242. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  243. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  244. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  245. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  246. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  247. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  248. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  249. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  250. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  251. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  252. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  253. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  254. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  255. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  256. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  257. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  258. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  259. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  260. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  261. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  262. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  263. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  264. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  265. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  266. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  267. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  268. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  269. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  270. package/kits/hub-game/scripts/test-hub-ops.mjs +119 -0
  271. package/kits/hub-game/scripts/test-hub-trip.mjs +240 -4
  272. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  273. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  274. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  275. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  276. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  277. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  278. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  279. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  280. package/kits/hub-game/scripts/test-menu-client.mjs +54 -5
  281. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  282. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  283. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  284. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  285. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  286. package/kits/hub-game/scripts/test-placeat-server.mjs +395 -0
  287. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  288. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  289. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  290. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  291. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  292. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  293. package/kits/hub-game/scripts/test-rehello.mjs +237 -0
  294. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  295. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  296. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  297. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  298. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  299. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  300. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  301. package/kits/hub-game/scripts/test-role-client.mjs +2 -1
  302. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  303. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  304. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  305. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  306. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  307. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  308. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  309. package/kits/hub-game/scripts/test-stuck.mjs +31 -0
  310. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  311. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  312. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  313. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  314. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  315. package/kits/hub-game/scripts/test-together.mjs +11 -0
  316. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  317. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  318. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  319. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  320. package/kits/hub-game/scripts/test-vehicle-client.mjs +68 -1
  321. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  322. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  323. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  324. package/kits/hub-game/scripts/test-world-labels.mjs +340 -0
  325. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  326. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  327. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  328. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  329. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  330. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +36 -2
  331. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +10 -2
  332. package/kits/multiplayer-3d/castle.json +5 -5
  333. package/kits/multiplayer-3d/code/client/resumeGate.js +49 -2
  334. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  335. package/kits/multiplayer-3d/code/server/world.js +19 -4
  336. package/kits/multiplayer-3d/code/systems/multiplayer.js +67 -11
  337. package/kits/multiplayer-3d/package-lock.json +1 -1
  338. package/kits/multiplayer-3d/package.json +2 -1
  339. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  340. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  341. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  342. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +191 -5
  343. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  344. package/kits/physics-2d/castle.json +2 -2
  345. package/kits/physics-2d/engine/scene.js +10 -2
  346. package/kits/physics-3d/CLAUDE.md +14 -0
  347. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  348. package/kits/physics-3d/castle.json +3 -3
  349. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  350. package/kits/physics-3d/docs/engine-player.md +76 -0
  351. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  352. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  353. package/kits/physics-3d/engine3d/gait.js +16 -8
  354. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  355. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  356. package/kits/physics-3d/engine3d/look.js +110 -17
  357. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  358. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  359. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  360. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  361. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  362. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  363. package/kits/physics-3d/engine3d/optimize.js +20 -9
  364. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  365. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  366. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  367. package/kits/physics-3d/engine3d/world3d.js +211 -17
  368. package/kits/physics-3d/package-lock.json +1 -1
  369. package/kits/physics-3d/package.json +2 -1
  370. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  371. package/kits/physics-3d/scripts/render.mjs +56 -8
  372. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  373. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  374. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  375. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  376. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  377. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  378. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  379. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  380. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  381. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  382. package/kits/physics-3d/systems/physics3d.js +51 -2
  383. package/kits/real-time/castle.json +2 -2
  384. package/kits/real-time/code/client/connection.js +3 -0
  385. package/package.json +2 -2
  386. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -93,10 +93,10 @@ try {
93
93
  assert.deepEqual(m.avatarFits[style][i], m.avatarFits.toon[i], 'all fallback fits use toon');
94
94
  }
95
95
  }
96
- const wearFiles = ['hats', 'earned', 'role'].flatMap((dir) => fs.readdirSync(path.join(kits, 'hub-game/models', dir), { recursive: true })
96
+ const wearFiles = ['hats', 'earned', 'role', 'hold-show'].flatMap((dir) => fs.readdirSync(path.join(kits, 'hub-game/models', dir), { recursive: true })
97
97
  .filter((file) => file.endsWith('.pxmodel')).map((file) => `${dir === 'hats' ? 'hat' : dir}/${file.slice(0, -'.pxmodel'.length).split(path.sep).join('/')}`));
98
98
  assert.deepEqual(Object.keys(m.wearModels).sort(), wearFiles.sort(), 'every kit wear model, including square variants');
99
- for (const id of ['role/top-vest', 'role/tool-torch', 'hat/police-cap', 'role/square/top-vest', 'earned/square/belt-plain']) {
99
+ for (const id of ['role/top-vest', 'role/tool-torch', 'hat/police-cap', 'role/square/top-vest', 'earned/square/belt-plain', 'hold-show/daisy', 'hold-show/square/moonflower']) {
100
100
  const asset = m.wearModels[id];
101
101
  assert.equal(asset.type, 'glb');
102
102
  assert.deepEqual(asset, m.assets[id], 'registered for cache restaging and upload');
@@ -106,6 +106,14 @@ try {
106
106
  assert.equal(m.wearPieces['role/top-vest'].scale, undefined, 'top stretching depends on the fit');
107
107
  assert.equal(m.wearPieces['role/tool-torch'].scale, 1.2);
108
108
  assert.equal(m.wearPieces['role/tool-torch'].anchor, 'hand');
109
+ // v1.182 hold-show flowers: right hand, holdShowLook's scale, tinted from the model's main colour.
110
+ for (const shape of ['daisy', 'tulip', 'sunflower', 'rose', 'moonflower']) {
111
+ assert.ok(m.wearModels[`hold-show/${shape}`] && m.wearModels[`hold-show/square/${shape}`], `hold-show ${shape} and its square variant`);
112
+ assert.equal(m.wearPieces[`hold-show/${shape}`].anchor, 'hand');
113
+ assert.equal(m.wearPieces[`hold-show/${shape}`].scale, 1.2);
114
+ assert.match(m.wearPieces[`hold-show/${shape}`].placement, /hubHoldShow/);
115
+ assert.equal(m.wearPieces[`hold-show/square/${shape}`], undefined, 'one piece per shape; the square model is chosen by fit');
116
+ }
109
117
  assert.equal(m.wearPieces['earned/badge-star'].scale, 2.6);
110
118
  assert.equal(m.wearPieces['earned/pin-round'].scale, 2.1);
111
119
  assert.equal(m.wearPieces['earned/belt-plain'].anchor, 'waist');
@@ -117,6 +125,15 @@ try {
117
125
  assert.ok(wearFaults({ wearPieces: null }).includes('wearPieces is not an object'));
118
126
  const missingHat = { ...m.wearModels }; delete missingHat['hat/police-cap'];
119
127
  assert.ok(wearFaults({ wearModels: missingHat }).includes('wearModels: missing hat/police-cap'));
128
+ // Flowers are optional (older manifests have none) but all or nothing, each with its piece.
129
+ const noFlowers = Object.fromEntries(Object.entries(m.wearModels).filter(([id]) => !id.startsWith('hold-show/')));
130
+ const noFlowerPieces = Object.fromEntries(Object.entries(m.wearPieces).filter(([id]) => !id.startsWith('hold-show/')));
131
+ assert.deepEqual(wearFaults({ wearModels: noFlowers, wearPieces: noFlowerPieces }), []);
132
+ const oneFlowerShort = { ...m.wearModels }; delete oneFlowerShort['hold-show/square/rose'];
133
+ assert.ok(wearFaults({ wearModels: oneFlowerShort }).includes('wearModels: missing hold-show/square/rose'));
134
+ assert.ok(wearFaults({ wearPieces: noFlowerPieces }).includes('wearPieces: missing hold-show/rose'));
135
+ assert.ok(wearFaults({ wearModels: noFlowers }).includes('wearPieces hold-show/daisy: anchor'));
136
+ assert.ok(wearFaults({ wearModels: { ...m.wearModels, 'hold-show/lily': m.wearModels['hold-show/daisy'] } }).includes('wearModels hold-show/lily: id'));
120
137
  // export-hub --deck-wear: what source.wear.deck.leftOut lists may be absent, with its pieces; nothing
121
138
  // else may, and a listed id must be a kit wear model that is really absent.
122
139
  const deckOnly = (leftOut, models = m.wearModels, pieces = m.wearPieces) =>
@@ -129,6 +146,13 @@ try {
129
146
  assert.ok(deckOnly(['hats/police-cap', ...roleIds], { ...noRole, 'role/tool-torch': m.wearModels['role/tool-torch'] }, noRolePieces).includes('wearModels role/tool-torch: listed as left out'));
130
147
  assert.ok(deckOnly(['hats/police-cap', 'hats/nonsense', ...roleIds], noRole, noRolePieces).includes('source.wear.deck.leftOut: hat/nonsense is not a kit wear model'));
131
148
  assert.ok(deckOnly(['hats/police-cap', ...roleIds], noRole, m.wearPieces).includes('wearPieces role/top-vest: no model'));
149
+ // leftOut never excuses a flower: listing one faults, and a manifest with any still needs all.
150
+ assert.ok(deckOnly(['hold-show/square/rose'], oneFlowerShort).includes('wearModels: missing hold-show/square/rose'));
151
+ assert.ok(deckOnly(['hold-show/square/rose'], oneFlowerShort).includes('source.wear.deck.leftOut: hold-show/square/rose is not a kit wear model'));
152
+ const noRose = Object.fromEntries(Object.entries(m.wearModels).filter(([id]) => !id.endsWith('/rose')));
153
+ const noRosePiece = { ...m.wearPieces }; delete noRosePiece['hold-show/rose'];
154
+ const roseOut = deckOnly(['hold-show/rose', 'hold-show/square/rose'], noRose, noRosePiece);
155
+ assert.ok(roseOut.includes('wearModels: missing hold-show/rose') && roseOut.includes('wearPieces: missing hold-show/rose'));
132
156
  const badWear = { ...m.wearModels, 'role/top-vest': { ...m.wearModels['role/top-vest'], uri: '../shared/missing.glb' } };
133
157
  assert.ok(wearFaults({ wearModels: badWear }).some((fault) => fault.startsWith('asset wearModels role/top-vest:') && fault.endsWith('missing')));
134
158
  const benchLayers = m.layers.filter((l) => l.role === 'prop');
@@ -269,6 +293,16 @@ try {
269
293
  fs.rmSync(path.join(deck, 'code/server/rocks.js'));
270
294
  assert.equal(run().cached, false, 'removing it exports again');
271
295
  assert.equal(manifest().actors['rock-a'], undefined);
296
+ // A car, disguise or replay look names the actor whose model it draws: a file making any one of
297
+ // those calls (spaces around it allowed) keeps its quoted ids apart too.
298
+ for (const call of ["hub.drive(p, { look: 'rock-a' })", "hub.disguise ?. (p, { look: 'rock-a' })", "hub.replay (p, 0, { trace: [], look: 'rock-a' })"]) {
299
+ fs.writeFileSync(path.join(deck, 'code/server/looks.js'), `export const go = (hub, p) => ${call};\n`);
300
+ assert.equal(run().cached, false, `${call}: exports again`);
301
+ assert.ok(manifest().actors['rock-a'] && !Object.values(manifest().merged).flat().includes('rock-a'), `${call}: its look has its own node`);
302
+ fs.rmSync(path.join(deck, 'code/server/looks.js'));
303
+ assert.equal(run().cached, false);
304
+ assert.equal(manifest().actors['rock-a'], undefined);
305
+ }
272
306
 
273
307
  // What a place can spawn, hide or show by an id the code never quotes for hide/show keeps its own
274
308
  // node: a template only ever spawned, one the decor catalogue copies (`"decor": true`), and ids
@@ -9,6 +9,7 @@ import crypto from 'node:crypto';
9
9
  import { HATS } from '../../code/client/hats.js';
10
10
  import { ROLE_TOPS, ROLE_TOOLS } from '../../code/client/role.js';
11
11
  import { EARNED_SHAPES, EARNED_SHAPE_CLASS, SQUARE_SHAPES } from '../../code/client/earned.js';
12
+ import { HOLD_SHOW_SHAPES } from '../../code/client/holdShow.js';
12
13
 
13
14
  export function validateManifest(m, dir, { hash = true } = {}) {
14
15
  const faults = [];
@@ -66,6 +67,10 @@ export function validateManifest(m, dir, { hash = true } = {}) {
66
67
  ...ROLE_TOPS.flatMap((id) => [`role/top-${id}`, `role/square/top-${id}`]),
67
68
  ...ROLE_TOOLS.map((id) => `role/tool-${id}`),
68
69
  ];
70
+ // v1.182 hold-show flowers: optional (manifests exported before them, and castle-client's
71
+ // export-hub, have none), but all or nothing, each with its square variant and piece.
72
+ const flowerModels = HOLD_SHOW_SHAPES.flatMap((id) => [`hold-show/${id}`, `hold-show/square/${id}`]);
73
+ const flowers = isObj(m.wearModels) && Object.keys(m.wearModels).some((id) => id.startsWith('hold-show/'));
69
74
  // castle-client export-hub --deck-wear builds only the wear models the deck's own bundle ships
70
75
  // and lists the kit's others in source.wear.deck.leftOut ('hats/<id>', 'role/...'): those may be
71
76
  // absent (with their pieces), never present; every other id is still required.
@@ -75,12 +80,14 @@ export function validateManifest(m, dir, { hash = true } = {}) {
75
80
  if (!isObj(m.wearModels)) fault('wearModels is not an object');
76
81
  else {
77
82
  for (const id of requiredModels) if (!Object.hasOwn(m.wearModels, id) && !leftOut.has(id)) fault(`wearModels: missing ${id}`);
83
+ // leftOut never excuses a flower: a manifest with any has every one.
84
+ if (flowers) for (const id of flowerModels) if (!Object.hasOwn(m.wearModels, id)) fault(`wearModels: missing ${id}`);
78
85
  for (const id of leftOut) {
79
86
  if (!requiredModels.includes(id)) fault(`source.wear.deck.leftOut: ${id} is not a kit wear model`);
80
87
  else if (Object.hasOwn(m.wearModels, id)) fault(`wearModels ${id}: listed as left out`);
81
88
  }
82
89
  for (const [id, asset] of Object.entries(m.wearModels)) {
83
- if (!/^(hat|earned|role)\/(square\/)?[a-z0-9-]+$/.test(id)) fault(`wearModels ${id}: id`);
90
+ if (!/^(hat|earned|role|hold-show)\/(square\/)?[a-z0-9-]+$/.test(id) || (id.startsWith('hold-show/') && !flowerModels.includes(id))) fault(`wearModels ${id}: id`);
84
91
  if (asset?.type !== 'glb') fault(`wearModels ${id}: not a glb asset`);
85
92
  if (asset?.uri !== `../shared/${asset?.sha256}.glb`) fault(`wearModels ${id}: uri`);
86
93
  checkAsset(`wearModels ${id}`, asset);
@@ -89,6 +96,7 @@ export function validateManifest(m, dir, { hash = true } = {}) {
89
96
  }
90
97
  const anchors = Object.fromEntries([
91
98
  ...ROLE_TOPS.map((id) => [`role/top-${id}`, 'waist']), ...ROLE_TOOLS.map((id) => [`role/tool-${id}`, 'hand']),
99
+ ...(flowers ? HOLD_SHOW_SHAPES.map((id) => [`hold-show/${id}`, 'hand']) : []),
92
100
  ...EARNED_SHAPES.map((shape) => {
93
101
  const cls = EARNED_SHAPE_CLASS[shape];
94
102
  return [`earned/${shape}`, cls === 'badge' || cls === 'pin' ? 'chest' : cls === 'belt' ? 'waist' : cls === 'held' ? 'hand' : 'sash'];
@@ -96,7 +104,7 @@ export function validateManifest(m, dir, { hash = true } = {}) {
96
104
  ]);
97
105
  if (!isObj(m.wearPieces)) fault('wearPieces is not an object');
98
106
  else {
99
- for (const id of Object.keys(anchors)) if (!Object.hasOwn(m.wearPieces, id) && !leftOut.has(id)) fault(`wearPieces: missing ${id}`);
107
+ for (const id of Object.keys(anchors)) if (!Object.hasOwn(m.wearPieces, id) && (!leftOut.has(id) || id.startsWith('hold-show/'))) fault(`wearPieces: missing ${id}`);
100
108
  for (const [id, piece] of Object.entries(m.wearPieces)) {
101
109
  if (!isObj(piece)) { fault(`wearPieces ${id}: not an object`); continue; }
102
110
  if (!anchors[id] || piece.anchor !== anchors[id]) fault(`wearPieces ${id}: anchor`);
@@ -7,26 +7,26 @@
7
7
  "imports": {
8
8
  "castle.real-time": {
9
9
  "deckId": "xFVr-afOLuUQ",
10
- "version": "2026-10-23T12:14:35.623Z"
10
+ "version": "2026-11-15T00:41:55.124Z"
11
11
  },
12
12
  "castle.physics-3d": {
13
13
  "deckId": "JH0SclbPVP0y",
14
- "version": "2026-10-23T12:14:42.092Z"
14
+ "version": "2026-11-15T00:45:03.769Z"
15
15
  },
16
16
  "castle.physics-2d": {
17
17
  "deckId": "ckRZGFW4iPrx",
18
- "version": "2026-10-17T06:02:29.713Z",
18
+ "version": "2026-11-15T00:41:50.817Z",
19
19
  "via": "castle.physics-3d"
20
20
  },
21
21
  "castle.base": {
22
22
  "deckId": "yRcmH4_aYllE",
23
- "version": "2026-10-23T12:08:44.010Z"
23
+ "version": "2026-11-15T00:40:25.157Z"
24
24
  }
25
25
  },
26
26
  "autoUpdateWhenImported": true,
27
27
  "deckId": "ZwA_P_-VO-Qh",
28
28
  "cardId": "bvRmCzyUpt_a",
29
- "publishedVersion": "2026-10-23T12:15:36.617Z",
29
+ "publishedVersion": "2026-11-15T00:45:38.865Z",
30
30
  "main": "main.jsx",
31
31
  "server": {
32
32
  "main": "code/server/index.js",
@@ -57,14 +57,21 @@ const WORLD = 'w';
57
57
  // ordinary release, as does a session that offers none.
58
58
  export const RESYNC_AWAY_MS = 5000;
59
59
 
60
+ // A socket can read connected and carry nothing after an away. A resync left
61
+ // unanswered this long asks the transport to recover instead of waiting for
62
+ // its keepalive deadline.
63
+ export const RESYNC_REPLY_MS = 3000;
64
+
60
65
  // An unarmed gate. `since` is the page time the room was last current,
61
66
  // `serverAt` the simulation time then (null with no clock yet), `shownAt` the
62
67
  // first page time the page was visible again while armed, `dropped` whether
63
68
  // the connection left `connected` during the away, `lostAt` the last page time
64
69
  // it was seen not connected, `backAt` when it came back after that, and
65
- // `asked` whether a resync was asked for (`ask`).
70
+ // `asked` whether a resync was asked for (`ask`), `askedAt` the page time then,
71
+ // `replyExpired` whether its unanswered reply has been reported, and `hiddenAt`
72
+ // the page time the page hid with a resync out (`suspendReply`).
66
73
  export function makeGate() {
67
- return { armed: false, since: 0, serverAt: null, shownAt: null, dropped: false, lostAt: null, backAt: null, asked: false };
74
+ return { armed: false, since: 0, serverAt: null, shownAt: null, dropped: false, lostAt: null, backAt: null, asked: false, askedAt: null, replyExpired: false, hiddenAt: null };
68
75
  }
69
76
 
70
77
  // Arm the gate for an away that began at page time `since`, when the server's
@@ -82,6 +89,9 @@ export function arm(gate, since, serverAt) {
82
89
  gate.lostAt = null;
83
90
  gate.backAt = null;
84
91
  gate.asked = false;
92
+ gate.askedAt = null;
93
+ gate.replyExpired = false;
94
+ gate.hiddenAt = null;
85
95
  return true;
86
96
  }
87
97
 
@@ -93,6 +103,9 @@ export function clear(gate) {
93
103
  gate.lostAt = null;
94
104
  gate.backAt = null;
95
105
  gate.asked = false;
106
+ gate.askedAt = null;
107
+ gate.replyExpired = false;
108
+ gate.hiddenAt = null;
96
109
  }
97
110
 
98
111
  // Whether to ask for a resync now, at page time `now`: once per away, an away
@@ -103,9 +116,43 @@ export function ask(gate, now) {
103
116
  return false;
104
117
  }
105
118
  gate.asked = true;
119
+ gate.askedAt = now;
106
120
  return true;
107
121
  }
108
122
 
123
+ // Whether a resync has gone unanswered at page time `now`, once per away.
124
+ // A limit of zero or less leaves recovery to the transport's own deadline.
125
+ export function unanswered(gate, now, limit) {
126
+ resumeReply(gate, now);
127
+ if (limit <= 0 || !gate.armed || !gate.asked || gate.dropped || gate.replyExpired || now - gate.askedAt < limit) {
128
+ return false;
129
+ }
130
+ gate.replyExpired = true;
131
+ return true;
132
+ }
133
+
134
+ // The page went away again at page time `now` with a resync out. A reply cannot
135
+ // be drained while hidden, so the reply wait and the give-up both count visible
136
+ // time only: `resumeReply` moves them on by the time away. Neither restarts, so
137
+ // a page that keeps hiding still reaches both.
138
+ export function suspendReply(gate, now) {
139
+ if (gate.armed && gate.asked && gate.hiddenAt === null) {
140
+ gate.hiddenAt = now;
141
+ }
142
+ }
143
+
144
+ function resumeReply(gate, now) {
145
+ if (gate.hiddenAt === null) {
146
+ return;
147
+ }
148
+ const away = now - gate.hiddenAt;
149
+ gate.hiddenAt = null;
150
+ gate.askedAt += away;
151
+ if (gate.shownAt !== null) {
152
+ gate.shownAt += away;
153
+ }
154
+ }
155
+
109
156
  // Note whether the connection is connected at page time `now`, while armed.
110
157
  // A return seen only by a frame dates from the last time it was seen lost, so
111
158
  // a WORLD that arrived between the two still counts.
@@ -96,12 +96,19 @@ function handOver(sim, entry, id, playerId, handovers) {
96
96
  entry.reportedAt = sim.timeMs;
97
97
  entry.claimedAt = sim.timeMs;
98
98
  entry.velocity = velocity;
99
+ // A grant starts with delivery slack only: neither elapsed time nor unused
100
+ // movement from the previous owner (or the server) belongs to this owner.
101
+ entry.moveBudget = Limits.MOVE_SLACK;
99
102
  const pose = entry.pose;
100
103
  entry.pose = null;
101
104
  if (playerId) {
102
105
  // An owned object is kinematic-position-based, so owner reports place it and
103
106
  // its collider remains active in the shared Rapier world.
104
107
  entry.body.setBodyType(RAPIER.RigidBodyType.KinematicPositionBased, true);
108
+ // A takeover can happen before the old owner's target has stepped. Cancel
109
+ // that target too, so the new grant starts at the body's current pose.
110
+ entry.body.setNextKinematicTranslation(entry.body.translation());
111
+ entry.body.setNextKinematicRotation(entry.body.rotation());
105
112
  } else {
106
113
  // A returned object becomes dynamic and keeps the velocity it had, so a
107
114
  // rolling object is still rolling when the server takes it back. Its last
@@ -168,20 +175,32 @@ export function setObjectPoses(sim, playerId, poses, handovers) {
168
175
  if (!asked) {
169
176
  continue;
170
177
  }
171
- const at = entry.body.translation();
172
- const elapsed = Math.max(0, sim.timeMs - entry.reportedAt) / 1000;
178
+ // The body reaches its kinematic target only at a physics step. A second
179
+ // report in the same tick must start from the newest accepted target of
180
+ // this grant, not the older body position. handOver clears that target.
181
+ const at = entry.pose?.at ?? entry.body.translation();
182
+ // Bank unused elapsed movement for reports delivered in a burst, up to the
183
+ // ownership timeout: a report gap shorter than that kept its whole
184
+ // elapsed allowance before, so no single report is judged more strictly
185
+ // than it was, and idle time never banks past it (60 m at 40 m/s).
186
+ // Slack is part of the shared budget, not a fresh allowance per report.
187
+ const bankS = Limits.OWNER_TIMEOUT_MS / 1000;
188
+ const elapsed = Math.min(bankS, Math.max(0, sim.timeMs - entry.reportedAt) / 1000);
189
+ const budget = Math.min(
190
+ Limits.MAX_OBJECT_SPEED * bankS + Limits.MOVE_SLACK,
191
+ (entry.moveBudget ?? Limits.MOVE_SLACK) + Limits.MAX_OBJECT_SPEED * elapsed,
192
+ );
193
+ const distance = Math.hypot(asked.x - at.x, asked.y - at.y, asked.z - at.z);
173
194
  entry.reportedAt = sim.timeMs;
174
195
 
175
196
  // A report beyond the object speed allowance releases the object to server
176
197
  // simulation. Player reports use clamping instead because each client must
177
198
  // continue controlling its own player (`players.js`).
178
- if (
179
- Math.hypot(asked.x - at.x, asked.y - at.y, asked.z - at.z) >
180
- Limits.MAX_OBJECT_SPEED * elapsed + Limits.MOVE_SLACK
181
- ) {
199
+ if (distance > budget) {
182
200
  handOver(sim, entry, id, null, handovers);
183
201
  continue;
184
202
  }
203
+ entry.moveBudget = budget - distance;
185
204
  const rotation = { x: number(qx), y: number(qy), z: number(qz), w: number(qw) };
186
205
  entry.body.setNextKinematicTranslation(asked);
187
206
  entry.body.setNextKinematicRotation(rotation);
@@ -69,15 +69,30 @@ export async function createSimulation(scenePath) {
69
69
  return sim;
70
70
  }
71
71
 
72
- // Add the server's 200 m square ground slab below the authored scene, unless
73
- // the scene has none (`"ground": { "none": true }`, as the engine reads it).
72
+ // Add the server's ground slab below the authored scene, unless the scene has
73
+ // none (`"ground": { "none": true }`, as the engine reads it): 200 m square, or
74
+ // twice the scene's `ground.half`, the size the engine's own collider takes
75
+ // (physics-3d engine3d/groundsize.js, whose rule `colliderHalf` repeats: the
76
+ // server bundle does not reach into the physics-3d import).
74
77
  // `Limits.FELL_OUT_Y` handles dynamic bodies that fall beyond its edge.
75
78
  function buildGround(sim) {
76
- if (sceneGround(sim.scenePath)?.none === true) {
79
+ const setting = sceneGround(sim.scenePath);
80
+ if (setting?.none === true) {
77
81
  return;
78
82
  }
83
+ const half = colliderHalf(setting);
79
84
  const ground = sim.world.createRigidBody(RAPIER.RigidBodyDesc.fixed().setTranslation(0, -0.5, 0));
80
- sim.world.createCollider(RAPIER.ColliderDesc.cuboid(100, 0.5, 100), ground);
85
+ sim.world.createCollider(RAPIER.ColliderDesc.cuboid(half, 0.5, half), ground);
86
+ }
87
+
88
+ // `ground.half` clamped to 1..200 (the world's xz bounds), or 100 when it is
89
+ // not a finite number.
90
+ function colliderHalf(setting) {
91
+ const half = setting?.half;
92
+ if (typeof half !== 'number' || !Number.isFinite(half)) {
93
+ return 100;
94
+ }
95
+ return Math.min(Limits.BOUNDS.xz, Math.max(1, half));
81
96
  }
82
97
 
83
98
  // Create Rapier bodies and indexes from the reduced scene representation.
@@ -31,7 +31,19 @@ const RESYNC = 'r';
31
31
  // How long the joining overlay may hold the card before giving up.
32
32
  const JOIN_WAIT_MS = 10000;
33
33
  const JOIN_WATCHDOG_MS = 20000;
34
+ // A frame gap this long, with no visibilitychange, is a suspended page (a
35
+ // backgrounded WebView that never said so), and a join pending across it is
36
+ // redone. Shorter gaps are load hitches: a cold Town load's first frames come
37
+ // seconds apart while the world builds, and treating those as a return threw
38
+ // every first join away. They are visible wall time, so they still spend the
39
+ // watchdog budget. After placement the resume gate keeps its own, much
40
+ // shorter, ResumeGate.STALL_MS.
41
+ const JOIN_STALL_MS = 10000;
34
42
  const JOIN_FAILURE_LIMIT = 3;
43
+ // A return's cover says nothing for this long after the page shows again:
44
+ // most returns are back sooner, and a plain cover over them reads as a blink
45
+ // rather than a fault. Past it, the cover says it is reconnecting.
46
+ export const QUIET_RETURN_MS = 2500;
35
47
  import { game } from '@imports/castle.real-time/code/client/gameHooks.js';
36
48
 
37
49
  // Apply this fraction of a server player correction per frame. Corrections over
@@ -213,10 +225,17 @@ class MultiplayerSystem {
213
225
  // `outAt` is the page time the player last came out from behind it, by a
214
226
  // snapshot, by giving up, or by the session closing under it (`returning`).
215
227
  this.resume = ResumeGate.makeGate();
228
+ // How long to wait for a resync reply before forcing recovery; 0 turns it off.
229
+ this.resyncReplyMs = ResumeGate.RESYNC_REPLY_MS;
216
230
  this.frameAt = 0;
217
231
  this.wasAway = false;
218
232
  this.gaveUp = false;
219
233
  this.outAt = null;
234
+ // Page time the return's quiet cover began: the away, or the page
235
+ // showing again after it (`QUIET_RETURN_MS`).
236
+ this.quietFrom = null;
237
+ // Whether the cover was last put up (`drawCover`).
238
+ this.coverUp = false;
220
239
  this.onVisibility = null;
221
240
  // Whether the session's last WORLD offered a resync (`rs`).
222
241
  this.resyncs = false;
@@ -230,7 +249,7 @@ class MultiplayerSystem {
230
249
  if (!this.net) {
231
250
  this.stepJoin(scene);
232
251
  this.watchJoin(scene);
233
- showJoinOverlay(this.joiningOverlayWanted(), this.coverText());
252
+ this.drawCover();
234
253
  return void this.start(scene);
235
254
  }
236
255
 
@@ -263,6 +282,9 @@ class MultiplayerSystem {
263
282
  // mean the room drawn is no longer current. The page being hidden arms the
264
283
  // same gate from its event (`start`), before the page goes.
265
284
  if (last && now - last > ResumeGate.STALL_MS) {
285
+ // Every stall return is quiet at first, even one that finds the gate
286
+ // still armed from an earlier away.
287
+ if (this.wasAway) { this.quietFrom = now; }
266
288
  this.away(last);
267
289
  }
268
290
  const connected = this.net.status().state === 'connected';
@@ -293,6 +315,10 @@ class MultiplayerSystem {
293
315
  if (this.watchJoin(scene)) {
294
316
  return;
295
317
  }
318
+ if (!pageHidden() && ResumeGate.unanswered(this.resume, now, this.resyncReplyMs)) {
319
+ console.warn('[multiplayer] resync unanswered; reconnecting');
320
+ this.net.reconnect?.();
321
+ }
296
322
  if (ResumeGate.waited(this.resume, now, !pageHidden())) {
297
323
  console.warn('[multiplayer] no current snapshot since coming back; showing the room as it is');
298
324
  this.resumed();
@@ -338,7 +364,7 @@ class MultiplayerSystem {
338
364
  }
339
365
  this.publish(scene, local);
340
366
  updateSoloBadge(this.net.status(), game);
341
- showJoinOverlay(this.joiningOverlayWanted(), this.coverText());
367
+ this.drawCover();
342
368
  }
343
369
 
344
370
  // Join the session `target` names (the public one unless `switchSession`
@@ -362,8 +388,12 @@ class MultiplayerSystem {
362
388
  if (pageHidden()) {
363
389
  if (this.joinAttempt) { this.joinAttempt.hidden = true; }
364
390
  this.away(this.frameAt || performance.now());
391
+ ResumeGate.suspendReply(this.resume, performance.now());
392
+ this.relabelCover();
365
393
  } else {
394
+ if (this.wasAway) { this.quietFrom = performance.now(); }
366
395
  this.visibleJoin(this.joinScene ?? scene, this.joinAttempt?.hidden === true);
396
+ this.relabelCover();
367
397
  }
368
398
  };
369
399
  document.addEventListener('visibilitychange', this.onVisibility);
@@ -421,7 +451,8 @@ class MultiplayerSystem {
421
451
  }
422
452
 
423
453
  // Only adjacent visible steps spend the budget. A suspended WebView can
424
- // miss visibilitychange entirely, including while getSession is pending.
454
+ // miss visibilitychange entirely, including while getSession is pending, so
455
+ // a gap past JOIN_STALL_MS counts as a return; a shorter one is a hitch.
425
456
  stepJoin(scene) {
426
457
  this.joinScene = scene;
427
458
  const now = performance.now();
@@ -430,7 +461,7 @@ class MultiplayerSystem {
430
461
  if (this.joined || this.target?.mode === 'hub' || this.joinFailed || this.net?.status().solo) { return; }
431
462
  const attempt = this.joinAttempt;
432
463
  const gap = attempt ? now - attempt.stepAt : 0;
433
- const stalled = this.starting ? gap > ResumeGate.STALL_MS : last !== null && now - last > ResumeGate.STALL_MS;
464
+ const stalled = this.starting ? gap > JOIN_STALL_MS : last !== null && now - last > JOIN_STALL_MS;
434
465
  if (!pageHidden() && (attempt?.hidden || stalled)) {
435
466
  this.visibleJoin(scene, true, true);
436
467
  return;
@@ -511,7 +542,7 @@ class MultiplayerSystem {
511
542
  this.joinFailed ||= this.joinFailures >= JOIN_FAILURE_LIMIT;
512
543
  if (this.joinFailed) {
513
544
  this.joinStage('gave up');
514
- showJoinOverlay(false);
545
+ this.drawCover(false);
515
546
  this.removeJoinFailure ??= showJoinFailure(this.joinName(), () => {
516
547
  if (!this.joinFailed) { return; }
517
548
  this.joinStage('retry tapped');
@@ -524,7 +555,7 @@ class MultiplayerSystem {
524
555
  this.joinRetryAt = 0;
525
556
  this.joinStartedAt = 0;
526
557
  void this.start(this.joinScene ?? scene);
527
- showJoinOverlay(this.joiningOverlayWanted(), this.coverText());
558
+ this.drawCover();
528
559
  });
529
560
  } else {
530
561
  this.joinRetryAt = performance.now() + Math.min(30_000, 1_000 * 2 ** Math.min(this.joinFailures - 1, 5));
@@ -584,7 +615,7 @@ class MultiplayerSystem {
584
615
  this.clock = Clock.makeClock();
585
616
  this.target = join;
586
617
  this.quiet = quiet;
587
- showJoinOverlay(this.joiningOverlayWanted(), this.coverText());
618
+ this.drawCover();
588
619
  }
589
620
 
590
621
  // Where the join `switchSession` asked for stands: 'joining', 'joined' (it
@@ -621,7 +652,8 @@ class MultiplayerSystem {
621
652
  if (ResumeGate.arm(this.resume, since, serverAt)) {
622
653
  console.log('[multiplayer] away; holding the room until a current snapshot');
623
654
  this.wasAway = true;
624
- showJoinOverlay(this.joiningOverlayWanted(), this.coverText());
655
+ this.quietFrom = performance.now();
656
+ this.drawCover();
625
657
  }
626
658
  }
627
659
 
@@ -691,10 +723,34 @@ class MultiplayerSystem {
691
723
  this.gaveUp = false;
692
724
  }
693
725
 
694
- // What the cover says.
726
+ // What the cover says. A return's says nothing while hidden and for
727
+ // QUIET_RETURN_MS after the page shows again.
695
728
  coverText() {
729
+ if (this.wasAway) {
730
+ return this.quietReturn() ? '' : 'Reconnecting…';
731
+ }
696
732
  const name = this.joinName();
697
- return this.wasAway ? 'Reconnecting…' : name ? `Joining ${name}…` : 'Joining…';
733
+ return name ? `Joining ${name}…` : 'Joining…';
734
+ }
735
+
736
+ // Put the cover up or take it down (`joiningOverlayWanted` unless told),
737
+ // with what it says now.
738
+ drawCover(wanted = this.joiningOverlayWanted()) {
739
+ this.coverUp = wanted;
740
+ showJoinOverlay(wanted, this.coverText());
741
+ }
742
+
743
+ // Only what an up cover says, now: a visibility change restarts a return's
744
+ // quiet before the next frame runs, and must not move the cover itself.
745
+ relabelCover() {
746
+ if (this.coverUp) {
747
+ showJoinOverlay(true, this.coverText());
748
+ }
749
+ }
750
+
751
+ // Whether a return's cover is still in its quiet first QUIET_RETURN_MS.
752
+ quietReturn() {
753
+ return this.wasAway && (pageHidden() || (this.quietFrom !== null && performance.now() - this.quietFrom < QUIET_RETURN_MS));
698
754
  }
699
755
 
700
756
  // Drain queued transport messages. State messages update clock, ownership, pose
@@ -1455,7 +1511,7 @@ class MultiplayerSystem {
1455
1511
  document.removeEventListener('visibilitychange', this.onVisibility);
1456
1512
  this.onVisibility = null;
1457
1513
  }
1458
- showJoinOverlay(false);
1514
+ this.drawCover(false);
1459
1515
  // The badge is a fixed element outside the scene, so a disposed runtime
1460
1516
  // (an editor preview closing, say) has to take it down explicitly.
1461
1517
  showSoloBadge(null);
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "../../sdk": {
34
34
  "name": "castle-web-sdk",
35
- "version": "0.4.50",
35
+ "version": "0.4.54",
36
36
  "dev": true,
37
37
  "devDependencies": {
38
38
  "eslint": "^9.0.0",
@@ -3,7 +3,8 @@
3
3
  "private": true,
4
4
  "type": "module",
5
5
  "scripts": {
6
- "test": "node scripts/test-own-name-tag.mjs && node scripts/test-eligible-claims.mjs && node scripts/test-resume-gate.mjs && node scripts/test-join-watchdog.mjs",
6
+ "test": "node scripts/test-own-name-tag.mjs && node scripts/test-ground-half.mjs && node scripts/test-eligible-claims.mjs && node scripts/test-resync-reconnect.mjs && node scripts/test-resume-gate.mjs && node scripts/test-join-watchdog.mjs && npm run test:owned-moves",
7
+ "test:owned-moves": "node scripts/test-owned-moves.mjs",
7
8
  "check": "eslint . && npm test && node --input-type=module -e \"const { bundleProject } = await import('../../cli/dist/bundle.js'); await bundleProject('.');\"",
8
9
  "format": "prettier --write \"code/**/*.js\" castle.json package.json"
9
10
  },
@@ -0,0 +1,56 @@
1
+ // The server's ground slab: 100 m each way without `ground.half`, the scene's
2
+ // half-width with it, and no slab for `ground.none`. A body dropped past the
3
+ // old edge stands only on the larger ground.
4
+ import assert from 'node:assert/strict';
5
+ import RAPIER from '@dimforge/rapier3d-compat';
6
+ import { runWorker } from './ownership-worker.mjs';
7
+ import { loadKit } from './ownership-harness.mjs';
8
+
9
+ const configs = {
10
+ absent: { actors: [] },
11
+ styled: { actors: [], ground: { color: '#336633' } },
12
+ wide: { actors: [], ground: { half: 150 } },
13
+ huge: { actors: [], ground: { half: 1e6 } },
14
+ text: { actors: [], ground: { half: '150' } },
15
+ none: { actors: [], ground: { none: true, half: 150 } },
16
+ };
17
+
18
+ // Where a straight-down ray from 10 m up at (x, 0) meets the ground, or null.
19
+ function groundAt(world, x) {
20
+ const hit = world.castRay(new RAPIER.Ray({ x, y: 10, z: 0 }, { x: 0, y: -1, z: 0 }), 50, true);
21
+ return hit ? Math.round((10 - hit.timeOfImpact) * 1000) / 1000 : null;
22
+ }
23
+
24
+ const which = process.argv[2];
25
+ if (which) {
26
+ const kit = await loadKit(configs[which]);
27
+ const sim = await kit.World.createSimulation();
28
+ // Scene queries see colliders only after a step.
29
+ sim.world.step();
30
+ const shapes = [];
31
+ sim.world.forEachCollider((c) => {
32
+ const h = c.halfExtents();
33
+ shapes.push([h.x, h.y, h.z, c.translation().y]);
34
+ });
35
+ const report = { shapes, at: Object.fromEntries([0, 90, 99, 101, 149, 151, 199, 201].map((x) => [x, groundAt(sim.world, x)])) };
36
+ sim.world.free();
37
+ process.stdout.write(JSON.stringify(report));
38
+ } else {
39
+ const out = {};
40
+ for (const name of Object.keys(configs)) {
41
+ out[name] = JSON.parse(await runWorker(new URL(import.meta.url), [name]));
42
+ }
43
+ const legacy = { shapes: [[100, 0.5, 100, -0.5]], at: { 0: 0, 90: 0, 99: 0, 101: null, 149: null, 151: null, 199: null, 201: null } };
44
+ assert.deepEqual(out.absent, legacy, 'no ground.half keeps the 100 m slab');
45
+ assert.deepEqual(out.styled, legacy, 'a dressed ground without half keeps the 100 m slab');
46
+ assert.deepEqual(out.text, legacy, 'a half that is not a number is ignored');
47
+ assert.deepEqual(out.wide.shapes, [[150, 0.5, 150, -0.5]], 'ground.half sizes the slab');
48
+ assert.equal(out.wide.at[101], 0, 'past the old edge stands on ground');
49
+ assert.equal(out.wide.at[149], 0);
50
+ assert.equal(out.wide.at[151], null, 'past the new edge falls');
51
+ assert.deepEqual(out.huge.shapes, [[200, 0.5, 200, -0.5]], 'half clamps to the world bounds');
52
+ assert.equal(out.huge.at[199], 0);
53
+ assert.equal(out.huge.at[201], null);
54
+ assert.deepEqual(out.none.shapes, [], 'ground.none still has no slab');
55
+ console.log('ground half: absent/dressed/non-number keep the 100 m slab; 150 and clamped 200 extend it; none has none');
56
+ }