summaryrefslogtreecommitdiff
path: root/anim/src/cursor.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-11 09:41:45 -0300
committerGabriel Schneider <[email protected]>2026-11-11 10:14:30 -0300
commit390872b7bb9cdcf3e8095442af88af0dfcb40602 (patch)
treeab767cf46dfca036e61e0e19bb5e1c4772cb1d4d /anim/src/cursor.zig
parent378379807fb4cd751e90808c8363caddb365bcd8 (diff)
downloadcomputeranim-390872b7bb9cdcf3e8095442af88af0dfcb40602.tar.gz
computeranim-390872b7bb9cdcf3e8095442af88af0dfcb40602.zip
canim: what the verification review found, fixed
A register's chain reads memory as its panel shows it, and follows again only after the bytes land: rsi no longer shows what read returns before the kernel writes it. Bytes keep their old value through the arm and change at their own strike, in every dump, stack word and loupe. The dive lands once. Captions lead what they name: the longest still in the syscalls scene is 2.8 s where it was 13. Pins hold through a sprint; a row of a view carries the pin of the register that points at it; a left child's badge sits on its left shoulder; a log scrolls with the row that arrives. The zoom scene's camera holds the disassembly's rows and the stack in one view. Six programs, the title says now. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/src/cursor.zig')
-rw-r--r--anim/src/cursor.zig153
1 files changed, 117 insertions, 36 deletions
diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig
index 2811488..f0f90ff 100644
--- a/anim/src/cursor.zig
+++ b/anim/src/cursor.zig
@@ -84,6 +84,10 @@ pub const Plan = struct {
/// The line fires (not on a step that goes on from the last one's
/// mark: a crossing stepped over, from its call row).
fires: bool = true,
+ /// Seconds of the step before's cool still to run at this one's start
+ /// (a step that went on from it without its rest: a crossing from its
+ /// call row): what it struck goes on cooling, never cut in a frame.
+ cooling: f32 = 0,
/// Once the pattern is known: the levels a stagger apart from the
/// first frame, the mark after them, in `seconds`.
@@ -91,8 +95,9 @@ pub const Plan = struct {
return .{ .gait = .run, .at = .{ 0, time.stagger, 2 * time.stagger }, .advance = time.run_ease, .travel = time.run_ease, .total = seconds };
}
+ /// The mark, seen only where a phrase ends, moves over the step there: never in a frame.
pub fn sprinting(seconds: f32) Plan {
- return .{ .gait = .sprint, .at = @splat(0), .advance = 0, .travel = 0, .total = seconds };
+ return .{ .gait = .sprint, .at = @splat(0), .advance = 0, .travel = seconds, .total = seconds };
}
};
@@ -115,7 +120,7 @@ pub const Cursor = struct {
/// 0 to 1 through the step it is taking; 1 at rest.
phase: anim.Value,
/// The step's `Plan`, a value a field.
- plan: [9]anim.Value,
+ plan: [10]anim.Value,
/// The moment the current mark was on, and the one it is on (or going to).
marks: [2]anim.Value,
/// 1 while steps are hurried (the head counts them), and while what
@@ -147,7 +152,7 @@ pub const Cursor = struct {
.stops = undefined,
.gaits = undefined,
.phase = s.value(1),
- .plan = .{ s.value(0), s.value(plan.at[0]), s.value(plan.at[1]), s.value(plan.at[2]), s.value(plan.advance), s.value(plan.travel), s.value(plan.total), s.value(0), s.value(1) },
+ .plan = .{ s.value(0), s.value(plan.at[0]), s.value(plan.at[1]), s.value(plan.at[2]), s.value(plan.advance), s.value(plan.travel), s.value(plan.total), s.value(0), s.value(1), s.value(0) },
.marks = .{ s.value(here), s.value(here) },
.hurried = s.value(0),
.veil = s.value(0),
@@ -176,7 +181,7 @@ pub const Cursor = struct {
stops: [history]anim.Value,
gaits: [history]anim.Value,
phase: anim.Value,
- plan: [9]anim.Value,
+ plan: [10]anim.Value,
marks: [2]anim.Value,
hurried: anim.Value,
veil: anim.Value,
@@ -253,24 +258,24 @@ pub const Cursor = struct {
const Step = struct {
stops: [history]f32,
gaits: [history]f32,
- plan: [9]f32,
+ plan: [10]f32,
marks: [2]f32,
count: f32,
seconds: f32,
fn run(st: @This(), sf: *anim.Frame, v: Cursor) void {
- var set: [2 * history + 13]anim.Animation = undefined;
+ var set: [2 * history + 14]anim.Animation = undefined;
for (v.stops, st.stops, 0..) |value, is, i| set[i] = value.to(is);
- for (v.gaits, st.gaits, 0..) |value, is, i| set[history + 13 + i] = value.to(is);
+ for (v.gaits, st.gaits, 0..) |value, is, i| set[history + 14 + i] = value.to(is);
for (v.plan, st.plan, history..) |value, is, n| set[n] = value.to(is);
- set[history + 9] = v.marks[0].to(st.marks[0]);
- set[history + 10] = v.marks[1].to(st.marks[1]);
- set[history + 11] = v.phase.to(0);
- set[history + 12] = v.count.to(st.count);
+ set[history + 10] = v.marks[0].to(st.marks[0]);
+ set[history + 11] = v.marks[1].to(st.marks[1]);
+ set[history + 12] = v.phase.to(0);
+ set[history + 13] = v.count.to(st.count);
sf.play(set, .{ .seconds = 0 });
sf.play(.{v.phase.to(1)}, .{ .seconds = st.seconds, .ease = anim.ease.linear });
}
};
- var st: Step = .{ .stops = undefined, .gaits = undefined, .plan = .{ @floatFromInt(@intFromEnum(plan.gait)), plan.at[0], plan.at[1], plan.at[2], plan.advance, plan.travel, plan.total, @floatFromInt(@intFromBool(plan.wave)), @floatFromInt(@intFromBool(plan.fires)) }, .marks = undefined, .count = settled(s, c.count) + 1, .seconds = seconds };
+ var st: Step = .{ .stops = undefined, .gaits = undefined, .plan = .{ @floatFromInt(@intFromEnum(plan.gait)), plan.at[0], plan.at[1], plan.at[2], plan.advance, plan.travel, plan.total, @floatFromInt(@intFromBool(plan.wave)), @floatFromInt(@intFromBool(plan.fires)), plan.cooling }, .marks = undefined, .count = settled(s, c.count) + 1, .seconds = seconds };
st.stops[0] = @floatFromInt(to);
for (1..history) |i| st.stops[i] = settled(s, c.stops[i - 1]);
st.gaits[0] = @floatFromInt(@intFromEnum(plan.gait));
@@ -329,10 +334,15 @@ pub const Cursor = struct {
const regs: f32 = @floatFromInt(@popCount(rec.registersChanged(from, to) & ~quiet));
// Memory gives up its slot when nothing it touched is drawn.
var wrote_n: usize = 0;
- for (rec.written(from, to)) |span| wrote_n += @intFromBool(rec.drawn(span, from, to));
+ var strikes_n: usize = 0;
+ for (rec.written(from, to)) |span| {
+ wrote_n += @intFromBool(rec.drawn(span, from, to));
+ strikes_n += @intFromBool(takesPlace(rec, span, from, to));
+ }
var read_n: usize = 0;
for (rec.read(from, to)) |span| read_n += @intFromBool(rec.drawn(span, from, to));
- const wrote: f32 = @floatFromInt(wrote_n);
+ // As many strikes as writes take a place (`takesPlace`): the last is 6 f a write after the first.
+ const wrote: f32 = @floatFromInt(if (wrote_n > 0) @max(strikes_n, 1) else 0);
const touched = wrote_n > 0 or read_n > 0;
const deeper = rec.depths[to] > rec.depths[from];
const back = rec.depths[to] < rec.depths[from];
@@ -485,6 +495,7 @@ pub const Cursor = struct {
.total = placed.value(c.plan[6]),
.wave = placed.value(c.plan[7]) >= 0.5,
.fires = placed.value(c.plan[8]) >= 0.5,
+ .cooling = placed.value(c.plan[9]),
},
.marks = .{ whole(rec, placed.value(c.marks[0])), whole(rec, placed.value(c.marks[1])) },
.hurried = placed.value(c.hurried),
@@ -510,6 +521,13 @@ pub const Cursor = struct {
}
};
+/// Whether a write of the step from `from` to `to` takes a place among
+/// its strikes: not on a stack frame the step has already left (a callee's
+/// words, under rsp, that no window shows: `Recording.drawn`).
+fn takesPlace(rec: *const Recording, span: Recording.Span, from: u64, to: u64) bool {
+ return rec.drawn(span, from, to) or zt.telescope.region(rec.moment(to), span.addr) catch .none != .stack;
+}
+
fn whole(rec: *const Recording, value: f32) u64 {
return @min(@as(u64, @intFromFloat(@max(value, 0))), rec.end());
}
@@ -671,7 +689,9 @@ pub const Now = struct {
n.rec.moment(n.stops[age]).read(addr, is[0..l], known_is[0..l]) catch return null;
var out: ?[2]u8 = null;
for (0..l) |i| if (known_was[i] and known_is[i] and was[i] != is[i]) {
- out = .{ if (out) |o| o[0] else @intCast(i), @intCast(i) };
+ // Its first apart: assigned in one expression, `out` would be read as it is written.
+ const first: u8 = if (out) |o| o[0] else @intCast(i);
+ out = .{ first, @intCast(i) };
};
return out;
}
@@ -718,6 +738,8 @@ pub const Now = struct {
if (a == 0 or a > s.ember_steps) return .none;
// A run changes values unmarked: it shows them settled.
if (n.gaits[a] == .run) return .none;
+ // The step before went on into this one before its cool was done: it cools on.
+ if (a == 1 and n.plan.cooling > 0 and n.gaits[1] == .walk and !n.resting() and n.time < n.plan.cooling) return cooled(1 - (n.plan.cooling - n.time) / s.cool, .nothing, 0);
if (a < s.ember_steps) return .ember;
// Linear: a fade, as the mark leaves: secondary action does not
// start on the fire's frame, where the step's primary one does.
@@ -753,17 +775,23 @@ pub const Now = struct {
if (since_strike >= -s.arm) armed.arm = std.math.clamp((since_strike + s.arm) / time.stagger, 0, 1);
return armed;
}
- const cooled = (n.time - n.plan.advance) / s.cool;
const in = std.math.clamp(since_strike / s.in, 0, 1);
+ var h = cooled((n.time - n.plan.advance) / s.cool, if (was.level >= 1) .ember else .nothing, if (was.level >= 1) 1 - in else 0);
+ h.in = in;
+ h.out = if (since_strike < s.pulse) theme.pulse(since_strike / s.pulse) else 0;
+ return h;
+ }
+
+ /// A struck thing `cooled` of the way through its cool (0 to 1): the
+ /// paper going on `glide`; the turned corner coming in over the cool's
+ /// last 6 f (and the old one, `corner_was`, going as a strike comes in over it).
+ fn cooled(p: f32, from: @FieldType(ui.Heat, "from"), corner_was: f32) ui.Heat {
+ const s = time.strike;
return .{
.level = 1,
- .solid = 1 - glide(std.math.clamp(cooled, 0, 1)),
- .in = in,
- .from = if (was.level >= 1) .ember else .nothing,
- .out = if (since_strike < s.pulse) theme.pulse(since_strike / s.pulse) else 0,
- // The turned corner: the old one goes as the paper comes in over
- // it; the new one comes in over the cool's last 6 f.
- .corner = @max(std.math.clamp((cooled - 1) * s.cool / s.corner + 1, 0, 1), if (was.level >= 1) 1 - in else 0),
+ .solid = 1 - glide(std.math.clamp(p, 0, 1)),
+ .from = from,
+ .corner = @max(std.math.clamp((p - 1) * s.cool / s.corner + 1, 0, 1), corner_was),
};
}
@@ -771,13 +799,33 @@ pub const Now = struct {
/// `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 {
+ var h = n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.sinceStrike(addr, size, level, delay));
// What the kernel fills in a crossing lands as its work does it, unpulsed.
- if (level == .memory) if (syscalls.filledAt(n, addr)) |at| {
- var h = n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.time - at);
- h.out = 0;
- return h;
+ if (level == .memory and syscalls.filledAt(n, addr) != null) h.out = 0;
+ return h;
+ }
+
+ /// Seconds since the strike of `addr .. addr + size` with `level`,
+ /// `delay` after its first and 6 f after the write of this step before
+ /// theirs; what the kernel fills in a crossing, as its work lands it.
+ fn sinceStrike(n: Now, addr: u64, size: u64, level: Level, delay: f32) f32 {
+ if (level == .memory) if (syscalls.filledAt(n, addr)) |at| return n.time - at;
+ return n.since(level, delay + n.writeDelay(addr, size));
+ }
+
+ /// Seconds since this step's write of `addr .. addr + size` struck in
+ /// memory, at a walk; null where the step did not write it, or at
+ /// another pace. Until `in / 2` after it (s+3) the old value stands,
+ /// through the arm (`shownAt`, a dump's runs, a chain's hops).
+ pub fn struckAgo(n: Now, addr: u64, size: u64) ?f32 {
+ if (!n.walking() or n.writeAge(addr, size) != 0) return null;
+ // What the kernel fills, a byte every 2 f: the value is there once its last byte is.
+ var last: ?f32 = null;
+ for (0..size) |i| if (syscalls.filledAt(n, addr + i)) |at| {
+ last = @max(last orelse at, at);
};
- return n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.since(level, delay + n.writeDelay(addr, size)));
+ if (last) |at| return n.time - at;
+ return n.sinceStrike(addr, size, .memory, 0);
}
/// `written`, struck `since` seconds ago (a loupe's own times: it strikes once it has opened).
@@ -785,11 +833,44 @@ pub const Now = struct {
return n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), struck);
}
- /// The state to draw the memory at `addr` from: `shown(.memory)`, but
- /// what the kernel fills in a crossing from when its byte lands.
- pub fn shownAt(n: Now, addr: u64) Recording.Moment {
- if (syscalls.filledAt(n, addr)) |at| return if (n.time - at >= time.strike.in / 2.0) n.moment() else n.before();
- return n.shown(.memory);
+ /// The state to draw the memory at `addr .. addr + size` from:
+ /// `shown(.memory)`, but a write of this step from its own strike
+ /// (s+3), never before its arm; what the kernel fills in a crossing
+ /// from when its byte lands.
+ pub fn shownAt(n: Now, addr: u64, size: u64) Recording.Moment {
+ return if (n.landedAt(addr, size)) n.moment() else n.before();
+ }
+
+ /// Whether memory at `addr .. addr + size` shows the step's state (`shownAt`).
+ pub fn landedAt(n: Now, addr: u64, size: u64) bool {
+ if (n.struckAgo(addr, size)) |ago| return ago >= time.strike.in / 2.0;
+ return n.landed(.memory, 0);
+ }
+
+ /// The memory a chain from `value` (a register's, struck or not) reads
+ /// as the panels show it (`shownAt`: the word it points at, from its
+ /// strike), and, where the step changes what the chain says, seconds
+ /// since its hops are followed again (`extend`): 4 f after the bytes
+ /// land, never before. Null where the chain did not change.
+ /// Before the bytes land, from their strike, the hops it shows fade out
+ /// (the third: how much they show), so that none goes in a frame.
+ pub fn following(n: Now, value: u64) struct { Recording.Moment, ?f32, f32 } {
+ const memory = n.shownAt(value, 8);
+ if (!n.walking()) return .{ memory, null, 1 };
+ const struck = n.struckAgo(value, 8) orelse n.since(.memory, 0);
+ const land = time.strike.in / 2.0;
+ // Followed again only while that shows (its hops 4 f apart, 6 f each).
+ if (struck < 0 or struck > land + 0.5) return .{ memory, null, 1 };
+ var bufs: [2][6]zt.telescope.Link = undefined;
+ var texts: [2][48]u8 = undefined;
+ const was = zt.telescope.chase(n.before(), value, &bufs[0], &texts[0]) catch return .{ memory, null, 1 };
+ const is = zt.telescope.chase(n.moment(), value, &bufs[1], &texts[1]) catch return .{ memory, null, 1 };
+ const same = was.len == is.len and for (was, is) |a, b| {
+ if (a.value != b.value or !std.mem.eql(u8, a.text, b.text)) break false;
+ } else true;
+ if (same) return .{ memory, null, 1 };
+ if (!n.landedAt(value, 8)) return .{ memory, null, 1 - std.math.clamp(struck / land, 0, 1) };
+ return .{ memory, struck - 4.0 / 60.0, 1 };
}
/// `written`, on a thing the viewer has watched only through the steps
@@ -805,9 +886,9 @@ pub const Now = struct {
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;
- // The kernel's own writes have their own times (`filledAt`).
- if (syscalls.filledAt(n, span.addr) != null) continue;
+ if (span.addr < addr +| size and span.addr + span.len > addr) return @min(order, 3) * write_apart;
+ // The kernel's own writes have their own times (`filledAt`); a frame the step has left takes no place.
+ if (syscalls.filledAt(n, span.addr) != null or !takesPlace(n.rec, span, n.stops[1], n.stops[0])) continue;
// 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;