clang-format; address one comment

This commit is contained in:
Valentin Vanelslande 2018-12-28 23:31:55 -05:00
parent 860860397b
commit 8e614c3eb0
11 changed files with 75 additions and 91 deletions

View File

@ -74,31 +74,32 @@ void Config::ReadValues() {
// TODO: add multiple input profile support // TODO: add multiple input profile support
for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]);
Settings::values.buttons[i] = Settings::values.current_input_profile.buttons[i] =
sdl2_config->GetString("Controls", Settings::NativeButton::mapping[i], default_param); sdl2_config->GetString("Controls", Settings::NativeButton::mapping[i], default_param);
if (Settings::values.buttons[i].empty()) if (Settings::values.current_input_profile.buttons[i].empty())
Settings::values.buttons[i] = default_param; Settings::values.current_input_profile.buttons[i] = default_param;
} }
for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
std::string default_param = InputCommon::GenerateAnalogParamFromKeys( std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], default_analogs[i][0], default_analogs[i][1], default_analogs[i][2],
default_analogs[i][3], default_analogs[i][4], 0.5f); default_analogs[i][3], default_analogs[i][4], 0.5f);
Settings::values.analogs[i] = Settings::values.current_input_profile.analogs[i] =
sdl2_config->GetString("Controls", Settings::NativeAnalog::mapping[i], default_param); sdl2_config->GetString("Controls", Settings::NativeAnalog::mapping[i], default_param);
if (Settings::values.analogs[i].empty()) if (Settings::values.current_input_profile.analogs[i].empty())
Settings::values.analogs[i] = default_param; Settings::values.current_input_profile.analogs[i] = default_param;
} }
Settings::values.motion_device = sdl2_config->GetString( Settings::values.current_input_profile.motion_device = sdl2_config->GetString(
"Controls", "motion_device", "Controls", "motion_device",
"engine:motion_emu,update_period:100,sensitivity:0.01,tilt_clamp:90.0"); "engine:motion_emu,update_period:100,sensitivity:0.01,tilt_clamp:90.0");
Settings::values.touch_device = Settings::values.current_input_profile.touch_device =
sdl2_config->GetString("Controls", "touch_device", "engine:emu_window"); sdl2_config->GetString("Controls", "touch_device", "engine:emu_window");
Settings::values.udp_input_address = sdl2_config->GetString( Settings::values.current_input_profile.udp_input_address = sdl2_config->GetString(
"Controls", "udp_input_address", InputCommon::CemuhookUDP::DEFAULT_ADDR); "Controls", "udp_input_address", InputCommon::CemuhookUDP::DEFAULT_ADDR);
Settings::values.udp_input_port = static_cast<u16>(sdl2_config->GetInteger( Settings::values.current_input_profile.udp_input_port =
"Controls", "udp_input_port", InputCommon::CemuhookUDP::DEFAULT_PORT)); static_cast<u16>(sdl2_config->GetInteger("Controls", "udp_input_port",
InputCommon::CemuhookUDP::DEFAULT_PORT));
// Core // Core
Settings::values.use_cpu_jit = sdl2_config->GetBoolean("Core", "use_cpu_jit", true); Settings::values.use_cpu_jit = sdl2_config->GetBoolean("Core", "use_cpu_jit", true);

View File

