@wildshard/engine 0.1.18 → 0.1.20

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 (334) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/budgets/shard-size-baseline.json +10 -4
  3. package/index.html +6 -4
  4. package/lint/engine-sides.json +18 -0
  5. package/lint/ratchet.json +0 -68
  6. package/lint/ratchet.mjs +1 -4
  7. package/package.json +19 -15
  8. package/scripts/agent-sync.mjs +27 -8
  9. package/scripts/app-build/appCook.ts +8 -2
  10. package/scripts/app-build/catalogue.ts +10 -7
  11. package/scripts/app-build/gen.ts +33 -2
  12. package/scripts/app-build/isolation.d.mts +10 -0
  13. package/scripts/app-build/isolation.mjs +47 -0
  14. package/scripts/app-build/outputProducts.mjs +4 -0
  15. package/scripts/app-build/previousDeploy.d.mts +2 -0
  16. package/scripts/app-build/previousDeploy.mjs +10 -1
  17. package/scripts/app-build/serviceWorker.ts +10 -3
  18. package/scripts/app-build/splitOutput.mjs +4 -2
  19. package/scripts/app-build/standaloneOutput.d.mts +1 -1
  20. package/scripts/app-build/standaloneOutput.mjs +5 -3
  21. package/scripts/app-build/titlePreloads.d.mts +8 -0
  22. package/scripts/app-build/titlePreloads.mjs +69 -0
  23. package/scripts/app-build/worldMapAtlas.ts +10 -6
  24. package/scripts/app-build-pipeline.mjs +31 -3
  25. package/scripts/built-product.mjs +1 -1
  26. package/scripts/cell-mem-bench.mjs +83 -23
  27. package/scripts/check-custom-sections-zero.mjs +1 -1
  28. package/scripts/check-devserver.mjs +2 -0
  29. package/scripts/check-models.mjs +2 -0
  30. package/scripts/check-paths.allow.json +0 -115
  31. package/scripts/check-paths.mjs +2 -2
  32. package/scripts/check-platform-ratchets.mjs +2 -3
  33. package/scripts/chromium-keychain.d.mts +1 -1
  34. package/scripts/ci-static.sh +1 -1
  35. package/scripts/committed-fast-checks.mjs +0 -2
  36. package/scripts/content-sw-proof.mjs +2 -1
  37. package/scripts/cook-worker.mjs +9 -3
  38. package/scripts/cook.mjs +18 -5
  39. package/scripts/docs-inputs-proof.mjs +6 -6
  40. package/scripts/e7-voice-staging-proof.mjs +1 -1
  41. package/scripts/gate-related-tests.mjs +1 -1
  42. package/scripts/git-source-view.mjs +1 -1
  43. package/scripts/goldens/capture.mjs +17 -5
  44. package/scripts/grid-crossing-nightly.mjs +59 -0
  45. package/scripts/grid-crossing-qa.mjs +44 -0
  46. package/scripts/grid-crossing-ratchet.d.mts +6 -0
  47. package/scripts/grid-crossing-ratchet.mjs +52 -0
  48. package/scripts/grid-crossing-report.mjs +122 -0
  49. package/scripts/grid-crossing-stages.mjs +47 -0
  50. package/scripts/grid-crossing-tour.mjs +284 -0
  51. package/scripts/grid-crossing-walk-proof.mjs +126 -17
  52. package/scripts/host-ruler/roots.mjs +2 -2
  53. package/scripts/host-ruler.d.mts +91 -0
  54. package/scripts/host-ruler.mjs +565 -0
  55. package/scripts/land.mjs +2 -1
  56. package/scripts/live-prepush.py +3 -5
  57. package/scripts/loading-flow/benchmax.mjs +37 -12
  58. package/scripts/loading-flow/deskbench.mjs +276 -0
  59. package/scripts/loading-flow/stalls.d.mts +17 -3
  60. package/scripts/loading-flow/stalls.mjs +82 -3
  61. package/scripts/look-loop/test_look_loop.py +1 -38
  62. package/scripts/memory-proof.mjs +61 -6
  63. package/scripts/mmo-bots.mjs +8 -2
  64. package/scripts/net-lag-proof.mjs +219 -0
  65. package/scripts/night-market-kit-budget.mjs +2 -2
  66. package/scripts/nightly-model.ts +9 -6
  67. package/scripts/offline-proof-rules.d.mts +2 -2
  68. package/scripts/offline-proof-rules.mjs +15 -4
  69. package/scripts/offline-proof.mjs +80 -13
  70. package/scripts/{shard-platform-output.mjs → output-reader.mjs} +1 -1
  71. package/scripts/page-release/content.d.mts +9 -1
  72. package/scripts/page-release/content.mjs +131 -17
  73. package/scripts/page-release/flow.mjs +36 -10
  74. package/scripts/page-release/stamp-content.mjs +24 -0
  75. package/scripts/page-release.mjs +28 -6
  76. package/scripts/page-size.mjs +2 -1
  77. package/scripts/parity/boot-smoke.mjs +13 -2
  78. package/scripts/pin-format.ts +5 -2
  79. package/scripts/pin-packs.ts +1 -1
  80. package/scripts/pins-reuse.d.mts +1 -0
  81. package/scripts/pins-reuse.mjs +22 -0
  82. package/scripts/pins.ts +4 -4
  83. package/scripts/precommit-checks.mjs +1 -7
  84. package/scripts/precommit-jobs.mjs +0 -1
  85. package/scripts/precommit-source.py +1 -9
  86. package/scripts/program-discovery.mjs +1 -1
  87. package/scripts/ring-cook.mjs +2 -1
  88. package/scripts/ring-step.ts +1 -1
  89. package/scripts/scratch-dir.mjs +95 -0
  90. package/scripts/scratch-sweep.mjs +182 -0
  91. package/scripts/script-scenario-metrics.mjs +1 -1
  92. package/scripts/shard-output-content.d.mts +1 -1
  93. package/scripts/shard-output-content.mjs +2 -2
  94. package/scripts/shard-outputs.mjs +1 -1
  95. package/scripts/shard-public.mjs +1 -1
  96. package/scripts/shard-wire-meter.mjs +24 -9
  97. package/scripts/side-parity.mjs +4 -2
  98. package/scripts/standalone-smoke.mjs +8 -3
  99. package/scripts/tier-textures.mjs +22 -4
  100. package/scripts/tile-bake-report.mjs +1 -1
  101. package/scripts/tile-bakes.mjs +1 -1
  102. package/scripts/title-assets.generated.json +2 -0
  103. package/scripts/tsconfig.json +2 -14
  104. package/scripts/vendor/basisu/LICENSE +201 -0
  105. package/scripts/vendor/basisu/basis_encoder.cjs +2 -0
  106. package/scripts/vendor/basisu/basis_encoder.wasm +0 -0
  107. package/scripts/vitest-push-guards.config.ts +1 -1
  108. package/scripts/vps/harden-apply.sh +4 -1
  109. package/scripts/vps/harden-prometheus.sh +179 -0
  110. package/scripts/vps/harden.sh +16 -0
  111. package/scripts/vps/rebuild.sh +18 -0
  112. package/scripts/vps/wildshard-config +6 -2
  113. package/scripts/worker-client-play.mjs +6 -2
  114. package/scripts/worktree-reap.mjs +59 -13
  115. package/scripts/worktree.mjs +19 -5
  116. package/src/.oxlintrc.json +3 -182
  117. package/src/client/app/entry.ts +10 -2
  118. package/src/client/engine/anim/rigParser.ts +2 -2
  119. package/src/client/engine/boot/bootCache.ts +2 -2
  120. package/src/client/engine/boot/bootTrace.ts +12 -4
  121. package/src/client/engine/boot/browserChunkRecovery.ts +4 -0
  122. package/src/client/engine/boot/clearDownloads.ts +5 -2
  123. package/src/client/engine/boot/contentRead.ts +11 -0
  124. package/src/client/engine/boot/gpuFiles.ts +4 -2
  125. package/src/client/engine/boot/lastEnd.ts +99 -12
  126. package/src/client/engine/boot/texturePack.ts +2 -2
  127. package/src/client/engine/core/Game.ts +63 -19
  128. package/src/client/engine/core/gpuOnly.ts +10 -0
  129. package/src/client/engine/core/renderBudget.ts +134 -0
  130. package/src/client/engine/net/netPlayer.ts +19 -2
  131. package/src/client/engine/net/otherPlayers.ts +55 -8
  132. package/src/client/engine/net/predictor.ts +33 -9
  133. package/src/client/engine/net/redial.ts +68 -10
  134. package/src/client/engine/pwa/cacheNames.ts +58 -1
  135. package/src/client/engine/pwa/sw.js +41 -11
  136. package/src/client/engine/render/dataLook.ts +219 -44
  137. package/src/client/engine/render/families/detail.ts +89 -0
  138. package/src/client/engine/render/families/pbr.ts +9 -1
  139. package/src/client/engine/render/families/registry.ts +11 -2
  140. package/src/client/engine/render/families/sceneSurface.ts +116 -0
  141. package/src/client/engine/render/look.ts +12 -0
  142. package/src/client/engine/render/lookLight.ts +103 -11
  143. package/src/client/engine/render/lookRender.ts +105 -0
  144. package/src/client/engine/render/precompile.ts +4 -2
  145. package/src/client/engine/render/tiers.ts +4 -1
  146. package/src/client/engine/saves/indexed.ts +2 -2
  147. package/src/client/engine/telemetry/browserErrors.ts +24 -3
  148. package/src/client/engine/telemetry/staleBuildReport.ts +22 -1
  149. package/src/client/engine/ui/debugOptions.ts +1 -1
  150. package/src/client/engine/ui/lookLightOption.ts +10 -6
  151. package/src/client/engine/ui/namePrompt.ts +7 -0
  152. package/src/client/engine/world/declaredProps.ts +5 -1
  153. package/src/client/engine/world/skyRig.ts +4 -1
  154. package/src/client/engine/world/terrainTileView.ts +64 -23
  155. package/src/client/game/boot/audio.generated.ts +114 -114
  156. package/src/client/game/boot/bytes.generated.ts +118 -220
  157. package/src/client/game/boot/placedSpawn.ts +35 -0
  158. package/src/client/game/boot/spawnDownload.ts +25 -6
  159. package/src/client/game/boot/versions.generated.ts +7 -5
  160. package/src/client/game/devScene/hook.ts +428 -0
  161. package/src/client/game/devScene/liveLook.ts +21 -0
  162. package/src/client/game/grid/cellLoading.ts +12 -2
  163. package/src/client/game/grid/live.ts +152 -19
  164. package/src/client/game/grid/liveSession.ts +53 -3
  165. package/src/client/game/grid/mapAtlas.ts +18 -4
  166. package/src/client/game/grid/minimapBlend.ts +15 -5
  167. package/src/client/game/grid/oneWayIn.ts +5 -1
  168. package/src/client/game/grid/pageEntry.ts +12 -1
  169. package/src/client/game/grid/placedCells.ts +114 -12
  170. package/src/client/game/grid/placedContent.ts +85 -0
  171. package/src/client/game/grid/prefetch.ts +9 -1
  172. package/src/client/game/grid/productInputs.ts +23 -10
  173. package/src/client/game/grid/productLeases.ts +4 -1
  174. package/src/client/game/grid/products.ts +8 -4
  175. package/src/client/game/grid/roadLook.ts +24 -15
  176. package/src/client/game/grid/roadLookPlatform.ts +4 -2
  177. package/src/client/game/grid/roadResources.ts +24 -0
  178. package/src/client/game/grid/roadSign.worker.ts +4 -3
  179. package/src/client/game/grid/roadSignPaint.ts +16 -5
  180. package/src/client/game/grid/roadSignPreparation.ts +4 -3
  181. package/src/client/game/grid/roadSignScale.ts +8 -0
  182. package/src/client/game/grid/roadTileCapture.worker.ts +3 -1
  183. package/src/client/game/grid/roadTileCaptureWorker.ts +2 -1
  184. package/src/client/game/grid/roadTileWrite.worker.ts +4 -2
  185. package/src/client/game/grid/roadTileWriter.ts +2 -1
  186. package/src/client/game/grid/screenReports.ts +39 -0
  187. package/src/client/game/grid/session.ts +32 -7
  188. package/src/client/game/grid/softWallLook.ts +25 -8
  189. package/src/client/game/mainMenu.ts +6 -2
  190. package/src/client/game/plugin/context.ts +2 -1
  191. package/src/client/game/plugin/followedMovers.ts +7 -1
  192. package/src/client/game/quest/figures.ts +2 -0
  193. package/src/client/game/session/finish.ts +9 -0
  194. package/src/client/game/shardfile/assetCache.ts +4 -4
  195. package/src/client/game/shardfile/client.ts +28 -8
  196. package/src/client/game/shardfile/clientAssets.ts +9 -5
  197. package/src/client/game/shardfile/clientLibrary.ts +1 -1
  198. package/src/client/game/shardfile/clientPropMaterials.ts +4 -1
  199. package/src/client/game/shardfile/clientViews.ts +36 -8
  200. package/src/client/game/shardfile/clientWater.ts +51 -9
  201. package/src/client/game/shardfile/clientWorker.ts +19 -7
  202. package/src/client/game/shardfile/constructionCheckpoint.ts +2 -2
  203. package/src/client/game/shardfile/groundMerge.ts +57 -5
  204. package/src/client/game/shardfile/hybrid.ts +2 -0
  205. package/src/client/game/shardfile/look.ts +8 -3
  206. package/src/client/game/shardfile/product.ts +34 -7
  207. package/src/client/game/shardfile/productChecks.ts +2 -2
  208. package/src/client/game/shardfile/productCost.ts +2 -2
  209. package/src/client/game/shardfile/readAsset.ts +2 -2
  210. package/src/client/game/shardfile/reflectingWater.ts +73 -0
  211. package/src/client/game/shardfile/seatGrace.ts +9 -0
  212. package/src/client/game/shardfile/skinPlayback.ts +1 -1
  213. package/src/client/game/shardfile/slabLibrary.ts +115 -49
  214. package/src/client/game/shardfile/tileContent.ts +1 -1
  215. package/src/client/game/shardfile/tileDriver.ts +38 -11
  216. package/src/client/game/shardfile/wirePage.ts +7 -3
  217. package/src/client/game/shardfile/worldScenes.ts +17 -10
  218. package/src/client/game/systems/npc/figureRows.ts +9 -0
  219. package/src/client/host/online/doctor.ts +22 -7
  220. package/src/client/host/online/doctorView.ts +2 -0
  221. package/src/client/host/online/linkScreens.ts +109 -5
  222. package/src/client/host/online/shell.ts +13 -4
  223. package/src/client/host/standalone/shell.ts +40 -0
  224. package/src/cook/game/astc6Encode.ts +55 -0
  225. package/src/cook/game/astc6Wasm.ts +176 -0
  226. package/src/cook/game/cookJob.ts +30 -6
  227. package/src/cook/game/cookWorker.ts +38 -11
  228. package/src/cook/game/entryTotals.ts +51 -24
  229. package/src/cook/game/shardCook.ts +35 -7
  230. package/src/cook/game/spawnParts.ts +33 -8
  231. package/src/cook/game/tierTextures.ts +87 -14
  232. package/src/server/engine/ai/bossContenders.ts +27 -3
  233. package/src/server/engine/ai/phases.ts +1 -1
  234. package/src/server/engine/entities/creatureRefill.ts +9 -2
  235. package/src/server/engine/net/ledgerBook.ts +2 -0
  236. package/src/server/engine/net/room.ts +15 -0
  237. package/src/server/engine/sim/respawn.ts +8 -0
  238. package/src/server/game/boss/arenaRoomEntry.ts +5 -1
  239. package/src/server/game/boss/arenaRoomNative.ts +2 -0
  240. package/src/server/game/boss/native.ts +2 -1
  241. package/src/server/game/boss/nativeWake.ts +9 -5
  242. package/src/server/game/boss/openArenaNative.ts +2 -2
  243. package/src/server/game/boss/openArenaRoom.ts +3 -1
  244. package/src/server/game/grid/room.ts +44 -3
  245. package/src/server/game/grid/simulation.ts +23 -0
  246. package/src/server/game/population/mixedRoster.ts +11 -3
  247. package/src/server/game/population/nativeBake.ts +8 -3
  248. package/src/server/game/population/nativeReturns.ts +6 -3
  249. package/src/server/game/population/roster.ts +5 -3
  250. package/src/server/game/quest/eliteDrops.ts +18 -3
  251. package/src/server/game/quest/nativeChapter.ts +1 -1
  252. package/src/server/game/quest/nativeComposition.ts +5 -1
  253. package/src/server/game/riding/nativeTaming.ts +22 -7
  254. package/src/server/game/riding/wildRefill.ts +3 -2
  255. package/src/server/game/shardfile/bossRow.ts +4 -2
  256. package/src/server/game/shardfile/homeKeeper.ts +4 -2
  257. package/src/server/host/bake/headlessWorker.ts +1 -1
  258. package/src/server/host/dedicated/cellHost.ts +112 -18
  259. package/src/server/host/dedicated/cellProtocol.ts +18 -1
  260. package/src/server/host/dedicated/cellWorker.ts +8 -5
  261. package/src/server/host/dedicated/dedicatedRoom.ts +38 -11
  262. package/src/server/host/dedicated/gridCells.ts +15 -6
  263. package/src/server/host/dedicated/loopLag.ts +21 -0
  264. package/src/server/host/dedicated/main.ts +13 -5
  265. package/src/server/host/dedicated/packReader.ts +3 -3
  266. package/src/server/host/dedicated/placementFile.ts +3 -2
  267. package/src/server/host/dedicated/roadRoom.ts +34 -4
  268. package/src/server/host/dedicated/serverMetrics.ts +135 -0
  269. package/src/server/host/dedicated/socketPump.ts +21 -4
  270. package/src/server/host/dedicated/workerTable.ts +32 -14
  271. package/src/server/host/dedicated/world.ts +65 -7
  272. package/src/server/host/headless.ts +1 -1
  273. package/src/server/host/headlessRuntime.ts +1 -1
  274. package/src/server/host/standalone/roadWorld.ts +15 -3
  275. package/src/server/host/standalone/serverHost.ts +57 -8
  276. package/src/server/host/standalone/serverProduct.ts +48 -16
  277. package/src/server/host/standalone/serverRuntime.ts +1 -1
  278. package/src/shared/engine/ai/BossBrain.ts +8 -0
  279. package/src/shared/engine/core/framePacing.ts +12 -1
  280. package/src/shared/engine/physics/terrainTiles.ts +20 -4
  281. package/src/shared/game/boss/wake.ts +6 -0
  282. package/src/shared/game/devColliders.ts +107 -0
  283. package/src/shared/game/devGameplay.ts +41 -0
  284. package/src/shared/game/eliteSystem.ts +8 -0
  285. package/src/shared/game/grid/allocator.ts +3 -0
  286. package/src/shared/game/grid/placementRows.ts +5 -2
  287. package/src/shared/game/plugin/bossRecord.ts +3 -2
  288. package/src/shared/game/shardfile/ktx2Targets.ts +23 -3
  289. package/src/shared/game/shardfile/outputDescriptor.ts +9 -5
  290. package/src/shared/game/shardfile/packReads.ts +28 -3
  291. package/src/shared/game/shardfile/serverPack.ts +9 -0
  292. package/src/shared/game/systems/looks/trampleField.ts +2 -0
  293. package/src/shared/host/formatJsonSchema.ts +2 -2
  294. package/src/tsconfig.json +1 -27
  295. package/lint/host-reviews.json +0 -14
  296. package/lint/listed-view-code.json +0 -13
  297. package/lint/platform-pending-users.json +0 -2520
  298. package/lint/platform-pending-users.md +0 -18
  299. package/scripts/cell-mem/metrics-preload.mjs +0 -65
  300. package/scripts/check-closed-components.d.mts +0 -7
  301. package/scripts/check-closed-components.mjs +0 -87
  302. package/scripts/g571-hosts.d.mts +0 -3
  303. package/scripts/g571-hosts.mjs +0 -54
  304. package/scripts/host-ruler/register-migrate.mjs +0 -242
  305. package/scripts/listed-view-code.d.mts +0 -7
  306. package/scripts/listed-view-code.mjs +0 -93
  307. package/scripts/look-loop/fit-lut.py +0 -142
  308. package/scripts/look-loop/palette-delta.py +0 -183
  309. package/scripts/look-loop/regions/driftwood-isle.json +0 -25
  310. package/scripts/look-loop/regions/far-reach.json +0 -225
  311. package/scripts/look-loop/regions/open-plot-night-market.json +0 -855
  312. package/scripts/look-loop/regions/pine-hollow.json +0 -22
  313. package/scripts/look-loop/regions/sunscar-dunes.json +0 -281
  314. package/scripts/platform-chargebacks.d.mts +0 -9
  315. package/scripts/platform-chargebacks.mjs +0 -135
  316. package/scripts/shard-component-spans.d.mts +0 -15
  317. package/scripts/shard-component-spans.mjs +0 -18
  318. package/scripts/shard-components.d.mts +0 -16
  319. package/scripts/shard-components.mjs +0 -363
  320. package/scripts/shard-platform-hosts.d.mts +0 -2
  321. package/scripts/shard-platform-hosts.mjs +0 -93
  322. package/scripts/shard-platform-sections.d.mts +0 -2
  323. package/scripts/shard-platform-sections.mjs +0 -9
  324. package/scripts/shard-platform.d.mts +0 -76
  325. package/scripts/shard-platform.mjs +0 -1072
  326. package/src/.oxfmtrc.json +0 -48
  327. package/src/scripts/ask-new.sh +0 -29
  328. package/src/scripts/asks.mjs +0 -142
  329. package/src/scripts/herdr-prompt.sh +0 -34
  330. package/src/scripts/herdr-question-open.sh +0 -67
  331. package/src/scripts/md-wrap.mjs +0 -229
  332. /package/scripts/{shard-platform-format.d.mts → node-format.d.mts} +0 -0
  333. /package/scripts/{shard-platform-format.mjs → node-format.mjs} +0 -0
  334. /package/scripts/{shard-platform-output.d.mts → output-reader.d.mts} +0 -0
