diff options
| author | 2021-05-17 15:15:07 -0400 | |
|---|---|---|
| committer | 2021-05-18 03:39:18 -0400 | |
| commit | 74f30c02239e034e065f5f1bd4e249c091f2d97f (patch) | |
| tree | fa6cbad3998595c29c45ca5cb7cb9180224fbce4 | |
| parent | hid/gesture: Replace x,y members of GestureState with a Point (diff) | |
| download | yuzu-74f30c02239e034e065f5f1bd4e249c091f2d97f.tar.gz yuzu-74f30c02239e034e065f5f1bd4e249c091f2d97f.tar.xz yuzu-74f30c02239e034e065f5f1bd4e249c091f2d97f.zip | |
hid/gesture: Make Point a template
We can now use this in a generic context to reuse it with the finger
position.
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/service/hid/controllers/gesture.cpp | 49 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/gesture.h | 35 |
2 files changed, 46 insertions, 38 deletions
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp index 86e9f4ea8..2c9330941 100644 --- a/src/core/hle/service/hid/controllers/gesture.cpp +++ b/src/core/hle/service/hid/controllers/gesture.cpp | |||
| @@ -123,8 +123,7 @@ void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size, | |||
| 123 | cur_entry.sampling_number2 = cur_entry.sampling_number; | 123 | cur_entry.sampling_number2 = cur_entry.sampling_number; |
| 124 | 124 | ||
| 125 | // Reset values to default | 125 | // Reset values to default |
| 126 | cur_entry.delta_x = 0; | 126 | cur_entry.delta = {}; |
| 127 | cur_entry.delta_y = 0; | ||
| 128 | cur_entry.vel_x = 0; | 127 | cur_entry.vel_x = 0; |
| 129 | cur_entry.vel_y = 0; | 128 | cur_entry.vel_y = 0; |
| 130 | cur_entry.direction = Direction::None; | 129 | cur_entry.direction = Direction::None; |
| @@ -147,10 +146,7 @@ void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size, | |||
| 147 | cur_entry.attributes = attributes; | 146 | cur_entry.attributes = attributes; |
| 148 | cur_entry.pos = gesture.mid_point; | 147 | cur_entry.pos = gesture.mid_point; |
| 149 | cur_entry.point_count = static_cast<s32>(gesture.active_points); | 148 | cur_entry.point_count = static_cast<s32>(gesture.active_points); |
| 150 | for (size_t id = 0; id < MAX_POINTS; id++) { | 149 | cur_entry.points = gesture.points; |
| 151 | cur_entry.points[id].x = gesture.points[id].x; | ||
| 152 | cur_entry.points[id].y = gesture.points[id].y; | ||
| 153 | } | ||
| 154 | last_gesture = gesture; | 150 | last_gesture = gesture; |
| 155 | 151 | ||
| 156 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); | 152 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); |
| @@ -261,11 +257,10 @@ void Controller_Gesture::UpdatePanEvent(GestureProperties& gesture, | |||
| 261 | auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; | 257 | auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; |
| 262 | const auto& last_entry = | 258 | const auto& last_entry = |
| 263 | shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17]; | 259 | shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17]; |
| 264 | cur_entry.delta_x = gesture.mid_point.x - last_entry.pos.x; | 260 | cur_entry.delta = gesture.mid_point - last_entry.pos; |
| 265 | cur_entry.delta_y = gesture.mid_point.y - last_entry.pos.y; | ||
| 266 | 261 | ||
| 267 | cur_entry.vel_x = static_cast<f32>(cur_entry.delta_x) / time_difference; | 262 | cur_entry.vel_x = static_cast<f32>(cur_entry.delta.x) / time_difference; |
| 268 | cur_entry.vel_y = static_cast<f32>(cur_entry.delta_y) / time_difference; | 263 | cur_entry.vel_y = static_cast<f32>(cur_entry.delta.y) / time_difference; |
| 269 | last_pan_time_difference = time_difference; | 264 | last_pan_time_difference = time_difference; |
| 270 | 265 | ||
| 271 | // Promote to pinch type | 266 | // Promote to pinch type |
| @@ -292,9 +287,9 @@ void Controller_Gesture::EndPanEvent(GestureProperties& gesture, | |||
| 292 | const auto& last_entry = | 287 | const auto& last_entry = |
| 293 | shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17]; | 288 | shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17]; |
| 294 | cur_entry.vel_x = | 289 | cur_entry.vel_x = |
| 295 | static_cast<f32>(last_entry.delta_x) / (last_pan_time_difference + time_difference); | 290 | static_cast<f32>(last_entry.delta.x) / (last_pan_time_difference + time_difference); |
| 296 | cur_entry.vel_y = | 291 | cur_entry.vel_y = |
| 297 | static_cast<f32>(last_entry.delta_y) / (last_pan_time_difference + time_difference); | 292 | static_cast<f32>(last_entry.delta.y) / (last_pan_time_difference + time_difference); |
| 298 | const f32 curr_vel = | 293 | const f32 curr_vel = |
| 299 | std::sqrt((cur_entry.vel_x * cur_entry.vel_x) + (cur_entry.vel_y * cur_entry.vel_y)); | 294 | std::sqrt((cur_entry.vel_x * cur_entry.vel_x) + (cur_entry.vel_y * cur_entry.vel_y)); |
| 300 | 295 | ||
| @@ -319,17 +314,17 @@ void Controller_Gesture::SetSwipeEvent(GestureProperties& gesture, | |||
| 319 | type = TouchType::Swipe; | 314 | type = TouchType::Swipe; |
| 320 | gesture = last_gesture_props; | 315 | gesture = last_gesture_props; |
| 321 | force_update = true; | 316 | force_update = true; |
| 322 | cur_entry.delta_x = last_entry.delta_x; | 317 | cur_entry.delta = last_entry.delta; |
| 323 | cur_entry.delta_y = last_entry.delta_y; | 318 | |
| 324 | if (std::abs(cur_entry.delta_x) > std::abs(cur_entry.delta_y)) { | 319 | if (std::abs(cur_entry.delta.x) > std::abs(cur_entry.delta.y)) { |
| 325 | if (cur_entry.delta_x > 0) { | 320 | if (cur_entry.delta.x > 0) { |
| 326 | cur_entry.direction = Direction::Right; | 321 | cur_entry.direction = Direction::Right; |
| 327 | return; | 322 | return; |
| 328 | } | 323 | } |
| 329 | cur_entry.direction = Direction::Left; | 324 | cur_entry.direction = Direction::Left; |
| 330 | return; | 325 | return; |
| 331 | } | 326 | } |
| 332 | if (cur_entry.delta_y > 0) { | 327 | if (cur_entry.delta.y > 0) { |
| 333 | cur_entry.direction = Direction::Down; | 328 | cur_entry.direction = Direction::Down; |
| 334 | return; | 329 | return; |
| 335 | } | 330 | } |
| @@ -375,8 +370,7 @@ std::size_t Controller_Gesture::UpdateTouchInputEvent( | |||
| 375 | finger_id = first_free_id.value(); | 370 | finger_id = first_free_id.value(); |
| 376 | fingers[finger_id].pressed = true; | 371 | fingers[finger_id].pressed = true; |
| 377 | } | 372 | } |
| 378 | fingers[finger_id].x = x; | 373 | fingers[finger_id].pos = {x, y}; |
| 379 | fingers[finger_id].y = y; | ||
| 380 | return finger_id; | 374 | return finger_id; |
| 381 | } | 375 | } |
| 382 | 376 | ||
| @@ -396,17 +390,18 @@ Controller_Gesture::GestureProperties Controller_Gesture::GetGestureProperties() | |||
| 396 | static_cast<std::size_t>(std::distance(active_fingers.begin(), end_iter)); | 390 | static_cast<std::size_t>(std::distance(active_fingers.begin(), end_iter)); |
| 397 | 391 | ||
| 398 | for (size_t id = 0; id < gesture.active_points; ++id) { | 392 | for (size_t id = 0; id < gesture.active_points; ++id) { |
| 399 | gesture.points[id].x = | 393 | const auto& [active_x, active_y] = active_fingers[id].pos; |
| 400 | static_cast<s32>(active_fingers[id].x * Layout::ScreenUndocked::Width); | 394 | gesture.points[id] = { |
| 401 | gesture.points[id].y = | 395 | .x = static_cast<s32>(active_x * Layout::ScreenUndocked::Width), |
| 402 | static_cast<s32>(active_fingers[id].y * Layout::ScreenUndocked::Height); | 396 | .y = static_cast<s32>(active_y * Layout::ScreenUndocked::Height), |
| 397 | }; | ||
| 403 | 398 | ||
| 404 | // Hack: There is no touch in docked but games still allow it | 399 | // Hack: There is no touch in docked but games still allow it |
| 405 | if (Settings::values.use_docked_mode.GetValue()) { | 400 | if (Settings::values.use_docked_mode.GetValue()) { |
| 406 | gesture.points[id].x = | 401 | gesture.points[id] = { |
| 407 | static_cast<s32>(active_fingers[id].x * Layout::ScreenDocked::Width); | 402 | .x = static_cast<s32>(active_x * Layout::ScreenDocked::Width), |
| 408 | gesture.points[id].y = | 403 | .y = static_cast<s32>(active_y * Layout::ScreenDocked::Height), |
| 409 | static_cast<s32>(active_fingers[id].y * Layout::ScreenDocked::Height); | 404 | }; |
| 410 | } | 405 | } |
| 411 | 406 | ||
| 412 | gesture.mid_point.x += static_cast<s32>(gesture.points[id].x / gesture.active_points); | 407 | gesture.mid_point.x += static_cast<s32>(gesture.points[id].x / gesture.active_points); |
diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h index 809303131..b2bcae2b7 100644 --- a/src/core/hle/service/hid/controllers/gesture.h +++ b/src/core/hle/service/hid/controllers/gesture.h | |||
| @@ -63,13 +63,28 @@ private: | |||
| 63 | }; | 63 | }; |
| 64 | static_assert(sizeof(Attribute) == 4, "Attribute is an invalid size"); | 64 | static_assert(sizeof(Attribute) == 4, "Attribute is an invalid size"); |
| 65 | 65 | ||
| 66 | template <typename T> | ||
| 66 | struct Point { | 67 | struct Point { |
| 67 | s32_le x{}; | 68 | T x{}; |
| 68 | s32_le y{}; | 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 | } | ||
| 69 | 84 | ||
| 70 | friend bool operator==(const Point&, const Point&) = default; | 85 | friend bool operator==(const Point&, const Point&) = default; |
| 71 | }; | 86 | }; |
| 72 | static_assert(sizeof(Point) == 8, "Point is an invalid size"); | 87 | static_assert(sizeof(Point<s32_le>) == 8, "Point is an invalid size"); |
| 73 | 88 | ||
| 74 | struct GestureState { | 89 | struct GestureState { |
| 75 | s64_le sampling_number; | 90 | s64_le sampling_number; |
| @@ -77,16 +92,15 @@ private: | |||
| 77 | s64_le detection_count; | 92 | s64_le detection_count; |
| 78 | TouchType type; | 93 | TouchType type; |
| 79 | Direction direction; | 94 | Direction direction; |
| 80 | Point pos; | 95 | Point<s32_le> pos; |
| 81 | s32_le delta_x; | 96 | Point<s32_le> delta; |
| 82 | s32_le delta_y; | ||
| 83 | f32 vel_x; | 97 | f32 vel_x; |
| 84 | f32 vel_y; | 98 | f32 vel_y; |
| 85 | Attribute attributes; | 99 | Attribute attributes; |
| 86 | f32 scale; | 100 | f32 scale; |
| 87 | f32 rotation_angle; | 101 | f32 rotation_angle; |
| 88 | s32_le point_count; | 102 | s32_le point_count; |
| 89 | std::array<Point, 4> points; | 103 | std::array<Point<s32_le>, 4> points; |
| 90 | }; | 104 | }; |
| 91 | static_assert(sizeof(GestureState) == 0x68, "GestureState is an invalid size"); | 105 | static_assert(sizeof(GestureState) == 0x68, "GestureState is an invalid size"); |
| 92 | 106 | ||
| @@ -97,15 +111,14 @@ private: | |||
| 97 | static_assert(sizeof(SharedMemory) == 0x708, "SharedMemory is an invalid size"); | 111 | static_assert(sizeof(SharedMemory) == 0x708, "SharedMemory is an invalid size"); |
| 98 | 112 | ||
| 99 | struct Finger { | 113 | struct Finger { |
| 100 | f32 x{}; | 114 | Point<f32> pos{}; |
| 101 | f32 y{}; | ||
| 102 | bool pressed{}; | 115 | bool pressed{}; |
| 103 | }; | 116 | }; |
| 104 | 117 | ||
| 105 | struct GestureProperties { | 118 | struct GestureProperties { |
| 106 | std::array<Point, MAX_POINTS> points{}; | 119 | std::array<Point<s32_le>, MAX_POINTS> points{}; |
| 107 | std::size_t active_points{}; | 120 | std::size_t active_points{}; |
| 108 | Point mid_point{}; | 121 | Point<s32_le> mid_point{}; |
| 109 | s64_le detection_count{}; | 122 | s64_le detection_count{}; |
| 110 | u64_le delta_time{}; | 123 | u64_le delta_time{}; |
| 111 | f32 average_distance{}; | 124 | f32 average_distance{}; |