From 467af4fff506d9044acb8c8e7ff8f47c95f4314e Mon Sep 17 00:00:00 2001 From: Francivan Bezerra Date: Fri, 28 Dec 2018 00:11:28 -0200 Subject: [PATCH] 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). --- .../com/jme3/input/lwjgl/GlfwJoystickInput.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java index d8d61805c..87bd18ede 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java @@ -52,8 +52,11 @@ public class GlfwJoystickInput implements JoyInput { private static final Logger LOGGER = Logger.getLogger(InputManager.class.getName()); private RawInputListener listener; + private final Map joysticks = new HashMap<>(); + private final Map joyButtonPressed = new HashMap<>(); + private boolean initialized = false; @Override @@ -88,8 +91,11 @@ public class GlfwJoystickInput implements JoyInput { int buttonIndex = 0; while (byteBuffer.hasRemaining()) { byteBuffer.get(); + 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++; } } @@ -133,7 +139,11 @@ public class GlfwJoystickInput implements JoyInput { for (final JoystickButton button : entry.getValue().getButtons()) { final boolean pressed = byteBuffer.get(button.getButtonId()) == GLFW_PRESS; - listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed)); + + if (joyButtonPressed.get(button) != pressed) { + joyButtonPressed.put(button, pressed); + listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed)); + } } } } @@ -213,6 +223,3 @@ public class GlfwJoystickInput implements JoyInput { } } } - - -