Renamed joystick state members.

This commit is contained in:
Camilla Berglund 2014-04-08 16:42:14 +02:00
parent eaf3bd5ca4
commit 48619a385e
6 changed files with 45 additions and 45 deletions

View File

@ -33,7 +33,7 @@
#include <IOKit/hid/IOHIDKeys.h> #include <IOKit/hid/IOHIDKeys.h>
#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \
_GLFWjoystickIOKit joystick[GLFW_JOYSTICK_LAST + 1] _GLFWjoystickIOKit iokit_js[GLFW_JOYSTICK_LAST + 1]
//======================================================================== //========================================================================

View File

@ -223,7 +223,7 @@ static void pollJoystickEvents(void)
{ {
CFIndex i; CFIndex i;
int buttonIndex = 0; int buttonIndex = 0;
_GLFWjoystickIOKit* joystick = _glfw.joystick + joy; _GLFWjoystickIOKit* joystick = _glfw.iokit_js + joy;
if (!joystick->present) if (!joystick->present)
continue; continue;
@ -368,7 +368,7 @@ void _glfwInitJoysticks(void)
CFRelease(valueRef); CFRelease(valueRef);
} }
_GLFWjoystickIOKit* joystick = _glfw.joystick + joy; _GLFWjoystickIOKit* joystick = _glfw.iokit_js + joy;
joystick->present = GL_TRUE; joystick->present = GL_TRUE;
result = IOCreatePlugInInterfaceForService(ioHIDDeviceObject, result = IOCreatePlugInInterfaceForService(ioHIDDeviceObject,
@ -450,7 +450,7 @@ void _glfwTerminateJoysticks(void)
for (i = 0; i < GLFW_JOYSTICK_LAST + 1; i++) for (i = 0; i < GLFW_JOYSTICK_LAST + 1; i++)
{ {
_GLFWjoystickIOKit* joystick = &_glfw.joystick[i]; _GLFWjoystickIOKit* joystick = &_glfw.iokit_js[i];
removeJoystick(joystick); removeJoystick(joystick);
} }
} }
@ -464,12 +464,12 @@ int _glfwPlatformJoystickPresent(int joy)
{ {
pollJoystickEvents(); pollJoystickEvents();
return _glfw.joystick[joy].present; return _glfw.iokit_js[joy].present;
} }
const float* _glfwPlatformGetJoystickAxes(int joy, int* count) const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
{ {
_GLFWjoystickIOKit* joystick = _glfw.joystick + joy; _GLFWjoystickIOKit* joystick = _glfw.iokit_js + joy;
pollJoystickEvents(); pollJoystickEvents();
@ -482,7 +482,7 @@ const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count) const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
{ {
_GLFWjoystickIOKit* joystick = _glfw.joystick + joy; _GLFWjoystickIOKit* joystick = _glfw.iokit_js + joy;
pollJoystickEvents(); pollJoystickEvents();
@ -498,6 +498,6 @@ const char* _glfwPlatformGetJoystickName(int joy)
{ {
pollJoystickEvents(); pollJoystickEvents();
return _glfw.joystick[joy].name; return _glfw.iokit_js[joy].name;
} }

View File

@ -56,7 +56,7 @@ static int openJoystickDevice(int joy, const char* path)
if (fd == -1) if (fd == -1)
return GL_FALSE; return GL_FALSE;
_glfw.joystick[joy].fd = fd; _glfw.linux_js[joy].fd = fd;
// Verify that the joystick driver version is at least 1.0 // Verify that the joystick driver version is at least 1.0
ioctl(fd, JSIOCGVERSION, &version); ioctl(fd, JSIOCGVERSION, &version);
@ -70,18 +70,18 @@ static int openJoystickDevice(int joy, const char* path)
if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0) if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0)
strncpy(name, "Unknown", sizeof(name)); strncpy(name, "Unknown", sizeof(name));
_glfw.joystick[joy].name = strdup(name); _glfw.linux_js[joy].name = strdup(name);
ioctl(fd, JSIOCGAXES, &axisCount); ioctl(fd, JSIOCGAXES, &axisCount);
_glfw.joystick[joy].axisCount = (int) axisCount; _glfw.linux_js[joy].axisCount = (int) axisCount;
ioctl(fd, JSIOCGBUTTONS, &buttonCount); ioctl(fd, JSIOCGBUTTONS, &buttonCount);
_glfw.joystick[joy].buttonCount = (int) buttonCount; _glfw.linux_js[joy].buttonCount = (int) buttonCount;
_glfw.joystick[joy].axes = calloc(axisCount, sizeof(float)); _glfw.linux_js[joy].axes = calloc(axisCount, sizeof(float));
_glfw.joystick[joy].buttons = calloc(buttonCount, 1); _glfw.linux_js[joy].buttons = calloc(buttonCount, 1);
_glfw.joystick[joy].present = GL_TRUE; _glfw.linux_js[joy].present = GL_TRUE;
#endif // __linux__ #endif // __linux__
return GL_TRUE; return GL_TRUE;
@ -98,21 +98,21 @@ static void pollJoystickEvents(void)
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
{ {
if (!_glfw.joystick[i].present) if (!_glfw.linux_js[i].present)
continue; continue;
// Read all queued events (non-blocking) // Read all queued events (non-blocking)
for (;;) for (;;)
{ {
errno = 0; errno = 0;
result = read(_glfw.joystick[i].fd, &e, sizeof(e)); result = read(_glfw.linux_js[i].fd, &e, sizeof(e));
if (errno == ENODEV) if (errno == ENODEV)
{ {
free(_glfw.joystick[i].axes); free(_glfw.linux_js[i].axes);
free(_glfw.joystick[i].buttons); free(_glfw.linux_js[i].buttons);
free(_glfw.joystick[i].name); free(_glfw.linux_js[i].name);
_glfw.joystick[i].present = GL_FALSE; _glfw.linux_js[i].present = GL_FALSE;
} }
if (result == -1) if (result == -1)
@ -124,12 +124,12 @@ static void pollJoystickEvents(void)
switch (e.type) switch (e.type)
{ {
case JS_EVENT_AXIS: case JS_EVENT_AXIS:
_glfw.joystick[i].axes[e.number] = _glfw.linux_js[i].axes[e.number] =
(float) e.value / 32767.0f; (float) e.value / 32767.0f;
break; break;
case JS_EVENT_BUTTON: case JS_EVENT_BUTTON:
_glfw.joystick[i].buttons[e.number] = _glfw.linux_js[i].buttons[e.number] =
e.value ? GLFW_PRESS : GLFW_RELEASE; e.value ? GLFW_PRESS : GLFW_RELEASE;
break; break;
@ -204,14 +204,14 @@ void _glfwTerminateJoysticks(void)
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
{ {
if (_glfw.joystick[i].present) if (_glfw.linux_js[i].present)
{ {
close(_glfw.joystick[i].fd); close(_glfw.linux_js[i].fd);
free(_glfw.joystick[i].axes); free(_glfw.linux_js[i].axes);
free(_glfw.joystick[i].buttons); free(_glfw.linux_js[i].buttons);
free(_glfw.joystick[i].name); free(_glfw.linux_js[i].name);
_glfw.joystick[i].present = GL_FALSE; _glfw.linux_js[i].present = GL_FALSE;
} }
} }
#endif // __linux__ #endif // __linux__
@ -226,35 +226,35 @@ int _glfwPlatformJoystickPresent(int joy)
{ {
pollJoystickEvents(); pollJoystickEvents();
return _glfw.joystick[joy].present; return _glfw.linux_js[joy].present;
} }
const float* _glfwPlatformGetJoystickAxes(int joy, int* count) const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
{ {
pollJoystickEvents(); pollJoystickEvents();
if (!_glfw.joystick[joy].present) if (!_glfw.linux_js[joy].present)
return NULL; return NULL;
*count = _glfw.joystick[joy].axisCount; *count = _glfw.linux_js[joy].axisCount;
return _glfw.joystick[joy].axes; return _glfw.linux_js[joy].axes;
} }
const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count) const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
{ {
pollJoystickEvents(); pollJoystickEvents();
if (!_glfw.joystick[joy].present) if (!_glfw.linux_js[joy].present)
return NULL; return NULL;
*count = _glfw.joystick[joy].buttonCount; *count = _glfw.linux_js[joy].buttonCount;
return _glfw.joystick[joy].buttons; return _glfw.linux_js[joy].buttons;
} }
const char* _glfwPlatformGetJoystickName(int joy) const char* _glfwPlatformGetJoystickName(int joy)
{ {
pollJoystickEvents(); pollJoystickEvents();
return _glfw.joystick[joy].name; return _glfw.linux_js[joy].name;
} }

View File

@ -28,7 +28,7 @@
#define _linux_joystick_h_ #define _linux_joystick_h_
#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \
_GLFWjoystickLinux joystick[GLFW_JOYSTICK_LAST + 1] _GLFWjoystickLinux linux_js[GLFW_JOYSTICK_LAST + 1]
//======================================================================== //========================================================================

View File

@ -63,7 +63,7 @@ void _glfwTerminateJoysticks(void)
int i; int i;
for (i = 0; i < GLFW_JOYSTICK_LAST; i++) for (i = 0; i < GLFW_JOYSTICK_LAST; i++)
free(_glfw.joystick[i].name); free(_glfw.winmm_js[i].name);
} }
@ -85,7 +85,7 @@ const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
{ {
JOYCAPS jc; JOYCAPS jc;
JOYINFOEX ji; JOYINFOEX ji;
float* axes = _glfw.joystick[joy].axes; float* axes = _glfw.winmm_js[joy].axes;
if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR)
return NULL; return NULL;
@ -118,7 +118,7 @@ const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
{ {
JOYCAPS jc; JOYCAPS jc;
JOYINFOEX ji; JOYINFOEX ji;
unsigned char* buttons = _glfw.joystick[joy].buttons; unsigned char* buttons = _glfw.winmm_js[joy].buttons;
if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR)
return NULL; return NULL;
@ -169,9 +169,9 @@ const char* _glfwPlatformGetJoystickName(int joy)
if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR) if (_glfw_joyGetDevCaps(joy, &jc, sizeof(JOYCAPS)) != JOYERR_NOERROR)
return NULL; return NULL;
free(_glfw.joystick[joy].name); free(_glfw.winmm_js[joy].name);
_glfw.joystick[joy].name = _glfwCreateUTF8FromWideString(jc.szPname); _glfw.winmm_js[joy].name = _glfwCreateUTF8FromWideString(jc.szPname);
return _glfw.joystick[joy].name; return _glfw.winmm_js[joy].name;
} }

View File

@ -28,7 +28,7 @@
#define _winmm_joystick_h_ #define _winmm_joystick_h_
#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \
_GLFWjoystickWinMM joystick[GLFW_JOYSTICK_LAST + 1] _GLFWjoystickWinMM winmm_js[GLFW_JOYSTICK_LAST + 1]
//======================================================================== //========================================================================