summaryrefslogtreecommitdiff
path: root/src/Kind.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Kind.zig')
-rw-r--r--src/Kind.zig98
1 files changed, 34 insertions, 64 deletions
diff --git a/src/Kind.zig b/src/Kind.zig
index e3d74b24..08c04154 100644
--- a/src/Kind.zig
+++ b/src/Kind.zig
@@ -162,13 +162,10 @@ pub const Slot = struct {
/// Its words' last values, a `Word arg` line each, which a kind with
/// no `dump` is given again when its pane comes back.
values: Buf(256) = .{},
- /// Its prefix as its last tick set it; where its window is in its
+ /// Its prefix as its last tick set it (the tick's outcome, on the
+ /// tape: a Shadow's is the authority's); where its window is in its
/// whole (the rail's thumb), 0 and 0 for none, as its last frame says.
prefix: Buf(96) = .{},
- /// Its tag's prefix as the last step read it (the authority's): what a
- /// Shadow says in a step, and what a dump keeps of it, so a replica
- /// joining lays its tag out as the session did.
- told: Buf(400) = .{},
thumb_at: f32 = 0,
thumb_span: f32 = 0,
/// The pointer its last frame asked for over it (PA_POINTER_*), and
@@ -482,20 +479,12 @@ fn colorOf(v: u32, default: surface.Color) surface.Color {
pub fn prefix(p: *const Pardes, arena: std.mem.Allocator, pane: *const Pane) ![]const u8 {
const slot = pane.addon.?;
var buf: [400]u8 = undefined;
- const made = tape.value(.addon, prefixOf, .{ p, slot, &buf });
- if (tape.stepping()) slot.told.set(made);
- return arena.dupe(u8, made);
+ return arena.dupe(u8, tape.value(.addon, prefixOf, .{ p, slot, &buf }));
}
fn prefixOf(p: *const Pardes, slot: *const Slot, buf: *[400]u8) []const u8 {
if (!slot.live) return if (slot.path.len > 0) slot.path else slot.nameOf();
- // A Shadow's is the authority's last step's, never its frames' guess:
- // a speculation, a load and a frame drawn between steps (which lays the
- // tag out too) all lay it out as the session's step did.
- // ponytail: so a window client's page in the tag is the session's last
- // step's, a notch behind its frames until the next step.
- if (slot.ops == null and slot.told.len > 0) return slot.told.slice();
- const own = if (slot.shadow) |sh| sh.prefix.slice() else slot.prefix.slice();
+ const own = slot.prefix.slice();
var w: std.Io.Writer = .fixed(buf);
w.writeAll(if (own.len > 0) own else slot.nameOf()) catch {};
// The same bytes whichever view's step lays the tag out (17.2): glyph
@@ -604,17 +593,22 @@ pub fn mouse(p: *Pardes, id: usize, m: pardes.Mouse, col: u16, row: u16) bool {
return taken(p, slot, cl.end(prev));
}
-/// The end of a step: each pane of a kind told of each view whose facts
-/// changed (17.1), and each whose focus changed, or whose time has come,
-/// ticked (16.2).
-pub fn step(p: *Pardes) void {
+/// The end of a step: each pane of a kind ticked that a call into it in
+/// the step asked for (16.2's rule 2). At a step of the session's own
+/// (`due`: a tick, a job's answer, a 9P request; never a client's input,
+/// which a replica guesses), also each told of each view whose facts
+/// changed (17.1), and ticked when its focus changed or its time came:
+/// units of the session's origin, which a replica replays (17.2).
+pub fn step(p: *Pardes, due: bool) void {
const now = p.clock.stepped_ns;
- // A kind's call is the authority's kind's alone: a speculation whose
- // step would make one waits for the authority's unit (guessed
- // untouched, the unit rolled it back, a visible rollback an input).
- if (tape.speculating()) return if (wouldTick(p, now)) tape.poison("a kind's tick");
+ // A kind's call is the authority's alone: a speculation's tick after a
+ // call into the pane waits with that call's input (it stopped there).
+ if (tape.speculating()) {
+ for (p.panes) |pslot| if (pslot) |pane| if (pane.addon) |slot| if (slot.next_tick == 1) return tape.poison("a kind's tick");
+ return;
+ }
for (p.panes, 0..) |pslot, id| if (pslot) |pane| if (pane.addon) |slot| {
- if (caps(p, slot).view) for (0..views.max) |k| {
+ if (due and caps(p, slot).view) for (0..views.max) |k| {
var v = viewOf(p, @intCast(k), id);
if (seen(&v) == slot.views[k]) continue;
slot.views[k] = seen(&v);
@@ -627,13 +621,11 @@ pub fn step(p: *Pardes) void {
};
if (!caps(p, slot).tick) continue;
const focused = focusedAnywhere(p, id);
- if (focused != slot.focused) {
- slot.focused = focused;
- slot.next_tick = 1;
- }
+ if (due and focused != slot.focused) slot.next_tick = 1;
// 1 is the next step, whatever the clock says (a session whose
// clock has not moved yet reads 0).
- if (slot.next_tick == 0 or (slot.next_tick > 1 and now < slot.next_tick)) continue;
+ if (slot.next_tick == 0 or (slot.next_tick > 1 and (!due or now < slot.next_tick))) continue;
+ slot.focused = focused;
var cl: Call = .{ .p = p, .id = id, .slot = slot };
const prev = cl.begin("tick");
// A frame drawn since its last tick: a fling's frames are counted by them.
@@ -645,11 +637,12 @@ pub fn step(p: *Pardes) void {
if (slot.ops) |o| {
o.tick.?(slot.st, &t);
cl.ret = @bitCast(t.next);
- slot.prefix.set(t.prefix[0..@min(t.prefix_len, t.prefix.len)]);
+ cl.prefix = t.prefix[0..@min(t.prefix_len, t.prefix.len)];
}
- slot.next_tick = @bitCast(cl.end(prev).ret);
+ const o = cl.end(prev);
+ slot.next_tick = @bitCast(o.ret);
+ slot.prefix.set(o.prefix);
p.needs_frame = true;
- repaint(p, slot, id);
};
}
@@ -664,34 +657,6 @@ fn seen(v: *const c.pa_view) u64 {
return if (v.cols == 0) 0 else std.hash.Wyhash.hash(0, std.mem.asBytes(v));
}
-/// Its thumb and pointer as its tick left them, 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 call some pane's 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| {
- if (viewOwed(p, slot, id)) return true;
- if (!caps(p, slot).tick) continue;
- if (focusedAnywhere(p, id) != slot.focused) return true;
- if (slot.next_tick == 1 or (slot.next_tick > 1 and now >= slot.next_tick)) return true;
- };
- return false;
-}
-
/// Pane `id` as view `k` shows it (its id k + 1): its body below its
/// notices, as draw.zig paints it, a cell's pixels, the theme's colours and
/// the raster that view's frontend wants a picture at; no cells when the
@@ -736,12 +701,14 @@ fn focusedAnywhere(p: *const Pardes, id: usize) bool {
return false;
}
-/// When the kinds next want a step: the soonest deadline (now, for a view
-/// whose facts a step's layout changed after the kind was told them), or null.
+/// When the kinds next want a step of the session's own: the soonest
+/// deadline (now, for a view whose facts changed after the kind was told
+/// them, or a focus), or null.
pub fn wake(p: *const Pardes) ?u64 {
var soonest: ?u64 = null;
for (p.panes, 0..) |pslot, id| if (pslot) |pane| if (pane.addon) |slot| {
- const due = if (viewOwed(p, slot, id)) @max(1, p.clock.stepped_ns) else slot.next_tick;
+ const moved = viewOwed(p, slot, id) or (caps(p, slot).tick and focusedAnywhere(p, id) != slot.focused);
+ const due = if (moved) @max(1, p.clock.stepped_ns) else slot.next_tick;
if (due != 0) soonest = @min(soonest orelse due, due);
};
return soonest;
@@ -866,6 +833,8 @@ pub const Outcome = struct {
exec: []const u8 = "",
selected: ?[]const u8 = null,
rows: []const u8 = "",
+ /// A tick's: the start of its tag (pa_tick.prefix).
+ prefix: []const u8 = "",
/// The jobs it asked for (their tokens, 0 past the last): every core
/// emits them, so a replica's effects are the authority's; and those
/// it cancelled, every core drops.
@@ -895,6 +864,7 @@ const Call = struct {
exec: Buf(256) = .{},
selected: ?[]const u8 = null,
rows: []const u8 = "",
+ prefix: []const u8 = "",
jobs: [8]u32 = @splat(0),
cancels: [4]u32 = @splat(0),
/// Debug: when it began, for the budget.
@@ -913,7 +883,7 @@ const Call = struct {
current = prev;
if (checked) overBudget(cl);
if (cl.quiet) return .{};
- const o = tape.value(.addon, same, .{Outcome{ .ret = cl.ret, .text = cl.refused.slice(), .said = cl.said.slice(), .err = cl.err, .look = cl.look.slice(), .pane_name = cl.pane_name.slice(), .pane_text = cl.pane_text, .exec = cl.exec.slice(), .selected = cl.selected, .rows = cl.rows, .jobs = cl.jobs, .cancels = cl.cancels }});
+ const o = tape.value(.addon, same, .{Outcome{ .ret = cl.ret, .text = cl.refused.slice(), .said = cl.said.slice(), .err = cl.err, .look = cl.look.slice(), .pane_name = cl.pane_name.slice(), .pane_text = cl.pane_text, .exec = cl.exec.slice(), .selected = cl.selected, .rows = cl.rows, .prefix = cl.prefix, .jobs = cl.jobs, .cancels = cl.cancels }});
if (cl.p) |p| if (p.panes[cl.id]) |pane| for (o.jobs) |token| if (token != 0) p.emit(.{ .job = .{ .pane = @intCast(cl.id), .serial = pane.serial, .token = token } });
for (o.cancels) |token| if (token != 0) {
for (&cl.slot.jobs) |*j| if (j.*) |job| if (job.token == token) {