Port to zig 0.17.0
This commit is contained in:
5
vendor/zglfw/build.zig
vendored
5
vendor/zglfw/build.zig
vendored
@@ -28,8 +28,9 @@ pub fn build(b: *std.Build) void {
|
||||
};
|
||||
|
||||
const options_step = b.addOptions();
|
||||
inline for (std.meta.fields(@TypeOf(options))) |field| {
|
||||
options_step.addOption(field.type, field.name, @field(options, field.name));
|
||||
const options_type_info = @typeInfo(@TypeOf(options)).@"struct";
|
||||
inline for (options_type_info.field_types, options_type_info.field_names) |field_type, field_name| {
|
||||
options_step.addOption(field_type, field_name, @field(options, field_name));
|
||||
}
|
||||
|
||||
const options_module = options_step.createModule();
|
||||
|
||||
75
vendor/zglfw/src/zglfw.zig
vendored
75
vendor/zglfw/src/zglfw.zig
vendored
@@ -14,7 +14,7 @@ fn cIntCast(value: anytype) c_int {
|
||||
const ValueType = @TypeOf(value);
|
||||
return switch (@typeInfo(ValueType)) {
|
||||
.int => @intCast(value),
|
||||
.@"enum", .enum_literal => @intFromEnum(value),
|
||||
.@"enum", .enum_literal => @backingInt(value),
|
||||
.bool => @intFromBool(value),
|
||||
else => @compileError("Cannot cast " ++ @typeName(ValueType) ++ "to int."),
|
||||
};
|
||||
@@ -26,8 +26,8 @@ fn cIntCast(value: anytype) c_int {
|
||||
//
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
pub const Bool = enum(c_int) { _ };
|
||||
pub const TRUE: Bool = @enumFromInt(1);
|
||||
pub const FALSE: Bool = @enumFromInt(0);
|
||||
pub const TRUE: Bool = @fromBackingInt(1);
|
||||
pub const FALSE: Bool = @fromBackingInt(0);
|
||||
|
||||
pub const InitHint = enum(c_int) {
|
||||
joystick_hat_buttons = 0x00050001,
|
||||
@@ -92,15 +92,12 @@ extern fn glfwGetRequiredInstanceExtensions(count: *u32) ?*?[*:0]const u8;
|
||||
|
||||
pub const VulkanFn = *const fn () callconv(.c) void;
|
||||
|
||||
const vk = if (options.enable_vulkan_import)
|
||||
@import("vulkan")
|
||||
else
|
||||
struct {
|
||||
pub const Instance = ?*const anyopaque;
|
||||
pub const PhysicalDevice = ?*const anyopaque;
|
||||
pub const AllocationCallbacks = anyopaque;
|
||||
pub const SurfaceKHR = anyopaque;
|
||||
};
|
||||
const vk = struct {
|
||||
pub const Instance = if (options.enable_vulkan_import) ?@import("vulkan").Instance else ?*const anyopaque;
|
||||
pub const PhysicalDevice = if (options.enable_vulkan_import) ?@import("vulkan").PhysicalDevice else ?*const anyopaque;
|
||||
pub const AllocationCallbacks = if (options.enable_vulkan_import) @import("vulkan").AllocationCallbacks else anyopaque;
|
||||
pub const SurfaceKHR = if (options.enable_vulkan_import) @import("vulkan").SurfaceKHR else anyopaque;
|
||||
};
|
||||
|
||||
pub const getInstanceProcAddress = glfwGetInstanceProcAddress;
|
||||
extern fn glfwGetInstanceProcAddress(instance: vk.Instance, procname: [*:0]const u8) ?VulkanFn;
|
||||
@@ -527,7 +524,7 @@ pub fn joystickIsGamepad(joystick: Joystick) bool {
|
||||
extern fn glfwJoystickIsGamepad(Joystick) Bool;
|
||||
|
||||
pub fn joystickAsGamepad(joystick: Joystick) ?Gamepad {
|
||||
return if (joystickIsGamepad(joystick)) @enumFromInt(@intFromEnum(joystick)) else null;
|
||||
return if (joystickIsGamepad(joystick)) @fromBackingInt(@backingInt(joystick)) else null;
|
||||
}
|
||||
|
||||
pub const JoystickFn = *const fn (joystick: Joystick, event: Joystick.Event) callconv(.c) void;
|
||||
@@ -579,15 +576,15 @@ pub const Gamepad = enum(c_int) {
|
||||
};
|
||||
|
||||
pub const State = extern struct {
|
||||
comptime {
|
||||
const c = @cImport(@cInclude("GLFW/glfw3.h"));
|
||||
assert(@sizeOf(c.GLFWgamepadstate) == @sizeOf(State));
|
||||
for (std.meta.fieldNames(State)) |field_name| {
|
||||
assert(@offsetOf(c.GLFWgamepadstate, field_name) == @offsetOf(State, field_name));
|
||||
}
|
||||
}
|
||||
buttons: [Button.count]Joystick.ButtonAction = .{Joystick.ButtonAction.release} ** Button.count,
|
||||
axes: [Axis.count]f32 = .{@as(f32, 0)} ** Axis.count,
|
||||
//comptime {
|
||||
// const c = @cImport(@cInclude("GLFW/glfw3.h"));
|
||||
// assert(@sizeOf(c.GLFWgamepadstate) == @sizeOf(State));
|
||||
// for (std.meta.fieldNames(State)) |field_name| {
|
||||
// assert(@offsetOf(c.GLFWgamepadstate, field_name) == @offsetOf(State, field_name));
|
||||
// }
|
||||
//}
|
||||
buttons: [Button.count]Joystick.ButtonAction = @splat(.release),
|
||||
axes: [Axis.count]f32 = @splat(0),
|
||||
};
|
||||
|
||||
pub const getName = getGamepadName;
|
||||
@@ -710,14 +707,14 @@ pub fn getVideoModes(monitor: *Monitor) Error![]VideoMode {
|
||||
extern fn glfwGetVideoModes(*Monitor, count: *c_int) ?[*]VideoMode;
|
||||
|
||||
pub const VideoMode = extern struct {
|
||||
comptime {
|
||||
const c = @cImport(@cInclude("GLFW/glfw3.h"));
|
||||
assert(@sizeOf(c.GLFWvidmode) == @sizeOf(VideoMode));
|
||||
for (std.meta.fieldNames(VideoMode), 0..) |field_name, i| {
|
||||
assert(@offsetOf(c.GLFWvidmode, std.meta.fieldNames(c.GLFWvidmode)[i]) ==
|
||||
@offsetOf(VideoMode, field_name));
|
||||
}
|
||||
}
|
||||
//comptime {
|
||||
// const c = @cImport(@cInclude("GLFW/glfw3.h"));
|
||||
// assert(@sizeOf(c.GLFWvidmode) == @sizeOf(VideoMode));
|
||||
// for (std.meta.fieldNames(VideoMode), 0..) |field_name, i| {
|
||||
// assert(@offsetOf(c.GLFWvidmode, std.meta.fieldNames(c.GLFWvidmode)[i]) ==
|
||||
// @offsetOf(VideoMode, field_name));
|
||||
// }
|
||||
//}
|
||||
width: c_int,
|
||||
height: c_int,
|
||||
red_bits: c_int,
|
||||
@@ -731,13 +728,13 @@ pub const VideoMode = extern struct {
|
||||
//
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
pub const Image = extern struct {
|
||||
comptime {
|
||||
const c = @cImport(@cInclude("GLFW/glfw3.h"));
|
||||
assert(@sizeOf(c.GLFWimage) == @sizeOf(Image));
|
||||
for (std.meta.fieldNames(Image)) |field_name| {
|
||||
assert(@offsetOf(c.GLFWimage, field_name) == @offsetOf(Image, field_name));
|
||||
}
|
||||
}
|
||||
//comptime {
|
||||
// const c = @cImport(@cInclude("GLFW/glfw3.h"));
|
||||
// assert(@sizeOf(c.GLFWimage) == @sizeOf(Image));
|
||||
// for (std.meta.fieldNames(Image)) |field_name| {
|
||||
// assert(@offsetOf(c.GLFWimage, field_name) == @offsetOf(Image, field_name));
|
||||
// }
|
||||
//}
|
||||
width: c_int,
|
||||
height: c_int,
|
||||
pixels: [*]u8,
|
||||
@@ -904,7 +901,7 @@ pub fn getWindowAttribute(
|
||||
comptime attrib: Window.Attribute,
|
||||
) Window.Attribute.ValueType(attrib) {
|
||||
return switch (@typeInfo(Window.Attribute.ValueType(attrib))) {
|
||||
.bool => @as(Bool, @enumFromInt(getWindowAttributeUntyped(window, attrib))) == TRUE,
|
||||
.bool => getWindowAttributeUntyped(window, attrib) != 0,
|
||||
.int => getWindowAttributeUntyped(window, attrib),
|
||||
else => unreachable,
|
||||
};
|
||||
@@ -1142,7 +1139,7 @@ pub fn getInputMode(
|
||||
window: *Window,
|
||||
comptime mode: InputMode,
|
||||
) Error!InputMode.ValueType(mode) {
|
||||
return @enumFromInt(try getInputModeUntyped(window, mode));
|
||||
return @fromBackingInt(try getInputModeUntyped(window, mode));
|
||||
}
|
||||
pub fn getInputModeUntyped(window: *Window, mode: InputMode) Error!c_int {
|
||||
const value = glfwGetInputMode(window, mode);
|
||||
|
||||
Reference in New Issue
Block a user