diff options
| -rw-r--r-- | src/tty/tty.zig | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/tty/tty.zig b/src/tty/tty.zig index efe8c752..264cfbef 100644 --- a/src/tty/tty.zig +++ b/src/tty/tty.zig @@ -1521,6 +1521,8 @@ const Shell = struct { /// PARDES_TEST_CLOCK's virtual time (host_io.testClock), and where the /// running-out wait moves it: the core's next wake. test_clock: ?u64 = null, + /// The tick the last paced frame was due at (waitInput). + pace_ns: u64 = 0, wake_to: u64 = 0, fn of(ctx: ?*anyopaque) *Shell { @@ -1575,9 +1577,23 @@ const Shell = struct { var batch: usize = 0; // The wait is the 9P connections' turn with the core. A timeout (the // core's next wake) arrives through the same queue (`wakeWatch`). - if (timeout_ms != 0) { + // While anything moves, a frame a tick (animation.frame_ns) on a grid + // of them, as the GUI paces to its display: the loop ran as fast as + // the terminal answered, a frame every 2 ms, each a write. An input + // ends the wait at once and its frame is drawn then; the ticks after + // it run from it. + var wait = timeout_ms; + if (s.test_clock == null and s.core.continuous()) { + const period = pardes.animation.frame_ns; + const now: u64 = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds); + var tick = if (s.pace_ns != 0 and now -| s.pace_ns < 2 * period) s.pace_ns + period else now; + if (tick < now) tick += (now - tick) / period * period; + s.pace_ns = tick; + wait = @intCast(@max(1, (tick -| now) / std.time.ns_per_ms)); + } + if (wait != 0) { s.wake_to = s.core.nextWake() orelse 0; - requestWake(s.io, timeout_ms); + requestWake(s.io, wait); } pardes.turn.rest(); const first = s.loop.nextEvent() catch { |
