summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/hid/controllers
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/hle/service/hid/controllers/gesture.cpp92
-rw-r--r--src/core/hle/service/hid/controllers/gesture.h36
-rw-r--r--src/core/hle/service/hid/controllers/touchscreen.cpp13
-rw-r--r--src/core/hle/service/hid/controllers/touchscreen.h7
4 files changed, 69 insertions, 79 deletions
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp
index d311f754b..764abb5b6 100644
--- a/src/core/hle/service/hid/controllers/gesture.cpp
+++ b/src/core/hle/service/hid/controllers/gesture.cpp
@@ -91,8 +91,7 @@ bool Controller_Gesture::ShouldUpdateGesture(const GestureProperties& gesture,
// Update if coordinates change
for (size_t id = 0; id < MAX_POINTS; id++) {
- if (gesture.points[id].x != last_gesture.points[id].x ||
- gesture.points[id].y != last_gesture.points[id].y) {
+ if (gesture.points[id] != last_gesture.points[id]) {
return true;
}
}
@@ -124,8 +123,7 @@ void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size,
cur_entry.sampling_number2 = cur_entry.sampling_number;
// Reset values to default
- cur_entry.delta_x = 0;
- cur_entry.delta_y = 0;
+ cur_entry.delta = {};
cur_entry.vel_x = 0;
cur_entry.vel_y = 0;
cur_entry.direction = Direction::None;
@@ -146,13 +144,9 @@ void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size,
cur_entry.detection_count = gesture.detection_count;
cur_entry.type = type;
cur_entry.attributes = attributes;
- cur_entry.x = gesture.mid_point.x;
- cur_entry.y = gesture.mid_point.y;
+ cur_entry.pos = gesture.mid_point;
cur_entry.point_count = static_cast<s32>(gesture.active_points);
- for (size_t id = 0; id < MAX_POINTS; id++) {
- cur_entry.points[id].x = gesture.points[id].x;
- cur_entry.points[id].y = gesture.points[id].y;
- }
+ cur_entry.points = gesture.points;
last_gesture = gesture;
std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory));
@@ -160,8 +154,8 @@ void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size,
void Controller_Gesture::NewGesture(GestureProperties& gesture, TouchType& type,
Attribute& attributes) {
- const auto& last_entry =
- shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+ const auto& last_entry = GetLastGestureEntry();
+
gesture.detection_count++;
type = TouchType::Touch;
@@ -174,13 +168,11 @@ void Controller_Gesture::NewGesture(GestureProperties& gesture, TouchType& type,
void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, TouchType& type,
f32 time_difference) {
- const auto& last_entry =
- shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+ const auto& last_entry = GetLastGestureEntry();
// Promote to pan type if touch moved
for (size_t id = 0; id < MAX_POINTS; id++) {
- if (gesture.points[id].x != last_gesture.points[id].x ||
- gesture.points[id].y != last_gesture.points[id].y) {
+ if (gesture.points[id] != last_gesture.points[id]) {
type = TouchType::Pan;
break;
}
@@ -192,10 +184,7 @@ void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, Touch
enable_press_and_tap = false;
gesture.active_points = 0;
gesture.mid_point = {};
- for (size_t id = 0; id < MAX_POINTS; id++) {
- gesture.points[id].x = 0;
- gesture.points[id].y = 0;
- }
+ gesture.points.fill({});
return;
}
@@ -214,8 +203,8 @@ void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, Touch
void Controller_Gesture::EndGesture(GestureProperties& gesture,
GestureProperties& last_gesture_props, TouchType& type,
Attribute& attributes, f32 time_difference) {
- const auto& last_entry =
- shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+ const auto& last_entry = GetLastGestureEntry();
+
if (last_gesture_props.active_points != 0) {
switch (last_entry.type) {
case TouchType::Touch:
@@ -265,13 +254,11 @@ void Controller_Gesture::UpdatePanEvent(GestureProperties& gesture,
GestureProperties& last_gesture_props, TouchType& type,
f32 time_difference) {
auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
- const auto& last_entry =
- shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
- cur_entry.delta_x = gesture.mid_point.x - last_entry.x;
- cur_entry.delta_y = gesture.mid_point.y - last_entry.y;
+ const auto& last_entry = GetLastGestureEntry();
- cur_entry.vel_x = static_cast<f32>(cur_entry.delta_x) / time_difference;
- cur_entry.vel_y = static_cast<f32>(cur_entry.delta_y) / time_difference;
+ cur_entry.delta = gesture.mid_point - last_entry.pos;
+ cur_entry.vel_x = static_cast<f32>(cur_entry.delta.x) / time_difference;
+ cur_entry.vel_y = static_cast<f32>(cur_entry.delta.y) / time_difference;
last_pan_time_difference = time_difference;
// Promote to pinch type
@@ -295,12 +282,11 @@ void Controller_Gesture::EndPanEvent(GestureProperties& gesture,
GestureProperties& last_gesture_props, TouchType& type,
f32 time_difference) {
auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
- const auto& last_entry =
- shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+ const auto& last_entry = GetLastGestureEntry();
cur_entry.vel_x =
- static_cast<f32>(last_entry.delta_x) / (last_pan_time_difference + time_difference);
+ static_cast<f32>(last_entry.delta.x) / (last_pan_time_difference + time_difference);
cur_entry.vel_y =
- static_cast<f32>(last_entry.delta_y) / (last_pan_time_difference + time_difference);
+ static_cast<f32>(last_entry.delta.y) / (last_pan_time_difference + time_difference);
const f32 curr_vel =
std::sqrt((cur_entry.vel_x * cur_entry.vel_x) + (cur_entry.vel_y * cur_entry.vel_y));
@@ -320,22 +306,22 @@ void Controller_Gesture::EndPanEvent(GestureProperties& gesture,
void Controller_Gesture::SetSwipeEvent(GestureProperties& gesture,
GestureProperties& last_gesture_props, TouchType& type) {
auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
- const auto& last_entry =
- shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+ const auto& last_entry = GetLastGestureEntry();
+
type = TouchType::Swipe;
gesture = last_gesture_props;
force_update = true;
- cur_entry.delta_x = last_entry.delta_x;
- cur_entry.delta_y = last_entry.delta_y;
- if (std::abs(cur_entry.delta_x) > std::abs(cur_entry.delta_y)) {
- if (cur_entry.delta_x > 0) {
+ cur_entry.delta = last_entry.delta;
+
+ if (std::abs(cur_entry.delta.x) > std::abs(cur_entry.delta.y)) {
+ if (cur_entry.delta.x > 0) {
cur_entry.direction = Direction::Right;
return;
}
cur_entry.direction = Direction::Left;
return;
}
- if (cur_entry.delta_y > 0) {
+ if (cur_entry.delta.y > 0) {
cur_entry.direction = Direction::Down;
return;
}
@@ -364,6 +350,14 @@ std::optional<std::size_t> Controller_Gesture::GetUnusedFingerID() const {
return std::nullopt;
}
+Controller_Gesture::GestureState& Controller_Gesture::GetLastGestureEntry() {
+ return shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+}
+
+const Controller_Gesture::GestureState& Controller_Gesture::GetLastGestureEntry() const {
+ return shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
+}
+
std::size_t Controller_Gesture::UpdateTouchInputEvent(
const std::tuple<float, float, bool>& touch_input, std::size_t finger_id) {
const auto& [x, y, pressed] = touch_input;
@@ -381,8 +375,7 @@ std::size_t Controller_Gesture::UpdateTouchInputEvent(
finger_id = first_free_id.value();
fingers[finger_id].pressed = true;
}
- fingers[finger_id].x = x;
- fingers[finger_id].y = y;
+ fingers[finger_id].pos = {x, y};
return finger_id;
}
@@ -402,17 +395,18 @@ Controller_Gesture::GestureProperties Controller_Gesture::GetGestureProperties()
static_cast<std::size_t>(std::distance(active_fingers.begin(), end_iter));
for (size_t id = 0; id < gesture.active_points; ++id) {
- gesture.points[id].x =
- static_cast<s32>(active_fingers[id].x * Layout::ScreenUndocked::Width);
- gesture.points[id].y =
- static_cast<s32>(active_fingers[id].y * Layout::ScreenUndocked::Height);
+ const auto& [active_x, active_y] = active_fingers[id].pos;
+ gesture.points[id] = {
+ .x = static_cast<s32>(active_x * Layout::ScreenUndocked::Width),
+ .y = static_cast<s32>(active_y * Layout::ScreenUndocked::Height),
+ };
// Hack: There is no touch in docked but games still allow it
if (Settings::values.use_docked_mode.GetValue()) {
- gesture.points[id].x =
- static_cast<s32>(active_fingers[id].x * Layout::ScreenDocked::Width);
- gesture.points[id].y =
- static_cast<s32>(active_fingers[id].y * Layout::ScreenDocked::Height);
+ gesture.points[id] = {
+ .x = static_cast<s32>(active_x * Layout::ScreenDocked::Width),
+ .y = static_cast<s32>(active_y * Layout::ScreenDocked::Height),
+ };
}
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 f46e29411..7e7ae6625 100644
--- a/src/core/hle/service/hid/controllers/gesture.h
+++ b/src/core/hle/service/hid/controllers/gesture.h
@@ -7,6 +7,7 @@
#include <array>
#include "common/bit_field.h"
#include "common/common_types.h"
+#include "common/point.h"
#include "core/frontend/input.h"
#include "core/hle/service/hid/controllers/controller_base.h"
@@ -63,29 +64,21 @@ private:
};
static_assert(sizeof(Attribute) == 4, "Attribute is an invalid size");
- struct Points {
- s32_le x;
- s32_le y;
- };
- static_assert(sizeof(Points) == 8, "Points is an invalid size");
-
struct GestureState {
s64_le sampling_number;
s64_le sampling_number2;
s64_le detection_count;
TouchType type;
Direction direction;
- s32_le x;
- s32_le y;
- s32_le delta_x;
- s32_le delta_y;
+ Common::Point<s32_le> pos;
+ Common::Point<s32_le> delta;
f32 vel_x;
f32 vel_y;
Attribute attributes;
f32 scale;
f32 rotation_angle;
s32_le point_count;
- std::array<Points, 4> points;
+ std::array<Common::Point<s32_le>, 4> points;
};
static_assert(sizeof(GestureState) == 0x68, "GestureState is an invalid size");
@@ -96,15 +89,14 @@ private:
static_assert(sizeof(SharedMemory) == 0x708, "SharedMemory is an invalid size");
struct Finger {
- f32 x{};
- f32 y{};
+ Common::Point<f32> pos{};
bool pressed{};
};
struct GestureProperties {
- std::array<Points, MAX_POINTS> points{};
+ std::array<Common::Point<s32_le>, MAX_POINTS> points{};
std::size_t active_points{};
- Points mid_point{};
+ Common::Point<s32_le> mid_point{};
s64_le detection_count{};
u64_le delta_time{};
f32 average_distance{};
@@ -148,7 +140,11 @@ private:
TouchType& type);
// Returns an unused finger id, if there is no fingers available std::nullopt is returned.
- std::optional<size_t> GetUnusedFingerID() const;
+ [[nodiscard]] std::optional<size_t> GetUnusedFingerID() const;
+
+ // Retrieves the last gesture entry, as indicated by shared memory indices.
+ [[nodiscard]] GestureState& GetLastGestureEntry();
+ [[nodiscard]] const GestureState& GetLastGestureEntry() const;
/**
* If the touch is new it tries to assign a new finger id, if there is no fingers available no
@@ -166,10 +162,10 @@ private:
std::unique_ptr<Input::TouchDevice> touch_mouse_device;
std::unique_ptr<Input::TouchDevice> touch_udp_device;
std::unique_ptr<Input::TouchDevice> touch_btn_device;
- std::array<size_t, MAX_FINGERS> mouse_finger_id;
- std::array<size_t, MAX_FINGERS> keyboard_finger_id;
- std::array<size_t, MAX_FINGERS> udp_finger_id;
- std::array<Finger, MAX_POINTS> fingers;
+ std::array<size_t, MAX_FINGERS> mouse_finger_id{};
+ std::array<size_t, MAX_FINGERS> keyboard_finger_id{};
+ std::array<size_t, MAX_FINGERS> udp_finger_id{};
+ std::array<Finger, MAX_POINTS> fingers{};
GestureProperties last_gesture{};
s64_le last_update_timestamp{};
s64_le last_tap_timestamp{};
diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp
index ac9112c40..6ef17acc5 100644
--- a/src/core/hle/service/hid/controllers/touchscreen.cpp
+++ b/src/core/hle/service/hid/controllers/touchscreen.cpp
@@ -74,8 +74,11 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
for (std::size_t id = 0; id < MAX_FINGERS; ++id) {
auto& touch_entry = cur_entry.states[id];
if (id < active_fingers_count) {
- touch_entry.x = static_cast<u16>(active_fingers[id].x * Layout::ScreenUndocked::Width);
- touch_entry.y = static_cast<u16>(active_fingers[id].y * Layout::ScreenUndocked::Height);
+ const auto& [active_x, active_y] = active_fingers[id].position;
+ touch_entry.position = {
+ .x = static_cast<u16>(active_x * Layout::ScreenUndocked::Width),
+ .y = static_cast<u16>(active_y * Layout::ScreenUndocked::Height),
+ };
touch_entry.diameter_x = Settings::values.touchscreen.diameter_x;
touch_entry.diameter_y = Settings::values.touchscreen.diameter_y;
touch_entry.rotation_angle = Settings::values.touchscreen.rotation_angle;
@@ -86,8 +89,7 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
} else {
// Clear touch entry
touch_entry.attribute.raw = 0;
- touch_entry.x = 0;
- touch_entry.y = 0;
+ touch_entry.position = {};
touch_entry.diameter_x = 0;
touch_entry.diameter_y = 0;
touch_entry.rotation_angle = 0;
@@ -140,8 +142,7 @@ std::size_t Controller_Touchscreen::UpdateTouchInputEvent(
fingers[finger_id].id = static_cast<u32_le>(finger_id);
attribute.start_touch.Assign(1);
}
- fingers[finger_id].x = x;
- fingers[finger_id].y = y;
+ fingers[finger_id].position = {x, y};
fingers[finger_id].attribute = attribute;
return finger_id;
}
diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h
index 2869d0cfd..ef2becefd 100644
--- a/src/core/hle/service/hid/controllers/touchscreen.h
+++ b/src/core/hle/service/hid/controllers/touchscreen.h
@@ -7,6 +7,7 @@
#include "common/bit_field.h"
#include "common/common_funcs.h"
#include "common/common_types.h"
+#include "common/point.h"
#include "common/swap.h"
#include "core/frontend/input.h"
#include "core/hle/service/hid/controllers/controller_base.h"
@@ -55,8 +56,7 @@ private:
u64_le delta_time;
Attributes attribute;
u32_le finger;
- u32_le x;
- u32_le y;
+ Common::Point<u32_le> position;
u32_le diameter_x;
u32_le diameter_y;
u32_le rotation_angle;
@@ -81,8 +81,7 @@ private:
struct Finger {
u64_le last_touch{};
- float x{};
- float y{};
+ Common::Point<float> position;
u32_le id{};
bool pressed{};
Attributes attribute;