Try matching gamepad mappings with CRC first

Fixes https://github.com/libsdl-org/SDL/issues/13874
This commit is contained in:
Sam Lantinga
2025-10-14 09:48:03 -07:00
parent 98944ecd0c
commit d819106c65
2 changed files with 112 additions and 18 deletions

View File

@@ -1372,7 +1372,8 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMappingForGUID(SDL_GUID guid, bool
{
GamepadMapping_t *mapping;
mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, true, adding_mapping);
// Try first with an exact match on version and CRC
mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, true, true);
if (mapping) {
return mapping;
}
@@ -1382,10 +1383,19 @@ static GamepadMapping_t *SDL_PrivateGetGamepadMappingForGUID(SDL_GUID guid, bool
return NULL;
}
// Try harder to get the best match, or create a mapping
// Try without CRC match
mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, true, false);
if (mapping) {
return mapping;
}
// Try without version match
if (SDL_JoystickGUIDUsesVersion(guid)) {
// Try again, ignoring the version
mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, false, true);
if (mapping) {
return mapping;
}
mapping = SDL_PrivateMatchGamepadMappingForGUID(guid, false, false);
if (mapping) {
return mapping;