ObjFW  Check-in [23e3ffff7a]

Overview
Comment:-[OHGameController {retrieve -> update}State]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 23e3ffff7a75aae296183ca72c65f6e587d985b5e621cc3db0a67ab51d4721ae
User & Date: js on 2024-10-22 22:29:41
Other Links: manifest | tags
Context
2024-10-25
22:38
OFSCTPSocket: Don't require -lsctp check-in: abe832b03d user: js tags: trunk
2024-10-22
22:29
-[OHGameController {retrieve -> update}State] check-in: 23e3ffff7a user: js tags: trunk
2024-10-19
14:07
GitHub Actions: Fix OpenBSD check-in: e389aa247e user: js tags: trunk
Changes

Modified src/hid/OHEvdevGameController.m from [5d84c38c52] to [8882f3e69e].

326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
			axis.oh_maxRawValue = info.maximum;
			axis.value = scale(info.value,
			    info.minimum, info.maximum);
		}
	}
}

- (void)retrieveState
{
	void *pool = objc_autoreleasePoolPush();
	struct input_event event;

	for (;;) {
		OHGameControllerButton *button;
		OHGameControllerAxis *axis;







|







326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
			axis.oh_maxRawValue = info.maximum;
			axis.value = scale(info.value,
			    info.minimum, info.maximum);
		}
	}
}

