castle-web-cli 0.4.233 → 0.4.235

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 (383) hide show
  1. package/dist/api.d.ts +11 -0
  2. package/dist/api.js +43 -0
  3. package/dist/bundle.d.ts +64 -0
  4. package/dist/bundle.js +558 -2
  5. package/dist/castle-host/host.d.ts +17 -2
  6. package/dist/castle-host/host.js +793 -36
  7. package/dist/castleJson.d.ts +20 -1
  8. package/dist/castleJson.js +44 -2
  9. package/dist/check.js +9 -2
  10. package/dist/chunkLoader.d.ts +3 -0
  11. package/dist/chunkLoader.js +111 -0
  12. package/dist/devParty.d.ts +26 -0
  13. package/dist/devParty.js +231 -0
  14. package/dist/devSaveStorage.js +4 -0
  15. package/dist/devSessionStorage.js +3 -1
  16. package/dist/devSocial.d.ts +24 -0
  17. package/dist/devSocial.js +70 -0
  18. package/dist/ide.d.ts +2 -0
  19. package/dist/ide.js +119 -15
  20. package/dist/index.js +8 -2
  21. package/dist/init.js +1 -1
  22. package/dist/save-deck.d.ts +20 -1
  23. package/dist/save-deck.js +141 -5
  24. package/dist/serve.js +29 -11
  25. package/dist/shell/assets/{index-BjOxR-lW.js → index-DulbYIJm.js} +97 -97
  26. package/dist/shell/index.html +1 -1
  27. package/dist/vitePlugins.d.ts +2 -1
  28. package/dist/vitePlugins.js +13 -0
  29. package/kits/base/castle.json +1 -1
  30. package/kits/base/sdk/README.md +266 -3
  31. package/kits/base/sdk/castle.d.ts +7 -3
  32. package/kits/base/sdk/castle.js +2 -0
  33. package/kits/base/sdk/commands.d.ts +162 -1
  34. package/kits/base/sdk/commands.js +3 -0
  35. package/kits/base/sdk/display.d.ts +3 -0
  36. package/kits/base/sdk/display.js +9 -3
  37. package/kits/base/sdk/hub.d.ts +33 -6
  38. package/kits/base/sdk/hub.js +68 -5
  39. package/kits/base/sdk/hubRejoin.d.ts +4 -0
  40. package/kits/base/sdk/hubRejoin.js +15 -0
  41. package/kits/base/sdk/multiplayer.d.ts +7 -1
  42. package/kits/base/sdk/multiplayer.js +147 -40
  43. package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
  44. package/kits/base/sdk/party.d.ts +23 -0
  45. package/kits/base/sdk/party.js +91 -0
  46. package/kits/base/sdk/reconnectBudget.d.ts +23 -0
  47. package/kits/base/sdk/reconnectBudget.js +96 -0
  48. package/kits/base/sdk/save.d.ts +38 -1
  49. package/kits/base/sdk/save.js +79 -6
  50. package/kits/base/sdk/server/hub.d.ts +31 -1
  51. package/kits/base/sdk/server/hub.js +50 -3
  52. package/kits/base/sdk/server/platformHandle.d.ts +13 -1
  53. package/kits/base/sdk/server/storage.d.ts +4 -0
  54. package/kits/base/sdk/server/storage.js +19 -3
  55. package/kits/base/sdk/server/wrapper.d.ts +7 -1
  56. package/kits/base/sdk/server/wrapper.js +10 -1
  57. package/kits/base/sdk/social.d.ts +9 -0
  58. package/kits/base/sdk/social.js +5 -0
  59. package/kits/hub-game/CLAUDE.md +123 -3
  60. package/kits/hub-game/README.md +63 -0
  61. package/kits/hub-game/castle.json +5 -5
  62. package/kits/hub-game/code/client/act.js +312 -0
  63. package/kits/hub-game/code/client/actionLayout.js +147 -0
  64. package/kits/hub-game/code/client/actionOverflow.js +556 -0
  65. package/kits/hub-game/code/client/arrivalCamera.js +50 -0
  66. package/kits/hub-game/code/client/askSlot.js +117 -0
  67. package/kits/hub-game/code/client/avatar.js +4 -2
  68. package/kits/hub-game/code/client/avatarShare.js +2 -0
  69. package/kits/hub-game/code/client/backVisibility.js +13 -0
  70. package/kits/hub-game/code/client/ballot.js +15 -10
  71. package/kits/hub-game/code/client/build.js +16 -0
  72. package/kits/hub-game/code/client/chat.js +41 -5
  73. package/kits/hub-game/code/client/chatModeration.js +5 -0
  74. package/kits/hub-game/code/client/chrome.js +1148 -258
  75. package/kits/hub-game/code/client/crowdNames.js +241 -0
  76. package/kits/hub-game/code/client/decor.js +10 -4
  77. package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
  78. package/kits/hub-game/code/client/doorErrors.js +39 -0
  79. package/kits/hub-game/code/client/fall.js +18 -0
  80. package/kits/hub-game/code/client/farAvatars.js +233 -0
  81. package/kits/hub-game/code/client/firstJoin.js +9 -2
  82. package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
  83. package/kits/hub-game/code/client/frameBatch.js +5 -0
  84. package/kits/hub-game/code/client/grab.js +31 -11
  85. package/kits/hub-game/code/client/hookLayer.js +87 -8
  86. package/kits/hub-game/code/client/hudCopy.js +51 -0
  87. package/kits/hub-game/code/client/hudRate.js +20 -0
  88. package/kits/hub-game/code/client/idle.js +14 -2
  89. package/kits/hub-game/code/client/invites.js +231 -0
  90. package/kits/hub-game/code/client/joinError.js +9 -0
  91. package/kits/hub-game/code/client/labelsNear.js +31 -2
  92. package/kits/hub-game/code/client/landscapeLayout.js +17 -0
  93. package/kits/hub-game/code/client/layoutCache.js +264 -0
  94. package/kits/hub-game/code/client/loadTelemetry.js +20 -0
  95. package/kits/hub-game/code/client/loadingCover.js +148 -0
  96. package/kits/hub-game/code/client/loadingEntry.js +8 -0
  97. package/kits/hub-game/code/client/menuRows.js +43 -0
  98. package/kits/hub-game/code/client/modelReady.js +7 -0
  99. package/kits/hub-game/code/client/padCueArrival.js +23 -0
  100. package/kits/hub-game/code/client/padCues.js +112 -0
  101. package/kits/hub-game/code/client/padOccupancy.js +88 -0
  102. package/kits/hub-game/code/client/padReadability.js +26 -0
  103. package/kits/hub-game/code/client/padRings.js +69 -0
  104. package/kits/hub-game/code/client/pushVisit.js +14 -0
  105. package/kits/hub-game/code/client/quality.js +205 -0
  106. package/kits/hub-game/code/client/qualityEntry.js +55 -0
  107. package/kits/hub-game/code/client/safeLayout.js +338 -0
  108. package/kits/hub-game/code/client/safeStyle.js +42 -0
  109. package/kits/hub-game/code/client/say.js +12 -3
  110. package/kits/hub-game/code/client/shot.js +64 -10
  111. package/kits/hub-game/code/client/shotFit.js +56 -0
  112. package/kits/hub-game/code/client/signIn.js +28 -0
  113. package/kits/hub-game/code/client/state.js +53 -0
  114. package/kits/hub-game/code/client/talk.js +209 -45
  115. package/kits/hub-game/code/client/tiers.js +68 -66
  116. package/kits/hub-game/code/client/together.js +7 -2
  117. package/kits/hub-game/code/client/weakestLookBake.js +92 -0
  118. package/kits/hub-game/code/client/weakestTier.js +295 -0
  119. package/kits/hub-game/code/client/worldLabels.js +241 -0
  120. package/kits/hub-game/code/client/yours.js +10 -9
  121. package/kits/hub-game/code/npcDisplayText.js +55 -0
  122. package/kits/hub-game/code/server/act.js +124 -0
  123. package/kits/hub-game/code/server/actions.js +6 -1
  124. package/kits/hub-game/code/server/actors.js +2 -1
  125. package/kits/hub-game/code/server/analytics.js +83 -0
  126. package/kits/hub-game/code/server/anonymousEntry.js +49 -0
  127. package/kits/hub-game/code/server/arrivalPose.js +36 -0
  128. package/kits/hub-game/code/server/companion.js +28 -3
  129. package/kits/hub-game/code/server/doorAnalytics.js +52 -0
  130. package/kits/hub-game/code/server/earned.js +22 -5
  131. package/kits/hub-game/code/server/frameBatch.js +183 -0
  132. package/kits/hub-game/code/server/friendsAmong.js +49 -9
  133. package/kits/hub-game/code/server/history.js +2 -0
  134. package/kits/hub-game/code/server/hub.js +1306 -95
  135. package/kits/hub-game/code/server/idle.js +30 -1
  136. package/kits/hub-game/code/server/index.js +26 -4
  137. package/kits/hub-game/code/server/invites.js +19 -0
  138. package/kits/hub-game/code/server/labels.js +9 -1
  139. package/kits/hub-game/code/server/loadAbandon.js +106 -0
  140. package/kits/hub-game/code/server/manifest.js +211 -3
  141. package/kits/hub-game/code/server/menu.js +31 -3
  142. package/kits/hub-game/code/server/npcs.js +226 -64
  143. package/kits/hub-game/code/server/observe.js +408 -0
  144. package/kits/hub-game/code/server/padOccupancy.js +85 -0
  145. package/kits/hub-game/code/server/players.js +9 -1
  146. package/kits/hub-game/code/server/resumePose.js +152 -0
  147. package/kits/hub-game/code/server/say.js +1 -1
  148. package/kits/hub-game/code/server/standing.js +4 -5
  149. package/kits/hub-game/code/server/storageLimit.js +187 -0
  150. package/kits/hub-game/code/server/vis.js +67 -5
  151. package/kits/hub-game/code/shared/act.js +35 -0
  152. package/kits/hub-game/code/shared/danceIdle.js +28 -0
  153. package/kits/hub-game/code/shared/loadStages.js +12 -0
  154. package/kits/hub-game/code/shared/quality.js +74 -0
  155. package/kits/hub-game/code/shared/say.js +2 -0
  156. package/kits/hub-game/code/shared/shot.js +35 -1
  157. package/kits/hub-game/code/systems/hub.js +970 -169
  158. package/kits/hub-game/docs/analytics.md +279 -0
  159. package/kits/hub-game/docs/contract.md +1259 -42
  160. package/kits/hub-game/docs/home-pieces.md +9 -2
  161. package/kits/hub-game/docs/observed-progress.md +252 -0
  162. package/kits/hub-game/main.jsx +2 -0
  163. package/kits/hub-game/package-lock.json +10 -3
  164. package/kits/hub-game/package.json +6 -3
  165. package/kits/hub-game/play/player.js +142 -0
  166. package/kits/hub-game/play/registry.js +47 -0
  167. package/kits/hub-game/play.jsx +37 -0
  168. package/kits/hub-game/scripts/check.mjs +39 -5
  169. package/kits/hub-game/scripts/companion-follower-wire.json +1 -1
  170. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +11 -0
  171. package/kits/hub-game/scripts/fixtures/decor-keyless.json +5 -5
  172. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +3 -0
  173. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +19 -3
  174. package/kits/hub-game/scripts/fixtures/interest-legacy.json +3 -3
  175. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -1
  176. package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
  177. package/kits/hub-game/scripts/test-act-client.mjs +186 -0
  178. package/kits/hub-game/scripts/test-act.mjs +171 -0
  179. package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
  180. package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
  181. package/kits/hub-game/scripts/test-actions-client.mjs +367 -2
  182. package/kits/hub-game/scripts/test-actors.mjs +20 -7
  183. package/kits/hub-game/scripts/test-analytics.mjs +76 -0
  184. package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
  185. package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
  186. package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
  187. package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
  188. package/kits/hub-game/scripts/test-avatar-wire.mjs +49 -10
  189. package/kits/hub-game/scripts/test-avatar.mjs +44 -0
  190. package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
  191. package/kits/hub-game/scripts/test-ballot.mjs +11 -4
  192. package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
  193. package/kits/hub-game/scripts/test-build.mjs +20 -2
  194. package/kits/hub-game/scripts/test-chat.mjs +206 -5
  195. package/kits/hub-game/scripts/test-companion-chat.mjs +20 -2
  196. package/kits/hub-game/scripts/test-control-layout-dom.mjs +120 -0
  197. package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
  198. package/kits/hub-game/scripts/test-decor-client.mjs +45 -4
  199. package/kits/hub-game/scripts/test-decor.mjs +7 -0
  200. package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
  201. package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
  202. package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
  203. package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
  204. package/kits/hub-game/scripts/test-earned.mjs +33 -3
  205. package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
  206. package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
  207. package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
  208. package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
  209. package/kits/hub-game/scripts/test-grab-orbit.mjs +47 -4
  210. package/kits/hub-game/scripts/test-high-only.mjs +170 -0
  211. package/kits/hub-game/scripts/test-hub-ops.mjs +321 -2
  212. package/kits/hub-game/scripts/test-hub-trip.mjs +879 -11
  213. package/kits/hub-game/scripts/test-hud-clear.mjs +162 -59
  214. package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
  215. package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
  216. package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
  217. package/kits/hub-game/scripts/test-idle.mjs +66 -0
  218. package/kits/hub-game/scripts/test-interest-cells.mjs +20 -0
  219. package/kits/hub-game/scripts/test-interest.mjs +15 -0
  220. package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
  221. package/kits/hub-game/scripts/test-invites.mjs +109 -0
  222. package/kits/hub-game/scripts/test-labels.mjs +71 -3
  223. package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
  224. package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
  225. package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
  226. package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
  227. package/kits/hub-game/scripts/test-manifest.mjs +265 -0
  228. package/kits/hub-game/scripts/test-menu-client.mjs +105 -0
  229. package/kits/hub-game/scripts/test-menu.mjs +23 -0
  230. package/kits/hub-game/scripts/test-npcs.mjs +917 -10
  231. package/kits/hub-game/scripts/test-observed.mjs +745 -0
  232. package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
  233. package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
  234. package/kits/hub-game/scripts/test-picker.mjs +234 -7
  235. package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
  236. package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
  237. package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
  238. package/kits/hub-game/scripts/test-quality.mjs +385 -0
  239. package/kits/hub-game/scripts/test-rehello.mjs +699 -5
  240. package/kits/hub-game/scripts/test-resume-action-order.mjs +598 -0
  241. package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
  242. package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
  243. package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
  244. package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
  245. package/kits/hub-game/scripts/test-say.mjs +1 -1
  246. package/kits/hub-game/scripts/test-shot.mjs +145 -0
  247. package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
  248. package/kits/hub-game/scripts/test-soundscape.mjs +22 -17
  249. package/kits/hub-game/scripts/test-standing.mjs +35 -2
  250. package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
  251. package/kits/hub-game/scripts/test-stuck.mjs +5 -4
  252. package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
  253. package/kits/hub-game/scripts/test-tiers-render.mjs +86 -13
  254. package/kits/hub-game/scripts/test-tiers.mjs +7 -8
  255. package/kits/hub-game/scripts/test-vis.mjs +433 -6
  256. package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
  257. package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
  258. package/kits/hub-game/scripts/test-yours-chrome.mjs +50 -6
  259. package/kits/hub-game/scripts/test-yours.mjs +39 -8
  260. package/kits/multiplayer-3d/castle.json +5 -5
  261. package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
  262. package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
  263. package/kits/multiplayer-3d/code/systems/multiplayer.js +369 -30
  264. package/kits/multiplayer-3d/package-lock.json +8 -1
  265. package/kits/multiplayer-3d/package.json +2 -1
  266. package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
  267. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
  268. package/kits/physics-2d/CLAUDE.md +10 -1
  269. package/kits/physics-2d/castle.json +2 -2
  270. package/kits/physics-2d/engine/frozenActors.js +233 -0
  271. package/kits/physics-2d/engine/scene.js +87 -5
  272. package/kits/physics-2d/eslint.config.js +1 -1
  273. package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
  274. package/kits/physics-2d/play/behaviors/Camera.js +40 -0
  275. package/kits/physics-2d/play/behaviors/Collider.js +122 -0
  276. package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
  277. package/kits/physics-2d/play/behaviors/Goal.js +46 -0
  278. package/kits/physics-2d/play/behaviors/Joints.js +126 -0
  279. package/kits/physics-2d/play/behaviors/Layout.js +71 -0
  280. package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
  281. package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
  282. package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
  283. package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
  284. package/kits/physics-2d/play/behaviors/Style.js +209 -0
  285. package/kits/physics-2d/play/behaviors/Text.js +85 -0
  286. package/kits/physics-2d/play/behaviors/Video.js +93 -0
  287. package/kits/physics-3d/CLAUDE.md +25 -1651
  288. package/kits/physics-3d/behaviors/Body.jsx +3 -0
  289. package/kits/physics-3d/behaviors/Model.jsx +3 -0
  290. package/kits/physics-3d/behaviors/Player.jsx +35 -18
  291. package/kits/physics-3d/behaviors/Shape.jsx +3 -0
  292. package/kits/physics-3d/behaviors/Solid.jsx +3 -0
  293. package/kits/physics-3d/behaviors/Transform.jsx +3 -0
  294. package/kits/physics-3d/castle.json +3 -3
  295. package/kits/physics-3d/docs/engine-camera.md +542 -0
  296. package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
  297. package/kits/physics-3d/docs/engine-load.md +149 -0
  298. package/kits/physics-3d/docs/engine-look.md +114 -0
  299. package/kits/physics-3d/docs/engine-shadows.md +372 -0
  300. package/kits/physics-3d/docs/engine-skip-work.md +187 -0
  301. package/kits/physics-3d/docs/engine-sky.md +198 -0
  302. package/kits/physics-3d/docs/engine-static-actors.md +226 -0
  303. package/kits/physics-3d/docs/engine-view.md +37 -0
  304. package/kits/physics-3d/docs/pxmodel-format.md +1 -1
  305. package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
  306. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -333
  307. package/kits/physics-3d/engine3d/actornode.js +1 -0
  308. package/kits/physics-3d/engine3d/branches.js +3 -13
  309. package/kits/physics-3d/engine3d/cage.js +2 -7
  310. package/kits/physics-3d/engine3d/cageops.js +2 -17
  311. package/kits/physics-3d/engine3d/dataBehaviors.js +12 -0
  312. package/kits/physics-3d/engine3d/framecap.js +4 -1
  313. package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
  314. package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
  315. package/kits/physics-3d/engine3d/gait.js +8 -0
  316. package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
  317. package/kits/physics-3d/engine3d/look.js +7 -0
  318. package/kits/physics-3d/engine3d/modelFiles.js +3 -17
  319. package/kits/physics-3d/engine3d/modelMath.js +49 -0
  320. package/kits/physics-3d/engine3d/modelready.js +16 -0
  321. package/kits/physics-3d/engine3d/motion.js +3 -3
  322. package/kits/physics-3d/engine3d/nearshadows.js +77 -10
  323. package/kits/physics-3d/engine3d/orbitinput.js +59 -25
  324. package/kits/physics-3d/engine3d/partgeometry.js +1 -16
  325. package/kits/physics-3d/engine3d/paths.js +1 -9
  326. package/kits/physics-3d/engine3d/playTimings.js +50 -0
  327. package/kits/physics-3d/engine3d/playerRun.js +372 -0
  328. package/kits/physics-3d/engine3d/pxmodel.js +3 -3
  329. package/kits/physics-3d/engine3d/rapier.js +27 -0
  330. package/kits/physics-3d/engine3d/scatter.js +1 -11
  331. package/kits/physics-3d/engine3d/shadowfade.js +23 -15
  332. package/kits/physics-3d/engine3d/sky.js +1 -1
  333. package/kits/physics-3d/engine3d/squarefirst.js +177 -0
  334. package/kits/physics-3d/engine3d/stillshadows.js +399 -0
  335. package/kits/physics-3d/engine3d/sweep.js +1 -25
  336. package/kits/physics-3d/engine3d/world3d.js +468 -18
  337. package/kits/physics-3d/eslint.config.js +2 -1
  338. package/kits/physics-3d/main.jsx +6 -3
  339. package/kits/physics-3d/package-lock.json +7 -0
  340. package/kits/physics-3d/package.json +5 -1
  341. package/kits/physics-3d/play/behaviors/Body.js +31 -0
  342. package/kits/physics-3d/play/behaviors/Door.js +37 -0
  343. package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
  344. package/kits/physics-3d/play/behaviors/Model.js +23 -0
  345. package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
  346. package/kits/physics-3d/play/behaviors/Player.js +1204 -0
  347. package/kits/physics-3d/play/behaviors/Shape.js +47 -0
  348. package/kits/physics-3d/play/behaviors/Solid.js +16 -0
  349. package/kits/physics-3d/play/behaviors/Transform.js +29 -0
  350. package/kits/physics-3d/pnpm-lock.yaml +8 -0
  351. package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
  352. package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
  353. package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
  354. package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
  355. package/kits/physics-3d/scripts/test-camera-orbit.mjs +52 -4
  356. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
  357. package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
  358. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +6 -3
  359. package/kits/physics-3d/scripts/test-frame-cap.mjs +1 -1
  360. package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
  361. package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
  362. package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -0
  363. package/kits/physics-3d/scripts/test-look-bake.mjs +1 -1
  364. package/kits/physics-3d/scripts/test-near-shadows.mjs +2 -2
  365. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +88 -7
  366. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +40 -3
  367. package/kits/physics-3d/scripts/test-orbit-shot.mjs +75 -1
  368. package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
  369. package/kits/physics-3d/scripts/test-sky.mjs +1 -1
  370. package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
  371. package/kits/physics-3d/scripts/test-static-actors.mjs +3 -1
  372. package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
  373. package/kits/physics-3d/scripts/test-static-scenery.mjs +5 -2
  374. package/kits/physics-3d/scripts/test-steady-hover.mjs +5 -2
  375. package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
  376. package/kits/physics-3d/systems/physics3d.js +37 -4
  377. package/kits/real-time/castle.json +2 -2
  378. package/kits/real-time/code/client/connection.js +33 -10
  379. package/kits/real-time/code/client/gameHooks.js +2 -0
  380. package/kits/real-time/code/client/joinOverlay.js +9 -4
  381. package/kits/real-time/code/server/session.js +6 -4
  382. package/kits/real-time/package-lock.json +1 -1
  383. package/package.json +2 -2
