summaryrefslogtreecommitdiff
path: root/anim/src/cursor.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 16:05:20 -0300
committerGabriel Schneider <[email protected]>2026-11-10 16:43:58 -0300
commit165bb6c1344b98de7bef1d3c2b72147b4a40797a (patch)
tree0e70e6222700063f604f78673f6ab3a5bfb9242d /anim/src/cursor.zig
parent66a2a7cf733f6abc1f79561c52d901ce67019fb1 (diff)
downloadcomputeranim-165bb6c1344b98de7bef1d3c2b72147b4a40797a.tar.gz
computeranim-165bb6c1344b98de7bef1d3c2b72147b4a40797a.zip
canim: the renderer speaks the design language
The blocks, their states and the tokens carry the catalogue's names: atoms in ui, chain/reg/slot in rows, insn with its line column, jump lane and annotations (read, write, taken or not, a call with its arguments, a return, a syscall) in disasm, bytes and hexdump with field paper and the reading column, the three splits and relayout in stage, the ties (thread, link and pin, projection, echo). A lens is a band over the whole context, its drawing left and its bytes right. Frames' spans on the stack, each instruction's line and a callee's parameter count come from the tracer. A gallery scene draws every block; the test compares six of its pages with pictures kept in test/gallery, drawn from a recording kept there too. The scenes are ported; the motion checks report no pop and no metronome in any of them. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'anim/src/cursor.zig')
-rw-r--r--anim/src/cursor.zig40
1 files changed, 32 insertions, 8 deletions
diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig
index 2ca8a97..2f7be1a 100644
--- a/anim/src/cursor.zig
+++ b/anim/src/cursor.zig
@@ -19,6 +19,9 @@ const ui = @import("ui.zig");
const theme = ui.theme;
const time = theme.time;
+/// The writes of one step strike this far apart, in the order they happened.
+pub const write_apart = 6.0 / 60.0;
+
/// A mark lasts this many steps, then one more to leave in.
const history = time.strike.ember_steps + 2;
@@ -214,10 +217,16 @@ pub const Cursor = struct {
};
var plan: Plan = .{ .travel = c.travel(from, to) };
var slot: f32 = 0;
- for (levels, &plan.at) |is, *strikes| {
- if (is) slot += time.cascade;
+ for (levels, &plan.at, 0..) |is, *strikes, level| {
+ // A drawing made of the bytes reacts when the projection from
+ // them arrives: its bracket and its line after their strike, and
+ // for a write its own arm.
+ const projected = level == 2 and is and levels[1] and c.levels.idea == .data;
+ if (projected) slot += time.project.bracket + time.project.draw + @as(f32, if (wrote > 0) time.strike.arm else 0) else if (is) slot += time.cascade;
strikes.* = @max(slot, time.cascade);
}
+ // The writes of one step strike 6 f apart: the last is later.
+ if (levels[1]) slot += @min(@max(wrote - 1, 0), 3) * write_apart;
if (slot > 0) {
// What there is to read: a level's worth each. (In the whole
// context a line changes more registers than anyone reads;
@@ -489,7 +498,7 @@ pub const Now = struct {
return n.registerAgeFrom(reg, 0);
}
- fn registerAgeFrom(n: Now, reg: usize, skip: usize) ?u64 {
+ pub fn registerAgeFrom(n: Now, reg: usize, skip: usize) ?u64 {
for (skip..history - 1) |age| {
if (n.rec.registersChanged(n.stops[age + 1], n.stops[age]) >> @intCast(reg) & 1 != 0) return age;
}
@@ -517,8 +526,9 @@ pub const Now = struct {
const a = age orelse return .none;
if (a == 0 or a > s.ember_steps) return .none;
if (a < s.ember_steps) return .ember;
- // Linear: a fade. Gone by the time this step is over.
- return .{ .level = 1 - std.math.clamp(n.time / s.out, 0, 1) };
+ // Linear: a fade, as the mark leaves: secondary action does not
+ // start on the fire's frame, where the step's primary one does.
+ return .{ .level = 1 - std.math.clamp((n.time - n.plan.advance) / s.out, 0, 1) };
}
/// The mark of a thing last changed `age` steps ago (`older`: not
@@ -553,9 +563,23 @@ pub const Now = struct {
}
/// The mark of the bytes `addr .. addr + size`, which strike with
- /// `level`, `delay` seconds after its first.
+ /// `level`, `delay` seconds after its first, and 6 f after the write of
+ /// this step before theirs.
pub fn written(n: Now, addr: u64, size: u64, level: Level, delay: f32) ui.Heat {
- return n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.since(level, delay));
+ return n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.since(level, delay + n.writeDelay(addr, size)));
+ }
+
+ /// How far after this step's first write the one of `addr .. addr + size` is.
+ pub fn writeDelay(n: Now, addr: u64, size: u64) f32 {
+ var order: f32 = 0;
+ var last: ?u64 = null;
+ for (n.rec.written(n.stops[1], n.stops[0])) |span| {
+ if (span.addr < addr + size and span.addr + span.len > addr) return @min(order, 3) * write_apart;
+ // Bytes of one write (one store, in pieces) are one strike.
+ if (last == null or span.addr != last.?) order += 1;
+ last = span.addr + span.len;
+ }
+ return 0;
}
/// The mark of a register: the CPU's level.
@@ -611,7 +635,7 @@ test "a write is armed, strikes, holds, cools with the advance, and leaves after
try expectEqual(ui.Heat.ember, rest.heat(2, 2, 0));
try expectEqual(ui.Heat.none, rest.heat(4, 4, 0));
try expectEqual(ui.Heat.none, rest.heat(null, null, 0));
- try std.testing.expectApproxEqAbs(@as(f32, 0.5), instant(s.out / 2.0, plan).heat(s.ember_steps, s.ember_steps, 0).level, 1e-3);
+ try std.testing.expectApproxEqAbs(@as(f32, 0.5), instant(0.90 + s.out / 2.0, plan).heat(s.ember_steps, s.ember_steps, 0).level, 1e-3);
// Struck again over its ember: armed with the ember still under it.
h = instant(0.20, plan).heat(0, 1, -0.10);
try expect(h.level == 1 and h.arm == 1 and h.solid == 0);