|
|
@ -91,8 +91,7 @@ bool Controller_Gesture::ShouldUpdateGesture(const GestureProperties& gesture,
|
|
|
|
|
|
|
|
|
|
|
|
// Update if coordinates change
|
|
|
|
// Update if coordinates change
|
|
|
|
for (size_t id = 0; id < MAX_POINTS; id++) {
|
|
|
|
for (size_t id = 0; id < MAX_POINTS; id++) {
|
|
|
|
if (gesture.points[id].x != last_gesture.points[id].x ||
|
|
|
|
if (gesture.points[id] != last_gesture.points[id]) {
|
|
|
|
gesture.points[id].y != last_gesture.points[id].y) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -124,8 +123,7 @@ void Controller_Gesture::UpdateGestureSharedMemory(u8* data, std::size_t size,
|
|
|
|
cur_entry.sampling_number2 = cur_entry.sampling_number;
|
|
|
|
cur_entry.sampling_number2 = cur_entry.sampling_number;
|
|
|
|
|
|
|
|
|
|
|
|
// Reset values to default
|
|
|
|
// Reset values to default
|
|
|
|
cur_entry.delta_x = 0;
|
|
|
|
cur_entry.delta = {};
|
|
|
|
cur_entry.delta_y = 0;
|
|
|
|
|
|
|
|
cur_entry.vel_x = 0;
|
|
|
|
cur_entry.vel_x = 0;
|
|
|
|
cur_entry.vel_y = 0;
|
|
|
|
cur_entry.vel_y = 0;
|
|
|
|
cur_entry.direction = Direction::None;
|
|
|
|
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.detection_count = gesture.detection_count;
|
|
|
|
cur_entry.type = type;
|
|
|
|
cur_entry.type = type;
|
|
|
|
cur_entry.attributes = attributes;
|
|
|
|
cur_entry.attributes = attributes;
|
|
|
|
cur_entry.x = gesture.mid_point.x;
|
|
|
|
cur_entry.pos = gesture.mid_point;
|
|
|
|
cur_entry.y = gesture.mid_point.y;
|
|
|
|
|
|
|
|
cur_entry.point_count = static_cast<s32>(gesture.active_points);
|
|
|
|
cur_entry.point_count = static_cast<s32>(gesture.active_points);
|
|
|
|
for (size_t id = 0; id < MAX_POINTS; id++) {
|
|
|
|
cur_entry.points = gesture.points;
|
|
|
|
cur_entry.points[id].x = gesture.points[id].x;
|
|
|
|
|
|
|
|
cur_entry.points[id].y = gesture.points[id].y;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
last_gesture = gesture;
|
|
|
|
last_gesture = gesture;
|
|
|
|
|
|
|
|
|
|
|
|
std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory));
|
|
|
|
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,
|
|
|
|
void Controller_Gesture::NewGesture(GestureProperties& gesture, TouchType& type,
|
|
|
|
Attribute& attributes) {
|
|
|
|
Attribute& attributes) {
|
|
|
|
const auto& last_entry =
|
|
|
|
const auto& last_entry = GetLastGestureEntry();
|
|
|
|
shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
|
|
|
|
|
|
|
|
gesture.detection_count++;
|
|
|
|
gesture.detection_count++;
|
|
|
|
type = TouchType::Touch;
|
|
|
|
type = TouchType::Touch;
|
|
|
|
|
|
|
|
|
|
|
@ -174,13 +168,11 @@ void Controller_Gesture::NewGesture(GestureProperties& gesture, TouchType& type,
|
|
|
|
|
|
|
|
|
|
|
|
void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, TouchType& type,
|
|
|
|
void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, TouchType& type,
|
|
|
|
f32 time_difference) {
|
|
|
|
f32 time_difference) {
|
|
|
|
const auto& last_entry =
|
|
|
|
const auto& last_entry = GetLastGestureEntry();
|
|
|
|
shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Promote to pan type if touch moved
|
|
|
|
// Promote to pan type if touch moved
|
|
|
|
for (size_t id = 0; id < MAX_POINTS; id++) {
|
|
|
|
for (size_t id = 0; id < MAX_POINTS; id++) {
|
|
|
|
if (gesture.points[id].x != last_gesture.points[id].x ||
|
|
|
|
if (gesture.points[id] != last_gesture.points[id]) {
|
|
|
|
gesture.points[id].y != last_gesture.points[id].y) {
|
|
|
|
|
|
|
|
type = TouchType::Pan;
|
|
|
|
type = TouchType::Pan;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -192,10 +184,7 @@ void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, Touch
|
|
|
|
enable_press_and_tap = false;
|
|
|
|
enable_press_and_tap = false;
|
|
|
|
gesture.active_points = 0;
|
|
|
|
gesture.active_points = 0;
|
|
|
|
gesture.mid_point = {};
|
|
|
|
gesture.mid_point = {};
|
|
|
|
for (size_t id = 0; id < MAX_POINTS; id++) {
|
|
|
|
gesture.points.fill({});
|
|
|
|
gesture.points[id].x = 0;
|
|
|
|
|
|
|
|
gesture.points[id].y = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -214,8 +203,8 @@ void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, Touch
|
|
|
|
void Controller_Gesture::EndGesture(GestureProperties& gesture,
|
|
|
|
void Controller_Gesture::EndGesture(GestureProperties& gesture,
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type,
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type,
|
|
|
|
Attribute& attributes, f32 time_difference) {
|
|
|
|
Attribute& attributes, f32 time_difference) {
|
|
|
|
const auto& last_entry =
|
|
|
|
const auto& last_entry = GetLastGestureEntry();
|
|
|
|
shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
|
|
|
|
|
|
|
|
if (last_gesture_props.active_points != 0) {
|
|
|
|
if (last_gesture_props.active_points != 0) {
|
|
|
|
switch (last_entry.type) {
|
|
|
|
switch (last_entry.type) {
|
|
|
|
case TouchType::Touch:
|
|
|
|
case TouchType::Touch:
|
|
|
@ -265,13 +254,11 @@ void Controller_Gesture::UpdatePanEvent(GestureProperties& gesture,
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type,
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type,
|
|
|
|
f32 time_difference) {
|
|
|
|
f32 time_difference) {
|
|
|
|
auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
|
|
|
|
auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
|
|
|
|
const auto& last_entry =
|
|
|
|
const auto& last_entry = GetLastGestureEntry();
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cur_entry.vel_x = static_cast<f32>(cur_entry.delta_x) / time_difference;
|
|
|
|
cur_entry.delta = gesture.mid_point - last_entry.pos;
|
|
|
|
cur_entry.vel_y = static_cast<f32>(cur_entry.delta_y) / time_difference;
|
|
|
|
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;
|
|
|
|
last_pan_time_difference = time_difference;
|
|
|
|
|
|
|
|
|
|
|
|
// Promote to pinch type
|
|
|
|
// Promote to pinch type
|
|
|
@ -295,12 +282,11 @@ void Controller_Gesture::EndPanEvent(GestureProperties& gesture,
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type,
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type,
|
|
|
|
f32 time_difference) {
|
|
|
|
f32 time_difference) {
|
|
|
|
auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
|
|
|
|
auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
|
|
|
|
const auto& last_entry =
|
|
|
|
const auto& last_entry = GetLastGestureEntry();
|
|
|
|
shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
|
|
|
|
|
|
|
|
cur_entry.vel_x =
|
|
|
|
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 =
|
|
|
|
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 =
|
|
|
|
const f32 curr_vel =
|
|
|
|
std::sqrt((cur_entry.vel_x * cur_entry.vel_x) + (cur_entry.vel_y * cur_entry.vel_y));
|
|
|
|
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,
|
|
|
|
void Controller_Gesture::SetSwipeEvent(GestureProperties& gesture,
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type) {
|
|
|
|
GestureProperties& last_gesture_props, TouchType& type) {
|
|
|
|
auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
|
|
|
|
auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
|
|
|
|
const auto& last_entry =
|
|
|
|
const auto& last_entry = GetLastGestureEntry();
|
|
|
|
shared_memory.gesture_states[(shared_memory.header.last_entry_index + 16) % 17];
|
|
|
|
|
|
|
|
type = TouchType::Swipe;
|
|
|
|
type = TouchType::Swipe;
|
|
|
|
gesture = last_gesture_props;
|
|
|
|
gesture = last_gesture_props;
|
|
|
|
force_update = true;
|
|
|
|
force_update = true;
|
|
|
|
cur_entry.delta_x = last_entry.delta_x;
|
|
|
|
cur_entry.delta = last_entry.delta;
|
|
|
|
cur_entry.delta_y = last_entry.delta_y;
|
|
|
|
|
|
|
|
if (std::abs(cur_entry.delta_x) > std::abs(cur_entry.delta_y)) {
|
|
|
|
if (std::abs(cur_entry.delta.x) > std::abs(cur_entry.delta.y)) {
|
|
|
|
if (cur_entry.delta_x > 0) {
|
|
|
|
if (cur_entry.delta.x > 0) {
|
|
|
|
cur_entry.direction = Direction::Right;
|
|
|
|
cur_entry.direction = Direction::Right;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cur_entry.direction = Direction::Left;
|
|
|
|
cur_entry.direction = Direction::Left;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cur_entry.delta_y > 0) {
|
|
|
|
if (cur_entry.delta.y > 0) {
|
|
|
|
cur_entry.direction = Direction::Down;
|
|
|
|
cur_entry.direction = Direction::Down;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -364,6 +350,14 @@ std::optional<std::size_t> Controller_Gesture::GetUnusedFingerID() const {
|
|
|
|
return std::nullopt;
|
|
|
|
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(
|
|
|
|
std::size_t Controller_Gesture::UpdateTouchInputEvent(
|
|
|
|
const std::tuple<float, float, bool>& touch_input, std::size_t finger_id) {
|
|
|
|
const std::tuple<float, float, bool>& touch_input, std::size_t finger_id) {
|
|
|
|
const auto& [x, y, pressed] = touch_input;
|
|
|
|
const auto& [x, y, pressed] = touch_input;
|
|
|
@ -381,8 +375,7 @@ std::size_t Controller_Gesture::UpdateTouchInputEvent(
|
|
|
|
finger_id = first_free_id.value();
|
|
|
|
finger_id = first_free_id.value();
|
|
|
|
fingers[finger_id].pressed = true;
|
|
|
|
fingers[finger_id].pressed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fingers[finger_id].x = x;
|
|
|
|
fingers[finger_id].pos = {x, y};
|
|
|
|
fingers[finger_id].y = y;
|
|
|
|
|
|
|
|
return finger_id;
|
|
|
|
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));
|
|
|
|
static_cast<std::size_t>(std::distance(active_fingers.begin(), end_iter));
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t id = 0; id < gesture.active_points; ++id) {
|
|
|
|
for (size_t id = 0; id < gesture.active_points; ++id) {
|
|
|
|
gesture.points[id].x =
|
|
|
|
const auto& [active_x, active_y] = active_fingers[id].pos;
|
|
|
|
static_cast<s32>(active_fingers[id].x * Layout::ScreenUndocked::Width);
|
|
|
|
gesture.points[id] = {
|
|
|
|
gesture.points[id].y =
|
|
|
|
.x = static_cast<s32>(active_x * Layout::ScreenUndocked::Width),
|
|
|
|
static_cast<s32>(active_fingers[id].y * Layout::ScreenUndocked::Height);
|
|
|
|
.y = static_cast<s32>(active_y * Layout::ScreenUndocked::Height),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Hack: There is no touch in docked but games still allow it
|
|
|
|
// Hack: There is no touch in docked but games still allow it
|
|
|
|
if (Settings::values.use_docked_mode.GetValue()) {
|
|
|
|
if (Settings::values.use_docked_mode.GetValue()) {
|
|
|
|
gesture.points[id].x =
|
|
|
|
gesture.points[id] = {
|
|
|
|
static_cast<s32>(active_fingers[id].x * Layout::ScreenDocked::Width);
|
|
|
|
.x = static_cast<s32>(active_x * Layout::ScreenDocked::Width),
|
|
|
|
gesture.points[id].y =
|
|
|
|
.y = static_cast<s32>(active_y * Layout::ScreenDocked::Height),
|
|
|
|
static_cast<s32>(active_fingers[id].y * Layout::ScreenDocked::Height);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gesture.mid_point.x += static_cast<s32>(gesture.points[id].x / gesture.active_points);
|
|
|
|
gesture.mid_point.x += static_cast<s32>(gesture.points[id].x / gesture.active_points);
|
|
|
|