@@ -0,0 +1,924 @@
1
+ import assert from 'node:assert/strict';
2
+ import fs from 'node:fs';
3
+ import { fpsTelemetryFor } from '../code/client/fpsTelemetry.js';
4
+ import { register } from 'node:module';
5
+ import { makeTiers, middleGpu, weakestGpu } from '../code/client/tiers.js';
6
+ import { goalAt } from '../code/client/labelsNear.js';
7
+ import { goalPointers, goalText, pointerAt } from '../code/client/together.js';
8
+ import { PerspectiveCamera } from 'three';
9
+ import { doorPoint } from '../code/client/doorFrame.js';
10
+ import { makeIdle, SIT_OFFER_M } from '../code/client/idle.js';
11
+ import { deck, hub, clear as clearHub } from '../code/client/state.js';
12
+ import { allActors, filterQualityScene, makeQualityVisit, qualityPlayers, samePad, talkActors } from '../code/client/quality.js';
13
+
14
+ const stubs = {
15
+ 'castle-web-sdk': `export const resolveDeckFile = (name) => String(name).replace(/^\\.\\//, '');
16
+ export const deckPrefixOf = () => ''; export const IMPORTS_DIR = 'imports'; export const IMPORTS_PREFIX = 'imports/';`,
17
+ './files': `export const initialFiles = {}; export const parseJsonFile = (path, text) => ({ value: JSON.parse(text) });
18
+ export const formatJson = (value) => JSON.stringify(value);`,
19
+ './systemRegistry': `export const systemInstallers = [];`,
20
+ './fonts': `export const deckFontFamily = 'sans-serif';`,
21
+ };
22
+ register(
23
+ 'data:text/javascript,' +
24
+ encodeURIComponent(`
25
+ import { existsSync } from 'node:fs';
26
+ import { fileURLToPath } from 'node:url';
27
+ const stubs = ${JSON.stringify(stubs)};
28
+ export async function resolve(specifier, context, next) {
29
+ const parent = context.parentURL ?? '';
30
+ if (parent.includes('/physics-2d/engine/') && stubs[specifier]) {
31
+ return { url: 'data:text/javascript,' + encodeURIComponent(stubs[specifier]), shortCircuit: true };
32
+ }
33
+ if (specifier.startsWith('@imports/castle.physics-3d/')) { specifier = parent.replace(/\\/kits\\/.*/, '/kits/physics-3d/') + specifier.slice(27); }
34
+ if (specifier.startsWith('@imports/castle.physics-2d/')) {
35
+ specifier = parent.replace(/\\/kits\\/.*/, '/kits/physics-2d/') + specifier.slice(27);
36
+ }
37
+ if ((specifier.startsWith('.') || specifier.startsWith('file:')) && parent.includes('/kits/') && !/\\.(m?js|jsx|json)$/.test(specifier)) {
38
+ const base = new URL(specifier, parent).href;
39
+ if (existsSync(fileURLToPath(base + '.js'))) return next(base + '.js', context);
40
+ }
41
+ return next(specifier, context);
42
+ }
43
+ `),
44
+ );
45
+
46
+ const { SceneRuntime } = await import('../../physics-2d/engine/scene.js');
47
+ const { makeWeakestTier, readDistricts } = await import('../code/client/weakestTier.js');
48
+
49
+ const spec = {
50
+ version: 1,
51
+ districts: [
52
+ {
53
+ id: 'left',
54
+ outline: [
55
+ [-20, -20],
56
+ [0, -20],
57
+ [0, 20],
58
+ [-20, 20],
59
+ ],
60
+ },
61
+ {
62
+ id: 'right',
63
+ outline: [
64
+ [0, -20],
65
+ [20, -20],
66
+ [20, 20],
67
+ [0, 20],
68
+ ],
69
+ },
70
+ ],
71
+ actors: [
72
+ { id: 'left-wall', districts: ['left'], origin: [-14, 0], bounds: [-15, -1, -14, 1] },
73
+ { id: 'right-wall', districts: ['right'], origin: [14, 0], bounds: [14, -1, 15, 1] },
74
+ { id: 'door', districts: ['right'], origin: [14, 0], bounds: [14, -1, 15, 1] },
75
+ ],
76
+ };
77
+ const inert = (id, x) => ({
78
+ id,
79
+ static: true,
80
+ components: { Transform: { x, y: 0, z: 0 }, Shape: { solid: true } },
81
+ runtime: { sentinel: {} },
82
+ });
83
+ function fixture() {
84
+ const player = { id: 'self', components: { Player: {}, Transform: { x: -10, z: 0 } } };
85
+ const left = inert('left-wall', -14),
86
+ right = inert('right-wall', 14);
87
+ const door = {
88
+ ...inert('door', 14),
89
+ components: { ...inert('door', 14).components, HubDoor: {} },
90
+ };
91
+ const data = { weakestDistricts: spec, actors: [player, left, right, door] };
92
+ const files = {
93
+ 'models/m.pxmodel': JSON.stringify({
94
+ parts: [{ id: 'a', look: { ao: 1, outline: 1 } }],
95
+ look: { rim: 0.2 },
96
+ }),
97
+ };
98
+ const scene = new SceneRuntime(data, [], {}, files);
99
+ return {
100
+ scene,
101
+ player: scene.getActor('self'),
102
+ left: scene.getActor('left-wall'),
103
+ right: scene.getActor('right-wall'),
104
+ files,
105
+ data: scene.data,
106
+ };
107
+ }
108
+ for (const value of [
109
+ null,
110
+ {},
111
+ { ...spec, districts: [null] },
112
+ { ...spec, actors: [{ ...spec.actors[0], districts: ['missing'] }] },
113
+ { ...spec, actors: [spec.actors[0], spec.actors[0]] },
114
+ ]) {
115
+ assert.equal(readDistricts(value), null);
116
+ }
117
+ assert.ok(readDistricts(spec));
118
+ for (const gpu of ['Mali-G52 MC1', 'ANGLE (ARM, Mali-G52 MC2, OpenGL ES 3.2)', 'mali-g52 mc2']) {
119
+ assert.ok(middleGpu(gpu), gpu);
120
+ }
121
+ for (const gpu of ['Mali-G52 MC3', 'Mali-G52 MC12', 'Mali-G51', 'PowerVR GE8320', 'Adreno 506', null, undefined, 42]) {
122
+ assert.ok(!middleGpu(gpu), String(gpu));
123
+ }
124
+ // The runtime-only model variant restores the inherited scene setting, while
125
+ // an existing or replacement own setting remains its owner's.
126
+ for (const initial of [undefined, false, true]) {
127
+ const h = fixture(),
128
+ controller = makeWeakestTier();
129
+ if (initial !== undefined) {
130
+ Object.defineProperty(h.scene, 'dropsEmptyParts', { value: initial, configurable: true });
131
+ }
132
+ controller.frame(h.scene, true, 0);
133
+ assert.equal(h.scene.dropsEmptyParts, initial ?? true);
134
+ controller.restore();
135
+ assert.equal(h.scene.dropsEmptyParts, initial ?? false);
136
+ assert.equal(Object.hasOwn(h.scene, 'dropsEmptyParts'), initial !== undefined);
137
+ controller.frame(h.scene, true, 1);
138
+ Object.defineProperty(h.scene, 'dropsEmptyParts', { value: false, configurable: true });
139
+ controller.restore();
140
+ assert.equal(h.scene.dropsEmptyParts, false);
141
+ assert.equal(Object.hasOwn(h.scene, 'dropsEmptyParts'), true);
142
+ }
143
+ assert.ok(weakestGpu('ANGLE (PowerVR, PowerVR Rogue GE8320, OpenGL ES 3.2)'));
144
+ for (const gpu of [
145
+ 'PowerVR SGX Doma',
146
+ 'PowerVR SGX (Doma)',
147
+ 'ANGLE (PowerVR, PowerVR SGX Doma, OpenGL ES 3.1)',
148
+ ]) {
149
+ assert.ok(weakestGpu(gpu), gpu);
150
+ }
151
+ for (const gpu of [
152
+ 'PowerVR SGX', 'PowerVR SGX 544MP', 'PowerVR SGX 545',
153
+ 'PowerVR SGX DomaXT', 'PowerVR SGX Doma Plus',
154
+ 'PowerVR Rogue GM9446', 'Mali-G52 MC2', null, undefined, 42,
155
+ ]) {
156
+ assert.ok(!weakestGpu(gpu), String(gpu));
157
+ }
158
+ for (const [enabled, gpu, profile] of [
159
+ [false, 'PowerVR Rogue GE8320', 'low'],
160
+ [true, 'PowerVR Rogue GE8320', 'weakest'],
161
+ [true, 'PowerVR SGX Doma', 'weakest'],
162
+ [true, 'PowerVR SGX (Doma)', 'weakest'],
163
+ [false, 'PowerVR SGX Doma', 'high'],
164
+ [true, 'PowerVR SGX 544MP', 'high'],
165
+ [true, 'Mali-G52 MC2', 'middle'],
166
+ [false, 'Mali-G52 MC2', 'low'],
167
+ ]) {
168
+ const tiers = makeTiers({
169
+ weakest: enabled,
170
+ storage: null,
171
+ deviceMemory: 4,
172
+ levers: { apply() {}, high() {} },
173
+ });
174
+ const renderer = { getContext: () => ({ getExtension: () => null, getParameter: () => gpu }) };
175
+ tiers.frame({ three: { renderer } }, true, 0);
176
+ assert.equal(tiers.handle.profile ?? tiers.current(), profile);
177
+ tiers.set('high');
178
+ assert.equal(tiers.handle.profile ?? tiers.current(), 'high');
179
+ tiers.set('low');
180
+ assert.equal(tiers.handle.profile ?? tiers.current(), ['weakest', 'middle'].includes(profile) ? profile : 'low');
181
+ assert.equal(tiers.middle(), profile === 'middle');
182
+ if (enabled) {
183
+ tiers.set('weakest');
184
+ assert.equal(tiers.weakest(), true);
185
+ assert.equal(tiers.middle(), false);
186
+ assert.equal(tiers.handle.profile, 'weakest');
187
+ }
188
+ }
189
+ const f = fixture(),
190
+ tier = makeWeakestTier();
191
+ tier.frame(f.scene, false, 0);
192
+ assert.equal(f.scene.files, f.files);
193
+ assert.equal(Object.hasOwn(f.scene, 'dropsEmptyParts'), false);
194
+
195
+ // Resolution belongs to this runtime and both render targets, then returns
196
+ // exactly to its previous settings on High or when entering a door scene.
197
+ {
198
+ const h = fixture(),
199
+ controller = makeWeakestTier();
200
+ let ratio = 2;
201
+ h.scene.three = {};
202
+ h.scene.three.renderer = {
203
+ getPixelRatio: () => ratio,
204
+ setPixelRatio: (v) => {
205
+ ratio = v;
206
+ },
207
+ };
208
+ h.scene.three.composer = {
209
+ _pixelRatio: 1.5,
210
+ setPixelRatio(v) {
211
+ this._pixelRatio = v;
212
+ },
213
+ };
214
+ controller.frame(h.scene, false, 0);
215
+ assert.equal(ratio, 2);
216
+ controller.frame(h.scene, true, 0);
217
+ assert.equal(ratio, 0.5);
218
+ assert.equal(h.scene.three.composer._pixelRatio, 0.5);
219
+ controller.frame(h.scene, false, 100);
220
+ assert.equal(ratio, 2);
221
+ assert.equal(h.scene.three.composer._pixelRatio, 1.5);
222
+ controller.frame(h.scene, true, 200);
223
+ // A later owner changed the buffers: restoring this tier must not undo it.
224
+ ratio = 1;
225
+ h.scene.three.composer._pixelRatio = 1;
226
+ controller.restore();
227
+ assert.equal(ratio, 1);
228
+ assert.equal(h.scene.three.composer._pixelRatio, 1);
229
+ }
230
+
231
+ // Execute the hub's actual entry method: an opted-in ordinary Low GPU never
232
+ // creates or frames the district/bake/resolution controller.
233
+ {
234
+ const source = fs.readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
235
+ const start = source.indexOf(' deviceTier(scene, mp, now) {');
236
+ const method = source.slice(start, source.indexOf('\n }\n', start) + 4).trim();
237
+ const Hub = { deck: { tiers: true, weakestTier: true }, hub: {} };
238
+ let enabled = false,
239
+ made = 0,
240
+ framed = 0,
241
+ restored = 0;
242
+ const tiers = { frame() {}, weakest: () => enabled, current: () => 'low', handle: {} };
243
+ const controller = {
244
+ active: false,
245
+ frame() {
246
+ framed++;
247
+ this.active = true;
248
+ },
249
+ restore() {
250
+ restored++;
251
+ this.active = false;
252
+ },
253
+ };
254
+ const entry = new Function(
255
+ 'Hub',
256
+ 'makeTiers',
257
+ 'makeWeakestTier',
258
+ 'readDistricts',
259
+ 'makeFarAvatars',
260
+ 'globalThis',
261
+ 'fpsTelemetryFor',
262
+ 'qualityFor',
263
+ `return function ${method};`,
264
+ )(
265
+ Hub,
266
+ () => tiers,
267
+ ({ profile }) => {
268
+ made++;
269
+ controller.profile = profile;
270
+ return controller;
271
+ },
272
+ readDistricts,
273
+ () => ({ update() {}, clear() {} }),
274
+ { __hub: {} },
275
+ fpsTelemetryFor,
276
+ () => null,
277
+ );
278
+ const system = { pendingEnd: null };
279
+ const scene = { actorWith: () => null };
280
+ for (let i = 0; i < 1000; i++) entry.call(system, scene, null, i);
281
+ assert.equal(made, 0);
282
+ assert.equal(framed, 0);
283
+ enabled = true;
284
+ for (let i = 0; i < 1000; i++) entry.call(system, scene, null, i);
285
+ assert.equal(made, 0);
286
+ assert.equal(framed, 0);
287
+ scene.data = { weakestDistricts: { version: 99 } };
288
+ entry.call(system, scene, null, 1000);
289
+ assert.equal(made, 0);
290
+ scene.data.weakestDistricts = spec;
291
+ entry.call(system, scene, null, 1001);
292
+ assert.equal(made, 1);
293
+ assert.equal(framed, 1);
294
+ enabled = false;
295
+ entry.call(system, {}, null, 1002);
296
+ entry.call(system, {}, null, 1003);
297
+ assert.equal(restored, 1);
298
+ Hub.deck.tiers = false;
299
+ system.tiers = undefined;
300
+ entry.call(system, {}, null, 1004);
301
+ assert.equal(system.tiers, undefined);
302
+ }
303
+
304
+ // Execute the hub entry with real tier selection and district controllers.
305
+ // No engine build or browser is needed: these are Low's existing buffers.
306
+ const hubSource = fs.readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
307
+ const deviceStart = hubSource.indexOf(' deviceTier(scene, mp, now) {');
308
+ const deviceMethod = hubSource.slice(deviceStart, hubSource.indexOf('\n }\n', deviceStart) + 4).trim();
309
+ function middleFixture({ enabled = true, gpu = 'Mali-G52 MC2', composerRatio = 2 } = {}) {
310
+ const h = fixture();
311
+ let ratio = 2;
312
+ const Hub = { deck: { tiers: true, weakestTier: enabled }, hub: { labels: {}, labelsMe: {} } };
313
+ const merges = [];
314
+ h.scene.three = {
315
+ renderer: {
316
+ getContext: () => ({ getExtension: () => null, getParameter: () => gpu }),
317
+ getPixelRatio: () => ratio,
318
+ setPixelRatio: (v) => { ratio = v; },
319
+ },
320
+ composer: { _pixelRatio: composerRatio, setPixelRatio(v) { this._pixelRatio = v; } },
321
+ nodes: new Map(),
322
+ camera: new PerspectiveCamera(60, 800 / 600, 0.1, 1000),
323
+ };
324
+ h.scene.three.camera.updateMatrixWorld();
325
+ const entry = new Function('Hub', 'makeTiers', 'makeWeakestTier', 'readDistricts', 'makeFarAvatars',
326
+ 'globalThis', 'fpsTelemetryFor', 'qualityFor', `return function ${deviceMethod};`)(
327
+ Hub,
328
+ (options) => makeTiers({ ...options, storage: null, deviceMemory: 4, levers: { apply() {}, high() {} } }),
329
+ makeWeakestTier, readDistricts, () => ({ update(...args) { merges.push(args.at(-1)); }, clear() {} }),
330
+ { __hub: {} }, fpsTelemetryFor, () => null,
331
+ );
332
+ const system = { pendingEnd: null };
333
+ return { ...h, Hub, system, merges, ratio: () => ratio,
334
+ setRatio: (v) => { ratio = v; }, frame: (now = 0) => entry.call(system, h.scene, null, now) };
335
+ }
336
+
337
+ {
338
+ const h = middleFixture({ composerRatio: 1.5 });
339
+ const queue = { skipSurfaceBakes: false, sentinel: {} };
340
+ h.scene.three.lookBake = queue;
341
+ h.Hub.deck.weakestLookBake = true; // Middle must ignore even this opt-in.
342
+ h.frame();
343
+ assert.equal(h.system.tiers.current(), 'low');
344
+ assert.equal(h.system.tiers.middle(), true);
345
+ assert.equal(h.system.tiers.handle.profile, 'middle');
346
+ assert.equal(h.system.weakestTier.profile, 'middle');
347
+ assert.equal(h.ratio(), 1, 'DPR 2 becomes DPR 1, rather than the absolute 0.5 Weakest cap');
348
+ assert.equal(h.scene.three.composer._pixelRatio, 0.75, 'each buffer halves its own Low ratio');
349
+ assert.equal(h.scene.isActorSleeping(h.right), true);
350
+ assert.equal(h.scene.files, h.files);
351
+ assert.equal(Object.hasOwn(h.scene, 'bakesLookLater'), false);
352
+ assert.equal(Object.hasOwn(h.scene, 'dropsEmptyParts'), false);
353
+ assert.equal(h.scene.three.lookBake, queue);
354
+ assert.deepEqual(Object.keys(queue), ['skipSurfaceBakes', 'sentinel']);
355
+ assert.equal(queue.skipSurfaceBakes, false);
356
+ assert.deepEqual(h.merges, [], 'Middle does not enable far-avatar merging');
357
+ h.frame(100);
358
+ assert.equal(h.ratio(), 1, 'repeated frames never halve again');
359
+ h.system.tiers.set('high');
360
+ h.frame(101);
361
+ assert.equal(h.system.tiers.middle(), false);
362
+ assert.equal(h.ratio(), 2);
363
+ assert.equal(h.scene.three.composer._pixelRatio, 1.5);
364
+ assert.equal(h.scene.getActors().length, h.scene.actors.size);
365
+ assert.equal(h.scene.files, h.files);
366
+ assert.equal(Object.hasOwn(h.scene, 'bakesLookLater'), false);
367
+ assert.equal(Object.hasOwn(h.scene, 'dropsEmptyParts'), false);
368
+ }
369
+ {
370
+ const h = middleFixture();
371
+ for (const mode of ['auto', 'weakest', 'low', 'weakest', 'high', 'low']) {
372
+ h.system.tiers?.set(mode);
373
+ h.frame();
374
+ const weakest = mode === 'weakest', high = mode === 'high';
375
+ assert.equal(h.system.tiers.handle.profile, weakest ? 'weakest' : high ? 'high' : 'middle');
376
+ assert.equal(h.ratio(), weakest ? 0.5 : high ? 2 : 1);
377
+ assert.equal(h.scene.three.composer._pixelRatio, h.ratio());
378
+ assert.equal(h.scene.isActorSleeping(h.right), !high);
379
+ assert.equal(h.scene.files === h.files, !weakest);
380
+ assert.equal(Object.hasOwn(h.scene, 'bakesLookLater'), weakest);
381
+ assert.equal(Object.hasOwn(h.scene, 'dropsEmptyParts'), weakest);
382
+ assert.equal(Object.hasOwn(h.scene.three.lookBake ?? {}, 'skipSurfaceBakes'), weakest);
383
+ if (mode === 'auto') assert.equal(h.scene.three.lookBake, undefined, 'Middle never creates a bake queue');
384
+ }
385
+ assert.deepEqual(h.merges, [12, 12], 'only Weakest enabled merging');
386
+ h.Hub.deck.mergeFarAvatars = true;
387
+ h.frame();
388
+ assert.equal(h.merges.at(-1), Infinity, 'explicit merge opt-in keeps its normal policy on Middle');
389
+ h.system.weakestTier.restore();
390
+ assert.equal(h.ratio(), 2);
391
+ assert.equal(h.scene.getActors().length, h.scene.actors.size);
392
+ }
393
+ for (const invalid of [undefined, { version: 99 }]) {
394
+ const h = middleFixture();
395
+ h.scene.data.weakestDistricts = invalid;
396
+ h.frame();
397
+ assert.equal(h.system.weakestTier, undefined);
398
+ assert.equal(h.ratio(), 2);
399
+ assert.equal(h.scene.getActors().length, h.scene.actors.size);
400
+ }
401
+ for (const options of [{ enabled: false }, { gpu: 'Mali-G52 MC3' }]) {
402
+ const h = middleFixture(options);
403
+ h.frame();
404
+ assert.equal(h.system.tiers.middle(), false);
405
+ assert.equal(h.system.weakestTier, undefined);
406
+ assert.equal(h.ratio(), 2);
407
+ }
408
+ {
409
+ const h = middleFixture({ gpu: 'PowerVR Rogue GE8320' });
410
+ h.frame();
411
+ assert.equal(h.system.tiers.weakest(), true);
412
+ assert.equal(h.system.tiers.middle(), false);
413
+ assert.equal(h.ratio(), 0.5);
414
+ h.system.weakestTier.restore();
415
+ }
416
+ // Restoration only touches owned ratios, and wakes actors even after data edits.
417
+ {
418
+ const h = middleFixture();
419
+ h.frame();
420
+ h.setRatio(1.25);
421
+ h.scene.data = { ...h.scene.data };
422
+ h.system.weakestTier.restore();
423
+ assert.equal(h.ratio(), 1.25);
424
+ assert.equal(h.scene.three.composer._pixelRatio, 2);
425
+ assert.equal(h.scene.getActors().length, h.scene.actors.size);
426
+ h.frame();
427
+ h.scene.three.composer._pixelRatio = 1.75;
428
+ h.system.weakestTier.restore();
429
+ assert.equal(h.ratio(), 1.25);
430
+ assert.equal(h.scene.three.composer._pixelRatio, 1.75);
431
+ }
432
+ for (const leave of [
433
+ (h) => { h.scene.content = {}; },
434
+ (h) => { h.scene.requestedScene = 'scenes/door.scene'; },
435
+ (h) => { h.player.components.Transform.x = 40; },
436
+ (h) => { h.scene.data = { ...h.scene.data, weakestDistricts: { version: 99 } }; },
437
+ ]) {
438
+ const h = middleFixture();
439
+ h.frame();
440
+ assert.equal(h.scene.isActorSleeping(h.right), true);
441
+ leave(h);
442
+ h.frame(1);
443
+ assert.equal(h.system.weakestTier.active, false);
444
+ assert.equal(h.ratio(), 2);
445
+ assert.equal(h.scene.three.composer._pixelRatio, 2);
446
+ assert.equal(h.scene.getActors().length, h.scene.actors.size);
447
+ assert.equal(h.scene.files, h.files);
448
+ }
449
+ // Same apron/protected/hidden-template rules for both profiles.
450
+ for (const profile of ['middle', 'weakest']) {
451
+ const h = fixture(), controller = makeWeakestTier({ profile });
452
+ const extras = [
453
+ ['anchor', 14, { RouteAnchor: {} }, 0, false],
454
+ ['body', 14, { Body: { type: 'dynamic' } }, 0, false],
455
+ ['player', 14, { Player: {} }, 0, false],
456
+ ['apron', -6, {}, 0, false],
457
+ ['beyond', -5.9, {}, 0, true],
458
+ ['hidden', -10, {}, -100, true],
459
+ ];
460
+ h.scene.data.weakestDistricts = { ...spec, actors: [...spec.actors] };
461
+ for (const [id, x, components, y] of extras) {
462
+ h.scene.spawnActor({ id, components: { Transform: { x, y, z: 0 }, ...components } });
463
+ h.scene.data.weakestDistricts.actors.push({ id, districts: [id === 'hidden' ? 'left' : 'right'], origin: [x, 0], bounds: [x, 0, x, 0] });
464
+ }
465
+ controller.frame(h.scene, true, 0);
466
+ for (const [id, , , , sleeps] of extras) assert.equal(h.scene.isActorSleeping(h.scene.getActor(id)), sleeps, `${profile}: ${id}`);
467
+ controller.restore();
468
+ assert.equal(h.scene.getActors().length, h.scene.actors.size);
469
+ }
470
+
471
+ // Run the actual goal/label collection and chrome.setPointers pass. Current
472
+ // target NPCs wake even when a new label arrives inside the 100 ms sleep tick.
473
+ const labelStart = hubSource.indexOf(' for (const [id, label] of Object.entries');
474
+ const labelLoop = hubSource.slice(labelStart, hubSource.indexOf(' // In a town only', labelStart));
475
+ const pointerStart = hubSource.indexOf(' const pointerView =');
476
+ const pointerPass = hubSource.slice(pointerStart, hubSource.indexOf('\n if (cam && idle)', pointerStart));
477
+ const drawPointers = new Function('Hub', 'scene', 'goalAt', 'goalPointers', 'goalText', 'pointerAt', `
478
+ const goals = [], placed = [], talkingWith = null;
479
+ ${labelLoop}
480
+ const view = { w: 800, h: 600 }, cam = scene.three.camera, idle = true, place = {}, inGame = false;
481
+ const local = scene.actorWith('Player'), GOALS_MAX = 2, GOAL_NEAR_M = 6;
482
+ const offsetWorldPoint = (point) => point;
483
+ let points;
484
+ const chrome = { setPointers: (value) => { points = value; } };
485
+ ${pointerPass}
486
+ return { points, placed };
487
+ `);
488
+ for (const mode of ['low', 'weakest']) {
489
+ const h = middleFixture();
490
+ h.right.components.HubNpc = {};
491
+ h.frame();
492
+ h.system.tiers.set(mode);
493
+ h.frame(1);
494
+ assert.equal(h.scene.isActorSleeping(h.right), true);
495
+ assert.equal(h.scene.isActorSleeping(h.scene.getActor('door')), true, `${mode}: unlabelled far door sleeps`);
496
+ h.Hub.hub.labelsMe = { 'right-wall': { style: 'goal', text: 'Market stamp', distanceM: 55 } };
497
+ h.Hub.hub.labels = { door: { style: 'sign', text: 'Market' } };
498
+ h.frame(2);
499
+ assert.equal(h.scene.isActorSleeping(h.right), false, `${mode}: target NPC wakes`);
500
+ assert.equal(h.scene.isActorSleeping(h.scene.getActor('door')), mode === 'weakest',
501
+ `${mode}: only Middle wakes a far shared-label target immediately`);
502
+ h.frame(150);
503
+ assert.equal(h.scene.isActorSleeping(h.right), false, `${mode}: goal target stays awake across district checks`);
504
+ assert.equal(h.scene.isActorSleeping(h.scene.getActor('door')), mode === 'weakest',
505
+ `${mode}: far shared-label target follows the profile's protection rule`);
506
+ const { points, placed } = drawPointers.call({ pendingEnd: null, together: { pointers: () => [] } },
507
+ h.Hub, h.scene, goalAt, goalPointers, goalText, pointerAt);
508
+ assert.equal(points.length, 1);
509
+ assert.equal(points[0].id, 'goal:right-wall');
510
+ assert.equal(points[0].text, 'Market stamp · 55 m');
511
+ assert.ok(Number.isFinite(points[0].x) && Number.isFinite(points[0].y));
512
+ assert.equal(placed[0].id, 'door');
513
+ assert.equal(placed[0].at, h.scene.getActor('door').components.Transform);
514
+ h.Hub.hub.labelsMe = {};
515
+ h.Hub.hub.labels = {};
516
+ h.frame(300);
517
+ assert.equal(h.scene.isActorSleeping(h.right), true, 'removed targets can sleep again');
518
+ h.system.weakestTier.restore();
519
+ }
520
+ // Other players are never put to sleep: party members, players on this
521
+ // player's pad and recent chatters are remote avatars, which carry no district
522
+ // row, so a far one stays live, and Middle never merges them.
523
+ for (const mode of ['low', 'weakest']) {
524
+ const h = middleFixture();
525
+ for (const [id, x] of [['party-peer', 14], ['pad-peer', 16], ['chat-peer', 18]]) {
526
+ h.scene.spawnActor({ id, components: { Transform: { x, y: 0, z: 0 }, HubAvatar: {} } });
527
+ }
528
+ h.frame();
529
+ h.system.tiers.set(mode);
530
+ h.frame(1);
531
+ h.frame(300);
532
+ assert.equal(h.scene.isActorSleeping(h.right), true, `${mode}: far district asleep`);
533
+ for (const id of ['party-peer', 'pad-peer', 'chat-peer']) {
534
+ assert.equal(h.scene.isActorSleeping(h.scene.getActor(id)), false, `${mode}: ${id} stays awake`);
535
+ }
536
+ if (mode === 'low') assert.deepEqual(h.merges, [], 'Middle leaves remote players unmerged');
537
+ h.system.weakestTier.restore();
538
+ }
539
+ // A pad on the active guide route stays awake in a far district while it is
540
+ // labelled for this player, and may sleep again once the guide moves on.
541
+ for (const mode of ['low', 'weakest']) {
542
+ const h = middleFixture();
543
+ h.scene.data.weakestDistricts = { ...spec, actors: [...spec.actors,
544
+ { id: 'route-pad', districts: ['right'], origin: [16, 0], bounds: [15, -1, 17, 1] }] };
545
+ h.scene.spawnActor({ id: 'route-pad', components: { Transform: { x: 16, y: 0, z: 0 }, HubPad: {} } });
546
+ h.frame();
547
+ h.system.tiers.set(mode);
548
+ h.frame(1);
549
+ const pad = h.scene.getActor('route-pad');
550
+ assert.equal(h.scene.isActorSleeping(pad), true, `${mode}: unlabelled far pad sleeps`);
551
+ h.Hub.hub.labelsMe = { 'route-pad': { style: 'sign', text: 'Step on the pad' } };
552
+ h.frame(2);
553
+ assert.equal(h.scene.isActorSleeping(pad), false, `${mode}: guide-route pad wakes`);
554
+ h.frame(300);
555
+ assert.equal(h.scene.isActorSleeping(pad), false, `${mode}: guide-route pad stays awake across district checks`);
556
+ h.Hub.hub.labelsMe = {};
557
+ h.frame(500);
558
+ assert.equal(h.scene.isActorSleeping(pad), true, `${mode}: pad sleeps after the guide moves on`);
559
+ h.system.weakestTier.restore();
560
+ }
561
+ console.log('middle tier: GPU selection, half Low buffers, sleep-only policy, transitions, ownership and far quest pointers passed');
562
+
563
+ assert.equal(f.scene.actors.size, 4);
564
+ tier.frame(f.scene, true, 0);
565
+ assert.equal(tier.active, true);
566
+ assert.equal(tier.district, 'left');
567
+ assert.equal(
568
+ f.scene.getActors().some((a) => a.id === 'right-wall'),
569
+ false,
570
+ );
571
+ assert.equal(
572
+ f.scene.getActors().some((a) => a.id === 'door'),
573
+ false,
574
+ );
575
+ assert.equal(f.scene.data, f.data);
576
+ assert.equal(f.data.actors.length, 4);
577
+ assert.equal(f.scene.bakesLookLater, true);
578
+ assert.equal(f.scene.dropsEmptyParts, true);
579
+ const cheap = JSON.parse(f.scene.files['models/m.pxmodel']);
580
+ assert.deepEqual(cheap, JSON.parse(f.files['models/m.pxmodel']));
581
+ assert.notEqual(f.scene.files['models/m.pxmodel'], f.files['models/m.pxmodel']);
582
+ assert.equal(JSON.parse(f.files['models/m.pxmodel']).look.ao, undefined);
583
+ f.player.components.Transform.x = 12;
584
+ tier.frame(f.scene, true, 50);
585
+ assert.equal(tier.district, 'right');
586
+ assert.equal(f.scene.actors.get('right-wall'), f.right);
587
+ assert.equal(
588
+ f.scene.getActors().some((a) => a.id === 'left-wall'),
589
+ false,
590
+ );
591
+ f.player.components.Transform.x = 40;
592
+ tier.frame(f.scene, true, 60);
593
+ assert.equal(tier.active, false);
594
+ assert.equal(f.scene.actors.get('left-wall'), f.left);
595
+ assert.equal(f.scene.files, f.files);
596
+ assert.equal(Object.hasOwn(f.scene, 'bakesLookLater'), false);
597
+ assert.equal(Object.hasOwn(f.scene, 'dropsEmptyParts'), false);
598
+ assert.equal(f.scene.dropsEmptyParts, false);
599
+ // Replaced ids, scene loads, mounted content, and externally changed files.
600
+ f.player.components.Transform.x = -10;
601
+ tier.frame(f.scene, true, 100);
602
+ const replacement = inert('right-wall', 16);
603
+ const spawned = f.scene.spawnActor(replacement);
604
+ tier.restore();
605
+ assert.equal(f.scene.actors.get('right-wall'), spawned);
606
+ tier.frame(f.scene, true, 200);
607
+ f.scene.load({ actors: [] });
608
+ tier.restore();
609
+ assert.equal(f.scene.actors.size, 0);
610
+ const g = fixture();
611
+ tier.frame(g.scene, true, 300);
612
+ g.scene.content = {};
613
+ tier.frame(g.scene, true, 301);
614
+ assert.equal(g.scene.actors.size, 4);
615
+ assert.equal(g.scene.files, g.files);
616
+ console.log(
617
+ 'weakest tier: deterministic selection, exact parked state, source/editor isolation, switches, and malformed data passed',
618
+ );
619
+
620
+ // Generic sleeping keeps ID lookup and serialization complete but pauses
621
+ // behavior passes, and spawns/despawns/loads cannot inherit stale sleep state.
622
+ {
623
+ class Counter {
624
+ static behaviorName = 'Counter';
625
+ update(actor) {
626
+ actor.runtime.calls = (actor.runtime.calls ?? 0) + 1;
627
+ }
628
+ }
629
+ const r = new SceneRuntime(
630
+ {
631
+ actors: [
632
+ { id: 'a', components: { Counter: {} } },
633
+ { id: 'b', components: { Counter: {} } },
634
+ ],
635
+ },
636
+ [Counter],
637
+ {},
638
+ {},
639
+ );
640
+ const b = r.getActor('b');
641
+ r.update(0.1);
642
+ const before = r.serialize();
643
+ assert.equal(r.setActorSleeping('b', true), true);
644
+ assert.equal(r.getActor('b'), b);
645
+ assert.deepEqual(r.serialize(), before);
646
+ r.update(0.1);
647
+ assert.equal(b.runtime.calls, 1);
648
+ assert.equal(r.getActor('a').runtime.calls, 2);
649
+ r.setActorSleeping(b, false);
650
+ r.update(0.1);
651
+ assert.equal(b.runtime.calls, 2);
652
+ r.setActorSleeping(b, true);
653
+ r.despawnActor('b');
654
+ const replacement = r.spawnActor({ id: 'b', components: { Counter: {} } });
655
+ assert.equal(r.setActorSleeping(b, false), false);
656
+ assert.ok(r.getActors().includes(replacement));
657
+ r.setActorSleeping(replacement, true);
658
+ r.load({ actors: [{ id: 'c', components: { Counter: {} } }] });
659
+ assert.deepEqual(
660
+ r.getActors().map((a) => a.id),
661
+ ['c'],
662
+ );
663
+ }
664
+ console.log('real runtime sleeping: ID lookup, behavior pause, serialization and ID reuse passed');
665
+
666
+ // Build gameplay caches while a far district sleeps, then return to it without
667
+ // changing the scene key, data, actor Map or its size. Use the production trip
668
+ // reveal and swing methods so the sleeping return door must actually close.
669
+ {
670
+ const method = (name) => {
671
+ const start = hubSource.indexOf(` ${name}(`);
672
+ return hubSource.slice(start, hubSource.indexOf('\n }\n', start) + 4).trim();
673
+ };
674
+ const helper = (name) => {
675
+ const start = hubSource.indexOf(`function ${name}(`);
676
+ return hubSource.slice(start, hubSource.indexOf('\n}\n', start) + 2);
677
+ };
678
+ const constants = ['REVEAL_MS', 'DOOR_SWING_DEG', 'clamp01', 'ease']
679
+ .map((name) => hubSource.match(new RegExp(`^const ${name} = .*;$`, 'm'))[0]).join('\n');
680
+ const doors = new Function('allActors', 'doorPoint', `${constants}
681
+ ${helper('doorActor')}
682
+ ${helper('isCabinet')}
683
+ return { doorActor, stepTrip: function ${method('stepTrip')}, swingDoor: function ${method('swingDoor')} };`)(allActors, doorPoint);
684
+ assert.deepEqual(allActors({ getActors: () => ['fallback'] }), ['fallback']);
685
+ assert.deepEqual(allActors({ actors: new Map(), getActors: () => ['awake'] }), []);
686
+ const previousQuality = deck.quality;
687
+ try {
688
+ for (const profile of ['weakest', 'middle']) {
689
+ clearHub();
690
+ delete deck.quality;
691
+ const h = fixture(), controller = makeWeakestTier({ profile });
692
+ const { scene, player } = h;
693
+ const door = scene.getActor('door');
694
+ door.components.HubDoor.id = 'gems';
695
+ const closed = structuredClone(door.components.Transform);
696
+ const trip = { phase: 'revealing', target: { arriveDoor: 'gems' }, startedAt: 0, revealAt: 0, marks: {} };
697
+ let finished = false;
698
+ const owner = { trip, doorBase: new Map(), swingDoor: doors.swingDoor,
699
+ setTripCover() {}, showLeaving() {}, finishTrip() { finished = true; } };
700
+ owner.swingDoor(door, 1, scene);
701
+ assert.equal(door.components.Transform.rotationY, 100);
702
+ for (const [id, component] of [['bench', 'HubSeat'], ['pad', 'HubPad'], ['npc', 'HubNpc']]) {
703
+ scene.spawnActor({ ...inert(id, 14), components: {
704
+ Transform: { x: 14, y: 0, z: 0 }, [component]: {},
705
+ Shape: { kind: 'box', width: 2.4, depth: 0.6 },
706
+ } });
707
+ }
708
+ scene.spawnActor({ id: 'guest', components: { Transform: { x: 15, z: 0 } } });
709
+ scene.data.weakestDistricts = { ...spec, actors: [...spec.actors,
710
+ ...['bench', 'pad', 'npc'].map((id) => ({ ...spec.actors[1], id }))] };
711
+ const q = makeQualityVisit({ current: () => 'low' });
712
+ filterQualityScene(scene, scene.data, q);
713
+ deck.quality = { low: { players: 0 } };
714
+ const sent = [], prompts = [];
715
+ let pressSit;
716
+ const mp = { net: { selfId: () => 'me', send: (msg) => sent.push(msg) },
717
+ avatars: { actors: new Map([['guest-player', 'guest']]) } };
718
+ scene.multiplayer = mp;
719
+ hub.place = { idle: { seats: true } };
720
+ const idle = makeIdle({ onSit: (fn) => { pressSit = fn; }, sitPrompt: (label) => prompts.push(label) });
721
+ controller.frame(scene, true, 0);
722
+ for (const id of ['door', 'bench', 'pad', 'npc']) {
723
+ assert.equal(scene.isActorSleeping(scene.getActor(id)), true, `${profile}: ${id} sleeps`);
724
+ assert.ok(!scene.getActors().includes(scene.getActor(id)));
725
+ assert.ok(allActors(scene).includes(scene.getActor(id)));
726
+ }
727
+ assert.equal(doors.doorActor(scene, 'gems'), 'door', `${profile}: sleeping door lookup`);
728
+ assert.equal(doors.doorActor(scene, 'missing'), null);
729
+ doors.stepTrip.call(owner, scene, mp, player, 700);
730
+ assert.equal(finished, true);
731
+ assert.equal(scene.isActorSleeping(door), true, 'closing does not wake the door');
732
+ assert.deepEqual(door.components.Transform, { ...closed, rotationY: 0 }, `${profile}: return closes sleeping door`);
733
+ idle.frame(scene, mp, player, true, 'town');
734
+ assert.equal(prompts.at(-1), null);
735
+ qualityPlayers(scene, q, 0);
736
+ assert.ok(q.culled.has('guest'), 'far guest uses no player slot');
737
+ const pads = q.pads;
738
+ const npcs = talkActors(scene);
739
+ assert.ok(pads.includes(scene.getActor('pad')), `${profile}: pad cached while asleep`);
740
+ assert.ok(npcs.includes(scene.getActor('npc')), `${profile}: NPC cached while asleep`);
741
+ const npcCache = q.npcs;
742
+ const count = scene.actors.size;
743
+ player.components.Transform.x = 14 + 1.2 + SIT_OFFER_M - 0.01;
744
+ controller.frame(scene, true, 500);
745
+ assert.equal(scene.actors.size, count);
746
+ for (const id of ['door', 'bench', 'pad', 'npc']) {
747
+ assert.equal(scene.isActorSleeping(scene.getActor(id)), false, `${profile}: ${id} wakes`);
748
+ }
749
+ assert.deepEqual(scene.getActor('door').components.Transform, { ...closed, rotationY: 0 }, 'wake keeps the closed pose');
750
+ idle.frame(scene, mp, player, true, 'town');
751
+ assert.equal(prompts.at(-1), 'Sit', `${profile}: cached sleeping bench offered on wake`);
752
+ pressSit();
753
+ idle.frame(scene, mp, player, true, 'town');
754
+ assert.deepEqual(sent.at(-1), { k: 'hub-sit', seat: 'bench' });
755
+ player.components.Transform.x = 14;
756
+ qualityPlayers(scene, q, 500);
757
+ assert.equal(q.pads, pads);
758
+ assert.equal(samePad(scene, player.components.Transform, scene.getActor('guest').components.Transform, pads), true);
759
+ assert.ok(q.drawn.has('guest-player'), `${profile}: cached pad exempts nearby guest`);
760
+ assert.deepEqual(talkActors(scene), [scene.getActor('npc')]);
761
+ assert.equal(q.npcs, npcCache);
762
+ // Preserve talkActors' live ID resolution even if its cache is retained.
763
+ scene.despawnActor('npc');
764
+ scene.spawnActor(inert('replacement', 14));
765
+ assert.deepEqual(talkActors(scene), []);
766
+ assert.equal(q.npcs, npcCache);
767
+ idle.dispose();
768
+ controller.restore();
769
+ }
770
+ } finally {
771
+ if (previousQuality === undefined) { delete deck.quality; } else { deck.quality = previousQuality; }
772
+ clearHub();
773
+ }
774
+ }
775
+ console.log('sleeping gameplay: Weakest/Middle return doors close, benches offer Sit, pad/NPC caches survive wake passed');
776
+
777
+ for (const weakest of [false, true]) {
778
+ const t = makeTiers({ weakest, storage: null });
779
+ assert.equal(t.set('weakest'), weakest);
780
+ if (weakest) {
781
+ assert.equal(t.current(), 'low');
782
+ assert.equal(t.weakest(), true);
783
+ }
784
+ }
785
+
786
+ // Mode toggles use authored bounds even after gameplay moves a wall.
787
+ {
788
+ const h = fixture(),
789
+ controller = makeWeakestTier();
790
+ h.right.components.Transform.x = -10;
791
+ controller.frame(h.scene, true, 0);
792
+ assert.ok(h.scene.getActors().includes(h.right));
793
+ h.scene.files['models/generated.pxmodel'] = JSON.stringify({ parts: [], look: { outline: 2 } });
794
+ const generatedDuringWeakest = h.scene.files['models/generated.pxmodel'];
795
+ controller.restore();
796
+ assert.notEqual(h.scene.files['models/generated.pxmodel'], generatedDuringWeakest);
797
+ assert.equal(JSON.parse(h.scene.files['models/generated.pxmodel']).look.outline, 2);
798
+ controller.frame(h.scene, true, 1000);
799
+ assert.ok(h.scene.getActors().includes(h.right));
800
+ const packed = JSON.parse(h.scene.files['models/m.pxmodel']);
801
+ controller.restore();
802
+ assert.deepEqual(packed, JSON.parse(h.scene.files['models/m.pxmodel']));
803
+ }
804
+ // v1.121: real engine queue ordering/drain, with body/accessory geometries.
805
+ {
806
+ const { makeLookBake, queueLookBake, stepLookBake } = await import('../../physics-3d/engine3d/lookbake.js');
807
+ const { makeWeakestLookBake } = await import('../code/client/weakestLookBake.js');
808
+ const THREE = await import('three');
809
+ const queue = makeLookBake();
810
+ let clock = 0;
811
+ queue.now = () => clock;
812
+ const add = (owner) => {
813
+ const geometry = new THREE.BufferGeometry();
814
+ queueLookBake(queue, owner, [geometry], function* () { clock += 2; yield; clock += 2; });
815
+ return geometry;
816
+ };
817
+ const far = add('far'), near = add('near'), own = add('self'), hat = add('shared-hat');
818
+ add('unknown');
819
+ const actor = (id, x) => ({ id, components: { Transform: { x, z: 0 } } });
820
+ const actors = new Map([['self', actor('self', 100)], ['near', actor('near', 101)], ['far', actor('far', 200)]]);
821
+ const node = (...geometries) => { const root = new THREE.Group(); for (const geometry of geometries) root.add(new THREE.Mesh(geometry)); return root; };
822
+ const scene = {
823
+ actorWith: () => actors.get('self'), getActor: (id) => actors.get(id),
824
+ multiplayer: { placed: () => true },
825
+ three: { scene: new THREE.Scene(), nodes: new Map([
826
+ ['far', { modelKey: 'far', node: node(far, hat) }],
827
+ ['near', { modelKey: 'near', node: node(near) }],
828
+ ['self', { modelKey: 'self', node: node(own, hat) }],
829
+ ]) },
830
+ };
831
+ const policy = makeWeakestLookBake(queue);
832
+ policy.frame(scene, 0);
833
+ assert.deepEqual(queue.tasks.map((t) => t.owner), ['self', 'shared-hat', 'near', 'far', 'unknown']);
834
+ assert.equal(queue.budgetMs, 24);
835
+ assert.equal(queue.hubWeakest.placedAt, 0);
836
+ const renderTarget = scene.three.scene;
837
+ const installedAfter = renderTarget.onAfterRender;
838
+ // Real render-loop order: hub policy ran, then sync adds a model. The
839
+ // Three scene callback runs after drawing and before engine queue stepping.
840
+ const justSynced = add('new-self-accessory');
841
+ scene.three.nodes.get('self').node.add(new THREE.Mesh(justSynced));
842
+ assert.equal(queue.unsorted, true);
843
+ renderTarget.onAfterRender();
844
+ assert.equal(queue.unsorted, false);
845
+ assert.deepEqual(queue.tasks.slice(0, 3).map((t) => t.owner), ['self', 'shared-hat', 'new-self-accessory']);
846
+ const lateHat = add('late-hat');
847
+ scene.three.nodes.get('self').node.add(new THREE.Mesh(lateHat));
848
+ policy.frame(scene, 100);
849
+ assert.deepEqual(queue.tasks.slice(0, 3).map((t) => t.owner), ['self', 'shared-hat', 'new-self-accessory']);
850
+ const copy = own.clone();
851
+ scene.three.nodes.get('self').node.add(new THREE.Mesh(copy));
852
+ assert.ok(queue.tasks.find((t) => t.owner === 'self').geometries.includes(copy));
853
+ queue.tasks.find((t) => t.owner === 'far').started = true;
854
+ actors.get('near').components.Transform.x = 300;
855
+ policy.frame(scene, 350);
856
+ assert.equal(queue.tasks[0].owner, 'far');
857
+ policy.frame(scene, 15000);
858
+ assert.equal(queue.budgetMs, 32);
859
+ assert.equal(queue.hubWeakest.budgetMs, 32);
860
+ stepLookBake(queue);
861
+ assert.equal(queue.pending, 7);
862
+ while (queue.pending) stepLookBake(queue);
863
+ assert.equal(queue.baked, 7);
864
+ assert.equal(queue.shown, false);
865
+ stepLookBake(queue);
866
+ assert.equal(queue.shown, true);
867
+ policy.frame(scene, 16000);
868
+ assert.equal(queue.hubWeakest.shown, true);
869
+ policy.restore();
870
+ assert.notEqual(renderTarget.onAfterRender, installedAfter);
871
+ assert.equal(Object.hasOwn(renderTarget, 'onAfterRender'), false);
872
+ assert.equal(queue.budgetMs, 6);
873
+ assert.equal(Object.hasOwn(queue, 'hubWeakest'), false);
874
+ }
875
+ for (const bounded of [false, true]) {
876
+ const h = fixture(), controller = makeWeakestTier();
877
+ const { makeLookBake } = await import('../../physics-3d/engine3d/lookbake.js');
878
+ const queue = makeLookBake();
879
+ h.scene.three = { lookBake: queue, nodes: new Map() };
880
+ h.scene.multiplayer = { placed: () => false };
881
+ controller.frame(h.scene, true, 0, bounded);
882
+ assert.equal(queue.skipSurfaceBakes, !bounded);
883
+ assert.equal(queue.budgetMs, bounded ? 24 : 6);
884
+ assert.equal(Object.hasOwn(queue, 'hubWeakest'), bounded);
885
+ assert.equal(h.scene.bakesLookLater, true);
886
+ if (bounded) {
887
+ controller.frame(h.scene, true, 1, false);
888
+ assert.equal(queue.skipSurfaceBakes, true);
889
+ assert.equal(queue.budgetMs, 6);
890
+ assert.equal(Object.hasOwn(queue, 'hubWeakest'), false);
891
+ }
892
+ controller.restore();
893
+ assert.equal(queue.budgetMs, 6);
894
+ assert.equal(Object.hasOwn(queue, 'skipSurfaceBakes'), false);
895
+ assert.equal(Object.hasOwn(queue, 'hubWeakest'), false);
896
+ assert.equal(h.scene.files, h.files);
897
+ assert.equal(Object.hasOwn(h.scene, 'bakesLookLater'), false);
898
+ }
899
+ console.log('bounded Weakest look: self/accessory/distance ordering, real drain and exact restoration passed');
900
+
901
+ {
902
+ const { makeLookBake } = await import('../../physics-3d/engine3d/lookbake.js');
903
+ const { makeWeakestLookBake } = await import('../code/client/weakestLookBake.js');
904
+ const THREE = await import('three');
905
+ for (const replaced of [false, true]) {
906
+ const target = new THREE.Scene(), queue = makeLookBake();
907
+ let calls = 0;
908
+ const prior = function (arg) { assert.equal(this, target); assert.equal(arg, 'draw'); calls += 1; };
909
+ target.onAfterRender = prior;
910
+ const policy = makeWeakestLookBake(queue);
911
+ policy.frame({ three: { scene: target }, multiplayer: { placed: () => false } }, 0);
912
+ const installed = target.onAfterRender;
913
+ target.onAfterRender('draw');
914
+ assert.equal(calls, 1);
915
+ const replacement = function (...args) { installed.apply(this, args); };
916
+ if (replaced) target.onAfterRender = replacement;
917
+ queue.budgetMs = 17; // another owner changed it; restore must not clobber.
918
+ policy.restore();
919
+ assert.equal(target.onAfterRender, replaced ? replacement : prior);
920
+ assert.equal(queue.budgetMs, 17);
921
+ target.onAfterRender('draw');
922
+ assert.equal(calls, 2);
923
+ }
924
+ }