author | Jørgen P. Tjernø <jorgen@valvesoftware.com> |
Wed, 05 Jun 2013 12:48:44 -0700 | |
changeset 7277 | 1290cd7f34af |
parent 7248 | 52d3427f8b5a |
child 7298 | 60b241342303 |
permissions | -rw-r--r-- |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 |
Simple DirectMedia Layer |
6885 | 3 |
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org> |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 |
This software is provided 'as-is', without any express or implied |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 |
warranty. In no event will the authors be held liable for any damages |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 |
arising from the use of this software. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
Permission is granted to anyone to use this software for any purpose, |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 |
including commercial applications, and to alter it and redistribute it |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 |
freely, subject to the following restrictions: |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 |
1. The origin of this software must not be misrepresented; you must not |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
claim that you wrote the original software. If you use this software |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 |
in a product, an acknowledgment in the product documentation would be |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 |
appreciated but is not required. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 |
2. Altered source versions must be plainly marked as such, and must not be |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
misrepresented as being the original software. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 |
3. This notice may not be removed or altered from any source distribution. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
#include "SDL_config.h" |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
/* This is the game controller API for Simple DirectMedia Layer */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
#include "SDL_events.h" |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
#include "SDL_assert.h" |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
#include "SDL_sysjoystick.h" |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
#include "SDL_hints.h" |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 |
#if !SDL_EVENTS_DISABLED |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
#include "../events/SDL_events_c.h" |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
#endif |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 |
#define ABS(_x) ((_x) < 0 ? -(_x) : (_x)) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
/* a list of currently opened game controllers */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 |
static SDL_GameController *SDL_gamecontrollers = NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 |
|
6843 | 39 |
/* keep track of the hat and mask value that transforms this hat movement into a button/axis press */ |
40 |
struct _SDL_HatMapping |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
42 |
int hat; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
43 |
Uint8 mask; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 |
}; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 |
#define k_nMaxReverseEntries 20 |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 |
|
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
48 |
/** |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
49 |
* We are encoding the "HAT" as 0xhm. where h == hat ID and m == mask |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
50 |
* MAX 4 hats supported |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
51 |
*/ |
6843 | 52 |
#define k_nMaxHatEntries 0x3f + 1 |
53 |
||
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 |
/* our in memory mapping db between joystick objects and controller mappings*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 |
struct _SDL_ControllerMapping |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
57 |
SDL_JoystickGUID guid; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
58 |
const char *name; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
60 |
/* mapping of axis/button id to controller version */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
61 |
int axes[SDL_CONTROLLER_AXIS_MAX]; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
62 |
int buttonasaxis[SDL_CONTROLLER_AXIS_MAX]; |
6842 | 63 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
64 |
int buttons[SDL_CONTROLLER_BUTTON_MAX]; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
65 |
int axesasbutton[SDL_CONTROLLER_BUTTON_MAX]; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
66 |
struct _SDL_HatMapping hatasbutton[SDL_CONTROLLER_BUTTON_MAX]; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
68 |
/* reverse mapping, joystick indices to buttons */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
69 |
SDL_GameControllerAxis raxes[k_nMaxReverseEntries]; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
70 |
SDL_GameControllerAxis rbuttonasaxis[k_nMaxReverseEntries]; |
6842 | 71 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
72 |
SDL_GameControllerButton rbuttons[k_nMaxReverseEntries]; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
73 |
SDL_GameControllerButton raxesasbutton[k_nMaxReverseEntries]; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
74 |
SDL_GameControllerButton rhatasbutton[k_nMaxHatEntries]; |
6842 | 75 |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 |
}; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 |
/* our hard coded list of mapping support */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 |
typedef struct _ControllerMapping_t |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
82 |
SDL_JoystickGUID guid; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
83 |
char *name; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
84 |
char *mapping; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
85 |
struct _ControllerMapping_t *next; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 |
} ControllerMapping_t; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 |
/* default mappings we support */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 |
const char *s_ControllerMappings [] = |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 |
{ |
6701
91160c9b35da
The XInput code is only available in the DirectInput joystick driver.
Sam Lantinga <slouken@libsdl.org>
parents:
6690
diff
changeset
|
92 |
#ifdef SDL_JOYSTICK_DINPUT |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
93 |
"xinput,X360 Controller,a:b10,b:b11,y:b13,x:b12,start:b4,guide:b14,back:b5,dpup:b0,dpleft:b2,dpdown:b1,dpright:b3,leftshoulder:b8,rightshoulder:b9,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5", |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
94 |
"341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7", |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
95 |
"88880803000000000000504944564944,PS3 Controller,a:b2,b:b1,x:b0,y:b3,start:b11,back:b8,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b6,righttrigger:b7,guide:b12", |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
96 |
"4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,y:b12,x:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9,", |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
97 |
"25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,x:b0,y:b3,start:b8,guide:,back:b9,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.4,dpdown:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5", |
7027
b1c25fd3907f
Added support for the GameStop Gamepad
Sam Lantinga <slouken@libsdl.org>
parents:
6998
diff
changeset
|
98 |
"ffff0000000000000000504944564944,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", |
7047
299de3271a7b
Add new controller mappings for Windows.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7037
diff
changeset
|
99 |
"6d0416c2000000000000504944564944,Generic DirectInput Controller,a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 |
#elif defined(__MACOSX__) |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
101 |
"5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftshoulder:b4,rightshoulder:b5,leftstick:b6,rightstick:b7,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", |
7277
1290cd7f34af
Mac: Fix invalid PS3 controller mapping.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7248
diff
changeset
|
102 |
"4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,x:b15,y:b12,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", |
7027
b1c25fd3907f
Added support for the GameStop Gamepad
Sam Lantinga <slouken@libsdl.org>
parents:
6998
diff
changeset
|
103 |
"0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", |
7055
76323a708ea5
Add 3 Logitech gamecontroller mappings for Mac OS X.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7047
diff
changeset
|
104 |
"6d040000000000001fc2000000000000,Logitech F710 Gamepad Controller (XInput),a:b0,b:b1,y:b3,x:b2,start:b8,guide:b10,back:b9,leftstick:b6,rightstick:b7,leftshoulder:b4,rightshoulder:b5,dpup:b11,dpleft:b13,dpdown:b12,dpright:b14,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
105 |
"6d0400000000000016c2000000000000,Logitech F310 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", /* Guide button doesn't seem to be sent in DInput mode. */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
106 |
"6d0400000000000019c2000000000000,Logitech Wireless Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", /* This includes F710 in DInput mode and the "Logitech Cordless RumblePad 2", at the very least. */ |
7247
6a4570f12c20
add in Controller configs for Logitech F510 for OS X / Linux
Edward Rudd <urkle@outoforder.cc>
parents:
7191
diff
changeset
|
107 |
"6d0400000000000018c2000000000000,Logitech Rumble Gamepad F510(DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,rightx:a2,lefty:a1,righty:a3,lefttrigger:b6,righttrigger:b7,", |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 |
#elif defined(__LINUX__) |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
109 |
"030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5", |
6997
0f91d1be17a4
Add GameController mappings for popular controllers.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6980
diff
changeset
|
110 |
"030000005e0400008e02000010010000,X360 Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", |
0f91d1be17a4
Add GameController mappings for popular controllers.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6980
diff
changeset
|
111 |
"030000005e0400001907000000010000,X360 Wireless Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:b13,dpleft:b11,dpdown:b14,dpright:b12,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
112 |
"030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,x:b15,y:b12,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9", |
6997
0f91d1be17a4
Add GameController mappings for popular controllers.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6980
diff
changeset
|
113 |
"030000006d0400001fc2000005030000,Logitech F710 Gamepad Controller (XInput),a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
114 |
"030000006d04000019c2000011010000,Logitech F710 Gamepad Controller (DInput),a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", /* Guide button doesn't seem to be sent in DInput mode. */ |
6997
0f91d1be17a4
Add GameController mappings for popular controllers.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6980
diff
changeset
|
115 |
"030000006d0400001dc2000014400000,Logitech F310 Gamepad (XInput),a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", |
6998
f7faeaa02efb
Missing comma in one gamepad mapping.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6997
diff
changeset
|
116 |
"030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,y:b3,x:b0,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", |
7027
b1c25fd3907f
Added support for the GameStop Gamepad
Sam Lantinga <slouken@libsdl.org>
parents:
6998
diff
changeset
|
117 |
"0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,y:b3,x:b2,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,", |
7181
d35a0936c674
Martin Gerhardy added support for the Jess Technology USB Game Controller
Sam Lantinga <slouken@libsdl.org>
parents:
7133
diff
changeset
|
118 |
"03000000ba2200002010000001010000,Jess Technology USB Game Controller,start:b9,a:b2,b:b1,x:b3,y:b0,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b6,righttrigger:b7,leftshoulder:b4,rightshoulder:b5,guide:,back:b8", |
7247
6a4570f12c20
add in Controller configs for Logitech F510 for OS X / Linux
Edward Rudd <urkle@outoforder.cc>
parents:
7191
diff
changeset
|
119 |
"030000006d0400001ec2000020200000,Logitech Rumble Gamepad F510(XInput),a:b0,b:b1,x:b2,y:b3,start:b7,back:b6,guide:b8,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,", |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 |
#endif |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
121 |
NULL |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 |
}; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 |
static ControllerMapping_t *s_pSupportedControllers = NULL; |
6708 | 125 |
#ifdef SDL_JOYSTICK_DINPUT |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 |
static ControllerMapping_t *s_pXInputMapping = NULL; |
6708 | 127 |
#endif |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 |
/* The SDL game controller structure */ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 |
struct _SDL_GameController |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
132 |
SDL_Joystick *joystick; /* underlying joystick device */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
133 |
int ref_count; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
134 |
Uint8 hatState[4]; /* the current hat state for this controller */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
135 |
struct _SDL_ControllerMapping mapping; /* the mapping object for this controller */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
136 |
struct _SDL_GameController *next; /* pointer to next game controller we have allocated */ |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
}; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 |
|
6917
47dc155b774d
Changed the game controller enum types to match SDL naming conventions.
Ryan C. Gordon <icculus@icculus.org>
parents:
6915
diff
changeset
|
140 |
int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
141 |
int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 |
* Event filter to fire controller events from joystick ones |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 |
int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
148 |
switch( event->type ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
149 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
150 |
case SDL_JOYAXISMOTION: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
151 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
152 |
SDL_GameController *controllerlist; |
6850
ad3416a14319
Fixed C variable declarations
Sam Lantinga <slouken@libsdl.org>
parents:
6847
diff
changeset
|
153 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
154 |
if ( event->jaxis.axis >= k_nMaxReverseEntries ) break; |
6843 | 155 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
156 |
controllerlist = SDL_gamecontrollers; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
157 |
while ( controllerlist ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
158 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
159 |
if ( controllerlist->joystick->instance_id == event->jaxis.which ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
160 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
161 |
if ( controllerlist->mapping.raxes[event->jaxis.axis] >= 0 ) /* simple axis to axis, send it through */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
162 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
163 |
SDL_GameControllerAxis axis = controllerlist->mapping.raxes[event->jaxis.axis]; |
7080
7353267a2ce2
Make gamecontroller triggers have values in 0 - 32767.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
7055
diff
changeset
|
164 |
Sint16 value = event->jaxis.value; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
165 |
switch (axis) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
166 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
167 |
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
168 |
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
169 |
/* Shift it to be 0 - 32767. */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
170 |
value = value / 2 + 16384; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
171 |
default: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
172 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
173 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
174 |
SDL_PrivateGameControllerAxis( controllerlist, axis, value ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
175 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
176 |
else if ( controllerlist->mapping.raxesasbutton[event->jaxis.axis] >= 0 ) /* simulate an axis as a button */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
177 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
178 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.raxesasbutton[event->jaxis.axis], ABS(event->jaxis.value) > 32768/2 ? SDL_PRESSED : SDL_RELEASED ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
179 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
180 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
181 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
182 |
controllerlist = controllerlist->next; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
183 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
184 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
185 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
186 |
case SDL_JOYBUTTONDOWN: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
187 |
case SDL_JOYBUTTONUP: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
188 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
189 |
SDL_GameController *controllerlist; |
6850
ad3416a14319
Fixed C variable declarations
Sam Lantinga <slouken@libsdl.org>
parents:
6847
diff
changeset
|
190 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
191 |
if ( event->jbutton.button >= k_nMaxReverseEntries ) break; |
6843 | 192 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
193 |
controllerlist = SDL_gamecontrollers; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
194 |
while ( controllerlist ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
195 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
196 |
if ( controllerlist->joystick->instance_id == event->jbutton.which ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
197 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
198 |
if ( controllerlist->mapping.rbuttons[event->jbutton.button] >= 0 ) /* simple button as button */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
199 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
200 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rbuttons[event->jbutton.button], event->jbutton.state ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
201 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
202 |
else if ( controllerlist->mapping.rbuttonasaxis[event->jbutton.button] >= 0 ) /* an button pretending to be an axis */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
203 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
204 |
SDL_PrivateGameControllerAxis( controllerlist, controllerlist->mapping.rbuttonasaxis[event->jbutton.button], event->jbutton.state > 0 ? 32767 : 0 ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
205 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
206 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
207 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
208 |
controllerlist = controllerlist->next; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
209 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
210 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
211 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
212 |
case SDL_JOYHATMOTION: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
213 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
214 |
SDL_GameController *controllerlist; |
6850
ad3416a14319
Fixed C variable declarations
Sam Lantinga <slouken@libsdl.org>
parents:
6847
diff
changeset
|
215 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
216 |
if ( event->jhat.hat >= 4 ) break; |
6843 | 217 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
218 |
controllerlist = SDL_gamecontrollers; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
219 |
while ( controllerlist ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
220 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
221 |
if ( controllerlist->joystick->instance_id == event->jhat.which ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
222 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
223 |
Uint8 bSame = controllerlist->hatState[event->jhat.hat] & event->jhat.value; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
224 |
/* Get list of removed bits (button release) */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
225 |
Uint8 bChanged = controllerlist->hatState[event->jhat.hat] ^ bSame; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
226 |
/* the hat idx in the high nibble */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
227 |
int bHighHat = event->jhat.hat << 4; |
6843 | 228 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
229 |
if ( bChanged & SDL_HAT_DOWN ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
230 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_DOWN], SDL_RELEASED ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
231 |
if ( bChanged & SDL_HAT_UP ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
232 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_UP], SDL_RELEASED ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
233 |
if ( bChanged & SDL_HAT_LEFT ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
234 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_LEFT], SDL_RELEASED ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
235 |
if ( bChanged & SDL_HAT_RIGHT ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
236 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_RIGHT], SDL_RELEASED ); |
6843 | 237 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
238 |
/* Get list of added bits (button press) */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
239 |
bChanged = event->jhat.value ^ bSame; |
6843 | 240 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
241 |
if ( bChanged & SDL_HAT_DOWN ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
242 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_DOWN], SDL_PRESSED ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
243 |
if ( bChanged & SDL_HAT_UP ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
244 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_UP], SDL_PRESSED ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
245 |
if ( bChanged & SDL_HAT_LEFT ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
246 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_LEFT], SDL_PRESSED ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
247 |
if ( bChanged & SDL_HAT_RIGHT ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
248 |
SDL_PrivateGameControllerButton( controllerlist, controllerlist->mapping.rhatasbutton[bHighHat | SDL_HAT_RIGHT], SDL_PRESSED ); |
6843 | 249 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
250 |
/* update our state cache */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
251 |
controllerlist->hatState[event->jhat.hat] = event->jhat.value; |
6843 | 252 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
253 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
254 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
255 |
controllerlist = controllerlist->next; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
256 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
257 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
258 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
259 |
case SDL_JOYDEVICEADDED: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
260 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
261 |
if ( SDL_IsGameController(event->jdevice.which ) ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
262 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
263 |
SDL_Event deviceevent; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
264 |
deviceevent.type = SDL_CONTROLLERDEVICEADDED; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
265 |
deviceevent.cdevice.which = event->jdevice.which; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
266 |
SDL_PushEvent(&deviceevent); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
267 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
268 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
269 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
270 |
case SDL_JOYDEVICEREMOVED: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
271 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
272 |
SDL_GameController *controllerlist = SDL_gamecontrollers; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
273 |
while ( controllerlist ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
274 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
275 |
if ( controllerlist->joystick->instance_id == event->jdevice.which ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
276 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
277 |
SDL_Event deviceevent; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
278 |
deviceevent.type = SDL_CONTROLLERDEVICEREMOVED; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
279 |
deviceevent.cdevice.which = event->jdevice.which; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
280 |
SDL_PushEvent(&deviceevent); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
281 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
282 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
283 |
controllerlist = controllerlist->next; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
284 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
285 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
286 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
287 |
default: |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
288 |
break; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
289 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
291 |
return 1; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 |
/* |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
295 |
* Helper function to scan the mappings database for a controller with the specified GUID |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
296 |
*/ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
297 |
ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
298 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
299 |
ControllerMapping_t *pSupportedController = s_pSupportedControllers; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
300 |
while ( pSupportedController ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
301 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
302 |
if ( !SDL_memcmp( guid, &pSupportedController->guid, sizeof(*guid) ) ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
303 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
304 |
return pSupportedController; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
305 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
306 |
pSupportedController = pSupportedController->next; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
307 |
} |
7129
538dd99173de
Corrected confusing indentation in C source file.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7081
diff
changeset
|
308 |
return NULL; |
538dd99173de
Corrected confusing indentation in C source file.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7081
diff
changeset
|
309 |
} |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
310 |
|
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
311 |
/* |
7133
87d4cb9bb66c
Corrected spelling in C source files.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7129
diff
changeset
|
312 |
* Helper function to determine pre-calculated offset to certain joystick mappings |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 |
ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 |
{ |
6701
91160c9b35da
The XInput code is only available in the DirectInput joystick driver.
Sam Lantinga <slouken@libsdl.org>
parents:
6690
diff
changeset
|
316 |
#ifdef SDL_JOYSTICK_DINPUT |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
317 |
if ( SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
318 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
319 |
return s_pXInputMapping; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
320 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
321 |
else |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 |
#endif |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
323 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
324 |
SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
325 |
return SDL_PrivateGetControllerMappingForGUID(&jGUID); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
326 |
} |
6841 | 327 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
328 |
return NULL; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 |
|
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
331 |
static const char* map_StringForControllerAxis[] = { |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
332 |
"leftx", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
333 |
"lefty", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
334 |
"rightx", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
335 |
"righty", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
336 |
"lefttrigger", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
337 |
"righttrigger", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
338 |
NULL |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
339 |
}; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
340 |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 |
* convert a string to its enum equivalent |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 |
*/ |
6917
47dc155b774d
Changed the game controller enum types to match SDL naming conventions.
Ryan C. Gordon <icculus@icculus.org>
parents:
6915
diff
changeset
|
344 |
SDL_GameControllerAxis SDL_GameControllerGetAxisFromString( const char *pchString ) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 |
{ |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
346 |
int entry; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
347 |
if ( !pchString || !pchString[0] ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
348 |
return SDL_CONTROLLER_AXIS_INVALID; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 |
|
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
350 |
for ( entry = 0; map_StringForControllerAxis[entry]; ++entry) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
351 |
{ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
352 |
if ( !SDL_strcasecmp( pchString, map_StringForControllerAxis[entry] ) ) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
353 |
return entry; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
354 |
} |
7129
538dd99173de
Corrected confusing indentation in C source file.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7081
diff
changeset
|
355 |
return SDL_CONTROLLER_AXIS_INVALID; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 |
|
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
358 |
/* |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
359 |
* convert an enum to its string equivalent |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
360 |
*/ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
361 |
const char* SDL_GameControllerGetStringForAxis( SDL_GameControllerAxis axis ) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
362 |
{ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
363 |
if (axis > SDL_CONTROLLER_AXIS_INVALID && axis < SDL_CONTROLLER_AXIS_MAX) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
364 |
{ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
365 |
return map_StringForControllerAxis[axis]; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
366 |
} |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
367 |
return NULL; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
368 |
} |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
369 |
|
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
370 |
static const char* map_StringForControllerButton[] = { |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
371 |
"a", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
372 |
"b", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
373 |
"x", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
374 |
"y", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
375 |
"back", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
376 |
"guide", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
377 |
"start", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
378 |
"leftstick", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
379 |
"rightstick", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
380 |
"leftshoulder", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
381 |
"rightshoulder", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
382 |
"dpup", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
383 |
"dpdown", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
384 |
"dpleft", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
385 |
"dpright", |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
386 |
NULL |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
387 |
}; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
388 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
389 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
390 |
* convert a string to its enum equivalent |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
391 |
*/ |
6917
47dc155b774d
Changed the game controller enum types to match SDL naming conventions.
Ryan C. Gordon <icculus@icculus.org>
parents:
6915
diff
changeset
|
392 |
SDL_GameControllerButton SDL_GameControllerGetButtonFromString( const char *pchString ) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
393 |
{ |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
394 |
int entry; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
395 |
if ( !pchString || !pchString[0] ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
396 |
return SDL_CONTROLLER_BUTTON_INVALID; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
397 |
|
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
398 |
for ( entry = 0; map_StringForControllerButton[entry]; ++entry) |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
399 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
400 |
if ( !SDL_strcasecmp( pchString, map_StringForControllerButton[entry] ) ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
401 |
return entry; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
402 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
403 |
return SDL_CONTROLLER_BUTTON_INVALID; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
404 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
405 |
|
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
406 |
/* |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
407 |
* convert an enum to its string equivalent |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
408 |
*/ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
409 |
const char* SDL_GameControllerGetStringForButton( SDL_GameControllerButton axis ) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
410 |
{ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
411 |
if (axis > SDL_CONTROLLER_BUTTON_INVALID && axis < SDL_CONTROLLER_BUTTON_MAX) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
412 |
{ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
413 |
return map_StringForControllerButton[axis]; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
414 |
} |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
415 |
return NULL; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
416 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
417 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
418 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
419 |
* given a controller button name and a joystick name update our mapping structure with it |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
420 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
421 |
void SDL_PrivateGameControllerParseButton( const char *szGameButton, const char *szJoystickButton, struct _SDL_ControllerMapping *pMapping ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
423 |
int iSDLButton = 0; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
424 |
SDL_GameControllerButton button; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
425 |
SDL_GameControllerAxis axis; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
426 |
button = SDL_GameControllerGetButtonFromString( szGameButton ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
427 |
axis = SDL_GameControllerGetAxisFromString( szGameButton ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
428 |
iSDLButton = SDL_atoi( &szJoystickButton[1] ); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
429 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
430 |
if ( szJoystickButton[0] == 'a' ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
431 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
432 |
if ( iSDLButton >= k_nMaxReverseEntries ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
433 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
434 |
SDL_SetError("Axis index too large: %d", iSDLButton ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
435 |
return; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
436 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
437 |
if ( axis != SDL_CONTROLLER_AXIS_INVALID ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
438 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
439 |
pMapping->axes[ axis ] = iSDLButton; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
440 |
pMapping->raxes[ iSDLButton ] = axis; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
441 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
442 |
else if ( button != SDL_CONTROLLER_BUTTON_INVALID ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
443 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
444 |
pMapping->axesasbutton[ button ] = iSDLButton; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
445 |
pMapping->raxesasbutton[ iSDLButton ] = button; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
446 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
447 |
else |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
448 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
449 |
SDL_assert( !"How did we get here?" ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
450 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
451 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
452 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
453 |
else if ( szJoystickButton[0] == 'b' ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
454 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
455 |
if ( iSDLButton >= k_nMaxReverseEntries ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
456 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
457 |
SDL_SetError("Button index too large: %d", iSDLButton ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
458 |
return; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
459 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
460 |
if ( button != SDL_CONTROLLER_BUTTON_INVALID ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
461 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
462 |
pMapping->buttons[ button ] = iSDLButton; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
463 |
pMapping->rbuttons[ iSDLButton ] = button; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
464 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
465 |
else if ( axis != SDL_CONTROLLER_AXIS_INVALID ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
466 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
467 |
pMapping->buttonasaxis[ axis ] = iSDLButton; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
468 |
pMapping->rbuttonasaxis[ iSDLButton ] = axis; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
469 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
470 |
else |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
471 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
472 |
SDL_assert( !"How did we get here?" ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
473 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
474 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
475 |
else if ( szJoystickButton[0] == 'h' ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
476 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
477 |
int hat = SDL_atoi( &szJoystickButton[1] ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
478 |
int mask = SDL_atoi( &szJoystickButton[3] ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
479 |
if (hat >= 4) { |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
480 |
SDL_SetError("Hat index too large: %d", iSDLButton ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
481 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
482 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
483 |
if ( button != SDL_CONTROLLER_BUTTON_INVALID ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
484 |
{ |
6854
7b1d78036e84
Hopefully fixed the last of the C variable declaration problems which caused compile failures with Visual Studio.
Sam Lantinga <slouken@libsdl.org>
parents:
6850
diff
changeset
|
485 |
int ridx; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
486 |
pMapping->hatasbutton[ button ].hat = hat; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
487 |
pMapping->hatasbutton[ button ].mask = mask; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
488 |
ridx = (hat << 4) | mask; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
489 |
pMapping->rhatasbutton[ ridx ] = button; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
490 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
491 |
else if ( axis != SDL_CONTROLLER_AXIS_INVALID ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
492 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
493 |
SDL_assert( !"Support hat as axis" ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
494 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
495 |
else |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
496 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
497 |
SDL_assert( !"How did we get here?" ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
498 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
499 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
500 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
501 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
502 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
503 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
504 |
* given a controller mapping string update our mapping object |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
505 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
506 |
static void |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
507 |
SDL_PrivateGameControllerParseControllerConfigString( struct _SDL_ControllerMapping *pMapping, const char *pchString ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
508 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
509 |
char szGameButton[20]; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
510 |
char szJoystickButton[20]; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
511 |
SDL_bool bGameButton = SDL_TRUE; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
512 |
int i = 0; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
513 |
const char *pchPos = pchString; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
514 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
515 |
SDL_memset( szGameButton, 0x0, sizeof(szGameButton) ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
516 |
SDL_memset( szJoystickButton, 0x0, sizeof(szJoystickButton) ); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
517 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
518 |
while ( pchPos && *pchPos ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
519 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
520 |
if ( *pchPos == ':' ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
521 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
522 |
i = 0; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
523 |
bGameButton = SDL_FALSE; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
524 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
525 |
else if ( *pchPos == ' ' ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
526 |
{ |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
527 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
528 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
529 |
else if ( *pchPos == ',' ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
530 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
531 |
i = 0; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
532 |
bGameButton = SDL_TRUE; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
533 |
SDL_PrivateGameControllerParseButton( szGameButton, szJoystickButton, pMapping ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
534 |
SDL_memset( szGameButton, 0x0, sizeof(szGameButton) ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
535 |
SDL_memset( szJoystickButton, 0x0, sizeof(szJoystickButton) ); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
536 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
537 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
538 |
else if ( bGameButton ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
539 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
540 |
if ( i >= sizeof(szGameButton)) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
541 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
542 |
SDL_SetError( "Button name too large: %s", szGameButton ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
543 |
return; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
544 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
545 |
szGameButton[i] = *pchPos; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
546 |
i++; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
547 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
548 |
else |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
549 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
550 |
if ( i >= sizeof(szJoystickButton)) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
551 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
552 |
SDL_SetError( "Joystick button name too large: %s", szJoystickButton ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
553 |
return; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
554 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
555 |
szJoystickButton[i] = *pchPos; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
556 |
i++; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
557 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
558 |
pchPos++; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
559 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
560 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
561 |
SDL_PrivateGameControllerParseButton( szGameButton, szJoystickButton, pMapping ); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
562 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
563 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
564 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
565 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
566 |
* Make a new button mapping struct |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
567 |
*/ |
6738 | 568 |
void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping ) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
569 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
570 |
int j; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
571 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
572 |
pMapping->guid = guid; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
573 |
pMapping->name = pchName; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
574 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
575 |
/* set all the button mappings to non defaults */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
576 |
for ( j = 0; j < SDL_CONTROLLER_AXIS_MAX; j++ ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
577 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
578 |
pMapping->axes[j] = -1; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
579 |
pMapping->buttonasaxis[j] = -1; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
580 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
581 |
for ( j = 0; j < SDL_CONTROLLER_BUTTON_MAX; j++ ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
582 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
583 |
pMapping->buttons[j] = -1; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
584 |
pMapping->axesasbutton[j] = -1; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
585 |
pMapping->hatasbutton[j].hat = -1; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
586 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
587 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
588 |
for ( j = 0; j < k_nMaxReverseEntries; j++ ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
589 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
590 |
pMapping->raxes[j] = SDL_CONTROLLER_AXIS_INVALID; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
591 |
pMapping->rbuttonasaxis[j] = SDL_CONTROLLER_AXIS_INVALID; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
592 |
pMapping->rbuttons[j] = SDL_CONTROLLER_BUTTON_INVALID; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
593 |
pMapping->raxesasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
594 |
} |
6843 | 595 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
596 |
for (j = 0; j < k_nMaxHatEntries; j++) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
597 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
598 |
pMapping->rhatasbutton[j] = SDL_CONTROLLER_BUTTON_INVALID; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
599 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
600 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
601 |
SDL_PrivateGameControllerParseControllerConfigString( pMapping, pchMapping ); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
602 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
603 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
604 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
605 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
606 |
* grab the guid string from a mapping string |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
607 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
608 |
char *SDL_PrivateGetControllerGUIDFromMappingString( const char *pMapping ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
609 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
610 |
const char *pFirstComma = SDL_strchr( pMapping, ',' ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
611 |
if ( pFirstComma ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
612 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
613 |
char *pchGUID = SDL_malloc( pFirstComma - pMapping + 1 ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
614 |
if ( !pchGUID ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
615 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
616 |
SDL_OutOfMemory(); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
617 |
return NULL; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
618 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
619 |
SDL_memcpy( pchGUID, pMapping, pFirstComma - pMapping ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
620 |
pchGUID[ pFirstComma - pMapping ] = 0; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
621 |
return pchGUID; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
622 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
623 |
return NULL; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
624 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
625 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
626 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
627 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
628 |
* grab the name string from a mapping string |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
629 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
630 |
char *SDL_PrivateGetControllerNameFromMappingString( const char *pMapping ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
631 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
632 |
const char *pFirstComma, *pSecondComma; |
6823
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
633 |
char *pchName; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
634 |
|
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
635 |
pFirstComma = SDL_strchr( pMapping, ',' ); |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
636 |
if ( !pFirstComma ) |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
637 |
return NULL; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
638 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
639 |
pSecondComma = SDL_strchr( pFirstComma + 1, ',' ); |
6823
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
640 |
if ( !pSecondComma ) |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
641 |
return NULL; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
642 |
|
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
643 |
pchName = SDL_malloc( pSecondComma - pFirstComma ); |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
644 |
if ( !pchName ) |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
645 |
{ |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
646 |
SDL_OutOfMemory(); |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
647 |
return NULL; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
648 |
} |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
649 |
SDL_memcpy( pchName, pFirstComma + 1, pSecondComma - pFirstComma ); |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
650 |
pchName[ pSecondComma - pFirstComma - 1 ] = 0; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
651 |
return pchName; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
652 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
653 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
654 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
655 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
656 |
* grab the button mapping string from a mapping string |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
657 |
*/ |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
658 |
char *SDL_PrivateGetControllerMappingFromMappingString( const char *pMapping ) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
659 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
660 |
const char *pFirstComma, *pSecondComma; |
6823
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
661 |
|
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
662 |
pFirstComma = SDL_strchr( pMapping, ',' ); |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
663 |
if ( !pFirstComma ) |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
664 |
return NULL; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
665 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
666 |
pSecondComma = SDL_strchr( pFirstComma + 1, ',' ); |
6823
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
667 |
if ( !pSecondComma ) |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
668 |
return NULL; |
e9d312d26979
Fixed crash when the game controller mapping hint is set - the hint was duplicated and not null terminated.
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
669 |
|
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
670 |
return SDL_strdup(pSecondComma + 1); /* mapping is everything after the 3rd comma */ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
671 |
} |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
672 |
|
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
673 |
void SDL_PrivateGameControllerRefreshMapping( ControllerMapping_t *pControllerMapping ) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
674 |
{ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
675 |
SDL_GameController *gamecontrollerlist = SDL_gamecontrollers; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
676 |
while ( gamecontrollerlist ) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
677 |
{ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
678 |
if ( !SDL_memcmp( &gamecontrollerlist->mapping.guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid) ) ) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
679 |
{ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
680 |
SDL_Event event; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
681 |
event.type = SDL_CONTROLLERDEVICEREMAPPED; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
682 |
event.cdevice.which = gamecontrollerlist->joystick->instance_id; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
683 |
SDL_PushEvent(&event); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
684 |
|
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
685 |
/* Not really threadsafe. Should this lock access within SDL_GameControllerEventWatcher? */ |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
686 |
SDL_PrivateLoadButtonMapping(&gamecontrollerlist->mapping, pControllerMapping->guid, pControllerMapping->name, pControllerMapping->mapping); |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
687 |
} |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
688 |
|
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
689 |
gamecontrollerlist = gamecontrollerlist->next; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
690 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
691 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
692 |
|
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
693 |
/* |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
694 |
* Add or update an entry into the Mappings Database |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
695 |
*/ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
696 |
int |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
697 |
SDL_GameControllerAddMapping( const char *mappingString ) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
698 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
699 |
char *pchGUID; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
700 |
char *pchName; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
701 |
char *pchMapping; |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
702 |
SDL_JoystickGUID jGUID; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
703 |
ControllerMapping_t *pControllerMapping; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
704 |
#ifdef SDL_JOYSTICK_DINPUT |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
705 |
SDL_bool is_xinput_mapping = SDL_FALSE; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
706 |
#endif |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
707 |
|
6975
36145df5a4dc
Fixed read after free bug in the game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6964
diff
changeset
|
708 |
pchGUID = SDL_PrivateGetControllerGUIDFromMappingString( mappingString ); |
36145df5a4dc
Fixed read after free bug in the game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6964
diff
changeset
|
709 |
if (!pchGUID) { |
36145df5a4dc
Fixed read after free bug in the game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6964
diff
changeset
|
710 |
return -1; |
36145df5a4dc
Fixed read after free bug in the game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6964
diff
changeset
|
711 |
} |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
712 |
#ifdef SDL_JOYSTICK_DINPUT |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
713 |
if ( !SDL_strcasecmp( pchGUID, "xinput" ) ) { |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
714 |
is_xinput_mapping = SDL_TRUE; |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
715 |
} |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
716 |
#endif |
6975
36145df5a4dc
Fixed read after free bug in the game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6964
diff
changeset
|
717 |
jGUID = SDL_JoystickGetGUIDFromString(pchGUID); |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
718 |
SDL_free(pchGUID); |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
719 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
720 |
pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID); |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
721 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
722 |
pchName = SDL_PrivateGetControllerNameFromMappingString( mappingString ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
723 |
if (!pchName) return -1; |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
724 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
725 |
pchMapping = SDL_PrivateGetControllerMappingFromMappingString( mappingString ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
726 |
if (!pchMapping) { |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
727 |
SDL_free( pchName ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
728 |
return -1; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
729 |
} |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
730 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
731 |
if (pControllerMapping) { |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
732 |
/* Update existing mapping */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
733 |
SDL_free( pControllerMapping->name ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
734 |
pControllerMapping->name = pchName; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
735 |
SDL_free( pControllerMapping->mapping ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
736 |
pControllerMapping->mapping = pchMapping; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
737 |
/* refresh open controllers */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
738 |
SDL_PrivateGameControllerRefreshMapping( pControllerMapping ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
739 |
return 0; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
740 |
} else { |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
741 |
pControllerMapping = SDL_malloc( sizeof(*pControllerMapping) ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
742 |
if (!pControllerMapping) { |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
743 |
SDL_free( pchName ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
744 |
SDL_free( pchMapping ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
745 |
return SDL_OutOfMemory(); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
746 |
} |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
747 |
#ifdef SDL_JOYSTICK_DINPUT |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
748 |
if ( is_xinput_mapping ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
749 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
750 |
s_pXInputMapping = pControllerMapping; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
751 |
} |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
752 |
#endif |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
753 |
pControllerMapping->guid = jGUID; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
754 |
pControllerMapping->name = pchName; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
755 |
pControllerMapping->mapping = pchMapping; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
756 |
pControllerMapping->next = s_pSupportedControllers; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
757 |
s_pSupportedControllers = pControllerMapping; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
758 |
return 1; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
759 |
} |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
760 |
} |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
761 |
|
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
762 |
/* |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
763 |
* Get the mapping string for this GUID |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
764 |
*/ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
765 |
char * |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
766 |
SDL_GameControllerMappingForGUID( SDL_JoystickGUID guid ) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
767 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
768 |
char *pMappingString = NULL; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
769 |
ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
770 |
if (mapping) { |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
771 |
char pchGUID[33]; |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
772 |
size_t needed; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
773 |
SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID)); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
774 |
/* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
775 |
needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
776 |
pMappingString = SDL_malloc( needed ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
777 |
SDL_snprintf( pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
778 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
779 |
return pMappingString; |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
780 |
} |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
781 |
|
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
782 |
/* |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
783 |
* Get the mapping string for this device |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
784 |
*/ |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
785 |
char * |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
786 |
SDL_GameControllerMapping( SDL_GameController * gamecontroller ) |
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
787 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
788 |
return SDL_GameControllerMappingForGUID( gamecontroller->mapping.guid ); |
6964
c8aa24f05042
add new gamecontroller APIs
Edward Rudd <urkle@outoforder.cc>
parents:
6932
diff
changeset
|
789 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
790 |
|
6976
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
791 |
static void |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
792 |
SDL_GameControllerLoadHints() |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
793 |
{ |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
794 |
const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG); |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
795 |
if ( hint && hint[0] ) { |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
796 |
int nchHints = SDL_strlen( hint ); |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
797 |
char *pUserMappings = SDL_malloc( nchHints + 1 ); |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
798 |
char *pTempMappings = pUserMappings; |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
799 |
SDL_memcpy( pUserMappings, hint, nchHints ); |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
800 |
while ( pUserMappings ) { |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
801 |
char *pchNewLine = NULL; |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
802 |
|
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
803 |
pchNewLine = SDL_strchr( pUserMappings, '\n' ); |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
804 |
if ( pchNewLine ) |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
805 |
*pchNewLine = '\0'; |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
806 |
|
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
807 |
SDL_GameControllerAddMapping( pUserMappings ); |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
808 |
|
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
809 |
if ( pchNewLine ) |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
810 |
pUserMappings = pchNewLine + 1; |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
811 |
else |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
812 |
pUserMappings = NULL; |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
813 |
} |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
814 |
SDL_free(pTempMappings); |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
815 |
} |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
816 |
} |
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
817 |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
818 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
819 |
* Initialize the game controller system, mostly load our DB of controller config mappings |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
820 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
821 |
int |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
822 |
SDL_GameControllerInit(void) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
823 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
824 |
int i = 0; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
825 |
const char *pMappingString = NULL; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
826 |
s_pSupportedControllers = NULL; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
827 |
pMappingString = s_ControllerMappings[i]; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
828 |
while ( pMappingString ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
829 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
830 |
SDL_GameControllerAddMapping( pMappingString ); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
831 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
832 |
i++; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
833 |
pMappingString = s_ControllerMappings[i]; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
834 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
835 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
836 |
/* load in any user supplied config */ |
6976
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
837 |
SDL_GameControllerLoadHints(); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
838 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
839 |
/* watch for joy events and fire controller ones if needed */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
840 |
SDL_AddEventWatch( SDL_GameControllerEventWatcher, NULL ); |
6976
177d1dc3dba6
Load the game controller mapping hint when opening a game controller.
Sam Lantinga <slouken@libsdl.org>
parents:
6975
diff
changeset
|
841 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
842 |
return (0); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
843 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
844 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
845 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
846 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
847 |
* Get the implementation dependent name of a controller |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
848 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
849 |
const char * |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
850 |
SDL_GameControllerNameForIndex(int device_index) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
851 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
852 |
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
853 |
if ( pSupportedController ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
854 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
855 |
return pSupportedController->name; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
856 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
857 |
return NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
858 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
859 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
860 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
861 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
862 |
* Return 1 if the joystick at this device index is a supported controller |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
863 |
*/ |
6871
bd681c870ccf
Check bounds in SDL_IsGameController. Switch two functions to SDL_bool.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6854
diff
changeset
|
864 |
SDL_bool |
bd681c870ccf
Check bounds in SDL_IsGameController. Switch two functions to SDL_bool.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6854
diff
changeset
|
865 |
SDL_IsGameController(int device_index) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
866 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
867 |
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
868 |
if ( pSupportedController ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
869 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
870 |
return SDL_TRUE; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
871 |
} |
6871
bd681c870ccf
Check bounds in SDL_IsGameController. Switch two functions to SDL_bool.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6854
diff
changeset
|
872 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
873 |
return SDL_FALSE; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
874 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
875 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
876 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
877 |
* Open a controller for use - the index passed as an argument refers to |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
878 |
* the N'th controller on the system. This index is the value which will |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
879 |
* identify this controller in future controller events. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
880 |
* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
881 |
* This function returns a controller identifier, or NULL if an error occurred. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
882 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
883 |
SDL_GameController * |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
884 |
SDL_GameControllerOpen(int device_index) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
885 |
{ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
886 |
SDL_GameController *gamecontroller; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
887 |
SDL_GameController *gamecontrollerlist; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
888 |
ControllerMapping_t *pSupportedController = NULL; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
889 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
890 |
if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) { |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
891 |
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks()); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
892 |
return (NULL); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
893 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
894 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
895 |
gamecontrollerlist = SDL_gamecontrollers; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
896 |
/* If the controller is already open, return it */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
897 |
while ( gamecontrollerlist ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
898 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
899 |
if ( SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id ) { |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
900 |
gamecontroller = gamecontrollerlist; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
901 |
++gamecontroller->ref_count; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
902 |
return (gamecontroller); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
903 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
904 |
gamecontrollerlist = gamecontrollerlist->next; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
905 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
906 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
907 |
/* Find a controller mapping */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
908 |
pSupportedController = SDL_PrivateGetControllerMapping(device_index); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
909 |
if ( !pSupportedController ) { |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
910 |
SDL_SetError("Couldn't find mapping for device (%d)", device_index ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
911 |
return (NULL); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
912 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
913 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
914 |
/* Create and initialize the joystick */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
915 |
gamecontroller = (SDL_GameController *) SDL_malloc((sizeof *gamecontroller)); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
916 |
if (gamecontroller == NULL) { |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
917 |
SDL_OutOfMemory(); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
918 |
return NULL; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
919 |
} |
6841 | 920 |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
921 |
SDL_memset(gamecontroller, 0, (sizeof *gamecontroller)); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
922 |
gamecontroller->joystick = SDL_JoystickOpen(device_index); |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
923 |
if ( !gamecontroller->joystick ) { |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
924 |
SDL_free(gamecontroller); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
925 |
return NULL; |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
926 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
927 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
928 |
SDL_PrivateLoadButtonMapping( &gamecontroller->mapping, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping ); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
929 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
930 |
/* Add joystick to list */ |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
931 |
++gamecontroller->ref_count; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
932 |
/* Link the joystick in the list */ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
933 |
gamecontroller->next = SDL_gamecontrollers; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
934 |
SDL_gamecontrollers = gamecontroller; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
935 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
936 |
SDL_SYS_JoystickUpdate( gamecontroller->joystick ); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
937 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
938 |
return (gamecontroller); |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
939 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
940 |
|
6919
c9c75d062fa8
Added SDL_GameControllerUpdate().
Ryan C. Gordon <icculus@icculus.org>
parents:
6917
diff
changeset
|
941 |
/* |
c9c75d062fa8
Added SDL_GameControllerUpdate().
Ryan C. Gordon <icculus@icculus.org>
parents:
6917
diff
changeset
|
942 |
* Manually pump for controller updates. |
c9c75d062fa8
Added SDL_GameControllerUpdate().
Ryan C. Gordon <icculus@icculus.org>
parents:
6917
diff
changeset
|
943 |
*/ |
c9c75d062fa8
Added SDL_GameControllerUpdate().
Ryan C. Gordon <icculus@icculus.org>
parents:
6917
diff
changeset
|
944 |
void |
c9c75d062fa8
Added SDL_GameControllerUpdate().
Ryan C. Gordon <icculus@icculus.org>
parents:
6917
diff
changeset
|
945 |
SDL_GameControllerUpdate(void) |
c9c75d062fa8
Added SDL_GameControllerUpdate().
Ryan C. Gordon <icculus@icculus.org>
parents:
6917
diff
changeset
|
946 |
{ |
c9c75d062fa8
Added SDL_GameControllerUpdate().
Ryan C. Gordon <icculus@icculus.org>
parents:
6917
diff
changeset
|
947 |
/* Just for API completeness; the joystick API does all the work. */ |
c9c75d062fa8
Added SDL_GameControllerUpdate().
Ryan C. Gordon <icculus@icculus.org>
parents:
6917
diff
changeset
|
948 |
SDL_JoystickUpdate(); |
c9c75d062fa8
Added SDL_GameControllerUpdate().
Ryan C. Gordon <icculus@icculus.org>
parents:
6917
diff
changeset
|
949 |
} |
c9c75d062fa8
Added SDL_GameControllerUpdate().
Ryan C. Gordon <icculus@icculus.org>
parents:
6917
diff
changeset
|
950 |
|
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
951 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
952 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
953 |
* Get the current state of an axis control on a controller |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
954 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
955 |
Sint16 |
6917
47dc155b774d
Changed the game controller enum types to match SDL naming conventions.
Ryan C. Gordon <icculus@icculus.org>
parents:
6915
diff
changeset
|
956 |
SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
957 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
958 |
if ( !gamecontroller ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
959 |
return 0; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
960 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
961 |
if (gamecontroller->mapping.axes[axis] >= 0 ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
962 |
{ |
7248
52d3427f8b5a
Add trigger value adjustment code to the SDL_GameControllerGetAxis code as well.
Edward Rudd <urkle@outoforder.cc>
parents:
7247
diff
changeset
|
963 |
Sint16 value = ( SDL_JoystickGetAxis( gamecontroller->joystick, gamecontroller->mapping.axes[axis]) ); |
52d3427f8b5a
Add trigger value adjustment code to the SDL_GameControllerGetAxis code as well.
Edward Rudd <urkle@outoforder.cc>
parents:
7247
diff
changeset
|
964 |
switch (axis) |
52d3427f8b5a
Add trigger value adjustment code to the SDL_GameControllerGetAxis code as well.
Edward Rudd <urkle@outoforder.cc>
parents:
7247
diff
changeset
|
965 |
{ |
52d3427f8b5a
Add trigger value adjustment code to the SDL_GameControllerGetAxis code as well.
Edward Rudd <urkle@outoforder.cc>
parents:
7247
diff
changeset
|
966 |
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: |
52d3427f8b5a
Add trigger value adjustment code to the SDL_GameControllerGetAxis code as well.
Edward Rudd <urkle@outoforder.cc>
parents:
7247
diff
changeset
|
967 |
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: |
52d3427f8b5a
Add trigger value adjustment code to the SDL_GameControllerGetAxis code as well.
Edward Rudd <urkle@outoforder.cc>
parents:
7247
diff
changeset
|
968 |
/* Shift it to be 0 - 32767. */ |
52d3427f8b5a
Add trigger value adjustment code to the SDL_GameControllerGetAxis code as well.
Edward Rudd <urkle@outoforder.cc>
parents:
7247
diff
changeset
|
969 |
value = value / 2 + 16384; |
52d3427f8b5a
Add trigger value adjustment code to the SDL_GameControllerGetAxis code as well.
Edward Rudd <urkle@outoforder.cc>
parents:
7247
diff
changeset
|
970 |
default: |
52d3427f8b5a
Add trigger value adjustment code to the SDL_GameControllerGetAxis code as well.
Edward Rudd <urkle@outoforder.cc>
parents:
7247
diff
changeset
|
971 |
break; |
52d3427f8b5a
Add trigger value adjustment code to the SDL_GameControllerGetAxis code as well.
Edward Rudd <urkle@outoforder.cc>
parents:
7247
diff
changeset
|
972 |
} |
52d3427f8b5a
Add trigger value adjustment code to the SDL_GameControllerGetAxis code as well.
Edward Rudd <urkle@outoforder.cc>
parents:
7247
diff
changeset
|
973 |
return value; |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
974 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
975 |
else if (gamecontroller->mapping.buttonasaxis[axis] >= 0 ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
976 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
977 |
Uint8 value; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
978 |
value = SDL_JoystickGetButton( gamecontroller->joystick, gamecontroller->mapping.buttonasaxis[axis] ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
979 |
if ( value > 0 ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
980 |
return 32767; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
981 |
return 0; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
982 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
983 |
return 0; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
984 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
985 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
986 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
987 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
988 |
* Get the current state of a button on a controller |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
989 |
*/ |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
990 |
Uint8 |
6917
47dc155b774d
Changed the game controller enum types to match SDL naming conventions.
Ryan C. Gordon <icculus@icculus.org>
parents:
6915
diff
changeset
|
991 |
SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
992 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
993 |
if ( !gamecontroller ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
994 |
return 0; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
995 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
996 |
if ( gamecontroller->mapping.buttons[button] >= 0 ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
997 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
998 |
return ( SDL_JoystickGetButton( gamecontroller->joystick, gamecontroller->mapping.buttons[button] ) ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
999 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1000 |
else if ( gamecontroller->mapping.axesasbutton[button] >= 0 ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1001 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1002 |
Sint16 value; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1003 |
value = SDL_JoystickGetAxis( gamecontroller->joystick, gamecontroller->mapping.axesasbutton[button] ); |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1004 |
if ( ABS(value) > 32768/2 ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1005 |
return 1; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1006 |
return 0; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1007 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1008 |
else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1009 |
{ |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1010 |
Uint8 value; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1011 |
value = SDL_JoystickGetHat( gamecontroller->joystick, gamecontroller->mapping.hatasbutton[button].hat ); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1012 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1013 |
if ( value & gamecontroller->mapping.hatasbutton[button].mask ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1014 |
return 1; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1015 |
return 0; |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1016 |
} |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1017 |
|
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1018 |
return 0; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1019 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1020 |
|
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1021 |
/* |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1022 |
* Return if the joystick in question is currently attached to the system, |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1023 |
* \return 0 if not plugged in, 1 if still present. |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1024 |
*/ |
6871
bd681c870ccf
Check bounds in SDL_IsGameController. Switch two functions to SDL_bool.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6854
diff
changeset
|
1025 |
SDL_bool |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1026 |
SDL_GameControllerGetAttached( SDL_GameController * gamecontroller ) |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1027 |
{ |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1028 |
if ( !gamecontroller ) |
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1029 |
return SDL_FALSE; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1030 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7181
diff
changeset
|
1031 |
return SDL_JoystickGetAttached(gamecontroller->joystick); |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1032 |