diff options
Diffstat (limited to 'anim/src/context.zig')
| -rw-r--r-- | anim/src/context.zig | 140 |
1 files changed, 109 insertions, 31 deletions
diff --git a/anim/src/context.zig b/anim/src/context.zig index 15ece55..d4bc94d 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -44,7 +44,8 @@ pub const legend = blk: { /// While a `dive` or a `surface` plays (`map.Map`): each working panel's /// box, and the rect it is drawn into instead, on its way between its /// window on the map and its place; its tags, rules and lanes how much shown. -pub const Zoom = struct { box: Rect, to: Rect, chrome: f32, shows: f32 = 1 }; +/// `fold`: how far the registers panel has folded its quiet rows (a dive lands it folded; `Registers.draw`). +pub const Zoom = struct { box: Rect, to: Rect, chrome: f32, shows: f32 = 1, fold: f32 = 1 }; pub var zoomed: [8]?Zoom = @splat(null); /// How much the thread shows: it fades in (12 f) once a dive has landed, never in a frame. pub var thread_shows: f32 = 1; @@ -94,32 +95,82 @@ pub const Registers = struct { /// between any two lines, so that nearly all of them change at every one. quiet: bool = false, focus: bool = false, + /// The registers the scene moves (`movedBy`), a bit each of `Regs.names`: + /// a row each, with its chain; the rest folded three to a row + /// (design/README.md, `registers` `quiet`). All of them on the map. + moves: u32 = every, const Shown = struct { regs: zt.Regs, moment: Recording.Moment }; pub fn draw(r: *const Registers, f: *sk.Frame, placed: anim.Placed) void { const box = r.stage.box(placed, .registers); const u = at(f, placed, box); + // In a dive the panel comes whole out of the map and folds as it lands (`Zoom.fold`). + const fold = if (ui.mapping) 1 else foldOf(box); + var shape = box; + shape.h = std.math.lerp(theme.layout.panelH(@floatFromInt(theme.metric.all_registers.len)), box.h, fold); const now = r.cursor.now(placed); const rec = r.cursor.rec; const is: Shown = .{ .regs = (now.moment().regs(rec.tid) catch null) orelse zt.Regs{}, .moment = now.moment() }; const was: Shown = .{ .regs = (now.before().regs(rec.tid) catch null) orelse is.regs, .moment = now.before() }; - const body = u.panel(box.w, box.h, "registers", .{ .focus = r.focus, .legend = &legend }); + // Taller than its place on its way in: its own page under it. + if (fold < 1) u.fill(.{ .x = 0, .y = m.tag, .w = shape.w, .h = shape.h - m.tag }, theme.color.page); + const body = u.panel(shape.w, shape.h, "registers", .{ .focus = r.focus, .legend = &legend }); // A link leaves from the panel's edge, not through a name. - ties.anchor(u, .registers, .{ .x = 0, .y = 0, .w = box.w, .h = box.h }); - clipBody(u, box); + ties.anchor(u, .registers, .{ .x = 0, .y = 0, .w = shape.w, .h = shape.h }); + clipBody(u, shape); defer u.unclip(); - const shown = @min(rowsOf(box), theme.metric.all_registers.len); - // Overlapping action: of the registers one step wrote, each strikes 2 f after the one above it. - for (theme.metric.all_registers[0..shown], 0..) |name, i| { - const y = body.y + m.pad + @as(f32, @floatFromInt(i)) * m.row; - if (std.mem.eql(u8, name, "rip")) { - r.rip(u, now, y, box.w, is, was); + const q = theme.metric.registers; + const full = fullRows(r.moves); + const top = body.y + m.pad; + // The quiet ones under a rule across, in pwndbg's order; rip the last row. + if (full < 16) u.faded(fold).fill(.{ .x = theme.stroke.rule, .y = top + @as(f32, @floatFromInt(full)) * m.row - 1, .w = shape.w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule); + var rows_before: usize = 0; + var quiet_before: usize = 0; + for (theme.metric.all_registers[0..16], 0..) |name, i| { + const unfolded = top + @as(f32, @floatFromInt(i)) * m.row; + if (r.moves >> @intCast(i) & 1 != 0) { + r.row(u, now, is, was, name, std.math.lerp(unfolded, top + @as(f32, @floatFromInt(rows_before)) * m.row, fold), shape.w); + rows_before += 1; continue; } - r.row(u, now, is, was, name, y, box.w); + const y = std.math.lerp(unfolded, top + @as(f32, @floatFromInt(full + quiet_before / q.quiet_per_row)) * m.row, fold); + const x = std.math.lerp(theme.metric.context.side, q.quiet_from + @as(f32, @floatFromInt(quiet_before % q.quiet_per_row)) * q.quiet_pitch, fold); + quiet_before += 1; + r.quietRow(u, now, is, was, name, x, y, shape.w, fold); } - veiled(u, box, now.veil); + r.rip(u, now, std.math.lerp(top + 16 * m.row, top + @as(f32, @floatFromInt(registerRows(r.moves) - 1)) * m.row, fold), shape.w, is, was); + veiled(u, shape, now.veil); + } + + /// A register no step of the scene changes, in its cell from `x` (its + /// name's place); in a dive's fold (`fold` below 1), on its way from + /// its whole row, its chain past the first hop gone over the move's first 24 f. + fn quietRow(r: *const Registers, u: ui.Ui, now: cursors.Now, is: Shown, was: Shown, name: []const u8, x: f32, y: f32, w: f32, fold: f32) void { + const i = index(name) orelse return; + const value = is.regs.named(name) orelse return; + const read_shows = if (r.carrier(now, name, was.regs.named(name) orelse value)) |c| c.shows else 0; + if (fold < 1) { + const dx = x - theme.metric.context.side; + _ = rows.reg(u.faded(1 - fold).moved(dx, 0), y, w - dx, name, is.moment, value, .{ .hops = 1 - std.math.clamp(fold / 0.4, 0, 1) }); + } + const hops = rows.quiet(u.faded(fold), x, y, name, is.moment, value, read_shows); + anchor(u, i, hops, y); + } + + /// Whether `name` carries the system call the step makes, holding + /// `value_was` (the argument): which argument, and how much its frame shows. + fn carrier(r: *const Registers, now: cursors.Now, name: []const u8, value_was: u64) ?struct { k: usize, made: Recording.Syscall, shows: f32 } { + const made = (if (r.syscalls) syscalls.inStep(now) else null) orelse return null; + // A register is framed as carrying the call only while it holds the + // argument in the moment shown: the stop before the call, until the + // call is back. (Set by the wrapper, between the stops, it carried + // it where no stop saw it: the kernel's rows say it.) + for (syscalls.carried(made), 1..) |carried, k| if (std.mem.eql(u8, carried, name) and value_was == made.args[k - 1]) { + const framed = now.time - syscalls.Plan.in(now, made).registers - @as(f32, @floatFromInt(k - 1)) * time.flight.second; + return .{ .k = k, .made = made, .shows = @min(std.math.clamp(framed / time.read.in, 0, 1), now.reading(.cpu, 0)) }; + }; + return null; } fn shownAt(rec: *const Recording, i: u64) ?Shown { @@ -166,23 +217,16 @@ pub const Registers = struct { var note: []const u8 = ""; var note_shows: f32 = 1; const crossing: ?Recording.Syscall = if (r.syscalls) syscalls.inStep(now) else null; - // A register is framed as carrying the call only while it holds the - // argument in the moment shown: the stop before the call, until the - // call is back. (Set by the wrapper, between the stops, it carried - // it where no stop saw it: the kernel's rows say it.) - const carrier: ?usize = if (crossing) |made| for (syscalls.carried(made), 1..) |carried, k| { - if (std.mem.eql(u8, carried, name) and value_was == made.args[k - 1]) break k; - } else null else null; - if (carrier) |k| if (crossing) |made| { - const framed = now.time - syscalls.Plan.in(now, made).registers - @as(f32, @floatFromInt(k - 1)) * time.flight.second; + if (r.carrier(now, name, value_was)) |c| { marks.read = 0; - marks.read_shows = @min(std.math.clamp(framed / time.read.in, 0, 1), now.reading(.cpu, 0)); + marks.read_shows = c.shows; // A descriptor says what it is open on: the `value` class `fd`. - const names = zt.syscalls.names(made.nr); - if (k <= names.len and std.mem.endsWith(u8, names[k - 1], "fd")) note = rec.openOn(u.f.scratch, value_was, made.enter); + const names = zt.syscalls.names(c.made.nr); + if (c.k <= names.len and std.mem.endsWith(u8, names[c.k - 1], "fd")) note = rec.openOn(u.f.scratch, value_was, c.made.enter); // In with its framing, over 12 f, and out with it: never in a frame. + const framed = now.time - syscalls.Plan.in(now, c.made).registers - @as(f32, @floatFromInt(c.k - 1)) * time.flight.second; note_shows = @min(std.math.clamp(framed / time.quick, 0, 1), now.reading(.cpu, 0)); - }; + } if (if (std.mem.eql(u8, name, "rax")) crossing else null) |made| { // rax: what was there, then the result, once the kernel's rows // have said it (the call's number went in at the wrapper). @@ -244,6 +288,44 @@ fn runFade(now: cursors.Now, level: cursors.Level) f32 { return std.math.clamp(now.since(level, 0) / time.run_ease, 0, 1); } +/// Every register of the seventeen, a bit each of `Regs.names`: none folded. +pub const every: u32 = (1 << 17) - 1; + +/// The registers a scene moves (design/README.md, `registers` `quiet`): a +/// bit each of `Regs.names` for those any of its steps (of `by`, from +/// `way[0]` to `way[1]`: the clock's, `Cursor.journey`) changes, net, with +/// rsp, rbp and rip always. Chosen once: no row comes or goes while it +/// plays. A scene with no way of its own folds none. +pub fn movedBy(rec: *const Recording, by: Recording.Stop, way: [2]u64) u32 { + if (way[1] <= way[0]) return every; + var mask: u32 = comptime 1 << index("rsp").? | 1 << index("rbp").? | 1 << index("rip").?; + var k = way[0]; + while (k < @min(way[1], rec.end())) { + const n = @min(rec.next(by, k), way[1]); + mask |= rec.registersChanged(k, n); + k = n; + } + return mask & every; +} + +/// How many of the sixteen keep a row of their own. +fn fullRows(moves: u32) usize { + return @popCount(moves & 0xffff); +} + +/// The registers panel's rows for `moves`: a row each for those the scene +/// moves, the quiet ones three to a row, and rip. +pub fn registerRows(moves: u32) usize { + const full = fullRows(moves); + return full + (16 - full + theme.metric.registers.quiet_per_row - 1) / theme.metric.registers.quiet_per_row + 1; +} + +/// How far a dive has folded the registers panel at `box` (1: in its place, folded). +fn foldOf(box: Rect) f32 { + for (zoomed) |z| if (z) |zz| if (@abs(zz.box.x - box.x) < 0.5 and @abs(zz.box.y - box.y) < 0.5 and @abs(zz.box.h - box.h) < 0.5) return zz.fold; + return 1; +} + /// A register's place in `Regs.names`. pub fn index(name: []const u8) ?usize { for (zt.Regs.names, 0..) |known, i| if (std.mem.eql(u8, known, name)) return i; @@ -385,12 +467,8 @@ pub const Stack = struct { return if (d == 0) "rsp" else if (d > 0) u_.print("rsp+{x}", .{@as(u64, @intCast(d))}) else u_.print("rsp-{x}", .{@as(u64, @intCast(-d))}); } }.of; - const words = switch (slots) { - 4 => "four", - 6 => "six", - 8 => "eight", - else => u.print("{d}", .{slots}), - }; + const numbers = [_][]const u8{ "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty" }; + const words = if (slots < numbers.len) numbers[slots] else u.print("{d}", .{slots}); // The first word shown and the last. // The range before memory lands and after: one that changes crossfades (12 f), as a role does. const recast = if (now.resting()) 1 else std.math.clamp(since_memory / time.quick, 0, 1); |
