mirror of
https://github.com/RPCS3/rpcs3.git
synced 2026-07-09 17:25:18 -06:00
Use std::string_view in input code
This commit is contained in:
parent
5bc128e085
commit
41a7cd29f8
@ -757,7 +757,7 @@ void cfg::log_entry::from_default()
|
||||
|
||||
std::pair<u16, u16> cfg::device_info::get_usb_ids() const
|
||||
{
|
||||
auto string_to_hex = [](const std::string& str) -> u16
|
||||
auto string_to_hex = [](std::string_view str) -> u16
|
||||
{
|
||||
u16 value = 0x0000;
|
||||
if (!str.empty() && std::from_chars(str.data(), str.data() + str.size(), value, 16).ec != std::errc{})
|
||||
|
||||
@ -11,7 +11,7 @@ PadHandlerBase::PadHandlerBase(pad_handler type) : m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<std::set<u32>> PadHandlerBase::find_key_combos(const std::unordered_map<u32, std::string>& map, const std::string& cfg_string)
|
||||
std::vector<std::set<u32>> PadHandlerBase::find_key_combos(const std::unordered_map<u32, std::string>& map, std::string_view cfg_string)
|
||||
{
|
||||
std::vector<std::set<u32>> key_codes;
|
||||
|
||||
@ -232,7 +232,7 @@ pad_capabilities PadHandlerBase::get_capabilities(const std::string& /*pad_id*/)
|
||||
};
|
||||
}
|
||||
|
||||
cfg_pad* PadHandlerBase::get_config(const std::string& pad_id)
|
||||
cfg_pad* PadHandlerBase::get_config(std::string_view pad_id)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
@ -595,52 +595,52 @@ std::array<std::vector<std::set<u32>>, PadHandlerBase::button::button_count> Pad
|
||||
if (!device || !cfg)
|
||||
return mapping;
|
||||
|
||||
mapping[button::up] = find_key_combos(button_list, cfg->up);
|
||||
mapping[button::down] = find_key_combos(button_list, cfg->down);
|
||||
mapping[button::left] = find_key_combos(button_list, cfg->left);
|
||||
mapping[button::right] = find_key_combos(button_list, cfg->right);
|
||||
mapping[button::cross] = find_key_combos(button_list, cfg->cross);
|
||||
mapping[button::square] = find_key_combos(button_list, cfg->square);
|
||||
mapping[button::circle] = find_key_combos(button_list, cfg->circle);
|
||||
mapping[button::triangle] = find_key_combos(button_list, cfg->triangle);
|
||||
mapping[button::start] = find_key_combos(button_list, cfg->start);
|
||||
mapping[button::select] = find_key_combos(button_list, cfg->select);
|
||||
mapping[button::l1] = find_key_combos(button_list, cfg->l1);
|
||||
mapping[button::l2] = find_key_combos(button_list, cfg->l2);
|
||||
mapping[button::l3] = find_key_combos(button_list, cfg->l3);
|
||||
mapping[button::r1] = find_key_combos(button_list, cfg->r1);
|
||||
mapping[button::r2] = find_key_combos(button_list, cfg->r2);
|
||||
mapping[button::r3] = find_key_combos(button_list, cfg->r3);
|
||||
mapping[button::ls_left] = find_key_combos(button_list, cfg->ls_left);
|
||||
mapping[button::ls_right] = find_key_combos(button_list, cfg->ls_right);
|
||||
mapping[button::ls_down] = find_key_combos(button_list, cfg->ls_down);
|
||||
mapping[button::ls_up] = find_key_combos(button_list, cfg->ls_up);
|
||||
mapping[button::rs_left] = find_key_combos(button_list, cfg->rs_left);
|
||||
mapping[button::rs_right] = find_key_combos(button_list, cfg->rs_right);
|
||||
mapping[button::rs_down] = find_key_combos(button_list, cfg->rs_down);
|
||||
mapping[button::rs_up] = find_key_combos(button_list, cfg->rs_up);
|
||||
mapping[button::ps] = find_key_combos(button_list, cfg->ps);
|
||||
mapping[button::up] = find_key_combos(button_list, cfg->up.to_string());
|
||||
mapping[button::down] = find_key_combos(button_list, cfg->down.to_string());
|
||||
mapping[button::left] = find_key_combos(button_list, cfg->left.to_string());
|
||||
mapping[button::right] = find_key_combos(button_list, cfg->right.to_string());
|
||||
mapping[button::cross] = find_key_combos(button_list, cfg->cross.to_string());
|
||||
mapping[button::square] = find_key_combos(button_list, cfg->square.to_string());
|
||||
mapping[button::circle] = find_key_combos(button_list, cfg->circle.to_string());
|
||||
mapping[button::triangle] = find_key_combos(button_list, cfg->triangle.to_string());
|
||||
mapping[button::start] = find_key_combos(button_list, cfg->start.to_string());
|
||||
mapping[button::select] = find_key_combos(button_list, cfg->select.to_string());
|
||||
mapping[button::l1] = find_key_combos(button_list, cfg->l1.to_string());
|
||||
mapping[button::l2] = find_key_combos(button_list, cfg->l2.to_string());
|
||||
mapping[button::l3] = find_key_combos(button_list, cfg->l3.to_string());
|
||||
mapping[button::r1] = find_key_combos(button_list, cfg->r1.to_string());
|
||||
mapping[button::r2] = find_key_combos(button_list, cfg->r2.to_string());
|
||||
mapping[button::r3] = find_key_combos(button_list, cfg->r3.to_string());
|
||||
mapping[button::ls_left] = find_key_combos(button_list, cfg->ls_left.to_string());
|
||||
mapping[button::ls_right] = find_key_combos(button_list, cfg->ls_right.to_string());
|
||||
mapping[button::ls_down] = find_key_combos(button_list, cfg->ls_down.to_string());
|
||||
mapping[button::ls_up] = find_key_combos(button_list, cfg->ls_up.to_string());
|
||||
mapping[button::rs_left] = find_key_combos(button_list, cfg->rs_left.to_string());
|
||||
mapping[button::rs_right] = find_key_combos(button_list, cfg->rs_right.to_string());
|
||||
mapping[button::rs_down] = find_key_combos(button_list, cfg->rs_down.to_string());
|
||||
mapping[button::rs_up] = find_key_combos(button_list, cfg->rs_up.to_string());
|
||||
mapping[button::ps] = find_key_combos(button_list, cfg->ps.to_string());
|
||||
|
||||
mapping[button::skateboard_ir_nose] = find_key_combos(button_list, cfg->ir_nose);
|
||||
mapping[button::skateboard_ir_tail] = find_key_combos(button_list, cfg->ir_tail);
|
||||
mapping[button::skateboard_ir_left] = find_key_combos(button_list, cfg->ir_left);
|
||||
mapping[button::skateboard_ir_right] = find_key_combos(button_list, cfg->ir_right);
|
||||
mapping[button::skateboard_tilt_left] = find_key_combos(button_list, cfg->tilt_left);
|
||||
mapping[button::skateboard_tilt_right] = find_key_combos(button_list, cfg->tilt_right);
|
||||
mapping[button::skateboard_ir_nose] = find_key_combos(button_list, cfg->ir_nose.to_string());
|
||||
mapping[button::skateboard_ir_tail] = find_key_combos(button_list, cfg->ir_tail.to_string());
|
||||
mapping[button::skateboard_ir_left] = find_key_combos(button_list, cfg->ir_left.to_string());
|
||||
mapping[button::skateboard_ir_right] = find_key_combos(button_list, cfg->ir_right.to_string());
|
||||
mapping[button::skateboard_tilt_left] = find_key_combos(button_list, cfg->tilt_left.to_string());
|
||||
mapping[button::skateboard_tilt_right] = find_key_combos(button_list, cfg->tilt_right.to_string());
|
||||
|
||||
if (b_has_pressure_intensity_button)
|
||||
{
|
||||
mapping[button::pressure_intensity_button] = find_key_combos(button_list, cfg->pressure_intensity_button);
|
||||
mapping[button::pressure_intensity_button] = find_key_combos(button_list, cfg->pressure_intensity_button.to_string());
|
||||
}
|
||||
|
||||
if (b_has_analog_limiter_button)
|
||||
{
|
||||
mapping[button::analog_limiter_button] = find_key_combos(button_list, cfg->analog_limiter_button);
|
||||
mapping[button::analog_limiter_button] = find_key_combos(button_list, cfg->analog_limiter_button.to_string());
|
||||
}
|
||||
|
||||
if (b_has_orientation)
|
||||
{
|
||||
mapping[button::orientation_reset_button] = find_key_combos(button_list, cfg->orientation_reset_button);
|
||||
mapping[button::orientation_reset_button] = find_key_combos(button_list, cfg->orientation_reset_button.to_string());
|
||||
}
|
||||
|
||||
return mapping;
|
||||
|
||||
@ -193,7 +193,7 @@ protected:
|
||||
std::shared_ptr<Pad> m_pad_for_pad_settings;
|
||||
|
||||
// Search an unordered map for a string value and return the found combos
|
||||
static std::vector<std::set<u32>> find_key_combos(const std::unordered_map<u32, std::string>& map, const std::string& cfg_string);
|
||||
static std::vector<std::set<u32>> find_key_combos(const std::unordered_map<u32, std::string>& map, std::string_view cfg_string);
|
||||
|
||||
// Search an unordered map for a combo and return the found key codes
|
||||
static std::set<u32> find_key_codes(const std::unordered_map<u32, std::string>& map, const pad::combo& combo);
|
||||
@ -324,7 +324,7 @@ protected:
|
||||
virtual void get_mapping(const pad_ensemble& binding);
|
||||
void TranslateButtonPress(const std::shared_ptr<PadDevice>& device, u32 keyCode, bool& pressed, u16& val, bool use_stick_multipliers, bool ignore_stick_threshold = false, bool ignore_trigger_threshold = false);
|
||||
void init_configs();
|
||||
cfg_pad* get_config(const std::string& pad_id);
|
||||
cfg_pad* get_config(std::string_view pad_id);
|
||||
|
||||
static void set_raw_orientation(ps_move_data& move_data, f32 accel_x, f32 accel_y, f32 accel_z, f32 gyro_x, f32 gyro_y, f32 gyro_z);
|
||||
static void set_raw_orientation(Pad& pad);
|
||||
|
||||
@ -85,9 +85,15 @@ void cfg_camera::camera_setting::from_string(std::string_view text)
|
||||
return;
|
||||
}
|
||||
|
||||
const auto to_integer = [](const std::string& str, int& out) -> bool
|
||||
const auto to_integer = [](std::string_view str, int& out) -> bool
|
||||
{
|
||||
auto [ptr, ec] = std::from_chars(str.c_str(), str.c_str() + str.size(), out);
|
||||
if (str.empty())
|
||||
{
|
||||
camera_log.error("Empty string cannot be interpreted as integer.");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), out);
|
||||
if (ec != std::errc{})
|
||||
{
|
||||
camera_log.error("String '%s' cannot be interpreted as integer.", str);
|
||||
@ -96,11 +102,17 @@ void cfg_camera::camera_setting::from_string(std::string_view text)
|
||||
return true;
|
||||
};
|
||||
|
||||
const auto to_double = [](const std::string& str, double& out) -> bool
|
||||
const auto to_double = [](std::string_view str, double& out) -> bool
|
||||
{
|
||||
if (str.empty())
|
||||
{
|
||||
camera_log.error("Empty string cannot be interpreted as double.");
|
||||
return false;
|
||||
}
|
||||
|
||||
char* end{};
|
||||
out = std::strtod(str.c_str(), &end);
|
||||
if (end != str.c_str() + str.size())
|
||||
out = std::strtod(str.data(), &end);
|
||||
if (end != str.data() + str.size())
|
||||
{
|
||||
camera_log.error("String '%s' cannot be interpreted as double.", str);
|
||||
return false;
|
||||
|
||||
@ -371,7 +371,7 @@ PadHandlerBase::connection evdev_joystick_handler::get_next_button_press(const s
|
||||
|
||||
const auto data = GetButtonValues(device);
|
||||
|
||||
const auto find_value = [&, this](const std::string& str)
|
||||
const auto find_value = [&, this](std::string_view str)
|
||||
{
|
||||
const std::vector<pad::combo> combos = cfg_pad::get_combos(str);
|
||||
|
||||
@ -1419,7 +1419,7 @@ bool evdev_joystick_handler::bindPadToDevice(std::shared_ptr<Pad> pad)
|
||||
e_sensor.mirrored = sensor.mirrored.get();
|
||||
e_sensor.shift = sensor.shift.get();
|
||||
|
||||
const std::vector<std::set<u32>> combos = find_key_combos(motion_axis_list, sensor.axis);
|
||||
const std::vector<std::set<u32>> combos = find_key_combos(motion_axis_list, sensor.axis.to_string());
|
||||
if (!combos.empty() && !combos.front().empty()) e_sensor.code = *combos.front().begin(); // We should only have one key for each of our sensors
|
||||
return e_sensor;
|
||||
};
|
||||
|
||||
@ -906,7 +906,7 @@ std::string keyboard_pad_handler::GetKeyName(u32 keyCode)
|
||||
return QKeySequence(keyCode).toString(QKeySequence::NativeText).toStdString();
|
||||
}
|
||||
|
||||
std::vector<std::set<u32>> keyboard_pad_handler::GetKeyCombos(const std::string& cfg_string)
|
||||
std::vector<std::set<u32>> keyboard_pad_handler::GetKeyCombos(std::string_view cfg_string)
|
||||
{
|
||||
std::vector<std::set<u32>> res;
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ public:
|
||||
static QStringList GetKeyNames(const QKeyEvent* keyEvent);
|
||||
static std::string GetKeyName(const QKeyEvent* keyEvent, bool with_modifiers);
|
||||
static std::string GetKeyName(u32 keyCode);
|
||||
static std::vector<std::set<u32>> GetKeyCombos(const std::string& cfg_string);
|
||||
static std::vector<std::set<u32>> GetKeyCombos(std::string_view cfg_string);
|
||||
static u32 GetKeyCode(const QString& keyName);
|
||||
|
||||
static int native_scan_code_from_string(const std::string& key);
|
||||
|
||||
@ -226,7 +226,7 @@ pad_preview_values mm_joystick_handler::get_preview_values(const std::unordered_
|
||||
if (buttons.size() != 10)
|
||||
return preview_values;
|
||||
|
||||
const auto get_key_value = [this, &data](const std::string& str) -> u16
|
||||
const auto get_key_value = [this, &data](std::string_view str) -> u16
|
||||
{
|
||||
u16 value{};
|
||||
|
||||
|
||||
@ -74,12 +74,12 @@ public:
|
||||
|
||||
const std::map<void*, raw_mouse>& get_mice() const { return m_raw_mice; };
|
||||
|
||||
void set_mouse_press_callback(std::function<void(const std::string&, s32, bool)> cb)
|
||||
void set_mouse_press_callback(std::function<void(std::string_view, s32, bool)> cb)
|
||||
{
|
||||
m_mouse_press_callback = std::move(cb);
|
||||
}
|
||||
|
||||
void mouse_press_callback(const std::string& device_name, s32 button_code, bool pressed)
|
||||
void mouse_press_callback(std::string_view device_name, s32 button_code, bool pressed)
|
||||
{
|
||||
if (m_mouse_press_callback)
|
||||
{
|
||||
@ -87,12 +87,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void set_key_press_callback(std::function<void(const std::string&, s32, bool)> cb)
|
||||
void set_key_press_callback(std::function<void(std::string_view, s32, bool)> cb)
|
||||
{
|
||||
m_key_press_callback = std::move(cb);
|
||||
}
|
||||
|
||||
void key_press_callback(const std::string& device_name, s32 scan_code, bool pressed)
|
||||
void key_press_callback(std::string_view device_name, s32 scan_code, bool pressed)
|
||||
{
|
||||
if (m_key_press_callback)
|
||||
{
|
||||
@ -120,8 +120,8 @@ private:
|
||||
|
||||
bool m_is_for_gui = false;
|
||||
std::map<void*, raw_mouse> m_raw_mice;
|
||||
std::function<void(const std::string&, s32, bool)> m_mouse_press_callback;
|
||||
std::function<void(const std::string&, s32, bool)> m_key_press_callback;
|
||||
std::function<void(std::string_view, s32, bool)> m_mouse_press_callback;
|
||||
std::function<void(std::string_view, s32, bool)> m_key_press_callback;
|
||||
|
||||
std::unique_ptr<named_thread<std::function<void()>>> m_thread;
|
||||
};
|
||||
|
||||
@ -6,7 +6,7 @@ LOG_CHANNEL(cfg_log, "CFG");
|
||||
// Helper methods to interact with YAML and the config settings.
|
||||
namespace cfg_adapter
|
||||
{
|
||||
static cfg::_base& get_cfg(const cfg::_base& root, const std::string& name)
|
||||
static cfg::_base& get_cfg(const cfg::_base& root, std::string_view name)
|
||||
{
|
||||
if (root.get_type() == cfg::type::node)
|
||||
{
|
||||
|
||||
@ -495,7 +495,7 @@ void pad_settings_dialog::InitButtons()
|
||||
return;
|
||||
}
|
||||
|
||||
const auto update_preview = [this](const std::string& pad_name, bool is_connected, int battery_level, int trigger_left, int trigger_right, int lx, int ly, int rx, int ry, const pad_capabilities& capabilities)
|
||||
const auto update_preview = [this](std::string_view pad_name, bool is_connected, int battery_level, int trigger_left, int trigger_right, int lx, int ly, int rx, int ry, const pad_capabilities& capabilities)
|
||||
{
|
||||
SwitchPadInfo(pad_name, is_connected);
|
||||
|
||||
@ -801,7 +801,7 @@ void pad_settings_dialog::switch_pad_info(int index, pad_device_info info, bool
|
||||
}
|
||||
}
|
||||
|
||||
void pad_settings_dialog::SwitchPadInfo(const std::string& pad_name, bool is_connected)
|
||||
void pad_settings_dialog::SwitchPadInfo(std::string_view pad_name, bool is_connected)
|
||||
{
|
||||
for (int i = 0; i < ui->chooseDevice->count(); i++)
|
||||
{
|
||||
|
||||
@ -228,7 +228,7 @@ private:
|
||||
|
||||
pad_device_info get_pad_info(QComboBox* combo, int index);
|
||||
void switch_pad_info(int index, pad_device_info info, bool is_connected);
|
||||
void SwitchPadInfo(const std::string& name, bool is_connected);
|
||||
void SwitchPadInfo(std::string_view name, bool is_connected);
|
||||
|
||||
/** Enable/Disable Buttons while trying to remap an other */
|
||||
void SwitchButtons(bool is_enabled);
|
||||
|
||||
@ -70,11 +70,11 @@ raw_mouse_settings_dialog::raw_mouse_settings_dialog(QWidget* parent)
|
||||
g_raw_mouse_handler = std::make_unique<raw_mouse_handler>();
|
||||
g_raw_mouse_handler->set_is_for_gui(true);
|
||||
g_raw_mouse_handler->Init(std::max(max_devices, ::size32(g_cfg_raw_mouse.players)));
|
||||
g_raw_mouse_handler->set_mouse_press_callback([this](const std::string& device_name, s32 button_code, bool pressed)
|
||||
g_raw_mouse_handler->set_mouse_press_callback([this](std::string_view device_name, s32 button_code, bool pressed)
|
||||
{
|
||||
mouse_press(device_name, button_code, pressed);
|
||||
});
|
||||
g_raw_mouse_handler->set_key_press_callback([this](const std::string& device_name, s32 scan_code, bool pressed)
|
||||
g_raw_mouse_handler->set_key_press_callback([this](std::string_view device_name, s32 scan_code, bool pressed)
|
||||
{
|
||||
key_press(device_name, scan_code, pressed);
|
||||
});
|
||||
@ -350,7 +350,7 @@ void raw_mouse_settings_dialog::reset_config()
|
||||
}
|
||||
}
|
||||
|
||||
void raw_mouse_settings_dialog::mouse_press(const std::string& device_name, s32 button_code, bool pressed)
|
||||
void raw_mouse_settings_dialog::mouse_press(std::string_view device_name, s32 button_code, bool pressed)
|
||||
{
|
||||
if (m_button_id < 0 || pressed) // Let's only react to mouse releases
|
||||
{
|
||||
@ -378,7 +378,7 @@ void raw_mouse_settings_dialog::mouse_press(const std::string& device_name, s32
|
||||
reactivate_buttons();
|
||||
}
|
||||
|
||||
void raw_mouse_settings_dialog::key_press(const std::string& device_name, s32 scan_code, bool pressed)
|
||||
void raw_mouse_settings_dialog::key_press(std::string_view device_name, s32 scan_code, bool pressed)
|
||||
{
|
||||
if (m_button_id < 0 || !pressed) // Let's only react to key presses
|
||||
{
|
||||
@ -404,7 +404,7 @@ void raw_mouse_settings_dialog::key_press(const std::string& device_name, s32 sc
|
||||
reactivate_buttons();
|
||||
}
|
||||
|
||||
void raw_mouse_settings_dialog::handle_device_change(const std::string& device_name)
|
||||
void raw_mouse_settings_dialog::handle_device_change(std::string_view device_name)
|
||||
{
|
||||
if (is_device_active(device_name))
|
||||
{
|
||||
@ -419,7 +419,7 @@ void raw_mouse_settings_dialog::handle_device_change(const std::string& device_n
|
||||
}
|
||||
}
|
||||
|
||||
bool raw_mouse_settings_dialog::is_device_active(const std::string& device_name)
|
||||
bool raw_mouse_settings_dialog::is_device_active(std::string_view device_name)
|
||||
{
|
||||
if (!g_raw_mouse_handler || device_name.empty())
|
||||
{
|
||||
|
||||
@ -30,10 +30,10 @@ private:
|
||||
void on_enumeration();
|
||||
void reset_config();
|
||||
void on_button_click(int id);
|
||||
void mouse_press(const std::string& device_name, s32 button_code, bool pressed);
|
||||
void key_press(const std::string& device_name, s32 scan_code, bool pressed);
|
||||
void handle_device_change(const std::string& device_name);
|
||||
bool is_device_active(const std::string& device_name);
|
||||
void mouse_press(std::string_view device_name, s32 button_code, bool pressed);
|
||||
void key_press(std::string_view device_name, s32 scan_code, bool pressed);
|
||||
void handle_device_change(std::string_view device_name);
|
||||
bool is_device_active(std::string_view device_name);
|
||||
std::string get_current_device_name(int player);
|
||||
void reactivate_buttons();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user