浏览代码

Remove JoystickState enum and replace with boolean value.

James Khan 6 年之前
父节点
当前提交
2f6185b5cf

+ 3 - 3
jme3-core/src/main/java/com/jme3/input/InputManager.java

@@ -995,11 +995,11 @@ public class InputManager implements RawInputListener {
      * Called when a joystick has been added or removed.
      * This should only be called internally.
      * @param joystickId the ID of the joystick.
-     * @param state      the state that occured (connected / disconnected).
+     * @param connected  the connection state of the joystick.
      */
-    public void fireJoystickConnectionEvent(int joystickId, JoystickState state) {
+    public void fireJoystickConnectionEvent(int joystickId, boolean connected) {
         for (JoystickConnectionListener listener : joystickConnectionListeners) {
-            listener.connectionChanged(joystickId, state);
+            listener.connectionChanged(joystickId, connected);
         }
     }
 

+ 1 - 1
jme3-core/src/main/java/com/jme3/input/JoystickConnectionListener.java

@@ -2,6 +2,6 @@ package com.jme3.input;
 
 public interface JoystickConnectionListener {
 
-    void connectionChanged(int joystickId, JoystickState action);
+    void connectionChanged(int joystickId, boolean connected);
 
 }

+ 0 - 12
jme3-core/src/main/java/com/jme3/input/JoystickState.java

@@ -1,12 +0,0 @@
-package com.jme3.input;
-
-/**
- * Response for joystick callback events.
- * @author jayfella
- */
-public enum JoystickState {
-
-    Connected,
-    Disconnected,
-
-}

+ 2 - 2
jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java

@@ -68,8 +68,8 @@ public class GlfwJoystickInput implements JoyInput {
         }
     }
 
-    public void fireJoystickConnectionEvent(int jid, JoystickState state) {
-        ((InputManager)listener).fireJoystickConnectionEvent(jid, state);
+    public void fireJoystickConnectionEvent(int jid, boolean connected) {
+        ((InputManager)listener).fireJoystickConnectionEvent(jid, connected);
     }
 
     public void reloadJoysticks() {

+ 3 - 7
jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java

@@ -38,7 +38,6 @@ import static org.lwjgl.opencl.CL10.CL_CONTEXT_PLATFORM;
 import static org.lwjgl.opengl.GL.createCapabilities;
 import static org.lwjgl.opengl.GL11.glGetInteger;
 
-import com.jme3.input.JoystickState;
 import com.jme3.input.lwjgl.GlfwJoystickInput;
 import com.jme3.input.lwjgl.GlfwKeyInput;
 import com.jme3.input.lwjgl.GlfwMouseInput;
@@ -239,13 +238,10 @@ public abstract class LwjglContext implements JmeContext {
         GLFW.glfwSetJoystickCallback(new GLFWJoystickCallback() {
             @Override
             public void invoke(int jid, int event) {
-                joyInput.reloadJoysticks();
-
-                JoystickState state = event == GLFW.GLFW_CONNECTED
-                        ? JoystickState.Connected
-                        : JoystickState.Disconnected;
 
-                joyInput.fireJoystickConnectionEvent(jid, state);
+                // fire the event after joysticks were reloaded.
+                joyInput.reloadJoysticks();
+                joyInput.fireJoystickConnectionEvent(jid, event == GLFW.GLFW_CONNECTED);
             }
         });