send one move input per joystick button press
This makes it easier to control on the RG351M, as inputting a single move no longer requires a frame perfect press and release.dev
parent
980d8cb6a1
commit
84d8766124
40
src/main.zig
40
src/main.zig
|
@ -220,6 +220,15 @@ pub fn main() !void {
|
||||||
std.log.info("detected joystick = \"{?s}\" {?s}", .{ seizer.backend.glfw.c.glfwGetJoystickName(seizer.backend.glfw.c.GLFW_JOYSTICK_1), seizer.backend.glfw.c.glfwGetJoystickGUID(seizer.backend.glfw.c.GLFW_JOYSTICK_1) });
|
std.log.info("detected joystick = \"{?s}\" {?s}", .{ seizer.backend.glfw.c.glfwGetJoystickName(seizer.backend.glfw.c.GLFW_JOYSTICK_1), seizer.backend.glfw.c.glfwGetJoystickGUID(seizer.backend.glfw.c.GLFW_JOYSTICK_1) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var prev_controller_input_state = InputState{
|
||||||
|
.left = false,
|
||||||
|
.right = false,
|
||||||
|
.up = false,
|
||||||
|
.down = false,
|
||||||
|
.action = false,
|
||||||
|
.undo = false,
|
||||||
|
};
|
||||||
|
|
||||||
while (seizer.backend.glfw.c.glfwWindowShouldClose(window) != seizer.backend.glfw.c.GLFW_TRUE) {
|
while (seizer.backend.glfw.c.glfwWindowShouldClose(window) != seizer.backend.glfw.c.GLFW_TRUE) {
|
||||||
input_state = .{
|
input_state = .{
|
||||||
.left = false,
|
.left = false,
|
||||||
|
@ -240,6 +249,15 @@ pub fn main() !void {
|
||||||
input_state.down = input_state.down or gamepad_state.buttons[seizer.backend.glfw.c.GLFW_GAMEPAD_BUTTON_DPAD_DOWN] != 0;
|
input_state.down = input_state.down or gamepad_state.buttons[seizer.backend.glfw.c.GLFW_GAMEPAD_BUTTON_DPAD_DOWN] != 0;
|
||||||
}
|
}
|
||||||
} else if (seizer.backend.glfw.c.glfwJoystickPresent(seizer.backend.glfw.c.GLFW_JOYSTICK_1) != 0) {
|
} else if (seizer.backend.glfw.c.glfwJoystickPresent(seizer.backend.glfw.c.GLFW_JOYSTICK_1) != 0) {
|
||||||
|
var controller_input_state = InputState{
|
||||||
|
.left = false,
|
||||||
|
.right = false,
|
||||||
|
.up = false,
|
||||||
|
.down = false,
|
||||||
|
.action = false,
|
||||||
|
.undo = false,
|
||||||
|
};
|
||||||
|
|
||||||
var hats_count: c_int = undefined;
|
var hats_count: c_int = undefined;
|
||||||
const hats_ptr = seizer.backend.glfw.c.glfwGetJoystickHats(seizer.backend.glfw.c.GLFW_JOYSTICK_1, &hats_count);
|
const hats_ptr = seizer.backend.glfw.c.glfwGetJoystickHats(seizer.backend.glfw.c.GLFW_JOYSTICK_1, &hats_count);
|
||||||
const hats = hats_ptr[0..@intCast(hats_count)];
|
const hats = hats_ptr[0..@intCast(hats_count)];
|
||||||
|
@ -249,16 +267,26 @@ pub fn main() !void {
|
||||||
const HAT_DOWN = seizer.backend.glfw.c.GLFW_HAT_DOWN;
|
const HAT_DOWN = seizer.backend.glfw.c.GLFW_HAT_DOWN;
|
||||||
const HAT_LEFT = seizer.backend.glfw.c.GLFW_HAT_LEFT;
|
const HAT_LEFT = seizer.backend.glfw.c.GLFW_HAT_LEFT;
|
||||||
|
|
||||||
input_state.left = input_state.left or hats[0] & HAT_LEFT != 0;
|
controller_input_state.left = hats[0] & HAT_LEFT != 0;
|
||||||
input_state.right = input_state.right or hats[0] & HAT_RIGHT != 0;
|
controller_input_state.right = hats[0] & HAT_RIGHT != 0;
|
||||||
input_state.up = input_state.up or hats[0] & HAT_UP != 0;
|
controller_input_state.up = hats[0] & HAT_UP != 0;
|
||||||
input_state.down = input_state.down or hats[0] & HAT_DOWN != 0;
|
controller_input_state.down = hats[0] & HAT_DOWN != 0;
|
||||||
|
|
||||||
var buttons_count: c_int = undefined;
|
var buttons_count: c_int = undefined;
|
||||||
const buttons_ptr = seizer.backend.glfw.c.glfwGetJoystickButtons(seizer.backend.glfw.c.GLFW_JOYSTICK_1, &buttons_count);
|
const buttons_ptr = seizer.backend.glfw.c.glfwGetJoystickButtons(seizer.backend.glfw.c.GLFW_JOYSTICK_1, &buttons_count);
|
||||||
const buttons = buttons_ptr[0..@intCast(buttons_count)];
|
const buttons = buttons_ptr[0..@intCast(buttons_count)];
|
||||||
input_state.action = input_state.action or buttons[0] != 0;
|
controller_input_state.action = buttons[0] != 0;
|
||||||
input_state.undo = input_state.undo or buttons[1] != 0;
|
controller_input_state.undo = buttons[1] != 0;
|
||||||
|
|
||||||
|
// detect rising for controller input
|
||||||
|
input_state.left = input_state.left or (!prev_controller_input_state.left and controller_input_state.left);
|
||||||
|
input_state.right = input_state.right or (!prev_controller_input_state.right and controller_input_state.right);
|
||||||
|
input_state.up = input_state.up or (!prev_controller_input_state.up and controller_input_state.up);
|
||||||
|
input_state.down = input_state.down or (!prev_controller_input_state.down and controller_input_state.down);
|
||||||
|
input_state.action = input_state.action or (!prev_controller_input_state.action and controller_input_state.action);
|
||||||
|
input_state.undo = input_state.undo or (!prev_controller_input_state.undo and controller_input_state.undo);
|
||||||
|
|
||||||
|
prev_controller_input_state = controller_input_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
var request_command: ?[]const u8 = null;
|
var request_command: ?[]const u8 = null;
|
||||||
|
|
Loading…
Reference in New Issue