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
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<u16>(sdl2_config->GetInteger(
"Controls", "udp_input_port", InputCommon::CemuhookUDP::DEFAULT_PORT));
Settings::values.current_input_profile.udp_input_port =
static_cast<u16>(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);

View file

@ -51,7 +51,7 @@ const std::array<std::array<int, 5>, 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<int>(p));

View file

@ -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<void (QComboBox::*)(int)>(&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();
}

View file

@ -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<u16>(ui->udp_port->text().toInt());
Settings::values.udp_pad_index = static_cast<u8>(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<u16>(ui->udp_port->text().toInt());
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();
accept();

View file

@ -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();

View file

@ -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<Input::ButtonDevice>);
circle_pad = Input::CreateDevice<Input::AnalogDevice>(
Settings::values.analogs[Settings::NativeAnalog::CirclePad]);
motion_device = Input::CreateDevice<Input::MotionDevice>(Settings::values.motion_device);
touch_device = Input::CreateDevice<Input::TouchDevice>(Settings::values.touch_device);
Settings::values.current_input_profile.analogs[Settings::NativeAnalog::CirclePad]);
motion_device = Input::CreateDevice<Input::MotionDevice>(
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) {

View file

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

View file

@ -35,11 +35,11 @@ static_assert(sizeof(SharedMem) == 0x98, "SharedMem has wrong size!");
void IR_RST::LoadInputDevices() {
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>(
Settings::values.buttons[Settings::NativeButton::ZR]);
Settings::values.current_input_profile.buttons[Settings::NativeButton::ZR]);
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() {

View file

@ -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<int>(values.input_profiles.size()) - 1;
LoadProfile(values.current_input_profile);
values.current_input_profile_index = static_cast<int>(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

View file

@ -108,16 +108,9 @@ struct Values {
// CheckNew3DS
bool is_new_3ds;
// Current controls
std::array<std::string, NativeButton::NumButtons> buttons;
std::array<std::string, NativeAnalog::NumAnalogs> 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<InputProfile> input_profiles; ///< The list of input profiles
// Core

View file

@ -71,8 +71,9 @@ private:
State::State() {
auto status = std::make_shared<DeviceStatus>();
client =
std::make_unique<Client>(status, Settings::values.udp_input_address,
Settings::values.udp_input_port, Settings::values.udp_pad_index);
std::make_unique<Client>(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<Input::TouchDevice>("cemuhookudp",
std::make_shared<UDPTouchFactory>(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<State> Init() {