Forráskód Böngészése

Remove redundant OS X joystick polling

Closes #729.
IntellectualKitty 9 éve
szülő
commit
ae4ece840d
1 módosított fájl, 32 hozzáadás és 20 törlés
  1. 32 20
      src/cocoa_joystick.m

+ 32 - 20
src/cocoa_joystick.m

@@ -192,27 +192,15 @@ static void removeJoystick(_GLFWjoydeviceNS* joystick)
     memset(joystick, 0, sizeof(_GLFWjoydeviceNS));
     memset(joystick, 0, sizeof(_GLFWjoydeviceNS));
 }
 }
 
 
-// Polls for joystick events and updates GLFW state
+// Polls for joystick axis events and updates GLFW state
 //
 //
-static GLFWbool pollJoystickEvents(_GLFWjoydeviceNS* joystick)
+static GLFWbool pollJoystickAxisEvents(_GLFWjoydeviceNS* joystick)
 {
 {
     CFIndex i;
     CFIndex i;
-    int buttonIndex = 0;
 
 
     if (!joystick->present)
     if (!joystick->present)
         return GLFW_FALSE;
         return GLFW_FALSE;
 
 
-    for (i = 0;  i < CFArrayGetCount(joystick->buttonElements);  i++)
-    {
-        _GLFWjoyelementNS* button = (_GLFWjoyelementNS*)
-            CFArrayGetValueAtIndex(joystick->buttonElements, i);
-
-        if (getElementValue(joystick, button))
-            joystick->buttons[buttonIndex++] = GLFW_PRESS;
-        else
-            joystick->buttons[buttonIndex++] = GLFW_RELEASE;
-    }
-
     for (i = 0;  i < CFArrayGetCount(joystick->axisElements);  i++)
     for (i = 0;  i < CFArrayGetCount(joystick->axisElements);  i++)
     {
     {
         _GLFWjoyelementNS* axis = (_GLFWjoyelementNS*)
         _GLFWjoyelementNS* axis = (_GLFWjoyelementNS*)
@@ -227,6 +215,30 @@ static GLFWbool pollJoystickEvents(_GLFWjoydeviceNS* joystick)
             joystick->axes[i] = (2.f * (value - axis->minReport) / readScale) - 1.f;
             joystick->axes[i] = (2.f * (value - axis->minReport) / readScale) - 1.f;
     }
     }
 
 
+    return GLFW_TRUE;
+}
+
+// Polls for joystick button events and updates GLFW state
+//
+static GLFWbool pollJoystickButtonEvents(_GLFWjoydeviceNS* joystick)
+{
+    CFIndex i;
+    int buttonIndex = 0;
+
+    if (!joystick->present)
+        return GLFW_FALSE;
+
+    for (i = 0;  i < CFArrayGetCount(joystick->buttonElements);  i++)
+    {
+        _GLFWjoyelementNS* button = (_GLFWjoyelementNS*)
+            CFArrayGetValueAtIndex(joystick->buttonElements, i);
+
+        if (getElementValue(joystick, button))
+            joystick->buttons[buttonIndex++] = GLFW_PRESS;
+        else
+            joystick->buttons[buttonIndex++] = GLFW_RELEASE;
+    }
+
     for (i = 0;  i < CFArrayGetCount(joystick->hatElements);  i++)
     for (i = 0;  i < CFArrayGetCount(joystick->hatElements);  i++)
     {
     {
         _GLFWjoyelementNS* hat = (_GLFWjoyelementNS*)
         _GLFWjoyelementNS* hat = (_GLFWjoyelementNS*)
@@ -469,13 +481,13 @@ void _glfwTerminateJoysticksNS(void)
 int _glfwPlatformJoystickPresent(int joy)
 int _glfwPlatformJoystickPresent(int joy)
 {
 {
     _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
     _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
-    return pollJoystickEvents(joystick);
+    return joystick->present ? GLFW_TRUE : GLFW_FALSE;
 }
 }
 
 
 const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
 const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
 {
 {
     _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
     _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
-    if (!pollJoystickEvents(joystick))
+    if (!pollJoystickAxisEvents(joystick))
         return NULL;
         return NULL;
 
 
     *count = (int) CFArrayGetCount(joystick->axisElements);
     *count = (int) CFArrayGetCount(joystick->axisElements);
@@ -485,7 +497,7 @@ const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
 const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
 const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
 {
 {
     _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
     _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
-    if (!pollJoystickEvents(joystick))
+    if (!pollJoystickButtonEvents(joystick))
         return NULL;
         return NULL;
 
 
     *count = (int) CFArrayGetCount(joystick->buttonElements) +
     *count = (int) CFArrayGetCount(joystick->buttonElements) +
@@ -496,9 +508,9 @@ const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
 const char* _glfwPlatformGetJoystickName(int joy)
 const char* _glfwPlatformGetJoystickName(int joy)
 {
 {
     _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
     _GLFWjoydeviceNS* joystick = _glfw.ns_js.devices + joy;
-    if (!pollJoystickEvents(joystick))
+    if (joystick->present)
+        return joystick->name;
+    else
         return NULL;
         return NULL;
-
-    return joystick->name;
 }
 }