ObjFW  Check-in [c7a5bfe9e6]

Overview
Comment:ObjFWHID: Improve test for gamepad profile
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c7a5bfe9e6a615ea00ee481eecbb8a4f56a9cd2c5e38b2a99eeb328bfa1da822
User & Date: js on 2024-06-08 22:59:06
Other Links: manifest | tags
Context
2024-06-08
23:04
OHEvdevGamepad: Fix name of trigger buttons check-in: 31f8c31ac7 user: js tags: trunk
22:59
ObjFWHID: Improve test for gamepad profile check-in: c7a5bfe9e6 user: js tags: trunk
22:47
OHEvdevGameController: Default to Xbox buttons check-in: 6b3b47c1f4 user: js tags: trunk
Changes

Modified tests/gamecontroller/GameControllerTests.m from [d73797114c] to [0c35b7944c].

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
97
98
99
100
@end

OF_APPLICATION_DELEGATE(GameControllerTests)

@implementation GameControllerTests
- (void)applicationDidFinishLaunching: (OFNotification *)notification
{
	bool gamepad = false;

#if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS)
	[OFStdIOStream setUpConsole];
#endif

	if ([[OFApplication arguments].firstObject isEqual: @"gamepad"])
		gamepad = true;

	for (;;) {
		void *pool = objc_autoreleasePoolPush();

		if (_lastControllersUpdate == nil ||
		    -[_lastControllersUpdate timeIntervalSinceNow] > 1) {
			[_controllers release];
			[_lastControllersUpdate release];

			_controllers = [[OHGameController controllers]
			    mutableCopy];
			_lastControllersUpdate = [[OFDate alloc] init];

			[OFStdOut clear];
		}

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

		for (OHGameController *controller in _controllers) {
			OHGameControllerProfile *profile = (gamepad

			    ? controller.gamepad : controller.rawProfile);
			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;







<
<




<
<
<


















|
>







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

OF_APPLICATION_DELEGATE(GameControllerTests)

@implementation GameControllerTests
- (void)applicationDidFinishLaunching: (OFNotification *)notification
{


#if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS)
	[OFStdIOStream setUpConsole];
#endif




	for (;;) {
		void *pool = objc_autoreleasePoolPush();

		if (_lastControllersUpdate == nil ||
		    -[_lastControllersUpdate timeIntervalSinceNow] > 1) {
			[_controllers release];
			[_lastControllersUpdate release];

			_controllers = [[OHGameController controllers]
			    mutableCopy];
			_lastControllersUpdate = [[OFDate alloc] init];

			[OFStdOut clear];
		}

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

		for (OHGameController *controller in _controllers) {
			OHGameControllerProfile *profile =
			    (controller.gamepad != nil
			    ? controller.gamepad : controller.rawProfile);
			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;
169
170
171
172
173
174
175
































176
177
178
179
180
181
182
183
184
185
186
187
				[OFStdOut writeFormat:
				    @"%@: (%5.2f, %5.2f)  ",
				    name, directionalPad.xAxis.value,
				    directionalPad.yAxis.value];
			}
			if (directionalPads.count > 0)
				[OFStdOut writeString: @"\n"];
































		}

#if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS)
		[OFThread waitForVerticalBlank];
#else
		[OFThread sleepForTimeInterval: 1.f / 60.f];
#endif

		objc_autoreleasePoolPop(pool);
	}
}
@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
				[OFStdOut writeFormat:
				    @"%@: (%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;

				[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];
				[OFStdOut writeFormat:
				    @"[Map] Left Trigger: %@"
				    @"  Right Trigger: %@\n",
				    gamepad.leftTriggerButton.name,
				    gamepad.rightTriggerButton.name];
				[OFStdOut writeFormat:
				    @"[Map] Left Thumbstick: %@"
				    @"  Right Thumbstick: %@\n",
				    gamepad.leftThumbstickButton.name,
				    gamepad.rightThumbstickButton.name];
				[OFStdOut writeFormat:
				    @"[Map] Menu: %@  Options: %@  Home: %@\n",
				    gamepad.menuButton.name,
				    gamepad.optionsButton.name,
				    gamepad.homeButton.name];
			}
		}

#if defined(OF_WII) || defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS)
		[OFThread waitForVerticalBlank];
#else
		[OFThread sleepForTimeInterval: 1.f / 60.f];
#endif

		objc_autoreleasePoolPop(pool);
	}
}
@end