Ryujinx-SDL/src/joystick/windows/SDL_windowsjoystick_c.h

94 lines
2.6 KiB
C
Raw Normal View History

/*
Simple DirectMedia Layer
2017-01-02 03:33:28 +01:00
Copyright (C) 1997-2017 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
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_events.h"
#include "../SDL_sysjoystick.h"
#include "../../core/windows/SDL_windows.h"
#include "../../core/windows/SDL_directx.h"
#define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */
typedef struct JoyStick_DeviceData
{
SDL_JoystickGUID guid;
char *joystickname;
Uint8 send_add_event;
SDL_JoystickID nInstanceID;
SDL_bool bXInputDevice;
BYTE SubType;
Uint8 XInputUserId;
DIDEVICEINSTANCE dxdevice;
Fixed bug 3299 - DirectInput: Incorrect joystick mapping when attaching new joysticks Jimb Esser Note: This is using DirectInput, I have to disable XInput as that causes all but the first 4 controllers to be completely ignored by SDL (I can find no way to reconcile XInput devices with DirectInput devices, otherwise I would make a patch that accepts the fifth and later controllers with DirectInput...). XInput does not seem to have the problem below, only DirectInput. I plug in 3 identical wireless Xbox 360 controllers, call them J1, J2, J3. Direct Input shows them as having GUIDs G1, G2, G3. I unplug J1, then J2 and J3 show up as having GUIDs G1 and G2! Not so "unique"... I start my SDL app when just J2 and J3 are plugged in, and open J2 and J3. Then I plug in a new controller, SDL sees that now G3 exists, assigns that a new SDL joystick instance ID, which I request to be opened, but G3 at this point is J3, which I already had opened! So I end up with two instances of J3 opened, and none of J1. "Re-"opening G1 would get the actual handle to the newly attached controller, but there's no current way to know this. This is clearly a bug or poor design in DirectInput or my wireless receiver drivers, but is a showstopping bug for my 8-20 player games (as soon as any one controller runs out of battery or goes to sleep and gets turned back on, suddenly things are busted requiring a restart (or, at least, a reinitialization of all controllers - the game can't go on)). The solution I found is to use HID paths instead of GUIDs to uniquely identify joysticks. GUIDs are still needed to open a controller, however I have added code to re-find the GUIDs for all joysticks whenever a new joystick is attached or removed. This does now require opening of all joysticks (instead of just enumerating them), though if your app, like mine, is opening all of them anyway so that any can press a button to join, that doesn't change much (although perhaps they joysticks should be kept open in this case, instead of closed and re-opened). If your app only ever opens one joystick, this will do more work at startup than it did previously.
2017-08-14 05:42:41 +02:00
WCHAR hidPath[MAX_PATH];
struct JoyStick_DeviceData *pNext;
} JoyStick_DeviceData;
extern JoyStick_DeviceData *SYS_Joystick; /* array to hold joystick ID values */
typedef enum Type
{
BUTTON,
AXIS,
HAT
} Type;
typedef struct input_t
{
/* DirectInput offset for this input type: */
DWORD ofs;
/* Button, axis or hat: */
Type type;
/* SDL input offset: */
Uint8 num;
} input_t;
/* The private structure used to keep track of a joystick */
struct joystick_hwdata
{
SDL_JoystickGUID guid;
SDL_bool removed;
SDL_bool send_remove_event;
#if SDL_JOYSTICK_DINPUT
LPDIRECTINPUTDEVICE8 InputDevice;
DIDEVCAPS Capabilities;
SDL_bool buffered;
input_t Inputs[MAX_INPUTS];
int NumInputs;
int NumSliders;
#endif
SDL_bool bXInputDevice; /* SDL_TRUE if this device supports using the xinput API rather than DirectInput */
SDL_bool bXInputHaptic; /* Supports force feedback via XInput. */
Uint8 userid; /* XInput userid index for this joystick */
DWORD dwPacketNumber;
};
2016-10-02 00:10:50 +02:00
#if SDL_JOYSTICK_DINPUT
2016-10-01 23:50:22 +02:00
extern const DIDATAFORMAT SDL_c_dfDIJoystick2;
2016-10-02 00:10:50 +02:00
#endif
2016-10-01 23:50:22 +02:00
extern void SDL_SYS_AddJoystickDevice(JoyStick_DeviceData *device);
/* vi: set ts=4 sw=4 expandtab: */