author | Sam Lantinga <slouken@libsdl.org> |
Fri, 26 Aug 2016 12:18:08 -0700 | |
changeset 10281 | cb13d22b7f09 |
parent 9998 | f67cf37e9cd4 |
child 10283 | 9a277db2806d |
permissions | -rw-r--r-- |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
/* |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
2 |
Simple DirectMedia Layer |
9998
f67cf37e9cd4
Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents:
9960
diff
changeset
|
3 |
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
5 |
This software is provided 'as-is', without any express or implied |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
6 |
warranty. In no event will the authors be held liable for any damages |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
7 |
arising from the use of this software. |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
9 |
Permission is granted to anyone to use this software for any purpose, |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
10 |
including commercial applications, and to alter it and redistribute it |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
11 |
freely, subject to the following restrictions: |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
13 |
1. The origin of this software must not be misrepresented; you must not |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
14 |
claim that you wrote the original software. If you use this software |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
15 |
in a product, an acknowledgment in the product documentation would be |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
16 |
appreciated but is not required. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
17 |
2. Altered source versions must be plainly marked as such, and must not be |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
18 |
misrepresented as being the original software. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
19 |
3. This notice may not be removed or altered from any source distribution. |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 |
*/ |
8093
b43765095a6f
Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents:
7861
diff
changeset
|
21 |
#include "../../SDL_internal.h" |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
|
8138
0fbc97d82043
Fixed comments in joystick implementation files claiming to be headers.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
8093
diff
changeset
|
23 |
/* This is the iOS implementation of the SDL joystick API */ |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
24 |
#include "SDL_sysjoystick_c.h" |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
25 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
26 |
/* needed for SDL_IPHONE_MAX_GFORCE macro */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
27 |
#include "SDL_config_iphoneos.h" |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
|
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
#include "SDL_joystick.h" |
9489
6cd0275146b3
iOS now respects SDL_HINT_ACCELEROMETER_AS_JOYSTICK.
Alex Szpakowski <slime73@gmail.com>
parents:
8921
diff
changeset
|
30 |
#include "SDL_hints.h" |
8921
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
31 |
#include "SDL_stdinc.h" |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
#include "../SDL_sysjoystick.h" |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 |
#include "../SDL_joystick_c.h" |
8921
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
34 |
|
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
35 |
#import <CoreMotion/CoreMotion.h> |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
|
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
37 |
#ifdef SDL_JOYSTICK_MFI |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
38 |
#import <GameController/GameController.h> |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
39 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
40 |
static id connectObserver = nil; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
41 |
static id disconnectObserver = nil; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
42 |
#endif /* SDL_JOYSTICK_MFI */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
43 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
44 |
static const char *accelerometerName = "iOS Accelerometer"; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
45 |
static CMMotionManager *motionManager = nil; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
46 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
47 |
static SDL_JoystickDeviceItem *deviceList = NULL; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
48 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
49 |
static int numjoysticks = 0; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
50 |
static SDL_JoystickID instancecounter = 0; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
51 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
52 |
static SDL_JoystickDeviceItem * |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
53 |
GetDeviceForIndex(int device_index) |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
54 |
{ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
55 |
SDL_JoystickDeviceItem *device = deviceList; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
56 |
int i = 0; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
57 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
58 |
while (i < device_index) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
59 |
if (device == NULL) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
60 |
return NULL; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
61 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
62 |
device = device->next; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
63 |
i++; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
64 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
65 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
66 |
return device; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
67 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
68 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
69 |
static void |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
70 |
SDL_SYS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controller) |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
71 |
{ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
72 |
#ifdef SDL_JOYSTICK_MFI |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
73 |
const char *name = NULL; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
74 |
/* Explicitly retain the controller because SDL_JoystickDeviceItem is a |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
75 |
* struct, and ARC doesn't work with structs. */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
76 |
device->controller = (__bridge GCController *) CFBridgingRetain(controller); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
77 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
78 |
if (controller.vendorName) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
79 |
name = controller.vendorName.UTF8String; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
80 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
81 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
82 |
if (!name) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
83 |
name = "MFi Gamepad"; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
84 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
85 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
86 |
device->name = SDL_strdup(name); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
87 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
88 |
device->guid.data[0] = 'M'; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
89 |
device->guid.data[1] = 'F'; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
90 |
device->guid.data[2] = 'i'; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
91 |
device->guid.data[3] = 'G'; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
92 |
device->guid.data[4] = 'a'; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
93 |
device->guid.data[5] = 'm'; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
94 |
device->guid.data[6] = 'e'; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
95 |
device->guid.data[7] = 'p'; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
96 |
device->guid.data[8] = 'a'; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
97 |
device->guid.data[9] = 'd'; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
98 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
99 |
if (controller.extendedGamepad) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
100 |
device->guid.data[10] = 1; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
101 |
} else if (controller.gamepad) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
102 |
device->guid.data[10] = 2; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
103 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
104 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
105 |
if (controller.extendedGamepad) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
106 |
device->naxes = 6; /* 2 thumbsticks and 2 triggers */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
107 |
device->nhats = 1; /* d-pad */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
108 |
device->nbuttons = 7; /* ABXY, shoulder buttons, pause button */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
109 |
} else if (controller.gamepad) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
110 |
device->naxes = 0; /* no traditional analog inputs */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
111 |
device->nhats = 1; /* d-pad */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
112 |
device->nbuttons = 7; /* ABXY, shoulder buttons, pause button */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
113 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
114 |
/* TODO: Handle micro profiles on tvOS. */ |
9960
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
115 |
|
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
116 |
/* This will be set when the first button press of the controller is |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
117 |
* detected. */ |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
118 |
controller.playerIndex = -1; |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
119 |
#endif |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
120 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
121 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
122 |
static void |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
123 |
SDL_SYS_AddJoystickDevice(GCController *controller, SDL_bool accelerometer) |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
124 |
{ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
125 |
SDL_JoystickDeviceItem *device = deviceList; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
126 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
127 |
while (device != NULL) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
128 |
if (device->controller == controller) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
129 |
return; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
130 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
131 |
device = device->next; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
132 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
133 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
134 |
device = (SDL_JoystickDeviceItem *) SDL_malloc(sizeof(SDL_JoystickDeviceItem)); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
135 |
if (device == NULL) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
136 |
return; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
137 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
138 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
139 |
SDL_zerop(device); |
8921
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
140 |
|
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
141 |
device->accelerometer = accelerometer; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
142 |
device->instance_id = instancecounter++; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
143 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
144 |
if (accelerometer) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
145 |
device->name = SDL_strdup(accelerometerName); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
146 |
device->naxes = 3; /* Device acceleration in the x, y, and z axes. */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
147 |
device->nhats = 0; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
148 |
device->nbuttons = 0; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
149 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
150 |
/* Use the accelerometer name as a GUID. */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
151 |
SDL_memcpy(&device->guid.data, device->name, SDL_min(sizeof(SDL_JoystickGUID), SDL_strlen(device->name))); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
152 |
} else if (controller) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
153 |
SDL_SYS_AddMFIJoystickDevice(device, controller); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
154 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
155 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
156 |
if (deviceList == NULL) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
157 |
deviceList = device; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
158 |
} else { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
159 |
SDL_JoystickDeviceItem *lastdevice = deviceList; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
160 |
while (lastdevice->next != NULL) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
161 |
lastdevice = lastdevice->next; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
162 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
163 |
lastdevice->next = device; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
164 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
165 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
166 |
++numjoysticks; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
167 |
|
10281
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
168 |
SDL_PrivateJoystickAdded(numjoysticks - 1); |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
169 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
170 |
|
9879
8465a79c9f85
iOS: show message boxes using the new UIAlertController APIs when supported, rather than the deprecated UIAlertView.
Alex Szpakowski <slime73@gmail.com>
parents:
9878
diff
changeset
|
171 |
static SDL_JoystickDeviceItem * |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
172 |
SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device) |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
173 |
{ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
174 |
SDL_JoystickDeviceItem *prev = NULL; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
175 |
SDL_JoystickDeviceItem *next = NULL; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
176 |
SDL_JoystickDeviceItem *item = deviceList; |
8921
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
177 |
|
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
178 |
if (device == NULL) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
179 |
return NULL; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
180 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
181 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
182 |
next = device->next; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
183 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
184 |
while (item != NULL) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
185 |
if (item == device) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
186 |
break; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
187 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
188 |
prev = item; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
189 |
item = item->next; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
190 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
191 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
192 |
/* Unlink the device item from the device list. */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
193 |
if (prev) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
194 |
prev->next = device->next; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
195 |
} else if (device == deviceList) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
196 |
deviceList = device->next; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
197 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
198 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
199 |
if (device->joystick) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
200 |
device->joystick->hwdata = NULL; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
201 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
202 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
203 |
#ifdef SDL_JOYSTICK_MFI |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
204 |
@autoreleasepool { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
205 |
if (device->controller) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
206 |
/* The controller was explicitly retained in the struct, so it |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
207 |
* should be explicitly released before freeing the struct. */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
208 |
GCController *controller = CFBridgingRelease((__bridge CFTypeRef)(device->controller)); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
209 |
controller.controllerPausedHandler = nil; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
210 |
device->controller = nil; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
211 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
212 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
213 |
#endif /* SDL_JOYSTICK_MFI */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
214 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
215 |
--numjoysticks; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
216 |
|
10281
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
9998
diff
changeset
|
217 |
SDL_PrivateJoystickRemoved(device->instance_id); |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
218 |
|
9878
63f03a567fe3
iOS: Fixed pointer dereference after free.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9876
diff
changeset
|
219 |
SDL_free(device->name); |
63f03a567fe3
iOS: Fixed pointer dereference after free.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9876
diff
changeset
|
220 |
SDL_free(device); |
63f03a567fe3
iOS: Fixed pointer dereference after free.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9876
diff
changeset
|
221 |
|
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
222 |
return next; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
223 |
} |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 |
|
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 |
/* Function to scan the system for joysticks. |
9311
a4b031e28de8
Fixed wrong documentation in joystick implementation source.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
8921
diff
changeset
|
226 |
* Joystick 0 should be the system default joystick. |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 |
* It should return 0, or -1 on an unrecoverable fatal error. |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 |
*/ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 |
int |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 |
SDL_SYS_JoystickInit(void) |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 |
{ |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
232 |
@autoreleasepool { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
233 |
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
234 |
const char *hint = SDL_GetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
235 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
236 |
if (!hint || SDL_atoi(hint)) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
237 |
/* Default behavior, accelerometer as joystick */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
238 |
SDL_SYS_AddJoystickDevice(nil, SDL_TRUE); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
239 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
240 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
241 |
#ifdef SDL_JOYSTICK_MFI |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
242 |
/* GameController.framework was added in iOS 7. */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
243 |
if (![GCController class]) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
244 |
return numjoysticks; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
245 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
246 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
247 |
for (GCController *controller in [GCController controllers]) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
248 |
SDL_SYS_AddJoystickDevice(controller, SDL_FALSE); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
249 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
250 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
251 |
connectObserver = [center addObserverForName:GCControllerDidConnectNotification |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
252 |
object:nil |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
253 |
queue:nil |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
254 |
usingBlock:^(NSNotification *note) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
255 |
GCController *controller = note.object; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
256 |
SDL_SYS_AddJoystickDevice(controller, SDL_FALSE); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
257 |
}]; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
258 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
259 |
disconnectObserver = [center addObserverForName:GCControllerDidDisconnectNotification |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
260 |
object:nil |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
261 |
queue:nil |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
262 |
usingBlock:^(NSNotification *note) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
263 |
GCController *controller = note.object; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
264 |
SDL_JoystickDeviceItem *device = deviceList; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
265 |
while (device != NULL) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
266 |
if (device->controller == controller) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
267 |
SDL_SYS_RemoveJoystickDevice(device); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
268 |
break; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
269 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
270 |
device = device->next; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
271 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
272 |
}]; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
273 |
#endif /* SDL_JOYSTICK_MFI */ |
9489
6cd0275146b3
iOS now respects SDL_HINT_ACCELEROMETER_AS_JOYSTICK.
Alex Szpakowski <slime73@gmail.com>
parents:
8921
diff
changeset
|
274 |
} |
6cd0275146b3
iOS now respects SDL_HINT_ACCELEROMETER_AS_JOYSTICK.
Alex Szpakowski <slime73@gmail.com>
parents:
8921
diff
changeset
|
275 |
|
6cd0275146b3
iOS now respects SDL_HINT_ACCELEROMETER_AS_JOYSTICK.
Alex Szpakowski <slime73@gmail.com>
parents:
8921
diff
changeset
|
276 |
return numjoysticks; |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 |
} |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 |
|
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
279 |
int SDL_SYS_NumJoysticks() |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
280 |
{ |
9489
6cd0275146b3
iOS now respects SDL_HINT_ACCELEROMETER_AS_JOYSTICK.
Alex Szpakowski <slime73@gmail.com>
parents:
8921
diff
changeset
|
281 |
return numjoysticks; |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
282 |
} |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
283 |
|
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
284 |
void SDL_SYS_JoystickDetect() |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
285 |
{ |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
286 |
} |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
287 |
|
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 |
/* Function to get the device-dependent name of a joystick */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 |
const char * |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
290 |
SDL_SYS_JoystickNameForDeviceIndex(int device_index) |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 |
{ |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
292 |
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
293 |
return device ? device->name : "Unknown"; |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
294 |
} |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
295 |
|
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
296 |
/* Function to perform the mapping from device index to the instance id for this index */ |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
297 |
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
298 |
{ |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
299 |
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
300 |
return device ? device->instance_id : 0; |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 |
} |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 |
|
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 |
/* Function to open a joystick for use. |
9380
07b7c1005a23
Updated internal documentation comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9311
diff
changeset
|
304 |
The joystick to open is specified by the device index. |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 |
This should fill the nbuttons and naxes fields of the joystick structure. |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 |
It returns 0, or -1 if there is an error. |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 |
*/ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 |
int |
6693
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
309 |
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 |
{ |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
311 |
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
312 |
if (device == NULL) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
313 |
return SDL_SetError("Could not open Joystick: no hardware device for the specified index"); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
314 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
315 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
316 |
joystick->hwdata = device; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
317 |
joystick->instance_id = device->instance_id; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
318 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
319 |
joystick->naxes = device->naxes; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
320 |
joystick->nhats = device->nhats; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
321 |
joystick->nbuttons = device->nbuttons; |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
322 |
joystick->nballs = 0; |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
323 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
324 |
device->joystick = joystick; |
8921
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
325 |
|
9506
18e3f94bd860
Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents:
9490
diff
changeset
|
326 |
@autoreleasepool { |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
327 |
if (device->accelerometer) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
328 |
if (motionManager == nil) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
329 |
motionManager = [[CMMotionManager alloc] init]; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
330 |
} |
8921
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
331 |
|
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
332 |
/* Shorter times between updates can significantly increase CPU usage. */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
333 |
motionManager.accelerometerUpdateInterval = 0.1; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
334 |
[motionManager startAccelerometerUpdates]; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
335 |
} else { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
336 |
#ifdef SDL_JOYSTICK_MFI |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
337 |
GCController *controller = device->controller; |
9960
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
338 |
controller.controllerPausedHandler = ^(GCController *c) { |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
339 |
if (joystick->hwdata) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
340 |
++joystick->hwdata->num_pause_presses; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
341 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
342 |
}; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
343 |
#endif /* SDL_JOYSTICK_MFI */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
344 |
} |
9506
18e3f94bd860
Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents:
9490
diff
changeset
|
345 |
} |
8921
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
346 |
|
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
347 |
return 0; |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
348 |
} |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
349 |
|
9561
d8ad01792399
Fixed typo in internal joystick documentation comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9536
diff
changeset
|
350 |
/* Function to determine if this joystick is attached to the system right now */ |
9879
8465a79c9f85
iOS: show message boxes using the new UIAlertController APIs when supported, rather than the deprecated UIAlertView.
Alex Szpakowski <slime73@gmail.com>
parents:
9878
diff
changeset
|
351 |
SDL_bool |
8465a79c9f85
iOS: show message boxes using the new UIAlertController APIs when supported, rather than the deprecated UIAlertView.
Alex Szpakowski <slime73@gmail.com>
parents:
9878
diff
changeset
|
352 |
SDL_SYS_JoystickAttached(SDL_Joystick *joystick) |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
353 |
{ |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
354 |
return joystick->hwdata != NULL; |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 |
} |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 |
|
9879
8465a79c9f85
iOS: show message boxes using the new UIAlertController APIs when supported, rather than the deprecated UIAlertView.
Alex Szpakowski <slime73@gmail.com>
parents:
9878
diff
changeset
|
357 |
static void |
8465a79c9f85
iOS: show message boxes using the new UIAlertController APIs when supported, rather than the deprecated UIAlertView.
Alex Szpakowski <slime73@gmail.com>
parents:
9878
diff
changeset
|
358 |
SDL_SYS_AccelerometerUpdate(SDL_Joystick * joystick) |
8921
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
359 |
{ |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
360 |
const float maxgforce = SDL_IPHONE_MAX_GFORCE; |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
361 |
const SInt16 maxsint16 = 0x7FFF; |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
362 |
CMAcceleration accel; |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
363 |
|
9506
18e3f94bd860
Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents:
9490
diff
changeset
|
364 |
@autoreleasepool { |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
365 |
if (!motionManager.isAccelerometerActive) { |
9506
18e3f94bd860
Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents:
9490
diff
changeset
|
366 |
return; |
18e3f94bd860
Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents:
9490
diff
changeset
|
367 |
} |
18e3f94bd860
Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents:
9490
diff
changeset
|
368 |
|
18e3f94bd860
Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents:
9490
diff
changeset
|
369 |
accel = motionManager.accelerometerData.acceleration; |
8921
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
370 |
} |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
371 |
|
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
372 |
/* |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
373 |
Convert accelerometer data from floating point to Sint16, which is what |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
374 |
the joystick system expects. |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
375 |
|
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
376 |
To do the conversion, the data is first clamped onto the interval |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
377 |
[-SDL_IPHONE_MAX_G_FORCE, SDL_IPHONE_MAX_G_FORCE], then the data is multiplied |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
378 |
by MAX_SINT16 so that it is mapped to the full range of an Sint16. |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
379 |
|
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
380 |
You can customize the clamped range of this function by modifying the |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
381 |
SDL_IPHONE_MAX_GFORCE macro in SDL_config_iphoneos.h. |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
382 |
|
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
383 |
Once converted to Sint16, the accelerometer data no longer has coherent |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
384 |
units. You can convert the data back to units of g-force by multiplying |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
385 |
it in your application's code by SDL_IPHONE_MAX_GFORCE / 0x7FFF. |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
386 |
*/ |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
387 |
|
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
388 |
/* clamp the data */ |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
389 |
accel.x = SDL_min(SDL_max(accel.x, -maxgforce), maxgforce); |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
390 |
accel.y = SDL_min(SDL_max(accel.y, -maxgforce), maxgforce); |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
391 |
accel.z = SDL_min(SDL_max(accel.z, -maxgforce), maxgforce); |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
392 |
|
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
393 |
/* pass in data mapped to range of SInt16 */ |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
394 |
SDL_PrivateJoystickAxis(joystick, 0, (accel.x / maxgforce) * maxsint16); |
8921
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
395 |
SDL_PrivateJoystickAxis(joystick, 1, -(accel.y / maxgforce) * maxsint16); |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
396 |
SDL_PrivateJoystickAxis(joystick, 2, (accel.z / maxgforce) * maxsint16); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
397 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
398 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
399 |
#ifdef SDL_JOYSTICK_MFI |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
400 |
static Uint8 |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
401 |
SDL_SYS_MFIJoystickHatStateForDPad(GCControllerDirectionPad *dpad) |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
402 |
{ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
403 |
Uint8 hat = 0; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
404 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
405 |
if (dpad.up.isPressed) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
406 |
hat |= SDL_HAT_UP; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
407 |
} else if (dpad.down.isPressed) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
408 |
hat |= SDL_HAT_DOWN; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
409 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
410 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
411 |
if (dpad.left.isPressed) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
412 |
hat |= SDL_HAT_LEFT; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
413 |
} else if (dpad.right.isPressed) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
414 |
hat |= SDL_HAT_RIGHT; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
415 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
416 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
417 |
if (hat == 0) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
418 |
return SDL_HAT_CENTERED; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
419 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
420 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
421 |
return hat; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
422 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
423 |
#endif |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
424 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
425 |
static void |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
426 |
SDL_SYS_MFIJoystickUpdate(SDL_Joystick * joystick) |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
427 |
{ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
428 |
#ifdef SDL_JOYSTICK_MFI |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
429 |
@autoreleasepool { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
430 |
GCController *controller = joystick->hwdata->controller; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
431 |
Uint8 hatstate = SDL_HAT_CENTERED; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
432 |
int i; |
9960
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
433 |
int updateplayerindex = 0; |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
434 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
435 |
if (controller.extendedGamepad) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
436 |
GCExtendedGamepad *gamepad = controller.extendedGamepad; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
437 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
438 |
/* Axis order matches the XInput Windows mappings. */ |
9960
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
439 |
Sint16 axes[] = { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
440 |
(Sint16) (gamepad.leftThumbstick.xAxis.value * 32767), |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
441 |
(Sint16) (gamepad.leftThumbstick.yAxis.value * -32767), |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
442 |
(Sint16) ((gamepad.leftTrigger.value * 65535) - 32768), |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
443 |
(Sint16) (gamepad.rightThumbstick.xAxis.value * 32767), |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
444 |
(Sint16) (gamepad.rightThumbstick.yAxis.value * -32767), |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
445 |
(Sint16) ((gamepad.rightTrigger.value * 65535) - 32768), |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
446 |
}; |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
447 |
|
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
448 |
/* Button order matches the XInput Windows mappings. */ |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
449 |
Uint8 buttons[] = { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
450 |
gamepad.buttonA.isPressed, gamepad.buttonB.isPressed, |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
451 |
gamepad.buttonX.isPressed, gamepad.buttonY.isPressed, |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
452 |
gamepad.leftShoulder.isPressed, |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
453 |
gamepad.rightShoulder.isPressed, |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
454 |
}; |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
455 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
456 |
hatstate = SDL_SYS_MFIJoystickHatStateForDPad(gamepad.dpad); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
457 |
|
9960
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
458 |
for (i = 0; i < SDL_arraysize(axes); i++) { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
459 |
/* The triggers (axes 2 and 5) are resting at -32768 but SDL |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
460 |
* initializes its values to 0. We only want to make sure the |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
461 |
* player index is up to date if the user actually moves an axis. */ |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
462 |
if ((i != 2 && i != 5) || axes[i] != -32768) { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
463 |
updateplayerindex |= (joystick->axes[i] != axes[i]); |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
464 |
} |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
465 |
SDL_PrivateJoystickAxis(joystick, i, axes[i]); |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
466 |
} |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
467 |
|
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
468 |
for (i = 0; i < SDL_arraysize(buttons); i++) { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
469 |
updateplayerindex |= (joystick->buttons[i] != buttons[i]); |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
470 |
SDL_PrivateJoystickButton(joystick, i, buttons[i]); |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
471 |
} |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
472 |
} else if (controller.gamepad) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
473 |
GCGamepad *gamepad = controller.gamepad; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
474 |
|
9960
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
475 |
/* Button order matches the XInput Windows mappings. */ |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
476 |
Uint8 buttons[] = { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
477 |
gamepad.buttonA.isPressed, gamepad.buttonB.isPressed, |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
478 |
gamepad.buttonX.isPressed, gamepad.buttonY.isPressed, |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
479 |
gamepad.leftShoulder.isPressed, |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
480 |
gamepad.rightShoulder.isPressed, |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
481 |
}; |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
482 |
|
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
483 |
hatstate = SDL_SYS_MFIJoystickHatStateForDPad(gamepad.dpad); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
484 |
|
9960
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
485 |
for (i = 0; i < SDL_arraysize(buttons); i++) { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
486 |
updateplayerindex |= (joystick->buttons[i] != buttons[i]); |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
487 |
SDL_PrivateJoystickButton(joystick, i, buttons[i]); |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
488 |
} |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
489 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
490 |
/* TODO: Handle micro profiles on tvOS. */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
491 |
|
9960
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
492 |
if (joystick->nhats > 0) { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
493 |
updateplayerindex |= (joystick->hats[0] != hatstate); |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
494 |
SDL_PrivateJoystickHat(joystick, 0, hatstate); |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
495 |
} |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
496 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
497 |
for (i = 0; i < joystick->hwdata->num_pause_presses; i++) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
498 |
/* The pause button is always last. */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
499 |
Uint8 pausebutton = joystick->nbuttons - 1; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
500 |
|
9960
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
501 |
SDL_PrivateJoystickButton(joystick, pausebutton, SDL_PRESSED); |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
502 |
SDL_PrivateJoystickButton(joystick, pausebutton, SDL_RELEASED); |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
503 |
|
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
504 |
updateplayerindex = YES; |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
505 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
506 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
507 |
joystick->hwdata->num_pause_presses = 0; |
9960
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
508 |
|
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
509 |
if (updateplayerindex && controller.playerIndex == -1) { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
510 |
BOOL usedPlayerIndexSlots[4] = {NO, NO, NO, NO}; |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
511 |
|
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
512 |
/* Find the player index of all other connected controllers. */ |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
513 |
for (GCController *c in [GCController controllers]) { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
514 |
if (c != controller && c.playerIndex >= 0) { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
515 |
usedPlayerIndexSlots[c.playerIndex] = YES; |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
516 |
} |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
517 |
} |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
518 |
|
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
519 |
/* Set this controller's player index to the first unused index. |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
520 |
* FIXME: This logic isn't great... but SDL doesn't expose this |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
521 |
* concept in its external API, so we don't have much to go on. */ |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
522 |
for (i = 0; i < SDL_arraysize(usedPlayerIndexSlots); i++) { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
523 |
if (!usedPlayerIndexSlots[i]) { |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
524 |
controller.playerIndex = i; |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
525 |
break; |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
526 |
} |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
527 |
} |
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
528 |
} |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
529 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
530 |
#endif |
8921
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
531 |
} |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
532 |
|
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
533 |
/* Function to update the state of a joystick - called as a device poll. |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
534 |
* This function shouldn't update the joystick structure directly, |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
535 |
* but instead should call SDL_PrivateJoystick*() to deliver events |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
536 |
* and update joystick device state. |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
537 |
*/ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
538 |
void |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
539 |
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
540 |
{ |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
541 |
SDL_JoystickDeviceItem *device = joystick->hwdata; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
542 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
543 |
if (device == NULL) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
544 |
return; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
545 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
546 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
547 |
if (device->accelerometer) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
548 |
SDL_SYS_AccelerometerUpdate(joystick); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
549 |
} else if (device->controller) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
550 |
SDL_SYS_MFIJoystickUpdate(joystick); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
551 |
} |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
552 |
} |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
553 |
|
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
554 |
/* Function to close a joystick after use */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
555 |
void |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
556 |
SDL_SYS_JoystickClose(SDL_Joystick * joystick) |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
557 |
{ |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
558 |
SDL_JoystickDeviceItem *device = joystick->hwdata; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
559 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
560 |
if (device == NULL) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
561 |
return; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
562 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
563 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
564 |
device->joystick = NULL; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
565 |
|
9506
18e3f94bd860
Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents:
9490
diff
changeset
|
566 |
@autoreleasepool { |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
567 |
if (device->accelerometer) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
568 |
[motionManager stopAccelerometerUpdates]; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
569 |
} else if (device->controller) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
570 |
#ifdef SDL_JOYSTICK_MFI |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
571 |
GCController *controller = device->controller; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
572 |
controller.controllerPausedHandler = nil; |
9960
a20484c998da
iOS: Set the player index of MFi gamepads when the user first presses a button, rather than when it's programatically opened.
Alex Szpakowski <slime73@gmail.com>
parents:
9909
diff
changeset
|
573 |
controller.playerIndex = -1; |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
574 |
#endif |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
575 |
} |
9506
18e3f94bd860
Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents:
9490
diff
changeset
|
576 |
} |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
577 |
} |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
578 |
|
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
579 |
/* Function to perform any system-specific joystick related cleanup */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
580 |
void |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
581 |
SDL_SYS_JoystickQuit(void) |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
582 |
{ |
9506
18e3f94bd860
Added missing autorelease pool blocks in UIKit backend code. Fixes memory leak issues, especially in SDL_video.
Alex Szpakowski <slime73@gmail.com>
parents:
9490
diff
changeset
|
583 |
@autoreleasepool { |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
584 |
#ifdef SDL_JOYSTICK_MFI |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
585 |
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
586 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
587 |
if (connectObserver) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
588 |
[center removeObserver:connectObserver name:GCControllerDidConnectNotification object:nil]; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
589 |
connectObserver = nil; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
590 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
591 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
592 |
if (disconnectObserver) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
593 |
[center removeObserver:disconnectObserver name:GCControllerDidDisconnectNotification object:nil]; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
594 |
disconnectObserver = nil; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
595 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
596 |
#endif /* SDL_JOYSTICK_MFI */ |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
597 |
|
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
598 |
while (deviceList != NULL) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
599 |
SDL_SYS_RemoveJoystickDevice(deviceList); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
600 |
} |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
601 |
|
8921
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
602 |
motionManager = nil; |
4a9feef61c85
Fixed bug 2603 - iOS: update joystick accelerometer code to use CoreMotion instead of the deprecated UIAccelerometer
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
603 |
} |
9489
6cd0275146b3
iOS now respects SDL_HINT_ACCELEROMETER_AS_JOYSTICK.
Alex Szpakowski <slime73@gmail.com>
parents:
8921
diff
changeset
|
604 |
|
6cd0275146b3
iOS now respects SDL_HINT_ACCELEROMETER_AS_JOYSTICK.
Alex Szpakowski <slime73@gmail.com>
parents:
8921
diff
changeset
|
605 |
numjoysticks = 0; |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
606 |
} |
6693
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
607 |
|
9879
8465a79c9f85
iOS: show message boxes using the new UIAlertController APIs when supported, rather than the deprecated UIAlertView.
Alex Szpakowski <slime73@gmail.com>
parents:
9878
diff
changeset
|
608 |
SDL_JoystickGUID |
8465a79c9f85
iOS: show message boxes using the new UIAlertController APIs when supported, rather than the deprecated UIAlertView.
Alex Szpakowski <slime73@gmail.com>
parents:
9878
diff
changeset
|
609 |
SDL_SYS_JoystickGetDeviceGUID( int device_index ) |
6693
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
610 |
{ |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
611 |
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index); |
6744
4ac2bb6dc80c
Fixed joystick GUID renaming for other platforms
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
612 |
SDL_JoystickGUID guid; |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
613 |
if (device) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
614 |
guid = device->guid; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
615 |
} else { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
616 |
SDL_zero(guid); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
617 |
} |
6693
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
618 |
return guid; |
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
619 |
} |
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
620 |
|
9879
8465a79c9f85
iOS: show message boxes using the new UIAlertController APIs when supported, rather than the deprecated UIAlertView.
Alex Szpakowski <slime73@gmail.com>
parents:
9878
diff
changeset
|
621 |
SDL_JoystickGUID |
8465a79c9f85
iOS: show message boxes using the new UIAlertController APIs when supported, rather than the deprecated UIAlertView.
Alex Szpakowski <slime73@gmail.com>
parents:
9878
diff
changeset
|
622 |
SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) |
6693
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
623 |
{ |
6744
4ac2bb6dc80c
Fixed joystick GUID renaming for other platforms
Sam Lantinga <slouken@libsdl.org>
parents:
6707
diff
changeset
|
624 |
SDL_JoystickGUID guid; |
9876
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
625 |
if (joystick->hwdata) { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
626 |
guid = joystick->hwdata->guid; |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
627 |
} else { |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
628 |
SDL_zero(guid); |
1496e502e51d
Added initial support for MFi game controllers on iOS.
Alex Szpakowski <slime73@gmail.com>
parents:
9619
diff
changeset
|
629 |
} |
6693
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
630 |
return guid; |
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
631 |
} |
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
632 |
|
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
633 |
/* vi: set ts=4 sw=4 expandtab: */ |