summaryrefslogtreecommitdiff
path: root/src/host_io.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/host_io.zig')
-rw-r--r--src/host_io.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/host_io.zig b/src/host_io.zig
index 6009c00f..f1a4eb98 100644
--- a/src/host_io.zig
+++ b/src/host_io.zig
@@ -12,6 +12,9 @@ pub const Host = struct {
pub const VTable = struct {
wait_input: ?*const fn (ctx: ?*anyopaque, timeout_ms: u32) void = null,
+ /// The shell's monotonic clock in ns: the only time the core sees.
+ /// Without one, core animation moves only by `.tick` events.
+ now: ?*const fn (ctx: ?*anyopaque) u64 = null,
present: ?*const fn (ctx: ?*anyopaque, surface: *const pardes.Surface) void = null,
post_present: ?*const fn (ctx: ?*anyopaque) void = null,
poll_frame: ?*const fn (ctx: ?*anyopaque) void = null,
@@ -39,6 +42,20 @@ pub const Host = struct {
};
};
+/// The shells' monotonic clock in ns, the one `Host.now` answers with.
+/// PARDES_TEST_CLOCK makes a shell answer a virtual clock instead, moved
+/// only when a timed wait runs out -- straight to the core's next wake -- so
+/// the snapshot harness sees the same frames whatever the machine's load.
+pub fn monotonicNs() u64 {
+ var ts: libc.timespec = undefined;
+ if (libc.clock_gettime(.MONOTONIC, &ts) != 0) return 0;
+ return @as(u64, @intCast(ts.sec)) * std.time.ns_per_s + @as(u64, @intCast(ts.nsec));
+}
+
+pub fn testClock() ?u64 {
+ return if (libc.getenv("PARDES_TEST_CLOCK")) |v| (if (std.mem.span(v).len != 0) 0 else null) else null;
+}
+
pub const Fallback = struct {
pub const dump_path = "pardes.dump.zon";