- (void)updateState
{
	void *pool = objc_autoreleasePoolPush();
	struct input_event event;

	for (;;) {
		OHGameControllerButton *button;
		OHGameControllerAxis *axis;

Modified src/hid/OHGameController.h from [b50a9d0041] to [5a0ee8476d].

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 * @brief Returns the available controllers.
 *
 * @return The available controllers
 */
+ (OFArray OF_GENERIC(OHGameController *) *)controllers;

/**
 * @brief Retrieves the current state from the game controller.
 *
 * The state returned by @ref OHGameController's methods does not change until
 * this method is called.
 *
 * @throw OFReadFailedException The controller's state could not be read
 */
- (void)retrieveState;
@end

#ifdef __cplusplus
extern "C" {
#endif
extern const uint16_t OHVendorIDSony;
extern const uint16_t OHVendorIDNintendo;







|






|







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 * @brief Returns the available controllers.
 *
 * @return The available controllers
 */
+ (OFArray OF_GENERIC(OHGameController *) *)controllers;

/**
 * @brief Updates the current state from the game controller.
 *
 * The state returned by @ref OHGameController's methods does not change until
 * this method is called.
 *
 * @throw OFReadFailedException The controller's state could not be read
 */
- (void)updateState;
@end

#ifdef __cplusplus
extern "C" {
#endif
extern const uint16_t OHVendorIDSony;
extern const uint16_t OHVendorIDNintendo;

Modified src/hid/OHGameController.m from [84aa11a3e7] to [12f0e8227c].

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
}

- (OFNumber *)productID
{
	return nil;
}

- (void)retrieveState
{
	OF_UNRECOGNIZED_SELECTOR
}

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







|







97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
}

- (OFNumber *)productID
{
	return nil;
}

- (void)updateState
{
	OF_UNRECOGNIZED_SELECTOR
}

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

Modified src/hid/OHNintendo3DSGameController.m from [2f027499a1] to [2ceda08904].

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
- (instancetype)init
{
	self = [super init];

	@try {
		_extendedGamepad = [[OHNintendo3DSExtendedGamepad alloc] init];

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

	return self;
}

- (void)dealloc
{
	[_extendedGamepad release];

	[super dealloc];
}

- (void)retrieveState
{
	void *pool = objc_autoreleasePoolPush();
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *)
	    *buttons = _extendedGamepad.buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *directionalPads = _extendedGamepad.directionalPads;
	u32 keys;







|















|







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
- (instancetype)init
{
	self = [super init];

	@try {
		_extendedGamepad = [[OHNintendo3DSExtendedGamepad alloc] init];

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

	return self;
}

- (void)dealloc
{
	[_extendedGamepad release];

	[super dealloc];
}

- (void)updateState
{
	void *pool = objc_autoreleasePoolPush();
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *)
	    *buttons = _extendedGamepad.buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *directionalPads = _extendedGamepad.directionalPads;
	u32 keys;

Modified src/hid/OHNintendoDSGameController.m from [7056d0ab9e] to [e8178e5420].

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
- (instancetype)init
{
	self = [super init];

	@try {
		_gamepad = [[OHNintendoDSGamepad alloc] init];

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

	return self;
}

- (void)dealloc
{
	[_gamepad release];

	[super dealloc];
}

- (void)retrieveState
{
	OFDictionary *buttons = _gamepad.buttons;
	OHGameControllerDirectionalPad *dPad =
	    [_gamepad.directionalPads objectForKey: @"D-Pad"];
	u32 keys;

	scanKeys();







|















|







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
- (instancetype)init
{
	self = [super init];

	@try {
		_gamepad = [[OHNintendoDSGamepad alloc] init];

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

	return self;
}

- (void)dealloc
{
	[_gamepad release];

	[super dealloc];
}

- (void)updateState
{
	OFDictionary *buttons = _gamepad.buttons;
	OHGameControllerDirectionalPad *dPad =
	    [_gamepad.directionalPads objectForKey: @"D-Pad"];
	u32 keys;

	scanKeys();

Modified src/hid/OHNintendoSwitchGameController.m from [a788c8cea8] to [6bf69b44e2].

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
		if (!padIsConnected(&_pad))
			@throw [OFInitializationFailedException
			    exceptionWithClass: self.class];

		_extendedGamepad =
		    [[OHNintendoSwitchExtendedGamepad alloc] init];

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

	return self;
}

- (void)dealloc
{
	[_extendedGamepad release];

	[super dealloc];
}

- (void)retrieveState
{
	void *pool = objc_autoreleasePoolPush();
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *)
	    *buttons = _extendedGamepad.buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *directionalPads = _extendedGamepad.directionalPads;
	u64 keys;







|















|







83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
		if (!padIsConnected(&_pad))
			@throw [OFInitializationFailedException
			    exceptionWithClass: self.class];

		_extendedGamepad =
		    [[OHNintendoSwitchExtendedGamepad alloc] init];

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

	return self;
}

- (void)dealloc
{
	[_extendedGamepad release];

	[super dealloc];
}

- (void)updateState
{
	void *pool = objc_autoreleasePoolPush();
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *)
	    *buttons = _extendedGamepad.buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *directionalPads = _extendedGamepad.directionalPads;
	u64 keys;

Modified src/hid/OHWiiGameController.m from [d2411fda9b] to [e32aeb7c28].

97
98
99
100
101
102
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
		if (type == WPAD_EXP_CLASSIC)
			_profile = [[OHWiiClassicController alloc] init];
		else if (type == WPAD_EXP_NUNCHUK)
			_profile = [[OHWiimoteWithNunchuk alloc] init];
		else
			_profile = [[OHWiimote alloc] init];

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

	return self;
}

- (void)dealloc
{
	[_profile release];

	[super dealloc];
}

- (void)retrieveState
{
	OFDictionary *buttons = _profile.buttons;
	OFDictionary *directionalPads = _profile.directionalPads;
	WPADData *data;

	if (WPAD_ReadPending(_index, NULL) < WPAD_ERR_NONE)
		@throw [OFReadFailedException







|















|







97
98
99
100
101
102
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
		if (type == WPAD_EXP_CLASSIC)
			_profile = [[OHWiiClassicController alloc] init];
		else if (type == WPAD_EXP_NUNCHUK)
			_profile = [[OHWiimoteWithNunchuk alloc] init];
		else
			_profile = [[OHWiimote alloc] init];

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

	return self;
}

- (void)dealloc
{
	[_profile release];

	[super dealloc];
}

- (void)updateState
{
	OFDictionary *buttons = _profile.buttons;
	OFDictionary *directionalPads = _profile.directionalPads;
	WPADData *data;

	if (WPAD_ReadPending(_index, NULL) < WPAD_ERR_NONE)
		@throw [OFReadFailedException

Modified src/hid/OHXInputGameController.m from [cc3b87f597] to [1bec2a2275].

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
				    capabilities.productID];
			}
		}

		_extendedGamepad = [[OHXboxGamepad alloc]
		    initWithHasGuideButton: (XInputVersion != 910)];

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

	return self;
}

- (void)dealloc
{
	[_vendorID release];
	[_productID release];
	[_extendedGamepad release];

	[super dealloc];
}

- (void)retrieveState
{
	XINPUT_STATE state = { 0 };

	if (XInputGetStateFuncPtr(_index, &state) != ERROR_SUCCESS)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: sizeof(state)
							    errNo: 0];







|

















|







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
				    capabilities.productID];
			}
		}

		_extendedGamepad = [[OHXboxGamepad alloc]
		    initWithHasGuideButton: (XInputVersion != 910)];

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

	return self;
}

