From fa17b7e6166c75edd0fd0b563feb4051b58dc84c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 30 Jan 2012 00:02:54 +0100 Subject: [PATCH] Compatibility fixes. --- src/cocoa_joystick.m | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index 5e3a6bf8..0aa10a4a 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -232,11 +232,13 @@ static long getElementValue(_glfwJoystick* joystick, _glfwJoystickElement* eleme static void removeJoystick(_glfwJoystick* joystick) { + int i; + if (joystick->present) { joystick->present = GL_FALSE; - for (int i = 0; i < joystick->numAxes; i++) + for (i = 0; i < joystick->numAxes; i++) { _glfwJoystickElement* axes = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, i); @@ -245,7 +247,7 @@ static void removeJoystick(_glfwJoystick* joystick) CFArrayRemoveAllValues(joystick->axes); joystick->numAxes = 0; - for (int i = 0; i < joystick->numButtons; i++) + for (i = 0; i < joystick->numButtons; i++) { _glfwJoystickElement* button = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, i); @@ -254,7 +256,7 @@ static void removeJoystick(_glfwJoystick* joystick) CFArrayRemoveAllValues(joystick->buttons); joystick->numButtons = 0; - for (int i = 0; i < joystick->numHats; i++) + for (i = 0; i < joystick->numHats; i++) { _glfwJoystickElement* hat = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->hats, i); @@ -287,23 +289,26 @@ static void removalCallback(void* target, IOReturn result, void* refcon, void* s static void pollJoystickEvents(void) { - for (int i = 0; i < GLFW_JOYSTICK_LAST + 1; i++) + int i; + CFIndex j; + + for (i = 0; i < GLFW_JOYSTICK_LAST + 1; i++) { _glfwJoystick* joystick = &_glfwJoysticks[i]; if (joystick->present) { - for (CFIndex i = 0; i < joystick->numButtons; i++) + for (j = 0; j < joystick->numButtons; j++) { _glfwJoystickElement* button = - (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, i); + (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, j); button->value = getElementValue(joystick, button); } - for (CFIndex i = 0; i < joystick->numAxes; i++) + for (j = 0; j < joystick->numAxes; j++) { _glfwJoystickElement* axes = - (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, i); + (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, j); axes->value = getElementValue(joystick, axes); } } @@ -449,7 +454,9 @@ void _glfwInitJoysticks(void) void _glfwTerminateJoysticks(void) { - for (int i = 0; i < GLFW_JOYSTICK_LAST + 1; i++) + int i; + + for (i = 0; i < GLFW_JOYSTICK_LAST + 1; i++) { _glfwJoystick* joystick = &_glfwJoysticks[i]; removeJoystick(joystick); @@ -498,6 +505,8 @@ int _glfwPlatformGetJoystickParam(int joy, int param) int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes) { + int i; + if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_LAST) return 0; @@ -514,7 +523,7 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes) // Update joystick state pollJoystickEvents(); - for (int i = 0; i < numaxes; i++) + for (i = 0; i < numaxes; i++) { _glfwJoystickElement* axes = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.axes, i); @@ -543,6 +552,8 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes) int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons) { + int i; + if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_LAST) return 0; @@ -559,7 +570,7 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, // Update joystick state pollJoystickEvents(); - for (int i = 0; i < numbuttons; i++) + for (i = 0; i < numbuttons; i++) { _glfwJoystickElement* button = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.buttons, i); buttons[i] = button->value ? GLFW_PRESS : GLFW_RELEASE;