all: update to latest Zig APIs (zig fmt)

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2023-06-29 09:54:32 -07:00
parent d95a453e78
commit 4bc32adeb8
61 changed files with 806 additions and 806 deletions

View file

@ -19,7 +19,7 @@ pub inline fn readPrecise(timer: *Timer) u64 {
/// Reads the timer value since start or the last reset in seconds.
pub inline fn read(timer: *Timer) f32 {
return @floatFromInt(f32, timer.readPrecise()) / @floatFromInt(f32, std.time.ns_per_s);
return @as(f32, @floatFromInt(timer.readPrecise())) / @as(f32, @floatFromInt(std.time.ns_per_s));
}
/// Resets the timer value to 0/now.
@ -34,5 +34,5 @@ pub inline fn lapPrecise(timer: *Timer) u64 {
/// Returns the current value of the timer in seconds, then resets it.
pub inline fn lap(timer: *Timer) f32 {
return @floatFromInt(f32, timer.lapPrecise()) / @floatFromInt(f32, std.time.ns_per_s);
return @as(f32, @floatFromInt(timer.lapPrecise())) / @as(f32, @floatFromInt(std.time.ns_per_s));
}

View file

@ -39,7 +39,7 @@ pub export fn mach_core_init() ?*MachCoreInstance {
}
pub export fn mach_core_deinit(_core: *MachCoreInstance) void {
var core = @ptrCast(*native.Core, @alignCast(@alignOf(@TypeOf(_core)), _core));
var core = @as(*native.Core, @ptrCast(@alignCast(@alignOf(@TypeOf(_core)), _core)));
native.Core.deinit(core);
}
@ -50,13 +50,13 @@ pub const MachCoreEventIterator = extern struct {
pub const MachCoreEvent = Core.Event;
pub export fn mach_core_poll_events(_core: *MachCoreInstance) MachCoreEventIterator {
var core = @ptrCast(*native.Core, @alignCast(@alignOf(@TypeOf(_core)), _core));
var core = @as(*native.Core, @ptrCast(@alignCast(@alignOf(@TypeOf(_core)), _core)));
var iter = native.Core.pollEvents(core);
return @ptrCast(*MachCoreEventIterator, &iter).*;
return @as(*MachCoreEventIterator, @ptrCast(&iter)).*;
}
pub export fn mach_core_event_iterator_next(_iter: *MachCoreEventIterator, event: *MachCoreEvent) bool {
var iter = @ptrCast(*native.Core.EventIterator, @alignCast(@alignOf(@TypeOf(_iter)), _iter));
var iter = @as(*native.Core.EventIterator, @ptrCast(@alignCast(@alignOf(@TypeOf(_iter)), _iter)));
var value = iter.next() orelse return false;
event.* = value;
return true;

View file

@ -155,7 +155,7 @@ pub fn init(core: *Core, allocator: std.mem.Allocator, options: Options) !void {
// Create a device with default limits/features.
const gpu_device = response.adapter.createDevice(&.{
.required_features_count = if (options.required_features) |v| @intCast(u32, v.len) else 0,
.required_features_count = if (options.required_features) |v| @as(u32, @intCast(v.len)) else 0,
.required_features = if (options.required_features) |v| @as(?[*]const gpu.FeatureName, v.ptr) else null,
.required_limits = if (options.required_limits) |limits| @as(?*const gpu.RequiredLimits, &gpu.RequiredLimits{
.limits = limits,
@ -302,8 +302,8 @@ fn initCallbacks(self: *Core) void {
const pf = (window.getUserPointer(UserPtr) orelse unreachable).self;
pf.pushEvent(.{
.mouse_scroll = .{
.xoffset = @floatCast(f32, xoffset),
.yoffset = @floatCast(f32, yoffset),
.xoffset = @as(f32, @floatCast(xoffset)),
.yoffset = @as(f32, @floatCast(yoffset)),
},
});
}
@ -419,8 +419,8 @@ pub fn setDisplayMode(self: *Core, mode: DisplayMode, monitor_index: ?usize) voi
self.window.setAttrib(.floating, false);
self.window.setMonitor(
null,
@intCast(i32, self.last_pos.x),
@intCast(i32, self.last_pos.y),
@as(i32, @intCast(self.last_pos.x)),
@as(i32, @intCast(self.last_pos.y)),
self.last_size.width,
self.last_size.height,
null,

View file

@ -180,8 +180,8 @@ pub fn msgSend(obj: anytype, sel_name: [:0]const u8, args: anytype, comptime Ret
};
// NOTE: func is a var because making it const causes a compile error which I believe is a compiler bug
var func = @ptrCast(FnType, &objc.objc_msgSend);
const sel = objc.sel_getUid(@ptrCast([*c]const u8, sel_name));
var func = @as(FnType, @ptrCast(&objc.objc_msgSend));
const sel = objc.sel_getUid(@as([*c]const u8, @ptrCast(sel_name)));
return @call(.auto, func, .{ obj, sel } ++ args);
}

View file

@ -31,10 +31,10 @@ pub const EventIterator = struct {
const event_int = js.machEventShift();
if (event_int == -1) return null;
const event_type = @enumFromInt(std.meta.Tag(Event), event_int);
const event_type = @as(std.meta.Tag(Event), @enumFromInt(event_int));
return switch (event_type) {
.key_press, .key_repeat => blk: {
const key = @enumFromInt(Key, js.machEventShift());
const key = @as(Key, @enumFromInt(js.machEventShift()));
switch (key) {
.left_shift, .right_shift => self.key_mods.shift = true,
.left_control, .right_control => self.key_mods.control = true,
@ -63,7 +63,7 @@ pub const EventIterator = struct {
continue;
},
.key_release => blk: {
const key = @enumFromInt(Key, js.machEventShift());
const key = @as(Key, @enumFromInt(js.machEventShift()));
switch (key) {
.left_shift, .right_shift => self.key_mods.shift = false,
.left_control, .right_control => self.key_mods.control = false,
@ -83,8 +83,8 @@ pub const EventIterator = struct {
continue;
},
.mouse_motion => blk: {
const x = @floatFromInt(f64, js.machEventShift());
const y = @floatFromInt(f64, js.machEventShift());
const x = @as(f64, @floatFromInt(js.machEventShift()));
const y = @as(f64, @floatFromInt(js.machEventShift()));
self.last_cursor_position = .{
.x = x,
.y = y,
@ -114,14 +114,14 @@ pub const EventIterator = struct {
},
.mouse_scroll => Event{
.mouse_scroll = .{
.xoffset = @floatCast(f32, std.math.sign(js.machEventShiftFloat())),
.yoffset = @floatCast(f32, std.math.sign(js.machEventShiftFloat())),
.xoffset = @as(f32, @floatCast(std.math.sign(js.machEventShiftFloat()))),
.yoffset = @as(f32, @floatCast(std.math.sign(js.machEventShiftFloat()))),
},
},
.framebuffer_resize => blk: {
const width = @intCast(u32, js.machEventShift());
const height = @intCast(u32, js.machEventShift());
const pixel_ratio = @intCast(u32, js.machEventShift());
const width = @as(u32, @intCast(js.machEventShift()));
const height = @as(u32, @intCast(js.machEventShift()));
const pixel_ratio = @as(u32, @intCast(js.machEventShift()));
break :blk Event{
.framebuffer_resize = .{
.width = width * pixel_ratio,
@ -195,7 +195,7 @@ pub fn setDisplayMode(self: *Core, mode: DisplayMode, monitor: ?usize) void {
}
pub fn displayMode(self: *Core) DisplayMode {
return @enumFromInt(DisplayMode, js.machDisplayMode(self.id));
return @as(DisplayMode, @enumFromInt(js.machDisplayMode(self.id)));
}
pub fn setBorder(self: *Core, value: bool) void {
@ -243,10 +243,10 @@ pub fn size(self: *Core) Size {
pub fn setSizeLimit(self: *Core, limit: SizeLimit) void {
js.machCanvasSetSizeLimit(
self.id,
if (limit.min.width) |val| @intCast(i32, val) else -1,
if (limit.min.height) |val| @intCast(i32, val) else -1,
if (limit.max.width) |val| @intCast(i32, val) else -1,
if (limit.max.height) |val| @intCast(i32, val) else -1,
if (limit.min.width) |val| @as(i32, @intCast(val)) else -1,
if (limit.min.height) |val| @as(i32, @intCast(val)) else -1,
if (limit.max.width) |val| @as(i32, @intCast(val)) else -1,
if (limit.max.height) |val| @as(i32, @intCast(val)) else -1,
);
}
@ -268,7 +268,7 @@ pub fn setCursorMode(self: *Core, mode: CursorMode) void {
}
pub fn cursorMode(self: *Core) CursorMode {
return @enumFromInt(CursorMode, js.machCursorMode(self.id));
return @as(CursorMode, @enumFromInt(js.machCursorMode(self.id)));
}
pub fn setCursorShape(self: *Core, shape: CursorShape) void {
@ -276,7 +276,7 @@ pub fn setCursorShape(self: *Core, shape: CursorShape) void {
}
pub fn cursorShape(self: *Core) CursorShape {
return @enumFromInt(CursorShape, js.machCursorShape(self.id));
return @as(CursorShape, @enumFromInt(js.machCursorShape(self.id)));
}
pub fn adapter(_: *Core) *gpu.Adapter {

View file

@ -21,5 +21,5 @@ pub fn lap(timer: *Timer) u64 {
const now = js.machPerfNow();
const initial = timer.initial;
timer.initial = now;
return @intFromFloat(u64, now - initial) * std.time.ns_per_ms;
return @as(u64, @intFromFloat(now - initial)) * std.time.ns_per_ms;
}