From 91b238e8b105a263ecc1bd8fbf34b553742bca5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Hamil?= Date: Wed, 11 Feb 2026 15:48:11 +0300 Subject: [PATCH] Address review comments --- rpcs3/Emu/Io/GunCon3.cpp | 2 +- rpcs3/Input/wiimote_handler.cpp | 31 ++++--- rpcs3/rpcs3qt/wiimote_settings_dialog.cpp | 103 +++++++++------------- rpcs3/rpcs3qt/wiimote_settings_dialog.h | 1 + 4 files changed, 64 insertions(+), 73 deletions(-) diff --git a/rpcs3/Emu/Io/GunCon3.cpp b/rpcs3/Emu/Io/GunCon3.cpp index 20f4e54b24..565780e3b5 100644 --- a/rpcs3/Emu/Io/GunCon3.cpp +++ b/rpcs3/Emu/Io/GunCon3.cpp @@ -226,7 +226,7 @@ bool usb_device_guncon3::handle_wiimote(GunCon3_data& gc) } } - if (my_wiimote_index < 0 || static_cast(my_wiimote_index) >= states.size()) + if (my_wiimote_index < 0 || static_cast(my_wiimote_index) >= states.size()) return false; const auto& ws = states[my_wiimote_index]; diff --git a/rpcs3/Input/wiimote_handler.cpp b/rpcs3/Input/wiimote_handler.cpp index 02db99c729..65ac708a7b 100644 --- a/rpcs3/Input/wiimote_handler.cpp +++ b/rpcs3/Input/wiimote_handler.cpp @@ -92,10 +92,10 @@ bool wiimote_device::initialize_ir() // 1. Enable IR logic / Pixel Clock (Requesting Acknowledgement for stability) constexpr std::array ir_on1 = { 0x13, 0x06 }; hid_write(m_handle, ir_on1.data(), ir_on1.size()); - std::this_thread::sleep_for(std::chrono::milliseconds(50)); + thread_ctrl::wait_for(50'000); constexpr std::array ir_on2 = { 0x1a, 0x06 }; hid_write(m_handle, ir_on2.data(), ir_on2.size()); - std::this_thread::sleep_for(std::chrono::milliseconds(50)); + thread_ctrl::wait_for(50'000); // 2. Enable IR Camera (Wii-style sequence) if (!write_reg(0xb00030, {0x01})) return false; @@ -113,7 +113,7 @@ bool wiimote_device::initialize_ir() // 6. Reporting mode: Buttons + Accel + IR (Continuous) constexpr std::array mode = { 0x12, 0x04, 0x33 }; if (hid_write(m_handle, mode.data(), mode.size()) < 0) return false; - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + thread_ctrl::wait_for(100'000); return true; } @@ -351,19 +351,30 @@ void wiimote_handler::thread_proc() }; std::vector candidates; - hid_device_info* devs = hid_instance::enumerate(vid, 0); - for (hid_device_info* cur = devs; cur; cur = cur->next) + hid_device_info* devs = nullptr; { - for (const auto& range : ranges) + std::lock_guard lock(g_hid_mutex); +#if defined(__APPLE__) + Emu.BlockingCallFromMainThread([&]() { - if (cur->product_id >= range.first && cur->product_id <= range.second) +#endif + devs = hid_enumerate(vid, 0); + for (hid_device_info* cur = devs; cur; cur = cur->next) + { + for (const auto& range : ranges) { - candidates.push_back({cur->path, cur->product_id, cur->serial_number ? cur->serial_number : L""}); - break; + if (cur->product_id >= range.first && cur->product_id <= range.second) + { + candidates.push_back({ cur->path, cur->product_id, cur->serial_number ? cur->serial_number : L"" }); + break; + } } } + hid_free_enumeration(devs); +#if defined(__APPLE__) + }, false); +#endif } - hid_instance::free_enumeration(devs); for (const auto& candidate : candidates) { diff --git a/rpcs3/rpcs3qt/wiimote_settings_dialog.cpp b/rpcs3/rpcs3qt/wiimote_settings_dialog.cpp index c2860eb022..d4896a1664 100644 --- a/rpcs3/rpcs3qt/wiimote_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/wiimote_settings_dialog.cpp @@ -10,6 +10,12 @@ wiimote_settings_dialog::wiimote_settings_dialog(QWidget* parent) , ui(new Ui::wiimote_settings_dialog) { ui->setupUi(this); + + m_boxes = { + ui->cb_trigger, ui->cb_a1, ui->cb_a2, ui->cb_c1, + ui->cb_b1, ui->cb_b2, ui->cb_b3, ui->cb_a3, ui->cb_c2 + }; + update_list(); connect(ui->restoreDefaultsButton, &QPushButton::clicked, this, &wiimote_settings_dialog::restore_defaults); @@ -29,8 +35,8 @@ void wiimote_settings_dialog::populate_mappings() auto* wm = wiimote_handler::get_instance(); if (!wm) return; - const QPair buttons[] = { - { tr("None"), wiimote_button::None }, + const std::array, 12> buttons = { + { { tr("None"), wiimote_button::None }, { tr("A"), wiimote_button::A }, { tr("B"), wiimote_button::B }, { tr("Plus (+)"), wiimote_button::Plus }, @@ -41,35 +47,33 @@ void wiimote_settings_dialog::populate_mappings() { tr("D-Pad Up"), wiimote_button::Up }, { tr("D-Pad Down"), wiimote_button::Down }, { tr("D-Pad Left"), wiimote_button::Left }, - { tr("D-Pad Right"), wiimote_button::Right }, - }; - - QComboBox* boxes[] = { - ui->cb_trigger, ui->cb_a1, ui->cb_a2, ui->cb_c1, - ui->cb_b1, ui->cb_b2, ui->cb_b3, ui->cb_a3, ui->cb_c2 + { tr("D-Pad Right"), wiimote_button::Right } } }; wiimote_guncon_mapping current = wm->get_mapping(); - wiimote_button* targets[] = { + const std::array targets = { ¤t.trigger, ¤t.a1, ¤t.a2, ¤t.c1, ¤t.b1, ¤t.b2, ¤t.b3, ¤t.a3, ¤t.c2 }; - for (int i = 0; i < 9; ++i) - { - boxes[i]->setMinimumWidth(150); // Make combo boxes wider for better readability + ensure(m_boxes.size() == targets.size()); - for (const auto& pair : buttons) + for (usz i = 0; i < m_boxes.size(); ++i) + { + m_boxes[i]->setMinimumWidth(150); // Make combo boxes wider for better readability + + for (const auto& [name, btn] : buttons) { - boxes[i]->addItem(pair.first, QVariant::fromValue(static_cast(pair.second))); + m_boxes[i]->addItem(name, QVariant::fromValue(static_cast(btn))); } // Set current selection - const int index = boxes[i]->findData(QVariant::fromValue(static_cast(*targets[i]))); - if (index >= 0) boxes[i]->setCurrentIndex(index); + const int index = m_boxes[i]->findData(QVariant::fromValue(static_cast(*targets[i]))); + if (index >= 0) m_boxes[i]->setCurrentIndex(index); // Connect change signal - connect(boxes[i], QOverload::of(&QComboBox::currentIndexChanged), this, [this](int) { + connect(m_boxes[i], &QComboBox::currentIndexChanged, this, [this](int) + { apply_mappings(); }); } @@ -85,40 +89,22 @@ void wiimote_settings_dialog::restore_defaults() wm->set_mapping(default_map); // Update UI - ui->cb_trigger->blockSignals(true); - ui->cb_a1->blockSignals(true); - ui->cb_a2->blockSignals(true); - ui->cb_c1->blockSignals(true); - ui->cb_b1->blockSignals(true); - ui->cb_b2->blockSignals(true); - ui->cb_b3->blockSignals(true); - ui->cb_a3->blockSignals(true); - ui->cb_c2->blockSignals(true); + for (auto* box : m_boxes) box->blockSignals(true); - auto set_box = [](QComboBox* box, wiimote_button btn) { - int index = box->findData(QVariant::fromValue(static_cast(btn))); - if (index >= 0) box->setCurrentIndex(index); + const std::array targets = { + default_map.trigger, default_map.a1, default_map.a2, default_map.c1, + default_map.b1, default_map.b2, default_map.b3, default_map.a3, default_map.c2 }; - set_box(ui->cb_trigger, default_map.trigger); - set_box(ui->cb_a1, default_map.a1); - set_box(ui->cb_a2, default_map.a2); - set_box(ui->cb_c1, default_map.c1); - set_box(ui->cb_b1, default_map.b1); - set_box(ui->cb_b2, default_map.b2); - set_box(ui->cb_b3, default_map.b3); - set_box(ui->cb_a3, default_map.a3); - set_box(ui->cb_c2, default_map.c2); + ensure(m_boxes.size() == targets.size()); - ui->cb_trigger->blockSignals(false); - ui->cb_a1->blockSignals(false); - ui->cb_a2->blockSignals(false); - ui->cb_c1->blockSignals(false); - ui->cb_b1->blockSignals(false); - ui->cb_b2->blockSignals(false); - ui->cb_b3->blockSignals(false); - ui->cb_a3->blockSignals(false); - ui->cb_c2->blockSignals(false); + for (usz i = 0; i < m_boxes.size(); ++i) + { + const int index = m_boxes[i]->findData(QVariant::fromValue(static_cast(targets[i]))); + if (index >= 0) m_boxes[i]->setCurrentIndex(index); + } + + for (auto* box : m_boxes) box->blockSignals(false); } void wiimote_settings_dialog::apply_mappings() @@ -127,24 +113,17 @@ void wiimote_settings_dialog::apply_mappings() if (!wm) return; wiimote_guncon_mapping map; - auto get_btn = [](QComboBox* box) { - return static_cast(box->currentData().toUInt()); + const std::array targets = { + &map.trigger, &map.a1, &map.a2, &map.c1, + &map.b1, &map.b2, &map.b3, &map.a3, &map.c2 }; - map.trigger = get_btn(ui->cb_trigger); - map.a1 = get_btn(ui->cb_a1); - map.a2 = get_btn(ui->cb_a2); - map.c1 = get_btn(ui->cb_c1); - map.b1 = get_btn(ui->cb_b1); - map.b2 = get_btn(ui->cb_b2); - map.b3 = get_btn(ui->cb_b3); - map.a3 = get_btn(ui->cb_a3); - map.c2 = get_btn(ui->cb_c2); + ensure(m_boxes.size() == targets.size()); - // Preserve alts or add UI for them later. For now, keep defaults or sync with main if matched - // To be safe, we can just leave alts as default Up/Down for now since they are D-Pad shortcuts - // Or we can reset them if the user maps Up/Down to something else to avoid conflict? - // For simplicity, let's keep defaults in the struct constructor. + for (usz i = 0; i < m_boxes.size(); ++i) + { + *targets[i] = static_cast(m_boxes[i]->currentData().toUInt()); + } wm->set_mapping(map); } diff --git a/rpcs3/rpcs3qt/wiimote_settings_dialog.h b/rpcs3/rpcs3qt/wiimote_settings_dialog.h index 3c02af7317..1cd7c0df82 100644 --- a/rpcs3/rpcs3qt/wiimote_settings_dialog.h +++ b/rpcs3/rpcs3qt/wiimote_settings_dialog.h @@ -12,6 +12,7 @@ public: private: std::unique_ptr ui; + std::vector m_boxes; void update_list(); void update_state(); void populate_mappings();