Refactor wiimote handling: Replace hardcoded values with MAX_WIIMOTES constant for better maintainability

This commit is contained in:
Barış Hamil 2026-02-14 15:36:15 +03:00
parent b7eeaac846
commit 02fb9b5cef
3 changed files with 7 additions and 5 deletions

View file

@ -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<wiimote_device>());
}

View file

@ -12,6 +12,8 @@
#include <chrono>
#include <array>
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<wiimote_ir_point, 4> ir {};
std::array<wiimote_ir_point, MAX_WIIMOTES> ir {};
bool connected = false;
};

View file

@ -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<QColor, 4> colors = { Qt::red, Qt::green, Qt::blue, Qt::yellow };
static const std::array<QColor, MAX_WIIMOTES> colors = { Qt::red, Qt::green, Qt::blue, Qt::yellow };
for (usz i = 0; i < state.ir.size(); ++i)
{