//! The introduction (design/motion.md, "A scene: the introduction"): one //! scene, one video, four chapters on one recording (`intro`: list.c from //! main's push(9) to line 22) and one clock counted forward only, from the //! recording's first stop at line 40. Each chapter opens on the last //! picture of the one before, at a seam that says its title in the //! caption's place (`title`) and keeps its name as the clock's label: //! I Memory (`intro_memory.zig`), II Registers (`intro_registers.zig`), //! III The stack (`intro_stack.zig`), IV Code and meaning (`intro_code.zig`), //! each a function this scene calls in order. const std = @import("std"); const anim = @import("anim"); const sk = @import("sketch"); const canim = @import("canim"); const recordings = @import("recordings"); const memory = @import("intro_memory.zig"); const registers = @import("intro_registers.zig"); const stack = @import("intro_stack.zig"); const code = @import("intro_code.zig"); pub const background = canim.background; pub const scene = anim.Live(frame, struct {}); const t = canim.theme.time; /// The chapters' names, as the clock's label says them (`II registers`). const names = [_][]const u8{ "I memory", "II registers", "III the stack", "IV code and meaning" }; fn frame(s: *anim.Frame) void { const rec = canim.open(recordings.intro); // The list's nodes are the chunks in use on glibc's heap (no agent told the allocations). rec.allocationsFromHeap(); // list.c's types as the pass would tell them: the recording is of the // plain build, which tells none (its locals are the debug info's). rec.declare("head", "*`struct node`"); rec.declare("`struct node`", "struct(16){value@0:i64;next@8:*`struct node`;}"); const label: Label = .{ .which = s.value(0), .docked = s.value(0) }; // I: its title from nothing (in at 6 f, read, out), the chapter's first text 6 f after it. s.cursor = f(6); const first = say(s, "I", "Memory"); first.out(s); const one = memory.chapter(s, rec); const two_title = seam(s, one.e, &.{one.caption}, "II", "Registers", label, 1); const two = registers.chapter(s, rec, one, two_title, label); const three_title = seam(s, two.e, two.texts(s), "III", "The stack", label, 2); const three = stack.chapter(s, rec, two, three_title); const four_title = seam(s, three.e, three.texts(s), "IV", "Code and meaning", label, 3); code.chapter(s, rec, three, four_title); // The clock's label, over every clock, from the first frame (the scene's end is where the cursor is left). const end = s.cursor; s.cursor = 0; const o = place(s, s.new(canim.ChapterLabel{ .names = &names, .which = label.which, .docked = label.docked, .widest = "moment 193 of 193" })); s.play(.{o.fadeIn()}, .{ .seconds = 0 }); s.cursor = end; } /// The clock's label: which chapter (`ChapterLabel.which`), and whether the clock is there to stand beside. pub const Label = struct { which: anim.Value, docked: anim.Value }; /// A chapter's title on screen, and when it has been read. pub const Title = struct { obj: anim.Obj, read_by: f32, /// It leaves at its reading time or now, the later (12 f); the cursor /// 6 f after: where the chapter's first text arrives. pub fn out(ti: Title, s: *anim.Frame) void { s.wait(@max(ti.read_by - s.cursor, 0)); s.play(.{ti.obj.fadeOut()}, .{ .seconds = t.caption_out, .ease = canim.ease.exit }); s.wait(t.caption_gap); } }; /// A chapter's title said in the caption's place (18 f, rising 8); the cursor where it has landed. pub fn say(s: *anim.Frame, numeral: []const u8, name: []const u8) Title { const o = canim.add(s, canim.Title{ .numeral = numeral, .name = name }); s.play(.{o.fadeIn()}, .{ .seconds = t.caption_in, .ease = canim.ease.enter }); return .{ .obj = o, .read_by = s.cursor + t.caption(@intCast(numeral.len + 2 + name.len)) }; } /// A seam (design/README.md, `title`), from `e`, the frame the chapter /// before has its last text read: still 30 f; `going` (its texts) leave /// together (12 f); the title arrives (48 to 66, rising 8), the clock's /// label crossfading to the chapter's with it (54 to 66, secondary); /// still to 126, where the cursor is left: the next chapter's opening. pub fn seam(s: *anim.Frame, e: f32, going: []const anim.Obj, numeral: []const u8, name: []const u8, label: Label, chapter: f32) Title { for (going) |o| { s.cursor = e + f(30); s.play(.{o.fadeOut()}, .{ .seconds = t.caption_out, .ease = canim.ease.exit }); } s.cursor = e + f(48); const ti = say(s, numeral, name); s.cursor = e + f(54); s.play(.{label.which.to(chapter)}, .{ .seconds = f(12), .ease = anim.ease.linear }); s.cursor = e + f(126); return ti; } pub fn f(frames: f32) f32 { return frames / 60; } /// Clock `v` from 0 to `frames`, linear, from the cursor; the cursor after it. pub fn run(s: *anim.Frame, v: anim.Value, frames: f32) void { s.play(.{v.to(0)}, .{ .seconds = 0 }); s.play(.{v.to(frames)}, .{ .seconds = f(frames), .ease = anim.ease.linear }); } /// The same, the cursor left where it was. pub fn start(s: *anim.Frame, v: anim.Value, frames: f32) void { const at = s.cursor; run(s, v, frames); s.cursor = at; } /// `v` to `to` over `frames`, linear, the cursor left where it was. pub fn to(s: *anim.Frame, v: anim.Value, value: f32, frames: f32) void { const at = s.cursor; s.play(.{v.to(value)}, .{ .seconds = f(frames), .ease = anim.ease.linear }); s.cursor = at; } /// A value at once, from the cursor. pub fn set(s: *anim.Frame, v: anim.Value, value: f32) void { s.play(.{v.to(value)}, .{ .seconds = 0 }); } pub fn place(s: *anim.Frame, data: anytype) anim.Obj { return s.custom(data, .{ .x = -640, .y = -360, .scale = canim.ui.scale }); } /// The page over a part of a panel the beat has not reached: lifted (its fade out) as the beat says it. pub const Cover = struct { box: canim.Rect, pub fn draw(c: *const Cover, fr: *sk.Frame, placed: anim.Placed) void { (canim.ui.Ui{ .f = fr, .at = placed }).fill(c.box, canim.theme.color.page); } }; /// A value framed as read (6 f in with its object's fade). pub const Read = struct { box: canim.Rect, pub fn draw(r: *const Read, fr: *sk.Frame, placed: anim.Placed) void { (canim.ui.Ui{ .f = fr, .at = placed }).read(r.box, 1); } }; /// A part of a disassembly row framed as read on a beat (an echo): the row /// of `addr` where the panel says it is this frame, from `x` (from the /// panel's left: the address 40, the operands 264, `disasm.zig`'s columns) /// `w` wide, `shows` of it. pub const RowRead = struct { addr: u64, x: f32, w: f32, shows: anim.Value, pub fn draw(r: *const RowRead, fr: *sk.Frame, placed: anim.Placed) void { const shows = std.math.clamp(placed.value(r.shows), 0, 1); if (shows <= 0) return; const px = canim.findPlace(fr, .{ .row = r.addr }) orelse return; const u = canim.fixed(fr, placed, 0); // Canvas pixels to the design's units (the camera is home: the frame fitted into the canvas). const w = @max(@floor(fr.in.window_width), 1); const h = @max(@floor(fr.in.window_height), 1); const k = @min(w / canim.theme.canvas.width, h / canim.theme.canvas.height); const left = (px[0] - w / 2) / k + canim.theme.canvas.width / 2.0; const top = (px[1] - h / 2) / k + canim.theme.canvas.height / 2.0; u.read(.{ .x = left + r.x, .y = top, .w = r.w, .h = canim.theme.metric.context.row }, shows); } }; pub fn cover(s: *anim.Frame, box: canim.Rect) anim.Obj { const o = place(s, s.new(Cover{ .box = box })); s.play(.{o.fadeIn()}, .{ .seconds = 0 }); return o; } /// Every one of `objs` there at once, from the cursor (a panel and the page over what it has not said yet). pub fn show(s: *anim.Frame, objs: []const ?anim.Obj) void { const at = s.cursor; for (objs) |o| if (o) |obj| { s.cursor = at; s.play(.{obj.fadeIn()}, .{ .seconds = 0 }); }; s.cursor = at; } /// A panel's tag and rules under the page, for `frame up`: its tag, its left, right and bottom rules, and its strip. pub fn chrome(s: *anim.Frame, b: canim.Rect, strip: bool) [5]?anim.Obj { const w = canim.theme.stroke.rule; const tag = canim.theme.metric.context.tag; return .{ cover(s, .{ .x = b.x, .y = b.y, .w = b.w, .h = tag }), cover(s, .{ .x = b.x, .y = b.y + tag, .w = w, .h = b.h - tag }), cover(s, .{ .x = b.x + b.w - w, .y = b.y + tag, .w = w, .h = b.h - tag }), cover(s, .{ .x = b.x, .y = b.y + b.h - w, .w = b.w, .h = w }), if (strip) cover(s, .{ .x = b.x + b.w - canim.theme.strip.cost, .y = b.y + tag, .w = canim.theme.strip.cost - w, .h = b.h - tag - w }) else null, }; } /// Lifts `covers` one after another, `apart` frames apart, `each` frames each, from the cursor; the cursor after the last. pub fn lift(s: *anim.Frame, covers: []const ?anim.Obj, apart: f32, each: f32) void { const at = s.cursor; var end = at; for (covers, 0..) |o, i| if (o) |obj| { s.cursor = at + f(apart * @as(f32, @floatFromInt(i))); s.play(.{obj.fadeOut()}, .{ .seconds = f(each), .ease = anim.ease.linear }); end = s.cursor; }; s.cursor = end; } /// The first moment from `from` at an instruction whose text has `text` in it. pub fn on(rec: *canim.Recording, from: u64, text: []const u8) u64 { var buf: [256]u8 = undefined; var i = from; while (i < rec.end()) : (i += 1) if (rec.instruction(i, rec.register(i, "rip"), &buf)) |here| if (std.mem.indexOf(u8, here.text, text) != null) return i; return from; } /// A clock counting the recording from its first stop at line 40 (`moment 6 of 193`), on `cursor`'s steps, in `ctx`'s frame. pub fn clock(s: *anim.Frame, rec: *canim.Recording, cursor: canim.Cursor, ctx: canim.Context) anim.Obj { var counts = cursor; counts.first = rec.lineMoment(40, 0); counts.last = rec.end(); return canim.add(s, canim.Clock{ .cursor = counts, .map = ctx.map, .stage = ctx.stage }); }