diff options
Diffstat (limited to 'core/Core.zig')
| -rw-r--r-- | core/Core.zig | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/core/Core.zig b/core/Core.zig index 9a542940..7ebcc020 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -1324,18 +1324,15 @@ fn nextQueued(p: *Pardes) ?Event { } pub fn hostForegroundName(p: *const Pardes, id: usize, buf: []u8) ?[]const u8 { - const f = p.host.vtable.fg_name orelse return null; - return f(p.host.ctx, .at(id), buf); + return p.tape.host(p, .fg_name, .{ .at(id), buf }) orelse null; } pub fn hostTtyTaken(p: *const Pardes, id: usize) bool { - const f = p.host.vtable.tty_taken orelse return false; - return f(p.host.ctx, .at(id)); + return p.tape.host(p, .tty_taken, .{.at(id)}) orelse false; } pub fn hostKillJob(p: *const Pardes, id: usize) bool { - const f = p.host.vtable.kill_job orelse return false; - return f(p.host.ctx, .at(id)); + return p.tape.host(p, .kill_job, .{.at(id)}) orelse false; } /// A terminal whose shell could not be started: said, and a run waiting @@ -1471,25 +1468,22 @@ pub fn animationActive(p: *const Pardes) bool { } pub fn pump(p: *Pardes, host: Host) !void { - // By hand, not `taped`: the host is set before the enter, which wraps it, and is no input. + // By hand, not `taped`: the host is set before the enter, which says which functions it has if it is another, and is no input. p.host = host; const taped = pardes.tape.enter(p, .pump); defer pardes.tape.leave(p, taped); - // The host as the tape sees it, while it records. - const h = p.host; - const v = h.vtable; - if (v.wait_input) |f| { + if (p.tape.has(p, .wait_input)) { // Asleep until input or until the core's next deadline // (nextWake); 0 is no timeout at all. // The clock read whether or not it is wanted: what a replica // waits on is its own (a picture decoding wakes only a frame // that draws it), and the tape has the same calls either way. - const now = if (v.now) |clock| clock(h.ctx) else p.clock.now_ns; + const now = p.tape.host(p, .now, .{}) orelse p.clock.now_ns; const timeout: u32 = if (p.nextWake()) |due| wake: { const ms = ((due -| now) + std.time.ns_per_ms - 1) / std.time.ns_per_ms; break :wake @intCast(std.math.clamp(ms, 1, std.math.maxInt(u32))); } else 0; - f(h.ctx, timeout); + _ = p.tape.host(p, .wait_input, .{timeout}); } // Detached, nobody's key dismisses a message: they go on the clock, // here in the step, where the clock read is taped (the host's wait @@ -1497,46 +1491,54 @@ pub fn pump(p: *Pardes, host: Host) !void { // go). Messages.expireUnattended(p); p.frames.mark_start = FrameStats.nowNs(); - if (v.now) |clock| p.advance(clock(h.ctx)); + if (p.tape.host(p, .now, .{})) |now| p.advance(now); p.settle(); // A quitting frame has already freed what it would draw. if (p.quit) return; - if (v.poll_frame) |f| f(h.ctx); + _ = p.tape.host(p, .poll_frame, .{}); // Nothing to draw: do not spend a frame, and above all do not block on // the display for one. This is what keeps the frame rate governing // rendering and nothing else. // A shell with a clock draws what `advance` stepped; one without // steps its own `.tick`s and draws while a deadline is due. - if (!p.needs_frame and (v.now != null or !p.animationActive())) return p.frames.idle(); + if (!p.needs_frame and (p.tape.has(p, .now) or !p.animationActive())) return p.frames.idle(); // No one to see it: the frame stays owed (needs_frame), not drawn. // A pty streaming into an unwatched session spent most of its time // drawing what nobody looked at. - if (v.watched) |f| if (!f(h.ctx)) return; + if (!(p.tape.host(p, .watched, .{}) orelse true)) return; // The one view this process shows (a replica client's is its own // process's to draw), drawn as it is if another's is live. // Not shown by the frontend (Host.present): owed. var skipped = false; const shown = Views.shown(p); if (shown != p.live) { - if (shown) |k| skipped = !try Views.drawOne(p, k, .{ .ctx = h.ctx, .f = v.present }); + if (shown) |k| skipped = !try Views.drawOne(p, k, .{ .ctx = p, .f = presentTaped }); } else { _ = p.frame_arena.reset(.{ .retain_with_limit = memory.limits.frame_kept }); p.frames.mark_update = FrameStats.nowNs(); p.frames.view = if (p.panes[p.view().active]) |pane| pane.scroll() else 0; const surface = try p.render(p.frame_arena.allocator()); p.frames.mark_render = FrameStats.nowNs(); - if (v.present) |f| skipped = !f(h.ctx, surface); + skipped = !(p.tape.host(p, .present, .{surface}) orelse true); Stream.askAhead(p); } // Settled before post_present: a shell ticks there, and what that // tick moves owes the next frame. p.needs_frame = skipped; - if (v.post_present) |f| f(h.ctx); + _ = p.tape.host(p, .post_present, .{}); // Still moving: the next frame is owed a period from now. const owed = if (p.nextWake()) |due| due <= p.clock.stepped_ns + frame_ns else false; p.frames.record(FrameStats.nowNs(), owed, skipped); } +/// The pump's other view presented as its own is, through the tape: +/// `present` stays inside `views.within`, whose live view the host's +/// `presented` reads. +fn presentTaped(ctx: ?*anyopaque, surface: *const pardes.Surface) bool { + const p: *Pardes = @ptrCast(@alignCast(ctx.?)); + return p.tape.host(p, .present, .{surface}) orelse true; +} + /// What a pump does between its wait and its frame: the queued inputs /// and the effects. Also the session at a step boundary, taken now (an /// Upgrade's dump, upgrade.zig). @@ -2073,7 +2075,7 @@ pub fn nextWake(p: *const Pardes) ?u64 { }; // Del's question goes up at the end of its delay: a frame then, and // none after (stepped time has reached it). - for (p.panes) |slot| if (slot) |pane| if (pane.prompt == .del_side and pane.question_due_ns > p.clock.stepped_ns) { + for (p.panes) |slot| if (slot) |pane| if (pane.prompt == .del_side and pane.question_due_ns > p.clock.stepped_ns and pane.question_due_ns != Pane.question_asked) { const wait = @max(1, (pane.question_due_ns - p.clock.stepped_ns + frame_ns - 1) / frame_ns); frames = if (frames) |soonest| @min(soonest, wait) else wait; }; @@ -2114,6 +2116,10 @@ fn advanceInner(p: *Pardes, now_ns: u64) void { p.clock.started = true; p.clock.now_ns = now_ns; if (!started) p.clock.stepped_ns = now_ns; + // Del's question asked since the last advance: its delay from now. + for (p.panes) |slot| if (slot) |pane| if (pane.question_due_ns == Pane.question_asked) { + pane.question_due_ns = now_ns + config.del_question_delay_ns; + }; const frame = frame_ns; var moving: u32 = 0; // The session's ticks are the recording session's: a picture still @@ -2273,6 +2279,11 @@ pub const Options = struct { startup_config: ?[]const u8 = null, ninep_name: []const u8 = "", ninep_tcp: ?[]const u8 = null, + /// This process's end of a socket pair its launch made (runtime/main.zig, + /// PARDES_PAIR): a session's first client is on it, taken before its + /// first effects (runtime/session.zig); a client's session is on it, + /// its first join made there with no hello (replica.join). + pair: ?c_int = null, mounts: []const filesystem.Mount = &.{}, config_dir: ?[]const u8 = null, /// Where what outlives the session is kept (Db.zig): the user's state @@ -2502,7 +2513,6 @@ test "LocationsConfig command reports partial updates and survives restore" { } test "TreeContext rows in the tag style keep the message rows" { - if (comptime !syntax.enabled) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 16 }); defer p.deinit(); const pane = try p.setTestFile("pub const Box = struct {\n pub fn run() void {\n" ++ (std.mem.asBytes(&@as([30][16]u8, @splat(" // body\n".*)))) ++ " }\n};\n"); @@ -2545,7 +2555,6 @@ test "TreeContext rows in the tag style keep the message rows" { } test "TreeContext command and custom tag survive a workspace round trip" { - if (comptime !syntax.enabled) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); const pane = try p.setTestFile("pub fn main() void {}\n"); |
