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

@ -94,11 +94,11 @@ pub const CompressorParams = struct {
} }
pub fn getPackUASTCFlags(self: CompressorParams) PackUASTCFlags { pub fn getPackUASTCFlags(self: CompressorParams) PackUASTCFlags {
return @bitCast(PackUASTCFlags, b.compressor_params_get_pack_uastc_flags(self.handle)); return @as(PackUASTCFlags, @bitCast(b.compressor_params_get_pack_uastc_flags(self.handle)));
} }
pub fn setPackUASTCFlags(self: CompressorParams, flags: PackUASTCFlags) void { pub fn setPackUASTCFlags(self: CompressorParams, flags: PackUASTCFlags) void {
b.compressor_params_set_pack_uastc_flags(self.handle, @bitCast(u32, flags)); b.compressor_params_set_pack_uastc_flags(self.handle, @as(u32, @bitCast(flags)));
} }
pub fn setBasisFormat(self: CompressorParams, format: BasisTextureFormat) void { pub fn setBasisFormat(self: CompressorParams, format: BasisTextureFormat) void {

View file

@ -18,7 +18,7 @@ pub const Transcoder = struct {
handle: *b.BasisFile, handle: *b.BasisFile,
pub fn init(src: []const u8) error{Unknown}!Transcoder { pub fn init(src: []const u8) error{Unknown}!Transcoder {
const h = b.transcoder_init(src.ptr, @intCast(u32, src.len)); const h = b.transcoder_init(src.ptr, @as(u32, @intCast(src.len)));
return if (!b.transcoder_start_transcoding(h)) return if (!b.transcoder_start_transcoding(h))
error.Unknown error.Unknown
else else
@ -101,11 +101,11 @@ pub const Transcoder = struct {
if (!b.transcoder_transcode( if (!b.transcoder_transcode(
self.handle, self.handle,
out_buf.ptr, out_buf.ptr,
@intCast(u32, out_buf.len), @as(u32, @intCast(out_buf.len)),
image_index, image_index,
level_index, level_index,
@intFromEnum(format), @intFromEnum(format),
@bitCast(u32, params.decode_flags), @as(u32, @bitCast(params.decode_flags)),
params.output_row_pitch orelse 0, params.output_row_pitch orelse 0,
params.output_rows orelse 0, params.output_rows orelse 0,
)) return error.Unknown; )) return error.Unknown;

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. /// Reads the timer value since start or the last reset in seconds.
pub inline fn read(timer: *Timer) f32 { 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. /// 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. /// Returns the current value of the timer in seconds, then resets it.
pub inline fn lap(timer: *Timer) f32 { 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 { 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); native.Core.deinit(core);
} }
@ -50,13 +50,13 @@ pub const MachCoreEventIterator = extern struct {
pub const MachCoreEvent = Core.Event; pub const MachCoreEvent = Core.Event;
pub export fn mach_core_poll_events(_core: *MachCoreInstance) MachCoreEventIterator { 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); 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 { 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; var value = iter.next() orelse return false;
event.* = value; event.* = value;
return true; 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. // Create a device with default limits/features.
const gpu_device = response.adapter.createDevice(&.{ 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_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{ .required_limits = if (options.required_limits) |limits| @as(?*const gpu.RequiredLimits, &gpu.RequiredLimits{
.limits = limits, .limits = limits,
@ -302,8 +302,8 @@ fn initCallbacks(self: *Core) void {
const pf = (window.getUserPointer(UserPtr) orelse unreachable).self; const pf = (window.getUserPointer(UserPtr) orelse unreachable).self;
pf.pushEvent(.{ pf.pushEvent(.{
.mouse_scroll = .{ .mouse_scroll = .{
.xoffset = @floatCast(f32, xoffset), .xoffset = @as(f32, @floatCast(xoffset)),
.yoffset = @floatCast(f32, yoffset), .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.setAttrib(.floating, false);
self.window.setMonitor( self.window.setMonitor(
null, null,
@intCast(i32, self.last_pos.x), @as(i32, @intCast(self.last_pos.x)),
@intCast(i32, self.last_pos.y), @as(i32, @intCast(self.last_pos.y)),
self.last_size.width, self.last_size.width,
self.last_size.height, self.last_size.height,
null, 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 // 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); var func = @as(FnType, @ptrCast(&objc.objc_msgSend));
const sel = objc.sel_getUid(@ptrCast([*c]const u8, sel_name)); const sel = objc.sel_getUid(@as([*c]const u8, @ptrCast(sel_name)));
return @call(.auto, func, .{ obj, sel } ++ args); return @call(.auto, func, .{ obj, sel } ++ args);
} }

View file

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

View file

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

View file

@ -37,12 +37,12 @@ pub const CharmapIterator = struct {
return .{ return .{
.face = face, .face = face,
.index = i, .index = i,
.charcode = @intCast(u32, cc), .charcode = @as(u32, @intCast(cc)),
}; };
} }
pub fn next(self: *CharmapIterator) ?u32 { pub fn next(self: *CharmapIterator) ?u32 {
self.charcode = @intCast(u32, c.FT_Get_Next_Char(self.face.handle, self.charcode, &self.index)); self.charcode = @as(u32, @intCast(c.FT_Get_Next_Char(self.face.handle, self.charcode, &self.index)));
return if (self.index != 0) return if (self.index != 0)
self.charcode self.charcode
else else
@ -77,11 +77,11 @@ pub fn attachStream(self: Face, args: OpenArgs) Error!void {
} }
pub fn loadGlyph(self: Face, index: u32, flags: LoadFlags) Error!void { pub fn loadGlyph(self: Face, index: u32, flags: LoadFlags) Error!void {
return intToError(c.FT_Load_Glyph(self.handle, index, @bitCast(i32, flags))); return intToError(c.FT_Load_Glyph(self.handle, index, @as(i32, @bitCast(flags))));
} }
pub fn loadChar(self: Face, char: u32, flags: LoadFlags) Error!void { pub fn loadChar(self: Face, char: u32, flags: LoadFlags) Error!void {
return intToError(c.FT_Load_Char(self.handle, char, @bitCast(i32, flags))); return intToError(c.FT_Load_Char(self.handle, char, @as(i32, @bitCast(flags))));
} }
pub fn setCharSize(self: Face, pt_width: i32, pt_height: i32, horz_resolution: u16, vert_resolution: u16) Error!void { pub fn setCharSize(self: Face, pt_width: i32, pt_height: i32, horz_resolution: u16, vert_resolution: u16) Error!void {
@ -133,16 +133,16 @@ pub fn getKerning(self: Face, left_char_index: u32, right_char_index: u32, mode:
pub fn getTrackKerning(self: Face, point_size: i32, degree: i32) Error!i32 { pub fn getTrackKerning(self: Face, point_size: i32, degree: i32) Error!i32 {
var kerning: c_long = 0; var kerning: c_long = 0;
try intToError(c.FT_Get_Track_Kerning(self.handle, point_size, degree, kerning)); try intToError(c.FT_Get_Track_Kerning(self.handle, point_size, degree, kerning));
return @intCast(i32, kerning); return @as(i32, @intCast(kerning));
} }
pub fn getGlyphName(self: Face, index: u32, buf: []u8) Error!void { pub fn getGlyphName(self: Face, index: u32, buf: []u8) Error!void {
try intToError(c.FT_Get_Glyph_Name(self.handle, index, buf.ptr, @intCast(c_uint, buf.len))); try intToError(c.FT_Get_Glyph_Name(self.handle, index, buf.ptr, @as(c_uint, @intCast(buf.len))));
} }
pub fn getPostscriptName(self: Face) ?[:0]const u8 { pub fn getPostscriptName(self: Face) ?[:0]const u8 {
return if (c.FT_Get_Postscript_Name(self.handle)) |face_name| return if (c.FT_Get_Postscript_Name(self.handle)) |face_name|
std.mem.span(@ptrCast([*:0]const u8, face_name)) std.mem.span(@as([*:0]const u8, @ptrCast(face_name)))
else else
null; null;
} }
@ -160,7 +160,7 @@ pub fn setCharmap(self: Face, char_map: *CharMap) Error!void {
} }
pub fn getFSTypeFlags(self: Face) FSType { pub fn getFSTypeFlags(self: Face) FSType {
return @bitCast(FSType, c.FT_Get_FSType_Flags(self.handle)); return @as(FSType, @bitCast(c.FT_Get_FSType_Flags(self.handle)));
} }
pub fn getCharVariantIndex(self: Face, char: u32, variant_selector: u32) ?u32 { pub fn getCharVariantIndex(self: Face, char: u32, variant_selector: u32) ?u32 {
@ -181,21 +181,21 @@ pub fn getCharVariantIsDefault(self: Face, char: u32, variant_selector: u32) ?bo
pub fn getVariantSelectors(self: Face) ?[]u32 { pub fn getVariantSelectors(self: Face) ?[]u32 {
return if (c.FT_Face_GetVariantSelectors(self.handle)) |chars| return if (c.FT_Face_GetVariantSelectors(self.handle)) |chars|
@ptrCast([]u32, std.mem.sliceTo(@ptrCast([*:0]u32, chars), 0)) @as([]u32, @ptrCast(std.mem.sliceTo(@as([*:0]u32, @ptrCast(chars)), 0)))
else else
null; null;
} }
pub fn getVariantsOfChar(self: Face, char: u32) ?[]u32 { pub fn getVariantsOfChar(self: Face, char: u32) ?[]u32 {
return if (c.FT_Face_GetVariantsOfChar(self.handle, char)) |variants| return if (c.FT_Face_GetVariantsOfChar(self.handle, char)) |variants|
@ptrCast([]u32, std.mem.sliceTo(@ptrCast([*:0]u32, variants), 0)) @as([]u32, @ptrCast(std.mem.sliceTo(@as([*:0]u32, @ptrCast(variants)), 0)))
else else
null; null;
} }
pub fn getCharsOfVariant(self: Face, variant_selector: u32) ?[]u32 { pub fn getCharsOfVariant(self: Face, variant_selector: u32) ?[]u32 {
return if (c.FT_Face_GetCharsOfVariant(self.handle, variant_selector)) |chars| return if (c.FT_Face_GetCharsOfVariant(self.handle, variant_selector)) |chars|
@ptrCast([]u32, std.mem.sliceTo(@ptrCast([*:0]u32, chars), 0)) @as([]u32, @ptrCast(std.mem.sliceTo(@as([*:0]u32, @ptrCast(chars)), 0)))
else else
null; null;
} }
@ -239,7 +239,7 @@ pub fn getPaint(self: Face, opaque_paint: OpaquePaint) ?Paint {
var p: c.FT_COLR_Paint = undefined; var p: c.FT_COLR_Paint = undefined;
if (c.FT_Get_Paint(self.handle, opaque_paint, &p) == 0) if (c.FT_Get_Paint(self.handle, opaque_paint, &p) == 0)
return null; return null;
return switch (@enumFromInt(PaintFormat, p.format)) { return switch (@as(PaintFormat, @enumFromInt(p.format))) {
.color_layers => Paint{ .color_layers = p.u.colr_layers }, .color_layers => Paint{ .color_layers = p.u.colr_layers },
.glyph => Paint{ .glyph = p.u.glyph }, .glyph => Paint{ .glyph = p.u.glyph },
.solid => Paint{ .solid = p.u.solid }, .solid => Paint{ .solid = p.u.solid },
@ -263,41 +263,41 @@ pub fn newSize(self: Face) Error!Size {
} }
pub fn numFaces(self: Face) u32 { pub fn numFaces(self: Face) u32 {
return @intCast(u32, self.handle.*.num_faces); return @as(u32, @intCast(self.handle.*.num_faces));
} }
pub fn faceIndex(self: Face) u32 { pub fn faceIndex(self: Face) u32 {
return @intCast(u32, self.handle.*.face_index); return @as(u32, @intCast(self.handle.*.face_index));
} }
pub fn faceFlags(self: Face) FaceFlags { pub fn faceFlags(self: Face) FaceFlags {
return @bitCast(FaceFlags, self.handle.*.face_flags); return @as(FaceFlags, @bitCast(self.handle.*.face_flags));
} }
pub fn styleFlags(self: Face) StyleFlags { pub fn styleFlags(self: Face) StyleFlags {
return @bitCast(StyleFlags, self.handle.*.style_flags); return @as(StyleFlags, @bitCast(self.handle.*.style_flags));
} }
pub fn numGlyphs(self: Face) u32 { pub fn numGlyphs(self: Face) u32 {
return @intCast(u32, self.handle.*.num_glyphs); return @as(u32, @intCast(self.handle.*.num_glyphs));
} }
pub fn familyName(self: Face) ?[:0]const u8 { pub fn familyName(self: Face) ?[:0]const u8 {
return if (self.handle.*.family_name) |family| return if (self.handle.*.family_name) |family|
std.mem.span(@ptrCast([*:0]const u8, family)) std.mem.span(@as([*:0]const u8, @ptrCast(family)))
else else
null; null;
} }
pub fn styleName(self: Face) ?[:0]const u8 { pub fn styleName(self: Face) ?[:0]const u8 {
return if (self.handle.*.style_name) |style_name| return if (self.handle.*.style_name) |style_name|
std.mem.span(@ptrCast([*:0]const u8, style_name)) std.mem.span(@as([*:0]const u8, @ptrCast(style_name)))
else else
null; null;
} }
pub fn numFixedSizes(self: Face) u32 { pub fn numFixedSizes(self: Face) u32 {
return @intCast(u32, self.handle.*.num_fixed_sizes); return @as(u32, @intCast(self.handle.*.num_fixed_sizes));
} }
pub fn availableSizes(self: Face) []BitmapSize { pub fn availableSizes(self: Face) []BitmapSize {
@ -309,20 +309,20 @@ pub fn availableSizes(self: Face) []BitmapSize {
pub fn getAdvance(self: Face, glyph_index: u32, load_flags: LoadFlags) Error!i32 { pub fn getAdvance(self: Face, glyph_index: u32, load_flags: LoadFlags) Error!i32 {
var a: c_long = 0; var a: c_long = 0;
try intToError(c.FT_Get_Advance(self.handle, glyph_index, @bitCast(i32, load_flags), &a)); try intToError(c.FT_Get_Advance(self.handle, glyph_index, @as(i32, @bitCast(load_flags)), &a));
return @intCast(i32, a); return @as(i32, @intCast(a));
} }
pub fn getAdvances(self: Face, start: u32, advances_out: []c_long, load_flags: LoadFlags) Error!void { pub fn getAdvances(self: Face, start: u32, advances_out: []c_long, load_flags: LoadFlags) Error!void {
try intToError(c.FT_Get_Advances(self.handle, start, @intCast(u32, advances_out.len), @bitCast(i32, load_flags), advances_out.ptr)); try intToError(c.FT_Get_Advances(self.handle, start, @as(u32, @intCast(advances_out.len)), @as(i32, @bitCast(load_flags)), advances_out.ptr));
} }
pub fn numCharmaps(self: Face) u32 { pub fn numCharmaps(self: Face) u32 {
return @intCast(u32, self.handle.*.num_charmaps); return @as(u32, @intCast(self.handle.*.num_charmaps));
} }
pub fn charmaps(self: Face) []const CharMap { pub fn charmaps(self: Face) []const CharMap {
return @ptrCast([*]const CharMap, self.handle.*.charmaps)[0..self.numCharmaps()]; return @as([*]const CharMap, @ptrCast(self.handle.*.charmaps))[0..self.numCharmaps()];
} }
pub fn bbox(self: Face) BBox { pub fn bbox(self: Face) BBox {

View file

@ -45,11 +45,11 @@ pub fn metrics(self: GlyphSlot) GlyphMetrics {
} }
pub fn linearHoriAdvance(self: GlyphSlot) i32 { pub fn linearHoriAdvance(self: GlyphSlot) i32 {
return @intCast(i32, self.handle.*.linearHoriAdvance); return @as(i32, @intCast(self.handle.*.linearHoriAdvance));
} }
pub fn linearVertAdvance(self: GlyphSlot) i32 { pub fn linearVertAdvance(self: GlyphSlot) i32 {
return @intCast(i32, self.handle.*.linearVertAdvance); return @as(i32, @intCast(self.handle.*.linearVertAdvance));
} }
pub fn advance(self: GlyphSlot) Vector { pub fn advance(self: GlyphSlot) Vector {
@ -57,7 +57,7 @@ pub fn advance(self: GlyphSlot) Vector {
} }
pub fn format(self: GlyphSlot) GlyphFormat { pub fn format(self: GlyphSlot) GlyphFormat {
return @enumFromInt(GlyphFormat, self.handle.*.format); return @as(GlyphFormat, @enumFromInt(self.handle.*.format));
} }
pub fn ownBitmap(self: GlyphSlot) Error!void { pub fn ownBitmap(self: GlyphSlot) Error!void {
@ -81,11 +81,11 @@ pub fn outline(self: GlyphSlot) ?Outline {
} }
pub fn lsbDelta(self: GlyphSlot) i32 { pub fn lsbDelta(self: GlyphSlot) i32 {
return @intCast(i32, self.handle.*.lsb_delta); return @as(i32, @intCast(self.handle.*.lsb_delta));
} }
pub fn rsbDelta(self: GlyphSlot) i32 { pub fn rsbDelta(self: GlyphSlot) i32 {
return @intCast(i32, self.handle.*.rsb_delta); return @as(i32, @intCast(self.handle.*.rsb_delta));
} }
pub fn render(self: GlyphSlot, render_mode: RenderMode) Error!void { pub fn render(self: GlyphSlot, render_mode: RenderMode) Error!void {

View file

@ -116,7 +116,7 @@ pub const PaletteData = struct {
} }
pub fn paletteFlag(self: PaletteData, index: u32) PaletteFlags { pub fn paletteFlag(self: PaletteData, index: u32) PaletteFlags {
return @bitCast(PaletteFlags, self.handle.palette_flags[index]); return @as(PaletteFlags, @bitCast(self.handle.palette_flags[index]));
} }
pub fn numPaletteEntries(self: PaletteData) u16 { pub fn numPaletteEntries(self: PaletteData) u16 {

View file

@ -11,27 +11,27 @@ pub const angel_pi2 = _c.FT_ANGLE_PI2;
pub const angel_pi4 = _c.FT_ANGLE_PI4; pub const angel_pi4 = _c.FT_ANGLE_PI4;
pub fn mulDiv(a: i32, b: i32, c: i32) i32 { pub fn mulDiv(a: i32, b: i32, c: i32) i32 {
return @intCast(i32, _c.FT_MulDiv(a, b, c)); return @as(i32, @intCast(_c.FT_MulDiv(a, b, c)));
} }
pub fn mulFix(a: i32, b: i32) i32 { pub fn mulFix(a: i32, b: i32) i32 {
return @intCast(i32, _c.FT_MulFix(a, b)); return @as(i32, @intCast(_c.FT_MulFix(a, b)));
} }
pub fn divFix(a: i32, b: i32) i32 { pub fn divFix(a: i32, b: i32) i32 {
return @intCast(i32, _c.FT_DivFix(a, b)); return @as(i32, @intCast(_c.FT_DivFix(a, b)));
} }
pub fn roundFix(a: i32) i32 { pub fn roundFix(a: i32) i32 {
return @intCast(i32, _c.FT_RoundFix(a)); return @as(i32, @intCast(_c.FT_RoundFix(a)));
} }
pub fn ceilFix(a: i32) i32 { pub fn ceilFix(a: i32) i32 {
return @intCast(i32, _c.FT_CeilFix(a)); return @as(i32, @intCast(_c.FT_CeilFix(a)));
} }
pub fn floorFix(a: i32) i32 { pub fn floorFix(a: i32) i32 {
return @intCast(i32, _c.FT_FloorFix(a)); return @as(i32, @intCast(_c.FT_FloorFix(a)));
} }
pub fn vectorTransform(vec: *Vector, matrix: Matrix) void { pub fn vectorTransform(vec: *Vector, matrix: Matrix) void {
@ -47,7 +47,7 @@ pub fn matrixInvert(m: *Matrix) Error!void {
} }
pub fn angleDiff(a: i32, b: i32) i32 { pub fn angleDiff(a: i32, b: i32) i32 {
return @intCast(i32, _c.FT_Angle_Diff(a, b)); return @as(i32, @intCast(_c.FT_Angle_Diff(a, b)));
} }
pub fn vectorUnit(vec: *Vector, angle: i32) void { pub fn vectorUnit(vec: *Vector, angle: i32) void {
@ -59,7 +59,7 @@ pub fn vectorRotate(vec: *Vector, angle: i32) void {
} }
pub fn vectorLength(vec: *Vector) i32 { pub fn vectorLength(vec: *Vector) i32 {
return @intCast(i32, _c.FT_Vector_Length(vec)); return @as(i32, @intCast(_c.FT_Vector_Length(vec)));
} }
pub fn vectorPolarize(vec: *Vector, length: *c_long, angle: *c_long) void { pub fn vectorPolarize(vec: *Vector, length: *c_long, angle: *c_long) void {

View file

@ -167,11 +167,11 @@ pub const OpenArgs = struct {
pub fn cast(self: OpenArgs) c.FT_Open_Args { pub fn cast(self: OpenArgs) c.FT_Open_Args {
var oa: c.FT_Open_Args = undefined; var oa: c.FT_Open_Args = undefined;
oa.flags = @bitCast(u32, self.flags); oa.flags = @as(u32, @bitCast(self.flags));
switch (self.data) { switch (self.data) {
.memory => |d| { .memory => |d| {
oa.memory_base = d.ptr; oa.memory_base = d.ptr;
oa.memory_size = @intCast(u31, d.len); oa.memory_size = @as(u31, @intCast(d.len));
}, },
// The Freetype API requires a mutable string. // The Freetype API requires a mutable string.
// This is an oversight, Freetype actually never writes to this string. // This is an oversight, Freetype actually never writes to this string.
@ -179,8 +179,8 @@ pub const OpenArgs = struct {
.stream => |d| oa.stream = d, .stream => |d| oa.stream = d,
.driver => |d| oa.driver = d, .driver => |d| oa.driver = d,
.params => |*d| { .params => |*d| {
oa.params = @ptrFromInt(*c.FT_Parameter, @intFromPtr(d.ptr)); oa.params = @as(*c.FT_Parameter, @ptrFromInt(@intFromPtr(d.ptr)));
oa.num_params = @intCast(u31, d.len); oa.num_params = @as(u31, @intCast(d.len));
}, },
} }
return oa; return oa;
@ -189,5 +189,5 @@ pub const OpenArgs = struct {
pub fn getCharmapIndex(self: [*c]CharMap) ?u32 { pub fn getCharmapIndex(self: [*c]CharMap) ?u32 {
const i = c.FT_Get_Charmap_Index(self); const i = c.FT_Get_Charmap_Index(self);
return if (i == -1) null else @intCast(u32, i); return if (i == -1) null else @as(u32, @intCast(i));
} }

View file

@ -54,24 +54,24 @@ pub const Glyph = struct {
pub fn toBitmapGlyph(self: *Glyph, render_mode: RenderMode, origin: ?Vector) Error!BitmapGlyph { pub fn toBitmapGlyph(self: *Glyph, render_mode: RenderMode, origin: ?Vector) Error!BitmapGlyph {
try intToError(c.FT_Glyph_To_Bitmap(&self.handle, @intFromEnum(render_mode), if (origin) |o| &o else null, 1)); try intToError(c.FT_Glyph_To_Bitmap(&self.handle, @intFromEnum(render_mode), if (origin) |o| &o else null, 1));
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) }; return BitmapGlyph{ .handle = @as(c.FT_BitmapGlyph, @ptrCast(self.handle)) };
} }
pub fn copyBitmapGlyph(self: *Glyph, render_mode: RenderMode, origin: ?Vector) Error!BitmapGlyph { pub fn copyBitmapGlyph(self: *Glyph, render_mode: RenderMode, origin: ?Vector) Error!BitmapGlyph {
try intToError(c.FT_Glyph_To_Bitmap(&self.handle, @intFromEnum(render_mode), if (origin) |o| &o else null, 0)); try intToError(c.FT_Glyph_To_Bitmap(&self.handle, @intFromEnum(render_mode), if (origin) |o| &o else null, 0));
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) }; return BitmapGlyph{ .handle = @as(c.FT_BitmapGlyph, @ptrCast(self.handle)) };
} }
pub fn castBitmapGlyph(self: Glyph) Error!BitmapGlyph { pub fn castBitmapGlyph(self: Glyph) Error!BitmapGlyph {
return BitmapGlyph{ .handle = @ptrCast(c.FT_BitmapGlyph, self.handle) }; return BitmapGlyph{ .handle = @as(c.FT_BitmapGlyph, @ptrCast(self.handle)) };
} }
pub fn castOutlineGlyph(self: Glyph) Error!OutlineGlyph { pub fn castOutlineGlyph(self: Glyph) Error!OutlineGlyph {
return OutlineGlyph{ .handle = @ptrCast(c.FT_OutlineGlyph, self.handle) }; return OutlineGlyph{ .handle = @as(c.FT_OutlineGlyph, @ptrCast(self.handle)) };
} }
pub fn castSvgGlyph(self: Glyph) Error!SvgGlyph { pub fn castSvgGlyph(self: Glyph) Error!SvgGlyph {
return SvgGlyph{ .handle = @ptrCast(c.FT_SvgGlyph, self.handle) }; return SvgGlyph{ .handle = @as(c.FT_SvgGlyph, @ptrCast(self.handle)) };
} }
pub fn stroke(self: *Glyph, stroker: Stroker) Error!void { pub fn stroke(self: *Glyph, stroker: Stroker) Error!void {
@ -83,7 +83,7 @@ pub const Glyph = struct {
} }
pub fn format(self: Glyph) GlyphFormat { pub fn format(self: Glyph) GlyphFormat {
return @enumFromInt(GlyphFormat, self.handle.*.format); return @as(GlyphFormat, @enumFromInt(self.handle.*.format));
} }
pub fn advanceX(self: Glyph) isize { pub fn advanceX(self: Glyph) isize {
@ -99,7 +99,7 @@ const SvgGlyph = struct {
handle: c.FT_SvgGlyph, handle: c.FT_SvgGlyph,
pub fn deinit(self: SvgGlyph) void { pub fn deinit(self: SvgGlyph) void {
c.FT_Done_Glyph(@ptrCast(c.FT_Glyph, self.handle)); c.FT_Done_Glyph(@as(c.FT_Glyph, @ptrCast(self.handle)));
} }
pub fn svgBuffer(self: SvgGlyph) []const u8 { pub fn svgBuffer(self: SvgGlyph) []const u8 {
@ -143,7 +143,7 @@ pub const BitmapGlyph = struct {
handle: c.FT_BitmapGlyph, handle: c.FT_BitmapGlyph,
pub fn deinit(self: BitmapGlyph) void { pub fn deinit(self: BitmapGlyph) void {
c.FT_Done_Glyph(@ptrCast(c.FT_Glyph, self.handle)); c.FT_Done_Glyph(@as(c.FT_Glyph, @ptrCast(self.handle)));
} }
pub fn left(self: BitmapGlyph) i32 { pub fn left(self: BitmapGlyph) i32 {
@ -163,7 +163,7 @@ pub const OutlineGlyph = struct {
handle: c.FT_OutlineGlyph, handle: c.FT_OutlineGlyph,
pub fn deinit(self: OutlineGlyph) void { pub fn deinit(self: OutlineGlyph) void {
c.FT_Done_Glyph(@ptrCast(c.FT_Glyph, self.handle)); c.FT_Done_Glyph(@as(c.FT_Glyph, @ptrCast(self.handle)));
} }
pub fn outline(self: OutlineGlyph) Outline { pub fn outline(self: OutlineGlyph) Outline {

View file

@ -13,13 +13,13 @@ pub const Blob = struct {
pub fn init(data: []u8, mode: MemoryMode) ?Blob { pub fn init(data: []u8, mode: MemoryMode) ?Blob {
return Blob{ return Blob{
.handle = c.hb_blob_create_or_fail(&data[0], @intCast(c_uint, data.len), @intFromEnum(mode), null, null) orelse return null, .handle = c.hb_blob_create_or_fail(&data[0], @as(c_uint, @intCast(data.len)), @intFromEnum(mode), null, null) orelse return null,
}; };
} }
pub fn initOrEmpty(data: []u8, mode: MemoryMode) Blob { pub fn initOrEmpty(data: []u8, mode: MemoryMode) Blob {
return .{ return .{
.handle = c.hb_blob_create(&data[0], @intCast(c_uint, data.len), @intFromEnum(mode), null, null).?, .handle = c.hb_blob_create(&data[0], @as(c_uint, @intCast(data.len)), @intFromEnum(mode), null, null).?,
}; };
} }

View file

@ -31,7 +31,7 @@ pub const GlyphInfo = extern struct {
var2: u32, var2: u32,
pub fn getFlags(self: GlyphInfo) GlyphFlags { pub fn getFlags(self: GlyphInfo) GlyphFlags {
return @bitCast(GlyphFlags, hb_glyph_info_get_glyph_flags(&self)); return @as(GlyphFlags, @bitCast(hb_glyph_info_get_glyph_flags(&self)));
} }
}; };
@ -56,8 +56,8 @@ pub const SegmentProps = struct {
pub fn from(c_struct: c.hb_segment_properties_t) SegmentProps { pub fn from(c_struct: c.hb_segment_properties_t) SegmentProps {
return .{ return .{
.direction = @enumFromInt(Direction, c_struct.direction), .direction = @as(Direction, @enumFromInt(c_struct.direction)),
.script = @enumFromInt(Script, c_struct.script), .script = @as(Script, @enumFromInt(c_struct.script)),
.language = Language{ .handle = c_struct.language }, .language = Language{ .handle = c_struct.language },
}; };
} }
@ -173,23 +173,23 @@ pub const Buffer = struct {
} }
pub fn addCodepoints(self: Buffer, text: []const u32, item_offset: u32, item_length: ?u31) void { pub fn addCodepoints(self: Buffer, text: []const u32, item_offset: u32, item_length: ?u31) void {
c.hb_buffer_add_codepoints(self.handle, &text[0], @intCast(c_int, text.len), item_offset, if (item_length) |l| l else @intCast(c_int, text.len)); c.hb_buffer_add_codepoints(self.handle, &text[0], @as(c_int, @intCast(text.len)), item_offset, if (item_length) |l| l else @as(c_int, @intCast(text.len)));
} }
pub fn addUTF32(self: Buffer, text: []const u32, item_offset: u32, item_length: ?u31) void { pub fn addUTF32(self: Buffer, text: []const u32, item_offset: u32, item_length: ?u31) void {
c.hb_buffer_add_utf32(self.handle, &text[0], @intCast(c_int, text.len), item_offset, if (item_length) |l| l else @intCast(c_int, text.len)); c.hb_buffer_add_utf32(self.handle, &text[0], @as(c_int, @intCast(text.len)), item_offset, if (item_length) |l| l else @as(c_int, @intCast(text.len)));
} }
pub fn addUTF16(self: Buffer, text: []const u16, item_offset: u32, item_length: ?u31) void { pub fn addUTF16(self: Buffer, text: []const u16, item_offset: u32, item_length: ?u31) void {
c.hb_buffer_add_utf16(self.handle, &text[0], @intCast(c_int, text.len), item_offset, if (item_length) |l| l else @intCast(c_int, text.len)); c.hb_buffer_add_utf16(self.handle, &text[0], @as(c_int, @intCast(text.len)), item_offset, if (item_length) |l| l else @as(c_int, @intCast(text.len)));
} }
pub fn addUTF8(self: Buffer, text: []const u8, item_offset: u32, item_length: ?u31) void { pub fn addUTF8(self: Buffer, text: []const u8, item_offset: u32, item_length: ?u31) void {
c.hb_buffer_add_utf8(self.handle, &text[0], @intCast(c_int, text.len), item_offset, if (item_length) |l| l else @intCast(c_int, text.len)); c.hb_buffer_add_utf8(self.handle, &text[0], @as(c_int, @intCast(text.len)), item_offset, if (item_length) |l| l else @as(c_int, @intCast(text.len)));
} }
pub fn addLatin1(self: Buffer, text: []const u8, item_offset: u32, item_length: ?u31) void { pub fn addLatin1(self: Buffer, text: []const u8, item_offset: u32, item_length: ?u31) void {
c.hb_buffer_add_latin1(self.handle, &text[0], @intCast(c_int, text.len), item_offset, if (item_length) |l| l else @intCast(c_int, text.len)); c.hb_buffer_add_latin1(self.handle, &text[0], @as(c_int, @intCast(text.len)), item_offset, if (item_length) |l| l else @as(c_int, @intCast(text.len)));
} }
pub fn append(self: Buffer, source: Buffer, start: u32, end: u32) void { pub fn append(self: Buffer, source: Buffer, start: u32, end: u32) void {
@ -197,7 +197,7 @@ pub const Buffer = struct {
} }
pub fn getContentType(self: Buffer) ContentType { pub fn getContentType(self: Buffer) ContentType {
return @enumFromInt(ContentType, c.hb_buffer_get_content_type(self.handle)); return @as(ContentType, @enumFromInt(c.hb_buffer_get_content_type(self.handle)));
} }
pub fn setContentType(self: Buffer, content_type: ContentType) void { pub fn setContentType(self: Buffer, content_type: ContentType) void {
@ -205,7 +205,7 @@ pub const Buffer = struct {
} }
pub fn getDirection(self: Buffer) Direction { pub fn getDirection(self: Buffer) Direction {
return @enumFromInt(Direction, c.hb_buffer_get_direction(self.handle)); return @as(Direction, @enumFromInt(c.hb_buffer_get_direction(self.handle)));
} }
pub fn setDirection(self: Buffer, direction: Direction) void { pub fn setDirection(self: Buffer, direction: Direction) void {
@ -213,7 +213,7 @@ pub const Buffer = struct {
} }
pub fn getScript(self: Buffer) Script { pub fn getScript(self: Buffer) Script {
return @enumFromInt(Script, c.hb_buffer_get_script(self.handle)); return @as(Script, @enumFromInt(c.hb_buffer_get_script(self.handle)));
} }
pub fn setScript(self: Buffer, script: Script) void { pub fn setScript(self: Buffer, script: Script) void {
@ -229,15 +229,15 @@ pub const Buffer = struct {
} }
pub fn getFlags(self: Buffer) Flags { pub fn getFlags(self: Buffer) Flags {
return @bitCast(Flags, c.hb_buffer_get_flags(self.handle)); return @as(Flags, @bitCast(c.hb_buffer_get_flags(self.handle)));
} }
pub fn setFlags(self: Buffer, flags: Flags) void { pub fn setFlags(self: Buffer, flags: Flags) void {
c.hb_buffer_set_flags(self.handle, @bitCast(u32, flags)); c.hb_buffer_set_flags(self.handle, @as(u32, @bitCast(flags)));
} }
pub fn getClusterLevel(self: Buffer) ClusterLevel { pub fn getClusterLevel(self: Buffer) ClusterLevel {
return @enumFromInt(ClusterLevel, c.hb_buffer_get_cluster_level(self.handle)); return @as(ClusterLevel, @enumFromInt(c.hb_buffer_get_cluster_level(self.handle)));
} }
pub fn setClusterLevel(self: Buffer, level: ClusterLevel) void { pub fn setClusterLevel(self: Buffer, level: ClusterLevel) void {
@ -275,7 +275,7 @@ pub const Buffer = struct {
pub fn getGlyphPositions(self: Buffer) ?[]Position { pub fn getGlyphPositions(self: Buffer) ?[]Position {
var length: u32 = 0; var length: u32 = 0;
return if (hb_buffer_get_glyph_positions(self.handle, &length)) |positions| return if (hb_buffer_get_glyph_positions(self.handle, &length)) |positions|
@ptrCast([*]Position, positions)[0..length] @as([*]Position, @ptrCast(positions))[0..length]
else else
null; null;
} }
@ -325,7 +325,7 @@ pub const Buffer = struct {
} }
pub fn diff(self: Buffer, ref: Buffer, dottedcircle_glyph: u32, position_fuzz: u32) DiffFlags { pub fn diff(self: Buffer, ref: Buffer, dottedcircle_glyph: u32, position_fuzz: u32) DiffFlags {
return @bitCast(DiffFlags, c.hb_buffer_diff(self.handle, ref.handle, dottedcircle_glyph, position_fuzz)); return @as(DiffFlags, @bitCast(c.hb_buffer_diff(self.handle, ref.handle, dottedcircle_glyph, position_fuzz)));
} }
}; };

View file

@ -9,11 +9,11 @@ pub const Direction = enum(u3) {
bit = c.HB_DIRECTION_BTT, bit = c.HB_DIRECTION_BTT,
pub fn fromString(str: []const u8) Direction { pub fn fromString(str: []const u8) Direction {
return @enumFromInt(Direction, c.hb_direction_from_string(str.ptr, @intCast(c_int, str.len))); return @as(Direction, @enumFromInt(c.hb_direction_from_string(str.ptr, @as(c_int, @intCast(str.len)))));
} }
pub fn toString(self: Direction) [:0]const u8 { pub fn toString(self: Direction) [:0]const u8 {
return std.mem.span(@ptrCast([*:0]const u8, c.hb_direction_to_string(@intFromEnum(self)))); return std.mem.span(@as([*:0]const u8, @ptrCast(c.hb_direction_to_string(@intFromEnum(self)))));
} }
}; };
@ -184,11 +184,11 @@ pub const Script = enum(u31) {
invalid = c.HB_SCRIPT_INVALID, invalid = c.HB_SCRIPT_INVALID,
pub fn fromISO15924Tag(tag: Tag) Script { pub fn fromISO15924Tag(tag: Tag) Script {
return @enumFromInt(Script, c.hb_script_from_iso15924_tag(tag.handle)); return @as(Script, @enumFromInt(c.hb_script_from_iso15924_tag(tag.handle)));
} }
pub fn fromString(str: []const u8) Script { pub fn fromString(str: []const u8) Script {
return @enumFromInt(Script, c.hb_script_from_string(str.ptr, @intCast(c_int, str.len))); return @as(Script, @enumFromInt(c.hb_script_from_string(str.ptr, @as(c_int, @intCast(str.len)))));
} }
pub fn toISO15924Tag(self: Script) Tag { pub fn toISO15924Tag(self: Script) Tag {
@ -196,7 +196,7 @@ pub const Script = enum(u31) {
} }
pub fn getHorizontalDirection(self: Script) Direction { pub fn getHorizontalDirection(self: Script) Direction {
return @enumFromInt(Direction, c.hb_script_get_horizontal_direction(@intFromEnum(self))); return @as(Direction, @enumFromInt(c.hb_script_get_horizontal_direction(@intFromEnum(self))));
} }
}; };
@ -205,12 +205,12 @@ pub const Language = struct {
pub fn fromString(name: []const u8) Language { pub fn fromString(name: []const u8) Language {
return .{ return .{
.handle = c.hb_language_from_string(name.ptr, @intCast(c_int, name.len)), .handle = c.hb_language_from_string(name.ptr, @as(c_int, @intCast(name.len))),
}; };
} }
pub fn toString(self: Language) [:0]const u8 { pub fn toString(self: Language) [:0]const u8 {
return std.mem.span(@ptrCast([*:0]const u8, c.hb_language_to_string(self.handle))); return std.mem.span(@as([*:0]const u8, @ptrCast(c.hb_language_to_string(self.handle))));
} }
pub fn getDefault() Language { pub fn getDefault() Language {
@ -226,14 +226,14 @@ pub const Feature = extern struct {
pub fn fromString(str: []const u8) ?Feature { pub fn fromString(str: []const u8) ?Feature {
var f: Feature = undefined; var f: Feature = undefined;
return if (hb_feature_from_string(str.ptr, @intCast(c_int, str.len), &f) > 1) return if (hb_feature_from_string(str.ptr, @as(c_int, @intCast(str.len)), &f) > 1)
f f
else else
null; null;
} }
pub fn toString(self: *Feature, buf: []u8) void { pub fn toString(self: *Feature, buf: []u8) void {
hb_feature_to_string(self, buf.ptr, @intCast(c_uint, buf.len)); hb_feature_to_string(self, buf.ptr, @as(c_uint, @intCast(buf.len)));
} }
}; };
@ -243,14 +243,14 @@ pub const Variation = extern struct {
pub fn fromString(str: []const u8) ?Variation { pub fn fromString(str: []const u8) ?Variation {
var v: Variation = undefined; var v: Variation = undefined;
return if (hb_variation_from_string(str.ptr, @intCast(c_int, str.len), &v) > 1) return if (hb_variation_from_string(str.ptr, @as(c_int, @intCast(str.len)), &v) > 1)
v v
else else
null; null;
} }
pub fn toString(self: *Variation, buf: []u8) void { pub fn toString(self: *Variation, buf: []u8) void {
hb_variation_to_string(self, buf.ptr, @intCast(c_uint, buf.len)); hb_variation_to_string(self, buf.ptr, @as(c_uint, @intCast(buf.len)));
} }
pub fn tag(self: Variation) Tag { pub fn tag(self: Variation) Tag {
@ -266,7 +266,7 @@ pub const Tag = struct {
handle: u32, handle: u32,
pub fn fromString(str: []const u8) Tag { pub fn fromString(str: []const u8) Tag {
return .{ .handle = c.hb_tag_from_string(str.ptr, @intCast(c_int, str.len)) }; return .{ .handle = c.hb_tag_from_string(str.ptr, @as(c_int, @intCast(str.len))) };
} }
pub fn toString(self: Tag) []const u8 { pub fn toString(self: Tag) []const u8 {

View file

@ -33,7 +33,7 @@ pub const Font = struct {
} }
pub fn setFreetypeLoadFlags(self: Font, flags: freetype.LoadFlags) void { pub fn setFreetypeLoadFlags(self: Font, flags: freetype.LoadFlags) void {
c.hb_ft_font_set_load_flags(self.handle, @bitCast(i32, flags)); c.hb_ft_font_set_load_flags(self.handle, @as(i32, @bitCast(flags)));
} }
pub fn getFace(self: Font) Face { pub fn getFace(self: Font) Face {
@ -60,7 +60,7 @@ pub const Font = struct {
var x: c_uint = 0; var x: c_uint = 0;
var y: c_uint = 0; var y: c_uint = 0;
c.hb_font_get_ppem(self.handle, &x, &y); c.hb_font_get_ppem(self.handle, &x, &y);
return @Vector(2, u32){ @intCast(u32, x), @intCast(u32, y) }; return @Vector(2, u32){ @as(u32, @intCast(x)), @as(u32, @intCast(y)) };
} }
pub fn getPTEM(self: Font) f32 { pub fn getPTEM(self: Font) f32 {
@ -71,7 +71,7 @@ pub const Font = struct {
var x: c_int = 0; var x: c_int = 0;
var y: c_int = 0; var y: c_int = 0;
c.hb_font_get_scale(self.handle, &x, &y); c.hb_font_get_scale(self.handle, &x, &y);
return @Vector(2, i32){ @intCast(i32, x), @intCast(i32, y) }; return @Vector(2, i32){ @as(i32, @intCast(x)), @as(i32, @intCast(y)) };
} }
pub fn setFace(self: Font, face: Face) void { pub fn setFace(self: Font, face: Face) void {
@ -83,7 +83,7 @@ pub const Font = struct {
self.handle, self.handle,
buf.handle, buf.handle,
if (features) |f| f.ptr else null, if (features) |f| f.ptr else null,
if (features) |f| @intCast(c_uint, f.len) else 0, if (features) |f| @as(c_uint, @intCast(f.len)) else 0,
); );
} }
@ -92,7 +92,7 @@ pub const Font = struct {
self.handle, self.handle,
buf.handle, buf.handle,
if (features) |f| f.ptr else null, if (features) |f| f.ptr else null,
if (features) |f| @intCast(c_uint, f.len) else 0, if (features) |f| @as(c_uint, @intCast(f.len)) else 0,
shapers, shapers,
) < 1) return error.ShapingFailed; ) < 1) return error.ShapingFailed;
} }

View file

@ -15,7 +15,7 @@ pub const ShapePlan = struct {
face.handle, face.handle,
&props.cast(), &props.cast(),
if (features) |f| f.ptr else null, if (features) |f| f.ptr else null,
if (features) |f| @intCast(c_uint, f.len) else 0, if (features) |f| @as(c_uint, @intCast(f.len)) else 0,
shapers, shapers,
).? }; ).? };
} }
@ -25,7 +25,7 @@ pub const ShapePlan = struct {
face.handle, face.handle,
&props.cast(), &props.cast(),
if (features) |f| f.ptr else null, if (features) |f| f.ptr else null,
if (features) |f| @intCast(c_uint, f.len) else 0, if (features) |f| @as(c_uint, @intCast(f.len)) else 0,
shapers, shapers,
).? }; ).? };
} }
@ -35,9 +35,9 @@ pub const ShapePlan = struct {
face.handle, face.handle,
&props.cast(), &props.cast(),
if (features) |f| f.ptr else null, if (features) |f| f.ptr else null,
if (features) |f| @intCast(c_uint, f.len) else 0, if (features) |f| @as(c_uint, @intCast(f.len)) else 0,
cords.ptr, cords.ptr,
@intCast(c_uint, cords.len), @as(c_uint, @intCast(cords.len)),
shapers, shapers,
).? }; ).? };
} }
@ -47,9 +47,9 @@ pub const ShapePlan = struct {
face.handle, face.handle,
&props.cast(), &props.cast(),
if (features) |f| f.ptr else null, if (features) |f| f.ptr else null,
if (features) |f| @intCast(c_uint, f.len) else 0, if (features) |f| @as(c_uint, @intCast(f.len)) else 0,
cords.ptr, cords.ptr,
@intCast(c_uint, cords.len), @as(c_uint, @intCast(cords.len)),
shapers, shapers,
).? }; ).? };
} }
@ -64,12 +64,12 @@ pub const ShapePlan = struct {
font.handle, font.handle,
buffer.handle, buffer.handle,
if (features) |f| f.ptr else null, if (features) |f| f.ptr else null,
if (features) |f| @intCast(c_uint, f.len) else 0, if (features) |f| @as(c_uint, @intCast(f.len)) else 0,
) < 1) return error.ShapingFailed; ) < 1) return error.ShapingFailed;
} }
pub fn getShaper(self: ShapePlan) [:0]const u8 { pub fn getShaper(self: ShapePlan) [:0]const u8 {
return std.mem.span(@ptrCast([*:0]const u8, c.hb_shape_plan_get_shaper(self.handle))); return std.mem.span(@as([*:0]const u8, @ptrCast(c.hb_shape_plan_get_shaper(self.handle))));
} }
}; };

View file

@ -84,7 +84,7 @@ pub const Bitmap = struct {
} }
pub fn pixelMode(self: Bitmap) PixelMode { pub fn pixelMode(self: Bitmap) PixelMode {
return @enumFromInt(PixelMode, self.handle.pixel_mode); return @as(PixelMode, @enumFromInt(self.handle.pixel_mode));
} }
pub fn buffer(self: Bitmap) ?[]const u8 { pub fn buffer(self: Bitmap) ?[]const u8 {
@ -122,11 +122,11 @@ pub const Outline = struct {
handle: *c.FT_Outline, handle: *c.FT_Outline,
pub fn numPoints(self: Outline) u15 { pub fn numPoints(self: Outline) u15 {
return @intCast(u15, self.handle.*.n_points); return @as(u15, @intCast(self.handle.*.n_points));
} }
pub fn numContours(self: Outline) u15 { pub fn numContours(self: Outline) u15 {
return @intCast(u15, self.handle.*.n_contours); return @as(u15, @intCast(self.handle.*.n_contours));
} }
pub fn points(self: Outline) []const Vector { pub fn points(self: Outline) []const Vector {
@ -134,7 +134,7 @@ pub const Outline = struct {
} }
pub fn tags(self: Outline) []const u8 { pub fn tags(self: Outline) []const u8 {
return self.handle.tags[0..@intCast(u15, self.handle.n_points)]; return self.handle.tags[0..@as(u15, @intCast(self.handle.n_points))];
} }
pub fn contours(self: Outline) []const i16 { pub fn contours(self: Outline) []const i16 {
@ -142,7 +142,7 @@ pub const Outline = struct {
} }
pub fn flags(self: Outline) Flags { pub fn flags(self: Outline) Flags {
return @bitCast(Flags, self.handle.*.flags); return @as(Flags, @bitCast(self.handle.*.flags));
} }
pub fn copy(self: Outline) Error!Outline { pub fn copy(self: Outline) Error!Outline {
@ -188,15 +188,15 @@ pub const Outline = struct {
} }
pub fn orientation(self: Outline) Orientation { pub fn orientation(self: Outline) Orientation {
return @enumFromInt(Orientation, c.FT_Outline_Get_Orientation(self.handle)); return @as(Orientation, @enumFromInt(c.FT_Outline_Get_Orientation(self.handle)));
} }
pub fn getInsideBorder(self: Outline) Stroker.Border { pub fn getInsideBorder(self: Outline) Stroker.Border {
return @enumFromInt(Stroker.Border, c.FT_Outline_GetInsideBorder(self.handle)); return @as(Stroker.Border, @enumFromInt(c.FT_Outline_GetInsideBorder(self.handle)));
} }
pub fn getOutsideBorder(self: Outline) Stroker.Border { pub fn getOutsideBorder(self: Outline) Stroker.Border {
return @enumFromInt(Stroker.Border, c.FT_Outline_GetOutsideBorder(self.handle)); return @as(Stroker.Border, @enumFromInt(c.FT_Outline_GetOutsideBorder(self.handle)));
} }
pub fn Funcs(comptime Context: type) type { pub fn Funcs(comptime Context: type) type {
@ -217,7 +217,7 @@ pub const Outline = struct {
callbacks: Funcs(Context), callbacks: Funcs(Context),
fn getSelf(ptr: ?*anyopaque) *Self { fn getSelf(ptr: ?*anyopaque) *Self {
return @ptrCast(*Self, @alignCast(@alignOf(Self), ptr)); return @as(*Self, @ptrCast(@alignCast(@alignOf(Self), ptr)));
} }
pub fn move_to(to: [*c]const c.FT_Vector, ctx: ?*anyopaque) callconv(.C) c_int { pub fn move_to(to: [*c]const c.FT_Vector, ctx: ?*anyopaque) callconv(.C) c_int {

View file

@ -115,7 +115,7 @@ pub const Shape = enum(i32) {
pub inline fn create(image: Image, xhot: i32, yhot: i32) ?Cursor { pub inline fn create(image: Image, xhot: i32, yhot: i32) ?Cursor {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const img = image.toC(); const img = image.toC();
if (c.glfwCreateCursor(&img, @intCast(c_int, xhot), @intCast(c_int, yhot))) |cursor| return Cursor{ .ptr = cursor }; if (c.glfwCreateCursor(&img, @as(c_int, @intCast(xhot)), @as(c_int, @intCast(yhot)))) |cursor| return Cursor{ .ptr = cursor };
return null; return null;
} }
@ -153,7 +153,7 @@ pub inline fn create(image: Image, xhot: i32, yhot: i32) ?Cursor {
/// see also: cursor_object, glfwCreateCursor /// see also: cursor_object, glfwCreateCursor
pub inline fn createStandard(shape: Shape) ?Cursor { pub inline fn createStandard(shape: Shape) ?Cursor {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (c.glfwCreateStandardCursor(@intCast(c_int, @intFromEnum(shape)))) |cursor| return Cursor{ .ptr = cursor }; if (c.glfwCreateStandardCursor(@as(c_int, @intCast(@intFromEnum(shape))))) |cursor| return Cursor{ .ptr = cursor };
return null; return null;
} }

View file

@ -54,7 +54,7 @@ pub inline fn toC(self: GammaRamp) c.GLFWgammaramp {
.red = &self.red[0], .red = &self.red[0],
.green = &self.green[0], .green = &self.green[0],
.blue = &self.blue[0], .blue = &self.blue[0],
.size = @intCast(c_uint, self.red.len), .size = @as(c_uint, @intCast(self.red.len)),
}; };
} }

View file

@ -48,8 +48,8 @@ pub inline fn init(allocator: mem.Allocator, width: u32, height: u32, pixel_data
/// The returned memory is valid for as long as the GLFW C memory is valid. /// The returned memory is valid for as long as the GLFW C memory is valid.
pub inline fn fromC(native: c.GLFWimage, pixel_data_len: usize) Image { pub inline fn fromC(native: c.GLFWimage, pixel_data_len: usize) Image {
return Image{ return Image{
.width = @intCast(u32, native.width), .width = @as(u32, @intCast(native.width)),
.height = @intCast(u32, native.height), .height = @as(u32, @intCast(native.height)),
.pixels = native.pixels[0..pixel_data_len], .pixels = native.pixels[0..pixel_data_len],
.owned = false, .owned = false,
}; };
@ -60,8 +60,8 @@ pub inline fn fromC(native: c.GLFWimage, pixel_data_len: usize) Image {
/// The returned memory is valid for as long as the Zig memory is valid. /// The returned memory is valid for as long as the Zig memory is valid.
pub inline fn toC(self: Image) c.GLFWimage { pub inline fn toC(self: Image) c.GLFWimage {
return c.GLFWimage{ return c.GLFWimage{
.width = @intCast(c_int, self.width), .width = @as(c_int, @intCast(self.width)),
.height = @intCast(c_int, self.height), .height = @as(c_int, @intCast(self.height)),
.pixels = &self.pixels[0], .pixels = &self.pixels[0],
}; };
} }

View file

@ -39,7 +39,7 @@ pub const Id = enum(c_int) {
fourteen = c.GLFW_JOYSTICK_14, fourteen = c.GLFW_JOYSTICK_14,
fifteen = c.GLFW_JOYSTICK_15, fifteen = c.GLFW_JOYSTICK_15,
sixteen = c.GLFW_JOYSTICK_16, sixteen = c.GLFW_JOYSTICK_16,
pub const last = @enumFromInt(@This(), c.GLFW_JOYSTICK_LAST); pub const last = @as(@This(), @enumFromInt(c.GLFW_JOYSTICK_LAST));
}; };
/// Gamepad input state /// Gamepad input state
@ -60,12 +60,12 @@ const GamepadState = extern struct {
/// Returns the state of the specified gamepad button. /// Returns the state of the specified gamepad button.
pub fn getButton(self: @This(), which: GamepadButton) Action { pub fn getButton(self: @This(), which: GamepadButton) Action {
return @enumFromInt(Action, self.buttons[@intCast(u32, @intFromEnum(which))]); return @as(Action, @enumFromInt(self.buttons[@as(u32, @intCast(@intFromEnum(which)))]));
} }
/// Returns the status of the specified gamepad axis, in the range -1.0 to 1.0 inclusive. /// Returns the status of the specified gamepad axis, in the range -1.0 to 1.0 inclusive.
pub fn getAxis(self: @This(), which: GamepadAxis) f32 { pub fn getAxis(self: @This(), which: GamepadAxis) f32 {
return self.axes[@intCast(u32, @intFromEnum(which))]; return self.axes[@as(u32, @intCast(@intFromEnum(which)))];
} }
}; };
@ -115,7 +115,7 @@ pub inline fn getAxes(self: Joystick) ?[]const f32 {
var count: c_int = undefined; var count: c_int = undefined;
const axes = c.glfwGetJoystickAxes(@intFromEnum(self.jid), &count); const axes = c.glfwGetJoystickAxes(@intFromEnum(self.jid), &count);
if (axes == null) return null; if (axes == null) return null;
return axes[0..@intCast(u32, count)]; return axes[0..@as(u32, @intCast(count))];
} }
/// Returns the state of all buttons of the specified joystick. /// Returns the state of all buttons of the specified joystick.
@ -148,7 +148,7 @@ pub inline fn getButtons(self: Joystick) ?[]const u8 {
var count: c_int = undefined; var count: c_int = undefined;
const buttons = c.glfwGetJoystickButtons(@intFromEnum(self.jid), &count); const buttons = c.glfwGetJoystickButtons(@intFromEnum(self.jid), &count);
if (buttons == null) return null; if (buttons == null) return null;
return buttons[0..@intCast(u32, count)]; return buttons[0..@as(u32, @intCast(count))];
} }
/// Returns the state of all hats of the specified joystick. /// Returns the state of all hats of the specified joystick.
@ -197,8 +197,8 @@ pub inline fn getHats(self: Joystick) ?[]const Hat {
var count: c_int = undefined; var count: c_int = undefined;
const hats = c.glfwGetJoystickHats(@intFromEnum(self.jid), &count); const hats = c.glfwGetJoystickHats(@intFromEnum(self.jid), &count);
if (hats == null) return null; if (hats == null) return null;
const slice = hats[0..@intCast(u32, count)]; const slice = hats[0..@as(u32, @intCast(count))];
return @ptrCast(*const []const Hat, &slice).*; return @as(*const []const Hat, @ptrCast(&slice)).*;
} }
/// Returns the name of the specified joystick. /// Returns the name of the specified joystick.
@ -225,7 +225,7 @@ pub inline fn getName(self: Joystick) ?[:0]const u8 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const name_opt = c.glfwGetJoystickName(@intFromEnum(self.jid)); const name_opt = c.glfwGetJoystickName(@intFromEnum(self.jid));
return if (name_opt) |name| return if (name_opt) |name|
std.mem.span(@ptrCast([*:0]const u8, name)) std.mem.span(@as([*:0]const u8, @ptrCast(name)))
else else
null; null;
} }
@ -262,7 +262,7 @@ pub inline fn getGUID(self: Joystick) ?[:0]const u8 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const guid_opt = c.glfwGetJoystickGUID(@intFromEnum(self.jid)); const guid_opt = c.glfwGetJoystickGUID(@intFromEnum(self.jid));
return if (guid_opt) |guid| return if (guid_opt) |guid|
std.mem.span(@ptrCast([*:0]const u8, guid)) std.mem.span(@as([*:0]const u8, @ptrCast(guid)))
else else
null; null;
} }
@ -279,7 +279,7 @@ pub inline fn getGUID(self: Joystick) ?[:0]const u8 {
/// see also: joystick_userptr, glfw.Joystick.getUserPointer /// see also: joystick_userptr, glfw.Joystick.getUserPointer
pub inline fn setUserPointer(self: Joystick, comptime T: type, pointer: *T) void { pub inline fn setUserPointer(self: Joystick, comptime T: type, pointer: *T) void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwSetJoystickUserPointer(@intFromEnum(self.jid), @ptrCast(*anyopaque, pointer)); c.glfwSetJoystickUserPointer(@intFromEnum(self.jid), @as(*anyopaque, @ptrCast(pointer)));
} }
/// Returns the user pointer of the specified joystick. /// Returns the user pointer of the specified joystick.
@ -296,7 +296,7 @@ pub inline fn setUserPointer(self: Joystick, comptime T: type, pointer: *T) void
pub inline fn getUserPointer(self: Joystick, comptime PointerType: type) ?PointerType { pub inline fn getUserPointer(self: Joystick, comptime PointerType: type) ?PointerType {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const ptr = c.glfwGetJoystickUserPointer(@intFromEnum(self.jid)); const ptr = c.glfwGetJoystickUserPointer(@intFromEnum(self.jid));
if (ptr) |p| return @ptrCast(PointerType, @alignCast(@alignOf(std.meta.Child(PointerType)), p)); if (ptr) |p| return @as(PointerType, @ptrCast(@alignCast(@alignOf(std.meta.Child(PointerType)), p)));
return null; return null;
} }
@ -335,8 +335,8 @@ pub inline fn setCallback(comptime callback: ?fn (joystick: Joystick, event: Eve
const CWrapper = struct { const CWrapper = struct {
pub fn joystickCallbackWrapper(jid: c_int, event: c_int) callconv(.C) void { pub fn joystickCallbackWrapper(jid: c_int, event: c_int) callconv(.C) void {
@call(.always_inline, user_callback, .{ @call(.always_inline, user_callback, .{
Joystick{ .jid = @enumFromInt(Joystick.Id, jid) }, Joystick{ .jid = @as(Joystick.Id, @enumFromInt(jid)) },
@enumFromInt(Event, event), @as(Event, @enumFromInt(event)),
}); });
} }
}; };
@ -424,7 +424,7 @@ pub inline fn getGamepadName(self: Joystick) ?[:0]const u8 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const name_opt = c.glfwGetGamepadName(@intFromEnum(self.jid)); const name_opt = c.glfwGetGamepadName(@intFromEnum(self.jid));
return if (name_opt) |name| return if (name_opt) |name|
std.mem.span(@ptrCast([*:0]const u8, name)) std.mem.span(@as([*:0]const u8, @ptrCast(name)))
else else
null; null;
} }
@ -457,7 +457,7 @@ pub inline fn getGamepadName(self: Joystick) ?[:0]const u8 {
pub inline fn getGamepadState(self: Joystick) ?GamepadState { pub inline fn getGamepadState(self: Joystick) ?GamepadState {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
var state: GamepadState = undefined; var state: GamepadState = undefined;
const success = c.glfwGetGamepadState(@intFromEnum(self.jid), @ptrCast(*c.GLFWgamepadstate, &state)); const success = c.glfwGetGamepadState(@intFromEnum(self.jid), @as(*c.GLFWgamepadstate, @ptrCast(&state)));
return if (success == c.GLFW_TRUE) state else null; return if (success == c.GLFW_TRUE) state else null;
} }

View file

@ -35,7 +35,7 @@ pub inline fn getPos(self: Monitor) Pos {
var xpos: c_int = 0; var xpos: c_int = 0;
var ypos: c_int = 0; var ypos: c_int = 0;
c.glfwGetMonitorPos(self.handle, &xpos, &ypos); c.glfwGetMonitorPos(self.handle, &xpos, &ypos);
return Pos{ .x = @intCast(u32, xpos), .y = @intCast(u32, ypos) }; return Pos{ .x = @as(u32, @intCast(xpos)), .y = @as(u32, @intCast(ypos)) };
} }
/// The monitor workarea, in screen coordinates. /// The monitor workarea, in screen coordinates.
@ -66,7 +66,7 @@ pub inline fn getWorkarea(self: Monitor) Workarea {
var width: c_int = 0; var width: c_int = 0;
var height: c_int = 0; var height: c_int = 0;
c.glfwGetMonitorWorkarea(self.handle, &xpos, &ypos, &width, &height); c.glfwGetMonitorWorkarea(self.handle, &xpos, &ypos, &width, &height);
return Workarea{ .x = @intCast(u32, xpos), .y = @intCast(u32, ypos), .width = @intCast(u32, width), .height = @intCast(u32, height) }; return Workarea{ .x = @as(u32, @intCast(xpos)), .y = @as(u32, @intCast(ypos)), .width = @as(u32, @intCast(width)), .height = @as(u32, @intCast(height)) };
} }
/// The physical size, in millimetres, of the display area of a monitor. /// The physical size, in millimetres, of the display area of a monitor.
@ -91,7 +91,7 @@ pub inline fn getPhysicalSize(self: Monitor) PhysicalSize {
var width_mm: c_int = 0; var width_mm: c_int = 0;
var height_mm: c_int = 0; var height_mm: c_int = 0;
c.glfwGetMonitorPhysicalSize(self.handle, &width_mm, &height_mm); c.glfwGetMonitorPhysicalSize(self.handle, &width_mm, &height_mm);
return PhysicalSize{ .width_mm = @intCast(u32, width_mm), .height_mm = @intCast(u32, height_mm) }; return PhysicalSize{ .width_mm = @as(u32, @intCast(width_mm)), .height_mm = @as(u32, @intCast(height_mm)) };
} }
/// The content scale for a monitor. /// The content scale for a monitor.
@ -123,7 +123,7 @@ pub inline fn getContentScale(self: Monitor) ContentScale {
var x_scale: f32 = 0; var x_scale: f32 = 0;
var y_scale: f32 = 0; var y_scale: f32 = 0;
c.glfwGetMonitorContentScale(self.handle, &x_scale, &y_scale); c.glfwGetMonitorContentScale(self.handle, &x_scale, &y_scale);
return ContentScale{ .x_scale = @floatCast(f32, x_scale), .y_scale = @floatCast(f32, y_scale) }; return ContentScale{ .x_scale = @as(f32, @floatCast(x_scale)), .y_scale = @as(f32, @floatCast(y_scale)) };
} }
/// Returns the name of the specified monitor. /// Returns the name of the specified monitor.
@ -140,7 +140,7 @@ pub inline fn getContentScale(self: Monitor) ContentScale {
/// see also: monitor_properties /// see also: monitor_properties
pub inline fn getName(self: Monitor) [*:0]const u8 { pub inline fn getName(self: Monitor) [*:0]const u8 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (c.glfwGetMonitorName(self.handle)) |name| return @ptrCast([*:0]const u8, name); if (c.glfwGetMonitorName(self.handle)) |name| return @as([*:0]const u8, @ptrCast(name));
// `glfwGetMonitorName` returns `null` only for errors, but the only error is unreachable // `glfwGetMonitorName` returns `null` only for errors, but the only error is unreachable
// (NotInitialized) // (NotInitialized)
unreachable; unreachable;
@ -176,7 +176,7 @@ pub inline fn getUserPointer(self: Monitor, comptime T: type) ?*T {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const ptr = c.glfwGetMonitorUserPointer(self.handle); const ptr = c.glfwGetMonitorUserPointer(self.handle);
if (ptr == null) return null; if (ptr == null) return null;
return @ptrCast(*T, @alignCast(@alignOf(T), ptr.?)); return @as(*T, @ptrCast(@alignCast(@alignOf(T), ptr.?)));
} }
/// Returns the available video modes for the specified monitor. /// Returns the available video modes for the specified monitor.
@ -200,10 +200,10 @@ pub inline fn getVideoModes(self: Monitor, allocator: mem.Allocator) mem.Allocat
internal_debug.assertInitialized(); internal_debug.assertInitialized();
var count: c_int = 0; var count: c_int = 0;
if (c.glfwGetVideoModes(self.handle, &count)) |modes| { if (c.glfwGetVideoModes(self.handle, &count)) |modes| {
const slice = try allocator.alloc(VideoMode, @intCast(u32, count)); const slice = try allocator.alloc(VideoMode, @as(u32, @intCast(count)));
var i: u32 = 0; var i: u32 = 0;
while (i < count) : (i += 1) { while (i < count) : (i += 1) {
slice[i] = VideoMode{ .handle = @ptrCast([*c]const c.GLFWvidmode, modes)[i] }; slice[i] = VideoMode{ .handle = @as([*c]const c.GLFWvidmode, @ptrCast(modes))[i] };
} }
return slice; return slice;
} }
@ -325,10 +325,10 @@ pub inline fn getAll(allocator: mem.Allocator) mem.Allocator.Error![]Monitor {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
var count: c_int = 0; var count: c_int = 0;
if (c.glfwGetMonitors(&count)) |monitors| { if (c.glfwGetMonitors(&count)) |monitors| {
const slice = try allocator.alloc(Monitor, @intCast(u32, count)); const slice = try allocator.alloc(Monitor, @as(u32, @intCast(count)));
var i: u32 = 0; var i: u32 = 0;
while (i < count) : (i += 1) { while (i < count) : (i += 1) {
slice[i] = Monitor{ .handle = @ptrCast([*c]const ?*c.GLFWmonitor, monitors)[i].? }; slice[i] = Monitor{ .handle = @as([*c]const ?*c.GLFWmonitor, @ptrCast(monitors))[i].? };
} }
return slice; return slice;
} }
@ -387,7 +387,7 @@ pub inline fn setCallback(comptime callback: ?fn (monitor: Monitor, event: Event
pub fn monitorCallbackWrapper(monitor: ?*c.GLFWmonitor, event: c_int) callconv(.C) void { pub fn monitorCallbackWrapper(monitor: ?*c.GLFWmonitor, event: c_int) callconv(.C) void {
@call(.always_inline, user_callback, .{ @call(.always_inline, user_callback, .{
Monitor{ .handle = monitor.? }, Monitor{ .handle = monitor.? },
@enumFromInt(Event, event), @as(Event, @enumFromInt(event)),
}); });
} }
}; };

View file

@ -11,32 +11,32 @@ handle: c.GLFWvidmode,
/// Returns the width of the video mode, in screen coordinates. /// Returns the width of the video mode, in screen coordinates.
pub inline fn getWidth(self: VideoMode) u32 { pub inline fn getWidth(self: VideoMode) u32 {
return @intCast(u32, self.handle.width); return @as(u32, @intCast(self.handle.width));
} }
/// Returns the height of the video mode, in screen coordinates. /// Returns the height of the video mode, in screen coordinates.
pub inline fn getHeight(self: VideoMode) u32 { pub inline fn getHeight(self: VideoMode) u32 {
return @intCast(u32, self.handle.height); return @as(u32, @intCast(self.handle.height));
} }
/// Returns the bit depth of the red channel of the video mode. /// Returns the bit depth of the red channel of the video mode.
pub inline fn getRedBits(self: VideoMode) u32 { pub inline fn getRedBits(self: VideoMode) u32 {
return @intCast(u32, self.handle.redBits); return @as(u32, @intCast(self.handle.redBits));
} }
/// Returns the bit depth of the green channel of the video mode. /// Returns the bit depth of the green channel of the video mode.
pub inline fn getGreenBits(self: VideoMode) u32 { pub inline fn getGreenBits(self: VideoMode) u32 {
return @intCast(u32, self.handle.greenBits); return @as(u32, @intCast(self.handle.greenBits));
} }
/// Returns the bit depth of the blue channel of the video mode. /// Returns the bit depth of the blue channel of the video mode.
pub inline fn getBlueBits(self: VideoMode) u32 { pub inline fn getBlueBits(self: VideoMode) u32 {
return @intCast(u32, self.handle.blueBits); return @as(u32, @intCast(self.handle.blueBits));
} }
/// Returns the refresh rate of the video mode, in Hz. /// Returns the refresh rate of the video mode, in Hz.
pub inline fn getRefreshRate(self: VideoMode) u32 { pub inline fn getRefreshRate(self: VideoMode) u32 {
return @intCast(u32, self.handle.refreshRate); return @as(u32, @intCast(self.handle.refreshRate));
} }
test "getters" { test "getters" {

View file

@ -22,7 +22,7 @@ handle: *c.GLFWwindow,
/// Returns a Zig GLFW window from an underlying C GLFW window handle. /// Returns a Zig GLFW window from an underlying C GLFW window handle.
pub inline fn from(handle: *anyopaque) Window { pub inline fn from(handle: *anyopaque) Window {
return Window{ .handle = @ptrCast(*c.GLFWwindow, @alignCast(@alignOf(*c.GLFWwindow), handle)) }; return Window{ .handle = @as(*c.GLFWwindow, @ptrCast(@alignCast(@alignOf(*c.GLFWwindow), handle))) };
} }
/// Resets all window hints to their default values. /// Resets all window hints to their default values.
@ -378,8 +378,8 @@ pub inline fn create(
if (!ignore_hints_struct) hints.set(); if (!ignore_hints_struct) hints.set();
if (c.glfwCreateWindow( if (c.glfwCreateWindow(
@intCast(c_int, width), @as(c_int, @intCast(width)),
@intCast(c_int, height), @as(c_int, @intCast(height)),
&title[0], &title[0],
if (monitor) |m| m.handle else null, if (monitor) |m| m.handle else null,
if (share) |w| w.handle else null, if (share) |w| w.handle else null,
@ -489,7 +489,7 @@ pub inline fn setIcon(self: Window, allocator: mem.Allocator, images: ?[]const I
const tmp = try allocator.alloc(c.GLFWimage, im.len); const tmp = try allocator.alloc(c.GLFWimage, im.len);
defer allocator.free(tmp); defer allocator.free(tmp);
for (im, 0..) |img, index| tmp[index] = img.toC(); for (im, 0..) |img, index| tmp[index] = img.toC();
c.glfwSetWindowIcon(self.handle, @intCast(c_int, im.len), &tmp[0]); c.glfwSetWindowIcon(self.handle, @as(c_int, @intCast(im.len)), &tmp[0]);
} else c.glfwSetWindowIcon(self.handle, 0, null); } else c.glfwSetWindowIcon(self.handle, 0, null);
} }
@ -517,7 +517,7 @@ pub inline fn getPos(self: Window) Pos {
var x: c_int = 0; var x: c_int = 0;
var y: c_int = 0; var y: c_int = 0;
c.glfwGetWindowPos(self.handle, &x, &y); c.glfwGetWindowPos(self.handle, &x, &y);
return Pos{ .x = @intCast(i64, x), .y = @intCast(i64, y) }; return Pos{ .x = @as(i64, @intCast(x)), .y = @as(i64, @intCast(y)) };
} }
/// Sets the position of the content area of the specified window. /// Sets the position of the content area of the specified window.
@ -542,7 +542,7 @@ pub inline fn getPos(self: Window) Pos {
/// see also: window_pos, glfw.Window.getPos /// see also: window_pos, glfw.Window.getPos
pub inline fn setPos(self: Window, pos: Pos) void { pub inline fn setPos(self: Window, pos: Pos) void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwSetWindowPos(self.handle, @intCast(c_int, pos.x), @intCast(c_int, pos.y)); c.glfwSetWindowPos(self.handle, @as(c_int, @intCast(pos.x)), @as(c_int, @intCast(pos.y)));
} }
pub const Size = struct { pub const Size = struct {
@ -567,7 +567,7 @@ pub inline fn getSize(self: Window) Size {
var width: c_int = 0; var width: c_int = 0;
var height: c_int = 0; var height: c_int = 0;
c.glfwGetWindowSize(self.handle, &width, &height); c.glfwGetWindowSize(self.handle, &width, &height);
return Size{ .width = @intCast(u32, width), .height = @intCast(u32, height) }; return Size{ .width = @as(u32, @intCast(width)), .height = @as(u32, @intCast(height)) };
} }
/// Sets the size of the content area of the specified window. /// Sets the size of the content area of the specified window.
@ -594,7 +594,7 @@ pub inline fn getSize(self: Window) Size {
/// see also: window_size, glfw.Window.getSize, glfw.Window.SetMonitor /// see also: window_size, glfw.Window.getSize, glfw.Window.SetMonitor
pub inline fn setSize(self: Window, size: Size) void { pub inline fn setSize(self: Window, size: Size) void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwSetWindowSize(self.handle, @intCast(c_int, size.width), @intCast(c_int, size.height)); c.glfwSetWindowSize(self.handle, @as(c_int, @intCast(size.width)), @as(c_int, @intCast(size.height)));
} }
/// A size with option width/height, used to represent e.g. constraints on a windows size while /// A size with option width/height, used to represent e.g. constraints on a windows size while
@ -637,10 +637,10 @@ pub inline fn setSizeLimits(self: Window, min: SizeOptional, max: SizeOptional)
c.glfwSetWindowSizeLimits( c.glfwSetWindowSizeLimits(
self.handle, self.handle,
if (min.width) |min_width| @intCast(c_int, min_width) else glfw.dont_care, if (min.width) |min_width| @as(c_int, @intCast(min_width)) else glfw.dont_care,
if (min.height) |min_height| @intCast(c_int, min_height) else glfw.dont_care, if (min.height) |min_height| @as(c_int, @intCast(min_height)) else glfw.dont_care,
if (max.width) |max_width| @intCast(c_int, max_width) else glfw.dont_care, if (max.width) |max_width| @as(c_int, @intCast(max_width)) else glfw.dont_care,
if (max.height) |max_height| @intCast(c_int, max_height) else glfw.dont_care, if (max.height) |max_height| @as(c_int, @intCast(max_height)) else glfw.dont_care,
); );
} }
@ -681,8 +681,8 @@ pub inline fn setAspectRatio(self: Window, numerator: ?u32, denominator: ?u32) v
c.glfwSetWindowAspectRatio( c.glfwSetWindowAspectRatio(
self.handle, self.handle,
if (numerator) |numerator_unwrapped| @intCast(c_int, numerator_unwrapped) else glfw.dont_care, if (numerator) |numerator_unwrapped| @as(c_int, @intCast(numerator_unwrapped)) else glfw.dont_care,
if (denominator) |denominator_unwrapped| @intCast(c_int, denominator_unwrapped) else glfw.dont_care, if (denominator) |denominator_unwrapped| @as(c_int, @intCast(denominator_unwrapped)) else glfw.dont_care,
); );
} }
@ -702,7 +702,7 @@ pub inline fn getFramebufferSize(self: Window) Size {
var width: c_int = 0; var width: c_int = 0;
var height: c_int = 0; var height: c_int = 0;
c.glfwGetFramebufferSize(self.handle, &width, &height); c.glfwGetFramebufferSize(self.handle, &width, &height);
return Size{ .width = @intCast(u32, width), .height = @intCast(u32, height) }; return Size{ .width = @as(u32, @intCast(width)), .height = @as(u32, @intCast(height)) };
} }
pub const FrameSize = struct { pub const FrameSize = struct {
@ -735,10 +735,10 @@ pub inline fn getFrameSize(self: Window) FrameSize {
var bottom: c_int = 0; var bottom: c_int = 0;
c.glfwGetWindowFrameSize(self.handle, &left, &top, &right, &bottom); c.glfwGetWindowFrameSize(self.handle, &left, &top, &right, &bottom);
return FrameSize{ return FrameSize{
.left = @intCast(u32, left), .left = @as(u32, @intCast(left)),
.top = @intCast(u32, top), .top = @as(u32, @intCast(top)),
.right = @intCast(u32, right), .right = @as(u32, @intCast(right)),
.bottom = @intCast(u32, bottom), .bottom = @as(u32, @intCast(bottom)),
}; };
} }
@ -1046,11 +1046,11 @@ pub inline fn setMonitor(self: Window, monitor: ?Monitor, xpos: i32, ypos: i32,
c.glfwSetWindowMonitor( c.glfwSetWindowMonitor(
self.handle, self.handle,
if (monitor) |m| m.handle else null, if (monitor) |m| m.handle else null,
@intCast(c_int, xpos), @as(c_int, @intCast(xpos)),
@intCast(c_int, ypos), @as(c_int, @intCast(ypos)),
@intCast(c_int, width), @as(c_int, @intCast(width)),
@intCast(c_int, height), @as(c_int, @intCast(height)),
if (refresh_rate) |refresh_rate_unwrapped| @intCast(c_int, refresh_rate_unwrapped) else glfw.dont_care, if (refresh_rate) |refresh_rate_unwrapped| @as(c_int, @intCast(refresh_rate_unwrapped)) else glfw.dont_care,
); );
} }
@ -1174,7 +1174,7 @@ pub inline fn setUserPointer(self: Window, pointer: ?*anyopaque) void {
/// see also: window_userptr, glfw.Window.setUserPointer /// see also: window_userptr, glfw.Window.setUserPointer
pub inline fn getUserPointer(self: Window, comptime T: type) ?*T { pub inline fn getUserPointer(self: Window, comptime T: type) ?*T {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (c.glfwGetWindowUserPointer(self.handle)) |user_pointer| return @ptrCast(?*T, @alignCast(@alignOf(T), user_pointer)); if (c.glfwGetWindowUserPointer(self.handle)) |user_pointer| return @as(?*T, @ptrCast(@alignCast(@alignOf(T), user_pointer)));
return null; return null;
} }
@ -1206,8 +1206,8 @@ pub inline fn setPosCallback(self: Window, comptime callback: ?fn (window: Windo
pub fn posCallbackWrapper(handle: ?*c.GLFWwindow, xpos: c_int, ypos: c_int) callconv(.C) void { pub fn posCallbackWrapper(handle: ?*c.GLFWwindow, xpos: c_int, ypos: c_int) callconv(.C) void {
@call(.always_inline, user_callback, .{ @call(.always_inline, user_callback, .{
from(handle.?), from(handle.?),
@intCast(i32, xpos), @as(i32, @intCast(xpos)),
@intCast(i32, ypos), @as(i32, @intCast(ypos)),
}); });
} }
}; };
@ -1239,8 +1239,8 @@ pub inline fn setSizeCallback(self: Window, comptime callback: ?fn (window: Wind
pub fn sizeCallbackWrapper(handle: ?*c.GLFWwindow, width: c_int, height: c_int) callconv(.C) void { pub fn sizeCallbackWrapper(handle: ?*c.GLFWwindow, width: c_int, height: c_int) callconv(.C) void {
@call(.always_inline, user_callback, .{ @call(.always_inline, user_callback, .{
from(handle.?), from(handle.?),
@intCast(i32, width), @as(i32, @intCast(width)),
@intCast(i32, height), @as(i32, @intCast(height)),
}); });
} }
}; };
@ -1459,8 +1459,8 @@ pub inline fn setFramebufferSizeCallback(self: Window, comptime callback: ?fn (w
pub fn framebufferSizeCallbackWrapper(handle: ?*c.GLFWwindow, width: c_int, height: c_int) callconv(.C) void { pub fn framebufferSizeCallbackWrapper(handle: ?*c.GLFWwindow, width: c_int, height: c_int) callconv(.C) void {
@call(.always_inline, user_callback, .{ @call(.always_inline, user_callback, .{
from(handle.?), from(handle.?),
@intCast(u32, width), @as(u32, @intCast(width)),
@intCast(u32, height), @as(u32, @intCast(height)),
}); });
} }
}; };
@ -1541,7 +1541,7 @@ pub inline fn setInputModeCursor(self: Window, value: InputModeCursor) void {
/// Gets the current input mode of the cursor. /// Gets the current input mode of the cursor.
pub inline fn getInputModeCursor(self: Window) InputModeCursor { pub inline fn getInputModeCursor(self: Window) InputModeCursor {
return @enumFromInt(InputModeCursor, self.getInputMode(InputMode.cursor)); return @as(InputModeCursor, @enumFromInt(self.getInputMode(InputMode.cursor)));
} }
/// Sets the input mode of sticky keys, if enabled a key press will ensure that `glfw.Window.getKey` /// Sets the input mode of sticky keys, if enabled a key press will ensure that `glfw.Window.getKey`
@ -1623,7 +1623,7 @@ pub inline fn getInputModeRawMouseMotion(self: Window) bool {
pub inline fn getInputMode(self: Window, mode: InputMode) i32 { pub inline fn getInputMode(self: Window, mode: InputMode) i32 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const value = c.glfwGetInputMode(self.handle, @intFromEnum(mode)); const value = c.glfwGetInputMode(self.handle, @intFromEnum(mode));
return @intCast(i32, value); return @as(i32, @intCast(value));
} }
/// Sets an input option for the specified window. /// Sets an input option for the specified window.
@ -1693,7 +1693,7 @@ pub inline fn setInputMode(self: Window, mode: InputMode, value: anytype) void {
pub inline fn getKey(self: Window, key: Key) Action { pub inline fn getKey(self: Window, key: Key) Action {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const state = c.glfwGetKey(self.handle, @intFromEnum(key)); const state = c.glfwGetKey(self.handle, @intFromEnum(key));
return @enumFromInt(Action, state); return @as(Action, @enumFromInt(state));
} }
/// Returns the last reported state of a mouse button for the specified window. /// Returns the last reported state of a mouse button for the specified window.
@ -1715,7 +1715,7 @@ pub inline fn getKey(self: Window, key: Key) Action {
pub inline fn getMouseButton(self: Window, button: MouseButton) Action { pub inline fn getMouseButton(self: Window, button: MouseButton) Action {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const state = c.glfwGetMouseButton(self.handle, @intFromEnum(button)); const state = c.glfwGetMouseButton(self.handle, @intFromEnum(button));
return @enumFromInt(Action, state); return @as(Action, @enumFromInt(state));
} }
pub const CursorPos = struct { pub const CursorPos = struct {
@ -1848,9 +1848,9 @@ pub inline fn setKeyCallback(self: Window, comptime callback: ?fn (window: Windo
pub fn keyCallbackWrapper(handle: ?*c.GLFWwindow, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void { pub fn keyCallbackWrapper(handle: ?*c.GLFWwindow, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void {
@call(.always_inline, user_callback, .{ @call(.always_inline, user_callback, .{
from(handle.?), from(handle.?),
@enumFromInt(Key, key), @as(Key, @enumFromInt(key)),
@intCast(i32, scancode), @as(i32, @intCast(scancode)),
@enumFromInt(Action, action), @as(Action, @enumFromInt(action)),
Mods.fromInt(mods), Mods.fromInt(mods),
}); });
} }
@ -1894,7 +1894,7 @@ pub inline fn setCharCallback(self: Window, comptime callback: ?fn (window: Wind
pub fn charCallbackWrapper(handle: ?*c.GLFWwindow, codepoint: c_uint) callconv(.C) void { pub fn charCallbackWrapper(handle: ?*c.GLFWwindow, codepoint: c_uint) callconv(.C) void {
@call(.always_inline, user_callback, .{ @call(.always_inline, user_callback, .{
from(handle.?), from(handle.?),
@intCast(u21, codepoint), @as(u21, @intCast(codepoint)),
}); });
} }
}; };
@ -1935,8 +1935,8 @@ pub inline fn setMouseButtonCallback(self: Window, comptime callback: ?fn (windo
pub fn mouseButtonCallbackWrapper(handle: ?*c.GLFWwindow, button: c_int, action: c_int, mods: c_int) callconv(.C) void { pub fn mouseButtonCallbackWrapper(handle: ?*c.GLFWwindow, button: c_int, action: c_int, mods: c_int) callconv(.C) void {
@call(.always_inline, user_callback, .{ @call(.always_inline, user_callback, .{
from(handle.?), from(handle.?),
@enumFromInt(MouseButton, button), @as(MouseButton, @enumFromInt(button)),
@enumFromInt(Action, action), @as(Action, @enumFromInt(action)),
Mods.fromInt(mods), Mods.fromInt(mods),
}); });
} }
@ -2087,7 +2087,7 @@ pub inline fn setDropCallback(self: Window, comptime callback: ?fn (window: Wind
pub fn dropCallbackWrapper(handle: ?*c.GLFWwindow, path_count: c_int, paths: [*c][*c]const u8) callconv(.C) void { pub fn dropCallbackWrapper(handle: ?*c.GLFWwindow, path_count: c_int, paths: [*c][*c]const u8) callconv(.C) void {
@call(.always_inline, user_callback, .{ @call(.always_inline, user_callback, .{
from(handle.?), from(handle.?),
@ptrCast([*][*:0]const u8, paths)[0..@intCast(u32, path_count)], @as([*][*:0]const u8, @ptrCast(paths))[0..@as(u32, @intCast(path_count))],
}); });
} }
}; };
@ -2125,15 +2125,15 @@ inline fn hint(h: Hint, value: anytype) void {
switch (value_type_info) { switch (value_type_info) {
.Int, .ComptimeInt => { .Int, .ComptimeInt => {
c.glfwWindowHint(@intFromEnum(h), @intCast(c_int, value)); c.glfwWindowHint(@intFromEnum(h), @as(c_int, @intCast(value)));
}, },
.Bool => { .Bool => {
const int_value = @intFromBool(value); const int_value = @intFromBool(value);
c.glfwWindowHint(@intFromEnum(h), @intCast(c_int, int_value)); c.glfwWindowHint(@intFromEnum(h), @as(c_int, @intCast(int_value)));
}, },
.Enum => { .Enum => {
const int_value = @intFromEnum(value); const int_value = @intFromEnum(value);
c.glfwWindowHint(@intFromEnum(h), @intCast(c_int, int_value)); c.glfwWindowHint(@intFromEnum(h), @as(c_int, @intCast(int_value)));
}, },
.Array => |arr_type| { .Array => |arr_type| {
if (arr_type.child != u8) { if (arr_type.child != u8) {

View file

@ -42,7 +42,7 @@ pub inline fn setClipboardString(value: [*:0]const u8) void {
/// see also: clipboard, glfwSetClipboardString /// see also: clipboard, glfwSetClipboardString
pub inline fn getClipboardString() ?[:0]const u8 { pub inline fn getClipboardString() ?[:0]const u8 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (c.glfwGetClipboardString(null)) |c_str| return std.mem.span(@ptrCast([*:0]const u8, c_str)); if (c.glfwGetClipboardString(null)) |c_str| return std.mem.span(@as([*:0]const u8, @ptrCast(c_str)));
return null; return null;
} }

View file

@ -26,12 +26,12 @@ pub const Hat = packed struct(u8) {
pub inline fn toInt(self: Hat, comptime IntType: type) IntType { pub inline fn toInt(self: Hat, comptime IntType: type) IntType {
verifyIntType(IntType); verifyIntType(IntType);
return @intCast(IntType, @bitCast(u8, self)); return @as(IntType, @intCast(@as(u8, @bitCast(self))));
} }
pub inline fn fromInt(flags: anytype) Hat { pub inline fn fromInt(flags: anytype) Hat {
verifyIntType(@TypeOf(flags)); verifyIntType(@TypeOf(flags));
return @bitCast(Hat, @intCast(u8, flags)); return @as(Hat, @bitCast(@as(u8, @intCast(flags))));
} }
}; };

View file

@ -150,7 +150,7 @@ pub const Key = enum(c_int) {
menu = cc.GLFW_KEY_MENU, menu = cc.GLFW_KEY_MENU,
pub inline fn last() Key { pub inline fn last() Key {
return @enumFromInt(Key, cc.GLFW_KEY_LAST); return @as(Key, @enumFromInt(cc.GLFW_KEY_LAST));
} }
/// Returns the layout-specific name of the specified printable key. /// Returns the layout-specific name of the specified printable key.
@ -215,9 +215,9 @@ pub const Key = enum(c_int) {
/// see also: input_key_name /// see also: input_key_name
pub inline fn getName(self: Key, scancode: i32) ?[:0]const u8 { pub inline fn getName(self: Key, scancode: i32) ?[:0]const u8 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const name_opt = cc.glfwGetKeyName(@intFromEnum(self), @intCast(c_int, scancode)); const name_opt = cc.glfwGetKeyName(@intFromEnum(self), @as(c_int, @intCast(scancode)));
return if (name_opt) |name| return if (name_opt) |name|
std.mem.span(@ptrCast([*:0]const u8, name)) std.mem.span(@as([*:0]const u8, @ptrCast(name)))
else else
null; null;
} }

View file

@ -273,9 +273,9 @@ pub const PlatformType = enum(c_int) {
fn initHint(hint: InitHint, value: anytype) void { fn initHint(hint: InitHint, value: anytype) void {
switch (@typeInfo(@TypeOf(value))) { switch (@typeInfo(@TypeOf(value))) {
.Int, .ComptimeInt => { .Int, .ComptimeInt => {
c.glfwInitHint(@intFromEnum(hint), @intCast(c_int, value)); c.glfwInitHint(@intFromEnum(hint), @as(c_int, @intCast(value)));
}, },
.Bool => c.glfwInitHint(@intFromEnum(hint), @intCast(c_int, @intFromBool(value))), .Bool => c.glfwInitHint(@intFromEnum(hint), @as(c_int, @intCast(@intFromBool(value)))),
else => @compileError("expected a int or bool, got " ++ @typeName(@TypeOf(value))), else => @compileError("expected a int or bool, got " ++ @typeName(@TypeOf(value))),
} }
} }
@ -301,7 +301,7 @@ fn initHint(hint: InitHint, value: anytype) void {
/// ///
/// thread_safety: This function may be called from any thread. /// thread_safety: This function may be called from any thread.
pub inline fn getVersionString() [:0]const u8 { pub inline fn getVersionString() [:0]const u8 {
return std.mem.span(@ptrCast([*:0]const u8, c.glfwGetVersionString())); return std.mem.span(@as([*:0]const u8, @ptrCast(c.glfwGetVersionString())));
} }
/// Returns the currently selected platform. /// Returns the currently selected platform.
@ -313,7 +313,7 @@ pub inline fn getVersionString() [:0]const u8 {
/// thread_safety: This function may be called from any thread. /// thread_safety: This function may be called from any thread.
pub fn getPlatform() PlatformType { pub fn getPlatform() PlatformType {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
return @enumFromInt(PlatformType, c.glfwGetPlatform()); return @as(PlatformType, @enumFromInt(c.glfwGetPlatform()));
} }
/// Returns whether the library includes support for the specified platform. /// Returns whether the library includes support for the specified platform.

View file

@ -26,12 +26,12 @@ pub const Mods = packed struct(u8) {
pub inline fn toInt(self: Mods, comptime IntType: type) IntType { pub inline fn toInt(self: Mods, comptime IntType: type) IntType {
verifyIntType(IntType); verifyIntType(IntType);
return @intCast(IntType, @bitCast(u8, self)); return @as(IntType, @intCast(@as(u8, @bitCast(self))));
} }
pub inline fn fromInt(flags: anytype) Mods { pub inline fn fromInt(flags: anytype) Mods {
verifyIntType(@TypeOf(flags)); verifyIntType(@TypeOf(flags));
return @bitCast(Mods, @intCast(u8, flags)); return @as(Mods, @bitCast(@as(u8, @intCast(flags))));
} }
}; };

View file

@ -61,7 +61,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getWin32Adapter(monitor: Monitor) [*:0]const u8 { pub fn getWin32Adapter(monitor: Monitor) [*:0]const u8 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (native.glfwGetWin32Adapter(@ptrCast(*native.GLFWmonitor, monitor.handle))) |adapter| return adapter; if (native.glfwGetWin32Adapter(@as(*native.GLFWmonitor, @ptrCast(monitor.handle)))) |adapter| return adapter;
// `glfwGetWin32Adapter` returns `null` only for errors // `glfwGetWin32Adapter` returns `null` only for errors
// but the only potential error is unreachable (NotInitialized) // but the only potential error is unreachable (NotInitialized)
unreachable; unreachable;
@ -75,7 +75,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getWin32Monitor(monitor: Monitor) [*:0]const u8 { pub fn getWin32Monitor(monitor: Monitor) [*:0]const u8 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (native.glfwGetWin32Monitor(@ptrCast(*native.GLFWmonitor, monitor.handle))) |mon| return mon; if (native.glfwGetWin32Monitor(@as(*native.GLFWmonitor, @ptrCast(monitor.handle)))) |mon| return mon;
// `glfwGetWin32Monitor` returns `null` only for errors // `glfwGetWin32Monitor` returns `null` only for errors
// but the only potential error is unreachable (NotInitialized) // but the only potential error is unreachable (NotInitialized)
unreachable; unreachable;
@ -94,8 +94,8 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getWin32Window(window: Window) std.os.windows.HWND { pub fn getWin32Window(window: Window) std.os.windows.HWND {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (native.glfwGetWin32Window(@ptrCast(*native.GLFWwindow, window.handle))) |win| if (native.glfwGetWin32Window(@as(*native.GLFWwindow, @ptrCast(window.handle)))) |win|
return @ptrCast(std.os.windows.HWND, win); return @as(std.os.windows.HWND, @ptrCast(win));
// `glfwGetWin32Window` returns `null` only for errors // `glfwGetWin32Window` returns `null` only for errors
// but the only potential error is unreachable (NotInitialized) // but the only potential error is unreachable (NotInitialized)
unreachable; unreachable;
@ -117,7 +117,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getWGLContext(window: Window) ?std.os.windows.HGLRC { pub fn getWGLContext(window: Window) ?std.os.windows.HGLRC {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (native.glfwGetWGLContext(@ptrCast(*native.GLFWwindow, window.handle))) |context| return context; if (native.glfwGetWGLContext(@as(*native.GLFWwindow, @ptrCast(window.handle)))) |context| return context;
return null; return null;
} }
@ -126,7 +126,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getCocoaMonitor(monitor: Monitor) u32 { pub fn getCocoaMonitor(monitor: Monitor) u32 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const mon = native.glfwGetCocoaMonitor(@ptrCast(*native.GLFWmonitor, monitor.handle)); const mon = native.glfwGetCocoaMonitor(@as(*native.GLFWmonitor, @ptrCast(monitor.handle)));
if (mon != native.kCGNullDirectDisplay) return mon; if (mon != native.kCGNullDirectDisplay) return mon;
// `glfwGetCocoaMonitor` returns `kCGNullDirectDisplay` only for errors // `glfwGetCocoaMonitor` returns `kCGNullDirectDisplay` only for errors
// but the only potential error is unreachable (NotInitialized) // but the only potential error is unreachable (NotInitialized)
@ -138,7 +138,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getCocoaWindow(window: Window) ?*anyopaque { pub fn getCocoaWindow(window: Window) ?*anyopaque {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
return native.glfwGetCocoaWindow(@ptrCast(*native.GLFWwindow, window.handle)); return native.glfwGetCocoaWindow(@as(*native.GLFWwindow, @ptrCast(window.handle)));
} }
/// Returns the `NSWindow` of the specified window. /// Returns the `NSWindow` of the specified window.
@ -148,7 +148,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getNSGLContext(window: Window) u32 { pub fn getNSGLContext(window: Window) u32 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
return native.glfwGetNSGLContext(@ptrCast(*native.GLFWwindow, window.handle)); return native.glfwGetNSGLContext(@as(*native.GLFWwindow, @ptrCast(window.handle)));
} }
/// Returns the `Display` used by GLFW. /// Returns the `Display` used by GLFW.
@ -156,7 +156,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getX11Display() *anyopaque { pub fn getX11Display() *anyopaque {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (native.glfwGetX11Display()) |display| return @ptrCast(*anyopaque, display); if (native.glfwGetX11Display()) |display| return @as(*anyopaque, @ptrCast(display));
// `glfwGetX11Display` returns `null` only for errors // `glfwGetX11Display` returns `null` only for errors
// but the only potential error is unreachable (NotInitialized) // but the only potential error is unreachable (NotInitialized)
unreachable; unreachable;
@ -167,7 +167,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getX11Adapter(monitor: Monitor) u32 { pub fn getX11Adapter(monitor: Monitor) u32 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const adapter = native.glfwGetX11Adapter(@ptrCast(*native.GLFWMonitor, monitor.handle)); const adapter = native.glfwGetX11Adapter(@as(*native.GLFWMonitor, @ptrCast(monitor.handle)));
if (adapter != 0) return adapter; if (adapter != 0) return adapter;
// `glfwGetX11Adapter` returns `0` only for errors // `glfwGetX11Adapter` returns `0` only for errors
// but the only potential error is unreachable (NotInitialized) // but the only potential error is unreachable (NotInitialized)
@ -179,7 +179,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getX11Monitor(monitor: Monitor) u32 { pub fn getX11Monitor(monitor: Monitor) u32 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const mon = native.glfwGetX11Monitor(@ptrCast(*native.GLFWmonitor, monitor.handle)); const mon = native.glfwGetX11Monitor(@as(*native.GLFWmonitor, @ptrCast(monitor.handle)));
if (mon != 0) return mon; if (mon != 0) return mon;
// `glfwGetX11Monitor` returns `0` only for errors // `glfwGetX11Monitor` returns `0` only for errors
// but the only potential error is unreachable (NotInitialized) // but the only potential error is unreachable (NotInitialized)
@ -191,8 +191,8 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getX11Window(window: Window) u32 { pub fn getX11Window(window: Window) u32 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const win = native.glfwGetX11Window(@ptrCast(*native.GLFWwindow, window.handle)); const win = native.glfwGetX11Window(@as(*native.GLFWwindow, @ptrCast(window.handle)));
if (win != 0) return @intCast(u32, win); if (win != 0) return @as(u32, @intCast(win));
// `glfwGetX11Window` returns `0` only for errors // `glfwGetX11Window` returns `0` only for errors
// but the only potential error is unreachable (NotInitialized) // but the only potential error is unreachable (NotInitialized)
unreachable; unreachable;
@ -234,7 +234,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getGLXContext(window: Window) ?*anyopaque { pub fn getGLXContext(window: Window) ?*anyopaque {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (native.glfwGetGLXContext(@ptrCast(*native.GLFWwindow, window.handle))) |context| return @ptrCast(*anyopaque, context); if (native.glfwGetGLXContext(@as(*native.GLFWwindow, @ptrCast(window.handle)))) |context| return @as(*anyopaque, @ptrCast(context));
return null; return null;
} }
@ -246,8 +246,8 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getGLXWindow(window: Window) ?*anyopaque { pub fn getGLXWindow(window: Window) ?*anyopaque {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const win = native.glfwGetGLXWindow(@ptrCast(*native.GLFWwindow, window.handle)); const win = native.glfwGetGLXWindow(@as(*native.GLFWwindow, @ptrCast(window.handle)));
if (win != 0) return @ptrCast(*anyopaque, win); if (win != 0) return @as(*anyopaque, @ptrCast(win));
return null; return null;
} }
@ -256,7 +256,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getWaylandDisplay() *anyopaque { pub fn getWaylandDisplay() *anyopaque {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (native.glfwGetWaylandDisplay()) |display| return @ptrCast(*anyopaque, display); if (native.glfwGetWaylandDisplay()) |display| return @as(*anyopaque, @ptrCast(display));
// `glfwGetWaylandDisplay` returns `null` only for errors // `glfwGetWaylandDisplay` returns `null` only for errors
// but the only potential error is unreachable (NotInitialized) // but the only potential error is unreachable (NotInitialized)
unreachable; unreachable;
@ -267,7 +267,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getWaylandMonitor(monitor: Monitor) *anyopaque { pub fn getWaylandMonitor(monitor: Monitor) *anyopaque {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (native.glfwGetWaylandMonitor(@ptrCast(*native.GLFWmonitor, monitor.handle))) |mon| return @ptrCast(*anyopaque, mon); if (native.glfwGetWaylandMonitor(@as(*native.GLFWmonitor, @ptrCast(monitor.handle)))) |mon| return @as(*anyopaque, @ptrCast(mon));
// `glfwGetWaylandMonitor` returns `null` only for errors // `glfwGetWaylandMonitor` returns `null` only for errors
// but the only potential error is unreachable (NotInitialized) // but the only potential error is unreachable (NotInitialized)
unreachable; unreachable;
@ -278,7 +278,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getWaylandWindow(window: Window) *anyopaque { pub fn getWaylandWindow(window: Window) *anyopaque {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (native.glfwGetWaylandWindow(@ptrCast(*native.GLFWwindow, window.handle))) |win| return @ptrCast(*anyopaque, win); if (native.glfwGetWaylandWindow(@as(*native.GLFWwindow, @ptrCast(window.handle)))) |win| return @as(*anyopaque, @ptrCast(win));
// `glfwGetWaylandWindow` returns `null` only for errors // `glfwGetWaylandWindow` returns `null` only for errors
// but the only potential error is unreachable (NotInitialized) // but the only potential error is unreachable (NotInitialized)
unreachable; unreachable;
@ -293,7 +293,7 @@ pub fn Native(comptime options: BackendOptions) type {
pub fn getEGLDisplay() *anyopaque { pub fn getEGLDisplay() *anyopaque {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const display = native.glfwGetEGLDisplay(); const display = native.glfwGetEGLDisplay();
if (display != native.EGL_NO_DISPLAY) return @ptrCast(*anyopaque, display); if (display != native.EGL_NO_DISPLAY) return @as(*anyopaque, @ptrCast(display));
// `glfwGetEGLDisplay` returns `EGL_NO_DISPLAY` only for errors // `glfwGetEGLDisplay` returns `EGL_NO_DISPLAY` only for errors
// but the only potential error is unreachable (NotInitialized) // but the only potential error is unreachable (NotInitialized)
unreachable; unreachable;
@ -307,8 +307,8 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety This function may be called from any thread. Access is not synchronized. /// thread_safety This function may be called from any thread. Access is not synchronized.
pub fn getEGLContext(window: Window) ?*anyopaque { pub fn getEGLContext(window: Window) ?*anyopaque {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const context = native.glfwGetEGLContext(@ptrCast(*native.GLFWwindow, window.handle)); const context = native.glfwGetEGLContext(@as(*native.GLFWwindow, @ptrCast(window.handle)));
if (context != native.EGL_NO_CONTEXT) return @ptrCast(*anyopaque, context); if (context != native.EGL_NO_CONTEXT) return @as(*anyopaque, @ptrCast(context));
return null; return null;
} }
@ -319,8 +319,8 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety This function may be called from any thread. Access is not synchronized. /// thread_safety This function may be called from any thread. Access is not synchronized.
pub fn getEGLSurface(window: Window) ?*anyopaque { pub fn getEGLSurface(window: Window) ?*anyopaque {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
const surface = native.glfwGetEGLSurface(@ptrCast(*native.GLFWwindow, window.handle)); const surface = native.glfwGetEGLSurface(@as(*native.GLFWwindow, @ptrCast(window.handle)));
if (surface != native.EGL_NO_SURFACE) return @ptrCast(*anyopaque, surface); if (surface != native.EGL_NO_SURFACE) return @as(*anyopaque, @ptrCast(surface));
return null; return null;
} }
@ -341,7 +341,7 @@ pub fn Native(comptime options: BackendOptions) type {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
var buf: OSMesaColorBuffer = undefined; var buf: OSMesaColorBuffer = undefined;
if (native.glfwGetOSMesaColorBuffer( if (native.glfwGetOSMesaColorBuffer(
@ptrCast(*native.GLFWwindow, window.handle), @as(*native.GLFWwindow, @ptrCast(window.handle)),
&buf.width, &buf.width,
&buf.height, &buf.height,
&buf.format, &buf.format,
@ -367,7 +367,7 @@ pub fn Native(comptime options: BackendOptions) type {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
var buf: OSMesaDepthBuffer = undefined; var buf: OSMesaDepthBuffer = undefined;
if (native.glfwGetOSMesaDepthBuffer( if (native.glfwGetOSMesaDepthBuffer(
@ptrCast(*native.GLFWwindow, window.handle), @as(*native.GLFWwindow, @ptrCast(window.handle)),
&buf.width, &buf.width,
&buf.height, &buf.height,
&buf.bytes_per_value, &buf.bytes_per_value,
@ -383,7 +383,7 @@ pub fn Native(comptime options: BackendOptions) type {
/// thread_safety: This function may be called from any thread. Access is not synchronized. /// thread_safety: This function may be called from any thread. Access is not synchronized.
pub fn getOSMesaContext(window: Window) ?*anyopaque { pub fn getOSMesaContext(window: Window) ?*anyopaque {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (native.glfwGetOSMesaContext(@ptrCast(*native.GLFWwindow, window.handle))) |context| return @ptrCast(*anyopaque, context); if (native.glfwGetOSMesaContext(@as(*native.GLFWwindow, @ptrCast(window.handle)))) |context| return @as(*anyopaque, @ptrCast(context));
return null; return null;
} }
}; };

View file

@ -85,7 +85,7 @@ pub inline fn getCurrentContext() ?Window {
/// see also: buffer_swap, glfwSwapBuffers /// see also: buffer_swap, glfwSwapBuffers
pub inline fn swapInterval(interval: i32) void { pub inline fn swapInterval(interval: i32) void {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
c.glfwSwapInterval(@intCast(c_int, interval)); c.glfwSwapInterval(@as(c_int, @intCast(interval)));
} }
/// Returns whether the specified extension is available. /// Returns whether the specified extension is available.

View file

@ -84,7 +84,7 @@ pub inline fn vulkanSupported() bool {
pub inline fn getRequiredInstanceExtensions() ?[][*:0]const u8 { pub inline fn getRequiredInstanceExtensions() ?[][*:0]const u8 {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
var count: u32 = 0; var count: u32 = 0;
if (c.glfwGetRequiredInstanceExtensions(&count)) |extensions| return @ptrCast([*][*:0]const u8, extensions)[0..count]; if (c.glfwGetRequiredInstanceExtensions(&count)) |extensions| return @as([*][*:0]const u8, @ptrCast(extensions))[0..count];
return null; return null;
} }
@ -128,7 +128,7 @@ pub const VKProc = *const fn () callconv(.C) void;
/// @thread_safety This function may be called from any thread. /// @thread_safety This function may be called from any thread.
pub fn getInstanceProcAddress(vk_instance: ?*anyopaque, proc_name: [*:0]const u8) callconv(.C) ?VKProc { pub fn getInstanceProcAddress(vk_instance: ?*anyopaque, proc_name: [*:0]const u8) callconv(.C) ?VKProc {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
if (c.glfwGetInstanceProcAddress(if (vk_instance) |v| @ptrCast(c.VkInstance, v) else null, proc_name)) |proc_address| return proc_address; if (c.glfwGetInstanceProcAddress(if (vk_instance) |v| @as(c.VkInstance, @ptrCast(v)) else null, proc_name)) |proc_address| return proc_address;
return null; return null;
} }
@ -165,8 +165,8 @@ pub inline fn getPhysicalDevicePresentationSupport(
) bool { ) bool {
internal_debug.assertInitialized(); internal_debug.assertInitialized();
return c.glfwGetPhysicalDevicePresentationSupport( return c.glfwGetPhysicalDevicePresentationSupport(
@ptrCast(c.VkInstance, vk_instance), @as(c.VkInstance, @ptrCast(vk_instance)),
@ptrCast(c.VkPhysicalDevice, vk_physical_device), @as(c.VkPhysicalDevice, @ptrCast(vk_physical_device)),
queue_family, queue_family,
) == c.GLFW_TRUE; ) == c.GLFW_TRUE;
} }
@ -231,15 +231,15 @@ pub inline fn createWindowSurface(vk_instance: anytype, window: Window, vk_alloc
// zig-vulkan uses enums to represent opaque pointers: // zig-vulkan uses enums to represent opaque pointers:
// pub const Instance = enum(usize) { null_handle = 0, _ }; // pub const Instance = enum(usize) { null_handle = 0, _ };
const instance: c.VkInstance = switch (@typeInfo(@TypeOf(vk_instance))) { const instance: c.VkInstance = switch (@typeInfo(@TypeOf(vk_instance))) {
.Enum => @ptrFromInt(c.VkInstance, @intFromEnum(vk_instance)), .Enum => @as(c.VkInstance, @ptrFromInt(@intFromEnum(vk_instance))),
else => @ptrCast(c.VkInstance, vk_instance), else => @as(c.VkInstance, @ptrCast(vk_instance)),
}; };
return c.glfwCreateWindowSurface( return c.glfwCreateWindowSurface(
instance, instance,
window.handle, window.handle,
if (vk_allocation_callbacks == null) null else @ptrCast(*const c.VkAllocationCallbacks, @alignCast(@alignOf(c.VkAllocationCallbacks), vk_allocation_callbacks)), if (vk_allocation_callbacks == null) null else @as(*const c.VkAllocationCallbacks, @ptrCast(@alignCast(@alignOf(c.VkAllocationCallbacks), vk_allocation_callbacks))),
@ptrCast(*c.VkSurfaceKHR, @alignCast(@alignOf(c.VkSurfaceKHR), vk_surface_khr)), @as(*c.VkSurfaceKHR, @ptrCast(@alignCast(@alignOf(c.VkSurfaceKHR), vk_surface_khr))),
); );
} }

View file

@ -256,8 +256,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 // 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); var func = @as(FnType, @ptrCast(&objc.objc_msgSend));
const sel = objc.sel_getUid(@ptrCast([*c]const u8, sel_name)); const sel = objc.sel_getUid(@as([*c]const u8, @ptrCast(sel_name)));
return @call(.auto, func, .{ obj, sel } ++ args); return @call(.auto, func, .{ obj, sel } ++ args);
} }

View file

@ -97,7 +97,7 @@ pub const Adapter = opaque {
const Helper = struct { const Helper = struct {
pub fn cCallback(status: RequestDeviceStatus, device: *Device, message: ?[*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { pub fn cCallback(status: RequestDeviceStatus, device: *Device, message: ?[*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
callback( callback(
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), if (Context == void) {} else @as(Context, @ptrCast(@alignCast(@alignOf(Context), userdata))),
status, status,
device, device,
message, message,

View file

@ -56,7 +56,7 @@ pub const Buffer = opaque {
pub const none = UsageFlags{}; pub const none = UsageFlags{};
pub fn equal(a: UsageFlags, b: UsageFlags) bool { pub fn equal(a: UsageFlags, b: UsageFlags) bool {
return @truncate(u10, @bitCast(u32, a)) == @truncate(u10, @bitCast(u32, b)); return @as(u10, @truncate(@as(u32, @bitCast(a)))) == @as(u10, @truncate(@as(u32, @bitCast(b))));
} }
}; };
@ -102,7 +102,7 @@ pub const Buffer = opaque {
offset_bytes, offset_bytes,
size + size % 4, size + size % 4,
); );
return if (data) |d| @ptrCast([*]const T, @alignCast(@alignOf(T), d))[0..len] else null; return if (data) |d| @as([*]const T, @ptrCast(@alignCast(@alignOf(T), d)))[0..len] else null;
} }
/// Default `offset_bytes`: 0 /// Default `offset_bytes`: 0
@ -119,7 +119,7 @@ pub const Buffer = opaque {
offset_bytes, offset_bytes,
size + size % 4, size + size % 4,
); );
return if (data) |d| @ptrCast([*]T, @alignCast(@alignOf(T), d))[0..len] else null; return if (data) |d| @as([*]T, @ptrCast(@alignCast(@alignOf(T), d)))[0..len] else null;
} }
pub inline fn getSize(buffer: *Buffer) u64 { pub inline fn getSize(buffer: *Buffer) u64 {
@ -141,7 +141,7 @@ pub const Buffer = opaque {
const Context = @TypeOf(context); const Context = @TypeOf(context);
const Helper = struct { const Helper = struct {
pub fn cCallback(status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void { pub fn cCallback(status: MapAsyncStatus, userdata: ?*anyopaque) callconv(.C) void {
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), status); callback(if (Context == void) {} else @as(Context, @ptrCast(@alignCast(@alignOf(std.meta.Child(Context)), userdata))), status);
} }
}; };
Impl.bufferMapAsync(buffer, mode, offset, size, Helper.cCallback, if (Context == void) null else context); Impl.bufferMapAsync(buffer, mode, offset, size, Helper.cCallback, if (Context == void) null else context);

View file

@ -98,8 +98,8 @@ pub const CommandEncoder = opaque {
command_encoder, command_encoder,
buffer, buffer,
buffer_offset_bytes, buffer_offset_bytes,
@ptrCast([*]const u8, std.mem.sliceAsBytes(data_slice).ptr), @as([*]const u8, @ptrCast(std.mem.sliceAsBytes(data_slice).ptr)),
@intCast(u64, data_slice.len) * @sizeOf(std.meta.Elem(@TypeOf(data_slice))), @as(u64, @intCast(data_slice.len)) * @sizeOf(std.meta.Elem(@TypeOf(data_slice))),
); );
} }

File diff suppressed because it is too large Load diff

View file

@ -120,7 +120,7 @@ pub const Device = opaque {
status, status,
compute_pipeline, compute_pipeline,
message, message,
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), if (Context == void) {} else @as(Context, @ptrCast(@alignCast(@alignOf(Context), userdata))),
); );
} }
}; };
@ -179,7 +179,7 @@ pub const Device = opaque {
userdata: ?*anyopaque, userdata: ?*anyopaque,
) callconv(.C) void { ) callconv(.C) void {
callback( callback(
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), if (Context == void) {} else @as(Context, @ptrCast(@alignCast(@alignOf(Context), userdata))),
status, status,
pipeline, pipeline,
message, message,
@ -271,7 +271,7 @@ pub const Device = opaque {
const Context = @TypeOf(context); const Context = @TypeOf(context);
const Helper = struct { const Helper = struct {
pub fn cCallback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { pub fn cCallback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), typ, message); callback(if (Context == void) {} else @as(Context, @ptrCast(@alignCast(@alignOf(std.meta.Child(Context)), userdata))), typ, message);
} }
}; };
Impl.devicePopErrorScope(device, Helper.cCallback, if (Context == void) null else context); Impl.devicePopErrorScope(device, Helper.cCallback, if (Context == void) null else context);
@ -290,7 +290,7 @@ pub const Device = opaque {
const Context = @TypeOf(context); const Context = @TypeOf(context);
const Helper = struct { const Helper = struct {
pub fn cCallback(reason: LostReason, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { pub fn cCallback(reason: LostReason, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
cb(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), reason, message); cb(if (Context == void) {} else @as(Context, @ptrCast(@alignCast(@alignOf(std.meta.Child(Context)), userdata))), reason, message);
} }
}; };
Impl.deviceSetDeviceLostCallback(device, Helper.cCallback, if (Context == void) null else context); Impl.deviceSetDeviceLostCallback(device, Helper.cCallback, if (Context == void) null else context);
@ -312,7 +312,7 @@ pub const Device = opaque {
const Context = @TypeOf(context); const Context = @TypeOf(context);
const Helper = struct { const Helper = struct {
pub fn cCallback(typ: LoggingType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { pub fn cCallback(typ: LoggingType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
cb(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), typ, message); cb(if (Context == void) {} else @as(Context, @ptrCast(@alignCast(@alignOf(std.meta.Child(Context)), userdata))), typ, message);
} }
}; };
Impl.deviceSetLoggingCallback(device, Helper.cCallback, if (Context == void) null else context); Impl.deviceSetLoggingCallback(device, Helper.cCallback, if (Context == void) null else context);
@ -330,7 +330,7 @@ pub const Device = opaque {
const Context = @TypeOf(context); const Context = @TypeOf(context);
const Helper = struct { const Helper = struct {
pub fn cCallback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { pub fn cCallback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void {
cb(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), typ, message); cb(if (Context == void) {} else @as(Context, @ptrCast(@alignCast(@alignOf(std.meta.Child(Context)), userdata))), typ, message);
} }
}; };
Impl.deviceSetUncapturedErrorCallback(device, Helper.cCallback, if (Context == void) null else context); Impl.deviceSetUncapturedErrorCallback(device, Helper.cCallback, if (Context == void) null else context);

View file

@ -45,7 +45,7 @@ pub const Instance = opaque {
userdata: ?*anyopaque, userdata: ?*anyopaque,
) callconv(.C) void { ) callconv(.C) void {
callback( callback(
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), if (Context == void) {} else @as(Context, @ptrCast(@alignCast(@alignOf(Context), userdata))),
status, status,
adapter, adapter,
message, message,

View file

@ -344,7 +344,7 @@ pub fn Export(comptime T: type) type {
// WGPU_EXPORT void wgpuBufferMapAsync(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapCallback callback, void * userdata); // WGPU_EXPORT void wgpuBufferMapAsync(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapCallback callback, void * userdata);
export fn wgpuBufferMapAsync(buffer: *gpu.Buffer, mode: u32, offset: usize, size: usize, callback: gpu.Buffer.MapCallback, userdata: ?*anyopaque) void { export fn wgpuBufferMapAsync(buffer: *gpu.Buffer, mode: u32, offset: usize, size: usize, callback: gpu.Buffer.MapCallback, userdata: ?*anyopaque) void {
T.bufferMapAsync(buffer, @bitCast(gpu.MapModeFlags, mode), offset, size, callback, userdata); T.bufferMapAsync(buffer, @as(gpu.MapModeFlags, @bitCast(mode)), offset, size, callback, userdata);
} }
// WGPU_EXPORT void wgpuBufferSetLabel(WGPUBuffer buffer, char const * label); // WGPU_EXPORT void wgpuBufferSetLabel(WGPUBuffer buffer, char const * label);

View file

@ -478,7 +478,7 @@ pub const ColorWriteMaskFlags = packed struct(u32) {
}; };
pub fn equal(a: ColorWriteMaskFlags, b: ColorWriteMaskFlags) bool { pub fn equal(a: ColorWriteMaskFlags, b: ColorWriteMaskFlags) bool {
return @truncate(u4, @bitCast(u32, a)) == @truncate(u4, @bitCast(u32, b)); return @as(u4, @truncate(@as(u32, @bitCast(a)))) == @as(u4, @truncate(@as(u32, @bitCast(b))));
} }
}; };
@ -498,7 +498,7 @@ pub const MapModeFlags = packed struct(u32) {
pub const undef = MapModeFlags{}; pub const undef = MapModeFlags{};
pub fn equal(a: MapModeFlags, b: MapModeFlags) bool { pub fn equal(a: MapModeFlags, b: MapModeFlags) bool {
return @truncate(u2, @bitCast(u32, a)) == @truncate(u2, @bitCast(u32, b)); return @as(u2, @truncate(@as(u32, @bitCast(a)))) == @as(u2, @truncate(@as(u32, @bitCast(b))));
} }
}; };
@ -519,7 +519,7 @@ pub const ShaderStageFlags = packed struct(u32) {
pub const none = ShaderStageFlags{}; pub const none = ShaderStageFlags{};
pub fn equal(a: ShaderStageFlags, b: ShaderStageFlags) bool { pub fn equal(a: ShaderStageFlags, b: ShaderStageFlags) bool {
return @truncate(u3, @bitCast(u32, a)) == @truncate(u3, @bitCast(u32, b)); return @as(u3, @truncate(@as(u32, @bitCast(a)))) == @as(u3, @truncate(@as(u32, @bitCast(b))));
} }
}; };

View file

@ -45,7 +45,7 @@ pub const Queue = opaque {
const Context = @TypeOf(context); const Context = @TypeOf(context);
const Helper = struct { const Helper = struct {
pub fn cCallback(status: WorkDoneStatus, userdata: ?*anyopaque) callconv(.C) void { pub fn cCallback(status: WorkDoneStatus, userdata: ?*anyopaque) callconv(.C) void {
callback(if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(std.meta.Child(Context)), userdata)), status); callback(if (Context == void) {} else @as(Context, @ptrCast(@alignCast(@alignOf(std.meta.Child(Context)), userdata))), status);
} }
}; };
Impl.queueOnSubmittedWorkDone(queue, signal_value, Helper.cCallback, if (Context == void) null else context); Impl.queueOnSubmittedWorkDone(queue, signal_value, Helper.cCallback, if (Context == void) null else context);
@ -69,7 +69,7 @@ pub const Queue = opaque {
queue, queue,
buffer, buffer,
buffer_offset_bytes, buffer_offset_bytes,
@ptrCast(*const anyopaque, std.mem.sliceAsBytes(data_slice).ptr), @as(*const anyopaque, @ptrCast(std.mem.sliceAsBytes(data_slice).ptr)),
data_slice.len * @sizeOf(std.meta.Elem(@TypeOf(data_slice))), data_slice.len * @sizeOf(std.meta.Elem(@TypeOf(data_slice))),
); );
} }
@ -84,8 +84,8 @@ pub const Queue = opaque {
Impl.queueWriteTexture( Impl.queueWriteTexture(
queue, queue,
destination, destination,
@ptrCast(*const anyopaque, std.mem.sliceAsBytes(data_slice).ptr), @as(*const anyopaque, @ptrCast(std.mem.sliceAsBytes(data_slice).ptr)),
@intCast(usize, data_slice.len) * @sizeOf(std.meta.Elem(@TypeOf(data_slice))), @as(usize, @intCast(data_slice.len)) * @sizeOf(std.meta.Elem(@TypeOf(data_slice))),
data_layout, data_layout,
write_size, write_size,
); );

View file

@ -46,7 +46,7 @@ pub const ShaderModule = opaque {
userdata: ?*anyopaque, userdata: ?*anyopaque,
) callconv(.C) void { ) callconv(.C) void {
callback( callback(
if (Context == void) {} else @ptrCast(Context, @alignCast(@alignOf(Context), userdata)), if (Context == void) {} else @as(Context, @ptrCast(@alignCast(@alignOf(Context), userdata))),
status, status,
compilation_info, compilation_info,
); );

View file

@ -149,7 +149,7 @@ pub const Texture = opaque {
pub const none = UsageFlags{}; pub const none = UsageFlags{};
pub fn equal(a: UsageFlags, b: UsageFlags) bool { pub fn equal(a: UsageFlags, b: UsageFlags) bool {
return @truncate(u6, @bitCast(u32, a)) == @truncate(u6, @bitCast(u32, b)); return @as(u6, @truncate(@as(u32, @bitCast(a)))) == @as(u6, @truncate(@as(u32, @bitCast(b))));
} }
}; };

View file

@ -64,7 +64,7 @@ pub fn save(self: M3d, quality: Quality, flags: Flags) Error![]u8 {
return if (c.m3d_save( return if (c.m3d_save(
self.handle, self.handle,
@intFromEnum(quality), @intFromEnum(quality),
@bitCast(c_int, flags), @as(c_int, @bitCast(flags)),
&size, &size,
)) |res| )) |res|
res[0..size] res[0..size]

View file

@ -53,12 +53,12 @@ const pitch = 440.0;
const radians_per_second = pitch * 2.0 * std.math.pi; const radians_per_second = pitch * 2.0 * std.math.pi;
var seconds_offset: f32 = 0.0; var seconds_offset: f32 = 0.0;
fn writeCallback(_: ?*anyopaque, frames: usize) void { fn writeCallback(_: ?*anyopaque, frames: usize) void {
const seconds_per_frame = 1.0 / @floatFromInt(f32, player.sampleRate()); const seconds_per_frame = 1.0 / @as(f32, @floatFromInt(player.sampleRate()));
for (0..frames) |fi| { for (0..frames) |fi| {
const sample = std.math.sin((seconds_offset + @floatFromInt(f32, fi) * seconds_per_frame) * radians_per_second); const sample = std.math.sin((seconds_offset + @as(f32, @floatFromInt(fi)) * seconds_per_frame) * radians_per_second);
player.writeAll(fi, sample); player.writeAll(fi, sample);
} }
seconds_offset = @mod(seconds_offset + seconds_per_frame * @floatFromInt(f32, frames), 1.0); seconds_offset = @mod(seconds_offset + seconds_per_frame * @as(f32, @floatFromInt(frames)), 1.0);
} }
fn deviceChange(_: ?*anyopaque) void { fn deviceChange(_: ?*anyopaque) void {

View file

@ -134,7 +134,7 @@ pub const Context = struct {
pub fn init(allocator: std.mem.Allocator, options: main.Context.Options) !backends.BackendContext { pub fn init(allocator: std.mem.Allocator, options: main.Context.Options) !backends.BackendContext {
try lib.load(); try lib.load();
_ = lib.snd_lib_error_set_handler(@ptrCast(c.snd_lib_error_handler_t, &util.doNothing)); _ = lib.snd_lib_error_set_handler(@as(c.snd_lib_error_handler_t, @ptrCast(&util.doNothing)));
var self = try allocator.create(Context); var self = try allocator.create(Context);
errdefer allocator.destroy(self); errdefer allocator.destroy(self);
@ -273,8 +273,8 @@ pub const Context = struct {
var i: usize = 0; var i: usize = 0;
var evt: *inotify_event = undefined; var evt: *inotify_event = undefined;
while (i < buf.len) : (i += @sizeOf(inotify_event) + evt.len) { while (i < buf.len) : (i += @sizeOf(inotify_event) + evt.len) {
evt = @ptrCast(*inotify_event, @alignCast(4, buf[i..])); evt = @as(*inotify_event, @ptrCast(@alignCast(4, buf[i..])));
const evt_name = @ptrCast([*]u8, buf[i..])[@sizeOf(inotify_event) .. @sizeOf(inotify_event) + 8]; const evt_name = @as([*]u8, @ptrCast(buf[i..]))[@sizeOf(inotify_event) .. @sizeOf(inotify_event) + 8];
if (evt.mask & std.os.linux.IN.ISDIR != 0 or !std.mem.startsWith(u8, evt_name, "pcm")) if (evt.mask & std.os.linux.IN.ISDIR != 0 or !std.mem.startsWith(u8, evt_name, "pcm"))
continue; continue;
@ -320,7 +320,7 @@ pub const Context = struct {
if (lib.snd_ctl_pcm_next_device(ctl, &dev_idx) < 0) if (lib.snd_ctl_pcm_next_device(ctl, &dev_idx) < 0)
return error.SystemResources; return error.SystemResources;
lib.snd_pcm_info_set_device(pcm_info, @intCast(c_uint, dev_idx)); lib.snd_pcm_info_set_device(pcm_info, @as(c_uint, @intCast(dev_idx)));
lib.snd_pcm_info_set_subdevice(pcm_info, 0); lib.snd_pcm_info_set_subdevice(pcm_info, 0);
const name = std.mem.span(lib.snd_pcm_info_get_name(pcm_info) orelse continue); const name = std.mem.span(lib.snd_pcm_info_get_name(pcm_info) orelse continue);
@ -328,7 +328,7 @@ pub const Context = struct {
const snd_stream = modeToStream(mode); const snd_stream = modeToStream(mode);
lib.snd_pcm_info_set_stream(pcm_info, snd_stream); lib.snd_pcm_info_set_stream(pcm_info, snd_stream);
const err = lib.snd_ctl_pcm_info(ctl, pcm_info); const err = lib.snd_ctl_pcm_info(ctl, pcm_info);
switch (@enumFromInt(std.os.E, -err)) { switch (@as(std.os.E, @enumFromInt(-err))) {
.SUCCESS => {}, .SUCCESS => {},
.NOENT, .NOENT,
.NXIO, .NXIO,
@ -417,8 +417,8 @@ pub const Context = struct {
if (lib.snd_pcm_hw_params_get_rate_max(params, &rate_max, null) < 0) if (lib.snd_pcm_hw_params_get_rate_max(params, &rate_max, null) < 0)
continue; continue;
break :blk .{ break :blk .{
.min = @intCast(u24, rate_min), .min = @as(u24, @intCast(rate_min)),
.max = @intCast(u24, rate_max), .max = @as(u24, @intCast(rate_max)),
}; };
}, },
.id = try self.allocator.dupeZ(u8, id), .id = try self.allocator.dupeZ(u8, id),
@ -464,7 +464,7 @@ pub const Context = struct {
pcm, pcm,
toAlsaFormat(format), toAlsaFormat(format),
c.SND_PCM_ACCESS_RW_INTERLEAVED, c.SND_PCM_ACCESS_RW_INTERLEAVED,
@intCast(c_uint, device.channels.len), @as(c_uint, @intCast(device.channels.len)),
sample_rate, sample_rate,
1, 1,
main.default_latency, main.default_latency,
@ -622,10 +622,10 @@ pub const Player = struct {
if (lib.snd_mixer_selem_get_playback_volume_range(self.mixer_elm, &min_vol, &max_vol) < 0) if (lib.snd_mixer_selem_get_playback_volume_range(self.mixer_elm, &min_vol, &max_vol) < 0)
return error.CannotSetVolume; return error.CannotSetVolume;
const dist = @floatFromInt(f32, max_vol - min_vol); const dist = @as(f32, @floatFromInt(max_vol - min_vol));
if (lib.snd_mixer_selem_set_playback_volume_all( if (lib.snd_mixer_selem_set_playback_volume_all(
self.mixer_elm, self.mixer_elm,
@intFromFloat(c_long, dist * vol) + min_vol, @as(c_long, @intFromFloat(dist * vol)) + min_vol,
) < 0) ) < 0)
return error.CannotSetVolume; return error.CannotSetVolume;
} }
@ -652,7 +652,7 @@ pub const Player = struct {
if (lib.snd_mixer_selem_get_playback_volume_range(self.mixer_elm, &min_vol, &max_vol) < 0) if (lib.snd_mixer_selem_get_playback_volume_range(self.mixer_elm, &min_vol, &max_vol) < 0)
return error.CannotGetVolume; return error.CannotGetVolume;
return @floatFromInt(f32, vol) / @floatFromInt(f32, max_vol - min_vol); return @as(f32, @floatFromInt(vol)) / @as(f32, @floatFromInt(max_vol - min_vol));
} }
}; };

View file

@ -72,7 +72,7 @@ pub const Context = struct {
0, 0,
null, null,
&io_size, &io_size,
@ptrCast(*anyopaque, devs), @as(*anyopaque, @ptrCast(devs)),
) != c.noErr) { ) != c.noErr) {
return error.OpeningDevice; return error.OpeningDevice;
} }
@ -128,7 +128,7 @@ pub const Context = struct {
0, 0,
null, null,
&io_size, &io_size,
@ptrCast(*anyopaque, buf_list), @as(*anyopaque, @ptrCast(buf_list)),
) != c.noErr) { ) != c.noErr) {
return error.OpeningDevice; return error.OpeningDevice;
} }
@ -210,8 +210,8 @@ pub const Context = struct {
.channels = channels, .channels = channels,
.formats = &.{ .i16, .i32, .f32 }, .formats = &.{ .i16, .i32, .f32 },
.sample_rate = .{ .sample_rate = .{
.min = @intFromFloat(u24, @floor(sample_rate)), .min = @as(u24, @intFromFloat(@floor(sample_rate))),
.max = @intFromFloat(u24, @floor(sample_rate)), .max = @as(u24, @intFromFloat(@floor(sample_rate))),
}, },
}; };
@ -334,10 +334,10 @@ pub const Player = struct {
_ = bus_number; _ = bus_number;
_ = frames_left; _ = frames_left;
const self = @ptrCast(*Player, @alignCast(@alignOf(*Player), self_opaque.?)); const self = @as(*Player, @ptrCast(@alignCast(@alignOf(*Player), self_opaque.?)));
for (self.channels, 0..) |*ch, i| { for (self.channels, 0..) |*ch, i| {
ch.ptr = @ptrCast([*]u8, buf.*.mBuffers[0].mData.?) + self.format.frameSize(i); ch.ptr = @as([*]u8, @ptrCast(buf.*.mBuffers[0].mData.?)) + self.format.frameSize(i);
} }
const frames = buf.*.mBuffers[0].mDataByteSize / self.format.frameSize(self.channels.len); const frames = buf.*.mBuffers[0].mDataByteSize / self.format.frameSize(self.channels.len);
self.writeFn(self.user_data, frames); self.writeFn(self.user_data, frames);
@ -412,7 +412,7 @@ fn freeDevice(allocator: std.mem.Allocator, device: main.Device) void {
fn createStreamDesc(format: main.Format, sample_rate: u24, ch_count: usize) !c.AudioStreamBasicDescription { fn createStreamDesc(format: main.Format, sample_rate: u24, ch_count: usize) !c.AudioStreamBasicDescription {
var desc = c.AudioStreamBasicDescription{ var desc = c.AudioStreamBasicDescription{
.mSampleRate = @floatFromInt(f64, sample_rate), .mSampleRate = @as(f64, @floatFromInt(sample_rate)),
.mFormatID = c.kAudioFormatLinearPCM, .mFormatID = c.kAudioFormatLinearPCM,
.mFormatFlags = switch (format) { .mFormatFlags = switch (format) {
.i16 => c.kAudioFormatFlagIsSignedInteger, .i16 => c.kAudioFormatFlagIsSignedInteger,
@ -425,7 +425,7 @@ fn createStreamDesc(format: main.Format, sample_rate: u24, ch_count: usize) !c.A
.mBytesPerPacket = format.frameSize(ch_count), .mBytesPerPacket = format.frameSize(ch_count),
.mFramesPerPacket = 1, .mFramesPerPacket = 1,
.mBytesPerFrame = format.frameSize(ch_count), .mBytesPerFrame = format.frameSize(ch_count),
.mChannelsPerFrame = @intCast(c_uint, ch_count), .mChannelsPerFrame = @as(c_uint, @intCast(ch_count)),
.mBitsPerChannel = switch (format) { .mBitsPerChannel = switch (format) {
.i16 => 16, .i16 => 16,
.i24 => 24, .i24 => 24,

View file

@ -74,8 +74,8 @@ pub const Context = struct {
pub fn init(allocator: std.mem.Allocator, options: main.Context.Options) !backends.BackendContext { pub fn init(allocator: std.mem.Allocator, options: main.Context.Options) !backends.BackendContext {
try lib.load(); try lib.load();
lib.jack_set_error_function(@ptrCast(?*const fn ([*c]const u8) callconv(.C) void, &util.doNothing)); lib.jack_set_error_function(@as(?*const fn ([*c]const u8) callconv(.C) void, @ptrCast(&util.doNothing)));
lib.jack_set_info_function(@ptrCast(?*const fn ([*c]const u8) callconv(.C) void, &util.doNothing)); lib.jack_set_info_function(@as(?*const fn ([*c]const u8) callconv(.C) void, @ptrCast(&util.doNothing)));
var status: c.jack_status_t = 0; var status: c.jack_status_t = 0;
var self = try allocator.create(Context); var self = try allocator.create(Context);
@ -120,16 +120,16 @@ pub const Context = struct {
freeDevice(self.allocator, d); freeDevice(self.allocator, d);
self.devices_info.clear(self.allocator); self.devices_info.clear(self.allocator);
const sample_rate = @intCast(u24, lib.jack_get_sample_rate(self.client)); const sample_rate = @as(u24, @intCast(lib.jack_get_sample_rate(self.client)));
const port_names = lib.jack_get_ports(self.client, null, null, 0) orelse const port_names = lib.jack_get_ports(self.client, null, null, 0) orelse
return error.OutOfMemory; return error.OutOfMemory;
defer lib.jack_free(@ptrCast(?*anyopaque, port_names)); defer lib.jack_free(@as(?*anyopaque, @ptrCast(port_names)));
var i: usize = 0; var i: usize = 0;
outer: while (port_names[i] != null) : (i += 1) { outer: while (port_names[i] != null) : (i += 1) {
const port = lib.jack_port_by_name(self.client, port_names[i]) orelse break; const port = lib.jack_port_by_name(self.client, port_names[i]) orelse break;
const port_type = lib.jack_port_type(port)[0..@intCast(usize, lib.jack_port_type_size())]; const port_type = lib.jack_port_type(port)[0..@as(usize, @intCast(lib.jack_port_type_size()))];
if (!std.mem.startsWith(u8, port_type, c.JACK_DEFAULT_AUDIO_TYPE)) if (!std.mem.startsWith(u8, port_type, c.JACK_DEFAULT_AUDIO_TYPE))
continue; continue;
@ -142,7 +142,7 @@ pub const Context = struct {
for (self.devices_info.list.items) |*dev| { for (self.devices_info.list.items) |*dev| {
if (std.mem.eql(u8, dev.id, id) and mode == dev.mode) { if (std.mem.eql(u8, dev.id, id) and mode == dev.mode) {
const new_ch = main.Channel{ const new_ch = main.Channel{
.id = @enumFromInt(main.Channel.Id, dev.channels.len), .id = @as(main.Channel.Id, @enumFromInt(dev.channels.len)),
}; };
dev.channels = try self.allocator.realloc(dev.channels, dev.channels.len + 1); dev.channels = try self.allocator.realloc(dev.channels, dev.channels.len + 1);
dev.channels[dev.channels.len - 1] = new_ch; dev.channels[dev.channels.len - 1] = new_ch;
@ -156,7 +156,7 @@ pub const Context = struct {
.mode = mode, .mode = mode,
.channels = blk: { .channels = blk: {
var channels = try self.allocator.alloc(main.Channel, 1); var channels = try self.allocator.alloc(main.Channel, 1);
channels[0] = .{ .id = @enumFromInt(main.Channel.Id, 0) }; channels[0] = .{ .id = @as(main.Channel.Id, @enumFromInt(0)) };
break :blk channels; break :blk channels;
}, },
.formats = &.{.f32}, .formats = &.{.f32},
@ -174,18 +174,18 @@ pub const Context = struct {
} }
fn sampleRateCallback(_: c.jack_nframes_t, arg: ?*anyopaque) callconv(.C) c_int { fn sampleRateCallback(_: c.jack_nframes_t, arg: ?*anyopaque) callconv(.C) c_int {
var self = @ptrCast(*Context, @alignCast(@alignOf(*Context), arg.?)); var self = @as(*Context, @ptrCast(@alignCast(@alignOf(*Context), arg.?)));
self.watcher.?.deviceChangeFn(self.watcher.?.user_data); self.watcher.?.deviceChangeFn(self.watcher.?.user_data);
return 0; return 0;
} }
fn portRegistrationCallback(_: c.jack_port_id_t, _: c_int, arg: ?*anyopaque) callconv(.C) void { fn portRegistrationCallback(_: c.jack_port_id_t, _: c_int, arg: ?*anyopaque) callconv(.C) void {
var self = @ptrCast(*Context, @alignCast(@alignOf(*Context), arg.?)); var self = @as(*Context, @ptrCast(@alignCast(@alignOf(*Context), arg.?)));
self.watcher.?.deviceChangeFn(self.watcher.?.user_data); self.watcher.?.deviceChangeFn(self.watcher.?.user_data);
} }
fn portRenameCalllback(_: c.jack_port_id_t, _: [*c]const u8, _: [*c]const u8, arg: ?*anyopaque) callconv(.C) void { fn portRenameCalllback(_: c.jack_port_id_t, _: [*c]const u8, _: [*c]const u8, arg: ?*anyopaque) callconv(.C) void {
var self = @ptrCast(*Context, @alignCast(@alignOf(*Context), arg.?)); var self = @as(*Context, @ptrCast(@alignCast(@alignOf(*Context), arg.?)));
self.watcher.?.deviceChangeFn(self.watcher.?.user_data); self.watcher.?.deviceChangeFn(self.watcher.?.user_data);
} }
@ -266,10 +266,10 @@ pub const Player = struct {
} }
fn processCallback(n_frames: c.jack_nframes_t, self_opaque: ?*anyopaque) callconv(.C) c_int { fn processCallback(n_frames: c.jack_nframes_t, self_opaque: ?*anyopaque) callconv(.C) c_int {
const self = @ptrCast(*Player, @alignCast(@alignOf(*Player), self_opaque.?)); const self = @as(*Player, @ptrCast(@alignCast(@alignOf(*Player), self_opaque.?)));
for (self.channels, 0..) |*ch, i| { for (self.channels, 0..) |*ch, i| {
ch.*.ptr = @ptrCast([*]u8, lib.jack_port_get_buffer(self.ports[i], n_frames)); ch.*.ptr = @as([*]u8, @ptrCast(lib.jack_port_get_buffer(self.ports[i], n_frames)));
} }
self.writeFn(self.user_data, n_frames); self.writeFn(self.user_data, n_frames);
@ -313,7 +313,7 @@ pub const Player = struct {
} }
pub fn sampleRate(self: Player) u24 { pub fn sampleRate(self: Player) u24 {
return @intCast(u24, lib.jack_get_sample_rate(self.client)); return @as(u24, @intCast(lib.jack_get_sample_rate(self.client)));
} }
}; };

View file

@ -37,7 +37,7 @@ pub const Context = struct {
} else { } else {
inline for (std.meta.fields(Backend), 0..) |b, i| { inline for (std.meta.fields(Backend), 0..) |b, i| {
if (@typeInfo( if (@typeInfo(
std.meta.fieldInfo(backends.BackendContext, @enumFromInt(Backend, b.value)).type, std.meta.fieldInfo(backends.BackendContext, @as(Backend, @enumFromInt(b.value))).type,
).Pointer.child.init(allocator, options)) |d| { ).Pointer.child.init(allocator, options)) |d| {
break :blk d; break :blk d;
} else |err| { } else |err| {
@ -275,37 +275,37 @@ pub const Player = struct {
fn unsignedToSigned(comptime T: type, sample: anytype) T { fn unsignedToSigned(comptime T: type, sample: anytype) T {
const half = 1 << (@bitSizeOf(@TypeOf(sample)) - 1); const half = 1 << (@bitSizeOf(@TypeOf(sample)) - 1);
const trunc = @bitSizeOf(T) - @bitSizeOf(@TypeOf(sample)); const trunc = @bitSizeOf(T) - @bitSizeOf(@TypeOf(sample));
return @intCast(T, sample -% half) << trunc; return @as(T, @intCast(sample -% half)) << trunc;
} }
fn unsignedToFloat(comptime T: type, sample: anytype) T { fn unsignedToFloat(comptime T: type, sample: anytype) T {
const max_int = std.math.maxInt(@TypeOf(sample)) + 1.0; const max_int = std.math.maxInt(@TypeOf(sample)) + 1.0;
return (@floatFromInt(T, sample) - max_int) * 1.0 / max_int; return (@as(T, @floatFromInt(sample)) - max_int) * 1.0 / max_int;
} }
fn signedToSigned(comptime T: type, sample: anytype) T { fn signedToSigned(comptime T: type, sample: anytype) T {
const trunc = @bitSizeOf(@TypeOf(sample)) - @bitSizeOf(T); const trunc = @bitSizeOf(@TypeOf(sample)) - @bitSizeOf(T);
return @intCast(T, sample >> trunc); return @as(T, @intCast(sample >> trunc));
} }
fn signedToUnsigned(comptime T: type, sample: anytype) T { fn signedToUnsigned(comptime T: type, sample: anytype) T {
const half = 1 << (@bitSizeOf(T) - 1); const half = 1 << (@bitSizeOf(T) - 1);
const trunc = @bitSizeOf(@TypeOf(sample)) - @bitSizeOf(T); const trunc = @bitSizeOf(@TypeOf(sample)) - @bitSizeOf(T);
return @intCast(T, (sample >> trunc) + half); return @as(T, @intCast((sample >> trunc) + half));
} }
fn signedToFloat(comptime T: type, sample: anytype) T { fn signedToFloat(comptime T: type, sample: anytype) T {
const max_int = std.math.maxInt(@TypeOf(sample)) + 1.0; const max_int = std.math.maxInt(@TypeOf(sample)) + 1.0;
return @floatFromInt(T, sample) * 1.0 / max_int; return @as(T, @floatFromInt(sample)) * 1.0 / max_int;
} }
fn floatToSigned(comptime T: type, sample: f64) T { fn floatToSigned(comptime T: type, sample: f64) T {
return @intFromFloat(T, sample * std.math.maxInt(T)); return @as(T, @intFromFloat(sample * std.math.maxInt(T)));
} }
fn floatToUnsigned(comptime T: type, sample: f64) T { fn floatToUnsigned(comptime T: type, sample: f64) T {
const half = 1 << @bitSizeOf(T) - 1; const half = 1 << @bitSizeOf(T) - 1;
return @intFromFloat(T, sample * (half - 1) + half); return @as(T, @intFromFloat(sample * (half - 1) + half));
} }
pub const Device = struct { pub const Device = struct {
@ -404,7 +404,7 @@ pub const Format = enum {
} }
pub fn frameSize(self: Format, ch_count: usize) u8 { pub fn frameSize(self: Format, ch_count: usize) u8 {
return self.size() * @intCast(u5, ch_count); return self.size() * @as(u5, @intCast(ch_count));
} }
}; };

View file

@ -208,7 +208,7 @@ pub const Context = struct {
c.PW_KEY_AUDIO_RATE, c.PW_KEY_AUDIO_RATE,
audio_rate.ptr, audio_rate.ptr,
@ptrFromInt(*allowzero u0, 0), @as(*allowzero u0, @ptrFromInt(0)),
); );
var player = try self.allocator.create(Player); var player = try self.allocator.create(Player);
@ -236,7 +236,7 @@ pub const Context = struct {
}; };
var info = c.spa_audio_info_raw{ var info = c.spa_audio_info_raw{
.format = c.SPA_AUDIO_FORMAT_F32, .format = c.SPA_AUDIO_FORMAT_F32,
.channels = @intCast(u32, device.channels.len), .channels = @as(u32, @intCast(device.channels.len)),
.rate = options.sample_rate, .rate = options.sample_rate,
.flags = 0, .flags = 0,
.position = undefined, .position = undefined,
@ -289,7 +289,7 @@ pub const Player = struct {
_ = old_state; _ = old_state;
_ = err; _ = err;
var self = @ptrCast(*Player, @alignCast(@alignOf(*Player), self_opaque.?)); var self = @as(*Player, @ptrCast(@alignCast(@alignOf(*Player), self_opaque.?)));
if (state == c.PW_STREAM_STATE_STREAMING or state == c.PW_STREAM_STATE_ERROR) { if (state == c.PW_STREAM_STATE_STREAMING or state == c.PW_STREAM_STATE_ERROR) {
lib.pw_thread_loop_signal(self.thread, false); lib.pw_thread_loop_signal(self.thread, false);
@ -297,7 +297,7 @@ pub const Player = struct {
} }
pub fn processCb(self_opaque: ?*anyopaque) callconv(.C) void { pub fn processCb(self_opaque: ?*anyopaque) callconv(.C) void {
var self = @ptrCast(*Player, @alignCast(@alignOf(*Player), self_opaque.?)); var self = @as(*Player, @ptrCast(@alignCast(@alignOf(*Player), self_opaque.?)));
const buf = lib.pw_stream_dequeue_buffer(self.stream) orelse unreachable; const buf = lib.pw_stream_dequeue_buffer(self.stream) orelse unreachable;
if (buf.*.buffer.*.datas[0].data == null) return; if (buf.*.buffer.*.datas[0].data == null) return;
@ -313,10 +313,10 @@ pub const Player = struct {
const stride = self.format.frameSize(self.channels.len); const stride = self.format.frameSize(self.channels.len);
const n_frames = @min(buf.*.requested, buf.*.buffer.*.datas[0].maxsize / stride); const n_frames = @min(buf.*.requested, buf.*.buffer.*.datas[0].maxsize / stride);
buf.*.buffer.*.datas[0].chunk.*.stride = stride; buf.*.buffer.*.datas[0].chunk.*.stride = stride;
buf.*.buffer.*.datas[0].chunk.*.size = @intCast(u32, n_frames * stride); buf.*.buffer.*.datas[0].chunk.*.size = @as(u32, @intCast(n_frames * stride));
for (self.channels, 0..) |*ch, i| { for (self.channels, 0..) |*ch, i| {
ch.ptr = @ptrCast([*]u8, buf.*.buffer.*.datas[0].data.?) + self.format.frameSize(i); ch.ptr = @as([*]u8, @ptrCast(buf.*.buffer.*.datas[0].data.?)) + self.format.frameSize(i);
} }
self.writeFn(self.user_data, n_frames); self.writeFn(self.user_data, n_frames);
} }

View file

@ -192,12 +192,12 @@ pub const Context = struct {
} }
fn subscribeOp(_: ?*c.pa_context, _: c.pa_subscription_event_type_t, _: u32, user_data: ?*anyopaque) callconv(.C) void { fn subscribeOp(_: ?*c.pa_context, _: c.pa_subscription_event_type_t, _: u32, user_data: ?*anyopaque) callconv(.C) void {
var self = @ptrCast(*Context, @alignCast(@alignOf(*Context), user_data.?)); var self = @as(*Context, @ptrCast(@alignCast(@alignOf(*Context), user_data.?)));
self.watcher.?.deviceChangeFn(self.watcher.?.user_data); self.watcher.?.deviceChangeFn(self.watcher.?.user_data);
} }
fn contextStateOp(ctx: ?*c.pa_context, user_data: ?*anyopaque) callconv(.C) void { fn contextStateOp(ctx: ?*c.pa_context, user_data: ?*anyopaque) callconv(.C) void {
var self = @ptrCast(*Context, @alignCast(@alignOf(*Context), user_data.?)); var self = @as(*Context, @ptrCast(@alignCast(@alignOf(*Context), user_data.?)));
self.ctx_state = lib.pa_context_get_state(ctx); self.ctx_state = lib.pa_context_get_state(ctx);
lib.pa_threaded_mainloop_signal(self.main_loop, 0); lib.pa_threaded_mainloop_signal(self.main_loop, 0);
@ -255,7 +255,7 @@ pub const Context = struct {
} }
fn serverInfoOp(_: ?*c.pa_context, info: [*c]const c.pa_server_info, user_data: ?*anyopaque) callconv(.C) void { fn serverInfoOp(_: ?*c.pa_context, info: [*c]const c.pa_server_info, user_data: ?*anyopaque) callconv(.C) void {
var self = @ptrCast(*Context, @alignCast(@alignOf(*Context), user_data.?)); var self = @as(*Context, @ptrCast(@alignCast(@alignOf(*Context), user_data.?)));
defer lib.pa_threaded_mainloop_signal(self.main_loop, 0); defer lib.pa_threaded_mainloop_signal(self.main_loop, 0);
self.default_sink = self.allocator.dupeZ(u8, std.mem.span(info.*.default_sink_name)) catch return; self.default_sink = self.allocator.dupeZ(u8, std.mem.span(info.*.default_sink_name)) catch return;
@ -266,7 +266,7 @@ pub const Context = struct {
} }
fn sinkInfoOp(_: ?*c.pa_context, info: [*c]const c.pa_sink_info, eol: c_int, user_data: ?*anyopaque) callconv(.C) void { fn sinkInfoOp(_: ?*c.pa_context, info: [*c]const c.pa_sink_info, eol: c_int, user_data: ?*anyopaque) callconv(.C) void {
var self = @ptrCast(*Context, @alignCast(@alignOf(*Context), user_data.?)); var self = @as(*Context, @ptrCast(@alignCast(@alignOf(*Context), user_data.?)));
if (eol != 0) { if (eol != 0) {
lib.pa_threaded_mainloop_signal(self.main_loop, 0); lib.pa_threaded_mainloop_signal(self.main_loop, 0);
return; return;
@ -276,7 +276,7 @@ pub const Context = struct {
} }
fn sourceInfoOp(_: ?*c.pa_context, info: [*c]const c.pa_source_info, eol: c_int, user_data: ?*anyopaque) callconv(.C) void { fn sourceInfoOp(_: ?*c.pa_context, info: [*c]const c.pa_source_info, eol: c_int, user_data: ?*anyopaque) callconv(.C) void {
var self = @ptrCast(*Context, @alignCast(@alignOf(*Context), user_data.?)); var self = @as(*Context, @ptrCast(@alignCast(@alignOf(*Context), user_data.?)));
if (eol != 0) { if (eol != 0) {
lib.pa_threaded_mainloop_signal(self.main_loop, 0); lib.pa_threaded_mainloop_signal(self.main_loop, 0);
return; return;
@ -301,8 +301,8 @@ pub const Context = struct {
}, },
.formats = available_formats, .formats = available_formats,
.sample_rate = .{ .sample_rate = .{
.min = @intCast(u24, info.*.sample_spec.rate), .min = @as(u24, @intCast(info.*.sample_spec.rate)),
.max = @intCast(u24, info.*.sample_spec.rate), .max = @as(u24, @intCast(info.*.sample_spec.rate)),
}, },
.id = id, .id = id,
.name = name, .name = name,
@ -329,7 +329,7 @@ pub const Context = struct {
const sample_spec = c.pa_sample_spec{ const sample_spec = c.pa_sample_spec{
.format = toPAFormat(format), .format = toPAFormat(format),
.rate = sample_rate, .rate = sample_rate,
.channels = @intCast(u5, device.channels.len), .channels = @as(u5, @intCast(device.channels.len)),
}; };
const channel_map = try toPAChannelMap(device.channels); const channel_map = try toPAChannelMap(device.channels);
@ -397,7 +397,7 @@ pub const Context = struct {
}; };
fn streamStateOp(stream: ?*c.pa_stream, user_data: ?*anyopaque) callconv(.C) void { fn streamStateOp(stream: ?*c.pa_stream, user_data: ?*anyopaque) callconv(.C) void {
var self = @ptrCast(*StreamStatus, @alignCast(@alignOf(*StreamStatus), user_data.?)); var self = @as(*StreamStatus, @ptrCast(@alignCast(@alignOf(*StreamStatus), user_data.?)));
switch (lib.pa_stream_get_state(stream)) { switch (lib.pa_stream_get_state(stream)) {
c.PA_STREAM_UNCONNECTED, c.PA_STREAM_UNCONNECTED,
@ -456,14 +456,14 @@ pub const Player = struct {
} }
fn playbackStreamWriteOp(_: ?*c.pa_stream, nbytes: usize, user_data: ?*anyopaque) callconv(.C) void { fn playbackStreamWriteOp(_: ?*c.pa_stream, nbytes: usize, user_data: ?*anyopaque) callconv(.C) void {
var self = @ptrCast(*Player, @alignCast(@alignOf(*Player), user_data.?)); var self = @as(*Player, @ptrCast(@alignCast(@alignOf(*Player), user_data.?)));
var frames_left = nbytes; var frames_left = nbytes;
if (lib.pa_stream_begin_write( if (lib.pa_stream_begin_write(
self.stream, self.stream,
@ptrCast( @as(
[*c]?*anyopaque, [*c]?*anyopaque,
@alignCast(@alignOf([*c]?*anyopaque), &self.write_ptr), @ptrCast(@alignCast(@alignOf([*c]?*anyopaque), &self.write_ptr)),
), ),
&frames_left, &frames_left,
) != 0) { ) != 0) {
@ -519,7 +519,7 @@ pub const Player = struct {
var cvolume: c.pa_cvolume = undefined; var cvolume: c.pa_cvolume = undefined;
_ = lib.pa_cvolume_init(&cvolume); _ = lib.pa_cvolume_init(&cvolume);
_ = lib.pa_cvolume_set(&cvolume, @intCast(c_uint, self.channels.len), lib.pa_sw_volume_from_linear(vol)); _ = lib.pa_cvolume_set(&cvolume, @as(c_uint, @intCast(self.channels.len)), lib.pa_sw_volume_from_linear(vol));
performOperation( performOperation(
self.main_loop, self.main_loop,
@ -534,7 +534,7 @@ pub const Player = struct {
} }
fn successOp(_: ?*c.pa_context, success: c_int, user_data: ?*anyopaque) callconv(.C) void { fn successOp(_: ?*c.pa_context, success: c_int, user_data: ?*anyopaque) callconv(.C) void {
var self = @ptrCast(*Player, @alignCast(@alignOf(*Player), user_data.?)); var self = @as(*Player, @ptrCast(@alignCast(@alignOf(*Player), user_data.?)));
if (success == 1) if (success == 1)
lib.pa_threaded_mainloop_signal(self.main_loop, 0); lib.pa_threaded_mainloop_signal(self.main_loop, 0);
} }
@ -557,14 +557,14 @@ pub const Player = struct {
} }
fn sinkInputInfoOp(_: ?*c.pa_context, info: [*c]const c.pa_sink_input_info, eol: c_int, user_data: ?*anyopaque) callconv(.C) void { fn sinkInputInfoOp(_: ?*c.pa_context, info: [*c]const c.pa_sink_input_info, eol: c_int, user_data: ?*anyopaque) callconv(.C) void {
var self = @ptrCast(*Player, @alignCast(@alignOf(*Player), user_data.?)); var self = @as(*Player, @ptrCast(@alignCast(@alignOf(*Player), user_data.?)));
if (eol != 0) { if (eol != 0) {
lib.pa_threaded_mainloop_signal(self.main_loop, 0); lib.pa_threaded_mainloop_signal(self.main_loop, 0);
return; return;
} }
self.vol = @floatFromInt(f32, info.*.volume.values[0]) / @floatFromInt(f32, c.PA_VOLUME_NORM); self.vol = @as(f32, @floatFromInt(info.*.volume.values[0])) / @as(f32, @floatFromInt(c.PA_VOLUME_NORM));
} }
}; };
@ -638,7 +638,7 @@ pub fn toPAFormat(format: main.Format) c.pa_sample_format_t {
pub fn toPAChannelMap(channels: []const main.Channel) !c.pa_channel_map { pub fn toPAChannelMap(channels: []const main.Channel) !c.pa_channel_map {
var channel_map: c.pa_channel_map = undefined; var channel_map: c.pa_channel_map = undefined;
channel_map.channels = @intCast(u5, channels.len); channel_map.channels = @as(u5, @intCast(channels.len));
for (channels, 0..) |ch, i| for (channels, 0..) |ch, i|
channel_map.map[i] = try toPAChannelPos(ch.id); channel_map.map[i] = try toPAChannelPos(ch.id);
return channel_map; return channel_map;

View file

@ -43,7 +43,7 @@ pub const Context = struct {
null, null,
win32.CLSCTX_ALL, win32.CLSCTX_ALL,
win32.IID_IMMDeviceEnumerator, win32.IID_IMMDeviceEnumerator,
@ptrCast(*?*anyopaque, &enumerator), @as(*?*anyopaque, @ptrCast(&enumerator)),
); );
switch (hr) { switch (hr) {
win32.S_OK => {}, win32.S_OK => {},
@ -99,7 +99,7 @@ pub const Context = struct {
fn queryInterfaceCB(self: *const win32.IUnknown, riid: ?*const win32.Guid, ppv: ?*?*anyopaque) callconv(std.os.windows.WINAPI) win32.HRESULT { fn queryInterfaceCB(self: *const win32.IUnknown, riid: ?*const win32.Guid, ppv: ?*?*anyopaque) callconv(std.os.windows.WINAPI) win32.HRESULT {
if (riid.?.eql(win32.IID_IUnknown.*) or riid.?.eql(win32.IID_IMMNotificationClient.*)) { if (riid.?.eql(win32.IID_IUnknown.*) or riid.?.eql(win32.IID_IMMNotificationClient.*)) {
ppv.?.* = @ptrFromInt(?*anyopaque, @intFromPtr(self)); ppv.?.* = @as(?*anyopaque, @ptrFromInt(@intFromPtr(self)));
_ = self.AddRef(); _ = self.AddRef();
return win32.S_OK; return win32.S_OK;
} else { } else {
@ -266,16 +266,16 @@ pub const Context = struct {
win32.S_OK, win32.INPLACE_S_TRUNCATED => {}, win32.S_OK, win32.INPLACE_S_TRUNCATED => {},
else => return error.OpeningDevice, else => return error.OpeningDevice,
} }
var wf = @ptrCast( var wf = @as(
*win32.WAVEFORMATEXTENSIBLE, *win32.WAVEFORMATEXTENSIBLE,
variant.anon.anon.anon.blob.pBlobData, @ptrCast(variant.anon.anon.anon.blob.pBlobData),
); );
defer win32.CoTaskMemFree(variant.anon.anon.anon.blob.pBlobData); defer win32.CoTaskMemFree(variant.anon.anon.anon.blob.pBlobData);
var device = main.Device{ var device = main.Device{
.mode = blk: { .mode = blk: {
var endpoint: ?*win32.IMMEndpoint = null; var endpoint: ?*win32.IMMEndpoint = null;
hr = imm_device.?.QueryInterface(win32.IID_IMMEndpoint, @ptrCast(?*?*anyopaque, &endpoint)); hr = imm_device.?.QueryInterface(win32.IID_IMMEndpoint, @as(?*?*anyopaque, @ptrCast(&endpoint)));
switch (hr) { switch (hr) {
win32.S_OK => {}, win32.S_OK => {},
win32.E_POINTER => unreachable, win32.E_POINTER => unreachable,
@ -308,12 +308,12 @@ pub const Context = struct {
break :blk try chn_arr.toOwnedSlice(); break :blk try chn_arr.toOwnedSlice();
}, },
.sample_rate = .{ .sample_rate = .{
.min = @intCast(u24, wf.Format.nSamplesPerSec), .min = @as(u24, @intCast(wf.Format.nSamplesPerSec)),
.max = @intCast(u24, wf.Format.nSamplesPerSec), .max = @as(u24, @intCast(wf.Format.nSamplesPerSec)),
}, },
.formats = blk: { .formats = blk: {
var audio_client: ?*win32.IAudioClient = null; var audio_client: ?*win32.IAudioClient = null;
hr = imm_device.?.Activate(win32.IID_IAudioClient, win32.CLSCTX_ALL, null, @ptrCast(?*?*anyopaque, &audio_client)); hr = imm_device.?.Activate(win32.IID_IAudioClient, win32.CLSCTX_ALL, null, @as(?*?*anyopaque, @ptrCast(&audio_client)));
switch (hr) { switch (hr) {
win32.S_OK => {}, win32.S_OK => {},
win32.E_POINTER => unreachable, win32.E_POINTER => unreachable,
@ -330,7 +330,7 @@ pub const Context = struct {
setWaveFormatFormat(wf, format); setWaveFormatFormat(wf, format);
if (audio_client.?.IsFormatSupported( if (audio_client.?.IsFormatSupported(
.SHARED, .SHARED,
@ptrCast(?*const win32.WAVEFORMATEX, @alignCast(@alignOf(*win32.WAVEFORMATEX), wf)), @as(?*const win32.WAVEFORMATEX, @ptrCast(@alignCast(@alignOf(*win32.WAVEFORMATEX), wf))),
&closest_match, &closest_match,
) == win32.S_OK) { ) == win32.S_OK) {
try fmt_arr.append(format); try fmt_arr.append(format);
@ -448,9 +448,9 @@ pub const Context = struct {
var audio_client: ?*win32.IAudioClient = null; var audio_client: ?*win32.IAudioClient = null;
var audio_client3: ?*win32.IAudioClient3 = null; var audio_client3: ?*win32.IAudioClient3 = null;
hr = imm_device.?.Activate(win32.IID_IAudioClient3, win32.CLSCTX_ALL, null, @ptrCast(?*?*anyopaque, &audio_client3)); hr = imm_device.?.Activate(win32.IID_IAudioClient3, win32.CLSCTX_ALL, null, @as(?*?*anyopaque, @ptrCast(&audio_client3)));
if (hr == win32.S_OK) { if (hr == win32.S_OK) {
hr = audio_client3.?.QueryInterface(win32.IID_IAudioClient, @ptrCast(?*?*anyopaque, &audio_client)); hr = audio_client3.?.QueryInterface(win32.IID_IAudioClient, @as(?*?*anyopaque, @ptrCast(&audio_client)));
switch (hr) { switch (hr) {
win32.S_OK => {}, win32.S_OK => {},
win32.E_NOINTERFACE => unreachable, win32.E_NOINTERFACE => unreachable,
@ -458,7 +458,7 @@ pub const Context = struct {
else => return error.OpeningDevice, else => return error.OpeningDevice,
} }
} else { } else {
hr = imm_device.?.Activate(win32.IID_IAudioClient, win32.CLSCTX_ALL, null, @ptrCast(?*?*anyopaque, &audio_client)); hr = imm_device.?.Activate(win32.IID_IAudioClient, win32.CLSCTX_ALL, null, @as(?*?*anyopaque, @ptrCast(&audio_client)));
switch (hr) { switch (hr) {
win32.S_OK => {}, win32.S_OK => {},
win32.E_POINTER => unreachable, win32.E_POINTER => unreachable,
@ -476,7 +476,7 @@ pub const Context = struct {
const wave_format = win32.WAVEFORMATEXTENSIBLE{ const wave_format = win32.WAVEFORMATEXTENSIBLE{
.Format = .{ .Format = .{
.wFormatTag = win32.WAVE_FORMAT_EXTENSIBLE, .wFormatTag = win32.WAVE_FORMAT_EXTENSIBLE,
.nChannels = @intCast(u16, device.channels.len), .nChannels = @as(u16, @intCast(device.channels.len)),
.nSamplesPerSec = sample_rate, .nSamplesPerSec = sample_rate,
.nAvgBytesPerSec = sample_rate * format.frameSize(device.channels.len), .nAvgBytesPerSec = sample_rate * format.frameSize(device.channels.len),
.nBlockAlign = format.frameSize(device.channels.len), .nBlockAlign = format.frameSize(device.channels.len),
@ -494,7 +494,7 @@ pub const Context = struct {
hr = audio_client3.?.InitializeSharedAudioStream( hr = audio_client3.?.InitializeSharedAudioStream(
win32.AUDCLNT_STREAMFLAGS_EVENTCALLBACK, win32.AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
0, // TODO: use the advantage of AudioClient3 0, // TODO: use the advantage of AudioClient3
@ptrCast(?*const win32.WAVEFORMATEX, @alignCast(@alignOf(*win32.WAVEFORMATEX), &wave_format)), @as(?*const win32.WAVEFORMATEX, @ptrCast(@alignCast(@alignOf(*win32.WAVEFORMATEX), &wave_format))),
null, null,
); );
switch (hr) { switch (hr) {
@ -521,7 +521,7 @@ pub const Context = struct {
win32.AUDCLNT_STREAMFLAGS_EVENTCALLBACK, win32.AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
0, 0,
0, 0,
@ptrCast(?*const win32.WAVEFORMATEX, @alignCast(@alignOf(*win32.WAVEFORMATEX), &wave_format)), @as(?*const win32.WAVEFORMATEX, @ptrCast(@alignCast(@alignOf(*win32.WAVEFORMATEX), &wave_format))),
null, null,
); );
switch (hr) { switch (hr) {
@ -547,7 +547,7 @@ pub const Context = struct {
} }
var render_client: ?*win32.IAudioRenderClient = null; var render_client: ?*win32.IAudioRenderClient = null;
hr = audio_client.?.GetService(win32.IID_IAudioRenderClient, @ptrCast(?*?*anyopaque, &render_client)); hr = audio_client.?.GetService(win32.IID_IAudioRenderClient, @as(?*?*anyopaque, @ptrCast(&render_client)));
switch (hr) { switch (hr) {
win32.S_OK => {}, win32.S_OK => {},
win32.E_POINTER => unreachable, win32.E_POINTER => unreachable,
@ -560,7 +560,7 @@ pub const Context = struct {
} }
var simple_volume: ?*win32.ISimpleAudioVolume = null; var simple_volume: ?*win32.ISimpleAudioVolume = null;
hr = audio_client.?.GetService(win32.IID_ISimpleAudioVolume, @ptrCast(?*?*anyopaque, &simple_volume)); hr = audio_client.?.GetService(win32.IID_ISimpleAudioVolume, @as(?*?*anyopaque, @ptrCast(&simple_volume)));
switch (hr) { switch (hr) {
win32.S_OK => {}, win32.S_OK => {},
win32.E_POINTER => unreachable, win32.E_POINTER => unreachable,
@ -728,7 +728,7 @@ pub const Player = struct {
const frames = buf_frames - padding_frames; const frames = buf_frames - padding_frames;
if (frames > 0) { if (frames > 0) {
var data: [*]u8 = undefined; var data: [*]u8 = undefined;
hr = self.render_client.?.GetBuffer(frames, @ptrCast(?*?*u8, &data)); hr = self.render_client.?.GetBuffer(frames, @as(?*?*u8, @ptrCast(&data)));
switch (hr) { switch (hr) {
win32.S_OK => {}, win32.S_OK => {},
win32.E_POINTER => unreachable, win32.E_POINTER => unreachable,

View file

@ -19,12 +19,12 @@ pub const Guid = extern union {
return guid; return guid;
} }
fn hexVal(c: u8) u4 { fn hexVal(c: u8) u4 {
if (c <= '9') return @intCast(u4, c - '0'); if (c <= '9') return @as(u4, @intCast(c - '0'));
if (c >= 'a') return @intCast(u4, c + 10 - 'a'); if (c >= 'a') return @as(u4, @intCast(c + 10 - 'a'));
return @intCast(u4, c + 10 - 'A'); return @as(u4, @intCast(c + 10 - 'A'));
} }
fn decodeHexByte(hex: [2]u8) u8 { fn decodeHexByte(hex: [2]u8) u8 {
return @intCast(u8, hexVal(hex[0])) << 4 | hexVal(hex[1]); return @as(u8, @intCast(hexVal(hex[0]))) << 4 | hexVal(hex[1]);
} }
pub fn eql(riid1: Guid, riid2: Guid) bool { pub fn eql(riid1: Guid, riid2: Guid) bool {
return riid1.Ints.a == riid2.Ints.a and return riid1.Ints.a == riid2.Ints.a and
@ -259,13 +259,13 @@ pub const IUnknown = extern struct {
pub fn MethodMixin(comptime T: type) type { pub fn MethodMixin(comptime T: type) type {
return struct { return struct {
pub inline fn QueryInterface(self: *const T, riid: ?*const Guid, ppvObject: ?*?*anyopaque) HRESULT { pub inline fn QueryInterface(self: *const T, riid: ?*const Guid, ppvObject: ?*?*anyopaque) HRESULT {
return @ptrCast(*const IUnknown.VTable, self.vtable).QueryInterface(@ptrCast(*const IUnknown, self), riid, ppvObject); return @as(*const IUnknown.VTable, @ptrCast(self.vtable)).QueryInterface(@as(*const IUnknown, @ptrCast(self)), riid, ppvObject);
} }
pub inline fn AddRef(self: *const T) u32 { pub inline fn AddRef(self: *const T) u32 {
return @ptrCast(*const IUnknown.VTable, self.vtable).AddRef(@ptrCast(*const IUnknown, self)); return @as(*const IUnknown.VTable, @ptrCast(self.vtable)).AddRef(@as(*const IUnknown, @ptrCast(self)));
} }
pub inline fn Release(self: *const T) u32 { pub inline fn Release(self: *const T) u32 {
return @ptrCast(*const IUnknown.VTable, self.vtable).Release(@ptrCast(*const IUnknown, self)); return @as(*const IUnknown.VTable, @ptrCast(self.vtable)).Release(@as(*const IUnknown, @ptrCast(self)));
} }
}; };
} }
@ -1239,40 +1239,40 @@ pub const IAudioClient = extern struct {
return struct { return struct {
pub usingnamespace IUnknown.MethodMixin(T); pub usingnamespace IUnknown.MethodMixin(T);
pub inline fn Initialize(self: *const T, ShareMode: AUDCLNT_SHAREMODE, StreamFlags: u32, hnsBufferDuration: i64, hnsPeriodicity: i64, pFormat: ?*const WAVEFORMATEX, AudioSessionGuid: ?*const Guid) HRESULT { pub inline fn Initialize(self: *const T, ShareMode: AUDCLNT_SHAREMODE, StreamFlags: u32, hnsBufferDuration: i64, hnsPeriodicity: i64, pFormat: ?*const WAVEFORMATEX, AudioSessionGuid: ?*const Guid) HRESULT {
return @ptrCast(*const IAudioClient.VTable, self.vtable).Initialize(@ptrCast(*const IAudioClient, self), ShareMode, StreamFlags, hnsBufferDuration, hnsPeriodicity, pFormat, AudioSessionGuid); return @as(*const IAudioClient.VTable, @ptrCast(self.vtable)).Initialize(@as(*const IAudioClient, @ptrCast(self)), ShareMode, StreamFlags, hnsBufferDuration, hnsPeriodicity, pFormat, AudioSessionGuid);
} }
pub inline fn GetBufferSize(self: *const T, pNumBufferFrames: ?*u32) HRESULT { pub inline fn GetBufferSize(self: *const T, pNumBufferFrames: ?*u32) HRESULT {
return @ptrCast(*const IAudioClient.VTable, self.vtable).GetBufferSize(@ptrCast(*const IAudioClient, self), pNumBufferFrames); return @as(*const IAudioClient.VTable, @ptrCast(self.vtable)).GetBufferSize(@as(*const IAudioClient, @ptrCast(self)), pNumBufferFrames);
} }
pub inline fn GetStreamLatency(self: *const T, phnsLatency: ?*i64) HRESULT { pub inline fn GetStreamLatency(self: *const T, phnsLatency: ?*i64) HRESULT {
return @ptrCast(*const IAudioClient.VTable, self.vtable).GetStreamLatency(@ptrCast(*const IAudioClient, self), phnsLatency); return @as(*const IAudioClient.VTable, @ptrCast(self.vtable)).GetStreamLatency(@as(*const IAudioClient, @ptrCast(self)), phnsLatency);
} }
pub inline fn GetCurrentPadding(self: *const T, pNumPaddingFrames: ?*u32) HRESULT { pub inline fn GetCurrentPadding(self: *const T, pNumPaddingFrames: ?*u32) HRESULT {
return @ptrCast(*const IAudioClient.VTable, self.vtable).GetCurrentPadding(@ptrCast(*const IAudioClient, self), pNumPaddingFrames); return @as(*const IAudioClient.VTable, @ptrCast(self.vtable)).GetCurrentPadding(@as(*const IAudioClient, @ptrCast(self)), pNumPaddingFrames);
} }
pub inline fn IsFormatSupported(self: *const T, ShareMode: AUDCLNT_SHAREMODE, pFormat: ?*const WAVEFORMATEX, ppClosestMatch: ?*?*WAVEFORMATEX) HRESULT { pub inline fn IsFormatSupported(self: *const T, ShareMode: AUDCLNT_SHAREMODE, pFormat: ?*const WAVEFORMATEX, ppClosestMatch: ?*?*WAVEFORMATEX) HRESULT {
return @ptrCast(*const IAudioClient.VTable, self.vtable).IsFormatSupported(@ptrCast(*const IAudioClient, self), ShareMode, pFormat, ppClosestMatch); return @as(*const IAudioClient.VTable, @ptrCast(self.vtable)).IsFormatSupported(@as(*const IAudioClient, @ptrCast(self)), ShareMode, pFormat, ppClosestMatch);
} }
pub inline fn GetMixFormat(self: *const T, ppDeviceFormat: ?*?*WAVEFORMATEX) HRESULT { pub inline fn GetMixFormat(self: *const T, ppDeviceFormat: ?*?*WAVEFORMATEX) HRESULT {
return @ptrCast(*const IAudioClient.VTable, self.vtable).GetMixFormat(@ptrCast(*const IAudioClient, self), ppDeviceFormat); return @as(*const IAudioClient.VTable, @ptrCast(self.vtable)).GetMixFormat(@as(*const IAudioClient, @ptrCast(self)), ppDeviceFormat);
} }
pub inline fn GetDevicePeriod(self: *const T, phnsDefaultDevicePeriod: ?*i64, phnsMinimumDevicePeriod: ?*i64) HRESULT { pub inline fn GetDevicePeriod(self: *const T, phnsDefaultDevicePeriod: ?*i64, phnsMinimumDevicePeriod: ?*i64) HRESULT {
return @ptrCast(*const IAudioClient.VTable, self.vtable).GetDevicePeriod(@ptrCast(*const IAudioClient, self), phnsDefaultDevicePeriod, phnsMinimumDevicePeriod); return @as(*const IAudioClient.VTable, @ptrCast(self.vtable)).GetDevicePeriod(@as(*const IAudioClient, @ptrCast(self)), phnsDefaultDevicePeriod, phnsMinimumDevicePeriod);
} }
pub inline fn Start(self: *const T) HRESULT { pub inline fn Start(self: *const T) HRESULT {
return @ptrCast(*const IAudioClient.VTable, self.vtable).Start(@ptrCast(*const IAudioClient, self)); return @as(*const IAudioClient.VTable, @ptrCast(self.vtable)).Start(@as(*const IAudioClient, @ptrCast(self)));
} }
pub inline fn Stop(self: *const T) HRESULT { pub inline fn Stop(self: *const T) HRESULT {
return @ptrCast(*const IAudioClient.VTable, self.vtable).Stop(@ptrCast(*const IAudioClient, self)); return @as(*const IAudioClient.VTable, @ptrCast(self.vtable)).Stop(@as(*const IAudioClient, @ptrCast(self)));
} }
pub inline fn Reset(self: *const T) HRESULT { pub inline fn Reset(self: *const T) HRESULT {
return @ptrCast(*const IAudioClient.VTable, self.vtable).Reset(@ptrCast(*const IAudioClient, self)); return @as(*const IAudioClient.VTable, @ptrCast(self.vtable)).Reset(@as(*const IAudioClient, @ptrCast(self)));
} }
pub inline fn SetEventHandle(self: *const T, eventHandle: ?*anyopaque) HRESULT { pub inline fn SetEventHandle(self: *const T, eventHandle: ?*anyopaque) HRESULT {
return @ptrCast(*const IAudioClient.VTable, self.vtable).SetEventHandle(@ptrCast(*const IAudioClient, self), eventHandle); return @as(*const IAudioClient.VTable, @ptrCast(self.vtable)).SetEventHandle(@as(*const IAudioClient, @ptrCast(self)), eventHandle);
} }
pub inline fn GetService(self: *const T, riid: ?*const Guid, ppv: ?*?*anyopaque) HRESULT { pub inline fn GetService(self: *const T, riid: ?*const Guid, ppv: ?*?*anyopaque) HRESULT {
return @ptrCast(*const IAudioClient.VTable, self.vtable).GetService(@ptrCast(*const IAudioClient, self), riid, ppv); return @as(*const IAudioClient.VTable, @ptrCast(self.vtable)).GetService(@as(*const IAudioClient, @ptrCast(self)), riid, ppv);
} }
}; };
} }
@ -1354,13 +1354,13 @@ pub const IAudioClient2 = extern struct {
return struct { return struct {
pub usingnamespace IAudioClient.MethodMixin(T); pub usingnamespace IAudioClient.MethodMixin(T);
pub inline fn IsOffloadCapable(self: *const T, Category: AUDIO_STREAM_CATEGORY, pbOffloadCapable: ?*BOOL) HRESULT { pub inline fn IsOffloadCapable(self: *const T, Category: AUDIO_STREAM_CATEGORY, pbOffloadCapable: ?*BOOL) HRESULT {
return @ptrCast(*const IAudioClient2.VTable, self.vtable).IsOffloadCapable(@ptrCast(*const IAudioClient2, self), Category, pbOffloadCapable); return @as(*const IAudioClient2.VTable, @ptrCast(self.vtable)).IsOffloadCapable(@as(*const IAudioClient2, @ptrCast(self)), Category, pbOffloadCapable);
} }
pub inline fn SetClientProperties(self: *const T, pProperties: ?*const AudioClientProperties) HRESULT { pub inline fn SetClientProperties(self: *const T, pProperties: ?*const AudioClientProperties) HRESULT {
return @ptrCast(*const IAudioClient2.VTable, self.vtable).SetClientProperties(@ptrCast(*const IAudioClient2, self), pProperties); return @as(*const IAudioClient2.VTable, @ptrCast(self.vtable)).SetClientProperties(@as(*const IAudioClient2, @ptrCast(self)), pProperties);
} }
pub inline fn GetBufferSizeLimits(self: *const T, pFormat: ?*const WAVEFORMATEX, bEventDriven: BOOL, phnsMinBufferDuration: ?*i64, phnsMaxBufferDuration: ?*i64) HRESULT { pub inline fn GetBufferSizeLimits(self: *const T, pFormat: ?*const WAVEFORMATEX, bEventDriven: BOOL, phnsMinBufferDuration: ?*i64, phnsMaxBufferDuration: ?*i64) HRESULT {
return @ptrCast(*const IAudioClient2.VTable, self.vtable).GetBufferSizeLimits(@ptrCast(*const IAudioClient2, self), pFormat, bEventDriven, phnsMinBufferDuration, phnsMaxBufferDuration); return @as(*const IAudioClient2.VTable, @ptrCast(self.vtable)).GetBufferSizeLimits(@as(*const IAudioClient2, @ptrCast(self)), pFormat, bEventDriven, phnsMinBufferDuration, phnsMaxBufferDuration);
} }
}; };
} }
@ -1422,13 +1422,13 @@ pub const IAudioClient3 = extern struct {
return struct { return struct {
pub usingnamespace IAudioClient2.MethodMixin(T); pub usingnamespace IAudioClient2.MethodMixin(T);
pub inline fn GetSharedModeEnginePeriod(self: *const T, pFormat: ?*const WAVEFORMATEX, pDefaultPeriodInFrames: ?*u32, pFundamentalPeriodInFrames: ?*u32, pMinPeriodInFrames: ?*u32, pMaxPeriodInFrames: ?*u32) HRESULT { pub inline fn GetSharedModeEnginePeriod(self: *const T, pFormat: ?*const WAVEFORMATEX, pDefaultPeriodInFrames: ?*u32, pFundamentalPeriodInFrames: ?*u32, pMinPeriodInFrames: ?*u32, pMaxPeriodInFrames: ?*u32) HRESULT {
return @ptrCast(*const IAudioClient3.VTable, self.vtable).GetSharedModeEnginePeriod(@ptrCast(*const IAudioClient3, self), pFormat, pDefaultPeriodInFrames, pFundamentalPeriodInFrames, pMinPeriodInFrames, pMaxPeriodInFrames); return @as(*const IAudioClient3.VTable, @ptrCast(self.vtable)).GetSharedModeEnginePeriod(@as(*const IAudioClient3, @ptrCast(self)), pFormat, pDefaultPeriodInFrames, pFundamentalPeriodInFrames, pMinPeriodInFrames, pMaxPeriodInFrames);
} }
pub inline fn GetCurrentSharedModeEnginePeriod(self: *const T, ppFormat: ?*?*WAVEFORMATEX, pCurrentPeriodInFrames: ?*u32) HRESULT { pub inline fn GetCurrentSharedModeEnginePeriod(self: *const T, ppFormat: ?*?*WAVEFORMATEX, pCurrentPeriodInFrames: ?*u32) HRESULT {
return @ptrCast(*const IAudioClient3.VTable, self.vtable).GetCurrentSharedModeEnginePeriod(@ptrCast(*const IAudioClient3, self), ppFormat, pCurrentPeriodInFrames); return @as(*const IAudioClient3.VTable, @ptrCast(self.vtable)).GetCurrentSharedModeEnginePeriod(@as(*const IAudioClient3, @ptrCast(self)), ppFormat, pCurrentPeriodInFrames);
} }
pub inline fn InitializeSharedAudioStream(self: *const T, StreamFlags: u32, PeriodInFrames: u32, pFormat: ?*const WAVEFORMATEX, AudioSessionGuid: ?*const Guid) HRESULT { pub inline fn InitializeSharedAudioStream(self: *const T, StreamFlags: u32, PeriodInFrames: u32, pFormat: ?*const WAVEFORMATEX, AudioSessionGuid: ?*const Guid) HRESULT {
return @ptrCast(*const IAudioClient3.VTable, self.vtable).InitializeSharedAudioStream(@ptrCast(*const IAudioClient3, self), StreamFlags, PeriodInFrames, pFormat, AudioSessionGuid); return @as(*const IAudioClient3.VTable, @ptrCast(self.vtable)).InitializeSharedAudioStream(@as(*const IAudioClient3, @ptrCast(self)), StreamFlags, PeriodInFrames, pFormat, AudioSessionGuid);
} }
}; };
} }
@ -1455,10 +1455,10 @@ pub const IAudioRenderClient = extern struct {
return struct { return struct {
pub usingnamespace IUnknown.MethodMixin(T); pub usingnamespace IUnknown.MethodMixin(T);
pub inline fn GetBuffer(self: *const T, NumFramesRequested: u32, ppData: ?*?*u8) HRESULT { pub inline fn GetBuffer(self: *const T, NumFramesRequested: u32, ppData: ?*?*u8) HRESULT {
return @ptrCast(*const IAudioRenderClient.VTable, self.vtable).GetBuffer(@ptrCast(*const IAudioRenderClient, self), NumFramesRequested, ppData); return @as(*const IAudioRenderClient.VTable, @ptrCast(self.vtable)).GetBuffer(@as(*const IAudioRenderClient, @ptrCast(self)), NumFramesRequested, ppData);
} }
pub inline fn ReleaseBuffer(self: *const T, NumFramesWritten: u32, dwFlags: u32) HRESULT { pub inline fn ReleaseBuffer(self: *const T, NumFramesWritten: u32, dwFlags: u32) HRESULT {
return @ptrCast(*const IAudioRenderClient.VTable, self.vtable).ReleaseBuffer(@ptrCast(*const IAudioRenderClient, self), NumFramesWritten, dwFlags); return @as(*const IAudioRenderClient.VTable, @ptrCast(self.vtable)).ReleaseBuffer(@as(*const IAudioRenderClient, @ptrCast(self)), NumFramesWritten, dwFlags);
} }
}; };
} }
@ -1492,16 +1492,16 @@ pub const ISimpleAudioVolume = extern struct {
return struct { return struct {
pub usingnamespace IUnknown.MethodMixin(T); pub usingnamespace IUnknown.MethodMixin(T);
pub inline fn SetMasterVolume(self: *const T, fLevel: f32, EventContext: ?*const Guid) HRESULT { pub inline fn SetMasterVolume(self: *const T, fLevel: f32, EventContext: ?*const Guid) HRESULT {
return @ptrCast(*const ISimpleAudioVolume.VTable, self.vtable).SetMasterVolume(@ptrCast(*const ISimpleAudioVolume, self), fLevel, EventContext); return @as(*const ISimpleAudioVolume.VTable, @ptrCast(self.vtable)).SetMasterVolume(@as(*const ISimpleAudioVolume, @ptrCast(self)), fLevel, EventContext);
} }
pub inline fn GetMasterVolume(self: *const T, pfLevel: ?*f32) HRESULT { pub inline fn GetMasterVolume(self: *const T, pfLevel: ?*f32) HRESULT {
return @ptrCast(*const ISimpleAudioVolume.VTable, self.vtable).GetMasterVolume(@ptrCast(*const ISimpleAudioVolume, self), pfLevel); return @as(*const ISimpleAudioVolume.VTable, @ptrCast(self.vtable)).GetMasterVolume(@as(*const ISimpleAudioVolume, @ptrCast(self)), pfLevel);
} }
pub inline fn SetMute(self: *const T, bMute: BOOL, EventContext: ?*const Guid) HRESULT { pub inline fn SetMute(self: *const T, bMute: BOOL, EventContext: ?*const Guid) HRESULT {
return @ptrCast(*const ISimpleAudioVolume.VTable, self.vtable).SetMute(@ptrCast(*const ISimpleAudioVolume, self), bMute, EventContext); return @as(*const ISimpleAudioVolume.VTable, @ptrCast(self.vtable)).SetMute(@as(*const ISimpleAudioVolume, @ptrCast(self)), bMute, EventContext);
} }
pub inline fn GetMute(self: *const T, pbMute: ?*BOOL) HRESULT { pub inline fn GetMute(self: *const T, pbMute: ?*BOOL) HRESULT {
return @ptrCast(*const ISimpleAudioVolume.VTable, self.vtable).GetMute(@ptrCast(*const ISimpleAudioVolume, self), pbMute); return @as(*const ISimpleAudioVolume.VTable, @ptrCast(self.vtable)).GetMute(@as(*const ISimpleAudioVolume, @ptrCast(self)), pbMute);
} }
}; };
} }
@ -1538,19 +1538,19 @@ pub const IPropertyStore = extern struct {
return struct { return struct {
pub usingnamespace IUnknown.MethodMixin(T); pub usingnamespace IUnknown.MethodMixin(T);
pub inline fn GetCount(self: *const T, cProps: ?*u32) HRESULT { pub inline fn GetCount(self: *const T, cProps: ?*u32) HRESULT {
return @ptrCast(*const IPropertyStore.VTable, self.vtable).GetCount(@ptrCast(*const IPropertyStore, self), cProps); return @as(*const IPropertyStore.VTable, @ptrCast(self.vtable)).GetCount(@as(*const IPropertyStore, @ptrCast(self)), cProps);
} }
pub inline fn GetAt(self: *const T, iProp: u32, pkey: ?*PROPERTYKEY) HRESULT { pub inline fn GetAt(self: *const T, iProp: u32, pkey: ?*PROPERTYKEY) HRESULT {
return @ptrCast(*const IPropertyStore.VTable, self.vtable).GetAt(@ptrCast(*const IPropertyStore, self), iProp, pkey); return @as(*const IPropertyStore.VTable, @ptrCast(self.vtable)).GetAt(@as(*const IPropertyStore, @ptrCast(self)), iProp, pkey);
} }
pub inline fn GetValue(self: *const T, key: ?*const PROPERTYKEY, pv: ?*PROPVARIANT) HRESULT { pub inline fn GetValue(self: *const T, key: ?*const PROPERTYKEY, pv: ?*PROPVARIANT) HRESULT {
return @ptrCast(*const IPropertyStore.VTable, self.vtable).GetValue(@ptrCast(*const IPropertyStore, self), key, pv); return @as(*const IPropertyStore.VTable, @ptrCast(self.vtable)).GetValue(@as(*const IPropertyStore, @ptrCast(self)), key, pv);
} }
pub inline fn SetValue(self: *const T, key: ?*const PROPERTYKEY, propvar: ?*const PROPVARIANT) HRESULT { pub inline fn SetValue(self: *const T, key: ?*const PROPERTYKEY, propvar: ?*const PROPVARIANT) HRESULT {
return @ptrCast(*const IPropertyStore.VTable, self.vtable).SetValue(@ptrCast(*const IPropertyStore, self), key, propvar); return @as(*const IPropertyStore.VTable, @ptrCast(self.vtable)).SetValue(@as(*const IPropertyStore, @ptrCast(self)), key, propvar);
} }
pub inline fn Commit(self: *const T) HRESULT { pub inline fn Commit(self: *const T) HRESULT {
return @ptrCast(*const IPropertyStore.VTable, self.vtable).Commit(@ptrCast(*const IPropertyStore, self)); return @as(*const IPropertyStore.VTable, @ptrCast(self.vtable)).Commit(@as(*const IPropertyStore, @ptrCast(self)));
} }
}; };
} }
@ -1586,16 +1586,16 @@ pub const IMMDevice = extern struct {
return struct { return struct {
pub usingnamespace IUnknown.MethodMixin(T); pub usingnamespace IUnknown.MethodMixin(T);
pub inline fn Activate(self: *const T, iid: ?*const Guid, dwClsCtx: u32, pActivationParams: ?*PROPVARIANT, ppInterface: ?*?*anyopaque) HRESULT { pub inline fn Activate(self: *const T, iid: ?*const Guid, dwClsCtx: u32, pActivationParams: ?*PROPVARIANT, ppInterface: ?*?*anyopaque) HRESULT {
return @ptrCast(*const IMMDevice.VTable, self.vtable).Activate(@ptrCast(*const IMMDevice, self), iid, dwClsCtx, pActivationParams, ppInterface); return @as(*const IMMDevice.VTable, @ptrCast(self.vtable)).Activate(@as(*const IMMDevice, @ptrCast(self)), iid, dwClsCtx, pActivationParams, ppInterface);
} }
pub inline fn OpenPropertyStore(self: *const T, stgmAccess: u32, ppProperties: ?*?*IPropertyStore) HRESULT { pub inline fn OpenPropertyStore(self: *const T, stgmAccess: u32, ppProperties: ?*?*IPropertyStore) HRESULT {
return @ptrCast(*const IMMDevice.VTable, self.vtable).OpenPropertyStore(@ptrCast(*const IMMDevice, self), stgmAccess, ppProperties); return @as(*const IMMDevice.VTable, @ptrCast(self.vtable)).OpenPropertyStore(@as(*const IMMDevice, @ptrCast(self)), stgmAccess, ppProperties);
} }
pub inline fn GetId(self: *const T, ppstrId: ?*?PWSTR) HRESULT { pub inline fn GetId(self: *const T, ppstrId: ?*?PWSTR) HRESULT {
return @ptrCast(*const IMMDevice.VTable, self.vtable).GetId(@ptrCast(*const IMMDevice, self), ppstrId); return @as(*const IMMDevice.VTable, @ptrCast(self.vtable)).GetId(@as(*const IMMDevice, @ptrCast(self)), ppstrId);
} }
pub inline fn GetState(self: *const T, pdwState: ?*u32) HRESULT { pub inline fn GetState(self: *const T, pdwState: ?*u32) HRESULT {
return @ptrCast(*const IMMDevice.VTable, self.vtable).GetState(@ptrCast(*const IMMDevice, self), pdwState); return @as(*const IMMDevice.VTable, @ptrCast(self.vtable)).GetState(@as(*const IMMDevice, @ptrCast(self)), pdwState);
} }
}; };
} }
@ -1635,19 +1635,19 @@ pub const IMMNotificationClient = extern struct {
return struct { return struct {
pub usingnamespace IUnknown.MethodMixin(T); pub usingnamespace IUnknown.MethodMixin(T);
pub inline fn OnDeviceStateChanged(self: *const T, pwstrDeviceId: ?[*:0]const u16, dwNewState: u32) HRESULT { pub inline fn OnDeviceStateChanged(self: *const T, pwstrDeviceId: ?[*:0]const u16, dwNewState: u32) HRESULT {
return @ptrCast(*const IMMNotificationClient.VTable, self.vtable).OnDeviceStateChanged(@ptrCast(*const IMMNotificationClient, self), pwstrDeviceId, dwNewState); return @as(*const IMMNotificationClient.VTable, @ptrCast(self.vtable)).OnDeviceStateChanged(@as(*const IMMNotificationClient, @ptrCast(self)), pwstrDeviceId, dwNewState);
} }
pub inline fn OnDeviceAdded(self: *const T, pwstrDeviceId: ?[*:0]const u16) HRESULT { pub inline fn OnDeviceAdded(self: *const T, pwstrDeviceId: ?[*:0]const u16) HRESULT {
return @ptrCast(*const IMMNotificationClient.VTable, self.vtable).OnDeviceAdded(@ptrCast(*const IMMNotificationClient, self), pwstrDeviceId); return @as(*const IMMNotificationClient.VTable, @ptrCast(self.vtable)).OnDeviceAdded(@as(*const IMMNotificationClient, @ptrCast(self)), pwstrDeviceId);
} }
pub inline fn OnDeviceRemoved(self: *const T, pwstrDeviceId: ?[*:0]const u16) HRESULT { pub inline fn OnDeviceRemoved(self: *const T, pwstrDeviceId: ?[*:0]const u16) HRESULT {
return @ptrCast(*const IMMNotificationClient.VTable, self.vtable).OnDeviceRemoved(@ptrCast(*const IMMNotificationClient, self), pwstrDeviceId); return @as(*const IMMNotificationClient.VTable, @ptrCast(self.vtable)).OnDeviceRemoved(@as(*const IMMNotificationClient, @ptrCast(self)), pwstrDeviceId);
} }
pub inline fn OnDefaultDeviceChanged(self: *const T, flow: DataFlow, role: Role, pwstrDefaultDeviceId: ?[*:0]const u16) HRESULT { pub inline fn OnDefaultDeviceChanged(self: *const T, flow: DataFlow, role: Role, pwstrDefaultDeviceId: ?[*:0]const u16) HRESULT {
return @ptrCast(*const IMMNotificationClient.VTable, self.vtable).OnDefaultDeviceChanged(@ptrCast(*const IMMNotificationClient, self), flow, role, pwstrDefaultDeviceId); return @as(*const IMMNotificationClient.VTable, @ptrCast(self.vtable)).OnDefaultDeviceChanged(@as(*const IMMNotificationClient, @ptrCast(self)), flow, role, pwstrDefaultDeviceId);
} }
pub inline fn OnPropertyValueChanged(self: *const T, pwstrDeviceId: ?[*:0]const u16, key: PROPERTYKEY) HRESULT { pub inline fn OnPropertyValueChanged(self: *const T, pwstrDeviceId: ?[*:0]const u16, key: PROPERTYKEY) HRESULT {
return @ptrCast(*const IMMNotificationClient.VTable, self.vtable).OnPropertyValueChanged(@ptrCast(*const IMMNotificationClient, self), pwstrDeviceId, key); return @as(*const IMMNotificationClient.VTable, @ptrCast(self.vtable)).OnPropertyValueChanged(@as(*const IMMNotificationClient, @ptrCast(self)), pwstrDeviceId, key);
} }
}; };
} }
@ -1672,10 +1672,10 @@ pub const IMMDeviceCollection = extern struct {
return struct { return struct {
pub usingnamespace IUnknown.MethodMixin(T); pub usingnamespace IUnknown.MethodMixin(T);
pub inline fn GetCount(self: *const T, pcDevices: ?*u32) HRESULT { pub inline fn GetCount(self: *const T, pcDevices: ?*u32) HRESULT {
return @ptrCast(*const IMMDeviceCollection.VTable, self.vtable).GetCount(@ptrCast(*const IMMDeviceCollection, self), pcDevices); return @as(*const IMMDeviceCollection.VTable, @ptrCast(self.vtable)).GetCount(@as(*const IMMDeviceCollection, @ptrCast(self)), pcDevices);
} }
pub inline fn Item(self: *const T, nDevice: u32, ppDevice: ?*?*IMMDevice) HRESULT { pub inline fn Item(self: *const T, nDevice: u32, ppDevice: ?*?*IMMDevice) HRESULT {
return @ptrCast(*const IMMDeviceCollection.VTable, self.vtable).Item(@ptrCast(*const IMMDeviceCollection, self), nDevice, ppDevice); return @as(*const IMMDeviceCollection.VTable, @ptrCast(self.vtable)).Item(@as(*const IMMDeviceCollection, @ptrCast(self)), nDevice, ppDevice);
} }
}; };
} }
@ -1716,19 +1716,19 @@ pub const IMMDeviceEnumerator = extern struct {
return struct { return struct {
pub usingnamespace IUnknown.MethodMixin(T); pub usingnamespace IUnknown.MethodMixin(T);
pub inline fn EnumAudioEndpoints(self: *const T, dataFlow: DataFlow, dwStateMask: u32, ppDevices: ?*?*IMMDeviceCollection) HRESULT { pub inline fn EnumAudioEndpoints(self: *const T, dataFlow: DataFlow, dwStateMask: u32, ppDevices: ?*?*IMMDeviceCollection) HRESULT {
return @ptrCast(*const IMMDeviceEnumerator.VTable, self.vtable).EnumAudioEndpoints(@ptrCast(*const IMMDeviceEnumerator, self), dataFlow, dwStateMask, ppDevices); return @as(*const IMMDeviceEnumerator.VTable, @ptrCast(self.vtable)).EnumAudioEndpoints(@as(*const IMMDeviceEnumerator, @ptrCast(self)), dataFlow, dwStateMask, ppDevices);
} }
pub inline fn GetDefaultAudioEndpoint(self: *const T, dataFlow: DataFlow, role: Role, ppEndpoint: ?*?*IMMDevice) HRESULT { pub inline fn GetDefaultAudioEndpoint(self: *const T, dataFlow: DataFlow, role: Role, ppEndpoint: ?*?*IMMDevice) HRESULT {
return @ptrCast(*const IMMDeviceEnumerator.VTable, self.vtable).GetDefaultAudioEndpoint(@ptrCast(*const IMMDeviceEnumerator, self), dataFlow, role, ppEndpoint); return @as(*const IMMDeviceEnumerator.VTable, @ptrCast(self.vtable)).GetDefaultAudioEndpoint(@as(*const IMMDeviceEnumerator, @ptrCast(self)), dataFlow, role, ppEndpoint);
} }
pub inline fn GetDevice(self: *const T, pwstrId: ?[*:0]const u16, ppDevice: ?*?*IMMDevice) HRESULT { pub inline fn GetDevice(self: *const T, pwstrId: ?[*:0]const u16, ppDevice: ?*?*IMMDevice) HRESULT {
return @ptrCast(*const IMMDeviceEnumerator.VTable, self.vtable).GetDevice(@ptrCast(*const IMMDeviceEnumerator, self), pwstrId, ppDevice); return @as(*const IMMDeviceEnumerator.VTable, @ptrCast(self.vtable)).GetDevice(@as(*const IMMDeviceEnumerator, @ptrCast(self)), pwstrId, ppDevice);
} }
pub inline fn RegisterEndpointNotificationCallback(self: *const T, pClient: ?*IMMNotificationClient) HRESULT { pub inline fn RegisterEndpointNotificationCallback(self: *const T, pClient: ?*IMMNotificationClient) HRESULT {
return @ptrCast(*const IMMDeviceEnumerator.VTable, self.vtable).RegisterEndpointNotificationCallback(@ptrCast(*const IMMDeviceEnumerator, self), pClient); return @as(*const IMMDeviceEnumerator.VTable, @ptrCast(self.vtable)).RegisterEndpointNotificationCallback(@as(*const IMMDeviceEnumerator, @ptrCast(self)), pClient);
} }
pub inline fn UnregisterEndpointNotificationCallback(self: *const T, pClient: ?*IMMNotificationClient) HRESULT { pub inline fn UnregisterEndpointNotificationCallback(self: *const T, pClient: ?*IMMNotificationClient) HRESULT {
return @ptrCast(*const IMMDeviceEnumerator.VTable, self.vtable).UnregisterEndpointNotificationCallback(@ptrCast(*const IMMDeviceEnumerator, self), pClient); return @as(*const IMMDeviceEnumerator.VTable, @ptrCast(self.vtable)).UnregisterEndpointNotificationCallback(@as(*const IMMDeviceEnumerator, @ptrCast(self)), pClient);
} }
}; };
} }
@ -1748,7 +1748,7 @@ pub const IMMEndpoint = extern struct {
return struct { return struct {
pub usingnamespace IUnknown.MethodMixin(T); pub usingnamespace IUnknown.MethodMixin(T);
pub inline fn GetDataFlow(self: *const T, pDataFlow: ?*DataFlow) HRESULT { pub inline fn GetDataFlow(self: *const T, pDataFlow: ?*DataFlow) HRESULT {
return @ptrCast(*const IMMEndpoint.VTable, self.vtable).GetDataFlow(@ptrCast(*const IMMEndpoint, self), pDataFlow); return @as(*const IMMEndpoint.VTable, @ptrCast(self.vtable)).GetDataFlow(@as(*const IMMEndpoint, @ptrCast(self)), pDataFlow);
} }
}; };
} }

View file

@ -163,7 +163,7 @@ pub const Player = struct {
} }
fn resumeOnClick(args: js.Object, _: usize, captures: []js.Value) js.Value { fn resumeOnClick(args: js.Object, _: usize, captures: []js.Value) js.Value {
const self = @ptrFromInt(*Player, @intFromFloat(usize, captures[0].view(.num))); const self = @as(*Player, @ptrFromInt(@as(usize, @intFromFloat(captures[0].view(.num)))));
self.play() catch {}; self.play() catch {};
const document = js.global().get("document").view(.object); const document = js.global().get("document").view(.object);
@ -177,7 +177,7 @@ pub const Player = struct {
} }
fn audioProcessEvent(args: js.Object, _: usize, captures: []js.Value) js.Value { fn audioProcessEvent(args: js.Object, _: usize, captures: []js.Value) js.Value {
const self = @ptrFromInt(*Player, @intFromFloat(usize, captures[0].view(.num))); const self = @as(*Player, @ptrFromInt(@as(usize, @intFromFloat(captures[0].view(.num)))));
const event = args.getIndex(0).view(.object); const event = args.getIndex(0).view(.object);
defer event.deinit(); defer event.deinit();
@ -219,7 +219,7 @@ pub const Player = struct {
pub fn volume(self: Player) !f32 { pub fn volume(self: Player) !f32 {
const gain = self.gain_node.get("gain").view(.object); const gain = self.gain_node.get("gain").view(.object);
defer gain.deinit(); defer gain.deinit();
return @floatCast(f32, gain.get("value").view(.num)); return @as(f32, @floatCast(gain.get("value").view(.num)));
} }
}; };

View file

@ -132,7 +132,7 @@ pub fn update(app: *App) !bool {
const time = app.timer.read() / @as(f32, std.time.ns_per_s); const time = app.timer.read() / @as(f32, std.time.ns_per_s);
const ubo = UniformBufferObject{ const ubo = UniformBufferObject{
.resolution = .{ @floatFromInt(f32, app.core.descriptor().width), @floatFromInt(f32, app.core.descriptor().height) }, .resolution = .{ @as(f32, @floatFromInt(app.core.descriptor().width)), @as(f32, @floatFromInt(app.core.descriptor().height)) },
.time = time, .time = time,
}; };
encoder.writeBuffer(app.uniform_buffer, 0, &[_]UniformBufferObject{ubo}); encoder.writeBuffer(app.uniform_buffer, 0, &[_]UniformBufferObject{ubo});

View file

@ -152,8 +152,8 @@ pub fn machSprite2DInit(adapter: anytype) !void {
.sprite_uv_transforms = sprite_uv_transforms, .sprite_uv_transforms = sprite_uv_transforms,
.sprite_sizes = sprite_sizes, .sprite_sizes = sprite_sizes,
.texture_size = Vec2{ .texture_size = Vec2{
@floatFromInt(f32, sprite2d.state().texture.getWidth()), @as(f32, @floatFromInt(sprite2d.state().texture.getWidth())),
@floatFromInt(f32, sprite2d.state().texture.getHeight()), @as(f32, @floatFromInt(sprite2d.state().texture.getHeight())),
}, },
.texture = sprite2d.state().texture, .texture = sprite2d.state().texture,
}); });
@ -195,10 +195,10 @@ pub fn tick(adapter: anytype) !void {
// Update uniform buffer // Update uniform buffer
const ortho = mat.ortho( const ortho = mat.ortho(
-@floatFromInt(f32, core.size().width) / 2, -@as(f32, @floatFromInt(core.size().width)) / 2,
@floatFromInt(f32, core.size().width) / 2, @as(f32, @floatFromInt(core.size().width)) / 2,
-@floatFromInt(f32, core.size().height) / 2, -@as(f32, @floatFromInt(core.size().height)) / 2,
@floatFromInt(f32, core.size().height) / 2, @as(f32, @floatFromInt(core.size().height)) / 2,
-0.1, -0.1,
100000, 100000,
); );
@ -234,7 +234,7 @@ pub fn tick(adapter: anytype) !void {
try sprite_sizes.append(adapter.allocator, size); try sprite_sizes.append(adapter.allocator, size);
} }
} }
const total_vertices = @intCast(u32, sprite_sizes.items.len * 6); const total_vertices = @as(u32, @intCast(sprite_sizes.items.len * 6));
if (sprite_transforms.items.len > 0) { if (sprite_transforms.items.len > 0) {
encoder.writeBuffer(sprite2d.state().sprite_transforms, 0, sprite_transforms.items); encoder.writeBuffer(sprite2d.state().sprite_transforms, 0, sprite_transforms.items);
encoder.writeBuffer(sprite2d.state().sprite_uv_transforms, 0, sprite_uv_transforms.items); encoder.writeBuffer(sprite2d.state().sprite_uv_transforms, 0, sprite_uv_transforms.items);

View file

@ -97,6 +97,6 @@ pub const Resource = struct {
// Returns the raw data, which you can use in any ways. Internally it is stored // Returns the raw data, which you can use in any ways. Internally it is stored
// as an *anyopaque // as an *anyopaque
pub fn getData(res: *const Resource, comptime T: type) *T { pub fn getData(res: *const Resource, comptime T: type) *T {
return @ptrCast(*T, @alignCast(std.meta.alignment(*T), res.resource)); return @as(*T, @ptrCast(@alignCast(std.meta.alignment(*T), res.resource)));
} }
}; };