summaryrefslogtreecommitdiff
path: root/anim/src/ties.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 18:06:30 -0300
committerGabriel Schneider <[email protected]>2026-11-10 19:01:23 -0300
commite63b0624f57472d40af32a006c32cc47d403b822 (patch)
treeb7295da62acd96bc7aba425720eed95605526693 /anim/src/ties.zig
parent318e16181a28725e218121363555580725d6d0d4 (diff)
downloadcomputeranim-e63b0624f57472d40af32a006c32cc47d403b822.tar.gz
computeranim-e63b0624f57472d40af32a006c32cc47d403b822.zip
canim: what the review found; the band as two panels; list and sort by instruction
The first videos were reviewed frame by frame and the catalogue changed with them. A lens is a drawing over the program column and its view over the state column, so the stack keeps six slots, its window on the whole frame. Operands are whole. list and sort are recorded by instruction from main (record --from), so their registers strike, links reach nodes and cells, rows that ran are marked and jumps are drawn. A call's node is a projection of its return address; pins travel and keep their side; a mark covers the bytes that changed, at the element's width; a syscall's result is stored after the kernel returns it and every panel is of one moment; fast passes are veiled; the clock stands still during a step; captions get their reading time and a scene's first step comes by four seconds. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'anim/src/ties.zig')
-rw-r--r--anim/src/ties.zig119
1 files changed, 106 insertions, 13 deletions
diff --git a/anim/src/ties.zig b/anim/src/ties.zig
index d18b996..3968d23 100644
--- a/anim/src/ties.zig
+++ b/anim/src/ties.zig
@@ -73,6 +73,11 @@ pub const Place = union(enum) {
}
};
+/// The stack's window this frame: its first word, how many it shows, and
+/// where its pin lane runs (canvas pixels: x, the first row's top, the
+/// row's height). A link to a word outside it ends at its edge.
+pub var stack_window: ?struct { first: u64, slots: usize, x: f32, top: f32, row: f32 } = null;
+
/// What this frame's components have said so far, in canvas pixels: left, top, right, bottom.
/// shortcut: one table for the process, emptied by `Ties.draw`; a scene with two players at once wants it on the frame.
var table: [512]struct { key: u64, box: [4]f32 } = undefined;
@@ -128,6 +133,24 @@ pub fn pinShows(now: cursors.Now, i: usize, target: enum { slot, node }) struct
};
}
+/// `establish` for a lens: its element `k` (in address order), `r`
+/// seconds into its elements' coming in: each fades in rising 8 units
+/// over 12 f, 2 f after the one before (all begun by 12 f after the
+/// first), with its row's quiet bracket beside it; no lines. How much of
+/// it shows, and how far below its place it is.
+pub fn rise(r: f32, k: usize, n: usize) struct { element: f32, below: f32 } {
+ const apart = @min(time.stagger, time.quick / @as(f32, @floatFromInt(@max(n, 2) - 1)));
+ const p = std.math.clamp((r - @as(f32, @floatFromInt(k)) * apart) / time.quick, 0, 1);
+ const eased = theme.ease(.enter, p);
+ return .{ .element = p, .below = (1 - eased) * time.caption_rise };
+}
+
+/// How long `n` elements take to come in.
+pub fn riseTime(n: usize) f32 {
+ const apart = @min(time.stagger, time.quick / @as(f32, @floatFromInt(@max(n, 2) - 1)));
+ return @as(f32, @floatFromInt(n -| 1)) * apart + time.quick;
+}
+
pub const Ties = struct {
cursor: cursors.Cursor,
stage: *const Stage,
@@ -139,6 +162,7 @@ pub const Ties = struct {
pub fn draw(g: *const Ties, f: *sk.Frame, at: anim.Placed) void {
defer said = 0;
+ defer stack_window = null;
const now = g.cursor.now(at);
// In canvas pixels, `k` of them a unit: places come from panels anywhere.
var raw: ui.Ui = .{ .f = f, .at = at };
@@ -182,7 +206,20 @@ pub const Ties = struct {
const value = regs.named(name) orelse continue;
const from = find(.{ .register = i }) orelse continue;
const node = find(.{ .node_pin = value });
- const target = node orelse find(.{ .slot_pin = value }) orelse continue;
+ // A word of the stack outside its window: the link ends at the
+ // window's edge, with a stub and how many words on it is.
+ var beyond: ?i64 = null;
+ const target = node orelse find(.{ .slot_pin = value }) orelse edge: {
+ const w = stack_window orelse continue;
+ if (value % 8 != 0 or rows.regionOf(now.moment(), value) != .stack) continue;
+ const words = @as(i64, @bitCast(value -% w.first)) >> 3;
+ if (words >= 0 and words < w.slots) continue;
+ if (@abs(words) > 64) continue;
+ beyond = if (words < 0) words else words - @as(i64, @intCast(w.slots)) + 1;
+ // Its nearest row's pin lane.
+ const y = if (words < 0) w.top else w.top + @as(f32, @floatFromInt(w.slots - 1)) * w.row;
+ break :edge [4]f32{ w.x, y, w.x + 10 * k, y + w.row };
+ };
const since = now.since(.cpu, strikeDelay(now, i));
const l = time.link;
const drawn = cursors.standard(std.math.clamp((since - l.after) / linkTime(if (node != null) .node else .slot), 0, 1));
@@ -190,7 +227,9 @@ pub const Ties = struct {
if (drawn <= 0 or back >= 1) return;
const color = rows.ink(rows.regionOf(now.moment(), value));
const y = (from[1] + from[3]) / 2;
- const lane = at.xf.apply(.{ theme.metric.tie.link_lane, 0 })[0];
+ // What climbs into the band takes the gutter's left lane; what
+ // goes down to a slot, the right.
+ const lane = at.xf.apply(.{ if (node != null) theme.metric.tie.link_lane else theme.metric.tie.projection_lane, 0 })[0];
var points: [5]ui.Vec = undefined;
var n: usize = 0;
points[0] = .{ edge[0] + 2 * k, y };
@@ -203,6 +242,15 @@ pub const Ties = struct {
points[3] = .{ cx, bottom };
points[4] = .{ cx, pin[1] };
n = 5;
+ } else if (beyond) |words| {
+ // Off the window: to its nearest row, into the pin lane, out
+ // to the panel's rule, where a head points on.
+ const mid = (target[1] + target[3]) / 2;
+ const rule = if (words < 0) target[1] - 6 * k else target[3] + 6 * k;
+ points[2] = .{ lane, mid };
+ points[3] = .{ target[0] + 6 * k, mid };
+ points[4] = .{ target[0] + 6 * k, rule };
+ n = 5;
} else {
// Along the gutter to the slot's row, and into its pin lane.
const mid = (target[1] + target[3]) / 2;
@@ -210,7 +258,18 @@ pub const Ties = struct {
points[3] = .{ target[0] - 2 * k, mid };
n = 4;
}
- raw.route(points[0..n], color, .{ .width = theme.stroke.tie.link * k, .head = .{ 10 * k, 10 * k }, .progress = drawn, .from = cursors.standard(back), .radius = theme.metric.tie.radius * k });
+ raw.route(points[0..n], color, .{ .width = theme.stroke.tie.link * k, .head = if (beyond == null) .{ 10 * k, 10 * k } else .{ 9 * k, 12 * k }, .progress = drawn, .from = cursors.standard(back), .radius = theme.metric.tie.radius * k });
+ if (beyond) |words| if (drawn >= 1) {
+ // How far the target is, faint, 6 past the head.
+ const v = raw.faded(1 - std.math.clamp((now.time - now.plan.advance) / l.out, 0, 1));
+ const tip = points[4];
+ v.text(.mono, theme.size.mono.context, tip[0] + 12 * k, tip[1] + (if (words < 0) @as(f32, 6) else 14) * k, v.print("{d} rows", .{@abs(words)}), theme.color.text.faint);
+ };
+ // The pin rides the line's head: the register's name beside it.
+ if (drawn > 0 and drawn < 1 and beyond == null) {
+ const tip = along(points[0..n], drawn);
+ raw.text(.mono_bold, theme.size.mono.context, tip[0] + 8 * k, tip[1] - 6 * k, name, theme.color.text.primary);
+ }
return;
}
}
@@ -224,27 +283,49 @@ pub const Ties = struct {
.{ .spans = rec.read(now.stops[1], now.stops[0]), .role = .read },
};
for (kinds) |kind| for (kind.spans) |span| {
- const word = span.addr & ~@as(u64, 7);
- const run = find(.{ .dump_run = word }) orelse continue;
- const part = find(.{ .node_part = word }) orelse continue;
- const node_addr = nodeOf(word) orelse continue;
+ // The run that begins where the bytes do (an element of an
+ // array), else the word they are in (a field of a node).
+ const word = if (find(.{ .dump_run = span.addr }) != null) span.addr else span.addr & ~@as(u64, 7);
+ // From the dump's run to the part of the drawing made of it; or
+ // from a word of the stack to the call it is the way back of.
+ const slot = find(.{ .word = span.addr });
+ // (A return draws no line: its node's badge is struck with rax's digits.)
+ const stacked = kind.role == .write and slot != null and find(.{ .node_address = span.addr }) != null and find(.{ .dump_run = word }) == null;
+ const run = if (stacked) slot.? else find(.{ .dump_run = word }) orelse continue;
+ if (!stacked) _ = find(.{ .node_part = word }) orelse continue;
+ const node_addr = if (stacked) span.addr else nodeOf(word) orelse continue;
const over = find(.{ .node_address = node_addr }) orelse continue;
const p = time.project;
const since = now.since(.memory, 0);
const bracket = std.math.clamp(since / p.bracket, 0, 1);
- const drawn = cursors.standard(std.math.clamp((since - p.bracket) / p.draw, 0, 1));
+ const drawn = cursors.standard(std.math.clamp((since - p.bracket) / @as(f32, if (stacked) p.far else p.draw), 0, 1));
const out = 1 - std.math.clamp((now.time - now.plan.advance) / p.out, 0, 1);
if (bracket <= 0 or out <= 0) return;
const color = theme.mark(kind.role).solid;
const v = raw.faded(out);
const tie = [2]f32{ theme.metric.bracket.tie[0] * k, theme.metric.bracket.tie[1] * k };
- // The bracket takes the row: x 7 of the dump, the row's height.
- const bx = run[0] - (rows.byteX(@intCast(word % 16)) - 4 - theme.metric.bytes.bracket) * k;
+ // The bracket takes the row: x 7 of the dump, the row's height;
+ // on the stack, the panel's left padding.
+ const bx = if (stacked) run[0] - (theme.metric.slot.chain - 5) * k else run[0] - (rows.byteX(@intCast(word % 16)) - 4 - theme.metric.bytes.bracket) * k;
v.faded(bracket).bracket(bx, run[1] + 2 * k, run[3] - 2 * k, color, tie, 1, false);
- const lane = at.xf.apply(.{ theme.metric.tie.projection_lane, 0 })[0];
- const top = at.xf.apply(.{ 0, split.band.y + theme.metric.context.tag + theme.metric.lens.top_lane })[1];
const cx = (over[0] + over[2]) / 2;
const y = (run[1] + run[3]) / 2;
+ if (stacked) {
+ // A frame's way back to its call's node: up the gutter's
+ // left lane, along the drawing's bottom lane, up to a
+ // bracket under the node, serifs up.
+ const lane = at.xf.apply(.{ theme.metric.tie.link_lane, 0 })[0];
+ const bottom = at.xf.apply(.{ 0, split.band.y + split.band.h - theme.metric.lens.bottom_lane })[1];
+ v.route(&.{ .{ bx - 1 * k, y }, .{ lane, y }, .{ lane, bottom }, .{ cx, bottom }, .{ cx, over[3] + 5 * k } }, color, .{ .width = theme.stroke.tie.projection * k, .head = null, .progress = drawn, .radius = theme.metric.tie.projection_radius * k });
+ if (drawn >= 1) {
+ v.fill(.{ .x = over[0], .y = over[3] + 2 * k, .w = over[2] - over[0], .h = 3 * k }, color);
+ v.fill(.{ .x = over[0], .y = over[3] - 3 * k, .w = 3 * k, .h = 8 * k }, color);
+ v.fill(.{ .x = over[2] - 3 * k, .y = over[3] - 3 * k, .w = 3 * k, .h = 8 * k }, color);
+ }
+ return;
+ }
+ const lane = at.xf.apply(.{ theme.metric.tie.projection_lane, 0 })[0];
+ const top = at.xf.apply(.{ 0, split.band.y + theme.metric.context.tag + theme.metric.lens.top_lane })[1];
v.route(&.{ .{ bx - 1 * k, y }, .{ lane, y }, .{ lane, top }, .{ cx, top }, .{ cx, over[1] - 4 * k } }, color, .{ .width = theme.stroke.tie.projection * k, .head = null, .progress = drawn, .radius = theme.metric.tie.projection_radius * k });
// Over the node's address: a bracket, serifs down.
if (drawn >= 1) {
@@ -252,12 +333,24 @@ pub const Ties = struct {
v.fill(.{ .x = over[0], .y = over[1] - 5 * k, .w = 3 * k, .h = 8 * k }, color);
v.fill(.{ .x = over[2] - 3 * k, .y = over[1] - 5 * k, .w = 3 * k, .h = 8 * k }, color);
}
- _ = part;
return;
};
}
};
+/// The point `p` of the way along the straight path through `points`.
+fn along(points: []const ui.Vec, p: f32) ui.Vec {
+ var total: f32 = 0;
+ for (points[0 .. points.len - 1], points[1..]) |a, b| total += sk.math.distance(a, b);
+ var left = total * p;
+ for (points[0 .. points.len - 1], points[1..]) |a, b| {
+ const d = sk.math.distance(a, b);
+ if (left <= d and d > 0) return sk.math.mix(a, b, left / d);
+ left -= d;
+ }
+ return points[points.len - 1];
+}
+
/// The node a field's address belongs to: the drawn node at or below it, within a record.
fn nodeOf(addr: u64) ?u64 {
var best: ?u64 = null;