Fixed iOS joystick support for new API
authorSam Lantinga <slouken@libsdl.org>
Mon, 26 Nov 2012 21:11:28 -0800
changeset 66933c98e4ec2180
parent 6692 f83fa0f4bb2d
child 6694 6b277a4ae26a
Fixed iOS joystick support for new API
Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj
src/joystick/SDL_joystick.c
src/joystick/SDL_sysjoystick.h
src/joystick/darwin/SDL_sysjoystick.c
src/joystick/iphoneos/SDL_sysjoystick.m
src/joystick/linux/SDL_sysjoystick.c
src/joystick/windows/SDL_dxjoystick.c
     1.1 --- a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj	Mon Nov 26 18:51:17 2012 -0800
     1.2 +++ b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj	Mon Nov 26 21:11:28 2012 -0800
     1.3 @@ -98,6 +98,8 @@
     1.4  		56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */; };
     1.5  		93CB792313FC5E5200BD3E05 /* SDL_uikitviewcontroller.h in Headers */ = {isa = PBXBuildFile; fileRef = 93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */; };
     1.6  		93CB792613FC5F5300BD3E05 /* SDL_uikitviewcontroller.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */; };
     1.7 +		AA0AD06216647BBB00CE5896 /* SDL_gamecontroller.c in Sources */ = {isa = PBXBuildFile; fileRef = AA0AD06116647BBB00CE5896 /* SDL_gamecontroller.c */; };
     1.8 +		AA0AD06516647BD400CE5896 /* SDL_gamecontroller.h in Headers */ = {isa = PBXBuildFile; fileRef = AA0AD06416647BD400CE5896 /* SDL_gamecontroller.h */; };
     1.9  		AA126AD41617C5E7005ABC8F /* SDL_uikitmodes.h in Headers */ = {isa = PBXBuildFile; fileRef = AA126AD21617C5E6005ABC8F /* SDL_uikitmodes.h */; };
    1.10  		AA126AD51617C5E7005ABC8F /* SDL_uikitmodes.m in Sources */ = {isa = PBXBuildFile; fileRef = AA126AD31617C5E6005ABC8F /* SDL_uikitmodes.m */; };
    1.11  		AA628ADB159369E3005138DD /* SDL_rotate.c in Sources */ = {isa = PBXBuildFile; fileRef = AA628AD9159369E3005138DD /* SDL_rotate.c */; };
    1.12 @@ -356,6 +358,8 @@
    1.13  		56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDL_syspower.m; path = ../../src/power/uikit/SDL_syspower.m; sourceTree = SOURCE_ROOT; };
    1.14  		93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitviewcontroller.h; sourceTree = "<group>"; };
    1.15  		93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_uikitviewcontroller.m; sourceTree = "<group>"; };
    1.16 +		AA0AD06116647BBB00CE5896 /* SDL_gamecontroller.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_gamecontroller.c; sourceTree = "<group>"; };
    1.17 +		AA0AD06416647BD400CE5896 /* SDL_gamecontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_gamecontroller.h; sourceTree = "<group>"; };
    1.18  		AA126AD21617C5E6005ABC8F /* SDL_uikitmodes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitmodes.h; sourceTree = "<group>"; };
    1.19  		AA126AD31617C5E6005ABC8F /* SDL_uikitmodes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_uikitmodes.m; sourceTree = "<group>"; };
    1.20  		AA628AD9159369E3005138DD /* SDL_rotate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_rotate.c; sourceTree = "<group>"; };
    1.21 @@ -830,6 +834,7 @@
    1.22  			isa = PBXGroup;
    1.23  			children = (
    1.24  				FD689EFF0E26E5B600F90B21 /* iphoneos */,
    1.25 +				AA0AD06116647BBB00CE5896 /* SDL_gamecontroller.c */,
    1.26  				FD5F9D1E0E0E08B3008E885B /* SDL_joystick.c */,
    1.27  				FD5F9D1F0E0E08B3008E885B /* SDL_joystick_c.h */,
    1.28  				FD5F9D200E0E08B3008E885B /* SDL_sysjoystick.h */,
    1.29 @@ -914,6 +919,7 @@
    1.30  				AA7558701595D55500BBD41B /* SDL_endian.h */,
    1.31  				AA7558711595D55500BBD41B /* SDL_error.h */,
    1.32  				AA7558721595D55500BBD41B /* SDL_events.h */,
    1.33 +				AA0AD06416647BD400CE5896 /* SDL_gamecontroller.h */,
    1.34  				AA7558731595D55500BBD41B /* SDL_gesture.h */,
    1.35  				AA7558741595D55500BBD41B /* SDL_haptic.h */,
    1.36  				AA7558751595D55500BBD41B /* SDL_hints.h */,
    1.37 @@ -1259,6 +1265,7 @@
    1.38  				AA704DD6162AA90A0076D1C1 /* SDL_dropevents_c.h in Headers */,
    1.39  				AA9FF9511637C6E5000DF050 /* SDL_messagebox.h in Headers */,
    1.40  				AABCC3941640643D00AB8930 /* SDL_uikitmessagebox.h in Headers */,
    1.41 +				AA0AD06516647BD400CE5896 /* SDL_gamecontroller.h in Headers */,
    1.42  			);
    1.43  			runOnlyForDeploymentPostprocessing = 0;
    1.44  		};
    1.45 @@ -1478,6 +1485,7 @@
    1.46  				AA126AD51617C5E7005ABC8F /* SDL_uikitmodes.m in Sources */,
    1.47  				AA704DD7162AA90A0076D1C1 /* SDL_dropevents.c in Sources */,
    1.48  				AABCC3951640643D00AB8930 /* SDL_uikitmessagebox.m in Sources */,
    1.49 +				AA0AD06216647BBB00CE5896 /* SDL_gamecontroller.c in Sources */,
    1.50  			);
    1.51  			runOnlyForDeploymentPostprocessing = 0;
    1.52  		};
     2.1 --- a/src/joystick/SDL_joystick.c	Mon Nov 26 18:51:17 2012 -0800
     2.2 +++ b/src/joystick/SDL_joystick.c	Mon Nov 26 21:11:28 2012 -0800
     2.3 @@ -661,13 +661,13 @@
     2.4  }
     2.5  
     2.6  
     2.7 -/* return the guid for this index*/
     2.8 +/* return the guid for this index */
     2.9  JoystickGUID SDL_JoystickGetDeviceGUID( int device_index )
    2.10  {
    2.11 -	return SDL_SYS_PrivateJoystickGetDeviceID( device_index );
    2.12 +	return SDL_SYS_PrivateJoystickGetDeviceGUID( device_index );
    2.13  }
    2.14  
    2.15 -/* return the guid for this openeded device*/
    2.16 +/* return the guid for this opened device */
    2.17  JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
    2.18  {
    2.19  	return SDL_SYS_PrivateJoystickGetGUID( joystick );
     3.1 --- a/src/joystick/SDL_sysjoystick.h	Mon Nov 26 18:51:17 2012 -0800
     3.2 +++ b/src/joystick/SDL_sysjoystick.h	Mon Nov 26 21:11:28 2012 -0800
     3.3 @@ -107,7 +107,7 @@
     3.4  
     3.5  /* Function to return the stable GUID for a plugged in device
     3.6   */
     3.7 -extern JoystickGUID SDL_SYS_PrivateJoystickGetDeviceID( int device_index );
     3.8 +extern JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index );
     3.9  
    3.10  /* Function to return the stable GUID for a opened joystick
    3.11   */
     4.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Mon Nov 26 18:51:17 2012 -0800
     4.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Mon Nov 26 21:11:28 2012 -0800
     4.3 @@ -1089,7 +1089,7 @@
     4.4  	return s_bDeviceAdded;
     4.5  }
     4.6  
     4.7 -JoystickGUID SDL_SYS_PrivateJoystickGetDeviceID( int device_index )
     4.8 +JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
     4.9  {
    4.10      recDevice *device = gpDeviceList;
    4.11      int index;
     5.1 --- a/src/joystick/iphoneos/SDL_sysjoystick.m	Mon Nov 26 18:51:17 2012 -0800
     5.2 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Mon Nov 26 21:11:28 2012 -0800
     5.3 @@ -37,13 +37,12 @@
     5.4  int
     5.5  SDL_SYS_JoystickInit(void)
     5.6  {
     5.7 -    SDL_numjoysticks = 1;
     5.8      return (1);
     5.9  }
    5.10  
    5.11  /* Function to get the device-dependent name of a joystick */
    5.12  const char *
    5.13 -SDL_SYS_JoystickName(int index)
    5.14 +SDL_SYS_JoystickNameForIndex(int index)
    5.15  {
    5.16  	switch(index) {
    5.17  		case 0:
    5.18 @@ -60,14 +59,13 @@
    5.19     It returns 0, or -1 if there is an error.
    5.20   */
    5.21  int
    5.22 -SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
    5.23 +SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
    5.24  {
    5.25 -	if (joystick->index == 0) {
    5.26 +	if (device_index == 0) {
    5.27  		joystick->naxes = 3;
    5.28  		joystick->nhats = 0;
    5.29  		joystick->nballs = 0;
    5.30  		joystick->nbuttons = 0;
    5.31 -		joystick->name  = accelerometerName;
    5.32  		[[SDLUIAccelerationDelegate sharedDelegate] startup];
    5.33  		return 0;
    5.34  	}
    5.35 @@ -107,7 +105,7 @@
    5.36  void
    5.37  SDL_SYS_JoystickClose(SDL_Joystick * joystick)
    5.38  {
    5.39 -	if (joystick->index == 0 && [[SDLUIAccelerationDelegate sharedDelegate] isRunning]) {
    5.40 +	if ([[SDLUIAccelerationDelegate sharedDelegate] isRunning]) {
    5.41  		[[SDLUIAccelerationDelegate sharedDelegate] shutdown];
    5.42  	}
    5.43  	SDL_SetError("No joystick open with that index");
    5.44 @@ -121,4 +119,51 @@
    5.45  {
    5.46      return;
    5.47  }
    5.48 +
    5.49 +/* Function to perform the mapping from device index to the instance id for this index */
    5.50 +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
    5.51 +{
    5.52 +    return index;
    5.53 +}
    5.54 +
    5.55 +/* Function to determine is this joystick is attached to the system right now */
    5.56 +int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    5.57 +{
    5.58 +    return 1;
    5.59 +}
    5.60 +
    5.61 +int SDL_SYS_NumJoysticks()
    5.62 +{
    5.63 +    return 1;
    5.64 +}
    5.65 +
    5.66 +int SDL_SYS_JoystickNeedsPolling()
    5.67 +{
    5.68 +    return 0;
    5.69 +}
    5.70 +
    5.71 +void SDL_SYS_JoystickDetect()
    5.72 +{
    5.73 +}
    5.74 +
    5.75 +JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
    5.76 +{
    5.77 +    JoystickGUID guid;
    5.78 +    // the GUID is just the first 16 chars of the name for now
    5.79 +    const char *name = SDL_SYS_JoystickNameForIndex( device_index );
    5.80 +    SDL_zero( guid );
    5.81 +    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
    5.82 +    return guid;
    5.83 +}
    5.84 +
    5.85 +JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
    5.86 +{
    5.87 +    JoystickGUID guid;
    5.88 +    // the GUID is just the first 16 chars of the name for now
    5.89 +    const char *name = joystick->name;
    5.90 +    SDL_zero( guid );
    5.91 +    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
    5.92 +    return guid;
    5.93 +}
    5.94 +
    5.95  /* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Mon Nov 26 18:51:17 2012 -0800
     6.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Mon Nov 26 21:11:28 2012 -0800
     6.3 @@ -513,7 +513,7 @@
     6.4  {
     6.5      int fd;
     6.6      static char namebuf[128];
     6.7 -    char *name;
     6.8 +    const char *name;
     6.9      SDL_logical_joydecl(int oindex = index);
    6.10  
    6.11  #ifndef NO_LOGICAL_JOYSTICKS
    6.12 @@ -1248,7 +1248,7 @@
    6.13  /* Function to determine is this joystick is attached to the system right now */
    6.14  int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    6.15  {
    6.16 -    return !joystick->closed;
    6.17 +    return 1;
    6.18  }
    6.19  
    6.20  int SDL_SYS_NumJoysticks()
    6.21 @@ -1265,24 +1265,27 @@
    6.22  {
    6.23  }
    6.24  
    6.25 -JoystickGUID SDL_SYS_PrivateJoystickGetDeviceID( int device_index )
    6.26 +JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
    6.27  {
    6.28 -    static JoystickGUID guid;
    6.29 +    JoystickGUID guid;
    6.30      // the GUID is just the first 16 chars of the name for now
    6.31      const char *name = SDL_SYS_JoystickNameForIndex( device_index );
    6.32 -    SDL_memcpy( &guid, name, sizeof(guid) );
    6.33 +    SDL_zero( guid );
    6.34 +    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
    6.35      return guid;
    6.36  }
    6.37  
    6.38  
    6.39  JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
    6.40  {
    6.41 -    static JoystickGUID guid;
    6.42 +    JoystickGUID guid;
    6.43      // the GUID is just the first 16 chars of the name for now
    6.44 -    const char *name = SDL_SYS_JoystickNameForIndex( joystick->name );
    6.45 -    SDL_memcpy( &guid, name, sizeof(guid) );
    6.46 +    const char *name = joystick->name;
    6.47 +    SDL_zero( guid );
    6.48 +    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
    6.49      return guid;
    6.50  }
    6.51  
    6.52  #endif /* SDL_JOYSTICK_LINUX */
    6.53 +
    6.54  /* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Mon Nov 26 18:51:17 2012 -0800
     7.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Mon Nov 26 21:11:28 2012 -0800
     7.3 @@ -1651,7 +1651,7 @@
     7.4  }
     7.5  
     7.6  /* return the stable device guid for this device index */
     7.7 -JoystickGUID SDL_SYS_PrivateJoystickGetDeviceID( int device_index )
     7.8 +JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
     7.9  {
    7.10  	JoyStick_DeviceData *device = SYS_Joystick;
    7.11  	int index;