Skip to content

Commit 19a5a7e

Browse files
committed
ImGui: Show vibration feedback icons inline with inputs overlay
1 parent 5cb7abf commit 19a5a7e

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

pcsx2/ImGui/ImGuiOverlays.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ SmallString s_gpu_usage_line;
7272
SmallString s_gpu_debug_info_line;
7373
SmallString s_speed_icon;
7474

75+
static constexpr float VIB_DISPLAY_DURATION = 1.0f;
76+
7577
constexpr ImU32 white_color = IM_COL32(255, 255, 255, 255);
7678

7779
// OSD positioning funcs
@@ -1006,6 +1008,14 @@ __ri void ImGuiManager::DrawInputsOverlay(float scale, float margin, float spaci
10061008
break;
10071009

10081010
case InputBindingInfo::Type::Motor:
1011+
{
1012+
const auto [large_intensity, small_intensity] = InputManager::getPadVibrationIntensity(slot);
1013+
const float intensity = (bi.bind_index == 0) ? large_intensity : small_intensity;
1014+
if (intensity > 0.0f)
1015+
text.append_format(" {}", ICON_PF_CONTROLLER_VIBRATION);
1016+
}
1017+
break;
1018+
10091019
case InputBindingInfo::Type::Macro:
10101020
case InputBindingInfo::Type::Unknown:
10111021
default:
@@ -1059,6 +1069,13 @@ __ri void ImGuiManager::DrawInputsOverlay(float scale, float margin, float spaci
10591069
break;
10601070

10611071
case InputBindingInfo::Type::Motor:
1072+
{
1073+
const auto [large_intensity, small_intensity] = InputManager::getPadVibrationIntensity(Pad::NUM_CONTROLLER_PORTS + port);
1074+
const float intensity = (bi.bind_index == 0) ? large_intensity : small_intensity;
1075+
if (intensity > 0.0f)
1076+
text.append_format(" {}", ICON_PF_CONTROLLER_VIBRATION);
1077+
}
1078+
break;
10621079
case InputBindingInfo::Type::Macro:
10631080
case InputBindingInfo::Type::Unknown:
10641081
default:

pcsx2/Input/InputManager.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ namespace InputManager
117117
static bool PreprocessEvent(InputBindingKey key, float value, GenericInputBinding generic_key);
118118
static bool ProcessEvent(InputBindingKey key, float value, bool skip_button_handlers);
119119

120+
static float s_pad_requested_large_intensity[Pad::NUM_CONTROLLER_PORTS + USB::NUM_PORTS] = {};
121+
static float s_pad_requested_small_intensity[Pad::NUM_CONTROLLER_PORTS + USB::NUM_PORTS] = {};
122+
120123
template <typename T>
121124
static void UpdateInputSourceState(SettingsInterface& si, std::unique_lock<std::mutex>& settings_lock, InputSourceType type);
122125
} // namespace InputManager
@@ -1381,6 +1384,12 @@ void InputManager::SetUSBVibrationIntensity(u32 port, float large_or_single_moto
13811384

13821385
void InputManager::SetPadVibrationIntensity(u32 pad_index, float large_or_single_motor_intensity, float small_motor_intensity)
13831386
{
1387+
// Store requested intensity regardless of hardware support, for OSD display.
1388+
if (pad_index < (Pad::NUM_CONTROLLER_PORTS + USB::NUM_PORTS))
1389+
{
1390+
s_pad_requested_large_intensity[pad_index] = large_or_single_motor_intensity;
1391+
s_pad_requested_small_intensity[pad_index] = small_motor_intensity;
1392+
}
13841393
for (PadVibrationBinding& pad : s_pad_vibration_array)
13851394
{
13861395
if (pad.pad_index != pad_index)
@@ -1445,6 +1454,14 @@ void InputManager::PauseVibration()
14451454
}
14461455
}
14471456

1457+
std::pair<float, float> InputManager::getPadVibrationIntensity(u32 pad_index)
1458+
{
1459+
if (pad_index < (Pad::NUM_CONTROLLER_PORTS + USB::NUM_PORTS))
1460+
return {s_pad_requested_large_intensity[pad_index], s_pad_requested_small_intensity[pad_index]};
1461+
1462+
return {0.0f, 0.0f};
1463+
}
1464+
14481465
void InputManager::UpdateContinuedVibration()
14491466
{
14501467
// update vibration intensities, so if the game does a long effect, it continues

pcsx2/Input/InputManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ namespace InputManager
287287
void SetUSBVibrationIntensity(u32 port, float large_or_single_motor_intensity, float small_motor_intensity);
288288
void SetPadVibrationIntensity(u32 pad_index, float large_or_single_motor_intensity, float small_motor_intensity);
289289

290+
/// Returns the current vibration intensity for the given pad index.
291+
/// Large motor is index 0, small motor is index 1.
292+
std::pair<float, float> getPadVibrationIntensity(u32 pad_index);
293+
290294
/// Zeros all vibration intensities. Call when pausing.
291295
/// The pad vibration state will internally remain, so that when emulation is unpaused, the effect resumes.
292296
void PauseVibration();

0 commit comments

Comments
 (0)