summaryrefslogtreecommitdiff
path: root/anim/src/ties.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/ties.zig')
-rw-r--r--anim/src/ties.zig204
1 files changed, 135 insertions, 69 deletions
diff --git a/anim/src/ties.zig b/anim/src/ties.zig
index e25c34b..58ada36 100644
--- a/anim/src/ties.zig
+++ b/anim/src/ties.zig
@@ -46,8 +46,10 @@ pub const Place = union(enum) {
node_pin: u64,
/// A part of a node (its value, its pointer half), by the address of the field it is drawn from.
node_part: u64,
- /// A run of bytes in the lens's dump, by its address.
+ /// A run of bytes in the lens's dump, by its address; a view's row, by
+ /// its first byte's: where a link to what a register points at lands.
dump_run: u64,
+ dump_pin: u64,
/// The source's current line; the disassembly's pc row; each run of
/// the current line's instructions in the disassembly.
source,
@@ -69,6 +71,7 @@ pub const Place = union(enum) {
.source => 10 << 56,
.pc => 11 << 56,
.run => |k| 12 << 56 | @as(u64, k),
+ .dump_pin => |a| 13 << 56 | (a & low),
};
}
};
@@ -178,6 +181,8 @@ pub const Ties = struct {
threaded: bool = true,
/// No links: the registers are not marked (`Registers.quiet`).
quiet: bool = false,
+ /// A link the scene plays on a beat of its own (`Context.tiesWith`).
+ beat: ?*const Beat = null,
pub fn draw(g: *const Ties, f: *sk.Frame, at: anim.Placed) void {
defer said = 0;
@@ -192,7 +197,8 @@ pub const Ties = struct {
raw.at.xf = .identity;
const k = at.scale;
const split = g.stage.now(at);
- if (g.threaded) thread(raw, at, k);
+ if (g.threaded) thread(raw.faded(@import("context.zig").thread_shows), at, k);
+ if (g.beat) |b| named(raw, at, now, k, split, b);
if (!now.walking()) return;
if (!g.quiet) g.link(raw, at, now, k, split);
g.projection(raw, at, now, k, split);
@@ -217,84 +223,119 @@ pub const Ties = struct {
}
/// The step's link: the first register it struck that now holds the
- /// address of a pinned thing (a stack slot, a node). rip and rsp are
- /// where execution and the stack are, and have none.
+ /// address of a pinned thing (a stack slot, a node, a view's row). rip
+ /// and rsp are where execution and the stack are, and have none.
fn link(g: *const Ties, raw: ui.Ui, at: anim.Placed, now: cursors.Now, k: f32, split: theme.layout.Split) void {
const rec = g.cursor.rec;
const regs = (now.moment().regs(rec.tid) catch null) orelse return;
- const edge = find(.registers) orelse return;
for (theme.metric.all_registers[0..16]) |name| {
const i = @import("context.zig").index(name).?;
if (now.registerAge(i) != 0 or std.mem.eql(u8, name, "rsp")) continue;
const value = regs.named(name) orelse continue;
- const from = find(.{ .register = i }) orelse continue;
- const node = find(.{ .node_pin = value });
- // 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 = linkSince(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));
+ const node = find(.{ .node_pin = value }) != null;
+ const drawn = cursors.standard(std.math.clamp((since - l.after) / linkTime(if (node) .node else .slot), 0, 1));
const back = std.math.clamp((now.time - now.plan.advance) / l.out, 0, 1);
- if (drawn <= 0 or back >= 1) return;
- const color = rows.ink(rows.regionOf(now.moment(), value));
- const y = (from[1] + from[3]) / 2;
- // 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 };
- points[1] = .{ lane, y };
- if (node) |pin| {
- // Up the gutter, along the lens's bottom lane, up into the pin under the node.
- const bottom = at.xf.apply(.{ 0, split.band.y + split.band.h - theme.metric.lens.bottom_lane })[1];
- const cx = (pin[0] + pin[2]) / 2;
- points[2] = .{ lane, bottom };
- 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;
- points[2] = .{ lane, mid };
- points[3] = .{ target[0] - 2 * k, mid };
- n = 4;
- }
- 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;
+ if (linkTo(raw, at, now, k, split, name, value, drawn, back)) return;
+ }
+ }
+
+ /// A link from register `name` to what it points at (`value`): a node's
+ /// pin, a slot's, a view's row, or a slot past the stack's window (a
+ /// stub and a row count), `drawn` of the way and drawing back `back` of
+ /// it. False where `value` is no such place.
+ fn linkTo(raw: ui.Ui, at: anim.Placed, now: cursors.Now, k: f32, split: theme.layout.Split, name: []const u8, value: u64, drawn: f32, back: f32) bool {
+ const i = @import("context.zig").index(name) orelse return false;
+ const edge = find(.registers) orelse return false;
+ const from = find(.{ .register = i }) orelse return false;
+ const node = find(.{ .node_pin = value });
+ // A view's row it points into: up the gutter to the row's left edge.
+ const row = if (node == null) find(.{ .dump_pin = value & ~@as(u64, 15) }) else null;
+ // 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 row orelse edge: {
+ const w = stack_window orelse return false;
+ if (value % 8 != 0 or rows.regionOf(now.moment(), value) != .stack) return false;
+ const words = @as(i64, @bitCast(value -% w.first)) >> 3;
+ if (words >= 0 and words < w.slots) return false;
+ if (@abs(words) > 64) return false;
+ 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 l = time.link;
+ if (drawn <= 0 or back >= 1) return true;
+ const color = rows.ink(rows.regionOf(now.moment(), value));
+ const y = (from[1] + from[3]) / 2;
+ // 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 or row != 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 };
+ points[1] = .{ lane, y };
+ if (node) |pin| {
+ // Up the gutter, along the lens's bottom lane, up into the pin under the node.
+ const bottom = at.xf.apply(.{ 0, split.band.y + split.band.h - theme.metric.lens.bottom_lane })[1];
+ const cx = (pin[0] + pin[2]) / 2;
+ points[2] = .{ lane, bottom };
+ 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 row, and into its pin lane (a view's row: to its edge).
+ const mid = (target[1] + target[3]) / 2;
+ points[2] = .{ lane, mid };
+ points[3] = .{ target[0] + (if (row != null) @as(f32, 2) else -2) * k, mid };
+ n = 4;
+ }
+ 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 - back);
+ 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);
}
+ _ = l;
+ return true;
+ }
+
+ /// The scene's `Beat`: its register framed as read, then its link.
+ fn named(raw: ui.Ui, at: anim.Placed, now: cursors.Now, k: f32, split: theme.layout.Split, b: *const Beat) void {
+ const t = at.value(b.t);
+ if (t < 0 or t >= b.total()) return;
+ const i = @import("context.zig").index(b.name) orelse return;
+ const px = find(.{ .register = i }) orelse return;
+ const l = time.link;
+ const back = std.math.clamp((t - (b.total() - l.out)) / l.out, 0, 1);
+ // Its value framed as read, in the panel's units.
+ const u: ui.Ui = .{ .f = raw.f, .at = at };
+ const inv = at.xf.invert();
+ const a = inv.apply(.{ px[0], px[1] });
+ const c = inv.apply(.{ px[2], px[3] });
+ u.read(.{ .x = a[0], .y = a[1], .w = c[0] - a[0], .h = c[1] - a[1] }, std.math.clamp(t / time.read.in, 0, 1) * (1 - back));
+ const rec = b.cursor.rec;
+ const regs = (now.moment().regs(rec.tid) catch null) orelse return;
+ const value = regs.named(b.name) orelse return;
+ const drawn = cursors.standard(std.math.clamp((t - l.after) / l.in_far, 0, 1));
+ _ = linkTo(raw, at, now, k, split, b.name, value, drawn, back);
}
/// The step's projection: the first run of bytes it read or wrote in
@@ -361,6 +402,31 @@ pub const Ties = struct {
}
};
+/// A link the narration plays on a beat the caption names, not a step's:
+/// register `name` framed as read (6 f), then its link to what it points at
+/// (6 f after, 36 f, `standard`, the name riding its head), held `hold`,
+/// and drawn back with the frame (18 f).
+pub const Beat = struct {
+ cursor: cursors.Cursor,
+ name: []const u8,
+ hold: f32,
+ /// Seconds into it; negative: none.
+ t: anim.Value,
+
+ pub fn total(b: *const Beat) f32 {
+ return time.link.after + time.link.in_far + b.hold + time.link.out;
+ }
+
+ /// Plays it from here; the scene's cursor stays where it was.
+ pub fn play(b: *const Beat, s: *anim.Frame) void {
+ const start = s.cursor;
+ s.play(.{b.t.to(0)}, .{ .seconds = 0 });
+ s.play(.{b.t.to(b.total())}, .{ .seconds = b.total(), .ease = anim.ease.linear });
+ s.play(.{b.t.to(-1)}, .{ .seconds = 0 });
+ s.cursor = start;
+ }
+};
+
/// 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;