diff options
| author | 2022-01-25 16:15:45 -0500 | |
|---|---|---|
| committer | 2022-01-25 16:15:45 -0500 | |
| commit | 432f4441b9420778970d9846750ff1458e6aaa03 (patch) | |
| tree | 3b500254540c0df824342b8f7dd737931ce446ab | |
| parent | Merge pull request #7773 from lioncash/udp-deprecated (diff) | |
| parent | input_common/input_engine: Ensure PadIdentifier UUIDs have a valid initial state (diff) | |
| download | yuzu-432f4441b9420778970d9846750ff1458e6aaa03.tar.gz yuzu-432f4441b9420778970d9846750ff1458e6aaa03.tar.xz yuzu-432f4441b9420778970d9846750ff1458e6aaa03.zip | |
Merge pull request #7774 from lioncash/mapping
input_common/main: Pass MappingData by const reference in callbacks
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/input_engine.h | 4 | ||||
| -rw-r--r-- | src/input_common/input_mapping.cpp | 11 | ||||
| -rw-r--r-- | src/input_common/input_mapping.h | 8 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 6 | ||||
| -rw-r--r-- | src/input_common/main.h | 2 |
5 files changed, 18 insertions, 13 deletions
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h index 390581c94..fe2faee5a 100644 --- a/src/input_common/input_engine.h +++ b/src/input_common/input_engine.h | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | // Pad Identifier of data source | 17 | // Pad Identifier of data source |
| 18 | struct PadIdentifier { | 18 | struct PadIdentifier { |
| 19 | Common::UUID guid{}; | 19 | Common::UUID guid{Common::INVALID_UUID}; |
| 20 | std::size_t port{}; | 20 | std::size_t port{}; |
| 21 | std::size_t pad{}; | 21 | std::size_t pad{}; |
| 22 | 22 | ||
| @@ -89,7 +89,7 @@ struct UpdateCallback { | |||
| 89 | 89 | ||
| 90 | // Triggered if data changed on the controller and the engine is on configuring mode | 90 | // Triggered if data changed on the controller and the engine is on configuring mode |
| 91 | struct MappingCallback { | 91 | struct MappingCallback { |
| 92 | std::function<void(MappingData)> on_data; | 92 | std::function<void(const MappingData&)> on_data; |
| 93 | }; | 93 | }; |
| 94 | 94 | ||
| 95 | // Input Identifier of data source | 95 | // Input Identifier of data source |
diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp index 475257f42..a7a6ad8c2 100644 --- a/src/input_common/input_mapping.cpp +++ b/src/input_common/input_mapping.cpp | |||
| @@ -2,14 +2,13 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included | 3 | // Refer to the license.txt file included |
| 4 | 4 | ||
| 5 | #include "common/common_types.h" | ||
| 6 | #include "common/settings.h" | 5 | #include "common/settings.h" |
| 7 | #include "input_common/input_engine.h" | 6 | #include "input_common/input_engine.h" |
| 8 | #include "input_common/input_mapping.h" | 7 | #include "input_common/input_mapping.h" |
| 9 | 8 | ||
| 10 | namespace InputCommon { | 9 | namespace InputCommon { |
| 11 | 10 | ||
| 12 | MappingFactory::MappingFactory() {} | 11 | MappingFactory::MappingFactory() = default; |
| 13 | 12 | ||
| 14 | void MappingFactory::BeginMapping(Polling::InputType type) { | 13 | void MappingFactory::BeginMapping(Polling::InputType type) { |
| 15 | is_enabled = true; | 14 | is_enabled = true; |
| @@ -19,7 +18,7 @@ void MappingFactory::BeginMapping(Polling::InputType type) { | |||
| 19 | second_axis = -1; | 18 | second_axis = -1; |
| 20 | } | 19 | } |
| 21 | 20 | ||
| 22 | [[nodiscard]] const Common::ParamPackage MappingFactory::GetNextInput() { | 21 | Common::ParamPackage MappingFactory::GetNextInput() { |
| 23 | Common::ParamPackage input; | 22 | Common::ParamPackage input; |
| 24 | input_queue.Pop(input); | 23 | input_queue.Pop(input); |
| 25 | return input; | 24 | return input; |
| @@ -57,7 +56,7 @@ void MappingFactory::StopMapping() { | |||
| 57 | void MappingFactory::RegisterButton(const MappingData& data) { | 56 | void MappingFactory::RegisterButton(const MappingData& data) { |
| 58 | Common::ParamPackage new_input; | 57 | Common::ParamPackage new_input; |
| 59 | new_input.Set("engine", data.engine); | 58 | new_input.Set("engine", data.engine); |
| 60 | if (data.pad.guid != Common::UUID{}) { | 59 | if (data.pad.guid.IsValid()) { |
| 61 | new_input.Set("guid", data.pad.guid.Format()); | 60 | new_input.Set("guid", data.pad.guid.Format()); |
| 62 | } | 61 | } |
| 63 | new_input.Set("port", static_cast<int>(data.pad.port)); | 62 | new_input.Set("port", static_cast<int>(data.pad.port)); |
| @@ -93,7 +92,7 @@ void MappingFactory::RegisterButton(const MappingData& data) { | |||
| 93 | void MappingFactory::RegisterStick(const MappingData& data) { | 92 | void MappingFactory::RegisterStick(const MappingData& data) { |
| 94 | Common::ParamPackage new_input; | 93 | Common::ParamPackage new_input; |
| 95 | new_input.Set("engine", data.engine); | 94 | new_input.Set("engine", data.engine); |
| 96 | if (data.pad.guid != Common::UUID{}) { | 95 | if (data.pad.guid.IsValid()) { |
| 97 | new_input.Set("guid", data.pad.guid.Format()); | 96 | new_input.Set("guid", data.pad.guid.Format()); |
| 98 | } | 97 | } |
| 99 | new_input.Set("port", static_cast<int>(data.pad.port)); | 98 | new_input.Set("port", static_cast<int>(data.pad.port)); |
| @@ -138,7 +137,7 @@ void MappingFactory::RegisterStick(const MappingData& data) { | |||
| 138 | void MappingFactory::RegisterMotion(const MappingData& data) { | 137 | void MappingFactory::RegisterMotion(const MappingData& data) { |
| 139 | Common::ParamPackage new_input; | 138 | Common::ParamPackage new_input; |
| 140 | new_input.Set("engine", data.engine); | 139 | new_input.Set("engine", data.engine); |
| 141 | if (data.pad.guid != Common::UUID{}) { | 140 | if (data.pad.guid.IsValid()) { |
| 142 | new_input.Set("guid", data.pad.guid.Format()); | 141 | new_input.Set("guid", data.pad.guid.Format()); |
| 143 | } | 142 | } |
| 144 | new_input.Set("port", static_cast<int>(data.pad.port)); | 143 | new_input.Set("port", static_cast<int>(data.pad.port)); |
diff --git a/src/input_common/input_mapping.h b/src/input_common/input_mapping.h index 93564b5f8..e0dfbc7ad 100644 --- a/src/input_common/input_mapping.h +++ b/src/input_common/input_mapping.h | |||
| @@ -3,8 +3,14 @@ | |||
| 3 | // Refer to the license.txt file included | 3 | // Refer to the license.txt file included |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 7 | #include "common/param_package.h" | ||
| 6 | #include "common/threadsafe_queue.h" | 8 | #include "common/threadsafe_queue.h" |
| 7 | 9 | ||
| 10 | namespace InputCommon::Polling { | ||
| 11 | enum class InputType; | ||
| 12 | } | ||
| 13 | |||
| 8 | namespace InputCommon { | 14 | namespace InputCommon { |
| 9 | class InputEngine; | 15 | class InputEngine; |
| 10 | struct MappingData; | 16 | struct MappingData; |
| @@ -20,7 +26,7 @@ public: | |||
| 20 | void BeginMapping(Polling::InputType type); | 26 | void BeginMapping(Polling::InputType type); |
| 21 | 27 | ||
| 22 | /// Returns an input event with mapping information from the input_queue | 28 | /// Returns an input event with mapping information from the input_queue |
| 23 | [[nodiscard]] const Common::ParamPackage GetNextInput(); | 29 | [[nodiscard]] Common::ParamPackage GetNextInput(); |
| 24 | 30 | ||
| 25 | /** | 31 | /** |
| 26 | * Registers mapping input data from the driver | 32 | * Registers mapping input data from the driver |
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 940744c5f..a4d7ed645 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -27,7 +27,7 @@ namespace InputCommon { | |||
| 27 | struct InputSubsystem::Impl { | 27 | struct InputSubsystem::Impl { |
| 28 | void Initialize() { | 28 | void Initialize() { |
| 29 | mapping_factory = std::make_shared<MappingFactory>(); | 29 | mapping_factory = std::make_shared<MappingFactory>(); |
| 30 | MappingCallback mapping_callback{[this](MappingData data) { RegisterInput(data); }}; | 30 | MappingCallback mapping_callback{[this](const MappingData& data) { RegisterInput(data); }}; |
| 31 | 31 | ||
| 32 | keyboard = std::make_shared<Keyboard>("keyboard"); | 32 | keyboard = std::make_shared<Keyboard>("keyboard"); |
| 33 | keyboard->SetMappingCallback(mapping_callback); | 33 | keyboard->SetMappingCallback(mapping_callback); |
| @@ -284,7 +284,7 @@ struct InputSubsystem::Impl { | |||
| 284 | #endif | 284 | #endif |
| 285 | } | 285 | } |
| 286 | 286 | ||
| 287 | void RegisterInput(MappingData data) { | 287 | void RegisterInput(const MappingData& data) { |
| 288 | mapping_factory->RegisterInput(data); | 288 | mapping_factory->RegisterInput(data); |
| 289 | } | 289 | } |
| 290 | 290 | ||
| @@ -394,7 +394,7 @@ void InputSubsystem::BeginMapping(Polling::InputType type) { | |||
| 394 | impl->mapping_factory->BeginMapping(type); | 394 | impl->mapping_factory->BeginMapping(type); |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | const Common::ParamPackage InputSubsystem::GetNextInput() const { | 397 | Common::ParamPackage InputSubsystem::GetNextInput() const { |
| 398 | return impl->mapping_factory->GetNextInput(); | 398 | return impl->mapping_factory->GetNextInput(); |
| 399 | } | 399 | } |
| 400 | 400 | ||
diff --git a/src/input_common/main.h b/src/input_common/main.h index c6f97f691..baf107e0f 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -126,7 +126,7 @@ public: | |||
| 126 | void BeginMapping(Polling::InputType type); | 126 | void BeginMapping(Polling::InputType type); |
| 127 | 127 | ||
| 128 | /// Returns an input event with mapping information. | 128 | /// Returns an input event with mapping information. |
| 129 | [[nodiscard]] const Common::ParamPackage GetNextInput() const; | 129 | [[nodiscard]] Common::ParamPackage GetNextInput() const; |
| 130 | 130 | ||
| 131 | /// Stop polling from all backends. | 131 | /// Stop polling from all backends. |
| 132 | void StopMapping() const; | 132 | void StopMapping() const; |