Added stubs for simple Steam Controller support

This commit is contained in:
Sam Lantinga
2017-09-22 08:30:52 -07:00
parent 53b2c91d26
commit d828647944
13 changed files with 421 additions and 56 deletions

View File

@@ -26,12 +26,15 @@
/* needed for SDL_IPHONE_MAX_GFORCE macro */
#include "SDL_config_iphoneos.h"
#include "SDL_assert.h"
#include "SDL_events.h"
#include "SDL_joystick.h"
#include "SDL_hints.h"
#include "SDL_stdinc.h"
#include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h"
#include "../steam/SDL_steamcontroller.h"
#if !SDL_EVENTS_DISABLED
#include "../../events/SDL_events_c.h"
@@ -242,7 +245,7 @@ SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device)
--numjoysticks;
SDL_PrivateJoystickRemoved(device->instance_id);
SDL_PrivateJoystickRemoved(device->instance_id);
SDL_free(device->name);
SDL_free(device);
@@ -266,6 +269,50 @@ SDL_AppleTVRemoteRotationHintChanged(void *udata, const char *name, const char *
}
#endif /* TARGET_OS_TV */
static SDL_bool SteamControllerConnectedCallback(const char *name, SDL_JoystickGUID guid, int *device_instance)
{
SDL_JoystickDeviceItem *device = (SDL_JoystickDeviceItem *)SDL_calloc(1, sizeof(SDL_JoystickDeviceItem));
if (device == NULL) {
return SDL_FALSE;
}
*device_instance = device->instance_id = instancecounter++;
device->name = SDL_strdup(name);
device->guid = guid;
SDL_GetSteamControllerInputs(&device->nbuttons,
&device->naxes,
&device->nhats);
device->m_bSteamController = SDL_TRUE;
if (deviceList == NULL) {
deviceList = device;
} else {
SDL_JoystickDeviceItem *lastdevice = deviceList;
while (lastdevice->next != NULL) {
lastdevice = lastdevice->next;
}
lastdevice->next = device;
}
++numjoysticks;
SDL_PrivateJoystickAdded(numjoysticks - 1);
return SDL_TRUE;
}
static void SteamControllerDisconnectedCallback(int device_instance)
{
SDL_JoystickDeviceItem *item;
for (item = deviceList; item; item = item->next) {
if (item->instance_id == device_instance) {
SDL_SYS_RemoveJoystickDevice(item);
break;
}
}
}
/* 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.
@@ -276,6 +323,9 @@ SDL_SYS_JoystickInit(void)
@autoreleasepool {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
SDL_InitSteamControllers(SteamControllerConnectedCallback,
SteamControllerDisconnectedCallback);
#if !TARGET_OS_TV
if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE)) {
/* Default behavior, accelerometer as joystick */
@@ -335,6 +385,7 @@ SDL_SYS_NumJoysticks(void)
void
SDL_SYS_JoystickDetect(void)
{
SDL_UpdateSteamControllers();
}
/* Function to get the device-dependent name of a joystick */
@@ -628,6 +679,11 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
if (device == NULL) {
return;
}
if (device->m_bSteamController) {
SDL_UpdateSteamController(joystick);
return;
}
if (device->accelerometer) {
SDL_SYS_AccelerometerUpdate(joystick);
@@ -696,6 +752,8 @@ SDL_SYS_JoystickQuit(void)
#endif /* !TARGET_OS_TV */
}
SDL_QuitSteamControllers();
numjoysticks = 0;
}

View File

@@ -44,6 +44,9 @@ typedef struct joystick_hwdata
int nbuttons;
int nhats;
/* Steam Controller support */
SDL_bool m_bSteamController;
struct joystick_hwdata *next;
} joystick_hwdata;