perf: unblock long-file loading; add collision detection and jump nav

Three things, all surfaced while working a multi-node protocol issue on a
5.7-hour capture.

**Loading was frame-paced, not compute-bound.** The STFT overview advanced
a fixed 200 segments per frame, so the frame limiter — not the FFT — set
the pace: 478k segments at ACTIVE_FPS meant over a minute spent waiting
between frames rather than computing. The tell was absurd: backgrounding
the window, which skips presenting entirely, loaded the same file in
seconds. The progress bar was slower precisely because you were watching
it. The overview is now computed in one blocking call after presenting the
loading panel, so focused load matches the unfocused speed. The panel says
the window will stop responding and drops the percentage, which could not
animate and would have read as a hang. ACTIVE_FPS 30 -> 60 while here;
idle still parks at ~0% CPU through the event-wait path.

Background work also no longer stops when the window loses focus. Pending
work now counts as "active" regardless of focus, so the loop doesn't block
in PollInputEvents waiting for input that isn't coming, and an unfocused
frame with work outstanding skips the draw pass entirely rather than
throttling the high-res fill to the refresh rate.

**Collision detection.** Annotations that overlap in both time and
frequency are flagged, merged into contiguous regions, and drawn as red
bands confined to the band the overlap occupies (padded, so a narrow
overlap stays findable) rather than spanning the full axis and hiding the
signal being pointed at. N / Shift+N and sidebar buttons jump between
regions, centring each without disturbing the current zoom.

Point markers are excluded: control events and assertions have no band and
zero duration, and treating a missing band as "whole spectrum" — which is
how they are *drawn* — made every marker collide with whatever it sat
inside. That was 38% of the reported collisions on a real capture. Only
things that actually occupy the air can interfere. Counts verified against
an independent reference implementation on two captures.

**Scope waveform via min/max summary.** The envelope rescanned every
visible sample every frame — ~245M reads, near 1 GB of memory traffic, on
a multi-hour file, measured at ~60 ms/frame for a few hundred pixel
columns. It now draws from 1024-sample buckets built once at load (60 ms,
1.9 MB), measured at ~0.07 ms/frame. Keeping both extremes per bucket
means single-sample transients still show at full zoom-out, which plain
decimation would drop; verified that no column ever understates a true
peak. Zoomed in past a bucket it falls back to raw samples, which is cheap
there by definition.

Also fixes ComputeCollisions never running for files opened through the
file browser, and moves the collision panel above the annotations dropdown
where it isn't pushed off the bottom of the sidebar.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V8ZWfr5XZyyDttvkhJUgHN
This commit is contained in:
2026-08-12 13:58:58 -07:00
parent 8026d10547
commit 4c3c6a955a
8 changed files with 656 additions and 135 deletions
+40
View File
@@ -127,6 +127,7 @@ static void LoadSelectedFile(void)
} else if (FileExists(filePath) && LoadWavFile(filePath, &app.signal)) {
ResetForNewSignal();
LoadMlnlFromWav(filePath, &app.annotations);
ComputeCollisions();
app.showFileBrowser = false;
TraceLog(LOG_INFO, "Loaded: %s", filePath);
}
@@ -505,6 +506,45 @@ void DrawSidebar(void)
annExp.x + 9 * scale, annExp.y + 5 * scale, 13, WHITE);
y += 28 * scale;
// Collision overlay toggle + summary. Only meaningful once something
// actually overlaps, so the row is hidden when nothing does.
if (app.collisionCount > 0) {
Rectangle colBtn = { x, y, sidebarWidth - 10 * scale, 24 * scale };
if (Clicked(colBtn)) app.showCollisions = !app.showCollisions;
DrawPanelBox(colBtn,
app.showCollisions ? (Color){ 90, 35, 35, 255 } : (Color){ 50, 50, 60, 255 },
app.showCollisions ? (Color){ 255, 120, 120, 255 } : GRAY);
DrawTextScaled(app.showCollisions ? "Collisions: ON" : "Collisions: off",
colBtn.x + 10 * scale, colBtn.y + 5 * scale, 13, WHITE);
y += 26 * scale;
DrawTextScaled(TextFormat("%d events in %d regions",
app.collisionCount, app.collisionRegionCount),
x + 8 * scale, y, 11, (Color){ 255, 150, 150, 255 });
y += 16 * scale;
// Prev/next jump. Mirrors the N / Shift+N bindings; having both
// means the feature is findable without reading the help overlay.
float half = (sidebarWidth - 14 * scale) * 0.5f;
Rectangle prevBtn = { x, y, half, 22 * scale };
Rectangle nextBtn = { x + half + 4 * scale, y, half, 22 * scale };
if (Clicked(prevBtn)) app.jumpCollisionRequest = -1;
if (Clicked(nextBtn)) app.jumpCollisionRequest = 1;
DrawPanelBox(prevBtn, (Color){ 55, 40, 40, 255 }, GRAY);
DrawPanelBox(nextBtn, (Color){ 55, 40, 40, 255 }, GRAY);
DrawTextScaled("< prev", prevBtn.x + 8 * scale, prevBtn.y + 4 * scale, 12, LIGHTGRAY);
DrawTextScaled("next >", nextBtn.x + 8 * scale, nextBtn.y + 4 * scale, 12, LIGHTGRAY);
y += 26 * scale;
if (app.currentCollision >= 0) {
DrawTextScaled(TextFormat("at %d/%d", app.currentCollision + 1,
app.collisionRegionCount),
x + 8 * scale, y, 11, GRAY);
y += 16 * scale;
}
}
if (app.annotationsExpanded) {
// Two opacity sliders: the spectrogram overlay is drawn at the
// "Base" alpha by default, and bumps to "Highlight" for any event