author | Philipp Wiesemann <philipp.wiesemann@arcor.de> |
Wed, 17 Aug 2016 21:04:50 +0200 | |
changeset 10275 | ba7dc3ebb81e |
parent 9998 | f67cf37e9cd4 |
child 10279 | d1c27f616999 |
permissions | -rw-r--r-- |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/* |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
Simple DirectMedia Layer |
9998
f67cf37e9cd4
Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents:
9835
diff
changeset
|
3 |
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
This software is provided 'as-is', without any express or implied |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
warranty. In no event will the authors be held liable for any damages |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
arising from the use of this software. |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
Permission is granted to anyone to use this software for any purpose, |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
including commercial applications, and to alter it and redistribute it |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
freely, subject to the following restrictions: |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 |
1. The origin of this software must not be misrepresented; you must not |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
claim that you wrote the original software. If you use this software |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
in a product, an acknowledgment in the product documentation would be |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
appreciated but is not required. |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
2. Altered source versions must be plainly marked as such, and must not be |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
misrepresented as being the original software. |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
3. This notice may not be removed or altered from any source distribution. |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 |
*/ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 |
#include "../../SDL_internal.h" |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 |
#ifdef SDL_JOYSTICK_EMSCRIPTEN |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
#include <stdio.h> /* For the definition of NULL */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 |
#include "SDL_error.h" |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 |
#include "SDL_events.h" |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
#if !SDL_EVENTS_DISABLED |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 |
#include "../../events/SDL_events_c.h" |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
#endif |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
#include "SDL_joystick.h" |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
#include "SDL_hints.h" |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
#include "SDL_assert.h" |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 |
#include "SDL_timer.h" |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
#include "SDL_log.h" |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
#include "SDL_sysjoystick_c.h" |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
#include "../SDL_joystick_c.h" |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
static SDL_joylist_item * JoystickByIndex(int index); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 |
static SDL_joylist_item *SDL_joylist = NULL; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
static SDL_joylist_item *SDL_joylist_tail = NULL; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
static int numjoysticks = 0; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
static int instance_counter = 0; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
|
9352
2cbf791a601c
Emscripten: Changed return type of callback implementations from int to EM_BOOL.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9346
diff
changeset
|
49 |
EM_BOOL |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData) |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
{ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
int i; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
SDL_joylist_item *item; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
if (JoystickByIndex(gamepadEvent->index) != NULL) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 |
return 1; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
#if !SDL_EVENTS_DISABLED |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
SDL_Event event; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
#endif |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item)); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
if (item == NULL) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
return 1; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 |
SDL_zerop(item); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 |
item->index = gamepadEvent->index; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
item->name = SDL_strdup(gamepadEvent->id); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
if ( item->name == NULL ) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 |
SDL_free(item); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
return 1; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 |
item->mapping = SDL_strdup(gamepadEvent->mapping); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 |
if ( item->mapping == NULL ) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 |
SDL_free(item->name); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 |
SDL_free(item); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 |
return 1; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 |
item->naxes = gamepadEvent->numAxes; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 |
item->nbuttons = gamepadEvent->numButtons; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 |
item->device_instance = instance_counter++; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
item->timestamp = gamepadEvent->timestamp; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 |
for( i = 0; i < item->naxes; i++) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 |
item->axis[i] = gamepadEvent->axis[i]; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 |
for( i = 0; i < item->nbuttons; i++) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 |
item->analogButton[i] = gamepadEvent->analogButton[i]; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
97 |
item->digitalButton[i] = gamepadEvent->digitalButton[i]; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
99 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 |
if (SDL_joylist_tail == NULL) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 |
SDL_joylist = SDL_joylist_tail = item; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 |
} else { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 |
SDL_joylist_tail->next = item; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 |
SDL_joylist_tail = item; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 |
++numjoysticks; |
9345
bf0874f4fd3a
Emscripten: Deactivated and corrected debug log messages on joystick events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9300
diff
changeset
|
108 |
#ifdef DEBUG_JOYSTICK |
bf0874f4fd3a
Emscripten: Deactivated and corrected debug log messages on joystick events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9300
diff
changeset
|
109 |
SDL_Log("Number of joysticks is %d", numjoysticks); |
bf0874f4fd3a
Emscripten: Deactivated and corrected debug log messages on joystick events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9300
diff
changeset
|
110 |
#endif |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 |
#if !SDL_EVENTS_DISABLED |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 |
event.type = SDL_JOYDEVICEADDED; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 |
if (SDL_GetEventState(event.type) == SDL_ENABLE) { |
9373
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
115 |
event.jdevice.which = numjoysticks - 1; |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 |
if ( (SDL_EventOK == NULL) || |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 |
(*SDL_EventOK) (SDL_EventOKParam, &event) ) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 |
SDL_PushEvent(&event); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 |
#endif /* !SDL_EVENTS_DISABLED */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 |
|
9345
bf0874f4fd3a
Emscripten: Deactivated and corrected debug log messages on joystick events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9300
diff
changeset
|
123 |
#ifdef DEBUG_JOYSTICK |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 |
SDL_Log("Added joystick with index %d", item->index); |
9345
bf0874f4fd3a
Emscripten: Deactivated and corrected debug log messages on joystick events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9300
diff
changeset
|
125 |
#endif |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 |
return 1; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 |
|
9352
2cbf791a601c
Emscripten: Changed return type of callback implementations from int to EM_BOOL.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9346
diff
changeset
|
130 |
EM_BOOL |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 |
Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData) |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
132 |
{ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 |
SDL_joylist_item *item = SDL_joylist; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 |
SDL_joylist_item *prev = NULL; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
135 |
#if !SDL_EVENTS_DISABLED |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
136 |
SDL_Event event; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 |
#endif |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 |
while (item != NULL) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
if (item->index == gamepadEvent->index) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
break; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 |
prev = item; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
144 |
item = item->next; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 |
if (item == NULL) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 |
return 1; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
150 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
151 |
if (item->joystick) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 |
item->joystick->hwdata = NULL; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 |
if (prev != NULL) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 |
prev->next = item->next; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 |
} else { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 |
SDL_assert(SDL_joylist == item); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 |
SDL_joylist = item->next; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 |
if (item == SDL_joylist_tail) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
162 |
SDL_joylist_tail = prev; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 |
/* Need to decrement the joystick count before we post the event */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 |
--numjoysticks; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 |
#if !SDL_EVENTS_DISABLED |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 |
event.type = SDL_JOYDEVICEREMOVED; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 |
if (SDL_GetEventState(event.type) == SDL_ENABLE) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 |
event.jdevice.which = item->device_instance; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
if ( (SDL_EventOK == NULL) || |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 |
(*SDL_EventOK) (SDL_EventOKParam, &event) ) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 |
SDL_PushEvent(&event); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 |
#endif /* !SDL_EVENTS_DISABLED */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 |
|
9345
bf0874f4fd3a
Emscripten: Deactivated and corrected debug log messages on joystick events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9300
diff
changeset
|
180 |
#ifdef DEBUG_JOYSTICK |
bf0874f4fd3a
Emscripten: Deactivated and corrected debug log messages on joystick events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9300
diff
changeset
|
181 |
SDL_Log("Removed joystick with id %d", item->device_instance); |
bf0874f4fd3a
Emscripten: Deactivated and corrected debug log messages on joystick events.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9300
diff
changeset
|
182 |
#endif |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 |
SDL_free(item->name); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 |
SDL_free(item->mapping); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 |
SDL_free(item); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 |
return 1; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 |
/* Function to scan the system for joysticks. |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 |
* It should return 0, or -1 on an unrecoverable fatal error. |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 |
*/ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 |
int |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 |
SDL_SYS_JoystickInit(void) |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 |
{ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 |
int retval, i, numjs; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 |
EmscriptenGamepadEvent gamepadState; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
198 |
numjoysticks = 0; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 |
numjs = emscripten_get_num_gamepads(); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 |
/* Check if gamepad is supported by browser */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 |
if (numjs == EMSCRIPTEN_RESULT_NOT_SUPPORTED) { |
9835
5b266c6b0ac6
Emscripten: Changed return -1 after SDL_SetError() to return SDL_SetError().
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9831
diff
changeset
|
203 |
return SDL_SetError("Gamepads not supported"); |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 |
/* handle already connected gamepads */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 |
if (numjs > 0) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 |
for(i = 0; i < numjs; i++) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 |
retval = emscripten_get_gamepad_status(i, &gamepadState); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 |
if (retval == EMSCRIPTEN_RESULT_SUCCESS) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 |
Emscripten_JoyStickConnected(EMSCRIPTEN_EVENT_GAMEPADCONNECTED, |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
212 |
&gamepadState, |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 |
NULL); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
214 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
215 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 |
retval = emscripten_set_gamepadconnected_callback(NULL, |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 |
0, |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 |
Emscripten_JoyStickConnected); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 |
if(retval != EMSCRIPTEN_RESULT_SUCCESS) { |
9357
620c3c2fb9b9
Emscripten: Fixed receiving joystick events after failed init or subsystem quit.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9353
diff
changeset
|
223 |
SDL_SYS_JoystickQuit(); |
9835
5b266c6b0ac6
Emscripten: Changed return -1 after SDL_SetError() to return SDL_SetError().
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9831
diff
changeset
|
224 |
return SDL_SetError("Could not set gamepad connect callback"); |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 |
retval = emscripten_set_gamepaddisconnected_callback(NULL, |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 |
0, |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 |
Emscripten_JoyStickDisconnected); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
230 |
if(retval != EMSCRIPTEN_RESULT_SUCCESS) { |
9357
620c3c2fb9b9
Emscripten: Fixed receiving joystick events after failed init or subsystem quit.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9353
diff
changeset
|
231 |
SDL_SYS_JoystickQuit(); |
9835
5b266c6b0ac6
Emscripten: Changed return -1 after SDL_SetError() to return SDL_SetError().
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9831
diff
changeset
|
232 |
return SDL_SetError("Could not set gamepad disconnect callback"); |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
233 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 |
return 0; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
236 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 |
|
9373
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
238 |
/* Returns item matching given SDL device index. */ |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
239 |
static SDL_joylist_item * |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
240 |
JoystickByDeviceIndex(int device_index) |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
241 |
{ |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
242 |
SDL_joylist_item *item = SDL_joylist; |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
243 |
|
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
244 |
while (0 < device_index) { |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
245 |
--device_index; |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
246 |
item = item->next; |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
247 |
} |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
248 |
|
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
249 |
return item; |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
250 |
} |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
251 |
|
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
252 |
/* Returns item matching given HTML gamepad index. */ |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 |
static SDL_joylist_item * |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 |
JoystickByIndex(int index) |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 |
{ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 |
SDL_joylist_item *item = SDL_joylist; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 |
if (index < 0) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
259 |
return NULL; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
260 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 |
while (item != NULL) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 |
if (item->index == index) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 |
break; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 |
item = item->next; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 |
return item; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 |
int SDL_SYS_NumJoysticks() |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
273 |
{ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
274 |
return numjoysticks; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
275 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
276 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 |
void SDL_SYS_JoystickDetect() |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 |
{ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 |
/* Function to get the device-dependent name of a joystick */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
282 |
const char * |
9373
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
283 |
SDL_SYS_JoystickNameForDeviceIndex(int device_index) |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
284 |
{ |
9373
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
285 |
return JoystickByDeviceIndex(device_index)->name; |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 |
/* Function to perform the mapping from device index to the instance id for this index */ |
9373
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
289 |
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
290 |
{ |
9373
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
291 |
return JoystickByDeviceIndex(device_index)->device_instance; |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
292 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
293 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 |
/* Function to open a joystick for use. |
9380
07b7c1005a23
Updated internal documentation comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9373
diff
changeset
|
295 |
The joystick to open is specified by the device index. |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 |
This should fill the nbuttons and naxes fields of the joystick structure. |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 |
It returns 0, or -1 if there is an error. |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 |
*/ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 |
int |
9373
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
300 |
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 |
{ |
9373
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
302 |
SDL_joylist_item *item = JoystickByDeviceIndex(device_index); |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
303 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
304 |
if (item == NULL ) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 |
return SDL_SetError("No such device"); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 |
if (item->joystick != NULL) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
309 |
return SDL_SetError("Joystick already opened"); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
310 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 |
joystick->instance_id = item->device_instance; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 |
joystick->hwdata = (struct joystick_hwdata *) item; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 |
item->joystick = joystick; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 |
/* HTML5 Gamepad API doesn't say anything about these */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
317 |
joystick->nhats = 0; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 |
joystick->nballs = 0; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 |
joystick->nbuttons = item->nbuttons; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
321 |
joystick->naxes = item->naxes; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 |
return (0); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
325 |
|
9561
d8ad01792399
Fixed typo in internal joystick documentation comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9560
diff
changeset
|
326 |
/* Function to determine if this joystick is attached to the system right now */ |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
327 |
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
328 |
{ |
9433
bd062398b648
Cleanups in the joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
9380
diff
changeset
|
329 |
return joystick->hwdata != NULL; |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
330 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 |
/* Function to update the state of a joystick - called as a device poll. |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 |
* This function shouldn't update the joystick structure directly, |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
334 |
* but instead should call SDL_PrivateJoystick*() to deliver events |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
335 |
* and update joystick device state. |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
336 |
*/ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 |
void |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
338 |
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
339 |
{ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
340 |
EmscriptenGamepadEvent gamepadState; |
9372
a9bf04588f17
Emscripten: Fixed sending button and motion events for not opened joysticks.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9357
diff
changeset
|
341 |
SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata; |
9291
02b47b8164da
Fixed compile warnings about unused variables.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9278
diff
changeset
|
342 |
int i, result, buttonState; |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
343 |
|
9372
a9bf04588f17
Emscripten: Fixed sending button and motion events for not opened joysticks.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9357
diff
changeset
|
344 |
if (item) { |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
345 |
result = emscripten_get_gamepad_status(item->index, &gamepadState); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
346 |
if( result == EMSCRIPTEN_RESULT_SUCCESS) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
347 |
if(gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
348 |
for(i = 0; i < item->nbuttons; i++) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
349 |
if(item->digitalButton[i] != gamepadState.digitalButton[i]) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
350 |
buttonState = gamepadState.digitalButton[i]? SDL_PRESSED: SDL_RELEASED; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
351 |
SDL_PrivateJoystickButton(item->joystick, i, buttonState); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 |
} |
9560
d1d80a69110b
Emscripten: Simplified implementation of joystick update function.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9433
diff
changeset
|
353 |
|
d1d80a69110b
Emscripten: Simplified implementation of joystick update function.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9433
diff
changeset
|
354 |
/* store values to compare them in the next update */ |
d1d80a69110b
Emscripten: Simplified implementation of joystick update function.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9433
diff
changeset
|
355 |
item->analogButton[i] = gamepadState.analogButton[i]; |
d1d80a69110b
Emscripten: Simplified implementation of joystick update function.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9433
diff
changeset
|
356 |
item->digitalButton[i] = gamepadState.digitalButton[i]; |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
357 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
358 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
359 |
for(i = 0; i < item->naxes; i++) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
360 |
if(item->axis[i] != gamepadState.axis[i]) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
361 |
// do we need to do conversion? |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
362 |
SDL_PrivateJoystickAxis(item->joystick, i, |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
363 |
(Sint16) (32767.*gamepadState.axis[i])); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
364 |
} |
9560
d1d80a69110b
Emscripten: Simplified implementation of joystick update function.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9433
diff
changeset
|
365 |
|
d1d80a69110b
Emscripten: Simplified implementation of joystick update function.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9433
diff
changeset
|
366 |
/* store to compare in next update */ |
d1d80a69110b
Emscripten: Simplified implementation of joystick update function.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9433
diff
changeset
|
367 |
item->axis[i] = gamepadState.axis[i]; |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
368 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
369 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
370 |
item->timestamp = gamepadState.timestamp; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
371 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
372 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
373 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
374 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
375 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
376 |
/* Function to close a joystick after use */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
377 |
void |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
378 |
SDL_SYS_JoystickClose(SDL_Joystick * joystick) |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
379 |
{ |
10275
ba7dc3ebb81e
Emscripten: Fixed opening previously closed joystick.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9998
diff
changeset
|
380 |
SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata; |
ba7dc3ebb81e
Emscripten: Fixed opening previously closed joystick.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9998
diff
changeset
|
381 |
item->joystick = NULL; |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
382 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
383 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
384 |
/* Function to perform any system-specific joystick related cleanup */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
385 |
void |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
386 |
SDL_SYS_JoystickQuit(void) |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
387 |
{ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
388 |
SDL_joylist_item *item = NULL; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
389 |
SDL_joylist_item *next = NULL; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
390 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
391 |
for (item = SDL_joylist; item; item = next) { |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
392 |
next = item->next; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
393 |
SDL_free(item->mapping); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
394 |
SDL_free(item->name); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
395 |
SDL_free(item); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
396 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
397 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
398 |
SDL_joylist = SDL_joylist_tail = NULL; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
399 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
400 |
numjoysticks = 0; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
401 |
instance_counter = 0; |
9357
620c3c2fb9b9
Emscripten: Fixed receiving joystick events after failed init or subsystem quit.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9353
diff
changeset
|
402 |
|
620c3c2fb9b9
Emscripten: Fixed receiving joystick events after failed init or subsystem quit.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9353
diff
changeset
|
403 |
emscripten_set_gamepadconnected_callback(NULL, 0, NULL); |
620c3c2fb9b9
Emscripten: Fixed receiving joystick events after failed init or subsystem quit.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9353
diff
changeset
|
404 |
emscripten_set_gamepaddisconnected_callback(NULL, 0, NULL); |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
405 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
406 |
|
9373
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
407 |
SDL_JoystickGUID |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
408 |
SDL_SYS_JoystickGetDeviceGUID(int device_index) |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
409 |
{ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
410 |
SDL_JoystickGUID guid; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
411 |
/* the GUID is just the first 16 chars of the name for now */ |
9373
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
412 |
const char *name = SDL_SYS_JoystickNameForDeviceIndex(device_index); |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
413 |
SDL_zero(guid); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
414 |
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name))); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
415 |
return guid; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
416 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
417 |
|
9373
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
418 |
SDL_JoystickGUID |
679eb3986e37
Emscripten: Fixed out of range joystick device index after joystick disconnect.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9372
diff
changeset
|
419 |
SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) |
9278
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
420 |
{ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
421 |
SDL_JoystickGUID guid; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
422 |
/* the GUID is just the first 16 chars of the name for now */ |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
423 |
const char *name = joystick->name; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
424 |
SDL_zero(guid); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
425 |
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name))); |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
426 |
return guid; |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
427 |
} |
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
428 |
|
8900afb78a19
Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
429 |
#endif /* SDL_JOYSTICK_EMSCRIPTEN */ |