Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pcsx2/ImGui/ImGuiOverlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ SmallString s_gpu_usage_line;
SmallString s_gpu_debug_info_line;
SmallString s_speed_icon;

static constexpr float VIB_DISPLAY_DURATION = 1.0f;

constexpr ImU32 white_color = IM_COL32(255, 255, 255, 255);

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

case InputBindingInfo::Type::Motor:
{
const auto [large_intensity, small_intensity] = InputManager::getPadVibrationIntensity(slot);
const float intensity = (bi.bind_index == 0) ? large_intensity : small_intensity;
if (intensity > 0.0f)
text.append_format(" {}", ICON_PF_CONTROLLER_VIBRATION);
}
break;

case InputBindingInfo::Type::Macro:
case InputBindingInfo::Type::Unknown:
default:
Expand Down Expand Up @@ -1059,6 +1069,13 @@ __ri void ImGuiManager::DrawInputsOverlay(float scale, float margin, float spaci
break;

case InputBindingInfo::Type::Motor:
{
const auto [large_intensity, small_intensity] = InputManager::getPadVibrationIntensity(Pad::NUM_CONTROLLER_PORTS + port);
const float intensity = (bi.bind_index == 0) ? large_intensity : small_intensity;
if (intensity > 0.0f)
text.append_format(" {}", ICON_PF_CONTROLLER_VIBRATION);
}
break;
case InputBindingInfo::Type::Macro:
case InputBindingInfo::Type::Unknown:
default:
Expand Down
17 changes: 17 additions & 0 deletions pcsx2/Input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ namespace InputManager
static bool PreprocessEvent(InputBindingKey key, float value, GenericInputBinding generic_key);
static bool ProcessEvent(InputBindingKey key, float value, bool skip_button_handlers);

static float s_pad_requested_large_intensity[Pad::NUM_CONTROLLER_PORTS + USB::NUM_PORTS] = {};
static float s_pad_requested_small_intensity[Pad::NUM_CONTROLLER_PORTS + USB::NUM_PORTS] = {};

template <typename T>
static void UpdateInputSourceState(SettingsInterface& si, std::unique_lock<std::mutex>& settings_lock, InputSourceType type);
} // namespace InputManager
Expand Down Expand Up @@ -1381,6 +1384,12 @@ void InputManager::SetUSBVibrationIntensity(u32 port, float large_or_single_moto

void InputManager::SetPadVibrationIntensity(u32 pad_index, float large_or_single_motor_intensity, float small_motor_intensity)
{
// Store requested intensity regardless of hardware support, for OSD display.
if (pad_index < (Pad::NUM_CONTROLLER_PORTS + USB::NUM_PORTS))
{
s_pad_requested_large_intensity[pad_index] = large_or_single_motor_intensity;
s_pad_requested_small_intensity[pad_index] = small_motor_intensity;
}
for (PadVibrationBinding& pad : s_pad_vibration_array)
{
if (pad.pad_index != pad_index)
Expand Down Expand Up @@ -1445,6 +1454,14 @@ void InputManager::PauseVibration()
}
}

std::pair<float, float> InputManager::getPadVibrationIntensity(u32 pad_index)
{
if (pad_index < (Pad::NUM_CONTROLLER_PORTS + USB::NUM_PORTS))
return {s_pad_requested_large_intensity[pad_index], s_pad_requested_small_intensity[pad_index]};

return {0.0f, 0.0f};
}

void InputManager::UpdateContinuedVibration()
{
// update vibration intensities, so if the game does a long effect, it continues
Expand Down
4 changes: 4 additions & 0 deletions pcsx2/Input/InputManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ namespace InputManager
void SetUSBVibrationIntensity(u32 port, float large_or_single_motor_intensity, float small_motor_intensity);
void SetPadVibrationIntensity(u32 pad_index, float large_or_single_motor_intensity, float small_motor_intensity);

/// Returns the current vibration intensity for the given pad index.
/// Large motor is index 0, small motor is index 1.
std::pair<float, float> getPadVibrationIntensity(u32 pad_index);

/// Zeros all vibration intensities. Call when pausing.
/// The pad vibration state will internally remain, so that when emulation is unpaused, the effect resumes.
void PauseVibration();
Expand Down
Loading