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
feat(ci): the flagship is played to its boss, as a criterion
esengine0a7686341e09
diff --git a/desktop/scripts/play-through.mjs b/desktop/scripts/play-through.mjsindex 0555c8da1..7a251f1e5 100644--- a/desktop/scripts/play-through.mjs+++ b/desktop/scripts/play-through.mjs@@ -26,13 +26,11 @@* `goal` is an entity name the probe can find, so a leg survives the level being* re-authored — the door moves, the route does not.*- * NOT a gate yet, and deliberately not wired into verify. Runs of the same- * package still disagree with each other: a leg occasionally reports arrival- * from a pickup that was not taken, and the run then fails later at a door that- * had every right to stay shut. Reading on a frame boundary and refusing a- * world mid-transition fixed most of it; what remains is timing-sensitive- * enough that adding console output changes the outcome, which is the shape of- * a race that has not been found yet.+ * Runs of one package agree to the frame, which took three rules: read on a+ * frame boundary, never read a world mid-transition, and credit an arrival+ * only from arm's reach with Lyra present.+ *+ * Answers `flagship-plays-through` via tools/verify-playthrough.mjs.*/import { app, BrowserWindow } from 'electron';import http from 'node:http';@@ -117,15 +115,18 @@ const stepScript = (keys, frames, tapKey) => `})()`;-/** Which keys walk from `from` toward `to` on the ground plane. */-function keysToward(from, to) {+/**+ * Which keys walk from `from` toward `to`. The dead band stops a stutter+ * between opposite keys; shrinking it is how a driver gets off a wall. Feet+ * collide where navigation planned from the origin, so a plan can be walkable+ * for the middle and a wall for the feet.+ */+function keysToward(from, to, deadband = 40) {const dx = to.x - from.x;const dy = to.y - from.y;const keys = [];- // The dead band keeps a driver from stuttering between two opposite keys when- // it is already lined up on one axis.- if (Math.abs(dx) > 40) keys.push(dx > 0 ? 'KeyD' : 'KeyA');- if (Math.abs(dy) > 40) keys.push(dy > 0 ? 'KeyW' : 'KeyS');+ if (Math.abs(dx) > deadband) keys.push(dx > 0 ? 'KeyD' : 'KeyA');+ if (Math.abs(dy) > deadband) keys.push(dy > 0 ? 'KeyW' : 'KeyS');return keys;}@@ -211,6 +212,8 @@ async function main() {let sawArea = false;let sawGoal = false;let lastGap = Infinity;+ let stuckFor = 0;+ let was = null;let plan = [];let replan = 0;let last = null;@@ -240,7 +243,20 @@ async function main() {// A goal that was there and now is not was reached — taken, or killed —// but only while Lyra is beside it: an area rebuilding after a death// empties the world for a moment, and that is not an arrival.- if (sawGoal && !goal && me && lastGap < REACH && !leg.throughDoor) { arrived = true; break; }+ if (sawGoal && !goal && me && lastGap < REACH && !leg.throughDoor) {+ // One read is not evidence. Something that is really gone stays gone;+ // something that blinked was a world caught mid-change, and crediting+ // it costs the run a pickup it never took.+ let gone = true;+ for (let i = 0; i < 3 && gone; i++) {+ await exec(stepScript([], 4, null));+ spent += 4;+ frames += 4;+ gone = !(await probe([leg.goal])).at[leg.goal];+ }+ if (gone) { arrived = true; break; }+ console.log(` ${label}: goal blinked out and came back — not counting it`);+ }if (goal) sawGoal = true;if (me && goal) {const gap = Math.hypot(goal.x - me.x, goal.y - me.y);@@ -256,7 +272,21 @@ async function main() {replan -= STEP;while (plan.length && Math.hypot(plan[0].x - me.x, plan[0].y - me.y) < 70) plan.shift();const aim = plan[0] ?? goal;- const keys = keysToward(me, aim);+ // Pressed and did not move: back off the dead band so the other axis+ // comes into play, and re-plan sooner.+ const moved = was ? Math.hypot(me.x - was.x, me.y - was.y) : Infinity;+ stuckFor = moved < 6 ? stuckFor + STEP : 0;+ was = me;+ if (stuckFor > 64) { replan = 0; }+ const keys = keysToward(me, aim, stuckFor > 32 ? 4 : 40);+ if (stuckFor > 32) {+ // Slide along whatever is in the way: press the axis the heading does+ // not need, flipping which way every so often until something gives.+ const alongX = Math.abs(aim.x - me.x) >= Math.abs(aim.y - me.y);+ const up = Math.floor(stuckFor / 96) % 2 === 0;+ const side = alongX ? (up ? 'KeyW' : 'KeyS') : (up ? 'KeyD' : 'KeyA');+ if (!keys.includes(side)) keys.push(side);+ }if (TRACE && spent % 160 === 0) {console.log(` ${label} @${spent}: at ${Math.round(me.x)},${Math.round(me.y)} `+ `aim ${Math.round(aim.x)},${Math.round(aim.y)} (${plan.length} waypoints) keys ${keys.join('+') || 'none'} gap ${Math.round(gap)}`);diff --git a/tools/releaseGate.mjs b/tools/releaseGate.mjsindex 76ca11a90..af73564bf 100644--- a/tools/releaseGate.mjs+++ b/tools/releaseGate.mjs@@ -97,6 +97,19 @@ export const CRITERIA = [answeredBy: 'pnpm run verify',needs: ['tools/check-golden.mjs', 'tools/check-minigame-host.mjs'],},+ {+ id: 'flagship-plays-through',+ says: 'the flagship can be played from its first room to its boss, as a package',+ // Every other gate asks whether something works. This asks the only thing a+ // player asks — and a game whose second door cannot be opened passes all of+ // the others.+ answeredBy: 'node tools/verify-playthrough.mjs',+ needs: [+ 'tools/verify-playthrough.mjs',+ 'desktop/scripts/play-through.mjs',+ 'examples/celestial-heights/playthrough.json',+ ],+ },{id: 'no-engine-gaps-at-ship',says: 'the flagship game had to route around the engine nowhere that is still open',diff --git a/tools/verify-playthrough.mjs b/tools/verify-playthrough.mjsnew file mode 100644index 000000000..d980cff7d--- /dev/null+++ b/tools/verify-playthrough.mjs@@ -0,0 +1,75 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file verify-playthrough.mjs — the flagship can still be played to its end.+ *+ * Every other gate asks whether something works: a package boots, a frame is+ * lively, an input is answered. None of them asks the only question a player+ * asks, which is whether the game can be finished — and a game whose second+ * door cannot be opened passes all of them.+ *+ * Packages the flagship and hands it to the closed-loop driver, which walks the+ * route by asking the running game where things are. What that proves is the+ * game's own progression: the pickups its doors ask for, the doors those open,+ * and the boss at the end of them.+ *+ * node tools/verify-playthrough.mjs [--project <id>] [--route <file>] [--keep]+ */+import { spawnSync } from 'node:child_process';+import { existsSync, mkdirSync, rmSync } from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';++const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');+const DESKTOP = path.join(ROOT, 'desktop');+const WORK = path.join(ROOT, '.playthrough');++const argv = process.argv.slice(2);+const flag = (name, fallback) => {+ const i = argv.indexOf(`--${name}`);+ return i >= 0 && argv[i + 1] && !argv[i + 1].startsWith('--') ? argv[i + 1] : fallback;+};++const PROJECT = flag('project', 'celestial-heights');+const projectDir = path.join(ROOT, 'examples', PROJECT);+const ROUTE = path.resolve(flag('route', path.join(projectDir, 'playthrough.json')));++if (!existsSync(path.join(projectDir, 'project.esproject'))) {+ console.error(`verify-playthrough: no project at ${projectDir}`);+ process.exit(2);+}+if (!existsSync(ROUTE)) {+ console.error(`verify-playthrough: ${PROJECT} declares no route at ${ROUTE}`);+ process.exit(2);+}++rmSync(WORK, { recursive: true, force: true });+mkdirSync(WORK, { recursive: true });+const out = path.join(WORK, PROJECT);++const exported = spawnSync(process.execPath, [+ path.join(DESKTOP, 'scripts', 'export-project.mjs'), projectDir,+ '--platform', 'web', '--out', out,+], { encoding: 'utf8', cwd: ROOT });++if (exported.status !== 0) {+ console.error(`✗ ${PROJECT} — packaging failed`);+ console.error((exported.stderr || exported.stdout || '').trim().slice(-600));+ process.exit(1);+}++const played = spawnSync('npx', [+ 'electron', path.join('scripts', 'play-through.mjs'),+ '--dir', out, '--route', ROUTE,+ '--out', path.join(WORK, `${PROJECT}.png`),+ '--budget', '26000',+], { encoding: 'utf8', cwd: DESKTOP });++for (const line of (played.stdout || '').split('\n')) if (line.trim()) console.log(line);+if (!argv.includes('--keep')) rmSync(WORK, { recursive: true, force: true });++if (played.status !== 0) {+ console.error(`✗ ${PROJECT} cannot be played to the end of its route`);+ process.exit(1);+}+console.log(`verify-playthrough: ${PROJECT} plays through — ok`);