ObjFW  Check-in [8be13b6bc6]

Overview
Comment:ObjFWHID: Make OHGameControllerProfile a protocol
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8be13b6bc6e2bb520d78c40d2497d5a9ffd686fa0acc8096bb7916068039219b
User & Date: js on 2024-06-09 15:12:03
Other Links: manifest | tags
Context
2024-06-09
16:36
ObjFWHID: Restore support for Wii check-in: 6e64dd58cb user: js tags: trunk
15:12
ObjFWHID: Make OHGameControllerProfile a protocol check-in: 8be13b6bc6 user: js tags: trunk
14:34
ObjFWHID: Add gamepad for Nintendo DS check-in: 5c70eba805 user: js tags: trunk
Changes

Modified src/hid/Makefile from [9c2b6d39ae] to [7d8ac1b256].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
1
2
3
4
5
6
7
8
9
10
11
12

13
14
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












-





-
-

















-
+
+
+
+







include ../../extra.mk

DISTCLEAN = Info.plist

SHARED_LIB = ${OBJFWHID_SHARED_LIB}
STATIC_LIB = ${OBJFWHID_STATIC_LIB}
FRAMEWORK = ${OBJFWHID_FRAMEWORK}
LIB_MAJOR = ${OBJFWHID_LIB_MAJOR}
LIB_MINOR = ${OBJFWHID_LIB_MINOR}
LIB_PATCH = ${OBJFWHID_LIB_PATCH}

SRCS = OHCombinedJoyCons.m		\
       OHExtendedGamepad.m		\
       OHGameController.m		\
       OHGameControllerAxis.m		\
       OHGameControllerButton.m		\
       OHGameControllerDirectionalPad.m	\
       OHGameControllerElement.m	\
       OHGameControllerProfile.m	\
       OHGamepad.m			\
       ${USE_SRCS_EVDEV}		\
       ${USE_SRCS_NINTENDO_3DS}		\
       ${USE_SRCS_NINTENDO_DS}		\
       ${USE_SRCS_XINPUT}
SRCS_EVDEV = OHEvdevDualSense.m				\
	     OHEvdevDualShock4.m			\
	     OHEvdevExtendedGamepad.m			\
	     OHEvdevGameController.m			\
	     OHEvdevPlayStationExtendedGamepad.m	\
	     OHEvdevStadiaExtendedGamepad.m
SRCS_NINTENDO_3DS = OHNintendo3DSExtendedGamepad.m	\
		    OHNintendo3DSGameController.m
SRCS_NINTENDO_DS = OHNintendoDSGamepad.m	\
		   OHNintendoDSGameController.m
SRCS_XINPUT = OHXInputExtendedGamepad.m	\
	      OHXInputGameController.m

INCLUDES := ${SRCS:.m=.h}	\
INCLUDES := ${SRCS:.m=.h}		\
	    OHExtendedGamepad.h		\
	    OHGameControllerProfile.h	\
	    OHGamepad.h			\
	    ObjFWHID.h

SRCS += OHGameControllerEmulatedAxis.m		\
	OHGameControllerEmulatedButton.m	\
	OHGameControllerEmulatedTriggerButton.m

includesubdir = ObjFWHID

Modified src/hid/OHCombinedJoyCons.h from [0b0c5cd7ee] to [90c4453390].

18
19
20
21
22
23
24


25
26
27
28
29
30

31

32
33





34
35
36
37
38
39
40
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







+
+






+
-
+

-
+
+
+
+
+







 */

#import "OHExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@class OHGameController;
@class OHGameControllerButton;
@class OHGameControllerDirectionalPad;

/**
 * @class OHCombinedJoyCons OHCombinedJoyCons.h ObjFWHID/OHCombinedJoyCons.h
 *
 * @brief Combines a left and a right Joy-Con into a gamepad.
 */
OF_SUBCLASSING_RESTRICTED
@interface OHCombinedJoyCons: OHExtendedGamepad
@interface OHCombinedJoyCons: OFObject <OHExtendedGamepad>
{
	OHGameControllerProfile *_leftJoyCon, *_rightJoyCon;
	id <OHGameControllerProfile> _leftJoyCon;
	id <OHGameControllerProfile> _rightJoyCon;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *_directionalPads;
}

