diff options
| -rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/common/point.h | 57 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/gesture.h | 36 |
3 files changed, 65 insertions, 29 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index eafb96b0b..7a4d9e354 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -154,6 +154,7 @@ add_library(common STATIC | |||
| 154 | param_package.cpp | 154 | param_package.cpp |
| 155 | param_package.h | 155 | param_package.h |
| 156 | parent_of_member.h | 156 | parent_of_member.h |
| 157 | point.h | ||
| 157 | quaternion.h | 158 | quaternion.h |
| 158 | ring_buffer.h | 159 | ring_buffer.h |
| 159 | scm_rev.cpp | 160 | scm_rev.cpp |
diff --git a/src/common/point.h b/src/common/point.h new file mode 100644 index 000000000..c0a52ad8d --- /dev/null +++ b/src/common/point.h | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <type_traits> | ||
| 8 | |||
| 9 | namespace Common { | ||
| 10 | |||
| 11 | // Represents a point within a 2D space. | ||
| 12 | template <typename T> | ||
| 13 | struct Point { | ||
| 14 | static_assert(std::is_arithmetic_v<T>, "T must be an arithmetic type!"); | ||
| 15 | |||
| 16 | T x{}; | ||
| 17 | T y{}; | ||
| 18 | |||
| 19 | #define ARITHMETIC_OP(op, compound_op) \ | ||
| 20 | friend constexpr Point operator op(const Point& lhs, const Point& rhs) noexcept { \ | ||
| 21 | return { \ | ||
| 22 | .x = static_cast<T>(lhs.x op rhs.x), \ | ||
| 23 | .y = static_cast<T>(lhs.y op rhs.y), \ | ||
| 24 | }; \ | ||
| 25 | } \ | ||
| 26 | friend constexpr Point operator op(const Point& lhs, T value) noexcept { \ | ||
| 27 | return { \ | ||
| 28 | .x = static_cast<T>(lhs.x op value), \ | ||
| 29 | .y = static_cast<T>(lhs.y op value), \ | ||
| 30 | }; \ | ||
| 31 | } \ | ||
| 32 | friend constexpr Point operator op(T value, const Point& rhs) noexcept { \ | ||
| 33 | return { \ | ||
| 34 | .x = static_cast<T>(value op rhs.x), \ | ||
| 35 | .y = static_cast<T>(value op rhs.y), \ | ||
| 36 | }; \ | ||
| 37 | } \ | ||
| 38 | friend constexpr Point& operator compound_op(Point& lhs, const Point& rhs) noexcept { \ | ||
| 39 | lhs.x = static_cast<T>(lhs.x op rhs.x); \ | ||
| 40 | lhs.y = static_cast<T>(lhs.y op rhs.y); \ | ||
| 41 | return lhs; \ | ||
| 42 | } \ | ||
| 43 | friend constexpr Point& operator compound_op(Point& lhs, T value) noexcept { \ | ||
| 44 | lhs.x = static_cast<T>(lhs.x op value); \ | ||
| 45 | lhs.y = static_cast<T>(lhs.y op value); \ | ||
| 46 | return lhs; \ | ||
| 47 | } | ||
| 48 | ARITHMETIC_OP(+, +=) | ||
| 49 | ARITHMETIC_OP(-, -=) | ||
| 50 | ARITHMETIC_OP(*, *=) | ||
| 51 | ARITHMETIC_OP(/, /=) | ||
| 52 | #undef ARITHMETIC_OP | ||
| 53 | |||
| 54 | friend constexpr bool operator==(const Point&, const Point&) = default; | ||
| 55 | }; | ||
| 56 | |||
| 57 | } // namespace Common | ||
diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h index eecfeaad5..7e7ae6625 100644 --- a/src/core/hle/service/hid/controllers/gesture.h +++ b/src/core/hle/service/hid/controllers/gesture.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include "common/bit_field.h" | 8 | #include "common/bit_field.h" |
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "common/point.h" | ||
| 10 | #include "core/frontend/input.h" | 11 | #include "core/frontend/input.h" |
| 11 | #include "core/hle/service/hid/controllers/controller_base.h" | 12 | #include "core/hle/service/hid/controllers/controller_base.h" |
| 12 | 13 | ||
| @@ -63,44 +64,21 @@ private: | |||
| 63 | }; | 64 | }; |
| 64 | static_assert(sizeof(Attribute) == 4, "Attribute is an invalid size"); | 65 | static_assert(sizeof(Attribute) == 4, "Attribute is an invalid size"); |
| 65 | 66 | ||
| 66 | template <typename T> | ||
| 67 | struct Point { | ||
| 68 | T x{}; | ||
| 69 | T y{}; | ||
| 70 | |||
| 71 | friend Point operator+(const Point& lhs, const Point& rhs) { | ||
| 72 | return { | ||
| 73 | .x = lhs.x + rhs.x, | ||
| 74 | .y = lhs.y + rhs.y, | ||
| 75 | }; | ||
| 76 | } | ||
| 77 | |||
| 78 | friend Point operator-(const Point& lhs, const Point& rhs) { | ||
| 79 | return { | ||
| 80 | .x = lhs.x - rhs.x, | ||
| 81 | .y = lhs.y - rhs.y, | ||
| 82 | }; | ||
| 83 | } | ||
| 84 | |||
| 85 | friend bool operator==(const Point&, const Point&) = default; | ||
| 86 | }; | ||
| 87 | static_assert(sizeof(Point<s32_le>) == 8, "Point is an invalid size"); | ||
| 88 | |||
| 89 | struct GestureState { | 67 | struct GestureState { |
| 90 | s64_le sampling_number; | 68 | s64_le sampling_number; |
| 91 | s64_le sampling_number2; | 69 | s64_le sampling_number2; |
| 92 | s64_le detection_count; | 70 | s64_le detection_count; |
| 93 | TouchType type; | 71 | TouchType type; |
| 94 | Direction direction; | 72 | Direction direction; |
| 95 | Point<s32_le> pos; | 73 | Common::Point<s32_le> pos; |
| 96 | Point<s32_le> delta; | 74 | Common::Point<s32_le> delta; |
| 97 | f32 vel_x; | 75 | f32 vel_x; |
| 98 | f32 vel_y; | 76 | f32 vel_y; |
| 99 | Attribute attributes; | 77 | Attribute attributes; |
| 100 | f32 scale; | 78 | f32 scale; |
| 101 | f32 rotation_angle; | 79 | f32 rotation_angle; |
| 102 | s32_le point_count; | 80 | s32_le point_count; |
| 103 | std::array<Point<s32_le>, 4> points; | 81 | std::array<Common::Point<s32_le>, 4> points; |
| 104 | }; | 82 | }; |
| 105 | static_assert(sizeof(GestureState) == 0x68, "GestureState is an invalid size"); | 83 | static_assert(sizeof(GestureState) == 0x68, "GestureState is an invalid size"); |
| 106 | 84 | ||
| @@ -111,14 +89,14 @@ private: | |||
| 111 | static_assert(sizeof(SharedMemory) == 0x708, "SharedMemory is an invalid size"); | 89 | static_assert(sizeof(SharedMemory) == 0x708, "SharedMemory is an invalid size"); |
| 112 | 90 | ||
| 113 | struct Finger { | 91 | struct Finger { |
| 114 | Point<f32> pos{}; | 92 | Common::Point<f32> pos{}; |
| 115 | bool pressed{}; | 93 | bool pressed{}; |
| 116 | }; | 94 | }; |
| 117 | 95 | ||
| 118 | struct GestureProperties { | 96 | struct GestureProperties { |
| 119 | std::array<Point<s32_le>, MAX_POINTS> points{}; | 97 | std::array<Common::Point<s32_le>, MAX_POINTS> points{}; |
| 120 | std::size_t active_points{}; | 98 | std::size_t active_points{}; |
| 121 | Point<s32_le> mid_point{}; | 99 | Common::Point<s32_le> mid_point{}; |
| 122 | s64_le detection_count{}; | 100 | s64_le detection_count{}; |
| 123 | u64_le delta_time{}; | 101 | u64_le delta_time{}; |
| 124 | f32 average_distance{}; | 102 | f32 average_distance{}; |