Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed iOS joystick support for new API
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 27, 2012
1 parent 5d6ed63 commit 1adba19
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 20 deletions.
8 changes: 8 additions & 0 deletions Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj
Expand Up @@ -98,6 +98,8 @@
56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */; };
93CB792313FC5E5200BD3E05 /* SDL_uikitviewcontroller.h in Headers */ = {isa = PBXBuildFile; fileRef = 93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */; };
93CB792613FC5F5300BD3E05 /* SDL_uikitviewcontroller.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */; };
AA0AD06216647BBB00CE5896 /* SDL_gamecontroller.c in Sources */ = {isa = PBXBuildFile; fileRef = AA0AD06116647BBB00CE5896 /* SDL_gamecontroller.c */; };
AA0AD06516647BD400CE5896 /* SDL_gamecontroller.h in Headers */ = {isa = PBXBuildFile; fileRef = AA0AD06416647BD400CE5896 /* SDL_gamecontroller.h */; };
AA126AD41617C5E7005ABC8F /* SDL_uikitmodes.h in Headers */ = {isa = PBXBuildFile; fileRef = AA126AD21617C5E6005ABC8F /* SDL_uikitmodes.h */; };
AA126AD51617C5E7005ABC8F /* SDL_uikitmodes.m in Sources */ = {isa = PBXBuildFile; fileRef = AA126AD31617C5E6005ABC8F /* SDL_uikitmodes.m */; };
AA628ADB159369E3005138DD /* SDL_rotate.c in Sources */ = {isa = PBXBuildFile; fileRef = AA628AD9159369E3005138DD /* SDL_rotate.c */; };
Expand Down Expand Up @@ -356,6 +358,8 @@
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; };
93CB792213FC5E5200BD3E05 /* SDL_uikitviewcontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitviewcontroller.h; sourceTree = "<group>"; };
93CB792513FC5F5300BD3E05 /* SDL_uikitviewcontroller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_uikitviewcontroller.m; sourceTree = "<group>"; };
AA0AD06116647BBB00CE5896 /* SDL_gamecontroller.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_gamecontroller.c; sourceTree = "<group>"; };
AA0AD06416647BD400CE5896 /* SDL_gamecontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_gamecontroller.h; sourceTree = "<group>"; };
AA126AD21617C5E6005ABC8F /* SDL_uikitmodes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitmodes.h; sourceTree = "<group>"; };
AA126AD31617C5E6005ABC8F /* SDL_uikitmodes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_uikitmodes.m; sourceTree = "<group>"; };
AA628AD9159369E3005138DD /* SDL_rotate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_rotate.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -830,6 +834,7 @@
isa = PBXGroup;
children = (
FD689EFF0E26E5B600F90B21 /* iphoneos */,
AA0AD06116647BBB00CE5896 /* SDL_gamecontroller.c */,
FD5F9D1E0E0E08B3008E885B /* SDL_joystick.c */,
FD5F9D1F0E0E08B3008E885B /* SDL_joystick_c.h */,
FD5F9D200E0E08B3008E885B /* SDL_sysjoystick.h */,
Expand Down Expand Up @@ -914,6 +919,7 @@
AA7558701595D55500BBD41B /* SDL_endian.h */,
AA7558711595D55500BBD41B /* SDL_error.h */,
AA7558721595D55500BBD41B /* SDL_events.h */,
AA0AD06416647BD400CE5896 /* SDL_gamecontroller.h */,
AA7558731595D55500BBD41B /* SDL_gesture.h */,
AA7558741595D55500BBD41B /* SDL_haptic.h */,
AA7558751595D55500BBD41B /* SDL_hints.h */,
Expand Down Expand Up @@ -1259,6 +1265,7 @@
AA704DD6162AA90A0076D1C1 /* SDL_dropevents_c.h in Headers */,
AA9FF9511637C6E5000DF050 /* SDL_messagebox.h in Headers */,
AABCC3941640643D00AB8930 /* SDL_uikitmessagebox.h in Headers */,
AA0AD06516647BD400CE5896 /* SDL_gamecontroller.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1478,6 +1485,7 @@
AA126AD51617C5E7005ABC8F /* SDL_uikitmodes.m in Sources */,
AA704DD7162AA90A0076D1C1 /* SDL_dropevents.c in Sources */,
AABCC3951640643D00AB8930 /* SDL_uikitmessagebox.m in Sources */,
AA0AD06216647BBB00CE5896 /* SDL_gamecontroller.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 3 additions & 3 deletions src/joystick/SDL_joystick.c
Expand Up @@ -661,13 +661,13 @@ SDL_PrivateJoystickNeedsPolling()
}


/* return the guid for this index*/
/* return the guid for this index */
JoystickGUID SDL_JoystickGetDeviceGUID( int device_index )
{
return SDL_SYS_PrivateJoystickGetDeviceID( device_index );
return SDL_SYS_PrivateJoystickGetDeviceGUID( device_index );
}

