ObjFW  Changes On Branch 3ef11175bc2fabca

Changes In Branch gamecontroller Through [3ef11175bc] Excluding Merge-Ins

This is equivalent to a diff from dcea3bad47 to 3ef11175bc

2024-05-09
10:22
Merge trunk into branch "gamecontroller" check-in: c0a80a897d user: js tags: gamecontroller
2024-05-05
23:07
OFGameController: Fix typos check-in: 3ef11175bc user: js tags: gamecontroller
19:56
OFGameController: Rename axis to analog stick check-in: 498a91a2a4 user: js tags: gamecontroller
19:04
OFStdIOStream: Add special case for column 0 check-in: 1c2fe75e6e user: js tags: trunk
18:59
Add OFGameController check-in: a0f4283e81 user: js tags: gamecontroller
12:33
Make OF_APPLICATION_DELEGATE() work with -mwindows check-in: dcea3bad47 user: js tags: trunk
12:15
Increase ObjFW library minor version check-in: ab1d9b0ecb user: js tags: trunk

Modified src/Makefile from [6486149d8c] to [188c5944db].

21
22
23
24
25
26
27

28
29
30
31
32
33
34
       OFData.m				\
       OFData+CryptographicHashing.m	\
       OFData+MessagePackParsing.m	\
       OFDate.m				\
       OFDictionary.m			\
       OFEnumerator.m			\
       OFFileManager.m			\

       OFGZIPStream.m			\
       OFHMAC.m				\
       OFINICategory.m			\
       OFINIFile.m			\
       OFIRI.m				\
       OFIRIHandler.m			\
       OFInflate64Stream.m		\







>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
       OFData.m				\
       OFData+CryptographicHashing.m	\
       OFData+MessagePackParsing.m	\
       OFDate.m				\
       OFDictionary.m			\
       OFEnumerator.m			\
       OFFileManager.m			\
       OFGameController.m		\
       OFGZIPStream.m			\
       OFHMAC.m				\
       OFINICategory.m			\
       OFINIFile.m			\
       OFIRI.m				\
       OFIRIHandler.m			\
       OFInflate64Stream.m		\

Added src/OFGameController.h version [542208ba0a].



































































































































































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

#import "OFObject.h"
#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

/** @file */

@class OFSet OF_GENERIC(ObjectType);

/**
 * @brief A class for reading state from a game controller.
 */
OF_SUBCLASSING_RESTRICTED
@interface OFGameController: OFObject
#ifdef OF_HAVE_CLASS_PROPERTIES
@property (class, readonly, nonatomic) size_t numControllers;
#endif

/**
 * @brief The buttons the controller has.
 */
@property (readonly, nonatomic) OFSet OF_GENERIC(OFString *) *buttons;

/**
 * @brief The currently pressed buttons on the controller.
 */
@property (readonly, nonatomic) OFSet OF_GENERIC(OFString *) *pressedButtons;

/**
 * @brief The number of analog sticks the controller has.
 */
@property (readonly, nonatomic) size_t numAnalogSticks;

/**
 * @brief Returns the number of available controllers.
 *
 * @return The number of available controllers
 */
+ (size_t)numControllers;

/**
 * @brief Returns the specified controller.
 *
 * @param index The index of the controller to return
 * @return The specified controller
 */
+ (OFGameController *)controllerWithIndex: (size_t)index;

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Returns the current position of the specified analog stick.
 *
 * The range is from (-1, -1) to (1, 1).
 *
 * @param index The index of the analog stick whose position to return
 * @return The current position of the specified analog stick
 */
- (OFPoint)positionOfAnalogStickWithIndex: (size_t)index;
@end

OF_ASSUME_NONNULL_END

