Changes from Alfred:
- rename JoystickGUID -> SDL_JoystickGUID - change SDL_JoystickGetGUIDString to take the string as an arg, rather than doing a malloc
This commit is contained in:
parent
6b3312c807
commit
89ef9e3168
9 changed files with 36 additions and 40 deletions
|
@ -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;
|
||||
|
||||
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 )
|
||||
{
|
||||
|
@ -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 )
|
||||
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
@ -720,7 +714,6 @@ char *SDL_JoystickGetGUIDString(JoystickGUID guid)
|
|||
*pchOut++ = k_rgchHexToASCII[ c & 0x0F ];
|
||||
}
|
||||
*pchOut = '\0';
|
||||
return pchString;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -405,9 +405,9 @@ 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 );
|
||||
|
@ -415,9 +415,9 @@ JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
|
|||
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 );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue