From 02fb9b5cef51ae21a7c3262b1f8531e6d49d42f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Hamil?= Date: Sat, 14 Feb 2026 15:36:15 +0300 Subject: [PATCH] Refactor wiimote handling: Replace hardcoded values with MAX_WIIMOTES constant for better maintainability --- rpcs3/Input/wiimote_handler.cpp | 6 +++--- rpcs3/Input/wiimote_handler.h | 4 +++- rpcs3/rpcs3qt/wiimote_settings_dialog.cpp | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/rpcs3/Input/wiimote_handler.cpp b/rpcs3/Input/wiimote_handler.cpp index ce8c9b01d5..1fe9956bf6 100644 --- a/rpcs3/Input/wiimote_handler.cpp +++ b/rpcs3/Input/wiimote_handler.cpp @@ -181,7 +181,7 @@ bool wiimote_device::update() m_state.acc_z = (buf[5] << 2) | ((buf[2] >> 6) & 1); // Each IR point is 3 bytes in Extended report 0x33. - for (int j = 0; j < 4; j++) + for (usz j = 0; j < MAX_WIIMOTES; j++) { const u8* ir = &buf[6 + j * 3]; m_state.ir[j].x = (ir[0] | ((ir[2] & 0x30) << 4)); @@ -252,8 +252,8 @@ wiimote_handler::wiimote_handler() if (!s_instance) s_instance = this; - // Pre-initialize 4 Wiimote slots (standard for DolphinBar and typical local multiplayer) - for (int i = 0; i < 4; i++) + // Pre-initialize Wiimote slots (standard for DolphinBar and typical local multiplayer) + for (usz i = 0; i < MAX_WIIMOTES; i++) { m_devices.push_back(std::make_unique()); } diff --git a/rpcs3/Input/wiimote_handler.h b/rpcs3/Input/wiimote_handler.h index d7dc5d56dd..c70ca4d40e 100644 --- a/rpcs3/Input/wiimote_handler.h +++ b/rpcs3/Input/wiimote_handler.h @@ -12,6 +12,8 @@ #include #include +static constexpr usz MAX_WIIMOTES = 4; + struct wiimote_ir_point { u16 x = 1023; @@ -58,7 +60,7 @@ struct wiimote_state s16 acc_x = 0; s16 acc_y = 0; s16 acc_z = 0; - std::array ir {}; + std::array ir {}; bool connected = false; }; diff --git a/rpcs3/rpcs3qt/wiimote_settings_dialog.cpp b/rpcs3/rpcs3qt/wiimote_settings_dialog.cpp index 28271ff662..da6af9cd2a 100644 --- a/rpcs3/rpcs3qt/wiimote_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/wiimote_settings_dialog.cpp @@ -183,7 +183,7 @@ void wiimote_settings_dialog::update_state() painter.drawLine(pixmap.width() / 2, 0, pixmap.width() / 2, pixmap.height()); painter.drawLine(0, pixmap.height() / 2, pixmap.width(), pixmap.height() / 2); - static const std::array colors = { Qt::red, Qt::green, Qt::blue, Qt::yellow }; + static const std::array colors = { Qt::red, Qt::green, Qt::blue, Qt::yellow }; for (usz i = 0; i < state.ir.size(); ++i) {