mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
Audio ran on the main thread and rebuilt the graph every frame: an AudioBuffer and a one-shot AudioBufferSourceNode per frame, roughly 18k nodes and 80MB of garbage per ten minutes of play. A single AudioWorkletNode now drains a ring buffer on the audio thread, so playback survives a stalled main thread. The route gets no COOP/COEP, so samples cross by transfer rather than through a SharedArrayBuffer, and the worklet hands each buffer straight back for the player to refill: 231 posts and 231 recycles over a four-second cart, so steady-state playback allocates nothing. The runtime fills a caller-owned buffer instead of returning a fresh slice, which drops the last copy. Frame pacing moves to pico8Pacer, and audio scheduling to pico8Audio, so the two pieces most likely to be wrong are unit-testable without a component. Both had no coverage while the wasm bindings did; they now have 19 tests between them, including the catch-up cap and the buffer recycling. useGamepad keeps the knowledge about raw pad state, so export isUsablePad, PAD_BUTTON and AXIS_THRESHOLD rather than restating them here. The button index map is now keyed by name, with the event-detail lookup derived from it. Vite inlines assets under 4KB as data: URIs, which addModule cannot be relied on to accept, so the worklet is pinned to a real file. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>