From bba6a81d4ab9379aaf6fbe4b5f29b5f7c9456b32 Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Wed, 6 Mar 2024 16:29:11 -0600 Subject: [PATCH] Read buttons when joystick is read, otherwise it sucks --- .../src/main/java/jace/hardware/Joystick.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Platform/Apple/tools/jace/src/main/java/jace/hardware/Joystick.java b/Platform/Apple/tools/jace/src/main/java/jace/hardware/Joystick.java index 60e06a3a..27587dc1 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/hardware/Joystick.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/hardware/Joystick.java @@ -92,7 +92,7 @@ public class Joystick extends Device { @ConfigurableField(name = "Prefer D-PAD", shortName = "dpad", description = "Physical game controller enable D-PAD") public boolean useDPad = false; @ConfigurableField(name = "Timer resolution", shortName = "timerres", description = "How many ticks until we poll the buttons again?") - public static long TIMER_RESOLUTION = TimedDevice.NTSC_1MHZ / 20; // 20FPS resolution + public static long TIMER_RESOLUTION = TimedDevice.NTSC_1MHZ / 15; // 15FPS resolution reads when joystick is not used Integer controllerNumber = null; @@ -194,11 +194,26 @@ public class Joystick extends Device { } joyX = (int) (x * 128.0 + 128.0); joyY = (int) (y * 128.0 + 128.0); + + readButtons(); } }); } } + private void readButtons() { + if (selectedPhysicalController()) { + Integer controllerNum = getControllerNum(); + if (controllerNum != null) { + ByteBuffer buttons = GLFW.glfwGetJoystickButtons(controllerNumber); + byte b0 = button0 >=0 && button0 < buttons.capacity() ? buttons.get(button0) : 0; + byte b1 = button1 >=0 && button1 < buttons.capacity() ? buttons.get(button1) : 0; + SoftSwitches.PB0.getSwitch().setState(b0 != 0); + SoftSwitches.PB1.getSwitch().setState(b1 != 0); + } + } + } + @Override protected String getDeviceName() { return "Joystick (port " + port + ")"; @@ -236,13 +251,7 @@ public class Joystick extends Device { // Read joystick buttons ~60 times a second as long as joystick is actively in use Integer controllerNum = getControllerNum(); if (controllerNum != null) { - Platform.runLater(()->{ - ByteBuffer buttons = GLFW.glfwGetJoystickButtons(controllerNumber); - byte b0 = button0 >=0 && button0 < buttons.capacity() ? buttons.get(button0) : 0; - byte b1 = button1 >=0 && button1 < buttons.capacity() ? buttons.get(button1) : 0; - SoftSwitches.PB0.getSwitch().setState(b0 != 0); - SoftSwitches.PB1.getSwitch().setState(b1 != 0); - }); + Platform.runLater(this::readButtons); } } } else if (finished) {