diff options
| author | 2024-01-04 20:37:43 -0600 | |
|---|---|---|
| committer | 2024-01-05 11:41:15 -0600 | |
| commit | ee847f8ff0b1b0aec39c1b78c010bc0c08a0a613 (patch) | |
| tree | 3b95cbb74be05f0ce7a007353f1f9f95e1ed3901 /src/core/hid/input_interpreter.h | |
| parent | Merge pull request #12437 from ameerj/gl-amd-fixes (diff) | |
| download | yuzu-ee847f8ff0b1b0aec39c1b78c010bc0c08a0a613.tar.gz yuzu-ee847f8ff0b1b0aec39c1b78c010bc0c08a0a613.tar.xz yuzu-ee847f8ff0b1b0aec39c1b78c010bc0c08a0a613.zip | |
hid_core: Move hid to it's own subproject
Diffstat (limited to 'src/core/hid/input_interpreter.h')
| -rw-r--r-- | src/core/hid/input_interpreter.h | 111 |
1 files changed, 0 insertions, 111 deletions
diff --git a/src/core/hid/input_interpreter.h b/src/core/hid/input_interpreter.h deleted file mode 100644 index 3569aac93..000000000 --- a/src/core/hid/input_interpreter.h +++ /dev/null | |||
| @@ -1,111 +0,0 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <array> | ||
| 7 | |||
| 8 | #include "common/common_types.h" | ||
| 9 | |||
| 10 | namespace Core { | ||
| 11 | class System; | ||
| 12 | } | ||
| 13 | |||
| 14 | namespace Core::HID { | ||
| 15 | enum class NpadButton : u64; | ||
| 16 | } | ||
| 17 | |||
| 18 | namespace Service::HID { | ||
| 19 | class NPad; | ||
| 20 | } | ||
| 21 | |||
| 22 | /** | ||
| 23 | * The InputInterpreter class interfaces with HID to retrieve button press states. | ||
| 24 | * Input is intended to be polled every 50ms so that a button is considered to be | ||
| 25 | * held down after 400ms has elapsed since the initial button press and subsequent | ||
| 26 | * repeated presses occur every 50ms. | ||
| 27 | */ | ||
| 28 | class InputInterpreter { | ||
| 29 | public: | ||
| 30 | explicit InputInterpreter(Core::System& system); | ||
| 31 | virtual ~InputInterpreter(); | ||
| 32 | |||
| 33 | /// Gets a button state from HID and inserts it into the array of button states. | ||
| 34 | void PollInput(); | ||
| 35 | |||
| 36 | /// Resets all the button states to their defaults. | ||
| 37 | void ResetButtonStates(); | ||
| 38 | |||
| 39 | /** | ||
| 40 | * Checks whether the button is pressed. | ||
| 41 | * | ||
| 42 | * @param button The button to check. | ||
| 43 | * | ||
| 44 | * @returns True when the button is pressed. | ||
| 45 | */ | ||
| 46 | [[nodiscard]] bool IsButtonPressed(Core::HID::NpadButton button) const; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * Checks whether any of the buttons in the parameter list is pressed. | ||
| 50 | * | ||
| 51 | * @tparam HIDButton The buttons to check. | ||
| 52 | * | ||
| 53 | * @returns True when at least one of the buttons is pressed. | ||
| 54 | */ | ||
| 55 | template <Core::HID::NpadButton... T> | ||
| 56 | [[nodiscard]] bool IsAnyButtonPressed() { | ||
| 57 | return (IsButtonPressed(T) || ...); | ||
| 58 | } | ||
| 59 | |||
| 60 | /** | ||
| 61 | * The specified button is considered to be pressed once | ||
| 62 | * if it is currently pressed and not pressed previously. | ||
| 63 | * | ||
| 64 | * @param button The button to check. | ||
| 65 | * | ||
| 66 | * @returns True when the button is pressed once. | ||
| 67 | */ | ||
| 68 | [[nodiscard]] bool IsButtonPressedOnce(Core::HID::NpadButton button) const; | ||
| 69 | |||
| 70 | /** | ||
| 71 | * Checks whether any of the buttons in the parameter list is pressed once. | ||
| 72 | * | ||
| 73 | * @tparam T The buttons to check. | ||
| 74 | * | ||
| 75 | * @returns True when at least one of the buttons is pressed once. | ||
| 76 | */ | ||
| 77 | template <Core::HID::NpadButton... T> | ||
| 78 | [[nodiscard]] bool IsAnyButtonPressedOnce() const { | ||
| 79 | return (IsButtonPressedOnce(T) || ...); | ||
| 80 | } | ||
| 81 | |||
| 82 | /** | ||
| 83 | * The specified button is considered to be held down if it is pressed in all 9 button states. | ||
| 84 | * | ||
| 85 | * @param button The button to check. | ||
| 86 | * | ||
| 87 | * @returns True when the button is held down. | ||
| 88 | */ | ||
| 89 | [[nodiscard]] bool IsButtonHeld(Core::HID::NpadButton button) const; | ||
| 90 | |||
| 91 | /** | ||
| 92 | * Checks whether any of the buttons in the parameter list is held down. | ||
| 93 | * | ||
| 94 | * @tparam T The buttons to check. | ||
| 95 | * | ||
| 96 | * @returns True when at least one of the buttons is held down. | ||
| 97 | */ | ||
| 98 | template <Core::HID::NpadButton... T> | ||
| 99 | [[nodiscard]] bool IsAnyButtonHeld() const { | ||
| 100 | return (IsButtonHeld(T) || ...); | ||
| 101 | } | ||
| 102 | |||
| 103 | private: | ||
| 104 | std::shared_ptr<Service::HID::NPad> npad; | ||
| 105 | |||
| 106 | /// Stores 9 consecutive button states polled from HID. | ||
| 107 | std::array<Core::HID::NpadButton, 9> button_states{}; | ||
| 108 | |||
| 109 | std::size_t previous_index{}; | ||
| 110 | std::size_t current_index{}; | ||
| 111 | }; | ||