Real-time audio & UI4
Both real-time audio (libs/audio) and UI4 scene rendering (libs/fh1data + apps/carview/ui.h) are strictly decoupled from platform I/O, enabling deterministic offline verification (--audio-out, --menu-png) alongside live gameplay.
Lock-Free Real-Time Audio Engine & 4K UI4 Instanced Renderer: Audio Architecture (libs/audio/include/audio/audio_engine.h): - Dedicated 48 kHz stereo RT render thread (480-frame / ~10 ms blocks into ~50 ms ring), zero heap allocations or mutexes in steady state. - Main Thread -> Audio Thread via lock-free TripleBuffer (per-frame engine RPM/load/throttle, listener pose, ToD) and SPSC Command Queue (collisions, landings, UI cues, SatNav/Co-Driver/VO). - Audio Thread -> Main Thread via TripleBuffer (meters, radio popup, backfire counter) and Retire Queue so swapped player destructors run on Main Thread. - Background Async Decoders decode FSB4/XMA2 (in-process), 62 AMB_*.fev beds, 429 ui4audio samples, and 702 VO samples off-thread. - DSP features: XML engine/harmonic synthesis + 100-250 Hz low-mid punch DSP, FEV1 envelopes (Lowpass/Tremolo/Flange/SpeakerLevel/Compressor), 39 mix snapshots across 21 categories, 12-slot exhaust burble/backfire pools, 615-pair surface collisions, 3D AMB_Quads (64 m emitter hash, Doppler, tunnels), 3 disc radio stations via dr_mp3 + Custom Radio. - Synchronous AudioEngine::render_offline() drives --audio-out WAV captures and headless tests. Anark UI4 & 4K Atlas (apps/carview/ui.h, libs/fh1data/include/fh1data/ui_scene.h): - Parses retail .bgf/.bsg/.fbf scenes (SUPER_STACKER, 9-slice BigPane01, dual-texture masks) and 11 vector fonts (A, B, C, D, E, SYM, DG1..DG5) + CJK bitmaps. - 4096x4096 (or 2048x2048) RGBA8 GPU-only patch atlas partitioned into 3 horizontal bands: - Rows 0..1023: VFont glyph cache (up to 192 px buckets, prewarmed HUD ASCII, active-frame eviction guard). - Rows 1024..2047: Persistent HUD & UI4 chrome textures. - Rows 2048..4095: LRU-evicted transient artwork (thumbnails, tickets, logos). - Single-pass instanced GPU draw of 96-byte ui::Instance (kRoundRect, kLine, kArc, kGlyph using pre-baked 512x512 R8_UNORM StrokeSdfAtlas, kImage, kImageMasked), with identical CPU rasterizer for headless --menu-png tests, uniform multi-aspect scaling, and inverse hit-testing.
Subsystem highlights#
In-process XMA2 & engine punch DSP
Decodes FSB4/XMA2 banks off-thread (bundled FFmpeg XMA2 decoder, zero CLI dependency), crossfades RPM/load/throttle XML loops, and applies retail-matched 100–250 Hz low-mid punch DSP plus per-car AI/traffic engine players.
FEV1 envelopes, acoustics & radio
Evaluates FEV1 DSP (Lowpass, Tremolo, Flange, SpeakerLevel, Compressor), 39 mix snapshots, 12-slot burble/backfire pools (synced to exhaust flames), 615-pair surface collisions, 3D AMB_Quads (64 m hash, Doppler, tunnels), and all 3 disc radio stations via dr_mp3.
Anark UI4 scenes & 11 vector fonts
Parses .bgf/.bsg/.fbf hierarchies (SUPER_STACKER lists, 9-slice BigPane01, dual-texture masks), all 11 retail vector fonts (A..E, SYM, DG1..DG5), CJK bitmap fonts, and a pre-baked 512×512 stroke SDF atlas.
4K atlas bands & multi-aspect hit-testing
Dedicated glyph rows (0..1023, up to 192 px buckets with active-frame eviction guard) prevent thumbnail streaming from ever blurring menu text. Scales uniformly across 4:3, 16:10, 16:9, ultrawide, and portrait with exact inverse hit-testing.
Offline inspection flags#
Render any audio mix or UI4 screen headlessly without opening a window:
# Offline 48 kHz stereo WAV capture (same DSP graph as live audio thread)
carview --play <dir> --headless --audio-out out.wav --audio-mix --seconds 5
# Offline UI4 menu, HUD, map, career, and screen captures
carview --play <dir> --menu-png menu.png
carview --play <dir> --map-png map.png --career-png career.png