//! The column's wide placements, on sort's rings (design/README.md, //! "column (an experiment)", mock 55): the opening in the working frame //! (the `blocks` lens), then the drawing across both columns twice its size, //! the rest folded to the shelf, a beat's text `on` it, in the corner the //! rings leave free, its stem round the drawing's outside to the pc's block; //! then a beat `above` it; then the working frame again. The steps are //! sort's own: its first trip round the inner loop, a block at a time. const anim = @import("anim"); const canim = @import("canim"); const recordings = @import("recordings"); pub const background = canim.background; pub const scene = anim.Live(frame, struct {}); fn frame(s: *anim.Frame) void { const rec = canim.open(recordings.sort); const graph = canim.graph; // As the sort scene opens: the `while`, about to compare 31 with 12. var start = rec.call("sort", 0).enter; while (rec.next(.over, rec.next(.over, start)) < rec.call("swap", 0).enter) start = rec.next(.over, start); var at = canim.cursor(s, rec, start); at.levels = .{ .fire = .disasm, .source_rows = 6 }; at.journey(.over, rec.call("swap", 0).exit.?); const ctx = canim.context(s, at, .{ .split = canim.layout.split.blocks, .graph = true }); const blocks = canim.add(s, graph.Blocks{ .cursor = at, .stage = ctx.stage, .focus = true }); const col = canim.column(s, ctx, .{ .lens = blocks, .titles = .{ .band = "its blocks" }, .at = .below }); const joins = ctx.ties(s); const block = struct { fn walk(c: canim.Cursor, f: *anim.Frame) void { graph.toEnd(c, f); graph.leave(c, f); } /// The block the pc is in, by its first instruction's address. fn here(c: canim.Cursor, f: *anim.Frame) u64 { const i = c.moment(f); const pc = c.rec.register(i, "rip"); const g = graph.read(f.arena, c.rec, i, pc) orelse return pc; return g.nodes[g.nodeOf(pc) orelse return pc].start; } }; canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, blocks, joins }); col.beat(s, .{ .say = "`sort` as its blocks: each loop a ring, the inner touching\nthe outer. `j > 0`, so `jle` goes on to the compare." }); block.walk(at, s); // `on`: the drawing across both columns, the text in the corner the rings leave free. col.beat(s, .{ .at = .on, .say = "31 > 12: `setg` leaves 1,\nand `jne` takes the swap,\nthe first time it is reached.", .where = .{ 104, 144 }, .level = .{ .block = block.here(at, s) }, }); block.walk(at, s); block.walk(at, s); // `above`: the text leads the eye in at the top. col.beat(s, .{ .at = .above, .say = "The swap and `j--`; then the inner loop turns, back up to `j > 0`: its first turn." }); block.walk(at, s); col.beat(s, .{ .at = .below, .say = "" }); col.close(s); }