summaryrefslogtreecommitdiff
path: root/anim/src/cursor.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-11 06:49:10 -0300
committerGabriel Schneider <[email protected]>2026-11-11 06:50:11 -0300
commit378379807fb4cd751e90808c8363caddb365bcd8 (patch)
treef84c7d0e7cbd42a9b9c93e791ab2b5376499d23d /anim/src/cursor.zig
parent5922ee911b9a6604f60dc83be36ba9e6c9abac98 (diff)
downloadcomputeranim-378379807fb4cd751e90808c8363caddb365bcd8.tar.gz
computeranim-378379807fb4cd751e90808c8363caddb365bcd8.zip
canim: nothing changes in one frame; the map's space is used; the heap scene at its storyboard's length
The motion check counts a third of the one-frame changes it did: the minimap's changes fade, and a register's value, a flag, a role, a pin's names, a tag's note, a backtrace row, a call tree's node and a dump row crossfade where they changed at once. What still fires is named in the README; an encoder's keyframe and the gallery's cuts are exempt by name. No caption stands over twelve seconds or under its reading time. The heap scene is 78 s: what the storyboard does not narrate runs, and each free's line cascades onto its call row (line stepping stops at a breakpoint for that). On the map, leftover space holds the stack continued, dumps round what the registers and the stack point at, open loupes and the key: between 1% and 13% of a map is page, where it was 14% to 42%. 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.zig95
1 files changed, 68 insertions, 27 deletions
diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig
index bbc3cf1..2811488 100644
--- a/anim/src/cursor.zig
+++ b/anim/src/cursor.zig
@@ -126,10 +126,11 @@ pub const Cursor = struct {
sprint_veil: anim.Value,
/// Steps taken.
count: anim.Value,
- /// The same values a little behind (`time.minimap_lag`): what the
- /// minimap draws from, secondary action that never starts on a primary
- /// onset's frame.
- lag: Lagged,
+ /// The same values a little behind (`time.minimap_lag`, then a frame
+ /// later each, `time.minimap_fade` of them): what the minimap draws
+ /// from, secondary action that never starts on a primary onset's frame
+ /// and fades over those frames.
+ lags: [time.minimap_fade]Lagged,
/// The levels the scene shows: set before the first step.
levels: Levels = .{},
/// The scene's whole way, for the head's progress line and counter (`journey`).
@@ -152,21 +153,21 @@ pub const Cursor = struct {
.veil = s.value(0),
.sprint_veil = s.value(0),
.count = s.value(0),
- .lag = undefined,
+ .lags = undefined,
.first = start,
.last = start,
};
// shortcut: an f32 holds whole moments up to 16 million; a longer recording needs two values a stop.
for (&c.stops) |*stop| stop.* = s.value(here);
for (&c.gaits) |*gait| gait.* = s.value(0);
- inline for (@typeInfo(Lagged).@"struct".field_names) |name| {
+ for (&c.lags) |*lag| inline for (@typeInfo(Lagged).@"struct".field_names) |name| {
const from = @field(c, name);
if (@TypeOf(from) == anim.Value) {
- @field(c.lag, name) = s.value(s.get(from));
- } else for (&@field(c.lag, name), from) |*to, one| {
+ @field(lag, name) = s.value(s.get(from));
+ } else for (&@field(lag, name), from) |*to, one| {
to.* = s.value(s.get(one));
}
- }
+ };
return c;
}
@@ -184,22 +185,44 @@ pub const Cursor = struct {
};
/// Plays `plays(values)` on the cursor's values from here, and on their
- /// lagging mirror `time.minimap_lag` later; the cursor ends where the first left it.
+ /// lagging mirrors `time.minimap_lag` later and a frame apart; the cursor ends where the first left it.
fn both(c: Cursor, s: *anim.Frame, plays: anytype) void {
const start = s.cursor;
- s.cursor = start + time.minimap_lag;
- plays.run(s, lagged(c));
+ for (0..c.lags.len) |k| {
+ s.cursor = start + time.minimap_lag + @as(f32, @floatFromInt(k)) / 60.0;
+ plays.run(s, lagged(c, k));
+ }
s.cursor = start;
plays.run(s, c);
}
- /// `c` with its lagging values in place of its own.
- fn lagged(c: Cursor) Cursor {
+ /// `c` with its `k`th lagging values in place of its own.
+ fn lagged(c: Cursor, k: usize) Cursor {
var out = c;
- inline for (@typeInfo(Lagged).@"struct".field_names) |name| @field(out, name) = @field(c.lag, name);
+ inline for (@typeInfo(Lagged).@"struct".field_names) |name| @field(out, name) = @field(c.lags[k], name);
return out;
}
+ /// `values` (a frame's every value, a copy) with the cursor's own as its
+ /// `k`th lagging mirror has them: what the minimap's `k`th drawing reads.
+ /// Returns whether they differ from the mirror before's (a drawing to make, not one to reuse).
+ pub fn lagInto(c: Cursor, values: []f32, k: usize) bool {
+ var differs = k == 0;
+ inline for (@typeInfo(Lagged).@"struct".field_names) |name| {
+ const own = @field(c, name);
+ const mirror = @field(c.lags[k], name);
+ const before = @field(c.lags[k -| 1], name);
+ if (@TypeOf(own) == anim.Value) {
+ values[@backingInt(own)] = values[@backingInt(mirror)];
+ differs = differs or values[@backingInt(mirror)] != values[@backingInt(before)];
+ } else for (own, mirror, before) |o, mv, b| {
+ values[@backingInt(o)] = values[@backingInt(mv)];
+ differs = differs or values[@backingInt(mv)] != values[@backingInt(b)];
+ }
+ }
+ return differs;
+ }
+
/// Where the timeline has taken the cursor so far: for scene code that
/// finds the next place from the last.
pub fn moment(c: Cursor, s: *const anim.Frame) u64 {
@@ -447,9 +470,8 @@ pub const Cursor = struct {
c.both(s, Jump{ .to = to });
}
- /// For a component, while it draws (on the minimap, `time.minimap_lag` behind).
- pub fn now(c_: Cursor, placed: anim.Placed) Now {
- const c = if (ui.strokes) lagged(c_) else c_;
+ /// For a component, while it draws (on the minimap the values are a lagging mirror's: `lagInto`).
+ pub fn now(c: Cursor, placed: anim.Placed) Now {
const rec = c.rec;
var n: Now = .{
.rec = rec,
@@ -577,12 +599,13 @@ pub const Now = struct {
/// How far (0 to 1, to be eased) a thing has got that moves as `level`
/// strikes: it sets off `lead` seconds before the strike and takes
/// `seconds`. At a run it sets off with its level and takes
- /// `time.run_ease`; at a sprint, and at rest, it is there.
+ /// `time.run_ease`; at a sprint it takes the step (4 f: never one
+ /// frame); at rest it is there.
pub fn moving(n: Now, level: Level, lead: f32, seconds: f32) f32 {
return switch (n.plan.gait) {
.walk => std.math.clamp((n.since(level, 0) + lead) / seconds, 0, 1),
.run => std.math.clamp(n.since(level, 0) / time.run_ease, 0, 1),
- .sprint => 1,
+ .sprint => if (n.resting()) 1 else std.math.clamp(n.time / @max(n.plan.total, 1.0 / 60.0), 0, 1),
};
}
@@ -597,6 +620,17 @@ pub const Now = struct {
return if (n.fired == in) n.fire() else 0;
}
+ /// 0 to 1 over the 12 f before the advance (from the step's start where
+ /// that is sooner, over the step at a sprint): how far a label that
+ /// changes in place with the step (a frame's name, a tag's note) has
+ /// crossfaded to the new one. Never in a frame.
+ pub fn renaming(n: Now) f32 {
+ if (n.resting()) return 1;
+ const span = @min(time.quick, n.plan.advance);
+ if (span <= 0) return std.math.clamp(n.time / @max(n.plan.total, 1.0 / 60.0), 0, 1);
+ return std.math.clamp((n.time - (n.plan.advance - span)) / span, 0, 1);
+ }
+
/// 0 to 1 (to be eased) through the mark's move to the next line: the
/// step's follow-through, and the next step's anticipation.
pub fn advancing(n: Now) f32 {
@@ -687,7 +721,8 @@ pub const Now = struct {
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.
- return .{ .level = 1 - std.math.clamp((n.time - n.plan.advance) / s.out, 0, 1) };
+ // Within the step: a short one (a run's) is not cut off mid-fade by the next.
+ return .{ .level = 1 - std.math.clamp((n.time - n.plan.advance) / @max(@min(s.out, n.plan.total - n.plan.advance), 1.0 / 60.0), 0, 1) };
}
/// The mark of a thing last changed `age` steps ago (`older`: not
@@ -701,10 +736,15 @@ pub const Now = struct {
if (age != 0) return n.left(age);
const was = n.left(older);
switch (n.plan.gait) {
- // Faster than a strike can be seen: embers only.
- .sprint => return .ember,
- // A run strikes nothing: its values change in place.
- .run => return .none,
+ // Faster than a strike can be seen: embers only, coming in over the step.
+ .sprint => return .{ .level = if (n.resting()) 1 else std.math.clamp(n.time / @max(n.plan.total, 1.0 / 60.0), 0, 1) },
+ // A run strikes nothing: its values change in place, and what
+ // marked them before goes with the run's ease, not in a frame.
+ .run => {
+ var gone = was;
+ gone.level *= 1 - (if (n.resting()) 1 else std.math.clamp(n.time / time.run_ease, 0, 1));
+ return gone;
+ },
.walk => {},
}
if (n.resting()) return .ember;
@@ -841,9 +881,10 @@ test "a write is armed, strikes, holds, cools with the advance, and leaves after
// 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);
- // Running: nothing struck. Sprinting: an ember, at once.
+ // Running: nothing struck, and the ember before goes over the run's ease. Sprinting: an ember, coming in over the step.
try expectEqual(ui.Heat.none, instant(0.2, Plan.running(0.3)).heat(0, null, 0.2));
- try expectEqual(ui.Heat.ember, instant(0.01, Plan.sprinting(0.05)).heat(0, null, 0.01));
+ try std.testing.expectApproxEqAbs(@as(f32, 0.5), instant(time.run_ease / 2.0, Plan.running(0.3)).heat(0, 1, 0).level, 1e-4);
+ try std.testing.expectApproxEqAbs(@as(f32, 0.2), instant(0.01, Plan.sprinting(0.05)).heat(0, null, 0.01).level, 1e-4);
}
test "what a step read is framed while its line is gold" {