@@ -151,88 +151,6 @@ struct Stick {
151
151
float y;
152
152
};
153
153
154
- inline float Clampf (float val, float min, float max) {
155
- if (val < min) return min;
156
- if (val > max) return max;
157
- return val;
158
- }
159
-
160
- inline float Signf (float val) {
161
- return (float )((0 .0f < val) - (val < 0 .0f ));
162
- }
163
-
164
- inline float LinearMapf (float val, float a0, float a1, float b0, float b1) {
165
- return b0 + (((val - a0) * (b1 - b0)) / (a1 - a0));
166
- }
167
-
168
- static Stick NormalizedDeadzoneFilter (short x, short y, float dz, int idzm, float idz, float st) {
169
- Stick s (x, y, 1 .0f / 32767 .0f );
170
-
171
- float magnitude = sqrtf (s.x * s.x + s.y * s.y );
172
- if (magnitude > dz) {
173
-
174
- // Circle to square mapping (the PSP stick outputs the full -1..1 square of values)
175
- #if 1
176
- // Looks way better than the old one, below, in the axis tester.
177
- float sx = s.x ;
178
- float sy = s.y ;
179
- float scaleFactor = sqrtf ((sx * sx + sy * sy) / std::max (sx * sx, sy * sy));
180
- s.x = sx * scaleFactor;
181
- s.y = sy * scaleFactor;
182
- #else
183
- if (magnitude > 1.0f) {
184
- s.x *= 1.41421f;
185
- s.y *= 1.41421f;
186
- }
187
- #endif
188
-
189
- // Linear range mapping (used to invert deadzones)
190
- float md = std::max (dz, idz);
191
-
192
- if (idzm == 1 )
193
- {
194
- float xSign = Signf (s.x );
195
- if (xSign != 0 .0f ) {
196
- s.x = LinearMapf (s.x , xSign * dz, xSign, xSign * md, xSign * st);
197
- }
198
- }
199
- else if (idzm == 2 )
200
- {
201
- float ySign = Signf (s.y );
202
- if (ySign != 0 .0f ) {
203
- s.y = LinearMapf (s.y , ySign * dz, ySign, ySign * md, ySign * st);
204
- }
205
- }
206
- else if (idzm == 3 )
207
- {
208
- float xNorm = s.x / magnitude;
209
- float yNorm = s.y / magnitude;
210
- float mapMag = LinearMapf (magnitude, dz, 1 .0f , md, st);
211
- s.x = xNorm * mapMag;
212
- s.y = yNorm * mapMag;
213
- }
214
-
215
- s.x = Clampf (s.x , -1 .0f , 1 .0f );
216
- s.y = Clampf (s.y , -1 .0f , 1 .0f );
217
- } else {
218
- s.x = 0 .0f ;
219
- s.y = 0 .0f ;
220
- }
221
- return s;
222
- }
223
-
224
- bool NormalizedDeadzoneDiffers (short x1, short y1, short x2, short y2, const float dz) {
225
- Stick s1 (x1, y1 , 1 .0f / 32767 .0f );
226
- Stick s2 (x2, y2, 1 .0f / 32767 .0f );
227
-
228
- float magnitude1 = sqrtf (s1.x * s1.x + s1.y * s1.y );
229
- float magnitude2 = sqrtf (s2.x * s2.x + s2.y * s2.y );
230
- if (magnitude1 > dz || magnitude2 > dz) {
231
- return x1 != x2 || y1 != y2;
232
- }
233
- return false ;
234
- }
235
-
236
154
bool NormalizedDeadzoneDiffers (u8 x1, u8 x2, const u8 thresh) {
237
155
if (x1 > thresh || x2 > thresh) {
238
156
return x1 != x2;
@@ -277,11 +195,6 @@ void XinputDevice::UpdatePad(int pad, const XINPUT_STATE &state, XINPUT_VIBRATIO
277
195
ApplyButtons (pad, state);
278
196
ApplyVibration (pad, vibration);
279
197
280
- const float STICK_DEADZONE = g_Config.fXInputAnalogDeadzone ;
281
- const int STICK_INV_MODE = g_Config.iXInputAnalogInverseMode ;
282
- const float STICK_INV_DEADZONE = g_Config.fXInputAnalogInverseDeadzone ;
283
- const float STICK_SENSITIVITY = g_Config.fXInputAnalogSensitivity ;
284
-
285
198
AxisInput axis;
286
199
axis.deviceId = DEVICE_ID_X360_0 + pad;
287
200
auto sendAxis = [&](AndroidJoystickAxis axisId, float value) {
@@ -290,19 +203,10 @@ void XinputDevice::UpdatePad(int pad, const XINPUT_STATE &state, XINPUT_VIBRATIO
290
203
NativeAxis (axis);
291
204
};
292
205
293
- if (NormalizedDeadzoneDiffers (prevState[pad].Gamepad .sThumbLX , prevState[pad].Gamepad .sThumbLY , state.Gamepad .sThumbLX , state.Gamepad .sThumbLY , STICK_DEADZONE)) {
294
- Stick left = NormalizedDeadzoneFilter (state.Gamepad .sThumbLX , state.Gamepad .sThumbLY , STICK_DEADZONE, STICK_INV_MODE, STICK_INV_DEADZONE, STICK_SENSITIVITY);
295
-
296
- sendAxis (JOYSTICK_AXIS_X, left.x );
297
- sendAxis (JOYSTICK_AXIS_Y, left.y );
298
- }
299
-
300
- if (NormalizedDeadzoneDiffers (prevState[pad].Gamepad .sThumbRX , prevState[pad].Gamepad .sThumbRY , state.Gamepad .sThumbRX , state.Gamepad .sThumbRY , STICK_DEADZONE)) {
301
- Stick right = NormalizedDeadzoneFilter (state.Gamepad .sThumbRX , state.Gamepad .sThumbRY , STICK_DEADZONE, STICK_INV_MODE, STICK_INV_DEADZONE, STICK_SENSITIVITY);
302
-
303
- sendAxis (JOYSTICK_AXIS_Z, right.x );
304
- sendAxis (JOYSTICK_AXIS_RZ, right.y );
305
- }
206
+ sendAxis (JOYSTICK_AXIS_X, (float )state.Gamepad .sThumbLX / 32767 .0f );
207
+ sendAxis (JOYSTICK_AXIS_Y, (float )state.Gamepad .sThumbLY / 32767 .0f );
208
+ sendAxis (JOYSTICK_AXIS_Z, (float )state.Gamepad .sThumbRX / 32767 .0f );
209
+ sendAxis (JOYSTICK_AXIS_RZ, (float )state.Gamepad .sThumbRY / 32767 .0f );
306
210
307
211
if (NormalizedDeadzoneDiffers (prevState[pad].Gamepad .bLeftTrigger , state.Gamepad .bLeftTrigger , XINPUT_GAMEPAD_TRIGGER_THRESHOLD)) {
308
212
sendAxis (JOYSTICK_AXIS_LTRIGGER, (float )state.Gamepad .bLeftTrigger / 255 .0f );
0 commit comments