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
feat(minigame): the engine subpackage fetch says how far along it is
esengine3b51f1314cce
diff --git a/pipeline/src/export/miniGameExportProfile.ts b/pipeline/src/export/miniGameExportProfile.tsindex 03a17f2e1..18278cf92 100644--- a/pipeline/src/export/miniGameExportProfile.ts+++ b/pipeline/src/export/miniGameExportProfile.ts@@ -94,20 +94,30 @@ bundle.boot(engineFactory, sideModuleFactories);`;${boot}`;}- // The engine binary is in a 分包, so the host has to fetch it before anything- // instantiates the engine. Failing loudly beats a blank canvas: without the- // binary there is no game to start, and the reason is worth saying once.+ // The host fetches the engine binary before anything can instantiate it, and+ // this runs BEFORE the bundle is parsed, so the runtime's own indicator+ // cannot cover the wait. Real byte progress, unlike every later stage.return `'use strict';// Generated by Estella exportGame (MiniGame entry, engine in a subpackage).-${ctx.hostGlobal}.loadSubpackage({+var __g = ${ctx.hostGlobal};+__g.showLoading({ title: 'Fetching the engine 0%', mask: true });+var __task = __g.loadSubpackage({name: ${JSON.stringify(ctx.engineSubpackage)},success() {${boot.split('\n').map((l) => (l ? ` ${l}` : l)).join('\n')}},fail(err) {+ __g.hideLoading();console.error('[estella] the engine subpackage ${ctx.engineSubpackage} did not load — the game cannot start', err);},});+// Optional on the host: a version without it leaves the 0% notice up, which is+// still a package that says it is doing something.+if (__task && __task.onProgressUpdate) {+ __task.onProgressUpdate(function (p) {+ __g.showLoading({ title: 'Fetching the engine ' + Math.round(p.progress || 0) + '%', mask: true });+ });+}`;}diff --git a/pipeline/tests/export-wechat.test.ts b/pipeline/tests/export-wechat.test.tsindex 1bb59e543..646fa8a41 100644--- a/pipeline/tests/export-wechat.test.ts+++ b/pipeline/tests/export-wechat.test.ts@@ -624,10 +624,22 @@ describe('exportGame (wechat)', () => {// 4. The entry asks for it BEFORE it boots — the binary is not in the package// until the host has loaded the 分包.const entry = readFileSync(path.join(o, 'game.js'), 'utf8');- expect(entry).toContain('wx.loadSubpackage');+ // The vendor's own host, bound once: `tt` answers the same shape and the+ // entry is generated from the profile, not written per vendor.+ expect(entry).toContain('= wx;');+ expect(entry).toContain('loadSubpackage');expect(entry.indexOf('loadSubpackage')).toBeLessThan(entry.indexOf('bundle.boot'));// And a failure says so rather than leaving a blank canvas.expect(entry).toContain('did not load');++ // 5. The player is told something is happening. This fetch runs BEFORE the+ // bundle is parsed, so the runtime's own indicator cannot cover it, and+ // it is the one part of a cold start with real byte progress.+ expect(entry.indexOf('showLoading')).toBeLessThan(entry.indexOf('loadSubpackage'));+ expect(entry).toContain('onProgressUpdate');+ // A failed fetch takes the notice down with it, rather than leaving the+ // host spinning over a game that will never start.+ expect(entry.slice(entry.indexOf('fail('))).toContain('hideLoading');}, 60_000);it('leaves the engine in the main package when the project did not ask', async () => {diff --git a/pipeline/tests/platform-catalog.test.ts b/pipeline/tests/platform-catalog.test.tsindex 4a0927855..37d43976e 100644--- a/pipeline/tests/platform-catalog.test.ts+++ b/pipeline/tests/platform-catalog.test.ts@@ -251,13 +251,13 @@ describe('loadProjectPlatform — the profile handed to exportMiniGame', () => {sideModules: [], engineGlueFile: 'esengine.js', runtimeDir: 'wasm',engineSubpackage: 'engine', hostGlobal: 'wx',});- expect(wxEntry).toContain('wx.loadSubpackage(');+ expect(wxEntry).toContain('= wx;');const ttEntry = p.emitEntry({sideModules: [], engineGlueFile: 'esengine.js', runtimeDir: 'wasm',engineSubpackage: 'engine', hostGlobal: 'tt',});- expect(ttEntry).toContain('tt.loadSubpackage(');- expect(ttEntry).not.toContain('wx.');+ expect(ttEntry).toContain('= tt;');+ expect(ttEntry).not.toContain('wx');// And the project's own emitter is what runs for config.expect(p.emitConfigFiles({ title: 'T', appid: '', orientation: 'portrait', subPackages: [], includeSuffixes: [], hasOpenData: false, openDataRoot: 'open-data' }))