mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 02:32:36 +01:00
input: use std::array for sticks, sensors and motors
We always have the same amount of those. So using a vector has always been a bit confusing.
This commit is contained in:
parent
c882f0baf0
commit
7b92cbcb9a
@ -350,7 +350,6 @@ 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, 0);
|
||||
pad->m_sensors.resize(preview_values.size(), AnalogSensor(0, 0, 0, 0, 0));
|
||||
pad_ensemble binding{pad, device, nullptr};
|
||||
get_extended_info(binding);
|
||||
|
||||
@ -505,18 +504,18 @@ bool PadHandlerBase::bindPadToDevice(std::shared_ptr<Pad> pad)
|
||||
pad->m_buttons.emplace_back(CELL_PAD_BTN_OFFSET_PRESS_PIGGYBACK, mapping[button::skateboard_tilt_right], CELL_PAD_CTRL_PRESS_R1);
|
||||
}
|
||||
|
||||
pad->m_sticks.emplace_back(CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X, mapping[button::ls_left], mapping[button::ls_right]);
|
||||
pad->m_sticks.emplace_back(CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y, mapping[button::ls_down], mapping[button::ls_up]);
|
||||
pad->m_sticks.emplace_back(CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X, mapping[button::rs_left], mapping[button::rs_right]);
|
||||
pad->m_sticks.emplace_back(CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y, mapping[button::rs_down], mapping[button::rs_up]);
|
||||
pad->m_sticks[0] = AnalogStick(CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X, mapping[button::ls_left], mapping[button::ls_right]);
|
||||
pad->m_sticks[1] = AnalogStick(CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y, mapping[button::ls_down], mapping[button::ls_up]);
|
||||
pad->m_sticks[2] = AnalogStick(CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X, mapping[button::rs_left], mapping[button::rs_right]);
|
||||
pad->m_sticks[3] = AnalogStick(CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y, mapping[button::rs_down], mapping[button::rs_up]);
|
||||
|
||||
pad->m_sensors.emplace_back(CELL_PAD_BTN_OFFSET_SENSOR_X, 0, 0, 0, DEFAULT_MOTION_X);
|
||||
pad->m_sensors.emplace_back(CELL_PAD_BTN_OFFSET_SENSOR_Y, 0, 0, 0, DEFAULT_MOTION_Y);
|
||||
pad->m_sensors.emplace_back(CELL_PAD_BTN_OFFSET_SENSOR_Z, 0, 0, 0, DEFAULT_MOTION_Z);
|
||||
pad->m_sensors.emplace_back(CELL_PAD_BTN_OFFSET_SENSOR_G, 0, 0, 0, DEFAULT_MOTION_G);
|
||||
pad->m_sensors[0] = AnalogSensor(CELL_PAD_BTN_OFFSET_SENSOR_X, 0, 0, 0, DEFAULT_MOTION_X);
|
||||
pad->m_sensors[1] = AnalogSensor(CELL_PAD_BTN_OFFSET_SENSOR_Y, 0, 0, 0, DEFAULT_MOTION_Y);
|
||||
pad->m_sensors[2] = AnalogSensor(CELL_PAD_BTN_OFFSET_SENSOR_Z, 0, 0, 0, DEFAULT_MOTION_Z);
|
||||
pad->m_sensors[3] = AnalogSensor(CELL_PAD_BTN_OFFSET_SENSOR_G, 0, 0, 0, DEFAULT_MOTION_G);
|
||||
|
||||
pad->m_vibrateMotors.emplace_back(true, 0);
|
||||
pad->m_vibrateMotors.emplace_back(false, 0);
|
||||
pad->m_vibrateMotors[0] = VibrateMotor(true, 0);
|
||||
pad->m_vibrateMotors[1] = VibrateMotor(false, 0);
|
||||
|
||||
m_bindings.emplace_back(pad, pad_device, nullptr);
|
||||
|
||||
|
@ -417,6 +417,7 @@ struct AnalogStick
|
||||
std::map<u32, u16> m_pressed_keys_min{}; // only used in keyboard_pad_handler
|
||||
std::map<u32, u16> m_pressed_keys_max{}; // only used in keyboard_pad_handler
|
||||
|
||||
AnalogStick() {}
|
||||
AnalogStick(u32 offset, std::set<u32> key_codes_min, std::set<u32> key_codes_max)
|
||||
: m_offset(offset)
|
||||
, m_key_codes_min(std::move(key_codes_min))
|
||||
@ -447,6 +448,7 @@ struct VibrateMotor
|
||||
bool m_is_large_motor = false;
|
||||
u8 m_value = 0;
|
||||
|
||||
VibrateMotor() {}
|
||||
VibrateMotor(bool is_large_motor, u8 value)
|
||||
: m_is_large_motor(is_large_motor)
|
||||
, m_value(value)
|
||||
@ -489,9 +491,9 @@ struct Pad
|
||||
u8 m_battery_level{0};
|
||||
|
||||
std::vector<Button> m_buttons;
|
||||
std::vector<AnalogStick> m_sticks;
|
||||
std::vector<AnalogSensor> m_sensors;
|
||||
std::vector<VibrateMotor> m_vibrateMotors;
|
||||
std::array<AnalogStick, 4> m_sticks{};
|
||||
std::array<AnalogSensor, 4> m_sensors{};
|
||||
std::array<VibrateMotor, 2> m_vibrateMotors{};
|
||||
|
||||
// These hold bits for their respective buttons
|
||||
u16 m_digital_1{0};
|
||||
|
@ -1219,7 +1219,7 @@ void evdev_joystick_handler::apply_input_events(const std::shared_ptr<Pad>& pad)
|
||||
s32 stick_val[4]{};
|
||||
|
||||
// Translate any corresponding keycodes to our two sticks. (ignoring thresholds for now)
|
||||
for (int i = 0; i < static_cast<int>(pad->m_sticks.size()); i++)
|
||||
for (usz i = 0; i < pad->m_sticks.size(); i++)
|
||||
{
|
||||
bool pressed{}; // unused
|
||||
u16 val_min{};
|
||||
@ -1424,23 +1424,23 @@ bool evdev_joystick_handler::bindPadToDevice(std::shared_ptr<Pad> pad)
|
||||
m_dev->axis_right[2] = find_buttons(cfg->rs_up);
|
||||
m_dev->axis_right[3] = find_buttons(cfg->rs_down);
|
||||
|
||||
pad->m_sticks.emplace_back(CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X, m_dev->axis_left[1], m_dev->axis_left[0]);
|
||||
pad->m_sticks.emplace_back(CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y, m_dev->axis_left[3], m_dev->axis_left[2]);
|
||||
pad->m_sticks.emplace_back(CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X, m_dev->axis_right[1], m_dev->axis_right[0]);
|
||||
pad->m_sticks.emplace_back(CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y, m_dev->axis_right[3], m_dev->axis_right[2]);
|
||||
pad->m_sticks[0] = AnalogStick(CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X, m_dev->axis_left[1], m_dev->axis_left[0]);
|
||||
pad->m_sticks[1] = AnalogStick(CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y, m_dev->axis_left[3], m_dev->axis_left[2]);
|
||||
pad->m_sticks[2] = AnalogStick(CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X, m_dev->axis_right[1], m_dev->axis_right[0]);
|
||||
pad->m_sticks[3] = AnalogStick(CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y, m_dev->axis_right[3], m_dev->axis_right[2]);
|
||||
|
||||
m_dev->axis_motion[0] = find_motion_button(cfg->motion_sensor_x);
|
||||
m_dev->axis_motion[1] = find_motion_button(cfg->motion_sensor_y);
|
||||
m_dev->axis_motion[2] = find_motion_button(cfg->motion_sensor_z);
|
||||
m_dev->axis_motion[3] = find_motion_button(cfg->motion_sensor_g);
|
||||
|
||||
pad->m_sensors.emplace_back(CELL_PAD_BTN_OFFSET_SENSOR_X, m_dev->axis_motion[0].code, m_dev->axis_motion[0].mirrored, m_dev->axis_motion[0].shift, DEFAULT_MOTION_X);
|
||||
pad->m_sensors.emplace_back(CELL_PAD_BTN_OFFSET_SENSOR_Y, m_dev->axis_motion[1].code, m_dev->axis_motion[1].mirrored, m_dev->axis_motion[1].shift, DEFAULT_MOTION_Y);
|
||||
pad->m_sensors.emplace_back(CELL_PAD_BTN_OFFSET_SENSOR_Z, m_dev->axis_motion[2].code, m_dev->axis_motion[2].mirrored, m_dev->axis_motion[2].shift, DEFAULT_MOTION_Z);
|
||||
pad->m_sensors.emplace_back(CELL_PAD_BTN_OFFSET_SENSOR_G, m_dev->axis_motion[3].code, m_dev->axis_motion[3].mirrored, m_dev->axis_motion[3].shift, DEFAULT_MOTION_G);
|
||||
pad->m_sensors[0] = AnalogSensor(CELL_PAD_BTN_OFFSET_SENSOR_X, m_dev->axis_motion[0].code, m_dev->axis_motion[0].mirrored, m_dev->axis_motion[0].shift, DEFAULT_MOTION_X);
|
||||
pad->m_sensors[1] = AnalogSensor(CELL_PAD_BTN_OFFSET_SENSOR_Y, m_dev->axis_motion[1].code, m_dev->axis_motion[1].mirrored, m_dev->axis_motion[1].shift, DEFAULT_MOTION_Y);
|
||||
pad->m_sensors[2] = AnalogSensor(CELL_PAD_BTN_OFFSET_SENSOR_Z, m_dev->axis_motion[2].code, m_dev->axis_motion[2].mirrored, m_dev->axis_motion[2].shift, DEFAULT_MOTION_Z);
|
||||
pad->m_sensors[3] = AnalogSensor(CELL_PAD_BTN_OFFSET_SENSOR_G, m_dev->axis_motion[3].code, m_dev->axis_motion[3].mirrored, m_dev->axis_motion[3].shift, DEFAULT_MOTION_G);
|
||||
|
||||
pad->m_vibrateMotors.emplace_back(true, 0);
|
||||
pad->m_vibrateMotors.emplace_back(false, 0);
|
||||
pad->m_vibrateMotors[0] = VibrateMotor(true, 0);
|
||||
pad->m_vibrateMotors[1] = VibrateMotor(false, 0);
|
||||
|
||||
if (std::shared_ptr<EvdevDevice> evdev_device = add_device(player_config->device, false))
|
||||
{
|
||||
|
@ -314,11 +314,6 @@ void keyboard_pad_handler::release_all_keys()
|
||||
|
||||
for (usz i = 0; i < pad.m_sticks.size(); i++)
|
||||
{
|
||||
if (i >= max_sticks)
|
||||
{
|
||||
input_log.fatal("Too many sticks (%d vs %d)", pad.m_sticks.size(), max_sticks);
|
||||
break;
|
||||
}
|
||||
m_stick_min[i] = 0;
|
||||
m_stick_max[i] = 128;
|
||||
m_stick_val[i] = 128;
|
||||
@ -1067,18 +1062,18 @@ bool keyboard_pad_handler::bindPadToDevice(std::shared_ptr<Pad> pad)
|
||||
pad->m_buttons.emplace_back(CELL_PAD_BTN_OFFSET_PRESS_PIGGYBACK, find_keys(cfg->tilt_right), CELL_PAD_CTRL_PRESS_R1);
|
||||
}
|
||||
|
||||
pad->m_sticks.emplace_back(CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X, find_keys(cfg->ls_left), find_keys(cfg->ls_right));
|
||||
pad->m_sticks.emplace_back(CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y, find_keys(cfg->ls_up), find_keys(cfg->ls_down));
|
||||
pad->m_sticks.emplace_back(CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X, find_keys(cfg->rs_left), find_keys(cfg->rs_right));
|
||||
pad->m_sticks.emplace_back(CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y, find_keys(cfg->rs_up), find_keys(cfg->rs_down));
|
||||
pad->m_sticks[0] = AnalogStick(CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X, find_keys(cfg->ls_left), find_keys(cfg->ls_right));
|
||||
pad->m_sticks[1] = AnalogStick(CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y, find_keys(cfg->ls_up), find_keys(cfg->ls_down));
|
||||
pad->m_sticks[2] = AnalogStick(CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X, find_keys(cfg->rs_left), find_keys(cfg->rs_right));
|
||||
pad->m_sticks[3] = AnalogStick(CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y, find_keys(cfg->rs_up), find_keys(cfg->rs_down));
|
||||
|
||||
pad->m_sensors.emplace_back(CELL_PAD_BTN_OFFSET_SENSOR_X, 0, 0, 0, DEFAULT_MOTION_X);
|
||||
pad->m_sensors.emplace_back(CELL_PAD_BTN_OFFSET_SENSOR_Y, 0, 0, 0, DEFAULT_MOTION_Y);
|
||||
pad->m_sensors.emplace_back(CELL_PAD_BTN_OFFSET_SENSOR_Z, 0, 0, 0, DEFAULT_MOTION_Z);
|
||||
pad->m_sensors.emplace_back(CELL_PAD_BTN_OFFSET_SENSOR_G, 0, 0, 0, DEFAULT_MOTION_G);
|
||||
pad->m_sensors[0] = AnalogSensor(CELL_PAD_BTN_OFFSET_SENSOR_X, 0, 0, 0, DEFAULT_MOTION_X);
|
||||
pad->m_sensors[1] = AnalogSensor(CELL_PAD_BTN_OFFSET_SENSOR_Y, 0, 0, 0, DEFAULT_MOTION_Y);
|
||||
pad->m_sensors[2] = AnalogSensor(CELL_PAD_BTN_OFFSET_SENSOR_Z, 0, 0, 0, DEFAULT_MOTION_Z);
|
||||
pad->m_sensors[3] = AnalogSensor(CELL_PAD_BTN_OFFSET_SENSOR_G, 0, 0, 0, DEFAULT_MOTION_G);
|
||||
|
||||
pad->m_vibrateMotors.emplace_back(true, 0);
|
||||
pad->m_vibrateMotors.emplace_back(false, 0);
|
||||
pad->m_vibrateMotors[0] = VibrateMotor(true, 0);
|
||||
pad->m_vibrateMotors[1] = VibrateMotor(false, 0);
|
||||
|
||||
m_bindings.emplace_back(pad, nullptr, nullptr);
|
||||
m_pads_internal.push_back(*pad);
|
||||
@ -1258,7 +1253,7 @@ void keyboard_pad_handler::process()
|
||||
|
||||
// Normalize and apply pad squircling
|
||||
// Copy sticks first. We don't want to modify the raw internal values
|
||||
std::vector<AnalogStick> squircled_sticks = pad_internal.m_sticks;
|
||||
std::array<AnalogStick, 4> squircled_sticks = pad_internal.m_sticks;
|
||||
|
||||
// Apply squircling
|
||||
if (cfg->lpadsquircling != 0)
|
||||
|
@ -212,11 +212,8 @@ void pad_thread::SetRumble(const u32 pad, u8 large_motor, bool small_motor)
|
||||
if (pad >= m_pads.size())
|
||||
return;
|
||||
|
||||
if (m_pads[pad]->m_vibrateMotors.size() >= 2)
|
||||
{
|
||||
m_pads[pad]->m_vibrateMotors[0].m_value = large_motor;
|
||||
m_pads[pad]->m_vibrateMotors[1].m_value = small_motor ? 255 : 0;
|
||||
}
|
||||
m_pads[pad]->m_vibrateMotors[0].m_value = large_motor;
|
||||
m_pads[pad]->m_vibrateMotors[1].m_value = small_motor ? 255 : 0;
|
||||
}
|
||||
|
||||
void pad_thread::SetIntercepted(bool intercepted)
|
||||
|
Loading…
Reference in New Issue
Block a user