summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/hid/controllers/gesture.cpp31
-rw-r--r--src/core/hle/service/hid/controllers/gesture.h6
2 files changed, 23 insertions, 14 deletions
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp
index 2c9330941..764abb5b6 100644
--- a/src/core/hle/service/hid/controllers/gesture.cpp
+++ b/src/core/hle/service/hid/controllers/gesture.cpp
@@ -154,8 +154,8 @@ void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size,
154 154
155void Controller_Gesture::NewGesture(GestureProperties& gesture, TouchType& type, 155void Controller_Gesture::NewGesture(GestureProperties& gesture, TouchType& type,
156 Attribute& attributes) { 156 Attribute& attributes) {
157 const auto& last_entry = 157 const auto& last_entry = GetLastGestureEntry();
158 shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17]; 158
159 gesture.detection_count++; 159 gesture.detection_count++;
160 type = TouchType::Touch; 160 type = TouchType::Touch;
161 161
@@ -168,8 +168,7 @@ void Controller_Gesture::NewGesture(GestureProperties& gesture, TouchType& type,
168 168
169void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, TouchType& type, 169void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, TouchType& type,
170 f32 time_difference) { 170 f32 time_difference) {
171 const auto& last_entry = 171 const auto& last_entry = GetLastGestureEntry();
172 shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
173 172
174 // Promote to pan type if touch moved 173 // Promote to pan type if touch moved
175 for (size_t id = 0; id < MAX_POINTS; id++) { 174 for (size_t id = 0; id < MAX_POINTS; id++) {
@@ -204,8 +203,8 @@ void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, Touch
204void Controller_Gesture::EndGesture(GestureProperties& gesture, 203void Controller_Gesture::EndGesture(GestureProperties& gesture,
205 GestureProperties& last_gesture_props, TouchType& type, 204 GestureProperties& last_gesture_props, TouchType& type,
206 Attribute& attributes, f32 time_difference) { 205 Attribute& attributes, f32 time_difference) {
207 const auto& last_entry = 206 const auto& last_entry = GetLastGestureEntry();
208 shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17]; 207
209 if (last_gesture_props.active_points != 0) { 208 if (last_gesture_props.active_points != 0) {
210 switch (last_entry.type) { 209 switch (last_entry.type) {
211 case TouchType::Touch: 210 case TouchType::Touch:
@@ -255,10 +254,9 @@ void Controller_Gesture::UpdatePanEvent(GestureProperties& gesture,
255 GestureProperties& last_gesture_props, TouchType& type, 254 GestureProperties& last_gesture_props, TouchType& type,
256 f32 time_difference) { 255 f32 time_difference) {
257 auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; 256 auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
258 const auto& last_entry = 257 const auto& last_entry = GetLastGestureEntry();
259 shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
260 cur_entry.delta = gesture.mid_point - last_entry.pos;
261 258
259 cur_entry.delta = gesture.mid_point - last_entry.pos;
262 cur_entry.vel_x = static_cast<f32>(cur_entry.delta.x) / time_difference; 260 cur_entry.vel_x = static_cast<f32>(cur_entry.delta.x) / time_difference;
263 cur_entry.vel_y = static_cast<f32>(cur_entry.delta.y) / time_difference; 261 cur_entry.vel_y = static_cast<f32>(cur_entry.delta.y) / time_difference;
264 last_pan_time_difference = time_difference; 262 last_pan_time_difference = time_difference;
@@ -284,8 +282,7 @@ void Controller_Gesture::EndPanEvent(GestureProperties& gesture,
284 GestureProperties& last_gesture_props, TouchType& type, 282 GestureProperties& last_gesture_props, TouchType& type,
285 f32 time_difference) { 283 f32 time_difference) {
286 auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; 284 auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
287 const auto& last_entry = 285 const auto& last_entry = GetLastGestureEntry();
288 shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
289 cur_entry.vel_x = 286 cur_entry.vel_x =
290 static_cast<f32>(last_entry.delta.x) / (last_pan_time_difference + time_difference); 287 static_cast<f32>(last_entry.delta.x) / (last_pan_time_difference + time_difference);
291 cur_entry.vel_y = 288 cur_entry.vel_y =
@@ -309,8 +306,8 @@ void Controller_Gesture::EndPanEvent(GestureProperties& gesture,
309void Controller_Gesture::SetSwipeEvent(GestureProperties& gesture, 306void Controller_Gesture::SetSwipeEvent(GestureProperties& gesture,
310 GestureProperties& last_gesture_props, TouchType& type) { 307 GestureProperties& last_gesture_props, TouchType& type) {
311 auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; 308 auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
312 const auto& last_entry = 309 const auto& last_entry = GetLastGestureEntry();
313 shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17]; 310
314 type = TouchType::Swipe; 311 type = TouchType::Swipe;
315 gesture = last_gesture_props; 312 gesture = last_gesture_props;
316 force_update = true; 313 force_update = true;
@@ -353,6 +350,14 @@ std::optional<std::size_t> Controller_Gesture::GetUnusedFingerID() const {
353 return std::nullopt; 350 return std::nullopt;
354} 351}
355 352
353Controller_Gesture::GestureState& Controller_Gesture::GetLastGestureEntry() {
354 return shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
355}
356
357const Controller_Gesture::GestureState& Controller_Gesture::GetLastGestureEntry() const {
358 return shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
359}
360
356std::size_t Controller_Gesture::UpdateTouchInputEvent( 361std::size_t Controller_Gesture::UpdateTouchInputEvent(
357 const std::tuple<float, float, bool>& touch_input, std::size_t finger_id) { 362 const std::tuple<float, float, bool>& touch_input, std::size_t finger_id) {
358 const auto& [x, y, pressed] = touch_input; 363 const auto& [x, y, pressed] = touch_input;
diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h
index c1578ec25..eecfeaad5 100644
--- a/src/core/hle/service/hid/controllers/gesture.h
+++ b/src/core/hle/service/hid/controllers/gesture.h
@@ -162,7 +162,11 @@ private:
162 TouchType& type); 162 TouchType& type);
163 163
164 // Returns an unused finger id, if there is no fingers available std::nullopt is returned. 164 // Returns an unused finger id, if there is no fingers available std::nullopt is returned.
165 std::optional<size_t> GetUnusedFingerID() const; 165 [[nodiscard]] std::optional<size_t> GetUnusedFingerID() const;
166
167 // Retrieves the last gesture entry, as indicated by shared memory indices.
168 [[nodiscard]] GestureState& GetLastGestureEntry();
169 [[nodiscard]] const GestureState& GetLastGestureEntry() const;
166 170
167 /** 171 /**
168 * If the touch is new it tries to assign a new finger id, if there is no fingers available no 172 * If the touch is new it tries to assign a new finger id, if there is no fingers available no