From b54c6776953d3243ab5b8e676e747713827ab320 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 11 Nov 2026 17:42:07 -0300 Subject: canim: the disassembly under the source everywhere; rings From the user. In every split the disassembly stays under the source; registers a scene never changes fold three to a row, and the stack takes the room: nine to twenty slots where it had six. The graph's first form is rings: a loop a ring its blocks sit on, an inner loop a smaller ring touching its parent, a way out leaving along the tangent; layers stay for functions without loops. Its layout comes from the code alone and it shows nothing from after the moment: a block not reached yet is quiet and is reached, a fold of what is not reached yet opens when the run arrives. A pane unrolls from its strip into its whole column and rolls back. The sqlite scene's strips move before their panes. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa --- anim/src/map.zig | 219 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 170 insertions(+), 49 deletions(-) (limited to 'anim/src/map.zig') diff --git a/anim/src/map.zig b/anim/src/map.zig index ee1d2a1..eaec991 100644 --- a/anim/src/map.zig +++ b/anim/src/map.zig @@ -119,7 +119,7 @@ pub fn content(w: f32) f32 { /// lens's view, the registers, and in the rest the stack going on /// (`continued`), in the third; the stack in the fourth, whole. // shortcut: a column's rest after the disassembly is page: the 5-row dumps round what the registers point at, the open loupes and the key are not built. -pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split { +pub fn split(rec: *const Recording, band_h: f32, way: [2]u64) Split { const st = theme.map.stage; const c = theme.map.columns; const w = theme.map.column; @@ -132,7 +132,9 @@ pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split return @floatFromInt(if (n > 0) n else default); } }.of; - const band: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = if (lens) theme.layout.split.subject.band.h else 0 }; + // The drawing as high as the working frame's. + const band: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = band_h }; + const lens = band_h > 0; const source_y = if (lens) band.y + band.h + gap else st.y; // The backtrace as long as the call chain gets over the scene's way: packed once, never repacked under the eye. const bt_rows = @max(want(.backtrace, 0), deepest(rec, way)); @@ -159,25 +161,6 @@ pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split return .{ .x = r.x, .y = y, .w = r.w, .h = @max(bottom - y, 0) }; } }.under; - // The disassembly as its graph (`graph.Map`): two columns wide beside the - // source, the drawing it is (no band); the registers over the stack in the last. - if (graph) { - const regs: Rect = .{ .x = c[3], .y = st.y, .w = w, .h = panelH(17) }; - const nothing: Rect = .{ .x = c[3], .y = st.y, .w = w, .h = 0 }; - const src: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = panelH(@floatFromInt(@min(rec.most_lines, theme.layout.rowsIn(foot - st.y - gap - panelH(bt_rows))))) }; - const bt: Rect = .{ .x = c[0], .y = src.y + src.h + gap, .w = w, .h = @min(panelH(bt_rows), foot - (src.y + src.h + gap)) }; - return .{ - .band = .{ .x = c[0], .y = st.y, .w = w, .h = 0 }, - .view = nothing, - .source = src, - .disasm = .{ .x = c[1], .y = st.y, .w = c[2] + w - c[1], .h = st.h }, - .registers = regs, - .stack = rest(regs, foot), - .backtrace = bt, - .dump_rows = theme.map.memory_rows, - .spare = .{ rest(bt, foot), .{ .x = c[1], .y = foot, .w = w, .h = 0 } }, - }; - } return .{ .band = band, .view = view, @@ -200,7 +183,8 @@ fn deepest(rec: *const Recording, way: [2]u64) f32 { var seen: ?@TypeOf(rec.depths[0]) = null; var i = way[0]; while (i <= @min(way[1], rec.end())) : (i += 1) { - if (seen != null and rec.depths[i] <= seen.?) continue; + // A recording that counts its calls is read where it goes deeper; one of breakpoints (no calls counted: sqlite's) at every stop. + if (seen != null and rec.depths[i] <= seen.? and rec.len() > 512) continue; seen = rec.depths[i]; var buf: [24]context.Frame = undefined; most = @max(most, context.frames(rec, i, &buf).len); @@ -362,13 +346,34 @@ pub const Map = struct { cursor: ?@import("cursor.zig").Cursor = null, /// The scene's loupes: open, each is a panel of its own on the map (`Spare`). loupes: [2]?*const @import("loupe.zig").Loupe = .{ null, null }, - /// The disassembly is its graph (`graph.Map`): the thread is its digits, - /// no line crosses the lanes; the band's window is the whole graph; the - /// disassembly's, the rows it shows. - graph: bool = false, - /// With `graph`: the stage of the linear disassembly the strip is a - /// column of (the map draws the graph, which is its own whole). - linear: ?*Stage = null, + /// The scene's `unroll`s, each a pane's column out of its strip for a beat (`Unroll` draws them). + unrolls: [4]Unrolled = undefined, + n_unrolls: usize = 0, + + const Unrolled = struct { panel: Panel, veil: anim.Value, grow: anim.Value }; + + /// `unroll`: the pane `panel`'s whole column out of its strip over the + /// frame, for a beat ("the whole function", "the whole stack"): the + /// panes it covers veiled and its strip's window bright (18 f), then the + /// column growing (36 f, `glide`), its window's outline riding from the + /// strip to the pane's rows in it; held until `roll`. + pub fn unroll(m: *Map, s: *anim.Frame, panel: Panel) void { + const u: Unrolled = .{ .panel = panel, .veil = s.value(0), .grow = s.value(0) }; + m.unrolls[m.n_unrolls] = u; + m.n_unrolls += 1; + const t = theme.time.unroll; + s.play(.{u.veil.to(1)}, .{ .seconds = t.veil, .ease = anim.ease.linear }); + s.play(.{u.grow.to(1)}, .{ .seconds = t.grow, .ease = anim.ease.linear }); + } + + /// `roll`: the last `unroll` back into its strip (36 f), the window's + /// outline landing as the strip's window; the veil lifts (18 f). + pub fn roll(m: *Map, s: *anim.Frame) void { + const u = m.unrolls[m.n_unrolls - 1]; + const t = theme.time.unroll; + s.play(.{u.grow.to(0)}, .{ .seconds = t.roll, .ease = anim.ease.linear }); + s.play(.{u.veil.to(0)}, .{ .seconds = t.veil, .ease = anim.ease.linear }); + } /// Which drawings a part is in: the map's, the strips' (what they are /// drawn from: a pane's column, as the linear disassembly the map draws @@ -397,7 +402,7 @@ pub const Map = struct { /// Puts a drawing on the map, in a band of its own over the source, /// for a scene whose working frame has none (its map is split anew). pub fn drawing(m: *Map, s: *anim.Frame, rec: *const Recording, component: anytype) void { - m.stage.first = split(rec, true, if (m.cursor) |c| .{ c.first, c.last } else .{ 0, 0 }, m.graph); + m.stage.first = split(rec, theme.layout.split.subject.band.h, if (m.cursor) |c| .{ c.first, c.last } else .{ 0, 0 }); m.add(s, component); } @@ -485,9 +490,8 @@ pub const Map = struct { const y = std.math.lerp(from.y, box.y, p); // The tags, rules and lanes, and the strips, come in as the map lands. const chrome = std.math.clamp((t - diving.lift) / 12, 0, 1); - // Out of a graph the rows and the lens are another form of what the map shows there: they come in on their way. - const other = m.graph and (i == @intFromEnum(Panel.disasm) or i == @intFromEnum(Panel.band)); - context.zoomed[i] = .{ .box = box, .to = .{ .x = x, .y = y, .w = box.w * scale, .h = box.h * scale }, .chrome = chrome, .shows = if (other) p else 1 }; + // The registers arrive whole from the map and fold as they land: each quiet row glides into its cell. + context.zoomed[i] = .{ .box = box, .to = .{ .x = x, .y = y, .w = box.w * scale, .h = box.h * scale }, .chrome = chrome, .fold = if (i == @intFromEnum(Panel.registers)) p else 1 }; }; } // Each pane's column squeezing into its strip: their places on the map give way first, then they go. @@ -496,8 +500,7 @@ pub const Map = struct { inline else => |tag| @field(working, @tagName(tag)), }; const gone = 1 - stripShows(panel, t); - // The graph's linear column is not on the map: its strip comes in with the tags. - if (box.h > 0 and gone > 0 and windows[@intFromEnum(panel)] != null and !(m.graph and panel == .disasm)) m.squeeze(f, fixed, at, panel, box, ways[@intFromEnum(panel)], .{ .masking = masking, .shows = gone, .veil = veil, .bright = bright }); + if (box.h > 0 and gone > 0 and windows[@intFromEnum(panel)] != null) m.squeeze(f, fixed, at, panel, box, ways[@intFromEnum(panel)], .{ .masking = masking, .shows = gone, .veil = veil, .bright = bright }); }; } @@ -620,7 +623,7 @@ pub const Map = struct { ui.mapping = true; counts = @splat(0); for (m.parts[0..m.n]) |p| if (p.in != .strips) p.draw(p.ctx, f, at); - if (m.cursor) |c| if (!m.graph) m.thread(f, at, c.now(at)); + if (m.cursor) |c| m.thread(f, at, c.now(at)); ui.mapping = false; } @@ -671,8 +674,7 @@ pub const Map = struct { inline for (.{ "band", "view", "source", "disasm", "registers", "stack", "backtrace" }) |name| { const panel = @field(Panel, name); const i = @intFromEnum(panel); - // The lens drawing the graph is: its window is the graph whole. - const box = if (m.graph and panel == .band) split_.disasm else @field(split_, name); + const box = @field(split_, name); if (box.h > 0) { const a = at.xf.apply(.{ box.x, box.y }); const b = at.xf.apply(.{ box.x + box.w, box.y + box.h }); @@ -687,16 +689,10 @@ pub const Map = struct { r[1] = std.math.lerp(from[0], to[0], win.p); r[3] = std.math.lerp(from[1], to[1], win.p); shown = true; - // In a graph the rows a window shows are in blocks: round them, not the panel's width. - if (m.graph and panel == .disasm) if (boxOf(i, win.now)) |round| { - const was_box = boxOf(i, win.was) orelse round; - r[0] = std.math.lerp(was_box[0], round[0], win.p); - r[2] = std.math.lerp(was_box[2], round[2], win.p); - }; } } window_px[i] = if (shown) r else null; - const rides = riding and slotOf(panel) != null and !(m.graph and panel == .disasm); + const rides = riding and slotOf(panel) != null; if (shown and !rides) { const w = theme.map.outline * k; const out = theme.map.outline_out * k; @@ -714,7 +710,7 @@ pub const Map = struct { const none: Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }; return switch (panel) { .source => .{ sp.source, sp.source_more }, - .disasm => .{ if (m.linear) |l| l.now(at).disasm else sp.disasm, none }, + .disasm => .{ sp.disasm, none }, .stack => .{ sp.stack, sp.more }, .view => .{ sp.view, none }, else => .{ none, none }, @@ -949,6 +945,127 @@ pub const Map = struct { } }; +/// A pane's far jump in its own column at a walk, this frame (the pane +/// publishes it as it draws; `Unroll` draws it and clears it): how far +/// the column has grown out of its strip (0 to 1, before its `glide`) and +/// how far the panes it covers are veiled. +pub var jumping: ?struct { panel: Panel, grow: f32, veil: f32 } = null; + +/// `unroll` and `roll` drawn (design/README.md, "6. Verbs"; motion.md, +/// "The map and the working frame"): the column grows out of the strip +/// over the pane and the panes under it, a row of the map's 4 units +/// scaling on its logarithm to as many as the stage holds (24 a row where +/// the column is short enough to read, to fit where it is long), right on +/// the strip's right edge, the pane's window in it level with the pane's +/// rows where the stage allows; the window's outline rides from the strip +/// to its rows in the column. Added last (`Context.ties`): it lies over +/// everything in the frame but the caption and the clock. +pub const Unroll = struct { + map: *const Map, + + pub fn draw(un: *const Unroll, f: *sk.Frame, placed: anim.Placed) void { + const m = un.map; + defer jumping = null; + if (ui.mapping or looking(f) or !m.settled(placed)) return; + var panel: Panel = .source; + var grow: f32 = 0; + var veil: f32 = 0; + for (m.unrolls[0..m.n_unrolls]) |u| { + const v = placed.value(u.veil); + if (v <= 0) continue; + panel = u.panel; + grow = placed.value(u.grow); + veil = v; + } + if (jumping) |j| { + panel = j.panel; + grow = j.grow; + veil = j.veil; + } + if (veil <= 0) return; + const fixed = @import("words.zig").fixed(f, placed, 0); + fixed.veil(theme.canvas.stage, veil); + m.strips(f, fixed.at); + const slot = slotOf(panel) orelse return; + const col = &atlas.columns[slot]; + if (col.n == 0 or col.rows <= 0) return; + const working = m.frame.now(placed); + const box = switch (panel) { + inline else => |tag| @field(working, @tagName(tag)), + }; + // The strip's window goes bright over the veil's first third (6 f), never in a frame. + unrolled(m, f, fixed, panel, box, col, theme.ease(.glide, grow), std.math.clamp(veil * 3, 0, 1)); + } +}; + +/// A pane's column `q` of its way (eased) from its strip to unrolled, in +/// `fixed` (the canvas's units). +fn unrolled(m: *const Map, f: *sk.Frame, fixed: ui.Ui, panel: Panel, box: Rect, col: *const Column, q: f32, bright: f32) void { + const st = theme.strip; + const cm = theme.metric.context; + const stage = theme.canvas.stage; + const r = stripRect(box); + const cap = @floor((r.h - st.top - st.foot) / st.pitch); + const win = windowOn(panel, col) orelse .{ 0, 0 }; + const first = firstShown(col, win, cap); + // Unrolled: as many rows as the stage holds, 24 a row at most. + const a = @min(cm.row, stage.h / col.rows); + const k1 = a / cm.row; + const h1 = col.rows * a; + const w1 = theme.map.column * k1; + const pane_mid = box.y + cm.tag + cm.pad + @as(f32, @floatFromInt(theme.layout.rowsIn(box.h))) * cm.row / 2; + const y1 = std.math.clamp(pane_mid - (win[0] + win[1] + 1) / 2 * a, stage.y, @max(stage.y + stage.h - h1, stage.y)); + const x1 = @max(r.x + r.w - w1, stage.x); + // Its scale on the logarithm, from the strip's (36 of 880 across, 4 of 24 a row) to the unrolled. + const kx = std.math.pow(f32, st.across, 1 - q) * std.math.pow(f32, k1, q); + const ky = std.math.pow(f32, @as(f32, st.pitch) / cm.row, 1 - q) * std.math.pow(f32, k1, q); + // The window rides: its first row from its place on the strip to its place in the column. + const wy = std.math.lerp(r.y + st.top + (win[0] - first) * st.pitch, y1 + win[0] * a, q); + const oy = wy - win[0] * cm.row * ky; + const ox = std.math.lerp(r.x + st.left, x1, q); + // What shows: the strip's rows at first, the column whole at last. + const top = std.math.lerp(r.y + st.top, y1, q); + const bottom = std.math.lerp(r.y + st.top + @min(cap, col.rows - first) * st.pitch, y1 + h1, q); + const left = std.math.lerp(r.x, x1, q); + const right = std.math.lerp(r.x + r.w, x1 + w1, q); + // Over the strip as it grows out of it, and gone into it as it lands: the strip's own drawing crossfades under it. + const lifts = std.math.clamp(q * 8, 0, 1); + if (q > 0) fixed.faded(lifts).fill(.{ .x = left - 4, .y = top - 4, .w = right - left + 8, .h = bottom - top + 8 }, theme.color.page); + var offset: f32 = 0; + for (m.column(fixed.at, panel)) |b| { + if (q <= 0) break; + if (b.h <= 0) continue; + const n: f32 = @floatFromInt(theme.layout.rowsIn(b.h)); + defer offset += n; + const body = b.y + cm.tag + cm.pad; + // The rows of this box inside what shows, in rows from the column's top. + const lo = std.math.clamp((top - oy) / (cm.row * ky), offset, offset + n); + const hi = std.math.clamp((bottom - oy) / (cm.row * ky), offset, offset + n); + if (hi <= lo) continue; + var moved = fixed.at; + moved.xf = fixed.at.xf.mul(.translate(ox, oy)).mul(.scale(kx, ky)).mul(.translate(-b.x, -(body - offset * cm.row))); + moved.scale = fixed.at.scale * ky; + // The text comes in over the strip's strokes as it starts to grow. + moved.pose.opacity *= lifts; + const u: ui.Ui = .{ .f = f, .at = moved }; + // Its parts clip to their own boxes inside this one's rows (`ui.bound`). + const rows_rect: Rect = .{ .x = b.x, .y = body + (lo - offset) * cm.row, .w = b.w, .h = (hi - lo) * cm.row }; + const a0 = moved.xf.apply(.{ rows_rect.x, rows_rect.y }); + const a1 = moved.xf.apply(.{ rows_rect.x + rows_rect.w, rows_rect.y + rows_rect.h }); + ui.bound = .{ .x = @round(a0[0]), .y = @round(a0[1]), .w = @round(a1[0]) - @round(a0[0]), .h = @round(a1[1]) - @round(a0[1]) }; + u.clip(rows_rect); + m.drawPanel(f, moved, panel); + ui.bound = null; + u.unclip(); + } + // The window's outline, the strip's framed bright as it begins (and as it ends), riding to round the pane's rows in the column. + const wt = oy + win[0] * cm.row * ky; + const wb = oy + (win[1] + 1) * cm.row * ky; + // On the strip it is the strip's window's own frame (primary, `bright` of the way to bright). + const ink = ui.mix(theme.color.text.primary, theme.color.text.bright, bright); + fixed.frame(.{ .x = std.math.lerp(r.x, left - st.window, q), .y = wt - st.window, .w = std.math.lerp(st.w, right - left + 2 * st.window, q), .h = wb - wt + st.window + std.math.lerp(1, st.window, q) }, ink, st.window); +} + /// The most rows a column has in the strips' images. const atlas_rows = 160; @@ -1004,9 +1121,13 @@ fn pastWindows(now: u64, back: u64) [7]?Window { /// was and where it is, as far as its scroll had gone. fn spanOf2(maybe: ?Window, col: *const Column) ?[2]f32 { const win = maybe orelse return null; - const is = col.span(win.now) orelse return null; - const was = col.span(win.was) orelse is; - return .{ std.math.lerp(was[0], is[0], win.p), std.math.lerp(was[1], is[1], win.p) }; + // A window going farther than the column holds (another place in a long + // file, another function) is where the column is: where it was until the + // column goes over with the pane, then where it is. + const was = col.span(win.was); + const is = col.span(win.now) orelse return was; + const from = was orelse is; + return .{ std.math.lerp(from[0], is[0], win.p), std.math.lerp(from[1], is[1], win.p) }; } /// The map whose columns the strips are (`context` sets it). -- cgit v1.3