diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-16 23:35:54 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | c3b9938e9cb381bc7378fdca9073520ff1711ad6 (patch) | |
| tree | 33f707ef2075bc26083a3c21d34a41b4a0e9c7ac /src/host/Sessions.zig | |
| parent | b2f7c605c279b2dea0c25180730c3d2e7b4b7d45 (diff) | |
| download | sketchbook-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/Sessions.zig')
| -rw-r--r-- | src/host/Sessions.zig | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/host/Sessions.zig b/src/host/Sessions.zig index 6f10bba..4399c63 100644 --- a/src/host/Sessions.zig +++ b/src/host/Sessions.zig @@ -81,7 +81,8 @@ keys: u64 = 0, batch: std.ArrayList(u8) = .empty, /// The first pending frame's tick. batch_time: u64 = 0, -/// The latest event time logged: times never go back. +/// The first and latest event time logged: times never go back. +first_time: u64 = 0, last_time: u64 = 0, /// The last keyframe's time, stretch and bytes' hash. key_time: u64 = 0, @@ -191,6 +192,7 @@ pub fn frame(s: *Sessions, one: []abi.Event, state: []const u8, why: ?Why) !void if (why) |w| { _ = try s.keyframe(w, state); } else if (tick -| s.key_time >= periodic_ns) _ = try s.keyframe(.periodic, state); + if (s.frames == 0) s.first_time = tick; if (s.batch.items.len == 0) { try s.batch.appendSlice(s.gpa, std.mem.asBytes(&std.mem.nativeToLittle(u64, s.frames))); s.batch_time = tick; @@ -487,6 +489,18 @@ pub fn load(s: *Sessions, session: u64, k: u64) !Loaded { } } +/// Keyframe `k`'s frame, time and why, without its bytes. +pub fn keyAt(s: *Sessions, session: u64, k: u64) !struct { frame: u64, time: u64, why: Why } { + switch (s.db) { + .off => return error.NotRecording, + inline .memory, .file => |*db| { + const R = Read(@TypeOf(db.*)); + const e = try R.at(try R.list(try R.session(db, session), .keys) orelse return error.NoSuchKeyframe, k); + return .{ .frame = try R.uint(e, .frame), .time = try R.uint(e, .time), .why = std.enums.fromInt(Why, try R.uint(e, .why)) orelse return error.CorruptSession }; + }, + } +} + /// The newest keyframe of `session` whose `by` (`.frame` or `.time`) is at /// most `value`: a binary search. pub fn keyBefore(s: *Sessions, session: u64, by: K, value: u64) !?u64 { |
