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

@ -59,7 +59,7 @@ public:
return nulllist;
}
bool bindPadToDevice(std::shared_ptr<Pad> /*pad*/, u8 /*player_id*/) override
bool bindPadToDevice(std::shared_ptr<Pad> /*pad*/) override
{
return true;
}

View File

@ -322,7 +322,7 @@ void PadHandlerBase::get_motion_sensors(const std::string& pad_id, const motion_
}
// Get the current motion values
std::shared_ptr<Pad> pad = std::make_shared<Pad>(m_type, 0, 0, 0);
std::shared_ptr<Pad> pad = std::make_shared<Pad>(m_type, 0, 0, 0, 0);
pad->m_sensors.resize(preview_values.size(), AnalogSensor(0, 0, 0, 0, 0));
pad_ensemble binding{pad, device, nullptr};
get_extended_info(binding);
@ -382,14 +382,14 @@ void PadHandlerBase::TranslateButtonPress(const std::shared_ptr<PadDevice>& devi
}
}
bool PadHandlerBase::bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_id)
bool PadHandlerBase::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)
{
return false;
@ -402,9 +402,9 @@ bool PadHandlerBase::bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_id)
return false;
}
m_pad_configs[player_id].from_string(player_config->config.to_string());
pad_device->config = &m_pad_configs[player_id];
pad_device->player_id = player_id;
m_pad_configs[pad->m_player_id].from_string(player_config->config.to_string());
pad_device->config = &m_pad_configs[pad->m_player_id];
pad_device->player_id = pad->m_player_id;
cfg_pad* config = pad_device->config;
if (config == nullptr)
{

View File

@ -278,7 +278,7 @@ public:
// Callback called during pad_thread::ThreadFunc
virtual void process();
// Binds a Pad to a device
virtual bool bindPadToDevice(std::shared_ptr<Pad> pad, u8 player_id);
virtual bool bindPadToDevice(std::shared_ptr<Pad> pad);
virtual void init_config(cfg_pad* cfg) = 0;
virtual connection get_next_button_press(const std::string& padId, const pad_callback& callback, const pad_fail_callback& fail_callback, bool get_blacklist, const std::vector<std::string>& buttons = {});
virtual void get_motion_sensors(const std::string& pad_id, const motion_callback& callback, const motion_fail_callback& fail_callback, motion_preview_values preview_values, const std::array<AnalogSensor, 4>& sensors);

View File

@ -450,6 +450,7 @@ struct VibrateMotor
struct Pad
{
const pad_handler m_pad_handler;
const u32 m_player_id;
bool m_buffer_cleared{true};
u32 m_port_status{0};
@ -466,7 +467,7 @@ struct Pad
bool m_pressure_intensity_toggled{}; // Whether the sensitivity is toggled on or off.
u8 m_pressure_intensity{127}; // 0-255
bool m_adjust_pressure_last{}; // only used in keyboard_pad_handler
bool get_pressure_intensity_button_active(bool is_toggle_mode);
bool get_pressure_intensity_button_active(bool is_toggle_mode, u32 player_id);
// Cable State: 0 - 1 plugged in ?
u8 m_cable_state{0};
@ -515,8 +516,9 @@ struct Pad
bool is_fake_pad = false;
explicit Pad(pad_handler handler, u32 port_status, u32 device_capability, u32 device_type)
explicit Pad(pad_handler handler, u32 player_id, u32 port_status, u32 device_capability, u32 device_type)
: m_pad_handler(handler)
, m_player_id(player_id)
, m_port_status(port_status)
, m_device_capability(device_capability)
, m_device_type(device_type)

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",