/**
 * @brief Creates a new @ref OHCombinedJoyCons with the specified left and
 *	  right Joy-Con.
 *
 * @param leftJoyCon The left Joy-Con

Modified src/hid/OHCombinedJoyCons.m from [3732ebd4b4] to [d9750ce99f].

24
25
26
27
28
29
30


31
32
33
34
35
36
37
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39







+
+







#import "OFNumber.h"
#import "OHGameController.h"
#import "OHGameControllerDirectionalPad.h"

#import "OFInvalidArgumentException.h"

@implementation OHCombinedJoyCons
@synthesize buttons = _buttons, directionalPads = _directionalPads;

+ (instancetype)gamepadWithLeftJoyCon: (OHGameController *)leftJoyCon
			  rightJoyCon: (OHGameController *)rightJoyCon
{
	return [[[self alloc] initWithLeftJoyCon: leftJoyCon
				     rightJoyCon: rightJoyCon] autorelease];
}

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
80
81
82
83
84
85
86


87
88
89
90
91
92
93







-
-







		[buttons removeObjectForKey: @"D-Pad Left"];
		[buttons removeObjectForKey: @"D-Pad Right"];
		[buttons removeObjectForKey: @"SL"];
		[buttons removeObjectForKey: @"SR"];
		[buttons makeImmutable];
		_buttons = [buttons retain];

		_axes = [[OFDictionary alloc] init];

		directionalPads =
		    [OFMutableDictionary dictionaryWithCapacity: 3];

		directionalPad = [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"Left Thumbstick"
			   xAxis: [_leftJoyCon.axes objectForKey: @"X"]
			   yAxis: [_leftJoyCon.axes objectForKey: @"Y"]]
124
125
126
127
128
129
130


131
132
133





134
135
136
137
138
139
140
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147







+
+



+
+
+
+
+







	return self;
}

- (void)dealloc
{
	[_leftJoyCon release];
	[_rightJoyCon release];
	[_buttons release];
	[_directionalPads release];

	[super dealloc];
}

- (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes
{
	return [OFDictionary dictionary];
}

- (OHGameControllerButton *)northButton
{
	return [_buttons objectForKey: @"X"];
}

- (OHGameControllerButton *)southButton
193
194
195
196
197
198
199
200

201
202
203
204
205

206
207
208
209
210
211
212
213
214
200
201
202
203
204
205
206

207
208
209
210
211

212
213
214
215
216
217
218
219
220
221







-
+




-
+









}

- (OHGameControllerButton *)homeButton
{
	return [_buttons objectForKey: @"Home"];
}

- (OHGameControllerDirectionalPad *)leftThumbStick
- (OHGameControllerDirectionalPad *)leftThumbstick
{
	return [_directionalPads objectForKey: @"Left Thumbstick"];
}

- (OHGameControllerDirectionalPad *)rightThumbStick
- (OHGameControllerDirectionalPad *)rightThumbstick
{
	return [_directionalPads objectForKey: @"Right Thumbstick"];
}

- (OHGameControllerDirectionalPad *)dPad
{
	return [_directionalPads objectForKey: @"D-Pad"];
}
@end

Modified src/hid/OHEvdevExtendedGamepad.h from [6c2895c0ea] to [b25eb5bac7].

18
19
20
21
22
23
24
25
26
27

28
29

30
31
32
33
34
35
18
19
20
21
22
23
24

25

26
27

28
29
30
31
32
33
34







-

-
+

-
+






 */

#import "OHExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@class OHEvdevGameController;
@class OHGameControllerProfile;

@interface OHEvdevExtendedGamepad: OHExtendedGamepad
@interface OHEvdevExtendedGamepad: OFObject <OHExtendedGamepad>
{
	OHGameControllerProfile *_rawProfile;
	id <OHGameControllerProfile> _rawProfile;
}

- (instancetype)initWithController: (OHEvdevGameController *)controller;
@end

OF_ASSUME_NONNULL_END

