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(render-host): read the engine's frame, not the page
esengine353333efe4ed
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex a0cc84498..4fa34823b 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -233,6 +233,12 @@ jobs:steps:- uses: actions/checkout@v7+ # The scale suite lives in the editor and imports its sources — the budgets+ # are about what the EDITOR costs at 50k assets.+ - uses: ./.github/actions/editor-checkout+ with:+ ssh-key: ${{ secrets.EDITOR_SSH_KEY }}+- uses: ./.github/actions/setup- name: Download web wasm artifactdiff --git a/sdk/tests/mover-smoke.mjs b/sdk/tests/mover-smoke.mjsindex 6e229c287..29968fbfc 100644--- a/sdk/tests/mover-smoke.mjs+++ b/sdk/tests/mover-smoke.mjs@@ -4,7 +4,7 @@// options wired through from the CharacterController component.import { readFileSync } from 'node:fs';import path from 'node:path';-import { requireWasm } from './helpers/wasmDir.mjs';+import { requireWasm } from '../../tools/lib/wasmDir.mjs';const wasmDir = requireWasm('physics.wasm');const factory = (await import('file://' + path.join(wasmDir, 'physics.js').replace(/\\/g, '/'))).default;diff --git a/sdk/tests/physics-features-smoke.mjs b/sdk/tests/physics-features-smoke.mjsindex 087f88da6..9b703d472 100644--- a/sdk/tests/physics-features-smoke.mjs+++ b/sdk/tests/physics-features-smoke.mjs@@ -3,7 +3,7 @@// same pattern as mover-smoke.mjs / sensor-smoke.mjs.import { readFileSync } from 'node:fs';import path from 'node:path';-import { requireWasm } from './helpers/wasmDir.mjs';+import { requireWasm } from '../../tools/lib/wasmDir.mjs';const wasmDir = requireWasm('physics.wasm');const factory = (await import('file://' + path.join(wasmDir, 'physics.js').replace(/\\/g, '/'))).default;diff --git a/sdk/tests/physics3d-smoke.mjs b/sdk/tests/physics3d-smoke.mjsindex 9f2f3ec7f..530d4af3e 100644--- a/sdk/tests/physics3d-smoke.mjs+++ b/sdk/tests/physics3d-smoke.mjs@@ -3,7 +3,7 @@// throwing proves nothing about where anything ended up.import { readFileSync } from 'node:fs';import path from 'node:path';-import { requireWasm } from './helpers/wasmDir.mjs';+import { requireWasm } from '../../tools/lib/wasmDir.mjs';const wasmDir = requireWasm('physics3d.wasm');const factory = (await import('file://' + path.join(wasmDir, 'physics3d.js').replace(/\\/g, '/'))).default;diff --git a/sdk/tests/sensor-smoke.mjs b/sdk/tests/sensor-smoke.mjsindex 977b03a5a..8639018eb 100644--- a/sdk/tests/sensor-smoke.mjs+++ b/sdk/tests/sensor-smoke.mjs@@ -2,7 +2,7 @@// enableSensorEvents fix. Run against the freshly built physics wasm.import { readFileSync } from 'node:fs';import path from 'node:path';-import { requireWasm } from './helpers/wasmDir.mjs';+import { requireWasm } from '../../tools/lib/wasmDir.mjs';const wasmDir = requireWasm('physics.wasm');const factory = (await import('file://' + path.join(wasmDir, 'physics.js').replace(/\\/g, '/'))).default;diff --git a/tools/gen-shader-twins.mjs b/tools/gen-shader-twins.mjsindex 0da836ee8..194d74f2f 100644--- a/tools/gen-shader-twins.mjs+++ b/tools/gen-shader-twins.mjs@@ -44,10 +44,11 @@ import { tmpdir } from 'node:os';import path from 'node:path';import { fileURLToPath, pathToFileURL } from 'node:url';import { glslToSpv } from '../build-tools/shader-twins/glslang.mjs';+import { resolveWasmDir } from './lib/wasmDir.mjs';import { spvFileToWgsl } from '../build-tools/shader-twins/naga.mjs';const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');-const WASM_GLUE = path.join(ROOT, 'desktop', 'public', 'wasm', 'esengine.js');+const WASM_GLUE = path.join(resolveWasmDir('esengine.js'), 'esengine.js');// Engine group-0 UBO slots (Shader::compile / WebGPU bind conventions).const BLOCK_BINDINGS = {diff --git a/sdk/tests/helpers/wasmDir.mjs b/tools/lib/wasmDir.mjssimilarity index 71%rename from sdk/tests/helpers/wasmDir.mjsrename to tools/lib/wasmDir.mjsindex 7819ad94a..bf887fd56 100644--- a/sdk/tests/helpers/wasmDir.mjs+++ b/tools/lib/wasmDir.mjs@@ -1,19 +1,20 @@// SPDX-License-Identifier: Apache-2.0// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team/**- * @file wasmDir.mjs — where the plain-node smoke scripts find the built WASM.+ * @file wasmDir.mjs — where plain-node tooling finds the built WASM.*- * The .mjs smokes cannot import the TypeScript {@link ../loadWasm.ts}, so this- * mirrors its resolution order. `build/wasm/web` is the authoritative build- * output; `desktop/public/wasm` is a synced copy that only exists when the- * editor submodule is checked out, so nothing engine-side may require it.+ * Mirrors the resolution order of sdk/tests/helpers/loadWasm.ts, which the .mjs+ * callers cannot import. `build/wasm/web` is the authoritative build output;+ * `desktop/public/wasm` is a copy synced into the editor and only exists when+ * that submodule is checked out, so nothing engine-side may REQUIRE it — a gate+ * that names it directly fails on a checkout without the editor.*/import { existsSync } from 'node:fs';import path from 'node:path';import { fileURLToPath } from 'node:url';const HERE = path.dirname(fileURLToPath(import.meta.url));-const ROOT = path.resolve(HERE, '../../..');+const ROOT = path.resolve(HERE, '..', '..');/** First candidate that actually holds `probe`; falls back to the build output. */export function resolveWasmDir(probe = 'esengine.wasm') {diff --git a/tools/perf-budget.mjs b/tools/perf-budget.mjsindex 958a13e71..6d5d6b44d 100644--- a/tools/perf-budget.mjs+++ b/tools/perf-budget.mjs@@ -30,6 +30,17 @@ import { dirname, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { runTool } from './lib/runTool.mjs';+// The editor is an optional submodule and this verifier drives it. Saying so+// beats the failure a missing checkout produces on its own ("Command vitest not+// found"), which names neither the editor nor the reason it is wanted.+function requireEditor(what) {+ if (existsSync(join(ROOT, 'desktop', 'package.json'))) return;+ console.error(`${what} measures the EDITOR, which is not checked out.`);+ console.error(' git submodule update --init desktop (private; you need access)');+ process.exit(2);+}++import { generateStressProject, countAssets } from './stress-project.mjs';const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');@@ -60,6 +71,7 @@ if (corpus.assets !== countAssets(1)) {// before writing anything.rmSync(REPORT, { force: true });+requireEditor('The scale budget suite');const run = runTool('pnpm', ['exec', 'vitest', 'run', '--config', 'vitest.scale.config.ts'], {cwd: join(ROOT, 'desktop'),stdio: 'inherit',diff --git a/tools/render-host/host.ts b/tools/render-host/host.tsindex 61ecb93ad..3bffcf25c 100644--- a/tools/render-host/host.ts+++ b/tools/render-host/host.ts@@ -18,7 +18,7 @@ import {createWebApp, setEditorMode, setPlayMode, Assets, acquireWebGPUDevice,loadSceneData, Renderer, instantiatePrefab, writeFieldPath, Transform, Name,getComponent, DeviceStatus, getDeviceStatus, getDeviceLostReport, recoverDevice,- finishDeviceRecovery, getContextLossGuardInfo, decodeImagePixels,+ finishDeviceRecovery, getContextLossGuardInfo, decodeImagePixels, captureFramePixels,} from 'esengine';import type { App, SceneData, PrefabData, RenderSurfaceSource } from 'esengine';import type { ESEngineModule } from 'esengine/wasm';@@ -260,6 +260,17 @@ const api = {return { world: 'engine', frames, dt };},+ /**+ * The frame as the ENGINE holds it, whichever backend drew it. captureViewport+ * reads the page instead, which on WebGPU is a compositor copy — blank in a+ * hidden window. Null when the surface was not configured for readback, which+ * has to be decided before anything is drawn.+ */+ async captureViewportPixels(): Promise<{ rgba: Uint8Array; width: number; height: number } | null> {+ if (!canvas || !module) return null;+ return captureFramePixels(module, canvas.width, canvas.height, async () => { await api.step(1, 1 / 60); });+ },+captureViewport(): { rgba: Uint8Array; width: number; height: number } {if (!canvas) throw new Error('captureViewport before boot');const w = canvas.width, h = canvas.height;