diff options
Diffstat (limited to 'anim/src/map.zig')
| -rw-r--r-- | anim/src/map.zig | 195 |
1 files changed, 164 insertions, 31 deletions
diff --git a/anim/src/map.zig b/anim/src/map.zig index e22db9f..341d75f 100644 --- a/anim/src/map.zig +++ b/anim/src/map.zig @@ -36,6 +36,14 @@ pub const diving = struct { pub const surface = 84; }; +/// The dive's frames over which the falling map crossfades into the minimap's drawing. +pub const minimap_lands = [2]f32{ 90, 96 }; + +/// How much of the minimap shows at dive frame `t`: none while the map falls, crossfading in as it lands. +pub fn minimapShows(t: f32) f32 { + return std.math.clamp((t - minimap_lands[0]) / (minimap_lands[1] - minimap_lands[0]), 0, 1); +} + /// Where each working window is on the map this frame, in canvas pixels. var window_px: [7]?[4]f32 = @splat(null); @@ -46,6 +54,16 @@ var windows: [7]?[2]u64 = @splat(null); var rows: [7][160]struct { key: u64, box: [4]f32 } = undefined; var counts: [7]usize = @splat(0); +/// The most rows each map panel has wanted so far (`measure`): its box is +/// as long as that, its content, and no longer. +/// shortcut: process-wide and a frame behind, as the drawing flags are; a scene's first frame packs by the defaults. +var held: [7]usize = @splat(0); + +/// While the map draws: `panel` wants `n` rows for what it shows now. +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 }; @@ -62,12 +80,13 @@ pub fn row(panel: Panel, key: u64, u: ui.Ui, r: Rect) void { counts[i] += 1; } -/// The map's boxes for a recording: the drawing (with a lens) and the -/// source in the first column, the disassembly in the second, the lens's -/// view (its region whole), the registers and the backtrace in the third, -/// the stack in the fourth. Each as long as its content where that is -/// shorter than the column. -// shortcut: a panel longer than its column is a window of what fits; continuing it in the next column's free space (`continued`), and the key in a column's foot, are not built. +/// The map's boxes for a recording, packed by content: each panel as long +/// as its rows (`measure`), the next under it 12 apart (design/README.md, +/// "The map and the minimap"). The drawing and the source in the first +/// column, the backtrace at its foot; the disassembly in the second; the +/// 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 { const st = theme.map.stage; const c = theme.map.columns; @@ -75,21 +94,32 @@ pub fn split(rec: *const Recording, lens: bool) Split { const gap = theme.canvas.row_gap; const panelH = theme.layout.panelH; const foot = st.y + st.h; + const want = struct { + fn of(panel: Panel, default: usize) f32 { + const n = held[@intFromEnum(panel)]; + return @floatFromInt(if (n > 0) n else default); + } + }.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 source_rows: f32 = @floatFromInt(@min(rec.line_count, theme.layout.rowsIn(foot - source_y))); - const view: Rect = .{ .x = c[2], .y = st.y, .w = w, .h = if (lens) panelH(theme.map.memory_rows) else 0 }; + const bt_rows = want(.backtrace, 5); + 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) }; - const bt_y = registers.y + registers.h + gap; + const more_y = registers.y + registers.h + gap; + const more_h = foot - more_y; return .{ .band = band, .view = view, - .source = .{ .x = c[0], .y = source_y, .w = w, .h = panelH(source_rows) }, - .disasm = .{ .x = c[1], .y = st.y, .w = w, .h = panelH(theme.map.disasm_rows) }, + .source = source, + .disasm = .{ .x = c[1], .y = st.y, .w = w, .h = panelH(@min(want(.disasm, theme.map.disasm_rows), theme.map.disasm_rows)) }, .registers = registers, .stack = .{ .x = c[3], .y = st.y, .w = w, .h = st.h }, - .backtrace = .{ .x = c[2], .y = bt_y, .w = w, .h = @min(panelH(12), foot - bt_y) }, + .backtrace = .{ .x = c[0], .y = bt_y, .w = w, .h = @min(panelH(bt_rows), foot - bt_y) }, .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 }, }; } @@ -108,6 +138,8 @@ pub const Map = struct { t: anim.Value, /// The map as an object of the scene, under the panels: it shows from `show`. 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, const Part = struct { ctx: *const anyopaque, draw: *const fn (*const anyopaque, *sk.Frame, anim.Placed) void }; @@ -164,33 +196,27 @@ pub const Map = struct { const t = placed.value(m.t); if (t >= diving.land) return; const fixed = @import("words.zig").fixed(f, placed, 0); - // The map: from filling the frame (half its units) to the minimap's rect (a twentieth). - const q = theme.ease(.glide, std.math.clamp((t - diving.move) / diving.fall, 0, 1)); - const mini = theme.minimap.box; - const k = std.math.pow(f32, 0.5, 1 - q) * std.math.pow(f32, theme.minimap.scale, q); - const origin = [2]f32{ q * mini.x, q * mini.y }; - var at = fixed.at; - at.xf = at.xf.mul(.translate(origin[0], origin[1])).mul(.scale(k, k)); - at.scale = fixed.at.scale * k; - fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); - m.drawAt(f, at, k < 0.12); - // The rest of the map veiled from 6 f to 24 f, lifting as it lands. - const veil = std.math.clamp((t - diving.bright) / (diving.move - diving.bright), 0, 1) * (1 - std.math.clamp((t - diving.lift) / (diving.land - diving.lift), 0, 1)); - (ui.Ui{ .f = f, .at = at }).veil(theme.map.stage, veil); - // The windows bright from 0 to 6 f, over the veil. - m.outline(f, at, k < 0.12, std.math.clamp(t / diving.bright, 0, 1)); + const at = m.falling(f, placed, t); + // Large, it is under the panels diving out of it; small (`falling`), over them, into the corner. + if (at.scale >= small * fixed.at.scale) m.copy(f, at, fixed, t) else fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); // Each working panel: from its window on the map at the start to its place, 6 f after the one before. const back = at.xf.invert(); const working = m.frame.now(placed); - inline for (.{ "band", "view", "source", "registers", "disasm", "stack", "backtrace" }, 0..) |name, order| { + // In the frame's reading order, except that a panel drawn over another + // sets off first: a panel in its place is never crossed by one still + // on its way (the disassembly over the source's foot, the stack over + // the registers' lower rows were, for a third of a second). + inline for (.{ "band", "view", "disasm", "stack", "source", "registers", "backtrace" }, 0..) |name, order| { const i = @intFromEnum(@field(Panel, name)); const box = @field(working, name); if (box.h > 0) if (window_px[i]) |w| { const a = back.apply(.{ w[0], w[1] }); const b = back.apply(.{ w[2], w[3] }); - // On the map as it fills the frame (half its units): the panel's rows on the window's rows, its tag above them. + // On the map as it fills the frame (half its units): the panel's rows on the window's rows, its tag above them; + // a window that is the panel whole (the band, the registers) has its tag in it. const s0 = (b[0] - a[0]) / 2 / box.w; - const lead = (if (i == @intFromEnum(Panel.band)) 0 else theme.metric.context.tag + theme.metric.context.pad) * s0; + const whole = i == @intFromEnum(Panel.band) or i == @intFromEnum(Panel.registers); + const lead = (if (whole) 0 else theme.metric.context.tag + theme.metric.context.pad) * s0; const from: Rect = .{ .x = a[0] / 2, .y = a[1] / 2 - lead, .w = box.w * s0, .h = box.h * s0 }; const p = theme.ease(.glide, std.math.clamp((t - diving.move - @as(f32, @floatFromInt(order)) * diving.apart) / diving.travel, 0, 1)); const scale = std.math.pow(f32, s0, 1 - p); @@ -203,6 +229,64 @@ pub const Map = struct { } } + /// 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; + + /// Where the map is at dive frame `t`: from filling the frame (half + /// its units) to the minimap's rect (a twentieth), its scale on the + /// logarithm, its corner going toward the minimap's as the scale does, + /// so that it falls into the corner. + fn falling(m: *const Map, f: *sk.Frame, placed: anim.Placed, t: f32) anim.Placed { + _ = m; + const fixed = @import("words.zig").fixed(f, placed, 0); + const q = theme.ease(.glide, std.math.clamp((t - diving.move) / diving.fall, 0, 1)); + const mini = theme.minimap.box; + const k = std.math.pow(f32, 0.5, 1 - q) * std.math.pow(f32, theme.minimap.scale, q); + const toward = (0.5 - k) / (0.5 - theme.minimap.scale); + var at = fixed.at; + at.xf = at.xf.mul(.translate(toward * mini.x, toward * mini.y)).mul(.scale(k, k)); + at.scale = fixed.at.scale * k; + return at; + } + + /// The falling map, veiled, its windows outlined, and its edge as the + /// minimap's; it crossfades into the minimap's own drawing as it lands. + fn copy(m: *const Map, f: *sk.Frame, at: anim.Placed, fixed: ui.Ui, t: f32) void { + const shows = 1 - minimapShows(t); + if (shows <= 0) return; + const mini = at.scale < small * fixed.at.scale; + if (!mini) fixed.fill(.{ .x = 0, .y = 0, .w = theme.canvas.width, .h = theme.canvas.height }, theme.color.page); + var faded = at; + faded.pose.opacity *= shows; + m.drawAt(f, faded, mini); + // The rest of the map veiled from 6 f to 24 f, lifting as it lands. + const veil = std.math.clamp((t - diving.bright) / (diving.move - diving.bright), 0, 1) * (1 - std.math.clamp((t - diving.lift) / (minimap_lands[1] - diving.lift), 0, 1)); + (ui.Ui{ .f = f, .at = faded }).veil(theme.map.stage, veil); + // The windows bright from 0 to 6 f, over the veil. + m.outline(f, faded, mini, std.math.clamp(t / diving.bright, 0, 1)); + var edge: ui.Ui = .{ .f = f, .at = faded }; + edge.at.xf = .identity; + const a = at.xf.apply(.{ 0, 0 }); + const b = at.xf.apply(.{ 2 * theme.canvas.width, 2 * theme.canvas.height }); + const q = std.math.clamp((0.5 * fixed.at.scale - at.scale) / ((0.5 - theme.minimap.scale) * fixed.at.scale), 0, 1); + edge.faded(q).frame(.{ .x = a[0] - 1, .y = a[1] - 1, .w = b[0] - a[0] + 2, .h = b[1] - a[1] + 2 }, theme.color.rule, @max(1, fixed.at.scale)); + } + + /// Small, the falling map over the working panels (the minimap's drawer calls it). + pub fn fallingOver(m: *const Map, f: *sk.Frame, placed: anim.Placed) void { + const t = placed.value(m.t); + if (t >= minimap_lands[1]) return; + const fixed = @import("words.zig").fixed(f, placed, 0); + const at = m.falling(f, placed, t); + if (at.scale >= small * fixed.at.scale) return; + // Its ground, so that it reads over what it passes. + var ground: ui.Ui = .{ .f = f, .at = at }; + ground.at.pose.opacity *= 1 - minimapShows(t); + ground.fill(.{ .x = 0, .y = 0, .w = 2 * theme.canvas.width, .h = 2 * theme.canvas.height }, theme.color.page); + m.copy(f, at, fixed, t); + } + /// The map in `at`'s transform (the map's units), and the working /// frame's windows outlined on it: a 2-unit `dim` frame 4 out; on the /// minimap (`mini`) a pixel of primary, the focused one 1.5. @@ -216,10 +300,56 @@ pub const Map = struct { ui.strokes = mini; counts = @splat(0); for (m.parts[0..m.n]) |p| p.draw(p.ctx, f, at); + if (m.cursor) |c| m.thread(f, at, c.now(at), mini); ui.mapping = false; ui.strokes = false; } + /// The thread on the map: the current line and the pc's row, joined + /// across the gutter between source and disassembly (x 1008), gold; on + /// the minimap a stroke a pixel wide. And there, a mark no working + /// window shows `flash`es: a ring 8 across drawing out to 14 and gone + /// (12 f), with the strike (the minimap's own time, 6 f behind). + fn thread(m: *const Map, f: *sk.Frame, at: anim.Placed, now: @import("cursor.zig").Now, mini: bool) void { + _ = m; + const rec = now.rec; + const k = at.scale; + var raw: ui.Ui = .{ .f = f, .at = at }; + raw.at.xf = .identity; + const marked = now.marked(); + const line = rows_of(.source, rec.own[marked]); + const pc = rows_of(.disasm, rec.register(marked, "rip")); + if (line != null and pc != null) { + const a = line.?; + const b = pc.?; + const lane = at.xf.apply(.{ 1008, 0 })[0]; + const w = if (mini) @max(1, k / theme.minimap.scale) else theme.stroke.line * k; + const gold = theme.mark(.current).solid; + 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. + 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 word = span.addr & ~@as(u64, 7); + if (word >= win[0] and word <= win[1]) continue; + const box = rows_of(.stack, word) orelse 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)); + } + } + + /// Where the map's row of key `key` in `panel` is this frame, in canvas pixels. + fn rows_of(panel: Panel, key: u64) ?[4]f32 { + const i = @intFromEnum(panel); + for (rows[i][0..counts[i]]) |rw| if (rw.key == key) return rw.box; + return null; + } + /// The working windows' outlines on the map in `at`, `bright` of the way /// from `dim` to bright; where they are is kept (`window_px`). fn outline(m: *const Map, f: *sk.Frame, at: anim.Placed, mini: bool, bright: f32) void { @@ -265,7 +395,10 @@ pub const Map = struct { /// 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`. pub fn minimap(m: *const Map, f: *sk.Frame, at: anim.Placed) void { - const fixed = @import("words.zig").fixed(f, at, 0); + var shown = at; + shown.pose.opacity *= minimapShows(at.value(m.t)); + 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); var placed = fixed.at; |