Modified src/hid/OHEvdevGameController.h from [10dbd16290] to [60077568e2].

14
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
14
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







+













-
+







 *
 * 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/>.
 */

#import "OHGameController.h"
#import "OHGameControllerProfile.h"

OF_ASSUME_NONNULL_BEGIN

@class OHGameControllerProfile;

@interface OHEvdevGameController: OHGameController
{
	OFString *_path;
	int _fd;
	bool _discardUntilReport;
	unsigned long *_evBits, *_keyBits, *_absBits;
	uint16_t _vendorID, _productID;
	OFString *_name;
	OHGameControllerProfile *_rawProfile;
	id <OHGameControllerProfile> _rawProfile;
}

- (instancetype)oh_initWithPath: (OFString *)path OF_METHOD_FAMILY(init);
- (void)oh_pollState;
@end

OF_ASSUME_NONNULL_END

Modified src/hid/OHEvdevGameController.m from [c35ba635a9] to [98e64f1a03].

51
52
53
54
55
56
57
58






59
60
61
62
63
64
65
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
68
69
70







-
+
+
+
+
+
+







@interface OHEvdevGameControllerAxis: OHGameControllerAxis
{
@public
	int32_t _minValue, _maxValue;
}
@end

@interface OHEvdevGameControllerProfile: OHGameControllerProfile
@interface OHEvdevGameControllerProfile: OFObject <OHGameControllerProfile>
{
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *_axes;
}

- (instancetype)oh_initWithButtons: (OFDictionary *)buttons
			      axes: (OFDictionary *)axes OF_METHOD_FAMILY(init);
@end

static const uint16_t buttonIDs[] = {
	BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_TL2,
	BTN_TR2, BTN_SELECT, BTN_START, BTN_MODE, BTN_THUMBL, BTN_THUMBR,
725
726
727
728
729
730
731
732

733
734
735
736
737

738
739
740
741
742
743
744
730
731
732
733
734
735
736

737
738
739
740
741

742
743
744
745
746
747
748
749







-
+




-
+







			   axis->_minValue, axis->_maxValue);

			break;
		}
	}
}

- (OHGamepad *)gamepad
- (id <OHGamepad>)gamepad
{
	return self.extendedGamepad;
}

