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: prepare paused scenes without advancing simulation
yhh89f5a57014b0
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex fe09ad2c8..170633aa4 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -10889,6 +10889,7 @@ query: QueryCost | undefined@internal _params: readonly SystemParam[]@internal _runAfter: readonly string[] | undefined@internal _runBefore: readonly string[] | undefined+@internal _runWhenPaused: boolean | undefined@internal _touches: SystemTouches | (() => SystemTouches) | undefined```@@ -10897,6 +10898,7 @@ query: QueryCost | undefinedname: string | undefinedrunAfter: string[] | undefinedrunBefore: string[] | undefined+runWhenPaused: boolean | undefinedtouches: SystemTouches | (() => SystemTouches) | undefined```diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 8a7d35c66..166d3c06d 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -11105,6 +11105,7 @@ query: QueryCost | undefined@internal _params: readonly SystemParam[]@internal _runAfter: readonly string[] | undefined@internal _runBefore: readonly string[] | undefined+@internal _runWhenPaused: boolean | undefined@internal _touches: SystemTouches | (() => SystemTouches) | undefined```@@ -11113,6 +11114,7 @@ query: QueryCost | undefinedname: string | undefinedrunAfter: string[] | undefinedrunBefore: string[] | undefined+runWhenPaused: boolean | undefinedtouches: SystemTouches | (() => SystemTouches) | undefined```diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex 3ab6f8e74..7febc6f6d 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -10884,6 +10884,7 @@ query: QueryCost | undefined@internal _params: readonly SystemParam[]@internal _runAfter: readonly string[] | undefined@internal _runBefore: readonly string[] | undefined+@internal _runWhenPaused: boolean | undefined@internal _touches: SystemTouches | (() => SystemTouches) | undefined```@@ -10892,6 +10893,7 @@ query: QueryCost | undefinedname: string | undefinedrunAfter: string[] | undefinedrunBefore: string[] | undefined+runWhenPaused: boolean | undefinedtouches: SystemTouches | (() => SystemTouches) | undefined```diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex b2c9bbdd8..b903c131f 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -11180,6 +11180,7 @@ query: QueryCost | undefined@internal _params: readonly SystemParam[]@internal _runAfter: readonly string[] | undefined@internal _runBefore: readonly string[] | undefined+@internal _runWhenPaused: boolean | undefined@internal _touches: SystemTouches | (() => SystemTouches) | undefined```@@ -11188,6 +11189,7 @@ query: QueryCost | undefinedname: string | undefinedrunAfter: string[] | undefinedrunBefore: string[] | undefined+runWhenPaused: boolean | undefinedtouches: SystemTouches | (() => SystemTouches) | undefined```diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex 11120f354..872d89064 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -10891,6 +10891,7 @@ query: QueryCost | undefined@internal _params: readonly SystemParam[]@internal _runAfter: readonly string[] | undefined@internal _runBefore: readonly string[] | undefined+@internal _runWhenPaused: boolean | undefined@internal _touches: SystemTouches | (() => SystemTouches) | undefined```@@ -10899,6 +10900,7 @@ query: QueryCost | undefinedname: string | undefinedrunAfter: string[] | undefinedrunBefore: string[] | undefined+runWhenPaused: boolean | undefinedtouches: SystemTouches | (() => SystemTouches) | undefined```diff --git a/sdk/src/app/app.ts b/sdk/src/app/app.tsindex 3e7e4bef2..f2e10b7ad 100644--- a/sdk/src/app/app.ts+++ b/sdk/src/app/app.ts@@ -920,6 +920,7 @@ export class App {return this;}+ /** Pause simulation time and ordinary systems; presentation opt-ins and Last still run. */setPaused(paused: boolean): void {this.user_paused_ = paused;}@@ -1624,6 +1625,10 @@ export class App {this.frame_paused_ = false;if (this.isPaused() && !this.step_pending_) {+ await this.runSchedule(Schedule.First, executionEpoch, true);+ await this.runSchedule(Schedule.PreUpdate, executionEpoch, true);+ await this.runSchedule(Schedule.Update, executionEpoch, true);+ await this.runSchedule(Schedule.PostUpdate, executionEpoch, true);await this.runSchedule(Schedule.Last, executionEpoch);} else {await this.runSchedule(Schedule.First, executionEpoch);@@ -1885,7 +1890,7 @@ export class App {}}- private async runSchedule(schedule: Schedule, executionEpoch = this.executionEpoch_): Promise<void> {+ private async runSchedule(schedule: Schedule, executionEpoch = this.executionEpoch_, pausedOnly = false): Promise<void> {const rawSystems = this.systems_.get(schedule);if (!rawSystems || !this.runner_ || this.frame_paused_ || this.isExecutionHeld() || executionEpoch !== this.executionEpoch_) {return;@@ -1917,6 +1922,7 @@ export class App {const entry = systems[i];if (this.frame_paused_ || this.isExecutionHeld() || executionEpoch !== this.executionEpoch_) break;if (schedule === Schedule.Startup && entry.startupInvoked) continue;+ if (pausedOnly && !entry.system._runWhenPaused) continue;if (entry.runIf && !entry.runIf()) { if (schedule === Schedule.Startup) entry.startupInvoked = true; continue; }if (entry.gate && schedule !== Schedule.Startup && !this.gateOpen_(entry.gate)) continue;@@ -2009,7 +2015,7 @@ export class App {const time = this.resources_.get(Time);const scale = time.scale >= 0 ? time.scale : 0;time.unscaledDelta = delta;- time.delta = hostPauseOwners.get(this)?.size && !this.step_pending_ ? 0 : delta * scale;+ time.delta = this.isPaused() && !this.step_pending_ ? 0 : delta * scale;time.elapsed += time.delta;time.frameCount++;if (this.step_pending_) this.steppedFrames_++;diff --git a/sdk/src/camera/CameraPlugin.ts b/sdk/src/camera/CameraPlugin.tsindex c6c7f20ee..0aaf5f77c 100644--- a/sdk/src/camera/CameraPlugin.ts+++ b/sdk/src/camera/CameraPlugin.ts@@ -860,6 +860,7 @@ export function cameraPlugin(const uiCameraSyncSystem: SystemDef = {_id: Symbol('UICameraSyncSystem'),_name: 'UICameraSyncSystem',+ _runWhenPaused: true,_params: [],_fn: () => {const { width, height } = viewport();diff --git a/sdk/src/ecs/system.ts b/sdk/src/ecs/system.tsindex 26a228371..ce7cac4dc 100644--- a/sdk/src/ecs/system.ts+++ b/sdk/src/ecs/system.ts@@ -159,13 +159,15 @@ export interface SystemDef {/** @internal */readonly _runAfter?: readonly string[];/** @internal */+ readonly _runWhenPaused?: boolean;+ /** @internal */readonly _touches?: SystemTouches | (() => SystemTouches);}let templateCounter_ = 0;/**- * Ordering a system carries with it. The names are matched against other+ * Scheduling policy a system carries with it. Names are matched against other* systems' names and against {@link SystemSet} names, so a set can be ordered* against without knowing which systems are in it.*@@ -178,6 +180,8 @@ export interface SystemOptions {runBefore?: string[];/** This system runs after each of these names (a system or a set). */runAfter?: string[];+ /** Opt into paused First/PreUpdate/Update/PostUpdate frames. Last already runs; fixed steps stay stopped. */+ runWhenPaused?: boolean;/*** What the system reaches for through {@link GetWorld}. See {@link SystemTouches}.*@@ -232,6 +236,7 @@ export function defineSystem<P extends readonly SystemParam[]>(_name: options?.name ?? '',_runBefore: options?.runBefore,_runAfter: options?.runAfter,+ _runWhenPaused: options?.runWhenPaused,_touches: options?.touches,};}diff --git a/sdk/src/postprocess/volumeSystem.ts b/sdk/src/postprocess/volumeSystem.tsindex b1ec3e580..8430df1c5 100644--- a/sdk/src/postprocess/volumeSystem.ts+++ b/sdk/src/postprocess/volumeSystem.ts@@ -338,7 +338,7 @@ export const postProcessVolumeSystem = defineSystem(applyBlendedEffects(api, cameraEntity, effectsAt(volumes, p.x, p.y, p.z), cameraData.projectionType !== ProjectionType.Orthographic);}},- { name: 'PostProcessVolumeSystem' }+ { name: 'PostProcessVolumeSystem', runWhenPaused: true });/**@@ -362,7 +362,7 @@ export function editorViewVolumeSystem(app: App) {const at = view.perspective ? editorViewEye(view) : { x: view.x, y: view.y, z: view.z };applyBlendedEffects(api, eye, effectsAt(volumes, at.x, at.y, at.z), view.perspective);},- { name: 'EditorViewVolumeSystem' },+ { name: 'EditorViewVolumeSystem', runWhenPaused: true },);}diff --git a/sdk/src/ui/layout/layout.ts b/sdk/src/ui/layout/layout.tsindex 47bf6bca9..f41881b20 100644--- a/sdk/src/ui/layout/layout.ts+++ b/sdk/src/ui/layout/layout.ts@@ -96,7 +96,7 @@ export class UILayoutPlugin implements Plugin {app.addSystemToSchedule(Schedule.PreUpdate, defineSystem([Res(ScreenLayout)],layoutFn,- { name: 'UILayoutSystem' }+ { name: 'UILayoutSystem', runWhenPaused: true }));// No transform pass after the late layout: nothing between PostUpdate and@@ -105,7 +105,7 @@ export class UILayoutPlugin implements Plugin {app.addSystemToSchedule(Schedule.PostUpdate, defineSystem([Res(ScreenLayout)],layoutOnlyFn,- { name: 'UILayoutLateSystem' }+ { name: 'UILayoutLateSystem', runWhenPaused: true }), { runAfter: [SystemLabel.ListView], runBefore: [SystemLabel.UIRenderOrder] });}}diff --git a/sdk/src/ui/layout/rect-anchors.ts b/sdk/src/ui/layout/rect-anchors.tsindex c6354a4c1..f1b69e77e 100644--- a/sdk/src/ui/layout/rect-anchors.ts+++ b/sdk/src/ui/layout/rect-anchors.ts@@ -145,12 +145,12 @@ export class RectAnchorsPlugin implements Plugin {app.addSystemToSchedule(Schedule.PostUpdate, defineSystem([Res(ScreenLayout)],(screen: ScreenLayoutData) => alignFrame(world, screen),- { name: SystemLabel.RectAnchors },+ { name: SystemLabel.RectAnchors, runWhenPaused: true },), { runBefore: [SystemLabel.UILayoutLate] });app.addSystemToSchedule(Schedule.PostUpdate, defineSystem([Res(ScreenLayout)],(screen: ScreenLayoutData) => alignFrame(world, screen),- { name: SystemLabel.RectAnchorsLate },+ { name: SystemLabel.RectAnchorsLate, runWhenPaused: true },), { runAfter: [SystemLabel.RectAnchors], runBefore: [SystemLabel.UIRenderOrder] });}}diff --git a/sdk/src/ui/layout/safe-area.ts b/sdk/src/ui/layout/safe-area.tsindex 43b3e04a9..02f9912fa 100644--- a/sdk/src/ui/layout/safe-area.ts+++ b/sdk/src/ui/layout/safe-area.ts@@ -194,7 +194,7 @@ export class SafeAreaPlugin implements Plugin {}}},- { name: 'SafeAreaSystem' }+ { name: 'SafeAreaSystem', runWhenPaused: true }), { runBefore: [SystemLabel.UILayout] });}}diff --git a/sdk/src/ui/render/content-rect.ts b/sdk/src/ui/render/content-rect.tsindex 9b3c6f782..f1ae97c43 100644--- a/sdk/src/ui/render/content-rect.ts+++ b/sdk/src/ui/render/content-rect.ts@@ -28,7 +28,7 @@ export class ContentRectPlugin implements Plugin {if (world.isChangedSince(entity, ContentRect, since)) applyContentRect(world, entity);}};- app.addSystemToSchedule(Schedule.PostUpdate, defineSystem([], sync, { name: 'ContentRectSystem' }));+ app.addSystemToSchedule(Schedule.PostUpdate, defineSystem([], sync, { name: 'ContentRectSystem', runWhenPaused: true }));app.addSystemToSchedule(Schedule.Last, defineSystem([], sync, { name: 'ContentRectLateSystem' }));}}diff --git a/sdk/src/ui/render/render-order.ts b/sdk/src/ui/render/render-order.tsindex ed6b446a2..712fca441 100644--- a/sdk/src/ui/render/render-order.ts+++ b/sdk/src/ui/render/render-order.ts@@ -22,7 +22,7 @@ export class UIRenderOrderPlugin implements Plugin {app.addSystemToSchedule(Schedule.PostUpdate, defineSystem([],() => { engine?.uiRenderOrder_update?.(registry); },- { name: 'UIRenderOrderSystem' }+ { name: 'UIRenderOrderSystem', runWhenPaused: true }));}}diff --git a/sdk/src/ui/text/inline-image-plugin.ts b/sdk/src/ui/text/inline-image-plugin.tsindex adf088cb1..3c17d1f06 100644--- a/sdk/src/ui/text/inline-image-plugin.ts+++ b/sdk/src/ui/text/inline-image-plugin.ts@@ -147,7 +147,7 @@ export class InlineImagePlugin implements Plugin {for (const [e, kids] of childrenOf) {if (!seen.has(e)) { despawnKids(kids); childrenOf.delete(e); }}- }, { name: 'InlineImageSystem' }));+ }, { name: 'InlineImageSystem', runWhenPaused: true }));function reap(textEntity: Entity): void {const kids = childrenOf.get(textEntity);diff --git a/sdk/src/ui/text/plugin.ts b/sdk/src/ui/text/plugin.tsindex 38b74e019..9f7e6f789 100644--- a/sdk/src/ui/text/plugin.ts+++ b/sdk/src/ui/text/plugin.ts@@ -244,12 +244,12 @@ export class TextPlugin implements Plugin {for (const renderer of [state.world.bitmap, state.world.sdf, state.screen.bitmap, state.screen.sdf]) {renderer?.beginFrame();}- }, { name: 'TextPageLifetimeSystem' }));+ }, { name: 'TextPageLifetimeSystem', runWhenPaused: true }));app.addSystemToSchedule(Schedule.PreUpdate, defineSystem([], () => {const state = this.states_.get(app);if (state && state.preloads.length > 0) this.stepPreloads(app, state.preloads);- }, { name: 'TextGlyphPreloadSystem' }));+ }, { name: 'TextGlyphPreloadSystem', runWhenPaused: true }));// A Text node inside a UINode is a UI render node: ensure it carries a// UIVisual (visualType None — not drawn as a quad) so the UI@@ -260,13 +260,14 @@ export class TextPlugin implements Plugin {ensureUIVisual(world, e as Entity);}};- app.addSystemToSchedule(Schedule.PreUpdate, defineSystem([], ensureTextRenderNodes, { name: 'TextRenderNodeSystem' }));+ app.addSystemToSchedule(Schedule.PreUpdate, defineSystem([], ensureTextRenderNodes, { name: 'TextRenderNodeSystem', runWhenPaused: true }));// A Text spawned in Update is not seen by the PreUpdate pass, so it would// reach the order pass with no UIVisual, take no uiOrder, and be drawn at// the base layer — under every panel — for its first frame. The late pass// gives it one before the order is assigned.app.addSystemToSchedule(Schedule.PostUpdate, defineSystem([], ensureTextRenderNodes, {name: 'TextRenderNodeLateSystem',+ runWhenPaused: true,runBefore: [SystemLabel.UIRenderOrder],}));@@ -277,7 +278,7 @@ export class TextPlugin implements Plugin {app.addSystemToSchedule(Schedule.PreUpdate, defineSystem([], () => {if (!app.hasResource(Localization)) return;applyTextLocalization(world as unknown as TextWorldView, app.getResource(Localization));- }, { name: 'TextLocalizeSystem' }));+ }, { name: 'TextLocalizeSystem', runWhenPaused: true }));const pipeline = app.pipeline;if (!pipeline) return; // logic-only host → nothing to drawdiff --git a/sdk/tests/aot-app.test.ts b/sdk/tests/aot-app.test.tsindex 71b85f7aa..92a4dba31 100644--- a/sdk/tests/aot-app.test.ts+++ b/sdk/tests/aot-app.test.ts@@ -37,14 +37,14 @@ const N = 8;useBytesPlatform();/** The same author's system either way; only whether a twin exists differs. */-function fadeApp(): { app: ReturnType<typeof bootMockApp>['app']; Fade: AnyComponentDef } {+function fadeApp(runWhenPaused = false): { app: ReturnType<typeof bootMockApp>['app']; Fade: AnyComponentDef } {const { app } = bootMockApp();const Fade = defineComponent('Fade', { alpha: 1, step: 0.1 }) as AnyComponentDef;app.addSystemToSchedule(Schedule.Update, defineSystem([Query(Mut(Fade))], (query) => {for (const [, fade] of query as Iterable<[Entity, { alpha: number; step: number }]>) {fade.alpha -= fade.step;}- }, { name: 'Fade' }));+ }, { name: 'Fade', runWhenPaused }));return { app, Fade };}@@ -62,6 +62,28 @@ const alphas = (app: ReturnType<typeof bootMockApp>['app'], Fade: AnyComponentDees.map((e) => (app.world.get(e, Fade) as { alpha: number }).alpha);describe('an App told to run its compiled twins', () => {+ it.skipIf(!EMCC)('applies paused presentation policy before dispatching compiled twins', async () => {+ const wasm = buildFadeModule(EMCC!, FADE_PROBE_C);+ for (const runWhenPaused of [false, true]) {+ const { app, Fade } = fadeApp(runWhenPaused);+ try {+ await app.useCompiledSystems({ host: new FakeEngine(), manifest: fadeManifest(), wasm });+ const entities = seed(app, Fade);+ const before = alphas(app, Fade, entities);+ app.setPaused(true);+ await app.tick(0.1);+ expect(app.compiledSystems.calls).toBe(runWhenPaused ? 1 : 0);+ expect(alphas(app, Fade, entities)).toEqual(runWhenPaused ? entities.map(() => FADE_PROBE_ALPHA) : before);+ expect(app.getResource(Time).elapsed).toBe(0);+ await app.stepFrames(1);+ expect(app.compiledSystems.calls).toBe(runWhenPaused ? 2 : 1);+ expect(app.isPaused()).toBe(true);+ } finally {+ app.quit();+ }+ }+ });+it.skipIf(!EMCC)('compiled scratch and foreign heap growth preserve held script views and cached query rows',async()=>{class GrowingEngine extends FakeEngine {grow():void {this.memory.grow(1);this.HEAPU8=new Uint8Array(this.memory.buffer);}diff --git a/sdk/tests/paused-presentation.test.ts b/sdk/tests/paused-presentation.test.tsnew file mode 100644index 000000000..60c2928a2--- /dev/null+++ b/sdk/tests/paused-presentation.test.ts@@ -0,0 +1,89 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+import { describe, expect, it } from 'vitest';+import { App, setAppHostPaused } from '../src/app/app';+import { Time } from '../src/ecs/resource';+import { defineSystem, defineSystemSet, Schedule } from '../src/ecs/system';++describe('paused presentation', () => {+ it('prepares every variable phase before rendering without running simulation', async () => {+ const app = App.new(), trace: string[] = [];+ const phases = [Schedule.First, Schedule.PreUpdate, Schedule.Update, Schedule.PostUpdate];+ for (const phase of phases) {+ app.addSystemToSchedule(phase, defineSystem([], () => { trace.push(Schedule[phase]); },+ { name: `Present${phase}`, runWhenPaused: true }));+ app.addSystemToSchedule(phase, defineSystem([], () => { trace.push('simulation'); }));+ }+ app.addSystemToSchedule(Schedule.FixedUpdate, defineSystem([], () => { trace.push('physics'); },+ { runWhenPaused: true }));+ app.addSystemToSchedule(Schedule.Last, defineSystem([], () => { trace.push('render'); }));+ app.setPaused(true);+ await app.tick(0.2);+ expect(trace).toEqual(['First', 'PreUpdate', 'Update', 'PostUpdate', 'render']);+ expect(app.getResource(Time)).toMatchObject({ delta: 0, elapsed: 0, fixedTick: 0, unscaledDelta: 0.2 });+ app.quit();+ });++ it.each(['user', 'host'] as const)('preserves explicit stepping and resume after %s pause', async owner => {+ const app = App.new(), host = {};+ let simulation = 0, presentation = 0;+ app.addSystem(defineSystem([], () => { simulation++; }));+ app.addSystem(defineSystem([], () => { presentation++; }, { runWhenPaused: true }));+ await app.tick(0.01);+ if (owner === 'host') setAppHostPaused(app, host, true);+ else app.setPaused(true);+ await app.tick(2);+ expect(simulation).toBe(1);+ expect(presentation).toBe(2);+ expect(app.getResource(Time).elapsed).toBeCloseTo(0.01);+ await app.stepFrames(1, 0.02);+ expect(app.isPaused()).toBe(true);+ expect(simulation).toBe(2);+ expect(presentation).toBe(3);+ expect(app.getResource(Time).elapsed).toBeCloseTo(0.03);+ if (owner === 'host') setAppHostPaused(app, host, false);+ else app.setPaused(false);+ await app.tick(0.01);+ expect(simulation).toBe(3);+ expect(presentation).toBe(4);+ expect(app.getResource(Time).elapsed).toBeCloseTo(0.04);+ app.quit();+ });++ it('preserves system-set gates and asynchronous ordering while filtering simulation', async () => {+ const app = App.new(), trace: string[] = [];+ let enabled = false;+ app.addSystemSet(defineSystemSet('presentation', {+ runIf: () => enabled,+ systems: [+ defineSystem([], () => { trace.push('layout'); },+ { name: 'layout', runAfter: ['viewport'], runWhenPaused: true }),+ defineSystem([], async () => { await Promise.resolve(); trace.push('viewport'); },+ { name: 'viewport', runWhenPaused: true }),+ defineSystem([], () => { trace.push('gameplay'); }, { name: 'gameplay' }),+ ],+ }));+ app.setPaused(true);+ await app.tick(0.1);+ expect(trace).toEqual([]);+ enabled = true;+ await app.tick(0.1);+ expect(trace).toEqual(['viewport', 'layout']);+ app.quit();+ });++ it('an execution hold still stops presentation and rendering', async () => {+ const app = App.new();+ let prepared = 0, rendered = 0;+ app.addSystem(defineSystem([], () => { prepared++; }, { runWhenPaused: true }));+ app.addSystemToSchedule(Schedule.Last, defineSystem([], () => { rendered++; }));+ app.setPaused(true);+ const release = app.holdExecution();+ await app.tick(0.1);+ expect([prepared, rendered]).toEqual([0, 0]);+ release();+ await app.tick(0.1);+ expect([prepared, rendered]).toEqual([1, 1]);+ app.quit();+ });+});diff --git a/sdk/tests/ui-layout-integration.test.ts b/sdk/tests/ui-layout-integration.test.tsindex 976ded476..c6369f19e 100644--- a/sdk/tests/ui-layout-integration.test.ts+++ b/sdk/tests/ui-layout-integration.test.ts@@ -18,6 +18,8 @@ import { UICameraInfo } from '../src/ui/core/ui-camera-info';import { ScreenLayout } from '../src/ui/core/screen-layout';import { uiLayoutPlugin } from '../src/ui/layout/layout';import { uiRenderOrderPlugin } from '../src/ui/render/render-order';+import { defineSystem, Schedule } from '../src/ecs/system';+import { Time } from '../src/ecs/resource';import { Transform, Sprite } from '../src/ecs/component';import type { ESEngineModule, CppRegistry } from '../src/wasm';import { loadWasmModule, HAS_WASM } from './helpers/loadWasm';@@ -174,6 +176,42 @@ describe.skipIf(!HAS_WASM)('UI Layout via App.tick() (WASM integration)', () =>disposeApp(app, registry);});+ it('lays out the first paused frame, resizes, and applies edits before rendering', async () => {+ const { app, registry } = createEditorApp();+ try {+ const world = app.world, root = world.spawn(), child = world.spawn();+ world.insert(root, Canvas, {});+ world.insert(root, UINode, fillNode());+ world.insert(root, Transform, makeTransform());+ world.insert(root, Sprite, makeSprite());+ world.setParent(child, root);+ world.insert(child, UINode, insetNode(10));+ world.insert(child, Transform, makeTransform());+ world.insert(child, Sprite, makeSprite());+ const widths: number[] = [];+ let updates = 0;+ app.addSystem(defineSystem([], () => { updates++; }));+ app.addSystemToSchedule(Schedule.Last, defineSystem([], () => {+ widths.push(nodeW(registry, child));+ }));+ app.setPaused(true);+ setCanvasRect(app, -400, -300, 400, 300);+ await app.tick(0.1);+ expect(widths).toEqual([780]);+ expect(registry.getSprite(child).layer).toBeGreaterThan(registry.getSprite(root).layer);+ setCanvasRect(app, -640, -360, 640, 360);+ await app.tick(0.1);+ world.set(child, UINode, insetNode(30));+ await app.tick(0.1);+ expect(widths).toEqual([780, 1260, 1220]);+ expect(nodeH(registry, child)).toBe(660);+ expect(updates).toBe(0);+ expect(app.getResource(Time).elapsed).toBe(0);+ } finally {+ disposeApp(app, registry);+ }+ });+it('should compute layout for child UINode entities', async () => {const { app, registry } = createEditorApp();const world = app.world;