summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/al.zig17
-rw-r--r--src/main.zig8
2 files changed, 17 insertions, 8 deletions
diff --git a/src/al.zig b/src/al.zig
index b15f2a1..e806e90 100644
--- a/src/al.zig
+++ b/src/al.zig
@@ -16,14 +16,25 @@
 // You should have received a copy of the GNU Lesser General Public License
 // along with zeal.  If not, see <https://www.gnu.org/licenses/>.
 
-usingnamespace @cImport({ @cInclude("AL/al.h"); });
+const Child = @import("std").meta.Child;
+
+usingnamespace @cImport(@cInclude("AL/al.h"));
 
 pub const POSITION = AL_POSITION;
 pub const ORIENTATION = AL_ORIENTATION;
 
 pub const listener = struct {
-    pub const setFloat = alListenerf;
-    pub const setFloatVector = alListenerfv;
+    pub fn set(comptime T: type, param: ALenum, value: T) void {
+        switch (T) {
+            f32 => alListenerf(param, value),
+            i32 => alListeneri(param, value),
+            else => switch (Child(T)) {
+                f32 => alListenerfv(param, value[0..]),
+                i32 => alListeneriv(param, value[0..]),
+                else => unreachable,
+            }
+        }
+    }
 };
 
 // alBufferData
diff --git a/src/main.zig b/src/main.zig
index 249d7c7..fc13fa8 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -73,15 +73,13 @@ pub const Listener = struct {
 
     pub fn setPosition(self: Listener, position: [3]f32) !void {
         try checkContext(self.context);
-        al.listener.setFloatVector(al.POSITION, &position);
+        al.listener.set([3]f32, al.POSITION, position);
     }
 
     pub fn setOrientation(self: Listener, at: [3]f32, up: [3]f32) !void {
         try checkContext(self.context);
-        al.listener.setFloatVector(al.ORIENTATION, &[_]f32 {
-            at[0], at[1], at[2],
-            up[0], up[1], up[2],
-        });
+        const orientation = [_]f32{ at[0], at[1], at[2], up[0], up[1], up[2] };
+        al.listener.set(@TypeOf(orientation), al.ORIENTATION, orientation);
     }
 };