perf: decode-ahead sprite cache; cache bust v56
Sprites.load() now awaits img.decode() before a tier image counts as ready, so every sprite is fully decoded during the title screen and first-draw decode jitter disappears on weak machines. Headless smoke keeps working via the typeof-decode fallback. Asset URLs bump to v=56.
This commit is contained in:
1 parent
4b9e4a1e97
commit
8c2141c3f1
3 files changed
+26
-26
No files matched your search
+1
-1
@@ -111,7 +111,7 @@ const SfxBank = {
|
||||
if (this.buffers.has(name) || this.pending.has(name) || this.failed.has(name)) return;
|
||||
const file = this.FILES[name];
|
||||
if (!file || !this.ctx || typeof fetch !== 'function') return;
|
||||
const job = fetch('/assets/sfx/' + encodeURIComponent(file) + '?v=55')
|
||||
const job = fetch('/assets/sfx/' + encodeURIComponent(file) + '?v=56')
|
||||
.then(r => { if (!r.ok) throw new Error('HTTP ' + r.status); return r.arrayBuffer(); })
|
||||
.then(bytes => this.ctx.decodeAudioData(bytes))
|
||||
.then(buffer => this.buffers.set(name, this.trim(buffer)))
|
||||
|
||||
+3
-3
@@ -86,12 +86,12 @@ const Sprites = {
|
||||
pending++;
|
||||
const img = new Image();
|
||||
const finish = () => { if (--pending === 0) G.imagesLoaded = true; };
|
||||
img.onload = () => { this.imgs[name] = img; finish(); };
|
||||
img.onload = () => { this.imgs[name] = img; if (typeof img.decode === 'function') img.decode().then(finish, finish); else finish(); };
|
||||
img.onerror = () => {
|
||||
if (hd && !img._sdRetry) { img._sdRetry = true; img.src = 'assets/' + name + '.png?v=55'; return; }
|
||||
if (hd && !img._sdRetry) { img._sdRetry = true; img.src = 'assets/' + name + '.png?v=56'; return; }
|
||||
finish();
|
||||
};
|
||||
img.src = hd ? 'assets/hd/' + name + '.webp?v=55' : 'assets/' + name + '.png?v=55';
|
||||
img.src = hd ? 'assets/hd/' + name + '.webp?v=56' : 'assets/' + name + '.png?v=56';
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in new issue
Block a user