ObjFW  Diff

Differences From Artifact [2ac5ac1c04]:

To Artifact [2baa5a5492]:


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
}

- (instancetype)initWithIndex: (size_t)index
{
	self = [super init];

	@try {
		padInitialize(&_padState, HidNpadIdType_No1 + index,
		    (index == 0 ? HidNpadIdType_Handheld : 0));
		padUpdate(&_padState);

		if (!(padGetAttributes(&_padState) &
		    HidNpadAttribute_IsConnected))
			@throw [OFInitializationFailedException
			    exceptionWithClass: self.class];

		_extendedGamepad =
		    [[OHNintendoSwitchExtendedGamepad alloc] init];

		[self retrieveState];







|

|

<
|







72
73
74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
}

- (instancetype)initWithIndex: (size_t)index
{
	self = [super init];

	@try {
		padInitialize(&_pad, HidNpadIdType_No1 + index,
		    (index == 0 ? HidNpadIdType_Handheld : 0));
		padUpdate(&_pad);


		if (!padIsConnected(&_pad))
			@throw [OFInitializationFailedException
			    exceptionWithClass: self.class];

		_extendedGamepad =
		    [[OHNintendoSwitchExtendedGamepad alloc] init];

		[self retrieveState];
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
	    *buttons = _extendedGamepad.buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *directionalPads = _extendedGamepad.directionalPads;
	u64 keys;
	HidAnalogStickState stick;
	OHGameControllerDirectionalPad *directionalPad;

	padUpdate(&_padState);
	keys = padGetButtons(&_padState);

	[[buttons objectForKey: @"A"] setValue: !!(keys & HidNpadButton_A)];
	[[buttons objectForKey: @"B"] setValue: !!(keys & HidNpadButton_B)];
	[[buttons objectForKey: @"X"] setValue: !!(keys & HidNpadButton_X)];
	[[buttons objectForKey: @"Y"] setValue: !!(keys & HidNpadButton_Y)];
	[[buttons objectForKey: @"L"] setValue: !!(keys & HidNpadButton_L)];
	[[buttons objectForKey: @"R"] setValue: !!(keys & HidNpadButton_R)];
	[[buttons objectForKey: @"ZL"] setValue: !!(keys & HidNpadButton_ZL)];
	[[buttons objectForKey: @"ZR"] setValue: !!(keys & HidNpadButton_ZR)];
	[[buttons objectForKey: @"Left Thumbstick"]
	    setValue: !!(keys & HidNpadButton_StickL)];
	[[buttons objectForKey: @"Right Thumbstick"]
	    setValue: !!(keys & HidNpadButton_StickR)];
	[[buttons objectForKey: @"+"] setValue: !!(keys & HidNpadButton_Plus)];
	[[buttons objectForKey: @"-"] setValue: !!(keys & HidNpadButton_Minus)];

	stick = padGetStickPos(&_padState, 0);
	directionalPad = [directionalPads objectForKey: @"Left Thumbstick"];
	[directionalPad.xAxis setValue:
	    (float)stick.x / (stick.x < 0 ? -INT16_MIN : INT16_MAX)];
	[directionalPad.yAxis setValue:
	    -(float)stick.y / (stick.y < 0 ? -INT16_MIN : INT16_MAX)];

	stick = padGetStickPos(&_padState, 1);
	directionalPad = [directionalPads objectForKey: @"Right Thumbstick"];
	[directionalPad.xAxis setValue:
	    (float)stick.x / (stick.x < 0 ? -INT16_MIN : INT16_MAX)];
	[directionalPad.yAxis setValue:
	    -(float)stick.y / (stick.y < 0 ? -INT16_MIN : INT16_MAX)];

	directionalPad = [directionalPads objectForKey: @"D-Pad"];







|
|
















|






|







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
	    *buttons = _extendedGamepad.buttons;
	OFDictionary OF_GENERIC(OFString *, OHGameControllerDirectionalPad *)
	    *directionalPads = _extendedGamepad.directionalPads;
	u64 keys;
	HidAnalogStickState stick;
	OHGameControllerDirectionalPad *directionalPad;

	padUpdate(&_pad);
	keys = padGetButtons(&_pad);

	[[buttons objectForKey: @"A"] setValue: !!(keys & HidNpadButton_A)];
	[[buttons objectForKey: @"B"] setValue: !!(keys & HidNpadButton_B)];
	[[buttons objectForKey: @"X"] setValue: !!(keys & HidNpadButton_X)];
	[[buttons objectForKey: @"Y"] setValue: !!(keys & HidNpadButton_Y)];
	[[buttons objectForKey: @"L"] setValue: !!(keys & HidNpadButton_L)];
	[[buttons objectForKey: @"R"] setValue: !!(keys & HidNpadButton_R)];
	[[buttons objectForKey: @"ZL"] setValue: !!(keys & HidNpadButton_ZL)];
	[[buttons objectForKey: @"ZR"] setValue: !!(keys & HidNpadButton_ZR)];
	[[buttons objectForKey: @"Left Thumbstick"]
	    setValue: !!(keys & HidNpadButton_StickL)];
	[[buttons objectForKey: @"Right Thumbstick"]
	    setValue: !!(keys & HidNpadButton_StickR)];
	[[buttons objectForKey: @"+"] setValue: !!(keys & HidNpadButton_Plus)];
	[[buttons objectForKey: @"-"] setValue: !!(keys & HidNpadButton_Minus)];

	stick = padGetStickPos(&_pad, 0);
	directionalPad = [directionalPads objectForKey: @"Left Thumbstick"];
	[directionalPad.xAxis setValue:
	    (float)stick.x / (stick.x < 0 ? -INT16_MIN : INT16_MAX)];
	[directionalPad.yAxis setValue:
	    -(float)stick.y / (stick.y < 0 ? -INT16_MIN : INT16_MAX)];

	stick = padGetStickPos(&_pad, 1);
	directionalPad = [directionalPads objectForKey: @"Right Thumbstick"];
	[directionalPad.xAxis setValue:
	    (float)stick.x / (stick.x < 0 ? -INT16_MIN : INT16_MAX)];
	[directionalPad.yAxis setValue:
	    -(float)stick.y / (stick.y < 0 ? -INT16_MIN : INT16_MAX)];

	directionalPad = [directionalPads objectForKey: @"D-Pad"];