commit 6ecdc2b5063171c96e18f5d8501a32c2b0e0ab25
parent 6b1075cfcb46c91a3030a7aa2ae41ec180a7faf1
Author: anon <anon@example.com>
Date: Sat, 17 Oct 2026 17:04:45 +0000
Prefetch footwear sounds across terrain changes
Diffstat:
2 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/src/runtime/browser_fetch.js b/src/runtime/browser_fetch.js
@@ -28,23 +28,31 @@ addToLibrary({
}
}
+ function soundFamily(url) {
+ // Terrain and action variants share one footwear directory.
+ const footsteps = /^(.*\/sound\/sfx\/foots\/[^/]+\/)[^/]+\.wav$/i.exec(url);
+ if (footsteps) return footsteps[1];
+ const numbered = /^(.*\/sound\/.*?)(\d+)\.wav$/i.exec(url);
+ return numbered && numbered[1];
+ }
+
function prefetchSounds(url) {
- const match = /^(.*\/sound\/.*?)(\d+)\.wav$/i.exec(url);
- if (!match || prefetchedFamilies.has(match[1])) return;
- prefetchedFamilies.add(match[1]);
+ const family = soundFamily(url);
+ if (!family || prefetchedFamilies.has(family)) return;
+ prefetchedFamilies.add(family);
// Return the requested sound first; find and fetch siblings in the background.
setTimeout(() => {
if (!soundGroups) {
// Sound reads begin after browser_initialize has built the remote file tree.
soundGroups = new Map();
for (const handle of allocatedFiles) {
- const other = /^(.*\/sound\/.*?)(\d+)\.wav$/i.exec(fileURL(handle));
+ const other = soundFamily(fileURL(handle));
if (!other) continue;
- if (!soundGroups.has(other[1])) soundGroups.set(other[1], []);
- soundGroups.get(other[1]).push(handle);
+ if (!soundGroups.has(other)) soundGroups.set(other, []);
+ soundGroups.get(other).push(handle);
}
}
- for (const handle of soundGroups.get(match[1]) || [])
+ for (const handle of soundGroups.get(family) || [])
if (!files.has(handle)) prefetchQueue.push(handle);
pumpPrefetch();
});
diff --git a/src/tests/browser_prefetch.mjs b/src/tests/browser_prefetch.mjs
@@ -68,3 +68,37 @@ assert.equal(requests.length,5);
assert.equal(timers.length,0);
assert.equal(requests.includes('boots_con_01.wav'), false);
console.log('PASS: bounded prefetch, shared foreground request, freed-file skip and retry');
+
+
+// Surface and action changes retain the same footwear, but other footwear stays unloaded.
+names.clear();
+for (const [handle,name] of [[1,'boots/boots_con_01.wav'],[2,'boots/boots_con_02.wav'],
+ [3,'boots/boots_dirt_01.wav'],[4,'boots/boots_grassdry_01.wav'],
+ [5,'boots/boots_con_jump.wav'],[6,'heavy/heavy_con_01.wav']]) names.set(handle,name);
+requests.length = pending.length = 0;
+await library._wasmfs_create_fetch_backend_js(2);
+const footwear = context.wasmFS$backends[2];
+for (const handle of names.keys()) await footwear.allocFile(handle);
+
+const concrete = footwear.getSize(1);
+await settle();
+pending[0](206);
+assert.equal(await concrete,4);
+timers.shift()();
+await settle();
+assert.deepEqual(requests,['boots_con_01.wav','boots_con_02.wav','boots_dirt_01.wav']);
+pending[1](206); pending[2](206);
+await settle();
+assert.deepEqual(requests,['boots_con_01.wav','boots_con_02.wav','boots_dirt_01.wav',
+ 'boots_grassdry_01.wav','boots_con_jump.wav']);
+pending[3](206); pending[4](206);
+await settle();
+const grass = await footwear.read(4,0,4,0);
+const jump = await footwear.read(5,4,4,0);
+
+assert.equal(grass,4);
+assert.equal(jump,4);
+assert.equal(requests.length,5);
+assert.equal(timers.length,0);
+assert.equal(requests.includes('heavy_con_01.wav'),false);
+console.log('PASS: terrain and action variants reuse footwear prefetch');