diff options
Diffstat (limited to 'anim/src/rows.zig')
| -rw-r--r-- | anim/src/rows.zig | 114 |
1 files changed, 87 insertions, 27 deletions
diff --git a/anim/src/rows.zig b/anim/src/rows.zig index 69aa62b..a125b05 100644 --- a/anim/src/rows.zig +++ b/anim/src/rows.zig @@ -205,25 +205,46 @@ pub const flags = [_]Flag{ .{ .name = "CF", .bit = 0 }, .{ .name = "PF", .bit = /// flag, and how much of the corner shows); read, framed (`read`: a bit per /// flag, while a conditional reads them: an echo of the row that set them, /// `read_shows` how much). The value of eflags is not drawn: the names are the value. -pub fn rip(u: ui.Ui, y: f32, w: f32, moment: Recording.Moment, pc: u64, eflags: u64, changed: u64, held: f32, fire: f32, read: u64, read_shows: f32) void { +pub fn rip(u: ui.Ui, y: f32, w: f32, moment: Recording.Moment, pc: u64, eflags: u64, changed: u64, held: f32, fire: f32, read: u64, read_shows: f32, was: ?RipWas) void { const gold = theme.mark(.current); u.current(.{ .x = theme.stroke.rule, .y = y, .w = w - 2 * theme.stroke.rule, .h = row_h }, theme.metric.plaque.rip, fire); u.text(.mono_bold, size, m.side, baseline(y), "rip", gold.on_solid); const fl = theme.metric.flags; var x = w - m.side - @as(f32, flags.len) * fl.pitch + 10; - _ = chain(u, m.chain_x, y, moment, pc, x - 16, .{}); + // Where execution is changes with the advance: the old value goes as the new one comes, over it. + const before = was orelse RipWas{ .moment = moment, .pc = pc, .eflags = eflags }; + if (before.pc != pc and before.going < 1) { + _ = chain(u.faded(1 - before.going), m.chain_x, y, before.moment, before.pc, x - 16, .{}); + _ = chain(u.faded(before.going), m.chain_x, y, moment, pc, x - 16, .{}); + } else _ = chain(u, m.chain_x, y, moment, pc, x - 16, .{}); for (flags) |flag| { const set = eflags >> flag.bit & 1 != 0; - if (set) { - u.chip(.{ .x = x, .y = y + 2, .w = fl.chip[0], .h = fl.chip[1] }); - u.text(.mono_bold, size, x + 4, baseline(y), flag.name, t.bright); - } else u.text(.mono, size, x + 4, baseline(y), u.print("{c}{c}", .{ std.ascii.toLower(flag.name[0]), std.ascii.toLower(flag.name[1]) }), ui.mix(t.dim, gold.ember, 0.2)); + // A flag the step sets or clears crossfades as it lands (`flip`). + if (set != (before.eflags >> flag.bit & 1 != 0) and before.flip < 1) { + ripFlag(u.faded(1 - before.flip), x, y, flag, !set); + ripFlag(u.faded(before.flip), x, y, flag, set); + } else ripFlag(u, x, y, flag, set); if (changed >> flag.bit & 1 != 0) u.corner(x, y + 2, m.corner, held); if (read >> flag.bit & 1 != 0 and read_shows > 0) u.read(.{ .x = x, .y = y + 2, .w = fl.chip[0], .h = fl.chip[1] }, read_shows); x += fl.pitch; } } +/// rip's row as it was before the step: its value, going to the new one +/// `going` of the way (the advance), and the flags, `flip` of the way. +pub const RipWas = struct { moment: Recording.Moment, pc: u64, eflags: u64, going: f32 = 1, flip: f32 = 1 }; + +fn ripFlag(u: ui.Ui, x: f32, y: f32, flag: Flag, set: bool) void { + const fl = theme.metric.flags; + if (set) { + u.chip(.{ .x = x, .y = y + 2, .w = fl.chip[0], .h = fl.chip[1] }); + u.text(.mono_bold, size, x + 4, baseline(y), flag.name, t.bright); + } else u.text(.mono, size, x + 4, baseline(y), u.print("{c}{c}", .{ std.ascii.toLower(flag.name[0]), std.ascii.toLower(flag.name[1]) }), ui.mix(t.dim, theme.mark(.current).ember, 0.2)); +} + +/// A slot's role as it was before the step, and how far (0 to 1) the role it has now has come in over it. +pub const Role = struct { name: []const u8, local: bool = false, going: f32 = 1, from_rsp: ?i64 = null }; + /// `slot`: a word of the stack: a lane to 112 for `row` pins (`pins`, the /// registers that hold its address); its offset from rsp (`from_rsp` /// bytes), hex, faint, ranged right to 172 (`+18`, `-8` above rsp); its @@ -232,19 +253,28 @@ pub fn rip(u: ui.Ui, y: f32, w: f32, moment: Recording.Moment, pc: u64, eflags: /// recording knows it: `saved rbp` dim, a `local`'s name primary), ranged right where the room ends /// (136 from the right edge `w`: the `call` spans'), the chain ending a /// character before it. -pub fn slot(u: ui.Ui, y: f32, w: f32, moment: Recording.Moment, addr: u64, from_rsp: i64, pins: []const []const u8, pin_shows: f32, marks: Marks, role: []const u8, local: bool) Hops { +pub fn slot(u: ui.Ui, y: f32, w: f32, moment: Recording.Moment, addr: u64, from_rsp: i64, pins: []const []const u8, pin_shows: f32, marks: Marks, role: []const u8, local: bool, was: ?Role) Hops { const s = theme.metric.slot; if (pins.len > 0 and pin_shows > 0) u.faded(pin_shows).pinRow(s.lane, y, pins, theme.color.region.stack); - offset(u, y, from_rsp); + // An offset that changes with rsp (the window held, or moved by more than the slide) crossfades as a role does. + if (was) |o| if (o.from_rsp) |old| if (old != from_rsp and o.going < 1) { + offset(u.faded(1 - o.going), y, old); + offset(u.faded(o.going), y, from_rsp); + } else offset(u, y, from_rsp) else offset(u, y, from_rsp) else offset(u, y, from_rsp); var lead = marks; lead.first = .none; const base = baseline(y); const end = u.address(s.address, base, addr, .{ .ink = ui.rgb(theme.color.region.stack), .lead = marks.lead }); var room = w - s.room; - if (role.len > 0) { - const rx = room - u.width(.mono, size, role); - u.text(.mono, size, rx, base, role, if (local) t.primary else t.dim); - room = rx - adv; + // A role that changes in place (the step makes the word another's) crossfades, `was.going` of the way. + const before = was orelse Role{ .name = role, .local = local }; + const changes = !std.mem.eql(u8, before.name, role) or before.local != local; + const right = room; + for ([2]Role{ before, .{ .name = role, .local = local } }, [2]f32{ if (changes) 1 - before.going else 0, if (changes) before.going else 1 }) |r, shows| { + if (r.name.len == 0 or shows <= 0) continue; + const rx = right - u.width(.mono, size, r.name); + u.faded(shows).text(.mono, size, rx, base, r.name, if (r.local) t.primary else t.dim); + room = @min(room, rx - adv); } const held = (Recording.word(moment, addr, 8) catch null) orelse { _ = u.arrow(end, y + row_h / 2, .points); @@ -299,8 +329,18 @@ pub fn spanNameX(u: ui.Ui, w: f32, name: []const u8) f32 { /// primary), file and line ranged right, dim. A name cut only where the /// arguments begin, saying so. pub fn callRow(u: ui.Ui, y: f32, w: f32, n: usize, name: []const u8, args: []const u8, where: []const u8, newest: bool) void { + if (newest) callCurrent(u, y, w); + callLabels(u, y, w, n, name, args, where, newest); +} + +/// The newest call's wash and plaque, apart from its words: for a row that becomes or stops being the newest. +pub fn callCurrent(u: ui.Ui, y: f32, w: f32) void { + u.current(.{ .x = theme.stroke.rule, .y = y, .w = w - 2 * theme.stroke.rule, .h = row_h }, 40, 0); +} + +/// A `call` row's words, apart from its wash: for one whose words crossfade. +pub fn callLabels(u: ui.Ui, y: f32, w: f32, n: usize, name: []const u8, args: []const u8, where: []const u8, newest: bool) void { const gold = theme.mark(.current); - if (newest) u.current(.{ .x = theme.stroke.rule, .y = y, .w = w - 2 * theme.stroke.rule, .h = row_h }, 40, 0); u.text(if (newest) .mono_bold else .mono, size, m.side, baseline(y), u.print("#{d}", .{n}), if (newest) gold.on_solid else t.faint); const where_x = w - m.side - u.width(.mono, size, where); const args_x: f32 = 384; @@ -515,10 +555,11 @@ pub const Arcs = struct { /// Nested spans take separate lanes, the longest outermost; spans that /// do not overlap share one; past `lanes` the step's come first, then - /// the shorter, and the rest are only read. + /// the shorter, and the rest are only read. A lane change glides: while + /// an arc draws or fades (12 f), the others go from the lanes they have + /// 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; - const Span = struct { lo: f32, hi: f32, y0: f32, y1: f32, i: usize }; var spans: [32]Span = undefined; for (a.items[0..a.n], spans[0..a.n], 0..) |arc, *sp, i| { const up = arc.to < arc.from; @@ -536,11 +577,35 @@ pub const Arcs = struct { return x.hi - x.lo > y.hi - y.lo; } }.longer); + // Arriving or leaving: how far (the least of them), and the lanes without them. + var settled: f32 = 1; + for (a.items[0..a.n]) |arc| settled = @min(settled, @min(arc.drawn, arc.shows)); + const with = a.assign(spans[0..a.n], lanes, false); + const without = if (settled < 1) a.assign(spans[0..a.n], lanes, true) else with; + for (spans[0..a.n]) |sp| { + const arc = a.items[sp.i]; + const lane = with[sp.i] orelse continue; + const was = without[sp.i] orelse lane; + const x = std.math.lerp(k.lanes[was], k.lanes[lane], cursorGlide(settled)); + const shade = ui.mix(arc.ink, theme.color.page, k.standing * (1 - std.math.clamp(arc.full, 0, 1))); + const v = u.faded(arc.shows); + if (arc.stub) { + v.route(&.{ .{ k.out, sp.y0 }, .{ x, sp.y0 }, .{ x, sp.y1 } }, shade, .{ .width = k.width, .head = k.head, .radius = k.radius, .progress = arc.drawn, .dashed = arc.dashed }); + } else v.route(&.{ .{ k.out, sp.y0 }, .{ x, sp.y0 }, .{ x, sp.y1 }, .{ k.in, sp.y1 } }, shade, .{ .width = k.width, .head = k.head, .radius = k.radius, .progress = arc.drawn, .dashed = arc.dashed }); + } + } + + const Span = struct { lo: f32, hi: f32, y0: f32, y1: f32, i: usize }; + + /// Each span's lane (`spans` longest first), the step's first; `settled`: + /// only of the arcs neither drawing nor fading (those keep their lane in full). + fn assign(a: *const Arcs, spans: []const Span, lanes: usize, settled: bool) [32]?usize { var taken: [3][32][2]f32 = undefined; var counts = [3]usize{ 0, 0, 0 }; var lane_of: [32]?usize = @splat(null); - for ([_]bool{ true, false }) |hot| for (spans[0..a.n]) |sp| { - if (a.items[sp.i].hot != hot) continue; + for ([_]bool{ true, false }) |hot| for (spans) |sp| { + const arc = a.items[sp.i]; + if (arc.hot != hot or (settled and (arc.drawn < 1 or arc.shows < 1))) continue; lane_of[sp.i] = for (0..@min(lanes, 3)) |l| { const clear = for (taken[l][0..counts[l]]) |t2| { if (!(sp.hi < t2[0] or sp.lo > t2[1])) break false; @@ -552,16 +617,11 @@ pub const Arcs = struct { } } else null; }; - for (spans[0..a.n]) |sp| { - const arc = a.items[sp.i]; - const lane = lane_of[sp.i] orelse continue; - const x = k.lanes[lane]; - const shade = ui.mix(arc.ink, theme.color.page, k.standing * (1 - std.math.clamp(arc.full, 0, 1))); - const v = u.faded(arc.shows); - if (arc.stub) { - v.route(&.{ .{ k.out, sp.y0 }, .{ x, sp.y0 }, .{ x, sp.y1 } }, shade, .{ .width = k.width, .head = k.head, .radius = k.radius, .progress = arc.drawn, .dashed = arc.dashed }); - } else v.route(&.{ .{ k.out, sp.y0 }, .{ x, sp.y0 }, .{ x, sp.y1 }, .{ k.in, sp.y1 } }, shade, .{ .width = k.width, .head = k.head, .radius = k.radius, .progress = arc.drawn, .dashed = arc.dashed }); - } + return lane_of; + } + + fn cursorGlide(p: f32) f32 { + return theme.ease(.glide, std.math.clamp(p, 0, 1)); } }; |
