move outdated winmm and psp joystick codes to struct _SDL_JoystickDriver

build-tested only. (bug #5472.)
This commit is contained in:
Ozkan Sezer 2021-01-23 17:30:50 +03:00
parent 8f1025899a
commit fd65aaa9a8
4 changed files with 198 additions and 80 deletions

View File

@ -62,6 +62,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
&SDL_WINDOWS_JoystickDriver,
#endif
#if defined(SDL_JOYSTICK_WINMM)
&SDL_WINMM_JoystickDriver,
#endif
#ifdef SDL_JOYSTICK_LINUX
&SDL_LINUX_JoystickDriver,
#endif
@ -86,6 +89,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
#ifdef SDL_JOYSTICK_OS2
&SDL_OS2_JoystickDriver,
#endif
#ifdef SDL_JOYSTICK_PSP
&SDL_PSP_JoystickDriver,
#endif
#ifdef SDL_JOYSTICK_VIRTUAL
&SDL_VIRTUAL_JoystickDriver,
#endif
@ -343,7 +349,7 @@ SDL_JoystickAxesCenteredAtZero(SDL_Joystick *joystick)
Uint32 id = MAKE_VIDPID(SDL_JoystickGetVendor(joystick),
SDL_JoystickGetProduct(joystick));
/*printf("JOYSTICK '%s' VID/PID 0x%.4x/0x%.4x AXES: %d\n", joystick->name, vendor, product, joystick->naxes);*/
/*printf("JOYSTICK '%s' VID/PID 0x%.4x/0x%.4x AXES: %d\n", joystick->name, vendor, product, joystick->naxes);*/
if (joystick->naxes == 2) {
/* Assume D-pad or thumbstick style axes are centered at 0 */
@ -1249,7 +1255,6 @@ SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick)
SDL_PrivateJoystickTouchpad(joystick, i, j, SDL_RELEASED, 0.0f, 0.0f, 0.0f);
}
}
}
void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)

View File

@ -24,7 +24,6 @@
#define SDL_sysjoystick_h_
/* This is the system specific header for the SDL joystick API */
#include "SDL_joystick.h"
#include "SDL_joystick_c.h"
@ -204,7 +203,9 @@ extern SDL_JoystickDriver SDL_LINUX_JoystickDriver;
extern SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver;
extern SDL_JoystickDriver SDL_WGI_JoystickDriver;
extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver;
extern SDL_JoystickDriver SDL_WINMM_JoystickDriver;
extern SDL_JoystickDriver SDL_OS2_JoystickDriver;
extern SDL_JoystickDriver SDL_PSP_JoystickDriver;
#endif /* SDL_sysjoystick_h_ */

View File

