ObjFW  Diff

Differences From Artifact [38aa35cd32]:

To Artifact [b6f18a05d5]:


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

#import "OHWiiGameController.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHWiiClassicController.h"



#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFReadFailedException.h"

#define asm __asm__
#include <wiiuse/wpad.h>
#undef asm

@interface OHWiiGameControllerProfile: OFObject <OHGameControllerProfile>
{
	OFDictionary OF_GENERIC(OFString *, OHGameControllerButton *) *_buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *_directionalPads;
}

- (instancetype)initWithType: (uint32_t)type;
@end

static OFString *const buttonNames[] = {
	@"A", @"B", @"1", @"2", @"+", @"-", @"Home"
};
static const size_t numButtons = sizeof(buttonNames) / sizeof(*buttonNames);
static OFString *const nunchukButtonNames[] = {
	@"C", @"Z"
};
static const size_t numNunchukButtons =
    sizeof(nunchukButtonNames) / sizeof(*nunchukButtonNames);

static float
scale(float value, float min, float max, float center)
{
	if (value < min)
		value = min;
	if (value > max)
		value = max;







>
>









<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







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

#import "OHWiiGameController.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerDirectionalPad.h"
#import "OHWiiClassicController.h"
#import "OHWiimote.h"
#import "OHWiimoteWithNunchuk.h"

#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFReadFailedException.h"

#define asm __asm__
#include <wiiuse/wpad.h>
#undef asm





















static float
scale(float value, float min, float max, float center)
{
	if (value < min)
		value = min;
	if (value > max)
		value = max;
110
111
112
113
114
115
116


117
118
119
120
121
122
123
124
125
126

	@try {
		_index = index;
		_type = type;

		if (type == WPAD_EXP_CLASSIC)
			_rawProfile = [[OHWiiClassicController alloc] init];


		else
			_rawProfile = [[OHWiiGameControllerProfile alloc]
			    initWithType: type];

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








>
>

|
<







92
93
94
95
96
97
98
99
100
101
102

103
104
105
106
107
108
109

	@try {
		_index = index;
		_type = type;

		if (type == WPAD_EXP_CLASSIC)
			_rawProfile = [[OHWiiClassicController alloc] init];
		else if (type == WPAD_EXP_NUNCHUK)
			_rawProfile = [[OHWiimoteWithNunchuk alloc] init];
		else
			_rawProfile = [[OHWiimote alloc] init];


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

266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
- (id <OHExtendedGamepad>)extendedGamepad
{
	if (_type == WPAD_EXP_CLASSIC)
		return (id <OHExtendedGamepad>)_rawProfile;

	return nil;
}
@end

@implementation OHWiiGameControllerProfile
@synthesize buttons = _buttons, directionalPads = _directionalPads;

- (instancetype)initWithType: (uint32_t)type
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons;
		OFMutableDictionary *directionalPads;
		OHGameControllerDirectionalPad *directionalPad;
		OHGameControllerButton *up, *down, *left, *right;
		OHGameControllerAxis *xAxis, *yAxis;

		if (type != WPAD_EXP_NONE && type != WPAD_EXP_NUNCHUK)
			@throw [OFInvalidArgumentException exception];

		buttons = [OFMutableDictionary
		    dictionaryWithCapacity: numButtons + numNunchukButtons];

		for (size_t i = 0; i < numButtons; i++) {
			OHGameControllerButton *button =
			    [[[OHGameControllerButton alloc]
			    initWithName: buttonNames[i]] autorelease];
			[buttons setObject: button forKey: buttonNames[i]];
		}

		directionalPads = [OFMutableDictionary dictionary];

		up = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Up"] autorelease];
		down = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Down"] autorelease];
		left = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Left"] autorelease];
		right = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Right"] autorelease];
		directionalPad = [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"D-Pad"
			      up: up
			    down: down
			    left: left
			   right: right] autorelease];
		[directionalPads setObject: directionalPad forKey: @"D-Pad"];

		if (type == WPAD_EXP_NUNCHUK) {
			for (size_t i = 0; i < numNunchukButtons; i++) {
				OHGameControllerButton *button =
				    [[[OHGameControllerButton alloc]
				    initWithName: nunchukButtonNames[i]]
					autorelease];

				[buttons setObject: button
					    forKey: nunchukButtonNames[i]];
			}

			xAxis = [[[OHGameControllerAxis alloc]
			    initWithName: @"X"] autorelease];
			yAxis = [[[OHGameControllerAxis alloc]
			    initWithName: @"Y"] autorelease];
			directionalPad = [[[OHGameControllerDirectionalPad alloc]
			    initWithName: @"Analog Stick"
				   xAxis: xAxis
				   yAxis: yAxis] autorelease];
			[directionalPads setObject: directionalPad
					    forKey: @"Analog Stick"];
		}

		[buttons makeImmutable];
		[directionalPads makeImmutable];
		_buttons = [buttons retain];
		_directionalPads = [directionalPads retain];

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

	return self;
}

- (void)dealloc
{
	[_buttons release];
	[_directionalPads release];

	[super dealloc];
}

- (OFDictionary OF_GENERIC(OFString *, OHGameControllerAxis *) *)axes
{
	return [OFDictionary dictionary];
}
@end








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
249
250
251
252
253
254
255
256

































































































- (id <OHExtendedGamepad>)extendedGamepad
{
	if (_type == WPAD_EXP_CLASSIC)
		return (id <OHExtendedGamepad>)_rawProfile;

	return nil;
}
@end