early-access version 2281
This commit is contained in:
@@ -155,7 +155,7 @@ SDL_SYS_HapticOpen(SDL_Haptic *haptic)
|
||||
int
|
||||
SDL_SYS_HapticMouse(void)
|
||||
{
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -653,7 +653,7 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
|
||||
return SDL_SYS_HapticOpenFromService(haptic, joystick->hwdata->ffservice);
|
||||
#else
|
||||
return -1;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
17
externals/SDL/src/haptic/linux/SDL_syshaptic.c
vendored
17
externals/SDL/src/haptic/linux/SDL_syshaptic.c
vendored
@@ -35,7 +35,6 @@
|
||||
#include <fcntl.h> /* O_RDWR */
|
||||
#include <limits.h> /* INT_MAX */
|
||||
#include <errno.h> /* errno, strerror */
|
||||
#include <math.h> /* atan2 */
|
||||
#include <sys/stat.h> /* stat */
|
||||
|
||||
/* Just in case. */
|
||||
@@ -166,7 +165,7 @@ SDL_SYS_HapticInit(void)
|
||||
i = 0;
|
||||
for (j = 0; j < MAX_HAPTICS; ++j) {
|
||||
|
||||
snprintf(path, PATH_MAX, joydev_pattern, i++);
|
||||
SDL_snprintf(path, PATH_MAX, joydev_pattern, i++);
|
||||
MaybeAddDevice(path);
|
||||
}
|
||||
|
||||
@@ -260,7 +259,7 @@ MaybeAddDevice(const char *path)
|
||||
}
|
||||
|
||||
/* try to open */
|
||||
fd = open(path, O_RDWR, 0);
|
||||
fd = open(path, O_RDWR | O_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -375,7 +374,7 @@ SDL_SYS_HapticName(int index)
|
||||
item = HapticByDevIndex(index);
|
||||
/* Open the haptic device. */
|
||||
name = NULL;
|
||||
fd = open(item->fname, O_RDONLY, 0);
|
||||
fd = open(item->fname, O_RDONLY | O_CLOEXEC, 0);
|
||||
|
||||
if (fd >= 0) {
|
||||
|
||||
@@ -453,7 +452,7 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic)
|
||||
|
||||
item = HapticByDevIndex(haptic->index);
|
||||
/* Open the character device */
|
||||
fd = open(item->fname, O_RDWR, 0);
|
||||
fd = open(item->fname, O_RDWR | O_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
return SDL_SetError("Haptic: Unable to open %s: %s",
|
||||
item->fname, strerror(errno));
|
||||
@@ -483,7 +482,7 @@ SDL_SYS_HapticMouse(void)
|
||||
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
/* Open the device. */
|
||||
fd = open(item->fname, O_RDWR, 0);
|
||||
fd = open(item->fname, O_RDWR | O_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
return SDL_SetError("Haptic: Unable to open %s: %s",
|
||||
item->fname, strerror(errno));
|
||||
@@ -570,7 +569,7 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
return SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities");
|
||||
}
|
||||
|
||||
fd = open(joystick->hwdata->fname, O_RDWR, 0);
|
||||
fd = open(joystick->hwdata->fname, O_RDWR | O_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
return SDL_SetError("Haptic: Unable to open %s: %s",
|
||||
joystick->hwdata->fname, strerror(errno));
|
||||
@@ -713,10 +712,10 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
|
||||
else {
|
||||
float f = SDL_atan2(src->dir[1], src->dir[0]); /* Ideally we'd use fixed point math instead of floats... */
|
||||
/*
|
||||
atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
|
||||
SDL_atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
|
||||
- Y-axis-value is the second coordinate (from center to SOUTH)
|
||||
- X-axis-value is the first coordinate (from center to EAST)
|
||||
We add 36000, because atan2 also returns negative values. Then we practically
|
||||
We add 36000, because SDL_atan2 also returns negative values. Then we practically
|
||||
have the first spherical value. Therefore we proceed as in case
|
||||
SDL_HAPTIC_SPHERICAL and add another 9000 to get the polar value.
|
||||
--> add 45000 in total
|
||||
|
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_haptic.h"
|
||||
#include "../SDL_syshaptic.h"
|
||||
@@ -70,6 +71,7 @@ SDL_DINPUT_HapticInit(void)
|
||||
{
|
||||
HRESULT ret;
|
||||
HINSTANCE instance;
|
||||
DWORD devClass;
|
||||
|
||||
if (dinput != NULL) { /* Already open. */
|
||||
return SDL_SetError("Haptic: SubSystem already open.");
|
||||
@@ -103,16 +105,24 @@ SDL_DINPUT_HapticInit(void)
|
||||
}
|
||||
|
||||
/* Look for haptic devices. */
|
||||
ret = IDirectInput8_EnumDevices(dinput,
|
||||
0,
|
||||
EnumHapticsCallback,
|
||||
NULL,
|
||||
DIEDFL_FORCEFEEDBACK |
|
||||
DIEDFL_ATTACHEDONLY);
|
||||
if (FAILED(ret)) {
|
||||
SDL_SYS_HapticQuit();
|
||||
return DI_SetError("Enumerating DirectInput devices", ret);
|
||||
for (devClass = DI8DEVCLASS_DEVICE; devClass <= DI8DEVCLASS_GAMECTRL; devClass++) {
|
||||
if (devClass == DI8DEVCLASS_GAMECTRL && SDL_WasInit(SDL_INIT_JOYSTICK)) {
|
||||
/* The joystick subsystem will manage adding DInput joystick haptic devices */
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = IDirectInput8_EnumDevices(dinput,
|
||||
devClass,
|
||||
EnumHapticsCallback,
|
||||
NULL,
|
||||
DIEDFL_FORCEFEEDBACK |
|
||||
DIEDFL_ATTACHEDONLY);
|
||||
if (FAILED(ret)) {
|
||||
SDL_SYS_HapticQuit();
|
||||
return DI_SetError("Enumerating DirectInput devices", ret);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -52,12 +52,28 @@ static int numhaptics = 0;
|
||||
int
|
||||
SDL_SYS_HapticInit(void)
|
||||
{
|
||||
JoyStick_DeviceData* device;
|
||||
|
||||
if (SDL_DINPUT_HapticInit() < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (SDL_XINPUT_HapticInit() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* The joystick subsystem will usually be initialized before haptics,
|
||||
* so the initial HapticMaybeAddDevice() calls from the joystick
|
||||
* subsystem will arrive too early to create haptic devices. We will
|
||||
* invoke those callbacks again here to pick up any joysticks that
|
||||
* were added prior to haptics initialization. */
|
||||
for (device = SYS_Joystick; device; device = device->pNext) {
|
||||
if (device->bXInputDevice) {
|
||||
SDL_XINPUT_HapticMaybeAddDevice(device->XInputUserId);
|
||||
} else {
|
||||
SDL_DINPUT_HapticMaybeAddDevice(&device->dxdevice);
|
||||
}
|
||||
}
|
||||
|
||||
return numhaptics;
|
||||
}
|
||||
|
||||
|
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_haptic.h"
|
||||
#include "../SDL_syshaptic.h"
|
||||
@@ -47,7 +48,8 @@ SDL_XINPUT_HapticInit(void)
|
||||
loaded_xinput = (WIN_LoadXInputDLL() == 0);
|
||||
}
|
||||
|
||||
if (loaded_xinput) {
|
||||
/* If the joystick subsystem is active, it will manage adding XInput haptic devices */
|
||||
if (loaded_xinput && !SDL_WasInit(SDL_INIT_JOYSTICK)) {
|
||||
DWORD i;
|
||||
for (i = 0; i < XUSER_MAX_COUNT; i++) {
|
||||
SDL_XINPUT_HapticMaybeAddDevice(i);
|
||||
|
Reference in New Issue
Block a user