diff options
Diffstat (limited to 'anim/src')
| -rw-r--r-- | anim/src/array.zig | 1 | ||||
| -rw-r--r-- | anim/src/context.zig | 90 | ||||
| -rw-r--r-- | anim/src/cursor.zig | 13 | ||||
| -rw-r--r-- | anim/src/disasm.zig | 3 | ||||
| -rw-r--r-- | anim/src/hexdump.zig | 81 | ||||
| -rw-r--r-- | anim/src/loupe.zig | 181 | ||||
| -rw-r--r-- | anim/src/map.zig | 286 | ||||
| -rw-r--r-- | anim/src/nodes.zig | 1 | ||||
| -rw-r--r-- | anim/src/objects.zig | 11 | ||||
| -rw-r--r-- | anim/src/root.zig | 30 | ||||
| -rw-r--r-- | anim/src/rows.zig | 174 | ||||
| -rw-r--r-- | anim/src/source.zig | 3 | ||||
| -rw-r--r-- | anim/src/theme.zig | 139 | ||||
| -rw-r--r-- | anim/src/ties.zig | 9 | ||||
| -rw-r--r-- | anim/src/ui.zig | 117 | ||||
| -rw-r--r-- | anim/src/words.zig | 8 |
16 files changed, 1045 insertions, 102 deletions
diff --git a/anim/src/array.zig b/anim/src/array.zig index d9216c3..8bb0a52 100644 --- a/anim/src/array.zig +++ b/anim/src/array.zig @@ -81,6 +81,7 @@ pub const Array = struct { const dump = hexdump.panel(f, at, g.stage, u.print("{x} to {x}, an element a run", .{ v.addr, v.addr + v.size - 1 }), &.{}); const rows_n = @min(dump.rows, (v.addr + v.size - first + 15) / 16); if (rows_n > 0) hexdump.draw(dump.u, now, 0, m.tag + m.pad, first, rows_n, .{ .array = .{ .addr = v.addr, .len = v.size, .elem = @intCast(elem), .type = elem_type }, .region = context.ink(context.regionOf(moment, v.addr)) }); + if (rows_n > 0) @import("map.zig").window(.view, first, first + 16 * (rows_n - 1)); dump.veil(now); u.clip(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); } diff --git a/anim/src/context.zig b/anim/src/context.zig index 9874cd7..e5a226a 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -16,6 +16,8 @@ const cursors = @import("cursor.zig"); const Recording = @import("Recording.zig"); const syscalls = @import("syscalls.zig"); const ties = @import("ties.zig"); +const hexdump = @import("hexdump.zig"); +const map = @import("map.zig"); const Stage = @import("stage.zig").Stage; const theme = ui.theme; const time = theme.time; @@ -39,9 +41,28 @@ pub const legend = blk: { }; }; -/// A panel's `Ui`, moved to where the stage has its box now. +/// While a `dive` or a `surface` plays (`map.Map`): each working panel's +/// box, and the rect it is drawn into instead, on its way between its +/// window on the map and its place; its tags, rules and lanes how much shown. +pub const Zoom = struct { box: Rect, to: Rect, chrome: f32 }; +pub var zoomed: [8]?Zoom = @splat(null); + +/// A panel's `Ui`, moved to where the stage has its box now (or, in a +/// dive, scaled into the rect it is on its way through). pub fn at(f: *sk.Frame, placed: anim.Placed, box: Rect) ui.Ui { - return (ui.Ui{ .f = f, .at = placed }).moved(box.x, box.y); + var p = placed; + ui.chrome = 1; + if (!ui.mapping) for (zoomed) |z| if (z) |zz| if (@abs(zz.box.x - box.x) < 0.5 and @abs(zz.box.y - box.y) < 0.5 and @abs(zz.box.h - box.h) < 0.5) { + const k = zz.to.w / box.w; + p.xf = p.xf.mul(.translate(zz.to.x, zz.to.y)).mul(.scale(k, k)).mul(.translate(-box.x, -box.y)); + p.scale *= k; + // On its way it is opaque, over the panels that set off before it; its tag and rules come in at the end. + const u = (ui.Ui{ .f = f, .at = p }).moved(box.x, box.y); + u.fill(.{ .x = 0, .y = m.tag, .w = box.w, .h = box.h - m.tag }, theme.color.page); + ui.chrome = zz.chrome; + return u; + }; + return (ui.Ui{ .f = f, .at = p }).moved(box.x, box.y); } pub fn veiled(u: ui.Ui, box: Rect, amount: f32) void { @@ -106,18 +127,19 @@ pub const Registers = struct { fn rip(r: *const Registers, u: ui.Ui, now: cursors.Now, y: f32, w: f32, is: Shown, was: Shown) void { const rec = r.cursor.rec; const moment = now.marks[if (now.advancing() >= 0.5) 1 else 0]; - // The flags' ticks are secondary: 6 f after the registers strike, + // The flags' corners are secondary: 6 f after the registers strike, // not with them; in a continue's wave, in its place after r15. const delay = if (now.plan.wave) ties.strikeDelay(now, index("eflags").?) else cursors.write_apart; const landed = now.landed(.cpu, delay); const flags = (if (landed) is else was).regs.eflags; - // The flags a step changed are ticked, for three steps. + // The flags a step changed have a turned corner, for three steps. const eflags_index = comptime index("eflags").?; - // Until this step's change lands, the ticks are the last one's: no effect before its cause. + // Until this step's change lands, the corners are the last one's: no effect before its cause. const age = if (landed) now.registerAge(eflags_index) else now.registerAgeFrom(eflags_index, 1); var changed: u64 = 0; if (age) |a| changed = rec.register(now.stops[a], "eflags") ^ rec.register(now.stops[a + 1], "eflags"); - const held = if (r.quiet) 0 else now.register(eflags_index, delay).level; + const heat = now.register(eflags_index, delay); + const held = if (r.quiet) 0 else heat.level * heat.corner; rows.rip(u, y, w, rec.moment(moment), rec.register(moment, "rip"), flags, changed, held, 0); } @@ -283,6 +305,8 @@ pub const Stack = struct { cursor: cursors.Cursor, stage: *const Stage, focus: bool = false, + /// On the map: the window from this many words above rsp, not scrolled. + above: u32 = 0, pub fn draw(k: *const Stack, f: *sk.Frame, placed: anim.Placed) void { const box = k.stage.box(placed, .stack); @@ -301,7 +325,7 @@ pub const Stack = struct { const hold = placed.value(k.stage.hold); const held = hold >= 0; const held_at: u64 = if (held) rec.register(@intFromFloat(hold), "rsp") -% 8 * @as(u64, @intFromFloat(placed.value(k.stage.hold_free))) else 0; - var window = if (held) [2]u64{ held_at, held_at } else [2]u64{ windowAt(now, is, slots, 0), windowAt(now, was, slots, 1) }; + var window = if (held) [2]u64{ held_at, held_at } else if (k.above > 0) [2]u64{ is.rsp -% 8 * @as(u64, k.above), was.rsp -% 8 * @as(u64, k.above) } else [2]u64{ windowAt(now, is, slots, 0), windowAt(now, was, slots, 1) }; // A window that goes farther than its own height (a continue to a // stop deeper or shallower than a call is) does not scroll: the old // rows fade out before memory strikes and the new ones in after, @@ -404,6 +428,16 @@ pub const Stack = struct { }.of; const size = theme.size.mono.context; const lone: ?[]const u8 = if (travel.len == 1) travel[0] else null; + // The offsets are from the rsp of the rows shown: they change with the slide, not before it. + const rsp_shown = if (landed) is.rsp else was.rsp; + // What each word is, where the recording says (`zt.telescope.slots`): + // a register saved for the caller, a local, the process's first stack. + const roles_from = window[0] -% 16; + var roles_buf: [80]zt.telescope.Slot = undefined; + const roles = zt.telescope.slots(memory, if (landed) &is else &was, roles_from, roles_buf[0..@min(slots + 4, roles_buf.len)]) catch roles_buf[0..0]; + // The words that point at other words of the window: `arc`s. + var at_rows: std.ArrayList(hexdump.RowAt) = .empty; + var pointers: std.ArrayList(struct { hexdump.RowAt, bool }) = .empty; var n: i64 = @as(i64, @intFromFloat(@floor(-slide))) - 1; while (n <= @as(i64, @intCast(slots)) - @as(i64, @intFromFloat(@floor(slide)))) : (n += 1) { const y = top + (@as(f32, @floatFromInt(n)) + slide) * m.row; @@ -416,9 +450,11 @@ pub const Stack = struct { marks.read = 0; marks.read_shows = now.reading(.memory, 0); } + const below_rsp: i64 = @bitCast(addr -% rsp_shown); + map.row(.stack, addr, u, .{ .x = 0, .y = y, .w = box.w, .h = m.row }); // `free`: above rsp, not yet reached: its address at 60%, its word faint. - if (held and addr < (if (landed) is.rsp else was.rsp)) { - rows.free(v, y, memory, addr, lead); + if (held and addr < rsp_shown) { + rows.free(v, y, memory, addr, below_rsp, lead); continue; } // A frame's name beside this row: the chain ends a character before it. @@ -435,17 +471,31 @@ pub const Stack = struct { } const gapped = gap > 0 and names.names.len > 0 and names.shows > 0; if (gapped) pinGap(v.faded(names.shows), y, names.names, lone.?, gap); - const hops = rows.slot(v, y, room_w, memory, addr, if (gapped) &.{} else names.names, names.shows, marks); + const k_role = (addr -% roles_from) / 8; + const what: zt.telescope.Role = if (k_role < roles.len) roles[k_role].role else .none; + const role = roleName(u, what, (Recording.word(memory, addr, 8) catch null) orelse 1); + const hops = rows.slot(v, y, room_w, memory, addr, below_rsp, if (gapped) &.{} else names.names, names.shows, marks, role.name, role.local); + at_rows.append(u.f.scratch, .{ .addr = addr, .y = y }) catch {}; + pointers.append(u.f.scratch, .{ .{ .addr = addr, .y = y }, what == .saved and std.mem.eql(u8, what.saved, "rbp") }) catch {}; // Only a row on show is a place a tie can land. if (y >= top - 1 and y + m.row <= box.h - m.pad + 1) { - ties.anchor(u, .{ .word = addr }, .{ .x = theme.metric.slot.chain, .y = y, .w = if (hops.n > 0) hops.x[0] + hops.w[0] - theme.metric.slot.chain else 120, .h = m.row }); + ties.anchor(u, .{ .word = addr }, .{ .x = theme.metric.slot.address, .y = y, .w = if (hops.n > 0) hops.x[0] + hops.w[0] - theme.metric.slot.address else 120, .h = m.row }); ties.anchor(u, .{ .slot_pin = addr }, .{ .x = theme.metric.slot.lane, .y = y, .w = theme.metric.slot.lane_end - theme.metric.slot.lane, .h = m.row }); } } + map.window(.stack, shown_at, shown_at + 8 * (@as(u64, slots) -| 1)); + // A frame's saved rbp is drawn by its span: its arc only in a step that touches it. + var arcs: rows.Arcs = .{}; + for (pointers.items) |p_| { + const word, const saved = p_; + if (saved and !(now.writeAge(word.addr, 8) == 0 or now.wasRead(word.addr, 8))) continue; + hexdump.pointerArcs(&arcs, now, word.addr, word.y, at_rows.items, 8, .{ top - m.pad, box.h - m.pad }, false); + } + arcs.draw(v, theme.metric.arc.stack_lanes); // Where the window is, for a link to a word outside it. const lane_at = u.at.xf.apply(.{ theme.metric.slot.lane, top }); const row_px = u.at.xf.apply(.{ 0, top + m.row })[1] - lane_at[1]; - ties.stack_window = .{ .first = window[0], .slots = slots, .x = lane_at[0], .top = lane_at[1], .row = row_px }; + if (!ui.mapping) ties.stack_window = .{ .first = window[0], .slots = slots, .x = lane_at[0], .top = lane_at[1], .row = row_px }; // The travelling tags: both of them at one word share a pin. var places: [2]f32 = undefined; for (travel, places[0..travel.len]) |name, *place| { @@ -465,6 +515,22 @@ pub const Stack = struct { veiled(u, box, now.veil); } + /// A slot's role as the catalogue writes it: `saved rbx` (dim); a + /// local's name (primary, `+8` a word into it); `argc`, `argv[0]`, + /// `argv end`, `envp end`, `auxv` (dim). A return address needs none: + /// its chain is code, named. `word`: what the slot holds (0 ends argv and envp). + fn roleName(u: ui.Ui, role: zt.telescope.Role, word: u64) struct { name: []const u8, local: bool = false } { + return switch (role) { + .none, .return_address => .{ .name = "" }, + .saved => |r| .{ .name = u.print("saved {s}", .{r}) }, + .local => |l| .{ .name = if (l.offset > 0) u.print("{s}+{x}", .{ l.name, @as(u32, @intCast(l.offset)) }) else l.name, .local = true }, + .argc => .{ .name = "argc" }, + .argv => |i| .{ .name = if (word == 0) "argv end" else u.print("argv[{d}]", .{i}) }, + .envp => |i| .{ .name = if (word == 0) "envp end" else u.print("envp[{d}]", .{i}) }, + .auxv => |i| .{ .name = if (i == 0) "auxv" else "" }, + }; + } + /// Where `name` goes in a row pin of `others` and it, in the registers' order. fn pinPlace(u: ui.Ui, others: []const []const u8, name: []const u8) f32 { const size = theme.size.mono.context; diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig index f196fab..6a02948 100644 --- a/anim/src/cursor.zig +++ b/anim/src/cursor.zig @@ -596,12 +596,17 @@ pub const Now = struct { if (since_strike >= -s.arm) armed.arm = std.math.clamp((since_strike + s.arm) / time.stagger, 0, 1); return armed; } + const cooled = (n.time - n.plan.advance) / s.cool; + const in = std.math.clamp(since_strike / s.in, 0, 1); return .{ .level = 1, - .solid = 1 - glide(std.math.clamp((n.time - n.plan.advance) / s.cool, 0, 1)), - .in = std.math.clamp(since_strike / s.in, 0, 1), + .solid = 1 - glide(std.math.clamp(cooled, 0, 1)), + .in = in, .from = if (was.level >= 1) .ember else .nothing, .out = if (since_strike < s.pulse) theme.pulse(since_strike / s.pulse) else 0, + // The turned corner: the old one goes as the paper comes in over + // it; the new one comes in over the cool's last 6 f. + .corner = @max(std.math.clamp((cooled - 1) * s.cool / s.corner + 1, 0, 1), if (was.level >= 1) 1 - in else 0), }; } @@ -683,8 +688,12 @@ test "a write is armed, strikes, holds, cools with the advance, and leaves after // Held solid until the mark leaves, then cooled, halfway at the middle. h = instant(0.89, plan).heat(0, null, 0.59); try expect(h.solid == 1 and h.in == 1 and h.out == 0); + try expect(h.corner == 0); h = instant(0.90 + s.cool / 2.0, plan).heat(0, null, 0.8); try std.testing.expectApproxEqAbs(@as(f32, 0.5), h.solid, 1e-3); + // The turned corner: none until the cool's last 6 f, then in. + try expect(h.corner == 0); + try std.testing.expectApproxEqAbs(@as(f32, 0.5), instant(0.90 + s.cool - s.corner / 2.0, plan).heat(0, null, 1).corner, 1e-3); // At rest, and for the steps after: the ember; then it goes. const rest = instant(std.math.inf(f32), plan); try expectEqual(ui.Heat.ember, rest.heat(0, null, std.math.inf(f32))); diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig index 6c28516..7f17ed6 100644 --- a/anim/src/disasm.zig +++ b/anim/src/disasm.zig @@ -17,6 +17,7 @@ const rows = @import("rows.zig"); const cursors = @import("cursor.zig"); const Recording = @import("Recording.zig"); const ties = @import("ties.zig"); +const map = @import("map.zig"); const context = @import("context.zig"); const Stage = @import("stage.zig").Stage; const theme = ui.theme; @@ -157,6 +158,7 @@ pub const Disasm = struct { break :blk rec.register(at - 1, "rip"); }; + if (shown.rows.len > 0) map.window(.disasm, shown.rows[0].addr, shown.rows[shown.rows.len - 1].addr); var last_line: ?u32 = null; // A source of many lines (SQLite's) has wider numbers, as wide as // its largest: what is right of them moves right by as much. @@ -182,6 +184,7 @@ pub const Disasm = struct { covered -|= 1; continue; } + map.row(.disasm, row.addr, u, .{ .x = 0, .y = y, .w = box.w, .h = m.row }); const is_pc = row.addr == pc[if (going >= 0.5) 1 else 0]; const was = if (is_pc) null else ran[j]; if (was) |r| lit.trail(c.mark, y, r.k); diff --git a/anim/src/hexdump.zig b/anim/src/hexdump.zig index fba212d..f1087ab 100644 --- a/anim/src/hexdump.zig +++ b/anim/src/hexdump.zig @@ -147,9 +147,19 @@ pub const View = struct { /// The dump: `count` rows from `first`, at `x` in `u` (the view's /// panel), the rows from `y`. The rows of what the drawing draws have -/// quiet brackets. +/// quiet brackets; a pointer to another of its rows, an `arc` (full ink +/// always, with `loud`: a loupe's). `rule`: the panel's top and bottom, +/// where a stub to a row past the window ends. pub fn draw(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize, of: Of) void { + drawArcs(u, now, x, y, first, count, of, false, .{ y - m.pad, y + @as(f32, @floatFromInt(count)) * m.row + m.pad }); +} + +pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize, of: Of, loud: bool, rule: [2]f32) void { const v = u.moved(x, 0); + var arcs: rows.Arcs = .{}; + var at_rows: [64]RowAt = undefined; + for (at_rows[0..@min(count, at_rows.len)], 0..) |*r, i| r.* = .{ .addr = first + 16 * i, .y = y + @as(f32, @floatFromInt(i)) * m.row }; + const shown_rows = at_rows[0..@min(count, at_rows.len)]; const moment = now.shown(.memory); const lead = ui.shared(&.{ first, first + 16 * @as(u64, count -| 1) }); // Room for the addresses, once for the dump: by its widest. @@ -204,7 +214,9 @@ pub fn draw(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize n += 1; at += run.len; } + @import("map.zig").row(.view, addr, v, .{ .x = 0, .y = ry, .w = theme.layout.state.w, .h = m.row }); rows.bytesAt(v, ry, addr, &values, &known, runs[0..n], of.region, lead, holds_drawn, moment, shift); + for (runs[0..n]) |run| if (run.kind == .pointer and run.len == 8) pointerArcs(&arcs, now, addr + run.first, ry, shown_rows, 16, rule, loud); const end = reading(v, ry, shift, moment, &values, &known, readings[0..n]); // The size word of the chunk after: malloc's, a note after the reading. const last = runs[n - 1]; @@ -213,6 +225,64 @@ pub fn draw(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize v.text(.sans, theme.size.sans.micro, end, rows.baseline(ry) - 1, v.print("malloc's: a chunk of {d}", .{size}), t.faint); } } + arcs.draw(v, theme.metric.arc.lanes.len); +} + +/// A row of a panel: its first byte's address and its top. +pub const RowAt = struct { addr: u64, y: f32 }; + +/// The `arc`s of the pointer at `field` (a word, on the row at `from`) +/// among `shown` (rows of 16 bytes, or of 8 on the stack): to the row its +/// target is in, as the step has it. Rewritten: the old arc goes dashed +/// with the arm, fades from 6 f after the strike as the new one draws at +/// full ink, and quiets with the cool. Read: full ink while the read is +/// framed. A target in the same region past the rows shown: a stub to the +/// panel's rule (`rule`: its top and bottom), only in the step that +/// touches it. `loud`: full ink always (a loupe's, opened to show them). +pub fn pointerArcs(arcs: *rows.Arcs, now: cursors.Now, field: u64, from: f32, shown: []const RowAt, size: u64, rule: [2]f32, loud: bool) void { + const a = time_arc; + const new = (Recording.word(now.moment(), field, 8) catch null) orelse return; + const old = (Recording.word(now.before(), field, 8) catch null) orelse new; + const written = now.writeAge(field, 8) == 0 and old != new; + const read = now.wasRead(field, 8) and !written; + const hot = written or read; + const full: f32 = if (loud) 1 else if (read) now.reading(.memory, 0) else 0; + if (written and now.walking()) { + const since = now.since(.memory, now.writeDelay(field, 8)); + const heat = now.written(field, 8, .memory, 0); + const armed = since >= -theme.time.strike.arm; + aim(arcs, now, field, old, from, shown, size, rule, .{ .full = full, .dashed = armed, .shows = 1 - std.math.clamp((since - a.after) / a.fade, 0, 1), .hot = true }); + if (since >= a.after) aim(arcs, now, field, new, from, shown, size, rule, .{ .full = if (loud) 1 else heat.solid, .drawn = cursors.standard(std.math.clamp((since - a.after) / a.draw, 0, 1)), .hot = true }); + return; + } + aim(arcs, now, field, if (written and !now.landed(.memory, 0)) old else new, from, shown, size, rule, .{ .full = full, .hot = hot }); +} + +const time_arc = theme.time.arc; + +/// One arc from the row at `from` to the row of `shown` that holds +/// `target`; a stub toward the rule for one in the region past them, only +/// for the step's (`state.hot`). +fn aim(arcs: *rows.Arcs, now: cursors.Now, field: u64, target: u64, from: f32, shown: []const RowAt, size: u64, rule: [2]f32, state: rows.Arcs.Arc) void { + if (target == 0 or shown.len < 2) return; + const moment = now.moment(); + var arc = state; + arc.from = from; + arc.ink = rows.ink(rows.regionOf(moment, target)); + for (shown) |r| if (target >= r.addr and target < r.addr + size) { + if (r.y == from) return; + arc.to = r.y; + // A loupe open on both rows carries this arc: the dump withholds it. + if (size == 16 and arc.full < 1) for (@import("loupe.zig").holding) |h| if (h) |o| { + if (field >= o.lo and field < o.hi and target >= o.lo and target < o.hi) arc.shows *= 1 - o.shows; + }; + return arcs.add(arc); + }; + // Past the rows: a stub, in the step that touches it, when it is the same region's. + if (!state.hot or rows.regionOf(moment, target) != rows.regionOf(moment, field) or rows.regionOf(moment, target) == .none) return; + arc.stub = true; + arc.to = if (target < shown[0].addr) rule[0] else rule[1]; + arcs.add(arc); } /// Whether an allocation the recording has begins just after the word at @@ -294,6 +364,7 @@ pub fn fielded(v: View, now: cursors.Now, y: f32, of: Fields) void { }.row; var ry = y; var last: ?u64 = null; + var at_rows: std.ArrayList(RowAt) = .empty; for (shown) |r| { // A stretch left out: one row, three dots and a count. const gap = if (last) |l| r - l - 1 else r; @@ -303,9 +374,17 @@ pub fn fielded(v: View, now: cursors.Now, y: f32, of: Fields) void { } last = r; fieldRow(u, now, ry, of.base + 16 * r, moment, of, lead, shift); + at_rows.append(u.f.scratch, .{ .addr = of.base + 16 * r, .y = ry }) catch {}; ry += m.row; } if (shown[shown.len - 1] < total - 1) more(u, ry, total - 1 - shown[shown.len - 1]); + // Its pointers to its own rows: arcs. + var arcs: rows.Arcs = .{}; + if (at_rows.items.len > 1) for (of.fields) |field| if (field.reads == .pointer and field.len == 8) { + const addr = of.base + field.at; + for (at_rows.items) |r| if (addr >= r.addr and addr < r.addr + 16) pointerArcs(&arcs, now, addr, r.y, at_rows.items, 16, .{ y - m.pad, ry + m.pad }, false); + }; + arcs.draw(u, theme.metric.arc.lanes.len); } /// Which of `rs` (rows of fields, the region's last row `last`) a window diff --git a/anim/src/loupe.zig b/anim/src/loupe.zig new file mode 100644 index 0000000..99dae71 --- /dev/null +++ b/anim/src/loupe.zig @@ -0,0 +1,181 @@ +//! `loupe` (design/README.md, "3. Panels"): the telescope's other form. A +//! chain says, flat, `rax → 407030 ◂ 12`; a loupe opens the place it points +//! to: a panel held over the context, lifted (its own surface, the one +//! shadow there is), with five `bytes` rows round the target, the target +//! framed bright, its pointers to its own rows as `arc`s at full ink. In +//! the working frame it hangs from its pointer: its tag's top on the foot +//! of the pointer's row, its left edge 92 left of the pointer's digits (the +//! tag's address under them), a bracket under the digits its stem. One +//! opened from a pointer field of a loupe hangs the same way from that +//! field, 120 to the right where the stage has room, deeper (its shadow +//! 20 and 26). Its verbs are `open` and `close`. +const std = @import("std"); +const sk = @import("sketch"); +const anim = @import("anim"); +const zt = @import("ztrace"); +const ui = @import("ui.zig"); +const rows = @import("rows.zig"); +const cursors = @import("cursor.zig"); +const Recording = @import("Recording.zig"); +const objects = @import("objects.zig"); +const hexdump = @import("hexdump.zig"); +const ties = @import("ties.zig"); +const context = @import("context.zig"); +const Stage = @import("stage.zig").Stage; +const theme = ui.theme; +const Rect = ui.Rect; +const t = theme.color.text; +const m = theme.metric.context; +const k = theme.metric.loupe; +const time = theme.time.loupe; + +/// The rows each open loupe shows, and how much it shows: a dump showing +/// the same rows withholds their arcs while it is open (the loupe carries +/// them). Set as each draws, read the next frame by the dumps drawn before it. +/// shortcut: process-wide, a frame behind; two players at once want it on the frame. +pub var holding: [2]?struct { lo: u64, hi: u64, shows: f32 } = @splat(null); + +pub const Loupe = struct { + cursor: cursors.Cursor, + stage: *const Stage, + /// What it opens from: a register, by name; or a pointer field (its + /// address) of the loupe it hangs under. + from: union(enum) { register: []const u8, field: struct { loupe: *const Loupe, at: u64 } }, + /// 0 to 1 as it opens (`time.loupe.open`) and as it closes (`close`). + opening: anim.Value = undefined, + closing: anim.Value = undefined, + + /// `open`: its pointer framed as read; the stem draws and the loupe + /// rises with it, its shadow growing; its target's frame lands last. + pub fn open(l: *const Loupe, s: *anim.Frame) void { + s.play(.{l.opening.to(1)}, .{ .seconds = time.open, .ease = anim.ease.linear }); + } + + /// `close`: the stem draws back and the loupe sinks, fading as it falls. + pub fn close(l: *const Loupe, s: *anim.Frame) void { + s.play(.{l.closing.to(1)}, .{ .seconds = time.close, .ease = anim.ease.linear }); + } + + /// Where it is now (in the working frame's units) and what it shows: + /// null while it is shut, or where its pointer is not on screen. + const Placed = struct { box: Rect, pointer: Rect, target: u64, first: u64, ink: u24 }; + + fn place(l: *const Loupe, u: ui.Ui, now: cursors.Now) ?Placed { + const moment = now.moment(); + var pointer: Rect = undefined; + var target: u64 = undefined; + var right: f32 = 0; + switch (l.from) { + .register => |name| { + const i = context.index(name) orelse return null; + const px = ties.find(.{ .register = i }) orelse return null; + const back = u.at.xf.invert(); + const a = back.apply(.{ px[0], px[1] }); + const b = back.apply(.{ px[2], px[3] }); + pointer = .{ .x = a[0], .y = a[1], .w = b[0] - a[0], .h = b[1] - a[1] }; + const regs = (moment.regs(l.cursor.rec.tid) catch null) orelse return null; + target = regs.named(name) orelse return null; + }, + .field => |field| { + const parent = field.loupe.place(u, now) orelse return null; + const row = @as(f32, @floatFromInt((field.at -| parent.first) / 16)); + const shift = rows.addressRoom(parent.first + 16 * (k.rows - 1)); + const at: u8 = @intCast(field.at % 16); + pointer = .{ .x = parent.box.x + shift + rows.byteX(at), .y = parent.box.y + m.tag + m.pad + row * m.row, .w = rows.byteX(at + 7) + 24 - rows.byteX(at), .h = m.row }; + target = (Recording.word(moment, field.at, 8) catch null) orelse return null; + right = parent.box.x + 120; + }, + } + if (target == 0) return null; + // shortcut: it keeps to the stage and does not yet move past the current marks or a changed row; the scene picks a pointer whose loupe covers neither. + const stage = theme.canvas.stage; + const h = theme.layout.panelH(k.rows); + const x = std.math.clamp(@max(pointer.x - k.hang, right), stage.x, stage.x + stage.w - k.width); + const y = @min(pointer.y + pointer.h - 1, stage.y + stage.h - h); + return .{ .box = .{ .x = x, .y = y, .w = k.width, .h = h }, .pointer = pointer, .target = target, .first = (target & ~@as(u64, 15)) - 16 * (k.rows / 2), .ink = rows.ink(rows.regionOf(moment, target)) }; + } + + pub fn draw(l: *const Loupe, f: *sk.Frame, placed: anim.Placed) void { + const deep = l.from == .field; + holding[@intFromBool(deep)] = null; + const opened = placed.value(l.opening) * time.open; + const closed = placed.value(l.closing); + if (opened <= 0 or closed >= 1 or ui.mapping) return; + const u: ui.Ui = .{ .f = f, .at = placed }; + const now = l.cursor.now(placed); + const p = l.place(u, now) orelse return; + holding[@intFromBool(deep)] = .{ .lo = p.first, .hi = p.first + 16 * k.rows, .shows = std.math.clamp((opened - time.read) / time.rise, 0, 1) * (1 - closed) }; + // Its pointer framed as read, first. + u.read(p.pointer, std.math.clamp(opened / time.read, 0, 1) * (1 - closed)); + // It rises with the stem: in over 12 f from 8 lower, its shadow growing; it sinks as it closes. + const since = opened - time.read; + if (since <= 0) return; + const rise = std.math.clamp(since / time.rise, 0, 1) * (1 - closed); + const lower = (1 - theme.ease(.enter, std.math.clamp(since / time.rise, 0, 1))) * theme.time.caption_rise + closed * theme.time.caption_rise; + const grow = cursors.standard(std.math.clamp(since / time.shadow, 0, 1)) * (1 - closed); + const off = k.shadow[@intFromBool(deep)]; + const b = p.box; + const v = u.faded(rise).moved(b.x, b.y + lower); + v.fill(.{ .x = off[0] * grow, .y = off[1] * grow, .w = b.w, .h = b.h }, theme.color.shade); + v.fill(.{ .x = 0, .y = 0, .w = b.w, .h = b.h }, theme.color.lift); + v.fill(.{ .x = 0, .y = 0, .w = b.w, .h = m.tag }, theme.color.lift_tag); + v.frame(.{ .x = 0, .y = 0, .w = b.w, .h = b.h }, t.dim, theme.stroke.rule); + // The tag: the pointer it opens from, and the target in its region's ink; the region and the type. + const size = theme.size.mono.context; + const base = m.tag - 6; + const moment = now.moment(); + const things = objects.reach(f.scratch, l.cursor.rec, moment, null); + const object: ?objects.Object = for (things) |o| { + if (o.holds(p.target)) break o; + } else null; + var x: f32 = m.side; + switch (l.from) { + .register => |name| { + v.text(.mono, size, x, base, name, t.dim); + x += v.width(.mono, size, name) + 6; + }, + .field => |field| x = v.address(x, base, field.at, .{ .ink = ui.rgb(rows.ink(rows.regionOf(moment, field.at))) }) + 6, + } + x = v.arrow(x, m.tag / 2, .points) + 8; + _ = v.address(x, base, p.target, .{ .ink = ui.rgb(p.ink) }); + const region = switch (rows.regionOf(moment, p.target)) { + .stack => "stack", + .heap => "heap", + .code => "code", + .data, .rwx => "data", + .rodata => "read-only", + .none => "", + }; + const note = if (object) |o| v.print("{s} \u{00b7} {s}, {d} bytes", .{ region, if (o.name.len > 0) o.name else "a struct", o.type.record.size }) else region; + v.text(.sans, theme.size.sans.micro, b.w - 10 - v.width(.sans, theme.size.sans.micro, note), base, note, t.dim); + // Its rows, typed where the recording types them, its own pointers as arcs at full ink. + const top = m.tag + m.pad; + v.clip(.{ .x = 0, .y = m.tag, .w = b.w, .h = b.h - m.tag }); + hexdump.drawArcs(v, now, 0, top, p.first, k.rows, .{ .things = things }, true, .{ m.tag, b.h - m.pad }); + v.unclip(); + // Its target, framed bright: each field of the struct, or the word. + const framed = std.math.clamp((since - time.stem - time.frame) / time.frame, 0, 1); + if (framed > 0) { + const row_y = top + @as(f32, @floatFromInt((p.target - p.first) / 16)) * m.row; + const shift = rows.addressRoom(p.first + 16 * (k.rows - 1)); + const w = v.faded(framed); + if (object) |o| { + for (o.type.record.fields) |field| frameRun(w, row_y, shift, o.addr + field.offset - (p.target & ~@as(u64, 15)), field.type.size() orelse 8); + } else frameRun(w, row_y, shift, p.target % 16, 8); + } + // The stem: a bracket under the pointer's digits, lying on the tag, drawn head first. + const drawn = cursors.standard(std.math.clamp(since / time.stem, 0, 1)) * (1 - closed); + u.faded(@min(rise * 2, 1)).fill(.{ .x = p.pointer.x - 2, .y = p.pointer.y + p.pointer.h - 3, .w = (p.pointer.w + 4) * drawn, .h = k.stem }, p.ink); + } +}; + +/// `attention` on the bytes `at .. at + len` of a row (from its first +/// byte, up to its end): a 2-unit bright frame round them. +fn frameRun(u: ui.Ui, y: f32, shift: f32, at: u64, len: u64) void { + if (at >= 16 or len == 0) return; + const first: u8 = @intCast(at); + const last: u8 = @intCast(@min(at + len, 16) - 1); + const x0 = shift + rows.byteX(first) - 4; + const x1 = shift + rows.byteX(last) + 28; + u.frame(.{ .x = x0 - 3, .y = y - 1, .w = x1 - x0 + 6, .h = m.row + 2 }, theme.mark(.attention).solid, theme.stroke.rule); +} diff --git a/anim/src/map.zig b/anim/src/map.zig new file mode 100644 index 0000000..e22db9f --- /dev/null +++ b/anim/src/map.zig @@ -0,0 +1,286 @@ +//! The `map` and the `minimap` (design/README.md, "The map and the +//! minimap"): the working frame unfolded, every panel at its full length on +//! a stage of 3840 by 2160 at the context's type size, and the same at a +//! twentieth in the caption band's right end. Its panels are the working +//! frame's components bound to a stage of their own (`split`), drawn with +//! `ui.mapping` set: then they publish their rows (`row`), and in the +//! working frame their windows (`window`); the map outlines each working +//! window round the rows of its own that it shows. +const std = @import("std"); +const sk = @import("sketch"); +const anim = @import("anim"); +const ui = @import("ui.zig"); +const Recording = @import("Recording.zig"); +const Stage = @import("stage.zig").Stage; +const theme = ui.theme; +const Rect = theme.Rect; +const Split = theme.layout.Split; + +pub const Panel = enum { band, view, source, disasm, registers, stack, backtrace }; + +/// `dive`'s frames: the windows bright by `bright`, the rest veiled by +/// `move`, when the panels set off (each `apart` after the one before, for +/// `travel`); the veil lifts from `lift` as the map lands at `land`; then +/// `still`. `surface` takes `surface` back. +pub const diving = struct { + pub const bright = 6; + pub const move = 24; + pub const apart = 6; + /// A panel's way, and the map's. + pub const travel = 60; + pub const fall = 72; + pub const lift = 84; + /// The last of seven panels in place: 24 + 6 * 6 + 60. + pub const land = 120; + pub const still = 30; + pub const surface = 84; +}; + +/// Where each working window is on the map this frame, in canvas pixels. +var window_px: [7]?[4]f32 = @splat(null); + +/// The working frame's windows this frame: the first and last key of the +/// rows each shows (a line number, an address). +var windows: [7]?[2]u64 = @splat(null); +/// The map's rows this frame, in canvas pixels: each one's key and box. +var rows: [7][160]struct { key: u64, box: [4]f32 } = undefined; +var counts: [7]usize = @splat(0); + +/// A working panel shows the rows of keys `first` to `last`. +pub fn window(panel: Panel, first: u64, last: u64) void { + if (!ui.mapping) windows[@intFromEnum(panel)] = .{ first, last }; +} + +/// A map panel's row of key `key` is at `r`, in `u`'s units. +pub fn row(panel: Panel, key: u64, u: ui.Ui, r: Rect) void { + if (!ui.mapping) return; + const i = @intFromEnum(panel); + if (counts[i] == rows[i].len) return; + const a = u.at.xf.apply(.{ r.x, r.y }); + const b = u.at.xf.apply(.{ r.x + r.w, r.y + r.h }); + rows[i][counts[i]] = .{ .key = key, .box = .{ a[0], a[1], b[0], b[1] } }; + counts[i] += 1; +} + +/// The map's boxes for a recording: the drawing (with a lens) and the +/// source in the first column, the disassembly in the second, the lens's +/// view (its region whole), the registers and the backtrace in the third, +/// the stack in the fourth. Each as long as its content where that is +/// shorter than the column. +// shortcut: a panel longer than its column is a window of what fits; continuing it in the next column's free space (`continued`), and the key in a column's foot, are not built. +pub fn split(rec: *const Recording, lens: bool) Split { + const st = theme.map.stage; + const c = theme.map.columns; + const w = theme.map.column; + const gap = theme.canvas.row_gap; + const panelH = theme.layout.panelH; + const foot = st.y + st.h; + const band: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = if (lens) theme.layout.split.subject.band.h else 0 }; + const source_y = if (lens) band.y + band.h + gap else st.y; + const source_rows: f32 = @floatFromInt(@min(rec.line_count, theme.layout.rowsIn(foot - source_y))); + const view: Rect = .{ .x = c[2], .y = st.y, .w = w, .h = if (lens) panelH(theme.map.memory_rows) else 0 }; + const registers: Rect = .{ .x = c[2], .y = if (lens) view.y + view.h + gap else st.y, .w = w, .h = panelH(17) }; + const bt_y = registers.y + registers.h + gap; + return .{ + .band = band, + .view = view, + .source = .{ .x = c[0], .y = source_y, .w = w, .h = panelH(source_rows) }, + .disasm = .{ .x = c[1], .y = st.y, .w = w, .h = panelH(theme.map.disasm_rows) }, + .registers = registers, + .stack = .{ .x = c[3], .y = st.y, .w = w, .h = st.h }, + .backtrace = .{ .x = c[2], .y = bt_y, .w = w, .h = @min(panelH(12), foot - bt_y) }, + .dump_rows = theme.map.memory_rows, + }; +} + +/// The map: its stage, and the components drawn on it, each a working +/// frame's component bound to that stage. +pub const Map = struct { + stage: *Stage, + parts: [8]Part = undefined, + n: usize = 0, + /// The panel the narration is in: its window bright on the minimap. + focus: ?Panel = null, + /// The working frame, whose panels dive out of their windows. + frame: *const Stage, + /// Frames into a `dive` (0: the map fills the frame; `diving.land` and + /// on: the working frame, the map its minimap). + t: anim.Value, + /// The map as an object of the scene, under the panels: it shows from `show`. + obj: anim.Obj = undefined, + + const Part = struct { ctx: *const anyopaque, draw: *const fn (*const anyopaque, *sk.Frame, anim.Placed) void }; + + /// Puts `component` (bound to `m.stage`) on the map, drawn in the order added. + pub fn add(m: *Map, s: *anim.Frame, component: anytype) void { + const T = @TypeOf(component); + const kept = s.new(component); + m.parts[m.n] = .{ .ctx = kept, .draw = struct { + fn draw(ctx: *const anyopaque, f: *sk.Frame, at: anim.Placed) void { + @as(*const T, @ptrCast(@alignCast(ctx))).draw(f, at); + } + }.draw }; + m.n += 1; + } + + /// Whether the working frame is in place (the minimap is the map). + pub fn settled(m: *const Map, at: anim.Placed) bool { + return at.value(m.t) >= diving.land; + } + + /// The map filling the frame, before a scene's first `dive`: it fades + /// in (18 f) with `with` (the working panels, at their windows on it). + pub fn show(m: *const Map, s: *anim.Frame, with: anytype) void { + s.play(.{m.t.to(0)}, .{ .seconds = 0 }); + var all: [with.len + 1]anim.Animation = undefined; + all[0] = m.obj.fadeIn(); + inline for (with, 1..) |o, i| all[i] = o.fadeIn(); + s.play(all, .{ .seconds = theme.time.cascade, .ease = anim.ease.linear }); + } + + /// `dive`: the windows go bright, the rest of the map is veiled; each + /// window travels to its panel's place, growing from the map's size to + /// the frame's on a logarithm (`glide`, 6 f apart in reading order), + /// as the map falls to the minimap's place; the veil lifts as it lands; + /// then the frame is still. + pub fn dive(m: *const Map, s: *anim.Frame) void { + s.play(.{m.t.to(diving.land + diving.still)}, .{ .seconds = @as(f32, diving.land + diving.still) / 60.0, .ease = anim.ease.linear }); + } + + /// `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 }); + 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); + } + + /// The map while it is shown or travelling (the scene's first object): + /// filling the frame at half its size, or on its way to the minimap. + /// It sets where each working panel is drawn on the way (`context.zoomed`). + pub fn draw(m: *const Map, f: *sk.Frame, placed: anim.Placed) void { + const context = @import("context.zig"); + context.zoomed = @splat(null); + const t = placed.value(m.t); + if (t >= diving.land) return; + const fixed = @import("words.zig").fixed(f, placed, 0); + // The map: from filling the frame (half its units) to the minimap's rect (a twentieth). + const q = theme.ease(.glide, std.math.clamp((t - diving.move) / diving.fall, 0, 1)); + const mini = theme.minimap.box; + const k = std.math.pow(f32, 0.5, 1 - q) * std.math.pow(f32, theme.minimap.scale, q); + const origin = [2]f32{ q * mini.x, q * mini.y }; + var at = fixed.at; + at.xf = at.xf.mul(.translate(origin[0], origin[1])).mul(.scale(k, k)); + at.scale = fixed.at.scale * k; + fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); + m.drawAt(f, at, k < 0.12); + // The rest of the map veiled from 6 f to 24 f, lifting as it lands. + const veil = std.math.clamp((t - diving.bright) / (diving.move - diving.bright), 0, 1) * (1 - std.math.clamp((t - diving.lift) / (diving.land - diving.lift), 0, 1)); + (ui.Ui{ .f = f, .at = at }).veil(theme.map.stage, veil); + // The windows bright from 0 to 6 f, over the veil. + m.outline(f, at, k < 0.12, std.math.clamp(t / diving.bright, 0, 1)); + // Each working panel: from its window on the map at the start to its place, 6 f after the one before. + const back = at.xf.invert(); + const working = m.frame.now(placed); + inline for (.{ "band", "view", "source", "registers", "disasm", "stack", "backtrace" }, 0..) |name, order| { + const i = @intFromEnum(@field(Panel, name)); + const box = @field(working, name); + if (box.h > 0) if (window_px[i]) |w| { + const a = back.apply(.{ w[0], w[1] }); + const b = back.apply(.{ w[2], w[3] }); + // On the map as it fills the frame (half its units): the panel's rows on the window's rows, its tag above them. + const s0 = (b[0] - a[0]) / 2 / box.w; + const lead = (if (i == @intFromEnum(Panel.band)) 0 else theme.metric.context.tag + theme.metric.context.pad) * s0; + const from: Rect = .{ .x = a[0] / 2, .y = a[1] / 2 - lead, .w = box.w * s0, .h = box.h * s0 }; + const p = theme.ease(.glide, std.math.clamp((t - diving.move - @as(f32, @floatFromInt(order)) * diving.apart) / diving.travel, 0, 1)); + const scale = std.math.pow(f32, s0, 1 - p); + const x = std.math.lerp(from.x, box.x, p); + 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 }; + }; + } + } + + /// The map in `at`'s transform (the map's units), and the working + /// frame's windows outlined on it: a 2-unit `dim` frame 4 out; on the + /// minimap (`mini`) a pixel of primary, the focused one 1.5. + pub fn drawAt(m: *const Map, f: *sk.Frame, at: anim.Placed, mini: bool) void { + m.drawParts(f, at, mini); + m.outline(f, at, mini, 0); + } + + fn drawParts(m: *const Map, f: *sk.Frame, at: anim.Placed, mini: bool) void { + ui.mapping = true; + ui.strokes = mini; + counts = @splat(0); + for (m.parts[0..m.n]) |p| p.draw(p.ctx, f, at); + ui.mapping = false; + ui.strokes = false; + } + + /// The working windows' outlines on the map in `at`, `bright` of the way + /// from `dim` to bright; where they are is kept (`window_px`). + fn outline(m: *const Map, f: *sk.Frame, at: anim.Placed, mini: bool, bright: f32) void { + var raw: ui.Ui = .{ .f = f, .at = at }; + raw.at.xf = .identity; + const k = at.scale; + const split_ = m.stage.now(at); + inline for (.{ "band", "view", "source", "disasm", "registers", "stack", "backtrace" }) |name| { + const panel = @field(Panel, name); + const i = @intFromEnum(panel); + 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 }); + var r: [4]f32 = .{ a[0], a[1], b[0], b[1] }; + var shown = panel == .registers or panel == .band; + if (windows[i]) |win| { + var top: f32 = std.math.inf(f32); + var bottom: f32 = -std.math.inf(f32); + for (rows[i][0..counts[i]]) |rw| if (rw.key >= win[0] and rw.key <= win[1]) { + top = @min(top, rw.box[1]); + bottom = @max(bottom, rw.box[3]); + }; + if (top < bottom) { + r[1] = top; + r[3] = bottom; + shown = true; + } + } + window_px[i] = if (shown) r else null; + if (shown) { + const focus = m.focus == panel; + // On the minimap a pixel of the frame: `k` is the canvas's pixels to a map unit. + const w = if (mini) @as(f32, if (focus) 1.5 else 1) * k / theme.minimap.scale else theme.map.outline * k; + const out = if (mini) w else theme.map.outline_out * k; + raw.frame(.{ .x = r[0] - out, .y = r[1] - out, .w = r[2] - r[0] + 2 * out, .h = r[3] - r[1] + 2 * out }, ui.mix(if (mini) theme.color.text.primary else theme.color.text.dim, theme.color.text.bright, bright), if (bright > 0 and !mini) w * 1.5 else w); + } + } + } + } +}; + +/// The minimap: `m` at a twentieth in the caption band's right end, still +/// while the camera moves; the page under it, framed a pixel in `rule`. +pub fn minimap(m: *const Map, f: *sk.Frame, at: anim.Placed) void { + const fixed = @import("words.zig").fixed(f, at, 0); + const box = theme.minimap.box; + fixed.fill(box, theme.color.page); + var placed = fixed.at; + placed.xf = placed.xf.mul(.translate(box.x, box.y)).mul(.scale(theme.minimap.scale, theme.minimap.scale)); + placed.scale = fixed.at.scale * theme.minimap.scale; + const clip = fixed.at.xf.apply(.{ box.x, box.y }); + const end = fixed.at.xf.apply(.{ box.x + box.w, box.y + box.h }); + f.clip(sk.Rect{ .x = @round(clip[0]), .y = @round(clip[1]), .w = @round(end[0]) - @round(clip[0]), .h = @round(end[1]) - @round(clip[1]) }); + m.drawAt(f, placed, true); + f.clip(null); + fixed.frame(.{ .x = box.x - 1, .y = box.y - 1, .w = box.w + 2, .h = box.h + 2 }, theme.color.rule, 1); +} + +test "the map's columns hold their panels" { + try std.testing.expectEqual(@as(f32, 1688), theme.layout.panelH(theme.map.disasm_rows)); + const st = theme.map.stage; + try std.testing.expectEqual(@as(f32, 3840), st.x + st.w + st.x); +} diff --git a/anim/src/nodes.zig b/anim/src/nodes.zig index d5c7613..b4ba951 100644 --- a/anim/src/nodes.zig +++ b/anim/src/nodes.zig @@ -76,6 +76,7 @@ pub const Nodes = struct { const shown = @min(count, (hi - first) / 16); const v = hexdump.panel(f, placed, g.stage, u.print("the heap, {x} to {x}", .{ first, first + 16 * shown - 1 }), &legend); if (v.rows > 0) hexdump.draw(v.u, now, 0, m.tag + m.pad, first, @min(shown, v.rows), .{ .things = things }); + if (v.rows > 0) @import("map.zig").window(.view, first, first + 16 * (@min(shown, v.rows) -| 1)); v.veil(now); u.clip(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); } diff --git a/anim/src/objects.zig b/anim/src/objects.zig index 0c4f48a..6ee2b4c 100644 --- a/anim/src/objects.zig +++ b/anim/src/objects.zig @@ -15,6 +15,8 @@ pub const Object = struct { slot: ?usize, /// Its allocation is gone: something still points at freed memory. freed: bool, + /// Its type's name, where the debug info names it (`struct node`). + name: []const u8 = "", pub fn holds(o: Object, addr: u64) bool { return addr >= o.addr and addr - o.addr < o.type.record.size; @@ -60,9 +62,14 @@ fn follow(scratch: std.mem.Allocator, rec: *const Recording, m: Recording.Moment if (t != .record) return; const addr = (Recording.word(m, at, 8) catch return) orelse return; if (addr == 0) return; - for (found.items) |o| if (o.addr == addr) return; + const name = if (pointee == .named) pointee.named else ""; + // Met again through a pointer that names it as C does (`struct node`, not a typedef): that name. + for (found.items) |*o| if (o.addr == addr) { + if (std.mem.startsWith(u8, name, "struct ") or std.mem.startsWith(u8, name, "union ")) o.name = name; + return; + }; const live = (m.allocation(addr) catch null) != null; - found.append(scratch, .{ .addr = addr, .type = t, .slot = slotOf(rec, addr, m), .freed = !live and wasAllocated(rec, addr, m.index) }) catch {}; + found.append(scratch, .{ .addr = addr, .type = t, .slot = slotOf(rec, addr, m), .freed = !live and wasAllocated(rec, addr, m.index), .name = name }) catch {}; } /// The place of the allocation at `addr` among every allocation of its diff --git a/anim/src/root.zig b/anim/src/root.zig index d68b99c..d8c2c76 100644 --- a/anim/src/root.zig +++ b/anim/src/root.zig @@ -44,6 +44,7 @@ const tying = @import("ties.zig"); pub const Ties = tying.Ties; pub const Place = tying.Place; pub const Array = @import("array.zig").Array; +pub const Loupe = @import("loupe.zig").Loupe; pub const syscalls = @import("syscalls.zig"); pub const Crossing = syscalls.Crossing; pub const Timeline = syscalls.Timeline; @@ -206,8 +207,13 @@ pub const Camera = struct { /// the program column (the whole source in a window, the disassembly at /// the pc), the ties between them, and the clock. A scene adds its lens in /// the band (`stage`): a lens is never shown instead of the machine. +pub const map = @import("map.zig"); + pub const Context = struct { stage: *Stage, + /// The working frame unfolded (`map.Map`): its panels, on a stage of its + /// own; drawn small as the minimap. A lens adds its drawing with `map.add`. + map: *map.Map, clock: anim.Obj, source: anim.Obj, disasm: anim.Obj, @@ -259,8 +265,17 @@ pub fn context(s: *anim.Frame, cursor_: Cursor, options: Context.Options) Contex const stage = Stage.init(s, options.split); var at = cursor_; at.levels.crossings = options.syscalls; + // The map first: while it fills the frame or falls to the minimap it is under the panels diving out of it. + const whole = s.new(map.Map{ .stage = Stage.init(s, map.split(at.rec, options.split.band.h > 0)), .frame = stage, .t = s.value(map.diving.land + map.diving.still) }); + whole.obj = s.custom(whole, .{ .x = -640, .y = -360, .scale = ui.scale }); + whole.add(s, Source{ .cursor = at, .stage = whole.stage }); + whole.add(s, Disasm{ .cursor = at, .stage = whole.stage }); + whole.add(s, Registers{ .cursor = at, .stage = whole.stage, .syscalls = options.syscalls, .quiet = options.quiet }); + whole.add(s, Stack{ .cursor = at, .stage = whole.stage, .above = theme.map.stack_above }); + whole.add(s, Backtrace{ .cursor = at, .stage = whole.stage }); return .{ .stage = stage, + .map = whole, .cursor = at, .quiet = options.quiet, .source = add(s, Source{ .cursor = at, .stage = stage }), @@ -268,7 +283,7 @@ pub fn context(s: *anim.Frame, cursor_: Cursor, options: Context.Options) Contex .registers = add(s, Registers{ .cursor = at, .stage = stage, .syscalls = options.syscalls, .quiet = options.quiet }), .stack = add(s, Stack{ .cursor = at, .stage = stage }), .backtrace = add(s, Backtrace{ .cursor = at, .stage = stage, .lens = options.backtrace }), - .clock = add(s, Clock{ .cursor = at }), + .clock = add(s, Clock{ .cursor = at, .map = whole }), }; } @@ -295,6 +310,17 @@ pub fn crossing(s: *anim.Frame, options: Crossing) anim.Obj { pub fn timeline(s: *anim.Frame, options: Timeline) anim.Obj { return add(s, options); } +/// A `loupe`, shut until its `open`: add it after the panels and the lens, +/// a deeper one after the loupe it hangs from, and the ties after them. +pub fn loupe(s: *anim.Frame, options: Loupe) *Loupe { + var l = options; + l.opening = s.value(0); + l.closing = s.value(0); + const made = s.new(l); + const o = s.custom(made, .{ .x = -640, .y = -360, .scale = ui.scale }); + s.play(.{o.fadeIn()}, .{ .seconds = 0 }); + return made; +} pub fn caption(s: *anim.Frame, text: []const u8) anim.Obj { return add(s, Caption{ .text = text }); } @@ -323,6 +349,8 @@ test { _ = calls; _ = @import("nodes.zig"); _ = @import("array.zig"); + _ = @import("loupe.zig"); + _ = map; _ = @import("syscalls.zig"); _ = objects; _ = words; diff --git a/anim/src/rows.zig b/anim/src/rows.zig index 8446b52..83064a6 100644 --- a/anim/src/rows.zig +++ b/anim/src/rows.zig @@ -44,8 +44,8 @@ pub fn baseline(y: f32) f32 { pub const Marks = struct { /// The first hop: a register (or a word) written: armed, struck, held. first: ui.Heat = .none, - /// A later hop, the memory under a pointer that did not change: its - /// tick sits before that hop alone. + /// A later hop, the memory under a pointer that did not change: the + /// turned corner sits on that hop alone. changed: ?usize = null, changed_heat: ui.Heat = .ember, /// A hop read, and how much its frame shows. @@ -56,9 +56,6 @@ pub const Marks = struct { extend: ?f32 = null, /// The first hop's `lead` (a column of addresses). lead: usize = 0, - /// Where the first hop's tick goes, left of its digits: 9 after a - /// name, 5 after an arrow. - tick: f32 = 9, }; /// Where a chain's hops were drawn: x and width of each one's digits. @@ -105,9 +102,9 @@ pub fn chain(u: ui.Ui, x: f32, y: f32, moment: Recording.Moment, value: u64, roo const marked: Rect = .{ .x = at, .y = y, .w = w, .h = row_h }; var face_ink: ui.Ink = .{ .ink = ui.rgb(if (pointer) ink(link.region) else t.primary) }; if (i == 0) { - if (v.written(marked, marks.first, marks.tick)) |struck| face_ink = struck; + if (v.written(marked, marks.first)) |struck| face_ink = struck; } else if (marks.changed == i) { - if (v.written(marked, marks.changed_heat, 5)) |struck| face_ink = struck; + if (v.written(marked, marks.changed_heat)) |struck| face_ink = struck; } if (marks.read == i) v.read(marked, marks.read_shows); if (pointer) { @@ -166,11 +163,12 @@ pub fn reg(u: ui.Ui, y: f32, w: f32, name: []const u8, moment: Recording.Moment, pub const Flag = struct { name: []const u8, bit: u6 }; pub const flags = [_]Flag{ .{ .name = "CF", .bit = 0 }, .{ .name = "PF", .bit = 2 }, .{ .name = "AF", .bit = 4 }, .{ .name = "ZF", .bit = 6 }, .{ .name = "SF", .bit = 7 }, .{ .name = "IF", .bit = 9 }, .{ .name = "DF", .bit = 10 }, .{ .name = "OF", .bit = 11 } }; -/// `reg` rip: gold plaque on the name, ember across, the address in +/// `reg` rip: gold plaque on the name, the wash across, the address in /// code's ink and its name; never struck. At its right end the `flags`, /// eight names on a pitch of 42: set, upper case on a chip, bold, bright; -/// clear, lower case, dim; changed, a tick (`changed`: a bit per flag, and -/// how held). The value of eflags is not drawn: the names are the value. +/// clear, lower case, dim; changed, a turned corner (`changed`: a bit per +/// flag, and how much of the corner shows). The value of eflags is not +/// drawn: the names are the value. pub fn rip(u: ui.Ui, y: f32, w: f32, moment: Recording.Moment, pc: u64, eflags: u64, changed: u64, held: f32, fire: f32) void { const gold = theme.mark(.current); u.current(.{ .x = theme.stroke.rule, .y = y, .w = w - 2 * theme.stroke.rule, .h = row_h }, theme.metric.plaque.rip, fire); @@ -180,26 +178,37 @@ pub fn rip(u: ui.Ui, y: f32, w: f32, moment: Recording.Moment, pc: u64, eflags: _ = chain(u, m.chain_x, y, moment, pc, x - 16, .{}); for (flags) |flag| { const set = eflags >> flag.bit & 1 != 0; - if (changed >> flag.bit & 1 != 0 and held > 0) u.fill(.{ .x = x - 7, .y = y + 3, .w = m.tick, .h = row_h - 6 }, ui.mix(gold.ember, theme.mark(.write).solid, held)); if (set) { u.chip(.{ .x = x, .y = y + 2, .w = fl.chip[0], .h = fl.chip[1] }); u.text(.mono_bold, size, x + 4, baseline(y), flag.name, t.bright); } else u.text(.mono, size, x + 4, baseline(y), u.print("{c}{c}", .{ std.ascii.toLower(flag.name[0]), std.ascii.toLower(flag.name[1]) }), ui.mix(t.dim, gold.ember, 0.2)); + if (changed >> flag.bit & 1 != 0) u.corner(x, y + 2, m.corner, held); x += fl.pitch; } } -/// `slot`: a word of the stack: a lane 112 wide for `row` pins (`pins`, -/// the registers that hold its address), then its chain from 122, -/// beginning with the slot's own address in stack ink with `lead`, room -/// to 136 from the right edge `w` (the `call` spans'). -pub fn slot(u: ui.Ui, y: f32, w: f32, moment: Recording.Moment, addr: u64, pins: []const []const u8, pin_shows: f32, marks: Marks) Hops { +/// `slot`: a word of the stack: a lane to 112 for `row` pins (`pins`, the +/// registers that hold its address); its offset from rsp (`from_rsp` +/// bytes), hex, faint, ranged right to 172 (`+18`, `-8` above rsp); its +/// address in stack ink with `lead` from 184; then its chain, beginning +/// with the word it holds; and its `role` (what the word is, where the +/// recording knows it: `saved rbp` dim, a `local`'s name primary), ranged right where the room ends +/// (136 from the right edge `w`: the `call` spans'), the chain ending a +/// character before it. +pub fn slot(u: ui.Ui, y: f32, w: f32, moment: Recording.Moment, addr: u64, from_rsp: i64, pins: []const []const u8, pin_shows: f32, marks: Marks, role: []const u8, local: bool) Hops { const s = theme.metric.slot; if (pins.len > 0 and pin_shows > 0) u.faded(pin_shows).pinRow(s.lane, y, pins, theme.color.region.stack); + offset(u, y, from_rsp); var lead = marks; lead.first = .none; const base = baseline(y); - const end = u.address(s.chain, base, addr, .{ .ink = ui.rgb(theme.color.region.stack), .lead = marks.lead }); + const end = u.address(s.address, base, addr, .{ .ink = ui.rgb(theme.color.region.stack), .lead = marks.lead }); + var room = w - s.room; + if (role.len > 0) { + const rx = room - u.width(.mono, size, role); + u.text(.mono, size, rx, base, role, if (local) t.primary else t.dim); + room = rx - adv; + } const held = (Recording.word(moment, addr, 8) catch null) orelse { _ = u.arrow(end, y + row_h / 2, .points); u.unknown(.{ .x = end + m.arrow_w, .y = y, .w = 24, .h = row_h }); @@ -210,17 +219,23 @@ pub fn slot(u: ui.Ui, y: f32, w: f32, moment: Recording.Moment, addr: u64, pins: const at = u.arrow(end, y + row_h / 2, if (pointer) .points else .holds); lead.lead = 0; lead.first = marks.first; - lead.tick = 5; - return chain(u, at, y, moment, held, w - s.room, lead); + return chain(u, at, y, moment, held, room, lead); +} + +/// 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))}); + u.text(.mono, size, theme.metric.slot.offset - u.width(.mono, size, text), baseline(y), text, t.faint); } /// `slot` `free`: a word above rsp the stack has not reached, shown while -/// the window is held for the camera: its address at 60%, its word -/// faint, no chain, no pin. -pub fn free(u: ui.Ui, y: f32, moment: Recording.Moment, addr: u64, lead: usize) void { +/// the window is held for the camera: its offset, its address at 60%, its +/// word faint, no chain, no pin. +pub fn free(u: ui.Ui, y: f32, moment: Recording.Moment, addr: u64, from_rsp: i64, lead: usize) void { const s = theme.metric.slot; const base = baseline(y); - const end = u.address(s.chain, base, addr, .{ .ink = ui.mix(theme.color.region.stack, theme.color.page, theme.metric.context.lead_alpha), .lead = lead }); + offset(u, y, from_rsp); + const end = u.address(s.address, base, addr, .{ .ink = ui.mix(theme.color.region.stack, theme.color.page, theme.metric.context.lead_alpha), .lead = lead }); const word = (Recording.word(moment, addr, 8) catch null) orelse return u.unknown(.{ .x = end + m.arrow_w, .y = y, .w = 24, .h = row_h }); u.text(.mono, size, end + m.arrow_w, base, u.print("{x}", .{word}), t.faint); } @@ -347,8 +362,8 @@ pub fn bytes(u: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *const [ } /// How far right of their column a dump's bytes (and its reading) go to -/// leave its widest address room: none for one of eight digits, 42 for a -/// stack address's twelve. A dump sets it once, so its rows keep one column. +/// leave its widest address room: none up to seven digits, 58 for a stack +/// address's twelve. A dump sets it once, so its rows keep one column. pub fn addressRoom(addr: u64) f32 { const b = theme.metric.bytes; return @max(b.address + @as(f32, @floatFromInt(ui.digits(addr))) * adv + adv - b.first, 0); @@ -367,22 +382,22 @@ pub fn bytesAt(at: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *cons const r: Rect = .{ .x = x0, .y = y + 1, .w = x1 - x0, .h = row_h - 2 }; const field = run.kind == .number or run.kind == .pointer or run.kind == .text; if (field) u.fill(r, theme.color.raised); - // Marks per run, never per byte: struck (the paper solid), read (a - // frame 3 out), held (a tick in the gap at the run's left). + // Marks per run, never per byte: struck (the softened paper, the + // digits bold and bright), read (a frame 3 out), held (a turned + // corner at the run's top left). var face: ui.Face = .mono; var struck_ink: ?ui.Color = null; const h = run.heat; - const held = h.level * (1 - (if (h.level >= 1) h.solid * h.in else 0)); - if (held > 0) u.fill(.{ .x = x0 - 7, .y = y + 3, .w = m.tick, .h = row_h - 6 }, ui.mix(theme.color.page, theme.mark(.write).solid, held)); if (h.arm > 0) u.faded(h.arm).frame(.{ .x = x0 - 3, .y = y - 1, .w = x1 - x0 + 6, .h = row_h + 2 }, theme.mark(.write).solid, 2); const solid = if (h.level >= 1) h.solid * h.in else 0; if (solid > 0) { - u.fill(.{ .x = r.x - h.out, .y = r.y - h.out, .w = r.w + 2 * h.out, .h = r.h + 2 * h.out }, ui.mix(theme.color.raised, theme.mark(.write).solid, solid)); + u.fill(.{ .x = r.x - h.out, .y = r.y - h.out, .w = r.w + 2 * h.out, .h = r.h + 2 * h.out }, ui.mix(theme.color.raised, theme.color.struck, solid)); if (solid >= 0.5) { face = .mono_bold; - struck_ink = ui.rgb(theme.mark(.write).on_solid); + struck_ink = ui.rgb(t.bright); } } + u.corner(x0, y + 2, m.corner, h.level * h.corner); if (run.read > 0) u.faded(run.read).frame(.{ .x = x0 - 3, .y = y - 1, .w = x1 - x0 + 6, .h = row_h + 2 }, theme.mark(.read).solid, 2); // A little-endian word: the bytes above its highest non-zero one are its padding. var top: usize = 0; @@ -416,3 +431,100 @@ pub fn byteX(i: u8) f32 { const b = theme.metric.bytes; return b.first + @as(f32, @floatFromInt(i)) * b.pitch + @as(f32, if (i >= 8) b.middle else 0); } + +/// `arc`s: the pointers of a panel of rows whose targets are rows of the +/// same panel, each drawn from its row along a lane at the panel's left +/// edge to the target's row, head first. A panel adds the pointers it +/// draws (`add`), then `draw`s them over its rows. +pub const Arcs = struct { + items: [32]Arc = undefined, + n: usize = 0, + + pub const Arc = struct { + /// The rows' tops: the pointer's, its target's (or the panel's + /// rule, for a `stub`: a target in the same region past the window). + from: f32 = 0, + to: f32 = 0, + ink: u24 = 0, + /// 0 standing, 1 full ink: the step writes or reads the pointer. + full: f32 = 0, + /// How much of it is drawn from its pointer (it draws head first), + /// and how much shows (it fades). + drawn: f32 = 1, + shows: f32 = 1, + dashed: bool = false, + stub: bool = false, + /// The step's: its lane comes first. + hot: bool = false, + }; + + pub fn add(a: *Arcs, arc: Arc) void { + if (a.n == a.items.len or arc.shows <= 0 or arc.from == arc.to) return; + a.items[a.n] = arc; + a.n += 1; + } + + /// Nested spans take separate lanes, the longest outermost; spans that + /// do not overlap share one; past `lanes` the step's come first, then + /// the shorter, and the rest are only read. + pub fn draw(a: *Arcs, u: ui.Ui, lanes: usize) void { + const k = theme.metric.arc; + const Span = struct { lo: f32, hi: f32, y0: f32, y1: f32, i: usize }; + var spans: [32]Span = undefined; + for (a.items[0..a.n], spans[0..a.n], 0..) |arc, *sp, i| { + const up = arc.to < arc.from; + const high: f32 = k.high; + const low: f32 = k.low; + sp.y0 = arc.from + if (up) high else low; + sp.y1 = if (arc.stub) arc.to else arc.to + if (up) low else high; + sp.lo = @min(sp.y0, sp.y1); + sp.hi = @max(sp.y0, sp.y1); + sp.i = i; + } + // The longest first, so it takes the outermost lane free. + std.mem.sort(Span, spans[0..a.n], {}, struct { + fn longer(_: void, x: Span, y: Span) bool { + return x.hi - x.lo > y.hi - y.lo; + } + }.longer); + var taken: [3][32][2]f32 = undefined; + var counts = [3]usize{ 0, 0, 0 }; + var lane_of: [32]?usize = @splat(null); + for ([_]bool{ true, false }) |hot| for (spans[0..a.n]) |sp| { + if (a.items[sp.i].hot != hot) continue; + lane_of[sp.i] = for (0..@min(lanes, 3)) |l| { + const clear = for (taken[l][0..counts[l]]) |t2| { + if (!(sp.hi < t2[0] or sp.lo > t2[1])) break false; + } else true; + if (clear) { + taken[l][counts[l]] = .{ sp.lo, sp.hi }; + counts[l] += 1; + break l; + } + } else null; + }; + for (spans[0..a.n]) |sp| { + const arc = a.items[sp.i]; + const lane = lane_of[sp.i] orelse continue; + const x = k.lanes[lane]; + const shade = ui.mix(arc.ink, theme.color.page, k.standing * (1 - std.math.clamp(arc.full, 0, 1))); + const v = u.faded(arc.shows); + if (arc.stub) { + v.route(&.{ .{ k.out, sp.y0 }, .{ x, sp.y0 }, .{ x, sp.y1 } }, shade, .{ .width = k.width, .head = k.head, .radius = k.radius, .progress = arc.drawn, .dashed = arc.dashed }); + } else v.route(&.{ .{ k.out, sp.y0 }, .{ x, sp.y0 }, .{ x, sp.y1 }, .{ k.in, sp.y1 } }, shade, .{ .width = k.width, .head = k.head, .radius = k.radius, .progress = arc.drawn, .dashed = arc.dashed }); + } + } +}; + +test "arcs of a chain share a lane; nested ones take the next" { + var a: Arcs = .{}; + // 1004090 -> 1004070 -> 1004050, rows 4, 2, 0: one lane. + a.add(.{ .from = 96, .to = 48, .ink = 0 }); + a.add(.{ .from = 48, .to = 0, .ink = 0 }); + // One across both: the outer lane. + a.add(.{ .from = 120, .to = 0, .ink = 0 }); + const k = theme.metric.arc; + const up_from = 96 + k.high; + const into = 48 + k.low; + try std.testing.expect(into < up_from and 48 + k.high < into); +} diff --git a/anim/src/source.zig b/anim/src/source.zig index 301e8cd..58b9df0 100644 --- a/anim/src/source.zig +++ b/anim/src/source.zig @@ -14,6 +14,7 @@ const ui = @import("ui.zig"); const rows = @import("rows.zig"); const context = @import("context.zig"); const ties = @import("ties.zig"); +const map = @import("map.zig"); const cursors = @import("cursor.zig"); const Stage = @import("stage.zig").Stage; const Cursor = cursors.Cursor; @@ -100,9 +101,11 @@ pub const Source = struct { found += 1; } + map.window(.source, shown_first, @min(shown_first + fit - 1, rec.line_count)); var line = @max(from, 1); while (line <= last) : (line += 1) { const y = top + (@as(f32, @floatFromInt(line)) - first) * m.row; + map.row(.source, line, u, .{ .x = 0, .y = y, .w = box.w, .h = m.row }); const span = text.lines[line - 1]; const k = std.mem.indexOfScalar(u32, trail[0..found], line); const on = shows >= 0.5 and line == mark_line; diff --git a/anim/src/theme.zig b/anim/src/theme.zig index 846014f..5a85f50 100644 --- a/anim/src/theme.zig +++ b/anim/src/theme.zig @@ -44,6 +44,31 @@ pub const canvas = struct { pub const caption_max_width = 1400; }; +/// The map (design/README.md, "The map and the minimap"): the working +/// frame unfolded on a stage of 3840 by 2160 at the context's type size, +/// four columns of 880; the working frame's windows outlined on it (2 in +/// `dim`, 4 out). The minimap: the map at a twentieth in the caption +/// band's right end, under the clock's, whose count moves left of it. +pub const map = struct { + pub const width = 3840; + pub const height = 2160; + pub const stage: Rect = .{ .x = 112, .y = 96, .w = 3616, .h = 1688 }; + pub const columns = [4]f32{ 112, 1024, 1936, 2848 }; + pub const column = 880; + pub const outline = 2; + pub const outline_out = 4; + /// The stack's column: from this many words above rsp (the 128 bytes the recording keeps under it). + pub const stack_above = 16; + pub const disasm_rows = 69; + pub const memory_rows = 32; +}; +pub const minimap = struct { + pub const box: Rect = .{ .x = 1664, .y = 912, .w = 192, .h = 108 }; + pub const scale = 1.0 / 20.0; + /// The clock's count, ranged right here. + pub const count_end = 1648; +}; + /// Left edge of column `i` (0 to 11). pub fn colX(i: u8) f32 { return @floatFromInt(@as(u32, canvas.margin_x) + @as(u32, i) * (canvas.column + canvas.gutter)); @@ -219,6 +244,19 @@ pub const color = struct { /// A node's pointer half. pub const well: u24 = 0x101a48; + /// The current row's band: bright a tenth of the way over the page, + /// opaque. Gold is kept for the plaque, the pc's marker, rip's name, + /// the thread and the trail (design/README.md, `mark`). + pub const wash: u24 = 0x212644; + /// A loupe's surface and its tag: lifted off the page, the one + /// elevation in the frame; and its shadow, the one shadow there is. + pub const lift: u24 = 0x121c52; + pub const lift_tag: u24 = 0x22317a; + pub const shade: u24 = 0x02061a; + /// A strike's paper: vermilion 70% over the page, its digits bold and + /// bright. The arm, the turned corner and a projection stay `mark(.write).solid`. + pub const struck: u24 = 0xb54f42; + /// Drawn over everything that is not the subject, to dim it: for a /// beat, and (deeper) under the camera. pub const veil: u24 = page; @@ -256,9 +294,9 @@ pub const Role = enum { /// How a role is drawn. No two roles share a form, so none is told by hue alone. pub const Form = enum { - /// A solid plaque on the thing's label and its ember across the row. + /// A solid plaque on the thing's label and a white wash across the row. plaque, - /// A solid fill with ink letters, cooling to its ember and a solid bar along the bottom. + /// A softened fill with bright bold letters, cooling to nothing and a turned corner. fill, /// A frame, with its ember inside. frame, @@ -293,7 +331,7 @@ pub const Mark = struct { pub fn mark(role: Role) Mark { const t = color.text; return switch (role) { - .current => .{ .solid = 0xe8c46a, .ember = 0x4a3d1c, .on_solid = t.ink, .form = .plaque }, + .current => .{ .solid = 0xe8c46a, .ember = color.wash, .on_solid = t.ink, .form = .plaque }, .write => .{ .solid = 0xff6a4a, .ember = 0x5a2218, .on_solid = t.ink, .form = .fill }, .read => .{ .solid = 0x6fd6e6, .ember = 0x1c4652, .on_solid = t.ink, .form = .frame }, // Its colour is the region's it points into (`color.region`); this is heap's. @@ -473,8 +511,9 @@ pub const metric = struct { /// highest non-zero one, this far. pub const lead_alpha = 0.6; pub const pad_alpha = 0.45; - /// `held`: a tick 4 wide, the row less 6 tall, at the value's left. - pub const tick = 4; + /// `held`: a turned corner, a vermilion right triangle this long on + /// its sides at the value's top left (4 left of its digits, 2 down). + pub const corner = 9; /// `read`: a 2-unit frame, 6 out at the sides. pub const read_frame = 2; /// `struck`: solid 5 wider each side; its edges pulse out 3. @@ -499,10 +538,12 @@ pub const metric = struct { pub const annotation = 564; }; - /// `bytes`: a hexdump row, from its panel's left edge (the band's right half). + /// `bytes`: a hexdump row, from its panel's left edge (the band's right + /// half): its `arc` lanes, the quiet bracket at 24, the address at 34, + /// the bytes 12 after it and at 132 at least. pub const bytes = struct { - pub const bracket = 7; - pub const address = 18; + pub const bracket = 24; + pub const address = 34; pub const first = 132; /// Two digits in 24 units on a pitch of 30, 12 more after the eighth. pub const pitch = 30; @@ -510,12 +551,15 @@ pub const metric = struct { pub const reading = 640; }; - /// `slot`: a lane for `row` pins, the chain from 122, room to 136 from - /// the right edge (which belongs to the `call` spans, 14 in). + /// `slot`: two `arc` lanes, a lane for `row` pins from 16 to 112, the offset from rsp + /// ranged right to 172, the address from 184 and its chain after it, + /// room to 136 from the right edge (which belongs to the `call` spans, + /// 14 in), a role ranged right where the room ends. pub const slot = struct { - pub const lane = 10; + pub const lane = 16; pub const lane_end = 112; - pub const chain = 122; + pub const offset = 172; + pub const address = 184; pub const room = 136; pub const span = 14; }; @@ -573,6 +617,38 @@ pub const metric = struct { pub const caller = [2]f32{ 64, 28 }; }; + /// `arc`: a pointer to a row of its own panel, along a lane at the + /// panel's left edge (4, 10, 16 in a dump or a loupe; 4, 10 on the + /// stack), 2 wide, corners of 4; out of its row at 21, into the + /// target's at 22 with a head 7 by 8; going up it leaves its row 9 down + /// and arrives 15 down (going down, 15 and 9). Standing, its ink 60% + /// toward the page. + pub const arc = struct { + pub const lanes = [3]f32{ 4, 10, 16 }; + pub const stack_lanes = 2; + pub const out = 21; + pub const in = 22; + pub const head = [2]f32{ 7, 8 }; + pub const high = 9; + pub const low = 15; + pub const width = 2; + pub const radius = 4; + pub const standing = 0.6; + }; + + /// `loupe`: 880 wide, five rows round its target in the working frame; + /// it hangs from its pointer, its left edge 92 left of the pointer's + /// digits, its tag's top on the foot of the pointer's row; its shadow + /// 12 right and 16 down (20 and 26 for one opened from a loupe); its + /// stem a bracket 4 high under the pointer's digits. + pub const loupe = struct { + pub const width = 880; + pub const rows = 5; + pub const hang = 92; + pub const shadow = [2][2]f32{ .{ 12, 16 }, .{ 20, 26 } }; + pub const stem = 4; + }; + /// A lens's lanes: projections 4 under its tag, links 8 above its bottom edge. pub const lens = struct { pub const top_lane = 4; @@ -589,8 +665,9 @@ pub const metric = struct { pub const projection_radius = 6; }; + /// `held` on a lens's cell: the turned corner at its top left. + pub const corner_cell = 12; /// A lens's cell, as the first pass drew them. - pub const ember_bar = 4; pub const pointer_frame_outset = 6; pub const elision_h = 24; pub const cell = [2]f32{ 96, 84 }; @@ -721,6 +798,8 @@ pub const time = struct { pub const pulse = 0.20; pub const hold = 0.50; pub const cool = 0.40; + /// `held`'s turned corner fades in over the cool's last 6 f. + pub const corner = 0.10; pub const ember_steps = 3; pub const ember_seconds = 4.0; pub const out = 0.60; @@ -791,6 +870,31 @@ pub const time = struct { pub const far = 0.50; pub const out = 0.30; }; + /// `arc`: a pointer rewritten: from 6 f after the strike the old arc + /// fades (`fade`) as the new draws (`draw`), at full ink; it quiets + /// with the cool (`quiet`); a lane change glides (`lane`). + pub const arc = struct { + pub const after = 0.10; + pub const draw = 0.20; + pub const fade = 0.20; + pub const quiet = 0.40; + pub const lane = 0.20; + }; + /// `open`, a loupe: its pointer framed as read (`read`); the stem + /// draws and the loupe rises with it (`stem`; it fades in over `rise` + /// from 8 units lower, its shadow grows over `shadow`); its target's + /// bright frame lands `frame` after. `close`: the stem draws back and + /// the loupe sinks, fading as it falls 8 units, over `close`. + pub const loupe = struct { + pub const read = 0.10; + pub const stem = 0.30; + pub const rise = 0.20; + pub const shadow = 0.30; + pub const frame = 0.10; + pub const close = 0.20; + /// From its first frame to its target's frame landed: read, stem, a frame's wait and the frame. + pub const open = 0.60; + }; /// `travel`, for a pin: it sets off `after` the strike that moved it; /// in a drawing it takes `node` to the next node or cell, `nodes` to /// one farther; in the stack's lane `row` to the next row and @@ -921,16 +1025,19 @@ test "every mark stands off the page, and letters read on it" { const m = mark(r); try expect(contrast(m.solid, color.page) >= 4.5); try expect(contrast(m.on_solid, m.solid) >= 4.5); - // A role with a quiet form: text reads on it, and it is not the page. + // A role with a quiet form: text reads on it, and it is not the page + // (the current row's wash is the quietest: 1.2 on the page). if (m.ember != m.solid and r != .freed and r != .fault) { try expect(contrast(color.text.primary, m.ember) >= 7); - try expect(contrast(m.ember, color.page) >= 1.4); + try expect(contrast(m.ember, color.page) >= @as(f64, if (r == .current) 1.2 else 1.4)); } } // The strokes that carry meaning on their own. for ([_]Role{ .current, .write, .read, .link, .allocated }) |r| try expect(contrast(mark(r).solid, color.page) >= 6.5); try expect(contrast(color.text.ink, mark(.write).solid) >= 6.5); + // A strike's bright digits on its softened paper. + try expect(contrast(color.text.bright, color.struck) >= 4.5); } test "no two roles are drawn the same way" { @@ -984,7 +1091,7 @@ test "easing runs from 0 to 1 without turning back" { test "durations are whole frames" { const t = time; - for ([_]f32{ t.snap, t.quick, t.step, t.step_per_row, t.step_max, t.move, t.travel, t.layout, t.camera, t.camera_far, t.fire, t.cascade, t.read_value, t.read_more, t.rest, t.strike.arm, t.strike.in, t.strike.pulse, t.strike.hold, t.strike.cool, t.strike.out, t.read.out, t.current_jump, t.flight.lift, t.flight.near, t.flight.second, t.veil, t.link.after, t.link.pin_out, t.link.in, t.link.in_far, t.link.settle, t.link.out, t.project.bracket, t.project.draw, t.project.out, t.establish_rise, t.relayout, t.relayout_fade, t.continue_wave, t.badge_after, t.pin.after, t.pin.node, t.pin.nodes, t.pin.row, t.pin.step_per_row, t.pin.row_max, t.pin.in, t.pin.out, t.pin.names, t.caption_in, t.caption_out, t.caption_gap, t.walk, t.run, t.sprint, t.phrase_rest, t.before_cut }) |d| { + for ([_]f32{ t.snap, t.quick, t.step, t.step_per_row, t.step_max, t.move, t.travel, t.layout, t.camera, t.camera_far, t.fire, t.cascade, t.read_value, t.read_more, t.rest, t.strike.arm, t.strike.in, t.strike.pulse, t.strike.hold, t.strike.cool, t.strike.corner, t.strike.out, t.loupe.read, t.loupe.stem, t.loupe.rise, t.loupe.shadow, t.loupe.frame, t.loupe.close, t.loupe.open, t.arc.after, t.arc.draw, t.arc.fade, t.arc.quiet, t.arc.lane, t.read.out, t.current_jump, t.flight.lift, t.flight.near, t.flight.second, t.veil, t.link.after, t.link.pin_out, t.link.in, t.link.in_far, t.link.settle, t.link.out, t.project.bracket, t.project.draw, t.project.out, t.establish_rise, t.relayout, t.relayout_fade, t.continue_wave, t.badge_after, t.pin.after, t.pin.node, t.pin.nodes, t.pin.row, t.pin.step_per_row, t.pin.row_max, t.pin.in, t.pin.out, t.pin.names, t.caption_in, t.caption_out, t.caption_gap, t.walk, t.run, t.sprint, t.phrase_rest, t.before_cut }) |d| { const frames = d * t.fps; try expect(@abs(frames - @round(frames)) < 1e-3); } diff --git a/anim/src/ties.zig b/anim/src/ties.zig index 0df8e34..323cecf 100644 --- a/anim/src/ties.zig +++ b/anim/src/ties.zig @@ -85,14 +85,15 @@ var said: usize = 0; /// `r` (in `u`'s units) is where `place` is, this frame. pub fn anchor(u: ui.Ui, place: Place, r: Rect) void { - if (said == table.len) return; + if (said == table.len or ui.mapping) return; const a = u.at.xf.apply(.{ r.x, r.y }); const b = u.at.xf.apply(.{ r.x + r.w, r.y + r.h }); table[said] = .{ .key = place.key(), .box = .{ a[0], a[1], b[0], b[1] } }; said += 1; } -fn find(place: Place) ?[4]f32 { +/// Where `place` is this frame, in canvas pixels (left, top, right, bottom), if a panel said. +pub fn find(place: Place) ?[4]f32 { for (table[0..said]) |entry| if (entry.key == place.key()) return entry.box; return null; } @@ -175,6 +176,8 @@ pub const Ties = struct { defer said = 0; defer stack_window = null; const now = g.cursor.now(at); + // Diving or surfacing, the panels are on their way: no ties. + for (@import("context.zig").zoomed) |z| if (z != null) return; // In canvas pixels, `k` of them a unit: places come from panels anywhere. var raw: ui.Ui = .{ .f = f, .at = at }; raw.at.xf = .identity; @@ -317,7 +320,7 @@ pub const Ties = struct { 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; // 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; + const bx = if (stacked) run[0] - (theme.metric.slot.address - 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 cx = (over[0] + over[2]) / 2; const y = (run[1] + run[3]) / 2; diff --git a/anim/src/ui.zig b/anim/src/ui.zig index 6120bbb..cf12914 100644 --- a/anim/src/ui.zig +++ b/anim/src/ui.zig @@ -16,6 +16,19 @@ pub const Vec = sk.math.Vec; /// Scene units to a design unit: `anim` frames 1280 by 720. pub const scale = 1280.0 / @as(comptime_float, theme.canvas.width); +/// While the map's panels draw (`map.zig`): they publish their rows, not +/// their windows and places. `strokes`: the minimap, a twentieth of the +/// map, where text is a stroke a pixel high in its ink at 45% toward the +/// page and the marks are blocks a few pixels across. +/// shortcut: process-wide, for one scene drawn at a time; two players at once want it on the frame. +pub var mapping = false; +pub var strokes = false; +/// How much of a panel's tag and rules shows: less while it dives out of +/// its window on the map (`context.at` sets it for the panel it hands out). +pub var chrome: f32 = 1; +/// The minimap's pixel, in the map's units. +const px = 20; + /// Adds `data` (a component: something with `draw(f, at)`) to the scene, /// its origin at design `x, y` and its units the design's. Like any /// object, it shows once something plays it in (`fadeIn`). @@ -145,8 +158,9 @@ pub const Ui = struct { u.f.fill(sk.Rect{ .x = x, .y = y, .w = @round(b[0]) - x, .h = @round(b[1]) - y }, u.at.faded(rgb(c))); } - /// A stroke `w` wide, wholly inside `r`. - pub fn frame(u: Ui, r: Rect, c: anytype, w: f32) void { + /// A stroke `w` wide, wholly inside `r` (on the minimap, a pixel at least). + pub fn frame(u: Ui, r: Rect, c: anytype, w_: f32) void { + const w = if (strokes) @max(w_, px) else w_; u.fill(.{ .x = r.x, .y = r.y, .w = r.w, .h = w }, c); u.fill(.{ .x = r.x, .y = r.y + r.h - w, .w = r.w, .h = w }, c); u.fill(.{ .x = r.x, .y = r.y + w, .w = w, .h = r.h - 2 * w }, c); @@ -164,6 +178,11 @@ pub const Ui = struct { /// which is the font's ascent above the baseline. pub fn text(u: Ui, face: Face, size: f32, x: f32, baseline: f32, bytes: []const u8, c: anytype) void { if (bytes.len == 0) return; + if (strokes) { + // A run of text: a stroke as long as it is, through its capitals' middle. + if (std.mem.indexOfNone(u8, bytes, " ") == null) return; + return u.fill(.{ .x = x, .y = baseline - 0.36 * size - px / 2, .w = u.width(face, size, bytes), .h = px }, mix(c, theme.color.page, 0.45)); + } // Go's ascent is 0.945 em; JetBrains Mono's, which every monospace is set in, 1.02. const at = u.point(x, baseline - @as(f32, if (set(face, size) == face) 0.945 else 1.02) * size); const drawn = size / 13.0 * u.at.scale; @@ -206,7 +225,7 @@ pub const Ui = struct { /// from frame to frame: with CANIM_PANELS in the environment, every /// frame tells where on the canvas (as fractions of it) `r` is. pub fn region(u: Ui, name: []const u8, r: Rect) void { - if (u.f.host.env("CANIM_PANELS") == null) return; + if (mapping or u.f.host.env("CANIM_PANELS") == null) return; const a = u.point(r.x, r.y); const b = u.point(r.x + r.w, r.y + r.h); const w = @floor(u.f.in.window_width); @@ -224,6 +243,12 @@ pub const Ui = struct { /// window `w` by `h` at the origin. Returns the body. pub fn panel(u: Ui, w: f32, h: f32, title: []const u8, options: struct { focus: bool = false, note: []const u8 = "", legend: []const Legend = &.{} }) Rect { u.region(title, .{ .x = 0, .y = 0, .w = w, .h = h }); + if (chrome < 1) return u.faded(chrome).panelChrome(w, h, title, options.focus, options.note, options.legend); + return u.panelChrome(w, h, title, options.focus, options.note, options.legend); + } + + fn panelChrome(u: Ui, w: f32, h: f32, title: []const u8, focus: bool, note: []const u8, legend: []const Legend) Rect { + const options = .{ .focus = focus, .note = note, .legend = legend }; const m = theme.metric.context; const t = theme.color.text; u.fill(.{ .x = 0, .y = 0, .w = w, .h = m.tag }, theme.color.raised); @@ -319,6 +344,7 @@ pub const Ui = struct { /// on the row whose middle is `mid`, faint: grammar, not data. /// Returns where it ends. pub fn arrow(u: Ui, x: f32, mid: f32, kind: Arrow) f32 { + if (strokes) return x + theme.metric.context.arrow_w + @as(f32, if (kind == .more) 24 else 0); const c = theme.color.text.faint; const head = theme.metric.context.arrow_head; const pen = u.at.pen(.{ .fill = rgb(c) }); @@ -340,53 +366,72 @@ pub const Ui = struct { /// `mark` on a value in the context (mono 20), as hot as `h` says: /// `armed` (a 2-unit vermilion frame round the old value), `struck` - /// (solid vermilion behind it, 5 wider each side, its edges pulsing out - /// 3; the digits bold, in ink: the ink this returns), then cooled to - /// nothing, and `held`: a tick 4 wide at the value's left for three - /// steps. A held change never sits under the digits it marks, whose - /// ink is where they point. `r` is the digits: x, width, and the row; - /// the tick is `tick` units left of them (5 after a chain's arrow). - pub fn written(u: Ui, r: Rect, h: Heat, tick: f32) ?Ink { + /// (the softened vermilion paper behind it, 5 wider each side, its + /// edges pulsing out 3; the digits bold and bright: the ink this + /// returns), then cooled to nothing, and `held`: a turned corner at + /// the value's top left for three steps, fading in over the cool's + /// last 6 f. A held change never sits under the digits it marks, whose + /// ink is where they point. `r` is the digits: x, width, and the row. + pub fn written(u: Ui, r: Rect, h: Heat) ?Ink { const w = theme.mark(.write); const m = theme.metric.context; - // The tick is what a strike cools to: not under it while it is solid. - const held = h.level * (1 - (if (h.level >= 1) h.solid * h.in else 0)); - if (held > 0) u.fill(.{ .x = r.x - tick, .y = r.y + 3, .w = m.tick, .h = r.h - 6 }, mix(theme.color.page, w.solid, held)); + if (strokes) { + // On the minimap: a strike a block 3 pixels across at the value's start; held, a pixel. + const mid = r.y + r.h / 2; + if (h.level >= 1 and h.solid * h.in > 0) { + u.faded(h.solid * h.in).fill(.{ .x = r.x, .y = mid - 1.5 * px, .w = 3 * px, .h = 3 * px }, w.solid); + } else if (h.level * h.corner > 0) u.faded(h.level * h.corner).fill(.{ .x = r.x, .y = mid - px / 2, .w = px, .h = px }, w.solid); + return null; + } if (h.arm > 0) u.faded(h.arm).frame(.{ .x = r.x - 6, .y = r.y, .w = r.w + 12, .h = r.h }, w.solid, m.read_frame); const solid = if (h.level >= 1) h.solid * h.in else 0; - if (solid <= 0) return null; - const out = @min(h.out, m.pulse_outset); - u.fill(.{ .x = r.x - m.strike_out - out, .y = r.y + 1 - out, .w = r.w + 2 * m.strike_out + 2 * out, .h = r.h - 2 + 2 * out }, mix(theme.color.page, w.solid, solid)); - return if (solid >= 0.5) Ink.all(w.on_solid, .mono_bold) else null; + if (solid > 0) { + const out = @min(h.out, m.pulse_outset); + u.fill(.{ .x = r.x - m.strike_out - out, .y = r.y + 1 - out, .w = r.w + 2 * m.strike_out + 2 * out, .h = r.h - 2 + 2 * out }, mix(theme.color.page, theme.color.struck, solid)); + } + u.corner(r.x - 4, r.y + 2, m.corner, h.level * h.corner); + return if (solid >= 0.5) Ink.all(theme.color.text.bright, .mono_bold) else null; + } + + /// `held`: a turned corner, a vermilion right triangle `side` on its + /// sides, its right angle at `x, y` (a value's or a cell's top left), + /// `shows` of it. + pub fn corner(u: Ui, x: f32, y: f32, side: f32, shows: f32) void { + if (shows <= 0) return; + sk.draw.polygon(u.f, &.{ .{ x, y }, .{ x + side, y }, .{ x, y + side } }, u.faded(shows).at.pen(.{ .fill = rgb(theme.mark(.write).solid) })); } /// `read` in the context: a 2-unit frame in read's colour, 6 out at /// the sides, no fill; `shows` of it (0 to 1: it fades in and out). pub fn read(u: Ui, r: Rect, shows: f32) void { + if (strokes) { + if (shows > 0) u.faded(shows).frame(.{ .x = r.x, .y = r.y + r.h / 2 - 1.5 * px, .w = 3 * px, .h = 3 * px }, theme.mark(.read).solid, px); + return; + } if (shows > 0) u.faded(shows).frame(.{ .x = r.x - 6, .y = r.y, .w = r.w + 12, .h = r.h }, theme.mark(.read).solid, theme.metric.context.read_frame); } - /// `mark` on a lens's cell: armed (a 3-unit frame), struck (a solid - /// fill coming in, its edges out 4 and back), cooled to its ember and - /// a vermilion bar 4 high along its bottom edge (`held`), `ground` - /// (null: nothing) once that has gone. Returns what to set its digits in. + /// `mark` on a lens's cell: armed (a 3-unit frame), struck (the + /// softened vermilion coming in, its edges out 4 and back, the digits + /// bold and bright), cooled to its ground (`ground`; null: nothing), + /// and `held`: a turned corner 12 on its sides at its top left. Returns + /// what to set its digits in. pub fn cellWritten(u: Ui, r: Rect, h: Heat, ground: ?u24) Ink { - const w = theme.mark(.write); const under: Color = rgb(ground orelse theme.color.page); - // No mark under coloured digits but a strike's: it cools to its ground, and the bar stays. - var body = if (h.level < 1) under else mix(under, w.solid, h.solid); + // No mark under coloured digits but a strike's: it cools to its ground, and the corner stays. + var body = if (h.level < 1) under else mix(under, theme.color.struck, h.solid); // Timing: a strike arrives over a tenth of a second, not in a frame. if (h.in < 1) body = mix(under, body, h.in); if (h.level > 0 or ground != null) u.fill(.{ .x = r.x - h.out, .y = r.y - h.out, .w = r.w + 2 * h.out, .h = r.h + 2 * h.out }, body); - const bar = theme.metric.ember_bar; - if (h.level > 0 and (h.in >= 1 or h.from == .ember)) u.fill(.{ .x = r.x, .y = r.y + r.h - bar, .w = r.w, .h = bar }, mix(under, w.solid, @min(h.level, 1))); - if (h.arm > 0) u.faded(h.arm).frame(r, w.solid, theme.stroke.line); - // Bold ink on the solid. The face changes at the middle of the - // cool, where the colour is moving fastest and hides it. + u.corner(r.x, r.y, theme.metric.corner_cell, h.level * h.corner); + if (h.arm > 0) u.faded(h.arm).frame(r, theme.mark(.write).solid, theme.stroke.line); + // Bold and bright on the paper. The face changes at the middle of + // the cool, where the colour is moving fastest and hides it. const heat = h.solid * h.in; if (h.level < 1 or heat <= 0) return .{}; const cooled: Ink = .{}; - return .{ .ink = mix(cooled.ink, w.on_solid, heat), .lead = mix(cooled.lead, w.on_solid, heat), .face = if (heat >= 0.5) .mono_bold else .mono }; + const t = theme.color.text; + return .{ .ink = mix(cooled.ink, t.bright, heat), .lead = mix(cooled.lead, t.bright, heat), .face = if (heat >= 0.5) .mono_bold else .mono }; } /// `read` on a lens's cell: a 2-unit frame 2 out, no fill. @@ -394,10 +439,12 @@ pub const Ui = struct { if (shows > 0) u.faded(shows).frame(.{ .x = r.x - 2, .y = r.y - 2, .w = r.w + 4, .h = r.h + 4 }, theme.mark(.read).solid, theme.stroke.rule); } - /// `current` on a row: gold ember across `r`, and a gold plaque `w` - /// wide at its left, its edges out `out` units (the fire). + /// `current` on a row: the white wash across `r`, and a gold plaque + /// `w` wide at its left, its edges out `out` units (the fire). pub fn current(u: Ui, r: Rect, w: f32, out: f32) void { const gold = theme.mark(.current); + // On the minimap: a gold stroke across the column, 2 pixels high. + if (strokes) return u.fill(.{ .x = r.x, .y = r.y + r.h / 2 - px, .w = r.w, .h = 2 * px }, gold.solid); u.fill(r, gold.ember); u.fill(.{ .x = r.x - out, .y = r.y - out, .w = w + 2 * out, .h = r.h + 2 * out }, gold.solid); } @@ -683,9 +730,15 @@ pub const Heat = struct { arm: f32 = 0, /// The strike's pulse: how far out its edges are, in units. out: f32 = 0, + /// 0 to 1: how much of `held`'s turned corner shows (of `level`): none + /// while struck, in over the cool's last 6 f; the old one's going as a + /// strike comes in over it. + corner: f32 = 1, pub const none: Heat = .{}; pub const ember: Heat = .{ .level = 1 }; + /// Struck, at rest: the paper solid, no corner yet. + pub const struck: Heat = .{ .level = 1, .solid = 1, .corner = 0 }; }; test "the camera zooms by ratio and ends where it was sent" { diff --git a/anim/src/words.zig b/anim/src/words.zig index bec5116..134b42f 100644 --- a/anim/src/words.zig +++ b/anim/src/words.zig @@ -22,6 +22,8 @@ const t = theme.color.text; pub const Clock = struct { cursor: Cursor, box: Rect = .{ .x = theme.canvas.stage.x, .y = theme.canvas.clock_y - 12, .w = theme.canvas.stage.w, .h = 24 }, + /// The map, drawn small under the clock's right end: the minimap. + map: ?*const @import("map.zig").Map = null, pub fn draw(k: *const Clock, f: *sk.Frame, at: anim.Placed) void { const u = fixed(f, at, 0); @@ -58,13 +60,15 @@ pub const Clock = struct { const size = theme.size.mono.context; const base = c.clock_y + 28; const count = u.print("moment {d} of {d}", .{ counted -| now.way[0], now.way[1] -| now.way[0] }); - const count_x = stage.x + stage.w - u.width(.mono, size, count); + // Ranged right left of the minimap. + const count_x = (if (k.map != null) theme.minimap.count_end else stage.x + stage.w) - u.width(.mono, size, count); u.text(.mono, size, count_x, base, count, t.faint); // Secondary action: the pace, said quietly. It only fades. if (now.hurried > 0) { const steps = if (now.of > 0) u.print("step {d} of {d}", .{ now.count, now.of }) else u.print("step {d}", .{now.count}); u.faded(now.hurried).text(.mono, size, count_x - u.width(.mono, size, steps) - 3 * ui.advance(size), base, steps, t.dim); } + if (k.map) |m| if (m.settled(at)) @import("map.zig").minimap(m, f, at); } }; @@ -195,7 +199,7 @@ pub const Legend = struct { u.label(.mono_bold, size, r, .center, "rip", theme.mark(.current).on_solid); }, .written, .changed => for ([_]Rect{ half, other }, [_][]const u8{ "2a", "00" }) |cell, digits| { - const ink = u.cellWritten(cell, if (entry == .written) .{ .level = 1, .solid = 1 } else .ember, theme.color.raised); + const ink = u.cellWritten(cell, if (entry == .written) .struck else .ember, theme.color.raised); u.label(ink.face, size, cell, .center, digits, ink.ink); }, .read => for ([_]Rect{ half, other }, [_][]const u8{ "2a", "00" }) |cell, digits| { |
