all: fix issue with glfw vulkan createWindowSurface; update to new for loop syntax (#713)

This commit is contained in:
Aksel Hjerpbakk 2023-03-02 02:33:17 +01:00 committed by GitHub
parent 5aecbb0ee6
commit 2b6f3fb1d9
Failed to generate hash of commit
14 changed files with 28 additions and 27 deletions

View file

@ -21,7 +21,8 @@ pub const Transcoder = struct {
const h = b.transcoder_init(src.ptr, @intCast(u32, src.len));
return if (!b.transcoder_start_transcoding(h))
error.Unknown
else .{ .handle = h };
else
.{ .handle = h };
}
pub fn deinit(self: Transcoder) void {

View file

@ -67,7 +67,7 @@ pub const ArchetypeStorage = struct {
}
fn debugValidateRow(storage: *ArchetypeStorage, gpa: Allocator, row: anytype) void {
inline for (std.meta.fields(@TypeOf(row))) |field, index| {
inline for (std.meta.fields(@TypeOf(row)), 0..) |field, index| {
const column = storage.columns[index];
if (typeId(field.type) != column.type_id) {
const msg = std.mem.concat(gpa, u8, &.{
@ -148,7 +148,7 @@ pub const ArchetypeStorage = struct {
if (is_debug) storage.debugValidateRow(gpa, row);
const fields = std.meta.fields(@TypeOf(row));
inline for (fields) |field, index| {
inline for (fields, 0..) |field, index| {
const ColumnType = field.type;
if (@sizeOf(ColumnType) == 0) continue;
@ -335,7 +335,7 @@ pub fn Entities(comptime all_components: anytype) type {
pub const Query = Query: {
const namespaces = std.meta.fields(@TypeOf(all_components));
var fields: [namespaces.len]std.builtin.Type.UnionField = undefined;
inline for (namespaces) |namespace, i| {
inline for (namespaces, 0..) |namespace, i| {
const component_enum = std.meta.FieldEnum(namespace.type);
fields[i] = .{
.name = namespace.name,

View file

@ -71,7 +71,7 @@ pub fn Messages(comptime messages: anytype) type {
pub fn MessagesTag(comptime messages: anytype) type {
var fields: []const EnumField = &[0]EnumField{};
const message_fields = std.meta.fields(@TypeOf(messages));
inline for (message_fields) |message_field, index| {
inline for (message_fields, 0..) |message_field, index| {
fields = fields ++ [_]std.builtin.Type.EnumField{.{
.name = message_field.name,
.value = index,

View file

@ -235,12 +235,12 @@ pub inline fn createWindowSurface(vk_instance: anytype, window: Window, vk_alloc
else => @ptrCast(c.VkInstance, vk_instance),
};
return @boolToInt(c.glfwCreateWindowSurface(
return c.glfwCreateWindowSurface(
instance,
window.handle,
if (vk_allocation_callbacks == null) null else @ptrCast(*const c.VkAllocationCallbacks, @alignCast(@alignOf(c.VkAllocationCallbacks), vk_allocation_callbacks)),
@ptrCast(*c.VkSurfaceKHR, @alignCast(@alignOf(c.VkSurfaceKHR), vk_surface_khr)),
) == c.VK_SUCCESS);
);
}
test "vulkanSupported" {

View file

@ -216,7 +216,7 @@ fn intToError(int: c_int) Error {
test {
testing.refAllDeclsRecursive(@This());
var model_file = try std.fs.cwd().openFile( thisDir("/../assets/cube.m3d"), .{});
var model_file = try std.fs.cwd().openFile(thisDir("/../assets/cube.m3d"), .{});
defer model_file.close();
var model_data = try model_file.readToEndAllocOptions(testing.allocator, 1024, 119, @alignOf(u8), 0);
defer testing.allocator.free(model_data);

View file

@ -364,7 +364,7 @@ pub const Context = struct {
if (chmap[0] == null) continue;
var channels = try self.allocator.alloc(main.Channel, chmap.*.*.map.channels);
for (channels) |*ch, i|
for (channels, 0..) |*ch, i|
ch.*.id = fromAlsaChannel(chmap[0][0].map.pos()[i]) catch return error.OpeningDevice;
break :blk channels;
} else {
@ -580,7 +580,7 @@ pub const Player = struct {
}
fn writeLoop(self: *Player) void {
for (self.channels) |*ch, i| {
for (self.channels, 0..) |*ch, i| {
ch.*.ptr = self.sample_buffer.ptr + self.format.frameSize(i);
}

View file

@ -201,7 +201,7 @@ pub const Context = struct {
var ports = try self.allocator.alloc(*c.jack_port_t, device.channels.len);
var dest_ports = try self.allocator.alloc([:0]const u8, ports.len);
var buf: [64]u8 = undefined;
for (device.channels) |_, i| {
for (device.channels, 0..) |_, i| {
const port_name = std.fmt.bufPrintZ(&buf, "playback_{d}", .{i + 1}) catch unreachable;
const dest_name = try std.fmt.allocPrintZ(self.allocator, "{s}:{s}", .{ device.id, port_name });
ports[i] = lib.jack_port_register(self.client, port_name.ptr, c.JACK_DEFAULT_AUDIO_TYPE, c.JackPortIsOutput, 0) orelse
@ -259,7 +259,7 @@ pub const Player = struct {
if (lib.jack_activate(self.client) != 0)
return error.CannotPlay;
for (self.ports) |port, i| {
for (self.ports, 0..) |port, i| {
if (lib.jack_connect(self.client, lib.jack_port_name(port), self.dest_ports[i].ptr) != 0)
return error.CannotPlay;
}
@ -268,7 +268,7 @@ pub const Player = struct {
fn processCallback(n_frames: c.jack_nframes_t, self_opaque: ?*anyopaque) callconv(.C) c_int {
const self = @ptrCast(*Player, @alignCast(@alignOf(*Player), self_opaque.?));
for (self.channels) |*ch, i| {
for (self.channels, 0..) |*ch, i| {
ch.*.ptr = @ptrCast([*]u8, lib.jack_port_get_buffer(self.ports[i], n_frames));
}
self.writeFn(self.user_data, n_frames);
@ -279,7 +279,7 @@ pub const Player = struct {
pub fn play(self: *Player) !void {
self.mutex.lock();
defer self.mutex.unlock();
for (self.ports) |port, i| {
for (self.ports, 0..) |port, i| {
if (lib.jack_connect(self.client, lib.jack_port_name(port), self.dest_ports[i].ptr) != 0)
return error.CannotPlay;
}
@ -288,7 +288,7 @@ pub const Player = struct {
pub fn pause(self: *Player) !void {
self.mutex.lock();
defer self.mutex.unlock();
for (self.ports) |port, i| {
for (self.ports, 0..) |port, i| {
if (lib.jack_disconnect(self.client, lib.jack_port_name(port), self.dest_ports[i].ptr) != 0)
return error.CannotPause;
}
@ -297,7 +297,7 @@ pub const Player = struct {
pub fn paused(self: *Player) bool {
self.mutex.lock();
defer self.mutex.unlock();
for (self.ports) |port, i| {
for (self.ports, 0..) |port, i| {
if (lib.jack_port_connected_to(port, self.dest_ports[i].ptr) == 1)
return false;
}

View file

@ -35,7 +35,7 @@ pub const Context = struct {
std.meta.fieldInfo(backends.BackendContext, b).type,
).Pointer.child.init(allocator, options);
} else {
inline for (std.meta.fields(Backend)) |b, i| {
inline for (std.meta.fields(Backend), 0..) |b, i| {
if (@typeInfo(
std.meta.fieldInfo(backends.BackendContext, @intToEnum(Backend, b.value)).type,
).Pointer.child.init(allocator, options)) |d| {

View file

@ -318,7 +318,7 @@ pub const Player = struct {
buf.*.buffer.*.datas[0].chunk.*.stride = stride;
buf.*.buffer.*.datas[0].chunk.*.size = n_frames * stride;
for (self.channels) |*ch, i| {
for (self.channels, 0..) |*ch, i| {
ch.ptr = @ptrCast([*]u8, buf.*.buffer.*.datas[0].data.?) + self.format.frameSize(i);
}
self.writeFn(self.user_data, n_frames);

View file

@ -239,7 +239,7 @@ pub const Context = struct {
if (self.default_source) |d|
self.allocator.free(d);
}
for (self.devices_info.list.items) |device, i| {
for (self.devices_info.list.items, 0..) |device, i| {
if ((device.mode == .playback and
self.default_sink != null and
std.mem.eql(u8, device.id, self.default_sink.?)) or
@ -295,7 +295,7 @@ pub const Context = struct {
.mode = mode,
.channels = blk: {
var channels = try self.allocator.alloc(main.Channel, info.*.channel_map.channels);
for (channels) |*ch, i|
for (channels, 0..) |*ch, i|
ch.*.id = fromPAChannelPos(info.*.channel_map.map[i]) catch unreachable;
break :blk channels;
},
@ -473,7 +473,7 @@ pub const Player = struct {
return;
}
for (self.channels) |*ch, i| {
for (self.channels, 0..) |*ch, i| {
ch.*.ptr = self.write_ptr + self.format.frameSize(i);
}
@ -644,7 +644,7 @@ pub fn toPAFormat(format: main.Format) !c.pa_sample_format_t {
pub fn toPAChannelMap(channels: []const main.Channel) !c.pa_channel_map {
var channel_map: c.pa_channel_map = undefined;
channel_map.channels = @intCast(u5, channels.len);
for (channels) |ch, i|
for (channels, 0..) |ch, i|
channel_map.map[i] = try toPAChannelPos(ch.id);
return channel_map;
}

View file

@ -742,7 +742,7 @@ pub const Player = struct {
else => unreachable,
}
for (self.channels) |*ch, i| {
for (self.channels, 0..) |*ch, i| {
ch.*.ptr = data + self.format.frameSize(i);
}

View file

@ -13,7 +13,7 @@ pub const Guid = extern union {
};
pub fn initString(s: []const u8) Guid {
var guid = Guid{ .Bytes = undefined };
for (hex_offsets) |hex_offset, i| {
for (hex_offsets, 0..) |hex_offset, i| {
guid.Bytes[i] = decodeHexByte([2]u8{ s[hex_offset], s[hex_offset + 1] });
}
return guid;

View file

@ -118,7 +118,7 @@ pub const Context = struct {
.write_step = @sizeOf(f32),
};
for (player.channels) |*ch, i| {
for (player.channels, 0..) |*ch, i| {
ch.*.ptr = player.buf.ptr + i * channel_size_bytes;
}
@ -186,7 +186,7 @@ pub const Player = struct {
self.writeFn(self.user_data, channel_size);
for (self.channels) |_, i| {
for (self.channels, 0..) |_, i| {
self.buf_js.copyBytes(self.buf[i * channel_size_bytes .. (i + 1) * channel_size_bytes]);
const buf_f32_js = js.constructType("Float32Array", &.{ self.buf_js.get("buffer"), self.buf_js.get("byteOffset"), js.createNumber(channel_size) });
defer buf_f32_js.deinit();