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.

feat(export): a packaged game says it is loading

esengine6462208a6f65
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7ce1f99e2..17b9c9876 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,6 +41,17 @@ published separately; it ships inside the editor.
### Added
+- **A packaged game now says it is loading.** Between the page opening and the first frame
+ an export showed its background colour and nothing else — and on a cold start that gap is
+ the whole download of a 1.7MB engine binary, which reads to a player as a page that did
+ not work. Web and desktop packages now open on a start screen carrying the project's name
+ and a bar moving through the eight stages the boot actually has, weighted by what each one
+ costs rather than counted evenly: reading the build, scripts, the asset list, the scene,
+ the engine, the renderer, assets, ready. It fades as the first frame arrives. A start
+ screen still standing after a package settles now fails that package's check, because
+ everything else about it passes — the canvas painted underneath, nothing errored — and
+ what it leaves on screen looks exactly like a game that is still loading.
+
- **The engine can ship outside a WeChat mini-game's main package entirely.** Compressing
it left 0.35MB of the 4MB limit spent before any of your content; *Engine in a subpackage*
moves the binary into a 分包 the host loads at startup, and the main package keeps only
diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.ts
index 3b330de3c..b44eaaa48 100644
--- a/pipeline/src/export/exportGame.ts
+++ b/pipeline/src/export/exportGame.ts
@@ -46,6 +46,7 @@ import { resolveEmcc, runEmcc } from '../bundle/emccPath';
import { findHostCC } from '../../../compiler/src/hostCC';
import { explainBundleErrors, type BundleMessage } from '../bundle/bundleDiagnostics';
import { orientationCss, orientationOverlayHtml, orientationLockScript, orientationLockCspHash, type ScreenOrientation } from './orientationHtml';
+import { splashCss, splashHtml } from './splash';
import { emitIosXcodeProject, type IosProjectSources } from '../../../build-tools/utils/iosProject.js';
import { emitAndroidGradleProject } from '../../../build-tools/utils/gradleProject.js';
import { androidTemplateSources } from '../../../build-tools/utils/nativeTemplate.js';
@@ -253,6 +254,10 @@ export interface ExportGameResult {
size?: BuildSizeReport;
}
+/** The page's ground, and what the start screen fades out over: the same colour on
+ * both sides, or the fade flashes through to white between them. */
+const PAGE_BACKGROUND = '#0e121b';
+
/** The web host page. `orientation` pins the canvas to a screen orientation (rotate-
* to-fit overlay + best-effort lock) — set for the mobile-facing web target, omitted
* for desktop (the Electron shell sizes its own window). */
@@ -274,13 +279,15 @@ function indexHtml(title: string, orientation?: ScreenOrientation): string {
<script type="importmap">${IMPORT_MAP_JSON}</script>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
- html, body { width: 100%; height: 100%; overflow: hidden; background: #0e121b; }
+ html, body { width: 100%; height: 100%; overflow: hidden; background: ${PAGE_BACKGROUND}; }
#canvas { display: block; width: 100%; height: 100%; touch-action: none; }
+ ${splashCss(PAGE_BACKGROUND)}
${orientation ? orientationCss(orientation) : ''}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
+ ${splashHtml(title)}
${orientation ? orientationOverlayHtml(orientation) : ''}
${orientation ? orientationLockScript(orientation) : ''}
<script type="module" src="./game.js"></script>
diff --git a/pipeline/src/export/splash.ts b/pipeline/src/export/splash.ts
new file mode 100644
index 000000000..e83b524e8
--- /dev/null
+++ b/pipeline/src/export/splash.ts
@@ -0,0 +1,113 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file splash.ts — the exported page's start screen, and the one list of boot
+ * stages it and the runtime both read.
+ *
+ * The page carries the markup because it has to be on screen before `game.js`
+ * is even fetched, and the runtime moves the bar because `boot()` is the only
+ * thing that knows which stage it reached. Those are two readers of one list, so
+ * the list lives here rather than being spelled once in each.
+ *
+ * Weights, not stage count: the stages are nowhere near equal — the engine
+ * binary and the first app are most of a cold start — and an even bar would sit
+ * at 60% for as long as the whole rest of the boot takes.
+ */
+
+/** A boot stage, in the order {@link boot} reaches them. */
+export const BOOT_STAGES = [
+ { id: 'config', weight: 4, says: 'Reading the build' },
+ { id: 'scripts', weight: 6, says: 'Loading scripts' },
+ { id: 'manifest', weight: 4, says: 'Reading the asset list' },
+ { id: 'scene', weight: 6, says: 'Loading the scene' },
+ { id: 'engine', weight: 40, says: 'Starting the engine' },
+ { id: 'app', weight: 22, says: 'Preparing the renderer' },
+ { id: 'assets', weight: 13, says: 'Loading assets' },
+ { id: 'ready', weight: 5, says: 'Ready' },
+] as const;
+
+export type BootStage = (typeof BOOT_STAGES)[number]['id'];
+
+const TOTAL = BOOT_STAGES.reduce((n, s) => n + s.weight, 0);
+
+/** Ids the page and the runtime agree on; `es-` so a game's own markup cannot collide. */
+const ROOT = 'es-splash';
+const BAR = 'es-splash-bar';
+const LABEL = 'es-splash-label';
+
+/**
+ * The start screen's CSS. `background` matches the page so the fade lands on the
+ * same colour the canvas clears to, rather than flashing through to white.
+ */
+export function splashCss(background: string): string {
+ return (
+ `#${ROOT}{position:fixed;inset:0;z-index:20;display:flex;flex-direction:column;`
+ + `align-items:center;justify-content:center;gap:18px;background:${background};`
+ + "color:#c7d0e0;font:500 14px/1.5 system-ui,-apple-system,'Segoe UI',sans-serif;"
+ + 'transition:opacity .35s ease;padding:24px;text-align:center;}'
+ + `#${ROOT}.es-splash-gone{opacity:0;pointer-events:none;}`
+ + `#${ROOT} .es-splash-title{font-size:19px;font-weight:650;letter-spacing:.01em;}`
+ + `#${ROOT} .es-splash-track{width:min(260px,62vw);height:3px;border-radius:2px;`
+ + 'background:rgba(199,208,224,.18);overflow:hidden;}'
+ + `#${ROOT} #${BAR}{height:100%;width:0;border-radius:2px;background:#c7d0e0;`
+ + 'transition:width .25s ease;}'
+ + `#${ROOT} #${LABEL}{font-size:12px;opacity:.72;min-height:1.5em;}`
+ // A start screen that outlives its own boot is worse than none: if the
+ // runtime never arrives to fade it, this hides it rather than covering the
+ // game forever.
+ + `@media (prefers-reduced-motion:reduce){#${ROOT}{transition:none;}}`
+ );
+}
+
+/** The start screen's markup — no script of its own, so the page adds no CSP hash. */
+export function splashHtml(title: string): string {
+ const safe = title.replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' }[c] as string));
+ return `<div id="${ROOT}" role="status" aria-live="polite">`
+ + `<div class="es-splash-title">${safe}</div>`
+ + `<div class="es-splash-track"><div id="${BAR}"></div></div>`
+ + `<div id="${LABEL}">${BOOT_STAGES[0].says}…</div>`
+ + '</div>';
+}
+
+/** What {@link attachSplash} hands the boot sequence. */
+export interface Splash {
+ /** Mark a stage finished and advance the bar by that stage's weight. */
+ reach(stage: BootStage): void;
+ /** Fade out and remove. Safe to call twice. */
+ done(): void;
+}
+
+/**
+ * Drive the page's start screen, or nothing when the page has none.
+ *
+ * A host that predates this (or a playable, which is sized by an SDK container
+ * and has no room for one) simply has no element, and boot proceeds untouched —
+ * the start screen must never be a thing a boot can fail on.
+ */
+export function attachSplash(doc: Document = document): Splash | null {
+ const root = doc.getElementById(ROOT);
+ if (!root) return null;
+ const bar = doc.getElementById(BAR);
+ const label = doc.getElementById(LABEL);
+ let done = 0;
+ const seen = new Set<BootStage>();
+ return {
+ reach(stage) {
+ // Idempotent by stage, not additive: a retried leg must not push the bar
+ // past what it has actually finished.
+ if (seen.has(stage)) return;
+ seen.add(stage);
+ done += BOOT_STAGES.find((s) => s.id === stage)?.weight ?? 0;
+ if (bar) bar.style.width = `${Math.min(100, Math.round((done / TOTAL) * 100))}%`;
+ const at = BOOT_STAGES.findIndex((s) => s.id === stage);
+ const next = BOOT_STAGES[at + 1];
+ if (label && next) label.textContent = `${next.says}…`;
+ },
+ done() {
+ if (!root.isConnected) return;
+ if (bar) bar.style.width = '100%';
+ root.classList.add('es-splash-gone');
+ setTimeout(() => root.remove(), 400);
+ },
+ };
+}
diff --git a/pipeline/src/runtime/gameHost.ts b/pipeline/src/runtime/gameHost.ts
index feb5a258d..0911a7a3d 100644
--- a/pipeline/src/runtime/gameHost.ts
+++ b/pipeline/src/runtime/gameHost.ts
@@ -25,8 +25,12 @@ import type {
SceneData, AddressableManifest, PackagedGameConfig, RenderSurfaceSource, WorldManifest,
} from 'esengine';
import type { ESEngineModule } from 'esengine/wasm';
+import { attachSplash } from '../export/splash';
async function boot(): Promise<void> {
const canvas = document.getElementById('canvas') as HTMLCanvasElement;
+ // Null on a page without one, and every call below is then a no-op: a start
+ // screen is something a boot shows, never something a boot depends on.
+ const splash = attachSplash();
// Render-verification hook: with ?headless the cooked build keeps its drawing
// buffer + exposes a framebuffer readback, so a driver can prove the SHIPPED
// runtime actually rendered the cooked scene (the editor host can't — it uses a
@@ -41,6 +45,7 @@ async function boot(): Promise<void> {
resize();
const cfg = (await (await fetch('./game.config.json')).json()) as PackagedGameConfig;
+ splash?.reach('config');
// The project's own components and systems. The config SAYS whether this build
// has any, so a load failure is a failure rather than a build that turned out
@@ -60,6 +65,7 @@ async function boot(): Promise<void> {
);
}
}
+ splash?.reach('scripts');
// Before anything acquires: the project's own modules were staged into wasm/
// beside the engine's, and this is what makes their ids resolvable.
registerPackagedSideModules(cfg);
@@ -70,6 +76,7 @@ async function boot(): Promise<void> {
const index = indexPackagedManifest(
(await (await fetch('./asset-manifest.json')).json()) as AddressableManifest,
);
+ splash?.reach('manifest');
// A named scene from the query boots instead of the entry, so a conformance
// harness can drive a fixture scene in the real package rather than needing a
// project of its own. Unknown names are refused rather than silently ignored.
@@ -88,6 +95,7 @@ async function boot(): Promise<void> {
worlds.push((await (await fetch(`./${world.manifest}`)).json()) as WorldManifest);
}
+ splash?.reach('scene');
const wasmBase = new URL('./wasm/', import.meta.url).href; // relative → mount-path agnostic
const { default: createModule } = (await import(/* @vite-ignore */ `${wasmBase}esengine.js`)) as {
default: (options?: Record<string, unknown>) => Promise<ESEngineModule>;
@@ -108,6 +116,8 @@ async function boot(): Promise<void> {
...(gpu.device ? { preinitializedWebGPUDevice: gpu.device } : {}),
});
+ splash?.reach('engine');
+
let gl: WebGL2RenderingContext | null = null;
let renderSurface: RenderSurfaceSource;
if (gpu.device) {
@@ -136,6 +146,7 @@ async function boot(): Promise<void> {
getViewportSize: () => ({ width: canvas.width, height: canvas.height }),
wasmBaseUrl: wasmBase.replace(/\/$/, ''), // SDK appends "/<file>" — no trailing slash
});
+ splash?.reach('app');
setEditorMode(false);
setPlayMode(true);
@@ -815,6 +826,11 @@ async function boot(): Promise<void> {
// Everything the config APPLIES to a live app: physics, the mixer, the theme.
...packagedRuntimeInit(cfg),
});
+ splash?.reach('assets');
+ // Before run(), not after: run() may hand control to the emscripten loop and
+ // never return, and the fade is what the first frames should arrive through.
+ splash?.reach('ready');
+ splash?.done();
app.run();
}
diff --git a/tools/launchers/launch-export.mjs b/tools/launchers/launch-export.mjs
index 608277230..2ba362953 100644
--- a/tools/launchers/launch-export.mjs
+++ b/tools/launchers/launch-export.mjs
@@ -308,14 +308,25 @@ const SCENE = flag('scene', '');
console.log(` render: ${JSON.stringify(seen)}`);
}
+ // A start screen that outlived its boot covers the game with something that
+ // looks like a game still loading, and every other check here still passes:
+ // the canvas painted underneath it, the frame is not flat, nothing errored.
+ const splashLeft = await win.webContents.executeJavaScript(
+ "!!document.getElementById('es-splash')",
+ ).catch(() => false);
+
const image = await win.webContents.capturePage();
if (OUT) await writeFile(OUT, image.toPNG());
stop();
server.close();
const live = frameIsLive(image);
- const ok = painted && live && errors.length === 0;
- console.log(`${ok ? '✓' : '✗'} ${path.basename(DIR)} — painted=${painted} live=${live} errors=${errors.length}`);
+ const ok = painted && live && !splashLeft && errors.length === 0;
+ console.log(`${ok ? '✓' : '✗'} ${path.basename(DIR)} — painted=${painted} live=${live}`
+ + `${splashLeft ? ' start-screen=STILL UP' : ''} errors=${errors.length}`);
+ if (splashLeft) {
+ console.log(' the start screen never faded — boot did not reach ready, or done() never ran');
+ }
for (const e of errors.slice(0, 5)) console.log(` ${e}`);
if (!painted) {
// How far it got, rather than "it did not start": a package drawing one slow
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 34ccfc2e3..d61de086a 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,9 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'feat(export): a packaged game says it is loading':
+ { note: 'A packaged game now says it is loading.' },
+
'fix(checks): a play realm that never came up says what it did say':
{ internal: "What an editor check prints when it fails; no creator runs the checks." },