@@ -19,6 +19,11 @@ import { saveStorage } from '../saves/slots';
19
19
  * iOS tab killed in the background (its pagehide ran hidden). index.html's 12 s self-reload (`boot.selfReload`,
20
20
  * claimed just before this document) is the engine's and resumes, unless it retried a hung player reload
21
21
  * fresh neither: a cold launch
22
+ * settleLastEnd() SENTRY-TRIAGE S20: a new tab has no session copy, so it reads the device copy, which may be
23
+ * another tab's live beat (a duplicated tab's session copy is one too). Each page holds a Web Lock
24
+ * named for its page id (on the beat) while it is shown; an end that rests on a beat stays pending
25
+ * until a lock query says whether that page still lives (then `fresh`, and its beat is left alone).
26
+ * The entry awaits it before the title reads lastEnd().
22
27
  * `document.wasDiscarded` rides along (Chrome's tab discarding; iOS never sets it).
23
28
  *
24
29
  * The last non-fresh end is kept in localStorage `life.lastEnd`, so pause ▸ Settings ▸ Debug ▸ Loading & memory can show it
@@ -56,7 +61,30 @@ const PLAYER_RETRY_MS = 60_000;
56
61
  export interface AliveInfo<M extends string = string> { slug: string; resident: string; mode: M }
57
62
  interface Stamp { t: number; build: string; slug: string; resident: string; mode: string }
58
63
  interface Unload extends Stamp { reason: string; reload?: true }
59
- interface Alive extends Stamp { vis: string }
64
+ interface Alive extends Stamp { vis: string; page?: string }
65
+ /** S20: a Web Lock each shown page holds, named for its page id, so another tab can ask whether the page behind a device beat
66
+ * still lives. `hold` returns the release. */
67
+ export interface PageLocks { hold: (name: string) => () => void; held: (name: string) => Promise<boolean> }
68
+ const PAGE_LOCK = 'ws-page:';
69
+ /** a lock query this slow answers "not held": the end stays what the beat said */
70
+ const SETTLE_MS = 500;
71
+ function browserLocks(): PageLocks | null {
72
+ // an old Safari, an insecure page or a test DOM may have none, or null
73
+ const locks: LockManager | null | undefined = typeof navigator === 'undefined' ? undefined : (navigator as { locks?: LockManager | null }).locks;
74
+ if (locks === undefined || locks === null || typeof locks.request !== 'function' || typeof locks.query !== 'function') return null;
75
+ return {
76
+ hold: (name) => {
77
+ let release = (): void => undefined;
78
+ const held = new Promise<void>((resolve) => { release = resolve; });
79
+ void locks.request(name, () => held).catch(() => undefined);
80
+ return release;
81
+ },
82
+ // a request not yet granted is a live page too (a first beat, a bfcache return, both before the grant)
83
+ held: async (name) => { const state = await locks.query(); return [...(state.held ?? []), ...(state.pending ?? [])].some((lock) => lock.name === name); },
84
+ };
85
+ }
86
+ /** Web Locks need a secure context, which always has randomUUID; without one the beat carries no id and reads as before */
87
+ const newPageId = (): string => { try { return crypto.randomUUID(); } catch { return ''; } };
60
88
  export interface LastEnd {
61
89
  kind: 'intentional' | 'unexpected' | 'fresh';
62
90
  /** what ended it, in words */
@@ -115,7 +143,15 @@ function navigationType(): string {
115
143
  export class PageLife {
116
144
  private source: (() => AliveInfo) | null = null;
117
145
  private alive = true;
118
- private readonly thisEnd: LastEnd;
146
+ private thisEnd: LastEnd;
147
+ /** S20: this page's id, on its beat and its Web Lock */
148
+ private readonly id = newPageId();
149
+ private readonly locks: PageLocks | null;
150
+ private readonly scope: Scope;
151
+ private releaseLock: (() => void) | null = null;
152
+ /** S20: the page id of a device beat this end rests on alone, until settle() asks whether it lives */
153
+ private pendingPage: string | null = null;
154
+ private settling: Promise<LastEnd> | undefined;
119
155
  private beforeReload: ((reason: ReloadReason) => boolean) | undefined;
120
156
  private readonly storage: typeof store;
121
157
  private readonly nav: () => string;
@@ -123,28 +159,67 @@ export class PageLife {
123
159
  private readonly page: () => { href: string; startedAt: number };
124
160
 
125
161
  constructor(scope: Scope, storage: typeof store = store, nav: () => string = navigationType,
126
- page: () => { href: string; startedAt: number } = () => ({ href: inPage() ? location.href : '', startedAt: typeof performance === 'undefined' ? Date.now() : performance.timeOrigin })) {
162
+ page: () => { href: string; startedAt: number } = () => ({ href: inPage() ? location.href : '', startedAt: typeof performance === 'undefined' ? Date.now() : performance.timeOrigin }),
163
+ locks: PageLocks | null = browserLocks()) {
127
164
  this.storage = storage;
165
+ this.locks = locks;
166
+ this.scope = scope;
128
167
  this.nav = nav;
129
168
  this.page = page;
130
169
  this.thisEnd = this.classify();
131
- inspectPreviousBoot();
132
- if (this.thisEnd.kind !== 'fresh' || this.thisEnd.discarded) writeJson(this.storage('local'), END_KEY, this.thisEnd);
133
- if (this.thisEnd.kind !== 'fresh') console.info(`[lastEnd] the previous page: ${this.thisEnd.reason}${this.thisEnd.resident === '' ? '' : ` · resident ${this.thisEnd.resident}`}`);
170
+ // S18: a reload the page before marked is never index.html's self-reload
171
+ inspectPreviousBoot(this.thisEnd.kind === 'intentional' && this.thisEnd.player !== true && this.thisEnd.bootedAt - this.thisEnd.at < INTENT_MS);
172
+ if (this.pendingPage === null) this.record();
173
+ this.holdLock();
134
174
  // the beat: the page's own timer (this module loads before any shard scope exists)
135
175
  if (inPage()) {
136
176
  this.beat();
137
177
  scope.interval(BEAT_MS, () => { this.beat(); });
138
178
  // back on screen after a pagehide that did not end the page (iOS can send one on an app switch): beating again
139
- scope.listen(document, 'visibilitychange', () => { if (document.visibilityState === 'visible') this.alive = true; this.beat(); });
179
+ scope.listen(document, 'visibilitychange', () => { if (document.visibilityState === 'visible') { this.alive = true; this.holdLock(); } this.beat(); });
140
180
  // a page that ends normally takes its marker with it; a bfcache return (pageshow persisted) puts it back
141
181
  scope.listen(window, 'pagehide', () => {
142
- this.alive = false; this.clearAlive();
182
+ this.alive = false; this.clearAlive(); this.dropLock();
143
183
  // QA 11-12 row 35: how this page ended, for telling the player's reload (a visible page) from a system one (hidden)
144
184
  writeJson(this.storage('session'), HID_KEY, { t: Date.now(), vis: document.visibilityState, href: location.href });
145
185
  });
146
- scope.listen(window, 'pageshow', (e) => { if (e.persisted) { this.alive = true; this.beat(); } });
186
+ scope.listen(window, 'pageshow', (e) => { if (e.persisted) { this.alive = true; this.holdLock(); this.beat(); } });
147
187
  }
188
+ scope.onDispose(() => { this.dropLock(); });
189
+ }
190
+
191
+ /** the device's last-end record and the console line, once the end is known */
192
+ private record(): void {
193
+ if (this.thisEnd.kind !== 'fresh' || this.thisEnd.discarded) writeJson(this.storage('local'), END_KEY, this.thisEnd);
194
+ if (this.thisEnd.kind !== 'fresh') console.info(`[lastEnd] the previous page: ${this.thisEnd.reason}${this.thisEnd.resident === '' ? '' : ` · resident ${this.thisEnd.resident}`}`);
195
+ }
196
+
197
+ /** S20: held while this page is shown; a pagehide lets it go (a held lock would keep the page out of the bfcache) */
198
+ private holdLock(): void { if (this.locks !== null && this.id !== '' && this.releaseLock === null) this.releaseLock = this.locks.hold(PAGE_LOCK + this.id); }
199
+ private dropLock(): void { this.releaseLock?.(); this.releaseLock = null; }
200
+
201
+ /** S20: an end that rests on a device beat alone is `fresh` when that beat's page still holds its lock (another tab, playing);
202
+ * else it stands, and the beat is cleared as the classification would have. Once; at most SETTLE_MS. */
203
+ settle(): Promise<LastEnd> {
204
+ this.settling ??= (async () => {
205
+ const id = this.pendingPage, locks = this.locks;
206
+ if (id === null || locks === null) return this.thisEnd;
207
+ let alive = false;
208
+ try {
209
+ let timer: ReturnType<Scope['timeout']> | undefined;
210
+ const late = new Promise<boolean>((resolve) => { timer = this.scope.timeout(SETTLE_MS, () => { resolve(false); }); });
211
+ alive = await Promise.race([locks.held(PAGE_LOCK + id).catch(() => false), late]);
212
+ if (timer !== undefined) this.scope.cancelTimer(timer);
213
+ } catch { /* not settled: the beat's word stands */ }
214
+ this.pendingPage = null;
215
+ if (alive) {
216
+ const { bootedAt, discarded, nav } = this.thisEnd;
217
+ this.thisEnd = { kind: 'fresh', reason: 'fresh launch (another tab is playing)', at: 0, resident: '', slug: '', mode: '', build: '', bootedAt, discarded, nav };
218
+ } else this.dropBeat(id);
219
+ this.record();
220
+ return this.thisEnd;
221
+ })();
222
+ return this.settling;
148
223
  }
149
224
 
150
225
  /** what the alive beat and markUnload record: the running shard and the resident list (main.ts, once the host exists) */
@@ -190,13 +265,19 @@ export class PageLife {
190
265
  private beat(): void {
191
266
  if (!this.alive) return;
192
267
  if (!inPage()) return;
193
- const a: Alive = { ...this.stamp(), vis: document.visibilityState };
268
+ const a: Alive = { ...this.stamp(), vis: document.visibilityState, ...(this.id === '' ? {} : { page: this.id }) };
194
269
  writeJson(this.storage('session'), ALIVE_KEY, a);
195
270
  // A killed iOS WebContent process may lose sessionStorage too. Normal
196
271
  // navigation clears both copies; a kill cannot run that cleanup.
197
272
  writeJson(this.storage('local'), ALIVE_BACKUP_KEY, a);
198
273
  }
199
274
 
275
+ /** the device beat of page `id`, consumed by this page's classification; once this page beats, the copy is its own and stays */
276
+ private dropBeat(id: string): void {
277
+ if (id === '') return;
278
+ try { const local = this.storage('local'); if (str(readJson(local, ALIVE_BACKUP_KEY), 'page') === id) local?.removeItem(ALIVE_BACKUP_KEY); } catch { /* storage blocked */ }
279
+ }
280
+
200
281
  private clearAlive(): void {
201
282
  try { this.storage('session')?.removeItem(ALIVE_KEY); } catch { /* storage blocked */ }
202
283
  try { this.storage('local')?.removeItem(ALIVE_BACKUP_KEY); } catch { /* storage blocked */ }
@@ -206,15 +287,19 @@ export class PageLife {
206
287
  const now = Date.now();
207
288
  const local = this.storage('local'), session = this.storage('session');
208
289
  const u = readJson(local, UNLOAD_KEY), a = readJson(session, ALIVE_KEY) ?? readJson(local, ALIVE_BACKUP_KEY);
209
- try { local?.removeItem(ALIVE_BACKUP_KEY); } catch { /* consumed by this page's classification */ }
290
+ // S20: a beat from a page with an id may be another tab's live one: the device copy in a new tab, or the session copy a
291
+ // duplicated tab (or a window.open) starts with. settle() asks before it is taken; a page of this tab can't be alive.
292
+ const otherPage = this.locks !== null ? str(a, 'page') : '';
293
+ if (otherPage === '') try { local?.removeItem(ALIVE_BACKUP_KEY); } catch { /* consumed by this page's classification */ }
210
294
  try { local?.removeItem(UNLOAD_KEY); } catch { /* read once either way */ }
211
295
  const discarded = inPage() && Reflect.get(document, 'wasDiscarded') === true;
212
296
  const nav = this.nav(), hid = readJson(session, HID_KEY);
213
297
  try { session?.removeItem(HID_KEY); } catch { /* read once either way */ }
214
298
  const base = { bootedAt: now, discarded, nav, ...(typeof u === 'object' && u !== null && Reflect.get(u, 'reload') === true ? { reload: true as const } : {}) };
215
299
  const ut = num(u, 't');
216
- if (u !== null && now - ut < INTENT_MS) return { kind: 'intentional', reason: str(u, 'reason'), at: ut, resident: str(u, 'resident'), slug: str(u, 'slug'), mode: str(u, 'mode'), build: str(u, 'build'), ...base };
300
+ if (u !== null && now - ut < INTENT_MS) { this.dropBeat(otherPage); return { kind: 'intentional', reason: str(u, 'reason'), at: ut, resident: str(u, 'resident'), slug: str(u, 'slug'), mode: str(u, 'mode'), build: str(u, 'build'), ...base }; }
217
301
  if (a !== null) {
302
+ if (otherPage !== '') this.pendingPage = otherPage;
218
303
  const where = str(a, 'vis') === 'hidden' ? 'in the background' : 'on screen';
219
304
  return { kind: 'unexpected', reason: `page ended unexpectedly ${where} (browser or system cause unknown)`, at: num(a, 't'), resident: str(a, 'resident'), slug: str(a, 'slug'), mode: str(a, 'mode'), build: str(a, 'build'), ...base };
220
305
  }
@@ -314,5 +399,7 @@ export function leaveSaved(go: () => void): void {
314
399
  }
315
400
 
316
401
  export function lastEnd(): LastEnd { return page.lastEnd(); }
402
+ /** S20: lastEnd() once a device beat it rests on alone is known to be no other tab's live page; the entry awaits it before the title */
403
+ export function settleLastEnd(): Promise<LastEnd> { return page.settle(); }
317
404
  export function lastRecordedEnd(): LastEnd | null { return page.lastRecordedEnd(); }
318
405
  export function lastEndLine(now: number = Date.now()): string { return page.lastEndLine(now); }
@@ -1,4 +1,4 @@
1
- import { ASSET_CACHE_NAME } from '../pwa/cacheNames';
1
+ import { assetCacheName } from '../pwa/cacheNames';
2
2
  import { publishBootResponse } from './bootCache';
3
3
  import { contentURL, isContentOrigin, pageURL } from './contentBase';
4
4
  import type { Scope } from '../../../shared/engine/app/scope';
@@ -147,7 +147,7 @@ async function readBody(response: Response, expected: number, signal: AbortSigna
147
147
  } catch (error) { void reader.cancel().catch(() => undefined); throw error; }
148
148
  }
149
149
  async function cachedPart(path: string): Promise<Response | undefined> {
150
- try { return typeof caches === 'undefined' ? undefined : await (await caches.open(ASSET_CACHE_NAME)).match(new URL(path, location.href).href, { ignoreVary: true }); }
150
+ try { return typeof caches === 'undefined' ? undefined : await (await caches.open(assetCacheName())).match(new URL(path, location.href).href, { ignoreVary: true }); }
151
151
  catch { return undefined; } // Storage denial preserves the ordinary direct read.
152
152
  }
153
153
  const readers = new Set<TexturePackReads>();
@@ -53,6 +53,7 @@ import { yieldTask } from '../../../shared/engine/core/workSlice';
53
53
  import { buildHeld, heldDrawDeferred, noteFrameDrawn } from '../../../shared/engine/core/framePacing';
54
54
  import { isDev, onDev } from './devMode';
55
55
  import { activeDevPixels, drawingPixelRatio } from './devPixels';
56
+ import { RenderBudget, budgetCeiling } from './renderBudget';
56
57
  import { graphicsMode, lowPowerOn, noteFastFrames, PIXELS_EVENT } from './graphicsMode';
57
58
  import { flagOn, frameCapFor, noteShipped, presetLabel, setFrameReadout, type ShippedLook } from './graphicsQuality';
58
59
  import { classifyFrames } from '../boot/lowPower';
@@ -179,6 +180,11 @@ const ARRIVAL_RADIUS = 125;
179
180
  /** one engine colour chain, built (Game.buildComposer): its effects, in order, and by name */
180
181
  interface BuiltChain { clean: boolean; order: Effect[]; fx: Omit<EngineEffects, 'order'> }
181
182
 
183
+ /** GC6: candidates a live display transform gets before it links on its next draw */
184
+ export const POST_PASS_ATTEMPTS = 4;
185
+ /** GC6: the longest an entered frame waits on live display transform preparation */
186
+ export const POST_PREPARATION_WAIT_MS = 12_000;
187
+
182
188
  /** An entered frame's preparation trace (`Game.entryPreparation`): its destination root, owner, running phase, measured
183
189
  * work counts and scalar timings. A named type, so consumers of the emitted declarations see it (a private field's type
184
190
  * is not emitted). */
@@ -526,10 +532,10 @@ export class Game {
526
532
  if (tracedBoot) recordGpuCheckpoint(this.renderer, 'renderer:created');
527
533
  // QA row 25 / MG2: a Developer's screen × density pick (core/devPixels.ts), else a phone's Low graphics
528
534
  // (core/graphicsMode.ts), stands in for the tier's cap; either applies live
529
- this.renderer.setPixelRatio(drawingPixelRatio(window.devicePixelRatio, TIER_CONFIG.dpr, this.phoneGraphics));
535
+ this.renderer.setPixelRatio(this.wantedRatio());
530
536
  // the new ratio waits for the frame that draws (RT3: never in the task that decided it, whose cleared canvas nothing
531
537
  // would replace; under a menu or the title the world stays as it was until play draws again)
532
- const repixel = (): void => { const ratio = drawingPixelRatio(window.devicePixelRatio, TIER_CONFIG.dpr, this.phoneGraphics); this.pickedRatio = ratio === this.renderer.getPixelRatio() ? null : ratio; this.applyQuality(); };
538
+ const repixel = (): void => { const ratio = this.wantedRatio(); this.pickedRatio = ratio === this.renderer.getPixelRatio() ? null : ratio; this.applyQuality(); };
533
539
  this.engineScope.listen(document, PIXELS_EVENT, repixel);
534
540
  // MG8 prototype: the player has control, so the boot's shadow draws are done: a no-shadows mode clears the maps once more
535
541
  this.engineScope.listen(document, 'ws:control-ready', () => { this.qualityClearedMaps = new WeakSet(); });
@@ -551,6 +557,7 @@ export class Game {
551
557
  // change tells the page (Settings, the first-play card) and lands in the next drawn frame
552
558
  this.engineScope.listen(document, 'visibilitychange', () => {
553
559
  if (document.visibilityState !== 'visible') return;
560
+ this.budget?.reset(); // NB5: the frames from before the page went away are not this page's pace
554
561
  const stamps: number[] = [];
555
562
  const tick = (now: number): void => {
556
563
  if (this.engineScope.disposed || document.visibilityState !== 'visible') return;
@@ -1096,18 +1103,24 @@ export class Game {
1096
1103
  const geometry = postTriangle(), mesh = new THREE.Mesh(geometry, pass.fullscreenMaterial), scene = new THREE.Scene();
1097
1104
  const target = pass.renderToScreen ? null : composer.inputBuffer;
1098
1105
  try {
1099
- let published = false;
1100
- while (current() && !published) published = await prepareEffectPass(pass, async material => {
1101
- mesh.material = material;
1102
- await runPrecompile(this.renderer, this.camera, [{ label: engineString('s_178612197e2b'), root: mesh, target: scene, rt: target }], 1,
1103
- undefined, undefined, current, false, () => waitForDrawnFrame(this.engineScope, () => this.frameCount, current));
1104
- }, material => {
1105
- mesh.material = material;
1106
- const prior = this.renderer.getRenderTarget(), face = this.renderer.getActiveCubeFace(), mip = this.renderer.getActiveMipmapLevel();
1107
- this.renderer.setRenderTarget(target);
1108
- try { this.renderer.compile(mesh, this.camera, scene); }
1109
- finally { this.renderer.setRenderTarget(prior, face, mip); }
1110
- }, current);
1106
+ // GC6 (QA 11-14 row 6): a pass that left the chain, or whose shader keeps changing under each candidate, never
1107
+ // published: the loop ran for ever and every entered frame awaiting it stayed unready. Past a few candidates it
1108
+ // links on its next draw (the boot path).
1109
+ let published = false, attempts = 0;
1110
+ while (current() && composer.passes.includes(pass) && !published) {
1111
+ if (attempts++ >= POST_PASS_ATTEMPTS) { pass.recompile(); break; }
1112
+ published = await prepareEffectPass(pass, async material => {
1113
+ mesh.material = material;
1114
+ await runPrecompile(this.renderer, this.camera, [{ label: engineString('s_178612197e2b'), root: mesh, target: scene, rt: target }], 1,
1115
+ undefined, undefined, current, false, () => waitForDrawnFrame(this.engineScope, () => this.frameCount, current));
1116
+ }, material => {
1117
+ mesh.material = material;
1118
+ const prior = this.renderer.getRenderTarget(), face = this.renderer.getActiveCubeFace(), mip = this.renderer.getActiveMipmapLevel();
1119
+ this.renderer.setRenderTarget(target);
1120
+ try { this.renderer.compile(mesh, this.camera, scene); }
1121
+ finally { this.renderer.setRenderTarget(prior, face, mip); }
1122
+ }, current);
1123
+ }
1111
1124
  } finally { geometry.dispose(); }
1112
1125
  };
1113
1126
  const work = prepare();
@@ -1169,10 +1182,18 @@ export class Game {
1169
1182
  // and first draws. An early composer lends only the compiler above; doing
1170
1183
  // the crossing warm-up here would add parked/offscreen frame variants.
1171
1184
  if (this.frameCount === 0) { trace.completed = true; return; }
1185
+ // GC6 (QA 11-14 row 6): a display transform's preparation that never settles (a lost link, a dead owner's frame
1186
+ // wait) held Nalati's on-road entry at afterPlay for ever: in the cell, no control. Past POST_PREPARATION_WAIT_MS
1187
+ // the entry goes on and that pass links on its first draw (D196: a stall reveals with what had linked).
1188
+ const postStarted = diagnosticNow();
1172
1189
  for (;;) {
1173
- const pending = this.postPreparation;
1174
- await pending;
1190
+ const pending = this.postPreparation, left = POST_PREPARATION_WAIT_MS - (diagnosticNow() - postStarted);
1191
+ let timer: ReturnType<Scope['timeout']> | undefined;
1192
+ const timedOut = left <= 0 || await Promise.race([pending.then(() => false),
1193
+ new Promise<boolean>(resolve => { timer = this.engineScope.timeout(left, () => { resolve(true); }); })])
1194
+ .finally(() => { if (timer !== undefined) this.engineScope.cancelTimer(timer); });
1175
1195
  if (!current()) throw new Error('Shader warm-up owner left');
1196
+ if (timedOut) { trace.stalled = 'post-preparation'; console.warn(`[entry] ${owner.name}: display transform preparation still running after ${String(POST_PREPARATION_WAIT_MS)} ms; entering without it`); break; }
1176
1197
  if (this.postPreparation === pending) break;
1177
1198
  }
1178
1199
  enter('shaders-and-composer');
@@ -1687,8 +1708,26 @@ export class Game {
1687
1708
  // MG8: Settings ▸ Graphics ▸ Pixel density replaces the boot-time render scale on a phone (Jake ~23:45: one pixel control)
1688
1709
  private readonly phoneGraphics: boolean = TIER === 'phone';
1689
1710
  resize(): void { this.fitSize(); this.kickLoop(); }
1711
+ /** NB5 (renderBudget.ts): the desktop's pixel budget and dynamic resolution, on the tier's own scale only: never a phone
1712
+ * (MG8's Pixel density; Jake 2026-10-20, no dynamic resolution on the phone), a Developer's pixel pick or a player's saved
1713
+ * render scale (Settings ▸ Graphics, gfxPrefs.dpr) */
1714
+ private budget: RenderBudget | null = null;
1715
+ private budgetOn(): boolean { return !this.phoneGraphics && activeDevPixels() === null && gfxPrefs.dpr === 'auto' && this.slowPacing === null; }
1716
+ /** NB5: the next drawn frame follows vsyncs skipped on purpose (a build hold): its interval is not the frame's cost */
1717
+ private budgetSkip = false;
1718
+ /** The drawing buffer's pixel ratio the page wants now: the budget's on the desktop's own scale, else drawingPixelRatio. */
1719
+ private wantedRatio(): number {
1720
+ const base = drawingPixelRatio(window.devicePixelRatio, TIER_CONFIG.dpr, this.phoneGraphics);
1721
+ if (!this.budgetOn()) { this.budget = null; return base; }
1722
+ const ceiling = budgetCeiling(window.innerWidth, viewportHeight(), window.devicePixelRatio, base);
1723
+ if (this.budget === null) this.budget = new RenderBudget(ceiling);
1724
+ else if (this.budget.ceiling !== ceiling) this.budget.resize(ceiling);
1725
+ return this.budget.ratio;
1726
+ }
1690
1727
  private fitSize(): void {
1691
1728
  const w = window.innerWidth, h = viewportHeight();
1729
+ // a new window size moves the budget's ceiling (a smaller ratio lands now: this resize redraws anyway)
1730
+ if (this.budget !== null) { const ratio = this.wantedRatio(); if (ratio !== this.renderer.getPixelRatio()) this.renderer.setPixelRatio(ratio); }
1692
1731
  this.camera.aspect = w / h;
1693
1732
  this.camera.updateProjectionMatrix();
1694
1733
  this.renderer.setSize(w, h);
@@ -1725,13 +1764,14 @@ export class Game {
1725
1764
  // worker messages and input; like a capped vsync, a skipped one does nothing. A capture draws at the tier's own
1726
1765
  // scale on its own clock: no spacing, and any lowered scale restored
1727
1766
  const capture = this.app.clock.mode === 'capture';
1728
- if (capture) this.slowPacing?.restore();
1767
+ if (capture) { this.slowPacing?.restore(); this.budget?.restore(); }
1729
1768
  const pacing = capture ? null : this.slowPacing;
1730
1769
  if (pacedSkip(pacing, lastRun, this.pacedStart, forceFrame, buildHeld())) return;
1731
1770
  // G782: held at a cell's wall with build slices running, skip vsyncs up to the 30 fps held floor (framePacing.ts);
1732
1771
  // like a capped vsync, a skipped one does nothing, so the drawn frame's dt is the whole interval
1733
- if (!forceFrame && heldDrawDeferred()) return;
1772
+ if (!forceFrame && heldDrawDeferred()) { this.budgetSkip = true; return; }
1734
1773
  const cap = frameCapFps();
1774
+ if (cap > 0) this.budget?.restore(); // NB5: a cap sets its own pace; the tier's own scale under it
1735
1775
  if (cap > 0 && !forceFrame) {
1736
1776
  const anchor = frameCapAnchor(lastDrawn, now ?? lastRun, cap);
1737
1777
  if (anchor === null) return;
@@ -1771,7 +1811,8 @@ export class Game {
1771
1811
  // QA row 25: a Developer pixel pick (core/devPixels.ts) holds against the software pacing's scale while it is set
1772
1812
  const paced = this.stepOnly ? null : this.slowPacing?.takeRatio() ?? null, picked = this.stepOnly ? null : this.pickedRatio;
1773
1813
  if (picked !== null) this.pickedRatio = null;
1774
- const ratio = picked ?? (paced !== null && activeDevPixels() === null ? paced : null);
1814
+ const budgeted = this.stepOnly || picked !== null || paced !== null ? null : this.budget?.takeRatio() ?? null;
1815
+ const ratio = picked ?? (paced !== null && activeDevPixels() === null ? paced : null) ?? (this.budgetOn() ? budgeted : null);
1775
1816
  if (ratio !== null) { this.renderer.setPixelRatio(ratio); this.fitSize(); }
1776
1817
  sky.update(realDt);
1777
1818
  // planet + sun disc travel with the camera so they stay "infinitely" far
@@ -1806,6 +1847,9 @@ export class Game {
1806
1847
  noteFrameDrawn(done, now, cap, cap > 0 && Number.isFinite(lastDrawn) ? lastDrawn : undefined); // Builds share the cap recovery deadline; actual rAF still measures display cadence.
1807
1848
  this.app.cpu.end();
1808
1849
  if (pacing !== null) this.measurePacedFrame(lastRun);
1850
+ // NB5: dynamic resolution reads the drawn frame's interval (uncapped play only: a cap or a capture sets its own pace)
1851
+ else if (this.budget !== null && !capture && cap === 0 && !forceFrame && !this.app.clock.paused && !this.budgetSkip) this.budget.measured(liveDt * 1000);
1852
+ this.budgetSkip = false;
1809
1853
  this.workMs[this.frameI] = work;
1810
1854
  this.frameRafTime = now ?? null;
1811
1855
  this.frameCount++;
@@ -48,6 +48,16 @@ function releaseCpuCopy(this: BufferAttribute): void {
48
48
  this.array = this.array.slice(0, 0);
49
49
  Object.defineProperty(this, 'needsUpdate', { configurable: true, get: () => false, set: (value: boolean) => { if (value) lateWrite(this); } });
50
50
  }
51
+ /**
52
+ * SHARD-SOURCE AP18 (dev only: `wildshard watch`'s ground swap): upload a whole new copy of a GPU-only attribute into its
53
+ * buffer. The array is the same length as the first upload's, so the buffer is rewritten in place (no second buffer); its
54
+ * CPU copy goes again once uploaded.
55
+ */
56
+ export function refillGpuOnly(attribute: BufferAttribute, array: Float32Array): void {
57
+ if (array.length !== attribute.count * attribute.itemSize) throw new Error(`gpu-only: a refill of ${array.length} values for ${attribute.count * attribute.itemSize}`);
58
+ Reflect.deleteProperty(attribute, 'needsUpdate');
59
+ attribute.array = array; attribute.needsUpdate = true;
60
+ }
51
61
  function lateWrite(attribute: BufferAttribute): void {
52
62
  const where = releasedAs.get(attribute) ?? 'gpu-only';
53
63
  if (lateWriters.has(where)) return;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * NINE-DRAGON-BENCHMAX NB5, widened (meta QA-FEEDBACK-2026-11-14 rows 2, 3 and 5; Jake, desktop Chrome on his Mac:
3
+ * "nine dragon is fucked on desktop", "nalati is shist too 30 fps", "driftwood all over the place 40-70 FPS"). The J343 bar
4
+ * is 60 fps on desktop. The desktop's drawing buffer, in two parts:
5
+ *
6
+ * - a pixel budget: the buffer never holds more than DESKTOP_PIXEL_BUDGET pixels, whatever the window. The tier's 1.5 cap
7
+ * alone let a big window grow without end (a 2560x1440 window at 1.5 is 8.3 Mpx; Jake's 1496x717 at 1.5 is 2.4 Mpx, under
8
+ * the budget, so his ceiling stays 1.5);
9
+ * - dynamic resolution: the render scale steps down fast and back up slowly from the drawn frame's own interval, between
10
+ * a floor (one buffer pixel per CSS pixel where the ceiling allows it) and that ceiling. A frame that misses 60 fps
11
+ * tries one step down; if the next frames are no faster the frame is not bound by its pixels (the main thread, a busy
12
+ * machine), so the step is taken back and held off for a while: a softer frame that buys nothing is never kept.
13
+ *
14
+ * Desktop only, and only the tier's own scale: the phone keeps its one Pixel density control (MG8) and "Render scale stays
15
+ * 2x on the phone (no dynamic resolution)" (Jake, 2026-10-20). A Developer's pixel pick, a player's saved render scale, a
16
+ * capture, a frame cap or a software rasterizer's pacing each leave the scale alone. Pure: it is driven by measured
17
+ * intervals alone, so the tests drive it with numbers.
18
+ */
19
+
20
+ /** The desktop drawing buffer's most pixels (fable-phoneperf's cleanroom budget is 3.5 to 4.5 Mpx on a desktop). */
21
+ export const DESKTOP_PIXEL_BUDGET = 4_200_000;
22
+ /** A window's frames over this median interval (ms) miss 60 fps: step down. */
23
+ export const OVER_MS: number = 1000 / 58;
24
+ /** A window's frames under this median interval (ms) have headroom for a step up (~80 fps). */
25
+ export const UNDER_MS = 12.5;
26
+ /** Drawn frames per decision. */
27
+ export const BUDGET_WINDOW = 30;
28
+ /** Calm windows in a row before one step up. */
29
+ export const RAISE_WINDOWS = 6;
30
+ /** A step down must make the frame at least this much faster (share of its interval) to be kept. */
31
+ export const STEP_PAYS = 0.06;
32
+ /** After a step that did not pay, no step down for this many windows; each unpaid step in a row doubles it, to at most
33
+ * MAX_HOLD_WINDOWS (a frame bound by its main thread is not re-tried, and re-softened, every few seconds). */
34
+ export const UNPAID_HOLD_WINDOWS = 20;
35
+ export const MAX_HOLD_WINDOWS = 160;
36
+ /** Pixel ratios snap to eighths (each change reallocates the composer's targets). */
37
+ const SNAP = 8;
38
+
39
+ /** The buffer's pixel ratio ceiling for a window: the tier's cap, the screen's own density, and the pixel budget. */
40
+ export function budgetCeiling(cssWidth: number, cssHeight: number, device: number, tierCap: number, budget: number = DESKTOP_PIXEL_BUDGET): number {
41
+ const cap = Math.min(device, tierCap), css = Math.max(1, cssWidth * cssHeight);
42
+ const fits = Math.sqrt(budget / css);
43
+ // snapped as a whole, so the ceiling is always one of budgetSteps' own eighths (a 1.1 screen draws at 1, never 1.125)
44
+ return Math.max(1 / SNAP, Math.floor(Math.min(cap, fits) * SNAP) / SNAP);
45
+ }
46
+
47
+ /** The lowest ratio dynamic resolution takes: one buffer pixel per CSS pixel, or 3/4 of a ceiling already under that. */
48
+ export function budgetFloor(ceiling: number): number {
49
+ return ceiling > 1 ? 1 : Math.max(1 / SNAP, Math.floor(ceiling * 0.75 * SNAP) / SNAP);
50
+ }
51
+
52
+ /** The steps between floor and ceiling, ascending, an eighth apart (both ends included). */
53
+ export function budgetSteps(floor: number, ceiling: number): number[] {
54
+ const steps: number[] = [];
55
+ for (let r = ceiling; r > floor + 1e-9; r -= 1 / SNAP) steps.push(Math.round(r * SNAP) / SNAP);
56
+ steps.push(floor);
57
+ return [...new Set(steps)].sort((a, b) => a - b);
58
+ }
59
+
60
+ const median = (values: readonly number[]): number => [...values].sort((a, b) => a - b)[Math.floor(values.length / 2)] ?? 0;
61
+
62
+ /** One page's render budget. */
63
+ export class RenderBudget {
64
+ private steps: number[];
65
+ private at: number;
66
+ private readonly intervals: number[] = [];
67
+ private calm = 0;
68
+ private hold = 0;
69
+ private nextHold = UNPAID_HOLD_WINDOWS;
70
+ /** the step down on trial: the median it was taken against and the step it came from */
71
+ private trial: { before: number; from: number } | null = null;
72
+ private pending: number | null = null;
73
+
74
+ constructor(ceiling: number) { this.steps = budgetSteps(budgetFloor(ceiling), ceiling); this.at = this.steps.length - 1; }
75
+
76
+ /** The ratio frames draw at now. */
77
+ get ratio(): number { return this.steps[this.at] ?? 1; }
78
+ /** The ceiling (the window's budget). */
79
+ get ceiling(): number { return this.steps.at(-1) ?? 1; }
80
+
81
+ /** A new window size or screen: a new ceiling. Returns the ratio to draw at (the current one, or the new ceiling if lower). */
82
+ resize(ceiling: number): number {
83
+ const was = this.ratio;
84
+ this.steps = budgetSteps(budgetFloor(ceiling), ceiling);
85
+ const keep = this.steps.findIndex((r) => r >= was - 1e-9);
86
+ this.at = keep === -1 ? this.steps.length - 1 : keep;
87
+ this.reset();
88
+ return this.ratio;
89
+ }
90
+
91
+ /** Back to the ceiling (a capture draws at the tier's own scale), from the next drawn frame. */
92
+ restore(): void { this.reset(); this.move(this.steps.length - 1); }
93
+
94
+ /** Forget the measurements (a resize, a capture, a page coming back): the next window starts afresh. */
95
+ reset(): void { this.intervals.length = 0; this.calm = 0; this.trial = null; }
96
+
97
+ /** The ratio to set right before the next frame draws, once (RT3: a resize clears the canvas, so it lands in the frame that draws). */
98
+ takeRatio(): number | null { const next = this.pending; this.pending = null; return next; }
99
+
100
+ /** A drawn frame's interval (ms, from the last drawn frame). Returns the new ratio when it changes, else null. */
101
+ measured(intervalMs: number): number | null {
102
+ if (!Number.isFinite(intervalMs) || intervalMs <= 0) return null;
103
+ this.intervals.push(intervalMs);
104
+ if (this.intervals.length < BUDGET_WINDOW) return null;
105
+ const m = median(this.intervals);
106
+ this.intervals.length = 0;
107
+ if (this.hold > 0) this.hold--;
108
+ const trial = this.trial;
109
+ if (trial !== null) {
110
+ this.trial = null;
111
+ // the step down didn't pay: not bound by pixels at this view; take it back and hold off
112
+ if (m > trial.before * (1 - STEP_PAYS)) {
113
+ this.hold = this.nextHold; this.nextHold = Math.min(MAX_HOLD_WINDOWS, this.nextHold * 2); this.calm = 0;
114
+ return this.move(trial.from);
115
+ }
116
+ this.nextHold = UNPAID_HOLD_WINDOWS;
117
+ }
118
+ if (m > OVER_MS) {
119
+ this.calm = 0;
120
+ if (this.hold > 0 || this.at === 0) return null;
121
+ this.trial = { before: m, from: this.at };
122
+ return this.move(this.at - 1);
123
+ }
124
+ this.calm = m < UNDER_MS ? this.calm + 1 : 0;
125
+ if (this.calm >= RAISE_WINDOWS && this.at < this.steps.length - 1) { this.calm = 0; return this.move(this.at + 1); }
126
+ return null;
127
+ }
128
+
129
+ private move(to: number): number | null {
130
+ if (to === this.at) return null;
131
+ this.at = to; this.pending = this.ratio; this.intervals.length = 0;
132
+ return this.ratio;
133
+ }
134
+ }
@@ -151,6 +151,16 @@ export class NetPlayer implements PlayerLink {
151
151
  get heldSlot(): number { return this.held; }
152
152
  /** The server has put this body somewhere: a frame has been heard. */
153
153
  get joined(): boolean { return this.seen !== null; }
154
+ /** OFFLINE OF10 (J298, Jake 2026-11-12: "do a very limited amount of client-side emulation"): a world page that opened without
155
+ * its seat (OF9) plays its input on the predictor alone until the ring is full (PREDICTION_RING, about 1 s), then holds. Nothing
156
+ * goes on the wire: these moves are the page's own, and the seat's first frame takes the server's place, gliding to it when it
157
+ * is near (under PREDICTION_SNAP). A rejoin or a crossing still holds still until its first frame. */
158
+ private unseated = false;
159
+ private unseatedSeq = 0;
160
+ /** OF10: play unseated until the first frame (a page that has heard one is seated, and this does nothing). */
161
+ playUnseated(): void { if (this.seen === null) this.unseated = true; }
162
+ /** OF10: unseated, and the ring is spent: movement holds until the seat. */
163
+ get unseatedHeld(): boolean { return this.unseated && this.predictor.full; }
154
164
  /** A death's authoritative pose is already reset on the server. Keep this page at the death until its overlay is dark. */
155
165
  holdRespawn(): void { this.respawnHeld = true; }
156
166
  /** Adopt the newest server pose under the dark, dropping commands from before the death. */
@@ -158,7 +168,8 @@ export class NetPlayer implements PlayerLink {
158
168
 
159
169
  /** A fixed step. False, with nothing sent, before the first frame or when a full ring says the server stopped answering. */
160
170
  step(input: PlayerWireInput): boolean {
161
- if (this.respawnHeld || this.seen === null || this.predictor.full) return false;
171
+ if (this.respawnHeld || this.predictor.full) return false;
172
+ if (this.seen === null) return this.unseated && this.deviceMode !== 'paused' && this.stepUnseated(input);
162
173
  if (!this.claimInputTick(0)) return false;
163
174
  const armed = this.armed(input);
164
175
  return this.sendCommand(armed, true, this.hooked(armed));
@@ -188,6 +199,12 @@ export class NetPlayer implements PlayerLink {
188
199
  for (let at = 1; at < MAX_FIXED_STEPS && !this.predictor.full && this.claimInputTick(MAX_FIXED_STEPS); at++) this.sendCommand(input, false);
189
200
  this.client.flush();
190
201
  }
202
+ /** OF10: one step of the page's own, unsent, with a seq of its own; world actions wait for the link (the hold cards). */
203
+ private stepUnseated(input: PlayerWireInput): boolean {
204
+ const seq = this.unseatedSeq = (this.unseatedSeq % 0xffff) + 1;
205
+ this.world.poseFor(seq, false);
206
+ return this.predictor.step(quantiseCommand({ ...input, seq, viewTick: 0 }));
207
+ }
191
208
  private claimInputTick(reserve: number): boolean {
192
209
  if (this.deviceMode === 'frame') return true;
193
210
  if (this.deviceMode === 'paused') return false;
@@ -234,7 +251,7 @@ export class NetPlayer implements PlayerLink {
234
251
  this.world.frame(frame.tick, frame.lastSeq);
235
252
  for (const event of this.heard.splice(0)) if (event.kind === 'mount') seat?.enter(event.mount); else seat?.leave();
236
253
  const ridden = seat === null ? null : frame.ride;
237
- if (first) { this.predictor.adopt(frame.lastSeq, frame.owner, frame.tick, ridden); return; }
254
+ if (first) { const glide = this.unseated; this.unseated = false; this.predictor.adopt(frame.lastSeq, frame.owner, frame.tick, ridden, glide); return; }
238
255
  this.predictor.reconcile(frame.lastSeq, frame.owner, frame.tick, ridden);
239
256
  const swung = PLAYER_CLASS.owner[LAST_SWING]?.value(frame.owner[LAST_SWING] ?? 0), held = PLAYER_CLASS.owner[HELD]?.value(frame.owner[HELD] ?? 0);
240
257
  this.attacks.frame(frame.lastSeq, typeof swung === 'number' ? swung : 0);