summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-24 15:08:53 -0300
committerGabriel Schneider <[email protected]>2026-10-24 21:00:18 -0300
commite28b0992e9cd8dcedea5ed435566277ee6a93d5b (patch)
treef3b3f22ed63a784cc88ea4c0fb34fa43073ae03b /src
parent0d3179f04a91c942fc10b0a05cdd6b8aa958d13e (diff)
downloadpardes-e28b0992e9cd8dcedea5ed435566277ee6a93d5b.tar.gz
pardes-e28b0992e9cd8dcedea5ed435566277ee6a93d5b.zip
anim 6: the tty's frames paced too while anything moves, one a 16 ms tick, an input's frame at once
Diffstat (limited to 'src')
-rw-r--r--src/tty/tty.zig20
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 {