diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index eafb96b0b3..7a4d9e3540 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -154,6 +154,7 @@ add_library(common STATIC param_package.cpp param_package.h parent_of_member.h + point.h quaternion.h ring_buffer.h scm_rev.cpp diff --git a/src/common/point.h b/src/common/point.h new file mode 100644 index 0000000000..c0a52ad8d2 --- /dev/null +++ b/src/common/point.h @@ -0,0 +1,57 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include + +namespace Common { + +// Represents a point within a 2D space. +template +struct Point { + static_assert(std::is_arithmetic_v, "T must be an arithmetic type!"); + + T x{}; + T y{}; + +#define ARITHMETIC_OP(op, compound_op) \ + friend constexpr Point operator op(const Point& lhs, const Point& rhs) noexcept { \ + return { \ + .x = static_cast(lhs.x op rhs.x), \ + .y = static_cast(lhs.y op rhs.y), \ + }; \ + } \ + friend constexpr Point operator op(const Point& lhs, T value) noexcept { \ + return { \ + .x = static_cast(lhs.x op value), \ + .y = static_cast(lhs.y op value), \ + }; \ + } \ + friend constexpr Point operator op(T value, const Point& rhs) noexcept { \ + return { \ + .x = static_cast(value op rhs.x), \ + .y = static_cast(value op rhs.y), \ + }; \ + } \ + friend constexpr Point& operator compound_op(Point& lhs, const Point& rhs) noexcept { \ + lhs.x = static_cast(lhs.x op rhs.x); \ + lhs.y = static_cast(lhs.y op rhs.y); \ + return lhs; \ + } \ + friend constexpr Point& operator compound_op(Point& lhs, T value) noexcept { \ + lhs.x = static_cast(lhs.x op value); \ + lhs.y = static_cast(lhs.y op value); \ + return lhs; \ + } + ARITHMETIC_OP(+, +=) + ARITHMETIC_OP(-, -=) + ARITHMETIC_OP(*, *=) + ARITHMETIC_OP(/, /=) +#undef ARITHMETIC_OP + + friend constexpr bool operator==(const Point&, const Point&) = default; +}; + +} // namespace Common diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h index eecfeaad54..7e7ae66259 100644 --- a/src/core/hle/service/hid/controllers/gesture.h +++ b/src/core/hle/service/hid/controllers/gesture.h @@ -7,6 +7,7 @@ #include #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,44 +64,21 @@ private: }; static_assert(sizeof(Attribute) == 4, "Attribute is an invalid size"); - template - struct Point { - T x{}; - T y{}; - - friend Point operator+(const Point& lhs, const Point& rhs) { - return { - .x = lhs.x + rhs.x, - .y = lhs.y + rhs.y, - }; - } - - friend Point operator-(const Point& lhs, const Point& rhs) { - return { - .x = lhs.x - rhs.x, - .y = lhs.y - rhs.y, - }; - } - - friend bool operator==(const Point&, const Point&) = default; - }; - static_assert(sizeof(Point) == 8, "Point is an invalid size"); - struct GestureState { s64_le sampling_number; s64_le sampling_number2; s64_le detection_count; TouchType type; Direction direction; - Point pos; - Point delta; + Common::Point pos; + Common::Point delta; f32 vel_x; f32 vel_y; Attribute attributes; f32 scale; f32 rotation_angle; s32_le point_count; - std::array, 4> points; + std::array, 4> points; }; static_assert(sizeof(GestureState) == 0x68, "GestureState is an invalid size"); @@ -111,14 +89,14 @@ private: static_assert(sizeof(SharedMemory) == 0x708, "SharedMemory is an invalid size"); struct Finger { - Point pos{}; + Common::Point pos{}; bool pressed{}; }; struct GestureProperties { - std::array, MAX_POINTS> points{}; + std::array, MAX_POINTS> points{}; std::size_t active_points{}; - Point mid_point{}; + Common::Point mid_point{}; s64_le detection_count{}; u64_le delta_time{}; f32 average_distance{};