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

Commit

Permalink
Changes from Alfred:
Browse files Browse the repository at this point in the history
- rename JoystickGUID -> SDL_JoystickGUID
- change SDL_JoystickGetGUIDString to take the string as an arg, rather than doing a malloc
  • Loading branch information
slouken committed Dec 11, 2012
1 parent 3d9a1cd commit 721963a
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 40 deletions.
10 changes: 5 additions & 5 deletions include/SDL_joystick.h
Expand Up @@ -65,7 +65,7 @@ typedef struct _SDL_Joystick SDL_Joystick;
/* A structure that encodes the stable unique id for a joystick device */
typedef struct {
Uint8 data[16];
} JoystickGUID;
} SDL_JoystickGUID;

typedef int SDL_JoystickID;

Expand Down Expand Up @@ -102,22 +102,22 @@ extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick);
/**
* Return the GUID for the joystick at this index
*/
extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);

/**
* Return the GUID for this opened joystick
*/
extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);

/**
* Return a string representation for this guid. You are responsible for freeing memory from this call
*/
extern DECLSPEC char *SDLCALL SDL_JoystickGetGUIDString(JoystickGUID guid);
extern DECLSPEC void SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);

/**
* convert a string into a joystick formatted guid
*/
extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);

/**
* Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.
Expand Down
15 changes: 8 additions & 7 deletions src/joystick/SDL_gamecontroller.c
Expand Up @@ -48,7 +48,7 @@ struct _SDL_HatAsButton
/* our in memory mapping db between joystick objects and controller mappings*/
struct _SDL_ControllerMapping
{
JoystickGUID guid;
SDL_JoystickGUID guid;
const char *name;

// mapping of axis/button id to controller version
Expand All @@ -71,7 +71,7 @@ struct _SDL_ControllerMapping
/* our hard coded list of mapping support */
typedef struct _ControllerMapping_t
{
JoystickGUID guid;
SDL_JoystickGUID guid;
char *name;
const char *mapping;
struct _ControllerMapping_t *next;
Expand Down Expand Up @@ -458,7 +458,7 @@ SDL_PrivateGameControllerParseControllerConfigString( struct _SDL_ControllerMapp
/*
* Make a new button mapping struct
*/
void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, JoystickGUID guid, const char *pchName, const char *pchMapping )
void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping )
{
int j;

Expand Down Expand Up @@ -673,7 +673,7 @@ SDL_GameControllerNameForIndex(int device_index)
}
else
{
JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
pSupportedController = s_pSupportedControllers;
while ( pSupportedController )
{
Expand All @@ -700,10 +700,11 @@ int SDL_IsGameController(int device_index)
}
else
{
JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
pSupportedController = s_pSupportedControllers;
// debug code to help get the guid string for a new joystick
/*const char *pchGUID = SDL_JoystickGetGUIDString( jGUID );
/* char szGUID[33];
SDL_JoystickGetGUIDString( jGUID, szGUID, sizeof(szGUID) );
printf( "%s\n", pchGUID );
SDL_free( pchGUID );*/
while ( pSupportedController )
Expand Down Expand Up @@ -759,7 +760,7 @@ SDL_GameControllerOpen(int device_index)
pSupportedController = SDL_PrivateGetControllerMapping(device_index);
if ( !pSupportedController )
{
JoystickGUID jGUID;
SDL_JoystickGUID jGUID;

jGUID = SDL_JoystickGetDeviceGUID( device_index );
pSupportedController = s_pSupportedControllers;
Expand Down
21 changes: 7 additions & 14 deletions src/joystick/SDL_joystick.c
Expand Up @@ -683,34 +683,28 @@ SDL_PrivateJoystickNeedsPolling()


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

/* return the guid for this opened device */
JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
{
return SDL_SYS_JoystickGetGUID( joystick );
}

/* convert the guid to a printable string */
char *SDL_JoystickGetGUIDString(JoystickGUID guid)
void SDL_JoystickGetGUIDString( SDL_JoystickGUID guid, char *pszGUID, int cbGUID )
{
static const char k_rgchHexToASCII[] = "0123456789abcdef";
char *pchOut = NULL;
char *pchString = NULL;
int i;
pchString = SDL_malloc(33); // 16 bytes
if ( !pchString )
{
SDL_OutOfMemory();
return NULL;
}

pchOut = pchString;
pchOut = pszGUID;

for ( i = 0; i < sizeof(guid); i++ )
for ( i = 0; i < sizeof(guid) && i < (cbGUID-1); i++ )
{
// each input byte writes 2 ascii chars, and might write a null byte.
// If we don't have room for next input byte, stop
Expand All @@ -720,7 +714,6 @@ char *SDL_JoystickGetGUIDString(JoystickGUID guid)
*pchOut++ = k_rgchHexToASCII[ c & 0x0F ];
}
*pchOut = '\0';
return pchString;
}


Expand Down Expand Up @@ -756,9 +749,9 @@ static unsigned char nibble( char c )


/* convert the string version of a joystick guid to the struct */
JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
{
JoystickGUID guid;
SDL_JoystickGUID guid;
int maxoutputbytes= sizeof(guid);
int len = SDL_strlen( pchGUID );
Uint8 *p;
Expand Down
4 changes: 2 additions & 2 deletions src/joystick/SDL_sysjoystick.h
Expand Up @@ -104,10 +104,10 @@ extern void SDL_SYS_JoystickClose(SDL_Joystick * joystick);
extern void SDL_SYS_JoystickQuit(void);

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

/* Function to return the stable GUID for a opened joystick */
extern JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);
extern SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);

#ifdef SDL_JOYSTICK_DINPUT
/* Function to get the current instance id of the joystick located at device_index */
Expand Down
4 changes: 2 additions & 2 deletions src/joystick/darwin/SDL_sysjoystick.c
Expand Up @@ -1083,7 +1083,7 @@ SDL_SYS_JoystickQuit(void)
}


JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
{
recDevice *device = gpDeviceList;
int index;
Expand All @@ -1094,7 +1094,7 @@ JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
return device->guid;
}

JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
{
return joystick->hwdata->guid;
}
Expand Down
6 changes: 4 additions & 2 deletions src/joystick/linux/SDL_sysjoystick.c
Expand Up @@ -953,13 +953,15 @@ SDL_SYS_JoystickQuit(void)
#endif
}

JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
{
JoystickGUID guid;
return JoystickByDevIndex(device_index)->guid;
}

JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
JoystickGUID guid;
return joystick->hwdata->guid;
}

