diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index 16bde3117..33a9d1568 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -5,7 +5,7 @@ #include "system.h" Log_SetChannel(AnalogController); -AnalogController::AnalogController(System* system) : m_system(system) +AnalogController::AnalogController(System* system, u32 index) : m_system(system), m_index(index) { m_axis_state.fill(0x80); } @@ -48,7 +48,7 @@ bool AnalogController::DoState(StateWrapper& sw) if (old_analog_mode != m_analog_mode) { - m_system->GetHostInterface()->AddFormattedOSDMessage(2.0f, "Controller switched to %s mode.", + m_system->GetHostInterface()->AddFormattedOSDMessage(2.0f, "Controller %u switched to %s mode.", m_index + 1u, m_analog_mode ? "analog" : "digital"); } } @@ -90,8 +90,8 @@ void AnalogController::SetButtonState(Button button, bool pressed) { if (m_analog_locked) { - m_system->GetHostInterface()->AddFormattedOSDMessage(2.0f, "Controller is locked to %s mode by the game.", - m_analog_mode ? "analog" : "digital"); + m_system->GetHostInterface()->AddFormattedOSDMessage(2.0f, "Controller %u is locked to %s mode by the game.", + m_index + 1u, m_analog_mode ? "analog" : "digital"); } else { @@ -149,8 +149,8 @@ void AnalogController::SetAnalogMode(bool enabled) if (m_analog_mode == enabled) return; - Log_InfoPrintf("Controller switched to %s mode.", enabled ? "analog" : "digital"); - m_system->GetHostInterface()->AddFormattedOSDMessage(2.0f, "Controller switched to %s mode.", + Log_InfoPrintf("Controller %u switched to %s mode.", m_index + 1u, enabled ? "analog" : "digital"); + m_system->GetHostInterface()->AddFormattedOSDMessage(2.0f, "Controller %u switched to %s mode.", m_index + 1u, enabled ? "analog" : "digital"); m_analog_mode = enabled; } @@ -393,9 +393,9 @@ bool AnalogController::Transfer(const u8 data_in, u8* data_out) return ack; } -std::unique_ptr AnalogController::Create(System* system) +std::unique_ptr AnalogController::Create(System* system, u32 index) { - return std::make_unique(system); + return std::make_unique(system, index); } std::optional AnalogController::StaticGetAxisCodeByName(std::string_view axis_name) diff --git a/src/core/analog_controller.h b/src/core/analog_controller.h index 5f6eb1f4a..d759aec20 100644 --- a/src/core/analog_controller.h +++ b/src/core/analog_controller.h @@ -41,10 +41,10 @@ public: static constexpr u8 NUM_MOTORS = 2; - AnalogController(System* system); + AnalogController(System* system, u32 index); ~AnalogController() override; - static std::unique_ptr Create(System* system); + static std::unique_ptr Create(System* system, u32 index); static std::optional StaticGetAxisCodeByName(std::string_view axis_name); static std::optional StaticGetButtonCodeByName(std::string_view button_name); static AxisList StaticGetAxisNames(); @@ -130,6 +130,7 @@ private: void SetMotorState(u8 motor, u8 value); System* m_system; + u32 m_index; bool m_analog_mode = false; bool m_analog_locked = false; diff --git a/src/core/controller.cpp b/src/core/controller.cpp index c1894c114..12e147fcd 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -38,7 +38,7 @@ float Controller::GetVibrationMotorStrength(u32 motor) return 0.0f; } -std::unique_ptr Controller::Create(System* system, ControllerType type) +std::unique_ptr Controller::Create(System* system, ControllerType type, u32 index) { switch (type) { @@ -46,7 +46,7 @@ std::unique_ptr Controller::Create(System* system, ControllerType ty return DigitalController::Create(); case ControllerType::AnalogController: - return AnalogController::Create(system); + return AnalogController::Create(system, index); case ControllerType::NamcoGunCon: return NamcoGunCon::Create(system); diff --git a/src/core/controller.h b/src/core/controller.h index 1833c29f0..908a295e7 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -49,7 +49,7 @@ public: virtual float GetVibrationMotorStrength(u32 motor); /// Creates a new controller of the specified type. - static std::unique_ptr Create(System* system, ControllerType type); + static std::unique_ptr Create(System* system, ControllerType type, u32 index); /// Gets the integer code for an axis in the specified controller type. static std::optional GetAxisCodeByName(ControllerType type, std::string_view axis_name); diff --git a/src/core/pad.cpp b/src/core/pad.cpp index 7d3117f23..84886c7db 100644 --- a/src/core/pad.cpp +++ b/src/core/pad.cpp @@ -50,7 +50,7 @@ bool Pad::DoState(StateWrapper& sw) m_controllers[i].reset(); if (state_controller_type != ControllerType::None) - m_controllers[i] = Controller::Create(m_system, state_controller_type); + m_controllers[i] = Controller::Create(m_system, state_controller_type, i); } if (m_controllers[i]) diff --git a/src/core/system.cpp b/src/core/system.cpp index 0751d95b4..9dfe568ad 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -787,7 +787,7 @@ void System::UpdateControllers() const ControllerType type = settings.controller_types[i]; if (type != ControllerType::None) { - std::unique_ptr controller = Controller::Create(this, type); + std::unique_ptr controller = Controller::Create(this, type, i); if (controller) m_pad->SetController(i, std::move(controller)); }