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(assets): a hot update reaches what was built from what it changed
esengine8b2e8d84a95b
diff --git a/sdk/src/asset/Assets.ts b/sdk/src/asset/Assets.tsindex 490480801..c5c5d7460 100644--- a/sdk/src/asset/Assets.ts+++ b/sdk/src/asset/Assets.ts@@ -946,6 +946,10 @@ export class Assets {// The manifest record already says what kind each changed asset is; the// notification carries it rather than collapsing to "maybe a texture".for (const c of changed) this.fireInvalidate_({ ref: c.key, type: c.type, oldValue: oldHandles.get(c.key) });+ // A changed asset is content-addressed, so its next load finds the update+ // on its own. An era already BUILT from one cannot: it holds what it read+ // at the revision it was prepared in, and only the walk ends it.+ for (const c of changed) void this.rebuild_(this.rebuildPlan_(c.key));this.persistActiveManifest_(pending.manifestJson);this.pendingUpdate_ = null;return { ok: true, updated: changed.length, failed: [] };diff --git a/sdk/tests/hot-update-runtime.test.ts b/sdk/tests/hot-update-runtime.test.tsindex 05501bae4..78e6af265 100644--- a/sdk/tests/hot-update-runtime.test.ts+++ b/sdk/tests/hot-update-runtime.test.ts@@ -107,6 +107,38 @@ describe('Assets.loadGroup — remote group', () => {});});+describe('a hot update reaches what was built from what it changed', () => {+ it('re-prepares the asset that read a changed one, against the new content', async () => {+ // The changed asset itself is content-addressed, so the next load of it+ // finds the update on its own. What CANNOT is an era already built from+ // it: it holds what it read at the revision it was prepared in.+ const backend = backendServing(cdnManifest(REMOTE_HASH, 'rev-2'));+ const assets = createAssets(backend);+ assets.setManifest(cdnManifest('aaaa', 'rev-1'));+ assets.setRemoteRoot('https://cdn/v1');+ const builtFrom: string[] = [];+ assets.register({+ type: 'widget', extensions: ['.widget'],+ registry: {+ prepare: async (path, ctx) => {+ await ctx.readSource!('assets/hero.png');+ builtFrom.push(assets.resolveLoadPath('assets/hero.png'));+ return { published: { path }, value: { id: path } };+ },+ },+ });+ await assets.acquireTyped('widget', 'w.widget');+ expect(builtFrom).toEqual(['https://cdn/v1/assets/aaaa.png']);++ await assets.checkForUpdate({ manifestUrl: 'asset-manifest.json', remoteRoot: 'https://cdn/v2' });+ await assets.applyUpdate();+ for (let i = 0; i < 4; i++) await new Promise((resolve) => setTimeout(resolve, 0));++ expect(builtFrom[1], 'the widget kept the revision it was built in')+ .toBe(`https://cdn/v2/assets/${REMOTE_HASH}.png`);+ });+});+describe('Assets.checkForUpdate / applyUpdate', () => {it('checkForUpdate diffs the fetched manifest against the active one without applying', async () => {const assets = createAssets(backendServing(cdnManifest('zzzz', 'rev-2')));