- (OHExtendedGamepad *)extendedGamepad
- (id <OHExtendedGamepad>)extendedGamepad
{
	@try {
		if (_vendorID == OHVendorIDSony &&
		    _productID == OHProductIDDualSense)
			return [[[OHEvdevDualSense alloc]
			    initWithController: self] autorelease];
		else if (_vendorID == OHVendorIDSony &&
777
778
779
780
781
782
783


784
785
786
787
788
789
790
791
792
793
794
795
796
797
798














799
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820







+
+















+
+
+
+
+
+
+
+
+
+
+
+
+
+

}
@end

@implementation OHEvdevGameControllerAxis
@end

@implementation OHEvdevGameControllerProfile
@synthesize buttons = _buttons, axes = _axes;

- (instancetype)oh_initWithButtons: (OFDictionary *)buttons
			      axes: (OFDictionary *)axes
{
	self = [super init];

	@try {
		_buttons = [buttons retain];
		_axes = [axes retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_buttons release];
	[_axes release];

	[super dealloc];
}

- (OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *) *)
    directionalPads
{
	return [OFDictionary dictionary];
}
@end

Modified src/hid/OHExtendedGamepad.h from [921dcc6b86] to [5c714fa829].

18
19
20
21
22
23
24
25

26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
18
19
20
21
22
23
24

25
26
27
28

29




30
31
32
33
34
35
36







-
+



-
+
-
-
-
-







 */

#import "OHGamepad.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class OHExtendedGamepad OHExtendedGamepad.h ObjFWHID/OHExtendedGamepad.h
 * @protocol OHExtendedGamepad OHExtendedGamepad.h ObjFWHID/OHExtendedGamepad.h
 *
 * @brief A game controller profile representing a gamepad.
 */
@interface OHExtendedGamepad: OHGamepad
@protocol OHExtendedGamepad <OHGamepad>
{
	OF_RESERVE_IVARS(OHExtendedGamepad, 4)
}

/**
 * @brief The left trigger button.
 */
@property (readonly, nonatomic) OHGameControllerButton *leftTriggerButton;

/**
 * @brief The right trigger button.

Deleted src/hid/OHExtendedGamepad.m version [d21610a1a5].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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










































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3.0 only,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * version 3.0 for more details.
 *
 * 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 "OHExtendedGamepad.h"

@implementation OHExtendedGamepad
@dynamic leftTriggerButton, rightTriggerButton, leftThumbstick, rightThumbstick;
@dynamic dPad;

- (OHGameControllerButton *)leftThumbstickButton
{
	return nil;
}

- (OHGameControllerButton *)rightThumbstickButton
{
	return nil;
}

- (OHGameControllerButton *)homeButton
{
	return nil;
}
@end

Modified src/hid/OHGameController.h from [805ad805e2] to [526e49cd36].

25
26
27
28
29
30
31



32
33
34
35
36
37
38
39
40
41
42
43
44
45
25
26
27
28
29
30
31
32
33
34
35
36
37
38

39

40
41
42
43
44
45
46







+
+
+




-

-







@import ObjFW;
# else
#  import <ObjFW/OFObject.h>
#  import <ObjFW/OFString.h>
# endif
#endif

#import "OHGamepad.h"
#import "OHExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@class OFArray OF_GENERIC(ObjectType);
@class OFNumber;
@class OHExtendedGamepad;
@class OHGameControllerProfile;
@class OHGamepad;

/**
 * @class OHGameController OHGameController.h ObjFWHID/OHGameController.h
 *
 * @brief A class for reading state from a game controller.
 */
@interface OHGameController: OFObject
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
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







-
+





-
+






-
+







 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFNumber *productID;

/**
 * @brief The raw profile for the game controller, meaning no remapping is
 *	  being performed.
 */
@property (readonly, nonatomic) OHGameControllerProfile *rawProfile;
@property (readonly, nonatomic) id <OHGameControllerProfile> rawProfile;

/**
 * @brief The gamepad profile for the game controller, or `nil` if not
 *	  supported.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OHGamepad *gamepad;
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) id <OHGamepad> gamepad;

/**
 * @brief The extended gamepad profile for the game controller, or `nil` if not
 *	  supported.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OHExtendedGamepad *extendedGamepad;
    id <OHExtendedGamepad> extendedGamepad;

/**
 * @brief Returns the available controllers.
 *
 * @return The available controllers
 */
+ (OFArray OF_GENERIC(OHGameController *) *)controllers;

Modified src/hid/OHGameController.m from [3129705f22] to [386bef4691].

92
93
94
95
96
97
98
99

100
101
102
103
104

105
106
107
108
109
110
111
92
93
94
95
96
97
98

99
100
101
102
103

104
105
106
107
108
109
110
111







-
+




-
+







}

- (void)retrieveState
{
	OF_UNRECOGNIZED_SELECTOR
}

- (OHGamepad *)gamepad
- (id <OHGamepad>)gamepad
{
	return nil;
}

- (OHExtendedGamepad *)extendedGamepad
- (id <OHExtendedGamepad>)extendedGamepad
{
	return nil;
}

- (OFString *)description
{
	if (self.vendorID != nil && self.productID != nil)

Modified src/hid/OHGameControllerProfile.h from [4820b1c9dc] to [ba80368ef8].

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
33
34
35
36
37
38
39


40
41
42
43
44

45








46
47
48
49
50
51
52







-
-
+
+



-
+
-
-
-
-
-
-
-
-








@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class OHGameControllerAxis;
@class OHGameControllerButton;
@class OHGameControllerDirectionalPad;

/**
 * @class OHGameControllerProfile \
 *	  OHGameControllerProfile.h ObjFWHID/OHGameControllerProfile.h
 * @protocol OHGameControllerProfile \
 *	     OHGameControllerProfile.h ObjFWHID/OHGameControllerProfile.h
 *
 * @brief A profile for a @ref OHGameController.
 */
@interface OHGameControllerProfile: OFObject
@protocol OHGameControllerProfile <OFObject>
{
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *_axes;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *_directionalPads;
	OF_RESERVE_IVARS(OHGameControllerProfile, 4)
}

/**
 * @brief A map of all button names to their @ref OHGameControllerButton.
 */
@property (readonly, nonatomic)
    OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *buttons;

/**

Deleted src/hid/OHGameControllerProfile.m version [c4be5284ad].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37





































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3.0 only,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * version 3.0 for more details.
 *
 * 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 "OHGameControllerProfile.h"
#import "OFDictionary.h"

@implementation OHGameControllerProfile
@synthesize buttons = _buttons, axes = _axes;
@synthesize directionalPads = _directionalPads;

- (void)dealloc
{
	[_buttons release];
	[_axes release];
	[_directionalPads release];

	[super dealloc];
}
@end

Modified src/hid/OHGamepad.h from [a630442063] to [6d0b74845c].

18
19
20
21
22
23
24
25

26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
18
19
20
21
22
23
24

25
26
27
28

29




30
31
32
33
34
35
36







-
+



-
+
-
-
-
-







 */

#import "OHGameControllerProfile.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class OHGamepad OHGamepad.h ObjFWHID/OHGamepad.h
 * @protocol OHGamepad OHGamepad.h ObjFWHID/OHGamepad.h
 *
 * @brief A game controller profile representing a gamepad.
 */
@interface OHGamepad: OHGameControllerProfile
@protocol OHGamepad <OHGameControllerProfile>
{
	OF_RESERVE_IVARS(OHGamepad, 4)
}

/**
 * @brief The north button on the gamepad's diamond pad.
 */
@property (readonly, nonatomic) OHGameControllerButton *northButton;

/**
 * @brief The south button on the gamepad's diamond pad.

Deleted src/hid/OHGamepad.m version [872795b145].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27



























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3.0 only,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * version 3.0 for more details.
 *
 * 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 "OHGamepad.h"

@implementation OHGamepad
@dynamic northButton, southButton, westButton, eastButton, leftShoulderButton;
@dynamic rightShoulderButton, menuButton, optionsButton, dPad;
@end

Modified src/hid/OHNintendo3DSExtendedGamepad.h from [3b15d599d3] to [20fc31d17d].

17
18
19
20
21
22
23
24






25
26
27
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32







-
+
+
+
+
+
+



 * <https://www.gnu.org/licenses/>.
 */

#import "OHExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHNintendo3DSExtendedGamepad: OHExtendedGamepad
@interface OHNintendo3DSExtendedGamepad: OFObject <OHExtendedGamepad>
{
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *_directionalPads;
}
@end

OF_ASSUME_NONNULL_END

Modified src/hid/OHNintendo3DSExtendedGamepad.m from [d5489dc9dd] to [0752ac2ef9].

27
28
29
30
31
32
33


34
35
36
37
38
39
40
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42







+
+








static OFString *const buttonNames[] = {
	@"A", @"B", @"X", @"Y", @"L", @"R", @"ZL", @"ZR", @"Start", @"Select"
};
static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames);

@implementation OHNintendo3DSExtendedGamepad
@synthesize buttons = _buttons, directionalPads = _directionalPads;

- (instancetype)init
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons =
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
51
52
53
54
55
56
57


58
59
60
61
62
63
64







-
-







			    [[[OHGameControllerButton alloc]
			    initWithName: buttonNames[i]] autorelease];
			[buttons setObject: button forKey: buttonNames[i]];
		}
		[buttons makeImmutable];
		_buttons = [buttons retain];

		_axes = [[OFDictionary alloc] init];

		directionalPads =
		    [OFMutableDictionary dictionaryWithCapacity: 3];

		xAxis = [[[OHGameControllerAxis alloc]
		    initWithName: @"X"] autorelease];
		yAxis = [[[OHGameControllerAxis alloc]
		    initWithName: @"Y"] autorelease];
