From 2dfddee8c6fab6eb76cbfe3d95f7c30bfb870702 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 25 Sep 2026 21:53:00 -0300 Subject: 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. --- src/host/audio.zig | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/host/audio.zig') 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 { -- cgit v1.3