@ -51,7 +51,7 @@ const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> Config:
void Config::ReadValues() { void Config::ReadValues() {
qt_config->beginGroup("Controls"); qt_config->beginGroup("Controls");
Settings::values.current_input_profile = ReadSetting("profile", 0).toInt(); Settings::values.current_input_profile_index = ReadSetting("profile", 0).toInt();
const auto append_profile = [this] { const auto append_profile = [this] {
Settings::InputProfile profile; Settings::InputProfile profile;
@ -102,8 +102,8 @@ void Config::ReadValues() {
qt_config->endArray(); qt_config->endArray();
if (Settings::values.current_input_profile <= num_input_profiles) { if (Settings::values.current_input_profile_index <= num_input_profiles) {
Settings::values.current_input_profile = 0; Settings::values.current_input_profile_index = 0;
} }
// create a input profile if no input profiles exist, with the default or old settings // create a input profile if no input profiles exist, with the default or old settings
@ -111,7 +111,7 @@ void Config::ReadValues() {
append_profile(); append_profile();
} }
Settings::LoadProfile(Settings::values.current_input_profile); Settings::LoadProfile(Settings::values.current_input_profile_index);
qt_config->endArray(); qt_config->endArray();
@ -377,7 +377,7 @@ void Config::ReadValues() {
void Config::SaveValues() { void Config::SaveValues() {
qt_config->beginGroup("Controls"); qt_config->beginGroup("Controls");
WriteSetting("profile", Settings::values.current_input_profile, 0); WriteSetting("profile", Settings::values.current_input_profile_index, 0);
qt_config->beginWriteArray("profiles"); qt_config->beginWriteArray("profiles");
for (std::size_t p = 0; p < Settings::values.input_profiles.size(); ++p) { for (std::size_t p = 0; p < Settings::values.input_profiles.size(); ++p) {
qt_config->setArrayIndex(static_cast<int>(p)); qt_config->setArrayIndex(static_cast<int>(p));

View File

@ -104,7 +104,7 @@ ConfigureInput::ConfigureInput(QWidget* parent)
ui->profile->addItem(QString::fromStdString(profile.name)); ui->profile->addItem(QString::fromStdString(profile.name));
} }
ui->profile->setCurrentIndex(Settings::values.current_input_profile); ui->profile->setCurrentIndex(Settings::values.current_input_profile_index);
button_map = { button_map = {
ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp, ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp,
@ -233,7 +233,7 @@ ConfigureInput::ConfigureInput(QWidget* parent)
connect(ui->profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(ui->profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
[this](int i) { [this](int i) {
applyConfiguration(); applyConfiguration();
Settings::SaveProfile(Settings::values.current_input_profile); Settings::SaveProfile(Settings::values.current_input_profile_index);
Settings::LoadProfile(i); Settings::LoadProfile(i);
loadConfiguration(); loadConfiguration();
}); });
@ -261,22 +261,24 @@ ConfigureInput::ConfigureInput(QWidget* parent)
ConfigureInput::~ConfigureInput() = default; ConfigureInput::~ConfigureInput() = default;
void ConfigureInput::applyConfiguration() { void ConfigureInput::applyConfiguration() {
std::transform(buttons_param.begin(), buttons_param.end(), Settings::values.buttons.begin(), std::transform(buttons_param.begin(), buttons_param.end(),
Settings::values.current_input_profile.buttons.begin(),
[](const Common::ParamPackage& param) { return param.Serialize(); }); [](const Common::ParamPackage& param) { return param.Serialize(); });
std::transform(analogs_param.begin(), analogs_param.end(), Settings::values.analogs.begin(), std::transform(analogs_param.begin(), analogs_param.end(),
Settings::values.current_input_profile.analogs.begin(),
[](const Common::ParamPackage& param) { return param.Serialize(); }); [](const Common::ParamPackage& param) { return param.Serialize(); });
} }
void ConfigureInput::applyProfile() { void ConfigureInput::applyProfile() {
Settings::values.current_input_profile = ui->profile->currentIndex(); Settings::values.current_input_profile_index = ui->profile->currentIndex();
} }
void ConfigureInput::loadConfiguration() { void ConfigureInput::loadConfiguration() {
std::transform(Settings::values.buttons.begin(), Settings::values.buttons.end(), std::transform(Settings::values.current_input_profile.buttons.begin(),
buttons_param.begin(), Settings::values.current_input_profile.buttons.end(), buttons_param.begin(),
[](const std::string& str) { return Common::ParamPackage(str); }); [](const std::string& str) { return Common::ParamPackage(str); });
std::transform(Settings::values.analogs.begin(), Settings::values.analogs.end(), std::transform(Settings::values.current_input_profile.analogs.begin(),
analogs_param.begin(), Settings::values.current_input_profile.analogs.end(), analogs_param.begin(),
[](const std::string& str) { return Common::ParamPackage(str); }); [](const std::string& str) { return Common::ParamPackage(str); });
updateButtonLabels(); updateButtonLabels();
} }
@ -398,7 +400,7 @@ void ConfigureInput::newProfile() {
Settings::SaveProfile(ui->profile->currentIndex()); Settings::SaveProfile(ui->profile->currentIndex());
Settings::CreateProfile(name.toStdString()); Settings::CreateProfile(name.toStdString());
ui->profile->addItem(name); ui->profile->addItem(name);
ui->profile->setCurrentIndex(Settings::values.current_input_profile); ui->profile->setCurrentIndex(Settings::values.current_input_profile_index);
loadConfiguration(); loadConfiguration();
} }

View File

@ -102,8 +102,8 @@ ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent)
ConfigureMotionTouch::~ConfigureMotionTouch() = default; ConfigureMotionTouch::~ConfigureMotionTouch() = default;
void ConfigureMotionTouch::setConfiguration() { void ConfigureMotionTouch::setConfiguration() {
Common::ParamPackage motion_param(Settings::values.motion_device); Common::ParamPackage motion_param(Settings::values.current_input_profile.motion_device);
Common::ParamPackage touch_param(Settings::values.touch_device); Common::ParamPackage touch_param(Settings::values.current_input_profile.touch_device);
std::string motion_engine = motion_param.Get("engine", "motion_emu"); std::string motion_engine = motion_param.Get("engine", "motion_emu");
std::string touch_engine = touch_param.Get("engine", "emu_window"); std::string touch_engine = touch_param.Get("engine", "emu_window");
@ -118,9 +118,10 @@ void ConfigureMotionTouch::setConfiguration() {
max_x = touch_param.Get("max_x", 1800); max_x = touch_param.Get("max_x", 1800);
max_y = touch_param.Get("max_y", 850); max_y = touch_param.Get("max_y", 850);
ui->udp_server->setText(QString::fromStdString(Settings::values.udp_input_address)); ui->udp_server->setText(
ui->udp_port->setText(QString::number(Settings::values.udp_input_port)); QString::fromStdString(Settings::values.current_input_profile.udp_input_address));
ui->udp_pad_index->setCurrentIndex(Settings::values.udp_pad_index); ui->udp_port->setText(QString::number(Settings::values.current_input_profile.udp_input_port));
ui->udp_pad_index->setCurrentIndex(Settings::values.current_input_profile.udp_pad_index);
} }
void ConfigureMotionTouch::updateUiDisplay() { void ConfigureMotionTouch::updateUiDisplay() {
@ -265,12 +266,14 @@ void ConfigureMotionTouch::applyConfiguration() {
touch_param.Set("max_y", max_y); touch_param.Set("max_y", max_y);
} }
Settings::values.motion_device = motion_param.Serialize(); Settings::values.current_input_profile.motion_device = motion_param.Serialize();
Settings::values.touch_device = touch_param.Serialize(); Settings::values.current_input_profile.touch_device = touch_param.Serialize();
Settings::values.udp_input_address = ui->udp_server->text().toStdString(); Settings::values.current_input_profile.udp_input_address = ui->udp_server->text().toStdString();
Settings::values.udp_input_port = static_cast<u16>(ui->udp_port->text().toInt()); Settings::values.current_input_profile.udp_input_port =
Settings::values.udp_pad_index = static_cast<u8>(ui->udp_pad_index->currentIndex()); static_cast<u16>(ui->udp_port->text().toInt());
Settings::SaveProfile(Settings::values.current_input_profile); Settings::values.current_input_profile.udp_pad_index =
static_cast<u8>(ui->udp_pad_index->currentIndex());
Settings::SaveProfile(Settings::values.current_input_profile_index);
InputCommon::ReloadInputDevices(); InputCommon::ReloadInputDevices();
accept(); accept();

View File

@ -1326,7 +1326,7 @@ void GMainWindow::OnConfigure() {
connect(&configureDialog, &ConfigureDialog::languageChanged, this, connect(&configureDialog, &ConfigureDialog::languageChanged, this,
&GMainWindow::OnLanguageChanged); &GMainWindow::OnLanguageChanged);
auto old_theme = UISettings::values.theme; auto old_theme = UISettings::values.theme;
const int old_input_profile = Settings::values.current_input_profile; const int old_input_profile = Settings::values.current_input_profile_index;
const auto old_input_profiles = Settings::values.input_profiles; const auto old_input_profiles = Settings::values.input_profiles;
const bool old_discord_presence = UISettings::values.enable_discord_presence; const bool old_discord_presence = UISettings::values.enable_discord_presence;
auto result = configureDialog.exec(); auto result = configureDialog.exec();

View File

@ -59,13 +59,17 @@ DirectionState GetStickDirectionState(s16 circle_pad_x, s16 circle_pad_y) {
} }
void Module::LoadInputDevices() { void Module::LoadInputDevices() {
std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, std::transform(Settings::values.current_input_profile.buttons.begin() +
Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END, Settings::NativeButton::BUTTON_HID_BEGIN,
Settings::values.current_input_profile.buttons.begin() +
Settings::NativeButton::BUTTON_HID_END,
buttons.begin(), Input::CreateDevice<Input::ButtonDevice>); buttons.begin(), Input::CreateDevice<Input::ButtonDevice>);
circle_pad = Input::CreateDevice<Input::AnalogDevice>( circle_pad = Input::CreateDevice<Input::AnalogDevice>(
Settings::values.analogs[Settings::NativeAnalog::CirclePad]); Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CirclePad]);
motion_device = Input::CreateDevice<Input::MotionDevice>(Settings::values.motion_device); motion_device = Input::CreateDevice<Input::MotionDevice>(
touch_device = Input::CreateDevice<Input::TouchDevice>(Settings::values.touch_device); Settings::values.current_input_profile.motion_device);
touch_device = Input::CreateDevice<Input::TouchDevice>(
Settings::values.current_input_profile.touch_device);
} }
void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) { void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {

View File

@ -263,11 +263,11 @@ void ExtraHID::RequestInputDevicesReload() {
void ExtraHID::LoadInputDevices() { void ExtraHID::LoadInputDevices() {
zl = Input::CreateDevice<Input::ButtonDevice>( zl = Input::CreateDevice<Input::ButtonDevice>(
Settings::values.buttons[Settings::NativeButton::ZL]); Settings::values.current_input_profile.buttons[Settings::NativeButton::ZL]);
zr = Input::CreateDevice<Input::ButtonDevice>( zr = Input::CreateDevice<Input::ButtonDevice>(
Settings::values.buttons[Settings::NativeButton::ZR]); Settings::values.current_input_profile.buttons[Settings::NativeButton::ZR]);
c_stick = Input::CreateDevice<Input::AnalogDevice>( c_stick = Input::CreateDevice<Input::AnalogDevice>(
Settings::values.analogs[Settings::NativeAnalog::CStick]); Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CStick]);
} }
} // namespace Service::IR } // namespace Service::IR

View File

@ -35,11 +35,11 @@ static_assert(sizeof(SharedMem) == 0x98, "SharedMem has wrong size!");
void IR_RST::LoadInputDevices() { void IR_RST::LoadInputDevices() {
zl_button = Input::CreateDevice<Input::ButtonDevice>( zl_button = Input::CreateDevice<Input::ButtonDevice>(
Settings::values.buttons[Settings::NativeButton::ZL]); Settings::values.current_input_profile.buttons[Settings::NativeButton::ZL]);
zr_button = Input::CreateDevice<Input::ButtonDevice>( zr_button = Input::CreateDevice<Input::ButtonDevice>(
Settings::values.buttons[Settings::NativeButton::ZR]); Settings::values.current_input_profile.buttons[Settings::NativeButton::ZR]);
c_stick = Input::CreateDevice<Input::AnalogDevice>( c_stick = Input::CreateDevice<Input::AnalogDevice>(
Settings::values.analogs[Settings::NativeAnalog::CStick]); Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CStick]);
} }
void IR_RST::UnloadInputDevices() { void IR_RST::UnloadInputDevices() {

View File

@ -101,41 +101,20 @@ void LogSettings() {
} }
void LoadProfile(int index) { void LoadProfile(int index) {
const auto& profile = values.input_profiles[index]; values.current_input_profile = values.input_profiles[index];
values.current_input_profile = index; values.current_input_profile_index = index;
values.analogs = profile.analogs;
values.buttons = profile.buttons;
values.motion_device = profile.motion_device;
values.touch_device = profile.touch_device;
values.udp_input_address = profile.udp_input_address;
values.udp_input_port = profile.udp_input_port;
values.udp_pad_index = profile.udp_pad_index;
} }
void SaveProfile(int index) { void SaveProfile(int index) {
auto& profile = values.input_profiles[index]; values.input_profiles[index] = values.current_input_profile;
profile.analogs = values.analogs;
profile.buttons = values.buttons;
profile.motion_device = values.motion_device;
profile.touch_device = values.touch_device;
profile.udp_input_address = values.udp_input_address;
profile.udp_input_port = values.udp_input_port;
profile.udp_pad_index = values.udp_pad_index;
} }
void CreateProfile(std::string name) { void CreateProfile(std::string name) {
InputProfile profile; InputProfile profile = values.current_input_profile;
profile.name = std::move(name); profile.name = std::move(name);
profile.analogs = values.analogs;
profile.buttons = values.buttons;
profile.motion_device = values.motion_device;
profile.touch_device = values.touch_device;
profile.udp_input_address = values.udp_input_address;
profile.udp_input_port = values.udp_input_port;
profile.udp_pad_index = values.udp_pad_index;
values.input_profiles.push_back(std::move(profile)); values.input_profiles.push_back(std::move(profile));
values.current_input_profile = static_cast<int>(values.input_profiles.size()) - 1; values.current_input_profile_index = static_cast<int>(values.input_profiles.size()) - 1;
LoadProfile(values.current_input_profile); LoadProfile(values.current_input_profile_index);
} }
void DeleteProfile(int index) { void DeleteProfile(int index) {
@ -144,7 +123,7 @@ void DeleteProfile(int index) {
} }
void RenameCurrentProfile(std::string new_name) { void RenameCurrentProfile(std::string new_name) {
values.input_profiles[values.current_input_profile].name = std::move(new_name); values.input_profiles[values.current_input_profile_index].name = std::move(new_name);
} }
} // namespace Settings } // namespace Settings

View File

@ -108,16 +108,9 @@ struct Values {
// CheckNew3DS // CheckNew3DS
bool is_new_3ds; bool is_new_3ds;
// Current controls // Controls
std::array<std::string, NativeButton::NumButtons> buttons; InputProfile current_input_profile; ///< The current input profile
std::array<std::string, NativeAnalog::NumAnalogs> analogs; int current_input_profile_index; ///< The current input profile index
std::string motion_device;
std::string touch_device;
std::string udp_input_address;
u16 udp_input_port;
u8 udp_pad_index;
int current_input_profile; ///< The current input profile index
std::vector<InputProfile> input_profiles; ///< The list of input profiles std::vector<InputProfile> input_profiles; ///< The list of input profiles
// Core // Core

View File

@ -71,8 +71,9 @@ private:
State::State() { State::State() {
auto status = std::make_shared<DeviceStatus>(); auto status = std::make_shared<DeviceStatus>();
client = client =
std::make_unique<Client>(status, Settings::values.udp_input_address, std::make_unique<Client>(status, Settings::values.current_input_profile.udp_input_address,
Settings::values.udp_input_port, Settings::values.udp_pad_index); Settings::values.current_input_profile.udp_input_port,
Settings::values.current_input_profile.udp_pad_index);
Input::RegisterFactory<Input::TouchDevice>("cemuhookudp", Input::RegisterFactory<Input::TouchDevice>("cemuhookudp",
std::make_shared<UDPTouchFactory>(status)); std::make_shared<UDPTouchFactory>(status));
@ -86,8 +87,9 @@ State::~State() {
} }
void State::ReloadUDPClient() { void State::ReloadUDPClient() {
client->ReloadSocket(Settings::values.udp_input_address, Settings::values.udp_input_port, client->ReloadSocket(Settings::values.current_input_profile.udp_input_address,
Settings::values.udp_pad_index); Settings::values.current_input_profile.udp_input_port,
Settings::values.current_input_profile.udp_pad_index);
} }
std::unique_ptr<State> Init() { std::unique_ptr<State> Init() {