103
104
105
106
107
108
109













110
111
112
113
114
115
116
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129







+
+
+
+
+
+
+
+
+
+
+
+
+







	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_buttons release];
	[_directionalPads release];

	[super dealloc];
}

- (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes
{
	return [OFDictionary dictionary];
}

- (OHGameControllerButton *)northButton
{
	return [_buttons objectForKey: @"X"];
}

- (OHGameControllerButton *)southButton
143
144
145
146
147
148
149










150
151
152
153
154
155
156
157
158
159





160
161
162
163
164
165
166
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194







+
+
+
+
+
+
+
+
+
+










+
+
+
+
+







	return [_buttons objectForKey: @"ZL"];
}

- (OHGameControllerButton *)rightTriggerButton
{
	return [_buttons objectForKey: @"ZR"];
}

- (OHGameControllerButton *)leftThumbstickButton
{
	return nil;
}

- (OHGameControllerButton *)rightThumbstickButton
{
	return nil;
}

- (OHGameControllerButton *)menuButton
{
	return [_buttons objectForKey: @"Start"];
}

- (OHGameControllerButton *)optionsButton
{
	return [_buttons objectForKey: @"Select"];
}

- (OHGameControllerButton *)homeButton
{
	return nil;
}

- (OHGameControllerDirectionalPad *)leftThumbstick
{
	return [_directionalPads objectForKey: @"Circle Pad"];
}

