From d23ac6f598bbef9163eed479e7ec8b2bbc734964 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 6 Jul 2024 18:41:41 +0200 Subject: [PATCH] input: move player_id to pad struct --- rpcs3/Emu/Io/Null/NullPadHandler.h | 2 +- rpcs3/Emu/Io/PadHandler.cpp | 14 +++++++------- rpcs3/Emu/Io/PadHandler.h | 2 +- rpcs3/Emu/Io/pad_types.h | 6 ++++-- rpcs3/Input/evdev_joystick_handler.cpp | 12 ++++++------ rpcs3/Input/evdev_joystick_handler.h | 2 +- rpcs3/Input/gui_pad_thread.cpp | 4 ++-- rpcs3/Input/keyboard_pad_handler.cpp | 10 +++++----- rpcs3/Input/keyboard_pad_handler.h | 2 +- rpcs3/Input/pad_thread.cpp | 6 +++--- 10 files changed, 31 insertions(+), 29 deletions(-) diff --git a/rpcs3/Emu/Io/Null/NullPadHandler.h b/rpcs3/Emu/Io/Null/NullPadHandler.h index 5c9f79ceac..bc5dd1afe4 100644 --- a/rpcs3/Emu/Io/Null/NullPadHandler.h +++ b/rpcs3/Emu/Io/Null/NullPadHandler.h @@ -59,7 +59,7 @@ public: return nulllist; } - bool bindPadToDevice(std::shared_ptr /*pad*/, u8 /*player_id*/) override + bool bindPadToDevice(std::shared_ptr /*pad*/) override { return true; } diff --git a/rpcs3/Emu/Io/PadHandler.cpp b/rpcs3/Emu/Io/PadHandler.cpp index 68a88f22b2..c6b380f556 100644 --- a/rpcs3/Emu/Io/PadHandler.cpp +++ b/rpcs3/Emu/Io/PadHandler.cpp @@ -322,7 +322,7 @@ void PadHandlerBase::get_motion_sensors(const std::string& pad_id, const motion_ } // Get the current motion values - std::shared_ptr pad = std::make_shared(m_type, 0, 0, 0); + std::shared_ptr pad = std::make_shared(m_type, 0, 0, 0, 0); pad->m_sensors.resize(preview_values.size(), AnalogSensor(0, 0, 0, 0, 0)); pad_ensemble binding{pad, device, nullptr}; get_extended_info(binding); @@ -382,14 +382,14 @@ void PadHandlerBase::TranslateButtonPress(const std::shared_ptr& devi } } -bool PadHandlerBase::bindPadToDevice(std::shared_ptr pad, u8 player_id) +bool PadHandlerBase::bindPadToDevice(std::shared_ptr pad) { - if (!pad || player_id >= g_cfg_input.player.size()) + if (!pad || pad->m_player_id >= g_cfg_input.player.size()) { return false; } - const cfg_player* player_config = g_cfg_input.player[player_id]; + const cfg_player* player_config = g_cfg_input.player[pad->m_player_id]; if (!player_config) { return false; @@ -402,9 +402,9 @@ bool PadHandlerBase::bindPadToDevice(std::shared_ptr pad, u8 player_id) return false; } - m_pad_configs[player_id].from_string(player_config->config.to_string()); - pad_device->config = &m_pad_configs[player_id]; - pad_device->player_id = player_id; + m_pad_configs[pad->m_player_id].from_string(player_config->config.to_string()); + pad_device->config = &m_pad_configs[pad->m_player_id]; + pad_device->player_id = pad->m_player_id; cfg_pad* config = pad_device->config; if (config == nullptr) { diff --git a/rpcs3/Emu/Io/PadHandler.h b/rpcs3/Emu/Io/PadHandler.h index 9ff4c36127..3081657c86 100644 --- a/rpcs3/Emu/Io/PadHandler.h +++ b/rpcs3/Emu/Io/PadHandler.h @@ -278,7 +278,7 @@ public: // Callback called during pad_thread::ThreadFunc virtual void process(); // Binds a Pad to a device - virtual bool bindPadToDevice(std::shared_ptr pad, u8 player_id); + virtual bool bindPadToDevice(std::shared_ptr pad); virtual void init_config(cfg_pad* cfg) = 0; virtual connection get_next_button_press(const std::string& padId, const pad_callback& callback, const pad_fail_callback& fail_callback, bool get_blacklist, const std::vector& buttons = {}); virtual void get_motion_sensors(const std::string& pad_id, const motion_callback& callback, const motion_fail_callback& fail_callback, motion_preview_values preview_values, const std::array& sensors); diff --git a/rpcs3/Emu/Io/pad_types.h b/rpcs3/Emu/Io/pad_types.h index 162f47b52a..79299dce81 100644 --- a/rpcs3/Emu/Io/pad_types.h +++ b/rpcs3/Emu/Io/pad_types.h @@ -450,6 +450,7 @@ struct VibrateMotor struct Pad { const pad_handler m_pad_handler; + const u32 m_player_id; bool m_buffer_cleared{true}; u32 m_port_status{0}; @@ -466,7 +467,7 @@ struct Pad bool m_pressure_intensity_toggled{}; // Whether the sensitivity is toggled on or off. u8 m_pressure_intensity{127}; // 0-255 bool m_adjust_pressure_last{}; // only used in keyboard_pad_handler - bool get_pressure_intensity_button_active(bool is_toggle_mode); + bool get_pressure_intensity_button_active(bool is_toggle_mode, u32 player_id); // Cable State: 0 - 1 plugged in ? u8 m_cable_state{0}; @@ -515,8 +516,9 @@ struct Pad bool is_fake_pad = false; - explicit Pad(pad_handler handler, u32 port_status, u32 device_capability, u32 device_type) + explicit Pad(pad_handler handler, u32 player_id, u32 port_status, u32 device_capability, u32 device_type) : m_pad_handler(handler) + , m_player_id(player_id) , m_port_status(port_status) , m_device_capability(device_capability) , m_device_type(device_type) diff --git a/rpcs3/Input/evdev_joystick_handler.cpp b/rpcs3/Input/evdev_joystick_handler.cpp index fdc1c95dd1..cfb5a74713 100644 --- a/rpcs3/Input/evdev_joystick_handler.cpp +++ b/rpcs3/Input/evdev_joystick_handler.cpp @@ -1242,12 +1242,12 @@ void evdev_joystick_handler::apply_pad_data(const pad_ensemble& binding) SetRumble(evdev_device, force_large, force_small); } -bool evdev_joystick_handler::bindPadToDevice(std::shared_ptr pad, u8 player_id) +bool evdev_joystick_handler::bindPadToDevice(std::shared_ptr pad) { - if (!pad || player_id >= g_cfg_input.player.size()) + if (!pad || pad->m_player_id >= g_cfg_input.player.size()) return false; - const cfg_player* player_config = g_cfg_input.player[player_id]; + const cfg_player* player_config = g_cfg_input.player[pad->m_player_id]; if (!pad) return false; @@ -1255,9 +1255,9 @@ bool evdev_joystick_handler::bindPadToDevice(std::shared_ptr pad, u8 player m_dev = std::make_shared(); - m_pad_configs[player_id].from_string(player_config->config.to_string()); - m_dev->config = &m_pad_configs[player_id]; - m_dev->player_id = player_id; + m_pad_configs[pad->m_player_id].from_string(player_config->config.to_string()); + m_dev->config = &m_pad_configs[pad->m_player_id]; + m_dev->player_id = pad->m_player_id; cfg_pad* cfg = m_dev->config; if (!cfg) return false; diff --git a/rpcs3/Input/evdev_joystick_handler.h b/rpcs3/Input/evdev_joystick_handler.h index 2436b2e64d..7dfeefb04a 100644 --- a/rpcs3/Input/evdev_joystick_handler.h +++ b/rpcs3/Input/evdev_joystick_handler.h @@ -406,7 +406,7 @@ public: void init_config(cfg_pad* cfg) override; bool Init() override; std::vector list_devices() override; - bool bindPadToDevice(std::shared_ptr pad, u8 player_id) override; + bool bindPadToDevice(std::shared_ptr pad) override; connection get_next_button_press(const std::string& padId, const pad_callback& callback, const pad_fail_callback& fail_callback, bool get_blacklist = false, const std::vector& buttons = {}) override; void get_motion_sensors(const std::string& padId, const motion_callback& callback, const motion_fail_callback& fail_callback, motion_preview_values preview_values, const std::array& sensors) override; std::unordered_map get_motion_axis_list() const override; diff --git a/rpcs3/Input/gui_pad_thread.cpp b/rpcs3/Input/gui_pad_thread.cpp index e2752b1e5b..2423d9bcc1 100644 --- a/rpcs3/Input/gui_pad_thread.cpp +++ b/rpcs3/Input/gui_pad_thread.cpp @@ -131,9 +131,9 @@ bool gui_pad_thread::init() cur_pad_handler->Init(); m_handler = cur_pad_handler; - m_pad = std::make_shared(handler_type, CELL_PAD_STATUS_DISCONNECTED, CELL_PAD_CAPABILITY_PS3_CONFORMITY | CELL_PAD_CAPABILITY_PRESS_MODE | CELL_PAD_CAPABILITY_ACTUATOR, CELL_PAD_DEV_TYPE_STANDARD); + m_pad = std::make_shared(handler_type, i, CELL_PAD_STATUS_DISCONNECTED, CELL_PAD_CAPABILITY_PS3_CONFORMITY | CELL_PAD_CAPABILITY_PRESS_MODE | CELL_PAD_CAPABILITY_ACTUATOR, CELL_PAD_DEV_TYPE_STANDARD); - if (!cur_pad_handler->bindPadToDevice(m_pad, i)) + if (!cur_pad_handler->bindPadToDevice(m_pad)) { gui_log.error("gui_pad_thread: Failed to bind device '%s' to handler %s.", cfg->device.to_string(), handler_type); } diff --git a/rpcs3/Input/keyboard_pad_handler.cpp b/rpcs3/Input/keyboard_pad_handler.cpp index fb25334850..c3a14c6a5f 100644 --- a/rpcs3/Input/keyboard_pad_handler.cpp +++ b/rpcs3/Input/keyboard_pad_handler.cpp @@ -893,17 +893,17 @@ std::string keyboard_pad_handler::native_scan_code_to_string(int native_scan_cod } } -bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr pad, u8 player_id) +bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr pad) { - if (!pad || player_id >= g_cfg_input.player.size()) + if (!pad || pad->m_player_id >= g_cfg_input.player.size()) return false; - const cfg_player* player_config = g_cfg_input.player[player_id]; + const cfg_player* player_config = g_cfg_input.player[pad->m_player_id]; if (!player_config || player_config->device.to_string() != pad::keyboard_device_name) return false; - m_pad_configs[player_id].from_string(player_config->config.to_string()); - const cfg_pad* cfg = &m_pad_configs[player_id]; + m_pad_configs[pad->m_player_id].from_string(player_config->config.to_string()); + const cfg_pad* cfg = &m_pad_configs[pad->m_player_id]; if (cfg == nullptr) return false; diff --git a/rpcs3/Input/keyboard_pad_handler.h b/rpcs3/Input/keyboard_pad_handler.h index 070a024502..41f7eeabfb 100644 --- a/rpcs3/Input/keyboard_pad_handler.h +++ b/rpcs3/Input/keyboard_pad_handler.h @@ -85,7 +85,7 @@ public: void init_config(cfg_pad* cfg) override; std::vector list_devices() override; connection get_next_button_press(const std::string& /*padId*/, const pad_callback& /*callback*/, const pad_fail_callback& /*fail_callback*/, bool /*get_blacklist*/ = false, const std::vector& /*buttons*/ = {}) override { return connection::connected; } - bool bindPadToDevice(std::shared_ptr pad, u8 player_id) override; + bool bindPadToDevice(std::shared_ptr pad) override; void process() override; static std::string GetMouseName(const QMouseEvent* event); diff --git a/rpcs3/Input/pad_thread.cpp b/rpcs3/Input/pad_thread.cpp index 92c1a2bc29..c1a225070b 100644 --- a/rpcs3/Input/pad_thread.cpp +++ b/rpcs3/Input/pad_thread.cpp @@ -171,7 +171,7 @@ void pad_thread::Init() } cur_pad_handler->Init(); - m_pads[i] = std::make_shared(handler_type, CELL_PAD_STATUS_DISCONNECTED, pad_settings[i].device_capability, pad_settings[i].device_type); + m_pads[i] = std::make_shared(handler_type, i, CELL_PAD_STATUS_DISCONNECTED, pad_settings[i].device_capability, pad_settings[i].device_type); if (pad_settings[i].is_ldd_pad) { @@ -179,11 +179,11 @@ void pad_thread::Init() } else { - if (!cur_pad_handler->bindPadToDevice(m_pads[i], i)) + if (!cur_pad_handler->bindPadToDevice(m_pads[i])) { // Failed to bind the device to cur_pad_handler so binds to NullPadHandler input_log.error("Failed to bind device '%s' to handler %s. Falling back to NullPadHandler.", cfg->device.to_string(), handler_type); - nullpad->bindPadToDevice(m_pads[i], i); + nullpad->bindPadToDevice(m_pads[i]); } input_log.notice("Pad %d: device='%s', handler=%s, VID=0x%x, PID=0x%x, class_type=0x%x, class_profile=0x%x",