diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 18:06:30 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 19:01:23 -0300 |
| commit | e63b0624f57472d40af32a006c32cc47d403b822 (patch) | |
| tree | b7295da62acd96bc7aba425720eed95605526693 /anim/src/array.zig | |
| parent | 318e16181a28725e218121363555580725d6d0d4 (diff) | |
| download | computeranim-e63b0624f57472d40af32a006c32cc47d403b822.tar.gz computeranim-e63b0624f57472d40af32a006c32cc47d403b822.zip | |
canim: what the review found; the band as two panels; list and sort by instruction
The first videos were reviewed frame by frame and the catalogue changed
with them. A lens is a drawing over the program column and its view over
the state column, so the stack keeps six slots, its window on the whole
frame. Operands are whole. list and sort are recorded by instruction
from main (record --from), so their registers strike, links reach nodes
and cells, rows that ran are marked and jumps are drawn. A call's node is
a projection of its return address; pins travel and keep their side; a
mark covers the bytes that changed, at the element's width; a syscall's
result is stored after the kernel returns it and every panel is of one
moment; fast passes are veiled; the clock stands still during a step;
captions get their reading time and a scene's first step comes by four
seconds.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'anim/src/array.zig')
| -rw-r--r-- | anim/src/array.zig | 128 |
1 files changed, 84 insertions, 44 deletions
diff --git a/anim/src/array.zig b/anim/src/array.zig index b4472e7..9adc132 100644 --- a/anim/src/array.zig +++ b/anim/src/array.zig @@ -38,19 +38,26 @@ pub const Array = struct { focus: bool = false, /// The timetable of a step that swaps two neighbouring cells (give it - /// to `Cursor.step`): the line fires, the first value lifts and - /// flies, the second a little behind it; each lands with a strike; - /// then the hold, and the mark moves on. 2.1 s. + /// to `Cursor.step`): the line fires; the registers strike; the two + /// runs of bytes strike, 6 f apart, and the projection draws from + /// them; only then does the first value lift and fly, the second a + /// little behind it; each lands with a strike; then the hold, and the + /// mark moves on. 2.9 s. pub const swap: cursors.Plan = blk: { - const lands = time.fire + fl.lift + fl.near; + const bytes = 2 * time.cascade; + const lands = bytes + time.project.bracket + time.project.draw + fl.lift + fl.near; const advance = lands + fl.second + time.read_value; - break :blk .{ .at = .{ time.cascade, time.cascade, lands }, .advance = advance, .travel = time.step, .total = advance + time.step + time.rest }; + break :blk .{ .at = .{ time.cascade, bytes, lands }, .advance = advance, .travel = time.step, .total = advance + time.step + time.rest }; }; pub fn draw(g: *const Array, f: *sk.Frame, at: anim.Placed) void { const box = g.stage.box(at, .band); if (box.h < theme.metric.context.tag + 24) return; - const u = context.at(f, at, box); + const u = context.at(f, at, box).faded(at.value(g.stage.drawing)); + // A relayout moves the band: what is drawn in it stays inside it + // (its view, drawn below, clips itself and hands the clip back). + u.clip(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); + defer u.unclip(); const now = g.cursor.now(at); const rec = g.cursor.rec; const moment = now.shown(.idea); @@ -59,21 +66,23 @@ pub const Array = struct { return; }; const kind = rec.typeOf(f.scratch, v.type); - // Its declaration in the tag, and in the right half its bytes. + // Its declaration in the tag, and in its view its bytes. _ = u.panel(box.w, box.h, objects.declare(f.scratch, rec, v), .{ .focus = g.focus }); const m = theme.metric.context; - const half = theme.layout.state.x - theme.layout.program.x; // An array of numbers; anything else is read as 4-byte ones. const elem: u64 = if (kind != null and kind.? == .array) kind.?.array.elem.size() orelse 4 else 4; const signed = kind == null or kind.? != .array or kind.?.array.elem.* != .scalar or kind.?.array.elem.scalar.kind == .int; + // An element is read as its type says: a character quoted, a boolean by name. + const elem_type: Recording.types.Type = if (kind != null and kind.? == .array) kind.?.array.elem.* else .{ .scalar = .{ .kind = .int, .bits = 32 } }; const count: usize = @intCast(@min(v.size / elem, 32)); if (count == 0) return; { const first = v.addr & ~@as(u64, 15); - const rows_n = @min(theme.layout.rowsIn(box.h), (v.addr + v.size - first + 15) / 16); - u.text(.sans_medium, theme.size.sans.tag, half + 12, m.tag - 6, "its bytes", t.primary); - u.text(.sans, theme.size.sans.micro, half + 12 + u.width(.sans_medium, theme.size.sans.tag, "its bytes") + 12, m.tag - 6, u.print("{x} to {x}, an element a run", .{ v.addr, v.addr + v.size - 1 }), t.faint); - hexdump.draw(u, now, half, m.tag + m.pad, first, rows_n, .{ .array = .{ .addr = v.addr, .len = v.size, .elem = @intCast(elem) }, .region = context.ink(context.regionOf(moment, v.addr)) }); + const dump = hexdump.panel(f, at, g.stage, u.print("{x} to {x}, an element a run", .{ v.addr, v.addr + v.size - 1 }), &.{}); + const rows_n = @min(dump.rows, (v.addr + v.size - first + 15) / 16); + if (rows_n > 0) hexdump.draw(dump.u, now, 0, m.tag + m.pad, first, rows_n, .{ .array = .{ .addr = v.addr, .len = v.size, .elem = @intCast(elem) }, .region = context.ink(context.regionOf(moment, v.addr)) }); + dump.veil(now); + u.clip(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); } // The cells, in the left half: a size up as the subject. @@ -82,8 +91,8 @@ pub const Array = struct { const cell: [2]f32 = if (subject) .{ 96, 72 } else .{ 80, 44 }; const size: f32 = if (subject) theme.size.mono.flight else theme.size.mono.small; const label: f32 = if (subject) theme.size.mono.small else theme.size.mono.context; - const left = (half - 32 - @as(f32, @floatFromInt(count)) * cell[0]) / 2; - const top = m.tag + @as(f32, if (subject) 44 else 16) + label * 1.2 + 4; + const left = (box.w - @as(f32, @floatFromInt(count)) * cell[0]) / 2; + const top = m.tag + @as(f32, if (subject) 72 else 16) + label * 1.2 + 4; const walking = now.walking(); // What moved: a cell written with what another cell held, which this step read. @@ -105,7 +114,11 @@ pub const Array = struct { } }; + // Each cell as much as it has risen from its bytes (`establish`). + const rising = at.value(g.stage.rise); for (0..count) |i| { + const risen = ties.rise(rising, i, count); + const cu = u.faded(risen.element).moved(0, risen.below); const r: Rect = .{ .x = left + @as(f32, @floatFromInt(i)) * cell[0], .y = top, .w = cell[0] - 2, .h = cell[1] }; const addr = v.addr + i * elem; // The cell a value is flying to is struck when it lands: the second a little after the first. @@ -117,13 +130,13 @@ pub const Array = struct { var heat = now.written(addr, elem, .idea, delay); // The value on its way is the anticipation: no frame as well. if (flown != null) heat.arm = 0; - const ink = u.cellWritten(r, heat, theme.color.raised); + const ink = cu.cellWritten(r, heat, theme.color.raised); // Staging: the compare is seen (framed as read) before anything moves. - if (now.wasRead(addr, elem) and now.writeAge(addr, elem) != 0) u.cellRead(r, now.reading(.idea, 0)); + if (now.wasRead(addr, elem) and now.writeAge(addr, elem) != 0) cu.cellRead(r, now.reading(.idea, 0)); // Its index over it, where a node has its address: the projection lands there. const index_text = u.print("{d}", .{i}); const ly = r.y - 4 - label * 1.2; - u.text(.mono, label, r.x + (r.w - @as(f32, @floatFromInt(index_text.len)) * label * 3 / 5) / 2, ly + label * 0.96, index_text, t.faint); + cu.text(.mono, label, r.x + (r.w - @as(f32, @floatFromInt(index_text.len)) * label * 3 / 5) / 2, ly + label * 0.96, index_text, t.faint); ties.anchor(u, .{ .node_address = addr }, .{ .x = r.x, .y = ly, .w = r.w, .h = label * 1.2 }); ties.anchor(u, .{ .node_part = addr }, r); // Until its new value lands a cell keeps the old one, faint once @@ -131,31 +144,10 @@ pub const Array = struct { const shown = if (pending) old[i] else values[i]; const digits = r; const leaving = pending and flown != null and (!walking or now.since(.idea, delay) >= -(flightTime(cell[0]) + fl.lift)); - if (shown) |n| u.label(ink.face, size, digits, .center, u.print("{d}", .{n}), if (leaving) ui.rgb(t.faint) else ink.ink) else u.unknown(digits); + if (shown) |n| cu.label(ink.face, size, digits, .center, objects.reading(u.f.scratch, n, elem_type), if (leaving) ui.rgb(t.faint) else ink.ink) else cu.unknown(digits); } - // Index variables: pins under the cell they index, sliding from - // cell to cell as the idea strikes; two in one cell share its pin. - var at_cell: [32]std.ArrayList([]const u8) = @splat(.empty); - var slide: [32]?f32 = @splat(null); - for (g.indices) |name| { - const iv = rec.variable(f.scratch, now.moment(), name) orelse continue; - const here = number(now.moment(), iv.addr, @min(iv.size, 8), true) orelse continue; - if (here < 0 or here >= count) continue; - const k: usize = @intCast(here); - at_cell[k].append(f.scratch, name) catch {}; - if (number(now.before(), iv.addr, @min(iv.size, 8), true)) |was| if (was != here and was >= 0 and was < count) { - slide[k] = @floatFromInt(was); - }; - } - for (at_cell, 0..) |names, k| { - if (names.items.len == 0) continue; - var x = left + (@as(f32, @floatFromInt(k)) + 0.5) * cell[0]; - if (slide[k]) |was| x = std.math.lerp(left + (was + 0.5) * cell[0], x, cursors.standard(now.moving(.idea, 0, time.move))); - u.pinUnder(x, top + cell[1], names.items, t.primary, label); - } - - // Values in flight, over everything: one over, the next under. + // Values in flight, over the cells and under every name and pin: one over, the next under. for (flights.items, 0..) |flight, k| { const from = ui.Vec{ left + (@as(f32, @floatFromInt(flight.from)) + 0.5) * cell[0], top + cell[1] / 2 + 9 }; const to = ui.Vec{ left + (@as(f32, @floatFromInt(flight.to)) + 0.5) * cell[0], top + cell[1] / 2 + 9 }; @@ -179,7 +171,10 @@ pub const Array = struct { } // Arcs: an idea moves on a curve, slow out of one cell and into the other, quickest over the top. const eased = cursors.glide(along); - const rise = std.math.clamp(fl.arc * far, fl.arc_min, fl.arc_max) + cell[1] / 2; + // As high as a quarter of the way, clear of the row, and never out of the band. + const card_half = (cell[1] + 4) * fl.lift_scale / 2; + const room = @min(from[1] - card_half - m.tag - 2, box.h - 4 - card_half - from[1]); + const rise = @min(std.math.clamp(fl.arc * far, fl.arc_min, fl.arc_max) + cell[1] / 2, room); const way: f32 = if (k % 2 == 0) -1 else 1; const c = sk.math.mix(from, to, eased) + ui.Vec{ 0, way * rise * @sin(std.math.pi * eased) }; const grown = std.math.lerp(1, fl.lift_scale, lifted); @@ -188,9 +183,53 @@ pub const Array = struct { const card: Rect = .{ .x = c[0] - w / 2, .y = c[1] - h / 2, .w = w, .h = h }; u.fill(card, theme.color.page); u.frame(card, t.bright, theme.stroke.line); - if (values[flight.to]) |n| u.label(.mono_bold, size, card, .center, u.print("{d}", .{n}), t.bright); + if (values[flight.to]) |n| u.label(.mono_bold, size, card, .center, objects.reading(u.f.scratch, n, elem_type), t.bright); _ = compact; } + // Under the cards in flight: index variables, pins under the cell they index, sliding from + // cell to cell as the idea strikes; two in one cell share its pin. + var at_cell: [32]std.ArrayList([]const u8) = @splat(.empty); + var slide: [32]?f32 = @splat(null); + for (g.indices) |name| { + const iv = rec.variable(f.scratch, now.moment(), name) orelse continue; + const here = number(now.moment(), iv.addr, @min(iv.size, 8), true) orelse continue; + if (here < 0 or here >= count) continue; + const k: usize = @intCast(here); + at_cell[k].append(f.scratch, name) catch {}; + if (number(now.before(), iv.addr, @min(iv.size, 8), true)) |was| if (was != here and was >= 0 and was < count) { + slide[k] = @floatFromInt(was); + }; + } + // And the registers that hold a cell's address: a pin, where a link lands. + const is = (now.moment().regs(rec.tid) catch null) orelse @import("ztrace").Regs{}; + const was_regs = (now.before().regs(rec.tid) catch null) orelse is; + const ink = context.ink(context.regionOf(moment, v.addr)); + for (&at_cell, 0..) |*names, k| { + const addr = v.addr + k * elem; + const cx = left + (@as(f32, @floatFromInt(k)) + 0.5) * cell[0]; + ties.anchor(u, .{ .node_pin = addr }, .{ .x = cx - 1, .y = top + cell[1], .w = 2, .h = label + 10 }); + const indices = names.items.len; + var shows: f32 = 1; + for (theme.metric.all_registers[0..16]) |name| { + const i = context.index(name).?; + const before = was_regs.named(name) == addr; + const after = is.named(name) == addr; + if (!before and !after) continue; + const s = ties.pinShows(now, i, .node); + const this = if (before and after) 1 else if (after) s.new else s.old; + if (this < 0.5) continue; + names.append(f.scratch, name) catch {}; + if (indices == 0) shows = @min(shows, this); + } + if (names.items.len == 0) continue; + var x = cx; + if (slide[k]) |from| x = std.math.lerp(left + (from + 0.5) * cell[0], x, cursors.standard(now.moving(.idea, 0, time.move))); + // An index lives on the stack: its name in stack's ink; a register's primary. + var inks: [8]u24 = @splat(t.primary); + for (inks[0..@min(indices, inks.len)]) |*i_ink| i_ink.* = theme.color.region.stack; + u.faded(shows * ties.rise(rising, k, count).element).pinUnderInked(x, top + cell[1], names.items, inks[0..@min(names.items.len, inks.len)], if (names.items.len > indices) ink else t.primary, label); + } + } }; @@ -203,7 +242,8 @@ fn number(moment: Recording.Moment, addr: u64, bytes: u64, signed: bool) ?i64 { return @as(i64, @bitCast(raw << shift)) >> shift; } -test "a swap of neighbours is 2.1 seconds" { - try std.testing.expectApproxEqAbs(@as(f32, 2.1), Array.swap.total, 1e-3); +test "a swap of neighbours is 2.9 seconds, its bytes before its flights" { + try std.testing.expectApproxEqAbs(@as(f32, 2.9), Array.swap.total, 1e-3); + try std.testing.expect(Array.swap.at[2] - fl.near - fl.lift > Array.swap.at[1]); try std.testing.expect(flightTime(168) == fl.near and flightTime(336) == fl.mid and flightTime(900) == fl.far); } |