@ -103,7 +103,7 @@ int JoystickUpdate(void *data)
* Joystick 0 should be the system default joystick.
* It should return number of joysticks, or -1 on an unrecoverable fatal error.
*/
int SDL_SYS_JoystickInit(void)
static int PSP_JoystickInit(void)
{
int i;
@ -132,35 +132,55 @@ int SDL_SYS_JoystickInit(void)
return 1;
}
int SDL_SYS_NumJoysticks(void)
static int PSP_NumJoysticks(void)
{
return 1;
}
void SDL_SYS_JoystickDetect(void)
static void PSP_JoystickDetect(void)
{
}
#if 0
/* Function to get the device-dependent name of a joystick */
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
static const char *PSP_JoystickName(int idx)
{
if (idx == 0) return "PSP controller";
SDL_SetError("No joystick available with that index");
return NULL;
}
#endif
/* Function to get the device-dependent name of a joystick */
static const char *PSP_JoystickGetDeviceName(int device_index)
{
return "PSP builtin joypad";
}
/* Function to perform the mapping from device index to the instance id for this index */
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
static int PSP_JoystickGetDevicePlayerIndex(int device_index)
{
return device_index;
return -1;
}
/* Function to get the device-dependent name of a joystick */
const char *SDL_SYS_JoystickName(int index)
static void
PSP_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
if (index == 0)
return "PSP controller";
}
SDL_SetError("No joystick available with that index");
return(NULL);
static SDL_JoystickGUID PSP_JoystickGetDeviceGUID(int device_index)
{
SDL_JoystickGUID guid;
/* the GUID is just the first 16 chars of the name for now */
const char *name = PSP_JoystickGetDeviceName(device_index);
SDL_zero(guid);
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
return guid;
}
/* Function to perform the mapping from device index to the instance id for this index */
static SDL_JoystickID PSP_JoystickGetDeviceInstanceID(int device_index)
{
return device_index;
}
/* Function to open a joystick for use.
@ -168,7 +188,7 @@ const char *SDL_SYS_JoystickName(int index)
This should fill the nbuttons and naxes fields of the joystick structure.
It returns 0, or -1 if there is an error.
*/
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
static int PSP_JoystickOpen(SDL_Joystick *joystick, int device_index)
{
joystick->nbuttons = 14;
joystick->naxes = 2;
@ -177,12 +197,40 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
return 0;
}
static int
PSP_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
return SDL_Unsupported();
}
static int
PSP_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
{
return SDL_Unsupported();
}
static SDL_bool PSP_JoystickHasLED(SDL_Joystick *joystick)
{
return SDL_FALSE;
}
static int
PSP_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
return SDL_Unsupported();
}
static int PSP_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
{
return SDL_Unsupported();
}
/* Function to update the state of a joystick - called as a device poll.
* This function shouldn't update the joystick structure directly,
* but instead should call SDL_PrivateJoystick*() to deliver events
* and update joystick device state.
*/
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
static void PSP_JoystickUpdate(SDL_Joystick *joystick)
{
int i;
enum PspCtrlButtons buttons;
@ -225,12 +273,12 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
}
/* Function to close a joystick after use */
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
static void PSP_JoystickClose(SDL_Joystick *joystick)
{
}
/* Function to perform any system-specific joystick related cleanup */
void SDL_SYS_JoystickQuit(void)
static void PSP_JoystickQuit(void)
{
/* Cleanup Threads and Semaphore. */
running = 0;
@ -238,25 +286,33 @@ void SDL_SYS_JoystickQuit(void)
SDL_DestroySemaphore(pad_sem);
}
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
static SDL_bool
PSP_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
{
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;
return SDL_FALSE;
}
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
SDL_JoystickDriver SDL_PSP_JoystickDriver =
{
SDL_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;
}
PSP_JoystickInit,
PSP_NumJoysticks,
PSP_JoystickDetect,
PSP_JoystickGetDeviceName,
PSP_JoystickGetDevicePlayerIndex,
PSP_JoystickSetDevicePlayerIndex,
PSP_JoystickGetDeviceGUID,
PSP_JoystickGetDeviceInstanceID,
PSP_JoystickOpen,
PSP_JoystickRumble,
PSP_JoystickRumbleTriggers,
PSP_JoystickHasLED,
PSP_JoystickSetLED,
PSP_JoystickSetSensorsEnabled,
PSP_JoystickUpdate,
PSP_JoystickClose,
PSP_JoystickQuit,
PSP_JoystickGetGamepadMapping
};
#endif /* SDL_JOYSTICK_PSP */

View File

