diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/gui/gui.zig | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index aa28a3f0..7aba4c34 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -1028,7 +1028,7 @@ const Own = struct { .fs = l.fs, .test_mode = o.test_mode, .test_clock = if (o.test_mode) host_io.testClock() else null, - .test_hz = if (std.c.getenv("PARDES_TEST_HZ")) |hz| @max(1, std.fmt.parseInt(u64, std.mem.span(hz), 10) catch 60) else 60, + .test_hz = testHz(), .peers = &l.peers, }; // A virtual clock never blinks: goldens and feel series hold still. @@ -1249,6 +1249,12 @@ const Client = struct { const minimized = !cl.test_mode and c.SDL_GetWindowFlags(g.window) & (c.SDL_WINDOW_MINIMIZED | c.SDL_WINDOW_OCCLUDED) != 0; cl.moving = !minimized and frontendMoving(g); cl.blink = if (minimized or cl.shell.surface == null) null else blinkNow(g, g.facts.cursor_blink); + // Idle, as the session's own window says it (writeTestStatus), once + // it has what the session was told: its digest asked when quiet + // and answered since the last unit (Link.quietCheck). + // A replica's `needs_frame` is the session's steps' (Replica.draw + // leaves it as it was): its own owed frame is the link's. + if (cl.test_mode) writeTestStatus(g, cl.in.core, cl.shell.presented and l.link.r.quiet() and !l.link.changed and !l.link.asked, l.link.dirty or l.link.owed); if (latency_fd >= 0) return client_loop.forever; var ms: u32 = if (cl.test_mode) 16 else client_loop.forever; if (demoDue(g)) |due| ms = @min(ms, @as(u32, @intCast(due))); @@ -1291,6 +1297,11 @@ const Client = struct { _ = c.SDL_SetWindowTitle(g.window, "pardes"); } if (cl.moving or (cl.blink != null and (cl.blink.?.edge or timed_out))) cl.again_due = true; + // A virtual clock: its own motion moves a display frame a pass, as + // the own window's (waitInput); the core's time is its session's. + if (cl.shell.test_clock) |*virtual| if (cl.moving) { + virtual.* += std.time.ns_per_s / cl.shell.test_hz; + }; } /// Its own view drawn in the window, as the tty's client draws its @@ -1416,6 +1427,8 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ .queue = &queue, .watches = &no_watches, .test_mode = test_mode, + .test_clock = if (test_mode) host_io.testClock() else null, + .test_hz = testHz(), .client = &window, .peers = &no_peers, }; @@ -2841,7 +2854,7 @@ fn pollFrame(ctx: ?*anyopaque) void { const geom = windowCells(g); if (updateCoreResize(core, geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height)) resetScroll(g); stepScroll(g, core, s.gpa); - if (s.test_mode) writeTestStatus(g, core, s.presented); + if (s.test_mode) writeTestStatus(g, core, s.presented, core.needs_frame); // A blink edge, or the window's own motion (its glide, its caret, a // jump's trail): the last frame again, moved on, no core render. if ((g.blink_due or frontendMoving(g)) and !core.needs_frame and s.presented) if (s.surface) |frame| { @@ -4731,14 +4744,19 @@ fn captureFrame(g: *Gui, gpa: std.mem.Allocator, cmd: *c.SDL_GPUCommandBuffer, t /// sees a step past the one it acted on, idle, has its frame, however slow /// the machine is. var test_status_step: u64 = 0; -fn writeTestStatus(g: *const Gui, core: *const pardes.Pardes, presented: bool) void { +/// PARDES_TEST_HZ: the display rate a virtual clock stands in for. +fn testHz() u64 { + return if (std.c.getenv("PARDES_TEST_HZ")) |hz| @max(1, std.fmt.parseInt(u64, std.mem.span(hz), 10) catch 60) else 60; +} + +fn writeTestStatus(g: *const Gui, core: *const pardes.Pardes, presented: bool, needs_frame: bool) void { test_status_step +%= 1; if (g.capture_dir.len == 0) return; - const idle = presented and !core.needs_frame and !frontendMoving(g) and core.nextWake() == null and + const idle = presented and !needs_frame and !frontendMoving(g) and core.nextWake() == null and !g.glide.moving() and g.scroll_lag == 0 and g.scroll_delta == 0 and g.scroll_notch == 0; var line_buf: [64]u8 = undefined; // What keeps it busy, after: owes a frame, moves, waits, not shown. - const line = std.fmt.bufPrint(&line_buf, "{d} {d} {d} {d}{d}{d}{d}\n", .{ test_status_step, g.captured, @intFromBool(idle), @intFromBool(core.needs_frame), @intFromBool(frontendMoving(g)), @intFromBool(core.nextWake() != null), @intFromBool(!presented) }) catch unreachable; // seven numbers fit 64 + const line = std.fmt.bufPrint(&line_buf, "{d} {d} {d} {d}{d}{d}{d}\n", .{ test_status_step, g.captured, @intFromBool(idle), @intFromBool(needs_frame), @intFromBool(frontendMoving(g)), @intFromBool(core.nextWake() != null), @intFromBool(!presented) }) catch unreachable; // seven numbers fit 64 var tmp_buf: [4096]u8 = undefined; var final_buf: [4096]u8 = undefined; const tmp_path = std.fmt.bufPrintSentinel(&tmp_buf, "{s}/status.tmp", .{g.capture_dir}, 0) catch return; |
