diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-12 04:45:57 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-12 07:03:05 -0300 |
| commit | 4907e35bc45d12102d0e09380994814fc2e0a369 (patch) | |
| tree | 7cfd90224653d73b63fbadaf2881fa0e6ba92860 /anim/src | |
| parent | ebdebe04a76f0302aeb24c1ac08fa9217b1a8257 (diff) | |
| download | computeranim-4907e35bc45d12102d0e09380994814fc2e0a369.tar.gz computeranim-4907e35bc45d12102d0e09380994814fc2e0a369.zip | |
canim: the introduction, from the review
The introduction records the plain build (clang -O0, no instrumentation),
so reverse's frame is the compiler's own push, mov and sub. The stack
chapter says its convention once and keeps four free words over rsp so
a push moves the pin and nothing else; reverse's rows stand under main's
and are stepped, each touching its word, the call before the push, the
aim drawn head first to the row it returns to. The close-up frames the
bytes and the stack together with their 128 bytes marked. Nothing is
named before it is shown; offsets are written in hex as the operands are;
the dump folds into its tag; the map is announced before it is shown.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/src')
| -rw-r--r-- | anim/src/Recording.zig | 58 | ||||
| -rw-r--r-- | anim/src/array.zig | 2 | ||||
| -rw-r--r-- | anim/src/aside.zig | 29 | ||||
| -rw-r--r-- | anim/src/context.zig | 35 | ||||
| -rw-r--r-- | anim/src/cursor.zig | 65 | ||||
| -rw-r--r-- | anim/src/hexdump.zig | 6 | ||||
| -rw-r--r-- | anim/src/nodes.zig | 14 | ||||
| -rw-r--r-- | anim/src/objects.zig | 3 | ||||
| -rw-r--r-- | anim/src/regroup.zig | 150 | ||||
| -rw-r--r-- | anim/src/rows.zig | 13 | ||||
| -rw-r--r-- | anim/src/segments.zig | 14 | ||||
| -rw-r--r-- | anim/src/ties.zig | 20 | ||||
| -rw-r--r-- | anim/src/ui.zig | 19 |
13 files changed, 317 insertions, 111 deletions
diff --git a/anim/src/Recording.zig b/anim/src/Recording.zig index 4bc9c1b..bcc8903 100644 --- a/anim/src/Recording.zig +++ b/anim/src/Recording.zig @@ -143,6 +143,11 @@ locals: []Declared = &.{}, /// The variables declared outside the stack (globals): bytes a lens draws. globals: []Span = &.{}, strings: std.AutoHashMapUnmanaged(u64, []const u8) = .empty, +/// What a program built without the pass does not tell of itself (the +/// introduction's plain build): its globals' types and its named types, in +/// the pass's notation (`types`), by name (`declare`); its locals are the +/// debug info's (`zt.telescope.slots`), untyped. +declared: std.StringHashMapUnmanaged(u64) = .empty, arena: std.heap.ArenaAllocator, const gpa = std.heap.smp_allocator; @@ -694,7 +699,55 @@ pub fn variable(r: *const Recording, scratch: std.mem.Allocator, m: Moment, text for (all) |v| { if (std.mem.eql(u8, r.name(v.name), text) and (found == null or v.depth > found.?.depth)) found = v; } - return found; + return found orelse if (r.declared.count() > 0) r.plain(m, text) else null; +} + +/// The live variables: the recording's, or a plain build's declared globals. +pub fn variables(r: *const Recording, scratch: std.mem.Allocator, m: Moment) []Variable { + const all = m.variables(scratch) catch return &.{}; + if (all.len > 0 or r.declared.count() == 0) return all; + var out: std.ArrayList(Variable) = .empty; + var it = r.declared.keyIterator(); + while (it.next()) |key| if (key.*[0] != '`') if (r.plain(m, key.*)) |v| out.append(scratch, v) catch break; + return out.items; +} + +/// Declares, for a program built without the pass, global `what`'s type +/// (`text`, in the pass's notation), or a named type's description +/// (`what` in backticks, as a type names it). Once each. +/// shortcut: a scene writes them from the source, as the tracer reads no types from the debug info; upgrade when it does. +pub fn declare(r: *Recording, what: []const u8, text: []const u8) void { + if (r.declared.contains(what)) return; + const a = r.arena.allocator(); + const named = what[0] == '`'; + const id = if (named) types.defId(what[1 .. what.len - 1]) else r.intern(text) catch return; + if (named) r.strings.put(a, id, a.dupe(u8, text) catch return) catch return; + r.declared.put(a, a.dupe(u8, what) catch return, id) catch {}; +} + +/// A plain build's variable `text` at `m`: a declared global, at the +/// address the recording names `text+0` (a word: what a lens hangs from is +/// a pointer); or a local of the newest frame, by the debug info. Its +/// `name` is 0: the recording has no id for it. +fn plain(r: *const Recording, m: Moment, text: []const u8) ?Variable { + if (r.declared.get(text)) |ty| { + var it = r.strings.iterator(); + while (it.next()) |e| { + const s = e.value_ptr.*; + if (e.key_ptr.* >> 63 == 0 and s.len == text.len + 2 and std.mem.startsWith(u8, s, text) and std.mem.endsWith(u8, s, "+0")) + return .{ .addr = e.key_ptr.*, .size = 8, .name = 0, .type = ty, .tid = r.tid, .depth = 0 }; + } + return null; + } + const regs = (m.regs(r.tid) catch null) orelse return null; + var buf: [32]zt.telescope.Slot = undefined; + const slots = zt.telescope.slots(m, ®s, regs.rsp, &buf) catch return null; + for (slots, 0..) |slot, k| if (slot.frame == 0 and slot.role == .local) { + const l = slot.role.local; + if (l.offset == 0 and std.mem.eql(u8, l.name, text)) + return .{ .addr = regs.rsp + 8 * k, .size = l.size, .name = 0, .type = 0, .tid = r.tid, .depth = r.depths[@min(m.index, r.end())] }; + }; + return null; } /// A variable's type, as the compiler pass described it, with a named type @@ -735,7 +788,8 @@ pub fn assigned(r: *const Recording, v: Variable, i: u64) bool { if (c.enter > i) break; if (c.active(i) and c.depth + 1 == v.depth) enter = c.enter; } - return touches(r.written(enter -| 1, i), v.addr, v.size); + // A plain build's local (`plain`): a store of the value its stretch of stack held assigns it too. + return touches(r.written(enter -| 1, i), v.addr, v.size) or (v.name == 0 and touches(r.store_spans.of(enter -| 1, i), v.addr, v.size)); } /// Which allocation ever made holds `addr` at moment `m`: the same number diff --git a/anim/src/array.zig b/anim/src/array.zig index fad10c5..e40c0d2 100644 --- a/anim/src/array.zig +++ b/anim/src/array.zig @@ -248,7 +248,7 @@ pub const Array = struct { for (inks[0..@min(indices, inks.len)]) |*i_ink| i_ink.* = theme.color.region.stack; const pv = u.faded(shows * ties.rise(rising, k, count).element); pv.pinUnderInked(x, top + cell[1], &.{}, &.{}, if (names.items.len > indices) ink else t.primary, label); - pv.faded(text).pinNames(x, top + cell[1], names.items, inks[0..@min(names.items.len, inks.len)], label); + pv.faded(text).pinNames(x, top + cell[1], names.items, inks[0..@min(names.items.len, inks.len)], label, 0); } } diff --git a/anim/src/aside.zig b/anim/src/aside.zig index 5400da5..c2c0ef8 100644 --- a/anim/src/aside.zig +++ b/anim/src/aside.zig @@ -1,7 +1,8 @@ //! A text beside what it speaks of, for a scene that builds its parts in //! place rather than in the column's panes (the introduction): the //! column's `bubble` (design/README.md, "column"), standing alone. Go 40 -//! on 54, code in mono 35, at most 40 characters a line, 16 of padding; +//! on 54, code in mono 35, at most 40 characters a line (twice as many +//! for a text `above` a subject across both columns: `Asides.wrap`), 16 of padding; //! the newest on `raised` paper, primary; an older one loses its paper and //! dims to `dim` (`dim`, 18 f). It arrives rising 8 (its object's fade, //! 18 f, `enter`) and leaves with its fade (12 f, `exit`). No stem: its @@ -28,10 +29,12 @@ pub const Aside = struct { level: f32, /// 0 newest, 1 the account (no paper, `dim`). dim: anim.Value, + /// Characters a line, at most. + wrap: usize = chars, pub fn draw(a: *const Aside, f: *sk.Frame, placed: anim.Placed) void { const u = (ui.Ui{ .f = f, .at = placed }).moved(0, (1 - placed.pose.opacity) * theme.time.caption_rise); - const wrapped = wrap(u, a.text); + const wrapped = wrap(u, a.text, a.wrap); const top = a.level - first; const h = first * 2 + @as(f32, @floatFromInt(wrapped.len - 1)) * line_pitch; var w: f32 = 0; @@ -54,13 +57,15 @@ pub const Asides = struct { spans: [8][2]f32 = undefined, n: usize = 0, read_by: f32 = 0, + /// Characters a line, at most, of the texts it says. + wrap: usize = chars, pub fn say(a: *Asides, s: *anim.Frame, text: []const u8, x: f32, level: f32) void { s.wait(@max(a.read_by - s.cursor, 0)); const dim = s.value(0); - const made = s.new(Aside{ .text = text, .x = x, .level = level, .dim = dim }); + const made = s.new(Aside{ .text = text, .x = x, .level = level, .dim = dim, .wrap = a.wrap }); const obj = s.custom(made, .{ .x = -640, .y = -360, .scale = ui.scale }); - const span = [2]f32{ level - first, level + first + @as(f32, @floatFromInt(lines(text) - 1)) * line_pitch }; + const span = [2]f32{ level - first, level + first + @as(f32, @floatFromInt(lines(text, a.wrap) - 1)) * line_pitch }; const at = s.cursor; var in_the_way = false; for (a.shown[0..a.n], a.dims[0..a.n], a.spans[0..a.n]) |*o, d, other| { @@ -105,7 +110,7 @@ fn easeGlide(x: f32) f32 { } /// How many lines `wrap` makes of `text` (a newline breaks one where the author says). -fn lines(text: []const u8) usize { +fn lines(text: []const u8, most: usize) usize { var count: usize = 0; var paragraphs = std.mem.splitScalar(u8, text, '\n'); while (paragraphs.next()) |paragraph| { @@ -114,7 +119,7 @@ fn lines(text: []const u8) usize { count += 1; while (it.next()) |word| { const seen = (std.unicode.utf8CountCodepoints(word) catch word.len) - std.mem.count(u8, word, "`"); - if (n > 0 and n + 1 + seen > chars) { + if (n > 0 and n + 1 + seen > most) { count += 1; n = 0; } @@ -135,7 +140,7 @@ fn width(u: ui.Ui, line: []const u8) f32 { /// Lines of at most `chars` visible characters, broken at spaces; a code /// run keeps its backticks on each line it spans. -fn wrap(u: ui.Ui, text: []const u8) []const []const u8 { +fn wrap(u: ui.Ui, text: []const u8, most: usize) []const []const u8 { var out: std.ArrayList([]const u8) = .empty; var paragraphs = std.mem.splitScalar(u8, text, '\n'); while (paragraphs.next()) |paragraph| { @@ -145,7 +150,7 @@ fn wrap(u: ui.Ui, text: []const u8) []const []const u8 { while (it.next()) |word| { const seen = std.unicode.utf8CountCodepoints(word) catch word.len; const ticks = std.mem.count(u8, word, "`"); - if (n > 0 and n + 1 + seen - ticks > chars) { + if (n > 0 and n + 1 + seen - ticks > most) { out.append(u.f.scratch, line.items) catch break; line = .empty; n = 0; @@ -164,10 +169,10 @@ fn wrap(u: ui.Ui, text: []const u8) []const []const u8 { } test "lines of at most forty characters, backticks not counted" { - try std.testing.expectEqual(@as(usize, 1), lines("Its address space, 128 TiB, to scale.")); - try std.testing.expectEqual(@as(usize, 2), lines("Its address space, 128 TiB, to scale: mapped only at each end.")); + try std.testing.expectEqual(@as(usize, 1), lines("Its address space, 128 TiB, to scale.", chars)); + try std.testing.expectEqual(@as(usize, 2), lines("Its address space, 128 TiB, to scale: mapped only at each end.", chars)); // Four code runs of nine: 39 shown, 47 with their backticks. - try std.testing.expectEqual(@as(usize, 1), lines("`012345678` `012345678` `012345678` `012345678`")); + try std.testing.expectEqual(@as(usize, 1), lines("`012345678` `012345678` `012345678` `012345678`", chars)); // A newline breaks where the author says. - try std.testing.expectEqual(@as(usize, 2), lines("And all of it at once:\nthe map.")); + try std.testing.expectEqual(@as(usize, 2), lines("And all of it at once:\nthe map.", chars)); } diff --git a/anim/src/context.zig b/anim/src/context.zig index 7d56c62..874a22a 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -391,7 +391,8 @@ pub fn frameBase(rec: *const Recording, i: u64, regs: zt.Regs) Base { /// `d` bytes from base `name` (`rbp-18`, `rbp+8`, `rbp`), as the stack's tag writes a range. fn fromBase(u: ui.Ui, name: []const u8, d: i64) []const u8 { - return if (d == 0) name else if (d > 0) u.print("{s}+{x}", .{ name, @as(u64, @intCast(d)) }) else u.print("{s}-{x}", .{ name, @as(u64, @intCast(-d)) }); + const p = rows.hexMark(@abs(d)); + return if (d == 0) name else if (d > 0) u.print("{s}+{s}{x}", .{ name, p, @as(u64, @intCast(d)) }) else u.print("{s}-{s}{x}", .{ name, p, @as(u64, @intCast(-d)) }); } /// A frame's span on the stack: its function's name, and as a call its @@ -472,15 +473,16 @@ pub const Stack = struct { /// The stack built a `column` at a time (design/README.md, 6. Verbs: /// `column`; motion.md, chapter II): each part a clock the scene plays /// (frames, negative before it begins), its rows coming in top down as - /// shown, 2 f apart, 12 f each; until then under the page. + /// shown, `apart` frames apart (2 by default), 12 f each; until then under the page. pub const Reveal = struct { offsets: anim.Value, roles: anim.Value, spans: anim.Value, + apart: f32 = 2, /// How much of row (or span) `k`'s part is still under the page, its clock at `clock`. - fn hidden(clock: f32, k: f32) f32 { - return 1 - std.math.clamp((clock - 2 * @max(k, 0)) / 12, 0, 1); + fn hidden(r: Reveal, clock: f32, k: f32) f32 { + return 1 - std.math.clamp((clock - r.apart * @max(k, 0)) / 12, 0, 1); } }; @@ -493,6 +495,8 @@ pub const Stack = struct { const slots = rowsOf(box); const is = (now.moment().regs(rec.tid) catch null) orelse return; const was = (now.before().regs(rec.tid) catch null) orelse is; + rows.prefixed = now.introduction; + defer rows.prefixed = false; // The window: from rsp, or further into the frame ([rsp, rbp+16)) // when that is longer than the panel, so that the word the last // steps touched is in its middle. When a step moves it the rows @@ -729,12 +733,12 @@ pub const Stack = struct { if (y + m.row < body.y or y > box.h) continue; const addr = window[0] +% @as(u64, @bitCast(n * 8)); // Not come in yet (`reveal`): the offset under the page (from past the pins to 172), the role with its row. - const hide_offset = if (k.reveal) |rv| Reveal.hidden(placed.value(rv.offsets), (y - top) / m.row) else 0; - const hide_role = if (k.reveal) |rv| Reveal.hidden(placed.value(rv.roles), (y - top) / m.row) else 0; + const hide_offset = if (k.reveal) |rv| rv.hidden(placed.value(rv.offsets), (y - top) / m.row) else 0; + const hide_role = if (k.reveal) |rv| rv.hidden(placed.value(rv.roles), (y - top) / m.row) else 0; // The page laid over them is opaque whatever the panel's own fade (a faded page over faded text leaves some). var page_u = u; page_u.at.pose.opacity = 1; - defer if (hide_offset > 0) page_u.faded(hide_offset).fill(.{ .x = 120, .y = y, .w = theme.metric.slot.offset + 4 - 120, .h = m.row }, theme.color.page); + defer if (hide_offset > 0) page_u.faded(hide_offset).fill(.{ .x = theme.metric.slot.lane_end, .y = y, .w = theme.metric.slot.offset + 4 - theme.metric.slot.lane_end, .h = m.row }, theme.color.page); // Who points here: a pin in the lane, landing with its link. const names = pins(u, now, is, was, addr, travel); var marks: rows.Marks = .{ .lead = lead, .first = now.writtenWatched(addr, 8, .memory, 0, watched_from, watched_to) }; @@ -744,10 +748,15 @@ pub const Stack = struct { marks.read = 0; marks.read_shows = now.reading(.memory, 0); } - // A word stored with the value it held (a `push rbp` over the old saved rbp): armed, and nothing struck. + // A word stored with the value it held (a `push rbp` over the old saved rbp): armed, and nothing struck; + // in the introduction struck as any write, its mark gone by the step's end (nothing remembers it). if (touched_here and touch.?.write and now.walking() and now.writeAge(addr, 8) != 0) { const s_at = now.plan.at[1]; - marks.first.arm = std.math.clamp((now.time - (s_at - time.strike.arm)) / time.stagger, 0, 1) * (1 - std.math.clamp((now.time - s_at) / time.quick, 0, 1)); + if (now.introduction) { + marks.first = now.heat(0, null, now.time - s_at); + marks.first.corner = 0; + marks.first.level *= 1 - std.math.clamp((now.time - now.plan.advance) / @max(now.plan.total - now.plan.advance, 1.0 / 60.0), 0, 1); + } else marks.first.arm = std.math.clamp((now.time - (s_at - time.strike.arm)) / time.stagger, 0, 1) * (1 - std.math.clamp((now.time - s_at) / time.quick, 0, 1)); } const below_rsp: i64 = if (tied) @bitCast(addr -% bases[1].value(is)) else @bitCast(addr -% if (held) rsp_shown else is.rsp); map.row(.stack, addr, u, .{ .x = 0, .y = y, .w = box.w, .h = m.row }); @@ -792,7 +801,9 @@ pub const Stack = struct { const k_role = (addr -% roles_from) / 8; var role_at: [2]@TypeOf(roleName(u, .none, 0)) = undefined; for (&role_at, roles, [2]Recording.Moment{ now.before(), now.moment() }) |*r, of, mem| { - r.* = slotName(u, if (k_role < of.len) of[k_role] else .{}, (Recording.word(mem, addr, 8) catch null) orelse 1); + const slot_is: zt.telescope.Slot = if (k_role < of.len) of[k_role] else .{}; + // The introduction names the way back too (its caption's words: `return address` would cut `main+50`). + r.* = if (now.introduction and slot_is.role == .return_address) .{ .name = "the way back" } else slotName(u, slot_is, (Recording.word(mem, addr, 8) catch null) orelse 1); } const what: zt.telescope.Role = if (k_role < roles[1].len) roles[1][k_role].role else .none; const role = role_at[1]; @@ -870,7 +881,7 @@ pub const Stack = struct { // Rows crossed, counted on its whole way (its start may be off the window). const count = std.math.clamp(@ceil(goes(now, was, is, "rsp") * total_rows - 0.01), 1, total_rows); const bytes: u64 = @intFromFloat(count * 8); - pinAmount(u, x, top + place * m.row, names_, if (is.rsp < was.rsp) u.print("-{x}", .{bytes}) else u.print("+{x}", .{bytes}), amount_shows); + pinAmount(u, x, top + place * m.row, names_, u.print("{s}{s}{x}", .{ if (is.rsp < was.rsp) "-" else "+", rows.hexMark(bytes), bytes }), amount_shows); // The rows it crossed, a 3-unit vermilion bracket in the outer arc lane. if (crossed > 0.05) u.faded(amount_shows).bracket(theme.metric.arc.lanes[0], top + @min(place, old) * m.row + 2, top + @max(place, old) * m.row - 2, theme.mark(.write).solid, theme.metric.bracket.tie, 1, false); } else if (lone != null and joinsBefore(pins(u, now, is, was, is.named(name) orelse 0, travel).names, name)) { @@ -886,7 +897,7 @@ pub const Stack = struct { } else u.pinRow(x, top + place * m.row, names_, theme.color.region.stack); } for (spans[0..n_spans], 0..) |sp, i| if (sp.shows > 0) { - const sv = if (k.reveal) |rv| v.faded(1 - Reveal.hidden(placed.value(rv.spans), @floatFromInt(i))) else v; + const sv = if (k.reveal) |rv| v.faded(1 - rv.hidden(placed.value(rv.spans), @floatFromInt(i))) else v; if (sp.was) |was_name| { rows.span(sv.faded(1 - renamed), map.content(box.w), sp.y0, sp.y1, was_name, sp.newest, sp.open); rows.span(sv.faded(renamed), map.content(box.w), sp.y0, sp.y1, sp.name, sp.newest, sp.open); diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig index b09db8d..c145823 100644 --- a/anim/src/cursor.zig +++ b/anim/src/cursor.zig @@ -80,8 +80,17 @@ pub const Levels = struct { annotation: enum { tied, whole } = .tied, /// A value's way between memory and a register (`carry`, "4. Ties"), /// read at each step (a beat may turn it on): none, an arrow, or the - /// arrow carrying the value's digits on a chip. - carry: enum { off, arrow, value } = .off, + /// arrow carrying the value's digits on a chip; or the arrow after the + /// instruction's touch, a store's too (the row names the word, then the + /// value goes there: the introduction's `push rbp`). + carry: enum { off, arrow, value, after_touch } = .off, + /// The introduction's (design/motion.md, "A scene: the introduction"): + /// what the working frame leaves to the eye, said: the stack's offsets + /// and a pin's amount written with `0x` where hex and decimal differ + /// (beside a symbol's decimal offset, `main+50`), a return address's + /// role named (`the way back`), and a store of the value its word held + /// struck as any write (the step's event). + introduction: bool = false, }; /// How a step is drawn. Walk: everything, as a sentence. Run: the mark and @@ -303,6 +312,11 @@ pub const Cursor = struct { /// The `aim` relation's knob (design/README.md, "4. Ties"): 0 off (the /// default), 1 standing (in and out over 18 f), 2 for the step. aim_knob: anim.Value, + /// A standing aim drawn as a step's is (`aim(.drawn)`): frames of its + /// way, 0 to 24 (18 the head's, 6 the row's frame; past 24, drawn), and + /// 1 while at full ink, 0 at the standing 60%. + aim_drawn: anim.Value, + aim_lit: anim.Value, /// The same values a little behind (`time.minimap_lag`, then a frame /// later each, `time.minimap_fade` of them): what the minimap draws /// from, secondary action that never starts on a primary onset's frame @@ -333,6 +347,8 @@ pub const Cursor = struct { .sprint_veil = s.value(0), .count = s.value(0), .aim_knob = s.value(0), + .aim_drawn = s.value(99), + .aim_lit = s.value(0), .lags = undefined, .first = start, .last = start, @@ -628,7 +644,12 @@ pub const Cursor = struct { const writes = c.levels.memory and (wrote > 0 or (touch != null and touch.?.write)); if (writes) { const store = if (carry) |cc| !cc.load else false; - if (store) { + if (store and c.levels.carry == .after_touch and touch != null and touch.?.write) { + // The touch to the word, the register framed as read (6 f), then the carry. + plan.touch = t + 6 * f; + plan.carry = plan.touch + k.touch + 12 * f; + plan.at[1] = plan.carry + k.carry + time.strike.arm; + } else if (store) { // The register framed as read (6 f), then the carry: no touch, the row having named the word. plan.carry = t + 12 * f; plan.at[1] = plan.carry + k.carry + time.strike.arm; @@ -778,30 +799,50 @@ pub const Cursor = struct { /// off unless the author turns it on, for a scene or a beat): `.standing` /// draws the aims of the words on screen, coming and going over 18 f; /// `.step` those of the words a walked step writes or reads. - pub fn aim(c: Cursor, s: *anim.Frame, knob: enum { off, step, standing }) void { + /// `drawn`: standing, but drawn as a step's aim is, head first from the + /// word at full ink (18 f), the row's address framed as it lands (6 f); + /// a `standing` after it falls to 60% (18 f). + pub fn aim(c: Cursor, s: *anim.Frame, knob: enum { off, step, standing, drawn }) void { // Over what follows: the timeline's cursor stays where it was. const start = s.cursor; defer s.cursor = start; switch (knob) { - .off, .standing => s.play(.{c.aim_knob.to(if (knob == .off) 0 else 1)}, .{ .seconds = 18.0 / 60.0, .ease = anim.ease.linear }), + .off, .standing => s.play(.{ c.aim_knob.to(if (knob == .off) 0 else 1), c.aim_lit.to(0) }, .{ .seconds = 18.0 / 60.0, .ease = anim.ease.linear }), .step => s.play(.{c.aim_knob.to(2)}, .{ .seconds = 0 }), + .drawn => { + s.play(.{ c.aim_knob.to(1), c.aim_lit.to(1), c.aim_drawn.to(0) }, .{ .seconds = 0 }); + s.play(.{c.aim_drawn.to(24)}, .{ .seconds = 24.0 / 60.0, .ease = anim.ease.linear }); + }, } } /// There at once, with nothing struck: a cut. pub fn jump(c: Cursor, s: *anim.Frame, to: u64) void { + c.jumpWalked(s, to, to); + } + + /// There at once, as though each moment from `from` on had been walked + /// to `to`, at rest: what the panels read of the steps before (the rows + /// run, the trail, the marks they left) as a walk leaves it (a chapter + /// opening on the last one's picture). + pub fn jumpWalked(c: Cursor, s: *anim.Frame, from: u64, to: u64) void { const Jump = struct { + from: u64, to: u64, fn run(j: @This(), sf: *anim.Frame, v: Cursor) void { var all: [history + 3]anim.Animation = undefined; - for (v.stops, 0..) |stop_value, i| all[i] = stop_value.to(@floatFromInt(j.to)); + for (v.stops, 0..) |stop_value, i| all[i] = stop_value.to(@floatFromInt(@max(j.to -| i, j.from))); all[history] = v.phase.to(1); all[history + 1] = v.marks[0].to(@floatFromInt(j.to)); all[history + 2] = v.marks[1].to(@floatFromInt(j.to)); sf.play(all, .{ .seconds = 0 }); } }; - c.both(s, Jump{ .to = to }); + // At the scene's first instant there is no before for the minimap's mirrors to lag behind. + if (s.cursor == 0) { + for (0..c.lags.len) |k| (Jump{ .from = from, .to = to }).run(s, lagged(c, k)); + (Jump{ .from = from, .to = to }).run(s, c); + } else c.both(s, Jump{ .from = from, .to = to }); } /// For a component, while it draws (on the minimap the values are a lagging mirror's: `lagInto`). @@ -824,6 +865,9 @@ pub const Cursor = struct { .annotation = c.levels.annotation, .way = .{ c.first, c.last }, .aim = placed.value(c.aim_knob), + .aim_drawn = placed.value(c.aim_drawn), + .aim_lit = placed.value(c.aim_lit), + .introduction = c.levels.introduction, }; var plan: [Plan.values]f32 = undefined; for (&plan, c.plan) |*is, v| is.* = placed.value(v); @@ -908,8 +952,13 @@ pub const Now = struct { annotation: @FieldType(Levels, "annotation") = .tied, /// The scene's way through the recording: its first moment and its last. way: [2]u64 = .{ 0, 0 }, - /// The `aim` knob: 0 off, up to 1 standing (coming or going), 2 for the step. + /// The `aim` knob: 0 off, up to 1 standing (coming or going), 2 for the step; + /// a standing one's way drawn (`Cursor.aim_drawn`, frames) and its ink (`aim_lit`). aim: f32 = 0, + aim_drawn: f32 = 99, + aim_lit: f32 = 0, + /// `Levels.introduction`. + introduction: bool = false, /// The program's state as shown. pub fn moment(n: Now) Recording.Moment { diff --git a/anim/src/hexdump.zig b/anim/src/hexdump.zig index 9b39bf6..d1c363c 100644 --- a/anim/src/hexdump.zig +++ b/anim/src/hexdump.zig @@ -801,8 +801,10 @@ pub fn readingIn(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: var word: u64 = 0; for (0..@min(len, 8)) |k| word |= @as(u64, bytes[k]) << @intCast(8 * k); if (word == 0) break :blk "NULL"; - if (x + theme.metric.context.arrow_w + @as(f32, @floatFromInt(ui.digits(word))) * adv > room) break :blk "\u{2026}"; - x = u.arrow(x, y + m.row / 2, .points); + // The arrow has its own room, as in a chain: no character before it. + const ax = if (x > b.reading + shift) x - adv else x; + if (ax + theme.metric.context.arrow_w + @as(f32, @floatFromInt(ui.digits(word))) * adv > room) break :blk "\u{2026}"; + x = u.arrow(ax, y + m.row / 2, .points); x = u.address(x, base, word, .{ .ink = ui.rgb(rows.ink(rows.regionOf(moment, word))) }) + adv; continue; }, diff --git a/anim/src/nodes.zig b/anim/src/nodes.zig index 5218d7f..bc2ef86 100644 --- a/anim/src/nodes.zig +++ b/anim/src/nodes.zig @@ -40,6 +40,9 @@ pub const Nodes = struct { /// No registers in the pins: an instrumented program's registers say nothing of it. quiet: bool = false, focus: bool = true, + /// A pin's names past the second by name where they fit before the next + /// node, not a count (the introduction's: what its caption names). + named: bool = false, pub fn draw(g: *const Nodes, f: *sk.Frame, placed: anim.Placed) void { const box = g.stage.box(placed, .band); @@ -175,13 +178,18 @@ pub const Nodes = struct { const new = for (before) |was| { if (was.addr == o.addr) break false; } else true; + // Its pin's names run right as far as the next node (or the band's edge). + var room = box.w - m.pad - 8; + for (places) |q| if (q.x > place.x) { + room = @min(room, q.x - 8); + }; // What begins fades in; it does not pop. - if (show > 0) g.node(u.faded(show * (if (new) now.moving(.idea, 0, time.quick) else 1)).moved(0, below), now, o, place, label, value_size); + if (show > 0) g.node(u.faded(show * (if (new) now.moving(.idea, 0, time.quick) else 1)).moved(0, below), now, o, place, label, value_size, room); } g.tags(u, now, things, places, label); } - fn node(g: *const Nodes, u: ui.Ui, now: cursors.Now, o: objects.Object, r: Rect, label: f32, value_size: f32) void { + fn node(g: *const Nodes, u: ui.Ui, now: cursors.Now, o: objects.Object, r: Rect, label: f32, value_size: f32, room: f32) void { const moment = now.shown(.idea); const heap = theme.color.region.heap; const pw = theme.metric.node.pointer_w; @@ -235,7 +243,7 @@ pub const Nodes = struct { ties.anchor(u, .{ .node_pin = o.addr }, .{ .x = cx - 1, .y = r.y + r.h, .w = 2, .h = label + 10 }); if (names.names.len > 0 and names.shows > 0) { u.faded(names.shows).pinUnderInked(cx, r.y + r.h, &.{}, &.{}, heap, label); - u.faded(names.shows * names.text).pinNames(cx, r.y + r.h, names.names, names.inks, label); + u.faded(names.shows * names.text).pinNames(cx, r.y + r.h, names.names, names.inks, label, if (g.named) room else 0); } } diff --git a/anim/src/objects.zig b/anim/src/objects.zig index 6ee2b4c..dd9ea85 100644 --- a/anim/src/objects.zig +++ b/anim/src/objects.zig @@ -38,8 +38,7 @@ pub const Link = struct { from: u64, to: ?u64 }; /// shortcut: 64 objects at most; a bigger structure wants a view of part of it. pub fn reach(scratch: std.mem.Allocator, rec: *const Recording, m: Recording.Moment, root: ?[]const u8) []Object { var found: std.ArrayList(Object) = .empty; - const variables = m.variables(scratch) catch return &.{}; - for (variables) |v| { + for (rec.variables(scratch, m)) |v| { if (root) |name| if (!std.mem.eql(u8, rec.name(v.name), name)) continue; // A local its call has yet to assign points wherever that stretch of stack did before. if (!rec.assigned(v, m.index)) continue; diff --git a/anim/src/regroup.zig b/anim/src/regroup.zig index c9f618a..a904ba2 100644 --- a/anim/src/regroup.zig +++ b/anim/src/regroup.zig @@ -4,14 +4,16 @@ //! verbs that make words of them, each a clock the scene plays (frames, //! linear): //! -//! - `in`: the rows arrive, sixteen bytes a row, 18 f each, 12 f apart; no +//! - `in`: the rows arrive, sixteen bytes a row, 18 f each, 18 f apart; no //! ink, the addresses faint. //! - `regroup` (design/README.md, 6. Verbs): sixteen a row to eight, the //! return address walked (its offsets, `low byte`, `high byte`, its bytes -//! flying low byte first on nested arcs to its word's field, the gaps -//! closing, `zeros in front`), the other fifteen at a run. +//! flying low byte first to its word's field, on nested arcs, or over a +//! top row one at a time; the gaps closing, `zeros in front`), the other +//! fifteen at a run. //! - `framed`: three words that hold addresses framed as read, 30 f apart. -//! - `fold`: the rows out (6 f), the dump's tag to the shelf (18 f, `glide`); back. +//! - `fold`: the rows glide up into the header (24 f), the header becomes +//! the tag, the tag to the shelf (24 f, `glide`); back, the reverse. //! - `ink` (6. Verbs): a word's digits to its region's ink, the walked one //! framed with its bytes (its band in `segments` is the scene's echo); //! the rest at a run, 2 f apart. @@ -31,6 +33,18 @@ const Rect = ui.Rect; const t = theme.color.text; pub const words = 16; +/// `in`: frames between one row's arrival and the next's (motion.md's 12: +/// the rows come while the first text is read, and its reading has them). +pub const rows_apart = 18; +/// The walked word's flights (motion.md, "A word read": 36 f, 6 f apart): +/// over its row there is room for one in the air at a time, so each is +/// 24 f and the next lifts as it comes down (18 f apart), nothing crossing +/// in the air; what follows them is `later` by as much. +const flight = 24; +const flight_apart = 18; +const later: f32 = 108 + 7 * flight_apart + flight - 186; +/// The regroup's clock, to the last word in. +pub const regroup_frames = 386 + later; const size = theme.size.mono.context; const adv = ui.advance(size); const pitch = theme.metric.context.row; @@ -148,11 +162,6 @@ pub const Words = struct { }; } - /// The word's text: its hex without the zeros in front. - fn digits(u: ui.Ui, v: u64) []const u8 { - return u.print("{x}", .{v}); - } - pub fn draw(w: *const Words, f: *sk.Frame, placed: anim.Placed) void { const u: ui.Ui = .{ .f = f, .at = placed }; const in = placed.value(w.in); @@ -161,28 +170,30 @@ pub const Words = struct { defer @import("segments.zig").unclipStage(f, was); const r = placed.value(w.regroup); const fold = placed.value(w.fold); - const shown = 1 - clamp01(fold / 6); + // Folding: the rows glide up into the header (24 f), which becomes the tag (`tag`). + const gather = glide(fold / 24); + const header_y = at.top - pitch; w.tag(u, fold); - if (shown <= 0) return; - const v = u.faded(shown); + if (gather >= 1) return; + const v = u; const data = read(w.rec, w.at); const m = w.rec.moment(w.at); // The header (mock 29), with the first row; gone as the dump is tied to its place. // The veil over every row but the walked one, while it is walked (the header too). - const veil = clamp01((r - 48) / 18) - clamp01((r - 270) / 18); - const header = clamp01(in / 18) * (1 - placed.value(w.placed)) * (1 - veil); - if (header > 0) v.faded(header).text(.sans, theme.size.sans.micro, at.address, at.top - 12, "128 bytes, from where rsp points", t.faint); + const veil = clamp01((r - 48) / 18) - clamp01((r - 270 - later) / 18); + const header = clamp01(in / 18) * (1 - placed.value(w.placed)) * (1 - veil) * (1 - clamp01((fold - 12) / 8)); + if (header > 0) v.faded(header).text(.sans, theme.size.sans.micro, at.address, at.top - 12, v.print("128 bytes at {x}", .{w.rec.register(w.at, "rsp")}), t.faint); const address_ink = ui.mix(t.faint, theme.color.region.stack, placed.value(w.placed)); const become = placed.value(w.become); const g = glide(become); for (0..words) |i| { const p = where(i, r); - const arrive = clamp01((in - 12 * @as(f32, @floatFromInt(i / 2))) / 18); + const arrive = clamp01((in - rows_apart * @as(f32, @floatFromInt(i / 2))) / 18); if (arrive <= 0) continue; - const row = v.faded(arrive * (if (i == w.walked) 1 else 1 - theme.color.veil_alpha * veil)); + const row = v.faded(arrive * (if (i == w.walked) 1 else 1 - theme.color.veil_alpha * veil) * (1 - gather)); const slot: f32 = @floatFromInt(@as(i64, @bitCast(data.base + 8 * i -% w.panel.first)) >> 3); - const y = std.math.lerp(p.y, w.panel.top + pitch * slot, g); + const y = std.math.lerp(std.math.lerp(p.y, header_y, gather), w.panel.top + pitch * slot, g); const base = theme.baseline(y, pitch, size); // The bytes go first (9 f), then the addresses travel right to the slots' column: never over them. const ax = std.math.lerp(at.address, w.panel.x + theme.metric.slot.address, glide((become - 0.25) / 0.75)); @@ -195,13 +206,16 @@ pub const Words = struct { const framed = placed.value(w.framed); if (framed >= 0) for (w.three, 0..) |i, k| { const shows = clamp01((framed - 30 * @as(f32, @floatFromInt(k))) / 6); - if (shows > 0) v.read(w.wordRect(i, data.words[i], placed), shows); + var rect = w.wordRect(i, data.words[i], placed); + rect.y = std.math.lerp(rect.y, header_y, gather); + if (shows > 0) v.faded(1 - gather).read(rect, shows); }; } /// Word `i`'s digits as they stand in the field (ranged right, or at its left). fn wordRect(w: *const Words, i: usize, value: u64, placed: anim.Placed) Rect { - const n: f32 = @floatFromInt(ui.digits(value)); + // A number that is no address as the stack panel writes it (`0x` in front): see `drawWord`. + const n: f32 = if (rows.regionOf(w.rec.moment(w.at), value) == .none) ui.Value.of(value, false).width() / adv else @floatFromInt(ui.digits(value)); const left = glide(placed.value(w.left) / 24); const x = std.math.lerp(at.field_end - n * adv, at.field, left); return .{ .x = x, .y = at.top + pitch * @as(f32, @floatFromInt(i)), .w = n * adv, .h = pitch }; @@ -215,7 +229,7 @@ pub const Words = struct { const b = i * 8 + k; if (i == w.walked and r >= 108) { // In flight or landed: a faint copy fades into its place from a third of its flight. - const copy = clamp01((r - 120 - 6 * @as(f32, @floatFromInt(k))) / 12); + const copy = clamp01((r - 108 - 8 - flight_apart * @as(f32, @floatFromInt(k))) / 12); if (copy > 0) u.faded(copy).text(.mono, size, bx, base, u.print("{x:0>2}", .{data.bytes[b]}), dimmed()); continue; } @@ -232,7 +246,7 @@ pub const Words = struct { /// How far the run has brought word `i` in (its word in, its bytes dim): 8 f, rows 6 f apart. fn runIn(w: *const Words, i: usize, r: f32) f32 { const q: f32 = @floatFromInt(if (i > w.walked) i - 1 else i); - return clamp01((r - 288 - 6 * q) / 8); + return clamp01((r - 288 - later - 6 * q) / 8); } fn walkedFrame(w: *const Words, placed: anim.Placed) f32 { @@ -242,7 +256,7 @@ pub const Words = struct { } fn drawWord(w: *const Words, u: ui.Ui, m: Recording.Moment, value: u64, i: usize, y: f32, r: f32, placed: anim.Placed) void { - const shows = if (i == w.walked) @as(f32, if (r >= 240) 1 else 0) else w.runIn(i, r); + const shows = if (i == w.walked) @as(f32, if (r >= 240 + later) 1 else 0) else w.runIn(i, r); if (shows <= 0) return; const v = u.faded(shows); const kind = rows.regionOf(m, value); @@ -279,88 +293,116 @@ pub const Words = struct { return; } } - if (kind == .none) v.text(.mono, size, rect.x, base, digits(u, value), ink) else _ = v.address(rect.x, base, value, .{ .ink = ink, .rwx = kind == .rwx }); + if (kind == .none) _ = v.value(rect.x, base, value, false, .{ .ink = ui.rgb(ink) }) else _ = v.address(rect.x, base, value, .{ .ink = ink, .rwx = kind == .rwx }); const frame = if (i == w.walked) w.walkedFrame(placed) else 0; if (frame > 0) v.read(rect, frame); } /// The walked word, from its offsets to its sixteen digits (motion.md, "A word read"). fn walk(w: *const Words, u: ui.Ui, data: Bytes, r: f32) void { - if (r < 66 or r >= 240) return; + if (r < 66 or r >= 240 + later) return; const y = at.top + pitch * @as(f32, @floatFromInt(w.walked)); const base = theme.baseline(y, pitch, size); const value = data.words[w.walked]; - // A row near the dump's top has no room over it for the arcs at x2 (the camera's frame - // begins two rows over the header): there the bytes fly under the row, over the veiled - // rows, and the offsets and labels stand over it, the header's place (veiled with the rest). + // A row near the dump's top (at x2 the camera's frame has a row and a half over the header): + // its offsets stand over it, in the header's row (veiled with the rest), `low byte` left of + // `+0` and `high byte` right of `+7`; the bytes fly over that row (40 up), one at a time, + // each with its offset over it, its label going as it lifts and coming on the other side as + // it lands, so that nothing in the air crosses what stands, and no row of memory is printed over. const flip = w.walked < 4; const dir: f32 = if (flip) -1 else 1; // Under the row (over it, flipped), its offsets and labels on the page (the veiled rows there give way). // They go as the gaps close (192), not after: closed, their pairs are 24 apart and they would touch. - const labels = clamp01((r - 84) / 12) * (1 - clamp01((r - 192) / 12)); - const offsets = clamp01((r - 66) / 12) * (1 - clamp01((r - 192) / 12)); - const zeros_mark = clamp01((r - 204) / 12) * (1 - clamp01((r - 228) / 12)); + const labels = clamp01((r - 84) / 12) * (1 - clamp01((r - 192 - later) / 12)); + const offsets = clamp01((r - 66) / 12) * (1 - clamp01((r - 192 - later) / 12)); + const zeros_mark = clamp01((r - 204 - later) / 12) * (1 - clamp01((r - 228 - later) / 12)); const page_x = at.bytes - 12; const page_w = at.field_end - at.bytes + 24; - if (offsets > 0) u.faded(offsets).fill(.{ .x = page_x, .y = if (flip) y - 2 * pitch - 6 else y + pitch, .w = page_w, .h = 2 * pitch + 6 }, theme.color.page); - if (zeros_mark > 0) u.faded(zeros_mark).fill(.{ .x = page_x, .y = y + pitch, .w = page_w, .h = 2 * pitch + 6 }, theme.color.page); - const close = glide((r - 192) / 12); + if (!flip and offsets > 0) u.faded(offsets).fill(.{ .x = page_x, .y = y + pitch, .w = page_w, .h = 2 * pitch + 6 }, theme.color.page); + const close = glide((r - 192 - later) / 12); for (0..8) |k| { const kf: f32 = @floatFromInt(k); - const s = clamp01((r - 108 - 6 * kf) / 36); + const s = clamp01((r - 108 - flight_apart * kf) / flight); const from = at.bytes + kf * at.pair; const pair = 7 - kf; const to = std.math.lerp(at.field + pair * at.pair, at.field_end - (8 - pair) * 2 * adv, close); - const long = to - from; - const high = std.math.clamp(long / 4, theme.time.flight.arc_min, theme.time.flight.arc_max); - const x = std.math.lerp(from, to, theme.ease(.glide, s)); - const lift = dir * high * @sin(std.math.pi * s); + // Up off its place, over, down onto it; flipped, a plateau 40 up, the same for all (one flies at a time). + var x: f32 = undefined; + var lift: f32 = undefined; + var across: f32 = undefined; + if (flip) { + across = glide((s - 0.1) / 0.8); + x = std.math.lerp(from, to, across); + // Clear of the offsets standing in the row over it; one in the air at a time, so one height. + lift = 40 * @min(theme.ease(.glide, clamp01(s / 0.25)), theme.ease(.glide, clamp01((1 - s) / 0.25))); + } else { + across = theme.ease(.glide, s); + x = std.math.lerp(from, to, across); + const high = std.math.clamp((to - from) / 4, theme.time.flight.arc_min, theme.time.flight.arc_max); + lift = high * @sin(std.math.pi * s); + } // The byte itself: bright and bold in the air (from 108 the walk draws it, not the row). if (r >= 108) { const air = s > 0 and s < 1; const text = u.print("{x:0>2}", .{data.bytes[w.walked * 8 + k]}); // In the air it carries its ground: over the veiled rows it reads alone. - if (air) u.fill(.{ .x = x - 3, .y = base - lift - 18, .w = 2 * adv + 6, .h = 24 }, theme.color.page); + if (air) u.fill(.{ .x = x - 3, .y = base - lift - 17, .w = 2 * adv + 6, .h = 20 }, theme.color.page); // Each digit of a pair on its own: a zero in front of the word fades on its own. for (0..2) |d| { const lead = 2 * (7 - k) + d < 16 - ui.digits(value); - const fade: f32 = if (lead and r >= 228) 1 - clamp01((r - 228) / 12) else 1; + const fade: f32 = if (lead and r >= 228 + later) 1 - clamp01((r - 228 - later) / 12) else 1; if (fade > 0) u.faded(fade).text(if (air) .mono_bold else .mono, size, x + @as(f32, @floatFromInt(d)) * adv, base - lift, text[d .. d + 1], if (air) t.bright else t.primary); } } - // Its offset under it, going with it. + // Its offset under it (over it, flipped), going with it (in the air 22 over it: the frame's top is near). const off = offsets * clamp01((r - 66 - 2 * kf) / 12); - if (off > 0 and s > 0 and s < 1) u.faded(off).fill(.{ .x = x - 3, .y = base + dir * pitch - lift - 18, .w = 2 * adv + 6, .h = 24 }, theme.color.page); - if (off > 0) u.faded(off).text(.mono, size, x, base + dir * pitch - lift, u.print("+{d}", .{k}), t.dim); + const off_base = base + dir * (if (flip) std.math.lerp(pitch, 22, clamp01(lift / 40)) else pitch) - lift; + if (off > 0 and s > 0 and s < 1) u.faded(off).fill(.{ .x = x - 3, .y = off_base - 18, .w = 2 * adv + 6, .h = 24 }, theme.color.page); + if (off > 0) u.faded(off).text(.mono, size, x, off_base, u.print("+{d}", .{k}), t.dim); // `low byte` from its byte's left, `high byte` to its byte's right: under the bytes, never the addresses. + // Flipped: beside its offset, outside the run, the low byte's on the left at rest and on the right + // landed (the word reads it last); it goes as its byte lifts and comes as it lands, never crossing its offset. if (k == 0 or k == 7) if (labels > 0) { const label = if (k == 0) "low byte" else "high byte"; const lw = u.width(.sans, theme.size.sans.tag, label); - u.faded(labels).text(.sans, theme.size.sans.tag, if (k == 0) x else x + 2 * adv - lw, base + dir * 2 * pitch + 2 - lift, label, t.dim); + const left = x - lw - adv / 2; + const right = x + 2 * adv + adv / 2; + const landing = s >= 0.5; + const lx = if (!flip) (if (k == 0) x else x + 2 * adv - lw) else if ((k == 0) == landing) right else left; + const ly = if (flip) off_base else base + 2 * pitch + 2 - lift; + // (`high byte`, right of `+7` at rest, would stand where `+6` lands: it goes as `+6` lifts.) + const gone = if (k == 7) clamp01((r - 108 - flight_apart * 6) / flight / 0.2) else clamp01(s / 0.2); + const there: f32 = if (!flip) 1 else if (landing) clamp01((s - 0.8) / 0.2) else 1 - gone; + if (there > 0) u.faded(labels * there).text(.sans, theme.size.sans.tag, lx, ly, label, t.dim); }; } - // The zeros in front, bracketed (motion.md: 204 to 228). + // The zeros in front, bracketed (motion.md: 204 to 228, here `later`), on a ground only as wide as its label. if (zeros_mark > 0) { const lead: f32 = @floatFromInt(16 - ui.digits(value)); const x0 = at.field_end - 16 * adv; const v = u.faded(zeros_mark); + const said = "zeros in front"; + v.fill(.{ .x = x0 - 4, .y = y + pitch + 2, .w = v.width(.sans, theme.size.sans.tag, said) + 8, .h = pitch - 2 }, theme.color.page); v.fill(.{ .x = x0, .y = y + pitch - 2, .w = lead * adv, .h = 2 }, t.dim); v.fill(.{ .x = x0, .y = y + pitch - 8, .w = 2, .h = 6 }, t.dim); v.fill(.{ .x = x0 + lead * adv - 2, .y = y + pitch - 8, .w = 2, .h = 6 }, t.dim); - v.text(.sans, theme.size.sans.tag, x0, base + pitch + 2, "zeros in front", t.dim); + v.text(.sans, theme.size.sans.tag, x0, base + pitch + 2, said, t.dim); } } - /// The dump folded to its tag on the shelf (mock 49's shelf, y 48): the - /// rows out over 6 f, the tag from over the rows to the shelf (18 f, `glide`). + /// The dump folded to its tag on the shelf (mock 49's shelf, y 48): as + /// the rows gather into the header, the header becomes the tag (the + /// header out 12 to 20, the tag in 16 to 24, its title where the + /// header's was), which then goes to the shelf (24 f, `glide`); back, + /// the reverse. fn tag(_: *const Words, u: ui.Ui, fold: f32) void { - if (fold <= 0) return; - const title = "the stack's 128 bytes"; - const p = glide((fold - 6) / 18); + if (fold <= 16) return; + const title = "the 128 bytes"; + const p = glide((fold - 24) / 24); const w = u.width(.sans_medium, theme.size.sans.tag, title) + 40; - const x = std.math.lerp(at.address - 8, theme.canvas.margin_x, p); + const x = std.math.lerp(at.address - 28, theme.canvas.margin_x, p); const y = std.math.lerp(at.top - 30, theme.canvas.stage.y, p); - const v = u.faded(clamp01(fold / 6)).moved(x, y); + const v = u.faded(clamp01((fold - 16) / 8)).moved(x, y); v.fill(.{ .x = 0, .y = 0, .w = w, .h = theme.metric.context.tag }, theme.color.raised); v.frame(.{ .x = 8, .y = 6, .w = 12, .h = 12 }, t.faint, theme.stroke.rule); v.text(.sans_medium, theme.size.sans.tag, 28, theme.metric.context.tag - 6, title, t.dim); diff --git a/anim/src/rows.zig b/anim/src/rows.zig index 08f1fb2..bdf9454 100644 --- a/anim/src/rows.zig +++ b/anim/src/rows.zig @@ -326,9 +326,20 @@ pub fn slot(u: ui.Ui, y: f32, w: f32, moment: Recording.Moment, addr: u64, from_ return chain(u, at, y, moment, held, room, lead); } +/// The stack panel's offsets written with `0x` while it draws its rows +/// (`Levels.introduction`), where hex and decimal differ (10 and over), as +/// an instruction's operands and a value are (`-8`, `-0x18`). +pub var prefixed = false; + +/// `0x` in front of `n` (`prefixed`), or nothing. +pub fn hexMark(n: u64) []const u8 { + return if (prefixed and n >= 10) "0x" else ""; +} + /// A slot's offset from rsp, `from_rsp` bytes: hex, faint, ranged right to 172. fn offset(u: ui.Ui, y: f32, from_rsp: i64) void { - const text = if (from_rsp < 0) u.print("-{x}", .{@as(u64, @intCast(-from_rsp))}) else u.print("+{x}", .{@as(u64, @intCast(from_rsp))}); + const p = hexMark(@abs(from_rsp)); + const text = if (from_rsp < 0) u.print("-{s}{x}", .{ p, @as(u64, @intCast(-from_rsp)) }) else u.print("+{s}{x}", .{ p, @as(u64, @intCast(from_rsp)) }); u.text(.mono, size, theme.metric.slot.offset - u.width(.mono, size, text), baseline(y), text, t.faint); } diff --git a/anim/src/segments.zig b/anim/src/segments.zig index db9d28f..a304993 100644 --- a/anim/src/segments.zig +++ b/anim/src/segments.zig @@ -572,6 +572,10 @@ pub const Place = struct { /// Frames into the tie (negative: not begun); frames into its quieting. clock: anim.Value, quiet: anim.Value, + /// 0 to 1: the dump's place marked on its box for a camera's visit (it + /// is far thinner than a unit there): a 2-unit tick across the box in + /// the stack's ink, `128 bytes` over it, left of where the link comes down. + tick: ?anim.Value = null, pub fn draw(p: *const Place, f: *sk.Frame, placed: anim.Placed) void { const clock = placed.value(p.clock); @@ -590,9 +594,15 @@ pub const Place = struct { u.route(&.{ .{ p.x, p.y0 }, .{ p.x, top }, .{ to[0], top }, .{ to[0], to[1] } }, ink, .{ .width = theme.stroke.tie.link, .head = .{ 10, 10 }, .progress = drawn, .radius = 8 }); // The stack's band framed bright as the head lands. const bright = std.math.clamp((clock - 42) / 6, 0, 1) * (1 - std.math.clamp((clock - 48) / 12, 0, 1)); - if (bright > 0) for (l.space.clusters, 0..) |c, i| if (i < 6 and p.addr >= c.lo and p.addr < c.hi) { + const marked = if (p.tick) |tv| std.math.clamp(placed.value(tv), 0, 1) else 0; + if (bright > 0 or marked > 0) for (l.space.clusters, 0..) |c, i| if (i < 6 and p.addr >= c.lo and p.addr < c.hi) { const b = l.boxes[i]; - u.faded(bright).frame(.{ .x = b.x - 5, .y = b.y - 5, .w = b.w + 10, .h = b.h + 10 }, t.bright, theme.stroke.line); + if (bright > 0) u.faded(bright).frame(.{ .x = b.x - 5, .y = b.y - 5, .w = b.w + 10, .h = b.h + 10 }, t.bright, theme.stroke.line); + if (marked > 0) { + const label = "128 bytes"; + u.faded(marked).fill(.{ .x = b.x, .y = to[1] - 1, .w = b.w, .h = 2 }, region.stack); + u.faded(marked).text(.sans, theme.size.sans.tag, to[0] - 8 - u.width(.sans, theme.size.sans.tag, label), to[1] - 6, label, region.stack); + } }; } }; diff --git a/anim/src/ties.zig b/anim/src/ties.zig index b5214e3..3048e32 100644 --- a/anim/src/ties.zig +++ b/anim/src/ties.zig @@ -765,7 +765,10 @@ const Cx = struct { line.target = .beyond; line.words = bb.words; } else return; - cx.linkTo(line, drawn, back); + // Drawn back toward its head, the head goes over the last third, not in a frame. + var faded = cx; + faded.raw = cx.raw.faded(1 - std.math.clamp((back - 2.0 / 3.0) * 3, 0, 1)); + faded.linkTo(line, drawn, back); } /// The step's projection: the first run of bytes it read or wrote in @@ -862,7 +865,9 @@ const Cx = struct { } const right = row_box[2]; // How much it shows: standing with the knob (18 f in and out), for the step from the word's mark to the advance. - var drawn: f32 = 1; + // Standing, drawn as a step's when the scene says (`aim(.drawn)`): head first, then the row's frame. + var drawn: f32 = if (step) 1 else cursors.standard(std.math.clamp(now.aim_drawn / 18.0, 0, 1)); + var framed: f32 = if (step) 1 else std.math.clamp((now.aim_drawn - 18.0) / 6.0, 0, 1); var shows: f32 = if (step) 1 else @min(now.aim, 1); if (step) { if (now.resting()) return; @@ -870,23 +875,24 @@ const Cx = struct { const long = @abs(y_row - y_word) > 10 * theme.metric.context.row * k; drawn = cursors.standard(std.math.clamp((now.time - from) / @as(f32, if (long) 24.0 / 60.0 else 18.0 / 60.0), 0, 1)); shows = 1 - std.math.clamp((now.time - now.plan.advance) / time.quick, 0, 1); + framed = if (drawn >= 1) 1 else 0; } if (drawn <= 0 or shows <= 0) return; - // Standing, 60% toward the page; fraying, dashed over its first 12 f, then fading. - const ink = if (step) ui.rgb(theme.color.region.code_) else ui.mix(theme.color.region.code_, theme.color.page, 0.6); + // Standing, 60% toward the page (at full ink while lit); fraying, dashed over its first 12 f, then fading. + const ink = if (step) ui.rgb(theme.color.region.code_) else ui.mix(theme.color.region.code_, theme.color.page, 0.6 * (1 - std.math.clamp(now.aim_lit, 0, 1))); const v = cx.raw.faded(shows * (1 - std.math.clamp((fray - 0.4) / 0.6, 0, 1))); const points = [4]ui.Vec{ .{ rule, y_word }, .{ lane, y_word }, .{ lane, y_row }, .{ right, y_row } }; if (fray > 0) { // Dashed, 12 on 8, the gaps opening over the fray's first 12 f. const open = std.math.clamp(fray / 0.4, 0, 1); dashed(v, &points, ink, theme.stroke.rule * k, 12 * k, 8 * k * open); - } else v.route(&points, ink, .{ .width = theme.stroke.rule * k, .head = .{ 8 * k, 8 * k }, .progress = drawn, .radius = theme.metric.tie.radius * k }); + } else v.route(&points, ink, .{ .width = theme.stroke.rule * k, .head = .{ 10 * k, 10 * k }, .progress = drawn, .radius = theme.metric.tie.radius * k }); // The row's address framed in code's ink as the head lands. - if (drawn >= 1 and fray == 0) { + if (drawn >= 1 and fray == 0 and framed > 0) { const adv = ui.advance(theme.size.mono.context) * k; const digits: f32 = @floatFromInt(ui.digits(if (row_box[1] == line.to[1]) line.value else line.was)); const x0 = row_box[0] + (theme.metric.insn.address - 4) * k; - v.frame(.{ .x = x0, .y = row_box[1], .w = digits * adv + 8 * k, .h = row_box[3] - row_box[1] }, ink, theme.stroke.rule * k); + v.faded(framed).frame(.{ .x = x0, .y = row_box[1], .w = digits * adv + 8 * k, .h = row_box[3] - row_box[1] }, ink, theme.stroke.rule * k); } } }; diff --git a/anim/src/ui.zig b/anim/src/ui.zig index 589bfb6..eeac127 100644 --- a/anim/src/ui.zig +++ b/anim/src/ui.zig @@ -555,13 +555,14 @@ pub const Ui = struct { u.fill(.{ .x = cx - p.stub / 2, .y = y + p.under_head[0] - 1, .w = p.stub, .h = rise - p.under_head[0] + 1 }, ink); sk.draw.polygon(u.f, &.{ .{ cx, y + 1 }, .{ cx - p.under_head[1] / 2, y + 1 + p.under_head[0] }, .{ cx + p.under_head[1] / 2, y + 1 + p.under_head[0] } }, u.at.pen(.{ .fill = rgb(ink) })); if (names.len == 0) return; - u.pinNames(cx, y, names, inks, size); + u.pinNames(cx, y, names, inks, size, 0); } /// The names of a `pin` `under`: the first left of the stub, the - /// second right of it ("" for a side kept free), the rest a count; - /// each bold in `inks` (a variable's: where it lives) or primary. - pub fn pinNames(u: Ui, cx: f32, y: f32, names: []const []const u8, inks: []const u24, size: f32) void { + /// second right of it ("" for a side kept free), the rest a count, or + /// by name where they fit before `room` (an x; 0: none); each bold in + /// `inks` (a variable's: where it lives) or primary. + pub fn pinNames(u: Ui, cx: f32, y: f32, names: []const []const u8, inks: []const u24, size: f32, room: f32) void { const p = theme.metric.pin; const by = y + 8 + size * 0.86; const ink = struct { @@ -573,7 +574,15 @@ pub const Ui = struct { // One name a side: a node's neighbour has its own. The rest are a count. if (names.len > 1) { u.text(.mono_bold, size, cx + p.under_names, by, names[1], ink(inks, 1)); - if (names.len > 2) u.text(.mono_bold, size, cx + p.under_names + u.width(.mono, size, names[1]) + advance(size) / 2, by, u.print("+{d}", .{names.len - 2}), theme.color.text.primary); + var x = cx + p.under_names + u.width(.mono, size, names[1]) + advance(size) / 2; + var end = x; + for (names[2..]) |n| end += u.width(.mono, size, n) + advance(size) / 2; + if (names.len > 2 and end - advance(size) / 2 <= room) { + for (names[2..], 2..) |n, i| { + u.text(.mono_bold, size, x, by, n, ink(inks, i)); + x += u.width(.mono, size, n) + advance(size) / 2; + } + } else if (names.len > 2) u.text(.mono_bold, size, x, by, u.print("+{d}", .{names.len - 2}), theme.color.text.primary); } } |