@ -146,14 +146,14 @@ GetJoystickName(int index, const char *szRegKey)
return (name);
}
static int SDL_SYS_numjoysticks = 0;
static int numjoysticks = 0;
/* Function to scan the system for joysticks.
* Joystick 0 should be the system default joystick.
* It should return 0, or -1 on an unrecoverable fatal error.
*/
int
SDL_SYS_JoystickInit(void)
static int
WINMM_JoystickInit(void)
{
int i;
int maxdevs;
@ -168,9 +168,9 @@ SDL_SYS_JoystickInit(void)
}
/* Loop over all potential joystick devices */
SDL_SYS_numjoysticks = 0;
numjoysticks = 0;
maxdevs = joyGetNumDevs();
for (i = JOYSTICKID1; i < maxdevs && SDL_SYS_numjoysticks < MAX_JOYSTICKS; ++i) {
for (i = JOYSTICKID1; i < maxdevs && numjoysticks < MAX_JOYSTICKS; ++i) {
joyinfo.dwSize = sizeof(joyinfo);
joyinfo.dwFlags = JOY_RETURNALL;
@ -178,31 +178,31 @@ SDL_SYS_JoystickInit(void)
if (result == JOYERR_NOERROR) {
result = joyGetDevCapsA(i, &joycaps, sizeof(joycaps));
if (result == JOYERR_NOERROR) {
SYS_JoystickID[SDL_SYS_numjoysticks] = i;
SYS_Joystick[SDL_SYS_numjoysticks] = joycaps;
SYS_JoystickName[SDL_SYS_numjoysticks] =
SYS_JoystickID[numjoysticks] = i;
SYS_Joystick[numjoysticks] = joycaps;
SYS_JoystickName[numjoysticks] =
GetJoystickName(i, joycaps.szRegKey);
SDL_SYS_numjoysticks++;
numjoysticks++;
}
}
}
return (SDL_SYS_numjoysticks);
return numjoysticks;
}
int
SDL_SYS_NumJoysticks(void)
static int
WINMM_NumJoysticks(void)
{
return SDL_SYS_numjoysticks;
return numjoysticks;
}
void
SDL_SYS_JoystickDetect(void)
static void
WINMM_JoystickDetect(void)
{
}
/* Function to get the device-dependent name of a joystick */
const char *
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
static const char *
WINMM_JoystickGetDeviceName(int device_index)
{
if (SYS_JoystickName[device_index] != NULL) {
return (SYS_JoystickName[device_index]);
@ -211,8 +211,29 @@ SDL_SYS_JoystickNameForDeviceIndex(int device_index)
}
}
static int
WINMM_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
}
static void
WINMM_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
}
static SDL_JoystickGUID WINMM_JoystickGetDeviceGUID(int device_index)
{
SDL_JoystickGUID guid;
/* the GUID is just the first 16 chars of the name for now */
const char *name = WINMM_JoystickGetDeviceName(device_index);
SDL_zero(guid);
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
return guid;
}
/* Function to perform the mapping from device index to the instance id for this index */
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
static SDL_JoystickID WINMM_JoystickGetDeviceInstanceID(int device_index)
{
return device_index;
}
@ -222,15 +243,14 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
This should fill the nbuttons and naxes fields of the joystick structure.
It returns 0, or -1 if there is an error.
*/
int
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
static int
WINMM_JoystickOpen(SDL_Joystick * joystick, int device_index)
{
int index, i;
int caps_flags[MAX_AXES - 2] =
{ JOYCAPS_HASZ, JOYCAPS_HASR, JOYCAPS_HASU, JOYCAPS_HASV };
int axis_min[MAX_AXES], axis_max[MAX_AXES];
/* shortcut */
index = device_index;
axis_min[0] = SYS_Joystick[index].wXmin;
@ -302,13 +322,41 @@ TranslatePOV(DWORD value)
return (pos);
}
static int
WINMM_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
return SDL_Unsupported();
}
static int
WINMM_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
{
return SDL_Unsupported();
}
static SDL_bool WINMM_JoystickHasLED(SDL_Joystick *joystick)
{
return SDL_FALSE;
}
static int
WINMM_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
return SDL_Unsupported();
}
static int WINMM_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
{
return SDL_Unsupported();
}
/* Function to update the state of a joystick - called as a device poll.
* This function shouldn't update the joystick structure directly,
* but instead should call SDL_PrivateJoystick*() to deliver events
* and update joystick device state.
*/
void
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
static void
WINMM_JoystickUpdate(SDL_Joystick * joystick)
{
MMRESULT result;
int i;
@ -365,15 +413,15 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
}
/* Function to close a joystick after use */
void
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
static void
WINMM_JoystickClose(SDL_Joystick * joystick)
{
SDL_free(joystick->hwdata);
}
/* Function to perform any system-specific joystick related cleanup */
void
SDL_SYS_JoystickQuit(void)
static void
WINMM_JoystickQuit(void)
{
int i;
for (i = 0; i < MAX_JOYSTICKS; i++) {
@ -382,24 +430,10 @@ SDL_SYS_JoystickQuit(void)
}
}
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
static SDL_bool
WINMM_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
{
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;
}
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
SDL_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;
return SDL_FALSE;
}
@ -447,6 +481,28 @@ SetMMerror(char *function, int code)
SDL_SetError("%s", errbuf);
}
SDL_JoystickDriver SDL_WINMM_JoystickDriver =
{
WINMM_JoystickInit,
WINMM_NumJoysticks,
WINMM_JoystickDetect,
WINMM_JoystickGetDeviceName,
WINMM_JoystickGetDevicePlayerIndex,
WINMM_JoystickSetDevicePlayerIndex,
WINMM_JoystickGetDeviceGUID,
WINMM_JoystickGetDeviceInstanceID,
WINMM_JoystickOpen,
WINMM_JoystickRumble,
WINMM_JoystickRumbleTriggers,
WINMM_JoystickHasLED,
WINMM_JoystickSetLED,
WINMM_JoystickSetSensorsEnabled,
WINMM_JoystickUpdate,
WINMM_JoystickClose,
WINMM_JoystickQuit,
WINMM_JoystickGetGamepadMapping
};
#endif /* SDL_JOYSTICK_WINMM */
/* vi: set ts=4 sw=4 expandtab: */