mirror of
https://github.com/InoriRus/Kyty.git
synced 2026-08-28 13:16:40 +00:00
release 0.1.0
This commit is contained in:
+5
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -23,10 +23,13 @@
|
||||
#include "SDL_syshaptic.h"
|
||||
#include "SDL_haptic_c.h"
|
||||
#include "../joystick/SDL_joystick_c.h" /* For SDL_PrivateJoystickValid */
|
||||
#include "SDL_assert.h"
|
||||
|
||||
/* Global for SDL_windowshaptic.c */
|
||||
#if (defined(SDL_HAPTIC_DINPUT) && SDL_HAPTIC_DINPUT) || (defined(SDL_HAPTIC_XINPUT) && SDL_HAPTIC_XINPUT)
|
||||
SDL_Haptic *SDL_haptics = NULL;
|
||||
#else
|
||||
static SDL_Haptic *SDL_haptics = NULL;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Initializes the Haptic devices.
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
+2
-3
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#ifdef SDL_HAPTIC_ANDROID
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_syshaptic_c.h"
|
||||
#include "../SDL_syshaptic.h"
|
||||
@@ -156,7 +155,7 @@ SDL_SYS_HapticOpen(SDL_Haptic *haptic)
|
||||
int
|
||||
SDL_SYS_HapticMouse(void)
|
||||
{
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+29
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -22,13 +22,12 @@
|
||||
|
||||
#ifdef SDL_HAPTIC_IOKIT
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_haptic.h"
|
||||
#include "../SDL_syshaptic.h"
|
||||
#include "SDL_joystick.h"
|
||||
#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
|
||||
#include "../../joystick/darwin/SDL_sysjoystick_c.h" /* For joystick hwdata */
|
||||
#include "../../joystick/darwin/SDL_iokitjoystick_c.h" /* For joystick hwdata */
|
||||
#include "SDL_syshaptic_c.h"
|
||||
|
||||
#include <IOKit/IOKitLib.h>
|
||||
@@ -599,9 +598,14 @@ SDL_SYS_HapticMouse(void)
|
||||
int
|
||||
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_IOKIT
|
||||
if (joystick->driver != &SDL_DARWIN_JoystickDriver) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (joystick->hwdata->ffservice != 0) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
#endif
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -612,10 +616,15 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
||||
int
|
||||
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_IOKIT
|
||||
if (joystick->driver != &SDL_DARWIN_JoystickDriver) {
|
||||
return 0;
|
||||
}
|
||||
if (IOObjectIsEqualTo((io_object_t) ((size_t)haptic->hwdata->device),
|
||||
joystick->hwdata->ffservice)) {
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -626,9 +635,13 @@ SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int
|
||||
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_IOKIT
|
||||
int device_index = 0;
|
||||
SDL_hapticlist_item *item;
|
||||
|
||||
|
||||
if (joystick->driver != &SDL_DARWIN_JoystickDriver) {
|
||||
return -1;
|
||||
}
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
if (IOObjectIsEqualTo((io_object_t) item->dev,
|
||||
joystick->hwdata->ffservice)) {
|
||||
@@ -639,6 +652,9 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
}
|
||||
|
||||
return SDL_SYS_HapticOpenFromService(haptic, joystick->hwdata->ffservice);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -756,6 +772,10 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
||||
rglDir[2] = dir->dir[2];
|
||||
}
|
||||
return 0;
|
||||
case SDL_HAPTIC_STEERING_AXIS:
|
||||
effect->dwFlags |= FFEFF_CARTESIAN;
|
||||
rglDir[0] = 0;
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return SDL_SetError("Haptic: Unknown direction type.");
|
||||
@@ -804,7 +824,11 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
||||
envelope->dwSize = sizeof(FFENVELOPE); /* Always should be this. */
|
||||
|
||||
/* Axes. */
|
||||
dest->cAxes = haptic->naxes;
|
||||
if (src->constant.direction.type == SDL_HAPTIC_STEERING_AXIS) {
|
||||
dest->cAxes = 1;
|
||||
} else {
|
||||
dest->cAxes = haptic->naxes;
|
||||
}
|
||||
if (dest->cAxes > 0) {
|
||||
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
|
||||
if (axes == NULL) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
+36
-18
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -22,12 +22,12 @@
|
||||
|
||||
#ifdef SDL_HAPTIC_LINUX
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_haptic.h"
|
||||
#include "../SDL_syshaptic.h"
|
||||
#include "SDL_joystick.h"
|
||||
#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
|
||||
#include "../../joystick/linux/SDL_sysjoystick_c.h" /* For joystick hwdata */
|
||||
#include "../../core/linux/SDL_evdev_capabilities.h"
|
||||
#include "../../core/linux/SDL_udev.h"
|
||||
|
||||
#include <unistd.h> /* close */
|
||||
@@ -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. */
|
||||
@@ -86,8 +85,6 @@ static SDL_hapticlist_item *SDL_hapticlist = NULL;
|
||||
static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
|
||||
static int numhaptics = 0;
|
||||
|
||||
#define test_bit(nr, addr) \
|
||||
(((1UL << ((nr) & 31)) & (((const unsigned int *) addr)[(nr) >> 5])) != 0)
|
||||
#define EV_TEST(ev,f) \
|
||||
if (test_bit((ev), features)) ret |= (f);
|
||||
/*
|
||||
@@ -168,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);
|
||||
}
|
||||
|
||||
@@ -262,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;
|
||||
}
|
||||
@@ -377,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) {
|
||||
|
||||
@@ -455,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));
|
||||
@@ -485,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));
|
||||
@@ -512,7 +509,15 @@ SDL_SYS_HapticMouse(void)
|
||||
int
|
||||
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
||||
{
|
||||
return EV_IsHaptic(joystick->hwdata->fd);
|
||||
#ifdef SDL_JOYSTICK_LINUX
|
||||
if (joystick->driver != &SDL_LINUX_JoystickDriver) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (EV_IsHaptic(joystick->hwdata->fd)) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
#endif
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -522,11 +527,16 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
|
||||
int
|
||||
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_LINUX
|
||||
if (joystick->driver != &SDL_LINUX_JoystickDriver) {
|
||||
return 0;
|
||||
}
|
||||
/* We are assuming Linux is using evdev which should trump the old
|
||||
* joystick methods. */
|
||||
if (SDL_strcmp(joystick->hwdata->fname, haptic->hwdata->fname) == 0) {
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -537,11 +547,15 @@ SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
int
|
||||
SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_LINUX
|
||||
int device_index = 0;
|
||||
int fd;
|
||||
int ret;
|
||||
SDL_hapticlist_item *item;
|
||||
|
||||
|
||||
if (joystick->driver != &SDL_LINUX_JoystickDriver) {
|
||||
return -1;
|
||||
}
|
||||
/* Find the joystick in the haptic list. */
|
||||
for (item = SDL_hapticlist; item; item = item->next) {
|
||||
if (SDL_strcmp(item->fname, joystick->hwdata->fname) == 0) {
|
||||
@@ -555,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));
|
||||
@@ -568,6 +582,9 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
haptic->hwdata->fname = SDL_strdup( joystick->hwdata->fname );
|
||||
|
||||
return 0;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -695,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
|
||||
@@ -709,7 +726,9 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
|
||||
*dest = (Uint16) tmp;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_HAPTIC_STEERING_AXIS:
|
||||
*dest = 0x4000;
|
||||
break;
|
||||
default:
|
||||
return SDL_SetError("Haptic: Unsupported direction type.");
|
||||
}
|
||||
@@ -801,8 +820,7 @@ SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
|
||||
else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN)
|
||||
dest->u.periodic.waveform = FF_SAW_DOWN;
|
||||
dest->u.periodic.period = CLAMP(periodic->period);
|
||||
/* Linux expects 0-65535, so multiply by 2 */
|
||||
dest->u.periodic.magnitude = CLAMP(periodic->magnitude) * 2;
|
||||
dest->u.periodic.magnitude = periodic->magnitude;
|
||||
dest->u.periodic.offset = periodic->offset;
|
||||
/* Linux phase is defined in interval "[0x0000, 0x10000[", corresponds with "[0deg, 360deg[" phase shift. */
|
||||
dest->u.periodic.phase = ((Uint32)periodic->phase * 0x10000U) / 36000;
|
||||
|
||||
+40
-40
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_haptic.h"
|
||||
#include "../SDL_syshaptic.h"
|
||||
@@ -51,10 +52,6 @@ static LPDIRECTINPUT8 dinput = NULL;
|
||||
static int
|
||||
DI_SetError(const char *str, HRESULT err)
|
||||
{
|
||||
/*
|
||||
SDL_SetError("Haptic: %s - %s: %s", str,
|
||||
DXGetErrorString8A(err), DXGetErrorDescription8A(err));
|
||||
*/
|
||||
return SDL_SetError("Haptic error %s", str);
|
||||
}
|
||||
|
||||
@@ -65,7 +62,7 @@ static BOOL CALLBACK
|
||||
EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
|
||||
{
|
||||
(void) pContext;
|
||||
SDL_DINPUT_MaybeAddDevice(pdidInstance);
|
||||
SDL_DINPUT_HapticMaybeAddDevice(pdidInstance);
|
||||
return DIENUM_CONTINUE; /* continue enumerating */
|
||||
}
|
||||
|
||||
@@ -74,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.");
|
||||
@@ -87,7 +85,7 @@ SDL_DINPUT_HapticInit(void)
|
||||
coinitialized = SDL_TRUE;
|
||||
|
||||
ret = CoCreateInstance(&CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER,
|
||||
&IID_IDirectInput8, (LPVOID)& dinput);
|
||||
&IID_IDirectInput8, (LPVOID *) &dinput);
|
||||
if (FAILED(ret)) {
|
||||
SDL_SYS_HapticQuit();
|
||||
return DI_SetError("CoCreateInstance", ret);
|
||||
@@ -107,21 +105,29 @@ 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;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
{
|
||||
HRESULT ret;
|
||||
LPDIRECTINPUTDEVICE8 device;
|
||||
@@ -180,7 +186,7 @@ SDL_DINPUT_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_MaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
{
|
||||
SDL_hapticlist_item *item;
|
||||
SDL_hapticlist_item *prev = NULL;
|
||||
@@ -423,7 +429,6 @@ SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
|
||||
{
|
||||
HRESULT ret;
|
||||
LPDIRECTINPUTDEVICE8 device;
|
||||
LPDIRECTINPUTDEVICE8 device8;
|
||||
|
||||
/* Open the device */
|
||||
ret = IDirectInput8_CreateDevice(dinput, &item->instance.guidInstance,
|
||||
@@ -433,19 +438,8 @@ SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Now get the IDirectInputDevice8 interface, instead. */
|
||||
ret = IDirectInputDevice8_QueryInterface(device,
|
||||
&IID_IDirectInputDevice8,
|
||||
(LPVOID *)&device8);
|
||||
/* Done with the temporary one now. */
|
||||
IDirectInputDevice8_Release(device);
|
||||
if (FAILED(ret)) {
|
||||
DI_SetError("Querying DirectInput interface", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (SDL_DINPUT_HapticOpenFromDevice(haptic, device8, SDL_FALSE) < 0) {
|
||||
IDirectInputDevice8_Release(device8);
|
||||
if (SDL_DINPUT_HapticOpenFromDevice(haptic, device, SDL_FALSE) < 0) {
|
||||
IDirectInputDevice8_Release(device);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -498,8 +492,7 @@ SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
++index;
|
||||
}
|
||||
|
||||
SDL_SetError("Couldn't find joystick in haptic device list");
|
||||
return -1;
|
||||
return SDL_SetError("Couldn't find joystick in haptic device list");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -589,6 +582,10 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
|
||||
if (naxes > 2)
|
||||
rglDir[2] = dir->dir[2];
|
||||
return 0;
|
||||
case SDL_HAPTIC_STEERING_AXIS:
|
||||
effect->dwFlags |= DIEFF_CARTESIAN;
|
||||
rglDir[0] = 0;
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return SDL_SetError("Haptic: Unknown direction type.");
|
||||
@@ -637,7 +634,11 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
||||
envelope->dwSize = sizeof(DIENVELOPE); /* Always should be this. */
|
||||
|
||||
/* Axes. */
|
||||
dest->cAxes = haptic->naxes;
|
||||
if (src->constant.direction.type == SDL_HAPTIC_STEERING_AXIS) {
|
||||
dest->cAxes = 1;
|
||||
} else {
|
||||
dest->cAxes = haptic->naxes;
|
||||
}
|
||||
if (dest->cAxes > 0) {
|
||||
axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
|
||||
if (axes == NULL) {
|
||||
@@ -709,7 +710,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
||||
/* Specifics */
|
||||
periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
|
||||
periodic->lOffset = CONVERT(hap_periodic->offset);
|
||||
periodic->dwPhase =
|
||||
periodic->dwPhase =
|
||||
(hap_periodic->phase + (hap_periodic->magnitude < 0 ? 18000 : 0)) % 36000;
|
||||
periodic->dwPeriod = hap_periodic->period * 1000;
|
||||
dest->cbTypeSpecificParams = sizeof(DIPERIODIC);
|
||||
@@ -957,8 +958,7 @@ SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SD
|
||||
REFGUID type = SDL_SYS_HapticEffectType(base);
|
||||
|
||||
if (type == NULL) {
|
||||
SDL_SetError("Haptic: Unknown effect type.");
|
||||
return -1;
|
||||
return SDL_SetError("Haptic: Unknown effect type.");
|
||||
}
|
||||
|
||||
/* Get the effect. */
|
||||
@@ -1196,13 +1196,13 @@ SDL_DINPUT_HapticInit(void)
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_DINPUT_MaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
|
||||
extern int SDL_DINPUT_HapticInit(void);
|
||||
extern int SDL_DINPUT_MaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance);
|
||||
extern int SDL_DINPUT_MaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance);
|
||||
extern int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance);
|
||||
extern int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance);
|
||||
extern int SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item);
|
||||
extern int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick);
|
||||
extern int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick);
|
||||
|
||||
+17
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#if SDL_HAPTIC_DINPUT || SDL_HAPTIC_XINPUT
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_timer.h"
|
||||
@@ -53,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -50,6 +50,7 @@ struct haptic_hwdata
|
||||
/*
|
||||
* Haptic system effect data.
|
||||
*/
|
||||
#if SDL_HAPTIC_DINPUT || SDL_HAPTIC_XINPUT
|
||||
struct haptic_hweffect
|
||||
{
|
||||
#if SDL_HAPTIC_DINPUT
|
||||
@@ -60,6 +61,7 @@ struct haptic_hweffect
|
||||
XINPUT_VIBRATION vibration;
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* List of available haptic devices.
|
||||
|
||||
+10
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -20,13 +20,13 @@
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_haptic.h"
|
||||
#include "../SDL_syshaptic.h"
|
||||
|
||||
#if SDL_HAPTIC_XINPUT
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_windowshaptic_c.h"
|
||||
@@ -48,17 +48,18 @@ 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_MaybeAddDevice(i);
|
||||
SDL_XINPUT_HapticMaybeAddDevice(i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_MaybeAddDevice(const DWORD dwUserid)
|
||||
SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
|
||||
{
|
||||
const Uint8 userid = (Uint8)dwUserid;
|
||||
SDL_hapticlist_item *item;
|
||||
@@ -107,7 +108,7 @@ SDL_XINPUT_MaybeAddDevice(const DWORD dwUserid)
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_MaybeRemoveDevice(const DWORD dwUserid)
|
||||
SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid)
|
||||
{
|
||||
const Uint8 userid = (Uint8)dwUserid;
|
||||
SDL_hapticlist_item *item;
|
||||
@@ -245,8 +246,7 @@ SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
||||
++index;
|
||||
}
|
||||
|
||||
SDL_SetError("Couldn't find joystick in haptic device list");
|
||||
return -1;
|
||||
return SDL_SetError("Couldn't find joystick in haptic device list");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -378,13 +378,13 @@ SDL_XINPUT_HapticInit(void)
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_MaybeAddDevice(const DWORD dwUserid)
|
||||
SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_XINPUT_MaybeRemoveDevice(const DWORD dwUserid)
|
||||
SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -25,8 +25,8 @@
|
||||
|
||||
|
||||
extern int SDL_XINPUT_HapticInit(void);
|
||||
extern int SDL_XINPUT_MaybeAddDevice(const DWORD dwUserid);
|
||||
extern int SDL_XINPUT_MaybeRemoveDevice(const DWORD dwUserid);
|
||||
extern int SDL_XINPUT_HapticMaybeAddDevice(const DWORD dwUserid);
|
||||
extern int SDL_XINPUT_HapticMaybeRemoveDevice(const DWORD dwUserid);
|
||||
extern int SDL_XINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item);
|
||||
extern int SDL_XINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick);
|
||||
extern int SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick);
|
||||
|
||||
Reference in New Issue
Block a user