A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(playable): a playable's start-screen bar moves through the whole boot - it was weighed as a web page's, whose start is mostly fetching the engine, so a page with everything inlined stood at 82% within a second and crawled for the rest; a playable weighs its own stages, and the scene's is followed through loading, shaders compiled and the world still being made, which a warm-up hold can now count (holdShaderWarmup answers how much is left)
yhh7912a874a4e0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d1b257e35..0835c11b6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -36,6 +36,7 @@ published separately; it ships inside the editor.### Fixed+- **A playable's start-screen bar moves through the whole boot.** The bar's stages were weighed for a web page, most of whose start is fetching the engine. A playable has the engine inlined, so its bar stood at 82% within a second and crawled to 95% over the twenty-five that followed. A playable now weighs its own stages (the scene's is four fifths of the bar), and that stage is followed in three stretches: assets being read and made (eased by the clock, since nothing counts them), shaders compiled against the most seen compiling, and the world prepared against the most its makers said was left. For that, a hold given to `holdShaderWarmup` may answer a number (pages, cells) where it answered yes, and `warmShaders` passes the sum to `onProgress`; Terrain and Foliage count theirs. One lake scene's bar went from 18% to 95% over its 22 seconds, with one stretch of four seconds standing still. `attachSplash` takes the weights.- **An effect chain keeps its uniform buffers from frame to frame.** A camera's post-process chain is said again every frame, and each of its passes made a uniform buffer for its parameters and deleted it when the chain was cleared: seventeen buffers created and seventeen deleted every frame for a lake scene with a volume's usual effects, counted in the GL calls of an exported page. The buffers of a cleared chain are now taken over by the passes of the next chain that need one the same size, and one that nothing has taken in eight clears is deleted. The same scene creates none in a steady frame.- **Walking a frame's meshes costs less, and the profiler says what it costs.** Every mesh, in every view, asked its material's layout several questions by name (does it read the picture behind it, is its alpha coverage, does it cut out a shadow), each a string search; they are answered once when the layout is registered, and the last material and layout asked for are kept. A child of a model (most of an imported scene's meshes) was decomposed afresh by every view of every frame though its matrix had not changed; it is decomposed again only when it moves. And the mesh walk read the clock at every phase of every mesh while profiled, which was four in ten samples of a profiled frame and most of the time it reported; it is timed whole (the split by phase is the build option `ES_PROFILE_COLLECT_PHASES`). On the Bistro scene at 640x360, the best of seven interleaved runs went from 9.97 to 6.83 ms a frame, and a grid of 4096 meshes on one material from 4.08 to 3.09 ms. `render-submit-cost.mjs --wall` times frames with the profiler off.- **Sprite and particle shaders compile in the background too.** With `quality.asyncShaderCompile`, mesh and material shaders were compiled without holding a frame, and the batch shader's variants (sprites, text, lit sprites) and the particle shader were not: each was linked in place when first needed, measured at 350 to 490 ms of one frame mid-play under ANGLE. They are deferred the same way now, their texture units set when the link lands. Without the setting nothing changes.diff --git a/pipeline/src/export/splash.ts b/pipeline/src/export/splash.tsindex 99dc843f9..4ec8a2329 100644--- a/pipeline/src/export/splash.ts+++ b/pipeline/src/export/splash.ts@@ -118,8 +118,13 @@ export const FIRST_FRAME_EVENT = 'esengine:firstframe';* Always returns: a page with no start screen (a playable exported before it had* one) still has a portal around it that wants the events. A boot must never be a* thing the start screen can fail.+ *+ * `weights` replaces a stage's share of the bar for a host whose boot is shaped differently: the list's own are a web page's,+ * most of whose start is fetching the engine, and a page with everything inlined spends that time elsewhere.*/-export function attachSplash(doc: Document = document): Splash {+export function attachSplash(doc: Document = document, weights: Partial<Record<BootStage, number>> = {}): Splash {+ const weightOf = (stage: BootStage): number => weights[stage] ?? BOOT_STAGES.find((s) => s.id === stage)?.weight ?? 0;+ const total = BOOT_STAGES.reduce((n, s) => n + weightOf(s.id), 0) || BOOT_TOTAL;const root = doc.getElementById(ROOT);const bar = root && doc.getElementById(BAR);const label = root && doc.getElementById(LABEL);@@ -151,9 +156,8 @@ export function attachSplash(doc: Document = document): Splash {return {within(stage, fraction) {if (seen.has(stage)) return;- const weight = BOOT_STAGES.find((s) => s.id === stage)?.weight ?? 0;- const partial = Math.max(0, Math.min(1, fraction)) * weight;- const progress = Math.min(1, (done + partial) / BOOT_TOTAL);+ const partial = Math.max(0, Math.min(1, fraction)) * weightOf(stage);+ const progress = Math.min(1, (done + partial) / total);// `partial` marks a stage still running, so a listener can tell "40% of// the way through fetching the engine" from "the engine is up".if (show(progress)) announce(BOOT_PROGRESS_EVENT, { stage, progress, partial: true });@@ -163,8 +167,8 @@ export function attachSplash(doc: Document = document): Splash {// past what it has actually finished.if (seen.has(stage)) return;seen.add(stage);- done += BOOT_STAGES.find((s) => s.id === stage)?.weight ?? 0;- const progress = Math.min(1, done / BOOT_TOTAL);+ done += weightOf(stage);+ const progress = Math.min(1, done / total);show(progress);const at = BOOT_STAGES.findIndex((s) => s.id === stage);const next = BOOT_STAGES[at + 1];diff --git a/pipeline/src/runtime/playableHost.ts b/pipeline/src/runtime/playableHost.tsindex 2bc0f7ba7..1341fdcb9 100644--- a/pipeline/src/runtime/playableHost.ts+++ b/pipeline/src/runtime/playableHost.ts@@ -42,6 +42,13 @@ declare const __GAME_FIRST__: string;* learning a new name for it. Absent fields are their defaults. */declare const __GAME_RUNTIME__: PackagedRuntimeFields;+/** A playable's share of the bar per stage: nothing is fetched, so the four a web page spends on the network are a sliver. */+const PLAYABLE_WEIGHTS = { config: 1, scripts: 1, manifest: 1, scene: 1, engine: 8, app: 6, assets: 80, ready: 2 } as const;+/** Of the scene's stage: reading and making its assets, then compiling its shaders; what is left is the world being prepared. */+const LOAD_SHARE = 0.3, COMPILE_SHARE = 0.25;+/** The time the uncounted loading stretch takes to cover about two thirds of its share. */+const LOAD_EASE_MS = 5000;+function decodeBase64(b64: string): Uint8Array {const raw = atob(b64);const bytes = new Uint8Array(raw.length);@@ -87,7 +94,9 @@ async function boot(): Promise<void> {typeof __GAME_RUNTIME__ !== 'undefined' ? __GAME_RUNTIME__ : {};// The page's start screen (an export from before it had one has none, and this then only announces the boot). Nothing is fetched,// so the stages a web build spends on the network are behind it already.- const splash = attachSplash();+ // The bar is weighed for this page, not a web one: the engine is here already (a quarter of a second to inflate and compile on a+ // desktop), and nearly all of the wait is the scene's: its assets read and made, its shaders compiled, its world prepared.+ const splash = attachSplash(document, PLAYABLE_WEIGHTS);for (const stage of ['config', 'scripts', 'manifest', 'scene'] as const) splash.reach(stage);// The page has to paint the screen before the engine is inflated and compiled, which holds this thread.await new Promise<void>((resolve) => requestAnimationFrame(() => setTimeout(resolve, 0)));@@ -157,11 +166,21 @@ async function boot(): Promise<void> {};}- // The bar's last stretch follows the shaders: of the most seen compiling at once, how many are done.- let most = 0;- const warming = (pending: number): void => {- most = Math.max(most, pending);- if (most > 0) splash.within('assets', 1 - pending / most);+ // The scene's stage in three stretches. Loading has no count to follow (the runtime reads and makes what the scene names in one+ // call), so the bar eases toward the end of its share by the clock and never reaches it. The other two are counted: shaders+ // against the most seen compiling at once, and the world against the most its makers said was left.+ const loadStarted = performance.now();+ const loading = setInterval(() => {+ splash.within('assets', LOAD_SHARE * (1 - Math.exp(-(performance.now() - loadStarted) / LOAD_EASE_MS)));+ }, 200);+ let mostCompiling = 0, mostMaking = 0;+ const warming = (pending: number, making: number): void => {+ clearInterval(loading);+ mostCompiling = Math.max(mostCompiling, pending);+ mostMaking = Math.max(mostMaking, making);+ const compiled = mostCompiling > 0 ? 1 - pending / mostCompiling : 1;+ const made = mostMaking > 0 ? 1 - making / mostMaking : 1;+ splash.within('assets', LOAD_SHARE + COMPILE_SHARE * compiled + (1 - LOAD_SHARE - COMPILE_SHARE) * made);// With none left compiling the warm-up is waiting on what is still being made (a ground's pages, a field's cells).splash.busy(pending > 0 ? 'Compiling shaders' : 'Preparing the scene');};@@ -178,7 +197,7 @@ async function boot(): Promise<void> {// The same condition the web host warms on: shaders compiled in the background, and the project asked to open on a complete picture....(runtimeConfig.quality?.asyncShaderCompile && runtimeConfig.quality.prewarmShaders? { prewarmShaders: { timeoutMs: runtimeConfig.quality.prewarmTimeoutMs, onProgress: warming } } : {}),- onBeforeRun: () => { splash.reach('assets'); splash.reach('ready'); splash.done(); },+ onBeforeRun: () => { clearInterval(loading); splash.reach('assets'); splash.reach('ready'); splash.done(); },// Everything the config APPLIES to a live app: physics, the mixer, the theme....packagedRuntimeInit(runtimeConfig),});diff --git a/pipeline/tests/splash-screen.test.ts b/pipeline/tests/splash-screen.test.tsindex 3bc8fa404..a62a9388e 100644--- a/pipeline/tests/splash-screen.test.ts+++ b/pipeline/tests/splash-screen.test.ts@@ -45,6 +45,20 @@ describe('driving the start screen', () => {expect(() => splash.busy('Compiling shaders')).not.toThrow();});+ it('weighs the bar as its host says, for a boot shaped unlike that of a web page', () => {+ const doc = mount();+ // Everything inlined: the network's stages are a sliver and the scene's is most of it.+ const splash = attachSplash(doc, { config: 1, scripts: 1, manifest: 1, scene: 1, engine: 8, app: 6, assets: 80, ready: 2 });+ const bar = (): string => doc.getElementById('es-splash-bar')!.style.width;+ for (const stage of ['config', 'scripts', 'manifest', 'scene', 'engine', 'app'] as const) splash.reach(stage);+ expect(bar()).toBe('18%');+ splash.within('assets', 0.5);+ expect(bar()).toBe('58%');+ splash.reach('assets');+ splash.reach('ready');+ expect(bar()).toBe('100%');+ });+it('shows a stretch nothing measures as alive, and says what it is', () => {const doc = mount();const splash = attachSplash(doc);diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex a0a06efe2..a58201928 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -8096,7 +8096,7 @@ physics3dBackend: Physics3DBackend | undefinedphysics3dWorld: Partial<Physics3DWorldConfig> | undefinedphysicsConfig: Physics2DPluginConfig | undefinedphysicsEnabled: boolean | undefined-prewarmShaders: { timeoutMs?: number; onProgress?: (pending: number) => void; } | undefined+prewarmShaders: { timeoutMs?: number; onProgress?: (pending: number, making: number) => void; } | undefinedruntime: RuntimeBuildConfig | undefinedscenes: { name: string; data: SceneData; }[]uiTheme: "dark" | "light" | undefined@@ -10107,7 +10107,7 @@ timedOut: boolean## ShaderWarmupOptions — interface @experimental```-onProgress: ((pending: number) => void) | undefined+onProgress: ((pending: number, making: number) => void) | undefinedsettleFrames: number | undefinedtimeoutMs: number | undefined```@@ -11805,6 +11805,7 @@ setModifier: (modifier: TerrainModifier) => voidsetPager: (pager: TerrainPager | null) => voidsetPaint: (paint: Repaint | null) => voidstatus: (entity: Entity) => TerrainStatus | null+toPrepare: numberstatic new (): Terrainsstatic prototype: Terrains```@@ -16368,7 +16369,7 @@ Plugin## holdShaderWarmup — function @experimental```-(app: App, busy: () => boolean): () => void+(app: App, busy: () => boolean | number): () => void```## imageBitmapOptions — function @experimentaldiff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 075d4697a..993d5786e 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -8310,7 +8310,7 @@ physics3dBackend: Physics3DBackend | undefinedphysics3dWorld: Partial<Physics3DWorldConfig> | undefinedphysicsConfig: Physics2DPluginConfig | undefinedphysicsEnabled: boolean | undefined-prewarmShaders: { timeoutMs?: number; onProgress?: (pending: number) => void; } | undefined+prewarmShaders: { timeoutMs?: number; onProgress?: (pending: number, making: number) => void; } | undefinedruntime: RuntimeBuildConfig | undefinedscenes: { name: string; data: SceneData; }[]uiTheme: "dark" | "light" | undefined@@ -10336,7 +10336,7 @@ timedOut: boolean## ShaderWarmupOptions — interface @experimental```-onProgress: ((pending: number) => void) | undefined+onProgress: ((pending: number, making: number) => void) | undefinedsettleFrames: number | undefinedtimeoutMs: number | undefined```@@ -12034,6 +12034,7 @@ setModifier: (modifier: TerrainModifier) => voidsetPager: (pager: TerrainPager | null) => voidsetPaint: (paint: Repaint | null) => voidstatus: (entity: Entity) => TerrainStatus | null+toPrepare: numberstatic new (): Terrainsstatic prototype: Terrains```@@ -16637,7 +16638,7 @@ Plugin## holdShaderWarmup — function @experimental```-(app: App, busy: () => boolean): () => void+(app: App, busy: () => boolean | number): () => void```## imageBitmapOptions — function @experimentaldiff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex 95d8a699e..8d80b50d5 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -8091,7 +8091,7 @@ physics3dBackend: Physics3DBackend | undefinedphysics3dWorld: Partial<Physics3DWorldConfig> | undefinedphysicsConfig: Physics2DPluginConfig | undefinedphysicsEnabled: boolean | undefined-prewarmShaders: { timeoutMs?: number; onProgress?: (pending: number) => void; } | undefined+prewarmShaders: { timeoutMs?: number; onProgress?: (pending: number, making: number) => void; } | undefinedruntime: RuntimeBuildConfig | undefinedscenes: { name: string; data: SceneData; }[]uiTheme: "dark" | "light" | undefined@@ -10102,7 +10102,7 @@ timedOut: boolean## ShaderWarmupOptions — interface @experimental```-onProgress: ((pending: number) => void) | undefined+onProgress: ((pending: number, making: number) => void) | undefinedsettleFrames: number | undefinedtimeoutMs: number | undefined```@@ -11800,6 +11800,7 @@ setModifier: (modifier: TerrainModifier) => voidsetPager: (pager: TerrainPager | null) => voidsetPaint: (paint: Repaint | null) => voidstatus: (entity: Entity) => TerrainStatus | null+toPrepare: numberstatic new (): Terrainsstatic prototype: Terrains```@@ -16363,7 +16364,7 @@ Plugin## holdShaderWarmup — function @experimental```-(app: App, busy: () => boolean): () => void+(app: App, busy: () => boolean | number): () => void```## imageBitmapOptions — function @experimentaldiff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex 72cacd7b5..e75509e8e 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -8388,7 +8388,7 @@ physics3dBackend: Physics3DBackend | undefinedphysics3dWorld: Partial<Physics3DWorldConfig> | undefinedphysicsConfig: Physics2DPluginConfig | undefinedphysicsEnabled: boolean | undefined-prewarmShaders: { timeoutMs?: number; onProgress?: (pending: number) => void; } | undefined+prewarmShaders: { timeoutMs?: number; onProgress?: (pending: number, making: number) => void; } | undefinedruntime: RuntimeBuildConfig | undefinedscenes: { name: string; data: SceneData; }[]uiTheme: "dark" | "light" | undefined@@ -10399,7 +10399,7 @@ timedOut: boolean## ShaderWarmupOptions — interface @experimental```-onProgress: ((pending: number) => void) | undefined+onProgress: ((pending: number, making: number) => void) | undefinedsettleFrames: number | undefinedtimeoutMs: number | undefined```@@ -12097,6 +12097,7 @@ setModifier: (modifier: TerrainModifier) => voidsetPager: (pager: TerrainPager | null) => voidsetPaint: (paint: Repaint | null) => voidstatus: (entity: Entity) => TerrainStatus | null+toPrepare: numberstatic new (): Terrainsstatic prototype: Terrains```@@ -16671,7 +16672,7 @@ Plugin## holdShaderWarmup — function @experimental```-(app: App, busy: () => boolean): () => void+(app: App, busy: () => boolean | number): () => void```## imageBitmapOptions — function @experimentaldiff --git a/sdk/etc/terrain.api.md b/sdk/etc/terrain.api.mdindex 7412303db..bdf86035a 100644--- a/sdk/etc/terrain.api.md+++ b/sdk/etc/terrain.api.md@@ -660,6 +660,7 @@ setModifier: (modifier: TerrainModifier) => voidsetPager: (pager: TerrainPager | null) => voidsetPaint: (paint: Repaint | null) => voidstatus: (entity: Entity) => TerrainStatus | null+toPrepare: numberstatic new (): Terrainsstatic prototype: Terrains```diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex 66e35c5be..340f51311 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -8098,7 +8098,7 @@ physics3dBackend: Physics3DBackend | undefinedphysics3dWorld: Partial<Physics3DWorldConfig> | undefinedphysicsConfig: Physics2DPluginConfig | undefinedphysicsEnabled: boolean | undefined-prewarmShaders: { timeoutMs?: number; onProgress?: (pending: number) => void; } | undefined+prewarmShaders: { timeoutMs?: number; onProgress?: (pending: number, making: number) => void; } | undefinedruntime: RuntimeBuildConfig | undefinedscenes: { name: string; data: SceneData; }[]uiTheme: "dark" | "light" | undefined@@ -10109,7 +10109,7 @@ timedOut: boolean## ShaderWarmupOptions — interface @experimental```-onProgress: ((pending: number) => void) | undefined+onProgress: ((pending: number, making: number) => void) | undefinedsettleFrames: number | undefinedtimeoutMs: number | undefined```@@ -11807,6 +11807,7 @@ setModifier: (modifier: TerrainModifier) => voidsetPager: (pager: TerrainPager | null) => voidsetPaint: (paint: Repaint | null) => voidstatus: (entity: Entity) => TerrainStatus | null+toPrepare: numberstatic new (): Terrainsstatic prototype: Terrains```@@ -16397,7 +16398,7 @@ Plugin## holdShaderWarmup — function @experimental```-(app: App, busy: () => boolean): () => void+(app: App, busy: () => boolean | number): () => void```## imageBitmapOptions — function @experimentaldiff --git a/sdk/src/foliage/foliagePlugin.ts b/sdk/src/foliage/foliagePlugin.tsindex a0681d7d8..5db59179f 100644--- a/sdk/src/foliage/foliagePlugin.ts+++ b/sdk/src/foliage/foliagePlugin.ts@@ -290,7 +290,7 @@ export class FoliagePlugin implements Plugin {field.app_ = app;app.insertResource(FoliageRes, field);// Cells still to be grown, or grown and not yet put in the world, draw with shaders nothing has asked for yet.- holdShaderWarmup(app, () => app.hasResource(Assets) && (field.pending > 0 || field.landed_.length > 0));+ holdShaderWarmup(app, () => (app.hasResource(Assets) ? field.pending + field.landed_.length : 0));this.clearContacts_ = installFoliageContacts(app);app.addSystemToSchedule(Schedule.Update, defineSystem([], () => {diff --git a/sdk/src/render/shaderWarmup.ts b/sdk/src/render/shaderWarmup.tsindex 2c9afb981..f0b11b9e0 100644--- a/sdk/src/render/shaderWarmup.ts+++ b/sdk/src/render/shaderWarmup.ts@@ -29,32 +29,38 @@ export interface ShaderWarmupOptions {timeoutMs?: number;/** Consecutive frames in which nothing was compiling before it counts as done: a frame can ask for a shader the one before did not. Default 3. */settleFrames?: number;- /** Called after each frame with how many shaders are still compiling. */- onProgress?: (pending: number) => void;+ /** Called after each frame with how many shaders are still compiling, and how much the scene's holds say is still to be made. */+ onProgress?: (pending: number, making: number) => void;}-const holds = new WeakMap<App, Set<() => boolean>>();+const holds = new WeakMap<App, Set<() => boolean | number>>();/*** Tells {@link warmShaders} that part of the scene is still being made while `busy` answers true: a ground whose pages are being painted, a field* whose cells are being grown. What is made later draws with shaders nothing has asked for yet, and a warm-up that stopped at the first quiet- * frames opened on a scene that then filled in. Returns what takes the hold away.+ * frames opened on a scene that then filled in. A number is how much is left to make (pages, cells: whatever the maker counts in), which+ * a loading screen can show going down; true is one thing of no size. Returns what takes the hold away.* @experimental*/-export function holdShaderWarmup(app: App, busy: () => boolean): () => void {+export function holdShaderWarmup(app: App, busy: () => boolean | number): () => void {let set = holds.get(app);if (!set) holds.set(app, set = new Set());set.add(busy);return () => { set.delete(busy); };}-function held(app: App): boolean {+/** How much the holds say is still being made: 0 when nothing is. */+function making(app: App): number {const set = holds.get(app);- if (!set) return false;+ if (!set) return 0;+ let left = 0;for (const busy of set) {- try { if (busy()) return true; } catch { /* a probe that throws holds nothing */ }+ try {+ const n = busy();+ left += n === true ? 1 : typeof n === 'number' && n > 0 ? n : 0;+ } catch { /* a probe that throws holds nothing */ }}- return false;+ return left;}const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));@@ -105,9 +111,10 @@ export async function warmShaders(app: App, options: ShaderWarmupOptions = {}):await app.stepFrames(1, 1e-4);++frames;pending = module.renderer_getPendingShaders?.() ?? 0;- options.onProgress?.(pending);+ const left = making(app);+ options.onProgress?.(pending, left);// Quiet is nothing compiling AND nothing still being made that will ask for more.- quiet = pending === 0 && !held(app) ? quiet + 1 : 0;+ quiet = pending === 0 && left === 0 ? quiet + 1 : 0;// The browser compiles between tasks: give it one.await sleep(8);}diff --git a/sdk/src/runtime/playableRuntime.ts b/sdk/src/runtime/playableRuntime.tsindex 1c2c3970d..3ecce0474 100644--- a/sdk/src/runtime/playableRuntime.ts+++ b/sdk/src/runtime/playableRuntime.ts@@ -74,7 +74,7 @@ export interface PlayableRuntimeConfig {* Draw the first scene out of sight (the canvas hidden) until its shaders have compiled, and show it complete: `quality.prewarmShaders` of a* project that also compiles them in the background. The wait is at most `timeoutMs`.*/- prewarmShaders?: { timeoutMs?: number; /** Called after each frame drawn out of sight with how many shaders are still compiling. */ onProgress?: (pending: number) => void };+ prewarmShaders?: { timeoutMs?: number; /** Called after each frame drawn out of sight with how many shaders are still compiling and how much of the scene is still to be made. */ onProgress?: (pending: number, making: number) => void };/** Called once everything is loaded and warmed, just before the loop starts: where a page takes its start screen away. */onBeforeRun?: () => void;}diff --git a/sdk/src/terrain/terrainPlugin.ts b/sdk/src/terrain/terrainPlugin.tsindex cc27d65dd..03a8c5fb9 100644--- a/sdk/src/terrain/terrainPlugin.ts+++ b/sdk/src/terrain/terrainPlugin.ts@@ -595,12 +595,16 @@ export class Terrains {}/** A ground is not drawn yet, or its layers are still being packed: what it draws with has not all been asked for. */- get preparing(): boolean {+ get preparing(): boolean { return this.toPrepare > 0; }++ /** How much of that is left: the pages still wanted, and one for each ground not yet drawn or still packing its layers. */+ get toPrepare(): number {+ let n = 0;for (const b of this.built_.values()) {if (b.failure) continue;- if (b.loading || !b.instance || b.packing || b.wanted.size > 0) return true;+ n += b.wanted.size + (b.loading || !b.instance || b.packing ? 1 : 0);}- return false;+ return n;}/** How many pages every terrain still wants made for what is in view. */@@ -683,7 +687,7 @@ export class TerrainPlugin implements Plugin {const terrains = new Terrains();terrains.app_ = app;app.insertResource(TerrainsRes, terrains);- holdShaderWarmup(app, () => app.hasResource(Assets) && terrains.preparing);+ holdShaderWarmup(app, () => (app.hasResource(Assets) ? terrains.toPrepare : 0));app.addSystemToSchedule(Schedule.Update, defineSystem([], () => {// What the ground IS needs no renderer: a server or a test without one still makes the source and answers from it.diff --git a/sdk/tests/shader-warmup.test.ts b/sdk/tests/shader-warmup.test.tsindex 19ce9e097..b90e4a641 100644--- a/sdk/tests/shader-warmup.test.ts+++ b/sdk/tests/shader-warmup.test.ts@@ -58,6 +58,15 @@ describe('shader warm-up', () => {expect((await warmShaders(app, { timeoutMs: 40 })).timedOut).toBe(true);release();expect((await warmShaders(app, { settleFrames: 2, timeoutMs: 400 })).frames).toBe(2);++ // A hold that counts says how much is left, for a loading screen to show going down; one that only says yes is one thing.+ let pages = 3;+ const off = [holdShaderWarmup(app, () => pages), holdShaderWarmup(app, () => pages > 1)];+ stepFrames.mockImplementation(async () => { if (pages > 0) --pages; });+ const left: number[] = [];+ await warmShaders(app, { settleFrames: 1, onProgress: (_pending, making) => left.push(making) });+ expect(left).toEqual([3, 1, 0]);+ off.forEach((f) => f());});it('does nothing where there is nothing to wait for', async () => {diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex f35a544f5..94138bfee 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -4792,4 +4792,6 @@ export const NOTED = {{"note": "An effect chain keeps its uniform buffers from frame to frame."},"feat(playable): a playable opens on a start screen - the page was empty while the engine was inflated and compiled and the first scene warmed, twenty-five seconds of nothing for one lake scene; it carries the web export's start screen now (title, bar, what the boot is doing), taken away just before the loop starts, and a stretch nothing measures (shaders compiling, a world being made) runs a light along the bar and says so, on a web page too":{"note": "A playable opens on a start screen."},+ "fix(playable): a playable's start-screen bar moves through the whole boot - it was weighed as a web page's, whose start is mostly fetching the engine, so a page with everything inlined stood at 82% within a second and crawled for the rest; a playable weighs its own stages, and the scene's is followed through loading, shaders compiled and the world still being made, which a warm-up hold can now count (holdShaderWarmup answers how much is left)":+ {"note": "A playable's start-screen bar moves through the whole boot."},};