castle-web-cli 0.4.238 → 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 (404) 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 +218 -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 +22 -3
  16. package/dist/init.js +24 -2
  17. package/dist/multiplayerDoc.d.ts +1 -1
  18. package/dist/multiplayerDoc.js +9 -0
  19. package/dist/platformDoc.js +4 -2
  20. package/dist/playPagePolicy.d.ts +1 -0
  21. package/dist/playPagePolicy.js +12 -3
  22. package/dist/resetLeaderboards.d.ts +8 -1
  23. package/dist/resetLeaderboards.js +43 -8
  24. package/dist/roomLogs.d.ts +39 -0
  25. package/dist/roomLogs.js +166 -0
  26. package/dist/save-deck.d.ts +32 -2
  27. package/dist/save-deck.js +240 -39
  28. package/kits/base/CLAUDE.md +2 -1
  29. package/kits/base/castle.json +1 -1
  30. package/kits/base/sdk/README.md +240 -8
  31. package/kits/base/sdk/analytics.d.ts +8 -0
  32. package/kits/base/sdk/analytics.js +92 -0
  33. package/kits/base/sdk/castle.d.ts +8 -2
  34. package/kits/base/sdk/castle.js +3 -0
  35. package/kits/base/sdk/commands.d.ts +79 -0
  36. package/kits/base/sdk/commands.js +1 -0
  37. package/kits/base/sdk/debugConsole.d.ts +17 -0
  38. package/kits/base/sdk/debugConsole.js +154 -0
  39. package/kits/base/sdk/experiments.js +24 -1
  40. package/kits/base/sdk/hostRetry.d.ts +7 -0
  41. package/kits/base/sdk/hostRetry.js +57 -0
  42. package/kits/base/sdk/hub.d.ts +20 -2
  43. package/kits/base/sdk/hub.js +99 -13
  44. package/kits/base/sdk/multiplayer.d.ts +2 -0
  45. package/kits/base/sdk/multiplayer.js +198 -26
  46. package/kits/base/sdk/reconnectBudget.d.ts +6 -0
  47. package/kits/base/sdk/reconnectBudget.js +41 -1
  48. package/kits/base/sdk/rooms.d.ts +11 -0
  49. package/kits/base/sdk/rooms.js +22 -0
  50. package/kits/base/sdk/runtime.js +36 -19
  51. package/kits/base/sdk/server/hub.d.ts +19 -0
  52. package/kits/base/sdk/server/hub.js +12 -0
  53. package/kits/base/sdk/server/platformHandle.d.ts +1 -0
  54. package/kits/base/sdk/server/wrapper.d.ts +1 -1
  55. package/kits/base/sdk/server/wrapper.js +26 -1
  56. package/kits/base/sdk/store.d.ts +8 -2
  57. package/kits/base/sdk/store.js +5 -1
  58. package/kits/base/sdk/transport.d.ts +2 -1
  59. package/kits/base/sdk/transport.js +35 -0
  60. package/kits/hub-game/CLAUDE.md +66 -19
  61. package/kits/hub-game/castle.json +4 -4
  62. package/kits/hub-game/code/client/act.js +9 -6
  63. package/kits/hub-game/code/client/actCore.js +26 -6
  64. package/kits/hub-game/code/client/actGateLog.js +36 -0
  65. package/kits/hub-game/code/client/actionOverflow.js +29 -8
  66. package/kits/hub-game/code/client/actionRailSurface.js +186 -0
  67. package/kits/hub-game/code/client/actionRailTree.js +173 -0
  68. package/kits/hub-game/code/client/askSurface.js +85 -0
  69. package/kits/hub-game/code/client/askTree.js +51 -0
  70. package/kits/hub-game/code/client/attention.js +31 -6
  71. package/kits/hub-game/code/client/ballot.js +42 -5
  72. package/kits/hub-game/code/client/ballotSurface.js +115 -0
  73. package/kits/hub-game/code/client/ballotTree.js +180 -0
  74. package/kits/hub-game/code/client/catchingUp.js +19 -0
  75. package/kits/hub-game/code/client/celebrate.js +66 -0
  76. package/kits/hub-game/code/client/chrome.js +474 -53
  77. package/kits/hub-game/code/client/companion.js +93 -23
  78. package/kits/hub-game/code/client/companionDress.js +1 -1
  79. package/kits/hub-game/code/client/cornerSurface.js +106 -0
  80. package/kits/hub-game/code/client/cornerTree.js +83 -0
  81. package/kits/hub-game/code/client/decor.js +20 -11
  82. package/kits/hub-game/code/client/deviceStorage.js +121 -0
  83. package/kits/hub-game/code/client/disguise.js +23 -0
  84. package/kits/hub-game/code/client/disguiseDraw.js +87 -0
  85. package/kits/hub-game/code/client/dockSurface.js +206 -0
  86. package/kits/hub-game/code/client/dockTree.js +232 -0
  87. package/kits/hub-game/code/client/earned.js +29 -0
  88. package/kits/hub-game/code/client/emoteSurface.js +188 -0
  89. package/kits/hub-game/code/client/emoteTree.js +264 -0
  90. package/kits/hub-game/code/client/farAvatars.js +4 -3
  91. package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
  92. package/kits/hub-game/code/client/grab.js +121 -50
  93. package/kits/hub-game/code/client/holdShow.js +19 -0
  94. package/kits/hub-game/code/client/hookLayer.js +96 -12
  95. package/kits/hub-game/code/client/hubControls.js +7 -1
  96. package/kits/hub-game/code/client/hudSurface.js +11 -3
  97. package/kits/hub-game/code/client/hudTree.js +7 -4
  98. package/kits/hub-game/code/client/idle.js +21 -3
  99. package/kits/hub-game/code/client/invites.js +24 -3
  100. package/kits/hub-game/code/client/keys.js +15 -0
  101. package/kits/hub-game/code/client/labelsNear.js +8 -1
  102. package/kits/hub-game/code/client/layoutCache.js +57 -8
  103. package/kits/hub-game/code/client/loadingCover.js +53 -4
  104. package/kits/hub-game/code/client/menuIcons.js +15 -0
  105. package/kits/hub-game/code/client/menuRows.js +8 -2
  106. package/kits/hub-game/code/client/menuSurface.js +102 -0
  107. package/kits/hub-game/code/client/menuTree.js +135 -0
  108. package/kits/hub-game/code/client/modelLook.js +41 -0
  109. package/kits/hub-game/code/client/pickerSurface.js +152 -0
  110. package/kits/hub-game/code/client/pickerTree.js +163 -0
  111. package/kits/hub-game/code/client/pushVisit.js +4 -2
  112. package/kits/hub-game/code/client/quality.js +188 -29
  113. package/kits/hub-game/code/client/qualityEntry.js +10 -1
  114. package/kits/hub-game/code/client/quickChatSurface.js +222 -0
  115. package/kits/hub-game/code/client/quickChatTree.js +201 -0
  116. package/kits/hub-game/code/client/rehello.js +75 -0
  117. package/kits/hub-game/code/client/renderVisibility.js +17 -0
  118. package/kits/hub-game/code/client/replay.js +118 -0
  119. package/kits/hub-game/code/client/role.js +3 -0
  120. package/kits/hub-game/code/client/safeLayout.js +441 -56
  121. package/kits/hub-game/code/client/safeStyle.js +13 -10
  122. package/kits/hub-game/code/client/say.js +2 -0
  123. package/kits/hub-game/code/client/soundSurface.js +77 -0
  124. package/kits/hub-game/code/client/soundTree.js +74 -0
  125. package/kits/hub-game/code/client/soundscape.js +12 -9
  126. package/kits/hub-game/code/client/soundscapeCues.js +1 -1
  127. package/kits/hub-game/code/client/state.js +67 -1
  128. package/kits/hub-game/code/client/stuckSurface.js +76 -0
  129. package/kits/hub-game/code/client/stuckTree.js +67 -0
  130. package/kits/hub-game/code/client/talk.js +42 -12
  131. package/kits/hub-game/code/client/talkTree.js +4 -2
  132. package/kits/hub-game/code/client/textAskSurface.js +147 -0
  133. package/kits/hub-game/code/client/textAskTree.js +67 -0
  134. package/kits/hub-game/code/client/tiers.js +252 -27
  135. package/kits/hub-game/code/client/together.js +4 -1
  136. package/kits/hub-game/code/client/uiDom.js +86 -8
  137. package/kits/hub-game/code/client/uiTree.js +33 -4
  138. package/kits/hub-game/code/client/vehicle.js +75 -52
  139. package/kits/hub-game/code/client/weakestTier.js +75 -31
  140. package/kits/hub-game/code/client/wear.js +159 -5
  141. package/kits/hub-game/code/client/worldLabels.js +215 -26
  142. package/kits/hub-game/code/companionSpec.js +4 -2
  143. package/kits/hub-game/code/server/act.js +3 -0
  144. package/kits/hub-game/code/server/actGate.js +83 -0
  145. package/kits/hub-game/code/server/actions.js +71 -15
  146. package/kits/hub-game/code/server/actors.js +20 -5
  147. package/kits/hub-game/code/server/analytics.js +40 -15
  148. package/kits/hub-game/code/server/ask.js +39 -3
  149. package/kits/hub-game/code/server/ballot.js +167 -4
  150. package/kits/hub-game/code/server/celebrate.js +64 -0
  151. package/kits/hub-game/code/server/companion.js +17 -2
  152. package/kits/hub-game/code/server/decor.js +11 -2
  153. package/kits/hub-game/code/server/disguise.js +63 -0
  154. package/kits/hub-game/code/server/doorAnalytics.js +2 -5
  155. package/kits/hub-game/code/server/earned.js +6 -2
  156. package/kits/hub-game/code/server/friendBests.js +13 -4
  157. package/kits/hub-game/code/server/friendsAmong.js +67 -8
  158. package/kits/hub-game/code/server/grab.js +12 -2
  159. package/kits/hub-game/code/server/heldOffers.js +142 -0
  160. package/kits/hub-game/code/server/holdShow.js +98 -0
  161. package/kits/hub-game/code/server/hub.js +854 -45
  162. package/kits/hub-game/code/server/idle.js +110 -9
  163. package/kits/hub-game/code/server/index.js +9 -0
  164. package/kits/hub-game/code/server/labels.js +13 -3
  165. package/kits/hub-game/code/server/loadAbandon.js +2 -5
  166. package/kits/hub-game/code/server/manifest.js +94 -6
  167. package/kits/hub-game/code/server/menu.js +26 -3
  168. package/kits/hub-game/code/server/npcs.js +55 -9
  169. package/kits/hub-game/code/server/observe.js +67 -6
  170. package/kits/hub-game/code/server/players.js +8 -1
  171. package/kits/hub-game/code/server/replay.js +135 -0
  172. package/kits/hub-game/code/server/storageLimit.js +4 -1
  173. package/kits/hub-game/code/server/townDay.js +74 -0
  174. package/kits/hub-game/code/server/trackQueue.js +29 -0
  175. package/kits/hub-game/code/server/vehicle.js +3 -0
  176. package/kits/hub-game/code/server/vis.js +26 -4
  177. package/kits/hub-game/code/server/wallet.js +677 -0
  178. package/kits/hub-game/code/server/wear.js +13 -3
  179. package/kits/hub-game/code/server/writerLease.js +191 -0
  180. package/kits/hub-game/code/shared/act.js +1 -1
  181. package/kits/hub-game/code/shared/expression.js +6 -0
  182. package/kits/hub-game/code/shared/replay.js +37 -0
  183. package/kits/hub-game/code/systems/hub.js +437 -57
  184. package/kits/hub-game/docs/analytics.md +20 -3
  185. package/kits/hub-game/docs/contract.md +942 -99
  186. package/kits/hub-game/docs/home-pieces.md +5 -6
  187. package/kits/hub-game/docs/observed-progress.md +49 -1
  188. package/kits/hub-game/docs/vehicle-preset.md +23 -0
  189. package/kits/hub-game/index.html +1 -0
  190. package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
  191. package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
  192. package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
  193. package/kits/hub-game/models/hats/cap.pxmodel +3 -3
  194. package/kits/hub-game/models/hats/captain.pxmodel +3 -3
  195. package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
  196. package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
  197. package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
  198. package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
  199. package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
  200. package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
  201. package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
  202. package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
  203. package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
  204. package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
  205. package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
  206. package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
  207. package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
  208. package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
  209. package/kits/hub-game/models/hats/straw.pxmodel +3 -3
  210. package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
  211. package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
  212. package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
  213. package/kits/hub-game/models/hats/witch.pxmodel +3 -3
  214. package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
  215. package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
  216. package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
  217. package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
  218. package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
  219. package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
  220. package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
  221. package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
  222. package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
  223. package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
  224. package/kits/hub-game/package-lock.json +3 -3
  225. package/kits/hub-game/package.json +4 -3
  226. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
  227. package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
  228. package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
  229. package/kits/hub-game/scripts/gen-hats.mjs +1 -1
  230. package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
  231. package/kits/hub-game/scripts/pack.mjs +89 -23
  232. package/kits/hub-game/scripts/test-act-client.mjs +5 -0
  233. package/kits/hub-game/scripts/test-act-core.mjs +32 -0
  234. package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
  235. package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
  236. package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
  237. package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
  238. package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
  239. package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
  240. package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
  241. package/kits/hub-game/scripts/test-actions.mjs +24 -0
  242. package/kits/hub-game/scripts/test-actors.mjs +19 -0
  243. package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
  244. package/kits/hub-game/scripts/test-analytics.mjs +80 -1
  245. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
  246. package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
  247. package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
  248. package/kits/hub-game/scripts/test-attention.mjs +43 -1
  249. package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
  250. package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
  251. package/kits/hub-game/scripts/test-ballot.mjs +420 -3
  252. package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
  253. package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
  254. package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
  255. package/kits/hub-game/scripts/test-chat.mjs +73 -0
  256. package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
  257. package/kits/hub-game/scripts/test-companion.mjs +110 -3
  258. package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
  259. package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
  260. package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
  261. package/kits/hub-game/scripts/test-decor.mjs +27 -0
  262. package/kits/hub-game/scripts/test-device-class.mjs +4 -1
  263. package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
  264. package/kits/hub-game/scripts/test-disguise.mjs +176 -0
  265. package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
  266. package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
  267. package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
  268. package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
  269. package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
  270. package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
  271. package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
  272. package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
  273. package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
  274. package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
  275. package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
  276. package/kits/hub-game/scripts/test-grab.mjs +10 -1
  277. package/kits/hub-game/scripts/test-hats.mjs +28 -0
  278. package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
  279. package/kits/hub-game/scripts/test-high-only.mjs +3 -3
  280. package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
  281. package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
  282. package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
  283. package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
  284. package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
  285. package/kits/hub-game/scripts/test-hub-ops.mjs +147 -0
  286. package/kits/hub-game/scripts/test-hub-trip.mjs +260 -5
  287. package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
  288. package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
  289. package/kits/hub-game/scripts/test-idle.mjs +160 -0
  290. package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
  291. package/kits/hub-game/scripts/test-labels.mjs +11 -0
  292. package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
  293. package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
  294. package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
  295. package/kits/hub-game/scripts/test-manifest.mjs +27 -0
  296. package/kits/hub-game/scripts/test-menu-client.mjs +55 -6
  297. package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
  298. package/kits/hub-game/scripts/test-npcs.mjs +128 -0
  299. package/kits/hub-game/scripts/test-observed.mjs +171 -3
  300. package/kits/hub-game/scripts/test-pack.mjs +166 -0
  301. package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
  302. package/kits/hub-game/scripts/test-placeat-server.mjs +395 -0
  303. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  304. package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
  305. package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
  306. package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
  307. package/kits/hub-game/scripts/test-quality.mjs +312 -9
  308. package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
  309. package/kits/hub-game/scripts/test-rehello.mjs +237 -0
  310. package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
  311. package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
  312. package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
  313. package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
  314. package/kits/hub-game/scripts/test-replay.mjs +178 -0
  315. package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
  316. package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
  317. package/kits/hub-game/scripts/test-resync.mjs +13 -0
  318. package/kits/hub-game/scripts/test-role-client.mjs +10 -3
  319. package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
  320. package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
  321. package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
  322. package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
  323. package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
  324. package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
  325. package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
  326. package/kits/hub-game/scripts/test-stuck.mjs +31 -0
  327. package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
  328. package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
  329. package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
  330. package/kits/hub-game/scripts/test-tiers.mjs +453 -3
  331. package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
  332. package/kits/hub-game/scripts/test-together.mjs +11 -0
  333. package/kits/hub-game/scripts/test-town-day.mjs +90 -0
  334. package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
  335. package/kits/hub-game/scripts/test-try-on.mjs +39 -0
  336. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
  337. package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
  338. package/kits/hub-game/scripts/test-vehicle-client.mjs +77 -1
  339. package/kits/hub-game/scripts/test-vis.mjs +145 -0
  340. package/kits/hub-game/scripts/test-wallet.mjs +650 -0
  341. package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
  342. package/kits/hub-game/scripts/test-world-labels.mjs +380 -0
  343. package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
  344. package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
  345. package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
  346. package/kits/hub-game/tools/hubScene/export.mjs +6 -5
  347. package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
  348. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +48 -2
  349. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +21 -3
  350. package/kits/multiplayer-3d/castle.json +5 -5
  351. package/kits/multiplayer-3d/code/client/resumeGate.js +49 -2
  352. package/kits/multiplayer-3d/code/server/ownership.js +25 -6
  353. package/kits/multiplayer-3d/code/server/world.js +19 -4
  354. package/kits/multiplayer-3d/code/systems/multiplayer.js +67 -11
  355. package/kits/multiplayer-3d/package-lock.json +1 -1
  356. package/kits/multiplayer-3d/package.json +2 -1
  357. package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
  358. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
  359. package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
  360. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +191 -5
  361. package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
  362. package/kits/physics-2d/castle.json +2 -2
  363. package/kits/physics-2d/engine/scene.js +10 -2
  364. package/kits/physics-3d/CLAUDE.md +14 -0
  365. package/kits/physics-3d/behaviors/Player.jsx +39 -3
  366. package/kits/physics-3d/castle.json +3 -3
  367. package/kits/physics-3d/docs/engine-model-cache.md +109 -0
  368. package/kits/physics-3d/docs/engine-player.md +76 -0
  369. package/kits/physics-3d/docs/engine-skip-work.md +16 -0
  370. package/kits/physics-3d/docs/pxmodel-format.md +5 -1
  371. package/kits/physics-3d/engine3d/gait.js +16 -8
  372. package/kits/physics-3d/engine3d/groundsize.js +23 -0
  373. package/kits/physics-3d/engine3d/kithooks.js +50 -0
  374. package/kits/physics-3d/engine3d/look.js +110 -17
  375. package/kits/physics-3d/engine3d/lookbake.js +19 -1
  376. package/kits/physics-3d/engine3d/materialpresets.js +3 -2
  377. package/kits/physics-3d/engine3d/modelcache.js +280 -0
  378. package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
  379. package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
  380. package/kits/physics-3d/engine3d/modelrefs.js +13 -0
  381. package/kits/physics-3d/engine3d/optimize.js +20 -9
  382. package/kits/physics-3d/engine3d/playerRun.js +26 -1
  383. package/kits/physics-3d/engine3d/pxmodel.js +7 -3
  384. package/kits/physics-3d/engine3d/templatecache.js +722 -0
  385. package/kits/physics-3d/engine3d/world3d.js +211 -17
  386. package/kits/physics-3d/package-lock.json +1 -1
  387. package/kits/physics-3d/package.json +2 -1
  388. package/kits/physics-3d/play/behaviors/Player.js +43 -3
  389. package/kits/physics-3d/scripts/render.mjs +56 -8
  390. package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
  391. package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
  392. package/kits/physics-3d/scripts/test-gait.mjs +53 -9
  393. package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
  394. package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
  395. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
  396. package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
  397. package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
  398. package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
  399. package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
  400. package/kits/physics-3d/systems/physics3d.js +51 -2
  401. package/kits/real-time/castle.json +2 -2
  402. package/kits/real-time/code/client/connection.js +3 -0
  403. package/package.json +2 -2
  404. package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
