update to latest Zig (zig fmt)

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2023-06-25 00:01:55 -07:00
parent 419d82d5fd
commit 29964c99bb
39 changed files with 156 additions and 156 deletions

View file

@ -185,7 +185,7 @@ fn sendData(
"Content-Type: {s}\r\n" ++
"\r\n{s}",
.{
@enumToInt(status),
@intFromEnum(status),
status.phrase() orelse "N/A",
switch (connection) {
.close => "close",
@ -206,7 +206,7 @@ fn sendData(
"Content-Type: {s}\r\n" ++
"\r\n",
.{
@enumToInt(status),
@intFromEnum(status),
status.phrase() orelse "N/A",
switch (connection) {
.close => "close",

View file

@ -11,7 +11,7 @@ pub fn init_transcoder() void {
/// Returns true if the specified format was enabled at compile time.
pub fn isFormatEnabled(self: BasisTextureFormat, transcoder_format: Transcoder.TextureFormat) bool {
return b.transcoder_is_format_supported(@enumToInt(self), @enumToInt(transcoder_format));
return b.transcoder_is_format_supported(@intFromEnum(self), @intFromEnum(transcoder_format));
}
pub const Transcoder = struct {
@ -62,7 +62,7 @@ pub const Transcoder = struct {
/// Returns the bytes neeeded to store output.
pub fn calcTranscodedSize(self: Transcoder, image_index: u32, level_index: u32, format: TextureFormat) error{OutOfBoundsLevelIndex}!u32 {
var size: u32 = undefined;
return if (b.transcoder_get_image_transcoded_size(self.handle, image_index, level_index, @enumToInt(format), &size))
return if (b.transcoder_get_image_transcoded_size(self.handle, image_index, level_index, @intFromEnum(format), &size))
size
else
error.OutOfBoundsLevelIndex;
@ -104,7 +104,7 @@ pub const Transcoder = struct {
@intCast(u32, out_buf.len),
image_index,
level_index,
@enumToInt(format),
@intFromEnum(format),
@bitCast(u32, params.decode_flags),
params.output_row_pitch orelse 0,
params.output_rows orelse 0,

View file

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

View file

@ -567,7 +567,7 @@ pub fn setCursorShape(self: *Core, cursor: CursorShape) void {
// we hope to provide custom backup images for these.
// See https://github.com/hexops/mach/pull/352 for more info
const enum_int = @enumToInt(cursor);
const enum_int = @intFromEnum(cursor);
const tried = self.cursors_tried[enum_int];
if (!tried) {
self.cursors_tried[enum_int] = true;

View file

@ -31,10 +31,10 @@ pub const EventIterator = struct {
const event_int = js.machEventShift();
if (event_int == -1) return null;
const event_type = @intToEnum(std.meta.Tag(Event), event_int);
const event_type = @enumFromInt(std.meta.Tag(Event), event_int);
return switch (event_type) {
.key_press, .key_repeat => blk: {
const key = @intToEnum(Key, js.machEventShift());
const key = @enumFromInt(Key, js.machEventShift());
switch (key) {
.left_shift, .right_shift => self.key_mods.shift = true,
.left_control, .right_control => self.key_mods.control = true,
@ -63,7 +63,7 @@ pub const EventIterator = struct {
continue;
},
.key_release => blk: {
const key = @intToEnum(Key, js.machEventShift());
const key = @enumFromInt(Key, js.machEventShift());
switch (key) {
.left_shift, .right_shift => self.key_mods.shift = false,
.left_control, .right_control => self.key_mods.control = false,
@ -83,8 +83,8 @@ pub const EventIterator = struct {
continue;
},
.mouse_motion => blk: {
const x = @intToFloat(f64, js.machEventShift());
const y = @intToFloat(f64, js.machEventShift());
const x = @floatFromInt(f64, js.machEventShift());
const y = @floatFromInt(f64, js.machEventShift());
self.last_cursor_position = .{
.x = x,
.y = y,
@ -191,11 +191,11 @@ pub fn setDisplayMode(self: *Core, mode: DisplayMode, monitor: ?usize) void {
// borderless fullscreen window has no meaning in web
mode = .fullscreen;
}
js.machCanvasSetDisplayMode(self.id, @enumToInt(mode));
js.machCanvasSetDisplayMode(self.id, @intFromEnum(mode));
}
pub fn displayMode(self: *Core) DisplayMode {
return @intToEnum(DisplayMode, js.machDisplayMode(self.id));
return @enumFromInt(DisplayMode, js.machDisplayMode(self.id));
}
pub fn setBorder(self: *Core, value: bool) void {
@ -264,19 +264,19 @@ pub fn sizeLimit(self: *Core) SizeLimit {
}
pub fn setCursorMode(self: *Core, mode: CursorMode) void {
js.machSetCursorMode(self.id, @enumToInt(mode));
js.machSetCursorMode(self.id, @intFromEnum(mode));
}
pub fn cursorMode(self: *Core) CursorMode {
return @intToEnum(CursorMode, js.machCursorMode(self.id));
return @enumFromInt(CursorMode, js.machCursorMode(self.id));
}
pub fn setCursorShape(self: *Core, shape: CursorShape) void {
js.machSetCursorShape(self.id, @enumToInt(shape));
js.machSetCursorShape(self.id, @intFromEnum(shape));
}
pub fn cursorShape(self: *Core) CursorShape {
return @intToEnum(CursorShape, js.machCursorShape(self.id));
return @enumFromInt(CursorShape, js.machCursorShape(self.id));
}
pub fn adapter(_: *Core) *gpu.Adapter {

View file

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

View file

@ -126,7 +126,7 @@ pub fn getNameIndex(self: Face, name: [:0]const u8) ?u32 {
pub fn getKerning(self: Face, left_char_index: u32, right_char_index: u32, mode: KerningMode) Error!Vector {
var kerning: Vector = undefined;
try intToError(c.FT_Get_Kerning(self.handle, left_char_index, right_char_index, @enumToInt(mode), &kerning));
try intToError(c.FT_Get_Kerning(self.handle, left_char_index, right_char_index, @intFromEnum(mode), &kerning));
return kerning;
}
@ -152,7 +152,7 @@ pub fn iterateCharmap(self: Face) CharmapIterator {
}
pub fn selectCharmap(self: Face, encoding: Encoding) Error!void {
return intToError(c.FT_Select_Charmap(self.handle, @enumToInt(encoding)));
return intToError(c.FT_Select_Charmap(self.handle, @intFromEnum(encoding)));
}
pub fn setCharmap(self: Face, char_map: *CharMap) Error!void {
@ -223,7 +223,7 @@ pub fn getGlyphLayersIterator(self: Face, glyph_index: u32) GlyphLayersIterator
pub fn getColorGlyphPaint(self: Face, base_glyph: u32, root_transform: RootTransform) ?Paint {
var opaque_paint: OpaquePaint = undefined;
if (c.FT_Get_Color_Glyph_Paint(self.handle, base_glyph, @enumToInt(root_transform), &opaque_paint) == 0)
if (c.FT_Get_Color_Glyph_Paint(self.handle, base_glyph, @intFromEnum(root_transform), &opaque_paint) == 0)
return null;
return self.getPaint(opaque_paint);
}
@ -239,7 +239,7 @@ pub fn getPaint(self: Face, opaque_paint: OpaquePaint) ?Paint {
var p: c.FT_COLR_Paint = undefined;
if (c.FT_Get_Paint(self.handle, opaque_paint, &p) == 0)
return null;
return switch (@intToEnum(PaintFormat, p.format)) {
return switch (@enumFromInt(PaintFormat, p.format)) {
.color_layers => Paint{ .color_layers = p.u.colr_layers },
.glyph => Paint{ .glyph = p.u.glyph },
.solid => Paint{ .solid = p.u.solid },

View file

@ -57,7 +57,7 @@ pub fn advance(self: GlyphSlot) Vector {
}
pub fn format(self: GlyphSlot) GlyphFormat {
return @intToEnum(GlyphFormat, self.handle.*.format);
return @enumFromInt(GlyphFormat, self.handle.*.format);
}
pub fn ownBitmap(self: GlyphSlot) Error!void {
@ -89,7 +89,7 @@ pub fn rsbDelta(self: GlyphSlot) i32 {
}
pub fn render(self: GlyphSlot, render_mode: RenderMode) Error!void {
return intToError(c.FT_Render_Glyph(self.handle, @enumToInt(render_mode)));
return intToError(c.FT_Render_Glyph(self.handle, @intFromEnum(render_mode)));
}
pub fn getSubGlyphInfo(self: GlyphSlot, sub_index: u32) Error!SubGlyphInfo {

View file

@ -78,7 +78,7 @@ pub fn renderOutline(self: Library, outline: Outline, params: *RasterParams) Err
}
pub fn setLcdFilter(self: Library, lcd_filter: LcdFilter) Error!void {
return intToError(c.FT_Library_SetLcdFilter(self.handle, @enumToInt(lcd_filter)));
return intToError(c.FT_Library_SetLcdFilter(self.handle, @intFromEnum(lcd_filter)));
}
pub extern fn FT_Outline_Render(library: c.FT_Library, outline: [*c]c.FT_Outline, params: [*c]RasterParams) c_int;

View file

@ -179,7 +179,7 @@ pub const OpenArgs = struct {
.stream => |d| oa.stream = d,
.driver => |d| oa.driver = d,
.params => |*d| {
oa.params = @intToPtr(*c.FT_Parameter, @ptrToInt(d.ptr));
oa.params = @ptrFromInt(*c.FT_Parameter, @intFromPtr(d.ptr));
oa.num_params = @intCast(u31, d.len);
},
}

View file

@ -32,7 +32,7 @@ pub const Glyph = struct {
pub fn newGlyph(library: Library, glyph_format: GlyphFormat) Glyph {
var g: c.FT_Glyph = undefined;
return .{
.handle = c.FT_New_Glyph(library.handle, @enumToInt(glyph_format), &g),
.handle = c.FT_New_Glyph(library.handle, @intFromEnum(glyph_format), &g),
};
}
@ -48,17 +48,17 @@ pub const Glyph = struct {
pub fn getCBox(self: Glyph, bbox_mode: BBoxMode) BBox {
var b: BBox = undefined;
c.FT_Glyph_Get_CBox(self.handle, @enumToInt(bbox_mode), &b);
c.FT_Glyph_Get_CBox(self.handle, @intFromEnum(bbox_mode), &b);
return b;
}
pub fn toBitmapGlyph(self: *Glyph, render_mode: RenderMode, origin: ?Vector) Error!BitmapGlyph {
try intToError(c.FT_Glyph_To_Bitmap(&self.handle, @enumToInt(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) };
}
pub fn copyBitmapGlyph(self: *Glyph, render_mode: RenderMode, origin: ?Vector) Error!BitmapGlyph {
try intToError(c.FT_Glyph_To_Bitmap(&self.handle, @enumToInt(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) };
}
@ -83,7 +83,7 @@ pub const Glyph = struct {
}
pub fn format(self: Glyph) GlyphFormat {
return @intToEnum(GlyphFormat, self.handle.*.format);
return @enumFromInt(GlyphFormat, self.handle.*.format);
}
pub fn advanceX(self: Glyph) isize {

View file

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

View file

@ -56,8 +56,8 @@ pub const SegmentProps = struct {
pub fn from(c_struct: c.hb_segment_properties_t) SegmentProps {
return .{
.direction = @intToEnum(Direction, c_struct.direction),
.script = @intToEnum(Script, c_struct.script),
.direction = @enumFromInt(Direction, c_struct.direction),
.script = @enumFromInt(Script, c_struct.script),
.language = Language{ .handle = c_struct.language },
};
}
@ -66,8 +66,8 @@ pub const SegmentProps = struct {
return .{
.reserved1 = undefined,
.reserved2 = undefined,
.direction = @enumToInt(self.direction),
.script = @enumToInt(self.script),
.direction = @intFromEnum(self.direction),
.script = @intFromEnum(self.script),
.language = self.language.handle,
};
}
@ -197,27 +197,27 @@ pub const Buffer = struct {
}
pub fn getContentType(self: Buffer) ContentType {
return @intToEnum(ContentType, c.hb_buffer_get_content_type(self.handle));
return @enumFromInt(ContentType, c.hb_buffer_get_content_type(self.handle));
}
pub fn setContentType(self: Buffer, content_type: ContentType) void {
c.hb_buffer_set_content_type(self.handle, @enumToInt(content_type));
c.hb_buffer_set_content_type(self.handle, @intFromEnum(content_type));
}
pub fn getDirection(self: Buffer) Direction {
return @intToEnum(Direction, c.hb_buffer_get_direction(self.handle));
return @enumFromInt(Direction, c.hb_buffer_get_direction(self.handle));
}
pub fn setDirection(self: Buffer, direction: Direction) void {
c.hb_buffer_set_direction(self.handle, @enumToInt(direction));
c.hb_buffer_set_direction(self.handle, @intFromEnum(direction));
}
pub fn getScript(self: Buffer) Script {
return @intToEnum(Script, c.hb_buffer_get_script(self.handle));
return @enumFromInt(Script, c.hb_buffer_get_script(self.handle));
}
pub fn setScript(self: Buffer, script: Script) void {
c.hb_buffer_set_script(self.handle, @enumToInt(script));
c.hb_buffer_set_script(self.handle, @intFromEnum(script));
}
pub fn getLanguage(self: Buffer) Language {
@ -237,11 +237,11 @@ pub const Buffer = struct {
}
pub fn getClusterLevel(self: Buffer) ClusterLevel {
return @intToEnum(ClusterLevel, c.hb_buffer_get_cluster_level(self.handle));
return @enumFromInt(ClusterLevel, c.hb_buffer_get_cluster_level(self.handle));
}
pub fn setClusterLevel(self: Buffer, level: ClusterLevel) void {
c.hb_buffer_set_cluster_level(self.handle, @enumToInt(level));
c.hb_buffer_set_cluster_level(self.handle, @intFromEnum(level));
}
pub fn getLength(self: Buffer) u32 {

View file

@ -9,11 +9,11 @@ pub const Direction = enum(u3) {
bit = c.HB_DIRECTION_BTT,
pub fn fromString(str: []const u8) Direction {
return @intToEnum(Direction, c.hb_direction_from_string(str.ptr, @intCast(c_int, str.len)));
return @enumFromInt(Direction, c.hb_direction_from_string(str.ptr, @intCast(c_int, str.len)));
}
pub fn toString(self: Direction) [:0]const u8 {
return std.mem.span(@ptrCast([*:0]const u8, c.hb_direction_to_string(@enumToInt(self))));
return std.mem.span(@ptrCast([*:0]const u8, c.hb_direction_to_string(@intFromEnum(self))));
}
};
@ -184,19 +184,19 @@ pub const Script = enum(u31) {
invalid = c.HB_SCRIPT_INVALID,
pub fn fromISO15924Tag(tag: Tag) Script {
return @intToEnum(Script, c.hb_script_from_iso15924_tag(tag.handle));
return @enumFromInt(Script, c.hb_script_from_iso15924_tag(tag.handle));
}
pub fn fromString(str: []const u8) Script {
return @intToEnum(Script, c.hb_script_from_string(str.ptr, @intCast(c_int, str.len)));
return @enumFromInt(Script, c.hb_script_from_string(str.ptr, @intCast(c_int, str.len)));
}
pub fn toISO15924Tag(self: Script) Tag {
return .{ .handle = c.hb_script_to_iso15924_tag(@enumToInt(self)) };
return .{ .handle = c.hb_script_to_iso15924_tag(@intFromEnum(self)) };
}
pub fn getHorizontalDirection(self: Script) Direction {
return @intToEnum(Direction, c.hb_script_get_horizontal_direction(@enumToInt(self)));
return @enumFromInt(Direction, c.hb_script_get_horizontal_direction(@intFromEnum(self)));
}
};

View file

@ -84,7 +84,7 @@ pub const Bitmap = struct {
}
pub fn pixelMode(self: Bitmap) PixelMode {
return @intToEnum(PixelMode, self.handle.pixel_mode);
return @enumFromInt(PixelMode, self.handle.pixel_mode);
}
pub fn buffer(self: Bitmap) ?[]const u8 {
@ -188,15 +188,15 @@ pub const Outline = struct {
}
pub fn orientation(self: Outline) Orientation {
return @intToEnum(Orientation, c.FT_Outline_Get_Orientation(self.handle));
return @enumFromInt(Orientation, c.FT_Outline_Get_Orientation(self.handle));
}
pub fn getInsideBorder(self: Outline) Stroker.Border {
return @intToEnum(Stroker.Border, c.FT_Outline_GetInsideBorder(self.handle));
return @enumFromInt(Stroker.Border, c.FT_Outline_GetInsideBorder(self.handle));
}
pub fn getOutsideBorder(self: Outline) Stroker.Border {
return @intToEnum(Stroker.Border, c.FT_Outline_GetOutsideBorder(self.handle));
return @enumFromInt(Stroker.Border, c.FT_Outline_GetOutsideBorder(self.handle));
}
pub fn Funcs(comptime Context: type) type {

View file

@ -31,7 +31,7 @@ pub const Stroker = struct {
handle: c.FT_Stroker,
pub fn set(self: Stroker, radius: i32, line_cap: LineCap, line_join: LineJoin, miter_limit: i32) void {
c.FT_Stroker_Set(self.handle, radius, @enumToInt(line_cap), @enumToInt(line_join), miter_limit);
c.FT_Stroker_Set(self.handle, radius, @intFromEnum(line_cap), @intFromEnum(line_join), miter_limit);
}
pub fn rewind(self: Stroker) void {
@ -64,12 +64,12 @@ pub const Stroker = struct {
pub fn getBorderCounts(self: Stroker, border: Border) Error!BorderCounts {
var counts: BorderCounts = undefined;
try intToError(c.FT_Stroker_GetBorderCounts(self.handle, @enumToInt(border), &counts.points, &counts.contours));
try intToError(c.FT_Stroker_GetBorderCounts(self.handle, @intFromEnum(border), &counts.points, &counts.contours));
return counts;
}
pub fn exportBorder(self: Stroker, border: Border, outline: *Outline) void {
c.FT_Stroker_ExportBorder(self.handle, @enumToInt(border), outline.handle);
c.FT_Stroker_ExportBorder(self.handle, @intFromEnum(border), outline.handle);
}
pub fn getCounts(self: Stroker) Error!BorderCounts {

View file

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

View file

@ -39,7 +39,7 @@ pub const Id = enum(c_int) {
fourteen = c.GLFW_JOYSTICK_14,
fifteen = c.GLFW_JOYSTICK_15,
sixteen = c.GLFW_JOYSTICK_16,
pub const last = @intToEnum(@This(), c.GLFW_JOYSTICK_LAST);
pub const last = @enumFromInt(@This(), c.GLFW_JOYSTICK_LAST);
};
/// Gamepad input state
@ -60,12 +60,12 @@ const GamepadState = extern struct {
/// Returns the state of the specified gamepad button.
pub fn getButton(self: @This(), which: GamepadButton) Action {
return @intToEnum(Action, self.buttons[@intCast(u32, @enumToInt(which))]);
return @enumFromInt(Action, self.buttons[@intCast(u32, @intFromEnum(which))]);
}
/// 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 {
return self.axes[@intCast(u32, @enumToInt(which))];
return self.axes[@intCast(u32, @intFromEnum(which))];
}
};
@ -85,7 +85,7 @@ const GamepadState = extern struct {
/// see also: joystick
pub inline fn present(self: Joystick) bool {
internal_debug.assertInitialized();
const is_present = c.glfwJoystickPresent(@enumToInt(self.jid));
const is_present = c.glfwJoystickPresent(@intFromEnum(self.jid));
return is_present == c.GLFW_TRUE;
}
@ -113,7 +113,7 @@ pub inline fn present(self: Joystick) bool {
pub inline fn getAxes(self: Joystick) ?[]const f32 {
internal_debug.assertInitialized();
var count: c_int = undefined;
const axes = c.glfwGetJoystickAxes(@enumToInt(self.jid), &count);
const axes = c.glfwGetJoystickAxes(@intFromEnum(self.jid), &count);
if (axes == null) return null;
return axes[0..@intCast(u32, count)];
}
@ -146,7 +146,7 @@ pub inline fn getAxes(self: Joystick) ?[]const f32 {
pub inline fn getButtons(self: Joystick) ?[]const u8 {
internal_debug.assertInitialized();
var count: c_int = undefined;
const buttons = c.glfwGetJoystickButtons(@enumToInt(self.jid), &count);
const buttons = c.glfwGetJoystickButtons(@intFromEnum(self.jid), &count);
if (buttons == null) return null;
return buttons[0..@intCast(u32, count)];
}
@ -195,7 +195,7 @@ pub inline fn getButtons(self: Joystick) ?[]const u8 {
pub inline fn getHats(self: Joystick) ?[]const Hat {
internal_debug.assertInitialized();
var count: c_int = undefined;
const hats = c.glfwGetJoystickHats(@enumToInt(self.jid), &count);
const hats = c.glfwGetJoystickHats(@intFromEnum(self.jid), &count);
if (hats == null) return null;
const slice = hats[0..@intCast(u32, count)];
return @ptrCast(*const []const Hat, &slice).*;
@ -223,7 +223,7 @@ pub inline fn getHats(self: Joystick) ?[]const Hat {
/// see also: joystick_name
pub inline fn getName(self: Joystick) ?[:0]const u8 {
internal_debug.assertInitialized();
const name_opt = c.glfwGetJoystickName(@enumToInt(self.jid));
const name_opt = c.glfwGetJoystickName(@intFromEnum(self.jid));
return if (name_opt) |name|
std.mem.span(@ptrCast([*:0]const u8, name))
else
@ -260,7 +260,7 @@ pub inline fn getName(self: Joystick) ?[:0]const u8 {
/// see also: gamepad
pub inline fn getGUID(self: Joystick) ?[:0]const u8 {
internal_debug.assertInitialized();
const guid_opt = c.glfwGetJoystickGUID(@enumToInt(self.jid));
const guid_opt = c.glfwGetJoystickGUID(@intFromEnum(self.jid));
return if (guid_opt) |guid|
std.mem.span(@ptrCast([*:0]const u8, guid))
else
@ -279,7 +279,7 @@ pub inline fn getGUID(self: Joystick) ?[:0]const u8 {
/// see also: joystick_userptr, glfw.Joystick.getUserPointer
pub inline fn setUserPointer(self: Joystick, comptime T: type, pointer: *T) void {
internal_debug.assertInitialized();
c.glfwSetJoystickUserPointer(@enumToInt(self.jid), @ptrCast(*anyopaque, pointer));
c.glfwSetJoystickUserPointer(@intFromEnum(self.jid), @ptrCast(*anyopaque, pointer));
}
/// Returns the user pointer of the specified joystick.
@ -295,7 +295,7 @@ pub inline fn setUserPointer(self: Joystick, comptime T: type, pointer: *T) void
/// see also: joystick_userptr, glfw.Joystick.setUserPointer
pub inline fn getUserPointer(self: Joystick, comptime PointerType: type) ?PointerType {
internal_debug.assertInitialized();
const ptr = c.glfwGetJoystickUserPointer(@enumToInt(self.jid));
const ptr = c.glfwGetJoystickUserPointer(@intFromEnum(self.jid));
if (ptr) |p| return @ptrCast(PointerType, @alignCast(@alignOf(std.meta.Child(PointerType)), p));
return null;
}
@ -335,8 +335,8 @@ pub inline fn setCallback(comptime callback: ?fn (joystick: Joystick, event: Eve
const CWrapper = struct {
pub fn joystickCallbackWrapper(jid: c_int, event: c_int) callconv(.C) void {
@call(.always_inline, user_callback, .{
Joystick{ .jid = @intToEnum(Joystick.Id, jid) },
@intToEnum(Event, event),
Joystick{ .jid = @enumFromInt(Joystick.Id, jid) },
@enumFromInt(Event, event),
});
}
};
@ -394,7 +394,7 @@ pub inline fn updateGamepadMappings(gamepad_mappings: [*:0]const u8) bool {
/// see also: gamepad, glfw.Joystick.getGamepadState
pub inline fn isGamepad(self: Joystick) bool {
internal_debug.assertInitialized();
const is_gamepad = c.glfwJoystickIsGamepad(@enumToInt(self.jid));
const is_gamepad = c.glfwJoystickIsGamepad(@intFromEnum(self.jid));
return is_gamepad == c.GLFW_TRUE;
}
@ -422,7 +422,7 @@ pub inline fn isGamepad(self: Joystick) bool {
/// see also: gamepad, glfw.Joystick.isGamepad
pub inline fn getGamepadName(self: Joystick) ?[:0]const u8 {
internal_debug.assertInitialized();
const name_opt = c.glfwGetGamepadName(@enumToInt(self.jid));
const name_opt = c.glfwGetGamepadName(@intFromEnum(self.jid));
return if (name_opt) |name|
std.mem.span(@ptrCast([*:0]const u8, name))
else
@ -457,7 +457,7 @@ pub inline fn getGamepadName(self: Joystick) ?[:0]const u8 {
pub inline fn getGamepadState(self: Joystick) ?GamepadState {
internal_debug.assertInitialized();
var state: GamepadState = undefined;
const success = c.glfwGetGamepadState(@enumToInt(self.jid), @ptrCast(*c.GLFWgamepadstate, &state));
const success = c.glfwGetGamepadState(@intFromEnum(self.jid), @ptrCast(*c.GLFWgamepadstate, &state));
return if (success == c.GLFW_TRUE) state else null;
}

View file

@ -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 {
@call(.always_inline, user_callback, .{
Monitor{ .handle = monitor.? },
@intToEnum(Event, event),
@enumFromInt(Event, event),
});
}
};

View file

@ -229,10 +229,10 @@ pub const Hints = struct {
fn set(hints: Hints) void {
internal_debug.assertInitialized();
inline for (comptime std.meta.fieldNames(Hint)) |field_name| {
const hint_tag = @enumToInt(@field(Hint, field_name));
const hint_tag = @intFromEnum(@field(Hint, field_name));
const hint_value = @field(hints, field_name);
switch (@TypeOf(hint_value)) {
bool => c.glfwWindowHint(hint_tag, @boolToInt(hint_value)),
bool => c.glfwWindowHint(hint_tag, @intFromBool(hint_value)),
?PositiveCInt => c.glfwWindowHint(hint_tag, if (hint_value) |unwrapped| unwrapped else glfw.dont_care),
c_int => c.glfwWindowHint(hint_tag, hint_value),
@ -241,7 +241,7 @@ pub const Hints = struct {
ContextRobustness,
ContextReleaseBehavior,
OpenGLProfile,
=> c.glfwWindowHint(hint_tag, @enumToInt(hint_value)),
=> c.glfwWindowHint(hint_tag, @intFromEnum(hint_value)),
[:0]const u8 => c.glfwWindowHintString(hint_tag, hint_value.ptr),
@ -1107,7 +1107,7 @@ pub const Attrib = enum(c_int) {
/// see also: window_attribs, glfw.Window.setAttrib
pub inline fn getAttrib(self: Window, attrib: Attrib) i32 {
internal_debug.assertInitialized();
return c.glfwGetWindowAttrib(self.handle, @enumToInt(attrib));
return c.glfwGetWindowAttrib(self.handle, @intFromEnum(attrib));
}
/// Sets an attribute of the specified window.
@ -1148,7 +1148,7 @@ pub inline fn setAttrib(self: Window, attrib: Attrib, value: bool) void {
=> true,
else => false,
});
c.glfwSetWindowAttrib(self.handle, @enumToInt(attrib), if (value) c.GLFW_TRUE else c.GLFW_FALSE);
c.glfwSetWindowAttrib(self.handle, @intFromEnum(attrib), if (value) c.GLFW_TRUE else c.GLFW_FALSE);
}
/// Sets the user pointer of the specified window.
@ -1541,7 +1541,7 @@ pub inline fn setInputModeCursor(self: Window, value: InputModeCursor) void {
/// Gets the current input mode of the cursor.
pub inline fn getInputModeCursor(self: Window) InputModeCursor {
return @intToEnum(InputModeCursor, self.getInputMode(InputMode.cursor));
return @enumFromInt(InputModeCursor, self.getInputMode(InputMode.cursor));
}
/// Sets the input mode of sticky keys, if enabled a key press will ensure that `glfw.Window.getKey`
@ -1622,7 +1622,7 @@ pub inline fn getInputModeRawMouseMotion(self: Window) bool {
/// see also: glfw.Window.setInputMode
pub inline fn getInputMode(self: Window, mode: InputMode) i32 {
internal_debug.assertInitialized();
const value = c.glfwGetInputMode(self.handle, @enumToInt(mode));
const value = c.glfwGetInputMode(self.handle, @intFromEnum(mode));
return @intCast(i32, value);
}
@ -1660,10 +1660,10 @@ pub inline fn setInputMode(self: Window, mode: InputMode, value: anytype) void {
const int_value: c_int = switch (@typeInfo(T)) {
.Enum,
.EnumLiteral,
=> @enumToInt(@as(InputModeCursor, value)),
else => @boolToInt(value),
=> @intFromEnum(@as(InputModeCursor, value)),
else => @intFromBool(value),
};
c.glfwSetInputMode(self.handle, @enumToInt(mode), int_value);
c.glfwSetInputMode(self.handle, @intFromEnum(mode), int_value);
}
/// Returns the last reported press state of a keyboard key for the specified window.
@ -1692,8 +1692,8 @@ pub inline fn setInputMode(self: Window, mode: InputMode, value: anytype) void {
/// see also: input_key
pub inline fn getKey(self: Window, key: Key) Action {
internal_debug.assertInitialized();
const state = c.glfwGetKey(self.handle, @enumToInt(key));
return @intToEnum(Action, state);
const state = c.glfwGetKey(self.handle, @intFromEnum(key));
return @enumFromInt(Action, state);
}
/// Returns the last reported state of a mouse button for the specified window.
@ -1714,8 +1714,8 @@ pub inline fn getKey(self: Window, key: Key) Action {
/// see also: input_mouse_button
pub inline fn getMouseButton(self: Window, button: MouseButton) Action {
internal_debug.assertInitialized();
const state = c.glfwGetMouseButton(self.handle, @enumToInt(button));
return @intToEnum(Action, state);
const state = c.glfwGetMouseButton(self.handle, @intFromEnum(button));
return @enumFromInt(Action, state);
}
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 {
@call(.always_inline, user_callback, .{
from(handle.?),
@intToEnum(Key, key),
@enumFromInt(Key, key),
@intCast(i32, scancode),
@intToEnum(Action, action),
@enumFromInt(Action, action),
Mods.fromInt(mods),
});
}
@ -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 {
@call(.always_inline, user_callback, .{
from(handle.?),
@intToEnum(MouseButton, button),
@intToEnum(Action, action),
@enumFromInt(MouseButton, button),
@enumFromInt(Action, action),
Mods.fromInt(mods),
});
}
@ -2125,21 +2125,21 @@ inline fn hint(h: Hint, value: anytype) void {
switch (value_type_info) {
.Int, .ComptimeInt => {
c.glfwWindowHint(@enumToInt(h), @intCast(c_int, value));
c.glfwWindowHint(@intFromEnum(h), @intCast(c_int, value));
},
.Bool => {
const int_value = @boolToInt(value);
c.glfwWindowHint(@enumToInt(h), @intCast(c_int, int_value));
const int_value = @intFromBool(value);
c.glfwWindowHint(@intFromEnum(h), @intCast(c_int, int_value));
},
.Enum => {
const int_value = @enumToInt(value);
c.glfwWindowHint(@enumToInt(h), @intCast(c_int, int_value));
const int_value = @intFromEnum(value);
c.glfwWindowHint(@intFromEnum(h), @intCast(c_int, int_value));
},
.Array => |arr_type| {
if (arr_type.child != u8) {
@compileError("expected array of u8, got " ++ @typeName(arr_type));
}
c.glfwWindowHintString(@enumToInt(h), &value[0]);
c.glfwWindowHintString(@intFromEnum(h), &value[0]);
},
.Pointer => |pointer_info| {
const pointed_type = @typeInfo(pointer_info.child);
@ -2152,7 +2152,7 @@ inline fn hint(h: Hint, value: anytype) void {
else => @compileError("expected pointer to array, got " ++ @typeName(pointed_type)),
}
c.glfwWindowHintString(@enumToInt(h), &value[0]);
c.glfwWindowHintString(@intFromEnum(h), &value[0]);
},
else => {
@compileError("expected a int, bool, enum, array, or pointer, got " ++ @typeName(value_type));

View file

@ -150,7 +150,7 @@ pub const Key = enum(c_int) {
menu = cc.GLFW_KEY_MENU,
pub inline fn last() Key {
return @intToEnum(Key, cc.GLFW_KEY_LAST);
return @enumFromInt(Key, cc.GLFW_KEY_LAST);
}
/// Returns the layout-specific name of the specified printable key.
@ -215,7 +215,7 @@ pub const Key = enum(c_int) {
/// see also: input_key_name
pub inline fn getName(self: Key, scancode: i32) ?[:0]const u8 {
internal_debug.assertInitialized();
const name_opt = cc.glfwGetKeyName(@enumToInt(self), @intCast(c_int, scancode));
const name_opt = cc.glfwGetKeyName(@intFromEnum(self), @intCast(c_int, scancode));
return if (name_opt) |name|
std.mem.span(@ptrCast([*:0]const u8, name))
else
@ -237,7 +237,7 @@ pub const Key = enum(c_int) {
/// @thread_safety This function may be called from any thread.
pub inline fn getScancode(self: Key) i32 {
internal_debug.assertInitialized();
return cc.glfwGetKeyScancode(@enumToInt(self));
return cc.glfwGetKeyScancode(@intFromEnum(self));
}
};

View file

@ -101,7 +101,7 @@ pub inline fn init(hints: InitHints) bool {
const init_hint = @field(InitHint, field_name);
const init_value = @field(hints, field_name);
if (@TypeOf(init_value) == PlatformType) {
initHint(init_hint, @enumToInt(init_value));
initHint(init_hint, @intFromEnum(init_value));
} else {
initHint(init_hint, init_value);
}
@ -273,9 +273,9 @@ pub const PlatformType = enum(c_int) {
fn initHint(hint: InitHint, value: anytype) void {
switch (@typeInfo(@TypeOf(value))) {
.Int, .ComptimeInt => {
c.glfwInitHint(@enumToInt(hint), @intCast(c_int, value));
c.glfwInitHint(@intFromEnum(hint), @intCast(c_int, value));
},
.Bool => c.glfwInitHint(@enumToInt(hint), @intCast(c_int, @boolToInt(value))),
.Bool => c.glfwInitHint(@intFromEnum(hint), @intCast(c_int, @intFromBool(value))),
else => @compileError("expected a int or bool, got " ++ @typeName(@TypeOf(value))),
}
}
@ -313,7 +313,7 @@ pub inline fn getVersionString() [:0]const u8 {
/// thread_safety: This function may be called from any thread.
pub fn getPlatform() PlatformType {
internal_debug.assertInitialized();
return @intToEnum(PlatformType, c.glfwGetPlatform());
return @enumFromInt(PlatformType, c.glfwGetPlatform());
}
/// Returns whether the library includes support for the specified platform.
@ -327,7 +327,7 @@ pub fn getPlatform() PlatformType {
/// thread_safety: This function may be called from any thread.
pub fn platformSupported(platform: PlatformType) bool {
internal_debug.assertInitialized();
return c.glfwPlatformSupported(@enumToInt(platform)) == c.GLFW_TRUE;
return c.glfwPlatformSupported(@intFromEnum(platform)) == c.GLFW_TRUE;
}
/// Processes all pending events.

View file

@ -231,7 +231,7 @@ pub inline fn createWindowSurface(vk_instance: anytype, window: Window, vk_alloc
// zig-vulkan uses enums to represent opaque pointers:
// pub const Instance = enum(usize) { null_handle = 0, _ };
const instance: c.VkInstance = switch (@typeInfo(@TypeOf(vk_instance))) {
.Enum => @intToPtr(c.VkInstance, @enumToInt(vk_instance)),
.Enum => @ptrFromInt(c.VkInstance, @intFromEnum(vk_instance)),
else => @ptrCast(c.VkInstance, vk_instance),
};

View file

@ -69,7 +69,7 @@ pub const Interface = struct {
pub inline fn adapterHasFeature(adapter: *gpu.Adapter, feature: gpu.FeatureName) bool {
return procs.adapterHasFeature.?(
@ptrCast(c.WGPUAdapter, adapter),
@enumToInt(feature),
@intFromEnum(feature),
);
}
@ -599,14 +599,14 @@ pub const Interface = struct {
pub inline fn deviceHasFeature(device: *gpu.Device, feature: gpu.FeatureName) bool {
return procs.deviceHasFeature.?(
@ptrCast(c.WGPUDevice, device),
@enumToInt(feature),
@intFromEnum(feature),
);
}
pub inline fn deviceInjectError(device: *gpu.Device, typ: gpu.ErrorType, message: [*:0]const u8) void {
procs.deviceInjectError.?(
@ptrCast(c.WGPUDevice, device),
@enumToInt(typ),
@intFromEnum(typ),
message,
);
}
@ -622,7 +622,7 @@ pub const Interface = struct {
pub inline fn devicePushErrorScope(device: *gpu.Device, filter: gpu.ErrorFilter) void {
procs.devicePushErrorScope.?(
@ptrCast(c.WGPUDevice, device),
@enumToInt(filter),
@intFromEnum(filter),
);
}
@ -737,7 +737,7 @@ pub const Interface = struct {
}
pub inline fn querySetGetType(query_set: *gpu.QuerySet) gpu.QueryType {
return @intToEnum(gpu.QueryType, procs.querySetGetType.?(@ptrCast(c.WGPUQuerySet, query_set)));
return @enumFromInt(gpu.QueryType, procs.querySetGetType.?(@ptrCast(c.WGPUQuerySet, query_set)));
}
pub inline fn querySetSetLabel(query_set: *gpu.QuerySet, label: [*:0]const u8) void {
@ -901,7 +901,7 @@ pub const Interface = struct {
procs.renderBundleEncoderSetIndexBuffer.?(
@ptrCast(c.WGPURenderBundleEncoder, render_bundle_encoder),
@ptrCast(c.WGPUBuffer, buffer),
@enumToInt(format),
@intFromEnum(format),
offset,
size,
);
@ -1032,7 +1032,7 @@ pub const Interface = struct {
procs.renderPassEncoderSetIndexBuffer.?(
@ptrCast(c.WGPURenderPassEncoder, render_pass_encoder),
@ptrCast(c.WGPUBuffer, buffer),
@enumToInt(format),
@intFromEnum(format),
offset,
size,
);
@ -1199,11 +1199,11 @@ pub const Interface = struct {
}
pub inline fn textureGetDimension(texture: *gpu.Texture) gpu.Texture.Dimension {
return @intToEnum(gpu.Texture.Dimension, procs.textureGetDimension.?(@ptrCast(c.WGPUTexture, texture)));
return @enumFromInt(gpu.Texture.Dimension, procs.textureGetDimension.?(@ptrCast(c.WGPUTexture, texture)));
}
pub inline fn textureGetFormat(texture: *gpu.Texture) gpu.Texture.Format {
return @intToEnum(gpu.Texture.Format, procs.textureGetFormat.?(@ptrCast(c.WGPUTexture, texture)));
return @enumFromInt(gpu.Texture.Format, procs.textureGetFormat.?(@ptrCast(c.WGPUTexture, texture)));
}
pub inline fn textureGetHeight(texture: *gpu.Texture) u32 {

View file

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

View file

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

View file

@ -311,7 +311,7 @@ pub const Context = struct {
var ctl: ?*c.snd_ctl_t = undefined;
_ = switch (-lib.snd_ctl_open(&ctl, card_id.ptr, 0)) {
0 => {},
@enumToInt(std.os.E.NOENT) => break,
@intFromEnum(std.os.E.NOENT) => break,
else => return error.OpeningDevice,
};
defer _ = lib.snd_ctl_close(ctl);
@ -328,7 +328,7 @@ pub const Context = struct {
const snd_stream = modeToStream(mode);
lib.snd_pcm_info_set_stream(pcm_info, snd_stream);
const err = lib.snd_ctl_pcm_info(ctl, pcm_info);
switch (@intToEnum(std.os.E, -err)) {
switch (@enumFromInt(std.os.E, -err)) {
.SUCCESS => {},
.NOENT,
.NXIO,
@ -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)
return error.CannotSetVolume;
const dist = @intToFloat(f32, max_vol - min_vol);
const dist = @floatFromInt(f32, max_vol - min_vol);
if (lib.snd_mixer_selem_set_playback_volume_all(
self.mixer_elm,
@floatToInt(c_long, dist * vol) + min_vol,
@intFromFloat(c_long, dist * vol) + min_vol,
) < 0)
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)
return error.CannotGetVolume;
return @intToFloat(f32, vol) / @intToFloat(f32, max_vol - min_vol);
return @floatFromInt(f32, vol) / @floatFromInt(f32, max_vol - min_vol);
}
};

View file

@ -210,8 +210,8 @@ pub const Context = struct {
.channels = channels,
.formats = &.{ .i16, .i32, .f32 },
.sample_rate = .{
.min = @floatToInt(u24, @floor(sample_rate)),
.max = @floatToInt(u24, @floor(sample_rate)),
.min = @intFromFloat(u24, @floor(sample_rate)),
.max = @intFromFloat(u24, @floor(sample_rate)),
},
};
@ -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 {
var desc = c.AudioStreamBasicDescription{
.mSampleRate = @intToFloat(f64, sample_rate),
.mSampleRate = @floatFromInt(f64, sample_rate),
.mFormatID = c.kAudioFormatLinearPCM,
.mFormatFlags = switch (format) {
.i16 => c.kAudioFormatFlagIsSignedInteger,

View file

@ -142,7 +142,7 @@ pub const Context = struct {
for (self.devices_info.list.items) |*dev| {
if (std.mem.eql(u8, dev.id, id) and mode == dev.mode) {
const new_ch = main.Channel{
.id = @intToEnum(main.Channel.Id, dev.channels.len),
.id = @enumFromInt(main.Channel.Id, dev.channels.len),
};
dev.channels = try self.allocator.realloc(dev.channels, dev.channels.len + 1);
dev.channels[dev.channels.len - 1] = new_ch;
@ -156,7 +156,7 @@ pub const Context = struct {
.mode = mode,
.channels = blk: {
var channels = try self.allocator.alloc(main.Channel, 1);
channels[0] = .{ .id = @intToEnum(main.Channel.Id, 0) };
channels[0] = .{ .id = @enumFromInt(main.Channel.Id, 0) };
break :blk channels;
},
.formats = &.{.f32},

View file

@ -37,7 +37,7 @@ pub const Context = struct {
} else {
inline for (std.meta.fields(Backend), 0..) |b, i| {
if (@typeInfo(
std.meta.fieldInfo(backends.BackendContext, @intToEnum(Backend, b.value)).type,
std.meta.fieldInfo(backends.BackendContext, @enumFromInt(Backend, b.value)).type,
).Pointer.child.init(allocator, options)) |d| {
break :blk d;
} else |err| {
@ -280,7 +280,7 @@ fn unsignedToSigned(comptime T: type, sample: anytype) T {
fn unsignedToFloat(comptime T: type, sample: anytype) T {
const max_int = std.math.maxInt(@TypeOf(sample)) + 1.0;
return (@intToFloat(T, sample) - max_int) * 1.0 / max_int;
return (@floatFromInt(T, sample) - max_int) * 1.0 / max_int;
}
fn signedToSigned(comptime T: type, sample: anytype) T {
@ -296,16 +296,16 @@ fn signedToUnsigned(comptime T: type, sample: anytype) T {
fn signedToFloat(comptime T: type, sample: anytype) T {
const max_int = std.math.maxInt(@TypeOf(sample)) + 1.0;
return @intToFloat(T, sample) * 1.0 / max_int;
return @floatFromInt(T, sample) * 1.0 / max_int;
}
fn floatToSigned(comptime T: type, sample: f64) T {
return @floatToInt(T, sample * std.math.maxInt(T));
return @intFromFloat(T, sample * std.math.maxInt(T));
}
fn floatToUnsigned(comptime T: type, sample: f64) T {
const half = 1 << @bitSizeOf(T) - 1;
return @floatToInt(T, sample * (half - 1) + half);
return @intFromFloat(T, sample * (half - 1) + half);
}
pub const Device = struct {

View file

@ -208,7 +208,7 @@ pub const Context = struct {
c.PW_KEY_AUDIO_RATE,
audio_rate.ptr,
@intToPtr(*allowzero u0, 0),
@ptrFromInt(*allowzero u0, 0),
);
var player = try self.allocator.create(Player);

View file

@ -564,7 +564,7 @@ pub const Player = struct {
return;
}
self.vol = @intToFloat(f32, info.*.volume.values[0]) / @intToFloat(f32, c.PA_VOLUME_NORM);
self.vol = @floatFromInt(f32, info.*.volume.values[0]) / @floatFromInt(f32, c.PA_VOLUME_NORM);
}
};

View file

@ -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 {
if (riid.?.eql(win32.IID_IUnknown.*) or riid.?.eql(win32.IID_IMMNotificationClient.*)) {
ppv.?.* = @intToPtr(?*anyopaque, @ptrToInt(self));
ppv.?.* = @ptrFromInt(?*anyopaque, @intFromPtr(self));
_ = self.AddRef();
return win32.S_OK;
} else {

View file

@ -87,7 +87,7 @@ pub const Context = struct {
errdefer self.allocator.destroy(player);
var captures = try self.allocator.alloc(js.Value, 1);
captures[0] = js.createNumber(@ptrToInt(player));
captures[0] = js.createNumber(@intFromPtr(player));
const document = js.global().get("document").view(.object);
defer document.deinit();
@ -163,7 +163,7 @@ pub const Player = struct {
}
fn resumeOnClick(args: js.Object, _: usize, captures: []js.Value) js.Value {
const self = @intToPtr(*Player, @floatToInt(usize, captures[0].view(.num)));
const self = @ptrFromInt(*Player, @intFromFloat(usize, captures[0].view(.num)));
self.play() catch {};
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 {
const self = @intToPtr(*Player, @floatToInt(usize, captures[0].view(.num)));
const self = @ptrFromInt(*Player, @intFromFloat(usize, captures[0].view(.num)));
const event = args.getIndex(0).view(.object);
defer event.deinit();

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 ubo = UniformBufferObject{
.resolution = .{ @intToFloat(f32, app.core.descriptor().width), @intToFloat(f32, app.core.descriptor().height) },
.resolution = .{ @floatFromInt(f32, app.core.descriptor().width), @floatFromInt(f32, app.core.descriptor().height) },
.time = time,
};
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_sizes = sprite_sizes,
.texture_size = Vec2{
@intToFloat(f32, sprite2d.state().texture.getWidth()),
@intToFloat(f32, sprite2d.state().texture.getHeight()),
@floatFromInt(f32, sprite2d.state().texture.getWidth()),
@floatFromInt(f32, sprite2d.state().texture.getHeight()),
},
.texture = sprite2d.state().texture,
});
@ -195,10 +195,10 @@ pub fn tick(adapter: anytype) !void {
// Update uniform buffer
const ortho = mat.ortho(
-@intToFloat(f32, core.size().width) / 2,
@intToFloat(f32, core.size().width) / 2,
-@intToFloat(f32, core.size().height) / 2,
@intToFloat(f32, core.size().height) / 2,
-@floatFromInt(f32, core.size().width) / 2,
@floatFromInt(f32, core.size().width) / 2,
-@floatFromInt(f32, core.size().height) / 2,
@floatFromInt(f32, core.size().height) / 2,
-0.1,
100000,
);