diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/input_engine.cpp | 20 | ||||
| -rw-r--r-- | src/input_common/input_engine.h | 18 |
2 files changed, 14 insertions, 24 deletions
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp index a4a07d4ac..9c17ca4f7 100644 --- a/src/input_common/input_engine.cpp +++ b/src/input_common/input_engine.cpp | |||
| @@ -10,41 +10,31 @@ namespace InputCommon { | |||
| 10 | 10 | ||
| 11 | void InputEngine::PreSetController(const PadIdentifier& identifier) { | 11 | void InputEngine::PreSetController(const PadIdentifier& identifier) { |
| 12 | std::lock_guard lock{mutex}; | 12 | std::lock_guard lock{mutex}; |
| 13 | if (!controller_list.contains(identifier)) { | 13 | controller_list.try_emplace(identifier); |
| 14 | controller_list.insert_or_assign(identifier, ControllerData{}); | ||
| 15 | } | ||
| 16 | } | 14 | } |
| 17 | 15 | ||
| 18 | void InputEngine::PreSetButton(const PadIdentifier& identifier, int button) { | 16 | void InputEngine::PreSetButton(const PadIdentifier& identifier, int button) { |
| 19 | std::lock_guard lock{mutex}; | 17 | std::lock_guard lock{mutex}; |
| 20 | ControllerData& controller = controller_list.at(identifier); | 18 | ControllerData& controller = controller_list.at(identifier); |
| 21 | if (!controller.buttons.contains(button)) { | 19 | controller.buttons.try_emplace(button, false); |
| 22 | controller.buttons.insert_or_assign(button, false); | ||
| 23 | } | ||
| 24 | } | 20 | } |
| 25 | 21 | ||
| 26 | void InputEngine::PreSetHatButton(const PadIdentifier& identifier, int button) { | 22 | void InputEngine::PreSetHatButton(const PadIdentifier& identifier, int button) { |
| 27 | std::lock_guard lock{mutex}; | 23 | std::lock_guard lock{mutex}; |
| 28 | ControllerData& controller = controller_list.at(identifier); | 24 | ControllerData& controller = controller_list.at(identifier); |
| 29 | if (!controller.hat_buttons.contains(button)) { | 25 | controller.hat_buttons.try_emplace(button, u8{0}); |
| 30 | controller.hat_buttons.insert_or_assign(button, u8{0}); | ||
| 31 | } | ||
| 32 | } | 26 | } |
| 33 | 27 | ||
| 34 | void InputEngine::PreSetAxis(const PadIdentifier& identifier, int axis) { | 28 | void InputEngine::PreSetAxis(const PadIdentifier& identifier, int axis) { |
| 35 | std::lock_guard lock{mutex}; | 29 | std::lock_guard lock{mutex}; |
| 36 | ControllerData& controller = controller_list.at(identifier); | 30 | ControllerData& controller = controller_list.at(identifier); |
| 37 | if (!controller.axes.contains(axis)) { | 31 | controller.axes.try_emplace(axis, 0.0f); |
| 38 | controller.axes.insert_or_assign(axis, 0.0f); | ||
| 39 | } | ||
| 40 | } | 32 | } |
| 41 | 33 | ||
| 42 | void InputEngine::PreSetMotion(const PadIdentifier& identifier, int motion) { | 34 | void InputEngine::PreSetMotion(const PadIdentifier& identifier, int motion) { |
| 43 | std::lock_guard lock{mutex}; | 35 | std::lock_guard lock{mutex}; |
| 44 | ControllerData& controller = controller_list.at(identifier); | 36 | ControllerData& controller = controller_list.at(identifier); |
| 45 | if (!controller.motions.contains(motion)) { | 37 | controller.motions.try_emplace(motion); |
| 46 | controller.motions.insert_or_assign(motion, BasicMotion{}); | ||
| 47 | } | ||
| 48 | } | 38 | } |
| 49 | 39 | ||
| 50 | void InputEngine::SetButton(const PadIdentifier& identifier, int button, bool value) { | 40 | void InputEngine::SetButton(const PadIdentifier& identifier, int button, bool value) { |
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h index 59707e173..ec8890484 100644 --- a/src/input_common/input_engine.h +++ b/src/input_common/input_engine.h | |||
| @@ -23,15 +23,15 @@ struct PadIdentifier { | |||
| 23 | friend constexpr bool operator==(const PadIdentifier&, const PadIdentifier&) = default; | 23 | friend constexpr bool operator==(const PadIdentifier&, const PadIdentifier&) = default; |
| 24 | }; | 24 | }; |
| 25 | 25 | ||
| 26 | // Basic motion data containing data from the sensors and a timestamp in microsecons | 26 | // Basic motion data containing data from the sensors and a timestamp in microseconds |
| 27 | struct BasicMotion { | 27 | struct BasicMotion { |
| 28 | float gyro_x; | 28 | float gyro_x{}; |
| 29 | float gyro_y; | 29 | float gyro_y{}; |
| 30 | float gyro_z; | 30 | float gyro_z{}; |
| 31 | float accel_x; | 31 | float accel_x{}; |
| 32 | float accel_y; | 32 | float accel_y{}; |
| 33 | float accel_z; | 33 | float accel_z{}; |
| 34 | u64 delta_timestamp; | 34 | u64 delta_timestamp{}; |
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| 37 | // Stages of a battery charge | 37 | // Stages of a battery charge |
| @@ -202,7 +202,7 @@ private: | |||
| 202 | std::unordered_map<int, u8> hat_buttons; | 202 | std::unordered_map<int, u8> hat_buttons; |
| 203 | std::unordered_map<int, float> axes; | 203 | std::unordered_map<int, float> axes; |
| 204 | std::unordered_map<int, BasicMotion> motions; | 204 | std::unordered_map<int, BasicMotion> motions; |
| 205 | BatteryLevel battery; | 205 | BatteryLevel battery{}; |
| 206 | }; | 206 | }; |
| 207 | 207 | ||
| 208 | void TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value); | 208 | void TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value); |