summaryrefslogtreecommitdiff
path: root/anim/src/map.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-11 13:22:07 -0300
committerGabriel Schneider <[email protected]>2026-11-11 13:26:44 -0300
commit2f27fbe0aa2da0f85d599c1e5f3ac14d025f590c (patch)
tree140a291011e453888ed87b7a43d75f538abb9fae /anim/src/map.zig
parent576a78b4de02c4c6566c327d85c465554d293975 (diff)
downloadcomputeranim-2f27fbe0aa2da0f85d599c1e5f3ac14d025f590c.tar.gz
computeranim-2f27fbe0aa2da0f85d599c1e5f3ac14d025f590c.zip
canim: the graph of a function's blocks
From the user. A blocks lens draws a function's basic blocks as boxes with their offsets and visit counts, loops in their lanes with the turn count, the path's last edges gold, the pc's block gold, and the disassembly as its view; leave and turn carry the mark along an edge, with the compare's flags framed for the edge chosen. On the map the graph takes the disassembly's place with its rows. The layout is a pure function, tested on sort, reverse and libc's open (twelve blocks the run never reached fold into six boxes). The sort scene walks one trip of its inner loop block by block and sprints the middle on the map. Every scene's linear rows carry a rule and a count at each block's head. The stack's panel no longer reads registers from the file on every draw: a frame is 20 ms where it was 57. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/src/map.zig')
-rw-r--r--anim/src/map.zig59
1 files changed, 48 insertions, 11 deletions
diff --git a/anim/src/map.zig b/anim/src/map.zig
index c870d60..108bafd 100644
--- a/anim/src/map.zig
+++ b/anim/src/map.zig
@@ -96,7 +96,7 @@ pub fn row(panel: Panel, key: u64, u: ui.Ui, r: Rect) void {
/// 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) Split {
+pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split {
const st = theme.map.stage;
const c = theme.map.columns;
const w = theme.map.column;
@@ -136,6 +136,25 @@ pub fn split(rec: *const Recording, lens: bool, way: [2]u64) 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.line_count, 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,
@@ -322,6 +341,10 @@ 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,
const Part = struct { ctx: *const anyopaque, draw: *const fn (*const anyopaque, *sk.Frame, anim.Placed) void };
@@ -340,7 +363,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.stage.first = split(rec, true, if (m.cursor) |c| .{ c.first, c.last } else .{ 0, 0 }, m.graph);
m.add(s, component);
}
@@ -371,7 +394,8 @@ pub const Map = struct {
/// `surface`: the dive backwards, a little quicker; then the map is
/// still before anything plays on it.
pub fn surface(m: *const Map, s: *anim.Frame) void {
- s.play(.{m.t.to(diving.land)}, .{ .seconds = 0 });
+ // A scene that did not open on it has not shown it yet: under the panels until it rises.
+ s.play(.{ m.t.to(diving.land), m.obj.fadeIn() }, .{ .seconds = 0 });
s.play(.{m.t.to(0)}, .{ .seconds = @as(f32, diving.surface) / 60.0, .ease = anim.ease.linear });
s.wait(@as(f32, diving.still) / 60.0);
}
@@ -414,7 +438,9 @@ pub const Map = struct {
const y = std.math.lerp(from.y, box.y, p);
// The tags, rules and lanes come in as the map lands.
const chrome = std.math.clamp((t - diving.lift) / 12, 0, 1);
- context.zoomed[i] = .{ .box = box, .to = .{ .x = x, .y = y, .w = box.w * scale, .h = box.h * scale }, .chrome = chrome };
+ // 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 };
};
}
}
@@ -505,7 +531,7 @@ pub const Map = struct {
ui.strokes = mini;
counts = @splat(0);
for (m.parts[0..m.n]) |p| p.draw(p.ctx, f, at);
- if (m.cursor) |c| m.thread(f, at, c.now(at), mini);
+ if (m.cursor) |c| if (!m.graph) m.thread(f, at, c.now(at), mini);
ui.mapping = false;
ui.strokes = false;
}
@@ -559,13 +585,17 @@ pub const Map = struct {
/// The top and bottom of the map's rows of panel `i` with keys from `keys[0]` to `keys[1]`, in canvas pixels.
fn spanOf(i: usize, keys: [2]u64) ?[2]f32 {
- var top: f32 = std.math.inf(f32);
- var bottom: f32 = -std.math.inf(f32);
+ const r = boxOf(i, keys) orelse return null;
+ return .{ r[1], r[3] };
+ }
+
+ /// The box round the map's rows of panel `i` with keys from `keys[0]` to `keys[1]`, in canvas pixels.
+ fn boxOf(i: usize, keys: [2]u64) ?[4]f32 {
+ var r: [4]f32 = .{ std.math.inf(f32), std.math.inf(f32), -std.math.inf(f32), -std.math.inf(f32) };
for (rows[i][0..counts[i]]) |rw| if (rw.key >= keys[0] and rw.key <= keys[1]) {
- top = @min(top, rw.box[1]);
- bottom = @max(bottom, rw.box[3]);
+ r = .{ @min(r[0], rw.box[0]), @min(r[1], rw.box[1]), @max(r[2], rw.box[2]), @max(r[3], rw.box[3]) };
};
- return if (top < bottom) .{ top, bottom } else null;
+ return if (r[1] < r[3]) r else null;
}
/// Where the map's row of key `key` in `panel` is this frame, in canvas pixels.
@@ -585,7 +615,8 @@ pub const Map = struct {
inline for (.{ "band", "view", "source", "disasm", "registers", "stack", "backtrace" }) |name| {
const panel = @field(Panel, name);
const i = @intFromEnum(panel);
- const box = @field(split_, name);
+ // 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);
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 });
@@ -606,6 +637,12 @@ pub const Map = struct {
r[1] = std.math.lerp(snap(from[0], mini), snap(to[0], mini), win.p);
r[3] = std.math.lerp(snap(from[1], mini), snap(to[1], mini), 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(snap(was_box[0], mini), snap(round[0], mini), win.p);
+ r[2] = std.math.lerp(snap(was_box[2], mini), snap(round[2], mini), win.p);
+ };
}
}
// On the minimap on whole pixels (a window's ends already are, at rest).