haiku: Patched to compile with new joystick interfaces.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 10 Aug 2018 15:04:08 -0400
changeset 121077c7cee9f2bc4
parent 12106 94f9bf5b9c36
child 12108 eb2820ee52ee
haiku: Patched to compile with new joystick interfaces.
src/joystick/SDL_joystick.c
src/joystick/SDL_sysjoystick.h
src/joystick/haiku/SDL_haikujoystick.cc
     1.1 --- a/src/joystick/SDL_joystick.c	Fri Aug 10 14:54:26 2018 -0400
     1.2 +++ b/src/joystick/SDL_joystick.c	Fri Aug 10 15:04:08 2018 -0400
     1.3 @@ -64,6 +64,9 @@
     1.4  #ifdef SDL_JOYSTICK_EMSCRIPTEN
     1.5      &SDL_EMSCRIPTEN_JoystickDriver,
     1.6  #endif
     1.7 +#ifdef SDL_JOYSTICK_HAIKU
     1.8 +    &SDL_HAIKU_JoystickDriver,
     1.9 +#endif
    1.10  #ifdef SDL_JOYSTICK_USBHID  /* !!! FIXME: "USBHID" is a generic name, and doubly-confusing with HIDAPI next to it. This is the *BSD interface, rename this. */
    1.11      &SDL_BSD_JoystickDriver,
    1.12  #endif
     2.1 --- a/src/joystick/SDL_sysjoystick.h	Fri Aug 10 14:54:26 2018 -0400
     2.2 +++ b/src/joystick/SDL_sysjoystick.h	Fri Aug 10 15:04:08 2018 -0400
     2.3 @@ -142,6 +142,7 @@
     2.4  extern SDL_JoystickDriver SDL_DARWIN_JoystickDriver;
     2.5  extern SDL_JoystickDriver SDL_DUMMY_JoystickDriver;
     2.6  extern SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver;
     2.7 +extern SDL_JoystickDriver SDL_HAIKU_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/haiku/SDL_haikujoystick.cc	Fri Aug 10 14:54:26 2018 -0400
     3.2 +++ b/src/joystick/haiku/SDL_haikujoystick.cc	Fri Aug 10 15:04:08 2018 -0400
     3.3 @@ -50,13 +50,13 @@
     3.4          int16 *new_axes;
     3.5      };
     3.6  
     3.7 -    static int SDL_SYS_numjoysticks = 0;
     3.8 +    static int numjoysticks = 0;
     3.9  
    3.10  /* Function to scan the system for joysticks.
    3.11   * Joystick 0 should be the system default joystick.
    3.12   * It should return 0, or -1 on an unrecoverable fatal error.
    3.13   */
    3.14 -    int SDL_SYS_JoystickInit(void)
    3.15 +    static int HAIKU_JoystickInit(void)
    3.16      {
    3.17          BJoystick joystick;
    3.18          int i;
    3.19 @@ -65,52 +65,54 @@
    3.20  
    3.21          /* Search for attached joysticks */
    3.22            nports = joystick.CountDevices();
    3.23 -          SDL_SYS_numjoysticks = 0;
    3.24 +          numjoysticks = 0;
    3.25            SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport));
    3.26            SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname));
    3.27 -        for (i = 0; (SDL_SYS_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i)
    3.28 +        for (i = 0; (numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i)
    3.29          {
    3.30              if (joystick.GetDeviceName(i, name) == B_OK) {
    3.31                  if (joystick.Open(name) != B_ERROR) {
    3.32                      BString stick_name;
    3.33                        joystick.GetControllerName(&stick_name);
    3.34 -                      SDL_joyport[SDL_SYS_numjoysticks] = SDL_strdup(name);
    3.35 -                      SDL_joyname[SDL_SYS_numjoysticks] = SDL_strdup(stick_name.String());
    3.36 -                      SDL_SYS_numjoysticks++;
    3.37 +                      SDL_joyport[numjoysticks] = SDL_strdup(name);
    3.38 +                      SDL_joyname[numjoysticks] = SDL_strdup(stick_name.String());
    3.39 +                      numjoysticks++;
    3.40                        joystick.Close();
    3.41                  }
    3.42              }
    3.43          }
    3.44 -        return (SDL_SYS_numjoysticks);
    3.45 +        return (numjoysticks);
    3.46      }
    3.47  
    3.48 -    int SDL_SYS_NumJoysticks(void)
    3.49 +    static int HAIKU_JoystickGetCount(void)
    3.50      {
    3.51 -        return SDL_SYS_numjoysticks;
    3.52 +        return numjoysticks;
    3.53      }
    3.54  
    3.55 -    void SDL_SYS_JoystickDetect(void)
    3.56 +    static void HAIKU_JoystickDetect(void)
    3.57      {
    3.58      }
    3.59  
    3.60  /* Function to get the device-dependent name of a joystick */
    3.61 -    const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    3.62 +    static const char *HAIKU_JoystickGetDeviceName(int device_index)
    3.63      {
    3.64          return SDL_joyname[device_index];
    3.65      }
    3.66  
    3.67  /* Function to perform the mapping from device index to the instance id for this index */
    3.68 -    SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
    3.69 +    static SDL_JoystickID HAIKU_JoystickGetDeviceInstanceID(int device_index)
    3.70      {
    3.71          return device_index;
    3.72      }
    3.73  
    3.74 +    static void HAIKU_JoystickClose(SDL_Joystick * joystick);
    3.75 +
    3.76  /* Function to open a joystick for use.
    3.77     The joystick to open is specified by the device index.
    3.78     This should fill the nbuttons and naxes fields of the joystick structure.
    3.79     It returns 0, or -1 if there is an error.
    3.80   */
    3.81 -    int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
    3.82 +    static int HAIKU_JoystickOpen(SDL_Joystick * joystick, int device_index)
    3.83      {
    3.84          BJoystick *stick;
    3.85  
    3.86 @@ -127,7 +129,7 @@
    3.87  
    3.88          /* Open the requested joystick for use */
    3.89          if (stick->Open(SDL_joyport[device_index]) == B_ERROR) {
    3.90 -            SDL_SYS_JoystickClose(joystick);
    3.91 +            HAIKU_JoystickClose(joystick);
    3.92              return SDL_SetError("Unable to open joystick");
    3.93          }
    3.94  
    3.95 @@ -144,12 +146,12 @@
    3.96          joystick->hwdata->new_hats = (uint8 *)
    3.97              SDL_malloc(joystick->nhats * sizeof(uint8));
    3.98          if (!joystick->hwdata->new_hats || !joystick->hwdata->new_axes) {
    3.99 -            SDL_SYS_JoystickClose(joystick);
   3.100 +            HAIKU_JoystickClose(joystick);
   3.101              return SDL_OutOfMemory();
   3.102          }
   3.103  
   3.104          /* We're done! */
   3.105 -        return (0);
   3.106 +        return 0;
   3.107      }
   3.108  
   3.109  /* Function to update the state of a joystick - called as a device poll.
   3.110 @@ -157,7 +159,7 @@
   3.111   * but instead should call SDL_PrivateJoystick*() to deliver events
   3.112   * and update joystick device state.
   3.113   */
   3.114 -    void SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
   3.115 +    static void HAIKU_JoystickUpdate(SDL_Joystick * joystick)
   3.116      {
   3.117          static const Uint8 hat_map[9] = {
   3.118              SDL_HAT_CENTERED,
   3.119 @@ -206,7 +208,7 @@
   3.120      }
   3.121  
   3.122  /* Function to close a joystick after use */
   3.123 -    void SDL_SYS_JoystickClose(SDL_Joystick * joystick)
   3.124 +    static void HAIKU_JoystickClose(SDL_Joystick * joystick)
   3.125      {
   3.126          if (joystick->hwdata) {
   3.127              joystick->hwdata->stick->Close();
   3.128 @@ -218,42 +220,52 @@
   3.129      }
   3.130  
   3.131  /* Function to perform any system-specific joystick related cleanup */
   3.132 -    void SDL_SYS_JoystickQuit(void)
   3.133 +    static void HAIKU_JoystickQuit(void)
   3.134      {
   3.135          int i;
   3.136  
   3.137 -        for (i = 0; i < SDL_SYS_numjoysticks; ++i) {
   3.138 +        for (i = 0; i < numjoysticks; ++i) {
   3.139              SDL_free(SDL_joyport[i]);
   3.140          }
   3.141          SDL_joyport[0] = NULL;
   3.142  
   3.143 -        for (i = 0; i < SDL_SYS_numjoysticks; ++i) {
   3.144 +        for (i = 0; i < numjoysticks; ++i) {
   3.145              SDL_free(SDL_joyname[i]);
   3.146          }
   3.147          SDL_joyname[0] = NULL;
   3.148      }
   3.149  
   3.150 -    SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
   3.151 +    static SDL_JoystickGUID HAIKU_JoystickGetDeviceGUID( int device_index )
   3.152      {
   3.153          SDL_JoystickGUID guid;
   3.154          /* the GUID is just the first 16 chars of the name for now */
   3.155 -        const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
   3.156 +        const char *name = HAIKU_JoystickGetDeviceName( device_index );
   3.157          SDL_zero( guid );
   3.158          SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   3.159          return guid;
   3.160      }
   3.161  
   3.162 -    SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
   3.163 +    static int HAIKU_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
   3.164      {
   3.165 -        SDL_JoystickGUID guid;
   3.166 -        /* the GUID is just the first 16 chars of the name for now */
   3.167 -        const char *name = joystick->name;
   3.168 -        SDL_zero( guid );
   3.169 -        SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   3.170 -        return guid;
   3.171 +        return SDL_Unsupported();
   3.172      }
   3.173  
   3.174 -};                              // extern "C"
   3.175 +    SDL_JoystickDriver SDL_HAIKU_JoystickDriver =
   3.176 +    {
   3.177 +        HAIKU_JoystickInit,
   3.178 +        HAIKU_JoystickGetCount,
   3.179 +        HAIKU_JoystickDetect,
   3.180 +        HAIKU_JoystickGetDeviceName,
   3.181 +        HAIKU_JoystickGetDeviceGUID,
   3.182 +        HAIKU_JoystickGetDeviceInstanceID,
   3.183 +        HAIKU_JoystickOpen,
   3.184 +        HAIKU_JoystickRumble,
   3.185 +        HAIKU_JoystickUpdate,
   3.186 +        HAIKU_JoystickClose,
   3.187 +        HAIKU_JoystickQuit,
   3.188 +    };
   3.189 +
   3.190 +}                              // extern "C"
   3.191  
   3.192  #endif /* SDL_JOYSTICK_HAIKU */
   3.193