diff options
| author | 2021-10-30 12:12:52 -0500 | |
|---|---|---|
| committer | 2021-11-24 20:30:26 -0600 | |
| commit | 5f69fdbfccdf68ddb5bb22de32321fa352b22c0a (patch) | |
| tree | 30e760b02a4be5def57075563c5bb684067538ef | |
| parent | input_common: Fix GC adapter initialization (diff) | |
| download | yuzu-5f69fdbfccdf68ddb5bb22de32321fa352b22c0a.tar.gz yuzu-5f69fdbfccdf68ddb5bb22de32321fa352b22c0a.tar.xz yuzu-5f69fdbfccdf68ddb5bb22de32321fa352b22c0a.zip | |
core/hid: Explain better what a temporary value does
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 38 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 14 |
2 files changed, 28 insertions, 24 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 2b051ccaf..3c3fa16d6 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -88,8 +88,9 @@ void EmulatedController::ReloadFromSettings() { | |||
| 88 | ReloadInput(); | 88 | ReloadInput(); |
| 89 | } | 89 | } |
| 90 | void EmulatedController::LoadDevices() { | 90 | void EmulatedController::LoadDevices() { |
| 91 | const auto left_joycon = button_params[Settings::NativeButton::ZL]; | 91 | // TODO(german77): Use more buttons to detect the correct device |
| 92 | const auto right_joycon = button_params[Settings::NativeButton::ZR]; | 92 | const auto left_joycon = button_params[Settings::NativeButton::A]; |
| 93 | const auto right_joycon = button_params[Settings::NativeButton::DRight]; | ||
| 93 | 94 | ||
| 94 | // Triggers for GC controllers | 95 | // Triggers for GC controllers |
| 95 | trigger_params[LeftIndex] = button_params[Settings::NativeButton::ZL]; | 96 | trigger_params[LeftIndex] = button_params[Settings::NativeButton::ZL]; |
| @@ -142,6 +143,7 @@ void EmulatedController::LoadTASParams() { | |||
| 142 | param = common_params; | 143 | param = common_params; |
| 143 | } | 144 | } |
| 144 | 145 | ||
| 146 | // TODO(german77): Replace this with an input profile or something better | ||
| 145 | tas_button_params[Settings::NativeButton::A].Set("button", 1 << 0); | 147 | tas_button_params[Settings::NativeButton::A].Set("button", 1 << 0); |
| 146 | tas_button_params[Settings::NativeButton::B].Set("button", 1 << 1); | 148 | tas_button_params[Settings::NativeButton::B].Set("button", 1 << 1); |
| 147 | tas_button_params[Settings::NativeButton::X].Set("button", 1 << 2); | 149 | tas_button_params[Settings::NativeButton::X].Set("button", 1 << 2); |
| @@ -271,24 +273,24 @@ void EmulatedController::UnloadInput() { | |||
| 271 | 273 | ||
| 272 | void EmulatedController::EnableConfiguration() { | 274 | void EmulatedController::EnableConfiguration() { |
| 273 | is_configuring = true; | 275 | is_configuring = true; |
| 274 | temporary_is_connected = is_connected; | 276 | tmp_is_connected = is_connected; |
| 275 | temporary_npad_type = npad_type; | 277 | tmp_npad_type = npad_type; |
| 276 | } | 278 | } |
| 277 | 279 | ||
| 278 | void EmulatedController::DisableConfiguration() { | 280 | void EmulatedController::DisableConfiguration() { |
| 279 | is_configuring = false; | 281 | is_configuring = false; |
| 280 | 282 | ||
| 281 | // Apply temporary npad type to the real controller | 283 | // Apply temporary npad type to the real controller |
| 282 | if (temporary_npad_type != npad_type) { | 284 | if (tmp_npad_type != npad_type) { |
| 283 | if (is_connected) { | 285 | if (is_connected) { |
| 284 | Disconnect(); | 286 | Disconnect(); |
| 285 | } | 287 | } |
| 286 | SetNpadType(temporary_npad_type); | 288 | SetNpadType(tmp_npad_type); |
| 287 | } | 289 | } |
| 288 | 290 | ||
| 289 | // Apply temporary connected status to the real controller | 291 | // Apply temporary connected status to the real controller |
| 290 | if (temporary_is_connected != is_connected) { | 292 | if (tmp_is_connected != is_connected) { |
| 291 | if (temporary_is_connected) { | 293 | if (tmp_is_connected) { |
| 292 | Connect(); | 294 | Connect(); |
| 293 | return; | 295 | return; |
| 294 | } | 296 | } |
| @@ -791,7 +793,7 @@ void EmulatedController::Connect() { | |||
| 791 | { | 793 | { |
| 792 | std::lock_guard lock{mutex}; | 794 | std::lock_guard lock{mutex}; |
| 793 | if (is_configuring) { | 795 | if (is_configuring) { |
| 794 | temporary_is_connected = true; | 796 | tmp_is_connected = true; |
| 795 | TriggerOnChange(ControllerTriggerType::Connected, false); | 797 | TriggerOnChange(ControllerTriggerType::Connected, false); |
| 796 | return; | 798 | return; |
| 797 | } | 799 | } |
| @@ -808,7 +810,7 @@ void EmulatedController::Disconnect() { | |||
| 808 | { | 810 | { |
| 809 | std::lock_guard lock{mutex}; | 811 | std::lock_guard lock{mutex}; |
| 810 | if (is_configuring) { | 812 | if (is_configuring) { |
| 811 | temporary_is_connected = false; | 813 | tmp_is_connected = false; |
| 812 | TriggerOnChange(ControllerTriggerType::Disconnected, false); | 814 | TriggerOnChange(ControllerTriggerType::Disconnected, false); |
| 813 | return; | 815 | return; |
| 814 | } | 816 | } |
| @@ -821,9 +823,9 @@ void EmulatedController::Disconnect() { | |||
| 821 | TriggerOnChange(ControllerTriggerType::Disconnected, true); | 823 | TriggerOnChange(ControllerTriggerType::Disconnected, true); |
| 822 | } | 824 | } |
| 823 | 825 | ||
| 824 | bool EmulatedController::IsConnected(bool temporary) const { | 826 | bool EmulatedController::IsConnected(bool get_temporary_value) const { |
| 825 | if (temporary) { | 827 | if (get_temporary_value) { |
| 826 | return temporary_is_connected; | 828 | return tmp_is_connected; |
| 827 | } | 829 | } |
| 828 | return is_connected; | 830 | return is_connected; |
| 829 | } | 831 | } |
| @@ -838,9 +840,9 @@ NpadIdType EmulatedController::GetNpadIdType() const { | |||
| 838 | return npad_id_type; | 840 | return npad_id_type; |
| 839 | } | 841 | } |
| 840 | 842 | ||
| 841 | NpadType EmulatedController::GetNpadType(bool temporary) const { | 843 | NpadType EmulatedController::GetNpadType(bool get_temporary_value) const { |
| 842 | if (temporary) { | 844 | if (get_temporary_value) { |
| 843 | return temporary_npad_type; | 845 | return tmp_npad_type; |
| 844 | } | 846 | } |
| 845 | return npad_type; | 847 | return npad_type; |
| 846 | } | 848 | } |
| @@ -850,10 +852,10 @@ void EmulatedController::SetNpadType(NpadType npad_type_) { | |||
| 850 | std::lock_guard lock{mutex}; | 852 | std::lock_guard lock{mutex}; |
| 851 | 853 | ||
| 852 | if (is_configuring) { | 854 | if (is_configuring) { |
| 853 | if (temporary_npad_type == npad_type_) { | 855 | if (tmp_npad_type == npad_type_) { |
| 854 | return; | 856 | return; |
| 855 | } | 857 | } |
| 856 | temporary_npad_type = npad_type_; | 858 | tmp_npad_type = npad_type_; |
| 857 | TriggerOnChange(ControllerTriggerType::Type, false); | 859 | TriggerOnChange(ControllerTriggerType::Type, false); |
| 858 | return; | 860 | return; |
| 859 | } | 861 | } |
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index eec51e34a..fea401365 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -149,10 +149,10 @@ public: | |||
| 149 | 149 | ||
| 150 | /** | 150 | /** |
| 151 | * Gets the NpadType for this controller | 151 | * Gets the NpadType for this controller |
| 152 | * @param Returns the temporary value if true | 152 | * @param If true tmp_npad_type will be returned |
| 153 | * @return NpadType set on the controller | 153 | * @return NpadType set on the controller |
| 154 | */ | 154 | */ |
| 155 | NpadType GetNpadType(bool temporary = false) const; | 155 | NpadType GetNpadType(bool get_temporary_value = false) const; |
| 156 | 156 | ||
| 157 | /// Sets the connected status to true | 157 | /// Sets the connected status to true |
| 158 | void Connect(); | 158 | void Connect(); |
| @@ -162,10 +162,10 @@ public: | |||
| 162 | 162 | ||
| 163 | /** | 163 | /** |
| 164 | * Is the emulated connected | 164 | * Is the emulated connected |
| 165 | * @param Returns the temporary value if true | 165 | * @param If true tmp_is_connected will be returned |
| 166 | * @return true if the controller has the connected status | 166 | * @return true if the controller has the connected status |
| 167 | */ | 167 | */ |
| 168 | bool IsConnected(bool temporary = false) const; | 168 | bool IsConnected(bool get_temporary_value = false) const; |
| 169 | 169 | ||
| 170 | /// Returns true if vibration is enabled | 170 | /// Returns true if vibration is enabled |
| 171 | bool IsVibrationEnabled() const; | 171 | bool IsVibrationEnabled() const; |
| @@ -346,12 +346,14 @@ private: | |||
| 346 | 346 | ||
| 347 | NpadIdType npad_id_type; | 347 | NpadIdType npad_id_type; |
| 348 | NpadType npad_type{NpadType::None}; | 348 | NpadType npad_type{NpadType::None}; |
| 349 | NpadType temporary_npad_type{NpadType::None}; | ||
| 350 | bool is_connected{false}; | 349 | bool is_connected{false}; |
| 351 | bool temporary_is_connected{false}; | ||
| 352 | bool is_configuring{false}; | 350 | bool is_configuring{false}; |
| 353 | f32 motion_sensitivity{0.01f}; | 351 | f32 motion_sensitivity{0.01f}; |
| 354 | 352 | ||
| 353 | // Temporary values to avoid doing changes while the controller is on configuration mode | ||
| 354 | NpadType tmp_npad_type{NpadType::None}; | ||
| 355 | bool tmp_is_connected{false}; | ||
| 356 | |||
| 355 | ButtonParams button_params; | 357 | ButtonParams button_params; |
| 356 | StickParams stick_params; | 358 | StickParams stick_params; |
| 357 | ControllerMotionParams motion_params; | 359 | ControllerMotionParams motion_params; |