diff options
Diffstat (limited to 'src/views.zig')
| -rw-r--r-- | src/views.zig | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/src/views.zig b/src/views.zig index b1786f83..ebf42387 100644 --- a/src/views.zig +++ b/src/views.zig @@ -579,6 +579,49 @@ pub fn drawOthers(p: *Pardes, h: pardes.Host) !void { pub const Present = struct { ctx: ?*anyopaque, f: ?*const fn (?*anyopaque, *const pardes.Surface) void }; +/// Render-time springs have no heap ownership. A replica keeps these +/// outside its rollback copy: reconciliation changes their destination, +/// never the position the user has already seen. +const motion_fields = [_][:0]const u8{ "lifts", "lift_serials", "cursor_glide", "cursor_view", "cursor_crossing", "cursor_held" }; +pub const RenderMotion = Part(Pardes, &motion_fields); + +pub fn motionActive(m: *const RenderMotion) bool { + for (m.lifts) |spring| if (!spring.settled) return true; + return m.cursor_glide.moving(); +} + +/// A replica's frame on its frontend's clock, with its own springs. The +/// session's clock and input time are restored before any replay or digest. +pub fn drawOneAt(p: *Pardes, k: u8, present: Present, motion: *RenderMotion, now_ns: u64, input_ns: u64) !void { + const Frame = struct { + present: Present, + motion: *RenderMotion, + now_ns: u64, + input_ns: u64, + + fn draw(f: @This(), q: *Pardes) anyerror!void { + const now = q.now_ns; + const input = q.input_ns; + const chrome = q.chrome_animation; + defer { + q.now_ns = now; + q.input_ns = input; + q.chrome_animation = chrome; + copy(&motion_fields, f.motion, q); + } + q.now_ns = f.now_ns; + q.input_ns = f.input_ns; + copy(&motion_fields, q, f.motion); + // A remote authority can be idle indefinitely: its tick-driven + // chrome fade must not hold this client's taglines in an old + // palette. Resolve the current theme for this frame only. + q.chrome_animation.snap(pardes.colors.ChromeTheme.fromTheme(q.theme())); + try drawLive(f.present, q); + } + }; + try drawOneWith(p, k, Frame{ .present = present, .motion = motion, .now_ns = now_ns, .input_ns = input_ns }, Frame.draw); +} + /// Parked view `k` unparked, drawn and presented. `unpark` hands each /// slot's selections to its body; drawn, the view is out again, and they /// are the slot's again (else a frame drawn would take them from a view, @@ -614,13 +657,18 @@ fn unparked(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pard /// view put back after exactly as it was, so the replica's digest is the /// authority's still. No post_present, as there. pub fn drawOne(p: *Pardes, k: u8, present: Present) !void { - if (k == p.view or !isOpen(p, k)) return drawLive(present, p); + try drawOneWith(p, k, present, drawLive); +} + +fn drawOneWith(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pardes) anyerror!void) !void { + if (k == p.view or !isOpen(p, k)) return f(ctx, p); const Draw = struct { - fn draw(pr: Present, q: *Pardes, kk: u8) anyerror!void { - try drawParked(q, kk, pr); + fn draw(x: @TypeOf(ctx), q: *Pardes, kk: u8) anyerror!void { + try unparked(q, kk, x, f); + copy(&drawn_fields, &q.parked[kk].?.view, q); } }; - try withParked(p, k, present, Draw.draw); + try withParked(p, k, ctx, Draw.draw); } /// `f(ctx, p)` with view `k` live, outside any step, and the live view put |
