From 9991a90aae7f4591e63e5ecb0ab2467a348ed54e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 13:18:42 -0300 Subject: kinds #22, a kind's frame as its tick left it: a step that ticks a kind paints it once for the live view (Kind.repaint) before its tag is laid out, where the tag took what the frame before the tick placed and the next input's step another (a replica's guess of that input, the last step's tag, missed: 13 of the 30 ms cell's 14 visible rollbacks), so a pane of a kind's tag has its art words from its first step (the fake and pdf addon scripts' windows a row shorter), and an input's step sends each client what it made of a kind's pane after its unit, not at the next pump (a terminal client looked at the frame from before its own key's tick, the text layer missing from its view) Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- addons/fake/fake.out | 3 +-- addons/pdf/pdf.out | 3 +-- src/Kind.zig | 21 ++++++++++++++++ src/replica.zig | 4 +++ test/panes.zig | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 4 deletions(-) diff --git a/addons/fake/fake.out b/addons/fake/fake.out index 7a09e97a..3693f2c3 100644 --- a/addons/fake/fake.out +++ b/addons/fake/fake.out @@ -1,6 +1,6 @@ > seed 7 > size 60 20 -window 58x8 +window 58x7 tag fake |count 0 | @@ -9,7 +9,6 @@ tag fake | | | -| placement 2x2 src 0,0 2x2 over 0,2 2x1 key 4b3cd99b86ea3486 > key ab tag fake diff --git a/addons/pdf/pdf.out b/addons/pdf/pdf.out index d598dd1e..23849db2 100644 --- a/addons/pdf/pdf.out +++ b/addons/pdf/pdf.out @@ -22,8 +22,7 @@ tag [1/16] | | | -| -placement 794x1123 src 0,0 794x204 over 0,0 78x10 key 3017bc3ce49f9593 at 0,0 624x160 +placement 794x1123 src 0,0 794x184 over 0,0 78x9 key 3017bc3ce49f9593 at 0,0 624x144 > size 60 20 window 58x7 tag [1/16] diff --git a/src/Kind.zig b/src/Kind.zig index de5323bb..66e37852 100644 --- a/src/Kind.zig +++ b/src/Kind.zig @@ -629,9 +629,30 @@ pub fn step(p: *Pardes) void { if (slot.ops) |o| cl.ret = @bitCast(o.tick.?(slot.st, now, flags)); slot.next_tick = @bitCast(cl.end(prev).ret); p.needs_frame = true; + repaint(p, slot, id); }; } +/// Its prefix and whether it places a picture as its tick left it, for +/// this step's tag: a frame's paint set them, a step behind the tick (a +/// PDF to its text layer, or back), and a replica guessing its next input +/// took the tag this step laid out. The live view's frame of it, painted +/// and let go; not a frame drawn (`painted` kept). +fn repaint(p: *Pardes, slot: *Slot, id: usize) void { + const pane = p.panes[id] orelse return; + if (slot.ops == null or pane.collapsed) return; + const r = p.view().rects[id]; + const cols = r.w -| pardes.config.GUTTER; + const rows = (r.h -| pane.tag_rows) -| pane.notices.span(); + if (cols == 0 or rows == 0) return; + const drawn = slot.painted; + defer slot.painted = drawn; + var arena: std.heap.ArenaAllocator = .init(slot.gpa); + defer arena.deinit(); + var frame: Frame = .{ .cols = cols, .rows = rows }; + _ = paint(p, slot, id, arena.allocator(), cols, rows, &frame); +} + /// Whether `step` would tick some pane of a kind now (its rule, read only). fn wouldTick(p: *const Pardes, now: u64) bool { for (p.panes, 0..) |pslot, id| if (pslot) |pane| if (pane.addon) |slot| { diff --git a/src/replica.zig b/src/replica.zig index c5e3fd34..e3deff40 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -1911,6 +1911,10 @@ pub const Peers = struct { ps.t.stamp = null; ps.screensOut(core, .fill); ps.unit(peer.id, in.seq); + // What the step made of a kind's pane (its tick: another layout, + // the text layer) goes now, not at the next pump's: one may not + // come before the client looks. + ps.screensOut(core, .flush); } const ScreensOut = enum { flush, fill }; diff --git a/test/panes.zig b/test/panes.zig index 15eca652..d16de109 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -3917,6 +3917,75 @@ const PdfAddon = struct { try std.testing.expect(r.stats.stopped >= 1); } + test "the tag a step lays out for a PDF's pane is of the frame its tick left, not the frame before it" { + if (!addons.has_pdf) return error.SkipZigTest; + const R = pardes.replica; + const gpa = std.testing.allocator; + const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &host_vtable }, false); + defer a.deinit(); + const Land = struct { + a: *R.Authority, + fn step(l: @This(), ev: pardes.Event) !void { + _ = try l.a.local(ev); + } + }; + const land: Land = .{ .a = a }; + const id = try opened(a, land); + const slot = a.core.panes[id].?.addon.?; + // A view without graphics: the page's text layer, no picture. + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") == null); + // A window's: its tick lays the pages out as pictures and asks + // for them; the step their answers land in ticks it again, and its + // tag says what that tick placed, as the next step's will (a + // replica's guess of its next input is the tag this step laid out). + try land.step(.{ .frontend = .{ .windowed = true, .native_images = true } }); + try jobs(a.core, land); + try std.testing.expect(slot.placed); + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") != null); + } + + test "a PDF's pane in a window's view and a terminal's in turn: each one's step lays its tag out as its frame shows it" { + if (!addons.has_pdf) return error.SkipZigTest; + const R = pardes.replica; + const gpa = std.testing.allocator; + const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &host_vtable }, false); + defer a.deinit(); + // A terminal's client on the session's view, a window's on its own. + const tty = try R.Replica.init(gpa, 1, try a.unit(0, 0), false); + defer tty.deinit(); + const Land = struct { + a: *R.Authority, + fn step(l: @This(), ev: pardes.Event) !void { + _ = try l.a.local(ev); + } + }; + const land: Land = .{ .a = a }; + const id = try opened(a, land); + const slot = a.core.panes[id].?.addon.?; + const k = (try a.openView(2)).view; + const was = pardes.tape.on; + pardes.tape.on = &a.t; + const bytes = try pardes.dump.byteDump(a.core); + pardes.tape.resync(&a.t); + pardes.tape.on = was; + defer a.core.gpa.free(bytes); + const win = try R.Replica.initDump(gpa, 2, k, bytes, .{ .cols = 80, .rows = 24 }); + defer win.deinit(); + _ = try a.take(try win.input(.{ .frontend = .{ .windowed = true, .native_images = true } })); + try jobs(a.core, land); + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") != null); + for (0..2) |_| { + // The terminal's key: its view's tick, the page's text layer. + _ = try a.take(try tty.input(.{ .key = .{ .cp = 'j', .text = "j" } })); + try jobs(a.core, land); + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") == null); + // The window's: the pages as pictures again, in its tag at once. + _ = try a.take(try win.input(.{ .key = .{ .cp = 'j', .text = "j" } })); + try std.testing.expect(std.mem.indexOf(u8, slot.told.slice(), "petscii") != null); + try jobs(a.core, land); + } + } + test "a PDF pane whose file changes on disk opens again from it at its page, its fit kept" { if (!addons.has_pdf) return error.SkipZigTest; const gpa = std.testing.allocator; -- cgit v1.3