summaryrefslogtreecommitdiff
path: root/src/sketch
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-16 23:24:29 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit57e254470e11ab40b6bae31b2cbf62aebca27ce4 (patch)
treec1ab036650033c896069fa35a3d6279fe004fb32 /src/sketch
parent8ce27cfdbab6d576db36403afbcef9659cb6dbdc (diff)
downloadsketchbook-57e254470e11ab40b6bae31b2cbf62aebca27ce4.tar.gz
sketchbook-57e254470e11ab40b6bae31b2cbf62aebca27ce4.zip
Record every run's frames to a sessions database in xitdb
Live play was recorded only after someone typed record N, into 16 fixed slots. Now every run is a session in one xitdb database per sketch, beside its state file (<name>.xitdb): an append-only log of the frames live update was fed, one commit a second of session time, and keyframes of the State at start, every minute, on jumps, before and after reloads and at exit. A kill -9 loses at most the uncommitted second (test-kill). Whether a build records travels in the sketch: App.Options.record, null meaning Debug, reaching the host as Info.record. Scripted runs from fresh state record in memory, exports not at all. Each stretch of a session keeps its build, layout and Info.source: the repository revision (one jj or git call per build, build_info), zig version, backend and mode. Sessions.zig takes plain data (bytes, events, strings, a path, an Io), so a second host can drive it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/sketch')
-rw-r--r--src/sketch/root.zig23
-rw-r--r--src/sketch/web.zig2
2 files changed, 18 insertions, 7 deletions
diff --git a/src/sketch/root.zig b/src/sketch/root.zig
index bc09add..c70b326 100644
--- a/src/sketch/root.zig
+++ b/src/sketch/root.zig
@@ -300,15 +300,24 @@ pub const Console = struct {
}
};
+/// What the build knows of a sketch and passes to `sketch` and
+/// `exportSketch` (build.zig's generated roots fill it in).
+pub const Build = struct {
+ /// The repository revision the sketch was built from, "" when unknown.
+ source: []const u8 = "",
+ /// Record sessions to a file (`abi.Info.record`).
+ record: bool = false,
+};
+
/// The entry points of `App`, for a host that links it statically.
-pub fn sketch(comptime App: type) abi.Sketch {
- const G = Glue(App);
+pub fn sketch(comptime App: type, comptime made: Build) abi.Sketch {
+ const G = Glue(App, made);
return .{ .info = G.info, .defaults = G.defaults, .init = G.init, .setup = G.setup, .update = G.update, .draw = G.draw, .command = G.command };
}
/// Exports `App` under `abi.Sketch.symbols`, for a hot-reloaded library.
-pub fn exportSketch(comptime App: type) void {
- const G = Glue(App);
+pub fn exportSketch(comptime App: type, comptime made: Build) void {
+ const G = Glue(App, made);
const names = abi.Sketch.symbols;
@export(&G.info, .{ .name = names.info });
@export(&G.defaults, .{ .name = names.defaults });
@@ -320,7 +329,7 @@ pub fn exportSketch(comptime App: type) void {
@export(&G.build, .{ .name = "sketch_build" });
}
-pub fn Glue(comptime App: type) type {
+pub fn Glue(comptime App: type, comptime made: Build) type {
return struct {
pub const State = if (@hasDecl(App, "State")) App.State else struct {};
pub const Session = if (@hasDecl(App, "Session")) App.Session else struct {};
@@ -337,6 +346,8 @@ pub fn Glue(comptime App: type) type {
.session = abi.layout.of(Session, .session),
.store = abi.layout.of(Store, .store),
.commands = if (@hasDecl(App, "commands")) &App.commands else &.{},
+ .source = made.source ++ " " ++ abi.build,
+ .record = made.record,
};
/// What a call can offer, by type.
@@ -471,7 +482,7 @@ test "setup receives session resources without a Frame and reports errors" {
ctx.session_root = std.mem.asBytes(&session);
ctx.session = std.testing.allocator;
ctx.store = std.testing.allocator;
- const app = sketch(App);
+ const app = sketch(App, .{});
try std.testing.expect(!app.setup(&ctx));
defer std.testing.allocator.free(session.bytes);
try std.testing.expectEqualStrings("ready", session.bytes);
diff --git a/src/sketch/web.zig b/src/sketch/web.zig
index 937b491..6cf165a 100644
--- a/src/sketch/web.zig
+++ b/src/sketch/web.zig
@@ -76,7 +76,7 @@ pub fn exportWeb(comptime App: type) void {
}
fn Driver(comptime App: type) type {
- const G = root.Glue(App);
+ const G = root.Glue(App, .{});
const gpa = std.heap.wasm_allocator;
return struct {
var ready = false;