Skip to content

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.

refactor(bench): one answer to where the built wasm is

esenginedb864e4646e1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a81600872..e4eaaa141 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -110,6 +110,12 @@ published separately; it ships inside the editor.
multi-tileset layer, whose singular field is still carried for older scenes,
and the particle curves that only one game has authored.
+- **Where the built wasm lives is answered by `tools/lib/wasmDir.mjs` and by
+ nobody else.** Three benches carried their own copy of the search order, each
+ slightly different in what it probed for and what it did when it found
+ nothing. The order is the library's now; what to say when the engine is not
+ built stays with each caller, which is the half that is actually theirs.
+
- **The output curve's number is worked out in one place.** `OutputTransform` is
a string union at the API and a number at the wasm boundary, and the
translation — `'aces' ? 1 : 0` — was written at both call sites. A third curve
diff --git a/bench/aot-frame/frame-bench.mjs b/bench/aot-frame/frame-bench.mjs
index 8df5fd050..0e4f272dd 100644
--- a/bench/aot-frame/frame-bench.mjs
+++ b/bench/aot-frame/frame-bench.mjs
@@ -54,6 +54,7 @@ import { spawnSync } from 'node:child_process';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { CONFIGS, measure, pct } from './measure.mjs';
+import { resolveWasmDir } from '../../tools/lib/wasmDir.mjs';
const ms = (x) => x.toFixed(3);
@@ -79,14 +80,6 @@ function detectRuntime() {
return 'unknown-runtime';
}
-function resolveWasmDir() {
- const candidates = [env('ESENGINE_WASM_DIR') && resolve(env('ESENGINE_WASM_DIR')),
- join(REPO, 'build', 'wasm', 'web'), join(REPO, 'desktop', 'public', 'wasm')].filter(Boolean);
- for (const dir of candidates) {
- if (existsSync(join(dir, 'esengine.wasm')) && existsSync(join(dir, 'esengine.js'))) return dir;
- }
- throw new Error(`no esengine.wasm + esengine.js. Tried:\n ${candidates.join('\n ')}`);
-}
function resolveSdk() {
const candidates = [env('ESENGINE_SDK') && resolve(env('ESENGINE_SDK')),
@@ -102,6 +95,9 @@ async function child(key) {
const sdk = await import(pathToFileURL(resolveSdk()).href);
const fixture = await import(pathToFileURL(join(BUILD, 'systems.js')).href);
const wasmDir = resolveWasmDir();
+ if (!existsSync(join(wasmDir, 'esengine.wasm'))) {
+ throw new Error(`no esengine.wasm in ${wasmDir} — run \`node build-tools/cli.js build -t web\`, or set ESENGINE_WASM_DIR.`);
+ }
const r = await measure({
sdk,
fixture,
@@ -132,6 +128,9 @@ async function main() {
throw new Error('nothing built yet — run `node bench/aot-frame/build.mjs` first');
}
const wasmDir = resolveWasmDir();
+ if (!existsSync(join(wasmDir, 'esengine.wasm'))) {
+ throw new Error(`no esengine.wasm in ${wasmDir} — run \`node build-tools/cli.js build -t web\`, or set ESENGINE_WASM_DIR.`);
+ }
console.log('='.repeat(72));
console.log('ESEngine AOT frame benchmark');
diff --git a/bench/aot-stage0/frame-share.mjs b/bench/aot-stage0/frame-share.mjs
index 98de0a5df..26a27be11 100644
--- a/bench/aot-stage0/frame-share.mjs
+++ b/bench/aot-stage0/frame-share.mjs
@@ -23,6 +23,7 @@
import { existsSync } from 'node:fs';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { dirname, join, resolve } from 'node:path';
+import { resolveWasmDir } from '../../tools/lib/wasmDir.mjs';
const HERE = dirname(fileURLToPath(import.meta.url));
const REPO = resolve(HERE, '..', '..');
@@ -53,17 +54,6 @@ function mulberry32(seed) {
};
}
-function resolveWasmDir() {
- const candidates = [
- process.env.ESENGINE_WASM_DIR && resolve(process.env.ESENGINE_WASM_DIR),
- join(REPO, 'build', 'wasm', 'web'),
- join(REPO, 'desktop', 'public', 'wasm'),
- ].filter(Boolean);
- for (const dir of candidates) {
- if (existsSync(join(dir, 'esengine.wasm'))) return dir;
- }
- throw new Error('no esengine.wasm — set ESENGINE_WASM_DIR. Tried:\n ' + candidates.join('\n '));
-}
function resolveSdk() {
const p = process.env.ESENGINE_SDK
@@ -84,6 +74,9 @@ const pctOf = (x, total) => total > 0 ? (100 * x / total).toFixed(1) + '%' : '
async function main() {
const wasmDir = resolveWasmDir();
+ if (!existsSync(join(wasmDir, 'esengine.wasm'))) {
+ throw new Error(`no esengine.wasm in ${wasmDir} — run \`node build-tools/cli.js build -t web\`, or set ESENGINE_WASM_DIR.`);
+ }
const sdkPath = resolveSdk();
const sdk = await import(pathToFileURL(sdkPath).href);
diff --git a/bench/nojit-frame-bench.mjs b/bench/nojit-frame-bench.mjs
index 70a191467..6ca7042a7 100644
--- a/bench/nojit-frame-bench.mjs
+++ b/bench/nojit-frame-bench.mjs
@@ -35,6 +35,7 @@
import { existsSync } from 'node:fs';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { dirname, join, resolve } from 'node:path';
+import { resolveWasmDir } from '../tools/lib/wasmDir.mjs';
const HERE = dirname(fileURLToPath(import.meta.url));
const REPO = resolve(HERE, '..');
@@ -80,20 +81,6 @@ function detectRuntime() {
return 'unknown-runtime';
}
-function resolveWasmDir() {
- const override = env('ESENGINE_WASM_DIR');
- const candidates = [
- override && resolve(override),
- join(REPO, 'build', 'wasm', 'web'),
- join(REPO, 'desktop', 'public', 'wasm'),
- ].filter(Boolean);
- for (const dir of candidates) {
- if (existsSync(join(dir, 'esengine.wasm')) && existsSync(join(dir, 'esengine.js'))) return dir;
- }
- throw new Error(
- 'could not find esengine.wasm + esengine.js. Set ESENGINE_WASM_DIR to the dir holding them.\n' +
- 'Tried:\n ' + candidates.join('\n '));
-}
function resolveSdk() {
const override = env('ESENGINE_SDK');
@@ -117,6 +104,9 @@ const ms = (x) => x.toFixed(3);
async function main() {
const label = env('BENCH_LABEL') || detectRuntime();
const wasmDir = resolveWasmDir();
+ if (!existsSync(join(wasmDir, 'esengine.wasm'))) {
+ throw new Error(`no esengine.wasm in ${wasmDir} — run \`node build-tools/cli.js build -t web\`, or set ESENGINE_WASM_DIR.`);
+ }
const sdkPath = resolveSdk();
console.log('='.repeat(64));