ObjFW  Check-in [764fe0bac3]

Overview
Comment:OFGameController: More code reuse
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | gamecontroller
Files: files | file ages | folders
SHA3-256: 764fe0bac3cc387e377d32c91e4d1f47c54d21db2d5336ad3b931fcf7cde8835
User & Date: js on 2024-05-18 11:37:49
Other Links: branch diff | manifest | tags
Context
2024-05-18
12:06
OFGameController: Map - to Select and + to Start check-in: c28b5e5208 user: js tags: gamecontroller
11:37
OFGameController: More code reuse check-in: 764fe0bac3 user: js tags: gamecontroller
2024-05-15
22:50
OFGameController: Use different subclasses check-in: 4ecdef7491 user: js tags: gamecontroller
Changes

Modified src/hid/OFEvdevGameController.m from [7d8e2879a0] to [3197bc7111].

596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
	if (button == OFGameControllerLeftTriggerButton &&
	    _hasLeftTriggerPressure)
		return _leftTriggerPressure;
	if (button == OFGameControllerRightTriggerButton &&
	    _hasRightTriggerPressure)
		return _rightTriggerPressure;

	return ([self.pressedButtons containsObject: button] ? 1 : 0);
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name];
}
@end







<
<
|
<
<
<


596
597
598
599
600
601
602


603



604
605
	if (button == OFGameControllerLeftTriggerButton &&
	    _hasLeftTriggerPressure)
		return _leftTriggerPressure;
	if (button == OFGameControllerRightTriggerButton &&
	    _hasRightTriggerPressure)
		return _rightTriggerPressure;



	return [super pressureForButton: button];



}
@end

Modified src/hid/OFGameController.m from [c04fc09244] to [d96cd2e808].

17
18
19
20
21
22
23


24
25
26
27
28
29
30
 * <https://www.gnu.org/licenses/>.
 */

#include "config.h"

#import "OFGameController.h"
#import "OFArray.h"



#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# include "OFEvdevGameController.h"
#endif
#ifdef OF_WINDOWS
# include "OFXInputGameController.h"
#endif







>
>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 * <https://www.gnu.org/licenses/>.
 */

#include "config.h"

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

#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# include "OFEvdevGameController.h"
#endif
#ifdef OF_WINDOWS
# include "OFXInputGameController.h"
#endif
122
123
124
125
126
127
128


129










130
131
132
133
134
135
136
- (void)retrieveState
{
	OF_UNRECOGNIZED_SELECTOR
}

- (float)pressureForButton: (OFGameControllerButton)button
{


	OF_UNRECOGNIZED_SELECTOR










}
@end

#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# include "OFEvdevGameController.m"
#endif
#ifdef OF_WINDOWS







>
>
|
>
>
>
>
>
>
>
>
>
>







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
- (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"
#endif
#ifdef OF_WINDOWS

Modified src/hid/OFNintendo3DSGameController.m from [a67f0beecf] to [ab4d725506].

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
	return true;
}

- (bool)hasRightAnalogStick
{
	return false;
}

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

- (OFString *)description
{
	return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name];
}
@end







<
<
<
<
<
<
<
<
<
<

170
171
172
173
174
175
176










177
	return true;
}

- (bool)hasRightAnalogStick
{
	return false;
}










@end

Modified src/hid/OFNintendoDSGameController.m from [9294d80bc8] to [ca22ee2dc5].

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
	return false;
}

- (bool)hasRightAnalogStick
{
	return false;
}

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

- (OFString *)description
{
	return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name];
}
@end







<
<
<
<
<
<
<
<
<
<

143
144
145
146
147
148
149










150
	return false;
}

- (bool)hasRightAnalogStick
{
	return false;
}










@end

Modified src/hid/OFXInputGameController.m from [ba31cb5921] to [a152c52018].

263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
- (float)pressureForButton: (OFGameControllerButton)button
{
	if (button == OFGameControllerLeftTriggerButton)
		return _leftTriggerPressure;
	if (button == OFGameControllerRightTriggerButton)
		return _rightTriggerPressure;

	return ([self.pressedButtons containsObject: button] ? 1 : 0);
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name];
}
@end







<
<
|
<
<
<


263
264
265
266
267
268
269


270



271
272
- (float)pressureForButton: (OFGameControllerButton)button
{
	if (button == OFGameControllerLeftTriggerButton)
		return _leftTriggerPressure;
	if (button == OFGameControllerRightTriggerButton)
		return _rightTriggerPressure;



	return [super pressureForButton: button];



}
@end

Modified tests/gamecontroller/GameControllerTests.m from [77c7b12639] to [54bd86368c].

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

		for (OFGameController *controller in controllers) {
			OFArray OF_GENERIC(OFGameControllerButton) *buttons =
			    controller.buttons.allObjects.sortedArray;
			size_t i = 0;

			[OFStdOut setForegroundColor: [OFColor green]];
			[OFStdOut writeString: controller.name];

			if (controller.vendorID != nil &&
			    controller.productID != nil) {
				[OFStdOut setForegroundColor: [OFColor teal]];
				[OFStdOut writeFormat: @" [%04X:%04X]",
				    controller.vendorID.unsignedShortValue,
				    controller.productID.unsignedShortValue];
			}

			[OFStdOut writeString: @"\n"];

			[controller retrieveState];

			for (OFGameControllerButton button in buttons) {
				float pressure =
				    [controller pressureForButton: button];








<
<
<
<
<
<
<
<
<
<
|







45
46
47
48
49
50
51










52
53
54
55
56
57
58
59

		for (OFGameController *controller in controllers) {
			OFArray OF_GENERIC(OFGameControllerButton) *buttons =
			    controller.buttons.allObjects.sortedArray;
			size_t i = 0;

			[OFStdOut setForegroundColor: [OFColor green]];










			[OFStdOut writeLine: controller.description];

			[controller retrieveState];

			for (OFGameControllerButton button in buttons) {
				float pressure =
				    [controller pressureForButton: button];