summaryrefslogtreecommitdiffstats
path: root/src/core/hid/emulated_controller.cpp
diff options
context:
space:
mode:
authorgerman77 <juangerman-13@hotmail.com>2021-10-27 07:20:28 +0200
committerNarr the Reg <juangerman-13@hotmail.com>2021-11-25 03:30:26 +0100
commitc085e54316c5520ed7d58a92a7faa9e896bb6c71 (patch)
tree05a5798ddc25ce2afa423cd70bec979705b63143 /src/core/hid/emulated_controller.cpp
parentinput_common: Fix UDP uuid (diff)
downloadyuzu-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/core/hid/emulated_controller.cpp')
-rw-r--r--src/core/hid/emulated_controller.cpp72
1 files changed, 72 insertions, 0 deletions
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() {