Added src/OFGameController.m version [8a9752888e].













































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
46
47
48
49
50
51
52
53
54
/*
 * 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 "OFGameController.h"

#import "OFOutOfRangeException.h"

#if defined(OF_NINTENDO_DS)
# include "platform/NintendoDS/OFGameController.m"
#elif defined(OF_NINTENDO_3DS)
# include "platform/Nintendo3DS/OFGameController.m"
#else
@implementation OFGameController
@dynamic buttons, pressedButtons, numAnalogSticks;

+ (size_t)numControllers
{
	return 0;
}

+ (OFGameController *)controllerWithIndex: (size_t)index
{
	@throw [OFOutOfRangeException exception];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (OFPoint)positionOfAnalogStickWithIndex: (size_t)index
{
	OF_UNRECOGNIZED_SELECTOR
}
@end
#endif

Modified src/ObjFW.h from [11ffe4203c] to [04ce1fb016].

144
145
146
147
148
149
150

151
152
153
154
155
156
157
#import "OFSystemInfo.h"
#import "OFLocale.h"
#import "OFOptionsParser.h"
#import "OFTimer.h"
#import "OFRunLoop.h"

#import "OFMatrix4x4.h"


#ifdef OF_WINDOWS
# import "OFWindowsRegistryKey.h"
#endif

#import "OFAllocFailedException.h"
#import "OFAlreadyOpenException.h"







>







144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#import "OFSystemInfo.h"
#import "OFLocale.h"
#import "OFOptionsParser.h"
#import "OFTimer.h"
#import "OFRunLoop.h"

#import "OFMatrix4x4.h"
#import "OFGameController.h"

#ifdef OF_WINDOWS
# import "OFWindowsRegistryKey.h"
#endif

#import "OFAllocFailedException.h"
#import "OFAlreadyOpenException.h"

Added src/platform/Nintendo3DS/OFGameController.m version [5edf21e397].







































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * 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 "OFGameController.h"
#import "OFSet.h"

#import "OFOutOfRangeException.h"

#define id id_3ds
#include <3ds.h>
#undef id

@interface OFGameController ()
- (instancetype)of_init OF_METHOD_FAMILY(init);
@end

static OFGameController *controller;

static void
initController(void)
{
	controller = [[OFGameController alloc] of_init];
}

@implementation OFGameController
+ (size_t)numControllers
{
	return 1;
}

+ (OFGameController *)controllerWithIndex: (size_t)index
{
	static OFOnceControl onceControl = OFOnceControlInitValue;

	if (index > 0)
		@throw [OFOutOfRangeException exception];

	OFOnce(&onceControl, initController);

	return [[controller retain] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)of_init
{
	return [super init];
}

- (OFSet *)buttons
{
	return [OFSet setWithObjects: @"A", @"B", @"Select", @"Start",
	    @"D-Pad Right", @"D-Pad Left", @"D-Pad Up", @"D-Pad Down", @"R",
	    @"L", @"X", @"Y", @"ZL", @"ZR", @"C-Stick Right", @"C-Stick Left",
	    @"C-Stick Up", @"C-Stick Down", nil];
}

- (OFSet *)pressedButtons
{
	OFMutableSet *pressedButtons = [OFMutableSet setWithCapacity: 18];
	u32 keys;

	hidScanInput();
	keys = hidKeysHeld();

	if (keys & KEY_A)
		[pressedButtons addObject: @"A"];
	if (keys & KEY_B)
		[pressedButtons addObject: @"A"];
	if (keys & KEY_SELECT)
		[pressedButtons addObject: @"Select"];
	if (keys & KEY_START)
		[pressedButtons addObject: @"Start"];
	if (keys & KEY_DRIGHT)
		[pressedButtons addObject: @"D-Pad Right"];
	if (keys & KEY_DLEFT)
		[pressedButtons addObject: @"D-Pad Left"];
	if (keys & KEY_DUP)
		[pressedButtons addObject: @"D-Pad Up"];
	if (keys & KEY_DDOWN)
		[pressedButtons addObject: @"D-Pad Down"];
	if (keys & KEY_R)
		[pressedButtons addObject: @"R"];
	if (keys & KEY_L)
		[pressedButtons addObject: @"L"];
	if (keys & KEY_X)
		[pressedButtons addObject: @"X"];
	if (keys & KEY_Y)
		[pressedButtons addObject: @"Y"];
	if (keys & KEY_ZL)
		[pressedButtons addObject: @"ZL"];
	if (keys & KEY_ZR)
		[pressedButtons addObject: @"ZR"];
	if (keys & KEY_CSTICK_RIGHT)
		[pressedButtons addObject: @"C-Stick Right"];
	if (keys & KEY_CSTICK_LEFT)
		[pressedButtons addObject: @"C-Stick Left"];
	if (keys & KEY_CSTICK_UP)
		[pressedButtons addObject: @"C-Stick Up"];
	if (keys & KEY_CSTICK_DOWN)
		[pressedButtons addObject: @"C-Stick Down"];

	[pressedButtons makeImmutable];

	return pressedButtons;
}

- (size_t)numAnalogSticks
{
	return 1;
}

- (OFPoint)positionOfAnalogStickWithIndex: (size_t)index
{
	circlePosition pos;

	if (index > 0)
		@throw [OFOutOfRangeException exception];

	hidCircleRead(&pos);

	return OFMakePoint(
	    (float)pos.dx / (pos.dx < 0 ? INT16_MIN : INT16_MAX),
	    (float)pos.dy / (pos.dy < 0 ? INT16_MIN : INT16_MAX));
}
@end

Added src/platform/NintendoDS/OFGameController.m version [30201f00f5].



























































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
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
/*
 * 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 "OFGameController.h"
#import "OFSet.h"

#import "OFOutOfRangeException.h"

#define asm __asm__
#include <nds.h>
#undef asm

@interface OFGameController ()
- (instancetype)of_init OF_METHOD_FAMILY(init);
@end

static OFGameController *controller;

static void
initController(void)
{
	controller = [[OFGameController alloc] of_init];
}

@implementation OFGameController
+ (size_t)numControllers
{
	return 1;
}

+ (OFGameController *)controllerWithIndex: (size_t)index
{
	static OFOnceControl onceControl = OFOnceControlInitValue;

	if (index > 0)
		@throw [OFOutOfRangeException exception];

	OFOnce(&onceControl, initController);

	return [[controller retain] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)of_init
{
	return [super init];
}

- (OFSet *)buttons
{
	return [OFSet setWithObjects: @"A", @"B", @"Select", @"Start",
	    @"D-Pad Right", @"D-Pad Left", @"D-Pad Up", @"D-Pad Down", @"R",
	    @"L", @"X", @"Y", nil];
}

- (OFSet *)pressedButtons
{
	OFMutableSet *pressedButtons = [OFMutableSet setWithCapacity: 12];
	uint32 keys;

	scanKeys();
	keys = keysCurrent();

	if (keys & KEY_A)
		[pressedButtons addObject: @"A"];
	if (keys & KEY_B)
		[pressedButtons addObject: @"A"];
	if (keys & KEY_SELECT)
		[pressedButtons addObject: @"Select"];
	if (keys & KEY_START)
		[pressedButtons addObject: @"Start"];
	if (keys & KEY_RIGHT)
		[pressedButtons addObject: @"D-Pad Right"];
	if (keys & KEY_LEFT)
		[pressedButtons addObject: @"D-Pad Left"];
	if (keys & KEY_UP)
		[pressedButtons addObject: @"D-Pad Up"];
	if (keys & KEY_DOWN)
		[pressedButtons addObject: @"D-Pad Down"];
	if (keys & KEY_R)
		[pressedButtons addObject: @"R"];
	if (keys & KEY_L)
		[pressedButtons addObject: @"L"];
	if (keys & KEY_X)
		[pressedButtons addObject: @"X"];
	if (keys & KEY_Y)
		[pressedButtons addObject: @"Y"];

	[pressedButtons makeImmutable];

	return pressedButtons;
}

- (size_t)numAnalogSticks
{
	return 0;
}

- (OFPoint)positionOfAnalogStickWithIndex: (size_t)index
{
	@throw [OFOutOfRangeException exception];
}
@end

Modified src/test/OTAppDelegate.m from [c99ef75558] to [2b12d71a47].

319
320
321
322
323
324
325
326
327
328
329
330
331
332


333
334
335
336
337
338
339
340
341
342
343
344
345
346
347


348
349
350
351
352
353
354
			WPAD_ScanPads();

			if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A)
				break;

			VIDEO_WaitVSync();
		}
#elif defined(OF_NINTENDO_DS)
		[OFStdOut setForegroundColor: [OFColor silver]];
		[OFStdOut writeLine: @"Press A to continue"];

		for (;;) {
			swiWaitForVBlank();
			scanKeys();



			if (keysDown() & KEY_A)
				break;
		}
#elif defined(OF_NINTENDO_3DS)
		[OFStdOut setForegroundColor: [OFColor silver]];
		[OFStdOut writeLine: @"Press A to continue"];

		for (;;) {
			hidScanInput();

			if (hidKeysDown() & KEY_A)
				break;

			gspWaitForVBlank();


		}
#elif defined(OF_NINTENDO_SWITCH)
		[OFStdOut setForegroundColor: [OFColor silver]];
		[OFStdOut writeLine: @"Press A to continue"];

		while (appletMainLoop()) {
			PadState pad;







|




<
|
>
>

|

|
|
<
<
|
<
<
|
<
<
<

>
>







319
320
321
322
323
324
325
326
327
328
329
330

331
332
333
334
335
336
337
338


339


340



341
342
343
344
345
346
347
348
349
350
			WPAD_ScanPads();

			if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A)
				break;

			VIDEO_WaitVSync();
		}
#elif defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS)
		[OFStdOut setForegroundColor: [OFColor silver]];
		[OFStdOut writeLine: @"Press A to continue"];

		for (;;) {

			void *pool = objc_autoreleasePoolPush();
			OFGameController *controller =
			    [OFGameController controllerWithIndex: 0];

			if ([controller.pressedButtons containsObject: @"A"])
				break;

# if defined(OF_NINTENDO_DS)


			swiWaitForVBlank();


# elif defined(OF_NINTENDO_3DS)



			gspWaitForVBlank();
# endif
			objc_autoreleasePoolPop(pool);
		}
#elif defined(OF_NINTENDO_SWITCH)
		[OFStdOut setForegroundColor: [OFColor silver]];
		[OFStdOut writeLine: @"Press A to continue"];

		while (appletMainLoop()) {
			PadState pad;