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
revert(export): the start screen's code-download progress, which stalled golden web packages on CI
esengined83cce30c3b3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex cdd11197a..0b71ac03e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,7 +16,6 @@ published separately; it ships inside the editor.### Added-- The web start screen moves while the game's own code downloads, before any of it can run: the page counts each script it finishes against the code the export measured, so on a Slow 4G link the bar no longer stands at its first step for 2.5 s (the longest it stands still is now about 0.6 s). A portal's own loading screen hears the same progress.- **Android release signing.** A Shipping APK (and App Bundle) is signed with the release key the project names under Project Settings → Android → Signing — two PEM paths, the passphrase kept in this machine's keychain (the command line reads `ESTELLA_ANDROID_KEY_PASSPHRASE`); Development builds keep the development key. A Shipping build without one says it will be refused by Google Play.- **Export profiles.** A project can name several exports of one target in `packaging.profiles` — a test and a production WeChat build, each with its own AppID, CDN root and development or shipping configuration, writing only what differs from the project's settings. The Build dialog creates, edits and deletes them per target, marking each setting a profile overrides with a reset that hands it back to the project; `estella export --profile <name>` and the agent's `export_game` build the same one, and the size history records which profile a build used.diff --git a/desktop b/desktopindex 1760e2348..7988d526a 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 1760e2348c8398841f36e5df50588d8efb5bb3ba+Subproject commit 7988d526acd0b7cbdd83dfdb5383b957621aef7adiff --git a/pipeline/src/export/bootCode.ts b/pipeline/src/export/bootCode.tsdeleted file mode 100644index 8b2b1f516..000000000--- a/pipeline/src/export/bootCode.ts+++ /dev/null@@ -1,38 +0,0 @@-// SPDX-License-Identifier: Apache-2.0-// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team-/**- * @file bootCode.ts — the code a web page downloads before the game's own boot- * can report anything, and so what the start screen measures on its own.- */-import { readFileSync, statSync, existsSync } from 'node:fs';-import path from 'node:path';--/** `import … from "x"`, `import "x"`, `export … from "x"` — not `import("x")`,- * which is fetched when the running game asks for it. */-const STATIC_IMPORT = /(?:^|[;\s}])(?:import|export)\s*(?:[\w*{}\s,$]*?\s*from\s*)?["']([^"'\n]+)["']/g;--/**- * The bytes of `entry` and every module it statically imports, resolved through- * the page's import map. Unresolved or missing specifiers are left out: they are- * not this page's to download.- */-export function bootCodeBytes(root: string, entry: string, importMap: Record<string, string>): number {- const seen = new Set<string>();- const pending = [path.resolve(root, entry)];- let bytes = 0;- while (pending.length > 0) {- const file = pending.pop()!;- if (seen.has(file) || !existsSync(file)) continue;- seen.add(file);- bytes += statSync(file).size;- const source = readFileSync(file, 'utf8');- for (const match of source.matchAll(STATIC_IMPORT)) {- const spec = match[1];- const mapped = importMap[spec];- const target = mapped !== undefined ? path.resolve(root, mapped)- : spec.startsWith('.') ? path.resolve(path.dirname(file), spec) : null;- if (target) pending.push(target);- }- }- return bytes;-}diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.tsindex 59ee6dbcb..8f281d121 100644--- a/pipeline/src/export/exportGame.ts+++ b/pipeline/src/export/exportGame.ts@@ -63,9 +63,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 { PAGE_BACKGROUND, splashCss, splashHtml, splashCodeJs, splashCodeScript, type SplashLook } from './splash';-import { bootCodeBytes } from './bootCode';-import { createHash } from 'node:crypto';+import { PAGE_BACKGROUND, splashCss, splashHtml, type SplashLook } 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';@@ -331,8 +329,7 @@ function indexHtml(// page may connect to; a build without a channel lists none.const connect = debugChannel ? ` ${new URL(debugChannel.url).origin}` : '';// Every inline script on this page needs its hash listed, or the browser blocks it.- const codeHash = `sha256-${createHash('sha256').update(splashCodeJs()).digest('base64')}`;- const inlineScripts = [map.cspHash, codeHash, ...(orientation ? [orientationLockCspHash(orientation)] : [])]+ const inlineScripts = [map.cspHash, ...(orientation ? [orientationLockCspHash(orientation)] : [])].map((h) => `'${h}'`).join(' ');return `<!doctype html>@@ -357,7 +354,6 @@ function indexHtml(<body><canvas id="canvas"></canvas>${splashHtml(title, look)}- ${splashCodeScript()}${orientation ? orientationOverlayHtml(orientation) : ''}${orientation ? orientationLockScript(orientation) : ''}<script type="module" src="./game.js"></script>@@ -1122,11 +1118,8 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>let splashBytes: number | undefined;if (!nativeContent) {progress({ phase: 'Writing host page' });- const look = {- ...await splashLook(opts.root, opts.splash, warnings),- codeBytes: bootCodeBytes(payloadDir, 'game.js', JSON.parse(engineMap.json).imports ?? {}),- };- splashBytes = Buffer.byteLength(splashCss(look.background ?? PAGE_BACKGROUND) + splashHtml(title, look) + splashCodeScript());+ const look = await splashLook(opts.root, opts.splash, warnings);+ splashBytes = Buffer.byteLength(splashCss(look.background ?? PAGE_BACKGROUND) + splashHtml(title, look));await writeFile(path.join(payloadDir, 'index.html'),indexHtml(title, engineMap, look, platform === 'web' ? orientation : undefined, debugChannel),diff --git a/pipeline/src/export/splash.ts b/pipeline/src/export/splash.tsindex 8835437f3..ab0d38ab2 100644--- a/pipeline/src/export/splash.ts+++ b/pipeline/src/export/splash.ts@@ -38,9 +38,6 @@ export interface SplashLook {minMs?: number;/** CSS colour behind it; the page's own when the project said nothing. */background?: string;- /** Bytes of code the page loads before the game's boot can report, which the- * page's own script measures (see {@link splashCodeScript}). */- codeBytes?: number;}/**@@ -68,12 +65,11 @@ export function splashCss(background: string): string {);}-/** The start screen's markup. `minMs` and `codeBytes` ride on data attributes,- * read by the scripts that drive it. */+/** The start screen's markup — no script of its own, so the page adds no CSP hash.+ * `minMs` rides on a data attribute for the same reason. */export function splashHtml(title: string, look: SplashLook = {}): string {const safe = title.replace(/[&<>]/g, (c) => ({ '&': '&', '<': '<', '>': '>' }[c] as string));- const hold = (look.minMs ? ` data-min-ms="${Math.round(look.minMs)}"` : '')- + (look.codeBytes ? ` data-code-bytes="${Math.round(look.codeBytes)}"` : '');+ const hold = look.minMs ? ` data-min-ms="${Math.round(look.minMs)}"` : '';// A game with a logo shows the logo; the title is then the alt text rather// than a second heading saying the same thing.const mark = look.logo@@ -86,30 +82,6 @@ export function splashHtml(title: string, look: SplashLook = {}): string {+ '</div>';}-const CODE_SHARE = (BOOT_STAGES.find((s) => s.id === 'code')?.weight ?? 0) / BOOT_TOTAL;--/**- * Moves the bar, and tells a portal, while the game's code downloads and none of- * it can run: each finished script adds its bytes to the total the export counted.- * A file counts once whole; a cross-origin host without Timing-Allow-Origin- * reports no size, and then the bar stays.- */-export function splashCodeJs(): string {- return `(function(){var r=document.getElementById('${ROOT}'),b=document.getElementById('${BAR}');`- + `var t=+(r&&r.getAttribute('data-code-bytes'))||0;if(!b||!t||!window.PerformanceObserver)return;`- + `var got=0,seen={};function take(l){l.getEntries().forEach(function(e){`- + `if(seen[e.name]||!/\\.m?js(\\?|$)/.test(e.name))return;seen[e.name]=1;got+=e.decodedBodySize||0;`- + `var f=Math.min(1,got/t);window.__esBootCode=f;if(window.__esBootTaken)return;`- + `b.style.width=Math.round(f*${CODE_SHARE}*100)+'%';`- + `dispatchEvent(new CustomEvent('${BOOT_PROGRESS_EVENT}',{detail:{stage:'code',progress:f*${CODE_SHARE},partial:true}}));});}`- + `try{new PerformanceObserver(take).observe({type:'resource',buffered:true});}catch(e){}})();`;-}--/** The inline script that measures the code download; see {@link splashCodeJs}. */-export function splashCodeScript(): string {- return `<script>${splashCodeJs()}</script>`;-}-/** What {@link attachSplash} hands the boot sequence. */export interface Splash {/** Mark a stage finished and advance the bar by that stage's weight. */@@ -144,12 +116,8 @@ export function attachSplash(doc: Document = document): Splash {const label = root && doc.getElementById(LABEL);const showUntil = Date.now() + Number(root?.getAttribute('data-min-ms') ?? 0);let done = 0;- // The page's own script has been moving the bar while this code downloaded;- // from here on the boot reports, and the bar carries on from where it is.- const view = doc.defaultView as (Window & { __esBootCode?: number; __esBootTaken?: boolean }) | null;- if (view) view.__esBootTaken = true;/** What the bar is showing, so a partial step never pulls it back. */- let shown = (view?.__esBootCode ?? 0) * CODE_SHARE;+ let shown = 0;let finished = false;const seen = new Set<BootStage>();const announce = (type: string, detail: unknown): void => {diff --git a/pipeline/src/runtime/gameHost.ts b/pipeline/src/runtime/gameHost.tsindex 04e8f2e6d..fec25194e 100644--- a/pipeline/src/runtime/gameHost.ts+++ b/pipeline/src/runtime/gameHost.ts@@ -105,7 +105,6 @@ async function boot(): Promise<void> {resize();const cfg = (await (await fetch('./game.config.json')).json()) as PackagedGameConfig;- splash?.reach('code');splash?.reach('config');// Before the engine boots, so a boot that fails is still heard by the editor.if (cfg.debugChannel) startDebugChannel(cfg.debugChannel);diff --git a/pipeline/tests/boot-code.test.ts b/pipeline/tests/boot-code.test.tsdeleted file mode 100644index abeb072ef..000000000--- a/pipeline/tests/boot-code.test.ts+++ /dev/null@@ -1,35 +0,0 @@-// SPDX-License-Identifier: Apache-2.0-// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team-/**- * @file The code a web page loads before its boot can report.- */-import { describe, it, expect, beforeAll, afterAll } from 'vitest';-import { mkdtempSync, mkdirSync, writeFileSync, rmSync, statSync } from 'node:fs';-import { tmpdir } from 'node:os';-import path from 'node:path';-import { bootCodeBytes } from '../src/export/bootCode';--let root: string;-const size = (f: string) => statSync(path.join(root, f)).size;--beforeAll(() => {- root = mkdtempSync(path.join(tmpdir(), 'boot-code-'));- mkdirSync(path.join(root, 'sdk', 'shared'), { recursive: true });- writeFileSync(path.join(root, 'game.js'), 'import { a } from "esengine";\nimport("./later.js");\nconsole.log(a);\n');- writeFileSync(path.join(root, 'later.js'), 'export const late = 1;\n');- writeFileSync(path.join(root, 'sdk', 'index.js'), 'import{t as x}from"./shared/one.js";export{b}from"./shared/two.js";export const a=x;\n');- writeFileSync(path.join(root, 'sdk', 'shared', 'one.js'), 'import"./two.js";export const t=1;\n');- writeFileSync(path.join(root, 'sdk', 'shared', 'two.js'), 'export const b=2;\n');-});-afterAll(() => rmSync(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 }));--describe('the code a page loads before its boot can report', () => {- it('is the entry and everything it statically imports, each once, through the import map', () => {- expect(bootCodeBytes(root, 'game.js', { esengine: './sdk/index.js' }))- .toBe(size('game.js') + size('sdk/index.js') + size('sdk/shared/one.js') + size('sdk/shared/two.js'));- });-- it('leaves out what the running game imports later, and specifiers the map does not name', () => {- expect(bootCodeBytes(root, 'game.js', {})).toBe(size('game.js'));- });-});diff --git a/pipeline/tests/export-splash.test.ts b/pipeline/tests/export-splash.test.tsindex 2250783fb..5749942b9 100644--- a/pipeline/tests/export-splash.test.ts+++ b/pipeline/tests/export-splash.test.ts@@ -8,8 +8,7 @@* same window the engine does, with nothing left to cover.*/import { describe, it, expect, beforeAll, afterAll } from 'vitest';-import { createHash } from 'node:crypto';-import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, statSync } from 'node:fs';+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';import path from 'node:path';import { exportGame } from '../src/export/exportGame';@@ -51,7 +50,7 @@ beforeAll(() => {afterAll(() => rmSync(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 }));/** Export for web and hand back the page plus whatever the build said about it. */-async function page(splash?: ProjectPackaging['splash']): Promise<{ html: string; warnings: string[]; splashBytes?: number; outDir: string }> {+async function page(splash?: ProjectPackaging['splash']): Promise<{ html: string; warnings: string[]; splashBytes?: number }> {const outDir = path.join(root, `dist-${Math.random().toString(36).slice(2)}`);const res = await exportGame({root,@@ -66,7 +65,7 @@ async function page(splash?: ProjectPackaging['splash']): Promise<{ html: stringsplash,});expect(res.ok, res.errors.join('\n')).toBe(true);- return { html: readFileSync(path.join(outDir, 'index.html'), 'utf8'), warnings: res.warnings, splashBytes: res.size?.splashBytes, outDir };+ return { html: readFileSync(path.join(outDir, 'index.html'), 'utf8'), warnings: res.warnings, splashBytes: res.size?.splashBytes };}describe('the exported page’s start screen', () => {@@ -78,17 +77,6 @@ describe('the exported page’s start screen', () => {expect(withLogo.splashBytes! - plain.splashBytes!).toBeGreaterThanOrEqual(Math.floor(PNG.length * 4 / 3));}, 180_000);- it('counts the code it loads before the boot can report, and may run the script that measures it', async () => {- const { html, outDir } = await page();- const bytes = Number(/data-code-bytes="(\d+)"/.exec(html)?.[1]);- const entry = JSON.parse(/<script type="importmap">([^<]*)<\/script>/.exec(html)![1]).imports.esengine as string;- expect(bytes).toBe(statSync(path.join(outDir, 'game.js')).size + statSync(path.join(outDir, entry)).size);- const script = /<script>(\(function\(\)\{var r=document\.getElementById\('es-splash'\)[\s\S]*?)<\/script>/.exec(html)?.[1];- expect(script).toBeDefined();- const hash = createHash('sha256').update(script!).digest('base64');- expect(html).toContain(`'sha256-${hash}'`);- }, 180_000);-it('is there with nothing configured, showing the game’s name', async () => {const { html } = await page();expect(html).toContain('id="es-splash"');diff --git a/pipeline/tests/splash-screen.test.ts b/pipeline/tests/splash-screen.test.tsindex e97147860..97f17ac24 100644--- a/pipeline/tests/splash-screen.test.ts+++ b/pipeline/tests/splash-screen.test.ts@@ -8,7 +8,7 @@* esbuild, and a DOM in that process breaks it.*/import { describe, it, expect } from 'vitest';-import { BOOT_STAGES, BOOT_PROGRESS_EVENT, FIRST_FRAME_EVENT, attachSplash, splashCodeJs } from '../src/export/splash';+import { BOOT_STAGES, BOOT_PROGRESS_EVENT, FIRST_FRAME_EVENT, attachSplash } from '../src/export/splash';describe('driving the start screen', () => {const mount = (attrs = ''): Document => {@@ -31,56 +31,6 @@ describe('driving the start screen', () => {expect(seen[seen.length - 1].progress).toBe(1);});- it('is moved by the page itself while the code downloads, a script at a time', () => {- const doc = mount(' data-code-bytes="1000"');- const view = window as Window & { __esBootCode?: number; __esBootTaken?: boolean; PerformanceObserver?: unknown };- delete view.__esBootTaken;- let deliver: (names: [string, number][]) => void = () => {};- const real = view.PerformanceObserver;- view.PerformanceObserver = class {- constructor(cb: (list: { getEntries: () => unknown[] }) => void) {- deliver = (names) => cb({ getEntries: () => names.map(([name, decodedBodySize]) => ({ name, decodedBodySize })) });- }- observe() {}- };- const seen: number[] = [];- const listen = (e: Event) => seen.push((e as CustomEvent).detail.progress);- window.addEventListener(BOOT_PROGRESS_EVENT, listen);- try {- new Function(splashCodeJs())();- const share = BOOT_STAGES.find((s) => s.id === 'code')!.weight / BOOT_STAGES.reduce((n, s) => n + s.weight, 0);- deliver([['https://game.example/game.js', 400], ['https://game.example/logo.png', 999]]);- deliver([['https://game.example/sdk/index.lean.js?v=2', 600], ['https://game.example/game.js', 400]]);- expect(view.__esBootCode).toBe(1);- expect(seen.map((p) => +(p / share).toFixed(3))).toEqual([0.4, 1]);- expect(doc.getElementById('es-splash-bar')!.style.width).toBe(`${Math.round(share * 100)}%`);- } finally {- window.removeEventListener(BOOT_PROGRESS_EVENT, listen);- view.PerformanceObserver = real;- delete view.__esBootCode;- }- });-- it('carries on from where the page moved the bar while the code downloaded', () => {- const doc = mount();- const view = window as Window & { __esBootCode?: number; __esBootTaken?: boolean };- view.__esBootCode = 0.5;- delete view.__esBootTaken;- const code = BOOT_STAGES.find((s) => s.id === 'code')!;- const total = BOOT_STAGES.reduce((n, s) => n + s.weight, 0);- const bar = doc.getElementById('es-splash-bar')!;- bar.style.width = `${Math.round(0.5 * (code.weight / total) * 100)}%`;- const before = bar.style.width;- const splash = attachSplash(doc);- expect(view.__esBootTaken).toBe(true);- // A partial step inside the code stage the page already passed does not pull it back.- splash.within('code', 0.1);- expect(bar.style.width).toBe(before);- splash.reach('code');- expect(parseInt(bar.style.width, 10)).toBe(Math.round((code.weight / total) * 100));- delete view.__esBootCode;- });-it('says when the first frame is up, even on a page with no start screen', () => {document.body.innerHTML = '';let frames = 0;diff --git a/sdk/src/runtime/bootStages.ts b/sdk/src/runtime/bootStages.tsindex 888790a94..52a304329 100644--- a/sdk/src/runtime/bootStages.ts+++ b/sdk/src/runtime/bootStages.ts@@ -15,9 +15,6 @@/** A boot stage, in the order a host reaches them. */export const BOOT_STAGES = [- // The game's own code, which a web page downloads before anything in it can- // report; the page measures it by bytes, a mini-game already holds it.- { id: 'code', weight: 24, says: 'Downloading the game' },{ id: 'config', weight: 4, says: 'Reading the build' },{ id: 'scripts', weight: 6, says: 'Loading scripts' },{ id: 'manifest', weight: 4, says: 'Reading the asset list' },diff --git a/sdk/src/runtime/miniGameRuntime.ts b/sdk/src/runtime/miniGameRuntime.tsindex 354dc9f4e..e39a762b6 100644--- a/sdk/src/runtime/miniGameRuntime.ts+++ b/sdk/src/runtime/miniGameRuntime.ts@@ -230,7 +230,6 @@ export async function initMiniGameRuntime(config: MiniGameRuntimeConfig): Promis}const tag = adapter.name;const progress = hostProgress(adapter.host);- progress.reach('code');progress.reach('config');progress.reach('scripts');diff --git a/sdk/tests/boot-stages.test.ts b/sdk/tests/boot-stages.test.tsindex 3775431d4..b409177e7 100644--- a/sdk/tests/boot-stages.test.ts+++ b/sdk/tests/boot-stages.test.ts@@ -32,7 +32,7 @@ describe('the boot a package reports', () => {it('says what it is about to do, not what it just did', () => {expect(bootSays([])).toBe(BOOT_STAGES[0].says);- expect(bootSays([ids[0]])).toBe(BOOT_STAGES[1].says);+ expect(bootSays(['config'])).toBe(BOOT_STAGES[1].says);});it('says the last stage once everything is done, rather than nothing', () => {diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 90f26f8b9..1f60b781d 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -1179,5 +1179,5 @@ export const NOTED = {'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.' },'feat(export): the start screen shows the game\'s code downloading':- { note: 'The web start screen moves while the game\'s own code downloads, before any of it can run: the page counts each script it finishes against the code the export measured, so on a Slow 4G link the bar no longer stands at its first step for 2.5 s (the longest it stands still is now about 0.6 s). A portal\'s own loading screen hears the same progress.' },+ { internal: 'Reverted before release: golden web packages stalled after 29 frames on the CI runners; see the revert.' },};