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(eht): writing an entity list on the web replaces it, where every write used to add to what was there and an empty list cleared nothing
yhhaa85bf2c2737
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5c6e75624..e3b33990e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -23,6 +23,8 @@ published separately; it ships inside the editor.### Fixed+- **Writing an entity list on the web replaces it.** A `SpringBone.colliders` or `MeshSkin.joints` written to a component that already had one was added to what was there, so a `[a, b]` written twice read `[a, b, a, b]`, a `Mut` row grew it on every write-back (72 entries in a few frames) and writing `[]` cleared nothing. Number lists and native builds were right.+- **A spring bone's colliders work in a native build.** Entity lists were left out of the native bindings unless written by hand, and only `MeshSkin` and `Children` were. `SpringBone.colliders` from a scene never reached the engine on a device, with no error: hair and tails passed through what they should have been kept out of, and a script reading the field got `undefined`. Every entity list now crosses as a generated pair, as other lists do.- **`Mut()` on the web no longer turns a component's colours to NaN** (#107). Since 0.98.0 a `Mut` row is written back when the loop moves on and once more when the system returns, and the first write rewrote the row's colour into the engine's shape, so the second sent NaN. A loop over `Mut(UIVisual)` that wrote nothing made the element vanish. Components read through the wasm heap, and every native build, were not affected. Writing back no longer touches the row. The same write also handed a list field to the engine as a JS array, so `Mut` on a component with one threw every frame; it now takes the one marshalled write `world.set` and `insert` use.- **A new character costs a phone about a third of what it did.** A glyph was drawn and distance-transformed at 4x its stored size, 16 times the pixels, and on a phone most of the time went there. It is now 2x, on the web and on every native host alike: at 12x magnification 2x and 4x look the same on the densest CJK glyph, where 1x loses its counters. The distance transform also leaves out the sites that cannot change a byte of its result, tested byte for byte against the plain transform. On a Snapdragon 8 Elite a new CJK glyph with its distance field went from 5.3 to 1.8 ms, and a Latin one from 3.4 to 0.74 ms. Text can differ from before by a few levels at its edges, up to 6 of 255 in the field.- **A native Android build shows CJK text from the system font.** Android 16's system CJK font (NotoSansCJK-Regular.ttc) has CFF2 outlines, which stb_truetype cannot read, and only Apple had the platform fallback for that, so on such a phone every CJK character from the system font drew nothing. Android now draws such a face with android.graphics: the same file and face its font matcher chose, with synthetic bold and italic where the face lacks them, handed back as coverage so the distance field and the atlas tile stay the shared code's. A project that bundles its own font is not affected.diff --git a/sdk/tests/mut-uivisual-wasm.test.ts b/sdk/tests/mut-uivisual-wasm.test.tsindex e0688a9f4..60dfa4e41 100644--- a/sdk/tests/mut-uivisual-wasm.test.ts+++ b/sdk/tests/mut-uivisual-wasm.test.ts@@ -8,12 +8,13 @@*/import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest';import { App } from '../src/app/app';-import { Transform, builtinComponentRegistry, defineComponent } from '../src/ecs/component';+import { Transform, builtinComponentRegistry, defineComponent, ensureBuiltinComponentsRegistered } from '../src/ecs/component';import { Query, Mut } from '../src/ecs/query';import { defineSystem, Schedule } from '../src/ecs/system';import { UIVisual } from '../src/ui/core/ui-visual';import { UINode } from '../src/ui/core/ui-node';import { uiPlugins } from '../src/app/uiPlugins';+import { numberListFieldsOf } from '../src/ecs/bridge/BuiltinBridge';import type { ESEngineModule } from '../src/wasm';import { HAS_WASM, loadWasmModule } from './helpers/loadWasm';import { log } from '../src/util/logger';@@ -22,6 +23,9 @@ let engine: ESEngineModule;const apps: App[] = [];afterEach(() => { for (const app of apps.splice(0)) app.quit(); vi.restoreAllMocks(); });+// The whole catalogue, as the package entry fills it: the typed definitions alone leave out what only the generated metadata names.+ensureBuiltinComponentsRegistered();+const PressScale = defineComponent('MutUIVisualPressScale', { value: 1 });const RED = { r: 0.25, g: 0.5, b: 0.75, a: 1 };@@ -133,4 +137,85 @@ describe.skipIf(!HAS_WASM)('Mut(UIVisual) on the web core', () => {expect(skipped).toEqual([]);expect(checked.length).toBeGreaterThan(20);});++ /** Every list field of every engine component: read off the same metadata the bridge marshals by, so a new one is covered. */+ function listFields() {+ const out: { name: string; def: never; field: string; values: (a: number, b: number) => number[]; kind: string }[] = [];+ for (const [name, def] of builtinComponentRegistry()) {+ // Kept in step with Parent by the hierarchy system: not the script's to write.+ if (name === 'Children') continue;+ const d = def as unknown as { _cppName: string; _default: Record<string, unknown>; entityFields?: readonly string[] };+ for (const field of numberListFieldsOf(d._cppName)) {+ out.push({ name, def: def as never, field, kind: 'number', values: () => [0.25, 0.5, 0.75] });+ }+ for (const field of d.entityFields ?? []) {+ if (Array.isArray(d._default[field])) {+ out.push({ name, def: def as never, field, kind: 'entity', values: (a, b) => [a, b] });+ }+ }+ }+ return out;+ }++ it('there are list fields of both kinds to hold this against', () => {+ const kinds = new Set(listFields().map((f) => f.kind));+ expect([...kinds].sort()).toEqual(['entity', 'number']);+ });++ describe('a list field written through a Mut row', () => {+ const row = (app: App, def: never, e: unknown) => app.world.get(e as never, def) as unknown as Record<string, number[]>;++ function setUp(def: never) {+ const app = start(false);+ const errors = vi.spyOn(log, 'error');+ const a = app.world.spawn();+ const b = app.world.spawn();+ const e = app.world.spawn();+ if ((def as unknown) !== Transform) app.world.insert(e, Transform, {});+ app.world.insert(e, def, {} as never);+ return { app, errors, a: a as number, b: b as number, e };+ }++ it.each(listFields().map((f) => [`${f.name}.${f.field}`, f] as const))('%s: a new list is read back', async (_label, f) => {+ const { app, errors, a, b, e } = setUp(f.def);+ const want = f.values(a, b);+ app.addSystemToSchedule(Schedule.Update, defineSystem([Query(Mut(f.def))], (q) => {+ for (const [, r] of q as Iterable<[unknown, Record<string, number[]>]>) r[f.field] = [...want];+ }));+ await app.tick(1 / 60);+ expect(Array.from(row(app, f.def, e)[f.field])).toEqual(want);+ expect(errors).not.toHaveBeenCalled();+ });++ it.each(listFields().map((f) => [`${f.name}.${f.field}`, f] as const))('%s: pushing onto the list a row holds lands, frame after frame', async (_label, f) => {+ const { app, errors, a, b, e } = setUp(f.def);+ const want = f.values(a, b);+ let frame = 0;+ app.addSystemToSchedule(Schedule.Update, defineSystem([Query(Mut(f.def))], (q) => {+ for (const [, r] of q as Iterable<[unknown, Record<string, number[]>]>) {+ expect(Array.isArray(r[f.field])).toBe(true);+ if (frame < want.length) r[f.field].push(want[frame]);+ }+ frame++;+ }));+ for (let i = 0; i < want.length + 2; i++) await app.tick(1 / 60);+ expect(Array.from(row(app, f.def, e)[f.field])).toEqual(want);+ expect(errors).not.toHaveBeenCalled();+ });++ it.each(listFields().map((f) => [`${f.name}.${f.field}`, f] as const))('%s: a row kept past the loop still holds an array, and its edit lands', async (_label, f) => {+ const { app, errors, a, b, e } = setUp(f.def);+ const want = f.values(a, b);+ app.addSystemToSchedule(Schedule.Update, defineSystem([Query(Mut(f.def))], (q) => {+ let kept: Record<string, number[]> | null = null;+ for (const [, r] of q as Iterable<[unknown, Record<string, number[]>]>) kept = r;+ // The loop has written it back once by now.+ expect(Array.isArray(kept![f.field])).toBe(true);+ kept![f.field] = [...want];+ }));+ await app.tick(1 / 60);+ expect(Array.from(row(app, f.def, e)[f.field])).toEqual(want);+ expect(errors).not.toHaveBeenCalled();+ });+ });});diff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cppindex 136247501..78d3df4ea 100644--- a/src/esengine/bindings/WebBindings.generated.cpp+++ b/src/esengine/bindings/WebBindings.generated.cpp@@ -917,6 +917,7 @@ struct MeshSkinJS {};void meshskinApplyJS(esengine::ecs::MeshSkin& c, const MeshSkinJS& js) {+ c.joints.clear();c.joints.reserve(js.joints.size());for (auto v : js.joints) c.joints.push_back(Entity(v));}@@ -1395,6 +1396,7 @@ void springboneApplyJS(esengine::ecs::SpringBone& c, const SpringBoneJS& js) {c.endLength = js.endLength;c.radius = js.radius;c.weight = js.weight;+ c.colliders.clear();c.colliders.reserve(js.colliders.size());for (auto v : js.colliders) c.colliders.push_back(Entity(v));}diff --git a/tools/eht/generators/embind.py b/tools/eht/generators/embind.pyindex 77755fc11..457845656 100644--- a/tools/eht/generators/embind.py+++ b/tools/eht/generators/embind.py@@ -213,6 +213,8 @@ class EmbindGenerator:elif self.types.is_enum(t):lines.append(f' c.{prop.name} = static_cast<{t}>(js.{prop.name});')elif t in self.types.VECTOR_TYPES and self.types.VECTOR_TYPES[t][0] == 'u32' and 'Entity' in t:+ # Cleared: this writes into a component that already exists on every write after the first.+ lines.append(f' c.{prop.name}.clear();')lines.append(f' c.{prop.name}.reserve(js.{prop.name}.size());')lines.append(f' for (auto v : js.{prop.name}) c.{prop.name}.push_back(Entity(v));')elif self.types.is_struct_vector(t):diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex f06e7d8b9..daa19561a 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -3846,4 +3846,8 @@ export const NOTED = {{"internal":"a release-gate table, nothing a creator can observe"},"fix(ecs): a Mut row is no longer rewritten by its own write-back, so walking one on the web keeps its colours and a list field crosses as a vector":{"note":"`Mut()` on the web no longer turns a component's colours to NaN"},+ "fix(eht): writing an entity list on the web replaces it, where every write used to add to what was there and an empty list cleared nothing":+ {"note":"Writing an entity list on the web replaces it"},+ "fix(native): a component's entity list reaches the native core, so a spring bone's colliders work in a device build and a script can read them":+ {"note":"A spring bone's colliders work in a native build"},};