- (OHGameControllerDirectionalPad *)rightThumbstick

Modified src/hid/OHNintendo3DSGameController.m from [01ae2ef5f1] to [0167f74bbf].

134
135
136
137
138
139
140
141

142
143
144
145
146

147
148
149
150
134
135
136
137
138
139
140

141
142
143
144
145

146
147
148
149
150







-
+




-
+




}

- (OFString *)name
{
	return @"Nintendo 3DS";
}

- (OHGameControllerProfile *)rawProfile
- (id <OHGameControllerProfile>)rawProfile
{
	return _extendedGamepad;
}

- (OHGamepad *)gamepad
- (id <OHGamepad>)gamepad
{
	return _extendedGamepad;
}
@end

Modified src/hid/OHNintendoDSGameController.m from [9d14fc6ff2] to [a4f9f01eef].

106
107
108
109
110
111
112
113

114
115
116
117
106
107
108
109
110
111
112

113
114
115
116
117







-
+




}

- (OFString *)name
{
	return @"Nintendo DS";
}

- (OHGameControllerProfile *)rawProfile
- (id <OHGameControllerProfile>)rawProfile
{
	return _gamepad;
}
@end

Modified src/hid/OHNintendoDSGamepad.h from [2368a4d576] to [cfe0e81593].

17
18
19
20
21
22
23
24






25
26
27
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32







-
+
+
+
+
+
+



 * <https://www.gnu.org/licenses/>.
 */

#import "OHGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHNintendoDSGamepad: OHGamepad
@interface OHNintendoDSGamepad: OFObject <OHGamepad>
{
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *_directionalPads;
}
@end

OF_ASSUME_NONNULL_END

Modified src/hid/OHNintendoDSGamepad.m from [38e3ed9f0f] to [3fa1706571].

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
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







+
+




















-
-








static OFString *const buttonNames[] = {
	@"A", @"B", @"X", @"Y", @"L", @"R", @"Start", @"Select"
};
static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames);

@implementation OHNintendoDSGamepad
@synthesize buttons = _buttons, directionalPads = _directionalPads;

- (instancetype)init
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons =
		    [OFMutableDictionary dictionaryWithCapacity: numButtons];
		OHGameControllerButton *up, *down, *left, *right;
		OHGameControllerDirectionalPad *dPad;

		for (size_t i = 0; i < numButtons; i++) {
			OHGameControllerButton *button =
			    [[[OHGameControllerButton alloc]
			    initWithName: buttonNames[i]] autorelease];
			[buttons setObject: button forKey: buttonNames[i]];
		}
		[buttons makeImmutable];
		_buttons = [buttons retain];

		_axes = [[OFMutableDictionary alloc] init];

		up = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Up"] autorelease];
		down = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Down"] autorelease];
		left = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Left"] autorelease];
		right = [[[OHGameControllerButton alloc]
75
76
77
78
79
80
81













82
83
84
85
86
87
88
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101







+
+
+
+
+
+
+
+
+
+
+
+
+







	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_buttons release];
	[_directionalPads release];

	[super dealloc];
}

