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
perf(ui): preserve transform composition across clean layout passes
yhhc20ceb9ae980
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 17815756e..f1b73e0b6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Fixed+- **Static UI layout preserves composed world transforms.** Clean early and late layout passes keep the transform cache valid, and the SDK composes through the shared change-aware path. Moving a screen box, changing layout properties, tweening, and structural edits still invalidate the affected composition.+- **Touch hit caches release ended pointer IDs.** Long-running touch sessions retain only the pointers present in the current input frame, including release-frame results needed by quick taps, instead of accumulating every historical finger ID.- **Pointer callbacks cancel invalid UI interactions immediately.** Disabling or deleting a control during hover, press or release stops later events from the same batch. Invalidated captures and interaction edges clear in the same frame, so re-enabling a button does not complete an old press.diff --git a/sdk/src/ui/layout/layout.ts b/sdk/src/ui/layout/layout.tsindex 464275d5f..47bf6bca9 100644--- a/sdk/src/ui/layout/layout.ts+++ b/sdk/src/ui/layout/layout.ts@@ -78,7 +78,7 @@ export class UILayoutPlugin implements Plugin {screen.right, screen.top,propertyDirty(),);- engine?.transform_update?.(registry);+ world.ensureTransformsComposed();layoutGen.generation++;};diff --git a/sdk/tests/ui-layout-transform-cache-wasm.test.ts b/sdk/tests/ui-layout-transform-cache-wasm.test.tsnew file mode 100644index 000000000..a364a325b--- /dev/null+++ b/sdk/tests/ui-layout-transform-cache-wasm.test.ts@@ -0,0 +1,67 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';+import { World } from '../src/ecs/world';+import { App } from '../src/app/app';+import { ScreenLayout, screenLayoutRect } from '../src/ui/core/screen-layout';+import { uiLayoutPlugin } from '../src/ui/layout/layout';+import { Canvas, Transform } from '../src/ecs/component';+import { UINode } from '../src/ui/core/ui-node';+import { px } from '../src/ui/core/dimension';+import type { CppRegistry, ESEngineModule } from '../src/wasm';+import { HAS_WASM, loadWasmModule } from './helpers/loadWasm';++describe.skipIf(!HAS_WASM)('layout preserves transform composition on real WASM', () => {+ let engine: ESEngineModule;+ let registry: CppRegistry;+ let world: World;+ let app: App;+ let root: ReturnType<World['spawn']>;+ beforeAll(async () => { engine = await loadWasmModule(); });+ beforeEach(() => {+ registry = new engine.Registry(); app = App.new(); app.connectCpp(registry, engine); world = app.world;+ root = world.spawn(); world.insert(root, Transform); world.insert(root, Canvas);+ world.insert(root, UINode, { width: px(100), height: px(80) });+ engine.uiLayout_update(registry, -400, -300, 400, 300, true);+ engine.transform_update(registry);+ });+ afterEach(() => {+ for (const entity of world.getAllEntities()) world.despawn(entity);+ world.disconnectCpp(); registry.delete();+ });+ const epoch = () => engine.HEAPU32[engine.transform_epochAddress!() >>> 2];+ const serial = () => engine.transform_compositionChanges!().serial;+ it('keeps clean early and late layout passes from recomposing the whole world', async () => {+ app.insertResource(ScreenLayout, screenLayoutRect(null, 800, 600));+ app.addPlugin(uiLayoutPlugin);+ for (let i = 0; i < 3; i++) await app.tick(1 / 60);+ const previousEpoch = epoch(), previousSerial = serial();+ for (let i = 0; i < 20; i++) {+ await app.tick(1 / 60);+ world.ensureTransformsComposed();+ }+ expect(epoch()).toBe(previousEpoch);+ expect(serial()).toBe(previousSerial);+ });+ it('recomposes descendants after the screen box moves without resizing', () => {+ const child = world.spawn(); world.insert(child, Transform, { position: { x: 7, y: 0, z: 0 } });+ world.setParent(child, root); world.ensureTransformsComposed();+ const x = world.get(child, Transform).worldPosition.x, previousSerial = serial();+ engine.uiLayout_update(registry, -300, -300, 500, 300, false);+ world.ensureTransformsComposed();+ expect(world.get(child, Transform).worldPosition.x).toBeCloseTo(x + 100);+ expect(serial()).toBe(previousSerial + 1);+ });+ it('recomposes after authored layout properties and transform writes', () => {+ const previous = serial();+ world.update(root, UINode, node => { node.width = px(160); });+ engine.uiLayout_update(registry, -400, -300, 400, 300, true);+ world.ensureTransformsComposed();+ expect(engine.getUINodeComputedWidth!(registry, root)).toBeCloseTo(160);+ expect(serial()).toBe(previous + 1);+ world.update(root, Transform, transform => { transform.position.x = 42; });+ world.ensureTransformsComposed();+ expect(world.get(root, Transform).worldPosition.x).toBe(42);+ expect(serial()).toBe(previous + 2);+ });+});diff --git a/src/esengine/ui/UILayoutSystem.cpp b/src/esengine/ui/UILayoutSystem.cppindex 9302a4546..513b542a7 100644--- a/src/esengine/ui/UILayoutSystem.cpp+++ b/src/esengine/ui/UILayoutSystem.cpp@@ -537,10 +537,6 @@ void UISystem::layoutUpdate(// touched, which hid the aliasing by throwing the stale state away.if (layoutCache_ && lastRegistryId_ != registry.instanceId()) layoutCache_.reset();lastRegistryId_ = registry.instanceId();- // This pass writes Transform.position for every laid-out node, so the- // composition it feeds is stale afterwards. Once per pass, not per node:- // the epoch answers "is it stale", never "how many moved".- invalidateTransformComposition();if (!layoutCache_) {layoutCache_ = std::make_unique<LayoutCache>();layoutPrimed_ = false; // a fresh cache has no hierarchy to reuse@@ -582,10 +578,16 @@ void UISystem::layoutUpdate(|| animNow || wasAnimActive;layoutPrimed_ = true;if (!dirty) {- if (centerChanged) placeScreenRoots(registry, tree, *layoutCache_, box);+ if (centerChanged) {+ invalidateTransformComposition();+ placeScreenRoots(registry, tree, *layoutCache_, box);+ }return;}+ // Only a pass that may write local transforms invalidates their composition.+ invalidateTransformComposition();+// Two signals, because they answer different questions. The hierarchy has to// be rebuilt when the tree's SHAPE changed. Output has to be written for// every node when the ROOT'S FRAME changed — a subtree root positions itselfdiff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 4d67f4050..f23134062 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'perf(ui): preserve transform composition across clean layout passes':+ { note: 'Static UI layout preserves composed world transforms.' },'fix(ui): bound hit caches to live pointer frames':{ note: 'Touch hit caches release ended pointer IDs.' },'fix(ui): cancel pointer events invalidated by callbacks':