|
7 | 7 | #include "Core/KeyMap.h" |
8 | 8 | #include "Core/ControlMapper.h" |
9 | 9 | #include "Core/Config.h" |
| 10 | +#include "Core/CoreParameter.h" |
| 11 | +#include "Core/System.h" |
10 | 12 |
|
11 | 13 | static float MapAxisValue(float v) { |
12 | 14 | const float deadzone = g_Config.fAnalogDeadzone; |
@@ -334,12 +336,21 @@ void ControlMapper::processAxis(const AxisInput &axis, int direction) { |
334 | 336 | case VIRTKEY_AXIS_RIGHT_Y_MAX: |
335 | 337 | SetPSPAxis('Y', value, CTRL_STICK_RIGHT); |
336 | 338 | break; |
| 339 | + |
| 340 | + case VIRTKEY_SPEED_ANALOG: |
| 341 | + ProcessAnalogSpeed(axis, false); |
| 342 | + break; |
337 | 343 | } |
338 | 344 | } |
339 | 345 |
|
340 | 346 | std::vector<int> resultsOpposite; |
341 | 347 | KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, -direction, &resultsOpposite); |
342 | 348 |
|
| 349 | + for (int result : resultsOpposite) { |
| 350 | + if (result == VIRTKEY_SPEED_ANALOG) |
| 351 | + ProcessAnalogSpeed(axis, true); |
| 352 | + } |
| 353 | + |
343 | 354 | int axisState = 0; |
344 | 355 | float threshold = axis.deviceId == DEVICE_ID_MOUSE ? AXIS_BIND_THRESHOLD_MOUSE : AXIS_BIND_THRESHOLD; |
345 | 356 | if (direction == 1 && axis.value >= threshold) { |
@@ -375,3 +386,55 @@ void ControlMapper::processAxis(const AxisInput &axis, int direction) { |
375 | 386 | } |
376 | 387 | } |
377 | 388 | } |
| 389 | + |
| 390 | +void ControlMapper::ProcessAnalogSpeed(const AxisInput &axis, bool opposite) { |
| 391 | + FPSLimit &limitMode = PSP_CoreParameter().fpsLimit; |
| 392 | + // If we're using an alternate speed already, let that win. |
| 393 | + if (limitMode != FPSLimit::NORMAL && limitMode != FPSLimit::ANALOG) |
| 394 | + return; |
| 395 | + // Don't even try if the limit is invalid. |
| 396 | + if (g_Config.iAnalogFpsLimit <= 0) |
| 397 | + return; |
| 398 | + |
| 399 | + AnalogFpsMode mode = (AnalogFpsMode)g_Config.iAnalogFpsMode; |
| 400 | + float value = axis.value; |
| 401 | + if (mode == AnalogFpsMode::AUTO) { |
| 402 | + // TODO: Consider the pad name for better auto? KeyMap::PadName(axis.deviceId); |
| 403 | + switch (axis.axisId) { |
| 404 | + case JOYSTICK_AXIS_X: |
| 405 | + case JOYSTICK_AXIS_Y: |
| 406 | + case JOYSTICK_AXIS_Z: |
| 407 | + case JOYSTICK_AXIS_RX: |
| 408 | + case JOYSTICK_AXIS_RY: |
| 409 | + case JOYSTICK_AXIS_RZ: |
| 410 | + // These, at least on directinput, can be used for triggers that go from mapped to opposite. |
| 411 | + mode = AnalogFpsMode::MAPPED_TO_OPPOSITE; |
| 412 | + break; |
| 413 | + |
| 414 | + default: |
| 415 | + // Other axises probably don't go from negative to positive. |
| 416 | + mode = AnalogFpsMode::MAPPED_DIRECTION; |
| 417 | + break; |
| 418 | + } |
| 419 | + } |
| 420 | + |
| 421 | + // Okay, now let's map it as appropriate. |
| 422 | + if (mode == AnalogFpsMode::MAPPED_DIRECTION) { |
| 423 | + value = fabsf(value); |
| 424 | + if (opposite) |
| 425 | + return; |
| 426 | + } else if (mode == AnalogFpsMode::MAPPED_TO_OPPOSITE) { |
| 427 | + value = fabsf(value); |
| 428 | + if (opposite) |
| 429 | + value = -value; |
| 430 | + value = 0.5f - value * 0.5f; |
| 431 | + } |
| 432 | + |
| 433 | + // If target is above 60, value is how much to speed up over 60. Otherwise, it's how much slower. |
| 434 | + // So normalize the target. |
| 435 | + int target = g_Config.iAnalogFpsLimit - 60; |
| 436 | + PSP_CoreParameter().analogFpsLimit = 60 + (int)(target * value); |
| 437 | + |
| 438 | + // If we've reset back to normal, turn it off. |
| 439 | + limitMode = PSP_CoreParameter().analogFpsLimit == 60 ? FPSLimit::NORMAL : FPSLimit::ANALOG; |
| 440 | +} |
0 commit comments