@@ -1,4 +1,5 @@
1
1
  import { animationDt } from './animationBudget';
2
+ import { modelCacheVisitReady } from './modelcachegate';
2
3
  // The three.js side of the kit: renderer, lighting rig, ground, and per-actor
3
4
  // nodes built from Shape components. Values follow the vase reference rig --
4
5
  // hemisphere + ambient + one tuned shadow-casting directional, PCFSoft shadows,
@@ -30,12 +31,14 @@ import { fitOrbitLens, giveBackOrbitLens } from './orbitlens.js';
30
31
  import { fitViewRange, giveBackViewRange } from './viewrange.js';
31
32
  import { renderWithSky, leaveSky, skyHorizonColor } from './sky.js';
32
33
  import { holdShadowFade, renderShadowFaded, dropShadowFade } from './shadowfade.js';
34
+ import { groundHalf } from './groundsize.js';
33
35
  import { readLoadKey, actorMayWait, makeModelLoad, loadSummary, nearModelKeys,
34
36
  consumerRegistryVersion, rememberModelConsumer, modelConsumerChanged } from './squarefirst.js';
35
37
  export { ensureActorModel, prepareModelConsumers } from './modelready.js';
36
38
  import {
37
39
  takeModel,
38
40
  releaseModel,
41
+ disposeParkedModels,
39
42
  copyModel,
40
43
  isStaticModel,
41
44
  dropEmptyGroups,
@@ -140,6 +143,10 @@ export function makeWorld3D(canvas, options = {}) {
140
143
  debugLines,
141
144
  ground,
142
145
  grid,
146
+ // A kit that sleeps actors asks the world for these rather than importing
147
+ // them, so the same kit on an older engine finds none and skips prewarm.
148
+ prewarmSleepingModels(runtime, options) { return prewarmSleepingModels(this, runtime, options); },
149
+ needsSleepingModelPrewarm(runtime) { return needsSleepingModelPrewarm(this, runtime); },
143
150
  };
144
151
  }