/* return the guid for this openeded device*/
/* return the guid for this opened device */
JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
{
return SDL_SYS_PrivateJoystickGetGUID( joystick );
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/SDL_sysjoystick.h
Expand Up @@ -107,7 +107,7 @@ extern int SDL_SYS_JoystickNeedsPolling();

/* Function to return the stable GUID for a plugged in device
*/
extern JoystickGUID SDL_SYS_PrivateJoystickGetDeviceID( int device_index );
extern JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index );

/* Function to return the stable GUID for a opened joystick
*/
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/darwin/SDL_sysjoystick.c
Expand Up @@ -1089,7 +1089,7 @@ SDL_SYS_JoystickNeedsPolling()
return s_bDeviceAdded;
}

JoystickGUID SDL_SYS_PrivateJoystickGetDeviceID( int device_index )
JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
{
recDevice *device = gpDeviceList;
int index;
Expand Down
57 changes: 51 additions & 6 deletions src/joystick/iphoneos/SDL_sysjoystick.m
Expand Up @@ -37,13 +37,12 @@
int
SDL_SYS_JoystickInit(void)
{
SDL_numjoysticks = 1;
return (1);
}

/* Function to get the device-dependent name of a joystick */
const char *
SDL_SYS_JoystickName(int index)
SDL_SYS_JoystickNameForIndex(int index)
{
switch(index) {
case 0:
Expand All @@ -60,14 +59,13 @@
It returns 0, or -1 if there is an error.
*/
int
SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
{
if (joystick->index == 0) {
if (device_index == 0) {
joystick->naxes = 3;
joystick->nhats = 0;
joystick->nballs = 0;
joystick->nbuttons = 0;
joystick->name = accelerometerName;
[[SDLUIAccelerationDelegate sharedDelegate] startup];
return 0;
}
Expand Down Expand Up @@ -107,7 +105,7 @@
void
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
{
if (joystick->index == 0 && [[SDLUIAccelerationDelegate sharedDelegate] isRunning]) {
if ([[SDLUIAccelerationDelegate sharedDelegate] isRunning]) {
[[SDLUIAccelerationDelegate sharedDelegate] shutdown];
}
SDL_SetError("No joystick open with that index");
Expand All @@ -121,4 +119,51 @@
{
return;
}

/* Function to perform the mapping from device index to the instance id for this index */
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
{
return index;
}

/* Function to determine is this joystick is attached to the system right now */
int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
{
return 1;
}

int SDL_SYS_NumJoysticks()
{
return 1;
}

int SDL_SYS_JoystickNeedsPolling()
{
return 0;
}

void SDL_SYS_JoystickDetect()
{
}

JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
{
JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
const char *name = SDL_SYS_JoystickNameForIndex( device_index );
SDL_zero( guid );
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
return guid;
}

JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
{
JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
const char *name = joystick->name;
SDL_zero( guid );
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
return guid;
}

/* vi: set ts=4 sw=4 expandtab: */
19 changes: 11 additions & 8 deletions src/joystick/linux/SDL_sysjoystick.c
Expand Up @@ -513,7 +513,7 @@ SDL_SYS_JoystickNameForIndex(int index)
{
int fd;
static char namebuf[128];
char *name;
const char *name;
SDL_logical_joydecl(int oindex = index);

#ifndef NO_LOGICAL_JOYSTICKS
Expand Down Expand Up @@ -1248,7 +1248,7 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
/* Function to determine is this joystick is attached to the system right now */
int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
{
return !joystick->closed;
return 1;
}

int SDL_SYS_NumJoysticks()
Expand All @@ -1265,24 +1265,27 @@ void SDL_SYS_JoystickDetect()
{
}

JoystickGUID SDL_SYS_PrivateJoystickGetDeviceID( int device_index )
JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
{
static JoystickGUID guid;
JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
const char *name = SDL_SYS_JoystickNameForIndex( device_index );
SDL_memcpy( &guid, name, sizeof(guid) );
SDL_zero( guid );
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
return guid;
}


JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
{
static JoystickGUID guid;
JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
const char *name = SDL_SYS_JoystickNameForIndex( joystick->name );
SDL_memcpy( &guid, name, sizeof(guid) );
const char *name = joystick->name;
SDL_zero( guid );
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
return guid;
}

#endif /* SDL_JOYSTICK_LINUX */

/* vi: set ts=4 sw=4 expandtab: */
2 changes: 1 addition & 1 deletion src/joystick/windows/SDL_dxjoystick.c
Expand Up @@ -1651,7 +1651,7 @@ int SDL_SYS_JoystickNeedsPolling()
}

/* return the stable device guid for this device index */
JoystickGUID SDL_SYS_PrivateJoystickGetDeviceID( int device_index )
JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
{
JoyStick_DeviceData *device = SYS_Joystick;
int index;
Expand Down

0 comments on commit 1adba19

Please sign in to comment.