Select mapping platform name at runtime

This is done in preparation for runtime platform selection.
This commit is contained in:
Camilla Löwy 2021-07-15 22:12:21 +02:00
parent d0776e04a3
commit 6d51b39106
10 changed files with 24 additions and 7 deletions

View File

@ -32,7 +32,6 @@
#define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickNS ns #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickNS ns
#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyJoystick; } #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyJoystick; }
#define _GLFW_PLATFORM_MAPPING_NAME "Mac OS X"
#define GLFW_BUILD_COCOA_MAPPINGS #define GLFW_BUILD_COCOA_MAPPINGS
// Cocoa-specific per-joystick data // Cocoa-specific per-joystick data

View File

@ -469,6 +469,11 @@ int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode)
return js->present; return js->present;
} }
const char* _glfwPlatformGetMappingName(void)
{
return "Mac OS X";
}
void _glfwPlatformUpdateGamepadGUID(char* guid) void _glfwPlatformUpdateGamepadGUID(char* guid)
{ {
if ((strncmp(guid + 4, "000000000000", 12) == 0) && if ((strncmp(guid + 4, "000000000000", 12) == 0) &&

View File

@ -234,8 +234,9 @@ static GLFWbool parseMapping(_GLFWmapping* mapping, const char* string)
} }
else else
{ {
length = strlen(_GLFW_PLATFORM_MAPPING_NAME); const char* name = _glfwPlatformGetMappingName();
if (strncmp(c, _GLFW_PLATFORM_MAPPING_NAME, length) != 0) length = strlen(name);
if (strncmp(c, name, length) != 0)
return GLFW_FALSE; return GLFW_FALSE;
} }

View File

@ -642,6 +642,7 @@ GLFWbool _glfwPlatformInitJoysticks(void);
void _glfwPlatformTerminateJoysticks(void); void _glfwPlatformTerminateJoysticks(void);
int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode); int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode);
void _glfwPlatformUpdateGamepadGUID(char* guid); void _glfwPlatformUpdateGamepadGUID(char* guid);
const char* _glfwPlatformGetMappingName(void);
uint64_t _glfwPlatformGetTimerValue(void); uint64_t _glfwPlatformGetTimerValue(void);
uint64_t _glfwPlatformGetTimerFrequency(void); uint64_t _glfwPlatformGetTimerFrequency(void);

View File

@ -422,6 +422,11 @@ int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode)
return js->present; return js->present;
} }
const char* _glfwPlatformGetMappingName(void)
{
return "Linux";
}
void _glfwPlatformUpdateGamepadGUID(char* guid) void _glfwPlatformUpdateGamepadGUID(char* guid)
{ {
} }

View File

@ -31,7 +31,6 @@
#define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickLinux linjs #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickLinux linjs
#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs
#define _GLFW_PLATFORM_MAPPING_NAME "Linux"
#define GLFW_BUILD_LINUX_MAPPINGS #define GLFW_BUILD_LINUX_MAPPINGS
// Linux-specific joystick data // Linux-specific joystick data

View File

@ -47,6 +47,11 @@ int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode)
return GLFW_FALSE; return GLFW_FALSE;
} }
const char* _glfwPlatformGetMappingName(void)
{
return "";
}
void _glfwPlatformUpdateGamepadGUID(char* guid) void _glfwPlatformUpdateGamepadGUID(char* guid)
{ {
} }

View File

@ -27,5 +27,3 @@
#define _GLFW_PLATFORM_JOYSTICK_STATE struct { int dummyJoystick; } #define _GLFW_PLATFORM_JOYSTICK_STATE struct { int dummyJoystick; }
#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyLibraryJoystick; } #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyLibraryJoystick; }
#define _GLFW_PLATFORM_MAPPING_NAME ""

View File

@ -740,6 +740,11 @@ int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode)
return GLFW_TRUE; return GLFW_TRUE;
} }
const char* _glfwPlatformGetMappingName(void)
{
return "Windows";
}
void _glfwPlatformUpdateGamepadGUID(char* guid) void _glfwPlatformUpdateGamepadGUID(char* guid)
{ {
if (strcmp(guid + 20, "504944564944") == 0) if (strcmp(guid + 20, "504944564944") == 0)

View File

@ -27,7 +27,6 @@
#define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickWin32 win32 #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickWin32 win32
#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyLibraryJoystick; } #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyLibraryJoystick; }
#define _GLFW_PLATFORM_MAPPING_NAME "Windows"
#define GLFW_BUILD_WIN32_MAPPINGS #define GLFW_BUILD_WIN32_MAPPINGS
// Joystick element (axis, button or slider) // Joystick element (axis, button or slider)