145
152
 
@@ -216,8 +223,9 @@ function dressGround(world, setting, sprites) {
216
223
  if (sig === world.groundSig) return;
217
224
  // Also callable outside an actor pass: the old material runs listeners.
218
225
  outsideCall(world, () => {
226
+ const size = sizeGround(world, setting);
219
227
  const tile = setting?.tile > 0 ? setting.tile : 2;
220
- const repeat = [GROUND_SIZE / tile, GROUND_SIZE / tile];
228
+ const repeat = [size / tile, size / tile];
221
229
  const texture = setting?.art ? resolveArtTexture(setting.art, sprites, repeat) : null;
222
230
  world.groundSig = sig;
223
231
  const material = new THREE.MeshStandardMaterial({
@@ -236,6 +244,22 @@ function dressGround(world, setting, sprites) {
236
244
  });
237
245
  }
238
246
 
247
+ // Draw the ground plane, and its line grid, `ground.half` each way from the
248
+ // origin; returns its width. A scene without the key keeps the 60 m plane
249
+ // `addGround` made, untouched.
250
+ function sizeGround(world, setting) {
251
+ const half = groundHalf(setting);
252
+ if (half !== (world.groundHalf ?? null)) {
253
+ const size = half === null ? GROUND_SIZE : half * 2;
254
+ world.groundHalf = half;
255
+ world.ground.geometry.dispose();
256
+ world.ground.geometry = new THREE.PlaneGeometry(size, size);
257
+ world.grid.geometry?.dispose();
258
+ world.grid.geometry = new THREE.GridHelper(size, Math.round(size), 0x505050, 0x505050).geometry;
259
+ }
260
+ return half === null ? GROUND_SIZE : half * 2;
261
+ }
262
+
239
263
  // The signature suffix for an actor's Model component: the model file's text
240
264
  // plus the readiness/identity of any art it references, and the same for every
241
265
  // model it references.
@@ -302,7 +326,7 @@ function attachEmptyActor(world, id, entry) {
302
326
  // for a static model in the player, a place among that model's instances.
303
327
  function addModelRig(world, entry, model, modelComponent, key, { sprites, files, drops, actor, wait }) {
304
328
  const file = modelComponent.file;
305
- if (drops === true) key = `${key}|dropEmptyParts`;
329
+ key = builtAs(drops, key);
306
330
  entry.modelKey = key;
307
331
  const load = world.modelLoadPass;
308
332
  if (!wait && load && world.modelLoad === load && !load.restMarked && !world.instanceModels &&
@@ -323,7 +347,11 @@ function addModelRig(world, entry, model, modelComponent, key, { sprites, files,
323
347
  return;
324
348
  }
325
349
  const build = () => buildModelNode(model, sprites, files, file, [file], { optimize: true });
326
- const template = takeModel(world.models, key, world.bakesLookLater ? () => buildBakingLater(world, key, build) : build);
350
+ const buildAsScene = world.bakesLookLater ? () => buildBakingLater(world, key, build) : build;
351
+ const template = takeModel(world.models, key, world.modelCache && !world.staticActorsOff
352
+ ? () => world.modelCache.template(key, file, model, sprites, files, drops, build,
353
+ world.bakesLookLater ? (make, restore) => buildBakingLater(world, key, make, restore) : null)
354
+ : buildAsScene);
327
355
  if (wait) {
328
356
  // Building may call consumer code. A cancelled wait never owns a user.
329
357
  if (entry.modelWait !== wait || world.modelLoad !== wait.load || world.disposed) {
@@ -653,15 +681,16 @@ function builtAs(drops, sig) {
653
681
 
654
682
  // `build`, for a scene that asked for its models' look to be baked after they
655
683
  // are drawn (lookbake.js): the baking is queued on the world as this model's.
656
- function buildBakingLater(world, key, build) {
684
+ function buildBakingLater(world, key, build, restoreTemplate = false) {
657
685
  if (world.disposed === true) return build();
658
686
  world.lookBake ??= makeLookBake();
659
- return bakingLater(world.lookBake, key, build);
687
+ return bakingLater(world.lookBake, key, build, restoreTemplate);
660
688
  }
661
689
 
662
690
  // Removes an actor's node. A shared model build is given back rather than
663
691
  // disposed, since other actors may still draw it.
664
- function releaseActorNode(world, entry) {
692
+ function releaseActorNode(world, entry, park = false) {
693
+ if (world.disposed) park = false;
665
694
  const waiting = entry.modelWait;
666
695
  if (waiting) forgetModelWait(waiting);
667
696
  if (world.frozenStatics) {
@@ -684,7 +713,153 @@ function releaseActorNode(world, entry) {
684
713
  world.instances.delete(entry.modelKey);
685
714
  }
686
715
  }
687
- releaseModel(world.models, entry.modelKey, disposeNode);
716
+ releaseModel(world.models, entry.modelKey, disposeNode, park);
717
+ if (park) world.hasParkedModels = true;
718
+ }
719
+
720
+ function actorIsSleeping(runtime, actor) {
721
+ return actor && runtime.getActor?.(actor.id) === actor && runtime.isActorSleeping?.(actor) === true;
722
+ }
723
+
724
+ function hasSleepingActors(runtime) {
725
+ if (runtime.sleepingActorCount !== undefined) return runtime.sleepingActorCount > 0;
726
+ // Older imported runtimes have no revision/count. They can still park safely.
727
+ if (!runtime.isActorSleeping) return false;
728
+ for (const actor of runtime.actors?.values() ?? []) if (actorIsSleeping(runtime, actor)) return true;
729
+ return false;
730
+ }
731
+
732
+ function clearSleepingModels(world) {
733
+ world.sleepingModelPrune = undefined;
734
+ world.sleepingModelPrewarm = undefined;
735
+ if (!world.hasParkedModels) return;
736
+ world.hasParkedModels = false;
737
+ disposeParkedModels(world.models, disposeNode);
738
+ }
739
+
740
+ function prewarmStillCurrent(world, runtime, state) {
741
+ if (!state || state.runtime !== runtime || state.data !== runtime.data ||
742
+ state.sleepVersion !== runtime.sleepVersion || state.drops !== (runtime.dropsEmptyParts === true) ||
743
+ state.later !== (runtime.bakesLookLater === true) ||
744
+ !readsTheSame(state, runtime.sprites, runtime.files)) return false;
745
+ for (let i = 0; i < state.actors.length; i++) {
746
+ const item = state.actors[i];
747
+ if (!actorIsSleeping(runtime, item.actor) || item.file !== item.actor.components.Model?.file ||
748
+ (state.done && item.key && !world.models.has(item.key))) return false;
749
+ }
750
+ if (runtime.sleepVersion === undefined) {
751
+ // Older runtimes lack a revision. Existing identities above plus a count
752
+ // catch both replacements and new sleepers without recreating the queue.
753
+ let count = 0;
754
+ for (const actor of runtime.actors.values()) if (actorIsSleeping(runtime, actor)) count++;
755
+ if (count !== state.actors.length) return false;
756
+ }
757
+ return true;
758
+ }
759
+
760
+ // Cheap completion check for frame policies: no new signatures, arrays or
761
+ // templates while a completed sleep set and its referenced assets stay put.
762
+ export function needsSleepingModelPrewarm(world, runtime) {
763
+ if (!world || world.disposed || world.modelLoadClearing || !hasSleepingActors(runtime)) return false;
764
+ const load = world.modelLoad;
765
+ if (load && (load.runtime !== runtime || load.data !== runtime.data || !load.restMarked)) return false;
766
+ if (runtime.data?.engine?.load && !load && readLoadKey(runtime.data)) return false;
767
+ const state = world.sleepingModelPrewarm;
768
+ return !prewarmStillCurrent(world, runtime, state) || !state.done;
769
+ }
770
+
771
+ // A woken actor acquires its parked template during sync, not when its sleep
772
+ // flag changes. Prune only after that opportunity, using a current sleep set.
773
+ function pruneSleepingModels(world, runtime) {
774
+ const pending = world.sleepingModelPrune;
775
+ if (!pending?.size) return;
776
+ const state = world.sleepingModelPrewarm;
777
+ // Changes since the queue rebuild need a fresh key set. Keep the candidates
778
+ // for the next prewarm + sync rather than risk disposing a sleeper's build.
779
+ if (!prewarmStillCurrent(world, runtime, state)) return;
780
+ world.sleepingModelPrune = undefined;
781
+ for (const key of pending) {
782
+ const entry = world.models.get(key);
783
+ if (!entry || entry.users !== 0 || state.keys.has(key)) continue;
784
+ world.models.delete(key);
785
+ disposeNode(entry.template);
786
+ }
787
+ }
788
+
789
+ const prewarmNow = () => performance.now();
790
+
791
+ // Build only shared templates, with no actor node or instance acquired. The
792
+ // key, empty-part variant and deferred look baking match addModelRig exactly.
793
+ // Initial engine.load work owns the build budget until load:rest-built.
794
+ export function prewarmSleepingModels(world, runtime, { budgetMs = 4, now = prewarmNow } = {}) {
795
+ if ((world.modelCache || runtime.data?.engine?.modelCache) && !modelCacheVisitReady(world, runtime)) return 0;
796
+ if (!needsSleepingModelPrewarm(world, runtime)) return 0;
797
+ const started = now();
798
+ let state = world.sleepingModelPrewarm;
799
+ if (!prewarmStillCurrent(world, runtime, state)) {
800
+ const actors = [];
801
+ const origin = world.camera?.position;
802
+ const drops = runtime.dropsEmptyParts === true;
803
+ const fileReads = [], artReads = [];
804
+ const files = recordReads(runtime.files, fileReads);
805
+ const sprites = recordReads(runtime.sprites, artReads);
806
+ const keys = new Set(), byFile = new Map();
807
+ for (const actor of runtime.actors.values()) {
808
+ if (!actorIsSleeping(runtime, actor)) continue;
809
+ const file = actor.components.Model?.file;
810
+ if (file && !byFile.has(file)) {
811
+ // A template's signature depends on the file, not its placement.
812
+ // Read each shared model once, including sleepers beyond this slice.
813
+ byFile.set(file, parseModelCached(files[file])
814
+ ? builtAs(drops, `${file}|${actorModelSig(actor, sprites, files)}`) : null);
815
+ }
816
+ const key = byFile.get(file) ?? null;
817
+ if (key) keys.add(key);
818
+ const t = actor.components.Transform;
819
+ actors.push({ actor, file, key,
820
+ distance: t && origin ? (t.x - origin.x) ** 2 + (t.z - origin.z) ** 2 : 0 });
821
+ }
822
+ actors.sort((a, b) => a.distance - b.distance);
823
+ state = world.sleepingModelPrewarm = { runtime, data: runtime.data,
824
+ sleepVersion: runtime.sleepVersion, drops,
825
+ later: runtime.bakesLookLater === true, look: lookIsEnabled(),
826
+ actors, keys, index: 0, done: false, fileReads, artReads: withReadiness(artReads) };
827
+ // Record obsolete parked keys, but give newly woken actors a renderer
828
+ // sync to acquire their templates before disposing any unused candidates.
829
+ for (const [key, entry] of world.models) {
830
+ if (entry.users !== 0 || keys.has(key)) continue;
831
+ (world.sleepingModelPrune ??= new Set()).add(key);
832
+ }
833
+ }
834
+ const fileReads = state.fileReads;
835
+ const artReads = [];
836
+ const files = recordReads(runtime.files, fileReads);
837
+ const sprites = recordReads(runtime.sprites, artReads);
838
+ let built = 0;
839
+ while (state.index < state.actors.length) {
840
+ const item = state.actors[state.index++];
841
+ const { actor, file, key } = item;
842
+ if (key && actorIsSleeping(runtime, actor)) {
843
+ const model = parseModelCached(files?.[file]);
844
+ if (model) {
845
+ if (!world.models.has(key)) {
846
+ const build = () => buildModelNode(model, sprites, files, file, [file], { optimize: true });
847
+ const template = world.modelCache && !world.staticActorsOff
848
+ ? world.modelCache.template(key, file, model, sprites, files, state.drops, build,
849
+ state.later ? (make, restore) => buildBakingLater(world, key, make, restore) : null, state.later)
850
+ : state.later ? buildBakingLater(world, key, build) : build();
851
+ if (state.drops) withoutEmptyParts(template, model);
852
+ world.models.set(key, { template, users: 0 });
853
+ world.hasParkedModels = true;
854
+ built++;
855
+ }
856
+ }
857
+ }
858
+ if (now() - started >= budgetMs) break;
859
+ }
860
+ state.artReads.push(...withReadiness(artReads));
861
+ state.done = state.index === state.actors.length;
862
+ return built;
688
863
  }
689
864
 
690
865
  const DEG = Math.PI / 180;
@@ -695,6 +870,7 @@ const DEG = Math.PI / 180;
695
870
  // degrees.
696
871
  // Worlds that never asked do not enter any empty-node lifecycle helpers.
697
872
  export function syncActors(world, runtime, sprites, dt = 0) {
873
+ if ((world.modelCache || runtime.data?.engine?.modelCache) && !modelCacheVisitReady(world, runtime)) return;
698
874
  if (world.modelLoadClearing) return;
699
875
  // The empty-node lifecycle can deliberately reject a reentrant sync. It
700
876
  // must not become the load queue's first completed actor pass either.
@@ -727,7 +903,13 @@ export function syncActors(world, runtime, sprites, dt = 0) {
727
903
  }
728
904
 
729
905
  function syncActorPass(world, runtime, sprites, dt) {
906
+ let synced = false;
730
907
  try {
908
+ if (world.sleepingModelRuntime !== runtime || world.sleepingModelData !== runtime.data) {
909
+ clearSleepingModels(world);
910
+ world.sleepingModelRuntime = runtime;
911
+ world.sleepingModelData = runtime.data;
912
+ }
731
913
  if (world.frozenStatics && (world.frozenStatics.owner !== runtime.frozenActors || world.disposed || world.staticActorsOff || world.instanceModels)) {
732
914
  world.frozenStatics.dispose();
733
915
  delete world.frozenStatics;
@@ -736,7 +918,7 @@ function syncActorPass(world, runtime, sprites, dt) {
736
918
  const state = world.emptyNodes;
737
919
  if (world.disposed || world.emptyNodesBlocked || (world.emptyPass && state !== world.emptyPass)) return;
738
920
  if (state && state.runtime === runtime) {
739
- syncActorsWithEmptyNodes(world, runtime, sprites, dt, state);
921
+ synced = syncActorsWithEmptyNodes(world, runtime, sprites, dt, state) === true;
740
922
  return;
741
923
  }
742
924
  }
@@ -745,6 +927,7 @@ function syncActorPass(world, runtime, sprites, dt) {
745
927
  // seen in and out by the world's keeper (`syncActorsKept`, below).
746
928
  if (world.stillKeeper || runtime.keepsStaticActors === true) {
747
929
  syncActorsKept(world, runtime, sprites, dt);
930
+ synced = true;
748
931
  return;
749
932
  }
750
933
  // Every other pass is counted while it runs, and that is all: nothing on a
@@ -754,11 +937,15 @@ function syncActorPass(world, runtime, sprites, dt) {
754
937
  world.unkept = (world.unkept ?? 0) + 1;
755
938
  try {
756
939
  syncActorsAsEver(world, runtime, sprites, dt);
940
+ synced = true;
757
941
  } finally {
758
942
  world.unkept -= 1;
759
943
  }
760
944
  } catch (error) {
761
945
  if (error !== EMPTY_PASS_ABORTED) throw error;
946
+ } finally {
947
+ if (world.hasParkedModels && !hasSleepingActors(runtime)) clearSleepingModels(world);
948
+ else if (synced && !world.syncDepth && !world.unkept) pruneSleepingModels(world, runtime);
762
949
  }
763
950
  }
764
951
 
@@ -778,6 +965,7 @@ function syncActorsWithEmptyNodes(world, runtime, sprites, dt, state) {
778
965
  try { syncActorsAsEver(world, runtime, sprites, dt, placeEmptyActor); }
779
966
  finally { world.unkept -= 1; }
780
967
  }
968
+ return true;
781
969
  } catch (error) {
782
970
  if (error !== EMPTY_PASS_ABORTED) throw error;
783
971
  } finally {
@@ -837,7 +1025,7 @@ function syncActorsAsEver(world, runtime, sprites, dt, place = placeActor) {
837
1025
  }
838
1026
  for (const [id, entry] of world.nodes) {
839
1027
  if (seen.has(id)) continue;
840
- releaseActorNode(world, entry);
1028
+ releaseActorNode(world, entry, actorIsSleeping(runtime, entry.actor));
841
1029
  if (world.emptyPass) checkEmptyPass(world);
842
1030
  world.nodes.delete(id);
843
1031
  }
@@ -857,6 +1045,7 @@ function syncActorsAsEver(world, runtime, sprites, dt, place = placeActor) {
857
1045
  // node only where its actor's signature still matches. A parked scene the
858
1046
  // runtime no longer names is released.
859
1047
  function swapSceneNodes(world, path, resident) {
1048
+ clearSleepingModels(world);
860
1049
  const keep = resident instanceof Set ? resident : new Set();
861
1050
  if (world.scenePath !== undefined && keep.has(world.scenePath) && world.scenePath !== path) {
862
1051
  const parked = new Map();
@@ -1058,6 +1247,7 @@ export function disposeWorld(world) {
1058
1247
  // such a sync writes nothing down; what was written down before goes now,
1059
1248
  // and again after the listeners have run, whether or not one throws.
1060
1249
  world.disposed = true;
1250
+ if (world.modelCache) { world.modelCache.close(); delete world.modelCache; }
1061
1251
  if (world.frozenStatics) {
1062
1252
  world.frozenStatics.dispose();
1063
1253
  delete world.frozenStatics;
@@ -1114,6 +1304,8 @@ function disposeNodes(world) {
1114
1304
  for (const entry of parked.values()) releaseActorNode(world, entry);
1115
1305
  }
1116
1306
  world.parked.clear();
1307
+ world.sleepingModelRuntime = world.sleepingModelData = undefined;
1308
+ clearSleepingModels(world);
1117
1309
  world.renderer.dispose();
1118
1310
  } finally {
1119
1311
  forgetEverything(world);
@@ -1278,7 +1470,7 @@ function skippingPass(world, runtime, sprites, dt, started, drops, pass, place =
1278
1470
  }
1279
1471
  // While the pass was alone every actor seen has its node and no node was
1280
1472
  // released, so as many nodes as actors seen means no node has lost its actor.
1281
- if (world.generation !== started || seen.size !== world.nodes.size) releaseUnseen(world, seen);
1473
+ if (world.generation !== started || seen.size !== world.nodes.size) releaseUnseen(world, seen, runtime);
1282
1474
  if (world.instances.size > 0) {
1283
1475
  leavingTheEngine(world);
1284
1476
  aimInstances(world.camera);
@@ -1319,6 +1511,7 @@ function placeActor(world, actor, t, sprites, files, started, drops) {
1319
1511
  const alone = world.generation === started;
1320
1512
  const entry = started === undefined ? ensureActorNode(world, actor, sprites, files, drops)
1321
1513
  : alone ? nodeFor(world, actor, sprites, files, drops) : nodeAsMain(world, actor, sprites, files, drops);
1514
+ entry.actor = actor;
1322
1515
  const node = entry.node;
1323
1516
  node.position.set(t.x, t.y, t.z);
1324
1517
  const quat = actor.runtime?.quat;
@@ -1337,6 +1530,7 @@ function placeEmptyActor(world, actor, transform, sprites, files, started, drops
1337
1530
  const found = started === undefined ? ensureActorNode(world, actor, sprites, files, drops)
1338
1531
  : world.generation === started ? nodeFor(world, actor, sprites, files, drops)
1339
1532
  : nodeAsMain(world, actor, sprites, files, drops);
1533
+ found.actor = actor;
1340
1534
  checkEmptyPass(world);
1341
1535
  putEmptyActor(found.node, transform, actor.runtime?.quat,
1342
1536
  world.generation === started ? snapshotOf(world, found) : null);
@@ -1363,20 +1557,20 @@ function putEmptyActor(node, t, quat, snapshot = null) {
1363
1557
  if (detached && (moved || !Object.is(q.x, x) || !Object.is(q.y, y) || !Object.is(q.z, z) || !Object.is(q.w, w))) updateEmptyNode(node);
1364
1558
  }
1365
1559
 
1366
- function releaseUnseen(world, seen) {
1560
+ function releaseUnseen(world, seen, runtime) {
1367
1561
  for (const [id, entry] of world.nodes) {
1368
1562
  if (seen.has(id)) continue;
1369
- releaseNode(world, entry);
1563
+ releaseNode(world, entry, actorIsSleeping(runtime, entry.actor));
1370
1564
  if (world.emptyPass) checkEmptyPass(world);
1371
1565
  world.nodes.delete(id);
1372
1566
  }
1373
1567
  }
1374
1568
 
1375
1569
  // `releaseActorNode`, from a skipping pass.
1376
- function releaseNode(world, entry) {
1570
+ function releaseNode(world, entry, park = false) {
1377
1571
  leavingTheEngine(world);
1378
1572
  entry.node.computedFrom = null;
1379
- releaseActorNode(world, entry);
1573
+ releaseActorNode(world, entry, park);
1380
1574
  }
1381
1575
 
1382
1576
  // The signature suffix for a Model component's file: `actorModelSig`'s, for an
@@ -1786,7 +1980,7 @@ function syncFrozenActors(world, runtime, sprites, dt, place) {
1786
1980
  if (runtime.getActor(actor.id) !== actor || runtime.isActorSleeping(actor) || !t) {
1787
1981
  if (runtime.getActor(actor.id) && runtime.getActor(actor.id) !== actor) { state.forget(actor); continue; }
1788
1982
  const entry = world.nodes.get(actor.id);
1789
- if (entry) { releaseNode(world, entry); world.nodes.delete(actor.id); }
1983
+ if (entry) { releaseNode(world, entry, actorIsSleeping(runtime, actor)); world.nodes.delete(actor.id); }
1790
1984
  state.forget(actor);
1791
1985
  continue;
1792
1986
  }
@@ -1809,7 +2003,7 @@ function syncFrozenActors(world, runtime, sprites, dt, place) {
1809
2003
  // from another scene. Reconcile that baseline once, as the full pass does.
1810
2004
  if (state.reconcileNodes) {
1811
2005
  const seen = new Set(runtime.getActors().filter(actor => actor.components.Transform).map(actor => actor.id));
1812
- releaseUnseen(world, seen);
2006
+ releaseUnseen(world, seen, runtime);
1813
2007
  if (world.frozenStatics !== state) return;
1814
2008
  state.reconcileNodes = false;
1815
2009
  }
@@ -1958,7 +2152,7 @@ function settledPass(world, runtime, sprites, dt, started, drops, place) {
1958
2152
  if (world.generation !== started || seen.size + skipped !== world.nodes.size) {
1959
2153
  // A still actor passed over is still the runtime's, and keeps its node.
1960
2154
  for (const actor of still) seen.add(actor.id);
1961
- releaseUnseen(world, seen);
2155
+ releaseUnseen(world, seen, runtime);
1962
2156
  }
1963
2157
  if (world.instances.size > 0) {
1964
2158
  leavingTheEngine(world);
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "../../sdk": {
37
37
  "name": "castle-web-sdk",
38
- "version": "0.4.31",
38
+ "version": "0.4.54",
39
39
  "dev": true,
40
40
  "devDependencies": {
41
41
  "eslint": "^9.0.0",
@@ -5,7 +5,8 @@
5
5
  "scripts": {
6
6
  "restart": "castle-web restart .",
7
7
  "screenshot": "castle-web screenshot .",
8
- "check": "eslint . && jscpd && node scripts/test-rapier-gz.mjs && node scripts/test-memory-profile.mjs && node scripts/test-model-parse-cache.mjs && node scripts/test-static-actors.mjs && node scripts/test-frozen-statics.mjs && node scripts/test-frozen-nested.mjs && node scripts/test-frozen-statics-legacy-physics2d.mjs && node scripts/test-skip-empty-nodes.mjs && node scripts/test-view-range.mjs && node scripts/test-look-bake.mjs && node scripts/test-square-first.mjs && node --input-type=module -e \"const { bundleProject } = await import('castle-web-cli/dist/bundle.js'); await bundleProject('.');\""
8
+ "test:wall-slide": "node scripts/test-wall-slide.mjs",
9
+ "check": "eslint . && jscpd && npm run test:wall-slide && node scripts/test-rapier-gz.mjs && node scripts/test-ground-half.mjs && node scripts/test-memory-profile.mjs && node scripts/test-model-parse-cache.mjs && node scripts/test-sleeping-models.mjs && node scripts/test-static-actors.mjs && node scripts/test-frozen-statics.mjs && node scripts/test-frozen-nested.mjs && node scripts/test-frozen-statics-legacy-physics2d.mjs && node scripts/test-skip-empty-nodes.mjs && node scripts/test-view-range.mjs && node scripts/test-look-bake.mjs && node scripts/test-template-cache.mjs && node scripts/test-template-cache-minified.mjs && node scripts/test-model-cache.mjs && node scripts/test-square-first.mjs && node --input-type=module -e \"const { bundleProject } = await import('castle-web-cli/dist/bundle.js'); await bundleProject('.');\""
9
10
  },
10
11
  "jscpd": {
11
12
  "path": [
@@ -87,10 +87,50 @@ function hoverSteadily(phys, actor, t, dims) {
87
87
  function pullSteadily(phys, actor) {
88
88
  phys.addForce(actor, { x: 0, y: -14 * phys.mass(actor), z: 0 });
89
89
  }
90
- function applyMove(phys, actor, move, speed, grounded, dt) {
90
+ // Clip the requested walk against at most two nearby wall planes. A second
91
+ // plane that sends the tangent back into the first is a closed corner.
92
+ // Keep the tangent's length: projecting must not speed up a diagonal walk.
93
+ function slideMove(phys, actor, move) {
94
+ const wanted = move;
95
+ let first = null;
96
+ let excludeCollider;
97
+ for (let i = 0; i < 2; i += 1) {
98
+ const length = Math.hypot(move.x, move.z);
99
+ if (length < 1e-6)
100
+ return { x: 0, z: 0 };
101
+ const hit = phys.castWalkWall(actor, { x: move.x / length, y: 0, z: move.z / length }, 0.12, excludeCollider);
102
+ const n = hit?.normal;
103
+ // castWalkWall resolves convex-edge support normals to surface faces:
104
+ // adjoining boxes in a straight wall do not supply a second wall plane.
105
+ // Floors and slopes keep their existing drive; only near-vertical faces.
106
+ if (!n || Math.abs(n.y) > 0.2)
107
+ break;
108
+ const horizontal = Math.hypot(n.x, n.z);
109
+ if (horizontal < 1e-6)
110
+ break;
111
+ const normal = { x: n.x / horizontal, z: n.z / horizontal };
112
+ const into = move.x * normal.x + move.z * normal.z;
113
+ if (into >= -1e-6)
114
+ break;
115
+ // Reproject the original request on the second plane. Projecting the
116
+ // first tangent again can create an unwanted escape along the corner
117
+ // (and drift from tiny errors in Rapier's sweep normals).
118
+ const amount = wanted.x * normal.x + wanted.z * normal.z;
119
+ move = { x: wanted.x - amount * normal.x, z: wanted.z - amount * normal.z };
120
+ if (first && move.x * first.x + move.z * first.z < -1e-6)
121
+ return { x: 0, z: 0 };
122
+ first = normal;
123
+ excludeCollider = hit.colliderHandle;
124
+ }
125
+ return move;
126
+ }
127
+ function applyMove(phys, actor, move, speed, grounded, dt, scene) {
91
128
  const mass = phys.mass(actor);
92
129
  const vel = phys.getVelocity(actor);
93
130
  if (move) {
131
+ if (scene.data?.engine?.player?.slideOnWalls === true && grounded && vel.y <= 1) {
132
+ move = slideMove(phys, actor, move);
133
+ }
94
134
  const factor = Math.min(1, dt * 14) * (grounded ? 1 : 0.3);
95
135
  phys.applyImpulse(actor, {
96
136
  x: (move.x * speed - vel.x) * mass * factor,
@@ -471,7 +511,7 @@ function updateOrbiting(actor, scene, props, dt) {
471
511
  scene.playerDrive.step(actor, phys, { keys: scene.keys, stick: scene.moveInput, grounded }, dt);
472
512
  }
473
513
  else {
474
- applyMove(phys, actor, driveOrbiting(scene, per, rt, props, dt), props.speed, grounded, dt);
514
+ applyMove(phys, actor, driveOrbiting(scene, per, rt, props, dt), props.speed, grounded, dt, scene);
475
515
  t.rotationY = rt.facing / DEG;
476
516
  jumpOrbiting(phys, actor, scene, rt, grounded, props.jumpSpeed, dt);
477
517
  }
@@ -1170,7 +1210,7 @@ class Player {
1170
1210
  z: -Math.cos(per.camAngle) * drive.forward,
1171
1211
  }
1172
1212
  : null;
1173
- applyMove(phys, actor, move, this.props.speed, grounded, dt);
1213
+ applyMove(phys, actor, move, this.props.speed, grounded, dt, scene);
1174
1214
  t.rotationY = rt.facing / DEG;
1175
1215
  // Jump: Space on keyboard, or a short tap anywhere on the canvas (which
1176
1216
  // works while another finger drives the drag stick). A tap is buffered
@@ -12,15 +12,25 @@
12
12
  // instead (render/sheet.js), saved as `<name>-motion.png`.
13
13
  //
14
14
  // The pixels come from the playtest service, the one a task agent uses. The
15
- // script builds a scratch deck in `.castle/render/sheet-deck/` -- the page in
16
- // `render/` plus links to this deck's imports and node_modules -- serves it on
17
- // a free port, and stops that serve when done. A playtest takes at most six
18
- // screenshots, so each covers two models of three pages, pressing `n` between
19
- // pages. The pages are joined side by side here.
15
+ // script builds a scratch deck -- the page in `render/` plus links to this
16
+ // deck's imports and node_modules -- serves it on a free port, and stops that
17
+ // serve when done. A playtest takes at most six screenshots, so each covers two
18
+ // models of three pages, pressing `n` between pages. The pages are joined side
19
+ // by side here.
20
+ //
21
+ // The scratch deck lives in the OS temp dir, one per deck
22
+ // (`<tmpdir>/castle-render/<hash of the deck's path>/sheet-deck`), never inside
23
+ // the deck: a cloud sandbox's checkpoint of the deck refuses its links, so every
24
+ // save failed while one sat in `.castle/render/`. In a sandbox the temp dir is
25
+ // another filesystem; links across it are fine, a rename across it is not, and
26
+ // nothing here renames. A scratch deck an older version left in the deck is
27
+ // removed on start.
20
28
 
21
29
  import { spawn } from 'node:child_process';
30
+ import { createHash } from 'node:crypto';
22
31
  import * as fs from 'node:fs';
23
32
  import * as net from 'node:net';
33
+ import * as os from 'node:os';
24
34
  import * as path from 'node:path';
25
35
  import { fileURLToPath } from 'node:url';
26
36
  import * as zlib from 'node:zlib';
@@ -28,7 +38,16 @@ import * as zlib from 'node:zlib';
28
38
  const KIT_RENDER_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), 'render');
29
39
  const DECK = process.cwd();
30
40
  const WORK = path.join(DECK, '.castle', 'render');
31
- const SHEET_DECK = path.join(WORK, 'sheet-deck');
41
+ // Stable per deck, so a kept serve (CASTLE_RENDER_KEEP=1) is found again and
42
+ // renders of the same deck share its start lock. Both paths are real paths:
43
+ // macOS's temp dir is behind a link, and vite resolves served files through
44
+ // links, so the serve's root should be the path its own files resolve to.
45
+ const SCRATCH = path.join(
46
+ fs.realpathSync(os.tmpdir()),
47
+ 'castle-render',
48
+ createHash('sha256').update(fs.realpathSync(DECK)).digest('hex').slice(0, 12)
49
+ );
50
+ const SHEET_DECK = path.join(SCRATCH, 'sheet-deck');
32
51
 
33
52
  // The deck's package.json sets this to the command its other scripts use.
34
53
  const CLI = (process.env.CASTLE_WEB_CLI || 'castle-web').trim().split(/\s+/);
@@ -195,7 +214,36 @@ function copyText(from, to) {
195
214
  fs.writeFileSync(to, fs.readFileSync(from));
196
215
  }
197
216
 
217
+ // Older versions built the scratch deck at `.castle/render/sheet-deck/`. It
218
+ // holds only links and copies, and the links point back into this deck, so they
219
+ // are unlinked first and never followed.
220
+ function removeOldSheetDeck() {
221
+ const old = path.join(WORK, 'sheet-deck');
222
+ const unlinkLinks = (dir) => {
223
+ let entries;
224
+ try {
225
+ entries = fs.readdirSync(dir, { withFileTypes: true });
226
+ } catch {
227
+ return;
228
+ }
229
+ for (const entry of entries) {
230
+ const at = path.join(dir, entry.name);
231
+ if (entry.isSymbolicLink()) {
232
+ // Another render of this deck may have taken it already.
233
+ fs.rmSync(at, { force: true });
234
+ } else if (entry.isDirectory()) {
235
+ unlinkLinks(at);
236
+ }
237
+ }
238
+ };
239
+ if (fs.lstatSync(old, { throwIfNoEntry: false })?.isDirectory()) {
240
+ unlinkLinks(old);
241
+ }
242
+ fs.rmSync(old, { recursive: true, force: true });
243
+ }
244
+
198
245
  function writeSheetDeck() {
246
+ removeOldSheetDeck();
199
247
  fs.mkdirSync(SHEET_DECK, { recursive: true });
200
248
  for (const name of ['index.html', 'sheet.js', 'filmstrip.js']) {
201
249
  copyText(path.join(KIT_RENDER_DIR, name), path.join(SHEET_DECK, name));
@@ -269,8 +317,8 @@ async function runningServe() {
269
317
 
270
318
  // Renders in the same deck at the same time take turns starting its serve.
271
319
  async function withStartLock(start) {
272
- const lock = path.join(WORK, 'serve.lock');
273
- fs.mkdirSync(WORK, { recursive: true });
320
+ const lock = path.join(SCRATCH, 'serve.lock');
321
+ fs.mkdirSync(SCRATCH, { recursive: true });
274
322
  for (;;) {
275
323
  try {
276
324
  fs.mkdirSync(lock);
@@ -0,0 +1,37 @@
1
+ import { deflateSync, inflateSync } from 'three/examples/jsm/libs/fflate.module.js';
2
+
3
+ // Alter otherwise valid entries, preserving framing and compressed payloads.
4
+ export function changeTemplate(bytes, change) {
5
+ const view = new DataView(bytes);
6
+ const header = JSON.parse(new TextDecoder().decode(new Uint8Array(bytes, 16, view.getUint32(8, true))));
7
+ const stored = new Uint8Array(bytes, Math.ceil((16 + view.getUint32(8, true)) / 8) * 8);
8
+ const payload = header.payloadCodec === 'deflate' ? inflateSync(stored) : stored.slice();
9
+ change(header, payload);
10
+ header.payloadCodec = 'deflate';
11
+ const compressed = deflateSync(payload, { level: 1 });
12
+ const json = new TextEncoder().encode(JSON.stringify(header));
13
+ const start = Math.ceil((16 + json.length) / 8) * 8;
14
+ const result = new ArrayBuffer(start + compressed.length);
15
+ const prefix = new DataView(result);
16
+ [view.getUint32(0, true), view.getUint32(4, true), json.length, compressed.length].forEach((value, index) => prefix.setUint32(index * 4, value, true));
17
+ new Uint8Array(result, 16, json.length).set(json);
18
+ new Uint8Array(result, start).set(compressed);
19
+ return result;
20
+ }
21
+
22
+ export function templateArray(attribute, payload) {
23
+ const [, , offset, count, storage] = attribute.array;
24
+ return new globalThis[storage](payload.buffer, payload.byteOffset + offset, count);
25
+ }
26
+
27
+ export function templateGroups(start, count, materialIndex = 0) {
28
+ return ['list', [['object', [['start', start], ['count', count], ['materialIndex', materialIndex]]]]];
29
+ }
30
+
31
+ export function outOfRangeIndex(header, payload) {
32
+ const geometry = header.geometries[0];
33
+ const position = geometry.attributes.find(([key]) => key === 'position')[1];
34
+ if (!geometry.index) geometry.index = { ...position, type: 'BufferAttribute', itemSize: 1, normalized: false,
35
+ array: ['array', 'Uint32Array', position.array[2], 3, 'Uint32Array', 1000000] };
36
+ templateArray(geometry.index, payload)[0] = position.array[3] / position.itemSize;
37
+ }