diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 10 | ||||
| -rw-r--r-- | src/input_common/drivers/sdl_driver.cpp | 33 |
2 files changed, 28 insertions, 15 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 83ced5635..916368c68 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -251,7 +251,8 @@ void EmulatedController::RestoreConfig() { | |||
| 251 | ReloadFromSettings(); | 251 | ReloadFromSettings(); |
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices(DeviceIndex device_index) const { | 254 | std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices( |
| 255 | DeviceIndex device_index) const { | ||
| 255 | std::vector<Common::ParamPackage> devices; | 256 | std::vector<Common::ParamPackage> devices; |
| 256 | for (const auto& param : button_params) { | 257 | for (const auto& param : button_params) { |
| 257 | if (!param.Has("engine")) { | 258 | if (!param.Has("engine")) { |
| @@ -658,6 +659,10 @@ bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue v | |||
| 658 | const auto& player = Settings::values.players.GetValue()[player_index]; | 659 | const auto& player = Settings::values.players.GetValue()[player_index]; |
| 659 | const f32 strength = static_cast<f32>(player.vibration_strength) / 100.0f; | 660 | const f32 strength = static_cast<f32>(player.vibration_strength) / 100.0f; |
| 660 | 661 | ||
| 662 | if (!player.vibration_enabled) { | ||
| 663 | return false; | ||
| 664 | } | ||
| 665 | |||
| 661 | // Exponential amplification is too strong at low amplitudes. Switch to a linear | 666 | // Exponential amplification is too strong at low amplitudes. Switch to a linear |
| 662 | // amplification if strength is set below 0.7f | 667 | // amplification if strength is set below 0.7f |
| 663 | const Input::VibrationAmplificationType type = | 668 | const Input::VibrationAmplificationType type = |
| @@ -860,6 +865,9 @@ AnalogSticks EmulatedController::GetSticks() const { | |||
| 860 | } | 865 | } |
| 861 | // Some drivers like stick from buttons need constant refreshing | 866 | // Some drivers like stick from buttons need constant refreshing |
| 862 | for (auto& device : stick_devices) { | 867 | for (auto& device : stick_devices) { |
| 868 | if (!device) { | ||
| 869 | continue; | ||
| 870 | } | ||
| 863 | device->SoftUpdate(); | 871 | device->SoftUpdate(); |
| 864 | } | 872 | } |
| 865 | return controller.analog_stick_state; | 873 | return controller.analog_stick_state; |
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index d56351815..53e282ef3 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp | |||
| @@ -94,7 +94,6 @@ public: | |||
| 94 | 94 | ||
| 95 | bool RumblePlay(const Input::VibrationStatus vibration) { | 95 | bool RumblePlay(const Input::VibrationStatus vibration) { |
| 96 | constexpr u32 rumble_max_duration_ms = 1000; | 96 | constexpr u32 rumble_max_duration_ms = 1000; |
| 97 | |||
| 98 | if (sdl_controller) { | 97 | if (sdl_controller) { |
| 99 | return SDL_GameControllerRumble( | 98 | return SDL_GameControllerRumble( |
| 100 | sdl_controller.get(), static_cast<u16>(vibration.low_amplitude), | 99 | sdl_controller.get(), static_cast<u16>(vibration.low_amplitude), |
| @@ -520,25 +519,31 @@ Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier, | |||
| 520 | const Input::VibrationStatus vibration) { | 519 | const Input::VibrationStatus vibration) { |
| 521 | const auto joystick = | 520 | const auto joystick = |
| 522 | GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port)); | 521 | GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port)); |
| 523 | const auto process_amplitude = [](f32 amplitude) { | 522 | const auto process_amplitude_exp = [](f32 amplitude, f32 factor) { |
| 524 | return (amplitude + std::pow(amplitude, 0.3f)) * 0.5f * 0xFFFF; | 523 | return (amplitude + std::pow(amplitude, factor)) * 0.5f * 0xFFFF; |
| 525 | }; | 524 | }; |
| 526 | const Input::VibrationStatus exponential_vibration{ | 525 | |
| 527 | .low_amplitude = process_amplitude(vibration.low_amplitude), | 526 | // Default exponential curve for rumble |
| 527 | f32 factor = 0.35f; | ||
| 528 | |||
| 529 | // If vibration is set as a linear output use a flatter value | ||
| 530 | if (vibration.type == Input::VibrationAmplificationType::Linear) { | ||
| 531 | factor = 0.5f; | ||
| 532 | } | ||
| 533 | |||
| 534 | // Amplitude for HD rumble needs no modification | ||
| 535 | if (joystick->HasHDRumble()) { | ||
| 536 | factor = 1.0f; | ||
| 537 | } | ||
| 538 | |||
| 539 | const Input::VibrationStatus new_vibration{ | ||
| 540 | .low_amplitude = process_amplitude_exp(vibration.low_amplitude, factor), | ||
| 528 | .low_frequency = vibration.low_frequency, | 541 | .low_frequency = vibration.low_frequency, |
| 529 | .high_amplitude = process_amplitude(vibration.high_amplitude), | 542 | .high_amplitude = process_amplitude_exp(vibration.high_amplitude, factor), |
| 530 | .high_frequency = vibration.high_frequency, | 543 | .high_frequency = vibration.high_frequency, |
| 531 | .type = Input::VibrationAmplificationType::Exponential, | 544 | .type = Input::VibrationAmplificationType::Exponential, |
| 532 | }; | 545 | }; |
| 533 | 546 | ||
| 534 | Input::VibrationStatus new_vibration{}; | ||
| 535 | |||
| 536 | if (vibration.type == Input::VibrationAmplificationType::Linear || joystick->HasHDRumble()) { | ||
| 537 | new_vibration = vibration; | ||
| 538 | } else { | ||
| 539 | new_vibration = exponential_vibration; | ||
| 540 | } | ||
| 541 | |||
| 542 | if (!joystick->RumblePlay(new_vibration)) { | 547 | if (!joystick->RumblePlay(new_vibration)) { |
| 543 | return Input::VibrationError::Unknown; | 548 | return Input::VibrationError::Unknown; |
| 544 | } | 549 | } |