mirror of
https://github.com/glfw/glfw.git
synced 2026-09-18 22:55:46 +00:00
Renamed global struct and substructs.
Renamed _glfwLibrary to _glfw and made all substructs lower-case, making global variable names easier to read and type. Partially inspired by the internal naming conventions of glwt.
This commit is contained in:
+36
-38
@@ -60,7 +60,7 @@ static int openJoystickDevice(int joy, const char* path)
|
||||
if (fd == -1)
|
||||
return GL_FALSE;
|
||||
|
||||
_glfwLibrary.X11.joystick[joy].fd = fd;
|
||||
_glfw.x11.joystick[joy].fd = fd;
|
||||
|
||||
// Verify that the joystick driver version is at least 1.0
|
||||
ioctl(fd, JSIOCGVERSION, &version);
|
||||
@@ -74,17 +74,16 @@ static int openJoystickDevice(int joy, const char* path)
|
||||
if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0)
|
||||
strncpy(name, "Unknown", sizeof(name));
|
||||
|
||||
_glfwLibrary.X11.joystick[joy].name = strdup(name);
|
||||
_glfw.x11.joystick[joy].name = strdup(name);
|
||||
|
||||
ioctl(fd, JSIOCGAXES, &numAxes);
|
||||
_glfwLibrary.X11.joystick[joy].numAxes = (int) numAxes;
|
||||
_glfw.x11.joystick[joy].numAxes = (int) numAxes;
|
||||
|
||||
ioctl(fd, JSIOCGBUTTONS, &numButtons);
|
||||
_glfwLibrary.X11.joystick[joy].numButtons = (int) numButtons;
|
||||
_glfw.x11.joystick[joy].numButtons = (int) numButtons;
|
||||
|
||||
_glfwLibrary.X11.joystick[joy].axis =
|
||||
(float*) malloc(sizeof(float) * numAxes);
|
||||
if (_glfwLibrary.X11.joystick[joy].axis == NULL)
|
||||
_glfw.x11.joystick[joy].axis = (float*) malloc(sizeof(float) * numAxes);
|
||||
if (_glfw.x11.joystick[joy].axis == NULL)
|
||||
{
|
||||
close(fd);
|
||||
|
||||
@@ -92,18 +91,17 @@ static int openJoystickDevice(int joy, const char* path)
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
_glfwLibrary.X11.joystick[joy].button =
|
||||
(unsigned char*) malloc(sizeof(char) * numButtons);
|
||||
if (_glfwLibrary.X11.joystick[joy].button == NULL)
|
||||
_glfw.x11.joystick[joy].button = (unsigned char*) malloc(numButtons);
|
||||
if (_glfw.x11.joystick[joy].button == NULL)
|
||||
{
|
||||
free(_glfwLibrary.X11.joystick[joy].axis);
|
||||
free(_glfw.x11.joystick[joy].axis);
|
||||
close(fd);
|
||||
|
||||
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
_glfwLibrary.X11.joystick[joy].present = GL_TRUE;
|
||||
_glfw.x11.joystick[joy].present = GL_TRUE;
|
||||
#endif // __linux__
|
||||
|
||||
return GL_TRUE;
|
||||
@@ -123,17 +121,17 @@ static void pollJoystickEvents(void)
|
||||
|
||||
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
|
||||
{
|
||||
if (!_glfwLibrary.X11.joystick[i].present)
|
||||
if (!_glfw.x11.joystick[i].present)
|
||||
continue;
|
||||
|
||||
// Read all queued events (non-blocking)
|
||||
for (;;)
|
||||
{
|
||||
errno = 0;
|
||||
result = read(_glfwLibrary.X11.joystick[i].fd, &e, sizeof(e));
|
||||
result = read(_glfw.x11.joystick[i].fd, &e, sizeof(e));
|
||||
|
||||
if (errno == ENODEV)
|
||||
_glfwLibrary.X11.joystick[i].present = GL_FALSE;
|
||||
_glfw.x11.joystick[i].present = GL_FALSE;
|
||||
|
||||
if (result == -1)
|
||||
break;
|
||||
@@ -144,21 +142,21 @@ static void pollJoystickEvents(void)
|
||||
switch (e.type)
|
||||
{
|
||||
case JS_EVENT_AXIS:
|
||||
_glfwLibrary.X11.joystick[i].axis[e.number] =
|
||||
_glfw.x11.joystick[i].axis[e.number] =
|
||||
(float) e.value / 32767.0f;
|
||||
|
||||
// We need to change the sign for the Y axes, so that
|
||||
// positive = up/forward, according to the GLFW spec.
|
||||
if (e.number & 1)
|
||||
{
|
||||
_glfwLibrary.X11.joystick[i].axis[e.number] =
|
||||
-_glfwLibrary.X11.joystick[i].axis[e.number];
|
||||
_glfw.x11.joystick[i].axis[e.number] =
|
||||
-_glfw.x11.joystick[i].axis[e.number];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case JS_EVENT_BUTTON:
|
||||
_glfwLibrary.X11.joystick[i].button[e.number] =
|
||||
_glfw.x11.joystick[i].button[e.number] =
|
||||
e.value ? GLFW_PRESS : GLFW_RELEASE;
|
||||
break;
|
||||
|
||||
@@ -239,14 +237,14 @@ void _glfwTerminateJoysticks(void)
|
||||
|
||||
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
|
||||
{
|
||||
if (_glfwLibrary.X11.joystick[i].present)
|
||||
if (_glfw.x11.joystick[i].present)
|
||||
{
|
||||
close(_glfwLibrary.X11.joystick[i].fd);
|
||||
free(_glfwLibrary.X11.joystick[i].axis);
|
||||
free(_glfwLibrary.X11.joystick[i].button);
|
||||
free(_glfwLibrary.X11.joystick[i].name);
|
||||
close(_glfw.x11.joystick[i].fd);
|
||||
free(_glfw.x11.joystick[i].axis);
|
||||
free(_glfw.x11.joystick[i].button);
|
||||
free(_glfw.x11.joystick[i].name);
|
||||
|
||||
_glfwLibrary.X11.joystick[i].present = GL_FALSE;
|
||||
_glfw.x11.joystick[i].present = GL_FALSE;
|
||||
}
|
||||
}
|
||||
#endif // __linux__
|
||||
@@ -265,7 +263,7 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
|
||||
{
|
||||
pollJoystickEvents();
|
||||
|
||||
if (!_glfwLibrary.X11.joystick[joy].present)
|
||||
if (!_glfw.x11.joystick[joy].present)
|
||||
return 0;
|
||||
|
||||
switch (param)
|
||||
@@ -274,10 +272,10 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
|
||||
return GL_TRUE;
|
||||
|
||||
case GLFW_AXES:
|
||||
return _glfwLibrary.X11.joystick[joy].numAxes;
|
||||
return _glfw.x11.joystick[joy].numAxes;
|
||||
|
||||
case GLFW_BUTTONS:
|
||||
return _glfwLibrary.X11.joystick[joy].numButtons;
|
||||
return _glfw.x11.joystick[joy].numButtons;
|
||||
|
||||
default:
|
||||
_glfwInputError(GLFW_INVALID_ENUM, NULL);
|
||||
@@ -297,14 +295,14 @@ int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numAxes)
|
||||
|
||||
pollJoystickEvents();
|
||||
|
||||
if (!_glfwLibrary.X11.joystick[joy].present)
|
||||
if (!_glfw.x11.joystick[joy].present)
|
||||
return 0;
|
||||
|
||||
if (_glfwLibrary.X11.joystick[joy].numAxes < numAxes)
|
||||
numAxes = _glfwLibrary.X11.joystick[joy].numAxes;
|
||||
if (_glfw.x11.joystick[joy].numAxes < numAxes)
|
||||
numAxes = _glfw.x11.joystick[joy].numAxes;
|
||||
|
||||
for (i = 0; i < numAxes; i++)
|
||||
axes[i] = _glfwLibrary.X11.joystick[joy].axis[i];
|
||||
axes[i] = _glfw.x11.joystick[joy].axis[i];
|
||||
|
||||
return numAxes;
|
||||
}
|
||||
@@ -321,14 +319,14 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
|
||||
|
||||
pollJoystickEvents();
|
||||
|
||||
if (!_glfwLibrary.X11.joystick[joy].present)
|
||||
if (!_glfw.x11.joystick[joy].present)
|
||||
return 0;
|
||||
|
||||
if (_glfwLibrary.X11.joystick[joy].numButtons < numButtons)
|
||||
numButtons = _glfwLibrary.X11.joystick[joy].numButtons;
|
||||
if (_glfw.x11.joystick[joy].numButtons < numButtons)
|
||||
numButtons = _glfw.x11.joystick[joy].numButtons;
|
||||
|
||||
for (i = 0; i < numButtons; i++)
|
||||
buttons[i] = _glfwLibrary.X11.joystick[joy].button[i];
|
||||
buttons[i] = _glfw.x11.joystick[joy].button[i];
|
||||
|
||||
return numButtons;
|
||||
}
|
||||
@@ -340,9 +338,9 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
|
||||
|
||||
const char* _glfwPlatformGetJoystickName(int joy)
|
||||
{
|
||||
if (!_glfwLibrary.X11.joystick[joy].present)
|
||||
if (!_glfw.x11.joystick[joy].present)
|
||||
return NULL;
|
||||
|
||||
return _glfwLibrary.X11.joystick[joy].name;
|
||||
return _glfw.x11.joystick[joy].name;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user