summaryrefslogtreecommitdiff
path: root/src/abi.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/abi.zig')
-rw-r--r--src/abi.zig39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/abi.zig b/src/abi.zig
index 271c6dc..2e80a35 100644
--- a/src/abi.zig
+++ b/src/abi.zig
@@ -321,8 +321,8 @@ pub const Voice = struct {
/// Slices must stay alive until the host consumes the frame, right after
/// `draw` returns. `sketch.Frame` copies the small ones (text, GPU
/// descriptions, uniforms) into scratch memory itself; bulk data (vertices,
-/// samples, pixels, uploads) must already live in scratch, session or store
-/// memory, or be a literal.
+/// samples, pixels, uploads) must already live in scratch or session memory,
+/// or be a literal.
pub const Command = union(enum) {
clear: Color,
rect: struct { dst: Rect, color: Color },
@@ -661,7 +661,9 @@ pub const Host = struct {
samples: *const fn (*anyopaque, Audio) []const f32,
/// The whole file, mapped for the life of the host; empty if missing.
readFile: *const fn (*anyopaque, []const u8) []const u8,
- env: *const fn (*anyopaque, []const u8) ?[]const u8,
+ /// See `Host.appendFile`: name, then bytes; `replace` for `writeFile`.
+ appendFile: *const fn (*anyopaque, [*]const u8, usize, [*]const u8, usize, bool) callconv(.c) [*:0]const u8,
+ env:*const fn (*anyopaque, []const u8) ?[]const u8,
/// A monotonic clock in nanoseconds, for measuring, not for state:
/// `update` must use `Input` time to stay replayable.
clock: *const fn (*anyopaque) u64,
@@ -734,6 +736,21 @@ pub const Host = struct {
pub fn readFile(h: Host, path: []const u8) []const u8 {
return h.vtable.readFile(h.ctx, path);
}
+ /// Appends `bytes` to the sketch's file `name` (no `/` in it),
+ /// creating it: `<stem>.<name>`, beside the save `<stem>.xitdb` (in
+ /// `.sketchbook/` under `zig build run`). Returns the file's path, for
+ /// `readFile`, or "" when nothing was written, which on the web is
+ /// always. Only `draw` and `command` can write, and a write is not
+ /// replayed, like sound. `readFile` maps a file once: what is appended
+ /// to it afterwards is not in what it returned.
+ pub fn appendFile(h: Host, name: []const u8, bytes: []const u8) []const u8 {
+ return std.mem.span(h.vtable.appendFile(h.ctx, name.ptr, name.len, bytes.ptr, bytes.len, false));
+ }
+ /// `appendFile` to a new, empty file of that name: what the old one
+ /// held is gone (a `readFile` of it keeps its bytes).
+ pub fn writeFile(h: Host, name: []const u8, bytes: []const u8) []const u8 {
+ return std.mem.span(h.vtable.appendFile(h.ctx, name.ptr, name.len, bytes.ptr, bytes.len, true));
+ }
pub fn env(h: Host, name: []const u8) ?[]const u8 {
return h.vtable.env(h.ctx, name);
}
@@ -753,12 +770,8 @@ pub const Context = struct {
/// This process: survives reloads; frees one allocation at a time, and
/// releases the rest when Session's layout changes.
session: std.mem.Allocator,
- /// On disk, next to the state file: survives reloads and restarts, at
- /// the same addresses, so Store may point into it.
- store: std.mem.Allocator,
- /// The sketch's `Session` and `Store` values.
+ /// The sketch's `Session` value.
session_root: [*]u8,
- store_root: [*]u8,
/// Filled by `draw`, using `scratch`.
commands: *std.ArrayList(Command),
};
@@ -807,20 +820,19 @@ pub const Info = struct {
height: u32,
state: Layout,
session: Layout,
- store: Layout,
/// Console completions offered by the sketch.
commands: []const []const u8 = &.{},
/// What the sketch was built from: its repository's revision ("jj:<commit>
/// <change>", "git:<sha>[+dirty]", or nothing), then `build`. Each
/// stretch of a recorded session keeps it.
source: []const u8 = "",
- /// Whether the host records sessions to a file (`App.Options.record`;
- /// Debug builds do unless told otherwise).
+ /// Whether the save keeps history, or only the present and the marks
+ /// (`App.Options.record`; Debug builds keep it unless told otherwise).
record: bool = false,
};
/// Which memory `sketch_defaults` fills.
-pub const Memory = enum(u8) { state, session, store };
+pub const Memory = enum(u8) { state, session };
/// The entry points of a sketch, exported from libraries under these names.
/// What became of a console line offered to a sketch.
@@ -842,8 +854,7 @@ pub const Sketch = struct {
setup: *const fn (*const Context) callconv(.c) bool,
/// Deterministic: new state from state and input, nothing else.
update: *const fn (*const Context, [*]u8) callconv(.c) void,
- /// Presentation: reads state, may change session and store, appends
- /// commands.
+ /// Presentation: reads state, may change session, appends commands.
draw: *const fn (*const Context, [*]const u8) callconv(.c) void,
/// A console line the host did not understand.
command: *const fn (*const Context, [*]u8, *const []const u8) callconv(.c) Outcome,