diff --git a/src/init.c b/src/init.c index e44d0ca2..aebbece4 100644 --- a/src/init.c +++ b/src/init.c @@ -28,7 +28,6 @@ //======================================================================== #include "internal.h" -#include "mappings.h" #include #include @@ -245,24 +244,12 @@ GLFWAPI int glfwInit(void) _glfwPlatformSetTls(&_glfw.errorSlot, &_glfwMainThreadError); + _glfwInitGamepadMappings(); + _glfw.initialized = GLFW_TRUE; _glfw.timer.offset = _glfwPlatformGetTimerValue(); glfwDefaultWindowHints(); - - { - int i; - - for (i = 0; _glfwDefaultMappings[i]; i++) - { - if (!glfwUpdateGamepadMappings(_glfwDefaultMappings[i])) - { - terminate(); - return GLFW_FALSE; - } - } - } - return GLFW_TRUE; } diff --git a/src/input.c b/src/input.c index 20b7c412..67919334 100644 --- a/src/input.c +++ b/src/input.c @@ -28,6 +28,7 @@ //======================================================================== #include "internal.h" +#include "mappings.h" #include #include @@ -396,6 +397,21 @@ void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value) ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// +// Adds the built-in set of gamepad mappings +// +void _glfwInitGamepadMappings(void) +{ + size_t i; + const size_t count = sizeof(_glfwDefaultMappings) / sizeof(char*); + _glfw.mappings = calloc(count, sizeof(_GLFWmapping)); + + for (i = 0; i < count; i++) + { + if (parseMapping(&_glfw.mappings[_glfw.mappingCount], _glfwDefaultMappings[i])) + _glfw.mappingCount++; + } +} + // Returns an available joystick object with arrays and name allocated // _GLFWjoystick* _glfwAllocJoystick(const char* name, diff --git a/src/internal.h b/src/internal.h index b28e9424..ad619b4e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -761,6 +761,7 @@ void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size); void _glfwFreeGammaArrays(GLFWgammaramp* ramp); void _glfwSplitBPP(int bpp, int* red, int* green, int* blue); +void _glfwInitGamepadMappings(void); _GLFWjoystick* _glfwAllocJoystick(const char* name, const char* guid, int axisCount, diff --git a/src/mappings.h b/src/mappings.h index 083a500f..11853a0a 100644 --- a/src/mappings.h +++ b/src/mappings.h @@ -997,7 +997,5 @@ const char* _glfwDefaultMappings[] = "03000000120c0000100e000011010000,ZEROPLUS P4 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,", "03000000120c0000101e000011010000,ZEROPLUS P4 Wired Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Linux,", #endif // GLFW_BUILD_LINUX_MAPPINGS - -NULL }; diff --git a/src/mappings.h.in b/src/mappings.h.in index 58fc44d8..26b544bd 100644 --- a/src/mappings.h.in +++ b/src/mappings.h.in @@ -78,7 +78,5 @@ const char* _glfwDefaultMappings[] = #if defined(GLFW_BUILD_LINUX_MAPPINGS) @GLFW_LINUX_MAPPINGS@ #endif // GLFW_BUILD_LINUX_MAPPINGS - -NULL };