summaryrefslogtreecommitdiff
path: root/anim/src/nodes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/nodes.zig')
-rw-r--r--anim/src/nodes.zig74
1 files changed, 68 insertions, 6 deletions
diff --git a/anim/src/nodes.zig b/anim/src/nodes.zig
index 7c842d3..5218d7f 100644
--- a/anim/src/nodes.zig
+++ b/anim/src/nodes.zig
@@ -73,10 +73,22 @@ pub const Nodes = struct {
if (lo < hi) {
@import("map.zig").measure(.view, (hi - lo) / 16);
const count = theme.layout.rowsIn(g.stage.box(placed, .view).h);
- const first = hexdump.window(now, lo, hi, count);
+ // Its window round the rows the step touches: from the last step's, scrolled
+ // (whole rows, 24 f, as the step begins), never a jump.
+ const first_new = hexdump.window(now, lo, hi, count);
+ const first_old = hexdump.windowAt(rec, now.stops[2], now.stops[1], lo, hi, count);
+ const scroll = if (now.resting() or first_old == first_new) 1 else cursors.glide(std.math.clamp(now.time / time.move, 0, 1));
+ const first = if (scroll >= 0.5) first_new else first_old;
const shown = @min(count, (hi - first) / 16);
const v = hexdump.panel(f, placed, g.stage, u.print("the heap, {x} to {x}", .{ first, first + 16 * shown - 1 }), &legend);
- if (v.rows > 0) hexdump.draw(v.u, now, 0, m.tag + m.pad, first, @min(shown, v.rows), .{ .things = things });
+ if (v.rows > 0) {
+ const top = @min(first_old, first_new);
+ const rows_apart: f32 = @floatFromInt((@max(first_old, first_new) - top) / 16);
+ const at = std.math.lerp(@as(f32, @floatFromInt((first_old - top) / 16)), @as(f32, @floatFromInt((first_new - top) / 16)), scroll);
+ v.u.clip(.{ .x = 0, .y = m.tag, .w = g.stage.box(placed, .view).w, .h = @as(f32, @floatFromInt(@min(shown, v.rows))) * m.row + 2 * m.pad });
+ hexdump.draw(v.u, now, 0, m.tag + m.pad - at * m.row, top, @min(@min(shown, v.rows) + @as(usize, @intFromFloat(rows_apart)), (hi - top) / 16), .{ .things = things });
+ v.u.unclip();
+ }
if (v.rows > 0) @import("map.zig").window(.view, .{ first, first + 16 * (@min(shown, v.rows) -| 1) }, .{ first, first + 16 * (@min(shown, v.rows) -| 1) }, 1);
v.veil(now);
u.clip(.{ .x = 0, .y = 0, .w = box.w, .h = box.h });
@@ -335,6 +347,27 @@ pub const Nodes = struct {
std.mem.swap(u24, &inks.items[k - 1], &inks.items[k]);
}
}
+ // Two names whose order the step turns (one reassigned to the same node): the names
+ // fade out in the old order and in the new one over the step's first 24 f, never swapped in a frame.
+ if (out.items.len == 2 and !now.resting() and now.stops[1] != now.stops[2]) both: {
+ // Both on the pin before the step too.
+ const then = g.namesAt(u, now.stops[1], addr);
+ for (out.items) |name| {
+ if (for (then) |o| {
+ if (std.mem.eql(u8, o, name)) break false;
+ } else true) break :both;
+ }
+ const a = g.arrivalAt(u, now.stops[1], now.stops[2], out.items[0], addr);
+ const b = g.arrivalAt(u, now.stops[1], now.stops[2], out.items[1], addr);
+ if (a > b) {
+ const p = std.math.clamp(now.time / (2 * time.quick), 0, 1);
+ text = @min(text, @abs(2 * p - 1));
+ if (p < 0.5) {
+ std.mem.swap([]const u8, &out.items[0], &out.items[1]);
+ std.mem.swap(u24, &inks.items[0], &inks.items[1]);
+ }
+ }
+ }
// Both sides taken: a variable the scene names (what the narration
// follows) takes the right from a register, which is counted.
if (out.items.len > 2 and context.index(out.items[1]) != null) for (out.items[2..], 2..) |name, j| {
@@ -348,7 +381,13 @@ pub const Nodes = struct {
};
if (out.items.len == 1) {
const first_before = g.firstBefore(u, now, addr, was);
- if (first_before != null and !std.mem.eql(u8, first_before.?, out.items[0])) {
+ // Kept on the right in the step before (the other had just left): it goes over
+ // to the left at the start of this one, fading out and in (24 f), never in a frame.
+ const older = g.namesAt(u, now.stops[2], addr);
+ const was_right = now.stops[2] != now.stops[1] and older.len >= 2 and !std.mem.eql(u8, older[0], out.items[0]);
+ const over = if (now.resting()) 1 else std.math.clamp(now.time / (2 * time.quick), 0, 1);
+ if (was_right and first_before == null) text = @min(text, @abs(2 * over - 1));
+ if ((first_before != null and !std.mem.eql(u8, first_before.?, out.items[0])) or (was_right and first_before == null and over < 0.5)) {
out.insert(u.f.scratch, 0, "") catch {};
inks.insert(u.f.scratch, 0, t.primary) catch {};
}
@@ -360,14 +399,19 @@ pub const Nodes = struct {
/// became it (a variable's, its last assignment), as of the stop shown
/// (or the one before, for a name that is leaving).
fn arrival(g: *const Nodes, u: ui.Ui, now: cursors.Now, name: []const u8, addr: u64) u64 {
+ return g.arrivalAt(u, now.stops[0], now.stops[1], name, addr);
+ }
+
+ /// The same, as of stop `here` (the one before it `before`).
+ fn arrivalAt(g: *const Nodes, u: ui.Ui, here: u64, before: u64, name: []const u8, addr: u64) u64 {
const rec = g.cursor.rec;
if (context.index(name)) |_| {
- var i = if (rec.registers[now.stops[0]].named(name) == addr) now.stops[0] else now.stops[1];
+ var i = if (rec.registers[here].named(name) == addr) here else before;
while (i > 0 and rec.registers[i - 1].named(name) == addr) i -= 1;
return i;
}
- const v = rec.variable(u.f.scratch, now.moment(), name) orelse return now.stops[0];
- var i = if ((Recording.word(now.moment(), v.addr, 8) catch null) == addr) now.stops[0] else now.stops[1];
+ const v = rec.variable(u.f.scratch, rec.moment(here), name) orelse return here;
+ var i = if ((Recording.word(rec.moment(here), v.addr, 8) catch null) == addr) here else before;
// Its assignment: a store, of a new value or of the one its slot held.
while (i > 0 and !Recording.touches(rec.written(i - 1, i), v.addr, 8) and !Recording.touches(rec.storedSame(i - 1, i), v.addr, 8)) i -= 1;
return i;
@@ -395,6 +439,24 @@ pub const Nodes = struct {
return out.items;
}
+ /// The names on `addr`'s pin at moment `at`.
+ fn namesAt(g: *const Nodes, u: ui.Ui, at: u64, addr: u64) []const []const u8 {
+ const rec = g.cursor.rec;
+ const mo = rec.moment(at);
+ var out: std.ArrayList([]const u8) = .empty;
+ for (g.track) |name| {
+ const v = rec.variable(u.f.scratch, mo, name) orelse continue;
+ if (!rec.assigned(v, mo.index)) continue;
+ if ((Recording.word(mo, v.addr, 8) catch null) != addr) continue;
+ out.append(u.f.scratch, name) catch break;
+ }
+ const regs = (mo.regs(rec.tid) catch null) orelse return out.items;
+ if (!g.quiet) for (theme.metric.all_registers[0..16]) |name| if (regs.named(name) == addr) {
+ out.append(u.f.scratch, name) catch break;
+ };
+ return out.items;
+ }
+
/// The ink of where variable `name` lives: stack for a local, data for a global.
fn home(g: *const Nodes, u: ui.Ui, now: cursors.Now, name: []const u8) u24 {
const v = g.cursor.rec.variable(u.f.scratch, now.moment(), name) orelse return t.primary;