ObjFW  Diff

Differences From Artifact [adf29c8c87]:

To Artifact [52a27f332c]:


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
	controllers = [[OFArray alloc] initWithObject:
	    [[[OFGameController alloc] of_init] autorelease]];

	objc_autoreleasePoolPop(pool);
}

@implementation OFGameController

@dynamic rightAnalogStickPosition;

+ (OFArray OF_GENERIC(OFGameController *) *)controllers
{
	static OFOnceControl onceControl = OFOnceControlInitValue;

	OFOnce(&onceControl, initControllers);

	return [[controllers retain] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

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








































































}

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








>


















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







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
148
	controllers = [[OFArray alloc] initWithObject:
	    [[[OFGameController alloc] of_init] autorelease]];

	objc_autoreleasePoolPop(pool);
}

@implementation OFGameController
@synthesize leftAnalogStickPosition = _leftAnalogStickPosition;
@dynamic rightAnalogStickPosition;

+ (OFArray OF_GENERIC(OFGameController *) *)controllers
{
	static OFOnceControl onceControl = OFOnceControlInitValue;

	OFOnce(&onceControl, initControllers);

	return [[controllers retain] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

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

	@try {
		_pressedButtons = [[OFMutableSet alloc] initWithCapacity: 18];

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

	return self;
}

- (void)dealloc
{
	[_pressedButtons release];

	[super dealloc];
}

- (void)retrieveState
{
	u32 keys;
	circlePosition pos;

	hidScanInput();

	keys = hidKeysHeld();
	hidCircleRead(&pos);

	[_pressedButtons removeAllObjects];

	if (keys & KEY_A)
		[_pressedButtons addObject: OFGameControllerButtonA];
	if (keys & KEY_B)
		[_pressedButtons addObject: OFGameControllerButtonB];
	if (keys & KEY_SELECT)
		[_pressedButtons addObject: OFGameControllerButtonSelect];
	if (keys & KEY_START)
		[_pressedButtons addObject: OFGameControllerButtonStart];
	if (keys & KEY_DRIGHT)
		[_pressedButtons addObject: OFGameControllerButtonDPadRight];
	if (keys & KEY_DLEFT)
		[_pressedButtons addObject: OFGameControllerButtonDPadLeft];
	if (keys & KEY_DUP)
		[_pressedButtons addObject: OFGameControllerButtonDPadUp];
	if (keys & KEY_DDOWN)
		[_pressedButtons addObject: OFGameControllerButtonDPadDown];
	if (keys & KEY_R)
		[_pressedButtons addObject: OFGameControllerButtonR];
	if (keys & KEY_L)
		[_pressedButtons addObject: OFGameControllerButtonL];
	if (keys & KEY_X)
		[_pressedButtons addObject: OFGameControllerButtonX];
	if (keys & KEY_Y)
		[_pressedButtons addObject: OFGameControllerButtonY];
	if (keys & KEY_ZL)
		[_pressedButtons addObject: OFGameControllerButtonZL];
	if (keys & KEY_ZR)
		[_pressedButtons addObject: OFGameControllerButtonZR];
	if (keys & KEY_CSTICK_RIGHT)
		[_pressedButtons addObject: OFGameControllerButtonCPadRight];
	if (keys & KEY_CSTICK_LEFT)
		[_pressedButtons addObject: OFGameControllerButtonCPadLeft];
	if (keys & KEY_CSTICK_UP)
		[_pressedButtons addObject: OFGameControllerButtonCPadUp];
	if (keys & KEY_CSTICK_DOWN)
		[_pressedButtons addObject: OFGameControllerButtonCPadDown];

	_leftAnalogStickPosition = OFMakePoint(
	    (float)pos.dx / (pos.dx < 0 ? -INT16_MIN : INT16_MAX),
	    (float)pos.dy / (pos.dy < 0 ? -INT16_MIN : INT16_MAX));
}

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

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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
	    OFGameControllerButtonZR, OFGameControllerButtonCPadRight,
	    OFGameControllerButtonCPadLeft, OFGameControllerButtonCPadUp,
	    OFGameControllerButtonCPadDown, nil];
}

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

	hidScanInput();
	keys = hidKeysHeld();

	if (keys & KEY_A)
		[pressedButtons addObject: OFGameControllerButtonA];
	if (keys & KEY_B)
		[pressedButtons addObject: OFGameControllerButtonB];
	if (keys & KEY_SELECT)
		[pressedButtons addObject: OFGameControllerButtonSelect];
	if (keys & KEY_START)
		[pressedButtons addObject: OFGameControllerButtonStart];
	if (keys & KEY_DRIGHT)
		[pressedButtons addObject: OFGameControllerButtonDPadRight];
	if (keys & KEY_DLEFT)
		[pressedButtons addObject: OFGameControllerButtonDPadLeft];
	if (keys & KEY_DUP)
		[pressedButtons addObject: OFGameControllerButtonDPadUp];
	if (keys & KEY_DDOWN)
		[pressedButtons addObject: OFGameControllerButtonDPadDown];
	if (keys & KEY_R)
		[pressedButtons addObject: OFGameControllerButtonR];
	if (keys & KEY_L)
		[pressedButtons addObject: OFGameControllerButtonL];
	if (keys & KEY_X)
		[pressedButtons addObject: OFGameControllerButtonX];
	if (keys & KEY_Y)
		[pressedButtons addObject: OFGameControllerButtonY];
	if (keys & KEY_ZL)
		[pressedButtons addObject: OFGameControllerButtonZL];
	if (keys & KEY_ZR)
		[pressedButtons addObject: OFGameControllerButtonZR];
	if (keys & KEY_CSTICK_RIGHT)
		[pressedButtons addObject: OFGameControllerButtonCPadRight];
	if (keys & KEY_CSTICK_LEFT)
		[pressedButtons addObject: OFGameControllerButtonCPadLeft];
	if (keys & KEY_CSTICK_UP)
		[pressedButtons addObject: OFGameControllerButtonCPadUp];
	if (keys & KEY_CSTICK_DOWN)
		[pressedButtons addObject: OFGameControllerButtonCPadDown];

	[pressedButtons makeImmutable];

	return pressedButtons;
}

- (bool)hasLeftAnalogStick
{
	return true;
}

- (bool)hasRightAnalogStick
{
	return false;
}

- (OFPoint)leftAnalogStickPosition
{
	circlePosition pos;
	hidCircleRead(&pos);

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

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

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







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|












<
<
<
<
<
<
<
<
<
<










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
	    OFGameControllerButtonZR, OFGameControllerButtonCPadRight,
	    OFGameControllerButtonCPadLeft, OFGameControllerButtonCPadUp,
	    OFGameControllerButtonCPadDown, nil];
}

- (OFSet OF_GENERIC(OFGameControllerButton) *)pressedButtons
{














































	return [[_pressedButtons copy] autorelease];
}

- (bool)hasLeftAnalogStick
{
	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