emscripten: Patched to compile with new joystick interfaces.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 10 Aug 2018 14:32:30 -0400
changeset 12104fc8ab202b5a8
parent 12103 89218a12363a
child 12105 997ec56425a8
emscripten: Patched to compile with new joystick interfaces.
src/joystick/SDL_joystick.c
src/joystick/SDL_sysjoystick.h
src/joystick/emscripten/SDL_sysjoystick.c
     1.1 --- a/src/joystick/SDL_joystick.c	Fri Aug 10 14:10:47 2018 -0400
     1.2 +++ b/src/joystick/SDL_joystick.c	Fri Aug 10 14:32:30 2018 -0400
     1.3 @@ -61,6 +61,9 @@
     1.4  #ifdef SDL_JOYSTICK_ANDROID
     1.5      &SDL_ANDROID_JoystickDriver,
     1.6  #endif
     1.7 +#ifdef SDL_JOYSTICK_EMSCRIPTEN
     1.8 +    &SDL_EMSCRIPTEN_JoystickDriver,
     1.9 +#endif
    1.10  #ifdef SDL_JOYSTICK_HIDAPI
    1.11      &SDL_HIDAPI_JoystickDriver,
    1.12  #endif
     2.1 --- a/src/joystick/SDL_sysjoystick.h	Fri Aug 10 14:10:47 2018 -0400
     2.2 +++ b/src/joystick/SDL_sysjoystick.h	Fri Aug 10 14:32:30 2018 -0400
     2.3 @@ -140,6 +140,7 @@
     2.4  extern SDL_JoystickDriver SDL_ANDROID_JoystickDriver;
     2.5  extern SDL_JoystickDriver SDL_DARWIN_JoystickDriver;
     2.6  extern SDL_JoystickDriver SDL_DUMMY_JoystickDriver;
     2.7 +extern SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver;
     2.8  extern SDL_JoystickDriver SDL_HIDAPI_JoystickDriver;
     2.9  extern SDL_JoystickDriver SDL_IOS_JoystickDriver;
    2.10  extern SDL_JoystickDriver SDL_LINUX_JoystickDriver;
     3.1 --- a/src/joystick/emscripten/SDL_sysjoystick.c	Fri Aug 10 14:10:47 2018 -0400
     3.2 +++ b/src/joystick/emscripten/SDL_sysjoystick.c	Fri Aug 10 14:32:30 2018 -0400
     3.3 @@ -156,11 +156,34 @@
     3.4      return 1;
     3.5  }
     3.6  
     3.7 +/* Function to perform any system-specific joystick related cleanup */
     3.8 +static void
     3.9 +EMSCRIPTEN_JoystickQuit(void)
    3.10 +{
    3.11 +    SDL_joylist_item *item = NULL;
    3.12 +    SDL_joylist_item *next = NULL;
    3.13 +
    3.14 +    for (item = SDL_joylist; item; item = next) {
    3.15 +        next = item->next;
    3.16 +        SDL_free(item->mapping);
    3.17 +        SDL_free(item->name);
    3.18 +        SDL_free(item);
    3.19 +    }
    3.20 +
    3.21 +    SDL_joylist = SDL_joylist_tail = NULL;
    3.22 +
    3.23 +    numjoysticks = 0;
    3.24 +    instance_counter = 0;
    3.25 +
    3.26 +    emscripten_set_gamepadconnected_callback(NULL, 0, NULL);
    3.27 +    emscripten_set_gamepaddisconnected_callback(NULL, 0, NULL);
    3.28 +}
    3.29 +
    3.30  /* Function to scan the system for joysticks.
    3.31   * It should return 0, or -1 on an unrecoverable fatal error.
    3.32   */
    3.33 -int
    3.34 -SDL_SYS_JoystickInit(void)
    3.35 +static int
    3.36 +EMSCRIPTEN_JoystickInit(void)
    3.37  {
    3.38      int retval, i, numjs;
    3.39      EmscriptenGamepadEvent gamepadState;
    3.40 @@ -190,7 +213,7 @@
    3.41                                                        Emscripten_JoyStickConnected);
    3.42  
    3.43      if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
    3.44 -        SDL_SYS_JoystickQuit();
    3.45 +        EMSCRIPTEN_JoystickQuit();
    3.46          return SDL_SetError("Could not set gamepad connect callback");
    3.47      }
    3.48  
    3.49 @@ -198,7 +221,7 @@
    3.50                                                           0,
    3.51                                                           Emscripten_JoyStickDisconnected);
    3.52      if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
    3.53 -        SDL_SYS_JoystickQuit();
    3.54 +        EMSCRIPTEN_JoystickQuit();
    3.55          return SDL_SetError("Could not set gamepad disconnect callback");
    3.56      }
    3.57  
    3.58 @@ -239,26 +262,25 @@
    3.59      return item;
    3.60  }
    3.61  
    3.62 -int
    3.63 -SDL_SYS_NumJoysticks(void)
    3.64 +static int
    3.65 +EMSCRIPTEN_JoystickGetCount(void)
    3.66  {
    3.67      return numjoysticks;
    3.68  }
    3.69  
    3.70 -void
    3.71 -SDL_SYS_JoystickDetect(void)
    3.72 +static void
    3.73 +EMSCRIPTEN_JoystickDetect(void)
    3.74  {
    3.75  }
    3.76  
    3.77 -/* Function to get the device-dependent name of a joystick */
    3.78 -const char *
    3.79 -SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    3.80 +static const char *
    3.81 +EMSCRIPTEN_JoystickGetDeviceName(int device_index)
    3.82  {
    3.83      return JoystickByDeviceIndex(device_index)->name;
    3.84  }
    3.85  
    3.86 -/* Function to perform the mapping from device index to the instance id for this index */
    3.87 -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
    3.88 +static SDL_JoystickID
    3.89 +EMSCRIPTEN_JoystickGetDeviceInstanceID(int device_index)
    3.90  {
    3.91      return JoystickByDeviceIndex(device_index)->device_instance;
    3.92  }
    3.93 @@ -268,8 +290,8 @@
    3.94     This should fill the nbuttons and naxes fields of the joystick structure.
    3.95     It returns 0, or -1 if there is an error.
    3.96   */
    3.97 -int
    3.98 -SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
    3.99 +static int
   3.100 +EMSCRIPTEN_JoystickOpen(SDL_Joystick * joystick, int device_index)
   3.101  {
   3.102      SDL_joylist_item *item = JoystickByDeviceIndex(device_index);
   3.103  
   3.104 @@ -300,8 +322,8 @@
   3.105   * but instead should call SDL_PrivateJoystick*() to deliver events
   3.106   * and update joystick device state.
   3.107   */
   3.108 -void
   3.109 -SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
   3.110 +static void
   3.111 +EMSCRIPTEN_JoystickUpdate(SDL_Joystick * joystick)
   3.112  {
   3.113      EmscriptenGamepadEvent gamepadState;
   3.114      SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
   3.115 @@ -340,8 +362,8 @@
   3.116  }
   3.117  
   3.118  /* Function to close a joystick after use */
   3.119 -void
   3.120 -SDL_SYS_JoystickClose(SDL_Joystick * joystick)
   3.121 +static void
   3.122 +EMSCRIPTEN_JoystickClose(SDL_Joystick * joystick)
   3.123  {
   3.124      SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
   3.125      if (item) {
   3.126 @@ -349,49 +371,36 @@
   3.127      }
   3.128  }
   3.129  
   3.130 -/* Function to perform any system-specific joystick related cleanup */
   3.131 -void
   3.132 -SDL_SYS_JoystickQuit(void)
   3.133 -{
   3.134 -    SDL_joylist_item *item = NULL;
   3.135 -    SDL_joylist_item *next = NULL;
   3.136 -
   3.137 -    for (item = SDL_joylist; item; item = next) {
   3.138 -        next = item->next;
   3.139 -        SDL_free(item->mapping);
   3.140 -        SDL_free(item->name);
   3.141 -        SDL_free(item);
   3.142 -    }
   3.143 -
   3.144 -    SDL_joylist = SDL_joylist_tail = NULL;
   3.145 -
   3.146 -    numjoysticks = 0;
   3.147 -    instance_counter = 0;
   3.148 -
   3.149 -    emscripten_set_gamepadconnected_callback(NULL, 0, NULL);
   3.150 -    emscripten_set_gamepaddisconnected_callback(NULL, 0, NULL);
   3.151 -}
   3.152 -
   3.153 -SDL_JoystickGUID
   3.154 -SDL_SYS_JoystickGetDeviceGUID(int device_index)
   3.155 +static SDL_JoystickGUID
   3.156 +EMSCRIPTEN_JoystickGetDeviceGUID(int device_index)
   3.157  {
   3.158      SDL_JoystickGUID guid;
   3.159      /* the GUID is just the first 16 chars of the name for now */
   3.160 -    const char *name = SDL_SYS_JoystickNameForDeviceIndex(device_index);
   3.161 +    const char *name = EMSCRIPTEN_JoystickGetDeviceName(device_index);
   3.162      SDL_zero(guid);
   3.163      SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
   3.164      return guid;
   3.165  }
   3.166  
   3.167 -SDL_JoystickGUID
   3.168 -SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
   3.169 +static int
   3.170 +EMSCRIPTEN_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
   3.171  {
   3.172 -    SDL_JoystickGUID guid;
   3.173 -    /* the GUID is just the first 16 chars of the name for now */
   3.174 -    const char *name = joystick->name;
   3.175 -    SDL_zero(guid);
   3.176 -    SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
   3.177 -    return guid;
   3.178 +    return SDL_Unsupported();
   3.179  }
   3.180  
   3.181 +SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver =
   3.182 +{
   3.183 +    EMSCRIPTEN_JoystickInit,
   3.184 +    EMSCRIPTEN_JoystickGetCount,
   3.185 +    EMSCRIPTEN_JoystickDetect,
   3.186 +    EMSCRIPTEN_JoystickGetDeviceName,
   3.187 +    EMSCRIPTEN_JoystickGetDeviceGUID,
   3.188 +    EMSCRIPTEN_JoystickGetDeviceInstanceID,
   3.189 +    EMSCRIPTEN_JoystickOpen,
   3.190 +    EMSCRIPTEN_JoystickRumble,
   3.191 +    EMSCRIPTEN_JoystickUpdate,
   3.192 +    EMSCRIPTEN_JoystickClose,
   3.193 +    EMSCRIPTEN_JoystickQuit,
   3.194 +};
   3.195 +
   3.196  #endif /* SDL_JOYSTICK_EMSCRIPTEN */