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(gates): the web road's AOT check was rotted, and nothing ran it
esengine92c22916389e
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 14db0746e..3f19f4a82 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -479,6 +479,15 @@ jobs:ELECTRON_DISABLE_SANDBOX: '1'run: xvfb-run -a node tools/verify-aot-parity.mjs+ # Does a real exported WEB package DISPATCH to its compiled systems — the+ # claim verify-aot-native makes for the desktop road, which the web road had+ # nobody making. A twin that loads and is never called changes no pixel and+ # raises no error, so parity below cannot see it either.+ - name: Check an exported web game runs its systems compiled+ env:+ ELECTRON_DISABLE_SANDBOX: '1'+ run: xvfb-run -a pnpm run verify:aot+# And the exact half: one fixture packaged both ways, stepped by a fixed dt# rather than by elapsed time, and the two displacements compared. This is# the check a twin reading the wrong offset cannot survive.diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a602a7da9..8360e73b2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -74,6 +74,28 @@ published separately; it ships inside the editor.and the software rasterizer agree on all four to the byte.+- **An exported WEB game is checked for running its systems compiled, and the+ checker that was supposed to do it had rotted.** `verify:aot` exports+ `examples/ecs-basics` through the CLI, boots the package and asks the host how+ many times a twin was CALLED — the claim `verify-aot-native` makes for the+ desktop road, and the one the web road had nobody making. Parity cannot see+ it: a twin that loads and is never called moves the entity to the same place.++ It had been failing with "the package carries no systems.json" since the+ manifest moved inline into `game.config.json`, and nothing noticed because+ **nothing ran it** — no workflow, no gate, no criterion. It reads the config+ the host reads now, the script clears its output directory (a `systems.wasm`+ two days stale was sitting beside the new one), and it runs in CI and is an+ exit criterion, so it cannot go quiet again. The web road was fine all along:+ `MoveSystem` installed, 91 twin calls.++- **`aotArtifacts.ts` described a wire that no longer exists.** Its file comment+ said the two names are "for both ends", warning that a name written twice+ makes the host's fetch 404. The host has not fetched either by name since the+ manifest was inlined — it reads the module path out of the config. They are+ build-step names, and the one checker that believed otherwise is the entry+ above.+- **A frame that WAITED is refused, not reported.** Every number the native benchpublishes comes from the host's own frame span, and that span can be spentwaiting: a frame the compositor throttles reads 16.6 ms whatever the scene@@ -92,6 +114,14 @@ published separately; it ships inside the editor.The cheapest frame in each comparison trips first, which is the right wayround: it is the one a throttle can pin while the other still has work in it.+ **And a refused run gets no verdict passed on it.** A throttled compiled half+ used to read 2.87 ms and draw a second failure — "a system is reaching the+ interpreter" — which is an accusation about the engine that a frame spent+ waiting cannot support. Both pairs now measure the same way (interleaved, three+ reps, `PAIR_REPS` in one place) and skip their timing verdict when either half+ was refused. Counts still judge: the checksums, whether a compiled system was+ dispatched to at all, `walked`, and whether the render pair is a pair.+- **A frame's TIME has a ceiling, and what it bounds is the drawing.** Countswere the only thing holding a frame: `sprite-scale-cost` and its siblings bounddraws, meshes and triangles, every one of which a frame can honour whilediff --git a/bench/aot-native/frame-bench.mjs b/bench/aot-native/frame-bench.mjsindex f7c35a3ce..647eeb7b6 100644--- a/bench/aot-native/frame-bench.mjs+++ b/bench/aot-native/frame-bench.mjs@@ -59,6 +59,12 @@ const ENTITIES = Number(process.env.BENCH_ENTITIES ?? (GATE ? 2000 : 5000));const FRAMES = Number(process.env.BENCH_FRAMES ?? (GATE ? 60 : 300));const WARMUP = Number(process.env.BENCH_WARMUP ?? (GATE ? 60 : 120));const REPS = Number(process.env.BENCH_REPS ?? (GATE ? 1 : 3));+/**+ * Reps for a PAIR, whose answer is a ratio: the smaller half decides it, and one+ * bad sample of that half decides the gate. Measured, the same tree read 0.735,+ * 1.195 and 2.864 ms on the compiled side at one rep.+ */+const PAIR_REPS = Math.max(REPS, 3);const BODIES = (process.env.BENCH_BODIES ?? 'thin').split(',').map((s) => s.trim()).filter(Boolean);/*** Which of the two builds to export and run. Both by default, because the ratio@@ -312,17 +318,18 @@ try {process.stdout.write(` exporting ${body} ${key}...\n`);built[key] = exportApp(project, path.join(out, `${body}-${key}`), key === 'compiled');}- for (const key of BUILDS) {- // Every rep in its own process, and the FASTEST kept: noise on a desktop- // only ever adds time, so the minimum is the closest thing to the cost.- let best = null;- for (let rep = 0; rep < REPS; rep++) {+ // Every rep in its own process and the FASTEST kept: noise only ever adds+ // time. Interleaved across the builds — run one's reps then the other's+ // and any drift between the two stretches lands whole in the ratio.+ const best = {};+ for (let rep = 0; rep < PAIR_REPS; rep++) {+ for (const key of BUILDS) {const r = run(built[key], `${body} ${key}`);- process.stdout.write(` ${body} ${key} rep ${rep + 1}/${REPS}: cpu p50 ${r.cpu.p50.toFixed(3)} ms\n`);- if (best === null || r.cpu.p50 < best.cpu.p50) best = r;+ process.stdout.write(` ${body} ${key} rep ${rep + 1}/${PAIR_REPS}: cpu p50 ${r.cpu.p50.toFixed(3)} ms\n`);+ if (best[key] === undefined || r.cpu.p50 < best[key].cpu.p50) best[key] = r;}- rows.push({ body, key, ...best });}+ for (const key of BUILDS) rows.push({ body, key, ...best[key] });}// The render pair. Compiled only: `idle` schedules no system, so the two// builds of it are the same program, and the interpreted export would cost a@@ -337,13 +344,11 @@ try {process.stdout.write(` exporting ${half} (${RENDER_ENTITIES} entities)...\n`);exe[half] = exportApp(project, path.join(out, `${half}-build`), true);}- // Interleaved: run one half's reps and then the other's, and any drift- // between the two stretches lands whole in the ratio. Three reps, because- // the denominator threw an outlier 12% high in one run of eight.- for (let rep = 0, reps = Math.max(REPS, 3); rep < reps; rep++) {+ // Interleaved and repped like the bodies above: same shape, same reason.+ for (let rep = 0; rep < PAIR_REPS; rep++) {for (const half of halves) {const r = run(exe[half], half);- process.stdout.write(` ${half} rep ${rep + 1}/${reps}: cpu p50 ${r.cpu.p50.toFixed(3)} ms\n`);+ process.stdout.write(` ${half} rep ${rep + 1}/${PAIR_REPS}: cpu p50 ${r.cpu.p50.toFixed(3)} ms\n`);if (render[half] === undefined || r.cpu.p50 < render[half].cpu.p50) render[half] = r;}}@@ -380,9 +385,13 @@ console.log('');// A frame the compositor throttled spends its span waiting and reads exactly like// a frame that cost that much — measured, 16.6 ms whatever the scene held, at 8%// busy, and the render pair reading 0.99x and passing. Refuse, do not report.+/** A run that measured nothing. Nothing downstream may pass a verdict on it. */+const unmeasured = (r) => r?.waited === true;+for (const r of rows.concat(Object.values(render))) {if (typeof r.busy !== 'number' || r.busy < 0) continue;if (r.busy >= MIN_BUSY) continue;+ r.waited = true;console.error(`✗ ${r.label || 'a run'}: only ${(r.busy * 100).toFixed(0)}% of its frame was CPU`+ ` (needs ${(MIN_BUSY * 100).toFixed(0)}%) — it WAITED, so ${r.cpu.p50.toFixed(2)} ms is the`+ ' compositor and not the engine. Measured causes: a covered window, and a virtual display'@@ -465,6 +474,10 @@ for (const body of [...new Set(rows.map((r) => r.body))]) {bad++;}if (body === 'idle') continue;+ // "A system is reaching the interpreter" is a verdict about the ENGINE, and a+ // half that spent its frame waiting cannot support one — it is already red+ // above, with the reason it is actually red for.+ if (unmeasured(i) || unmeasured(c)) continue;const ratio = i.cpu.p50 / c.cpu.p50;if (GATE && !(ratio >= MIN_RATIO)) {console.error(`✗ ${body}: the compiled frame is only ${ratio.toFixed(2)}x the interpreted one `@@ -495,6 +508,16 @@ for (const body of [...new Set(rows.map((r) => r.body))]) {// The frame's TIME, which nothing else bounds: the count ceilings hold draws,// meshes and triangles, every one of which a frame can honour for twice the CPU.if (render.drawing && render.holding) {+ // Counts first, and they hold whether or not the frame was measurable: two+ // halves that both drew nothing would read 1.0x, having measured one scene+ // twice, and no timing rule can catch that.+ if (!(render.drawing.draws > 0) || render.holding.draws !== 0) {+ console.error(`✗ drawing: the pair is not a pair — ${render.drawing.draws} draw(s) with sprites, `+ + `${render.holding.draws} without`);+ bad++;+ }+}+if (render.drawing && render.holding && !unmeasured(render.drawing) && !unmeasured(render.holding)) {const drawing = render.drawing.cpu.p50;const holding = render.holding.cpu.p50;const ratio = drawing / holding;@@ -507,13 +530,6 @@ if (render.drawing && render.holding) {+ `entities, over the ${RENDER_MAX_RATIO}x ceiling — submitting a sprite got dearer`);bad++;}- // A half that drew nothing is not a control, it is a broken export: the pair- // would read 1.0x and pass, having measured one scene twice.- if (!(render.drawing.draws > 0) || render.holding.draws !== 0) {- console.error(`✗ drawing: the pair is not a pair — ${render.drawing.draws} draw(s) with sprites, `- + `${render.holding.draws} without`);- bad++;- }}if (bad > 0) process.exit(1);diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex ae86afddd..620fc45b3 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -194,9 +194,13 @@ platform-tools,不是完整 SDK。**注意编译那一半才是被卡住的**`frame-bench --gate` 在这里会拒绝作答。天花板本身的标定是在没被节流的时候取的(drawing 10.3–10.6 / holding 2.45–2.89,破坏 17.0–17.2 / 2.46),数是干净的。-**遗留:`thin` 那条 AOT 比值准则在 `--gate` 下是 `REPS=1`,一个坏样本就定案。** 同一棵树-上 compiled 侧读到过 0.735 / 1.195 / 2.864 ms,最后那次让准则红了(2.67x,要求 5x)。-渲染这一对是靠**交错跑 + 3 reps 取最小**解决同一个问题的;`thin` 还没有。+**`thin` 那条准则的反复无常已查清,而我第一次归错了因。** 同一棵树上 compiled 侧读到过+0.735 / 1.195 / 2.864 / 16.6 ms,我当时判成「`REPS=1`,采样不够」——**不是抖动,是同一个+节流**:`busy` 上线后那个 2.87 ms 显示只有 25% 是 CPU。两对现在按同一套量(交错 + 至少+3 reps 取最小,`PAIR_REPS` 一处),而**真正的修复是「测不成就别下判决」**:任何一半被+`busy` 拒绝,那一对的计时判决就不再打印 —— 此前它会同时喊「a system is reaching the+interpreter」,那是对引擎的诬告。校验和、「有没有真派发」、`walked`、「这一对是不是一对」+都是计数,照常判。## 4. 重读 `rendering` 的判决,顺手解锁 fog / DOF / SSAOdiff --git a/package.json b/package.jsonindex 56ca15376..76f4ec8be 100644--- a/package.json+++ b/package.json@@ -29,7 +29,7 @@"render-host": "node tools/render-host/build.mjs","verify:render": "node tools/verify-render.mjs","test": "vitest run --config vitest.engine.config.ts",- "verify:aot": "node pipeline/bin/estella.mjs export examples/ecs-basics --out .aot-verify && pnpm exec electron tools/launchers/headless-aot-verify.mjs .aot-verify",+ "verify:aot": "rm -rf .aot-verify && node pipeline/bin/estella.mjs export examples/ecs-basics --out .aot-verify && pnpm exec electron tools/launchers/headless-aot-verify.mjs .aot-verify","verify:cooked": "ESTELLA_COOK_FIXTURE=1 pnpm --filter @estella/pipeline exec vitest run tests/cooked-verify-fixture.test.ts && pnpm exec electron tools/launchers/headless-cooked-verify.mjs","verify:hotupdate": "ESTELLA_HOTUPDATE_FIXTURE=1 pnpm --filter @estella/pipeline exec vitest run tests/hotupdate-verify-fixture.test.ts && pnpm exec electron tools/launchers/headless-hotupdate-verify.mjs"},diff --git a/pipeline/src/bundle/aotArtifacts.ts b/pipeline/src/bundle/aotArtifacts.tsindex fd7d83eab..dfcc984e2 100644--- a/pipeline/src/bundle/aotArtifacts.ts+++ b/pipeline/src/bundle/aotArtifacts.ts@@ -2,12 +2,13 @@// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team/*** @file aotArtifacts.ts- * @brief What the AOT step's two files are called, for both ends of the wire.+ * @brief What the AOT step's two files are called where it writes them.*- * @details The export writes them and the game host fetches them, and a name- * written twice fails in the worst way available: the fetch 404s, no- * twin is installed, and the game runs the interpreter at full speed- * with nothing to say. NO IMPORTS — the host bundles this.+ * @details These are BUILD names, not a wire: a package carries the module at+ * the path `game.config.json` records and the manifest inlined beside+ * it, so the host never fetches either by name. It said otherwise for+ * two releases, and the one checker that believed it looked for+ * `systems.json` in a package that has not carried one since.*//** The compiled systems, as a module importing the engine's memory. */diff --git a/tools/launchers/headless-aot-verify.mjs b/tools/launchers/headless-aot-verify.mjsindex 7b73dc3f2..5a2ab02eb 100644--- a/tools/launchers/headless-aot-verify.mjs+++ b/tools/launchers/headless-aot-verify.mjs@@ -56,10 +56,14 @@ app.whenReady().then(async () => {const diag = [];try {if (!existsSync(path.join(PACKAGE, 'index.html'))) throw new Error(`no package at ${PACKAGE}`);- // The two files the export writes for this. Absent means the export did not- // compile anything, which makes everything below vacuous.- for (const f of ['systems.wasm', 'systems.json']) {- if (!existsSync(path.join(PACKAGE, f))) throw new Error(`the package carries no ${f}`);+ // Asked of the CONFIG the host reads, which is where the module's path and+ // the inlined manifest actually live. This looked for `systems.json` at the+ // package root until now — a shape the export dropped, unnoticed, unrun.+ const config = JSON.parse(await readFile(path.join(PACKAGE, 'game.config.json'), 'utf8'));+ if (!config.aot) throw new Error('game.config.json carries no `aot` — the export compiled nothing');+ if (!config.aot.manifest?.systems?.length) throw new Error('the aot manifest declares no systems');+ if (!existsSync(path.join(PACKAGE, config.aot.module))) {+ throw new Error(`the config names ${config.aot.module}, which the package does not carry`);}server = await serve(PACKAGE);diff --git a/tools/releaseGate.mjs b/tools/releaseGate.mjsindex 3bb8e0e3d..20126f197 100644--- a/tools/releaseGate.mjs+++ b/tools/releaseGate.mjs@@ -114,6 +114,19 @@ export const CRITERIA = ['sdk/src/ecs/aot/installNativeAot.ts',],},+ {+ id: 'a-web-game-runs-its-systems-as-machine-code',+ says: 'an exported web game loads its compiled systems and dispatches to them',+ // The claim the desktop road already makes, on the road most games ship on.+ // A twin that loads and is never called raises no error and changes no pixel,+ // so neither parity nor the cooked check can see it.+ answeredBy: 'pnpm run verify:aot',+ needs: [+ 'tools/launchers/headless-aot-verify.mjs',+ 'sdk/src/runtime/runtimeLoader.ts',+ 'pipeline/src/bundle/buildCompiledSystems.ts',+ ],+ },{id: 'a-compiled-system-is-cheaper-where-there-is-no-jit',says: 'on a host with no JIT, a compiled system costs a fraction of the interpreted one',