1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
//! 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 });
}
|