diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-29 20:56:03 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-30 02:12:12 -0300 |
| commit | 57aa8d2f9ae851fa9806abbd1fd04abf1fd2b57f (patch) | |
| tree | ec77e56aa09568b592fbbb28fa2c379df922d922 /src/views.zig | |
| parent | 3703c2526fb59708b00e12816bd88ffd8a15fc69 (diff) | |
| download | pardes-57aa8d2f9ae851fa9806abbd1fd04abf1fd2b57f.tar.gz pardes-57aa8d2f9ae851fa9806abbd1fd04abf1fd2b57f.zip | |
replicas' core for a socket: a client's input settles as a `step` (no clock, no wait, no frame) on both sides, every kind of input speculated, the session's clock guessed, views no frontend here draws left undrawn, and a drawn view's selections given back to its slot
pardes.zig: `step`, the middle of a pump, is a client input's own top-level input on the authority and in the replica's speculation, so the two tapes read alike; a pump skips the live view when it is `undrawn` (a replica client's, drawn by its own process); `settle` is the pump's whole middle, the Upgrade's too.
tape.zig: a `.step` input; `unattended` is a watched field; a speculation's clock reads answer a guess of the session's clocks (`Guess`); `resync` says the host and its writes again for a joiner; `adoptCore`; a short ret is shown in a trace.
views.zig: `drawOne` draws a replica client's own view between steps; `drawParked` gives a drawn view's selections back to its slot, for drawOthers too.
rollback.zig: std's lists by walk.isList (a safe build's have a third field).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/views.zig')
| -rw-r--r-- | src/views.zig | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/src/views.zig b/src/views.zig index b9760143..361d14a3 100644 --- a/src/views.zig +++ b/src/views.zig @@ -508,28 +508,64 @@ pub fn drawOthers(p: *Pardes, h: pardes.Host) !void { } for (0..max) |i| { const k: u8 = @intCast(i); - if (k == live or !isOpen(p, k)) continue; - // `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, and a replica that draws - // nothing would keep them). - var sels: [MAX_PANES]struct { s: @TypeOf(@as(Pane, undefined).body.sels), n: @TypeOf(@as(Pane, undefined).body.nsel) } = undefined; - for (p.panes, 0..) |s, id| if (s) |pane| { - sels[id] = .{ .s = pane.pv[k].body.sels, .n = pane.pv[k].body.nsel }; - }; - defer for (p.panes, 0..) |s, id| if (s) |pane| { - pane.pv[k].body.sels = sels[id].s; - pane.pv[k].body.nsel = sels[id].n; - }; - unpark(p, k); - _ = p.frame_arena.reset(.{ .retain_with_limit = pardes.memory.limits.frame_kept }); - const surface = try p.render(p.frame_arena.allocator()); - if (v.present) |f| f(h.ctx, surface); + if (k == live or !isOpen(p, k) or p.undrawn & (@as(u8, 1) << @intCast(k)) != 0) continue; // No post_present: what a shell acknowledges there moves the // session's pointer and hover, which are the live view's to move; // a view's panels are acknowledged when it is live and drawn. - copy(&drawn_fields, &p.parked[k].?.view, p); + try drawParked(p, k, .{ .ctx = h.ctx, .f = v.present }); + } +} + +pub const Present = struct { ctx: ?*anyopaque, f: ?*const fn (?*anyopaque, *const pardes.Surface) void }; + +/// 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, +/// and a replica that draws nothing would keep them). +fn drawParked(p: *Pardes, k: u8, present: Present) !void { + var sels: [MAX_PANES]struct { []Text.SelRange, u16 } = undefined; + for (p.panes, 0..) |s, id| if (s) |pane| { + sels[id] = .{ pane.pv[k].body.sels, pane.pv[k].body.nsel }; + }; + unpark(p, k); + defer for (p.panes, 0..) |s, id| if (s) |pane| { + pane.pv[k].body.sels = sels[id][0]; + pane.pv[k].body.nsel = sels[id][1]; + }; + _ = p.frame_arena.reset(.{ .retain_with_limit = pardes.memory.limits.frame_kept }); + const surface = try p.render(p.frame_arena.allocator()); + if (present.f) |f| f(present.ctx, surface); + copy(&drawn_fields, &p.parked[k].?.view, p); +} + +/// View `k` drawn and presented outside any step, by a replica client +/// (src/replica.zig) whose own it is: as `drawOthers` draws one, the live +/// 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)) { + _ = p.frame_arena.reset(.{ .retain_with_limit = pardes.memory.limits.frame_kept }); + const surface = try p.render(p.frame_arena.allocator()); + if (present.f) |f| f(present.ctx, surface); + return; + } + const live = p.view; + park(p); + defer { + copy(&fields, p, &p.parked[live].?.view); + p.view = live; + for (p.panes) |s| if (s) |pane| { + const pv = &pane.pv[live]; + copy(&pane_fields, pane, pv); + copy(&body_fields, &pane.body, &pv.body); + if (!pane.isTerminal()) { + pane.cols = pv.cols; + pane.rows = pv.rows; + } + if (pane.file) |*f| f.scroll = pv.scroll; + }; } + try drawParked(p, k, present); } // ---- tests ---- |
