Fix joystick support

main
Ivan Epifanov 2020-11-02 19:38:20 +03:00 committed by Sam Lantinga
parent 41d6c80b07
commit 73b545ed28
3 changed files with 60 additions and 49 deletions

View File

@ -95,6 +95,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
#ifdef SDL_JOYSTICK_VIRTUAL #ifdef SDL_JOYSTICK_VIRTUAL
&SDL_VIRTUAL_JoystickDriver, &SDL_VIRTUAL_JoystickDriver,
#endif #endif
#ifdef SDL_JOYSTICK_VITA
&SDL_VITA_JoystickDriver
#endif
#if defined(SDL_JOYSTICK_DUMMY) || defined(SDL_JOYSTICK_DISABLED) #if defined(SDL_JOYSTICK_DUMMY) || defined(SDL_JOYSTICK_DISABLED)
&SDL_DUMMY_JoystickDriver &SDL_DUMMY_JoystickDriver
#endif #endif

View File

@ -206,6 +206,7 @@ extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver;
extern SDL_JoystickDriver SDL_WINMM_JoystickDriver; extern SDL_JoystickDriver SDL_WINMM_JoystickDriver;
extern SDL_JoystickDriver SDL_OS2_JoystickDriver; extern SDL_JoystickDriver SDL_OS2_JoystickDriver;
extern SDL_JoystickDriver SDL_PSP_JoystickDriver; extern SDL_JoystickDriver SDL_PSP_JoystickDriver;
extern SDL_JoystickDriver SDL_VITA_JoystickDriver;
#endif /* SDL_sysjoystick_h_ */ #endif /* SDL_sysjoystick_h_ */

View File

@ -90,7 +90,7 @@ static int calc_bezier_y(float t)
* Joystick 0 should be the system default joystick. * Joystick 0 should be the system default joystick.
* It should return number of joysticks, or -1 on an unrecoverable fatal error. * It should return number of joysticks, or -1 on an unrecoverable fatal error.
*/ */
int SDL_SYS_JoystickInit(void) int VITA_JoystickInit(void)
{ {
int i; int i;
@ -129,38 +129,23 @@ int SDL_SYS_JoystickInit(void)
return SDL_numjoysticks; return SDL_numjoysticks;
} }
int SDL_SYS_NumJoysticks() int VITA_JoystickGetCount()
{ {
return SDL_numjoysticks; return SDL_numjoysticks;
} }
void SDL_SYS_JoystickDetect() void VITA_JoystickDetect()
{ {
} }
/* Function to get the device-dependent name of a joystick */
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
{
if (device_index == 1)
return "PSVita Controller";
if (device_index == 2)
return "PSVita Controller";
if (device_index == 3)
return "PSVita Controller";
return "PSVita Controller";
}
/* Function to perform the mapping from device index to the instance id for this index */ /* Function to perform the mapping from device index to the instance id for this index */
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) SDL_JoystickID VITA_JoystickGetDeviceInstanceID(int device_index)
{ {
return device_index; return device_index;
} }
/* Function to get the device-dependent name of a joystick */ /* Function to get the device-dependent name of a joystick */
const char *SDL_SYS_JoystickName(int index) const char *VITA_JoystickGetDeviceName(int index)
{ {
if (index == 0) if (index == 0)
return "PSVita Controller"; return "PSVita Controller";
@ -178,12 +163,24 @@ const char *SDL_SYS_JoystickName(int index)
return(NULL); return(NULL);
} }
static int
VITA_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
}
static void
VITA_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
}
/* Function to open a joystick for use. /* Function to open a joystick for use.
The joystick to open is specified by the device index. The joystick to open is specified by the device index.
This should fill the nbuttons and naxes fields of the joystick structure. This should fill the nbuttons and naxes fields of the joystick structure.
It returns 0, or -1 if there is an error. It returns 0, or -1 if there is an error.
*/ */
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index) int VITA_JoystickOpen(SDL_Joystick *joystick, int device_index)
{ {
joystick->nbuttons = sizeof(button_map)/sizeof(*button_map); joystick->nbuttons = sizeof(button_map)/sizeof(*button_map);
joystick->naxes = 4; joystick->naxes = 4;
@ -193,18 +190,12 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
return 0; return 0;
} }
/* Function to determine if this joystick is attached to the system right now */
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
{
return SDL_TRUE;
}
/* Function to update the state of a joystick - called as a device poll. /* Function to update the state of a joystick - called as a device poll.
* This function shouldn't update the joystick structure directly, * This function shouldn't update the joystick structure directly,
* but instead should call SDL_PrivateJoystick*() to deliver events * but instead should call SDL_PrivateJoystick*() to deliver events
* and update joystick device state. * and update joystick device state.
*/ */
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) void VITA_JoystickUpdate(SDL_Joystick *joystick)
{ {
int i; int i;
unsigned int buttons; unsigned int buttons;
@ -275,35 +266,51 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
} }
/* Function to close a joystick after use */ /* Function to close a joystick after use */
void SDL_SYS_JoystickClose(SDL_Joystick *joystick) void VITA_JoystickClose(SDL_Joystick *joystick)
{ {
} }
/* Function to perform any system-specific joystick related cleanup */ /* Function to perform any system-specific joystick related cleanup */
void SDL_SYS_JoystickQuit(void) void VITA_JoystickQuit(void)
{ {
} }
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) SDL_JoystickGUID VITA_JoystickGetDeviceGUID( int device_index )
{ {
SDL_JoystickGUID guid; SDL_JoystickGUID guid;
/* the GUID is just the first 16 chars of the name for now */ /* the GUID is just the first 16 chars of the name for now */
const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index ); const char *name = VITA_JoystickGetDeviceName( device_index );
SDL_zero( guid ); SDL_zero( guid );
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
return guid; return guid;
} }
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) static int
VITA_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{ {
SDL_JoystickGUID guid; return SDL_Unsupported();
/* 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;
} }
SDL_JoystickDriver SDL_VITA_JoystickDriver =
{
VITA_JoystickInit,
VITA_JoystickGetCount,
VITA_JoystickDetect,
VITA_JoystickGetDeviceName,
VITA_JoystickGetDevicePlayerIndex,
VITA_JoystickSetDevicePlayerIndex,
VITA_JoystickGetDeviceGUID,
VITA_JoystickGetDeviceInstanceID,
VITA_JoystickOpen,
VITA_JoystickRumble,
VITA_JoystickUpdate,
VITA_JoystickClose,
VITA_JoystickQuit,
};
#endif /* SDL_JOYSTICK_VITA */ #endif /* SDL_JOYSTICK_VITA */
/* vim: ts=4 sw=4 /* vim: ts=4 sw=4