diff options
| author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-09-18 15:58:13 +0700 |
|---|---|---|
| committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-09-18 15:58:13 +0700 |
| commit | ceac1c57eac2cff4e60f93d63d1082c05f2ce163 (patch) | |
| tree | 6cc386c74916955f423337997b78d2791e8bab06 /src | |
| parent | cfb42e206ff4b9f7dca9d0796b21792629eab902 (diff) | |
| download | zeal-ceac1c57eac2cff4e60f93d63d1082c05f2ce163.tar.gz | |
Remove Context reference from higher-level structs
Diffstat (limited to 'src')
| -rw-r--r-- | src/zeal.zig | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/zeal.zig b/src/zeal.zig index d470fbb..1749e28 100644 --- a/src/zeal.zig +++ b/src/zeal.zig @@ -79,14 +79,12 @@ pub const Context = struct { } }; -pub const Listener = struct { - context: Context, - - pub fn setPosition(self: Listener, position: [3]f32) Error!void { +pub const listener = struct { + pub fn setPosition(position: [3]f32) Error!void { try al.listener.set(al.POSITION, position); } - pub fn setOrientation(self: Listener, at: [3]f32, up: [3]f32) Error!void { + pub fn setOrientation(at: [3]f32, up: [3]f32) Error!void { const orientation = [_]f32{ at[0], at[1], at[2], up[0], up[1], up[2] }; try al.listener.set(al.ORIENTATION, orientation); } @@ -123,13 +121,12 @@ pub const Audio = struct { }; pub const Buffer = struct { - context: Context, reference: u32, - pub fn init(context: Context, audio: Audio) Error!Buffer { + pub fn init(audio: Audio) Error!Buffer { const reference = try al.buffer.create(); try al.buffer.fill(reference, audio.data, audio.frequency); - return Buffer{ .context = context, .reference = reference }; + return Buffer{ .reference = reference }; } pub fn deinit(self: Buffer) Error!void { @@ -138,12 +135,11 @@ pub const Buffer = struct { }; pub const Source = struct { - context: Context, reference: u32, - pub fn init(context: Context) Error!Source { + pub fn init() Error!Source { const reference = try al.source.create(); - return Source{ .context = context, .reference = reference }; + return Source{ .reference = reference }; } pub fn deinit(self: Source) Error!void { @@ -202,13 +198,12 @@ test "Context" { try context.checkCurrent(); } -test "Listener" { +test "listener" { const context = try Context.init(try Device.init(null), &.{}); defer context.device.deinit() catch unreachable; defer context.deinit() catch unreachable; try context.makeCurrent(); - const listener = Listener{ .context = context }; try listener.setPosition(.{ 1, 2, 3 }); try listener.setOrientation(.{ 4, 5, 6 }, .{ 7, 8, 9 }); } |
