Fixed call to onJoyButtonEvent()
The method onJoyButtonEvent() was being called on every update(). Now it is called only when the state of a button changes (from not pressed to pressed and vice-versa).
This commit is contained in:
parent
61e19c6381
commit
0c7f194feb
@ -52,8 +52,11 @@ public class GlfwJoystickInput implements JoyInput {
|
|||||||
private static final Logger LOGGER = Logger.getLogger(InputManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(InputManager.class.getName());
|
||||||
|
|
||||||
private RawInputListener listener;
|
private RawInputListener listener;
|
||||||
|
|
||||||
private final Map<Integer, GlfwJoystick> joysticks = new HashMap<>();
|
private final Map<Integer, GlfwJoystick> joysticks = new HashMap<>();
|
||||||
|
|
||||||
|
private final Map<JoystickButton, Boolean> joyButtonPressed = new HashMap<>();
|
||||||
|
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -88,8 +91,11 @@ public class GlfwJoystickInput implements JoyInput {
|
|||||||
int buttonIndex = 0;
|
int buttonIndex = 0;
|
||||||
while (byteBuffer.hasRemaining()) {
|
while (byteBuffer.hasRemaining()) {
|
||||||
byteBuffer.get();
|
byteBuffer.get();
|
||||||
|
|
||||||
final String logicalId = JoystickCompatibilityMappings.remapComponent(joystick.getName(), String.valueOf(buttonIndex));
|
final String logicalId = JoystickCompatibilityMappings.remapComponent(joystick.getName(), String.valueOf(buttonIndex));
|
||||||
joystick.addButton(new DefaultJoystickButton(inputManager, joystick, buttonIndex, String.valueOf(buttonIndex), logicalId));
|
final JoystickButton button = new DefaultJoystickButton(inputManager, joystick, buttonIndex, String.valueOf(buttonIndex), logicalId);
|
||||||
|
joystick.addButton(button);
|
||||||
|
joyButtonPressed.put(button, false);
|
||||||
buttonIndex++;
|
buttonIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,10 +139,14 @@ public class GlfwJoystickInput implements JoyInput {
|
|||||||
|
|
||||||
for (final JoystickButton button : entry.getValue().getButtons()) {
|
for (final JoystickButton button : entry.getValue().getButtons()) {
|
||||||
final boolean pressed = byteBuffer.get(button.getButtonId()) == GLFW_PRESS;
|
final boolean pressed = byteBuffer.get(button.getButtonId()) == GLFW_PRESS;
|
||||||
|
|
||||||
|
if (joyButtonPressed.get(button) != pressed) {
|
||||||
|
joyButtonPressed.put(button, pressed);
|
||||||
listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed));
|
listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
@ -213,6 +223,3 @@ public class GlfwJoystickInput implements JoyInput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user