- (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes
{
	return [OFDictionary dictionary];
}

- (OHGameControllerButton *)northButton
{
	return [_buttons objectForKey: @"X"];
}

- (OHGameControllerButton *)southButton

Modified src/hid/OHXInputExtendedGamepad.h from [137e523e2b] to [0e601afe16].

17
18
19
20
21
22
23
24






25
26
27
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32







-
+
+
+
+
+
+



 * <https://www.gnu.org/licenses/>.
 */

#import "OHExtendedGamepad.h"

OF_ASSUME_NONNULL_BEGIN

@interface OHXInputExtendedGamepad: OHExtendedGamepad
@interface OHXInputExtendedGamepad: OFObject <OHExtendedGamepad>
{
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *_directionalPads;
}
@end

OF_ASSUME_NONNULL_END

Modified src/hid/OHXInputExtendedGamepad.m from [3e95130dc5] to [c47a92c25d].

29
30
31
32
33
34
35


36
37
38
39
40
41
42
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44







+
+







static OFString *const buttonNames[] = {
	@"A", @"B", @"X", @"Y", @"LB", @"RB", @"LT", @"RT", @"LSB", @"RSB",
	@"Start", @"Back", @"Guide"
};
static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames);

@implementation OHXInputExtendedGamepad
@synthesize buttons = _buttons, directionalPads = _directionalPads;

- (instancetype)init
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons =
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
58
59
60
61
62
63
64


65
66
67
68
69
70
71







-
-







			button = [[OHGameControllerButton alloc]
			    initWithName: buttonNames[i]];
			[buttons setObject: button forKey: buttonNames[i]];
		}
		[buttons makeImmutable];
		_buttons = [buttons retain];

		_axes = [[OFDictionary alloc] init];

		directionalPads =
		    [OFMutableDictionary dictionaryWithCapacity: 3];

		xAxis = [[[OHGameControllerAxis alloc]
		    initWithName: @"X"] autorelease];
		yAxis = [[[OHGameControllerAxis alloc]
		    initWithName: @"Y"] autorelease];
110
111
112
113
114
115
116













117
118
119
120
121
122
123
110
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







+
+
+
+
+
+
+
+
+
+
+
+
+







	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_buttons release];
	[_directionalPads release];

	[super dealloc];
}

- (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes
{
	return [OFDictionary dictionary];
}

- (OHGameControllerButton *)northButton
{
	return [_buttons objectForKey: @"Y"];
}

- (OHGameControllerButton *)southButton

Modified src/hid/OHXInputGameController.m from [7c14afb2ff] to [fe788fd33d].

232
233
234
235
236
237
238
239

240
241
242
243
244

245
246
247
248
232
233
234
235
236
237
238

239
240
241
242
243

244
245
246
247
248







-
+




-
+




	case 910:
		return @"XInput 9.1.0 device";
	}

	return nil;
}

- (OHGameControllerProfile *)rawProfile
- (id <OHGameControllerProfile>)rawProfile
{
	return _extendedGamepad;
}

- (OHGamepad *)gamepad
- (id <OHGamepad>)gamepad
{
	return _extendedGamepad;
}
@end

Modified tests/gamecontroller/GameControllerTests.m from [fdb8a65717] to [e80833a68c].

58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72







-
+







	OFArray OF_GENERIC(OHGameController *) *_controllers;
	OFDate *_lastControllersUpdate;
}
@end

OF_APPLICATION_DELEGATE(GameControllerTests)

