Skip to content

Commit

Permalink
Added support for SDL hints in the game controller mapping database
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Mar 13, 2020
1 parent 93ed3c8 commit db3b3a1
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 50 deletions.
42 changes: 42 additions & 0 deletions src/joystick/SDL_gamecontroller.c
Expand Up @@ -43,6 +43,7 @@
#define SDL_MINIMUM_GUIDE_BUTTON_DELAY_MS 250

#define SDL_CONTROLLER_PLATFORM_FIELD "platform:"
#define SDL_CONTROLLER_HINT_FIELD "hint:"
#define SDL_CONTROLLER_SDKGE_FIELD "sdk>=:"
#define SDL_CONTROLLER_SDKLE_FIELD "sdk<=:"

Expand Down Expand Up @@ -1164,6 +1165,47 @@ SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMap
return SDL_InvalidParamError("mappingString");
}

{ /* Extract and verify the hint field */
const char *tmp;

tmp = SDL_strstr(mappingString, SDL_CONTROLLER_HINT_FIELD);
if (tmp != NULL) {
SDL_bool default_value, value, negate;
int len;
char hint[128];

tmp += SDL_strlen(SDL_CONTROLLER_HINT_FIELD);

if (*tmp == '!') {
negate = SDL_TRUE;
++tmp;
} else {
negate = SDL_FALSE;
}

len = 0;
while (*tmp && *tmp != ',' && *tmp != ':' && len < (sizeof(hint) - 1)) {
hint[len++] = *tmp++;
}
hint[len] = '\0';

if (tmp[0] == ':' && tmp[1] == '=') {
tmp += 2;
default_value = SDL_atoi(tmp);
} else {
default_value = SDL_FALSE;
}

value = SDL_GetHintBoolean(hint, default_value);
if (negate) {
value = !value;
}
if (!value) {
return 0;
}
}
}

#ifdef ANDROID
{ /* Extract and verify the SDK version */
const char *tmp;
Expand Down

0 comments on commit db3b3a1

Please sign in to comment.