input: move player_id to pad struct

This commit is contained in:
Megamouse 2024-07-06 18:41:41 +02:00
parent 6948c0a30a
commit d23ac6f598
10 changed files with 31 additions and 29 deletions

View file

@ -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> pad, u8 player_id)
bool evdev_joystick_handler::bindPadToDevice(std::shared_ptr<Pad> 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> pad, u8 player
m_dev = std::make_shared<EvdevDevice>();
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;

View file

@ -406,7 +406,7 @@ public:
void init_config(cfg_pad* cfg) override;
bool Init() override;
std::vector<pad_list_entry> list_devices() override;
bool bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_id) override;
bool bindPadToDevice(std::shared_ptr<Pad> 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<std::string>& 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<AnalogSensor, 4>& sensors) override;
std::unordered_map<u32, std::string> get_motion_axis_list() const override;

View file

@ -131,9 +131,9 @@ bool gui_pad_thread::init()
cur_pad_handler->Init();
m_handler = cur_pad_handler;
m_pad = std::make_shared<Pad>(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<Pad>(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);
}

View file

@ -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> pad, u8 player_id)
bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr<Pad> 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;

View file

@ -85,7 +85,7 @@ public:
void init_config(cfg_pad* cfg) override;
std::vector<pad_list_entry> 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<std::string>& /*buttons*/ = {}) override { return connection::connected; }
bool bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_id) override;
bool bindPadToDevice(std::shared_ptr<Pad> pad) override;
void process() override;
static std::string GetMouseName(const QMouseEvent* event);

View file

@ -171,7 +171,7 @@ void pad_thread::Init()
}
cur_pad_handler->Init();
m_pads[i] = std::make_shared<Pad>(handler_type, CELL_PAD_STATUS_DISCONNECTED, pad_settings[i].device_capability, pad_settings[i].device_type);
m_pads[i] = std::make_shared<Pad>(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",