mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-06-09 23:29:37 +00:00
Read buttons when joystick is read, otherwise it sucks
This commit is contained in:
parent
cd16f37259
commit
bba6a81d4a
|
@ -92,7 +92,7 @@ public class Joystick extends Device {
|
||||||
@ConfigurableField(name = "Prefer D-PAD", shortName = "dpad", description = "Physical game controller enable D-PAD")
|
@ConfigurableField(name = "Prefer D-PAD", shortName = "dpad", description = "Physical game controller enable D-PAD")
|
||||||
public boolean useDPad = false;
|
public boolean useDPad = false;
|
||||||
@ConfigurableField(name = "Timer resolution", shortName = "timerres", description = "How many ticks until we poll the buttons again?")
|
@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;
|
Integer controllerNumber = null;
|
||||||
|
|
||||||
|
@ -194,11 +194,26 @@ public class Joystick extends Device {
|
||||||
}
|
}
|
||||||
joyX = (int) (x * 128.0 + 128.0);
|
joyX = (int) (x * 128.0 + 128.0);
|
||||||
joyY = (int) (y * 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
|
@Override
|
||||||
protected String getDeviceName() {
|
protected String getDeviceName() {
|
||||||
return "Joystick (port " + port + ")";
|
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
|
// Read joystick buttons ~60 times a second as long as joystick is actively in use
|
||||||
Integer controllerNum = getControllerNum();
|
Integer controllerNum = getControllerNum();
|
||||||
if (controllerNum != null) {
|
if (controllerNum != null) {
|
||||||
Platform.runLater(()->{
|
Platform.runLater(this::readButtons);
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (finished) {
|
} else if (finished) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user