diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2025-01-29 02:02:46 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2025-02-01 01:54:10 -0600 |
| commit | 6e7e808b6614f98674dba7290bea2ea044c4d5d2 (patch) | |
| tree | 1057bab0dbecfea831f2532f0756de8695851e9d /Source/Core/InputCommon | |
| parent | cd3993708f25ecbfb62eea9cdd8279bc002a01d1 (diff) | |
DolphinQt/Mapping: Add setting to enable waiting for alternate mappings
using the OR-operator.
Diffstat (limited to 'Source/Core/InputCommon')
4 files changed, 36 insertions, 17 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp b/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp index b9141658e6..3a29d4c98f 100644 --- a/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp +++ b/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp @@ -491,7 +491,7 @@ void InputDetector::Update(std::chrono::milliseconds initial_wait, Detection new_detection; new_detection.device = device_state.device; new_detection.input = input_state.input; - new_detection.press_time = Clock::now(); + new_detection.press_time = now; new_detection.smoothness = smoothness; // We found an input. Add it to our detections. @@ -516,12 +516,12 @@ bool InputDetector::IsComplete() const return !m_state; } -auto InputDetector::GetResults() const -> const std::vector<Detection>& +auto InputDetector::GetResults() const -> const Results& { return m_detections; } -auto InputDetector::TakeResults() -> std::vector<Detection> +auto InputDetector::TakeResults() -> Results { return std::move(m_detections); } diff --git a/Source/Core/InputCommon/ControllerInterface/CoreDevice.h b/Source/Core/InputCommon/ControllerInterface/CoreDevice.h index 0370fce894..92f53df9fa 100644 --- a/Source/Core/InputCommon/ControllerInterface/CoreDevice.h +++ b/Source/Core/InputCommon/ControllerInterface/CoreDevice.h @@ -250,6 +250,7 @@ class InputDetector { public: using Detection = DeviceContainer::InputDetection; + using Results = std::vector<Detection>; InputDetector(); ~InputDetector(); @@ -259,16 +260,16 @@ public: std::chrono::milliseconds maximum_wait); bool IsComplete() const; - const std::vector<Detection>& GetResults() const; + const Results& GetResults() const; // move-return'd to prevent copying. - std::vector<Detection> TakeResults(); + Results TakeResults(); private: struct Impl; Clock::time_point m_start_time; - std::vector<Detection> m_detections; + Results m_detections; std::unique_ptr<Impl> m_state; }; diff --git a/Source/Core/InputCommon/ControllerInterface/MappingCommon.cpp b/Source/Core/InputCommon/ControllerInterface/MappingCommon.cpp index cb06a7ed30..3765ef24a6 100644 --- a/Source/Core/InputCommon/ControllerInterface/MappingCommon.cpp +++ b/Source/Core/InputCommon/ControllerInterface/MappingCommon.cpp @@ -51,11 +51,10 @@ std::string GetExpressionForControl(const std::string& control_name, return expr; } -std::string -BuildExpression(const std::vector<ciface::Core::DeviceContainer::InputDetection>& detections, - const ciface::Core::DeviceQualifier& default_device, Quote quote) +std::string BuildExpression(const Core::InputDetector::Results& detections, + const ciface::Core::DeviceQualifier& default_device, Quote quote) { - std::vector<const ciface::Core::DeviceContainer::InputDetection*> pressed_inputs; + std::vector<const Core::InputDetector::Detection*> pressed_inputs; std::vector<std::string> alternations; @@ -135,8 +134,7 @@ BuildExpression(const std::vector<ciface::Core::DeviceContainer::InputDetection> return fmt::to_string(fmt::join(alternations, "|")); } -void RemoveSpuriousTriggerCombinations( - std::vector<ciface::Core::DeviceContainer::InputDetection>* detections) +void RemoveSpuriousTriggerCombinations(Core::InputDetector::Results* detections) { const auto is_spurious = [&](const auto& detection) { return std::ranges::any_of(*detections, [&](const auto& d) { @@ -149,4 +147,21 @@ void RemoveSpuriousTriggerCombinations( std::erase_if(*detections, is_spurious); } +void RemoveDetectionsAfterTimePoint(Core::InputDetector::Results* results, + Core::DeviceContainer::Clock::time_point after) +{ + const auto is_after_time = [&](const Core::InputDetector::Detection& detection) { + return detection.release_time.value_or(after) >= after; + }; + + std::erase_if(*results, is_after_time); +} + +bool ContainsCompleteDetection(const Core::InputDetector::Results& results) +{ + return std::ranges::any_of(results, [](const Core::InputDetector::Detection& detection) { + return detection.release_time.has_value(); + }); +} + } // namespace ciface::MappingCommon diff --git a/Source/Core/InputCommon/ControllerInterface/MappingCommon.h b/Source/Core/InputCommon/ControllerInterface/MappingCommon.h index 1822125557..f58813a50c 100644 --- a/Source/Core/InputCommon/ControllerInterface/MappingCommon.h +++ b/Source/Core/InputCommon/ControllerInterface/MappingCommon.h @@ -17,13 +17,16 @@ enum class Quote }; std::string GetExpressionForControl(const std::string& control_name, - const ciface::Core::DeviceQualifier& control_device, - const ciface::Core::DeviceQualifier& default_device, + const Core::DeviceQualifier& control_device, + const Core::DeviceQualifier& default_device, Quote quote = Quote::On); -std::string BuildExpression(const std::vector<ciface::Core::DeviceContainer::InputDetection>&, - const ciface::Core::DeviceQualifier& default_device, Quote quote); +std::string BuildExpression(const Core::InputDetector::Results&, + const Core::DeviceQualifier& default_device, Quote quote); -void RemoveSpuriousTriggerCombinations(std::vector<ciface::Core::DeviceContainer::InputDetection>*); +void RemoveSpuriousTriggerCombinations(Core::InputDetector::Results*); +void RemoveDetectionsAfterTimePoint(Core::InputDetector::Results*, + Core::DeviceContainer::Clock::time_point after); +bool ContainsCompleteDetection(const Core::InputDetector::Results&); } // namespace ciface::MappingCommon |