- (void)dealloc
{
	[_vendorID release];
	[_productID release];
	[_extendedGamepad release];

	[super dealloc];
}

- (void)updateState
{
	XINPUT_STATE state = { 0 };

	if (XInputGetStateFuncPtr(_index, &state) != ERROR_SUCCESS)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: sizeof(state)
							    errNo: 0];

Modified src/test/OTAppDelegate.m from [545f03258c] to [81ba721124].

290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# endif
			void *pool = objc_autoreleasePoolPush();
			OHGameController *controller =
			    [[OHGameController controllers] objectAtIndex: 0];
			OHGameControllerButton *button =
			    [controller.profile.buttons objectForKey: @"A"];

			[controller retrieveState];

			if (button.pressed)
				break;

# ifdef OF_NINTENDO_SWITCH
			updateConsole(true);
# else







|







290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# endif
			void *pool = objc_autoreleasePoolPush();
			OHGameController *controller =
			    [[OHGameController controllers] objectAtIndex: 0];
			OHGameControllerButton *button =
			    [controller.profile.buttons objectForKey: @"A"];

			[controller updateState];

			if (button.pressed)
				break;

# ifdef OF_NINTENDO_SWITCH
			updateConsole(true);
# else
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
		OHGameControllerButton *button =
# ifdef OF_WII
		    [controller.profile.buttons objectForKey: @"Home"];
# else
		    [controller.profile.buttons objectForKey: @"Start"];
# endif

		[controller retrieveState];

		if (button.pressed)
			break;

		[OFThread waitForVerticalBlank];

		objc_autoreleasePoolPop(pool);







|







548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
		OHGameControllerButton *button =
# ifdef OF_WII
		    [controller.profile.buttons objectForKey: @"Home"];
# else
		    [controller.profile.buttons objectForKey: @"Start"];
# endif

		[controller updateState];

		if (button.pressed)
			break;

		[OFThread waitForVerticalBlank];

		objc_autoreleasePoolPop(pool);

Modified tests/gamecontroller/GameControllerTests.m from [fd38b501b0] to [5f0d39c588].

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
			id <OHGameControllerProfile> profile =
			    controller.profile;

			[OFStdOut setForegroundColor: [OFColor green]];
			[OFStdOut writeLine: controller.description];

			@try {
				[controller retrieveState];
			} @catch (OFReadFailedException *e) {
				[OFStdOut setForegroundColor: [OFColor red]];
				[OFStdOut writeString: e.description];
				continue;
			}

			printProfile(profile);







|







217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
			id <OHGameControllerProfile> profile =
			    controller.profile;

			[OFStdOut setForegroundColor: [OFColor green]];
			[OFStdOut writeLine: controller.description];

			@try {
				[controller updateState];
			} @catch (OFReadFailedException *e) {
				[OFStdOut setForegroundColor: [OFColor red]];
				[OFStdOut writeString: e.description];
				continue;
			}

			printProfile(profile);