ObjFW  Diff

Differences From Artifact [49ccebbc34]:

To Artifact [f3d0e406e6]:


15
16
17
18
19
20
21
22

23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67


68
69
70

71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
15
16
17
18
19
20
21

22
23
24
25
26
27

28
29












30

























31
32

33

34
35
36

37








38
39
40
41
42
43
44

45
46
47
48
49
50
51
52







-
+





-
+

-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-

-
+


-
+
-
-
-
-
-
-
-
-







-
+







 * You should have received a copy of the GNU Lesser General Public License
 * version 3.0 along with this program. If not, see
 * <https://www.gnu.org/licenses/>.
 */

#include "config.h"

#import "OFGameController.h"
#import "HIDGameController.h"
#import "OFArray.h"
#import "OFNumber.h"
#import "OFSet.h"

#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# include "OFEvdevGameController.h"
# include "HIDEvdevGameController.h"
#endif
#ifdef OF_WINDOWS
# include "OFXInputGameController.h"
#endif
#ifdef OF_WII
# include "OFWiiGameController.h"
#endif
#ifdef OF_NINTENDO_DS
# include "OFNintendoDSGameController.h"
#endif
#ifdef OF_NINTENDO_3DS
# include "OFNintendo3DSGameController.h"
#endif

const OFGameControllerButton OFGameControllerNorthButton = @"North";
const OFGameControllerButton OFGameControllerSouthButton = @"South";
const OFGameControllerButton OFGameControllerWestButton = @"West";
const OFGameControllerButton OFGameControllerEastButton = @"East";
const OFGameControllerButton OFGameControllerLeftTriggerButton =
    @"Left Trigger";
const OFGameControllerButton OFGameControllerRightTriggerButton =
    @"Right Trigger";
const OFGameControllerButton OFGameControllerLeftShoulderButton =
    @"Left Shoulder";
const OFGameControllerButton OFGameControllerRightShoulderButton =
    @"Right Shoulder";
const OFGameControllerButton OFGameControllerLeftStickButton = @"Left Stick";
const OFGameControllerButton OFGameControllerRightStickButton = @"Right Stick";
const OFGameControllerButton OFGameControllerDPadUpButton = @"D-Pad Up";
const OFGameControllerButton OFGameControllerDPadDownButton = @"D-Pad Down";
const OFGameControllerButton OFGameControllerDPadLeftButton = @"D-Pad Left";
const OFGameControllerButton OFGameControllerDPadRightButton = @"D-Pad Right";
const OFGameControllerButton OFGameControllerStartButton = @"Start";
const OFGameControllerButton OFGameControllerSelectButton = @"Select";
const OFGameControllerButton OFGameControllerHomeButton = @"Home";
const OFGameControllerButton OFGameControllerCaptureButton = @"Capture";

@implementation OFGameController
@dynamic name, buttons, pressedButtons, hasLeftAnalogStick;
@implementation HIDGameController
@dynamic name, buttons, axes;
@dynamic leftAnalogStickPosition, hasRightAnalogStick, rightAnalogStickPosition;

+ (OFArray OF_GENERIC(OFGameController *) *)controllers
+ (OFArray OF_GENERIC(HIDGameController *) *)controllers
{
#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
	return [OFEvdevGameController controllers];
	return [HIDEvdevGameController controllers];
#elif defined(OF_WINDOWS)
	return [OFXInputGameController controllers];
#elif defined(OF_WII)
	return [OFWiiGameController controllers];
#elif defined(OF_NINTENDO_DS)
	return [OFNintendoDSGameController controllers];
#elif defined(OF_NINTENDO_3DS)
	return [OFNintendo3DSGameController controllers];
#else
	return [OFArray array];
#endif
}

- (instancetype)init
{
	if ([self isMemberOfClass: [OFGameController class]]) {
	if ([self isMemberOfClass: [HIDGameController class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
		} @catch (id e) {
			[self release];
			@throw e;
		}

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146
147
148
149
150
67
68
69
70
71
72
73





74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89



















-
-
-
-
-














-
+

-
-
-
-
-
-
-
-
-
-
-
-
}

- (void)retrieveState
{
	OF_UNRECOGNIZED_SELECTOR
}

- (float)pressureForButton: (OFGameControllerButton)button
{
	return ([self.pressedButtons containsObject: button] ? 1 : 0);
}

- (OFString *)description
{
	if (self.vendorID != nil && self.productID != nil)
		return [OFString stringWithFormat:
		    @"<%@: %@ [%04X:%04X]>",
		    self.class, self.name, self.vendorID.unsignedShortValue,
		    self.productID.unsignedShortValue];
	else
		return [OFString stringWithFormat: @"<%@: %@>",
						   self.class, self.name];
}
@end

#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# include "OFEvdevGameController.m"
# include "HIDEvdevGameController.m"
#endif
#ifdef OF_WINDOWS
# include "OFXInputGameController.m"
#endif
#ifdef OF_WII
# include "OFWiiGameController.m"
#endif
#ifdef OF_NINTENDO_DS
# include "OFNintendoDSGameController.m"
#endif
#ifdef OF_NINTENDO_3DS
# include "OFNintendo3DSGameController.m"
#endif