Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The master branch of zig is not currently supported.
Choose the command that matches your desired zig-sdl3 version and run it in your project's root directory:
* For the latest tagged release:
```sh
zig fetch --save git+https://github.com/Gota7/zig-sdl3#v0.1.4
zig fetch --save git+https://github.com/Gota7/zig-sdl3#v0.1.5
```
* For in progress updates (nightly):
```sh
Expand Down
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn build(b: *std.Build) !void {
.version = .{
.major = 0,
.minor = 1,
.patch = 4,
.patch = 5,
},
};

Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.{
.name = .sdl3,
.version = "0.1.4",
.version = "0.1.5",
.minimum_zig_version = "0.15.1",
.dependencies = .{
.sdl = .{
Expand Down
14 changes: 7 additions & 7 deletions src/assert.zig
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ pub fn getDefaultHandler() HandlerC {
///
/// ## Version
/// This function is available since SDL 3.2.0.
pub fn getHandler() struct { handler: HandlerC, user_data: ?*anyopaque } {
pub fn getHandler() struct { HandlerC, ?*anyopaque } {
var user_data: ?*anyopaque = undefined;
const handler = c.SDL_GetAssertionHandler(&user_data).?;
return .{ .handler = handler, .user_data = user_data };
return .{ handler, user_data };
}

/// Get a list of all assertion failures.
Expand Down Expand Up @@ -241,7 +241,7 @@ pub fn setHandler(
) void {
const Cb = struct {
pub fn run(assert_data_c: [*c]const c.SDL_AssertData, user_data_c: ?*anyopaque) callconv(.c) c.SDL_AssertState {
return @intFromEnum(handler.?(@bitCast(assert_data_c.*), @alignCast(@ptrCast(user_data_c))));
return @intFromEnum(handler.?(@bitCast(assert_data_c.*), @ptrCast(@alignCast(user_data_c))));
}
};
c.SDL_SetAssertionHandler(if (handler != null) Cb.run else null, user_data);
Expand All @@ -260,9 +260,9 @@ fn testAssertCallback(assert_data: AssertData, user_data: ?*TestHandlerCallbackD
test "Assert" {
std.testing.refAllDeclsRecursive(@This());

const handler = getHandler();
try std.testing.expectEqual(getDefaultHandler(), handler.handler);
try std.testing.expectEqual(null, handler.user_data);
const handler, const user_data = getHandler();
try std.testing.expectEqual(getDefaultHandler(), handler);
try std.testing.expectEqual(null, user_data);

var data = TestHandlerCallbackData{};
setHandler(TestHandlerCallbackData, testAssertCallback, &data);
Expand All @@ -288,5 +288,5 @@ test "Assert" {
try std.testing.expectEqual(null, getReport());

setHandler(void, null, null);
try std.testing.expectEqual(getDefaultHandler(), getHandler().handler);
try std.testing.expectEqual(getDefaultHandler(), getHandler()[0]);
}
38 changes: 19 additions & 19 deletions src/audio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ pub const Device = packed struct {
/// * `self`: The device instance to query.
///
/// ## Return Value
/// Returns the audio specification of the device as long as the buffer size in sample frames.
/// Returns the audio specification of the device as well as the buffer size in sample frames.
///
/// ## Remarks
/// For an opened device, this will report the format the device is currently using.
Expand All @@ -523,7 +523,7 @@ pub const Device = packed struct {
/// This function is available since SDL 3.2.0.
pub fn getFormat(
self: Device,
) !struct { spec: Spec, buffer_size_frames: usize } {
) !struct { Spec, usize } {
var spec: c.SDL_AudioSpec = undefined;
var buffer_size_frames: c_int = undefined;
const ret = c.SDL_GetAudioDeviceFormat(
Expand All @@ -532,7 +532,7 @@ pub const Device = packed struct {
&buffer_size_frames,
);
try errors.wrapCallBool(ret);
return .{ .spec = Spec.fromSdl(spec), .buffer_size_frames = @intCast(buffer_size_frames) };
return .{ Spec.fromSdl(spec), @intCast(buffer_size_frames) };
}

/// Get the current channel map of an audio device.
Expand Down Expand Up @@ -825,7 +825,7 @@ pub const Device = packed struct {
additional_amount_c: c_int,
total_amount_c: c_int,
) callconv(.c) void {
callback.?(@alignCast(@ptrCast(user_data_c)), .{ .value = stream_c.? }, @intCast(additional_amount_c), @intCast(total_amount_c));
callback.?(@ptrCast(@alignCast(user_data_c)), .{ .value = stream_c.? }, @intCast(additional_amount_c), @intCast(total_amount_c));
}
};
const spec_sdl: c.SDL_AudioSpec = if (spec) |val| val.toSdl() else undefined;
Expand Down Expand Up @@ -985,7 +985,7 @@ pub const Device = packed struct {
) !void {
const Cb = struct {
pub fn run(user_data_c: ?*anyopaque, spec_c: [*c]const c.SDL_AudioSpec, buffer_c: [*c]f32, buffer_len_c: c_int) callconv(.c) void {
callback.?(@alignCast(@ptrCast(user_data_c)), Spec.fromSdl(spec_c.*), buffer_c[0..@intCast(buffer_len_c)]);
callback.?(@ptrCast(@alignCast(user_data_c)), Spec.fromSdl(spec_c.*), buffer_c[0..@intCast(buffer_len_c)]);
}
};
return errors.wrapCallBool(c.SDL_SetAudioPostmixCallback(self.value, Cb.run orelse null, user_data));
Expand Down Expand Up @@ -1162,7 +1162,7 @@ pub const Stream = packed struct {
/// * `self`: The stream to query.
///
/// ## Return Value
/// Returns the input and output formats of the stream.
/// Returns the input and output formats of the stream in that order.
///
/// ## Thread Safety
/// It is safe to call this function from any thread, as it holds a stream-specific mutex while running.
Expand All @@ -1171,13 +1171,13 @@ pub const Stream = packed struct {
/// This function is available since SDL 3.2.0.
pub fn getFormat(
self: Stream,
) !struct { input_format: Spec, output_format: Spec } {
) !struct { Spec, Spec } {
var input_format: c.SDL_AudioSpec = undefined;
var output_format: c.SDL_AudioSpec = undefined;
try errors.wrapCallBool(c.SDL_GetAudioStreamFormat(self.value, &input_format, &output_format));
return .{
.input_format = Spec.fromSdl(input_format),
.output_format = Spec.fromSdl(output_format),
Spec.fromSdl(input_format),
Spec.fromSdl(output_format),
};
}

Expand Down Expand Up @@ -1598,7 +1598,7 @@ pub const Stream = packed struct {
additional_amount_c: c_int,
total_amount_c: c_int,
) callconv(.c) void {
callback.?(@alignCast(@ptrCast(user_data_c)), .{ .value = stream_c.? }, @intCast(additional_amount_c), @intCast(total_amount_c));
callback.?(@ptrCast(@alignCast(user_data_c)), .{ .value = stream_c.? }, @intCast(additional_amount_c), @intCast(total_amount_c));
}
};
_ = c.SDL_SetAudioStreamGetCallback(
Expand Down Expand Up @@ -1747,7 +1747,7 @@ pub const Stream = packed struct {
additional_amount_c: c_int,
total_amount_c: c_int,
) callconv(.c) void {
callback.?(@alignCast(@ptrCast(user_data_c)), .{ .value = stream_c.? }, @intCast(additional_amount_c), @intCast(total_amount_c));
callback.?(@ptrCast(@alignCast(user_data_c)), .{ .value = stream_c.? }, @intCast(additional_amount_c), @intCast(total_amount_c));
}
};
_ = c.SDL_SetAudioStreamPutCallback(
Expand Down Expand Up @@ -2050,7 +2050,7 @@ pub fn getRecordingDevices() ![]Device {
/// * `path`: The file path for the WAV to open.
///
/// ## Return Value
/// Returns the audio spec of the WAV along with its data.
/// Returns the audio spec of the WAV along with its data in that order.
/// The `data` must be freed with `free()`.
///
/// ## Remarks
Expand All @@ -2064,7 +2064,7 @@ pub fn getRecordingDevices() ![]Device {
/// This function is available since SDL 3.2.0.
pub fn loadWav(
path: [:0]const u8,
) !struct { spec: Spec, data: []u8 } {
) !struct { Spec, []u8 } {
var data: [*c]u8 = undefined;
var len: u32 = undefined;
var spec: c.SDL_AudioSpec = undefined;
Expand All @@ -2075,8 +2075,8 @@ pub fn loadWav(
&len,
));
return .{
.spec = Spec.fromSdl(spec),
.data = data[0..@intCast(len)],
Spec.fromSdl(spec),
data[0..@intCast(len)],
};
}

Expand All @@ -2087,7 +2087,7 @@ pub fn loadWav(
/// * `close_io`: Will close the `src` before returning, even on error.
///
/// ## Return Value
/// Returns the audio spec of the WAV along with its data.
/// Returns the audio spec of the WAV along with its data in that order.
/// The `data` must be freed with `free()`.
///
/// ## Remarks
Expand Down Expand Up @@ -2121,7 +2121,7 @@ pub fn loadWav(
pub fn loadWavIo(
src: io_stream.Stream,
close_io: bool,
) !struct { spec: Spec, data: []u8 } {
) !struct { Spec, []u8 } {
var data: [*c]u8 = undefined;
var len: u32 = undefined;
var spec: c.SDL_AudioSpec = undefined;
Expand All @@ -2133,8 +2133,8 @@ pub fn loadWavIo(
&len,
));
return .{
.spec = Spec.fromSdl(spec),
.data = data[0..@intCast(len)],
Spec.fromSdl(spec),
data[0..@intCast(len)],
};
}

Expand Down
10 changes: 5 additions & 5 deletions src/camera.zig
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub const Camera = packed struct {
///
/// ## Return Value
/// Returns a new frame of video on success, `null` if none is currently available.
/// Also returns frame's timestamp, or `null` on error.
/// Also returns frame's timestamp in nanoseconds, or `null` on error.
///
/// ## Remarks
/// The frame is a memory pointer to the image data, whose size and format are given by the spec requested when opening the device.
Expand Down Expand Up @@ -185,13 +185,13 @@ pub const Camera = packed struct {
/// This function is available since SDL 3.2.0.
pub fn acquireFrame(
self: Camera,
) struct { frame: ?surface.Surface, timestamp_nanoseconds: ?u64 } {
) struct { ?surface.Surface, ?u64 } {
var timestamp_nanoseconds: u64 = undefined;
const ret = c.SDL_AcquireCameraFrame(
self.value,
&timestamp_nanoseconds,
);
return .{ .frame = if (ret != null) .{ .value = ret } else null, .timestamp_nanoseconds = if (timestamp_nanoseconds == 0) null else timestamp_nanoseconds };
return .{ if (ret != null) .{ .value = ret } else null, if (timestamp_nanoseconds == 0) null else timestamp_nanoseconds };
}

/// Use this function to shut down camera processing and close the camera device.
Expand Down Expand Up @@ -571,8 +571,8 @@ test "Camera" {
_ = cam.getFormat() catch {};
_ = cam.getPermissionState();
_ = cam.getProperties() catch {};
const frame = cam.acquireFrame();
if (frame.frame) |frame_surface| cam.releaseFrame(frame_surface);
const frame, _ = cam.acquireFrame();
if (frame) |frame_surface| cam.releaseFrame(frame_surface);
}
}
}
Expand Down
Loading