Fixed updating bindings for controllers using the wildcard mappings
authorSam Lantinga <slouken@libsdl.org>
Thu, 04 Oct 2018 15:23:42 -0700
changeset 12291287350656743
parent 12285 30c3ffcbed38
child 12292 f4dde3c6bae9
Fixed updating bindings for controllers using the wildcard mappings
src/joystick/SDL_gamecontroller.c
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Wed Oct 03 15:48:26 2018 -0700
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Thu Oct 04 15:23:42 2018 -0700
     1.3 @@ -111,7 +111,6 @@
     1.4      SDL_Joystick *joystick; /* underlying joystick device */
     1.5      int ref_count;
     1.6  
     1.7 -    SDL_JoystickGUID guid;
     1.8      const char *name;
     1.9      int num_bindings;
    1.10      SDL_ExtendedGameControllerBind *bindings;
    1.11 @@ -683,11 +682,10 @@
    1.12  /*
    1.13   * Make a new button mapping struct
    1.14   */
    1.15 -static void SDL_PrivateLoadButtonMapping(SDL_GameController *gamecontroller, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping)
    1.16 +static void SDL_PrivateLoadButtonMapping(SDL_GameController *gamecontroller, const char *pchName, const char *pchMapping)
    1.17  {
    1.18      int i;
    1.19  
    1.20 -    gamecontroller->guid = guid;
    1.21      gamecontroller->name = pchName;
    1.22      gamecontroller->num_bindings = 0;
    1.23      SDL_memset(gamecontroller->last_match_axis, 0, gamecontroller->joystick->naxes * sizeof(*gamecontroller->last_match_axis));
    1.24 @@ -801,14 +799,16 @@
    1.25  {
    1.26      SDL_GameController *gamecontrollerlist = SDL_gamecontrollers;
    1.27      while (gamecontrollerlist) {
    1.28 -        if (!SDL_memcmp(&gamecontrollerlist->guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid))) {
    1.29 -            SDL_Event event;
    1.30 -            event.type = SDL_CONTROLLERDEVICEREMAPPED;
    1.31 -            event.cdevice.which = gamecontrollerlist->joystick->instance_id;
    1.32 -            SDL_PushEvent(&event);
    1.33 +        if (!SDL_memcmp(&gamecontrollerlist->joystick->guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid))) {
    1.34 +            /* Not really threadsafe.  Should this lock access within SDL_GameControllerEventWatcher? */
    1.35 +            SDL_PrivateLoadButtonMapping(gamecontrollerlist, pControllerMapping->name, pControllerMapping->mapping);
    1.36  
    1.37 -            /* Not really threadsafe.  Should this lock access within SDL_GameControllerEventWatcher? */
    1.38 -            SDL_PrivateLoadButtonMapping(gamecontrollerlist, pControllerMapping->guid, pControllerMapping->name, pControllerMapping->mapping);
    1.39 +            {
    1.40 +                SDL_Event event;
    1.41 +                event.type = SDL_CONTROLLERDEVICEREMAPPED;
    1.42 +                event.cdevice.which = gamecontrollerlist->joystick->instance_id;
    1.43 +                SDL_PushEvent(&event);
    1.44 +            }
    1.45          }
    1.46  
    1.47          gamecontrollerlist = gamecontrollerlist->next;
    1.48 @@ -1273,7 +1273,7 @@
    1.49          return NULL;
    1.50      }
    1.51  
    1.52 -    return SDL_GameControllerMappingForGUID(gamecontroller->guid);
    1.53 +    return SDL_GameControllerMappingForGUID(gamecontroller->joystick->guid);
    1.54  }
    1.55  
    1.56  static void
    1.57 @@ -1582,7 +1582,7 @@
    1.58          }
    1.59      }
    1.60  
    1.61 -    SDL_PrivateLoadButtonMapping(gamecontroller, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping);
    1.62 +    SDL_PrivateLoadButtonMapping(gamecontroller, pSupportedController->name, pSupportedController->mapping);
    1.63  
    1.64      /* Add the controller to list */
    1.65      ++gamecontroller->ref_count;