diff options
Diffstat (limited to 'anim/scenes/gallery.zig')
| -rw-r--r-- | anim/scenes/gallery.zig | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/anim/scenes/gallery.zig b/anim/scenes/gallery.zig index 693553e..48fba99 100644 --- a/anim/scenes/gallery.zig +++ b/anim/scenes/gallery.zig @@ -10,6 +10,11 @@ //! 3.6 s a step, mid-way: struck, read, projection, echo (mock 10) //! 6 s `subject` (mock 11); 8 s `none`, with the backtrace //! 10.8 s two loupes in depth, from rax and its node's `next` (mock 21) +//! 21 s the `blocks` lens: at rest (blocks reached and not yet, the trail, +//! an edge never taken), `leave` mid-way, `turn` landing, folds +//! 24 s the graph with its rows, as the map draws it (here at half size): +//! sort's (panned to its loop, the pc's block annotated) and libc's +//! `open` at its syscall (the blocks never reached folded) const std = @import("std"); const sk = @import("sketch"); const anim = @import("anim"); @@ -306,6 +311,101 @@ fn rowsPage(u: ui.Ui, p: *const Pages) void { _ = canim.hexdump.reading(panel, 3 * row, 0, m, &values, &known, &.{ .{ .at = 0, .len = 1, .type = char }, .{ .at = 1, .len = 1, .type = boolean }, .{ .at = 4, .len = 4, .type = int }, .{ .at = 8, .len = 8, .reads = .pointer } }); } +/// The graph pages' names, over their drawings. +const GraphPages = struct { + box: canim.Rect = .{ .x = 0, .y = 0, .w = 1920, .h = 1080 }, + + pub fn draw(_: *const GraphPages, f: *sk.Frame, at: anim.Placed) void { + const u: ui.Ui = .{ .f = f, .at = at }; + if (at.t >= 21 and at.t < 24) { + title(u, 64, 40, "graph: the blocks lens"); + for ([_][2]f32{ .{ 64, 72 }, .{ 976, 72 }, .{ 64, 488 }, .{ 976, 488 } }, [_][]const u8{ "at rest: reached, not yet, the trail, never taken", "leave: the edge drawn gold, the mark on it", "turn: landed, the lane's count and the header's struck", "folds: libc's open, the blocks never reached" }) |p, words| note(u, p[0], p[1], words); + } else if (at.t >= 24 and at.t < 27) { + title(u, 64, 40, "graph: with its rows, as on the map (half size)"); + } + } +}; + +/// A component drawn at half its size (the map's rows as the map shows them filling a 1080p frame). +fn Half(comptime T: type) type { + return struct { + inner: T, + box: canim.Rect = .{ .x = 0, .y = 0, .w = 1920, .h = 1080 }, + + pub fn draw(h: *const @This(), f: *sk.Frame, at: anim.Placed) void { + var p = at; + p.xf = p.xf.mul(.scale(0.5, 0.5)); + p.scale *= 0.5; + h.inner.draw(f, p); + } + }; +} + +/// The graph pages: sort's blocks in the lens, at rest and in `leave` and +/// `turn`, and libc's `open` folded; then the map's form of both. +fn graphPages(s: *anim.Frame, at_time: f32) [3]anim.Obj { + const graph = canim.graph; + const sort = canim.open(recordings.gallery_sort); + const hello = canim.open(recordings.gallery_hello); + const sort0 = sort.register(sort.call("sort", 0).enter, "rip"); + // Where the opening of the sort scene is: the inner loop's test, about to compare 31 with 12. + var start = sort.call("sort", 0).enter; + while (sort.next(.over, sort.next(.over, start)) < sort.call("swap", 0).enter) start = sort.next(.over, start); + // The first `jne` to the swap, and the first jump back to the test. + var jne = start; + while (!(sort.insn_branches[jne] != null and sort.insn_branches[jne].?.taken and sort.insn_branches[jne].?.to == sort0 + 0xc5)) jne += 1; + var back = jne; + while (!(sort.insn_branches[back] != null and sort.insn_branches[back].?.to == sort0 + 0x8a)) back += 1; + var syscall_at: u64 = 0; + var buf: [256]u8 = undefined; + for (hello.registers, 0..) |r, k| if (hello.strings.get(r.rip)) |name| if (std.mem.startsWith(u8, name, "libc.so.6!open+") and std.mem.eql(u8, (hello.instruction(k, r.rip, &buf) orelse continue).text, "syscall")) { + syscall_at = k; + break; + }; + const place = struct { + fn stage(s_: *anim.Frame, band: canim.Rect, disasm: canim.Rect) *canim.Stage { + var split = canim.layout.split.blocks; + split.band = band; + split.disasm = disasm; + return canim.Stage.init(s_, split); + } + }.stage; + const nowhere: canim.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }; + const rest = canim.cursor(s, sort, start); + const leaving = canim.cursor(s, sort, jne); + const turning = canim.cursor(s, sort, back); + const open_at = canim.cursor(s, hello, syscall_at); + const lenses = .{ + canim.add(s, graph.Blocks{ .cursor = rest, .stage = place(s, .{ .x = 64, .y = 84, .w = 880, .h = 296 }, nowhere) }), + canim.add(s, graph.Blocks{ .cursor = leaving, .stage = place(s, .{ .x = 976, .y = 84, .w = 880, .h = 296 }, nowhere) }), + canim.add(s, graph.Blocks{ .cursor = turning, .stage = place(s, .{ .x = 64, .y = 500, .w = 880, .h = 296 }, nowhere) }), + canim.add(s, graph.Blocks{ .cursor = open_at, .stage = place(s, .{ .x = 976, .y = 500, .w = 880, .h = 296 }, nowhere) }), + }; + // Each step played so that the page shows it at `at_time`: the leave with its mark mid-way, the turn just landed. + const l = canim.theme.time.leave; + s.cursor = at_time - l.sets_off - l.mark / 2.0 - 0.05; + graph.leave(leaving, s); + s.cursor = at_time - l.sets_off - 0.30 - l.count; + graph.leave(turning, s); + // The map's form, at half size: the map's units, two columns wide each. + const maps = .{ + canim.add(s, Half(graph.Map){ .inner = .{ .cursor = canim.cursor(s, sort, jne), .stage = place(s, nowhere, .{ .x = 128, .y = 176, .w = 1792, .h = 1688 }) } }), + canim.add(s, Half(graph.Map){ .inner = .{ .cursor = canim.cursor(s, hello, syscall_at), .stage = place(s, nowhere, .{ .x = 1952, .y = 176, .w = 1792, .h = 1688 }) } }), + }; + const pages = canim.add(s, GraphPages{}); + var all: [lenses.len]anim.Animation = undefined; + inline for (lenses, 0..) |o, i| all[i] = o.fadeIn(); + s.cursor = 21; + s.play(.{pages.fadeIn()}, .{ .seconds = 0 }); + s.play(all, .{ .seconds = 0 }); + s.cursor = 24; + inline for (lenses, 0..) |o, i| all[i] = o.fadeOut(); + s.play(all, .{ .seconds = 0 }); + s.play(.{ maps[0].fadeIn(), maps[1].fadeIn() }, .{ .seconds = 0 }); + s.cursor = 27; + return .{ pages, maps[0], maps[1] }; +} + fn frame(s: *anim.Frame) void { const rec = canim.open(recordings.gallery); const reverse = rec.call("reverse", 0); @@ -341,5 +441,12 @@ fn frame(s: *anim.Frame) void { near.open(s); s.wait(18.8 - s.cursor); deeper.open(s); + s.wait(20.6 - s.cursor); + deeper.close(s); + near.close(s); s.wait(21 - s.cursor); + // The graph's pages: the context stands aside. + inline for (panels, 0..) |o, i| all[i] = o.fadeOut(); + s.play(all, .{ .seconds = 0 }); + _ = graphPages(s, 21.8); } |
