summaryrefslogtreecommitdiff
path: root/anim/src/map.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/map.zig')
-rw-r--r--anim/src/map.zig360
1 files changed, 323 insertions, 37 deletions
diff --git a/anim/src/map.zig b/anim/src/map.zig
index 341d75f..255ea2d 100644
--- a/anim/src/map.zig
+++ b/anim/src/map.zig
@@ -36,6 +36,11 @@ pub const diving = struct {
pub const surface = 84;
};
+/// Whether every frame is the map (`Map.wholeMap`): `CANIM_MAP` in the environment.
+pub fn looking(f: *sk.Frame) bool {
+ return f.host.env("CANIM_MAP") != null;
+}
+
/// The dive's frames over which the falling map crossfades into the minimap's drawing.
pub const minimap_lands = [2]f32{ 90, 96 };
@@ -48,8 +53,10 @@ pub fn minimapShows(t: f32) f32 {
var window_px: [7]?[4]f32 = @splat(null);
/// The working frame's windows this frame: the first and last key of the
-/// rows each shows (a line number, an address).
-var windows: [7]?[2]u64 = @splat(null);
+/// rows each shows (a line number, an address), those it shows at the
+/// step's start, and how far (0 to 1, eased) it has gone from them.
+var windows: [7]?Window = @splat(null);
+const Window = struct { now: [2]u64, was: [2]u64, p: f32 };
/// The map's rows this frame, in canvas pixels: each one's key and box.
var rows: [7][160]struct { key: u64, box: [4]f32 } = undefined;
var counts: [7]usize = @splat(0);
@@ -64,9 +71,11 @@ pub fn measure(panel: Panel, n: usize) void {
if (ui.mapping) held[@intFromEnum(panel)] = @max(held[@intFromEnum(panel)], n);
}
-/// A working panel shows the rows of keys `first` to `last`.
-pub fn window(panel: Panel, first: u64, last: u64) void {
- if (!ui.mapping) windows[@intFromEnum(panel)] = .{ first, last };
+/// A working panel shows the rows of keys `now` (first and last), going
+/// there from `was`, `p` of the way (eased): its outline on the minimap
+/// glides with its scroll, and never jumps.
+pub fn window(panel: Panel, now: [2]u64, was: [2]u64, p: f32) void {
+ if (!ui.mapping) windows[@intFromEnum(panel)] = .{ .now = now, .was = was, .p = p };
}
/// A map panel's row of key `key` is at `r`, in `u`'s units.
@@ -87,7 +96,7 @@ pub fn row(panel: Panel, key: u64, u: ui.Ui, r: Rect) void {
/// lens's view, the registers, and in the rest the stack going on
/// (`continued`), in the third; the stack in the fourth, whole.
// shortcut: a column's rest after the disassembly is page: the 5-row dumps round what the registers point at, the open loupes and the key are not built.
-pub fn split(rec: *const Recording, lens: bool) Split {
+pub fn split(rec: *const Recording, lens: bool, way: [2]u64) Split {
const st = theme.map.stage;
const c = theme.map.columns;
const w = theme.map.column;
@@ -102,32 +111,203 @@ pub fn split(rec: *const Recording, lens: bool) Split {
}.of;
const band: Rect = .{ .x = c[0], .y = st.y, .w = w, .h = if (lens) theme.layout.split.subject.band.h else 0 };
const source_y = if (lens) band.y + band.h + gap else st.y;
- const bt_rows = want(.backtrace, 5);
+ // The backtrace as long as the call chain gets over the scene's way: packed once, never repacked under the eye.
+ const bt_rows = @max(want(.backtrace, 0), deepest(rec, way));
const source_rows: f32 = @floatFromInt(@min(rec.line_count, theme.layout.rowsIn(foot - source_y - gap - panelH(bt_rows))));
const source: Rect = .{ .x = c[0], .y = source_y, .w = w, .h = panelH(source_rows) };
const bt_y = source.y + source.h + gap;
- const view: Rect = .{ .x = c[2], .y = st.y, .w = w, .h = if (lens) panelH(@min(want(.view, theme.map.memory_rows), theme.map.memory_rows)) else 0 };
- const registers: Rect = .{ .x = c[2], .y = if (lens) view.y + view.h + gap else st.y, .w = w, .h = panelH(17) };
+ // The view as long as what draws there has wanted: none where nothing does (a lens drawn alone).
+ const view_rows = @min(want(.view, 0), theme.map.memory_rows);
+ const view: Rect = .{ .x = c[2], .y = st.y, .w = w, .h = if (lens and view_rows > 0) panelH(view_rows) else 0 };
+ const registers: Rect = .{ .x = c[2], .y = if (view.h > 0) view.y + view.h + gap else st.y, .w = w, .h = panelH(17) };
const more_y = registers.y + registers.h + gap;
const more_h = foot - more_y;
+ const disasm: Rect = .{ .x = c[1], .y = st.y, .w = w, .h = panelH(@min(want(.disasm, theme.map.disasm_rows), theme.map.disasm_rows)) };
+ // The source longer than its column (69 lines round the current line, or the file whole if shorter)
+ // goes on at the top of the next column's free space, under its tag, `continued`.
+ const lines_left: f32 = @as(f32, @floatFromInt(@min(rec.line_count, theme.map.disasm_rows))) - source_rows;
+ const under_disasm = disasm.y + disasm.h + gap;
+ const more_rows = @min(lines_left, @as(f32, @floatFromInt(theme.layout.rowsIn(foot - under_disasm))));
+ const source_more: Rect = .{ .x = c[1], .y = under_disasm, .w = w, .h = if (more_rows >= 3) panelH(more_rows) else 0 };
+ const backtrace: Rect = .{ .x = c[0], .y = bt_y, .w = w, .h = @min(panelH(bt_rows), foot - bt_y) };
+ const rest = struct {
+ fn under(r: Rect, bottom: f32) Rect {
+ const y = r.y + r.h + theme.canvas.row_gap;
+ return .{ .x = r.x, .y = y, .w = r.w, .h = @max(bottom - y, 0) };
+ }
+ }.under;
return .{
.band = band,
.view = view,
.source = source,
- .disasm = .{ .x = c[1], .y = st.y, .w = w, .h = panelH(@min(want(.disasm, theme.map.disasm_rows), theme.map.disasm_rows)) },
+ .disasm = disasm,
.registers = registers,
.stack = .{ .x = c[3], .y = st.y, .w = w, .h = st.h },
- .backtrace = .{ .x = c[0], .y = bt_y, .w = w, .h = @min(panelH(bt_rows), foot - bt_y) },
+ .backtrace = backtrace,
.dump_rows = theme.map.memory_rows,
.more = .{ .x = c[2], .y = more_y, .w = w, .h = if (more_h >= panelH(3)) theme.layout.panelH(@floor((more_h - 32) / 24)) else 0 },
+ .source_more = source_more,
+ .spare = .{ rest(backtrace, foot), if (source_more.h > 0) rest(source_more, foot) else rest(disasm, foot) },
};
}
+/// The most frames the call chain has from moment `way[0]` to `way[1]` (5 where it knows none).
+fn deepest(rec: *const Recording, way: [2]u64) f32 {
+ const context = @import("context.zig");
+ var most: usize = 0;
+ var seen: ?@TypeOf(rec.depths[0]) = null;
+ var i = way[0];
+ while (i <= @min(way[1], rec.end())) : (i += 1) {
+ if (seen != null and rec.depths[i] <= seen.?) continue;
+ seen = rec.depths[i];
+ var buf: [24]context.Frame = undefined;
+ most = @max(most, context.frames(rec, i, &buf).len);
+ }
+ return @floatFromInt(if (most > 0) most else 5);
+}
+
+/// What the map gives the rest of its first two columns, in the
+/// catalogue's order once the stack has had more (its own column, and the
+/// registers' column's rest, `stack, continued`): a short dump round each
+/// place the registers and the stack's words point at, outside the stack
+/// and the code (five rows, the target's row in the middle, its region's
+/// ink: registers first, in pwndbg's order, then the words up from rsp,
+/// none within another's rows); the loupes open, each a lifted panel of
+/// nine rows; and last the key. Only then page.
+pub const Spare = struct {
+ cursor: @import("cursor.zig").Cursor,
+ stage: *const Stage,
+ map: *const Map,
+
+ pub fn draw(sp: *const Spare, f: *sk.Frame, placed: anim.Placed) void {
+ if (!ui.mapping) return;
+ const hexdump = @import("hexdump.zig");
+ const context = @import("context.zig");
+ const rows_ = @import("rows.zig");
+ const m = theme.metric.context;
+ const panelH = theme.layout.panelH;
+ var free = sp.stage.now(placed).spare;
+ const now = sp.cursor.now(placed);
+ const rec = sp.cursor.rec;
+ const moment = now.moment();
+ const regs = (moment.regs(rec.tid) catch null) orelse return;
+ const things = @import("objects.zig").reach(f.scratch, rec, moment, null);
+ // The next box of height `h` in what is left: from the top of the first column with room.
+ const take = struct {
+ fn of(left: *[2]Rect, h: f32) ?Rect {
+ for (left) |*r| if (r.h >= h) {
+ const out: Rect = .{ .x = r.x, .y = r.y, .w = r.w, .h = h };
+ r.y += h + theme.canvas.row_gap;
+ r.h = @max(r.h - h - theme.canvas.row_gap, 0);
+ return out;
+ };
+ return null;
+ }
+ }.of;
+ const Target = struct { name: []const u8, at: u64 };
+ var targets: [24]Target = undefined;
+ var n: usize = 0;
+ const add = struct {
+ fn of(list: []Target, count: *usize, mo: Recording.Moment, name: []const u8, at: u64) void {
+ if (count.* == list.len) return;
+ switch (rows_.regionOf(mo, at)) {
+ .heap, .data, .rwx, .rodata => {},
+ .none, .stack, .code => return,
+ }
+ var byte: [8]u8 = undefined;
+ var known: [8]bool = undefined;
+ mo.read(at & ~@as(u64, 7), &byte, &known) catch return;
+ if (!known[0]) return;
+ // None within another's five rows.
+ for (list[0..count.*]) |t_| if (@abs(@as(i64, @bitCast((at & ~@as(u64, 15)) -% (t_.at & ~@as(u64, 15))))) < 5 * 16) return;
+ list[count.*] = .{ .name = name, .at = at };
+ count.* += 1;
+ }
+ }.of;
+ for (theme.metric.all_registers[0..16]) |name| {
+ if (std.mem.eql(u8, name, "rsp") or std.mem.eql(u8, name, "rbp")) continue;
+ add(&targets, &n, moment, name, regs.named(name) orelse continue);
+ }
+ var word: u64 = 0;
+ while (word < 64) : (word += 1) {
+ const addr = regs.rsp + 8 * word;
+ const points = (Recording.word(moment, addr, 8) catch null) orelse continue;
+ add(&targets, &n, moment, f.format("rsp+{x}", .{8 * word}), points);
+ }
+ for (targets[0..n]) |target| {
+ const box = take(&free, panelH(5)) orelse break;
+ const u = context.at(f, placed, box);
+ const region = rows_.regionOf(moment, target.at);
+ _ = u.panel(box.w, box.h, target.name, .{ .note = f.format("\u{2192} {x} \u{00b7} {s}", .{ target.at, regionName(region) }) });
+ hexdump.drawArcs(u, now, 0, m.tag + m.pad, (target.at & ~@as(u64, 15)) -| 32, 5, .{ .things = things, .region = rows_.ink(region) }, false, .{ m.tag, box.h - m.pad });
+ }
+ // The loupes open: lifted, nine rows round their target.
+ for (sp.map.loupes) |maybe| {
+ const l = maybe orelse continue;
+ const shows = std.math.clamp(placed.value(l.opening) * theme.time.loupe.open / theme.time.loupe.rise, 0, 1) * (1 - placed.value(l.closing));
+ if (shows <= 0) continue;
+ const aim = l.aim(now) orelse continue;
+ const box = take(&free, panelH(9)) orelse break;
+ const u = context.at(f, placed, box).faded(shows);
+ u.fill(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }, theme.color.lift);
+ _ = u.panel(box.w, box.h, "loupe", .{ .note = f.format("{s} \u{2192} {x}", .{ aim.name, aim.target }) });
+ hexdump.drawArcs(u, now, 0, m.tag + m.pad, (aim.target & ~@as(u64, 15)) -| 64, 9, .{ .things = things, .region = rows_.ink(rows_.regionOf(moment, aim.target)) }, true, .{ m.tag, box.h - m.pad });
+ }
+ // The key: the recording and the moment, the marks, the inks.
+ if (take(&free, panelH(3))) |box| key(context.at(f, placed, box), box, rec, now);
+ }
+
+ fn regionName(region: @import("ztrace").telescope.Region) []const u8 {
+ return switch (region) {
+ .stack => "stack",
+ .heap => "heap",
+ .code => "code",
+ .data, .rwx => "data",
+ .rodata => "read-only",
+ .none => "",
+ };
+ }
+
+ /// The map's key, three rows: what ran and where in it the map is; the marks, each drawn as it is; the inks.
+ fn key(u: ui.Ui, box: Rect, rec: *const Recording, now: @import("cursor.zig").Now) void {
+ const m = theme.metric.context;
+ const t = theme.color.text;
+ const size = theme.size.mono.context;
+ const body = u.panel(box.w, box.h, "key", .{ .note = "the marks and inks of every picture", .legend = &.{} });
+ const rows_ = @import("rows.zig");
+ var y = body.y + m.pad;
+ u.text(.mono, size, m.side, rows_.baseline(y), u.print("{s} \u{00b7} moment {d} of {d}", .{ rec.file, now.marked() -| now.way[0], now.way[1] -| now.way[0] }), t.primary);
+ y += m.row;
+ var x: f32 = m.side;
+ u.current(.{ .x = x, .y = y, .w = 120, .h = m.row }, 40, 0);
+ u.text(.mono, size, x + 48, rows_.baseline(y), "current", t.primary);
+ x += 160;
+ _ = u.written(.{ .x = x + 6, .y = y, .w = 24, .h = m.row }, .struck);
+ u.text(.mono_bold, size, x + 6, rows_.baseline(y), "2a", t.bright);
+ u.text(.mono, size, x + 48, rows_.baseline(y), "written", t.primary);
+ x += 160;
+ u.corner(x + 2, y + 2, m.corner, 1);
+ u.text(.mono, size, x + 6, rows_.baseline(y), "2a", t.primary);
+ u.text(.mono, size, x + 48, rows_.baseline(y), "changed", t.primary);
+ x += 160;
+ u.read(.{ .x = x + 6, .y = y, .w = 24, .h = m.row }, 1);
+ u.text(.mono, size, x + 6, rows_.baseline(y), "2a", t.primary);
+ u.text(.mono, size, x + 48, rows_.baseline(y), "read", t.primary);
+ y += m.row;
+ x = m.side;
+ for (@import("context.zig").legend) |entry| {
+ u.text(.mono, size, x, rows_.baseline(y), entry.text, entry.ink);
+ if (entry.under) u.fill(.{ .x = x, .y = rows_.baseline(y) + 3, .w = u.width(.mono, size, entry.text), .h = theme.stroke.rule }, entry.ink);
+ x += u.width(.mono, size, entry.text) + 24;
+ }
+ }
+};
+
/// The map: its stage, and the components drawn on it, each a working
/// frame's component bound to that stage.
pub const Map = struct {
stage: *Stage,
- parts: [8]Part = undefined,
+ parts: [12]Part = undefined,
n: usize = 0,
/// The panel the narration is in: its window bright on the minimap.
focus: ?Panel = null,
@@ -140,6 +320,8 @@ pub const Map = struct {
obj: anim.Obj = undefined,
/// Where the program is: for the thread across the gutter, and the minimap's flashes.
cursor: ?@import("cursor.zig").Cursor = null,
+ /// The scene's loupes: open, each is a panel of its own on the map (`Spare`).
+ loupes: [2]?*const @import("loupe.zig").Loupe = .{ null, null },
const Part = struct { ctx: *const anyopaque, draw: *const fn (*const anyopaque, *sk.Frame, anim.Placed) void };
@@ -155,6 +337,13 @@ pub const Map = struct {
m.n += 1;
}
+ /// Puts a drawing on the map, in a band of its own over the source,
+ /// for a scene whose working frame has none (its map is split anew).
+ pub fn drawing(m: *Map, s: *anim.Frame, rec: *const Recording, component: anytype) void {
+ m.stage.first = split(rec, true, if (m.cursor) |c| .{ c.first, c.last } else .{ 0, 0 });
+ m.add(s, component);
+ }
+
/// Whether the working frame is in place (the minimap is the map).
pub fn settled(m: *const Map, at: anim.Placed) bool {
return at.value(m.t) >= diving.land;
@@ -229,6 +418,21 @@ pub const Map = struct {
}
}
+ /// Frames into the dive now; 0 (the map filling the frame, as a scene
+ /// that opens on it shows it) with `CANIM_MAP` in the environment.
+ fn diveAt(m: *const Map, f: *sk.Frame, placed: anim.Placed) f32 {
+ return if (looking(f)) 0 else placed.value(m.t);
+ }
+
+ /// With `CANIM_MAP` in the environment every frame is the map filling
+ /// it, as a scene that opens on it shows it (the clock draws it, `wholeMap`; the
+ /// working panels, the ties and the loupes stand aside): for looking at
+ /// any scene's map at 1:1 in a 4K export.
+ pub fn wholeMap(m: *const Map, f: *sk.Frame, placed: anim.Placed) void {
+ const fixed = @import("words.zig").fixed(f, placed, 0);
+ m.copy(f, m.falling(f, placed, 0), fixed, 0);
+ }
+
/// Below this scale (of the frame's) the falling map is drawn over the
/// panels, on its way into the corner, and not under them.
const small = 0.12;
@@ -328,19 +532,39 @@ pub const Map = struct {
raw.route(&.{ .{ a[2], (a[1] + a[3]) / 2 }, .{ lane, (a[1] + a[3]) / 2 }, .{ lane, (b[1] + b[3]) / 2 }, .{ b[0], (b[1] + b[3]) / 2 } }, gold, .{ .width = w, .head = null, .radius = 0 });
}
if (!mini or !now.walking()) return;
- // A struck word outside every window: the stack's, round its rsp.
+ // A mark no working window shows: a word struck or read, on the
+ // stack (its own column or continued) or in memory the map draws
+ // (the view's dump, the dumps round the pointers), flashes where the
+ // map has it, in the mark's colour.
const since = now.since(.memory, 0);
const p = since / (12.0 / 60.0);
if (p < 0 or p > 1) return;
- const win = windows[@intFromEnum(Panel.stack)] orelse return;
- for (rec.written(now.stops[1], now.stops[0])) |span| {
+ const marks = [2]struct { spans: []const Recording.Span, ink: u24 }{
+ .{ .spans = rec.written(now.stops[1], now.stops[0]), .ink = theme.color.struck },
+ .{ .spans = rec.read(now.stops[1], now.stops[0]), .ink = theme.mark(.read).solid },
+ };
+ for (marks) |mark| for (mark.spans) |span| {
+ // Where the map has it: the stack's word, or the 16 bytes of a dump's row.
const word = span.addr & ~@as(u64, 7);
- if (word >= win[0] and word <= win[1]) continue;
- const box = rows_of(.stack, word) orelse continue;
+ const sixteen = span.addr & ~@as(u64, 15);
+ const panel: Panel, const key: u64 = if (rows_of(.stack, word) != null) .{ .stack, word } else .{ .view, sixteen };
+ const box = rows_of(panel, key) orelse continue;
+ if (windows[@intFromEnum(panel)]) |win| if (key >= win.now[0] and key <= win.now[1]) continue;
const c = ui.Vec{ (box[0] + box[2]) / 2, (box[1] + box[3]) / 2 };
const r = std.math.lerp(@as(f32, 4), 7, p) * k / theme.minimap.scale;
- raw.faded(1 - p).disc(c, r, null, ui.rgb(theme.color.struck), @max(1, k / theme.minimap.scale));
- }
+ raw.faded(1 - p).disc(c, r, null, ui.rgb(mark.ink), @max(1, k / theme.minimap.scale));
+ };
+ }
+
+ /// The top and bottom of the map's rows of panel `i` with keys from `keys[0]` to `keys[1]`, in canvas pixels.
+ fn spanOf(i: usize, keys: [2]u64) ?[2]f32 {
+ var top: f32 = std.math.inf(f32);
+ var bottom: f32 = -std.math.inf(f32);
+ for (rows[i][0..counts[i]]) |rw| if (rw.key >= keys[0] and rw.key <= keys[1]) {
+ top = @min(top, rw.box[1]);
+ bottom = @max(bottom, rw.box[3]);
+ };
+ return if (top < bottom) .{ top, bottom } else null;
}
/// Where the map's row of key `key` in `panel` is this frame, in canvas pixels.
@@ -367,48 +591,110 @@ pub const Map = struct {
var r: [4]f32 = .{ a[0], a[1], b[0], b[1] };
var shown = panel == .registers or panel == .band;
if (windows[i]) |win| {
- var top: f32 = std.math.inf(f32);
- var bottom: f32 = -std.math.inf(f32);
- for (rows[i][0..counts[i]]) |rw| if (rw.key >= win[0] and rw.key <= win[1]) {
- top = @min(top, rw.box[1]);
- bottom = @max(bottom, rw.box[3]);
- };
- if (top < bottom) {
- r[1] = top;
- r[3] = bottom;
+ // Where the window was and where it is, and between them as far as its scroll has gone.
+ const is = spanOf(i, win.now);
+ const was = spanOf(i, win.was) orelse is;
+ if (is orelse was) |to| {
+ const from = was orelse to;
+ // On the minimap each end on whole pixels: crisp at rest, between them only while it glides.
+ const snap = struct {
+ fn of(v: f32, on: bool) f32 {
+ return if (on) @round(v) else v;
+ }
+ }.of;
+ r[1] = std.math.lerp(snap(from[0], mini), snap(to[0], mini), win.p);
+ r[3] = std.math.lerp(snap(from[1], mini), snap(to[1], mini), win.p);
shown = true;
}
}
+ // On the minimap on whole pixels (a window's ends already are, at rest).
+ if (mini) {
+ r[0] = @round(r[0]);
+ r[2] = @round(r[2]);
+ if (windows[i] == null) {
+ r[1] = @round(r[1]);
+ r[3] = @round(r[3]);
+ }
+ }
window_px[i] = if (shown) r else null;
if (shown) {
const focus = m.focus == panel;
// On the minimap a pixel of the frame: `k` is the canvas's pixels to a map unit.
const w = if (mini) @as(f32, if (focus) 1.5 else 1) * k / theme.minimap.scale else theme.map.outline * k;
const out = if (mini) w else theme.map.outline_out * k;
- raw.frame(.{ .x = r[0] - out, .y = r[1] - out, .w = r[2] - r[0] + 2 * out, .h = r[3] - r[1] + 2 * out }, ui.mix(if (mini) theme.color.text.primary else theme.color.text.dim, theme.color.text.bright, bright), if (bright > 0 and !mini) w * 1.5 else w);
+ const ring: Rect = .{ .x = r[0] - out, .y = r[1] - out, .w = r[2] - r[0] + 2 * out, .h = r[3] - r[1] + 2 * out };
+ const ink = ui.mix(if (mini) theme.color.text.primary else theme.color.text.dim, theme.color.text.bright, bright);
+ // On the minimap not snapped to pixels: a window that glides moves a pixel over many frames, not in one.
+ if (mini) {
+ const pen = raw.at.pen(.{ .fill = ink });
+ for ([4]sk.math.Rect{ .{ .x = ring.x, .y = ring.y, .w = ring.w, .h = w }, .{ .x = ring.x, .y = ring.y + ring.h - w, .w = ring.w, .h = w }, .{ .x = ring.x, .y = ring.y + w, .w = w, .h = ring.h - 2 * w }, .{ .x = ring.x + ring.w - w, .y = ring.y + w, .w = w, .h = ring.h - 2 * w } }) |edge| sk.draw.rect(f, edge, pen);
+ } else raw.frame(ring, ink, if (bright > 0) w * 1.5 else w);
}
}
}
}
};
+/// The minimap's drawings, a frame apart, and what they are averaged into:
+/// the host's images, made once for a size.
+/// shortcut: a process-wide cache of host images, for one player at a time; two at once want it in their Session.
+var fades: struct { w: u32 = 0, h: u32 = 0, images: [theme.time.minimap_fade + 1]sk.Image = undefined } = .{};
+
/// The minimap: `m` at a twentieth in the caption band's right end, still
/// while the camera moves; the page under it, framed a pixel in `rule`.
+/// Every change on it fades in over `time.minimap_fade` frames from
+/// `time.minimap_lag` after its onset: it is the average of that many
+/// drawings, each from the cursor's mirror a frame later (`Cursor.lagInto`),
+/// so a stroke that changes, a mark that comes and the gold that moves on
+/// all fade, and a window's glide is smoothed, never stepped.
pub fn minimap(m: *const Map, f: *sk.Frame, at: anim.Placed) void {
var shown = at;
- shown.pose.opacity *= minimapShows(at.value(m.t));
+ shown.pose.opacity *= minimapShows(m.diveAt(f, at));
if (shown.pose.opacity <= 0) return;
const fixed = @import("words.zig").fixed(f, shown, 0);
const box = theme.minimap.box;
- fixed.fill(box, theme.color.page);
+ const a = fixed.at.xf.apply(.{ box.x, box.y });
+ const b = fixed.at.xf.apply(.{ box.x + box.w, box.y + box.h });
+ const px: sk.Rect = .{ .x = @round(a[0]), .y = @round(a[1]), .w = @round(b[0]) - @round(a[0]), .h = @round(b[1]) - @round(a[1]) };
+ const w: u32 = @intFromFloat(@max(px.w, 1));
+ const h: u32 = @intFromFloat(@max(px.h, 1));
+ if (fades.w != w or fades.h != h) {
+ if (fades.w != 0) for (fades.images) |img| f.host.freeImage(img);
+ for (&fades.images) |*img| img.* = f.host.newImage(w, h);
+ fades.w = w;
+ fades.h = h;
+ }
+ // Each drawing in an image of its own, the page under it, in the image's pixels.
var placed = fixed.at;
- placed.xf = placed.xf.mul(.translate(box.x, box.y)).mul(.scale(theme.minimap.scale, theme.minimap.scale));
+ placed.pose.opacity = 1;
+ placed.xf = sk.math.Affine.translate(-px.x, -px.y).mul(fixed.at.xf).mul(.translate(box.x, box.y)).mul(.scale(theme.minimap.scale, theme.minimap.scale));
placed.scale = fixed.at.scale * theme.minimap.scale;
- const clip = fixed.at.xf.apply(.{ box.x, box.y });
- const end = fixed.at.xf.apply(.{ box.x + box.w, box.y + box.h });
- f.clip(sk.Rect{ .x = @round(clip[0]), .y = @round(clip[1]), .w = @round(end[0]) - @round(clip[0]), .h = @round(end[1]) - @round(clip[1]) });
- m.drawAt(f, placed, true);
- f.clip(null);
+ const values = f.scratch.dupe(f32, at.values) catch return;
+ placed.values = values;
+ const n = theme.time.minimap_fade;
+ var weights: [n]f32 = @splat(0);
+ var made: usize = 0;
+ for (0..n) |k| {
+ // A mirror the same as the one before draws the same: its drawing counts twice.
+ const differs = if (m.cursor) |c| c.lagInto(values, k) else k == 0;
+ if (differs) {
+ f.target(fades.images[made]);
+ f.clear(ui.rgb(theme.color.page));
+ m.drawAt(f, placed, true);
+ made += 1;
+ }
+ weights[made - 1] += 1;
+ }
+ // Averaged: each drawing over those before it at its share of the drawings so far.
+ const whole: sk.Rect = .{ .x = 0, .y = 0, .w = px.w, .h = px.h };
+ f.target(fades.images[n]);
+ var so_far: f32 = 0;
+ for (fades.images[0..made], weights[0..made]) |img, weight| {
+ so_far += weight;
+ f.image(img, whole, .{ .tint = sk.Color.white.alphaFloat(weight / so_far) });
+ }
+ f.target(.none);
+ f.image(fades.images[n], px, .{ .tint = sk.Color.white.alphaFloat(shown.pose.opacity) });
fixed.frame(.{ .x = box.x - 1, .y = box.y - 1, .w = box.w + 2, .h = box.h + 2 }, theme.color.rule, 1);
}