//! The introduction, chapter IV: code and meaning (design/motion.md, "A //! scene: the introduction", IV1 to IV5; mocks 32, 33, 36), a function the //! scene `intro` calls after III's seam. On the //! `intro` recording at the load in `reverse` (line 21, `node *next = //! cur->next;`, the instruction that reads `cur->next`): the code's bytes //! as a dump row, that instruction's four framed; `decode`d into its row //! of `aligned` (`interleaved`), its neighbours at a run, each line level //! with its run; then `align` to `columns`; then the working frame with the //! nodes drawn from the heap's bytes, each pane's minimap drawing itself //! last; then the map (`surface`). It opens on chapter III's last picture, //! its state column staying veiled until the decoded code spans it, and //! the one clock steps on to the load as the working frame assembles. The //! texts `above` the aligned panel, then below the working frame, the //! last landing before the map surfaces under it. const std = @import("std"); const anim = @import("anim"); const sk = @import("sketch"); const canim = @import("canim"); const intro = @import("intro.zig"); const stack = @import("intro_stack.zig"); const t = canim.theme.time; const f = intro.f; const run = intro.run; const on = intro.on; /// The page over a part not drawn yet (a pane's minimap until IV4). const Page = struct { box: canim.Rect, pub fn draw(c: *const Page, fr: *sk.Frame, placed: anim.Placed) void { (canim.ui.Ui{ .f = fr, .at = placed }).fill(c.box, canim.theme.color.page); } }; /// The variables whose tags the nodes carry, as the list scene's. const tracked = [_][]const u8{ "prev", "cur", "next", "head" }; /// From the seam's opening (the cursor), on chapter III's last picture. pub fn chapter(s: *anim.Frame, rec: *canim.Recording, three: stack.Three, title: intro.Title) void { const reverse = rec.call("reverse", 0); // The load: `cur->next` read, line 21's second instruction. const moment = on(rec, rec.lineMoment(21, reverse.enter), "[rax + 8]"); const pc = rec.register(moment, "rip"); var buf: [256]u8 = undefined; const insn = rec.instruction(moment, pc, &buf).?; // Its bytes and its text as canim writes it (the size word dropped), from the recording. var code: [16]u8 = undefined; var known: [16]bool = undefined; rec.moment(moment).read(pc, code[0..insn.len], known[0..insn.len]) catch {}; var hex: std.ArrayList(u8) = .empty; for (code[0..insn.len], 0..) |b, k| hex.print(s.arena, "{s}{x:0>2}", .{ if (k > 0) " " else "", b }) catch {}; const text = std.mem.replaceOwned(u8, s.arena, insn.text, "qword ptr ", "") catch insn.text; const opening = three; const begun = s.cursor; var at = canim.cursor(s, rec, moment); at.journey(.moment, moment + 1); at.levels = .{ .idea = .data, .follow = t.move, .source_rows = 8, .introduction = true }; const ctx = canim.context(s, at, .{ .split = canim.layout.split.subject }); const list = canim.nodes(s, .{ .cursor = at, .stage = ctx.stage, .root = "head", .track = &tracked, .named = true }); ctx.map.add(s, canim.Nodes{ .cursor = at, .stage = ctx.map.stage, .root = "head", .track = &tracked, .named = true }); // The one clock (II's and III's cursor), over this context's map: it takes the old one's place at once, the same picture. const clock = intro.clock(s, rec, opening.at, ctx); // The relations, and rax's link to the node as III3 names it. const joins, const rax_link = ctx.tiesWith(s, "rax", 1.0); // Each pane's minimap under the page until III4, where they draw themselves last, top down // (over the panels, under the aligned rows landing on them; on from the panels' first frame). const first = ctx.stage.first; var strips: [4]anim.Obj = undefined; for ([_]canim.Rect{ first.view, first.source, first.stack, first.disasm }, &strips) |b, *o| o.* = s.custom(s.new(Page{ .box = .{ .x = b.x + b.w - canim.theme.strip.cost, .y = b.y + canim.theme.metric.context.tag, .w = canim.theme.strip.cost - canim.theme.stroke.rule, .h = b.h - canim.theme.metric.context.tag - canim.theme.stroke.rule } }), .{ .x = -640, .y = -360, .scale = canim.ui.scale }); const al = s.new(canim.Aligned.init(s, rec, moment)); const panel = s.custom(al, .{ .x = -640, .y = -360, .scale = canim.ui.scale }); s.cursor = begun; s.play(.{panel.fadeIn()}, .{ .seconds = 0 }); // Texts above the panel that spans both columns: twice a beside's line (two lines in the band of 120). var asides: canim.Asides = .{ .wrap = 2 * 40 }; const left = canim.theme.canvas.margin_x; const above = canim.theme.canvas.stage.y + 40; // The opening, from III's last picture (its texts gone at the seam): its code gives // way (18 f); its state column stays, veiled at 50%, until the decoded code takes both // columns; the clock and its label stay, under the stage. s.play(.{ opening.code[0].fadeOut(), opening.code[1].fadeOut(), opening.code[2].fadeOut(), opening.state[0].move(.{ .opacity = 0.5 }), opening.state[1].move(.{ .opacity = 0.5 }) }, .{ .seconds = f(18), .ease = anim.ease.linear }); title.out(s); // III1: the code's bytes, one instruction's framed. asides.say(s, std.fmt.allocPrint(s.arena, "Code is bytes too: `{s}` is one instruction.", .{hex.items}) catch "", left, above); s.wait(t.caption_lead); run(s, al.bytes, 12 + 2 * 15 + 12 + 6); s.wait(t.beat); // III2: decoded into its row, its neighbours at a run, each line heading its run. asides.say(s, std.fmt.allocPrint(s.arena, "Decoded: `{s}`, from line {d}.\nEach line heads the instructions it compiled to.", .{ text, insn.line orelse 0 }) catch "", left, above); // II's state column goes as the decoded rows come to span it (12 f). s.play(.{ opening.state[0].fadeOut(), opening.state[1].fadeOut() }, .{ .seconds = f(12), .ease = anim.ease.linear }); s.cursor -= f(12); run(s, al.decode, 60); // The neighbours at half the run's pace (rows 4 f apart): they come while the text is read. s.play(.{al.rows_in.to(0)}, .{ .seconds = 0 }); s.play(.{al.rows_in.to(2 * 32 + 8)}, .{ .seconds = 2 * f(2 * 32 + 8), .ease = anim.ease.linear }); run(s, al.chrome, 24); s.wait(t.beat); // III2, the other form: two columns, each line level with the first of its instructions. asides.say(s, "Two columns: each line by its first instruction. A square after `]`: a byte it touches.", left, above); // `align` at two thirds of its pace (120 f for 80): the two columns come while the text is read. s.play(.{al.form.to(0)}, .{ .seconds = 0 }); s.play(.{al.form.to(80)}, .{ .seconds = f(120), .ease = anim.ease.linear }); s.wait(t.beat); // Into the working frame: the texts above leave; `stack`: the lines glide to // the source panel's rows, the instructions to the disassembly's (60 f); those // panels come in under them as the aligned rows go (12 f): the same rows; then // the band and the state column (`establish`). asides.leave(s); al.to = .{ .source = ctx.stage.first.source, .disasm = ctx.stage.first.disasm }; run(s, al.stack, 60); s.play(.{ strips[0].fadeIn(), strips[1].fadeIn(), strips[2].fadeIn(), strips[3].fadeIn() }, .{ .seconds = 0 }); s.play(.{ ctx.source.fadeIn(), ctx.disasm.fadeIn(), panel.fadeOut() }, .{ .seconds = f(12), .ease = anim.ease.linear }); var says: canim.Narrator = .{}; // The one clock goes on, forward, to IV's moment: the chapters before's cursor taken // there (its panels gone), the count changing and its gold fading in as a step's (12 f). const later: canim.Plan = .{ .advance = 0, .travel = 0, .total = t.quick }; const counted = s.cursor; s.play(.{ opening.clock.fadeOut(), clock.fadeIn() }, .{ .seconds = 0 }); opening.at.step(s, moment, later, later.total); s.cursor = counted; canim.establish(s, .{ ctx.registers, ctx.stack, joins }); // III3: the node it reads, as bytes and drawn: the band comes in, its // elements rising from their bytes. No camera: at x1.5 the drawing's // nodes and its bytes do not both fit the frame, and the band is whole at x1. says.line(s, "Later, at line 21, `rax` points at a list node on the heap:\nits bytes, and drawn, the node."); // The heap's dump first, in the band's right half (18 f); then the nodes drawn from it, rising (`establish`). s.play(.{ctx.stage.drawing.to(0)}, .{ .seconds = 0 }); s.play(.{list.fadeIn()}, .{ .seconds = f(18), .ease = anim.ease.linear }); s.wait(f(30)); s.play(.{ctx.stage.drawing.to(1)}, .{ .seconds = f(12), .ease = anim.ease.linear }); s.cursor -= f(12); ctx.establish(s, .{}, 3); s.wait(t.beat); // rax framed as read, its link up to the node it points at, held, drawn back. rax_link.play(s); s.wait(rax_link.total()); s.wait(t.beat); // III4: the whole frame; each pane's minimap draws itself, last, top down (24 f, 72 f apart: while the text is read). says.line(s, "This is the whole frame. Every view in it is these same bytes;\neach strip, the whole of its pane."); const strips_from = s.cursor; for (strips, 0..) |o, k| { s.cursor = strips_from + f(72 * @as(f32, @floatFromInt(k))); s.play(.{o.fadeOut()}, .{ .seconds = f(24), .ease = anim.ease.linear }); } s.wait(t.beat); // III5: its text lands before the move, under the map as under the frame; then `surface`. says.line(s, "And all of it at once: the map."); ctx.map.surface(s); s.wait(@max(says.read_by - s.cursor, 0)); s.wait(t.before_cut); }