diff options
author | german77 <juangerman-13@hotmail.com> | 2021-10-27 07:20:28 +0200 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2021-11-25 03:30:26 +0100 |
commit | c085e54316c5520ed7d58a92a7faa9e896bb6c71 (patch) | |
tree | 05a5798ddc25ce2afa423cd70bec979705b63143 /src | |
parent | input_common: Fix UDP uuid (diff) | |
download | yuzu-c085e54316c5520ed7d58a92a7faa9e896bb6c71.tar yuzu-c085e54316c5520ed7d58a92a7faa9e896bb6c71.tar.gz yuzu-c085e54316c5520ed7d58a92a7faa9e896bb6c71.tar.bz2 yuzu-c085e54316c5520ed7d58a92a7faa9e896bb6c71.tar.lz yuzu-c085e54316c5520ed7d58a92a7faa9e896bb6c71.tar.xz yuzu-c085e54316c5520ed7d58a92a7faa9e896bb6c71.tar.zst yuzu-c085e54316c5520ed7d58a92a7faa9e896bb6c71.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/common/settings.h | 1 | ||||
-rw-r--r-- | src/core/hid/emulated_controller.cpp | 72 | ||||
-rw-r--r-- | src/core/hid/emulated_controller.h | 9 | ||||
-rw-r--r-- | src/yuzu/configuration/config.cpp | 2 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_tas.cpp | 2 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_tas.ui | 9 |
6 files changed, 82 insertions, 13 deletions
diff --git a/src/common/settings.h b/src/common/settings.h index 4cf28617c..dac44d000 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -567,7 +567,6 @@ struct Values { BasicSetting<bool> pause_tas_on_load{true, "pause_tas_on_load"}; BasicSetting<bool> tas_enable{false, "tas_enable"}; BasicSetting<bool> tas_loop{false, "tas_loop"}; - BasicSetting<bool> tas_swap_controllers{true, "tas_swap_controllers"}; BasicSetting<bool> mouse_panning{false, "mouse_panning"}; BasicRangedSetting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"}; diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 916368c68..2b051ccaf 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -105,6 +105,8 @@ void EmulatedController::LoadDevices() { output_params[LeftIndex].Set("output", true); output_params[RightIndex].Set("output", true); + LoadTASParams(); + std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, button_params.begin() + Settings::NativeButton::BUTTON_NS_END, button_devices.begin(), Input::CreateDevice<Input::InputDevice>); @@ -120,6 +122,51 @@ void EmulatedController::LoadDevices() { Input::CreateDevice<Input::InputDevice>); std::transform(output_params.begin(), output_params.end(), output_devices.begin(), Input::CreateDevice<Input::OutputDevice>); + + // Initialize TAS devices + std::transform(tas_button_params.begin(), tas_button_params.end(), tas_button_devices.begin(), + Input::CreateDevice<Input::InputDevice>); + std::transform(tas_stick_params.begin(), tas_stick_params.begin(), tas_stick_devices.begin(), + Input::CreateDevice<Input::InputDevice>); +} + +void EmulatedController::LoadTASParams() { + const auto player_index = NpadIdTypeToIndex(npad_id_type); + Common::ParamPackage common_params{}; + common_params.Set("engine", "tas"); + common_params.Set("pad", static_cast<int>(player_index)); + for (auto& param : tas_button_params) { + param = common_params; + } + for (auto& param : tas_stick_params) { + param = common_params; + } + + tas_button_params[Settings::NativeButton::A].Set("button", 1 << 0); + tas_button_params[Settings::NativeButton::B].Set("button", 1 << 1); + tas_button_params[Settings::NativeButton::X].Set("button", 1 << 2); + tas_button_params[Settings::NativeButton::Y].Set("button", 1 << 3); + tas_button_params[Settings::NativeButton::LStick].Set("button", 1 << 4); + tas_button_params[Settings::NativeButton::RStick].Set("button", 1 << 5); + tas_button_params[Settings::NativeButton::L].Set("button", 1 << 6); + tas_button_params[Settings::NativeButton::R].Set("button", 1 << 7); + tas_button_params[Settings::NativeButton::ZL].Set("button", 1 << 8); + tas_button_params[Settings::NativeButton::ZR].Set("button", 1 << 9); + tas_button_params[Settings::NativeButton::Plus].Set("button", 1 << 10); + tas_button_params[Settings::NativeButton::Minus].Set("button", 1 << 11); + tas_button_params[Settings::NativeButton::DLeft].Set("button", 1 << 12); + tas_button_params[Settings::NativeButton::DUp].Set("button", 1 << 13); + tas_button_params[Settings::NativeButton::DRight].Set("button", 1 << 14); + tas_button_params[Settings::NativeButton::DDown].Set("button", 1 << 15); + tas_button_params[Settings::NativeButton::SL].Set("button", 1 << 16); + tas_button_params[Settings::NativeButton::SR].Set("button", 1 << 17); + tas_button_params[Settings::NativeButton::Home].Set("button", 1 << 18); + tas_button_params[Settings::NativeButton::Screenshot].Set("button", 1 << 19); + + tas_stick_params[Settings::NativeAnalog::LStick].Set("axis_x", 0); + tas_stick_params[Settings::NativeAnalog::LStick].Set("axis_y", 1); + tas_stick_params[Settings::NativeAnalog::RStick].Set("axis_x", 2); + tas_stick_params[Settings::NativeAnalog::RStick].Set("axis_y", 3); } void EmulatedController::ReloadInput() { @@ -174,6 +221,25 @@ void EmulatedController::ReloadInput() { motion_devices[index]->SetCallback(motion_callback); motion_devices[index]->ForceUpdate(); } + + // Register TAS devices. No need to force update + for (std::size_t index = 0; index < tas_button_devices.size(); ++index) { + if (!tas_button_devices[index]) { + continue; + } + Input::InputCallback button_callback{ + [this, index](Input::CallbackStatus callback) { SetButton(callback, index); }}; + tas_button_devices[index]->SetCallback(button_callback); + } + + for (std::size_t index = 0; index < tas_stick_devices.size(); ++index) { + if (!tas_stick_devices[index]) { + continue; + } + Input::InputCallback stick_callback{ + [this, index](Input::CallbackStatus callback) { SetStick(callback, index); }}; + tas_stick_devices[index]->SetCallback(stick_callback); + } } void EmulatedController::UnloadInput() { @@ -195,6 +261,12 @@ void EmulatedController::UnloadInput() { for (auto& output : output_devices) { output.reset(); } + for (auto& button : tas_button_devices) { + button.reset(); + } + for (auto& stick : tas_stick_devices) { + stick.reset(); + } } void EmulatedController::EnableConfiguration() { diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index eb705a241..eec51e34a 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h @@ -299,6 +299,9 @@ private: /// creates input devices from params void LoadDevices(); + /// Set the params for TAS devices + void LoadTASParams(); + /** * Updates the button status of the controller * @param callback: A CallbackStatus containing the button status @@ -363,6 +366,12 @@ private: BatteryDevices battery_devices; OutputDevices output_devices; + // TAS related variables + ButtonParams tas_button_params; + StickParams tas_stick_params; + ButtonDevices tas_button_devices; + StickDevices tas_stick_devices; + mutable std::mutex mutex; std::unordered_map<int, ControllerUpdateCallback> callback_list; int last_callback_key = 0; diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 56af07507..7a748d9c8 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -573,7 +573,6 @@ void Config::ReadControlValues() { ReadBasicSetting(Settings::values.tas_enable); ReadBasicSetting(Settings::values.tas_loop); - ReadBasicSetting(Settings::values.tas_swap_controllers); ReadBasicSetting(Settings::values.pause_tas_on_load); ReadGlobalSetting(Settings::values.use_docked_mode); @@ -1209,7 +1208,6 @@ void Config::SaveControlValues() { WriteBasicSetting(Settings::values.tas_enable); WriteBasicSetting(Settings::values.tas_loop); - WriteBasicSetting(Settings::values.tas_swap_controllers); WriteBasicSetting(Settings::values.pause_tas_on_load); qt_config->endGroup(); diff --git a/src/yuzu/configuration/configure_tas.cpp b/src/yuzu/configuration/configure_tas.cpp index 8e5a4c72d..979a8db61 100644 --- a/src/yuzu/configuration/configure_tas.cpp +++ b/src/yuzu/configuration/configure_tas.cpp @@ -32,7 +32,6 @@ void ConfigureTasDialog::LoadConfiguration() { ui->tas_path_edit->setText( QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::TASDir))); ui->tas_enable->setChecked(Settings::values.tas_enable.GetValue()); - ui->tas_control_swap->setChecked(Settings::values.tas_swap_controllers.GetValue()); ui->tas_loop_script->setChecked(Settings::values.tas_loop.GetValue()); ui->tas_pause_on_load->setChecked(Settings::values.pause_tas_on_load.GetValue()); } @@ -40,7 +39,6 @@ void ConfigureTasDialog::LoadConfiguration() { void ConfigureTasDialog::ApplyConfiguration() { Common::FS::SetYuzuPath(Common::FS::YuzuPath::TASDir, ui->tas_path_edit->text().toStdString()); Settings::values.tas_enable.SetValue(ui->tas_enable->isChecked()); - Settings::values.tas_swap_controllers.SetValue(ui->tas_control_swap->isChecked()); Settings::values.tas_loop.SetValue(ui->tas_loop_script->isChecked()); Settings::values.pause_tas_on_load.SetValue(ui->tas_pause_on_load->isChecked()); } diff --git a/src/yuzu/configuration/configure_tas.ui b/src/yuzu/configuration/configure_tas.ui index 7d44895c4..cf88a5bf0 100644 --- a/src/yuzu/configuration/configure_tas.ui +++ b/src/yuzu/configuration/configure_tas.ui @@ -59,20 +59,13 @@ </widget> </item> <item row="1" column="0" colspan="4"> - <widget class="QCheckBox" name="tas_control_swap"> - <property name="text"> - <string>Automatic controller profile swapping</string> - </property> - </widget> - </item> - <item row="2" column="0" colspan="4"> <widget class="QCheckBox" name="tas_loop_script"> <property name="text"> <string>Loop script</string> </property> </widget> </item> - <item row="3" column="0" colspan="4"> + <item row="2" column="0" colspan="4"> <widget class="QCheckBox" name="tas_pause_on_load"> <property name="enabled"> <bool>false</bool> |