summary refs log tree commit diff
path: root/src/misc.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc.zig')
-rw-r--r--src/misc.zig11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/misc.zig b/src/misc.zig
index 9ad5933..353dcac 100644
--- a/src/misc.zig
+++ b/src/misc.zig
@@ -17,6 +17,7 @@
 // along with Black Shades.  If not, see <https://www.gnu.org/licenses/>.
 
 usingnamespace @cImport({
+    @cInclude("AL/al.h");
     @cInclude("GL/gl.h");
     @cInclude("GL/glu.h");
     @cInclude("lodepng.h");
@@ -33,6 +34,7 @@ const sep = std.fs.path.sep;
 const span = std.mem.span;
 const std = @import("std");
 
+/// Load audio file into an OpenAL buffer and return it.
 pub fn loadSound(filename: [*:0]const u8) callconv(.C) u32 {
     const path = join(allocator, &.{ data_dir ++ "sounds", span(filename) })
         catch unreachable;
@@ -49,6 +51,7 @@ fn check(errorString: fn (c_uint) callconv(.C) [*c]const u8,
         @panic(span(errorString(@intCast(c_uint, status))));
 }
 
+/// Load PNG file into an OpenGL buffer and return it.
 pub fn loadTexture(filename: [*:0]const u8) callconv(.C) GLuint {
     var dir = cwd().openDir(data_dir ++ "textures", .{}) catch unreachable;
     defer dir.close();
@@ -81,3 +84,11 @@ pub fn loadTexture(filename: [*:0]const u8) callconv(.C) GLuint {
                                             GL_RGBA, GL_UNSIGNED_BYTE, data));
     return texture;
 }
+
+/// Move sound source to given position and play it.
+pub fn playSound(source: u32, x: f32, y: f32, z: f32) callconv(.C) void {
+    const src = al.Source{ .reference = source };
+    _ = alGetError(); // TODO: remove when completely migrate to zeal
+    src.setPosition(.{ x / 32, y / 32, z / 32 }) catch unreachable;
+    src.play() catch unreachable;
+}