From 13b3c78c7f82fda08e1bf23ab691ca7ef0e3759d Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 15 Oct 2022 12:41:21 +0200 Subject: [PATCH] Input: fix MMJOY axis identification --- rpcs3/Emu/Io/PadHandler.cpp | 51 ++++++++++++-------- rpcs3/Emu/Io/PadHandler.h | 12 +++-- rpcs3/Input/ds3_pad_handler.cpp | 8 ++-- rpcs3/Input/ds3_pad_handler.h | 8 ++-- rpcs3/Input/ds4_pad_handler.cpp | 8 ++-- rpcs3/Input/ds4_pad_handler.h | 8 ++-- rpcs3/Input/dualsense_pad_handler.cpp | 8 ++-- rpcs3/Input/dualsense_pad_handler.h | 8 ++-- rpcs3/Input/evdev_joystick_handler.cpp | 8 ++-- rpcs3/Input/evdev_joystick_handler.h | 8 ++-- rpcs3/Input/mm_joystick_handler.cpp | 66 ++++++++++++++------------ rpcs3/Input/mm_joystick_handler.h | 13 ++--- rpcs3/Input/xinput_pad_handler.cpp | 8 ++-- rpcs3/Input/xinput_pad_handler.h | 8 ++-- 14 files changed, 118 insertions(+), 104 deletions(-) diff --git a/rpcs3/Emu/Io/PadHandler.cpp b/rpcs3/Emu/Io/PadHandler.cpp index f92b723941..884e27503a 100644 --- a/rpcs3/Emu/Io/PadHandler.cpp +++ b/rpcs3/Emu/Io/PadHandler.cpp @@ -357,8 +357,8 @@ void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_ if (!get_blacklist && std::find(blacklist.begin(), blacklist.end(), keycode) != blacklist.end()) continue; - const bool is_trigger = get_is_left_trigger(keycode) || get_is_right_trigger(keycode); - const bool is_stick = !is_trigger && (get_is_left_stick(keycode) || get_is_right_stick(keycode)); + const bool is_trigger = get_is_left_trigger(device, keycode) || get_is_right_trigger(device, keycode); + const bool is_stick = !is_trigger && (get_is_left_stick(device, keycode) || get_is_right_stick(device, keycode)); const bool is_button = !is_trigger && !is_stick; if ((is_trigger && (value > m_trigger_threshold)) || (is_stick && (value > m_thumb_threshold)) || (is_button && (value > 0))) @@ -382,8 +382,8 @@ void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_ return; } - const auto preview_values = get_preview_values(data); - const auto battery_level = get_battery_level(pad_id); + const pad_preview_values preview_values = get_preview_values(data); + const u32 battery_level = get_battery_level(pad_id); if (callback) { @@ -451,22 +451,22 @@ void PadHandlerBase::TranslateButtonPress(const std::shared_ptr& devi return; } - if (get_is_left_trigger(keyCode)) + if (get_is_left_trigger(device, keyCode)) { pressed = val > (ignore_trigger_threshold ? 0 : device->config->ltriggerthreshold); val = pressed ? NormalizeTriggerInput(val, device->config->ltriggerthreshold) : 0; } - else if (get_is_right_trigger(keyCode)) + else if (get_is_right_trigger(device, keyCode)) { pressed = val > (ignore_trigger_threshold ? 0 : device->config->rtriggerthreshold); val = pressed ? NormalizeTriggerInput(val, device->config->rtriggerthreshold) : 0; } - else if (get_is_left_stick(keyCode)) + else if (get_is_left_stick(device, keyCode)) { pressed = val > (ignore_stick_threshold ? 0 : device->config->lstickdeadzone); val = pressed ? NormalizeStickInput(val, device->config->lstickdeadzone, device->config->lstickmultiplier, ignore_stick_threshold) : 0; } - else if (get_is_right_stick(keyCode)) + else if (get_is_right_stick(device, keyCode)) { pressed = val > (ignore_stick_threshold ? 0 : device->config->rstickdeadzone); val = pressed ? NormalizeStickInput(val, device->config->rstickdeadzone, device->config->rstickmultiplier, ignore_stick_threshold) : 0; @@ -571,12 +571,23 @@ bool PadHandlerBase::bindPadToDevice(std::shared_ptr pad, u8 player_id) return true; } -std::array PadHandlerBase::get_mapped_key_codes(const std::shared_ptr& /*device*/, const cfg_pad* cfg) +std::array PadHandlerBase::get_mapped_key_codes(const std::shared_ptr& device, const cfg_pad* cfg) { std::array mapping{}; - if (!cfg) + if (!device || !cfg) return mapping; + device->trigger_code_left = FindKeyCode(button_list, cfg->l2); + device->trigger_code_right = FindKeyCode(button_list, cfg->r2); + device->axis_code_left[0] = FindKeyCode(button_list, cfg->ls_left); + device->axis_code_left[1] = FindKeyCode(button_list, cfg->ls_right); + device->axis_code_left[2] = FindKeyCode(button_list, cfg->ls_down); + device->axis_code_left[3] = FindKeyCode(button_list, cfg->ls_up); + device->axis_code_right[0] = FindKeyCode(button_list, cfg->rs_left); + device->axis_code_right[1] = FindKeyCode(button_list, cfg->rs_right); + device->axis_code_right[2] = FindKeyCode(button_list, cfg->rs_down); + device->axis_code_right[3] = FindKeyCode(button_list, cfg->rs_up); + mapping[button::up] = FindKeyCode(button_list, cfg->up); mapping[button::down] = FindKeyCode(button_list, cfg->down); mapping[button::left] = FindKeyCode(button_list, cfg->left); @@ -588,19 +599,19 @@ std::array PadHandlerBase::get_mapped mapping[button::start] = FindKeyCode(button_list, cfg->start); mapping[button::select] = FindKeyCode(button_list, cfg->select); mapping[button::l1] = FindKeyCode(button_list, cfg->l1); - mapping[button::l2] = FindKeyCode(button_list, cfg->l2); + mapping[button::l2] = ::narrow(device->trigger_code_left); mapping[button::l3] = FindKeyCode(button_list, cfg->l3); mapping[button::r1] = FindKeyCode(button_list, cfg->r1); - mapping[button::r2] = FindKeyCode(button_list, cfg->r2); + mapping[button::r2] = ::narrow(device->trigger_code_right); mapping[button::r3] = FindKeyCode(button_list, cfg->r3); - mapping[button::ls_left] = FindKeyCode(button_list, cfg->ls_left); - mapping[button::ls_right] = FindKeyCode(button_list, cfg->ls_right); - mapping[button::ls_down] = FindKeyCode(button_list, cfg->ls_down); - mapping[button::ls_up] = FindKeyCode(button_list, cfg->ls_up); - mapping[button::rs_left] = FindKeyCode(button_list, cfg->rs_left); - mapping[button::rs_right] = FindKeyCode(button_list, cfg->rs_right); - mapping[button::rs_down] = FindKeyCode(button_list, cfg->rs_down); - mapping[button::rs_up] = FindKeyCode(button_list, cfg->rs_up); + mapping[button::ls_left] = ::narrow(device->axis_code_left[0]); + mapping[button::ls_right] = ::narrow(device->axis_code_left[1]); + mapping[button::ls_down] = ::narrow(device->axis_code_left[2]); + mapping[button::ls_up] = ::narrow(device->axis_code_left[3]); + mapping[button::rs_left] = ::narrow(device->axis_code_right[0]); + mapping[button::rs_right] = ::narrow(device->axis_code_right[1]); + mapping[button::rs_down] = ::narrow(device->axis_code_right[2]); + mapping[button::rs_up] = ::narrow(device->axis_code_right[3]); mapping[button::ps] = FindKeyCode(button_list, cfg->ps); mapping[button::pressure_intensity_button] = FindKeyCode(button_list, cfg->pressure_intensity_button); diff --git a/rpcs3/Emu/Io/PadHandler.h b/rpcs3/Emu/Io/PadHandler.h index 66fe2a2437..e86e468f71 100644 --- a/rpcs3/Emu/Io/PadHandler.h +++ b/rpcs3/Emu/Io/PadHandler.h @@ -18,6 +18,10 @@ public: virtual ~PadDevice() = default; cfg_pad* config{ nullptr }; u8 player_id{0}; + u64 trigger_code_left = 0; + u64 trigger_code_right = 0; + std::array axis_code_left{}; + std::array axis_code_right{}; }; struct pad_ensemble @@ -206,10 +210,10 @@ public: private: virtual std::shared_ptr get_device(const std::string& /*device*/) { return nullptr; } - virtual bool get_is_left_trigger(u64 /*keyCode*/) { return false; } - virtual bool get_is_right_trigger(u64 /*keyCode*/) { return false; } - virtual bool get_is_left_stick(u64 /*keyCode*/) { return false; } - virtual bool get_is_right_stick(u64 /*keyCode*/) { return false; } + virtual bool get_is_left_trigger(const std::shared_ptr& /*device*/, u64 /*keyCode*/) { return false; } + virtual bool get_is_right_trigger(const std::shared_ptr& /*device*/, u64 /*keyCode*/) { return false; } + virtual bool get_is_left_stick(const std::shared_ptr& /*device*/, u64 /*keyCode*/) { return false; } + virtual bool get_is_right_stick(const std::shared_ptr& /*device*/, u64 /*keyCode*/) { return false; } virtual PadHandlerBase::connection update_connection(const std::shared_ptr& /*device*/) { return connection::disconnected; } virtual void get_extended_info(const pad_ensemble& /*binding*/) {} virtual void apply_pad_data(const pad_ensemble& /*binding*/) {} diff --git a/rpcs3/Input/ds3_pad_handler.cpp b/rpcs3/Input/ds3_pad_handler.cpp index 33d541c9c7..a069a13d85 100644 --- a/rpcs3/Input/ds3_pad_handler.cpp +++ b/rpcs3/Input/ds3_pad_handler.cpp @@ -492,17 +492,17 @@ void ds3_pad_handler::get_extended_info(const pad_ensemble& binding) //pad->m_sensors[3].m_value = polish_value(pad->m_sensors[3].m_value, 1, 1, 512, 512, 0, 1023); } -bool ds3_pad_handler::get_is_left_trigger(u64 keyCode) +bool ds3_pad_handler::get_is_left_trigger(const std::shared_ptr& /*device*/, u64 keyCode) { return keyCode == DS3KeyCodes::L2; } -bool ds3_pad_handler::get_is_right_trigger(u64 keyCode) +bool ds3_pad_handler::get_is_right_trigger(const std::shared_ptr& /*device*/, u64 keyCode) { return keyCode == DS3KeyCodes::R2; } -bool ds3_pad_handler::get_is_left_stick(u64 keyCode) +bool ds3_pad_handler::get_is_left_stick(const std::shared_ptr& /*device*/, u64 keyCode) { switch (keyCode) { @@ -516,7 +516,7 @@ bool ds3_pad_handler::get_is_left_stick(u64 keyCode) } } -bool ds3_pad_handler::get_is_right_stick(u64 keyCode) +bool ds3_pad_handler::get_is_right_stick(const std::shared_ptr& /*device*/, u64 keyCode) { switch (keyCode) { diff --git a/rpcs3/Input/ds3_pad_handler.h b/rpcs3/Input/ds3_pad_handler.h index af61acfbf8..727ff027a2 100644 --- a/rpcs3/Input/ds3_pad_handler.h +++ b/rpcs3/Input/ds3_pad_handler.h @@ -89,10 +89,10 @@ private: int send_output_report(ds3_device* ds3dev) override; void check_add_device(hid_device* hidDevice, std::string_view path, std::wstring_view serial) override; - bool get_is_left_trigger(u64 keyCode) override; - bool get_is_right_trigger(u64 keyCode) override; - bool get_is_left_stick(u64 keyCode) override; - bool get_is_right_stick(u64 keyCode) override; + bool get_is_left_trigger(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_right_trigger(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_left_stick(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_right_stick(const std::shared_ptr& device, u64 keyCode) override; PadHandlerBase::connection update_connection(const std::shared_ptr& device) override; void get_extended_info(const pad_ensemble& binding) override; void apply_pad_data(const pad_ensemble& binding) override; diff --git a/rpcs3/Input/ds4_pad_handler.cpp b/rpcs3/Input/ds4_pad_handler.cpp index 7c73a1b1a2..4edd30b86e 100644 --- a/rpcs3/Input/ds4_pad_handler.cpp +++ b/rpcs3/Input/ds4_pad_handler.cpp @@ -755,17 +755,17 @@ ds4_pad_handler::DataStatus ds4_pad_handler::get_data(DS4Device* device) return DataStatus::NewData; } -bool ds4_pad_handler::get_is_left_trigger(u64 keyCode) +bool ds4_pad_handler::get_is_left_trigger(const std::shared_ptr& /*device*/, u64 keyCode) { return keyCode == DS4KeyCodes::L2; } -bool ds4_pad_handler::get_is_right_trigger(u64 keyCode) +bool ds4_pad_handler::get_is_right_trigger(const std::shared_ptr& /*device*/, u64 keyCode) { return keyCode == DS4KeyCodes::R2; } -bool ds4_pad_handler::get_is_left_stick(u64 keyCode) +bool ds4_pad_handler::get_is_left_stick(const std::shared_ptr& /*device*/, u64 keyCode) { switch (keyCode) { @@ -779,7 +779,7 @@ bool ds4_pad_handler::get_is_left_stick(u64 keyCode) } } -bool ds4_pad_handler::get_is_right_stick(u64 keyCode) +bool ds4_pad_handler::get_is_right_stick(const std::shared_ptr& /*device*/, u64 keyCode) { switch (keyCode) { diff --git a/rpcs3/Input/ds4_pad_handler.h b/rpcs3/Input/ds4_pad_handler.h index d4e21e7f14..7e7d29c074 100644 --- a/rpcs3/Input/ds4_pad_handler.h +++ b/rpcs3/Input/ds4_pad_handler.h @@ -69,10 +69,10 @@ private: int send_output_report(DS4Device* device) override; void check_add_device(hid_device* hidDevice, std::string_view path, std::wstring_view serial) override; - bool get_is_left_trigger(u64 keyCode) override; - bool get_is_right_trigger(u64 keyCode) override; - bool get_is_left_stick(u64 keyCode) override; - bool get_is_right_stick(u64 keyCode) override; + bool get_is_left_trigger(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_right_trigger(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_left_stick(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_right_stick(const std::shared_ptr& device, u64 keyCode) override; PadHandlerBase::connection update_connection(const std::shared_ptr& device) override; void get_extended_info(const pad_ensemble& binding) override; void apply_pad_data(const pad_ensemble& binding) override; diff --git a/rpcs3/Input/dualsense_pad_handler.cpp b/rpcs3/Input/dualsense_pad_handler.cpp index 4c5fae7a16..2526577b14 100644 --- a/rpcs3/Input/dualsense_pad_handler.cpp +++ b/rpcs3/Input/dualsense_pad_handler.cpp @@ -549,17 +549,17 @@ bool dualsense_pad_handler::get_calibration_data(DualSenseDevice* dualsense_devi return true; } -bool dualsense_pad_handler::get_is_left_trigger(u64 keyCode) +bool dualsense_pad_handler::get_is_left_trigger(const std::shared_ptr& /*device*/, u64 keyCode) { return keyCode == DualSenseKeyCodes::L2; } -bool dualsense_pad_handler::get_is_right_trigger(u64 keyCode) +bool dualsense_pad_handler::get_is_right_trigger(const std::shared_ptr& /*device*/, u64 keyCode) { return keyCode == DualSenseKeyCodes::R2; } -bool dualsense_pad_handler::get_is_left_stick(u64 keyCode) +bool dualsense_pad_handler::get_is_left_stick(const std::shared_ptr& /*device*/, u64 keyCode) { switch (keyCode) { @@ -573,7 +573,7 @@ bool dualsense_pad_handler::get_is_left_stick(u64 keyCode) } } -bool dualsense_pad_handler::get_is_right_stick(u64 keyCode) +bool dualsense_pad_handler::get_is_right_stick(const std::shared_ptr& /*device*/, u64 keyCode) { switch (keyCode) { diff --git a/rpcs3/Input/dualsense_pad_handler.h b/rpcs3/Input/dualsense_pad_handler.h index b661a0e916..5802e21e02 100644 --- a/rpcs3/Input/dualsense_pad_handler.h +++ b/rpcs3/Input/dualsense_pad_handler.h @@ -80,10 +80,10 @@ private: void check_add_device(hid_device* hidDevice, std::string_view path, std::wstring_view wide_serial) override; int send_output_report(DualSenseDevice* device) override; - bool get_is_left_trigger(u64 keyCode) override; - bool get_is_right_trigger(u64 keyCode) override; - bool get_is_left_stick(u64 keyCode) override; - bool get_is_right_stick(u64 keyCode) override; + bool get_is_left_trigger(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_right_trigger(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_left_stick(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_right_stick(const std::shared_ptr& device, u64 keyCode) override; PadHandlerBase::connection update_connection(const std::shared_ptr& device) override; std::unordered_map get_button_values(const std::shared_ptr& device) override; pad_preview_values get_preview_values(const std::unordered_map& data) override; diff --git a/rpcs3/Input/evdev_joystick_handler.cpp b/rpcs3/Input/evdev_joystick_handler.cpp index b355439471..5c10db5e9f 100644 --- a/rpcs3/Input/evdev_joystick_handler.cpp +++ b/rpcs3/Input/evdev_joystick_handler.cpp @@ -1349,22 +1349,22 @@ bool evdev_joystick_handler::check_buttons(const std::array& b, return std::any_of(b.begin(), b.end(), [this, code](const EvdevButton& b) { return check_button(b, code); }); }; -bool evdev_joystick_handler::get_is_left_trigger(u64 keyCode) +bool evdev_joystick_handler::get_is_left_trigger(const std::shared_ptr& /*device*/, u64 keyCode) { return check_button(m_dev->trigger_left, static_cast(keyCode)); } -bool evdev_joystick_handler::get_is_right_trigger(u64 keyCode) +bool evdev_joystick_handler::get_is_right_trigger(const std::shared_ptr& /*device*/, u64 keyCode) { return check_button(m_dev->trigger_right, static_cast(keyCode)); } -bool evdev_joystick_handler::get_is_left_stick(u64 keyCode) +bool evdev_joystick_handler::get_is_left_stick(const std::shared_ptr& /*device*/, u64 keyCode) { return check_buttons(m_dev->axis_left, static_cast(keyCode)); } -bool evdev_joystick_handler::get_is_right_stick(u64 keyCode) +bool evdev_joystick_handler::get_is_right_stick(const std::shared_ptr& /*device*/, u64 keyCode) { return check_buttons(m_dev->axis_right, static_cast(keyCode)); } diff --git a/rpcs3/Input/evdev_joystick_handler.h b/rpcs3/Input/evdev_joystick_handler.h index 7d6852c0ac..36acd2df60 100644 --- a/rpcs3/Input/evdev_joystick_handler.h +++ b/rpcs3/Input/evdev_joystick_handler.h @@ -424,10 +424,10 @@ protected: void get_mapping(const pad_ensemble& binding) override; void get_extended_info(const pad_ensemble& binding) override; void apply_pad_data(const pad_ensemble& binding) override; - bool get_is_left_trigger(u64 keyCode) override; - bool get_is_right_trigger(u64 keyCode) override; - bool get_is_left_stick(u64 keyCode) override; - bool get_is_right_stick(u64 keyCode) override; + bool get_is_left_trigger(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_right_trigger(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_left_stick(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_right_stick(const std::shared_ptr& device, u64 keyCode) override; }; #endif diff --git a/rpcs3/Input/mm_joystick_handler.cpp b/rpcs3/Input/mm_joystick_handler.cpp index d1a2344707..634afb9951 100644 --- a/rpcs3/Input/mm_joystick_handler.cpp +++ b/rpcs3/Input/mm_joystick_handler.cpp @@ -134,16 +134,16 @@ std::array mm_joystick_handler::get_m if (!joy_device || !cfg) return mapping; - joy_device->trigger_left = find_key(cfg->l2); - joy_device->trigger_right = find_key(cfg->r2); - joy_device->axis_left[0] = find_key(cfg->ls_left); - joy_device->axis_left[1] = find_key(cfg->ls_right); - joy_device->axis_left[2] = find_key(cfg->ls_down); - joy_device->axis_left[3] = find_key(cfg->ls_up); - joy_device->axis_right[0] = find_key(cfg->rs_left); - joy_device->axis_right[1] = find_key(cfg->rs_right); - joy_device->axis_right[2] = find_key(cfg->rs_down); - joy_device->axis_right[3] = find_key(cfg->rs_up); + joy_device->trigger_code_left = find_key(cfg->l2); + joy_device->trigger_code_right = find_key(cfg->r2); + joy_device->axis_code_left[0] = find_key(cfg->ls_left); + joy_device->axis_code_left[1] = find_key(cfg->ls_right); + joy_device->axis_code_left[2] = find_key(cfg->ls_down); + joy_device->axis_code_left[3] = find_key(cfg->ls_up); + joy_device->axis_code_right[0] = find_key(cfg->rs_left); + joy_device->axis_code_right[1] = find_key(cfg->rs_right); + joy_device->axis_code_right[2] = find_key(cfg->rs_down); + joy_device->axis_code_right[3] = find_key(cfg->rs_up); mapping[button::up] = static_cast(find_key(cfg->up)); mapping[button::down] = static_cast(find_key(cfg->down)); @@ -154,22 +154,22 @@ std::array mm_joystick_handler::get_m mapping[button::circle] = static_cast(find_key(cfg->circle)); mapping[button::triangle] = static_cast(find_key(cfg->triangle)); mapping[button::l1] = static_cast(find_key(cfg->l1)); - mapping[button::l2] = static_cast(joy_device->trigger_left); + mapping[button::l2] = static_cast(joy_device->trigger_code_left); mapping[button::l3] = static_cast(find_key(cfg->l3)); mapping[button::r1] = static_cast(find_key(cfg->r1)); - mapping[button::r2] = static_cast(joy_device->trigger_right); + mapping[button::r2] = static_cast(joy_device->trigger_code_right); mapping[button::r3] = static_cast(find_key(cfg->r3)); mapping[button::start] = static_cast(find_key(cfg->start)); mapping[button::select] = static_cast(find_key(cfg->select)); mapping[button::ps] = static_cast(find_key(cfg->ps)); - mapping[button::ls_left] = static_cast(joy_device->axis_left[0]); - mapping[button::ls_right] = static_cast(joy_device->axis_left[1]); - mapping[button::ls_down] = static_cast(joy_device->axis_left[2]); - mapping[button::ls_up] = static_cast(joy_device->axis_left[3]); - mapping[button::rs_left] = static_cast(joy_device->axis_right[0]); - mapping[button::rs_right] = static_cast(joy_device->axis_right[1]); - mapping[button::rs_down] = static_cast(joy_device->axis_right[2]); - mapping[button::rs_up] = static_cast(joy_device->axis_right[3]); + mapping[button::ls_left] = static_cast(joy_device->axis_code_left[0]); + mapping[button::ls_right] = static_cast(joy_device->axis_code_left[1]); + mapping[button::ls_down] = static_cast(joy_device->axis_code_left[2]); + mapping[button::ls_up] = static_cast(joy_device->axis_code_left[3]); + mapping[button::rs_left] = static_cast(joy_device->axis_code_right[0]); + mapping[button::rs_right] = static_cast(joy_device->axis_code_right[1]); + mapping[button::rs_down] = static_cast(joy_device->axis_code_right[2]); + mapping[button::rs_up] = static_cast(joy_device->axis_code_right[3]); mapping[button::pressure_intensity_button] = static_cast(find_key(cfg->pressure_intensity_button)); @@ -238,7 +238,7 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const u64 keycode = button.first; u16 value = data[keycode]; - if (!get_blacklist && std::find(m_blacklist.begin(), m_blacklist.end(), keycode) != m_blacklist.end()) + if (!get_blacklist && std::find(m_blacklist.cbegin(), m_blacklist.cend(), keycode) != m_blacklist.cend()) continue; if (value > m_thumb_threshold) @@ -260,7 +260,7 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const u64 keycode = button.first; u16 value = data[keycode]; - if (!get_blacklist && std::find(m_blacklist.begin(), m_blacklist.end(), keycode) != m_blacklist.end()) + if (!get_blacklist && std::find(m_blacklist.cbegin(), m_blacklist.cend(), keycode) != m_blacklist.cend()) continue; if (value > 0) @@ -284,7 +284,7 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const if (keycode == NO_BUTTON) continue; - if (!get_blacklist && std::find(m_blacklist.begin(), m_blacklist.end(), keycode) != m_blacklist.end()) + if (!get_blacklist && std::find(m_blacklist.cbegin(), m_blacklist.cend(), keycode) != m_blacklist.cend()) continue; const u16 value = data[keycode]; @@ -490,24 +490,28 @@ std::shared_ptr mm_joystick_handler::get_device(const std::string& de return joy_device; } -bool mm_joystick_handler::get_is_left_trigger(u64 keyCode) +bool mm_joystick_handler::get_is_left_trigger(const std::shared_ptr& device, u64 keyCode) { - return m_dev && m_dev->trigger_left == keyCode; + const MMJOYDevice* dev = static_cast(device.get()); + return dev && dev->trigger_code_left == keyCode; } -bool mm_joystick_handler::get_is_right_trigger(u64 keyCode) +bool mm_joystick_handler::get_is_right_trigger(const std::shared_ptr& device, u64 keyCode) { - return m_dev && m_dev->trigger_right == keyCode; + const MMJOYDevice* dev = static_cast(device.get()); + return dev && dev->trigger_code_right == keyCode; } -bool mm_joystick_handler::get_is_left_stick(u64 keyCode) +bool mm_joystick_handler::get_is_left_stick(const std::shared_ptr& device, u64 keyCode) { - return m_dev && std::find(m_dev->axis_left.begin(), m_dev->axis_left.end(), keyCode) != m_dev->axis_left.end(); + const MMJOYDevice* dev = static_cast(device.get()); + return dev && std::find(dev->axis_code_left.cbegin(), dev->axis_code_left.cend(), keyCode) != dev->axis_code_left.cend(); } -bool mm_joystick_handler::get_is_right_stick(u64 keyCode) +bool mm_joystick_handler::get_is_right_stick(const std::shared_ptr& device, u64 keyCode) { - return m_dev && std::find(m_dev->axis_right.begin(), m_dev->axis_right.end(), keyCode) != m_dev->axis_right.end(); + const MMJOYDevice* dev = static_cast(device.get()); + return dev && std::find(dev->axis_code_right.cbegin(), dev->axis_code_right.cend(), keyCode) != dev->axis_code_right.cend(); } PadHandlerBase::connection mm_joystick_handler::update_connection(const std::shared_ptr& device) diff --git a/rpcs3/Input/mm_joystick_handler.h b/rpcs3/Input/mm_joystick_handler.h index c8a4ceeb71..1a70361c4c 100644 --- a/rpcs3/Input/mm_joystick_handler.h +++ b/rpcs3/Input/mm_joystick_handler.h @@ -105,10 +105,6 @@ class mm_joystick_handler final : public PadHandlerBase JOYINFOEX device_info{}; JOYCAPS device_caps{}; MMRESULT device_status = JOYERR_UNPLUGGED; - u64 trigger_left = 0; - u64 trigger_right = 0; - std::vector axis_left{}; - std::vector axis_right{}; }; public: @@ -128,17 +124,16 @@ private: bool is_init = false; std::vector m_blacklist; - std::shared_ptr m_dev; std::unordered_map m_devices; u64 find_key(const std::string& name) const; std::array get_mapped_key_codes(const std::shared_ptr& device, const cfg_pad* cfg) override; std::shared_ptr get_device(const std::string& device) override; - bool get_is_left_trigger(u64 keyCode) override; - bool get_is_right_trigger(u64 keyCode) override; - bool get_is_left_stick(u64 keyCode) override; - bool get_is_right_stick(u64 keyCode) override; + bool get_is_left_trigger(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_right_trigger(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_left_stick(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_right_stick(const std::shared_ptr& device, u64 keyCode) override; PadHandlerBase::connection update_connection(const std::shared_ptr& device) override; std::unordered_map get_button_values(const std::shared_ptr& device) override; }; diff --git a/rpcs3/Input/xinput_pad_handler.cpp b/rpcs3/Input/xinput_pad_handler.cpp index b6ac0369a1..913b27d7a9 100644 --- a/rpcs3/Input/xinput_pad_handler.cpp +++ b/rpcs3/Input/xinput_pad_handler.cpp @@ -422,17 +422,17 @@ std::shared_ptr xinput_pad_handler::get_device(const std::string& dev return x_device; } -bool xinput_pad_handler::get_is_left_trigger(u64 keyCode) +bool xinput_pad_handler::get_is_left_trigger(const std::shared_ptr& /*device*/, u64 keyCode) { return keyCode == XInputKeyCodes::LT; } -bool xinput_pad_handler::get_is_right_trigger(u64 keyCode) +bool xinput_pad_handler::get_is_right_trigger(const std::shared_ptr& /*device*/, u64 keyCode) { return keyCode == XInputKeyCodes::RT; } -bool xinput_pad_handler::get_is_left_stick(u64 keyCode) +bool xinput_pad_handler::get_is_left_stick(const std::shared_ptr& /*device*/, u64 keyCode) { switch (keyCode) { @@ -446,7 +446,7 @@ bool xinput_pad_handler::get_is_left_stick(u64 keyCode) } } -bool xinput_pad_handler::get_is_right_stick(u64 keyCode) +bool xinput_pad_handler::get_is_right_stick(const std::shared_ptr& /*device*/, u64 keyCode) { switch (keyCode) { diff --git a/rpcs3/Input/xinput_pad_handler.h b/rpcs3/Input/xinput_pad_handler.h index 3dcb5ba56a..5a76a021e2 100644 --- a/rpcs3/Input/xinput_pad_handler.h +++ b/rpcs3/Input/xinput_pad_handler.h @@ -135,10 +135,10 @@ private: PFN_XINPUTGETBATTERYINFORMATION xinputGetBatteryInformation{ nullptr }; std::shared_ptr get_device(const std::string& device) override; - bool get_is_left_trigger(u64 keyCode) override; - bool get_is_right_trigger(u64 keyCode) override; - bool get_is_left_stick(u64 keyCode) override; - bool get_is_right_stick(u64 keyCode) override; + bool get_is_left_trigger(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_right_trigger(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_left_stick(const std::shared_ptr& device, u64 keyCode) override; + bool get_is_right_stick(const std::shared_ptr& device, u64 keyCode) override; PadHandlerBase::connection update_connection(const std::shared_ptr& device) override; void get_extended_info(const pad_ensemble& binding) override; void apply_pad_data(const pad_ensemble& binding) override;