summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 14:36:54 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:53:45 -0300
commitb5bb5e8ccf71a5755dde95f04440ee9c6aaa18da (patch)
tree801403ea35508b571b34b0a750faed47be102f3d /src
parent333cdea69956adda91f462980a18f5bac6548dda (diff)
downloadpardes-b5bb5e8ccf71a5755dde95f04440ee9c6aaa18da.tar.gz
pardes-b5bb5e8ccf71a5755dde95f04440ee9c6aaa18da.zip
kinds #28, the Life dogfood's fixes: Deadline.every steps a period from when it was due while that is under a period behind and re-arms a period from now when it is further behind or more than one ahead (a restored record's), which Life's catch-up and guard lines were and snake's 150 ms now keep without drift; the tick after a key or a focus is told the clock's now, not the last stepped frame's, which lags it while the next wake is to come (the core's, Kind.step: Life's resume no longer jumps four generations); ops refuses at compile time a word that opens no pane, there being no ctl, and its doc names the functions it handles; reference.typ says how a script's key, tick and size work and that a pane a dump loads is a new pane with a new seed, as the header now does
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
-rw-r--r--src/Kind.zig5
-rw-r--r--src/kinds/addon.zig18
-rw-r--r--src/kinds/pardes_addon.h4
3 files changed, 20 insertions, 7 deletions
diff --git a/src/Kind.zig b/src/Kind.zig
index 66e37852..9785a1a3 100644
--- a/src/Kind.zig
+++ b/src/Kind.zig
@@ -626,7 +626,10 @@ pub fn step(p: *Pardes) void {
// counted by them.
const flags = (if (focused) c.PA_FOCUSED else 0) | (if (slot.painted and caps(p, slot).v22) c.PA_FRAMED else 0);
slot.painted = false;
- if (slot.ops) |o| cl.ret = @bitCast(o.tick.?(slot.st, now, flags));
+ // The clock's now for a tick after an event (a key, a focus): the
+ // stepped frame lags it while the next wake is still to come.
+ const at = if (slot.next_tick == 1) @max(now, p.clock.now_ns) else now;
+ if (slot.ops) |o| cl.ret = @bitCast(o.tick.?(slot.st, at, flags));
slot.next_tick = @bitCast(cl.end(prev).ret);
p.needs_frame = true;
repaint(p, slot, id);
diff --git a/src/kinds/addon.zig b/src/kinds/addon.zig
index afb59337..41b431ea 100644
--- a/src/kinds/addon.zig
+++ b/src/kinds/addon.zig
@@ -1,12 +1,16 @@
//! A kind of pane in Zig: what an addon imports beside the C ABI it is
//! built to (pardes_addon.h, translated: `c`), which stays the contract.
//! It imports nothing of the core. A kind is a struct whose `head` names
-//! it and whose functions are whichever of pa_ops's it has, each over a
-//! `*T` that `open` is handed zeroed (its defaults set) in the pane's arena:
+//! it and whose functions are any of `open`, `paint` (required), `tick`,
+//! `key`, `body`, `ctlRead`, `jobRun`, `jobDone`, `dump` and `load`, each
+//! over a `*T` that `open` is handed zeroed (its defaults set) in the
+//! pane's arena; pa_ops's others (mouse, ctl, address, where, search,
+//! close) no kind here has needed yet:
//!
//! export const pardes_addon = addon.ops(Snake);
//!
-//! addons/snake/snake.zig and addons/image/image.zig are the examples.
+//! addons/snake/snake.zig, addons/life/life.zig and addons/image/image.zig
+//! are the examples.
const std = @import("std");
pub const c = @import("pardes_addon");
const Allocator = std.mem.Allocator;
@@ -119,9 +123,11 @@ pub const Deadline = extern struct {
pub fn due(d: Deadline, now: u64) bool {
return d.at != 0 and now >= d.at;
}
- /// Due `period` after now, unless it is still ahead: its time.
+ /// Due a period after it was (a tick comes on a frame, late), or a
+ /// period from now when that is more than a period behind or ahead (a
+ /// record's, of another clock); kept while ahead: its time.
pub fn every(d: *Deadline, now: u64, period: u64) u64 {
- if (d.at == 0 or now >= d.at) d.at = now + period;
+ if (d.at == 0 or now -| d.at >= period or d.at > now + period) d.at = now + period else if (now >= d.at) d.at += period;
return d.at;
}
/// None: tick is next called when something happens to the pane.
@@ -219,6 +225,8 @@ pub fn ops(comptime T: type) c.pa_ops {
inline for (fns) |m| if (@hasDecl(T, m[0])) {
@field(o, m[1]) = @field(F, m[1]);
};
+ // A word for its pane goes to `ctl`, which this file does not make.
+ for (T.head.words) |w| if (!w.opens) @compileError(@typeName(T) ++ "'s word " ++ w.name ++ " opens no pane, and addon.zig makes no ctl to take it");
// A public function of another name (a typo) would be left out unsaid.
const names = [_][]const u8{ "open", "paint", "tick", "key", "body", "ctlRead", "jobRun", "jobDone", "dump", "load" };
inline for (@typeInfo(T).@"struct".decl_names) |d| if (comptime @typeInfo(@TypeOf(@field(T, d))) == .@"fn" and for (names) |n| {
diff --git a/src/kinds/pardes_addon.h b/src/kinds/pardes_addon.h
index 0870aa6f..a2b57155 100644
--- a/src/kinds/pardes_addon.h
+++ b/src/kinds/pardes_addon.h
@@ -196,7 +196,9 @@ typedef struct pa_api {
/* A new text pane named `name` holding `bytes`; its serial, 0 if none. */
uint32_t (*text)(const char *name, uint32_t name_len, const char *bytes, uint32_t n);
/* The pane's seed: the same pane, the same number, on every machine (a
- * game's board), and what `pardes --addon-test`'s `seed N` sets. */
+ * game's board), and what `pardes --addon-test`'s `seed N` sets. A pane
+ * restored from a dump is a new one: a kind keeps its seed in its record
+ * to reseed alike. */
uint64_t (*seed)(void);
/* 2.1 (api->size >= 96): memory of pardes's that outlives a call, as
* realloc's (n 0 frees it), on any thread at any time: what a pane's