diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 14:36:54 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 14:53:45 -0300 |
| commit | b5bb5e8ccf71a5755dde95f04440ee9c6aaa18da (patch) | |
| tree | 801403ea35508b571b34b0a750faed47be102f3d /src/kinds/addon.zig | |
| parent | 333cdea69956adda91f462980a18f5bac6548dda (diff) | |
| download | pardes-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/kinds/addon.zig')
| -rw-r--r-- | src/kinds/addon.zig | 18 |
1 files changed, 13 insertions, 5 deletions
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| { |