static void printProfile(OHGameControllerProfile *profile)
static void printProfile(id <OHGameControllerProfile> profile)
{
	OFArray OF_GENERIC(OFString *) *buttons =
	    profile.buttons.allKeys.sortedArray;
	OFArray OF_GENERIC(OFString *) *axes = profile.axes.allKeys.sortedArray;
	OFArray OF_GENERIC(OFString *) *directionalPads =
	    profile.directionalPads.allKeys.sortedArray;
	size_t i;
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
151
152
153
154
155
156
157
158


159
160
161
162
163
164
165
166
167



168
169
170
171
172
173

174
175
176
177
178
179
180
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
151
152
153
154
155
156


157
158
159
160
161
162
163
164



165
166
167
168
169
170
171
172

173
174
175
176
177
178
179
180







-
-
+
+











-
-
-
+
+
+











-
-
+
+






-
-
-
+
+
+





-
+







		    @"%@: (%5.2f, %5.2f)  ",
		    name,
		    directionalPad.xAxis.value, directionalPad.yAxis.value];
	}
	if (directionalPads.count > 0)
		[OFStdOut writeString: @"\n"];

	if ([profile isKindOfClass: [OHGamepad class]]) {
		OHGamepad *gamepad = (OHGamepad *)profile;
	if ([profile conformsToProtocol: @protocol(OHGamepad)]) {
		id <OHGamepad> gamepad = (id <OHGamepad>)profile;

		[OFStdOut writeFormat:
		    @"[Map] North: %@  South: %@  West: %@  East: %@\n",
		    gamepad.northButton.name, gamepad.southButton.name,
		    gamepad.westButton.name, gamepad.eastButton.name];
		[OFStdOut writeFormat:
		    @"[Map] Left Shoulder: %@  Right Shoulder: %@\n",
		    gamepad.leftShoulderButton.name,
		    gamepad.rightShoulderButton.name];
	}

	if ([profile isKindOfClass: [OHExtendedGamepad class]]) {
		OHExtendedGamepad *extendedGamepad =
		    (OHExtendedGamepad *)profile;
	if ([profile conformsToProtocol: @protocol(OHExtendedGamepad)]) {
		id <OHExtendedGamepad> extendedGamepad =
		    (id <OHExtendedGamepad>)profile;

		[OFStdOut writeFormat:
		    @"[Map] Left Trigger: %@  Right Trigger: %@\n",
		    extendedGamepad.leftTriggerButton.name,
		    extendedGamepad.rightTriggerButton.name];
		[OFStdOut writeFormat:
		    @"[Map] Left Thumbstick: %@  Right Thumbstick: %@\n",
		    extendedGamepad.leftThumbstickButton.name,
		    extendedGamepad.rightThumbstickButton.name];
	}

	if ([profile isKindOfClass: [OHGamepad class]]) {
		OHGamepad *gamepad = (OHGamepad *)profile;
	if ([profile conformsToProtocol: @protocol(OHGamepad)]) {
		id <OHGamepad> gamepad = (id <OHGamepad>)profile;

		[OFStdOut writeFormat:
		    @"[Map] Menu: %@  Options: %@",
		    gamepad.menuButton.name, gamepad.optionsButton.name];
	}

	if ([profile isKindOfClass: [OHExtendedGamepad class]]) {
		OHExtendedGamepad *extendedGamepad =
		    (OHExtendedGamepad *)profile;
	if ([profile conformsToProtocol: @protocol(OHExtendedGamepad)]) {
		id <OHExtendedGamepad> extendedGamepad =
		    (id <OHExtendedGamepad>)profile;

		[OFStdOut writeFormat: @"  Home: %@",
		    extendedGamepad.homeButton.name];
	}

	if ([profile isKindOfClass: [OHGamepad class]])
	if ([profile conformsToProtocol: @protocol(OHGamepad)])
		[OFStdOut writeString: @"\n"];
}

@implementation GameControllerTests
- (void)applicationDidFinishLaunching: (OFNotification *)notification
{
#if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS)
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209







-
+








			[OFStdOut clear];
		}

		[OFStdOut setCursorPosition: OFMakePoint(0, 0)];

		for (OHGameController *controller in _controllers) {
			OHGameControllerProfile *profile;
			id <OHGameControllerProfile> profile;

			profile = controller.extendedGamepad;
			if (profile == nil)
				profile = controller.gamepad;
			if (profile == nil)
				profile = controller.rawProfile;