summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-24 13:53:53 -0300
committerGabriel Schneider <[email protected]>2026-10-24 20:59:59 -0300
commitc07af484b6f2688a64e850562d1f804c76c5ac52 (patch)
treecb1e553288097d5f415e67cc8040895e762a751d /src/pardes.zig
parent3b9ad2f510267d7be7280386cc95bb41a6e71308 (diff)
downloadpardes-c07af484b6f2688a64e850562d1f804c76c5ac52.tar.gz
pardes-c07af484b6f2688a64e850562d1f804c76c5ac52.zip
anim 1: a game's frame probe, FrameStats: every drawn frame's update, render and present times, the gap since the last, jank and over-budget counters, in the Debug box and dumped by PARDES_FRAMES; PARDES_FRAMES_DEMO runs a scroll timedemo in the GUI
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 1b1355ef..22b43a51 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -1,6 +1,7 @@
const std = @import("std");
pub const layout = @import("layout.zig");
pub const animation = @import("animation.zig");
+pub const FrameStats = @import("FrameStats.zig");
pub const Presentation = @import("Presentation.zig");
const uucode = @import("uucode");
const vaxis = @import("vaxis");
@@ -491,6 +492,7 @@ test {
_ = @import("animation.zig");
_ = @import("pager.zig");
_ = @import("Places.zig");
+ _ = @import("FrameStats.zig");
_ = @import("Query.zig");
_ = @import("Names.zig");
_ = @import("Stream.zig");
@@ -4493,6 +4495,8 @@ pub const Pardes = struct {
/// the pane and view origin it was last aimed in, and the last key or
/// click, which a blink holds for.
cursor_glide: animation.CursorGlide = .{},
+ /// Every drawn frame's timings (FrameStats: the Debug box, PARDES_FRAMES).
+ frames: FrameStats = .{},
/// A pixel shell's own render-time motion is under way (its smooth
/// scroll, G6): the core then keeps the continuous path running, so the
/// shell draws every loop and a virtual clock moves on, as for a lift.
@@ -4937,6 +4941,7 @@ pub const Pardes = struct {
}
pub fn deinit(p: *Pardes) void {
+ if (comptime hosted) if (std.c.getenv("PARDES_FRAMES")) |path| p.frames.dump(std.mem.span(path));
// Every file open now is closed with its dot, and the list kept.
for (p.panes) |slot| if (slot) |pane| p.noteClosed(pane);
p.store.flush(p, true);
@@ -5944,6 +5949,7 @@ pub const Pardes = struct {
} else 0;
f(h.ctx, timeout);
}
+ p.frames.mark_start = FrameStats.nowNs();
if (v.now) |clock| p.advance(clock(h.ctx));
// What a 9P open wrote in a row goes in once the writes pause.
ctlfs.pane.flushPausedBatch(p);
@@ -5968,13 +5974,19 @@ pub const Pardes = struct {
// drawing what nobody looked at.
if (v.watched) |f| if (!f(h.ctx)) return;
_ = p.frame_arena.reset(.{ .retain_with_limit = memory.limits.frame_kept });
+ p.frames.mark_update = FrameStats.nowNs();
const surface = try p.render(p.frame_arena.allocator());
+ p.frames.mark_render = FrameStats.nowNs();
if (v.present) |f| f(h.ctx, surface);
// Settled before post_present: a shell ticks there, and what that
// tick moves owes the next frame.
+ const skipped = p.present_skipped;
p.needs_frame = p.present_skipped;
p.present_skipped = false;
if (v.post_present) |f| f(h.ctx);
+ // Still moving: the next frame is owed a period from now.
+ const owed = if (p.nextWake()) |due| due <= p.stepped_ns + animation.frame_ns else false;
+ p.frames.record(FrameStats.nowNs(), owed or p.continuous(), skipped);
}
/// One request of the control filesystem, from whichever thread has the