From 8e614c3eb038bbb288cd95ab993f66fefda9257d Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Fri, 28 Dec 2018 23:31:55 -0500 Subject: [PATCH] clang-format; address one comment --- src/citra/config.cpp | 23 ++++++------ src/citra_qt/configuration/config.cpp | 10 +++--- .../configuration/configure_input.cpp | 22 ++++++------ .../configuration/configure_motion_touch.cpp | 25 +++++++------ src/citra_qt/main.cpp | 2 +- src/core/hle/service/hid/hid.cpp | 14 +++++--- src/core/hle/service/ir/extra_hid.cpp | 6 ++-- src/core/hle/service/ir/ir_rst.cpp | 6 ++-- src/core/settings.cpp | 35 ++++--------------- src/core/settings.h | 13 ++----- src/input_common/udp/udp.cpp | 10 +++--- 11 files changed, 75 insertions(+), 91 deletions(-) diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 563c3b953..7b5d437ac 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -74,31 +74,32 @@ void Config::ReadValues() { // TODO: add multiple input profile support for (int i = 0; i < Settings::NativeButton::NumButtons; ++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); - if (Settings::values.buttons[i].empty()) - Settings::values.buttons[i] = default_param; + if (Settings::values.current_input_profile.buttons[i].empty()) + Settings::values.current_input_profile.buttons[i] = default_param; } for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { std::string default_param = InputCommon::GenerateAnalogParamFromKeys( default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], 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); - if (Settings::values.analogs[i].empty()) - Settings::values.analogs[i] = default_param; + if (Settings::values.current_input_profile.analogs[i].empty()) + 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", "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"); - 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); - Settings::values.udp_input_port = static_cast(sdl2_config->GetInteger( - "Controls", "udp_input_port", InputCommon::CemuhookUDP::DEFAULT_PORT)); + Settings::values.current_input_profile.udp_input_port = + static_cast(sdl2_config->GetInteger("Controls", "udp_input_port", + InputCommon::CemuhookUDP::DEFAULT_PORT)); // Core Settings::values.use_cpu_jit = sdl2_config->GetBoolean("Core", "use_cpu_jit", true); diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 05698e592..91f6fbd8f 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -51,7 +51,7 @@ const std::array, Settings::NativeAnalog::NumAnalogs> Config: void Config::ReadValues() { 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] { Settings::InputProfile profile; @@ -102,8 +102,8 @@ void Config::ReadValues() { qt_config->endArray(); - if (Settings::values.current_input_profile <= num_input_profiles) { - Settings::values.current_input_profile = 0; + if (Settings::values.current_input_profile_index <= num_input_profiles) { + Settings::values.current_input_profile_index = 0; } // create a input profile if no input profiles exist, with the default or old settings @@ -111,7 +111,7 @@ void Config::ReadValues() { append_profile(); } - Settings::LoadProfile(Settings::values.current_input_profile); + Settings::LoadProfile(Settings::values.current_input_profile_index); qt_config->endArray(); @@ -377,7 +377,7 @@ void Config::ReadValues() { void Config::SaveValues() { 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"); for (std::size_t p = 0; p < Settings::values.input_profiles.size(); ++p) { qt_config->setArrayIndex(static_cast(p)); diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 5f05eff41..80db5c29f 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -104,7 +104,7 @@ ConfigureInput::ConfigureInput(QWidget* parent) 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 = { ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp, @@ -233,7 +233,7 @@ ConfigureInput::ConfigureInput(QWidget* parent) connect(ui->profile, static_cast(&QComboBox::currentIndexChanged), [this](int i) { applyConfiguration(); - Settings::SaveProfile(Settings::values.current_input_profile); + Settings::SaveProfile(Settings::values.current_input_profile_index); Settings::LoadProfile(i); loadConfiguration(); }); @@ -261,22 +261,24 @@ ConfigureInput::ConfigureInput(QWidget* parent) ConfigureInput::~ConfigureInput() = default; 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(); }); - 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(); }); } void ConfigureInput::applyProfile() { - Settings::values.current_input_profile = ui->profile->currentIndex(); + Settings::values.current_input_profile_index = ui->profile->currentIndex(); } void ConfigureInput::loadConfiguration() { - std::transform(Settings::values.buttons.begin(), Settings::values.buttons.end(), - buttons_param.begin(), + std::transform(Settings::values.current_input_profile.buttons.begin(), + Settings::values.current_input_profile.buttons.end(), buttons_param.begin(), [](const std::string& str) { return Common::ParamPackage(str); }); - std::transform(Settings::values.analogs.begin(), Settings::values.analogs.end(), - analogs_param.begin(), + std::transform(Settings::values.current_input_profile.analogs.begin(), + Settings::values.current_input_profile.analogs.end(), analogs_param.begin(), [](const std::string& str) { return Common::ParamPackage(str); }); updateButtonLabels(); } @@ -398,7 +400,7 @@ void ConfigureInput::newProfile() { Settings::SaveProfile(ui->profile->currentIndex()); Settings::CreateProfile(name.toStdString()); ui->profile->addItem(name); - ui->profile->setCurrentIndex(Settings::values.current_input_profile); + ui->profile->setCurrentIndex(Settings::values.current_input_profile_index); loadConfiguration(); } diff --git a/src/citra_qt/configuration/configure_motion_touch.cpp b/src/citra_qt/configuration/configure_motion_touch.cpp index 289570beb..80bf6a148 100644 --- a/src/citra_qt/configuration/configure_motion_touch.cpp +++ b/src/citra_qt/configuration/configure_motion_touch.cpp @@ -102,8 +102,8 @@ ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent) ConfigureMotionTouch::~ConfigureMotionTouch() = default; void ConfigureMotionTouch::setConfiguration() { - Common::ParamPackage motion_param(Settings::values.motion_device); - Common::ParamPackage touch_param(Settings::values.touch_device); + Common::ParamPackage motion_param(Settings::values.current_input_profile.motion_device); + Common::ParamPackage touch_param(Settings::values.current_input_profile.touch_device); std::string motion_engine = motion_param.Get("engine", "motion_emu"); 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_y = touch_param.Get("max_y", 850); - ui->udp_server->setText(QString::fromStdString(Settings::values.udp_input_address)); - ui->udp_port->setText(QString::number(Settings::values.udp_input_port)); - ui->udp_pad_index->setCurrentIndex(Settings::values.udp_pad_index); + ui->udp_server->setText( + QString::fromStdString(Settings::values.current_input_profile.udp_input_address)); + 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() { @@ -265,12 +266,14 @@ void ConfigureMotionTouch::applyConfiguration() { touch_param.Set("max_y", max_y); } - Settings::values.motion_device = motion_param.Serialize(); - Settings::values.touch_device = touch_param.Serialize(); - Settings::values.udp_input_address = ui->udp_server->text().toStdString(); - Settings::values.udp_input_port = static_cast(ui->udp_port->text().toInt()); - Settings::values.udp_pad_index = static_cast(ui->udp_pad_index->currentIndex()); - Settings::SaveProfile(Settings::values.current_input_profile); + Settings::values.current_input_profile.motion_device = motion_param.Serialize(); + Settings::values.current_input_profile.touch_device = touch_param.Serialize(); + Settings::values.current_input_profile.udp_input_address = ui->udp_server->text().toStdString(); + Settings::values.current_input_profile.udp_input_port = + static_cast(ui->udp_port->text().toInt()); + Settings::values.current_input_profile.udp_pad_index = + static_cast(ui->udp_pad_index->currentIndex()); + Settings::SaveProfile(Settings::values.current_input_profile_index); InputCommon::ReloadInputDevices(); accept(); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 0af691e70..245b1b404 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -1326,7 +1326,7 @@ void GMainWindow::OnConfigure() { connect(&configureDialog, &ConfigureDialog::languageChanged, this, &GMainWindow::OnLanguageChanged); 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 bool old_discord_presence = UISettings::values.enable_discord_presence; auto result = configureDialog.exec(); diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 417f3b4d2..132594091 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -59,13 +59,17 @@ DirectionState GetStickDirectionState(s16 circle_pad_x, s16 circle_pad_y) { } void Module::LoadInputDevices() { - std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, - Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END, + std::transform(Settings::values.current_input_profile.buttons.begin() + + Settings::NativeButton::BUTTON_HID_BEGIN, + Settings::values.current_input_profile.buttons.begin() + + Settings::NativeButton::BUTTON_HID_END, buttons.begin(), Input::CreateDevice); circle_pad = Input::CreateDevice( - Settings::values.analogs[Settings::NativeAnalog::CirclePad]); - motion_device = Input::CreateDevice(Settings::values.motion_device); - touch_device = Input::CreateDevice(Settings::values.touch_device); + Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CirclePad]); + motion_device = Input::CreateDevice( + Settings::values.current_input_profile.motion_device); + touch_device = Input::CreateDevice( + Settings::values.current_input_profile.touch_device); } void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) { diff --git a/src/core/hle/service/ir/extra_hid.cpp b/src/core/hle/service/ir/extra_hid.cpp index 8568f15a1..e5332cc76 100644 --- a/src/core/hle/service/ir/extra_hid.cpp +++ b/src/core/hle/service/ir/extra_hid.cpp @@ -263,11 +263,11 @@ void ExtraHID::RequestInputDevicesReload() { void ExtraHID::LoadInputDevices() { zl = Input::CreateDevice( - Settings::values.buttons[Settings::NativeButton::ZL]); + Settings::values.current_input_profile.buttons[Settings::NativeButton::ZL]); zr = Input::CreateDevice( - Settings::values.buttons[Settings::NativeButton::ZR]); + Settings::values.current_input_profile.buttons[Settings::NativeButton::ZR]); c_stick = Input::CreateDevice( - Settings::values.analogs[Settings::NativeAnalog::CStick]); + Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CStick]); } } // namespace Service::IR diff --git a/src/core/hle/service/ir/ir_rst.cpp b/src/core/hle/service/ir/ir_rst.cpp index 7b7849afd..71d16a1ce 100644 --- a/src/core/hle/service/ir/ir_rst.cpp +++ b/src/core/hle/service/ir/ir_rst.cpp @@ -35,11 +35,11 @@ static_assert(sizeof(SharedMem) == 0x98, "SharedMem has wrong size!"); void IR_RST::LoadInputDevices() { zl_button = Input::CreateDevice( - Settings::values.buttons[Settings::NativeButton::ZL]); + Settings::values.current_input_profile.buttons[Settings::NativeButton::ZL]); zr_button = Input::CreateDevice( - Settings::values.buttons[Settings::NativeButton::ZR]); + Settings::values.current_input_profile.buttons[Settings::NativeButton::ZR]); c_stick = Input::CreateDevice( - Settings::values.analogs[Settings::NativeAnalog::CStick]); + Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CStick]); } void IR_RST::UnloadInputDevices() { diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 667fe1b52..8ac3b17c8 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -101,41 +101,20 @@ void LogSettings() { } void LoadProfile(int index) { - const auto& profile = values.input_profiles[index]; - values.current_input_profile = 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; + values.current_input_profile = values.input_profiles[index]; + values.current_input_profile_index = index; } void SaveProfile(int index) { - auto& profile = values.input_profiles[index]; - 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[index] = values.current_input_profile; } void CreateProfile(std::string name) { - InputProfile profile; + InputProfile profile = values.current_input_profile; 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.current_input_profile = static_cast(values.input_profiles.size()) - 1; - LoadProfile(values.current_input_profile); + values.current_input_profile_index = static_cast(values.input_profiles.size()) - 1; + LoadProfile(values.current_input_profile_index); } void DeleteProfile(int index) { @@ -144,7 +123,7 @@ void DeleteProfile(int index) { } 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 diff --git a/src/core/settings.h b/src/core/settings.h index 2bf6b5e6e..ccb00928f 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -108,16 +108,9 @@ struct Values { // CheckNew3DS bool is_new_3ds; - // Current controls - std::array buttons; - std::array analogs; - 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 + // Controls + InputProfile current_input_profile; ///< The current input profile + int current_input_profile_index; ///< The current input profile index std::vector input_profiles; ///< The list of input profiles // Core diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index d94278def..239cf25ed 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp @@ -71,8 +71,9 @@ private: State::State() { auto status = std::make_shared(); client = - std::make_unique(status, Settings::values.udp_input_address, - Settings::values.udp_input_port, Settings::values.udp_pad_index); + std::make_unique(status, Settings::values.current_input_profile.udp_input_address, + Settings::values.current_input_profile.udp_input_port, + Settings::values.current_input_profile.udp_pad_index); Input::RegisterFactory("cemuhookudp", std::make_shared(status)); @@ -86,8 +87,9 @@ State::~State() { } void State::ReloadUDPClient() { - client->ReloadSocket(Settings::values.udp_input_address, Settings::values.udp_input_port, - Settings::values.udp_pad_index); + client->ReloadSocket(Settings::values.current_input_profile.udp_input_address, + Settings::values.current_input_profile.udp_input_port, + Settings::values.current_input_profile.udp_pad_index); } std::unique_ptr Init() {