summaryrefslogtreecommitdiff
path: root/src/host/timeline.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-16 23:35:54 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitc3b9938e9cb381bc7378fdca9073520ff1711ad6 (patch)
tree33f707ef2075bc26083a3c21d34a41b4a0e9c7ac /src/host/timeline.zig
parentb2f7c605c279b2dea0c25180730c3d2e7b4b7d45 (diff)
downloadsketchbook-c3b9938e9cb381bc7378fdca9073520ff1711ad6.tar.gz
sketchbook-c3b9938e9cb381bc7378fdca9073520ff1711ad6.zip
Play past sessions back, re-synced at their keyframes
play session S [at SECONDS] restores the session's keyframe before that time (a binary search over its keyframes' times), replays its frames up to it and leaves it paused there; without a time it plays from the start. At each later keyframe the replay reaches, the State is compared with it over the leaves migration kept: a keyframe taken of what update made (periodic, mark, before a reload, exit) that differs is reported once, "diverged before frame F: N values, first <field>", and every keyframe is restored, so a replay across a jump the log does not hold (set, load, a sketch command) goes on from the State that followed it. A session built from another source or build says so. The console's status line names the session, frame and time, the mark, the clip and where it records. test-past records a session, replays it by the same build (the mark's State exactly, frame 120's two seconds in, no divergence), then by a build with an edited fixture (one divergence, before the mark). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/host/timeline.zig')
-rw-r--r--src/host/timeline.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/host/timeline.zig b/src/host/timeline.zig
index 697a9df..c2eeff3 100644
--- a/src/host/timeline.zig
+++ b/src/host/timeline.zig
@@ -61,10 +61,29 @@ pub const Timeline = struct {
/// Set whenever live state is restored from a keyframe, for the host
/// to reset the input state that went with the old bytes.
restored: bool = false,
+ /// Frames fed since the keyframe was restored.
+ fed: u64 = 0,
+ /// A past session played (`play session`), not a clip: its index, and
+ /// its keyframes after the one played from, checked against the replay
+ /// as their frames are reached (Host.resync).
+ session: ?u64 = null,
+ checks: std.ArrayList(Check) = .empty,
+ next_check: usize = 0,
+
+ pub const Check = struct {
+ frame: u64,
+ key: u64,
+ /// Taken of what `update` made (periodic, a mark, before a reload,
+ /// at exit): a replay must match it. Other keyframes follow a jump
+ /// the log does not hold, and are restored without a word.
+ observed: bool,
+ };
pub fn deinit(self: *Timeline) void {
if (self.key) |k| k.free(self.gpa);
+ self.key = null;
self.events.deinit(self.gpa);
+ self.checks.deinit(self.gpa);
}
/// Puts a keyframe, in whatever layout it was taken, into live state.
@@ -73,6 +92,8 @@ pub const Timeline = struct {
defer arena.deinit();
_ = try memory.restore(arena.allocator(), key.layout, key.state, self.state.layout, self.state.slot(0), self.defaults);
self.restored = true;
+ self.fed = 0;
+ self.next_check = 0;
}
/// Makes a clip, its start keyframe and its frames, the one played; both
@@ -81,6 +102,8 @@ pub const Timeline = struct {
self.deinit();
self.key = key;
self.events = events;
+ self.session = null;
+ self.checks = .empty;
var it = frames(events.items);
const first = it.next();
self.base = if (first) |f| f[f.len - 1].time else 0;