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.zig52
1 files changed, 46 insertions, 6 deletions
diff --git a/anim/src/nodes.zig b/anim/src/nodes.zig
index 1f8acec..d5c7613 100644
--- a/anim/src/nodes.zig
+++ b/anim/src/nodes.zig
@@ -223,8 +223,8 @@ pub const Nodes = struct {
}
/// Where variable `name`'s tag is: it travels from node to node in the
- /// drawing's slot, after its word has been struck (`glide`, 30 f to the
- /// next node, 36 f further); it does not jump.
+ /// drawing's slot, as the idea strikes, after its word has been struck
+ /// (`glide`, `time.pin`: 30 f to the next node, 36 f further); it does not jump.
fn tagOf(g: *const Nodes, u: ui.Ui, now: cursors.Now, name: []const u8) Tag {
const rec = g.cursor.rec;
const at = struct {
@@ -237,7 +237,7 @@ pub const Nodes = struct {
const to = at.value(rec, u.f.scratch, now.moment(), name);
const from = at.value(rec, u.f.scratch, now.before(), name);
if (from == to or now.resting()) return .{ .from = from, .to = to, .p = 1 };
- const far: f32 = if (from != 0 and to != 0 and @abs(@as(i64, @bitCast(to -% from))) > 0x30) time.flight.mid else time.flight.near;
+ const far: f32 = if (from != 0 and to != 0 and @abs(@as(i64, @bitCast(to -% from))) > 0x30) time.pin.nodes else time.pin.node;
const p = switch (now.plan.gait) {
.walk => std.math.clamp(now.since(.idea, 0) / far, 0, 1),
.run => now.moving(.idea, 0, time.run_ease),
@@ -269,10 +269,10 @@ pub const Nodes = struct {
const x = std.math.lerp(a.?.x + a.?.w / 2, b.?.x + b.?.w / 2, cursors.glide(tag.p));
u.pinUnderInked(x, a.?.y + a.?.h, names, inks, heap, label);
} else if (b) |r| {
- const p = std.math.clamp(tag.p / (time.quick / time.flight.near), 0, 1);
+ const p = std.math.clamp(tag.p / (time.pin.in / time.pin.node), 0, 1);
u.faded(p).pinUnderInked(r.x + r.w / 2, r.y + r.h + (1 - p) * theme.time.caption_rise, names, inks, heap, label);
} else if (a) |r| {
- u.faded(1 - std.math.clamp(tag.p / (time.quick / time.flight.near), 0, 1)).pinUnderInked(r.x + r.w / 2, r.y + r.h, names, inks, heap, label);
+ u.faded(1 - std.math.clamp(tag.p / (time.pin.out / time.pin.node), 0, 1)).pinUnderInked(r.x + r.w / 2, r.y + r.h, names, inks, heap, label);
}
}
}
@@ -312,7 +312,30 @@ pub const Nodes = struct {
inks.append(u.f.scratch, t.primary) catch break;
shows = @max(shows, this);
};
- // Names keep their side: one left alone where it was on the right stays there.
+ // Names keep their side: the first to come is on the left, the next
+ // on the right, and a name that lands where another is stays on the
+ // right it travelled on; one left alone where it was on the right stays there.
+ const came = u.f.scratch.alloc(u64, out.items.len) catch return .{ .names = out.items, .inks = inks.items, .shows = shows };
+ for (out.items, came) |name, *at| at.* = g.arrival(u, now, name, addr);
+ for (1..@max(out.items.len, 1)) |i| {
+ var k = i;
+ while (k > 0 and came[k - 1] > came[k]) : (k -= 1) {
+ std.mem.swap(u64, &came[k - 1], &came[k]);
+ std.mem.swap([]const u8, &out.items[k - 1], &out.items[k]);
+ std.mem.swap(u24, &inks.items[k - 1], &inks.items[k]);
+ }
+ }
+ // 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| {
+ if (context.index(name) != null) continue;
+ var k = j;
+ while (k > 1) : (k -= 1) {
+ std.mem.swap([]const u8, &out.items[k - 1], &out.items[k]);
+ std.mem.swap(u24, &inks.items[k - 1], &inks.items[k]);
+ }
+ break;
+ };
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])) {
@@ -323,6 +346,23 @@ pub const Nodes = struct {
return .{ .names = out.items, .inks = inks.items, .shows = shows };
}
+ /// When `name` came to point at `addr`: the moment its value last
+ /// 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 {
+ 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];
+ 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];
+ // 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;
+ }
+
/// The first name on `addr`'s pin before this step, if another name was beside it.
fn firstBefore(g: *const Nodes, u: ui.Ui, now: cursors.Now, addr: u64, was: zt.Regs) ?[]const u8 {
const names = g.namesBefore(u, now, addr, was);