yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

core/hid: Add TAS input

This commit is contained in:
german77 2021-10-27 00:20:28 -05:00 committed by Narr the Reg
parent 1d71d4b874
commit c085e54316
6 changed files with 82 additions and 13 deletions

View File

@ -567,7 +567,6 @@ struct Values {
BasicSetting<bool> pause_tas_on_load{true, "pause_tas_on_load"}; BasicSetting<bool> pause_tas_on_load{true, "pause_tas_on_load"};
BasicSetting<bool> tas_enable{false, "tas_enable"}; BasicSetting<bool> tas_enable{false, "tas_enable"};
BasicSetting<bool> tas_loop{false, "tas_loop"}; BasicSetting<bool> tas_loop{false, "tas_loop"};
BasicSetting<bool> tas_swap_controllers{true, "tas_swap_controllers"};
BasicSetting<bool> mouse_panning{false, "mouse_panning"}; BasicSetting<bool> mouse_panning{false, "mouse_panning"};
BasicRangedSetting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"}; BasicRangedSetting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"};

View File

@ -105,6 +105,8 @@ void EmulatedController::LoadDevices() {
output_params[LeftIndex].Set("output", true); output_params[LeftIndex].Set("output", true);
output_params[RightIndex].Set("output", true); output_params[RightIndex].Set("output", true);
LoadTASParams();
std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
button_params.begin() + Settings::NativeButton::BUTTON_NS_END, button_params.begin() + Settings::NativeButton::BUTTON_NS_END,
button_devices.begin(), Input::CreateDevice<Input::InputDevice>); button_devices.begin(), Input::CreateDevice<Input::InputDevice>);
@ -120,6 +122,51 @@ void EmulatedController::LoadDevices() {
Input::CreateDevice<Input::InputDevice>); Input::CreateDevice<Input::InputDevice>);
std::transform(output_params.begin(), output_params.end(), output_devices.begin(), std::transform(output_params.begin(), output_params.end(), output_devices.begin(),
Input::CreateDevice<Input::OutputDevice>); 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() { void EmulatedController::ReloadInput() {
@ -174,6 +221,25 @@ void EmulatedController::ReloadInput() {
motion_devices[index]->SetCallback(motion_callback); motion_devices[index]->SetCallback(motion_callback);
motion_devices[index]->ForceUpdate(); 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() { void EmulatedController::UnloadInput() {
@ -195,6 +261,12 @@ void EmulatedController::UnloadInput() {
for (auto& output : output_devices) { for (auto& output : output_devices) {
output.reset(); output.reset();
} }
for (auto& button : tas_button_devices) {
button.reset();
}
for (auto& stick : tas_stick_devices) {
stick.reset();
}
} }
void EmulatedController::EnableConfiguration() { void EmulatedController::EnableConfiguration() {

View File

@ -299,6 +299,9 @@ private:
/// creates input devices from params /// creates input devices from params
void LoadDevices(); void LoadDevices();
/// Set the params for TAS devices
void LoadTASParams();
/** /**
* Updates the button status of the controller * Updates the button status of the controller
* @param callback: A CallbackStatus containing the button status * @param callback: A CallbackStatus containing the button status
@ -363,6 +366,12 @@ private:
BatteryDevices battery_devices; BatteryDevices battery_devices;
OutputDevices output_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; mutable std::mutex mutex;
std::unordered_map<int, ControllerUpdateCallback> callback_list; std::unordered_map<int, ControllerUpdateCallback> callback_list;
int last_callback_key = 0; int last_callback_key = 0;

View File

@ -573,7 +573,6 @@ void Config::ReadControlValues() {
ReadBasicSetting(Settings::values.tas_enable); ReadBasicSetting(Settings::values.tas_enable);
ReadBasicSetting(Settings::values.tas_loop); ReadBasicSetting(Settings::values.tas_loop);
ReadBasicSetting(Settings::values.tas_swap_controllers);
ReadBasicSetting(Settings::values.pause_tas_on_load); ReadBasicSetting(Settings::values.pause_tas_on_load);
ReadGlobalSetting(Settings::values.use_docked_mode); ReadGlobalSetting(Settings::values.use_docked_mode);
@ -1209,7 +1208,6 @@ void Config::SaveControlValues() {
WriteBasicSetting(Settings::values.tas_enable); WriteBasicSetting(Settings::values.tas_enable);
WriteBasicSetting(Settings::values.tas_loop); WriteBasicSetting(Settings::values.tas_loop);
WriteBasicSetting(Settings::values.tas_swap_controllers);
WriteBasicSetting(Settings::values.pause_tas_on_load); WriteBasicSetting(Settings::values.pause_tas_on_load);
qt_config->endGroup(); qt_config->endGroup();

View File

@ -32,7 +32,6 @@ void ConfigureTasDialog::LoadConfiguration() {
ui->tas_path_edit->setText( ui->tas_path_edit->setText(
QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::TASDir))); QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::TASDir)));
ui->tas_enable->setChecked(Settings::values.tas_enable.GetValue()); 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_loop_script->setChecked(Settings::values.tas_loop.GetValue());
ui->tas_pause_on_load->setChecked(Settings::values.pause_tas_on_load.GetValue()); ui->tas_pause_on_load->setChecked(Settings::values.pause_tas_on_load.GetValue());
} }
@ -40,7 +39,6 @@ void ConfigureTasDialog::LoadConfiguration() {
void ConfigureTasDialog::ApplyConfiguration() { void ConfigureTasDialog::ApplyConfiguration() {
Common::FS::SetYuzuPath(Common::FS::YuzuPath::TASDir, ui->tas_path_edit->text().toStdString()); 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_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.tas_loop.SetValue(ui->tas_loop_script->isChecked());
Settings::values.pause_tas_on_load.SetValue(ui->tas_pause_on_load->isChecked()); Settings::values.pause_tas_on_load.SetValue(ui->tas_pause_on_load->isChecked());
} }

View File

@ -59,20 +59,13 @@
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="4"> <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"> <widget class="QCheckBox" name="tas_loop_script">
<property name="text"> <property name="text">
<string>Loop script</string> <string>Loop script</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="4"> <item row="2" column="0" colspan="4">
<widget class="QCheckBox" name="tas_pause_on_load"> <widget class="QCheckBox" name="tas_pause_on_load">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>