commit cb3d7e168bd37d37355e057a3fd97ed4836a4fbd
parent d05a2b38fb8892de78d36b957a0690631270212f
Author: anon <anon@example.com>
Date: Sun, 18 Oct 2026 05:47:52 +0000
Fix browser camera input and move playback to an audio worklet
Diffstat:
16 files changed, 629 insertions(+), 93 deletions(-)
diff --git a/README.md b/README.md
@@ -4,8 +4,8 @@
Run commands from the repository root. Compressed runtime data is checked in;
the compiled browser client is kept outside Git. Server development needs Go
-1.24 or newer and a copy of the five matching files in `client/`:
-`index.html`, `game.js`, `game.wasm.gz`, `profile-worker.js`, and `build.json`.
+1.24 or newer and a copy of the six matching files in `client/`:
+`index.html`, `game.js`, `game.wasm.gz`, `profile-worker.js`, `audio-worklet.js`, and `build.json`.
Copy the entire directory from a client build machine, preserving timestamps:
```sh
@@ -26,6 +26,8 @@ randomized Solitus visitor near Bronto Burger in Omni-Entertainment. A persisten
cookie identifies your character on later visits; no account or training is
required. New visitors start in run mode with character tips disabled.
Click the game or press a key to enable sound.
+Two-finger scrolling (or a mouse wheel) rotates the browser camera. Right-button
+drag and Ctrl-drag also work; the game canvas suppresses the browser context menu.
The first server run verifies and unpacks the bundled data.
[Server controls](http://127.0.0.1:8080/control)
provide character editing, teleporting and time controls.
@@ -72,7 +74,7 @@ make wasm -j8
```
This downloads/builds the audio dependencies, compiles the game, and writes the
-five files above to ignored `client/`, where Go serves them. The first build is
+six files above to ignored `client/`, where Go serves them. The first build is
heavy; allow several gigabytes of build space and substantial compilation time.
Copy the complete matching bundle to other machines after validating it. Do not
mix JavaScript and WASM from different builds or commit generated client files.
diff --git a/server/browser_client_test.go b/server/browser_client_test.go
@@ -51,7 +51,7 @@ func TestBrowserClientServesPublishedWasm(t *testing.T) {
}
func TestBrowserClientRevalidatesUnchangedFiles(t *testing.T) {
- for _, name := range []string{"game.js", "game.wasm.gz", "index.html", "profile-worker.js", "build.json"} {
+ for _, name := range []string{"game.js", "game.wasm.gz", "index.html", "profile-worker.js", "audio-worklet.js", "build.json"} {
t.Run(name, func(t *testing.T) {
t.Chdir(t.TempDir())
if err := os.Mkdir("client", 0755); err != nil {
diff --git a/src/Makefile.wasm b/src/Makefile.wasm
@@ -25,12 +25,16 @@ build/wasm/terrain-occlusion.js: tests/terrain_occlusion.c game/bbr.dll/lifted-0
$(CC) $(CPPFLAGS) $(CFLAGS) -DRECOMP_YIELD_EVERY=16 $(filter %.c,$^) -o $@
.PHONY: all objects
-all: build/wasm/web/game.js build/wasm/web/game.wasm build/wasm/web/index.html build/wasm/web/profile-worker.js
+all: build/wasm/web/game.js build/wasm/web/game.wasm build/wasm/web/index.html build/wasm/web/profile-worker.js build/wasm/web/audio-worklet.js
build/wasm/web/profile-worker.js: browser/profile-worker.js
@mkdir -p $(@D)
cp $< $@
+build/wasm/web/audio-worklet.js: browser/audio-worklet.js
+ @mkdir -p $(@D)
+ cp $< $@
+
build/wasm/web/resource-dispatch-test.html: tests/browser_resource_queue.c runtime/browser_host.c
@mkdir -p $(@D)
$(CC) $(CPPFLAGS) $(CFLAGS) $^ -sWASMFS -sPROXY_TO_PTHREAD -sPTHREAD_POOL_SIZE=2 -sALLOW_BLOCKING_ON_MAIN_THREAD=0 -o $@
@@ -83,9 +87,13 @@ build/wasm/web/pacing-test.html: tests/browser_pacing.c runtime/linux_graphics.c
@mkdir -p $(@D)
$(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) --js-library runtime/browser_host.js -sUSE_SDL=2 -sJSPI -sPROXY_TO_PTHREAD -sPTHREAD_POOL_SIZE=2 -sALLOW_BLOCKING_ON_MAIN_THREAD=0 -sALLOW_MEMORY_GROWTH -sOFFSCREENCANVAS_SUPPORT -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -Wl,--wrap=clock_nanosleep -o $@ --js-library runtime/browser_profile.js
-build/wasm/web/audio-output-test.html: tests/browser_audio.html build/wasm/web/audio-output-test.js
+build/wasm/web/audio-output-test.html: tests/browser_audio.html build/wasm/web/audio-output-test.js build/wasm/web/audio-worklet.js
cp $< $@
+build/wasm/web/camera-test.html: tests/browser_camera.c runtime/linux_window.c runtime/guest_heap.c runtime/guest_memory.c runtime/recomp_state.c runtime/browser_host.js Makefile.wasm
+ @mkdir -p $(@D)
+ $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -sUSE_SDL=2 -sPROXY_TO_PTHREAD -sPTHREAD_POOL_SIZE=2 -sALLOW_BLOCKING_ON_MAIN_THREAD=0 -sALLOW_MEMORY_GROWTH --js-library runtime/browser_host.js -o $@
+
build/wasm/web/audio-output-test.js: tests/browser_audio.c runtime/browser_audio.c runtime/browser_audio.h runtime/browser_audio.js Makefile.wasm runtime/browser_profile.c runtime/browser_profile.js
@mkdir -p $(@D)
$(CC) $(CPPFLAGS) $(CFLAGS) -sUSE_SDL=2 $(filter %.c,$^) --js-library runtime/browser_audio.js -sPROXY_TO_PTHREAD -sPTHREAD_POOL_SIZE=2 -sALLOW_BLOCKING_ON_MAIN_THREAD=0 -o $@ --js-library runtime/browser_profile.js
diff --git a/src/browser/audio-worklet.js b/src/browser/audio-worklet.js
@@ -0,0 +1,95 @@
+// One producer (the mixer worker) and one consumer (this audio render thread).
+// Header words: read, write, paused, ready, flush-before, underruns.
+class AOAudioProcessor extends AudioWorkletProcessor {
+ constructor(options) {
+ super();
+ const {buffer, offset, capacity, channels, prefill} = options.processorOptions;
+ this.state = new Int32Array(buffer, offset, 6);
+ this.samples = new Float32Array(buffer, offset + 24, capacity * channels);
+ this.capacity = capacity;
+ this.channels = channels;
+ this.prefill = prefill;
+ this.flush = 0;
+ this.waiting = true;
+ this.closed = false;
+ this.closing = false;
+ this.gain = 0;
+ this.last = new Float32Array(channels);
+ this.start = new Float32Array(channels);
+ this.port.onmessage = () => {
+ this.closing = true;
+ this.closeIfSilent();
+ };
+ Atomics.store(this.state, 3, 1);
+ }
+
+ closeIfSilent() {
+ for (let channel = 0; channel < this.channels; ++channel)
+ if (this.last[channel]) return;
+ this.closed = true;
+ // No further shared-memory access after acknowledging close.
+ this.port.postMessage('closed');
+ }
+
+ process(inputs, outputs) {
+ if (this.closed) return false;
+ const output = outputs[0];
+ if (this.closing) {
+ for (let frame = 0; frame < output[0].length; ++frame) {
+ for (let channel = 0; channel < this.channels; ++channel) {
+ this.last[channel] *= 0.95;
+ if (Math.abs(this.last[channel]) < 1e-6) this.last[channel] = 0;
+ output[channel][frame] = this.last[channel];
+ }
+ }
+ this.closeIfSilent();
+ return !this.closed;
+ }
+ let read = Atomics.load(this.state, 0) >>> 0;
+ const paused = Atomics.load(this.state, 2);
+ const flush = Atomics.load(this.state, 4) >>> 0;
+ const write = Atomics.load(this.state, 1) >>> 0;
+ if (flush !== this.flush) {
+ read = flush;
+ this.flush = flush;
+ this.waiting = true;
+ }
+ let available = (write - read) >>> 0;
+ if (!paused && this.waiting && available >= this.prefill) {
+ this.waiting = false;
+ this.gain = 0;
+ this.start.set(this.last);
+ }
+
+ // Fade at buffer exhaustion and on pause; resume only after replenishing.
+ // The render callback allocates nothing and never waits for another thread.
+ for (let frame = 0; frame < output[0].length; ++frame) {
+ if (!paused && !this.waiting && available) {
+ this.gain = Math.min(1, this.gain + 1 / 128);
+ const index = (read & (this.capacity - 1)) * this.channels;
+ for (let channel = 0; channel < this.channels; ++channel) {
+ this.last[channel] = (this.samples[index + channel] * this.gain +
+ this.start[channel] * (1 - this.gain)) * Math.min(1, available / 128);
+ output[channel][frame] = this.last[channel];
+ }
+ read = (read + 1) >>> 0;
+ --available;
+ } else {
+ for (let channel = 0; channel < this.channels; ++channel) {
+ this.last[channel] *= 0.95;
+ if (Math.abs(this.last[channel]) < 1e-6) this.last[channel] = 0;
+ output[channel][frame] = this.last[channel];
+ }
+ this.gain = 0;
+ if (!paused && !this.waiting) {
+ Atomics.add(this.state, 5, 1);
+ this.waiting = true;
+ }
+ }
+ }
+ Atomics.store(this.state, 0, read);
+ return true;
+ }
+}
+
+registerProcessor('ao-audio', AOAudioProcessor);
diff --git a/src/runtime/browser_audio.c b/src/runtime/browser_audio.c
@@ -2,21 +2,30 @@
#include "browser_audio.h"
#include <assert.h>
#include <pthread.h>
+#include <stdatomic.h>
+#include <stddef.h>
+#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-unsigned ao_audio_open(int rate, int channels, int bits);
-int ao_audio_ready(unsigned handle);
-double ao_audio_submit(unsigned handle, const void *buffer, int frames);
-void ao_audio_clear(unsigned handle);
-void ao_audio_close(unsigned handle);
+/* Shared with audio-worklet.js; only the consumer advances read. */
+struct audio_ring {
+ atomic_uint read, write, paused;
+ atomic_int ready;
+ atomic_uint flush, underruns;
+ float samples[];
+};
+_Static_assert(offsetof(struct audio_ring, samples) == 24, "AudioWorklet header layout");
+enum { AUDIO_RING_FRAMES = 16384 };
+int ao_audio_open(struct audio_ring *ring, int capacity, int channels, int block_size);
+void ao_audio_close(struct audio_ring *ring);
struct audio_output {
SDL_AudioSpec format;
pthread_t thread;
pthread_mutex_t mutex;
pthread_cond_t condition;
- unsigned handle;
+ struct audio_ring *ring;
int paused, closed;
};
@@ -25,10 +34,12 @@ static void *mix_audio(void *argument)
struct audio_output *output = argument;
unsigned char *buffer = malloc(output->format.size);
if (!buffer) abort();
+ unsigned target = output->format.freq / 10;
+ if (target > AUDIO_RING_FRAMES - output->format.samples)
+ target = AUDIO_RING_FRAMES - output->format.samples;
+ unsigned reported_underruns = 0;
for (;;) {
- /* Browser calls can wait for its UI thread, so keep them outside the mixer lock. */
- int ready = ao_audio_ready(output->handle);
- /* Only workers take this lock; the browser receives completed PCM blocks. */
+ /* Only workers take this lock. Playback never proxies through the UI thread. */
if (pthread_mutex_lock(&output->mutex)) abort();
while (output->paused && !output->closed)
if (pthread_cond_wait(&output->condition, &output->mutex)) abort();
@@ -36,13 +47,31 @@ static void *mix_audio(void *argument)
if (pthread_mutex_unlock(&output->mutex)) abort();
break;
}
- double profile_start = ready ? ao_profile_begin("audio mix") : 0;
- if (ready)
- output->format.callback(output->format.userdata, buffer, output->format.size);
+ unsigned write = atomic_load(&output->ring->write);
+ unsigned queued = write - atomic_load(&output->ring->read);
+ if (atomic_load(&output->ring->ready) != 1 || queued >= target) {
+ if (pthread_mutex_unlock(&output->mutex)) abort();
+ usleep(5000);
+ continue;
+ }
+ double profile_start = ao_profile_begin("audio mix");
+ output->format.callback(output->format.userdata, buffer, output->format.size);
+ for (unsigned frame = 0; frame < output->format.samples; ++frame) {
+ unsigned destination = ((write + frame) & (AUDIO_RING_FRAMES - 1)) * output->format.channels;
+ for (unsigned channel = 0; channel < output->format.channels; ++channel) {
+ unsigned index = frame * output->format.channels + channel;
+ output->ring->samples[destination + channel] = output->format.format == AUDIO_U8 ?
+ ((int)buffer[index] - 128) / 128.0f : ((int16_t *)buffer)[index] / 32768.0f;
+ }
+ }
+ atomic_store(&output->ring->write, write + output->format.samples);
if (pthread_mutex_unlock(&output->mutex)) abort();
ao_profile_end("audio mix", profile_start, NULL);
- double delay = ready ? ao_audio_submit(output->handle, buffer, output->format.samples) : 10;
- usleep((unsigned)(delay * 1000));
+ unsigned underruns = atomic_load(&output->ring->underruns);
+ if (underruns != reported_underruns) {
+ fprintf(stderr, "[browser-audio] playback underruns: %u\n", underruns);
+ reported_underruns = underruns;
+ }
}
free(buffer);
return NULL;
@@ -52,14 +81,18 @@ SDL_AudioDeviceID audio_output_open(const SDL_AudioSpec *desired, SDL_AudioSpec
{
assert(desired->format == AUDIO_S16LSB || desired->format == AUDIO_U8);
assert(desired->channels == 1 || desired->channels == 2);
+ assert(desired->samples && desired->samples < AUDIO_RING_FRAMES);
struct audio_output *output = calloc(1, sizeof(*output));
if (!output) abort();
output->format = *desired;
output->format.size = desired->samples * desired->channels * (SDL_AUDIO_BITSIZE(desired->format) / 8);
output->format.silence = desired->format == AUDIO_U8 ? 128 : 0;
output->paused = 1;
+ output->ring = calloc(1, sizeof(*output->ring) + AUDIO_RING_FRAMES * desired->channels * sizeof(float));
+ if (!output->ring) abort();
+ atomic_store(&output->ring->paused, 1);
if (pthread_mutex_init(&output->mutex, NULL) || pthread_cond_init(&output->condition, NULL)) abort();
- output->handle = ao_audio_open(desired->freq, desired->channels, SDL_AUDIO_BITSIZE(desired->format));
+ output->format.freq = ao_audio_open(output->ring, AUDIO_RING_FRAMES, desired->channels, desired->samples);
if (pthread_create(&output->thread, NULL, mix_audio, output)) abort();
*obtained = output->format;
return (uintptr_t)output;
@@ -80,7 +113,8 @@ void audio_output_pause(SDL_AudioDeviceID device, int paused)
struct audio_output *output = (void *)(uintptr_t)device;
audio_output_lock(device);
output->paused = paused;
- if (paused) ao_audio_clear(output->handle);
+ if (paused) atomic_store(&output->ring->flush, atomic_load(&output->ring->write));
+ atomic_store(&output->ring->paused, !!paused);
if (pthread_cond_signal(&output->condition)) abort();
audio_output_unlock(device);
}
@@ -90,10 +124,11 @@ void audio_output_close(SDL_AudioDeviceID device)
struct audio_output *output = (void *)(uintptr_t)device;
audio_output_lock(device);
output->closed = 1;
+ atomic_store(&output->ring->paused, 1);
if (pthread_cond_signal(&output->condition)) abort();
audio_output_unlock(device);
if (pthread_join(output->thread, NULL)) abort();
- ao_audio_close(output->handle);
+ ao_audio_close(output->ring);
if (pthread_cond_destroy(&output->condition) || pthread_mutex_destroy(&output->mutex)) abort();
free(output);
}
diff --git a/src/runtime/browser_audio.js b/src/runtime/browser_audio.js
@@ -1,52 +1,50 @@
addToLibrary({
- $AOAudio: {next: 1, devices: new Map()},
+ $AOAudio: {devices: new Map(), module: null},
ao_audio_open__deps: ['$AOAudio'],
ao_audio_open__proxy: 'sync',
- ao_audio_open: (rate, channels, bits) => {
+ ao_audio_open: (ring, capacity, channels, blockSize) => {
const context = Module['audioContext'] ||= new AudioContext();
- const handle = AOAudio.next++;
- AOAudio.devices.set(handle, {context, rate, channels, bits, nextTime: 0, sources: new Set()});
- return handle;
+ const state = new Int32Array(HEAPU8.buffer, ring, 6);
+ const device = {state, node: null, failed: false};
+ AOAudio.devices.set(ring, device);
+ AOAudio.module ||= context.audioWorklet.addModule('/wasm/audio-worklet.js');
+ device.ready = AOAudio.module.then(() => {
+ device.node = new AudioWorkletNode(context, 'ao-audio', {
+ numberOfInputs: 0, numberOfOutputs: 1, outputChannelCount: [channels],
+ processorOptions: {buffer: HEAPU8.buffer, offset: ring, capacity, channels,
+ prefill: Math.min(Math.floor(context.sampleRate / 10), capacity - blockSize)}
+ });
+ device.node.onprocessorerror = () => {
+ device.failed = true;
+ Atomics.store(state, 3, -1);
+ console.error('AO audio processor stopped');
+ };
+ device.node.connect(context.destination);
+ }).catch(error => {
+ device.failed = true;
+ Atomics.store(state, 3, -1);
+ console.error('AO audio initialization failed:', error);
+ });
+ return context.sampleRate;
},
- ao_audio_ready__deps: ['$AOAudio'],
- ao_audio_ready__proxy: 'sync',
- ao_audio_ready: (handle) => AOAudio.devices.get(handle).context.state === 'running',
- ao_audio_submit__deps: ['$AOAudio'],
- ao_audio_submit__proxy: 'sync',
- ao_audio_submit: (handle, data, frames) => {
- const output = AOAudio.devices.get(handle);
- const buffer = output.context.createBuffer(output.channels, frames, output.rate);
- for (let channel = 0; channel < output.channels; ++channel) {
- const samples = buffer.getChannelData(channel);
- for (let frame = 0; frame < frames; ++frame) {
- const index = frame * output.channels + channel;
- samples[frame] = output.bits === 16 ? HEAP16[(data >> 1) + index] / 32768 :
- (HEAPU8[data + index] - 128) / 128;
+ ao_audio_close__deps: ['$AOAudio', 'free'],
+ ao_audio_close__proxy: 'async',
+ ao_audio_close: (ring) => {
+ const device = AOAudio.devices.get(ring);
+ AOAudio.devices.delete(ring);
+ device.ready.then(() => {
+ if (device.failed) {
+ device.node?.disconnect();
+ _free(ring);
+ return;
}
- }
- const source = output.context.createBufferSource();
- source.buffer = buffer;
- source.connect(output.context.destination);
- output.sources.add(source);
- source.onended = () => { output.sources.delete(source); source.disconnect(); };
- // Keep a short queue ahead of the playback clock without blocking the UI thread.
- const start = Math.max(output.nextTime, output.context.currentTime + .01);
- source.start(start);
- output.nextTime = start + frames / output.rate;
- return Math.max(1, (output.nextTime - output.context.currentTime - .03) * 1000);
- },
- ao_audio_clear__deps: ['$AOAudio'],
- ao_audio_clear__proxy: 'sync',
- ao_audio_clear: (handle) => {
- const output = AOAudio.devices.get(handle);
- for (const source of output.sources) { source.stop(); source.disconnect(); }
- output.sources.clear();
- output.nextTime = 0;
- },
- ao_audio_close__deps: ['$AOAudio', 'ao_audio_clear'],
- ao_audio_close__proxy: 'sync',
- ao_audio_close: (handle) => {
- _ao_audio_clear(handle);
- AOAudio.devices.delete(handle);
+ // Keep the ring alive until the render thread acknowledges shutdown.
+ device.node.port.onmessage = () => {
+ device.node.disconnect();
+ device.node.port.close();
+ _free(ring);
+ };
+ device.node.port.postMessage('close');
+ });
}
});
diff --git a/src/runtime/browser_host.js b/src/runtime/browser_host.js
@@ -46,6 +46,7 @@ addToLibrary({
ao_asset_base_url: () => {
// SDL's browser backend has no CaptureMouse; use canvas pointer capture.
const canvas = Module.canvas;
+ canvas.addEventListener('contextmenu', event => event.preventDefault());
canvas.addEventListener('pointerdown', event => {
if (!event.isPrimary) return;
Module.aoMousePointer = event.pointerId;
diff --git a/src/runtime/linux_window.c b/src/runtime/linux_window.c
@@ -39,6 +39,13 @@ static int quit_pending;
static uint32_t quit_code;
static uint8_t keyboard_state[256];
static uint32_t queued_mouse_buttons;
+#ifdef __EMSCRIPTEN__
+/* Browsers cannot warp the physical pointer; camera recentering is virtual. */
+static int cursor_x, cursor_y, cursor_warped, control_drag;
+static int wheel_drag;
+static uint32_t wheel_deadline;
+static float wheel_x, wheel_y;
+#endif
/* The SDL default cursor has a guest handle; native pointers never enter guest state. */
static uint32_t current_cursor = 0xf4500000u;
static void destroy_window(void);
@@ -758,11 +765,35 @@ static void cursor_position(void)
if (!output) { MEM32(g_fs_base + 0x34) = 998; return; }
if (!linux_graphics_window()) { MEM32(g_fs_base + 0x34) = 8; return; }
int x, y;
+#ifdef __EMSCRIPTEN__
+ if (!cursor_warped) SDL_GetMouseState(&cursor_x, &cursor_y);
+ if (cursor_warped) {
+ int dx = (int)wheel_x, dy = (int)wheel_y;
+ wheel_x -= dx; wheel_y -= dy;
+ cursor_x += dx; cursor_y += dy;
+ }
+ x = cursor_x; y = cursor_y;
+#else
SDL_GetGlobalMouseState(&x, &y);
+#endif
MEM32(output) = x; MEM32(output + 4) = y;
g_eax = 1;
}
+static void set_cursor_position(void)
+{
+ int x = MEM32(g_esp + 4), y = MEM32(g_esp + 8);
+ g_esp += 12;
+#ifdef __EMSCRIPTEN__
+ cursor_x = x; cursor_y = y;
+ cursor_warped = 1;
+ g_eax = 1;
+#else
+ g_eax = SDL_WarpMouseGlobal(x, y) == 0;
+ if (!g_eax) MEM32(g_fs_base + 0x34) = 87;
+#endif
+}
+
static void set_cursor(void)
{
uint32_t cursor = MEM32(g_esp + 4);
@@ -924,6 +955,18 @@ static uint32_t virtual_key(SDL_Keycode key, unsigned *scan)
return 0;
}
+#ifdef __EMSCRIPTEN__
+static void end_wheel_drag(void)
+{
+ if (!wheel_drag) return;
+ wheel_drag = 0;
+ wheel_x = wheel_y = 0;
+ queued_mouse_buttons &= ~2u;
+ queue_message(client.handle, 0x205, queued_mouse_buttons,
+ (cursor_x & 0xffffu) | ((uint32_t)cursor_y << 16), 2, 0);
+}
+#endif
+
static void process_event(const SDL_Event *event)
{
if (!client.handle) return;
@@ -943,6 +986,16 @@ static void process_event(const SDL_Event *event)
}
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
+#ifdef __EMSCRIPTEN__
+ end_wheel_drag();
+ static const uint32_t releases[][2] = {{1, 0x202}, {2, 0x205}, {16, 0x208}};
+ for (unsigned i = 0; i < 3; ++i) {
+ if (!(queued_mouse_buttons & releases[i][0])) continue;
+ queued_mouse_buttons &= ~releases[i][0];
+ queue_message(client.handle, releases[i][1], queued_mouse_buttons, 0, 2, 0);
+ }
+ control_drag = cursor_warped = 0;
+#endif
if (client.capture) change_capture(0);
if (client.active) {
client.active = 0;
@@ -973,6 +1026,16 @@ static void process_event(const SDL_Event *event)
uint32_t state = (event->motion.state & SDL_BUTTON_LMASK ? 1 : 0) |
(event->motion.state & SDL_BUTTON_RMASK ? 2 : 0) |
(event->motion.state & SDL_BUTTON_MMASK ? 16 : 0);
+#ifdef __EMSCRIPTEN__
+ /* Include virtual gestures and keep lost-focus buttons released. */
+ state = queued_mouse_buttons;
+ if (!wheel_drag) {
+ if (cursor_warped && (state & 2)) {
+ cursor_x += event->motion.xrel;
+ cursor_y += event->motion.yrel;
+ } else cursor_warped = 0;
+ }
+#endif
queued_mouse_buttons = state;
SDL_Keymod modifiers = SDL_GetModState();
state |= modifiers & KMOD_SHIFT ? 4 : 0;
@@ -981,6 +1044,15 @@ static void process_event(const SDL_Event *event)
(event->motion.x & 0xffffu) | ((uint32_t)event->motion.y << 16), 2, 0);
} else if (event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP) {
uint32_t button = event->button.button, message, mask;
+#ifdef __EMSCRIPTEN__
+ end_wheel_drag();
+ if (button == SDL_BUTTON_LEFT) {
+ if (event->type == SDL_MOUSEBUTTONDOWN)
+ control_drag = !!(SDL_GetModState() & KMOD_CTRL);
+ if (control_drag) button = SDL_BUTTON_RIGHT;
+ if (event->type == SDL_MOUSEBUTTONUP) control_drag = 0;
+ }
+#endif
if (button == SDL_BUTTON_LEFT) { message = 0x201; mask = 1; }
else if (button == SDL_BUTTON_RIGHT) { message = 0x204; mask = 2; }
else if (button == SDL_BUTTON_MIDDLE) { message = 0x207; mask = 16; }
@@ -994,6 +1066,21 @@ static void process_event(const SDL_Event *event)
queue_message(client.handle, message + up, state,
(event->button.x & 0xffffu) | ((uint32_t)event->button.y << 16), 2, 0);
} else if (event->type == SDL_MOUSEWHEEL) {
+#ifdef __EMSCRIPTEN__
+ /* SDL converts pixel wheel deltas to steps; restore pixels for the camera. */
+ if (!wheel_drag && !(queued_mouse_buttons & 2)) {
+ wheel_drag = 1;
+ cursor_warped = 0;
+ queued_mouse_buttons |= 2;
+ SDL_GetMouseState(&cursor_x, &cursor_y);
+ queue_message(client.handle, 0x204, queued_mouse_buttons,
+ (cursor_x & 0xffffu) | ((uint32_t)cursor_y << 16), 2, 0);
+ }
+ float direction = event->wheel.direction == SDL_MOUSEWHEEL_FLIPPED ? -100 : 100;
+ wheel_x += event->wheel.preciseX * direction;
+ wheel_y -= event->wheel.preciseY * direction;
+ wheel_deadline = SDL_GetTicks() + 200;
+#else
int x, y;
SDL_GetGlobalMouseState(&x, &y);
int delta = event->wheel.y * 120;
@@ -1002,6 +1089,7 @@ static void process_event(const SDL_Event *event)
(SDL_GetModState() & KMOD_CTRL ? 8 : 0);
queue_message(client.handle, 0x20a, ((uint32_t)delta << 16) | state,
(x & 0xffffu) | ((uint32_t)y << 16), 2, 0);
+#endif
}
}
@@ -1066,6 +1154,9 @@ static void retrieve_message(int wait)
for (;;) {
SDL_Event event;
while (SDL_PollEvent(&event)) process_event(&event);
+#ifdef __EMSCRIPTEN__
+ if (wheel_drag && SDL_TICKS_PASSED(SDL_GetTicks(), wheel_deadline)) end_wheel_drag();
+#endif
if (read_message(output, window, first, last, flags & 1)) {
g_eax = !wait || MEM32(output + 4) != 0x12;
return;
@@ -1206,6 +1297,7 @@ recomp_func_t linux_window_lookup(const char *dll, const char *name)
if (!strcmp(name, "GetWindowRect")) return window_rect;
if (!strcmp(name, "ClientToScreen")) return client_to_screen;
if (!strcmp(name, "GetCursorPos")) return cursor_position;
+ if (!strcmp(name, "SetCursorPos")) return set_cursor_position;
if (!strcmp(name, "SetCursor")) return set_cursor;
if (!strcmp(name, "SetCapture")) return set_capture;
if (!strcmp(name, "GetCapture")) return get_capture;
diff --git a/src/tests/audio.c b/src/tests/audio.c
@@ -228,7 +228,9 @@ static void driver_lifetime(uint32_t scratch)
uint32_t latency = call("_AIL_digital_latency@4", 1, &driver);
assert(latency > 0 && latency < 1000);
assert(call("_AIL_digital_latency@4", 1, &driver) == latency);
-#ifndef _WIN32
+#ifdef __EMSCRIPTEN__
+ assert(latency == 11);
+#elif !defined(_WIN32)
assert(latency == (i & 1 ? 11 : 23));
#endif
uint32_t volume[] = {driver, i & 1 ? 127 : 0};
@@ -507,6 +509,8 @@ static void retained_music_driver(uint32_t scratch)
assert(!nonzero_samples);
linux_audio_enable_music(driver, generation);
+ /* Restart the short clip so this check does not depend on output queue depth. */
+ call("_AIL_start_stream@4", 1, &stream);
for (unsigned i = 0; call("_AIL_stream_status@4", 1, &stream) == 4 && i < 1000; ++i) SDL_Delay(1);
assert(nonzero_samples > 0 && !bad_samples);
capture = 0;
diff --git a/src/tests/browser_audio.c b/src/tests/browser_audio.c
@@ -36,16 +36,18 @@ int main(void)
desired.userdata = &desired;
atomic_store(&callbacks, 0);
SDL_AudioDeviceID device = audio_output_open(&desired, &obtained);
- assert(obtained.freq == 44100 && obtained.channels == desired.channels);
+ assert(obtained.freq == MAIN_THREAD_EM_ASM_INT({ return Module.audioContext.sampleRate; }));
+ assert(obtained.channels == desired.channels);
assert(obtained.format == desired.format && obtained.samples == 512);
audio_output_pause(device, 0);
- for (unsigned attempt = 0; attempt < 500 && atomic_load(&callbacks) < 8; ++attempt) usleep(10000);
+ for (unsigned attempt = 0; attempt < 500 && atomic_load(&callbacks) < 32; ++attempt) usleep(10000);
+ assert(MAIN_THREAD_EM_ASM_INT({ return Module.verifyPlaybackWithStall(); }));
audio_output_lock(device);
unsigned locked_count = atomic_load(&callbacks);
usleep(50000);
- assert(locked_count >= 8 && atomic_load(&callbacks) == locked_count);
+ assert(locked_count >= 32 && atomic_load(&callbacks) == locked_count);
audio_output_unlock(device);
audio_output_pause(device, 1);
unsigned paused_count = atomic_load(&callbacks);
@@ -59,6 +61,9 @@ int main(void)
usleep(50000);
assert(atomic_load(&callbacks) == closed_count);
}
- assert(MAIN_THREAD_EM_ASM_INT({ return Module['checkedBuffers'] >= 18; }));
- puts("PASS: worker audio mixing, PCM channel conversion, playback scheduling, locking, pause/resume and close");
+ for (unsigned attempt = 0; attempt < 500 &&
+ !MAIN_THREAD_EM_ASM_INT({ return Module.outputs.every(output => output.closed); }); ++attempt)
+ usleep(10000);
+ assert(MAIN_THREAD_EM_ASM_INT({ return Module.outputs.length === 2 && Module.outputs.every(output => output.closed); }));
+ puts("PASS: worker mixing, PCM conversion, uninterrupted playback during UI stalls, locking, pause/resume and acknowledged close");
}
diff --git a/src/tests/browser_audio.html b/src/tests/browser_audio.html
@@ -5,7 +5,7 @@
<pre id="output"></pre>
<script>
var Module = {
- checkedBuffers: 0,
+ outputs: [],
print: message => { document.querySelector('#output').textContent += message + '\n'; },
printErr: message => { document.querySelector('#output').textContent += message + '\n'; }
};
@@ -13,23 +13,34 @@
event.target.disabled = true;
Module.audioContext = new AudioContext();
Module.audioContext.resume();
- const createSource = Module.audioContext.createBufferSource.bind(Module.audioContext);
- Module.audioContext.createBufferSource = () => {
- const source = createSource(), start = source.start.bind(source);
- source.start = time => {
- if (Module.audioContext.state !== 'running' || time < Module.audioContext.currentTime)
- throw new Error('Audio was not scheduled on a running playback clock');
- for (let channel = 0; channel < source.buffer.numberOfChannels; ++channel) {
- const samples = source.buffer.getChannelData(channel);
- for (let frame = 0; frame < samples.length; ++frame) {
- const expected = (frame % 128 < 64 ? 1 : -1) * (channel ? -1 : 1) / 32;
- if (samples[frame] !== expected) throw new Error('Incorrect PCM sample or channel');
- }
+ const WorkletNode = AudioWorkletNode;
+ window.AudioWorkletNode = class extends WorkletNode {
+ constructor(context, name, options) {
+ super(context, name, options);
+ const output = {...options.processorOptions, closed: false};
+ Module.outputs.push(output);
+ this.port.addEventListener('message', event => { if (event.data === 'closed') output.closed = true; });
+ this.port.start();
+ }
+ };
+ Module.verifyPlaybackWithStall = () => {
+ const output = Module.outputs.at(-1);
+ const state = new Int32Array(output.buffer, output.offset, 6);
+ const samples = new Float32Array(output.buffer, output.offset + 24, output.capacity * output.channels);
+ const before = Atomics.load(state, 0) >>> 0, write = Atomics.load(state, 1) >>> 0;
+ for (let frame = before; frame < write; ++frame) {
+ for (let channel = 0; channel < output.channels; ++channel) {
+ const expected = (frame % 128 < 64 ? 1 : -1) * (channel ? -1 : 1) / 32;
+ if (samples[(frame % output.capacity) * output.channels + channel] !== expected)
+ throw new Error('Incorrect PCM sample or channel');
}
- ++Module.checkedBuffers;
- start(time);
- };
- return source;
+ }
+ const underruns = Atomics.load(state, 5), deadline = performance.now() + 500;
+ while (performance.now() < deadline) { /* Deliberately stall only the UI thread. */ }
+ const consumed = ((Atomics.load(state, 0) >>> 0) - before) >>> 0;
+ const remainingUnderruns = Atomics.load(state, 5);
+ Module.print(`UI stall: consumed ${consumed} frames, underruns ${underruns} -> ${remainingUnderruns}`);
+ return consumed > Module.audioContext.sampleRate * .35 && remainingUnderruns === underruns;
};
const script = document.createElement('script');
script.src = 'audio-output-test.js';
diff --git a/src/tests/browser_audio_worklet.mjs b/src/tests/browser_audio_worklet.mjs
@@ -0,0 +1,113 @@
+import assert from 'node:assert/strict';
+import fs from 'node:fs';
+import vm from 'node:vm';
+
+let Processor;
+vm.runInNewContext(fs.readFileSync(new URL('../browser/audio-worklet.js', import.meta.url), 'utf8'), {
+ AudioWorkletProcessor: class { port = {postMessage: message => { this.closedMessage = message; }}; },
+ registerProcessor: (name, constructor) => { assert.equal(name, 'ao-audio'); Processor = constructor; }
+});
+
+function stream(channels = 2) {
+ const buffer = new SharedArrayBuffer(24 + 2048 * channels * 4);
+ return {
+ state: new Int32Array(buffer, 0, 6),
+ samples: new Float32Array(buffer, 24),
+ processor: new Processor({processorOptions: {buffer, offset: 0, capacity: 2048, channels, prefill: 512}})
+ };
+}
+
+function render(processor) {
+ const output = Array.from({length: processor.channels}, () => new Float32Array(128));
+ assert.equal(processor.process([], [output]), true);
+ return output;
+}
+
+function stereoSamplesRemainContinuousAcrossRingWrap() {
+ const {state, samples, processor} = stream();
+ for (let frame = 0; frame < 2048; ++frame) {
+ samples[frame * 2] = .25;
+ samples[frame * 2 + 1] = -.5;
+ }
+ state[0] = 0xffffff00;
+ state[1] = 512;
+
+ render(processor);
+ render(processor);
+ const output = render(processor);
+
+ assert.equal(state[0], 128);
+ assert.equal(state[5], 0);
+ assert.deepEqual([...output[0]], Array(128).fill(.25));
+ assert.deepEqual([...output[1]], Array(128).fill(-.5));
+}
+
+function starvationFadesAndWaitsForRefill() {
+ const {state, samples, processor} = stream(1);
+ samples.fill(.5);
+ state[1] = 512;
+ let previous = 0, largestStep = 0;
+
+ for (let block = 0; block < 8; ++block) {
+ for (const value of render(processor)[0]) {
+ largestStep = Math.max(largestStep, Math.abs(value - previous));
+ previous = value;
+ }
+ }
+ state[1] = 768;
+ render(processor);
+
+ assert.equal(state[0], 512);
+ assert.equal(state[5], 1);
+ assert(largestStep <= 1 / 256);
+ state[1] = 1024;
+ const resumed = render(processor)[0];
+ assert.equal(state[0], 640);
+ assert.equal(resumed[0], 1 / 256);
+ assert.equal(resumed[127], .5);
+}
+
+function pauseDiscardsOldAudioAndCloseStopsMemoryAccess() {
+ const {state, samples, processor} = stream(1);
+ samples.fill(.5);
+ state[1] = 512;
+ render(processor);
+
+ state[4] = 512;
+ state[2] = 1;
+ const paused = render(processor)[0];
+ processor.port.onmessage({data: 'close'});
+ const closedRead = state[0];
+ for (let block = 0; block < 4; ++block) processor.process([], [[new Float32Array(128)]]);
+ const keepAlive = processor.process([], [[new Float32Array(128)]]);
+
+ assert.equal(state[0], 512);
+ assert.equal(state[5], 0);
+ assert(paused[0] < .5 && paused[0] > .45);
+ assert(paused[127] < .001);
+ assert.equal(processor.closedMessage, 'closed');
+ assert.equal(keepAlive, false);
+ assert.equal(state[0], closedRead);
+}
+
+function immediateResumeCrossfadesToNewSamples() {
+ const {state, samples, processor} = stream(1);
+ samples.fill(.5);
+ state[1] = 512;
+ render(processor);
+ samples.fill(-.5, 512, 1024);
+
+ state[4] = 512;
+ state[1] = 1024;
+ const output = render(processor)[0];
+
+ assert.equal(output[0], .5 - 1 / 128);
+ assert.equal(output[127], -.5);
+ assert.equal(state[5], 0);
+}
+
+stereoSamplesRemainContinuousAcrossRingWrap();
+starvationFadesAndWaitsForRefill();
+pauseDiscardsOldAudioAndCloseStopsMemoryAccess();
+immediateResumeCrossfadesToNewSamples();
+console.log('PASS: audio continuity, counter/ring wrap, underrun fade/refill, pause flushing and acknowledged close');
diff --git a/src/tests/browser_camera.c b/src/tests/browser_camera.c
@@ -0,0 +1,156 @@
+#include "linux_window.h"
+#include "linux_graphics.h"
+#include "guest_memory.h"
+#include <SDL2/SDL.h>
+#include <assert.h>
+#include <stdio.h>
+#include <unistd.h>
+
+static SDL_Window *native_window;
+static uint32_t window;
+struct SDL_Window *linux_graphics_window(void) { return native_window; }
+int linux_graphics_display_mode(SDL_DisplayMode *mode) { return SDL_GetCurrentDisplayMode(0, mode); }
+recomp_func_t recomp_lookup(uint32_t address)
+{
+ assert(address == 0x11110000);
+ return linux_window_lookup("user32.dll", "DefWindowProcA");
+}
+recomp_func_t recomp_lookup_import(uint32_t address) { return recomp_lookup(address); }
+
+static uint32_t call(const char *name, unsigned count, const uint32_t *arguments)
+{
+ uint32_t stack = g_esp;
+ for (unsigned i = count; i; --i) PUSH32(g_esp, arguments[i - 1]);
+ PUSH32(g_esp, RECOMP_RETADDR);
+ recomp_func_t function = linux_window_lookup("user32.dll", name);
+ assert(function);
+ function();
+ assert(g_esp == stack);
+ return g_eax;
+}
+
+static uint32_t mouse_message(void)
+{
+ uint32_t peek[] = {0x50003000, window, 0x200, 0x20a, 1};
+ if (!call("PeekMessageA", 5, peek)) return 0;
+ return MEM32(0x50003004);
+}
+
+static void recentering_preserves_relative_motion(void)
+{
+ SDL_Event event = {.type = SDL_MOUSEBUTTONDOWN};
+ event.button.button = SDL_BUTTON_RIGHT;
+ assert(SDL_PushEvent(&event) == 1);
+ assert(mouse_message() == 0x204);
+ assert(call("SetCursorPos", 2, (uint32_t[]){320, 240}));
+ event = (SDL_Event){.type = SDL_MOUSEMOTION};
+ event.motion.state = SDL_BUTTON_RMASK;
+ event.motion.x = 40; event.motion.y = 50;
+ event.motion.xrel = 7; event.motion.yrel = -3;
+
+ assert(SDL_PushEvent(&event) == 1);
+ assert(mouse_message() == 0x200);
+ uint32_t output = 0x50003100;
+ assert(call("GetCursorPos", 1, &output));
+
+ assert(MEM32(output) == 327 && MEM32(output + 4) == 237);
+ assert(call("SetCursorPos", 2, (uint32_t[]){320, 240}));
+ assert(call("GetCursorPos", 1, &output));
+ assert(MEM32(output) == 320 && MEM32(output + 4) == 240);
+ event = (SDL_Event){.type = SDL_MOUSEBUTTONUP};
+ event.button.button = SDL_BUTTON_RIGHT;
+ assert(SDL_PushEvent(&event) == 1);
+ assert(mouse_message() == 0x205);
+ assert(!(MEM32(0x50003008) & 2));
+}
+
+static void control_drag_releases_after_modifier_release(void)
+{
+ SDL_SetModState(KMOD_CTRL);
+ SDL_Event event = {.type = SDL_MOUSEBUTTONDOWN};
+ event.button.button = SDL_BUTTON_LEFT;
+ assert(SDL_PushEvent(&event) == 1);
+ assert(mouse_message() == 0x204);
+
+ SDL_SetModState(KMOD_NONE);
+ event.type = SDL_MOUSEBUTTONUP;
+ assert(SDL_PushEvent(&event) == 1);
+
+ assert(mouse_message() == 0x205);
+ assert(!MEM32(0x50003008));
+ assert(!mouse_message());
+}
+
+static void wheel_rotation_keeps_fractional_motion_and_ends(void)
+{
+ SDL_Event event = {.type = SDL_MOUSEWHEEL};
+ event.wheel.preciseX = 0.125f;
+ event.wheel.preciseY = -0.0625f;
+ assert(SDL_PushEvent(&event) == 1);
+ assert(mouse_message() == 0x204);
+ /* The game saves the physical position before its first camera recenter. */
+ uint32_t output = 0x50003100;
+ assert(call("GetCursorPos", 1, &output));
+ assert(call("SetCursorPos", 2, (uint32_t[]){320, 240}));
+
+ assert(call("GetCursorPos", 1, &output));
+
+ assert(MEM32(output) == 332 && MEM32(output + 4) == 246);
+ assert(call("SetCursorPos", 2, (uint32_t[]){320, 240}));
+ assert(SDL_PushEvent(&event) == 1);
+ assert(!mouse_message());
+ assert(call("GetCursorPos", 1, &output));
+ assert(MEM32(output) == 333 && MEM32(output + 4) == 246);
+ usleep(250000);
+ assert(mouse_message() == 0x205);
+ assert(!MEM32(0x50003008));
+ assert(!mouse_message());
+}
+
+static void focus_loss_releases_camera_button(void)
+{
+ SDL_Event event = {.type = SDL_MOUSEWHEEL};
+ event.wheel.preciseX = 0.5f;
+ assert(SDL_PushEvent(&event) == 1);
+ assert(mouse_message() == 0x204);
+
+ event = (SDL_Event){.type = SDL_WINDOWEVENT};
+ event.window.windowID = SDL_GetWindowID(native_window);
+ event.window.event = SDL_WINDOWEVENT_FOCUS_LOST;
+ assert(SDL_PushEvent(&event) == 1);
+
+ assert(mouse_message() == 0x205);
+ assert(!MEM32(0x50003008));
+ assert(!mouse_message());
+ event = (SDL_Event){.type = SDL_MOUSEMOTION};
+ event.motion.state = SDL_BUTTON_RMASK;
+ assert(SDL_PushEvent(&event) == 1);
+ assert(mouse_message() == 0x200);
+ assert(!MEM32(0x50003008));
+}
+
+int main(void)
+{
+ assert(guest_map("camera test", 0x50000000, 0x10000));
+ g_esp = 0x5000ff00; g_fs_base = 0x50004000;
+ assert(!SDL_Init(SDL_INIT_VIDEO));
+ native_window = SDL_CreateWindow("Camera test", 0, 0, 640, 480, SDL_WINDOW_HIDDEN);
+ assert(native_window);
+ uint32_t record = 0x50002000, text = 0x50002100;
+ MEM32(record + 4) = 0x11110000;
+ MEM32(record + 16) = 1;
+ MEM32(record + 36) = text;
+ strcpy((void *)ADDR(text), "Camera test");
+ uint32_t atom = call("RegisterClassA", 1, &record);
+ assert(atom);
+ uint32_t arguments[] = {0, atom, text, 0, 0, 0, 640, 480, 0, 0, 1, 0};
+ window = call("CreateWindowExA", 12, arguments);
+ assert(window);
+ SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
+ recentering_preserves_relative_motion();
+ control_drag_releases_after_modifier_release();
+ wheel_rotation_keeps_fractional_motion_and_ends();
+ focus_loss_releases_camera_button();
+ puts("camera: recentering, Ctrl-drag, fractional wheel motion, timeout and focus loss passed");
+ return 0;
+}
diff --git a/src/tests/browser_mixer.html b/src/tests/browser_mixer.html
@@ -10,7 +10,8 @@
};
document.querySelector('#start').onclick = async event => {
event.target.disabled = true;
- Module.audioContext = new AudioContext();
+ // Sample-count fixtures use 44.1 kHz; output negotiation is tested separately.
+ Module.audioContext = new AudioContext({sampleRate: 44100});
await Module.audioContext.resume();
const script = document.createElement('script');
script.src = 'mixer-test.js';
diff --git a/src/tests/window.c b/src/tests/window.c
@@ -560,6 +560,20 @@ static void cursor_query_writes_a_guest_point(void)
assert(!call("GetCursorPos", 1, &null) && error() == 998);
}
+static void cursor_warp_updates_screen_coordinates(void)
+{
+ uint32_t output = workspace() + 256;
+ assert(call("GetCursorPos", 1, &output));
+ uint32_t original[] = {memory(output)[0], memory(output)[1]};
+ uint32_t target[] = {123, 97};
+
+ assert(call("SetCursorPos", 2, target));
+ assert(call("GetCursorPos", 1, &output));
+
+ assert(memory(output)[0] == 123 && memory(output)[1] == 97);
+ assert(call("SetCursorPos", 2, original));
+}
+
static void null_cursor_hides_and_previous_cursor_can_be_restored(void)
{
uint32_t null = 0;
@@ -923,6 +937,7 @@ int main(void)
ascii_translation_uses_supplied_keyboard_state();
desktop_context_reports_native_pixel_storage();
cursor_query_writes_a_guest_point();
+ cursor_warp_updates_screen_coordinates();
null_cursor_hides_and_previous_cursor_can_be_restored();
modifier_queries_combine_left_and_right_keys();
#ifndef _WIN32
diff --git a/tools/client/publish_wasm.py b/tools/client/publish_wasm.py
@@ -15,7 +15,7 @@ staging = root / 'src/build/wasm/publish'
staging.mkdir(exist_ok=True)
# Publish one matching JS/WASM pair, compressed for transfer to browsers and laptops.
-for name in ['game.js', 'index.html', 'profile-worker.js']:
+for name in ['game.js', 'index.html', 'profile-worker.js', 'audio-worklet.js']:
shutil.copyfile(source / name, staging / name)
with (source / 'game.wasm').open('rb') as input_file:
with (staging / 'game.wasm.gz').open('wb') as output_file:
@@ -39,7 +39,7 @@ metadata = {
]).decode().splitlines()[0],
'files': {},
}
-for name in ['game.js', 'game.wasm.gz', 'index.html', 'profile-worker.js']:
+for name in ['game.js', 'game.wasm.gz', 'index.html', 'profile-worker.js', 'audio-worklet.js']:
path = staging / name
metadata['files'][name] = {
'bytes': path.stat().st_size,