Expand Down
6 changes: 3 additions & 3 deletions src/joystick/windows/SDL_dxjoystick.c
Expand Up @@ -79,7 +79,7 @@ extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
LPUNKNOWN punkOuter);
struct JoyStick_DeviceData_
{
JoystickGUID guid;
SDL_JoystickGUID guid;
DIDEVICEINSTANCE dxdevice;
char *joystickname;
Uint8 send_add_event;
Expand Down Expand Up @@ -1676,7 +1676,7 @@ SDL_SYS_JoystickQuit(void)


/* return the stable device guid for this device index */
JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
{
JoyStick_DeviceData *device = SYS_Joystick;
int index;
Expand All @@ -1687,7 +1687,7 @@ JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
return device->guid;
}

JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
return joystick->hwdata->guid;
}
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/windows/SDL_dxjoystick_c.h
Expand Up @@ -87,7 +87,7 @@ struct joystick_hwdata
LPDIRECTINPUTDEVICE8 InputDevice;
DIDEVCAPS Capabilities;
int buffered;
JoystickGUID guid;
SDL_JoystickGUID guid;

input_t Inputs[MAX_INPUTS];
int NumInputs;
Expand Down
8 changes: 4 additions & 4 deletions src/joystick/windows/SDL_mmjoystick.c
Expand Up @@ -405,19 +405,19 @@ SDL_SYS_JoystickQuit(void)
}
}

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

JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
JoystickGUID guid;
SDL_JoystickGUID guid;
// the GUID is just the first 16 chars of the name for now
const char *name = joystick->name;
SDL_zero( guid );
Expand Down

0 comments on commit 721963a

Please sign in to comment.