summaryrefslogtreecommitdiff
path: root/src/host/audio.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-25 21:53:00 -0300
committerGabriel Schneider <[email protected]>2026-09-25 21:54:39 -0300
commit2dfddee8c6fab6eb76cbfe3d95f7c30bfb870702 (patch)
tree32a8bbb55226721834fd5675e7bafc163508dd1e /src/host/audio.zig
parent50f4ee716aeafa13118cbcfa0f5cb37f7d3940a4 (diff)
downloadsketchbook-2dfddee8c6fab6eb76cbfe3d95f7c30bfb870702.tar.gz
sketchbook-2dfddee8c6fab6eb76cbfe3d95f7c30bfb870702.zip
sketchbook: what the game's review needed
- input.started: true on the first update of a run, never after a reload, for a sketch to stop what should not resume from saved state. - A console line that errors fails its script. Sketch commands answer unknown, done or failed (abi.Outcome) instead of a bool that hid errors. - addScript also takes the hot-reloadable library, run through the generic host, so scripts can reload a real build. - Sounds that do not load are .none, not an empty clip. - sk_tag reads an enum field's tag name from the web build, for tests.
Diffstat (limited to 'src/host/audio.zig')
-rw-r--r--src/host/audio.zig11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/host/audio.zig b/src/host/audio.zig
index fc8dcfb..87332b1 100644
--- a/src/host/audio.zig
+++ b/src/host/audio.zig
@@ -55,19 +55,22 @@ pub const Audio = struct {
return out;
}
+ /// `.none` when the file is missing or unreadable, remembered so the
+ /// warning prints once.
pub fn load(self: *Audio, path: []const u8) abi.Audio {
if (self.paths.get(path)) |audio| return audio;
- const audio = self.add(decodeFile(self.gpa, path) catch |err| blk: {
+ const audio: abi.Audio = if (decodeFile(self.gpa, path)) |samples| self.add(samples) else |err| blk: {
std.log.warn("sound {s}: {t}", .{ path, err });
- break :blk &.{};
- });
+ break :blk .none;
+ };
const key = self.gpa.dupe(u8, path) catch return audio;
self.paths.put(self.gpa, key, audio) catch self.gpa.free(key);
return audio;
}
+ /// `.none` when `wav` does not decode.
pub fn decode(self: *Audio, wav: []const u8) abi.Audio {
- return self.add(decodeWav(self.gpa, wav) catch &.{});
+ return self.add(decodeWav(self.gpa, wav) catch return .none);
}
fn add(self: *Audio, samples: []f32) abi.Audio {