aboutsummaryrefslogtreecommitdiff
path: root/src/misc.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc.zig')
-rw-r--r--src/misc.zig16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/misc.zig b/src/misc.zig
index 9015a02..9ad5933 100644
--- a/src/misc.zig
+++ b/src/misc.zig
@@ -22,14 +22,26 @@ usingnamespace @cImport({
@cInclude("lodepng.h");
});
+const al = @import("zeal");
const allocator = std.heap.c_allocator;
const cwd = std.fs.cwd;
const data_dir = @import("build_options").data_dir ++ [_]u8{ sep };
const free = std.c.free;
-const sep = std.fs.path.sep;
+const join = std.fs.path.joinZ;
const maxInt = std.math.maxInt;
-const std = @import("std");
+const sep = std.fs.path.sep;
const span = std.mem.span;
+const std = @import("std");
+
+pub fn loadSound(filename: [*:0]const u8) callconv(.C) u32 {
+ const path = join(allocator, &.{ data_dir ++ "sounds", span(filename) })
+ catch unreachable;
+ defer allocator.free(path);
+ const audio = al.Audio.read(allocator, span(path)) catch unreachable;
+ defer audio.free();
+ const buffer = al.Buffer.init(audio) catch unreachable;
+ return buffer.reference;
+}
fn check(errorString: fn (c_uint) callconv(.C) [*c]const u8,
status: anytype) void {