glfw: Revert error denormalization

This commit is contained in:
InKryption 2021-11-22 00:34:38 +01:00 committed by Stephen Gutekanst
parent 44fee8f1f1
commit ef7ada052c
10 changed files with 146 additions and 146 deletions

View file

@ -86,13 +86,13 @@ const GamepadState = extern struct {
/// @thread_safety This function must only be called from the main thread.
///
/// see also: joystick
pub inline fn present(self: Joystick) error{ InvalidEnum, PlatformError }!bool {
pub inline fn present(self: Joystick) Error!bool {
internal_debug.assertInitialized();
const is_present = c.glfwJoystickPresent(self.jid);
getError() catch |err| return switch (err) {
Error.InvalidEnum,
Error.PlatformError,
=> @errSetCast(error{ InvalidEnum, PlatformError }, err),
=> err,
else => unreachable,
};
return is_present == c.GLFW_TRUE;
@ -118,14 +118,14 @@ pub inline fn present(self: Joystick) error{ InvalidEnum, PlatformError }!bool {
///
/// see also: joystick_axis
/// Replaces `glfwGetJoystickPos`.
pub inline fn getAxes(self: Joystick) error{ InvalidEnum, PlatformError }!?[]const f32 {
pub inline fn getAxes(self: Joystick) Error!?[]const f32 {
internal_debug.assertInitialized();
var count: c_int = undefined;
const axes = c.glfwGetJoystickAxes(self.jid, &count);
getError() catch |err| return switch (err) {
Error.InvalidEnum,
Error.PlatformError,
=> @errSetCast(error{ InvalidEnum, PlatformError }, err),
=> err,
else => unreachable,
};
if (axes == null) return null;
@ -156,14 +156,14 @@ pub inline fn getAxes(self: Joystick) error{ InvalidEnum, PlatformError }!?[]con
/// @thread_safety This function must only be called from the main thread.
///
/// see also: joystick_button
pub inline fn getButtons(self: Joystick) error{ InvalidEnum, PlatformError }!?[]const u8 {
pub inline fn getButtons(self: Joystick) Error!?[]const u8 {
internal_debug.assertInitialized();
var count: c_int = undefined;
const buttons = c.glfwGetJoystickButtons(self.jid, &count);
getError() catch |err| return switch (err) {
Error.InvalidEnum,
Error.PlatformError,
=> @errSetCast(error{ InvalidEnum, PlatformError }, err),
=> err,
else => unreachable,
};
if (buttons == null) return null;
@ -210,14 +210,14 @@ pub inline fn getButtons(self: Joystick) error{ InvalidEnum, PlatformError }!?[]
/// @thread_safety This function must only be called from the main thread.
///
/// see also: joystick_hat
pub inline fn getHats(self: Joystick) error{ InvalidEnum, PlatformError }!?[]const Hat {
pub inline fn getHats(self: Joystick) Error!?[]const Hat {
internal_debug.assertInitialized();
var count: c_int = undefined;
const hats = c.glfwGetJoystickHats(self.jid, &count);
getError() catch |err| return switch (err) {
Error.InvalidEnum,
Error.PlatformError,
=> @errSetCast(error{ InvalidEnum, PlatformError }, err),
=> err,
else => unreachable,
};
if (hats == null) return null;
@ -244,13 +244,13 @@ pub inline fn getHats(self: Joystick) error{ InvalidEnum, PlatformError }!?[]con
/// @thread_safety This function must only be called from the main thread.
///
/// see also: joystick_name
pub inline fn getName(self: Joystick) error{ InvalidEnum, PlatformError }!?[:0]const u8 {
pub inline fn getName(self: Joystick) Error!?[:0]const u8 {
internal_debug.assertInitialized();
const name_opt = c.glfwGetJoystickName(self.jid);
getError() catch |err| return switch (err) {
Error.InvalidEnum,
Error.PlatformError,
=> @errSetCast(error{ InvalidEnum, PlatformError }, err),
=> err,
else => unreachable,
};
return if (name_opt) |name|
@ -286,13 +286,13 @@ pub inline fn getName(self: Joystick) error{ InvalidEnum, PlatformError }!?[:0]c
/// @thread_safety This function must only be called from the main thread.
///
/// see also: gamepad
pub inline fn getGUID(self: Joystick) error{ InvalidEnum, PlatformError }!?[:0]const u8 {
pub inline fn getGUID(self: Joystick) Error!?[:0]const u8 {
internal_debug.assertInitialized();
const guid_opt = c.glfwGetJoystickGUID(self.jid);
getError() catch |err| return switch (err) {
Error.InvalidEnum,
Error.PlatformError,
=> @errSetCast(error{ InvalidEnum, PlatformError }, err),
=> err,
else => unreachable,
};
return if (guid_opt) |guid|
@ -404,11 +404,11 @@ pub inline fn setCallback(callback: ?fn (joystick: Joystick, event: Event) void)
///
///
/// @ingroup input
pub inline fn updateGamepadMappings(gamepad_mappings: [*:0]const u8) error{ InvalidValue }!void {
pub inline fn updateGamepadMappings(gamepad_mappings: [*:0]const u8) Error!void {
internal_debug.assertInitialized();
_ = c.glfwUpdateGamepadMappings(gamepad_mappings);
getError() catch |err| return switch (err) {
Error.InvalidValue => @errSetCast(error{ InvalidValue }, err),
Error.InvalidValue => err,
else => unreachable,
};
}
@ -462,11 +462,11 @@ pub inline fn isGamepad(self: Joystick) bool {
/// see also: gamepad, glfw.Joystick.isGamepad
// TODO: Consider this; GLFW documentation for this function doesn't list any errors,
// but source code in 'init.c' only appears to return 'GLFW_INVALID_ENUM' and 'GLFW_NOT_INITIALIZED' on error.
pub inline fn getGamepadName(self: Joystick) error{ InvalidEnum }!?[:0]const u8 {
pub inline fn getGamepadName(self: Joystick) Error!?[:0]const u8 {
internal_debug.assertInitialized();
const name_opt = c.glfwGetGamepadName(self.jid);
getError() catch |err| return switch (err) {
Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err),
Error.InvalidEnum => err,
else => unreachable,
};
return if (name_opt) |name|
@ -499,12 +499,12 @@ pub inline fn getGamepadName(self: Joystick) error{ InvalidEnum }!?[:0]const u8
/// @thread_safety This function must only be called from the main thread.
///
/// see also: gamepad, glfw.UpdateGamepadMappings, glfw.Joystick.isGamepad
pub inline fn getGamepadState(self: Joystick) error{ InvalidEnum }!?GamepadState {
pub inline fn getGamepadState(self: Joystick) Error!?GamepadState {
internal_debug.assertInitialized();
var state: GamepadState = undefined;
const success = c.glfwGetGamepadState(self.jid, @ptrCast(*c.GLFWgamepadstate, &state));
getError() catch |err| return switch (err) {
Error.InvalidEnum => @errSetCast(error{ InvalidEnum }, err),
Error.InvalidEnum => err,
else => unreachable,
};
return if (success == c.GLFW_TRUE) state else null;