summaryrefslogtreecommitdiff
path: root/anim/src/cursor.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/cursor.zig')
-rw-r--r--anim/src/cursor.zig21
1 files changed, 13 insertions, 8 deletions
diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig
index e9aab67..b09db8d 100644
--- a/anim/src/cursor.zig
+++ b/anim/src/cursor.zig
@@ -866,6 +866,18 @@ pub fn jumps(rec: *const Recording, from: u64, to: u64) bool {
return a.src != b.src or rec.depths[from] != rec.depths[to] or rows > time.current_jump_rows;
}
+/// Whether the chain from `value` reads otherwise at `is` than at `was` (the
+/// values and texts of its hops).
+pub fn chainMoved(was: Recording.Moment, is: Recording.Moment, value: u64) bool {
+ var bufs: [2][6]zt.telescope.Link = undefined;
+ var texts: [2][48]u8 = undefined;
+ const a = zt.telescope.chase(was, value, &bufs[0], &texts[0]) catch return false;
+ const b = zt.telescope.chase(is, value, &bufs[1], &texts[1]) catch return false;
+ if (a.len != b.len) return true;
+ for (a, b) |x, y| if (x.value != y.value or !std.mem.eql(u8, x.text, y.text)) return true;
+ return false;
+}
+
/// The cursor at one instant.
pub const Now = struct {
rec: *const Recording,
@@ -1188,14 +1200,7 @@ pub const Now = struct {
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 (!chainMoved(n.before(), n.moment(), value)) 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 };
}