diff options
Diffstat (limited to 'anim/src')
| -rw-r--r-- | anim/src/Recording.zig | 104 | ||||
| -rw-r--r-- | anim/src/context.zig | 23 | ||||
| -rw-r--r-- | anim/src/cursor.zig | 21 | ||||
| -rw-r--r-- | anim/src/descent.zig | 39 | ||||
| -rw-r--r-- | anim/src/disasm.zig | 73 | ||||
| -rw-r--r-- | anim/src/graph.zig | 9 | ||||
| -rw-r--r-- | anim/src/hexdump.zig | 19 | ||||
| -rw-r--r-- | anim/src/map.zig | 882 | ||||
| -rw-r--r-- | anim/src/root.zig | 31 | ||||
| -rw-r--r-- | anim/src/rows.zig | 22 | ||||
| -rw-r--r-- | anim/src/source.zig | 115 | ||||
| -rw-r--r-- | anim/src/syscalls.zig | 3 | ||||
| -rw-r--r-- | anim/src/theme.zig | 31 | ||||
| -rw-r--r-- | anim/src/ui.zig | 88 | ||||
| -rw-r--r-- | anim/src/words.zig | 12 |
15 files changed, 1051 insertions, 421 deletions
diff --git a/anim/src/Recording.zig b/anim/src/Recording.zig index a6e940c..359305c 100644 --- a/anim/src/Recording.zig +++ b/anim/src/Recording.zig @@ -101,6 +101,15 @@ source: []const u8, /// Its functions, as pardes outlines them, and how many lines it has. functions: []const Function = &.{}, line_count: u32 = 0, +/// Every file the source panel can show: the program's own first (`file`, +/// `source`), then those the build gave it (a library's, by the path its +/// debug info names); and the most lines any of them has. +sources: []const Source = &.{}, +most_lines: u32 = 0, +/// Where the source panel stands after each moment: the line the pc is on +/// where its file is one of `sources`, else the last such line (the +/// deepest frame that has source, a frame up). +shown: []Shown = &.{}, /// The thread shown: the first to make an event. tid: u32 = 0, /// The source line `tid` is on after each moment (line 0: none yet), in @@ -142,17 +151,39 @@ const gpa = std.heap.smp_allocator; /// `frame` runs every frame and asks again. var opened: std.ArrayList(*Recording) = .empty; +/// A file the source panel can show: its path as the debug info names it +/// (the program's own, its bare name), its text and how many lines. +pub const Source = struct { + path: []const u8, + text: []const u8, + lines: u32, + + /// What its tag says: the file's name. + pub fn name(s: Source) []const u8 { + return std.fs.path.basename(s.path); + } +}; + +/// A line of `sources[src]`; `here`: the pc is on it (else a frame up is). +pub const Shown = struct { src: u16 = 0, line: u32 = 0, here: bool = false }; + /// A recording as the build embeds it in `recordings`: a `.ztrace` file's -/// bytes (`trace`), the source it ran (`source`) and its name (`file`). -/// Opened and indexed the first time. +/// bytes (`trace`), the source it ran (`source`) and its name (`file`), +/// and the other sources its lines name that the build found (`sources`: +/// path and text). Opened and indexed the first time. pub fn open(program: anytype) *Recording { for (opened.items) |r| if (r.key == program.trace.ptr) return r; - const r = load(program.trace, program.file, program.source) catch |err| std.debug.panic("canim: cannot open the recording of {s}: {t}", .{ program.file, err }); + const more: []const [2][]const u8 = if (@hasField(@TypeOf(program), "sources")) program.sources else &.{}; + const r = load(program.trace, program.file, program.source, more) catch |err| std.debug.panic("canim: cannot open the recording of {s}: {t}", .{ program.file, err }); opened.append(gpa, r) catch @panic("canim: out of memory"); return r; } -fn load(bytes: []const u8, file: []const u8, source: []const u8) !*Recording { +fn lineCount(text: []const u8) u32 { + return @intCast(std.mem.count(u8, text, "\n") + @intFromBool(text.len > 0 and text[text.len - 1] != '\n')); +} + +fn load(bytes: []const u8, file: []const u8, source: []const u8, more: []const [2][]const u8) !*Recording { // The trace reads a file: give it one in memory. const linux = std.os.linux; const rc = linux.memfd_create("canim", linux.MFD.CLOEXEC); @@ -173,7 +204,12 @@ fn load(bytes: []const u8, file: []const u8, source: []const u8) !*Recording { r.* = .{ .trace = try .open(gpa, std.Io.Threaded.global_single_threaded.io(), path), .key = bytes.ptr, .file = file, .source = source, .arena = .init(gpa) }; if (r.trace.len == 0) return error.EmptyRecording; r.functions = try outline(r.arena.allocator(), source, file); - r.line_count = @intCast(std.mem.count(u8, source, "\n") + @intFromBool(source.len > 0 and source[source.len - 1] != '\n')); + r.line_count = lineCount(source); + const sources = try r.arena.allocator().alloc(Source, 1 + more.len); + sources[0] = .{ .path = file, .text = source, .lines = r.line_count }; + for (more, sources[1..]) |pair, *s| s.* = .{ .path = pair[0], .text = pair[1], .lines = lineCount(pair[1]) }; + r.sources = sources; + for (sources) |s| r.most_lines = @max(r.most_lines, s.lines); try r.index(); return r; } @@ -184,13 +220,32 @@ fn load(bytes: []const u8, file: []const u8, source: []const u8) !*Recording { /// its function is (0: not known); `line`, the line of the program's own /// source it was compiled from (null: another file's, or not known); /// `params`, a direct call's callee's parameter count. -pub fn instruction(r: *const Recording, i: u64, addr: u64, buf: []u8) ?struct { len: u8, back: u8, text: []const u8, line: ?u32, params: ?u8 } { +pub fn instruction(r: *const Recording, i: u64, addr: u64, buf: []u8) ?struct { len: u8, back: u8, text: []const u8, line: ?u32, src: u16 = 0, params: ?u8 } { const found = (zt.telescope.instruction(r.moment(i), addr, buf) catch return null) orelse return null; - var line: ?u32 = null; - if (found.line) |l| if (std.mem.eql(u8, std.fs.path.basename(r.name(l.file)), r.file)) { - line = l.line; - }; - return .{ .len = found.len, .back = found.back, .text = found.text, .line = line orelse r.lineOf(addr), .params = found.params }; + if (found.line) |l| if (r.sourceOf(l.file)) |k| return .{ .len = found.len, .back = found.back, .text = found.text, .line = l.line, .src = k, .params = found.params }; + return .{ .len = found.len, .back = found.back, .text = found.text, .line = r.lineOf(addr), .params = found.params }; +} + +/// The source a line's file (a string id) is, of `sources`: null where the recording has none. +pub fn sourceOf(r: *const Recording, file: u64) ?u16 { + const path = r.name(file); + if (std.mem.eql(u8, std.fs.path.basename(path), r.file)) return 0; + for (r.sources, 0..) |s, k| if (k > 0 and std.mem.eql(u8, s.path, path)) return @intCast(k); + return null; +} + +/// Where the code at `addr` is, as the debug info has it at moment `i`: +/// its file's name and line, whatever the file (a library's too, its +/// source in hand or not); at moment `i`'s own pc, the moment's line. +pub fn where(r: *const Recording, i: u64, addr: u64) ?struct { file: []const u8, line: u32 } { + var buf: [256]u8 = undefined; + if (addr == r.register(i, "rip")) { + const l = r.lines[@min(i, r.end())]; + if (l.line != 0) return .{ .file = std.fs.path.basename(r.name(l.file)), .line = l.line }; + } + const found = (zt.telescope.instruction(r.moment(i), addr, &buf) catch null) orelse return null; + if (found.line) |l| return .{ .file = std.fs.path.basename(r.name(l.file)), .line = l.line }; + return if (r.lineOf(addr)) |l| .{ .file = r.file, .line = l } else null; } /// The source line the instruction at `addr` was compiled from, for a @@ -218,8 +273,9 @@ pub fn ownLine(r: *const Recording, i: u64) ?u32 { return l.line; } -/// Whether the pc at moment `i` is in the program's own source: not in a -/// library's code, a PLT stub, the vDSO (where `own` keeps the last line). +/// Whether the pc at moment `i` is on a line the source panel can show (the +/// program's own, or a library's whose source the build gave): not in a +/// PLT stub, the vDSO, a library without source (where `shown` keeps the last line). pub fn sourced(r: *const Recording, i: u64) bool { var buf: [256]u8 = undefined; const here = r.instruction(i, r.register(i, "rip"), &buf) orelse return r.ownLine(i) != null; @@ -227,14 +283,20 @@ pub fn sourced(r: *const Recording, i: u64) bool { } /// The first line a source panel of `fit` lines shows when the program is -/// on `line`: the whole file when it fits; else a window that has the line -/// in its middle third, and is the same window for every line of that -/// third, so that the text moves only when the program has moved on. -pub fn viewFirst(r: *const Recording, fit: u32, line: u32) u32 { - if (r.line_count <= fit or fit < 3) return 1; +/// on `line` of a file of `lines`: the whole file when it fits; else a +/// window that has the line in its middle third, and is the same window +/// for every line of that third, so that the text moves only when the +/// program has moved on. +pub fn viewFirst(fit: u32, lines: u32, line: u32) u32 { + if (lines <= fit or fit < 3) return 1; const third = fit / 3; const band = (@max(line, 1) - 1) / third; - return std.math.clamp(@as(u32, @intCast(@max(@as(i64, band) - 1, 0))) * third + 1, 1, r.line_count - fit + 1); + return std.math.clamp(@as(u32, @intCast(@max(@as(i64, band) - 1, 0))) * third + 1, 1, lines - fit + 1); +} + +/// The first line of `shown`'s file a source panel of `fit` lines shows. +pub fn shownFirst(r: *const Recording, fit: u32, shown: Shown) u32 { + return viewFirst(fit, r.sources[shown.src].lines, shown.line); } /// Runs of bytes, a list for each moment. @@ -257,6 +319,7 @@ fn index(r: *Recording) !void { const arena = r.arena.allocator(); var lines: std.ArrayList(store.Line) = .empty; var own: std.ArrayList(u32) = .empty; + var shown: std.ArrayList(Shown) = .empty; var reached: std.ArrayList(bool) = .empty; var depths: std.ArrayList(u32) = .empty; var calls: std.ArrayList(Call) = .empty; @@ -429,6 +492,8 @@ fn index(r: *Recording) !void { try lines.append(arena, line); const ours = line.line != 0 and std.mem.eql(u8, std.fs.path.basename(r.name(line.file)), r.file); try own.append(arena, if (ours) line.line else if (own.items.len > 0) own.items[own.items.len - 1] else 0); + const src = if (line.line != 0) r.sourceOf(line.file) else null; + try shown.append(arena, if (src) |k| .{ .src = k, .line = line.line, .here = true } else if (shown.items.len > 0) .{ .src = shown.items[shown.items.len - 1].src, .line = shown.items[shown.items.len - 1].line } else .{}); try reached.append(arena, ours and line_file != null); try touch_list.append(arena, touched); pending = touched; @@ -509,6 +574,7 @@ fn index(r: *Recording) !void { }; r.lines = lines.items; r.own = own.items; + r.shown = shown.items; r.reached = reached.items; r.depths = depths.items; r.calls = calls.items; diff --git a/anim/src/context.zig b/anim/src/context.zig index 55ff9d6..15ece55 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -298,17 +298,17 @@ pub fn callArguments(u: ui.Ui, rec: *const Recording, open: []const Recording.Ca /// not); an older one on its call's line, or where the recording only /// knows a line near its return address, that one. pub fn frameWhere(u: ui.Ui, rec: *const Recording, moment: u64, i: usize, pc: u64) []const u8 { - const line = if (i == 0) rec.ownLine(moment) else callLine(rec, moment, pc) orelse rec.lineOf(pc); - return if (line) |l| u.print("{s}:{d}", .{ rec.file, l }) else ""; + const place = if (i == 0) rec.where(moment, pc) else rec.where(moment, callOf(rec, moment, pc) orelse pc); + return if (place) |l| u.print("{s}:{d}", .{ l.file, l.line }) else ""; } -/// The line of the call that returns to `ret`, where the recording has it: -/// an outer frame is on its call's line, not on the one it returns to. -fn callLine(rec: *const Recording, moment: u64, ret: u64) ?u32 { +/// The call that returns to `ret`, where the recording has it: an outer +/// frame is on its call's line, not on the one it returns to. +fn callOf(rec: *const Recording, moment: u64, ret: u64) ?u64 { var buf: [256]u8 = undefined; const after = rec.instruction(moment, ret, &buf) orelse return null; if (after.back == 0) return null; - return (rec.instruction(moment, ret - after.back, &buf) orelse return null).line; + return ret - after.back; } /// A frame's name: its function's (no offset), or its module's and offset where there is no symbol. @@ -529,10 +529,10 @@ pub const Stack = struct { if (slot_shows <= 0) continue; const vs = v.faded(slot_shows); // A frame's name beside this row: the chain ends a character before it. - var room_w = box.w; + var room_w = map.content(box.w); for (spans[0..n_spans]) |sp| { const mid = (sp.y0 + sp.y1) / 2; - if (mid + m.row / 2 > y and mid - m.row / 2 < y + m.row) room_w = @min(room_w, rows.spanNameX(u, box.w, sp.name) - ui.advance(theme.size.mono.context) + theme.metric.slot.room); + if (mid + m.row / 2 > y and mid - m.row / 2 < y + m.row) room_w = @min(room_w, rows.spanNameX(u, map.content(box.w), sp.name) - ui.advance(theme.size.mono.context) + theme.metric.slot.room); } var gap: f32 = 0; if (lone) |name| { @@ -605,10 +605,11 @@ pub const Stack = struct { u.pinRow(x, top + place * m.row, if (both) &.{ "rsp", "rbp" } else &.{name}, theme.color.region.stack); } for (spans[0..n_spans]) |sp| if (sp.was) |was_name| { - rows.span(v.faded(1 - renamed), box.w, sp.y0, sp.y1, was_name, sp.newest, sp.open); - rows.span(v.faded(renamed), box.w, sp.y0, sp.y1, sp.name, sp.newest, sp.open); - } else rows.span(v, box.w, sp.y0, sp.y1, sp.name, sp.newest, sp.open); + rows.span(v.faded(1 - renamed), map.content(box.w), sp.y0, sp.y1, was_name, sp.newest, sp.open); + rows.span(v.faded(renamed), map.content(box.w), sp.y0, sp.y1, sp.name, sp.newest, sp.open); + } else rows.span(v, map.content(box.w), sp.y0, sp.y1, sp.name, sp.newest, sp.open); veiled(u, box, now.veil); + if (k.part == .stack) map.strip(.stack, u, box); } /// A slot's role as the catalogue writes it: `saved rbx` (dim); a diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig index f0f90ff..9de02c1 100644 --- a/anim/src/cursor.zig +++ b/anim/src/cursor.zig @@ -394,10 +394,19 @@ pub const Cursor = struct { /// or at the end of a continue (`wave`). fn travel(c: Cursor, from: u64, to: u64, wave: bool) f32 { const rec = c.rec; - // The source's window moves with it: by whole lines, and never a cut. - if (rec.viewFirst(c.levels.source_rows, rec.own[from]) != rec.viewFirst(c.levels.source_rows, rec.own[to])) return time.move; + const a = rec.shown[from]; + const b = rec.shown[to]; + // Another file: the source fades through (12 f out, 12 f in). + if (a.src != b.src) return time.move; + // The source's window moves with it: by whole lines, and never a cut; + // farther than its own height, its strip shows where it goes first + // (the window gliding there, 24 f), then the pane fades through. + const fit = c.levels.source_rows; + const windows = [2]u32{ rec.shownFirst(fit, a), rec.shownFirst(fit, b) }; + if (@max(windows[0], windows[1]) - @min(windows[0], windows[1]) > fit) return 2 * time.move; + if (windows[0] != windows[1]) return time.move; if (wave or jumps(rec, from, to)) return 2 * time.current_jump; - const rows: f32 = @floatFromInt(@max(rec.own[from], rec.own[to]) - @min(rec.own[from], rec.own[to])); + const rows: f32 = @floatFromInt(@max(a.line, b.line) - @min(a.line, b.line)); return @min(time.step + time.step_per_row * @max(rows - 1, 0), time.step_max); } @@ -540,8 +549,10 @@ fn settled(s: *const anim.Frame, v: anim.Value) f32 { /// (fades out there and in here) and does not slide: a call is not a /// journey across the lines between. pub fn jumps(rec: *const Recording, from: u64, to: u64) bool { - const rows = @max(rec.own[from], rec.own[to]) - @min(rec.own[from], rec.own[to]); - return rec.depths[from] != rec.depths[to] or rows > time.current_jump_rows; + const a = rec.shown[from]; + const b = rec.shown[to]; + const rows = @max(a.line, b.line) - @min(a.line, b.line); + return a.src != b.src or rec.depths[from] != rec.depths[to] or rows > time.current_jump_rows; } /// The cursor at one instant. diff --git a/anim/src/descent.zig b/anim/src/descent.zig index 53d46c5..5dd156c 100644 --- a/anim/src/descent.zig +++ b/anim/src/descent.zig @@ -247,8 +247,10 @@ pub const Descent = struct { // Which rows ran in the last three steps: the trail. const ran = recentRows(a, now, if (going >= 0.5) 0 else 1); - const current_line = rec.own[marked]; - const widen0 = rows.numberRoom(rec.line_count); + // The line the source panel is on, in the file it shows: rows of that file carry their numbers. + const current = rec.shown[marked]; + const current_line = current.line; + const widen0 = rows.numberRoom(rec.most_lines); var covered: usize = 0; var covered_before: usize = 0; var runs: disasm.Runs = .{}; @@ -268,7 +270,7 @@ pub const Descent = struct { .head => |h| { v.fill(.{ .x = theme.stroke.rule, .y = y, .w = box.w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); v.text(.sans_medium, theme.size.sans.micro, c.address, y + 18, h.name, t.primary); - v.text(.sans, theme.size.sans.micro, box.w - m.side - v.width(.sans, theme.size.sans.micro, h.note), y + 18, h.note, t.faint); + v.text(.sans, theme.size.sans.micro, map.content(box.w) - m.side - v.width(.sans, theme.size.sans.micro, h.note), y + 18, h.note, t.faint); covered -|= 1; }, .more => |words| { @@ -286,7 +288,7 @@ pub const Descent = struct { }; const lead = ui.shared(addrs[0..n]); const wide = @as(f32, @floatFromInt(@max(ui.digits(row.addr), 7) - 7)) * adv; - const line = if (row.outside) null else row.line; + const line = if (row.outside or row.src != current.src) null else row.line; const state: disasm.Disasm.State = switch (p.item.state) { // The row the plaque has not reached yet is ahead. .current => if (p.old == null or p.old.?.state != .current) (if (going >= 0.5) .current else .ahead) else if (p.new == null or p.new.?.state != .current) (if (going < 0.5) .current else .ahead) else .current, @@ -309,10 +311,10 @@ pub const Descent = struct { runs.add(line != null and line.? == current_line, y, y + m.row); // A row drawn twice (crossfading) counts once for the arguments that hang over the rows under it. const covers = if (p.twin) covered_before > 0 else covered > 0; - const hangs = dd.insn(v, now, row, y, box.w, widen0 + wide, line, line != last_line, current_line, lead, state, base, covers, .{ addrs[0], addrs[n -| 1] }, null); + const hangs = dd.insn(v, now, row, y, map.content(box.w), widen0 + wide, line, line != last_line, current_line, lead, state, base, covers, .{ addrs[0], addrs[n -| 1] }, null); const w = @min(p.item.window, rules.len - 1); if (rules[w] == null) rules[w] = graph.Rules.init(u.f.scratch, rec, now.marks, .{ row.addr, row.addr }, going); - rules[w].?.draw(v, row.addr, y, box.w, !covers and !row.outside and !dd.noted(v, now, row, y, state, base, .{ addrs[0], addrs[n -| 1] }, null)); + rules[w].?.draw(v, row.addr, y, map.content(box.w), !covers and !row.outside and !dd.noted(v, now, row, y, state, base, .{ addrs[0], addrs[n -| 1] }, null)); if (!p.twin) covered_before = covered; covered = if (p.twin) @max(covered, hangs) else @max(covered -| 1, hangs); last_line = line; @@ -343,10 +345,13 @@ pub const Descent = struct { const yb = p.y + m.row / 2; u.route(&.{ .{ 14, ya }, .{ 14, yb }, .{ c.address - 4, yb } }, t.primary, .{ .width = theme.stroke.rule, .head = .{ 7, 8 }, .radius = 4, .progress = cursors.standard(drawn) }); } - map.window(.disasm, .{ first(after), last(after) }, .{ first(before), last(before) }, cursors.glide(going)); + // Its strip is the deepest window's function's column, that window framed on it. + map.window(.disasm, deepest(after), deepest(before), cursors.glide(going)); if (pc_y[1] orelse pc_y[0]) |y| ties.anchor(u, .pc, .{ .x = 0, .y = y, .w = theme.metric.plaque.pc, .h = m.row }); kernel(u, now, box, under orelse top + @as(f32, @floatFromInt(room -| 3)) * m.row, pc_y[0] orelse pc_y[1]); context.veiled(u, box, now.veil); + // Going down or up, the strip is another function's column: it fades through as the mark lands (24 f). + map.strip(.disasm, if (kind == .same) u else u.faded(map.through(now, now.plan.travel + f(12))), box); } }; @@ -380,15 +385,15 @@ fn windowOf(items: anytype, window: u8) @TypeOf(items) { return if (lo < hi) items[lo..hi] else items[0..0]; } -fn first(l: Layout) u64 { - for (l.items) |it| if (it.what == .insn) return it.key; - return 0; -} - -fn last(l: Layout) u64 { - var out: u64 = 0; +/// The first and last instruction of the deepest window of code. +fn deepest(l: Layout) [2]u64 { + var window: u8 = 0; for (l.items) |it| if (it.what == .insn) { - out = it.key; + window = @max(window, it.window); + }; + var out = [2]u64{ std.math.maxInt(u64), 0 }; + for (l.items) |it| if (it.what == .insn and it.window == window) { + out = .{ @min(out[0], it.key), @max(out[1], it.key) }; }; return out; } @@ -600,7 +605,9 @@ fn headNote(u: ui.Ui, rec: *const Recording, i: u64, l: Level) []const u8 { const module = moduleOf(u, rec, i, l.at); if (std.mem.eql(u8, module, "[vdso]")) return "vdso \u{00b7} the kernel's code, run here"; var buf: [256]u8 = undefined; - if ((@import("ztrace").telescope.instruction(rec.moment(i), l.at, &buf) catch null)) |here| if (here.line != null) return rec.file; + // Its source, where the build gave it: the program's own file, or the library's (its entry's: not the header a line of it is inlined from). + const entry = if (@import("ztrace").telescope.function(rec.moment(i), l.at)) |fun| fun.start else l.at; + if (rec.instruction(i, entry, &buf)) |here| if (here.line != null) return if (here.src == 0) rec.file else u.print("{s} \u{00b7} {s}", .{ module, rec.sources[here.src].name() }); return u.print("{s} \u{00b7} no source", .{module}); } diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig index 282c66e..be3452f 100644 --- a/anim/src/disasm.zig +++ b/anim/src/disasm.zig @@ -37,8 +37,9 @@ pub const Insn = struct { text: []const u8, /// Past the function's end. outside: bool = false, - /// The line of the program's source it was compiled from. + /// The line it was compiled from, of `src` (`Recording.sources`). line: ?u32 = null, + src: u16 = 0, /// A direct call's callee's parameter count. params: ?u8 = null, /// A graph's row: its block's head carries the address, the row its offset. @@ -72,6 +73,8 @@ pub const Disasm = struct { cursor: cursors.Cursor, stage: *const Stage, focus: bool = false, + /// On the map its box is as long as what it shows (not where it is a strip's column alone). + measures: bool = true, pub fn draw(d: *const Disasm, f: *sk.Frame, placed: anim.Placed) void { const box = d.stage.box(placed, .disasm); @@ -79,13 +82,12 @@ pub const Disasm = struct { const now = d.cursor.now(placed); const rec = d.cursor.rec; const room = theme.layout.rowsIn(box.h); - const above = (room -| 1) / 2; // The mark: it moves last, with the source's and rip. const going = now.advancing(); - const from = listing(u, rec, now.marks[0], room, above); - const to = listing(u, rec, now.marks[1], room, above); + const from = listing(u, rec, now.marks[0], room); + const to = listing(u, rec, now.marks[1], room); // On the map its box is as long as the instructions the recording has round the pc. - if (ui.mapping) map.measure(.disasm, listing(u, rec, now.marks[1], theme.map.disasm_rows, (theme.map.disasm_rows - 1) / 2).rows.len); + if (ui.mapping and d.measures) map.measure(.disasm, listing(u, rec, now.marks[1], theme.map.disasm_rows).rows.len); const pc = [2]u64{ rec.register(now.marks[0], "rip"), rec.register(now.marks[1], "rip") }; // The function's name: one that changes with the advance crossfades over it. @@ -111,6 +113,7 @@ pub const Disasm = struct { var merged: []const Insn = to.rows; var offsets = [2]f32{ 0, 0 }; var fade: f32 = 1; + var faded_through = false; var shown = to; if (pc[0] != pc[1] and going < 1) { if (merge(u, from.rows, to.rows)) |both| { @@ -120,6 +123,7 @@ pub const Disasm = struct { merged = if (going < 0.5) from.rows else to.rows; shown = if (going < 0.5) from else to; fade = @abs(2 * going - 1); + faded_through = true; } } const scroll = std.math.lerp(offsets[0], offsets[1], cursors.glide(going)); @@ -137,7 +141,9 @@ pub const Disasm = struct { // Which moment the current mark stands for, and the three steps before it. const base: usize = if (going >= 0.5) 0 else 1; - const current_line = rec.own[now.marks[if (going >= 0.5) 1 else 0]]; + // The line the source panel is on, in the file it shows: rows of that file carry their numbers. + const current = rec.shown[now.marks[if (going >= 0.5) 1 else 0]]; + const current_line = current.line; // The addresses' shared digits, of the window the mark is in: they // change with the advance, not before it. const lead = blk: { @@ -190,12 +196,12 @@ pub const Disasm = struct { 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. - const widen = rows.numberRoom(rec.line_count); + const widen = rows.numberRoom(rec.most_lines); // The thread's runs: of the line the mark leaves and of the one it // goes to, each a span of rows; published sliding from the one to // the other with the advance (`threadRuns`). var runs: [2]Runs = .{ .{}, .{} }; - const lines_of = [2]u32{ rec.own[now.marks[0]], rec.own[now.marks[1]] }; + const lines_of = [2]Recording.Shown{ rec.shown[now.marks[0]], rec.shown[now.marks[1]] }; var lanes: [2]?f32 = .{ null, null }; // A call's arguments hang in the annotation column of the rows under it. var covered: usize = 0; @@ -206,9 +212,9 @@ pub const Disasm = struct { const rules = graph.Rules.init(u.f.scratch, rec, now.marks, pc, going); for (merged, 0..) |row, j| { const y = top + (@as(f32, @floatFromInt(j)) - scroll) * m.row; - const line = if (row.outside) null else row.line; + const line = if (row.outside or row.src != current.src) null else row.line; // The thread: the current line's runs of instructions. - for (&runs, lines_of) |*r, of| r.add(line != null and line.? == of and mark_shows >= 1, @max(y, top), @min(y, box.h - m.pad)); + for (&runs, lines_of) |*r, of| r.add(!row.outside and row.line != null and row.line.? == of.line and row.src == of.src and mark_shows >= 1, @max(y, top), @min(y, box.h - m.pad)); // A row wholly above the body (the window it scrolls from or to) // does not take the line number from the first row shown. const above_body = y + m.row <= top + 0.5; @@ -222,8 +228,8 @@ pub const Disasm = struct { const was = if (is_pc) null else ran[j]; if (was) |r| lit.trail(c.mark, y, r.k); const state: State = if (is_pc) .current else if (was) |r| .{ .ran = r } else .ahead; - const hangs = d.insn(lit, now, row, y, box.w, widen, line, line != last_line, current_line, lead, state, base, covered > 0, window, echo); - rules.draw(lit, row.addr, y, box.w, covered == 0 and !row.outside and !d.noted(lit, now, row, y, state, base, window, echo)); + const hangs = d.insn(lit, now, row, y, map.content(box.w), widen, line, line != last_line, current_line, lead, state, base, covered > 0, window, echo); + rules.draw(lit, row.addr, y, map.content(box.w), covered == 0 and !row.outside and !d.noted(lit, now, row, y, state, base, window, echo)); covered = @max(covered -| 1, hangs); last_line = if (above_body) null else line; if (jumped == row.addr and !is_pc) lanes[0] = y; @@ -231,13 +237,16 @@ pub const Disasm = struct { } const end_y = @min(top + (@as(f32, @floatFromInt(merged.len)) - scroll) * m.row, box.h - m.pad); for (&runs) |*r| r.add(false, end_y, end_y); - threadRuns(u, box.w, runs, if (lines_of[0] == lines_of[1]) 1 else cursors.standard(going)); + threadRuns(u, box.w, runs, if (std.meta.eql(lines_of[0], lines_of[1])) 1 else cursors.standard(going)); if (lanes[0] != null and lanes[1] != null and lanes[0].? != lanes[1].?) { const ya = lanes[0].? + m.row / 2; const yb = lanes[1].? + m.row / 2; lit.route(&.{ .{ 38, ya }, .{ c.jump_lane, ya }, .{ c.jump_lane, yb }, .{ 39, yb } }, theme.color.trail[0], .{ .width = theme.stroke.rule, .head = .{ 7, 8 }, .radius = 4 }); } context.veiled(u, box, now.veil); + // A window going to another column (another function) fades through, and its strip with it. + const column_changes = faded_through and (from.rows.len == 0 or to.rows.len == 0 or !(map.inColumn(.disasm, .{ from.rows[0].addr, from.rows[from.rows.len - 1].addr }) and map.inColumn(.disasm, .{ to.rows[0].addr, to.rows[to.rows.len - 1].addr }))); + map.strip(.disasm, if (column_changes) u.faded(map.through(now, now.plan.travel)) else u, box); } pub const State = union(enum) { @@ -272,7 +281,7 @@ pub const Disasm = struct { const name = if (rec.strings.get(row.addr)) |n| n[0 .. std.mem.lastIndexOfScalar(u8, n, '+') orelse n.len] else ""; const ops = shorn(u, row); const x = if (name.len > 0) annotationX(operandsWidth(u, row, ops, ""), room, @as(f32, @floatFromInt(name.len)) * adv) else room + gap; - operands(u, row, ops, "", base_y, (if (covered) c.annotation else x) - gap - c.operands, t.faint); + operands(u, row, ops, "", base_y, (if (covered) annotationColumn() else x) - gap - c.operands, t.faint); u.text(.mono, size, x, base_y, name, t.faint); return 0; } @@ -286,21 +295,21 @@ pub const Disasm = struct { const pad = row.padding(); u.text(.mono_bold, size, c.mnemonic, base_y, row.mnemonic(), if (pad) t.faint else theme.color.code.keyword); // How wide the annotation is, drawn where nothing shows; then where it goes. - const need = d.annotation(u.faded(0), now, row, y, c.annotation, std.math.inf(f32), state, base, window, echo); + const need = d.annotation(u.faded(0), now, row, y, annotationColumn(), std.math.inf(f32), state, base, window, echo); // When the operands and the annotation do not both fit: the // annotation moves left (never past its column), then the operands give way. const ops = shorn(u, row); const stub = if (target(row)) |to| pltName(u, rec, to) else ""; var x = room + gap; - if (need.drawn) x = annotationX(operandsWidth(u, row, ops, stub), room, need.end - c.annotation); - operands(u, row, ops, stub, base_y, (if (covered) @min(x, c.annotation) else x) - gap - c.operands, if (pad) t.faint else theme.color.code.plain); + if (need.drawn) x = annotationX(operandsWidth(u, row, ops, stub), room, need.end - annotationColumn()); + operands(u, row, ops, stub, base_y, (if (covered) @min(x, annotationColumn()) else x) - gap - c.operands, if (pad) t.faint else theme.color.code.plain); // Its annotation column holds the arguments of a call above: its own gives way. return if (need.drawn and !covered) d.annotation(u, now, row, y, x, room, state, base, window, echo).hangs else 0; } /// Whether `row` has an annotation: where it has none, its block's visits may be ranged right. pub fn noted(d: *const Disasm, u: ui.Ui, now: cursors.Now, row: Insn, y: f32, state: State, base: usize, window: [2]u64, echo: ?Echo) bool { - return d.annotation(u.faded(0), now, row, y, c.annotation, std.math.inf(f32), state, base, window, echo).drawn; + return d.annotation(u.faded(0), now, row, y, annotationColumn(), std.math.inf(f32), state, base, window, echo).drawn; } const Note = struct { drawn: bool = false, end: f32 = 0, hangs: usize = 0 }; @@ -809,6 +818,11 @@ pub fn readsFlags(rec: *const Recording, i: u64) u16 { return flagsRead((Insn{ .addr = pc, .len = here.len, .text = here.text }).mnemonic()); } +/// Where an annotation starts: 564 on the map, 540 in a pane with a strip. +fn annotationColumn() f32 { + return if (ui.mapping) c.annotation else c.annotation - theme.strip.cost / 2; +} + /// The gap between the operands and the annotation: a character. const gap = adv; @@ -853,7 +867,7 @@ pub fn threadRuns(u: ui.Ui, w: f32, runs: [2]Runs, p: f32) void { /// after operands `width` wide: at its column, or a character after the /// operands, or (when both do not fit) where it just fits. fn annotationX(width: f32, room: f32, need: f32) f32 { - return @max(c.annotation, @min(c.operands + width + gap, room - need)); + return @max(annotationColumn(), @min(c.operands + width + gap, room - need)); } /// The row in `rows` (in address order) of the instruction at `addr`. @@ -899,7 +913,7 @@ pub fn bareRow(u: ui.Ui, row: Insn, y: f32) void { const base_y = rows.baseline(y); const pad = row.padding(); u.text(.mono_bold, size, c.mnemonic, base_y, row.mnemonic(), if (pad) t.faint else theme.color.code.keyword); - operands(u, row, shorn(u, row), "", base_y, c.annotation - gap - c.operands, if (pad) t.faint else theme.color.code.plain); + operands(u, row, shorn(u, row), "", base_y, annotationColumn() - gap - c.operands, if (pad) t.faint else theme.color.code.plain); } /// Operands as canim draws them (design/README.md, `insn` and `width`): @@ -1056,15 +1070,24 @@ fn full(name: []const u8) ?[]const u8 { /// The window at moment `i`: up to `above` of the function's own /// instructions over the pc (fewer near its start), the pc's, and as many /// after it as fill `room`; past the function's end, `outside`. -fn listing(u: ui.Ui, rec: *const Recording, i: u64, room: usize, above: usize) Listing { - return listingAt(u, rec, i, rec.register(i, "rip"), room, above); +/// `room` rows round the pc at moment `i`: in a pane, as many above as +/// below; on the map, the function from its start where the pc is in its +/// first three quarters of the rows (a strip's column stays still while +/// the pc walks it), else round the pc. +fn listing(u: ui.Ui, rec: *const Recording, i: u64, room: usize) Listing { + const pc = rec.register(i, "rip"); + if (ui.mapping) { + const whole = listingAt(u, rec, i, pc, room, room * 3 / 4); + if (whole.pc < room * 3 / 4) return whole; + } + return listingAt(u, rec, i, pc, room, (room -| 1) / 2); } /// The same round the instruction at `pc` (in the window, `Listing.pc`). pub fn listingAt(u: ui.Ui, rec: *const Recording, i: u64, pc: u64, room: usize, above: usize) Listing { const out = u.f.scratch.alloc(Insn, room) catch return .{ .rows = &.{}, .pc = 0 }; var buf: [256]u8 = undefined; - var up: [16]Insn = undefined; + var up: [theme.map.disasm_rows]Insn = undefined; var n_up: usize = 0; var addr = pc; while (n_up < @min(above, up.len)) { @@ -1072,7 +1095,7 @@ pub fn listingAt(u: ui.Ui, rec: *const Recording, i: u64, pc: u64, room: usize, if (here.back == 0) break; addr -= here.back; const one = rec.instruction(i, addr, &buf) orelse break; - up[n_up] = .{ .addr = addr, .len = one.len, .text = u.print("{s}", .{one.text}), .line = one.line, .params = one.params }; + up[n_up] = .{ .addr = addr, .len = one.len, .text = u.print("{s}", .{one.text}), .line = one.line, .src = one.src, .params = one.params }; n_up += 1; } var n: usize = 0; @@ -1083,7 +1106,7 @@ pub fn listingAt(u: ui.Ui, rec: *const Recording, i: u64, pc: u64, room: usize, while (n < room) : (n += 1) { const one = rec.instruction(i, addr, &buf) orelse break; if (n > pc_row and one.back == 0) outside = true; - out[n] = .{ .addr = addr, .len = one.len, .text = u.print("{s}", .{one.text}), .outside = outside, .line = one.line, .params = one.params }; + out[n] = .{ .addr = addr, .len = one.len, .text = u.print("{s}", .{one.text}), .outside = outside, .line = one.line, .src = one.src, .params = one.params }; addr += one.len; } return .{ .rows = out[0..n], .pc = pc_row }; diff --git a/anim/src/graph.zig b/anim/src/graph.zig index f4e61ea..fa91adb 100644 --- a/anim/src/graph.zig +++ b/anim/src/graph.zig @@ -499,6 +499,8 @@ pub const Rules = struct { v.* = g.nodes[k].visits; }; if (visits[0] == null and visits[1] == null) return; + // For a strip: a tick at the row's top. + if (ui.strokes) return ui.collectMark(u, 0, y, .tick, 1); u.fill(.{ .x = theme.stroke.rule, .y = y, .w = w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); if (!free) return; const size = theme.size.mono.context; @@ -1210,7 +1212,7 @@ pub const Map = struct { const module: []const u8 = if (std.mem.indexOfScalar(u8, full, '!')) |bang| full[0..bang] else ""; const folded = g.foldedBlocks(); const title = if (module.len > 0) u.print("disassembly \u{00b7} {s} \u{00b7} {s}", .{ name, module }) else u.print("disassembly \u{00b7} {s}", .{name}); - const note = if (folded > 0) u.print("{s}{d} blocks \u{00b7} folded: {d} never reached", .{ if (rec.sourced(now.stops[0])) "" else "no source \u{00b7} ", g.blocks, folded }) else if (g.exact) "its blocks \u{00b7} visits so far \u{00b7} the edges the run took" else "its blocks \u{00b7} visits so far"; + const note = if (folded > 0) u.print("{s}{d} blocks \u{00b7} folded: {d} not reached", .{ if (rec.sourced(now.stops[0])) "" else "no source \u{00b7} ", g.blocks, folded }) else if (g.exact) "its blocks \u{00b7} visits so far \u{00b7} the edges the run took" else "its blocks \u{00b7} visits so far"; _ = u.panel(box.w, box.h, title, .{ .note = note }); u.clip(.{ .x = theme.stroke.rule, .y = m.tag, .w = box.w - 2 * theme.stroke.rule, .h = room }); defer u.unclip(); @@ -1242,11 +1244,12 @@ pub const Map = struct { const gold = golden(v, k); o.fill(r, theme.color.page); if (n.folded > 0) { - // Blocks the whole recording never reached: one dashed box, its offsets and its count. + // Blocks the whole recording never reached: one dashed box, its offsets and its count, + // said of the run so far (a graph says what has happened by the moment shown, never what will not). o.dashedFrame(r, theme.color.rule, theme.stroke.rule); const last = n.start + n.len - 1; o.text(.mono, size, n.x + m.side, rows.baseline(n.y), o.print("+{x} to +{x}", .{ n.start - g.start, last - g.start }), t.faint); - const words = if (n.folded > 1) o.print("{d} blocks never reached", .{n.folded}) else "never reached"; + const words = if (n.folded > 1) o.print("{d} blocks not reached", .{n.folded}) else "not reached"; const micro = theme.size.sans.micro; o.text(.sans, micro, n.x + w - m.side - o.width(.sans, micro, words), n.y + m.tag - 6, words, t.faint); return; diff --git a/anim/src/hexdump.zig b/anim/src/hexdump.zig index 21db91f..a35f091 100644 --- a/anim/src/hexdump.zig +++ b/anim/src/hexdump.zig @@ -142,9 +142,12 @@ pub const View = struct { rows: usize, box: Rect, - /// What a sprint cannot show: veiled, over its rows. + /// What a sprint cannot show: veiled, over its rows; then, a dump's, + /// its minimap: its window (published as it drew, `map.window`) on its + /// column of the map, a strip of its own (`map.strip`). pub fn veil(v: View, now: cursors.Now) void { @import("context.zig").veiled(v.u, v.box, now.sprint_veil); + @import("map.zig").strip(.view, v.u, v.box); } }; @@ -281,20 +284,20 @@ fn rowPasses(now: cursors.Now, addr: u64) Passes { fn rowPin(u: ui.Ui, now: cursors.Now, addr: u64, y: f32) f32 { ties.anchor(u, .{ .dump_pin = addr }, .{ .x = 0, .y = y, .w = b.bracket, .h = m.row }); const at = pinned(u, now, addr); - if (at.names.len == 0 or at.shows <= 0) return full_room; - const x = u.faded(at.shows).pinEnd(full_room, y, at.names, rows.ink(rows.regionOf(now.moment(), addr))); + if (at.names.len == 0 or at.shows <= 0) return viewRoom(); + const x = u.faded(at.shows).pinEnd(viewRoom(), y, at.names, rows.ink(rows.regionOf(now.moment(), addr))); return x - adv; } /// Where the reading of a row must end for its pin (`rowPin`), not drawing it. fn rowPinRoom(u: ui.Ui, now: cursors.Now, addr: u64) f32 { const at = pinned(u, now, addr); - if (at.names.len == 0 or at.shows <= 0) return full_room; + if (at.names.len == 0 or at.shows <= 0) return viewRoom(); const p = theme.metric.pin; var shown: []const u8 = ""; for (at.names[0..@min(at.names.len, 3)], 0..) |name, i| shown = if (i == 0) name else u.print("{s} {s}", .{ shown, name }); if (at.names.len > 3) shown = u.print("{s} +{d}", .{ shown, at.names.len - 3 }); - return full_room - u.width(.mono, theme.size.mono.context, shown) - p.row_gap - p.row_head[0] - adv; + return viewRoom() - u.width(.mono, theme.size.mono.context, shown) - p.row_gap - p.row_head[0] - adv; } fn pinned(u: ui.Ui, now: cursors.Now, addr: u64) struct { names: []const []const u8, shows: f32 } { @@ -527,6 +530,7 @@ pub fn fielded(v: View, now: cursors.Now, y: f32, of: Fields) void { 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, field.reads == .protected); }; arcs.draw(u, theme.metric.arc.lanes.len); + if (of.pins) @import("map.zig").window(.view, .{ of.base + 16 * shown[0], of.base + 16 * shown[shown.len - 1] }, .{ of.base + 16 * shown[0], of.base + 16 * shown[shown.len - 1] }, 1); } /// Which of `rs` (rows of fields, the region's last row `last`) a window @@ -699,6 +703,11 @@ pub fn reading(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: * /// The panel's width less its side: where a reading ends with no pin at its row's end. const full_room = theme.layout.state.w - theme.metric.context.side; +/// A view's: less its strip, in the working frame. +fn viewRoom() f32 { + return @import("map.zig").content(full_room); +} + /// `reading`, ending at `room` (a pin at the row's end takes the rest). pub fn readingIn(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: *const [16]u8, known: *const [16]bool, fields: []const Field, room: f32) f32 { const size = theme.size.mono.context; diff --git a/anim/src/map.zig b/anim/src/map.zig index 108bafd..ee1d2a1 100644 --- a/anim/src/map.zig +++ b/anim/src/map.zig @@ -1,11 +1,12 @@ -//! The `map` and the `minimap` (design/README.md, "The map and the +//! The `map` and the panes' minimaps (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. +//! a stage of 3840 by 2160 at the context's type size; and each pane's +//! column of it, small, in a `strip` inside the pane's frame at its right. +//! 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, +//! and a strip frames it. const std = @import("std"); const sk = @import("sketch"); const anim = @import("anim"); @@ -18,17 +19,25 @@ const Split = theme.layout.Split; pub const Panel = enum { band, view, source, disasm, registers, stack, backtrace }; +/// The panes with a strip, in the order of their places in the strips' images. +pub const stripped = [_]Panel{ .source, .disasm, .stack, .view }; + +fn slotOf(panel: Panel) ?usize { + return std.mem.indexOfScalar(Panel, &stripped, panel); +} + /// `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. +/// `travel`), each pane's column squeezing into its strip with it; the +/// rest of the map gone by `gone`; the strips and the tags in from `lift`; +/// then `still` from `land`. `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. + /// A panel's way, and its column's. pub const travel = 60; - pub const fall = 72; + pub const gone = 72; pub const lift = 84; /// The last of seven panels in place: 24 + 6 * 6 + 60. pub const land = 120; @@ -41,14 +50,6 @@ pub fn looking(f: *sk.Frame) bool { return f.host.env("CANIM_MAP") != null; } -/// The dive's frames over which the falling map crossfades into the minimap's drawing. -pub const minimap_lands = [2]f32{ 90, 96 }; - -/// How much of the minimap shows at dive frame `t`: none while the map falls, crossfading in as it lands. -pub fn minimapShows(t: f32) f32 { - return std.math.clamp((t - minimap_lands[0]) / (minimap_lands[1] - minimap_lands[0]), 0, 1); -} - /// Where each working window is on the map this frame, in canvas pixels. var window_px: [7]?[4]f32 = @splat(null); @@ -72,8 +73,8 @@ pub fn measure(panel: Panel, n: usize) void { } /// A working panel shows the rows of keys `now` (first and last), going -/// there from `was`, `p` of the way (eased): its outline on the minimap -/// glides with its scroll, and never jumps. +/// there from `was`, `p` of the way (eased): its outline on the map and +/// its window on its strip glide with its scroll, and never jump. pub fn window(panel: Panel, now: [2]u64, was: [2]u64, p: f32) void { if (!ui.mapping) windows[@intFromEnum(panel)] = .{ .now = now, .was = was, .p = p }; } @@ -89,6 +90,28 @@ pub fn row(panel: Panel, key: u64, u: ui.Ui, r: Rect) void { counts[i] += 1; } +/// How much of a pane's strip shows as the pane fades through to another +/// column (another file, another function) over the advance's `travel` +/// seconds: out and in as the pane does, as late as the strip's own +/// drawing is (`time.minimap_lag` and half its fade), so that the column it +/// changes to comes in while the strip is out. +pub fn through(now: @import("cursor.zig").Now, travel: f32) f32 { + if (now.resting() or travel <= 0) return 1; + const lag = theme.time.minimap_lag + @as(f32, theme.time.minimap_fade) / 2.0 / 60.0; + return @abs(2 * std.math.clamp((now.time - now.plan.advance - lag) / travel, 0, 1) - 1); +} + +/// Whether `panel`'s column on its strip has the rows of keys `keys[0]` to `keys[1]`. +pub fn inColumn(panel: Panel, keys: [2]u64) bool { + const col = &atlas.columns[slotOf(panel) orelse return false]; + return col.span(.{ keys[0], keys[0] }) != null and col.span(.{ keys[1], keys[1] }) != null; +} + +/// The width a pane's rows have: its box's, less its strip's in the working frame. +pub fn content(w: f32) f32 { + return if (ui.mapping) w else w - theme.strip.cost; +} + /// The map's boxes for a recording, packed by content: each panel as long /// as its rows (`measure`), the next under it 12 apart (design/README.md, /// "The map and the minimap"). The drawing and the source in the first @@ -113,7 +136,7 @@ pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split const source_y = if (lens) band.y + band.h + gap else st.y; // The backtrace as long as the call chain gets over the scene's way: packed once, never repacked under the eye. const bt_rows = @max(want(.backtrace, 0), deepest(rec, way)); - const source_rows: f32 = @floatFromInt(@min(rec.line_count, theme.layout.rowsIn(foot - source_y - gap - panelH(bt_rows)))); + const source_rows: f32 = @floatFromInt(@min(rec.most_lines, theme.layout.rowsIn(foot - source_y - gap - panelH(bt_rows)))); const source: Rect = .{ .x = c[0], .y = source_y, .w = w, .h = panelH(source_rows) }; const bt_y = source.y + source.h + gap; // The view as long as what draws there has wanted: none where nothing does (a lens drawn alone). @@ -125,7 +148,7 @@ pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split const disasm: Rect = .{ .x = c[1], .y = st.y, .w = w, .h = panelH(@min(want(.disasm, theme.map.disasm_rows), theme.map.disasm_rows)) }; // The source longer than its column (69 lines round the current line, or the file whole if shorter) // goes on at the top of the next column's free space, under its tag, `continued`. - const lines_left: f32 = @as(f32, @floatFromInt(@min(rec.line_count, theme.map.disasm_rows))) - source_rows; + const lines_left: f32 = @as(f32, @floatFromInt(@min(rec.most_lines, theme.map.disasm_rows))) - source_rows; const under_disasm = disasm.y + disasm.h + gap; const more_rows = @min(lines_left, @as(f32, @floatFromInt(theme.layout.rowsIn(foot - under_disasm)))); const source_more: Rect = .{ .x = c[1], .y = under_disasm, .w = w, .h = if (more_rows >= 3) panelH(more_rows) else 0 }; @@ -141,7 +164,7 @@ pub fn split(rec: *const Recording, lens: bool, way: [2]u64, graph: bool) Split if (graph) { const regs: Rect = .{ .x = c[3], .y = st.y, .w = w, .h = panelH(17) }; const nothing: Rect = .{ .x = c[3], .y = st.y, .w = w, .h = 0 }; - const src: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = panelH(@floatFromInt(@min(rec.line_count, theme.layout.rowsIn(foot - st.y - gap - panelH(bt_rows))))) }; + const src: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = panelH(@floatFromInt(@min(rec.most_lines, theme.layout.rowsIn(foot - st.y - gap - panelH(bt_rows))))) }; const bt: Rect = .{ .x = c[0], .y = src.y + src.h + gap, .w = w, .h = @min(panelH(bt_rows), foot - (src.y + src.h + gap)) }; return .{ .band = .{ .x = c[0], .y = st.y, .w = w, .h = 0 }, @@ -326,18 +349,16 @@ pub const Spare = struct { /// frame's component bound to that stage. pub const Map = struct { stage: *Stage, - parts: [12]Part = undefined, + parts: [14]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). + /// on: the working frame, each pane's column in its strip). t: anim.Value, /// The map as an object of the scene, under the panels: it shows from `show`. obj: anim.Obj = undefined, - /// Where the program is: for the thread across the gutter, and the minimap's flashes. + /// Where the program is: for the thread across the gutter, and the strips' flashes. cursor: ?@import("cursor.zig").Cursor = null, /// The scene's loupes: open, each is a panel of its own on the map (`Spare`). loupes: [2]?*const @import("loupe.zig").Loupe = .{ null, null }, @@ -345,18 +366,31 @@ pub const Map = struct { /// no line crosses the lanes; the band's window is the whole graph; the /// disassembly's, the rows it shows. graph: bool = false, + /// With `graph`: the stage of the linear disassembly the strip is a + /// column of (the map draws the graph, which is its own whole). + linear: ?*Stage = null, - const Part = struct { ctx: *const anyopaque, draw: *const fn (*const anyopaque, *sk.Frame, anim.Placed) void }; + /// Which drawings a part is in: the map's, the strips' (what they are + /// drawn from: a pane's column, as the linear disassembly the map draws + /// as a graph or a descent), or both. + pub const In = enum { both, map, strips }; + /// `panel`: the box it draws in (null: a lens's, its drawing and its view), for a column squeezing in a dive. + const Part = struct { ctx: *const anyopaque, draw: *const fn (*const anyopaque, *sk.Frame, anim.Placed) void, in: In, panel: ?Panel }; - /// Puts `component` (bound to `m.stage`) on the map, drawn in the order added. + /// Puts `component` (bound to `m.stage`; a lens, unless `addIn` says + /// which panel it is) on the map, drawn in the order added. pub fn add(m: *Map, s: *anim.Frame, component: anytype) void { + m.addIn(s, component, .both, null); + } + + pub fn addIn(m: *Map, s: *anim.Frame, component: anytype, in: In, panel: ?Panel) 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 }; + }.draw, .in = in, .panel = panel }; m.n += 1; } @@ -367,7 +401,7 @@ pub const Map = struct { m.add(s, component); } - /// Whether the working frame is in place (the minimap is the map). + /// Whether the working frame is in place. pub fn settled(m: *const Map, at: anim.Placed) bool { return at.value(m.t) >= diving.land; } @@ -385,8 +419,8 @@ pub const Map = struct { /// `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. + /// each pane's column squeezing into its strip with it; the rest of + /// the map fades where it is; 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 }); } @@ -400,22 +434,34 @@ pub const Map = struct { 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`). + /// The map while it is shown or a dive plays (the scene's first + /// object): filling the frame at half its size, the rest of it fading + /// where it is as each pane's column squeezes into its strip. 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); context.thread_shows = std.math.clamp((t - diving.land) / 12, 0, 1); if (t >= diving.land) return; + // The columns' rows, where the strips have them. + m.strips(f, placed); const fixed = @import("words.zig").fixed(f, placed, 0); - const at = m.falling(f, placed, t); - // Large, it is under the panels diving out of it; small (`falling`), over them, into the corner. - if (at.scale >= small * fixed.at.scale) m.copy(f, at, fixed, t) else fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); + fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); + const at = half(fixed.at); + // The rest of the map veiled from 6 to 24 f, then gone where it is by 72. + var rest = at; + rest.pose.opacity *= 1 - std.math.clamp((t - diving.move) / (diving.gone - diving.move), 0, 1); + m.drawParts(f, rest); + const veil = std.math.clamp((t - diving.bright) / (diving.move - diving.bright), 0, 1); + (ui.Ui{ .f = f, .at = rest }).veil(theme.map.stage, veil); + // The windows bright from 0 to 6 f, over the veil: a pane's with a strip rides on its column. + const bright = std.math.clamp(t / diving.bright, 0, 1); + m.outline(f, rest, bright, true); // 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); + var ways: [7]f32 = @splat(0); // In the frame's reading order, except that a panel drawn over another // sets off first: a panel in its place is never crossed by one still // on its way (the disassembly over the source's foot, the stack over @@ -433,22 +479,117 @@ pub const Map = struct { const lead = (if (whole) 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)); + ways[i] = p; 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. + // The tags, rules and lanes, and the strips, come in as the map lands. const chrome = std.math.clamp((t - diving.lift) / 12, 0, 1); // Out of a graph the rows and the lens are another form of what the map shows there: they come in on their way. const other = m.graph and (i == @intFromEnum(Panel.disasm) or i == @intFromEnum(Panel.band)); context.zoomed[i] = .{ .box = box, .to = .{ .x = x, .y = y, .w = box.w * scale, .h = box.h * scale }, .chrome = chrome, .shows = if (other) p else 1 }; }; } + // Each pane's column squeezing into its strip: their places on the map give way first, then they go. + for ([_]bool{ true, false }) |masking| for (stripped) |panel| { + const box = switch (panel) { + inline else => |tag| @field(working, @tagName(tag)), + }; + const gone = 1 - stripShows(panel, t); + // The graph's linear column is not on the map: its strip comes in with the tags. + if (box.h > 0 and gone > 0 and windows[@intFromEnum(panel)] != null and !(m.graph and panel == .disasm)) m.squeeze(f, fixed, at, panel, box, ways[@intFromEnum(panel)], .{ .masking = masking, .shows = gone, .veil = veil, .bright = bright }); + }; + } + + /// How much of a pane's strip shows at dive frame `t`: it comes in as + /// its pane lands (12 f), its column going into it. + fn stripShows(panel: Panel, t: f32) f32 { + // The panels' order setting off (`draw`). + const order: f32 = switch (panel) { + .band => 0, + .view => 1, + .disasm => 2, + .stack => 3, + .source => 4, + .registers => 5, + .backtrace => 6, + }; + const lands = diving.move + order * diving.apart + diving.travel; + return std.math.clamp((t - lands + 12) / 12, 0, 1); } - /// Frames into the dive now; 0 (the map filling the frame, as a scene - /// that opens on it shows it) with `CANIM_MAP` in the environment. - fn diveAt(m: *const Map, f: *sk.Frame, placed: anim.Placed) f32 { - return if (looking(f)) 0 else placed.value(m.t); + /// The map filling the frame: half its units. + fn half(at: anim.Placed) anim.Placed { + var out = at; + out.xf = at.xf.mul(.scale(0.5, 0.5)); + out.scale = at.scale * 0.5; + return out; + } + + const Squeeze = struct { masking: bool, shows: f32, veil: f32, bright: f32 }; + + /// A pane's column in a dive, `p` of its way (eased) from its place on + /// the map (`at`: filling the frame) into the pane's strip: the rows the + /// strip shows, its width and its height each on its logarithm (to 36 + /// of 880; to 4 of 24 a row), the text thinning as it lands, the + /// window's outline riding on it. With `masking`, only its place on the + /// map given up (the page over it: the column goes from there). + fn squeeze(m: *const Map, f: *sk.Frame, fixed: ui.Ui, at: anim.Placed, panel: Panel, box: Rect, p: f32, how: Squeeze) void { + const col = &atlas.columns[slotOf(panel).?]; + if (col.n == 0) return; + const st = theme.strip; + const cm = theme.metric.context; + const r = stripRect(box); + const cap = (r.h - st.top - st.foot) / st.pitch; + const win = windowOn(panel, col) orelse return; + const first = firstShown(col, win, cap); + const k = [2]f32{ std.math.pow(f32, 0.5, 1 - p) * std.math.pow(f32, st.across, p), std.math.pow(f32, 0.5, 1 - p) * std.math.pow(f32, @as(f32, st.pitch) / cm.row, p) }; + var offset: f32 = 0; + for (m.column(at, panel)) |b| { + if (b.h <= 0) continue; + const n: f32 = @floatFromInt(theme.layout.rowsIn(b.h)); + defer offset += n; + const lo = @max(first, offset); + const hi = @min(first + cap, @min(offset + n, col.rows)); + if (hi <= lo) continue; + const body = b.y + cm.tag + cm.pad; + const rows_rect: Rect = .{ .x = b.x, .y = body + (lo - offset) * cm.row, .w = b.w, .h = (hi - lo) * cm.row }; + if (how.masking) { + (ui.Ui{ .f = f, .at = at }).fill(.{ .x = rows_rect.x, .y = rows_rect.y - cm.pad, .w = rows_rect.w, .h = rows_rect.h + 2 * cm.pad }, theme.color.page); + continue; + } + // Its first row: where it is on the map, and where it goes in the strip. + const from = [2]f32{ rows_rect.x / 2, rows_rect.y / 2 }; + const to = [2]f32{ r.x + st.left, r.y + st.top + (lo - first) * st.pitch }; + var moved = fixed.at; + moved.xf = fixed.at.xf.mul(.translate(std.math.lerp(from[0], to[0], p), std.math.lerp(from[1], to[1], p))).mul(.scale(k[0], k[1])).mul(.translate(-rows_rect.x, -rows_rect.y)); + moved.scale = fixed.at.scale * k[1]; + moved.pose.opacity *= how.shows; + const u: ui.Ui = .{ .f = f, .at = moved }; + // Its parts clip to their boxes inside it. + u.clip(rows_rect); + const a0 = moved.xf.apply(.{ rows_rect.x, rows_rect.y }); + const a1 = moved.xf.apply(.{ rows_rect.x + rows_rect.w, rows_rect.y + rows_rect.h }); + ui.bound = .{ .x = @round(a0[0]), .y = @round(a0[1]), .w = @round(a1[0]) - @round(a0[0]), .h = @round(a1[1]) - @round(a0[1]) }; + m.drawPanel(f, moved, panel); + // Veiled with the map until it leaves. + u.veil(rows_rect, how.veil * (1 - p)); + ui.bound = null; + u.unclip(); + // The window's outline, where its rows are in this box: from the map's (dim, 2 and 4 out) to the strip's (primary, 2). + const w0 = @max(win[0], lo); + const w1 = @min(win[1] + 1, hi); + if (w1 > w0) { + const a = moved.xf.apply(.{ rows_rect.x, body + (w0 - offset) * cm.row }); + const c = moved.xf.apply(.{ rows_rect.x + rows_rect.w, body + (w1 - offset) * cm.row }); + const line = std.math.lerp(theme.map.outline / 2.0, st.window, p) * fixed.at.scale; + const out = std.math.lerp(theme.map.outline_out / 2.0, 0, p) * fixed.at.scale; + const ink = ui.mix(ui.mix(theme.color.text.dim, theme.color.text.bright, how.bright), theme.color.text.primary, p); + var raw: ui.Ui = .{ .f = f, .at = moved }; + raw.at.xf = .identity; + raw.frame(.{ .x = a[0] - out - line, .y = a[1] - out - line, .w = c[0] - a[0] + 2 * (out + line), .h = c[1] - a[1] + 2 * (out + line) }, ink, line); + } + } } /// With `CANIM_MAP` in the environment every frame is the map filling @@ -457,130 +598,44 @@ pub const Map = struct { /// any scene's map at 1:1 in a 4K export. pub fn wholeMap(m: *const Map, f: *sk.Frame, placed: anim.Placed) void { const fixed = @import("words.zig").fixed(f, placed, 0); - m.copy(f, m.falling(f, placed, 0), fixed, 0); - } - - /// Below this scale (of the frame's) the falling map is drawn over the - /// panels, on its way into the corner, and not under them. - const small = 0.12; - - /// Where the map is at dive frame `t`: from filling the frame (half - /// its units) to the minimap's rect (a twentieth), its scale on the - /// logarithm, its corner going toward the minimap's as the scale does, - /// so that it falls into the corner. - fn falling(m: *const Map, f: *sk.Frame, placed: anim.Placed, t: f32) anim.Placed { - _ = m; - const fixed = @import("words.zig").fixed(f, placed, 0); - 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 toward = (0.5 - k) / (0.5 - theme.minimap.scale); - var at = fixed.at; - at.xf = at.xf.mul(.translate(toward * mini.x, toward * mini.y)).mul(.scale(k, k)); - at.scale = fixed.at.scale * k; - return at; - } - - /// The falling map, veiled, its windows outlined, and its edge as the - /// minimap's; it crossfades into the minimap's own drawing as it lands. - fn copy(m: *const Map, f: *sk.Frame, at: anim.Placed, fixed: ui.Ui, t: f32) void { - const shows = 1 - minimapShows(t); - if (shows <= 0) return; - const mini = at.scale < small * fixed.at.scale; - if (!mini) fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); - var faded = at; - faded.pose.opacity *= shows; - m.drawAt(f, faded, mini); - // 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) / (minimap_lands[1] - diving.lift), 0, 1)); - (ui.Ui{ .f = f, .at = faded }).veil(theme.map.stage, veil); - // The windows bright from 0 to 6 f, over the veil. - m.outline(f, faded, mini, std.math.clamp(t / diving.bright, 0, 1)); - var edge: ui.Ui = .{ .f = f, .at = faded }; - edge.at.xf = .identity; - const a = at.xf.apply(.{ 0, 0 }); - const b = at.xf.apply(.{ 2 * theme.canvas.width, 2 * theme.canvas.height }); - const q = std.math.clamp((0.5 * fixed.at.scale - at.scale) / ((0.5 - theme.minimap.scale) * fixed.at.scale), 0, 1); - edge.faded(q).frame(.{ .x = a[0] - 1, .y = a[1] - 1, .w = b[0] - a[0] + 2, .h = b[1] - a[1] + 2 }, theme.color.rule, @max(1, fixed.at.scale)); + fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); + m.drawAt(f, half(fixed.at)); } - /// Small, the falling map over the working panels (the minimap's drawer calls it). - pub fn fallingOver(m: *const Map, f: *sk.Frame, placed: anim.Placed) void { - const t = placed.value(m.t); - if (t >= minimap_lands[1]) return; - const fixed = @import("words.zig").fixed(f, placed, 0); - const at = m.falling(f, placed, t); - if (at.scale >= small * fixed.at.scale) return; - // Its ground, so that it reads over what it passes. - var ground: ui.Ui = .{ .f = f, .at = at }; - ground.at.pose.opacity *= 1 - minimapShows(t); - ground.fill(.{ .x = 0, .y = 0, .w = 2 * theme.canvas.width, .h = 2 * theme.canvas.height }, theme.color.page); - m.copy(f, at, fixed, t); + /// 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. + pub fn drawAt(m: *const Map, f: *sk.Frame, at: anim.Placed) void { + m.drawParts(f, at); + m.outline(f, at, 0, false); } - /// 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); + /// The parts that draw `panel` (a dump: the lens's), as the map draws them. + fn drawPanel(m: *const Map, f: *sk.Frame, at: anim.Placed, panel: Panel) void { + ui.mapping = true; + defer ui.mapping = false; + for (m.parts[0..m.n]) |p| if (p.in != .strips and (p.panel == panel or (p.panel == null and panel == .view))) p.draw(p.ctx, f, at); } - fn drawParts(m: *const Map, f: *sk.Frame, at: anim.Placed, mini: bool) void { + fn drawParts(m: *const Map, f: *sk.Frame, at: anim.Placed) void { ui.mapping = true; - ui.strokes = mini; counts = @splat(0); - for (m.parts[0..m.n]) |p| p.draw(p.ctx, f, at); - if (m.cursor) |c| if (!m.graph) m.thread(f, at, c.now(at), mini); + for (m.parts[0..m.n]) |p| if (p.in != .strips) p.draw(p.ctx, f, at); + if (m.cursor) |c| if (!m.graph) m.thread(f, at, c.now(at)); ui.mapping = false; - ui.strokes = false; } /// The thread on the map: the current line and the pc's row, joined - /// across the gutter between source and disassembly (x 1008), gold; on - /// the minimap a stroke a pixel wide. And there, a mark no working - /// window shows `flash`es: a ring 8 across drawing out to 14 and gone - /// (12 f), with the strike (the minimap's own time, 6 f behind). - fn thread(m: *const Map, f: *sk.Frame, at: anim.Placed, now: @import("cursor.zig").Now, mini: bool) void { + /// across the gutter between source and disassembly (x 1008), gold. + fn thread(m: *const Map, f: *sk.Frame, at: anim.Placed, now: @import("cursor.zig").Now) void { _ = m; const rec = now.rec; - const k = at.scale; var raw: ui.Ui = .{ .f = f, .at = at }; raw.at.xf = .identity; const marked = now.marked(); - const line = rows_of(.source, rec.own[marked]); - const pc = rows_of(.disasm, rec.register(marked, "rip")); - if (line != null and pc != null) { - const a = line.?; - const b = pc.?; - const lane = at.xf.apply(.{ 1008, 0 })[0]; - const w = if (mini) @max(1, k / theme.minimap.scale) else theme.stroke.line * k; - const gold = theme.mark(.current).solid; - raw.route(&.{ .{ a[2], (a[1] + a[3]) / 2 }, .{ lane, (a[1] + a[3]) / 2 }, .{ lane, (b[1] + b[3]) / 2 }, .{ b[0], (b[1] + b[3]) / 2 } }, gold, .{ .width = w, .head = null, .radius = 0 }); - } - if (!mini or !now.walking()) return; - // A mark no working window shows: a word struck or read, on the - // stack (its own column or continued) or in memory the map draws - // (the view's dump, the dumps round the pointers), flashes where the - // map has it, in the mark's colour. - const since = now.since(.memory, 0); - const p = since / (12.0 / 60.0); - if (p < 0 or p > 1) return; - const marks = [2]struct { spans: []const Recording.Span, ink: u24 }{ - .{ .spans = rec.written(now.stops[1], now.stops[0]), .ink = theme.color.struck }, - .{ .spans = rec.read(now.stops[1], now.stops[0]), .ink = theme.mark(.read).solid }, - }; - for (marks) |mark| for (mark.spans) |span| { - // Where the map has it: the stack's word, or the 16 bytes of a dump's row. - const word = span.addr & ~@as(u64, 7); - const sixteen = span.addr & ~@as(u64, 15); - const panel: Panel, const key: u64 = if (rows_of(.stack, word) != null) .{ .stack, word } else .{ .view, sixteen }; - const box = rows_of(panel, key) orelse continue; - if (windows[@intFromEnum(panel)]) |win| if (key >= win.now[0] and key <= win.now[1]) continue; - const c = ui.Vec{ (box[0] + box[2]) / 2, (box[1] + box[3]) / 2 }; - const r = std.math.lerp(@as(f32, 4), 7, p) * k / theme.minimap.scale; - raw.faded(1 - p).disc(c, r, null, ui.rgb(mark.ink), @max(1, k / theme.minimap.scale)); - }; + const line = rows_of(.source, rec.shown[marked].line) orelse return; + const pc = rows_of(.disasm, rec.register(marked, "rip")) orelse return; + const lane = at.xf.apply(.{ 1008, 0 })[0]; + raw.route(&.{ .{ line[2], (line[1] + line[3]) / 2 }, .{ lane, (line[1] + line[3]) / 2 }, .{ lane, (pc[1] + pc[3]) / 2 }, .{ pc[0], (pc[1] + pc[3]) / 2 } }, theme.mark(.current).solid, .{ .width = theme.stroke.line * at.scale, .head = null, .radius = 0 }); } /// The top and bottom of the map's rows of panel `i` with keys from `keys[0]` to `keys[1]`, in canvas pixels. @@ -606,8 +661,9 @@ pub const Map = struct { } /// 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 { + /// from `dim` to bright; where they are is kept (`window_px`). With + /// `riding`, a pane's with a strip is not drawn: it rides on its column (`squeeze`). + fn outline(m: *const Map, f: *sk.Frame, at: anim.Placed, bright: f32, riding: bool) void { var raw: ui.Ui = .{ .f = f, .at = at }; raw.at.xf = .identity; const k = at.scale; @@ -628,116 +684,439 @@ pub const Map = struct { const was = spanOf(i, win.was) orelse is; if (is orelse was) |to| { const from = was orelse to; - // On the minimap each end on whole pixels: crisp at rest, between them only while it glides. - const snap = struct { - fn of(v: f32, on: bool) f32 { - return if (on) @round(v) else v; - } - }.of; - r[1] = std.math.lerp(snap(from[0], mini), snap(to[0], mini), win.p); - r[3] = std.math.lerp(snap(from[1], mini), snap(to[1], mini), win.p); + r[1] = std.math.lerp(from[0], to[0], win.p); + r[3] = std.math.lerp(from[1], to[1], win.p); shown = true; // In a graph the rows a window shows are in blocks: round them, not the panel's width. if (m.graph and panel == .disasm) if (boxOf(i, win.now)) |round| { const was_box = boxOf(i, win.was) orelse round; - r[0] = std.math.lerp(snap(was_box[0], mini), snap(round[0], mini), win.p); - r[2] = std.math.lerp(snap(was_box[2], mini), snap(round[2], mini), win.p); + r[0] = std.math.lerp(was_box[0], round[0], win.p); + r[2] = std.math.lerp(was_box[2], round[2], win.p); }; } } - // On the minimap on whole pixels (a window's ends already are, at rest). - if (mini) { - r[0] = @round(r[0]); - r[2] = @round(r[2]); - if (windows[i] == null) { - r[1] = @round(r[1]); - r[3] = @round(r[3]); - } - } 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; + const rides = riding and slotOf(panel) != null and !(m.graph and panel == .disasm); + if (shown and !rides) { + const w = theme.map.outline * k; + const out = theme.map.outline_out * k; const ring: Rect = .{ .x = r[0] - out, .y = r[1] - out, .w = r[2] - r[0] + 2 * out, .h = r[3] - r[1] + 2 * out }; - const ink = ui.mix(if (mini) theme.color.text.primary else theme.color.text.dim, theme.color.text.bright, bright); - // On the minimap not snapped to pixels: a window that glides moves a pixel over many frames, not in one. - if (mini) { - const pen = raw.at.pen(.{ .fill = ink }); - for ([4]sk.math.Rect{ .{ .x = ring.x, .y = ring.y, .w = ring.w, .h = w }, .{ .x = ring.x, .y = ring.y + ring.h - w, .w = ring.w, .h = w }, .{ .x = ring.x, .y = ring.y + w, .w = w, .h = ring.h - 2 * w }, .{ .x = ring.x + ring.w - w, .y = ring.y + w, .w = w, .h = ring.h - 2 * w } }) |edge| sk.draw.rect(f, edge, pen); - } else raw.frame(ring, ink, if (bright > 0) w * 1.5 else w); + raw.frame(ring, ui.mix(theme.color.text.dim, theme.color.text.bright, bright), if (bright > 0) w * 1.5 else w); } } } } -}; -/// The minimap's drawings, a frame apart, and what they are averaged into: -/// the host's images, made once for a size. -/// shortcut: a process-wide cache of host images, for one player at a time; two at once want it in their Session. -var fades: struct { w: u32 = 0, h: u32 = 0, images: [theme.time.minimap_fade + 1]sk.Image = undefined } = .{}; + /// The boxes on the map of `panel`'s column, in order: the second where + /// it goes on (`continued`), or none. + fn column(m: *const Map, at: anim.Placed, panel: Panel) [2]Rect { + const sp = m.stage.now(at); + const none: Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }; + return switch (panel) { + .source => .{ sp.source, sp.source_more }, + .disasm => .{ if (m.linear) |l| l.now(at).disasm else sp.disasm, none }, + .stack => .{ sp.stack, sp.more }, + .view => .{ sp.view, none }, + else => .{ none, none }, + }; + } + + /// The strips, drawn once a frame: the map drawn for them (`collect`) + /// six times, each from the cursor's mirror a frame later (6 to 11 f + /// behind: `Cursor.lagInto`) and with the panes' windows as they were + /// as long ago (`past`), each into an image of every strip as it shows + /// (its rows round its window, the window framed), and those averaged: + /// every change on a strip, a window gliding or its column scrolling + /// too, fades in over 6 f from 6 f after its onset, and nothing on it + /// moves a pixel in a frame. + fn strips(m: *const Map, f: *sk.Frame, at: anim.Placed) void { + if (atlas.frame == f.in.frame and atlas.map == m) return; + atlas.frame = f.in.frame; + atlas.map = m; + f.clip(null); + const st = theme.strip; + const k = @import("words.zig").fixed(f, at, 0).at.scale; + const w: u32 = @intFromFloat(@ceil(@as(f32, stripped.len * st.w) * k)); + const h: u32 = @intFromFloat(@ceil(theme.canvas.stage.h * k)); + if (atlas.w != w or atlas.h != h) { + if (atlas.w != 0) for (atlas.images) |img| f.host.freeImage(img); + for (&atlas.images) |*img| img.* = f.host.newImage(w, h); + atlas.w = w; + atlas.h = h; + } + if (atlas.scrap == null) atlas.scrap = f.host.newImage(4, 4); + atlas.k = k; + // After a seek the windows kept are of another time. + if (f.in.jumped) past = @splat(.{}); + past[f.in.frame % past.len] = .{ .frame = f.in.frame, .windows = windows }; + // Each pane's strip as high as its box has it now (a relayout moves them). + const working = m.frame.now(at); + var heights: [stripped.len]f32 = undefined; + for (stripped, &heights) |panel, *sh| sh.* = switch (panel) { + inline else => |tag| stripRect(@field(working, @tagName(tag))).h, + }; + const values = f.scratch.dupe(f32, at.values) catch return; + var placed = at; + placed.values = values; + placed.xf = .identity; + placed.scale = 1; + placed.pose.opacity = 1; + const n = theme.time.minimap_fade; + var weights: [n]f32 = @splat(0); + var made: usize = 0; + const chrome = ui.chrome; + defer ui.chrome = chrome; + var cols: [stripped.len]Column = undefined; + for (0..n) |lag| { + const then = pastWindows(f.in.frame, @as(u64, @intFromFloat(theme.time.minimap_lag * 60)) + lag); + // A mirror the same as the one before draws the same (its windows too): its drawing counts twice. + const moved = lag > 0 and !std.meta.eql(then, pastWindows(f.in.frame, @as(u64, @intFromFloat(theme.time.minimap_lag * 60)) + lag - 1)); + const differs = (if (m.cursor) |c| c.lagInto(values, lag) else lag == 0) or moved; + if (differs) { + m.collect(f, placed); + m.columns(placed, &cols); + if (made == 0) atlas.columns = cols; + f.target(atlas.images[made]); + f.clear(ui.rgb(theme.color.well)); + m.render(f, placed, k, &cols, then, heights); + made += 1; + } + weights[made - 1] += 1; + } + // Averaged: each drawing over those before it at its share of the drawings so far. + const whole: sk.Rect = .{ .x = 0, .y = 0, .w = @floatFromInt(w), .h = @floatFromInt(h) }; + f.target(atlas.images[n]); + var so_far: f32 = 0; + for (atlas.images[0..made], weights[0..made]) |img, weight| { + so_far += weight; + f.image(img, whole, .{ .tint = sk.Color.white.alphaFloat(weight / so_far) }); + } + f.target(.none); + } + + /// The map drawn for the strips, into nothing that shows: its parts + /// publish their rows and the text, marks and arcs they draw are + /// collected (`ui.collected`), with the flashes of the moment. + fn collect(m: *const Map, f: *sk.Frame, placed: anim.Placed) void { + f.target(atlas.scrap.?); + ui.mapping = true; + ui.strokes = true; + counts = @splat(0); + ui.collected.reset(); + for (m.parts[0..m.n]) |p| if (p.in != .map) p.draw(p.ctx, f, placed); + f.clip(null); + n_flashes = 0; + if (m.cursor) |c| flash(c.now(placed)); + ui.mapping = false; + ui.strokes = false; + } -/// 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`. -/// Every change on it fades in over `time.minimap_fade` frames from -/// `time.minimap_lag` after its onset: it is the average of that many -/// drawings, each from the cursor's mirror a frame later (`Cursor.lagInto`), -/// so a stroke that changes, a mark that comes and the gold that moves on -/// all fade, and a window's glide is smoothed, never stepped. -pub fn minimap(m: *const Map, f: *sk.Frame, at: anim.Placed) void { - var shown = at; - shown.pose.opacity *= minimapShows(m.diveAt(f, at)); - if (shown.pose.opacity <= 0) return; - const fixed = @import("words.zig").fixed(f, shown, 0); - const box = theme.minimap.box; - const a = fixed.at.xf.apply(.{ box.x, box.y }); - const b = fixed.at.xf.apply(.{ box.x + box.w, box.y + box.h }); - const px: sk.Rect = .{ .x = @round(a[0]), .y = @round(a[1]), .w = @round(b[0]) - @round(a[0]), .h = @round(b[1]) - @round(a[1]) }; - const w: u32 = @intFromFloat(@max(px.w, 1)); - const h: u32 = @intFromFloat(@max(px.h, 1)); - if (fades.w != w or fades.h != h) { - if (fades.w != 0) for (fades.images) |img| f.host.freeImage(img); - for (&fades.images) |*img| img.* = f.host.newImage(w, h); - fades.w = w; - fades.h = h; + /// Each strip's column, from the map just collected: its rows' keys and places. + fn columns(m: *const Map, at: anim.Placed, out: *[stripped.len]Column) void { + for (stripped, out) |panel, *c| { + c.* = .{}; + const boxes = m.column(at, panel); + const i = @intFromEnum(panel); + for (rows[i][0..counts[i]]) |rw| { + if (c.n == c.keys.len) break; + const place = spotIn(boxes, rw.box[0] + 1, rw.box[1], false) orelse continue; + c.keys[c.n] = rw.key; + c.at[c.n] = place.r; + c.n += 1; + c.rows = @max(c.rows, @round(place.r) + 1); + } + } } - // Each drawing in an image of its own, the page under it, in the image's pixels. - var placed = fixed.at; - placed.pose.opacity = 1; - placed.xf = sk.math.Affine.translate(-px.x, -px.y).mul(fixed.at.xf).mul(.translate(box.x, box.y)).mul(.scale(theme.minimap.scale, theme.minimap.scale)); - placed.scale = fixed.at.scale * theme.minimap.scale; - const values = f.scratch.dupe(f32, at.values) catch return; - placed.values = values; - // Its drawings outline the windows in their images' pixels: where the - // falling map has them (a dive's panels set off from there) is kept. - const falling_px = window_px; - defer window_px = falling_px; - const n = theme.time.minimap_fade; - var weights: [n]f32 = @splat(0); - var made: usize = 0; - for (0..n) |k| { - // A mirror the same as the one before draws the same: its drawing counts twice. - const differs = if (m.cursor) |c| c.lagInto(values, k) else k == 0; - if (differs) { - f.target(fades.images[made]); - f.clear(ui.rgb(theme.color.page)); - m.drawAt(f, placed, true); - made += 1; + + /// Every strip, as it shows, into the image in hand, a strip's width + /// each (`heights`: as high as each is): its column's rows round its + /// window (`then`: the panes' windows as long ago as the drawing is), + /// each run of text a stroke from where it starts, as long as it is, in + /// its ink 65% of the way from the page; at a row's left its marks (the + /// current row gold, a strike vermilion, a read in read's colour, held + /// a vermilion 2 by 2); an arc with an end off its pane's window a + /// 2-unit line in its ink down the left edge; a block's first row a + /// tick; a flash's ring; three faint dots at an end where the column + /// goes on; the window framed 2 in primary. + fn render(m: *const Map, f: *sk.Frame, at: anim.Placed, k: f32, cols: *const [stripped.len]Column, then: [7]?Window, heights: [stripped.len]f32) void { + const st = theme.strip; + var boxes: [stripped.len][2]Rect = undefined; + for (stripped, &boxes) |panel, *b| b.* = m.column(at, panel); + // Each strip's window and the first row it shows. + var wins: [stripped.len]?[2]f32 = undefined; + var firsts: [stripped.len]f32 = undefined; + var caps: [stripped.len]f32 = undefined; + for (stripped, cols, &wins, &firsts, &caps, heights) |panel, *col, *win, *first, *cap, sh| { + cap.* = (sh - st.top - st.foot) / st.pitch; + win.* = spanOf2(then[@intFromEnum(panel)], col); + // Whole rows at rest: its strokes on the image's pixels. + first.* = firstShown(col, win.* orelse .{ 0, 0 }, @floor(cap.*)); } - weights[made - 1] += 1; + // Where row `r` of strip `slot` is drawn, and whether it shows. + const Row = struct { + fn y(fs: [stripped.len]f32, slot: usize, r: f32) f32 { + return st.top + (r - fs[slot]) * st.pitch; + } + fn shows(fs: [stripped.len]f32, cs: [stripped.len]f32, slot: usize, r: f32) bool { + return r > fs[slot] - 0.75 and r < fs[slot] + cs[slot] - 0.25; + } + }; + const c = &ui.collected; + const page = ui.rgb(theme.color.page); + for (c.runs[0..c.n_runs]) |run| for (boxes, 0..) |pair, slot| { + const spot = spotIn(pair, run.x0, run.y, true) orelse continue; + if (Row.shows(firsts, caps, slot, spot.r)) { + const ink = ui.mix(page, run.ink.alphaFloat(1), st.ink).alphaFloat(@as(f32, @floatFromInt(run.ink.a)) / 255); + pixels(f, k, slot, st.left + spot.x * st.across, Row.y(firsts, slot, spot.r), (run.x1 - run.x0) * st.across, st.stroke, ink); + } + break; + }; + // The marks of each row: the most of each kind it has, side by side in the catalogue's order. + var shows: [stripped.len][atlas_rows][4]f32 = @splat(@splat(@splat(0))); + var place: [stripped.len][atlas_rows]f32 = undefined; + for (c.marks[0..c.n_marks]) |mk| for (boxes, 0..) |pair, slot| { + const spot = spotIn(pair, mk.x, mk.y, mk.kind != .tick) orelse continue; + if (!Row.shows(firsts, caps, slot, spot.r)) break; + if (mk.kind == .tick) { + pixels(f, k, slot, 0, Row.y(firsts, slot, spot.r) - 1, st.left + st.mark, 2, ui.rgb(theme.color.rule).alphaFloat(mk.shows)); + break; + } + const near = @round(spot.r); + if (near < 0 or near >= atlas_rows) break; + const i: usize = @intFromFloat(near); + shows[slot][i][@intFromEnum(mk.kind)] = @max(shows[slot][i][@intFromEnum(mk.kind)], @min(mk.shows, 1)); + place[slot][i] = spot.r; + break; + }; + for (shows, place, 0..) |of_slot, places, slot| for (of_slot, places) |kinds, r| { + var x: f32 = st.left; + const y = Row.y(firsts, slot, r); + const write = ui.rgb(theme.mark(.write).solid); + if (kinds[0] > 0) { + pixels(f, k, slot, x, y, st.mark, st.mark, ui.rgb(theme.mark(.current).solid).alphaFloat(kinds[0])); + x += st.mark_apart; + } + if (kinds[1] > 0) { + pixels(f, k, slot, x, y, st.mark, st.mark, write.alphaFloat(kinds[1])); + x += st.mark_apart; + } else if (kinds[3] > 0) { + pixels(f, k, slot, x + 1, y + 1, st.held, st.held, write.alphaFloat(kinds[3])); + x += st.mark_apart; + } + if (kinds[2] > 0) pixels(f, k, slot, x, y, st.mark, st.mark, ui.rgb(theme.mark(.read).solid).alphaFloat(kinds[2])); + }; + for (c.arcs[0..c.n_arcs]) |arc| for (boxes, 0..) |pair, slot| { + const a = spotIn(pair, arc.x, arc.from, true) orelse continue; + const b = spotIn(pair, arc.x, arc.to, true) orelse break; + // An arc with both ends in its pane's window is there: only one with an end off it is here. + const win = wins[slot] orelse break; + const in = struct { + fn of(r: f32, w: [2]f32) bool { + return r > w[0] - 0.5 and r < w[1] + 0.5; + } + }.of; + if (in(a.r, win) and in(b.r, win)) break; + const y0 = @max(Row.y(firsts, slot, @min(a.r, b.r)) + 1, st.top); + const y1 = @min(Row.y(firsts, slot, @max(a.r, b.r)) + 2, st.top + caps[slot] * st.pitch); + if (y1 > y0) pixels(f, k, slot, 0, y0, 2, y1 - y0, arc.ink); + break; + }; + // A flash: a ring 8 across drawing out to 14, and gone. + var scaled = at; + scaled.xf = sk.math.Affine.scale(k, k); + scaled.scale = k; + const u: ui.Ui = .{ .f = f, .at = scaled }; + for (flashes[0..n_flashes]) |fl| { + const slot = slotOf(fl.panel).?; + const r = (cols[slot].span(.{ fl.key, fl.key }) orelse continue)[0]; + if (!Row.shows(firsts, caps, slot, r)) continue; + u.faded(1 - fl.p).disc(.{ @as(f32, @floatFromInt(slot)) * st.w + st.left + 7, Row.y(firsts, slot, r) + 1.5 }, std.math.lerp(@as(f32, 4), 7, fl.p), null, ui.rgb(fl.ink), 2); + } + for (cols, firsts, caps, wins, 0..) |*col, first, cap, win, slot| { + const left = @as(f32, @floatFromInt(slot)) * st.w; + // Where it goes on: three faint dots, 2 by 2, 6 apart, coming as the column's end leaves (over a row). + const shown = @min(cap, col.rows - first); + for ([2]f32{ std.math.clamp(first, 0, 1), std.math.clamp(col.rows - first - shown, 0, 1) }, [2]f32{ 0, st.top + cap * st.pitch + 1 }) |q, y| if (q > 0) { + for (0..3) |i| pixels(f, k, slot, 13 + 6 * @as(f32, @floatFromInt(i)), y, 2, 2, ui.rgb(theme.color.text.faint).alphaFloat(q)); + }; + // Its window: the brightest thing on it. + if (win) |w| { + const top = st.top + (w[0] - first) * st.pitch - st.window; + const bottom = st.top + (w[1] - first + 1) * st.pitch + 1; + u.frame(.{ .x = left, .y = top, .w = st.w, .h = bottom - top }, theme.color.text.primary, st.window); + } + } + } +}; + +/// The most rows a column has in the strips' images. +const atlas_rows = 160; + +/// A pane's column of the map as its strip draws it: each of its rows' +/// key and place (rows from the column's top, continuous where the map's +/// panel scrolls), and how many rows the column has. +const Column = struct { + n: usize = 0, + keys: [atlas_rows]u64 = undefined, + at: [atlas_rows]f32 = undefined, + rows: f32 = 0, + + /// The first and last place of its rows with keys `keys[0]` to `keys[1]`. + fn span(c: *const Column, keys: [2]u64) ?[2]f32 { + var lo = std.math.inf(f32); + var hi = -std.math.inf(f32); + for (c.keys[0..c.n], c.at[0..c.n]) |key, at| if (key >= keys[0] and key <= keys[1]) { + lo = @min(lo, at); + hi = @max(hi, at); + }; + return if (lo <= hi) .{ lo, hi } else null; } - // Averaged: each drawing over those before it at its share of the drawings so far. - const whole: sk.Rect = .{ .x = 0, .y = 0, .w = px.w, .h = px.h }; - f.target(fades.images[n]); - var so_far: f32 = 0; - for (fades.images[0..made], weights[0..made]) |img, weight| { - so_far += weight; - f.image(img, whole, .{ .tint = sk.Color.white.alphaFloat(weight / so_far) }); +}; + +/// The strips' images: one for each lagging drawing of the map +/// (`time.minimap_fade`) and their average, last; each strip a column of +/// them, its column whole from its top. +/// shortcut: a process-wide cache of host images, for one player at a time; two at once want it in their Session. +var atlas: struct { + w: u32 = 0, + h: u32 = 0, + images: [theme.time.minimap_fade + 1]sk.Image = undefined, + /// What a collecting drawing draws into: nothing of it shows. + scrap: ?sk.Image = null, + /// The frame they were made for, and of which map. + frame: u64 = std.math.maxInt(u64), + map: ?*const Map = null, + /// Pixels a unit. + k: f32 = 1, + columns: [stripped.len]Column = @splat(.{}), +} = .{}; + +/// The panes' windows in the frames before, for the strips' lagging drawings (`Map.strips`). +var past: [16]struct { frame: u64 = std.math.maxInt(u64), windows: [7]?Window = @splat(null) } = @splat(.{}); + +/// The panes' windows `back` frames before frame `now` (where they were not kept, as they are). +fn pastWindows(now: u64, back: u64) [7]?Window { + const e = past[(now -% back) % past.len]; + return if (e.frame == now -% back) e.windows else windows; +} + +/// Where a window is on a column: its first and last row, between where it +/// was and where it is, as far as its scroll had gone. +fn spanOf2(maybe: ?Window, col: *const Column) ?[2]f32 { + const win = maybe orelse return null; + const is = col.span(win.now) orelse return null; + const was = col.span(win.was) orelse is; + return .{ std.math.lerp(was[0], is[0], win.p), std.math.lerp(was[1], is[1], win.p) }; +} + +/// The map whose columns the strips are (`context` sets it). +/// shortcut: process-wide, as the drawing flags are: one scene drawn at a time. +pub var current: ?*const Map = null; + +/// A mark no working window shows, `flash`ing on its pane's strip. +const Flash = struct { panel: Panel, key: u64, ink: u24, p: f32 }; +var flashes: [16]Flash = undefined; +var n_flashes: usize = 0; + +/// The flashes of the step, in the strips' time (6 f behind): a word +/// struck or read on the stack or in the view's dump that its pane's +/// window does not show; `p` of its 12 f. +fn flash(now: @import("cursor.zig").Now) void { + if (!now.walking()) return; + const p = now.since(.memory, 0) / (12.0 / 60.0); + if (p < 0 or p > 1) return; + const rec = now.rec; + const marks = [2]struct { spans: []const Recording.Span, ink: u24 }{ + .{ .spans = rec.written(now.stops[1], now.stops[0]), .ink = theme.color.struck }, + .{ .spans = rec.read(now.stops[1], now.stops[0]), .ink = theme.mark(.read).solid }, + }; + for (marks) |mark| for (mark.spans) |span| { + // Where the map has it: the stack's word, or the 16 bytes of a dump's row. + const word = span.addr & ~@as(u64, 7); + const sixteen = span.addr & ~@as(u64, 15); + const panel: Panel, const key: u64 = if (Map.rows_of(.stack, word) != null) .{ .stack, word } else .{ .view, sixteen }; + if (Map.rows_of(panel, key) == null) continue; + if (windows[@intFromEnum(panel)]) |win| if (key >= win.now[0] and key <= win.now[1]) continue; + if (n_flashes == flashes.len) return; + flashes[n_flashes] = .{ .panel = panel, .key = key, .ink = mark.ink, .p = p }; + n_flashes += 1; + }; +} + +const Spot = struct { r: f32, x: f32 }; + +/// Where a point of the map is in a column of `boxes`: its row, counted +/// from the column's top (continuous: `middle`, a point on a row's middle, +/// else on its top), and how far across its box. +fn spotIn(boxes: [2]Rect, x: f32, y: f32, middle: bool) ?Spot { + const cm = theme.metric.context; + var offset: f32 = 0; + for (boxes) |b| { + if (b.h <= 0) continue; + const body = b.y + cm.tag + cm.pad; + const n: f32 = @floatFromInt(theme.layout.rowsIn(b.h)); + if (x >= b.x - 1 and x <= b.x + b.w + 1 and y >= body - 1 and y <= body + n * cm.row + 1) + return .{ .r = offset + (y - body - @as(f32, if (middle) cm.row / 2 else 0)) / cm.row, .x = x - b.x }; + offset += n; } - f.target(.none); - f.image(fades.images[n], px, .{ .tint = sk.Color.white.alphaFloat(shown.pose.opacity) }); - fixed.frame(.{ .x = box.x - 1, .y = box.y - 1, .w = box.w + 2, .h = box.h + 2 }, theme.color.rule, 1); + return null; +} + +/// A rect of a strip's column, in strip units from its slot's corner, in the image's pixels (one at least). +fn pixels(f: *sk.Frame, k: f32, slot: usize, x: f32, y: f32, w: f32, h: f32, color: sk.Color) void { + const left = @as(f32, @floatFromInt(slot)) * theme.strip.w; + const x0 = @round((left + x) * k); + const y0 = @round(y * k); + const x1 = @max(@round((left + x + w) * k), x0 + 1); + const y1 = @max(@round((y + h) * k), y0 + 1); + f.fill(sk.Rect{ .x = x0, .y = y0, .w = x1 - x0, .h = y1 - y0 }, color); +} + +/// Where a pane's window is on its column now: its first and last row, +/// between where it was and where it is, as far as its scroll has gone. +fn windowOn(panel: Panel, col: *const Column) ?[2]f32 { + return spanOf2(windows[@intFromEnum(panel)], col); +} + +/// The first row a strip of `cap` rows shows: the column's top, or where +/// it is longer, the window in the middle, clamped to the column's ends. +fn firstShown(col: *const Column, win: [2]f32, cap: f32) f32 { + if (col.rows <= cap) return 0; + return std.math.clamp((win[0] + win[1] + 1) / 2 - cap / 2, 0, col.rows - cap); +} + +/// A pane's strip, in the pane's units (`box` its box). +fn stripRect(box: Rect) Rect { + const st = theme.strip; + return .{ .x = box.x + box.w - st.inset - st.w, .y = box.y + theme.metric.context.tag, .w = st.w, .h = box.h - theme.metric.context.tag - st.inset }; +} + +/// A pane's minimap (design/README.md, "The map and the minimap"): its +/// column of the map in a strip inside its frame at its right; where the +/// column is longer than the strip, the rows round its window, with three +/// faint dots at an end where it goes on; its window framed in primary, +/// gliding with its scroll. `u` is the pane's `Ui` at its box's corner (a +/// pane fading through passes its faded one); drawn last, over its rows. +pub fn strip(panel: Panel, u: ui.Ui, box: Rect) void { + if (ui.mapping) return; + const m = current orelse return; + const f = u.f; + if (looking(f)) return; + const slot = slotOf(panel) orelse return; + // In a dive it comes in as its pane lands. + const v = u.faded(Map.stripShows(panel, u.at.value(m.t))); + if (v.at.pose.opacity <= 0) return; + m.strips(f, u.at); + const col = &atlas.columns[slot]; + if (col.n == 0) return; + const st = theme.strip; + const r = stripRect(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); + if (r.h <= st.top + st.foot + st.pitch) return; + // The strip as its drawings have it, its rows, dots and window in place. + const k = atlas.k; + const a = v.at.xf.apply(.{ r.x, r.y }); + const b = v.at.xf.apply(.{ r.x + r.w, r.y + r.h }); + f.image(atlas.images[theme.time.minimap_fade], sk.Rect{ .x = a[0], .y = a[1], .w = b[0] - a[0], .h = b[1] - a[1] }, .{ .src = sk.Rect{ .x = @as(f32, @floatFromInt(slot)) * st.w * k, .y = 0, .w = st.w * k, .h = r.h * k }, .tint = sk.Color.white.alphaFloat(v.at.pose.opacity) }); } test "the map's columns hold their panels" { @@ -745,3 +1124,14 @@ test "the map's columns hold their panels" { const st = theme.map.stage; try std.testing.expectEqual(@as(f32, 3840), st.x + st.w + st.x); } + +test "a point of the map is placed in its column, the second box going on from the first" { + const cm = theme.metric.context; + const boxes = [2]Rect{ .{ .x = 0, .y = 0, .w = 880, .h = theme.layout.panelH(10) }, .{ .x = 900, .y = 100, .w = 880, .h = theme.layout.panelH(5) } }; + const first = spotIn(boxes, 40, cm.tag + cm.pad + 3 * cm.row + cm.row / 2, true).?; + try std.testing.expectEqual(@as(f32, 3), first.r); + const second = spotIn(boxes, 940, 100 + cm.tag + cm.pad + cm.row, false).?; + try std.testing.expectEqual(@as(f32, 11), second.r); + try std.testing.expectEqual(@as(f32, 40), second.x); + try std.testing.expect(spotIn(boxes, 2000, 50, true) == null); +} diff --git a/anim/src/root.zig b/anim/src/root.zig index b7be9b4..78da9dc 100644 --- a/anim/src/root.zig +++ b/anim/src/root.zig @@ -220,7 +220,7 @@ 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`. + /// own; each pane's column of it is the pane's strip. A lens adds its drawing with `map.add`. map: *map.Map, clock: anim.Obj, source: anim.Obj, @@ -288,18 +288,29 @@ 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. + // The map first: while it fills the frame 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, .{ at.first, at.last }, options.graph)), .frame = stage, .t = s.value(map.diving.land + map.diving.still), .cursor = at, .graph = options.graph }); whole.obj = s.custom(whole, .{ .x = -640, .y = -360, .scale = ui.scale }); - whole.add(s, Source{ .cursor = at, .stage = whole.stage, .descent = options.descent }); - whole.add(s, Source{ .cursor = at, .stage = whole.stage, .descent = options.descent, .part = .source_more }); - if (options.graph) whole.add(s, graph.Map{ .cursor = at, .stage = whole.stage }) else if (options.descent) whole.add(s, Descent{ .cursor = at, .stage = whole.stage }) else 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.addIn(s, Source{ .cursor = at, .stage = whole.stage, .descent = options.descent }, .both, .source); + whole.addIn(s, Source{ .cursor = at, .stage = whole.stage, .descent = options.descent, .part = .source_more }, .both, .source); + // The disassembly's strip is its linear column: where the map draws a + // graph or a descent, the rows round the pc are drawn for the strip alone. + if (options.graph) { + whole.linear = Stage.init(s, map.split(at.rec, options.split.band.h > 0, .{ at.first, at.last }, false)); + whole.addIn(s, graph.Map{ .cursor = at, .stage = whole.stage }, .map, .disasm); + whole.addIn(s, Disasm{ .cursor = at, .stage = whole.linear.?, .measures = false }, .strips, .disasm); + } else if (options.descent) { + whole.addIn(s, Descent{ .cursor = at, .stage = whole.stage }, .map, .disasm); + whole.addIn(s, Disasm{ .cursor = at, .stage = whole.stage, .measures = false }, .strips, .disasm); + } else whole.addIn(s, Disasm{ .cursor = at, .stage = whole.stage }, .both, .disasm); + whole.addIn(s, Registers{ .cursor = at, .stage = whole.stage, .syscalls = options.syscalls, .quiet = options.quiet }, .map, .registers); + whole.addIn(s, Stack{ .cursor = at, .stage = whole.stage, .above = theme.map.stack_above }, .both, .stack); // The stack goes on in the rest of the memory's column, from where its own column ends. - whole.add(s, Stack{ .cursor = at, .stage = whole.stage, .above = theme.map.stack_above - @as(i32, @intCast(theme.layout.rowsIn(whole.stage.first.stack.h))), .part = .more }); - whole.add(s, Backtrace{ .cursor = at, .stage = whole.stage }); - whole.add(s, map.Spare{ .cursor = at, .stage = whole.stage, .map = whole }); + whole.addIn(s, Stack{ .cursor = at, .stage = whole.stage, .above = theme.map.stack_above - @as(i32, @intCast(theme.layout.rowsIn(whole.stage.first.stack.h))), .part = .more }, .both, .stack); + whole.addIn(s, Backtrace{ .cursor = at, .stage = whole.stage }, .map, .backtrace); + // The rest of the first two columns: no pane's. + whole.addIn(s, map.Spare{ .cursor = at, .stage = whole.stage, .map = whole }, .map, .backtrace); + map.current = whole; return .{ .stage = stage, .map = whole, diff --git a/anim/src/rows.zig b/anim/src/rows.zig index 95400be..f82bb81 100644 --- a/anim/src/rows.zig +++ b/anim/src/rows.zig @@ -356,7 +356,8 @@ pub fn callLabels(u: ui.Ui, y: f32, w: f32, n: usize, name: []const u8, args: [] /// `text` in `width` units of mono 20: whole, or cut at its far end with `…`. pub fn fitted(u: ui.Ui, text: []const u8, width: f32) []const u8 { - const chars: usize = @intFromFloat(@max(width / adv, 1)); + // (A width measured without a room is infinite: whole.) + const chars: usize = @intFromFloat(std.math.clamp(width / adv, 1, 1 << 16)); if (text.len <= chars) return text; return u.print("{s}\u{2026}", .{text[0 .. chars - 1]}); } @@ -378,7 +379,9 @@ pub fn line(u: ui.Ui, y: f32, w: f32, number: u32, widen: f32, text: []const u8, const on = state == .current or state == .marked; const num = u.print("{d}", .{number}); u.text(if (on) .mono_bold else .mono, size, m.line_number_end + widen - @as(f32, @floatFromInt(num.len)) * adv, baseline(y), num, if (on) gold.on_solid else t.faint); - const limit: usize = m.source_chars - @as(usize, @intFromFloat(widen / adv)); + // Cut as much sooner as the row is narrower than its column (a pane's strip takes 48: four characters). + const cut: usize = @intFromFloat(@max(theme.layout.program.w - w, 0) / adv); + const limit: usize = m.source_chars - @as(usize, @intFromFloat(widen / adv)) - cut; const end = @min(text.len, limit); var i: usize = 0; while (i < end) { @@ -490,6 +493,10 @@ pub fn bytesAt(at: ui.Ui, y: f32, addr: u64, values: *const [16]u8, known: *cons u.fill(.{ .x = bx0, .y = r.y - h.out, .w = bx1 - bx0, .h = r.h + 2 * h.out }, ui.mix(theme.color.raised, theme.color.struck, solid)); }; u.corner(s0, y + 2, m.corner, h.level * h.corner); + if (ui.strokes) { + if (h.level >= 1 and h.solid * h.in > 0) ui.collectMark(u, s0, y + row_h / 2, .struck, h.solid * h.in) else ui.collectMark(u, s0, y + row_h / 2, .held, h.level * h.corner); + ui.collectMark(u, x0, y + row_h / 2, .read, run.read); + } 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; @@ -564,6 +571,17 @@ pub const Arcs = struct { /// without it to those they have with it, as far as it has drawn or shows. pub fn draw(a: *Arcs, u: ui.Ui, lanes: usize) void { const k = theme.metric.arc; + // For a strip: each arc's rows, the middles of its pointer's and its target's. + if (ui.strokes) { + const c = &ui.collected; + for (a.items[0..a.n]) |arc| if (!arc.stub and c.n_arcs < c.arcs.len) { + const p = u.at.xf.apply(.{ 0, arc.from + row_h / 2 }); + const q = u.at.xf.apply(.{ 0, arc.to + row_h / 2 }); + c.arcs[c.n_arcs] = .{ .x = p[0], .from = p[1], .to = q[1], .ink = u.faded(arc.shows).at.faded(ui.rgb(arc.ink)) }; + c.n_arcs += 1; + }; + return; + } 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; diff --git a/anim/src/source.zig b/anim/src/source.zig index 0705f5b..5a5f1cd 100644 --- a/anim/src/source.zig +++ b/anim/src/source.zig @@ -41,41 +41,59 @@ pub const Source = struct { const u = context.at(f, placed, box); const rec = p.cursor.rec; const now = p.cursor.now(placed); - const text = prepared(rec.source, rec.file) orelse return; // Its window, and on the map the lines of both its boxes (`continued`): this one from `skip` lines in. const head = theme.layout.rowsIn(p.stage.box(placed, .source).h); const tail = theme.layout.rowsIn(p.stage.box(placed, .source_more).h); const fit: u32 = @intCast(theme.layout.rowsIn(box.h)); const span_fit: u32 = @intCast(head + tail); const skip: f32 = if (p.part == .source_more) @floatFromInt(head) else 0; - // The mark: leaving the line of one moment for that of the next. - const was = rec.own[now.marks[0]]; - const here = rec.own[now.marks[1]]; + // The mark: leaving the line of one moment for that of the next, in + // whichever file the pc is on a line of (a library's, where the + // build gave its source), else where it waits a frame up. + const at = [2]Recording.Shown{ rec.shown[now.marks[0]], rec.shown[now.marks[1]] }; + const was = at[0].line; + const here = at[1].line; // The window: where the line it is on has it, and (as the mark // moves on) gliding to where the next one does. It never cuts. const going = now.advancing(); - const windows = [2]f32{ @as(f32, @floatFromInt(rec.viewFirst(span_fit, was))) + skip, @as(f32, @floatFromInt(rec.viewFirst(span_fit, here))) + skip }; - // Farther than its own height (another function far off): what - // leaves has left before what replaces it arrives; a scroll of more - // lines than the window shows would be a blur, and say nothing. - const far = @abs(windows[1] - windows[0]) > @as(f32, @floatFromInt(fit)); - const first = if (far) windows[if (going >= 0.5) 1 else 0] else std.math.lerp(windows[0], windows[1], cursors.glide(going)); - const lit = if (far and going < 1) u.faded(@abs(2 * going - 1)) else u; + const windows = [2]f32{ @as(f32, @floatFromInt(rec.shownFirst(span_fit, at[0]))) + skip, @as(f32, @floatFromInt(rec.shownFirst(span_fit, at[1]))) + skip }; + // Another file: the panel fades through (12 f out, 12 f in), its tag + // naming the file it comes to. Farther than its own height in one + // file (another function far off): its strip shows where it goes + // first (24 f), then what leaves has left before what replaces it + // arrives; a scroll of more lines than the window shows would be a + // blur, and say nothing. + const turn = at[0].src != at[1].src and going < 1; + const far = !turn and @abs(windows[1] - windows[0]) > @as(f32, @floatFromInt(fit)) and going < 1; + const side: usize = if (turn) @intFromBool(going >= 0.5) else if (far) @intFromBool(going >= 0.75) else @intFromBool(going >= 0.5); + const file = rec.sources[at[side].src]; + const text = prepared(file.text, file.path) orelse return; + const first = if (turn or far) windows[side] else std.math.lerp(windows[0], windows[1], cursors.glide(going)); + const fade: f32 = if (turn) @abs(2 * going - 1) else if (far) (if (going < 0.5) 1 else @abs(4 * going - 3)) else 1; + const lit = u.faded(fade); const from: u32 = @intFromFloat(@floor(first)); - const last: u32 = @min(from + @as(u32, @intCast(context.rowsOf(box))), rec.line_count); - const shown_first: u32 = @intFromFloat(windows[if (going >= 0.5) 1 else 0]); - // Waiting: the pc is in code with no source, under this line's call. - const waits = p.descent and !rec.sourced(now.marked()) and rec.own[now.marked()] != 0; - const lines_note = if (rec.line_count > fit) u.print("lines {d} to {d} of {d}", .{ shown_first, @min(shown_first + fit - 1, rec.line_count), rec.line_count }) else u.print("{d} lines", .{rec.line_count}); + const last: u32 = @min(from + @as(u32, @intCast(context.rowsOf(box))), file.lines); + // Waiting: the pc is in code with no source (a PLT stub, a library without it), under this line's call. + const waits = p.descent and !at[side].here and at[side].line != 0; + var lines_notes: [2][]const u8 = undefined; + for (at, windows, &lines_notes) |a, w, *note| { + const lines = rec.sources[a.src].lines; + const shown_first: u32 = @intFromFloat(w - skip); + note.* = if (lines > fit) u.print("lines {d} to {d} of {d}", .{ shown_first, @min(shown_first + fit - 1, lines), lines }) else u.print("{d} lines", .{lines}); + } // Where the pc is, said where it waits: a change of it (on through a // stub) crossfades over the 12 f before the advance, never in a frame. var notes: [2][]const u8 = undefined; - for (now.marks, ¬es) |mk, *note| note.* = if (p.descent and !rec.sourced(mk) and rec.own[mk] != 0) u.print("{s} waits at line {d} \u{00b7} the pc is in {s}", .{ context.frameName(u, rec, rec.register(firstOwn(rec, mk), "rip")), rec.own[mk], whereIs(u, rec, mk) }) else lines_note; - const swap = !std.mem.eql(u8, notes[0], notes[1]) and (notes[0].ptr != lines_note.ptr or notes[1].ptr != lines_note.ptr) and now.walking(); - const body = u.panel(box.w, box.h, if (p.part == .source_more) u.print("{s}, continued", .{rec.file}) else rec.file, .{ .focus = p.focus, .note = if (swap) "" else if (waits) notes[if (going >= 0.5) 1 else 0] else lines_note }); + for (now.marks, at, ¬es, lines_notes) |mk, a, *note, lines_note| note.* = if (p.descent and !a.here and a.line != 0) u.print("{s} waits at line {d} \u{00b7} the pc is in {s}", .{ context.frameName(u, rec, rec.register(lastShown(rec, mk), "rip")), a.line, whereIs(u, rec, mk) }) else lines_note; + const swap = !std.mem.eql(u8, notes[0], notes[1]) and now.walking(); + const titles = [2][]const u8{ rec.sources[at[0].src].name(), rec.sources[at[1].src].name() }; + const title = if (p.part == .source_more) u.print("{s}, continued", .{file.name()}) else file.name(); + const body = u.panel(box.w, box.h, if (turn) "" else title, .{ .focus = p.focus, .note = if (swap) "" else notes[side] }); + // Its tag's file and note change with the fade through it; a note otherwise over the 12 f before the advance. + if (turn) for (titles, [2]f32{ 1 - 2 * going, 2 * going - 1 }) |t, shows| u.faded(shows).tagTitle(t, p.focus); if (swap) { - const c = now.renaming(); - u.faded(1 - c).tagNote(box.w, notes[0]); + const c = if (turn) std.math.clamp(2 * going - 1, 0, 1) else now.renaming(); + u.faded(if (turn) 1 - 2 * going else 1 - c).tagNote(box.w, notes[0]); u.faded(c).tagNote(box.w, notes[1]); } const top = body.y + m.pad; @@ -86,7 +104,18 @@ pub const Source = struct { var mark_line = here; var mark_at: f32 = @floatFromInt(here); var shows: f32 = 1; - if (going < 1) { + if (turn or far) { + // It goes with the fade: out with the old window, in with the new. + mark_line = at[side].line; + mark_at = @floatFromInt(mark_line); + shows = fade; + // On the map, for the strip, it lights on its new line at once: the strip shows where the pane goes before it fades. + if (ui.mapping and far and going > 0) { + mark_line = here; + mark_at = @floatFromInt(here); + shows = 1; + } + } else if (going < 1) { if (!now.plan.wave and !cursors.jumps(rec, now.marks[0], now.marks[1])) { // A line near by: it slides, off promptly and settling on // the next. The step's follow-through. @@ -104,10 +133,9 @@ pub const Source = struct { } } const mark_y = top + (mark_at - first) * m.row; - // The numbers as wide as the program's largest: a scroll does not shift the text. - const widen = rows.numberRoom(rec.line_count); + // The numbers as wide as the widest file's largest: a scroll or another file does not shift the text. + const widen = rows.numberRoom(rec.most_lines); context.clipBody(u, box); - defer u.unclip(); // The plaque over the number. Fire: on the line about to run its // edges go out and come back, once, and nothing else moves. if (waits) { @@ -117,29 +145,35 @@ pub const Source = struct { } else if (shows > 0) u.faded(shows).current(.{ .x = theme.stroke.rule, .y = mark_y, .w = box.w - 2 * theme.stroke.rule, .h = m.row }, theme.metric.plaque.line + widen, now.fires(.source)); if (shows >= 1 and mark_y >= body.y and mark_y + m.row <= box.h) ties.anchor(u, .source, .{ .x = 0, .y = mark_y, .w = box.w, .h = m.row }); - // The trail: the last three other lines it was on, as the mark left - // them and as it finds them: a bar that moves crossfades with the advance. + // The trail: the last three other lines of its file it was on, as + // the mark left them and as it finds them: a bar that moves crossfades with the advance. var trails: [2][3]u32 = @splat(@splat(0)); var founds = [2]usize{ 0, 0 }; for (now.marks, &trails, &founds) |mk, *trail, *found| { - const on_line = rec.own[mk]; + const on = rec.shown[mk]; var back = mk; while (back > 0 and found.* < trail.len) { back -= 1; - const l = rec.own[back]; - if (l == 0 or l == on_line or std.mem.indexOfScalar(u32, trail[0..found.*], l) != null) continue; - trail[found.*] = l; + const l = rec.shown[back]; + if (l.line == 0 or l.src != on.src or l.line == on.line or std.mem.indexOfScalar(u32, trail[0..found.*], l.line) != null) continue; + trail[found.*] = l.line; found.* += 1; } } + if (turn) { + // Another file's trail is not this one's. + trails[1 - side] = @splat(0); + founds[1 - side] = 0; + } const lines_of = struct { - fn of(at: f32, n: u32, lines: u32) [2]u64 { - const a: u32 = @intFromFloat(at); - return .{ a, @min(a + n - 1, lines) }; + fn of(a: f32, n: u32, lines: u32) [2]u64 { + const l: u32 = @intFromFloat(a); + return .{ l, @min(l + n - 1, lines) }; } }.of; - map.window(.source, lines_of(windows[1], fit, rec.line_count), lines_of(windows[0], fit, rec.line_count), cursors.glide(going)); + // On the strip the window glides there; a window fading through goes before the fade, so the strip shows where it went first. + map.window(.source, lines_of(windows[1], fit, rec.sources[at[1].src].lines), lines_of(windows[0], fit, rec.sources[at[0].src].lines), if (turn) @floatFromInt(side) else cursors.glide(if (far) @min(2 * going, 1) else going)); var line = @max(from, 1); while (line <= last) : (line += 1) { const y = top + (@as(f32, @floatFromInt(line)) - first) * m.row; @@ -149,18 +183,21 @@ pub const Source = struct { const k = if (going >= 0.5) ks[1] else ks[0]; const on = shows >= 0.5 and line == mark_line; const fading = !std.meta.eql(ks[0], ks[1]) and going > 0 and going < 1; - rows.line(lit, y, box.w, line, widen, text.bytes[span[0]..span[1]], text.styles[span[0]..span[1]], if (on and !waits) .marked else if (fading) .plain else if (k) |n| .{ .trail = n } else .plain); + rows.line(lit, y, map.content(box.w), line, widen, text.bytes[span[0]..span[1]], text.styles[span[0]..span[1]], if (on and !waits) .marked else if (fading) .plain else if (k) |n| .{ .trail = n } else .plain); if (fading and !(on and !waits)) for (ks, [2]f32{ 1 - going, going }) |kk, amount| if (kk) |n| lit.faded(amount).trail(theme.stroke.rule, y, n); } // The source is read at a run; at a sprint it is veiled too. context.veiled(u, box, now.sprint_veil); + u.unclip(); + // Another file is another column: its strip fades through as the pane does. + map.strip(.source, if (turn) u.faded(map.through(now, travel)) else u, box); } }; -/// The last moment at or before `i` whose pc was on a line of the program's source. -fn firstOwn(rec: *const Recording, i: u64) u64 { +/// The last moment at or before `i` whose pc was on a line the panel can show. +fn lastShown(rec: *const Recording, i: u64) u64 { var at = i; - while (at > 0 and !rec.sourced(at)) at -= 1; + while (at > 0 and !rec.shown[at].here) at -= 1; return at; } diff --git a/anim/src/syscalls.zig b/anim/src/syscalls.zig index b568612..3788fe3 100644 --- a/anim/src/syscalls.zig +++ b/anim/src/syscalls.zig @@ -425,7 +425,8 @@ pub const Crossing = struct { .read = if (bufferRead(given) != null) now.held(p.work) else 0, .pins = true, }); - v.veil(now); + // The log is whole: no strip. + context.veiled(v.u, v.box, now.sprint_veil); } }; diff --git a/anim/src/theme.zig b/anim/src/theme.zig index 7d505d7..156088c 100644 --- a/anim/src/theme.zig +++ b/anim/src/theme.zig @@ -47,8 +47,7 @@ pub const canvas = struct { /// 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. +/// `dim`, 4 out). Each pane's minimap is a `strip` of its own column. pub const map = struct { pub const width = 3840; pub const height = 2160; @@ -62,11 +61,29 @@ pub const map = struct { 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; +/// A pane's minimap: its column of the map in a strip 40 wide inside its +/// frame at its right (inside the 2-unit rule), under the tag, on `well`; +/// a row of the map 4 units (a stroke 3 high), its 880 across 36, from 2 +/// in; the window framed 2 in primary; marks 4 by 4 at a row's left, 5 +/// apart. The pane's content keeps 8 from it: the strip costs it 48, and +/// the disassembly's annotation column 24 (564 to 540). +pub const strip = struct { + pub const w = 40; + pub const inset = 2; + pub const cost = 48; + pub const pitch = 4; + pub const stroke = 3; + pub const across = 36.0 / 880.0; + pub const left = 2; + pub const mark = 4; + pub const mark_apart = 5; + pub const held = 2; + pub const window = 2; + /// Above the first row; under the last, the dots where the column goes on. + pub const top = 2; + pub const foot = 4; + /// A row's text 65% of the way from the page to its ink. + pub const ink = 0.65; }; /// Left edge of column `i` (0 to 11). diff --git a/anim/src/ui.zig b/anim/src/ui.zig index bcefff3..589bfb6 100644 --- a/anim/src/ui.zig +++ b/anim/src/ui.zig @@ -17,17 +17,49 @@ pub const Vec = sk.math.Vec; 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. +/// their windows and places. `strokes`: the map drawn for the panes' +/// strips (`map.strip`), where nothing shows and what a strip draws is +/// collected (`collected`): each run of text, the marks, the arcs, the +/// blocks' first rows. /// 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; +/// A clip every other stays inside, in canvas pixels: a map column squeezing into its strip. +pub var bound: ?sk.Rect = null; + +/// What a map drawn for the strips holds, in its own units (`map.strip` +/// draws it in no transform but its own): text runs by their middle, the +/// marks by their row's middle, the arcs by their rows' tops. +pub const Collected = struct { + pub const Run = struct { x0: f32, x1: f32, y: f32, ink: Color }; + pub const Kind = enum { current, struck, read, held, tick }; + pub const Mark = struct { x: f32, y: f32, kind: Kind, shows: f32 }; + pub const Arc = struct { x: f32, from: f32, to: f32, ink: Color }; + runs: [12288]Run = undefined, + n_runs: usize = 0, + marks: [1024]Mark = undefined, + n_marks: usize = 0, + arcs: [96]Arc = undefined, + n_arcs: usize = 0, + + pub fn reset(c: *Collected) void { + c.n_runs = 0; + c.n_marks = 0; + c.n_arcs = 0; + } +}; +pub var collected: Collected = .{}; + +/// A mark on the row whose middle is `y` (in `u`), for the strips; `shows` of it. +pub fn collectMark(u: Ui, x: f32, y: f32, kind: Collected.Kind, shows: f32) void { + if (!strokes or shows <= 0 or collected.n_marks == collected.marks.len) return; + const p = u.point(x, y); + collected.marks[collected.n_marks] = .{ .x = p[0], .y = p[1], .kind = kind, .shows = shows * u.at.pose.opacity }; + collected.n_marks += 1; +} /// 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 @@ -158,9 +190,8 @@ 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` (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_; + /// A stroke `w` wide, wholly inside `r`. + pub fn frame(u: Ui, r: Rect, c: anytype, w: f32) void { 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); @@ -179,9 +210,14 @@ pub const Ui = struct { 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)); + // A run of text, for a strip: where it starts and ends, through its capitals' middle, and its ink. + if (std.mem.indexOfNone(u8, bytes, " ") == null or collected.n_runs == collected.runs.len) return; + const lead = std.mem.indexOfNone(u8, bytes, " ").?; + const a = u.point(x + u.width(face, size, bytes[0..lead]), baseline - 0.36 * size); + const b = u.point(x + u.width(face, size, std.mem.trimEnd(u8, bytes, " ")), baseline); + collected.runs[collected.n_runs] = .{ .x0 = a[0], .x1 = b[0], .y = a[1], .ink = u.at.faded(rgb(c)) }; + collected.n_runs += 1; + return; } // 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); @@ -254,6 +290,11 @@ pub const Ui = struct { u.text(.sans, micro, w - 10 - u.width(.sans, micro, note), theme.metric.context.tag - 6, note, theme.color.text.faint); } + /// A tag's title drawn apart from its panel: for one that crossfades with another. + pub fn tagTitle(u: Ui, title: []const u8, focus: bool) void { + u.text(.sans_medium, theme.size.sans.tag, 28, theme.metric.context.tag - 6, title, if (focus) theme.color.text.primary else theme.color.text.dim); + } + 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; @@ -383,11 +424,8 @@ pub const Ui = struct { const w = theme.mark(.write); const m = theme.metric.context; 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); + // For a strip: a strike, or held. + if (h.level >= 1 and h.solid * h.in > 0) collectMark(u, r.x, r.y + r.h / 2, .struck, h.solid * h.in) else collectMark(u, r.x, r.y + r.h / 2, .held, h.level * h.corner); 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); @@ -411,10 +449,7 @@ pub const Ui = struct { /// `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 (strokes) return collectMark(u, r.x, r.y + r.h / 2, .read, shows); 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); } @@ -450,8 +485,7 @@ pub const Ui = struct { /// `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); + if (strokes) return collectMark(u, r.x, r.y + r.h / 2, .current, 1); 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); } @@ -566,11 +600,17 @@ pub const Ui = struct { pub fn clip(u: Ui, r: Rect) void { const a = u.point(r.x, r.y); const b = u.point(r.x + r.w, r.y + r.h); - u.f.clip(sk.Rect{ .x = @round(a[0]), .y = @round(a[1]), .w = @round(b[0]) - @round(a[0]), .h = @round(b[1]) - @round(a[1]) }); + var c: sk.Rect = .{ .x = @round(a[0]), .y = @round(a[1]), .w = @round(b[0]) - @round(a[0]), .h = @round(b[1]) - @round(a[1]) }; + if (bound) |o| { + const x0 = @max(c.x, o.x); + const y0 = @max(c.y, o.y); + c = .{ .x = x0, .y = y0, .w = @max(@min(c.x + c.w, o.x + o.w) - x0, 0), .h = @max(@min(c.y + c.h, o.y + o.h) - y0, 0) }; + } + u.f.clip(c); } pub fn unclip(u: Ui) void { - u.f.clip(null); + if (bound) |b| u.f.clip(b) else u.f.clip(null); } /// A path through `points` with corners of radius `radius`, `progress` diff --git a/anim/src/words.zig b/anim/src/words.zig index f66f6d2..5411385 100644 --- a/anim/src/words.zig +++ b/anim/src/words.zig @@ -22,7 +22,7 @@ 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. + /// The map: with `CANIM_MAP`, drawn over everything (`Map.wholeMap`). map: ?*const @import("map.zig").Map = null, pub fn draw(k: *const Clock, f: *sk.Frame, at: anim.Placed) void { @@ -60,19 +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] }); - // 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); + // Ranged right at the stage's right edge, 1856. + const count_x = 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 (@import("map.zig").looking(f)) return m.wholeMap(f, at); - m.fallingOver(f, at); - @import("map.zig").minimap(m, f, at); - } + if (k.map) |m| if (@import("map.zig").looking(f)) m.wholeMap(f, at); } }; |
