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.

fix(export): a compressing host no longer runs the boot bar to the end of the engine download early

esengine834b10f0493c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bf24cc5c5..0b71ac03e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,8 @@ published separately; it ships inside the editor.
### Fixed
+- On a host that compresses the engine binary (most CDNs and static hosts), the web boot bar no longer runs to the end of the engine download a third of the way through and stands there for the rest of it: the page divided decompressed bytes by the compressed Content-Length. The export now records the binary's own size (`engineBytes` in `game.config.json`) and the bar measures against that.
+- Project Settings says the start screen's logo is for web exports; a mini-game shows its host's own start screen and loading text.
- The Profiler no longer reports a connected build's debug-channel cost as 0 ms when the device's clock is too coarse to measure it — a browser that is not cross-origin isolated steps by 0.1 ms. The device reports its clock's step, the row reads "< 0.100 ms", and `profile_frames` returns it as `channelClockMs`.
- An export warns when a signing key the project names (a quick game's or Android's) sits inside the project and is committed to its repository, or is not ignored and would be committed next.
- Opening a project no longer holds the editor behind "Preparing play realm…" for about ten seconds: the play realm's warm-up was being cut off and the editor waited out its deadline. A project now opens in under a second, and the first Play is still warm.
diff --git a/desktop b/desktop
index f900ac227..d96af00b3 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit f900ac22751a9823d20fedfd2428c97d9a0e8093
+Subproject commit d96af00b30a763ab815d46a5005f0e24aa293b2c
diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.ts
index 520c35ab6..8f281d121 100644
--- a/pipeline/src/export/exportGame.ts
+++ b/pipeline/src/export/exportGame.ts
@@ -1137,6 +1137,8 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>
...(aot ? { aot } : {}),
...(world.worlds.length > 0 ? { worlds: world.worlds } : {}),
...(debugChannel ? { debugChannel } : {}),
+ ...(existsSync(path.join(payloadDir, 'wasm', 'esengine.wasm'))
+ ? { engineBytes: statSync(path.join(payloadDir, 'wasm', 'esengine.wasm')).size } : {}),
};
await writeFile(path.join(payloadDir, 'game.config.json'), JSON.stringify(gameConfig, null, 2) + '\n');
diff --git a/pipeline/src/runtime/engineDownload.ts b/pipeline/src/runtime/engineDownload.ts
new file mode 100644
index 000000000..8876f14e9
--- /dev/null
+++ b/pipeline/src/runtime/engineDownload.ts
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file engineDownload.ts — how far the engine binary's download has got, as
+ * the boot bar reports it.
+ */
+
+/**
+ * The bytes a download will count, or 0 when nothing honest can be said. The
+ * stream yields decompressed bytes, so a compressing host's Content-Length is no
+ * denominator (the bar ended its stage a third of the way through). The size the
+ * export recorded is the answer when it is given.
+ */
+export function engineDownloadTotal(headers: Headers, engineBytes: number | undefined): number {
+ if (engineBytes && engineBytes > 0) return engineBytes;
+ const encoding = headers.get('content-encoding');
+ if (encoding && encoding !== 'identity') return 0;
+ return Number(headers.get('content-length') ?? 0);
+}
+
+/** The same bytes, with the fraction that has passed announced as they do. */
+export function countedStream(
+ body: ReadableStream<Uint8Array>, total: number, onFraction: (fraction: number) => void,
+): ReadableStream<Uint8Array> {
+ const reader = body.getReader();
+ let got = 0;
+ return new ReadableStream<Uint8Array>({
+ async pull(controller) {
+ const { done, value } = await reader.read();
+ if (done) {
+ controller.close();
+ return;
+ }
+ got += value.byteLength;
+ onFraction(got / total);
+ controller.enqueue(value);
+ },
+ cancel(reason) {
+ void reader.cancel(reason);
+ },
+ });
+}
diff --git a/pipeline/src/runtime/gameHost.ts b/pipeline/src/runtime/gameHost.ts
index 1d432d1f1..fec25194e 100644
--- a/pipeline/src/runtime/gameHost.ts
+++ b/pipeline/src/runtime/gameHost.ts
@@ -59,6 +59,7 @@ import type {
} from 'esengine';
import type { ESEngineModule } from 'esengine/wasm';
import { attachSplash, type Splash } from '../export/splash';
+import { countedStream, engineDownloadTotal } from './engineDownload';
/**
* Fetch the engine binary through a stream we can count, and hand the SAME
@@ -66,16 +67,18 @@ import { attachSplash, type Splash } from '../export/splash';
* sees the bytes. Re-wrapping the body keeps `instantiateStreaming`: reading it
* to an ArrayBuffer first would buy the bar at the cost of what it measures.
*/
-function engineInstantiator(url: string, splash: Splash | null) {
+function engineInstantiator(url: string, splash: Splash | null, engineBytes: number | undefined) {
return (imports: WebAssembly.Imports,
ok: (inst: WebAssembly.Instance, mod: WebAssembly.Module) => void): Record<string, never> => {
void (async () => {
const res = await fetch(url);
- const total = Number(res.headers.get('content-length') ?? 0);
+ const total = engineDownloadTotal(res.headers, engineBytes);
// No length or no stream ⇒ the honest answer is the stage weight alone.
- const source = total > 0 && res.body ? new Response(counted(res.body, total, splash), {
- headers: { 'content-type': 'application/wasm' },
- }) : res;
+ const source = total > 0 && res.body
+ ? new Response(countedStream(res.body, total, (f) => splash?.within('engine', f)), {
+ headers: { 'content-type': 'application/wasm' },
+ })
+ : res;
const { instance, module } = await WebAssembly.instantiateStreaming(source, imports);
ok(instance, module);
})();
@@ -83,27 +86,6 @@ function engineInstantiator(url: string, splash: Splash | null) {
};
}
-/** The same bytes, announced as they pass. */
-function counted(body: ReadableStream<Uint8Array>, total: number, splash: Splash | null): ReadableStream<Uint8Array> {
- const reader = body.getReader();
- let got = 0;
- return new ReadableStream<Uint8Array>({
- async pull(controller) {
- const { done, value } = await reader.read();
- if (done) {
- controller.close();
- return;
- }
- got += value.byteLength;
- splash?.within('engine', got / total);
- controller.enqueue(value);
- },
- cancel(reason) {
- void reader.cancel(reason);
- },
- });
-}
-
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
@@ -191,7 +173,7 @@ async function boot(): Promise<void> {
const module = await createModule({
canvas,
locateFile: (p: string) => `${wasmBase}${p}`,
- instantiateWasm: engineInstantiator(`${wasmBase}esengine.wasm`, splash),
+ instantiateWasm: engineInstantiator(`${wasmBase}esengine.wasm`, splash, cfg.engineBytes),
print: (t: string) => console.log(t),
printErr: (t: string) => console.error(t),
...(gpu.device ? { preinitializedWebGPUDevice: gpu.device } : {}),
diff --git a/pipeline/tests/engine-download.test.ts b/pipeline/tests/engine-download.test.ts
new file mode 100644
index 000000000..85aa63672
--- /dev/null
+++ b/pipeline/tests/engine-download.test.ts
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file The boot bar's engine download, measured against what actually arrives.
+ */
+import { describe, it, expect } from 'vitest';
+import { gzipSync } from 'node:zlib';
+import { countedStream, engineDownloadTotal } from '../src/runtime/engineDownload';
+
+/** A binary a host serves compressed, as a page's fetch sees it: decoded body,
+ * but the Content-Length of the compressed one. */
+function compressedResponse(raw: Uint8Array): { res: Response; stated: number } {
+ const gz = gzipSync(raw);
+ const body = new Response(gz).body!.pipeThrough(new DecompressionStream('gzip'));
+ return {
+ res: new Response(body, { headers: { 'content-length': String(gz.length), 'content-encoding': 'gzip' } }),
+ stated: gz.length,
+ };
+}
+
+async function drain(stream: ReadableStream<Uint8Array>): Promise<void> {
+ const r = stream.getReader();
+ while (!(await r.read()).done) { /* read to the end */ }
+}
+
+const binary = (): Uint8Array => {
+ const bytes = new Uint8Array(512 * 1024);
+ for (let i = 0; i < bytes.length; i++) bytes[i] = (i * 7) % 13;
+ return bytes;
+};
+
+describe('the engine download a boot bar reports', () => {
+ it('reaches its end with the last byte when the host compresses', async () => {
+ const raw = binary();
+ const { res, stated } = compressedResponse(raw);
+ expect(stated).toBeLessThan(raw.length / 3);
+ const seen: number[] = [];
+ await drain(countedStream(res.body!, engineDownloadTotal(res.headers, raw.length), (f) => seen.push(f)));
+ expect(seen.at(-1)).toBeCloseTo(1, 6);
+ expect(seen.filter((f) => f >= 1)).toHaveLength(1);
+ });
+
+ it('does not divide decoded bytes by a compressed length', () => {
+ const { res } = compressedResponse(binary());
+ expect(engineDownloadTotal(res.headers, undefined)).toBe(0);
+ });
+
+ it('uses the stated length when nothing is compressed', () => {
+ expect(engineDownloadTotal(new Headers({ 'content-length': '1000' }), undefined)).toBe(1000);
+ });
+});
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 17e699813..30ea95ff6 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -5319,6 +5319,7 @@ audioConfig: AudioProjectConfig | undefined
colorSpace: "gamma" | "linear" | undefined
debugChannel: DebugChannelConfig | undefined
depthLayers: number | undefined
+engineBytes: number | undefined
entryScene: string
hotUpdate: { remoteRoot?: string; persistUpdateKey?: string; } | undefined
msaaSamples: number | undefined
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index b709944ba..2fa298f09 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -5510,6 +5510,7 @@ audioConfig: AudioProjectConfig | undefined
colorSpace: "gamma" | "linear" | undefined
debugChannel: DebugChannelConfig | undefined
depthLayers: number | undefined
+engineBytes: number | undefined
entryScene: string
hotUpdate: { remoteRoot?: string; persistUpdateKey?: string; } | undefined
msaaSamples: number | undefined
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index e8ffc2ddc..633550f82 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -5314,6 +5314,7 @@ audioConfig: AudioProjectConfig | undefined
colorSpace: "gamma" | "linear" | undefined
debugChannel: DebugChannelConfig | undefined
depthLayers: number | undefined
+engineBytes: number | undefined
entryScene: string
hotUpdate: { remoteRoot?: string; persistUpdateKey?: string; } | undefined
msaaSamples: number | undefined
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index 77fb91427..6bfde910d 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -5584,6 +5584,7 @@ audioConfig: AudioProjectConfig | undefined
colorSpace: "gamma" | "linear" | undefined
debugChannel: DebugChannelConfig | undefined
depthLayers: number | undefined
+engineBytes: number | undefined
entryScene: string
hotUpdate: { remoteRoot?: string; persistUpdateKey?: string; } | undefined
msaaSamples: number | undefined
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index c5bf5d782..38382dcc1 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -5321,6 +5321,7 @@ audioConfig: AudioProjectConfig | undefined
colorSpace: "gamma" | "linear" | undefined
debugChannel: DebugChannelConfig | undefined
depthLayers: number | undefined
+engineBytes: number | undefined
entryScene: string
hotUpdate: { remoteRoot?: string; persistUpdateKey?: string; } | undefined
msaaSamples: number | undefined
diff --git a/sdk/src/runtime/packagedRuntime.ts b/sdk/src/runtime/packagedRuntime.ts
index 142343f1c..ad48ff7ef 100644
--- a/sdk/src/runtime/packagedRuntime.ts
+++ b/sdk/src/runtime/packagedRuntime.ts
@@ -80,6 +80,12 @@ export interface PackagedGameConfig {
/** The Steam application id, when this build ships to Steam. Its presence is
* what makes the runtime try to bring a Steam client up at all. */
steamAppId?: number;
+ /**
+ * The engine binary's size as it arrives in the page, decompressed. A host
+ * that compresses states a Content-Length for fewer bytes than a download
+ * counts, so the boot bar measures against this instead.
+ */
+ engineBytes?: number;
/**
* Install physics even when the shipped scene shows no bodies — a project
* that spawns them from script (Project Settings → Physics → Enabled).
diff --git a/tools/launchers/launch-export.mjs b/tools/launchers/launch-export.mjs
index c32e7f3ff..2b309e73e 100644
--- a/tools/launchers/launch-export.mjs
+++ b/tools/launchers/launch-export.mjs
@@ -53,6 +53,7 @@
import { app, BrowserWindow } from 'electron';
import http from 'node:http';
import { readFile, writeFile } from 'node:fs/promises';
+import { gzipSync } from 'node:zlib';
import { existsSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -155,7 +156,7 @@ const clockScript = (ms) => `<script>(() => {
});
})();</script>`;
-function serve(root, safeArea, frameMs) {
+function serve(root, safeArea, frameMs, compress) {
const server = http.createServer(async (req, res) => {
try {
let rel = decodeURIComponent(new URL(req.url, 'http://x').pathname).replace(/^\/+/, '');
@@ -175,12 +176,20 @@ function serve(root, safeArea, frameMs) {
if (injected === html) console.log(' no <head> to inject the safe area or clock into');
bytes = Buffer.from(injected);
}
+ // A modelled network is also a modelled host, and hosts compress: served
+ // raw, the link carries three times what a player downloads, and a
+ // compressed Content-Length (which a download bar must survive) never occurs.
+ const type = MIME[path.extname(abs).toLowerCase()] ?? 'application/octet-stream';
+ const encode = compress && /gzip/.test(String(req.headers['accept-encoding'] ?? ''))
+ && /javascript|json|wasm|html|css/.test(type);
+ if (encode) bytes = gzipSync(bytes);
// Content-Length, which node omits unless told (it chunks instead): every
// real server sends it, and a loader that reports download progress has
// nothing to divide by without it.
res.writeHead(200, {
- 'content-type': MIME[path.extname(abs).toLowerCase()] ?? 'application/octet-stream',
+ 'content-type': type,
'content-length': bytes.length,
+ ...(encode ? { 'content-encoding': 'gzip' } : {}),
}).end(bytes);
} catch {
res.writeHead(404).end();
@@ -221,7 +230,7 @@ const AI = flag('ai', '');
const RENDER = has('render');
/** Boot a named scene from the package instead of its entry. */
const SCENE = flag('scene', '');
- const server = await serve(DIR, flag('safe-area', ''), Number(flag('frame-ms', String(1000 / 60))));
+ const server = await serve(DIR, flag('safe-area', ''), Number(flag('frame-ms', String(1000 / 60))), !!THROTTLE);
const query = new URLSearchParams();
if (PROBE || GAMEPLAY || PARTICLES || COMBAT || AI || RENDER || FACTS || STREAMING) query.set('headless', '');
if (SCENE) query.set('scene', SCENE);
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 031c96786..05964dae0 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -1174,4 +1174,8 @@ export const NOTED = {
{ note: 'The CDN root remote asset groups and hot updates use is a packaging setting of the project (`packaging.remoteRoot`, the Package dialog\'s CDN root field), and export profiles override it — a production profile carries the real CDN while the project stays same-origin. `.esengine/asset-groups.json`\'s `activeProfile` / `profiles` are still read for a project that sets no root of its own; hot-update-demo and the hot-update docs use the new shape.' },
'feat(build): the CDN root field writes the project\'s setting':
{ note: 'The CDN root remote asset groups and hot updates use is a packaging setting of the project (`packaging.remoteRoot`, the Package dialog\'s CDN root field), and export profiles override it — a production profile carries the real CDN while the project stays same-origin. `.esengine/asset-groups.json`\'s `activeProfile` / `profiles` are still read for a project that sets no root of its own; hot-update-demo and the hot-update docs use the new shape.' },
+ 'fix(export): a compressing host no longer runs the boot bar to the end of the engine download early':
+ { note: 'On a host that compresses the engine binary (most CDNs and static hosts), the web boot bar no longer runs to the end of the engine download a third of the way through and stands there for the rest of it: the page divided decompressed bytes by the compressed Content-Length. The export now records the binary\'s own size (`engineBytes` in `game.config.json`) and the bar measures against that.' },
+ 'fix(settings): the start screen\'s logo says it is for web exports':
+ { note: 'Project Settings says the start screen\'s logo is for web exports; a mini-game shows its host\'s own start screen and loading text.' },
};