summaryrefslogtreecommitdiff
path: root/src/core/hid/input_interpreter.cpp
diff options
context:
space:
mode:
authorGravatar Narr the Reg2024-01-04 20:37:43 -0600
committerGravatar Narr the Reg2024-01-05 11:41:15 -0600
commitee847f8ff0b1b0aec39c1b78c010bc0c08a0a613 (patch)
tree3b95cbb74be05f0ce7a007353f1f9f95e1ed3901 /src/core/hid/input_interpreter.cpp
parentMerge pull request #12437 from ameerj/gl-amd-fixes (diff)
downloadyuzu-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.cpp')
-rw-r--r--src/core/hid/input_interpreter.cpp64
1 files changed, 0 insertions, 64 deletions
diff --git a/src/core/hid/input_interpreter.cpp b/src/core/hid/input_interpreter.cpp
deleted file mode 100644
index 072f38a68..000000000
--- a/src/core/hid/input_interpreter.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include "core/core.h"
5#include "core/hid/hid_types.h"
6#include "core/hid/input_interpreter.h"
7#include "core/hle/service/hid/controllers/npad.h"
8#include "core/hle/service/hid/hid_server.h"
9#include "core/hle/service/hid/resource_manager.h"
10#include "core/hle/service/sm/sm.h"
11
12InputInterpreter::InputInterpreter(Core::System& system)
13 : npad{system.ServiceManager()
14 .GetService<Service::HID::IHidServer>("hid")
15 ->GetResourceManager()
16 ->GetNpad()} {
17 ResetButtonStates();
18}
19
20InputInterpreter::~InputInterpreter() = default;
21
22void InputInterpreter::PollInput() {
23 if (npad == nullptr) {
24 return;
25 }
26 const auto button_state = npad->GetAndResetPressState();
27
28 previous_index = current_index;
29 current_index = (current_index + 1) % button_states.size();
30
31 button_states[current_index] = button_state;
32}
33
34void InputInterpreter::ResetButtonStates() {
35 previous_index = 0;
36 current_index = 0;
37
38 button_states[0] = Core::HID::NpadButton::All;
39
40 for (std::size_t i = 1; i < button_states.size(); ++i) {
41 button_states[i] = Core::HID::NpadButton::None;
42 }
43}
44
45bool InputInterpreter::IsButtonPressed(Core::HID::NpadButton button) const {
46 return True(button_states[current_index] & button);
47}
48
49bool InputInterpreter::IsButtonPressedOnce(Core::HID::NpadButton button) const {
50 const bool current_press = True(button_states[current_index] & button);
51 const bool previous_press = True(button_states[previous_index] & button);
52
53 return current_press && !previous_press;
54}
55
56bool InputInterpreter::IsButtonHeld(Core::HID::NpadButton button) const {
57 Core::HID::NpadButton held_buttons{button_states[0]};
58
59 for (std::size_t i = 1; i < button_states.size(); ++i) {
60 held_buttons &= button_states[i];
61 }
62
63 return True(held_buttons & button);
64}