mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-09-01 02:51:41 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5fe800bae6 |
@@ -89,7 +89,6 @@ add_library(
|
||||
param_package.h
|
||||
parent_of_member.h
|
||||
point.h
|
||||
quaternion.h
|
||||
range_map.h
|
||||
range_mutex.h
|
||||
range_sets.h
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/vector_math.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
template <typename T>
|
||||
class Quaternion {
|
||||
public:
|
||||
Vec3<T> xyz;
|
||||
T w{};
|
||||
|
||||
[[nodiscard]] Quaternion<decltype(-T{})> Inverse() const {
|
||||
return {-xyz, w};
|
||||
}
|
||||
|
||||
[[nodiscard]] Quaternion<decltype(T{} + T{})> operator+(const Quaternion& other) const {
|
||||
return {xyz + other.xyz, w + other.w};
|
||||
}
|
||||
|
||||
[[nodiscard]] Quaternion<decltype(T{} - T{})> operator-(const Quaternion& other) const {
|
||||
return {xyz - other.xyz, w - other.w};
|
||||
}
|
||||
|
||||
[[nodiscard]] Quaternion<decltype(T{} * T{} - T{} * T{})> operator*(
|
||||
const Quaternion& other) const {
|
||||
return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz),
|
||||
w * other.w - Dot(xyz, other.xyz)};
|
||||
}
|
||||
|
||||
[[nodiscard]] Quaternion<T> Normalized() const {
|
||||
T length = std::sqrt(xyz.Length2() + w * w);
|
||||
return {xyz / length, w / length};
|
||||
}
|
||||
|
||||
[[nodiscard]] std::array<decltype(-T{}), 16> ToMatrix() const {
|
||||
const T x2 = xyz[0] * xyz[0];
|
||||
const T y2 = xyz[1] * xyz[1];
|
||||
const T z2 = xyz[2] * xyz[2];
|
||||
|
||||
const T xy = xyz[0] * xyz[1];
|
||||
const T wz = w * xyz[2];
|
||||
const T xz = xyz[0] * xyz[2];
|
||||
const T wy = w * xyz[1];
|
||||
const T yz = xyz[1] * xyz[2];
|
||||
const T wx = w * xyz[0];
|
||||
|
||||
return {1.0f - 2.0f * (y2 + z2),
|
||||
2.0f * (xy + wz),
|
||||
2.0f * (xz - wy),
|
||||
0.0f,
|
||||
2.0f * (xy - wz),
|
||||
1.0f - 2.0f * (x2 + z2),
|
||||
2.0f * (yz + wx),
|
||||
0.0f,
|
||||
2.0f * (xz + wy),
|
||||
2.0f * (yz - wx),
|
||||
1.0f - 2.0f * (x2 + y2),
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
1.0f};
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] auto QuaternionRotate(const Quaternion<T>& q, const Vec3<T>& v) {
|
||||
return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline Quaternion<float> MakeQuaternion(const Vec3<float>& axis, float angle) {
|
||||
return {axis * std::sin(angle / 2), std::cos(angle / 2)};
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
+85
-560
@@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2014 Tony Wasserka
|
||||
@@ -21,7 +21,7 @@ class Vec2;
|
||||
template <typename T>
|
||||
class Vec3;
|
||||
template <typename T>
|
||||
class Vec4;
|
||||
class Quaternion;
|
||||
|
||||
template <typename T>
|
||||
class Vec2 {
|
||||
@@ -30,141 +30,82 @@ public:
|
||||
T y{};
|
||||
|
||||
constexpr Vec2() = default;
|
||||
constexpr Vec2(const T& x_, const T& y_) : x(x_), y(y_) {}
|
||||
constexpr Vec2(const T& x_, const T& y_) noexcept : x(x_), y(y_) {}
|
||||
|
||||
template <typename T2>
|
||||
[[nodiscard]] constexpr Vec2<T2> Cast() const {
|
||||
return Vec2<T2>(static_cast<T2>(x), static_cast<T2>(y));
|
||||
}
|
||||
|
||||
[[nodiscard]] static constexpr Vec2 AssignToAll(const T& f) {
|
||||
return Vec2{f, f};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vec2<decltype(T{} + T{})> operator+(const Vec2& other) const {
|
||||
[[nodiscard]] constexpr Vec2<decltype(T{} + T{})> operator+(const Vec2& other) const noexcept {
|
||||
return {x + other.x, y + other.y};
|
||||
}
|
||||
constexpr Vec2& operator+=(const Vec2& other) {
|
||||
constexpr Vec2& operator+=(const Vec2& other) noexcept {
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
return *this;
|
||||
}
|
||||
[[nodiscard]] constexpr Vec2<decltype(T{} - T{})> operator-(const Vec2& other) const {
|
||||
[[nodiscard]] constexpr Vec2<decltype(T{} - T{})> operator-(const Vec2& other) const noexcept {
|
||||
return {x - other.x, y - other.y};
|
||||
}
|
||||
constexpr Vec2& operator-=(const Vec2& other) {
|
||||
constexpr Vec2& operator-=(const Vec2& other) noexcept {
|
||||
x -= other.x;
|
||||
y -= other.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename U = T>
|
||||
[[nodiscard]] constexpr Vec2<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
|
||||
[[nodiscard]] constexpr Vec2<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const noexcept {
|
||||
return {-x, -y};
|
||||
}
|
||||
[[nodiscard]] constexpr Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const {
|
||||
[[nodiscard]] constexpr Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const noexcept {
|
||||
return {x * other.x, y * other.y};
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
[[nodiscard]] constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const {
|
||||
[[nodiscard]] constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const noexcept {
|
||||
using TV = decltype(T{} * V{});
|
||||
using C = std::common_type_t<T, V>;
|
||||
|
||||
return {
|
||||
static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)),
|
||||
static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)),
|
||||
TV(C(x) * C(f)),
|
||||
TV(C(y) * C(f)),
|
||||
};
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
constexpr Vec2& operator*=(const V& f) {
|
||||
*this = *this * f;
|
||||
return *this;
|
||||
constexpr Vec2& operator*=(const V& f) noexcept {
|
||||
return *this = *this * f;
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
[[nodiscard]] constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const {
|
||||
[[nodiscard]] constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const noexcept {
|
||||
using TV = decltype(T{} / V{});
|
||||
using C = std::common_type_t<T, V>;
|
||||
|
||||
return {
|
||||
static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)),
|
||||
static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)),
|
||||
TV(C(x) / C(f)),
|
||||
TV(C(y) / C(f)),
|
||||
};
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
constexpr Vec2& operator/=(const V& f) {
|
||||
*this = *this / f;
|
||||
return *this;
|
||||
constexpr Vec2& operator/=(const V& f) noexcept {
|
||||
return *this = *this / f;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T Length2() const {
|
||||
[[nodiscard]] constexpr T Length2() const noexcept {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
// Only implemented for T=float
|
||||
[[nodiscard]] float Length() const;
|
||||
[[nodiscard]] float Normalize(); // returns the previous length, which is often useful
|
||||
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t i) {
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t i) noexcept {
|
||||
return *((&x) + i);
|
||||
}
|
||||
[[nodiscard]] constexpr const T& operator[](std::size_t i) const {
|
||||
[[nodiscard]] constexpr const T& operator[](std::size_t i) const noexcept {
|
||||
return *((&x) + i);
|
||||
}
|
||||
|
||||
constexpr void SetZero() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
// Common aliases: UV (texel coordinates), ST (texture coordinates)
|
||||
[[nodiscard]] constexpr T& u() {
|
||||
return x;
|
||||
}
|
||||
[[nodiscard]] constexpr T& v() {
|
||||
return y;
|
||||
}
|
||||
[[nodiscard]] constexpr T& s() {
|
||||
return x;
|
||||
}
|
||||
[[nodiscard]] constexpr T& t() {
|
||||
return y;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const T& u() const {
|
||||
return x;
|
||||
}
|
||||
[[nodiscard]] constexpr const T& v() const {
|
||||
return y;
|
||||
}
|
||||
[[nodiscard]] constexpr const T& s() const {
|
||||
return x;
|
||||
}
|
||||
[[nodiscard]] constexpr const T& t() const {
|
||||
return y;
|
||||
}
|
||||
|
||||
// swizzlers - create a subvector of specific components
|
||||
[[nodiscard]] constexpr Vec2 yx() const {
|
||||
return Vec2(y, x);
|
||||
}
|
||||
[[nodiscard]] constexpr Vec2 vu() const {
|
||||
return Vec2(y, x);
|
||||
}
|
||||
[[nodiscard]] constexpr Vec2 ts() const {
|
||||
return Vec2(y, x);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename V>
|
||||
[[nodiscard]] constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) {
|
||||
[[nodiscard]] constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) noexcept {
|
||||
using C = std::common_type_t<T, V>;
|
||||
|
||||
return Vec2<T>(static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.x)),
|
||||
static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.y)));
|
||||
return Vec2<T>(T(C(f) * C(vec.x)), T(C(f) * C(vec.y)));
|
||||
}
|
||||
|
||||
using Vec2f = Vec2<float>;
|
||||
@@ -174,13 +115,6 @@ inline float Vec2<float>::Length() const {
|
||||
return std::sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline float Vec2<float>::Normalize() {
|
||||
float length = Length();
|
||||
*this /= length;
|
||||
return length;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class Vec3 {
|
||||
public:
|
||||
@@ -189,33 +123,24 @@ public:
|
||||
T z{};
|
||||
|
||||
constexpr Vec3() = default;
|
||||
constexpr Vec3(const T& x_, const T& y_, const T& z_) : x(x_), y(y_), z(z_) {}
|
||||
constexpr Vec3(const T& x_, const T& y_, const T& z_) noexcept : x(x_), y(y_), z(z_) {}
|
||||
|
||||
template <typename T2>
|
||||
[[nodiscard]] constexpr Vec3<T2> Cast() const {
|
||||
return Vec3<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z));
|
||||
}
|
||||
|
||||
[[nodiscard]] static constexpr Vec3 AssignToAll(const T& f) {
|
||||
return Vec3(f, f, f);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vec3<decltype(T{} + T{})> operator+(const Vec3& other) const {
|
||||
[[nodiscard]] constexpr Vec3<decltype(T{} + T{})> operator+(const Vec3& other) const noexcept {
|
||||
return {x + other.x, y + other.y, z + other.z};
|
||||
}
|
||||
|
||||
constexpr Vec3& operator+=(const Vec3& other) {
|
||||
constexpr Vec3 operator+=(const Vec3& other) noexcept {
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
z += other.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vec3<decltype(T{} - T{})> operator-(const Vec3& other) const {
|
||||
[[nodiscard]] constexpr Vec3<decltype(T{} - T{})> operator-(const Vec3& other) const noexcept {
|
||||
return {x - other.x, y - other.y, z - other.z};
|
||||
}
|
||||
|
||||
constexpr Vec3& operator-=(const Vec3& other) {
|
||||
constexpr Vec3 operator-=(const Vec3& other) noexcept {
|
||||
x -= other.x;
|
||||
y -= other.y;
|
||||
z -= other.z;
|
||||
@@ -223,177 +148,68 @@ public:
|
||||
}
|
||||
|
||||
template <typename U = T>
|
||||
[[nodiscard]] constexpr Vec3<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
|
||||
[[nodiscard]] constexpr Vec3<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const noexcept {
|
||||
return {-x, -y, -z};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vec3<decltype(T{} * T{})> operator*(const Vec3& other) const {
|
||||
[[nodiscard]] constexpr Vec3<decltype(T{} * T{})> operator*(const Vec3& other) const noexcept {
|
||||
return {x * other.x, y * other.y, z * other.z};
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
[[nodiscard]] constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const {
|
||||
[[nodiscard]] constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const noexcept {
|
||||
using TV = decltype(T{} * V{});
|
||||
using C = std::common_type_t<T, V>;
|
||||
|
||||
return {
|
||||
static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)),
|
||||
static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)),
|
||||
static_cast<TV>(static_cast<C>(z) * static_cast<C>(f)),
|
||||
TV(C(x) * C(f)),
|
||||
TV(C(y) * C(f)),
|
||||
TV(C(z) * C(f)),
|
||||
};
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
constexpr Vec3& operator*=(const V& f) {
|
||||
*this = *this * f;
|
||||
return *this;
|
||||
constexpr Vec3 operator*=(const V& f) noexcept {
|
||||
return *this = *this * f;
|
||||
}
|
||||
template <typename V>
|
||||
[[nodiscard]] constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const {
|
||||
[[nodiscard]] constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const noexcept {
|
||||
using TV = decltype(T{} / V{});
|
||||
using C = std::common_type_t<T, V>;
|
||||
|
||||
return {
|
||||
static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)),
|
||||
static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)),
|
||||
static_cast<TV>(static_cast<C>(z) / static_cast<C>(f)),
|
||||
TV(C(x) / C(f)),
|
||||
TV(C(y) / C(f)),
|
||||
TV(C(z) / C(f)),
|
||||
};
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
constexpr Vec3& operator/=(const V& f) {
|
||||
*this = *this / f;
|
||||
return *this;
|
||||
constexpr Vec3& operator/=(const V& f) noexcept {
|
||||
return *this = *this / f;
|
||||
}
|
||||
|
||||
void RotateFromOrigin(float roll, float pitch, float yaw) {
|
||||
float temp = y;
|
||||
y = std::cos(roll) * y - std::sin(roll) * z;
|
||||
z = std::sin(roll) * temp + std::cos(roll) * z;
|
||||
|
||||
temp = x;
|
||||
x = std::cos(pitch) * x + std::sin(pitch) * z;
|
||||
z = -std::sin(pitch) * temp + std::cos(pitch) * z;
|
||||
|
||||
temp = x;
|
||||
x = std::cos(yaw) * x - std::sin(yaw) * y;
|
||||
y = std::sin(yaw) * temp + std::cos(yaw) * y;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T Length2() const {
|
||||
[[nodiscard]] constexpr T Length2() const noexcept {
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
// Only implemented for T=float
|
||||
[[nodiscard]] float Length() const;
|
||||
[[nodiscard]] Vec3 Normalized() const;
|
||||
[[nodiscard]] float Normalize(); // returns the previous length, which is often useful
|
||||
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t i) {
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t i) noexcept {
|
||||
return *((&x) + i);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const T& operator[](std::size_t i) const {
|
||||
[[nodiscard]] constexpr const T& operator[](std::size_t i) const noexcept {
|
||||
return *((&x) + i);
|
||||
}
|
||||
|
||||
constexpr void SetZero() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
}
|
||||
|
||||
// Common aliases: UVW (texel coordinates), RGB (colors), STQ (texture coordinates)
|
||||
[[nodiscard]] constexpr T& u() {
|
||||
return x;
|
||||
}
|
||||
[[nodiscard]] constexpr T& v() {
|
||||
return y;
|
||||
}
|
||||
[[nodiscard]] constexpr T& w() {
|
||||
return z;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T& r() {
|
||||
return x;
|
||||
}
|
||||
[[nodiscard]] constexpr T& g() {
|
||||
return y;
|
||||
}
|
||||
[[nodiscard]] constexpr T& b() {
|
||||
return z;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T& s() {
|
||||
return x;
|
||||
}
|
||||
[[nodiscard]] constexpr T& t() {
|
||||
return y;
|
||||
}
|
||||
[[nodiscard]] constexpr T& q() {
|
||||
return z;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const T& u() const {
|
||||
return x;
|
||||
}
|
||||
[[nodiscard]] constexpr const T& v() const {
|
||||
return y;
|
||||
}
|
||||
[[nodiscard]] constexpr const T& w() const {
|
||||
return z;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const T& r() const {
|
||||
return x;
|
||||
}
|
||||
[[nodiscard]] constexpr const T& g() const {
|
||||
return y;
|
||||
}
|
||||
[[nodiscard]] constexpr const T& b() const {
|
||||
return z;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const T& s() const {
|
||||
return x;
|
||||
}
|
||||
[[nodiscard]] constexpr const T& t() const {
|
||||
return y;
|
||||
}
|
||||
[[nodiscard]] constexpr const T& q() const {
|
||||
return z;
|
||||
}
|
||||
|
||||
// swizzlers - create a subvector of specific components
|
||||
// e.g. Vec2 uv() { return Vec2(x,y); }
|
||||
// _DEFINE_SWIZZLER2 defines a single such function, DEFINE_SWIZZLER2 defines all of them for all
|
||||
// component names (x<->r) and permutations (xy<->yx)
|
||||
#define _DEFINE_SWIZZLER2(a, b, name) \
|
||||
[[nodiscard]] constexpr Vec2<T> name() const { return Vec2<T>(a, b); }
|
||||
#define DEFINE_SWIZZLER2(a, b, a2, b2, a3, b3, a4, b4) \
|
||||
_DEFINE_SWIZZLER2(a, b, a##b); \
|
||||
_DEFINE_SWIZZLER2(a, b, a2##b2); \
|
||||
_DEFINE_SWIZZLER2(a, b, a3##b3); \
|
||||
_DEFINE_SWIZZLER2(a, b, a4##b4); \
|
||||
_DEFINE_SWIZZLER2(b, a, b##a); \
|
||||
_DEFINE_SWIZZLER2(b, a, b2##a2); \
|
||||
_DEFINE_SWIZZLER2(b, a, b3##a3); \
|
||||
_DEFINE_SWIZZLER2(b, a, b4##a4)
|
||||
|
||||
DEFINE_SWIZZLER2(x, y, r, g, u, v, s, t);
|
||||
DEFINE_SWIZZLER2(x, z, r, b, u, w, s, q);
|
||||
DEFINE_SWIZZLER2(y, z, g, b, v, w, t, q);
|
||||
#undef DEFINE_SWIZZLER2
|
||||
#undef _DEFINE_SWIZZLER2
|
||||
};
|
||||
|
||||
template <typename T, typename V>
|
||||
[[nodiscard]] constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) {
|
||||
[[nodiscard]] constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) noexcept {
|
||||
using C = std::common_type_t<T, V>;
|
||||
|
||||
return Vec3<T>(static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.x)),
|
||||
static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.y)),
|
||||
static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.z)));
|
||||
return Vec3<T>(T(C(f) * C(vec.x)), T(C(f) * C(vec.y)), T(C(f) * C(vec.z)));
|
||||
}
|
||||
|
||||
template <>
|
||||
@@ -406,353 +222,62 @@ inline Vec3<float> Vec3<float>::Normalized() const {
|
||||
return *this / Length();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline float Vec3<float>::Normalize() {
|
||||
float length = Length();
|
||||
*this /= length;
|
||||
return length;
|
||||
}
|
||||
|
||||
using Vec3f = Vec3<float>;
|
||||
|
||||
template <typename T>
|
||||
class Vec4 {
|
||||
class Quaternion {
|
||||
public:
|
||||
T x{};
|
||||
T y{};
|
||||
T z{};
|
||||
Vec3<T> xyz;
|
||||
T w{};
|
||||
|
||||
constexpr Vec4() = default;
|
||||
constexpr Vec4(const T& x_, const T& y_, const T& z_, const T& w_)
|
||||
: x(x_), y(y_), z(z_), w(w_) {}
|
||||
|
||||
template <typename T2>
|
||||
[[nodiscard]] constexpr Vec4<T2> Cast() const {
|
||||
return Vec4<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z),
|
||||
static_cast<T2>(w));
|
||||
[[nodiscard]] Quaternion<decltype(T{} + T{})> operator+(const Quaternion& other) const noexcept {
|
||||
return {xyz + other.xyz, w + other.w};
|
||||
}
|
||||
|
||||
[[nodiscard]] static constexpr Vec4 AssignToAll(const T& f) {
|
||||
return Vec4(f, f, f, f);
|
||||
[[nodiscard]] Quaternion<decltype(T{} - T{})> operator-(const Quaternion& other) const noexcept {
|
||||
return {xyz - other.xyz, w - other.w};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vec4<decltype(T{} + T{})> operator+(const Vec4& other) const {
|
||||
return {x + other.x, y + other.y, z + other.z, w + other.w};
|
||||
[[nodiscard]] Quaternion<decltype(T{} * T{} - T{} * T{})> operator*(const Quaternion& other) const noexcept {
|
||||
return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz), w * other.w - Dot(xyz, other.xyz)};
|
||||
}
|
||||
|
||||
constexpr Vec4& operator+=(const Vec4& other) {
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
z += other.z;
|
||||
w += other.w;
|
||||
return *this;
|
||||
[[nodiscard]] Quaternion<T> Normalized() const noexcept {
|
||||
T length = std::sqrt(xyz.Length2() + w * w);
|
||||
return {xyz / length, w / length};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vec4<decltype(T{} - T{})> operator-(const Vec4& other) const {
|
||||
return {x - other.x, y - other.y, z - other.z, w - other.w};
|
||||
}
|
||||
[[nodiscard]] std::array<decltype(-T{}), 16> ToMatrix() const {
|
||||
const T x2 = xyz[0] * xyz[0];
|
||||
const T y2 = xyz[1] * xyz[1];
|
||||
const T z2 = xyz[2] * xyz[2];
|
||||
|
||||
constexpr Vec4& operator-=(const Vec4& other) {
|
||||
x -= other.x;
|
||||
y -= other.y;
|
||||
z -= other.z;
|
||||
w -= other.w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename U = T>
|
||||
[[nodiscard]] constexpr Vec4<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
|
||||
return {-x, -y, -z, -w};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Vec4<decltype(T{} * T{})> operator*(const Vec4& other) const {
|
||||
return {x * other.x, y * other.y, z * other.z, w * other.w};
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
[[nodiscard]] constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const {
|
||||
using TV = decltype(T{} * V{});
|
||||
using C = std::common_type_t<T, V>;
|
||||
const T xy = xyz[0] * xyz[1];
|
||||
const T wz = w * xyz[2];
|
||||
const T xz = xyz[0] * xyz[2];
|
||||
const T wy = w * xyz[1];
|
||||
const T yz = xyz[1] * xyz[2];
|
||||
const T wx = w * xyz[0];
|
||||
|
||||
return {
|
||||
static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)),
|
||||
static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)),
|
||||
static_cast<TV>(static_cast<C>(z) * static_cast<C>(f)),
|
||||
static_cast<TV>(static_cast<C>(w) * static_cast<C>(f)),
|
||||
1.0f - 2.0f * (y2 + z2),
|
||||
2.0f * (xy + wz),
|
||||
2.0f * (xz - wy),
|
||||
0.0f,
|
||||
2.0f * (xy - wz),
|
||||
1.0f - 2.0f * (x2 + z2),
|
||||
2.0f * (yz + wx),
|
||||
0.0f,
|
||||
2.0f * (xz + wy),
|
||||
2.0f * (yz - wx),
|
||||
1.0f - 2.0f * (x2 + y2),
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
1.0f
|
||||
};
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
constexpr Vec4& operator*=(const V& f) {
|
||||
*this = *this * f;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
[[nodiscard]] constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const {
|
||||
using TV = decltype(T{} / V{});
|
||||
using C = std::common_type_t<T, V>;
|
||||
|
||||
return {
|
||||
static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)),
|
||||
static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)),
|
||||
static_cast<TV>(static_cast<C>(z) / static_cast<C>(f)),
|
||||
static_cast<TV>(static_cast<C>(w) / static_cast<C>(f)),
|
||||
};
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
constexpr Vec4& operator/=(const V& f) {
|
||||
*this = *this / f;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T Length2() const {
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr T& operator[](std::size_t i) {
|
||||
return *((&x) + i);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const T& operator[](std::size_t i) const {
|
||||
return *((&x) + i);
|
||||
}
|
||||
|
||||
constexpr void SetZero() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
w = 0;
|
||||
}
|
||||
|
||||
// Common alias: RGBA (colors)
|
||||
[[nodiscard]] constexpr T& r() {
|
||||
return x;
|
||||
}
|
||||
[[nodiscard]] constexpr T& g() {
|
||||
return y;
|
||||
}
|
||||
[[nodiscard]] constexpr T& b() {
|
||||
return z;
|
||||
}
|
||||
[[nodiscard]] constexpr T& a() {
|
||||
return w;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const T& r() const {
|
||||
return x;
|
||||
}
|
||||
[[nodiscard]] constexpr const T& g() const {
|
||||
return y;
|
||||
}
|
||||
[[nodiscard]] constexpr const T& b() const {
|
||||
return z;
|
||||
}
|
||||
[[nodiscard]] constexpr const T& a() const {
|
||||
return w;
|
||||
}
|
||||
|
||||
// Swizzlers - Create a subvector of specific components
|
||||
// e.g. Vec2 uv() { return Vec2(x,y); }
|
||||
|
||||
// _DEFINE_SWIZZLER2 defines a single such function
|
||||
// DEFINE_SWIZZLER2_COMP1 defines one-component functions for all component names (x<->r)
|
||||
// DEFINE_SWIZZLER2_COMP2 defines two component functions for all component names (x<->r) and
|
||||
// permutations (xy<->yx)
|
||||
#define _DEFINE_SWIZZLER2(a, b, name) \
|
||||
[[nodiscard]] constexpr Vec2<T> name() const { return Vec2<T>(a, b); }
|
||||
#define DEFINE_SWIZZLER2_COMP1(a, a2) \
|
||||
_DEFINE_SWIZZLER2(a, a, a##a); \
|
||||
_DEFINE_SWIZZLER2(a, a, a2##a2)
|
||||
#define DEFINE_SWIZZLER2_COMP2(a, b, a2, b2) \
|
||||
_DEFINE_SWIZZLER2(a, b, a##b); \
|
||||
_DEFINE_SWIZZLER2(a, b, a2##b2); \
|
||||
_DEFINE_SWIZZLER2(b, a, b##a); \
|
||||
_DEFINE_SWIZZLER2(b, a, b2##a2)
|
||||
|
||||
DEFINE_SWIZZLER2_COMP2(x, y, r, g);
|
||||
DEFINE_SWIZZLER2_COMP2(x, z, r, b);
|
||||
DEFINE_SWIZZLER2_COMP2(x, w, r, a);
|
||||
DEFINE_SWIZZLER2_COMP2(y, z, g, b);
|
||||
DEFINE_SWIZZLER2_COMP2(y, w, g, a);
|
||||
DEFINE_SWIZZLER2_COMP2(z, w, b, a);
|
||||
DEFINE_SWIZZLER2_COMP1(x, r);
|
||||
DEFINE_SWIZZLER2_COMP1(y, g);
|
||||
DEFINE_SWIZZLER2_COMP1(z, b);
|
||||
DEFINE_SWIZZLER2_COMP1(w, a);
|
||||
#undef DEFINE_SWIZZLER2_COMP1
|
||||
#undef DEFINE_SWIZZLER2_COMP2
|
||||
#undef _DEFINE_SWIZZLER2
|
||||
|
||||
#define _DEFINE_SWIZZLER3(a, b, c, name) \
|
||||
[[nodiscard]] constexpr Vec3<T> name() const { return Vec3<T>(a, b, c); }
|
||||
#define DEFINE_SWIZZLER3_COMP1(a, a2) \
|
||||
_DEFINE_SWIZZLER3(a, a, a, a##a##a); \
|
||||
_DEFINE_SWIZZLER3(a, a, a, a2##a2##a2)
|
||||
#define DEFINE_SWIZZLER3_COMP3(a, b, c, a2, b2, c2) \
|
||||
_DEFINE_SWIZZLER3(a, b, c, a##b##c); \
|
||||
_DEFINE_SWIZZLER3(a, c, b, a##c##b); \
|
||||
_DEFINE_SWIZZLER3(b, a, c, b##a##c); \
|
||||
_DEFINE_SWIZZLER3(b, c, a, b##c##a); \
|
||||
_DEFINE_SWIZZLER3(c, a, b, c##a##b); \
|
||||
_DEFINE_SWIZZLER3(c, b, a, c##b##a); \
|
||||
_DEFINE_SWIZZLER3(a, b, c, a2##b2##c2); \
|
||||
_DEFINE_SWIZZLER3(a, c, b, a2##c2##b2); \
|
||||
_DEFINE_SWIZZLER3(b, a, c, b2##a2##c2); \
|
||||
_DEFINE_SWIZZLER3(b, c, a, b2##c2##a2); \
|
||||
_DEFINE_SWIZZLER3(c, a, b, c2##a2##b2); \
|
||||
_DEFINE_SWIZZLER3(c, b, a, c2##b2##a2)
|
||||
|
||||
DEFINE_SWIZZLER3_COMP3(x, y, z, r, g, b);
|
||||
DEFINE_SWIZZLER3_COMP3(x, y, w, r, g, a);
|
||||
DEFINE_SWIZZLER3_COMP3(x, z, w, r, b, a);
|
||||
DEFINE_SWIZZLER3_COMP3(y, z, w, g, b, a);
|
||||
DEFINE_SWIZZLER3_COMP1(x, r);
|
||||
DEFINE_SWIZZLER3_COMP1(y, g);
|
||||
DEFINE_SWIZZLER3_COMP1(z, b);
|
||||
DEFINE_SWIZZLER3_COMP1(w, a);
|
||||
#undef DEFINE_SWIZZLER3_COMP1
|
||||
#undef DEFINE_SWIZZLER3_COMP3
|
||||
#undef _DEFINE_SWIZZLER3
|
||||
};
|
||||
|
||||
template <typename T, typename V>
|
||||
[[nodiscard]] constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) {
|
||||
using TV = decltype(V{} * T{});
|
||||
using C = std::common_type_t<T, V>;
|
||||
|
||||
return {
|
||||
static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.x)),
|
||||
static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.y)),
|
||||
static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.z)),
|
||||
static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.w)),
|
||||
};
|
||||
}
|
||||
|
||||
using Vec4f = Vec4<float>;
|
||||
|
||||
template <typename T>
|
||||
constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec2<T>& a, const Vec2<T>& b) {
|
||||
return a.x * b.x + a.y * b.y;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec3<T>& a, const Vec3<T>& b) {
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec4<T>& a, const Vec4<T>& b) {
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
||||
}
|
||||
|
||||
template <>
|
||||
[[nodiscard]] inline float Dot(const Vec4<float>& a, const Vec4<float>& b) {
|
||||
#ifdef __ARM_NEON
|
||||
float32x4_t va = vld1q_f32(&a.x);
|
||||
float32x4_t vb = vld1q_f32(&b.x);
|
||||
float32x4_t result = vmulq_f32(va, vb);
|
||||
#if defined(__aarch64__) // Use vaddvq_f32 in ARMv8 architectures
|
||||
return vaddvq_f32(result);
|
||||
#else // Use manual addition for older architectures
|
||||
float32x2_t sum2 = vadd_f32(vget_high_f32(result), vget_low_f32(result));
|
||||
return vget_lane_f32(vpadd_f32(sum2, sum2), 0);
|
||||
#endif
|
||||
#else
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr Vec3<decltype(T{} * T{} - T{} * T{})> Cross(const Vec3<T>& a,
|
||||
const Vec3<T>& b) {
|
||||
return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x};
|
||||
}
|
||||
|
||||
// linear interpolation via float: 0.0=begin, 1.0=end
|
||||
template <typename X>
|
||||
[[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end,
|
||||
const float t) {
|
||||
return begin * (1.f - t) + end * t;
|
||||
}
|
||||
|
||||
// linear interpolation via int: 0=begin, base=end
|
||||
template <typename X, int base>
|
||||
[[nodiscard]] constexpr decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begin,
|
||||
const X& end,
|
||||
const int t) {
|
||||
return (begin * (base - t) + end * t) / base;
|
||||
}
|
||||
|
||||
// bilinear interpolation. s is for interpolating x00-x01 and x10-x11, and t is for the second
|
||||
// interpolation.
|
||||
template <typename X>
|
||||
[[nodiscard]] constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& x11,
|
||||
const float s, const float t) {
|
||||
auto y0 = Lerp(x00, x01, s);
|
||||
auto y1 = Lerp(x10, x11, s);
|
||||
return Lerp(y0, y1, t);
|
||||
}
|
||||
|
||||
// Utility vector factories
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr Vec2<T> MakeVec(const T& x, const T& y) {
|
||||
return Vec2<T>{x, y};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr Vec3<T> MakeVec(const T& x, const T& y, const T& z) {
|
||||
return Vec3<T>{x, y, z};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const T& y, const Vec2<T>& zw) {
|
||||
return MakeVec(x, y, zw[0], zw[1]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr Vec3<T> MakeVec(const Vec2<T>& xy, const T& z) {
|
||||
return MakeVec(xy[0], xy[1], z);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr Vec3<T> MakeVec(const T& x, const Vec2<T>& yz) {
|
||||
return MakeVec(x, yz[0], yz[1]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const T& y, const T& z, const T& w) {
|
||||
return Vec4<T>{x, y, z, w};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const T& z, const T& w) {
|
||||
return MakeVec(xy[0], xy[1], z, w);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const Vec2<T>& yz, const T& w) {
|
||||
return MakeVec(x, yz[0], yz[1], w);
|
||||
}
|
||||
|
||||
// NOTE: This has priority over "Vec2<Vec2<T>> MakeVec(const Vec2<T>& x, const Vec2<T>& y)".
|
||||
// Even if someone wanted to use an odd object like Vec2<Vec2<T>>, the compiler would error
|
||||
// out soon enough due to misuse of the returned structure.
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const Vec2<T>& zw) {
|
||||
return MakeVec(xy[0], xy[1], zw[0], zw[1]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr Vec4<T> MakeVec(const Vec3<T>& xyz, const T& w) {
|
||||
return MakeVec(xyz[0], xyz[1], xyz[2], w);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const Vec3<T>& yzw) {
|
||||
return MakeVec(x, yzw[0], yzw[1], yzw[2]);
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
|
||||
@@ -358,7 +358,7 @@ private:
|
||||
|
||||
ConnectionState(boost::asio::ip::tcp::socket&& client_socket_, async_pipe signal_pipe_, Kernel::KernelCore& kernel)
|
||||
: client_socket{std::move(client_socket_)}
|
||||
, signal_pipe{std::move(signal_pipe_)}
|
||||
, signal_pipe{signal_pipe_}
|
||||
, active_thread{kernel, nullptr}
|
||||
{}
|
||||
|
||||
|
||||
@@ -54,11 +54,11 @@ void PutValue(std::span<u8> buffer, const T& t) {
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
void BSD_USA::PollWork::Execute(BSD_USA* bsd) {
|
||||
void BSD::PollWork::Execute(BSD* bsd) {
|
||||
std::tie(ret, bsd_errno) = bsd->PollImpl(write_buffer, read_buffer, nfds, timeout);
|
||||
}
|
||||
|
||||
void BSD_USA::PollWork::Response(HLERequestContext& ctx) {
|
||||
void BSD::PollWork::Response(HLERequestContext& ctx) {
|
||||
if (write_buffer.size() > 0) {
|
||||
ctx.WriteBuffer(write_buffer);
|
||||
}
|
||||
@@ -69,11 +69,11 @@ void BSD_USA::PollWork::Response(HLERequestContext& ctx) {
|
||||
rb.PushEnum(bsd_errno);
|
||||
}
|
||||
|
||||
void BSD_USA::AcceptWork::Execute(BSD_USA* bsd) {
|
||||
void BSD::AcceptWork::Execute(BSD* bsd) {
|
||||
std::tie(ret, bsd_errno) = bsd->AcceptImpl(fd, write_buffer);
|
||||
}
|
||||
|
||||
void BSD_USA::AcceptWork::Response(HLERequestContext& ctx) {
|
||||
void BSD::AcceptWork::Response(HLERequestContext& ctx) {
|
||||
if (write_buffer.size() > 0) {
|
||||
ctx.WriteBuffer(write_buffer);
|
||||
}
|
||||
@@ -85,22 +85,22 @@ void BSD_USA::AcceptWork::Response(HLERequestContext& ctx) {
|
||||
rb.Push<u32>(static_cast<u32>(write_buffer.size()));
|
||||
}
|
||||
|
||||
void BSD_USA::ConnectWork::Execute(BSD_USA* bsd) {
|
||||
void BSD::ConnectWork::Execute(BSD* bsd) {
|
||||
bsd_errno = bsd->ConnectImpl(fd, addr);
|
||||
}
|
||||
|
||||
void BSD_USA::ConnectWork::Response(HLERequestContext& ctx) {
|
||||
void BSD::ConnectWork::Response(HLERequestContext& ctx) {
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push<s32>(bsd_errno == Errno::SUCCESS ? 0 : -1);
|
||||
rb.PushEnum(bsd_errno);
|
||||
}
|
||||
|
||||
void BSD_USA::RecvWork::Execute(BSD_USA* bsd) {
|
||||
void BSD::RecvWork::Execute(BSD* bsd) {
|
||||
std::tie(ret, bsd_errno) = bsd->RecvImpl(fd, flags, message);
|
||||
}
|
||||
|
||||
void BSD_USA::RecvWork::Response(HLERequestContext& ctx) {
|
||||
void BSD::RecvWork::Response(HLERequestContext& ctx) {
|
||||
ctx.WriteBuffer(message);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
@@ -109,11 +109,11 @@ void BSD_USA::RecvWork::Response(HLERequestContext& ctx) {
|
||||
rb.PushEnum(bsd_errno);
|
||||
}
|
||||
|
||||
void BSD_USA::RecvFromWork::Execute(BSD_USA* bsd) {
|
||||
void BSD::RecvFromWork::Execute(BSD* bsd) {
|
||||
std::tie(ret, bsd_errno) = bsd->RecvFromImpl(fd, flags, message, addr);
|
||||
}
|
||||
|
||||
void BSD_USA::RecvFromWork::Response(HLERequestContext& ctx) {
|
||||
void BSD::RecvFromWork::Response(HLERequestContext& ctx) {
|
||||
ctx.WriteBuffer(message, 0);
|
||||
if (!addr.empty()) {
|
||||
ctx.WriteBuffer(addr, 1);
|
||||
@@ -126,29 +126,29 @@ void BSD_USA::RecvFromWork::Response(HLERequestContext& ctx) {
|
||||
rb.Push<u32>(static_cast<u32>(addr.size()));
|
||||
}
|
||||
|
||||
void BSD_USA::SendWork::Execute(BSD_USA* bsd) {
|
||||
void BSD::SendWork::Execute(BSD* bsd) {
|
||||
std::tie(ret, bsd_errno) = bsd->SendImpl(fd, flags, message);
|
||||
}
|
||||
|
||||
void BSD_USA::SendWork::Response(HLERequestContext& ctx) {
|
||||
void BSD::SendWork::Response(HLERequestContext& ctx) {
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push<s32>(ret);
|
||||
rb.PushEnum(bsd_errno);
|
||||
}
|
||||
|
||||
void BSD_USA::SendToWork::Execute(BSD_USA* bsd) {
|
||||
void BSD::SendToWork::Execute(BSD* bsd) {
|
||||
std::tie(ret, bsd_errno) = bsd->SendToImpl(fd, flags, message, addr);
|
||||
}
|
||||
|
||||
void BSD_USA::SendToWork::Response(HLERequestContext& ctx) {
|
||||
void BSD::SendToWork::Response(HLERequestContext& ctx) {
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push<s32>(ret);
|
||||
rb.PushEnum(bsd_errno);
|
||||
}
|
||||
|
||||
void BSD_USA::RegisterClient(HLERequestContext& ctx) {
|
||||
void BSD::RegisterClient(HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service, "(STUBBED) called");
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
@@ -157,7 +157,7 @@ void BSD_USA::RegisterClient(HLERequestContext& ctx) {
|
||||
rb.Push<s32>(0); // bsd errno
|
||||
}
|
||||
|
||||
void BSD_USA::StartMonitoring(HLERequestContext& ctx) {
|
||||
void BSD::StartMonitoring(HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service, "(STUBBED) called");
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
@@ -165,7 +165,7 @@ void BSD_USA::StartMonitoring(HLERequestContext& ctx) {
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
||||
void BSD_USA::Socket(HLERequestContext& ctx) {
|
||||
void BSD::Socket(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const u32 domain = rp.Pop<u32>();
|
||||
const u32 type = rp.Pop<u32>();
|
||||
@@ -181,7 +181,7 @@ void BSD_USA::Socket(HLERequestContext& ctx) {
|
||||
rb.PushEnum(bsd_errno);
|
||||
}
|
||||
|
||||
void BSD_USA::SocketExempt(HLERequestContext& ctx) {
|
||||
void BSD::SocketExempt(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const u32 domain = rp.Pop<u32>();
|
||||
const u32 type = rp.Pop<u32>();
|
||||
@@ -200,7 +200,7 @@ void BSD_USA::SocketExempt(HLERequestContext& ctx) {
|
||||
rb.PushEnum(bsd_errno);
|
||||
}
|
||||
|
||||
void BSD_USA::Select(HLERequestContext& ctx) {
|
||||
void BSD::Select(HLERequestContext& ctx) {
|
||||
LOG_DEBUG(Service, "(STUBBED) called");
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
@@ -210,7 +210,7 @@ void BSD_USA::Select(HLERequestContext& ctx) {
|
||||
rb.Push<u32>(0); // bsd errno
|
||||
}
|
||||
|
||||
void BSD_USA::Poll(HLERequestContext& ctx) {
|
||||
void BSD::Poll(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 nfds = rp.Pop<s32>();
|
||||
const s32 timeout = rp.Pop<s32>();
|
||||
@@ -225,7 +225,7 @@ void BSD_USA::Poll(HLERequestContext& ctx) {
|
||||
});
|
||||
}
|
||||
|
||||
void BSD_USA::Accept(HLERequestContext& ctx) {
|
||||
void BSD::Accept(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
|
||||
@@ -237,7 +237,7 @@ void BSD_USA::Accept(HLERequestContext& ctx) {
|
||||
});
|
||||
}
|
||||
|
||||
void BSD_USA::Bind(HLERequestContext& ctx) {
|
||||
void BSD::Bind(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
|
||||
@@ -245,7 +245,7 @@ void BSD_USA::Bind(HLERequestContext& ctx) {
|
||||
BuildErrnoResponse(ctx, BindImpl(fd, ctx.ReadBuffer()));
|
||||
}
|
||||
|
||||
void BSD_USA::Connect(HLERequestContext& ctx) {
|
||||
void BSD::Connect(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
|
||||
@@ -257,7 +257,7 @@ void BSD_USA::Connect(HLERequestContext& ctx) {
|
||||
});
|
||||
}
|
||||
|
||||
void BSD_USA::GetPeerName(HLERequestContext& ctx) {
|
||||
void BSD::GetPeerName(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
|
||||
@@ -275,7 +275,7 @@ void BSD_USA::GetPeerName(HLERequestContext& ctx) {
|
||||
rb.Push<u32>(static_cast<u32>(write_buffer.size()));
|
||||
}
|
||||
|
||||
void BSD_USA::GetSockName(HLERequestContext& ctx) {
|
||||
void BSD::GetSockName(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
|
||||
@@ -293,7 +293,7 @@ void BSD_USA::GetSockName(HLERequestContext& ctx) {
|
||||
rb.Push<u32>(static_cast<u32>(write_buffer.size()));
|
||||
}
|
||||
|
||||
void BSD_USA::GetSockOpt(HLERequestContext& ctx) {
|
||||
void BSD::GetSockOpt(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
const u32 level = rp.Pop<u32>();
|
||||
@@ -315,7 +315,7 @@ void BSD_USA::GetSockOpt(HLERequestContext& ctx) {
|
||||
rb.Push<u32>(static_cast<u32>(optval.size()));
|
||||
}
|
||||
|
||||
void BSD_USA::Listen(HLERequestContext& ctx) {
|
||||
void BSD::Listen(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
const s32 backlog = rp.Pop<s32>();
|
||||
@@ -325,7 +325,7 @@ void BSD_USA::Listen(HLERequestContext& ctx) {
|
||||
BuildErrnoResponse(ctx, ListenImpl(fd, backlog));
|
||||
}
|
||||
|
||||
void BSD_USA::Fcntl(HLERequestContext& ctx) {
|
||||
void BSD::Fcntl(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
const s32 cmd = rp.Pop<s32>();
|
||||
@@ -341,7 +341,7 @@ void BSD_USA::Fcntl(HLERequestContext& ctx) {
|
||||
rb.PushEnum(bsd_errno);
|
||||
}
|
||||
|
||||
void BSD_USA::SetSockOpt(HLERequestContext& ctx) {
|
||||
void BSD::SetSockOpt(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
@@ -355,7 +355,7 @@ void BSD_USA::SetSockOpt(HLERequestContext& ctx) {
|
||||
BuildErrnoResponse(ctx, SetSockOptImpl(fd, level, optname, optval));
|
||||
}
|
||||
|
||||
void BSD_USA::Shutdown(HLERequestContext& ctx) {
|
||||
void BSD::Shutdown(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
@@ -366,7 +366,7 @@ void BSD_USA::Shutdown(HLERequestContext& ctx) {
|
||||
BuildErrnoResponse(ctx, ShutdownImpl(fd, how));
|
||||
}
|
||||
|
||||
void BSD_USA::Recv(HLERequestContext& ctx) {
|
||||
void BSD::Recv(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
@@ -381,7 +381,7 @@ void BSD_USA::Recv(HLERequestContext& ctx) {
|
||||
});
|
||||
}
|
||||
|
||||
void BSD_USA::RecvFrom(HLERequestContext& ctx) {
|
||||
void BSD::RecvFrom(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
@@ -398,7 +398,7 @@ void BSD_USA::RecvFrom(HLERequestContext& ctx) {
|
||||
});
|
||||
}
|
||||
|
||||
void BSD_USA::Send(HLERequestContext& ctx) {
|
||||
void BSD::Send(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
@@ -413,7 +413,7 @@ void BSD_USA::Send(HLERequestContext& ctx) {
|
||||
});
|
||||
}
|
||||
|
||||
void BSD_USA::SendTo(HLERequestContext& ctx) {
|
||||
void BSD::SendTo(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
const u32 flags = rp.Pop<u32>();
|
||||
@@ -429,7 +429,7 @@ void BSD_USA::SendTo(HLERequestContext& ctx) {
|
||||
});
|
||||
}
|
||||
|
||||
void BSD_USA::Write(HLERequestContext& ctx) {
|
||||
void BSD::Write(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
|
||||
@@ -442,7 +442,7 @@ void BSD_USA::Write(HLERequestContext& ctx) {
|
||||
});
|
||||
}
|
||||
|
||||
void BSD_USA::Read(HLERequestContext& ctx) {
|
||||
void BSD::Read(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
|
||||
@@ -454,7 +454,7 @@ void BSD_USA::Read(HLERequestContext& ctx) {
|
||||
rb.Push<u32>(0); // bsd errno
|
||||
}
|
||||
|
||||
void BSD_USA::Close(HLERequestContext& ctx) {
|
||||
void BSD::Close(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const s32 fd = rp.Pop<s32>();
|
||||
|
||||
@@ -464,7 +464,7 @@ void BSD_USA::Close(HLERequestContext& ctx) {
|
||||
}
|
||||
|
||||
/// @brief Only bsd:s is able to dup()
|
||||
void BSD_USA::DuplicateSocket(HLERequestContext& ctx) {
|
||||
void BSD::DuplicateSocket(HLERequestContext& ctx) {
|
||||
struct InputParameters {
|
||||
s32 fd;
|
||||
u64 reserved;
|
||||
@@ -505,7 +505,7 @@ void BSD_USA::DuplicateSocket(HLERequestContext& ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
void BSD_USA::EventFd(HLERequestContext& ctx) {
|
||||
void BSD::EventFd(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const u64 initval = rp.Pop<u64>();
|
||||
const u32 flags = rp.Pop<u32>();
|
||||
@@ -516,12 +516,12 @@ void BSD_USA::EventFd(HLERequestContext& ctx) {
|
||||
}
|
||||
|
||||
template <typename Work>
|
||||
void BSD_USA::ExecuteWork(HLERequestContext& ctx, Work work) {
|
||||
void BSD::ExecuteWork(HLERequestContext& ctx, Work work) {
|
||||
work.Execute(this);
|
||||
work.Response(ctx);
|
||||
}
|
||||
|
||||
std::pair<s32, Errno> BSD_USA::SocketImpl(Domain domain, Type type, Protocol protocol) {
|
||||
std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protocol) {
|
||||
// user bsd:u has restrictions on SOCK_SEQPACKET and SOCK_RAW
|
||||
if (is_user && (type == Type::SEQPACKET || type == Type::RAW)) {
|
||||
if (type == Type::RAW && domain == Domain::INET && protocol == Protocol::ICMP) {
|
||||
@@ -565,7 +565,7 @@ std::pair<s32, Errno> BSD_USA::SocketImpl(Domain domain, Type type, Protocol pro
|
||||
return {fd, Errno::SUCCESS};
|
||||
}
|
||||
|
||||
std::pair<s32, Errno> BSD_USA::PollImpl(std::vector<u8>& write_buffer, std::span<const u8> read_buffer,
|
||||
std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::span<const u8> read_buffer,
|
||||
s32 nfds, s32 timeout) {
|
||||
if (nfds <= 0) {
|
||||
// When no entries are provided, -1 is returned with errno zero
|
||||
@@ -632,7 +632,7 @@ std::pair<s32, Errno> BSD_USA::PollImpl(std::vector<u8>& write_buffer, std::span
|
||||
return Translate(result);
|
||||
}
|
||||
|
||||
std::pair<s32, Errno> BSD_USA::AcceptImpl(s32 fd, std::vector<u8>& write_buffer) {
|
||||
std::pair<s32, Errno> BSD::AcceptImpl(s32 fd, std::vector<u8>& write_buffer) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return {-1, Errno::BADF};
|
||||
}
|
||||
@@ -660,7 +660,7 @@ std::pair<s32, Errno> BSD_USA::AcceptImpl(s32 fd, std::vector<u8>& write_buffer)
|
||||
return {new_fd, Errno::SUCCESS};
|
||||
}
|
||||
|
||||
Errno BSD_USA::BindImpl(s32 fd, std::span<const u8> addr) {
|
||||
Errno BSD::BindImpl(s32 fd, std::span<const u8> addr) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return Errno::BADF;
|
||||
}
|
||||
@@ -675,7 +675,7 @@ Errno BSD_USA::BindImpl(s32 fd, std::span<const u8> addr) {
|
||||
return Translate(file_descriptors[fd]->socket->Bind(Translate(addr_in)));
|
||||
}
|
||||
|
||||
Errno BSD_USA::ConnectImpl(s32 fd, std::span<const u8> addr) {
|
||||
Errno BSD::ConnectImpl(s32 fd, std::span<const u8> addr) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return Errno::BADF;
|
||||
}
|
||||
@@ -698,7 +698,7 @@ Errno BSD_USA::ConnectImpl(s32 fd, std::span<const u8> addr) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Errno BSD_USA::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
||||
Errno BSD::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return Errno::BADF;
|
||||
}
|
||||
@@ -720,7 +720,7 @@ Errno BSD_USA::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
||||
return Translate(bsd_errno);
|
||||
}
|
||||
|
||||
Errno BSD_USA::GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
||||
Errno BSD::GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return Errno::BADF;
|
||||
}
|
||||
@@ -742,7 +742,7 @@ Errno BSD_USA::GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
||||
return Translate(bsd_errno);
|
||||
}
|
||||
|
||||
Errno BSD_USA::ListenImpl(s32 fd, s32 backlog) {
|
||||
Errno BSD::ListenImpl(s32 fd, s32 backlog) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return Errno::BADF;
|
||||
}
|
||||
@@ -753,7 +753,7 @@ Errno BSD_USA::ListenImpl(s32 fd, s32 backlog) {
|
||||
return Translate(file_descriptors[fd]->socket->Listen(backlog));
|
||||
}
|
||||
|
||||
std::pair<s32, Errno> BSD_USA::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) {
|
||||
std::pair<s32, Errno> BSD::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return {-1, Errno::BADF};
|
||||
}
|
||||
@@ -783,7 +783,7 @@ std::pair<s32, Errno> BSD_USA::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) {
|
||||
}
|
||||
}
|
||||
|
||||
Errno BSD_USA::GetSockOptImpl(s32 fd, u32 level, OptName optname, std::vector<u8>& optval) {
|
||||
Errno BSD::GetSockOptImpl(s32 fd, u32 level, OptName optname, std::vector<u8>& optval) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return Errno::BADF;
|
||||
}
|
||||
@@ -818,7 +818,7 @@ Errno BSD_USA::GetSockOptImpl(s32 fd, u32 level, OptName optname, std::vector<u8
|
||||
}
|
||||
}
|
||||
|
||||
Errno BSD_USA::SetSockOptImpl(s32 fd, u32 level, OptName optname, std::span<const u8> optval) {
|
||||
Errno BSD::SetSockOptImpl(s32 fd, u32 level, OptName optname, std::span<const u8> optval) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return Errno::BADF;
|
||||
}
|
||||
@@ -872,7 +872,7 @@ Errno BSD_USA::SetSockOptImpl(s32 fd, u32 level, OptName optname, std::span<cons
|
||||
}
|
||||
}
|
||||
|
||||
Errno BSD_USA::ShutdownImpl(s32 fd, s32 how) {
|
||||
Errno BSD::ShutdownImpl(s32 fd, s32 how) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return Errno::BADF;
|
||||
}
|
||||
@@ -884,7 +884,7 @@ Errno BSD_USA::ShutdownImpl(s32 fd, s32 how) {
|
||||
return Translate(file_descriptors[fd]->socket->Shutdown(host_how));
|
||||
}
|
||||
|
||||
std::pair<s32, Errno> BSD_USA::RecvImpl(s32 fd, u32 flags, std::vector<u8>& message) {
|
||||
std::pair<s32, Errno> BSD::RecvImpl(s32 fd, u32 flags, std::vector<u8>& message) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return {-1, Errno::BADF};
|
||||
}
|
||||
@@ -911,7 +911,7 @@ std::pair<s32, Errno> BSD_USA::RecvImpl(s32 fd, u32 flags, std::vector<u8>& mess
|
||||
return {ret, bsd_errno};
|
||||
}
|
||||
|
||||
std::pair<s32, Errno> BSD_USA::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& message,
|
||||
std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& message,
|
||||
std::vector<u8>& addr) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return {-1, Errno::BADF};
|
||||
@@ -958,7 +958,7 @@ std::pair<s32, Errno> BSD_USA::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>&
|
||||
return {ret, bsd_errno};
|
||||
}
|
||||
|
||||
std::pair<s32, Errno> BSD_USA::SendImpl(s32 fd, u32 flags, std::span<const u8> message) {
|
||||
std::pair<s32, Errno> BSD::SendImpl(s32 fd, u32 flags, std::span<const u8> message) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return {-1, Errno::BADF};
|
||||
}
|
||||
@@ -969,7 +969,7 @@ std::pair<s32, Errno> BSD_USA::SendImpl(s32 fd, u32 flags, std::span<const u8> m
|
||||
return Translate(file_descriptors[fd]->socket->Send(message, flags));
|
||||
}
|
||||
|
||||
std::pair<s32, Errno> BSD_USA::SendToImpl(s32 fd, u32 flags, std::span<const u8> message,
|
||||
std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, std::span<const u8> message,
|
||||
std::span<const u8> addr) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return {-1, Errno::BADF};
|
||||
@@ -991,7 +991,7 @@ std::pair<s32, Errno> BSD_USA::SendToImpl(s32 fd, u32 flags, std::span<const u8>
|
||||
return Translate(file_descriptors[fd]->socket->SendTo(flags, message, p_addr_in));
|
||||
}
|
||||
|
||||
Errno BSD_USA::CloseImpl(s32 fd) {
|
||||
Errno BSD::CloseImpl(s32 fd) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return Errno::BADF;
|
||||
}
|
||||
@@ -1011,7 +1011,7 @@ Errno BSD_USA::CloseImpl(s32 fd) {
|
||||
return bsd_errno;
|
||||
}
|
||||
|
||||
std::variant<s32, Errno> BSD_USA::DuplicateSocketImpl(s32 fd) {
|
||||
std::variant<s32, Errno> BSD::DuplicateSocketImpl(s32 fd) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return Errno::BADF;
|
||||
}
|
||||
@@ -1030,7 +1030,7 @@ std::variant<s32, Errno> BSD_USA::DuplicateSocketImpl(s32 fd) {
|
||||
return new_fd;
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<Network::SocketBase>> BSD_USA::GetSocket(s32 fd) {
|
||||
std::optional<std::shared_ptr<Network::SocketBase>> BSD::GetSocket(s32 fd) {
|
||||
if (!IsFileDescriptorValid(fd)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -1041,7 +1041,7 @@ std::optional<std::shared_ptr<Network::SocketBase>> BSD_USA::GetSocket(s32 fd) {
|
||||
return file_descriptors[fd]->socket;
|
||||
}
|
||||
|
||||
s32 BSD_USA::FindFreeFileDescriptorHandle() noexcept {
|
||||
s32 BSD::FindFreeFileDescriptorHandle() noexcept {
|
||||
for (s32 fd = 0; fd < static_cast<s32>(file_descriptors.size()); ++fd) {
|
||||
if (!file_descriptors[fd]) {
|
||||
return fd;
|
||||
@@ -1050,7 +1050,7 @@ s32 BSD_USA::FindFreeFileDescriptorHandle() noexcept {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool BSD_USA::IsFileDescriptorValid(s32 fd) const noexcept {
|
||||
bool BSD::IsFileDescriptorValid(s32 fd) const noexcept {
|
||||
if (fd > static_cast<s32>(MAX_FD) || fd < 0) {
|
||||
LOG_ERROR(Service, "Invalid file descriptor handle={}", fd);
|
||||
return false;
|
||||
@@ -1062,7 +1062,7 @@ bool BSD_USA::IsFileDescriptorValid(s32 fd) const noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
void BSD_USA::BuildErrnoResponse(HLERequestContext& ctx, Errno bsd_errno) const noexcept {
|
||||
void BSD::BuildErrnoResponse(HLERequestContext& ctx, Errno bsd_errno) const noexcept {
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
|
||||
rb.Push(ResultSuccess);
|
||||
@@ -1070,7 +1070,7 @@ void BSD_USA::BuildErrnoResponse(HLERequestContext& ctx, Errno bsd_errno) const
|
||||
rb.PushEnum(bsd_errno);
|
||||
}
|
||||
|
||||
void BSD_USA::OnProxyPacketReceived(const Network::ProxyPacket& packet) {
|
||||
void BSD::OnProxyPacketReceived(const Network::ProxyPacket& packet) {
|
||||
for (auto& optional_descriptor : file_descriptors) {
|
||||
if (!optional_descriptor.has_value()) {
|
||||
continue;
|
||||
@@ -1080,43 +1080,43 @@ void BSD_USA::OnProxyPacketReceived(const Network::ProxyPacket& packet) {
|
||||
}
|
||||
}
|
||||
|
||||
BSD_USA::BSD_USA(Core::System& system_, const char* name, bool is_user_)
|
||||
BSD::BSD(Core::System& system_, const char* name, bool is_user_)
|
||||
: ServiceFramework{system_, name}
|
||||
, is_user{is_user_} {
|
||||
// clang-format off
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, &BSD_USA::RegisterClient, "RegisterClient"},
|
||||
{1, &BSD_USA::StartMonitoring, "StartMonitoring"},
|
||||
{2, &BSD_USA::Socket, "Socket"},
|
||||
{3, &BSD_USA::SocketExempt, "SocketExempt"},
|
||||
{0, &BSD::RegisterClient, "RegisterClient"},
|
||||
{1, &BSD::StartMonitoring, "StartMonitoring"},
|
||||
{2, &BSD::Socket, "Socket"},
|
||||
{3, &BSD::SocketExempt, "SocketExempt"},
|
||||
{4, nullptr, "Open"},
|
||||
{5, &BSD_USA::Select, "Select"},
|
||||
{6, &BSD_USA::Poll, "Poll"},
|
||||
{5, &BSD::Select, "Select"},
|
||||
{6, &BSD::Poll, "Poll"},
|
||||
{7, nullptr, "Sysctl"},
|
||||
{8, &BSD_USA::Recv, "Recv"},
|
||||
{9, &BSD_USA::RecvFrom, "RecvFrom"},
|
||||
{10, &BSD_USA::Send, "Send"},
|
||||
{11, &BSD_USA::SendTo, "SendTo"},
|
||||
{12, &BSD_USA::Accept, "Accept"},
|
||||
{13, &BSD_USA::Bind, "Bind"},
|
||||
{14, &BSD_USA::Connect, "Connect"},
|
||||
{15, &BSD_USA::GetPeerName, "GetPeerName"},
|
||||
{16, &BSD_USA::GetSockName, "GetSockName"},
|
||||
{17, &BSD_USA::GetSockOpt, "GetSockOpt"},
|
||||
{18, &BSD_USA::Listen, "Listen"},
|
||||
{8, &BSD::Recv, "Recv"},
|
||||
{9, &BSD::RecvFrom, "RecvFrom"},
|
||||
{10, &BSD::Send, "Send"},
|
||||
{11, &BSD::SendTo, "SendTo"},
|
||||
{12, &BSD::Accept, "Accept"},
|
||||
{13, &BSD::Bind, "Bind"},
|
||||
{14, &BSD::Connect, "Connect"},
|
||||
{15, &BSD::GetPeerName, "GetPeerName"},
|
||||
{16, &BSD::GetSockName, "GetSockName"},
|
||||
{17, &BSD::GetSockOpt, "GetSockOpt"},
|
||||
{18, &BSD::Listen, "Listen"},
|
||||
{19, nullptr, "Ioctl"},
|
||||
{20, &BSD_USA::Fcntl, "Fcntl"},
|
||||
{21, &BSD_USA::SetSockOpt, "SetSockOpt"},
|
||||
{22, &BSD_USA::Shutdown, "Shutdown"},
|
||||
{20, &BSD::Fcntl, "Fcntl"},
|
||||
{21, &BSD::SetSockOpt, "SetSockOpt"},
|
||||
{22, &BSD::Shutdown, "Shutdown"},
|
||||
{23, nullptr, "ShutdownAllSockets"},
|
||||
{24, &BSD_USA::Write, "Write"},
|
||||
{25, &BSD_USA::Read, "Read"},
|
||||
{26, &BSD_USA::Close, "Close"},
|
||||
{27, &BSD_USA::DuplicateSocket, "DuplicateSocket"},
|
||||
{24, &BSD::Write, "Write"},
|
||||
{25, &BSD::Read, "Read"},
|
||||
{26, &BSD::Close, "Close"},
|
||||
{27, &BSD::DuplicateSocket, "DuplicateSocket"},
|
||||
{28, nullptr, "GetResourceStatistics"},
|
||||
{29, nullptr, "RecvMMsg"}, //3.0.0+
|
||||
{30, nullptr, "SendMMsg"}, //3.0.0+
|
||||
{31, &BSD_USA::EventFd, "EventFd"}, //7.0.0+
|
||||
{31, &BSD::EventFd, "EventFd"}, //7.0.0+
|
||||
{32, nullptr, "RegisterResourceStatisticsName"}, //7.0.0+
|
||||
{33, nullptr, "RegisterClientShared"}, //10.0.0+
|
||||
{34, nullptr, "GetSocketStatistics"}, //15.0.0+
|
||||
@@ -1144,13 +1144,13 @@ BSD_USA::BSD_USA(Core::System& system_, const char* name, bool is_user_)
|
||||
}
|
||||
}
|
||||
|
||||
BSD_USA::~BSD_USA() {
|
||||
BSD::~BSD() {
|
||||
if (auto room_member = Network::GetRoomMember().lock()) {
|
||||
room_member->Unbind(proxy_packet_received);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> BSD_USA::LockService() noexcept {
|
||||
std::unique_lock<std::mutex> BSD::LockService() noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -27,10 +27,10 @@ class Socket;
|
||||
|
||||
namespace Service::Sockets {
|
||||
|
||||
class BSD_USA final : public ServiceFramework<BSD_USA> {
|
||||
class BSD final : public ServiceFramework<BSD> {
|
||||
public:
|
||||
explicit BSD_USA(Core::System& system_, const char* name, bool is_user);
|
||||
~BSD_USA() override;
|
||||
explicit BSD(Core::System& system_, const char* name, bool is_user);
|
||||
~BSD() override;
|
||||
|
||||
// These methods are called from SSL; the first two are also called from
|
||||
// this class for the corresponding IPC methods.
|
||||
@@ -50,7 +50,7 @@ private:
|
||||
};
|
||||
|
||||
struct PollWork {
|
||||
void Execute(BSD_USA* bsd);
|
||||
void Execute(BSD* bsd);
|
||||
void Response(HLERequestContext& ctx);
|
||||
|
||||
s32 nfds;
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
};
|
||||
|
||||
struct AcceptWork {
|
||||
void Execute(BSD_USA* bsd);
|
||||
void Execute(BSD* bsd);
|
||||
void Response(HLERequestContext& ctx);
|
||||
|
||||
s32 fd;
|
||||
@@ -72,7 +72,7 @@ private:
|
||||
};
|
||||
|
||||
struct ConnectWork {
|
||||
void Execute(BSD_USA* bsd);
|
||||
void Execute(BSD* bsd);
|
||||
void Response(HLERequestContext& ctx);
|
||||
|
||||
s32 fd;
|
||||
@@ -81,7 +81,7 @@ private:
|
||||
};
|
||||
|
||||
struct RecvWork {
|
||||
void Execute(BSD_USA* bsd);
|
||||
void Execute(BSD* bsd);
|
||||
void Response(HLERequestContext& ctx);
|
||||
|
||||
s32 fd;
|
||||
@@ -92,7 +92,7 @@ private:
|
||||
};
|
||||
|
||||
struct RecvFromWork {
|
||||
void Execute(BSD_USA* bsd);
|
||||
void Execute(BSD* bsd);
|
||||
void Response(HLERequestContext& ctx);
|
||||
|
||||
s32 fd;
|
||||
@@ -104,7 +104,7 @@ private:
|
||||
};
|
||||
|
||||
struct SendWork {
|
||||
void Execute(BSD_USA* bsd);
|
||||
void Execute(BSD* bsd);
|
||||
void Response(HLERequestContext& ctx);
|
||||
|
||||
s32 fd;
|
||||
@@ -115,7 +115,7 @@ private:
|
||||
};
|
||||
|
||||
struct SendToWork {
|
||||
void Execute(BSD_USA* bsd);
|
||||
void Execute(BSD* bsd);
|
||||
void Response(HLERequestContext& ctx);
|
||||
|
||||
s32 fd;
|
||||
|
||||
@@ -66,9 +66,9 @@ void LoopProcess(Core::System& system) {
|
||||
|
||||
server_manager->RegisterNamedService("ethc:c", std::make_shared<ETHC_C>(system));
|
||||
server_manager->RegisterNamedService("ethc:i", std::make_shared<ETHC_I>(system));
|
||||
server_manager->RegisterNamedService("bsd:s", std::make_shared<BSD_USA>(system, "bsd:s", false));
|
||||
server_manager->RegisterNamedService("bsd:u", std::make_shared<BSD_USA>(system, "bsd:u", true));
|
||||
server_manager->RegisterNamedService("bsd:a", std::make_shared<BSD_USA>(system, "bsd:a", true));
|
||||
server_manager->RegisterNamedService("bsd:s", std::make_shared<BSD>(system, "bsd:s", false));
|
||||
server_manager->RegisterNamedService("bsd:u", std::make_shared<BSD>(system, "bsd:u", true));
|
||||
server_manager->RegisterNamedService("bsd:a", std::make_shared<BSD>(system, "bsd:a", true));
|
||||
server_manager->RegisterNamedService("bsd:nu", std::make_shared<BSD_NU>(system));
|
||||
server_manager->RegisterNamedService("bsdcfg", std::make_shared<BSDCFG>(system, "bsdcfg"));
|
||||
server_manager->RegisterNamedService("ifcfg", std::make_shared<BSDCFG>(system, "ifcfg"));
|
||||
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
LOG_ERROR(Service_SSL,
|
||||
"do_not_close_socket was changed after setting socket; is this right?");
|
||||
} else {
|
||||
auto bsd = system.ServiceManager().GetService<Service::Sockets::BSD_USA>("bsd:u");
|
||||
auto bsd = system.ServiceManager().GetService<Service::Sockets::BSD>("bsd:u");
|
||||
if (bsd) {
|
||||
auto err = bsd->CloseImpl(fd);
|
||||
if (err != Service::Sockets::Errno::SUCCESS) {
|
||||
@@ -157,7 +157,7 @@ private:
|
||||
Result SetSocketDescriptorImpl(s32* out_fd, s32 fd) {
|
||||
LOG_DEBUG(Service_SSL, "called, fd={}", fd);
|
||||
ASSERT(!did_handshake);
|
||||
auto bsd = system.ServiceManager().GetService<Service::Sockets::BSD_USA>("bsd:u");
|
||||
auto bsd = system.ServiceManager().GetService<Service::Sockets::BSD>("bsd:u");
|
||||
ASSERT_OR_EXECUTE(bsd, { return ResultInternalError; });
|
||||
|
||||
auto const res_v = bsd->DuplicateSocketImpl(fd);
|
||||
|
||||
@@ -76,34 +76,57 @@ void ProtectMemory(const void* base, size_t size, bool is_executable) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static const HostFeature features = []() {
|
||||
HostFeature f{};
|
||||
HostFeature GetHostFeatures() {
|
||||
HostFeature features = {};
|
||||
#ifdef DYNARMIC_ENABLE_CPU_FEATURE_DETECTION
|
||||
using Cpu = Xbyak::util::Cpu;
|
||||
Xbyak::util::Cpu cpu_info{};
|
||||
if (cpu_info.has(Cpu::tSSSE3)) f |= HostFeature::SSSE3;
|
||||
if (cpu_info.has(Cpu::tSSE41)) f |= HostFeature::SSE41;
|
||||
if (cpu_info.has(Cpu::tSSE42)) f |= HostFeature::SSE42;
|
||||
if (cpu_info.has(Cpu::tAVX)) f |= HostFeature::AVX;
|
||||
if (cpu_info.has(Cpu::tAVX2)) f |= HostFeature::AVX2;
|
||||
if (cpu_info.has(Cpu::tAVX512F)) f |= HostFeature::AVX512F;
|
||||
if (cpu_info.has(Cpu::tAVX512CD)) f |= HostFeature::AVX512CD;
|
||||
if (cpu_info.has(Cpu::tAVX512VL)) f |= HostFeature::AVX512VL;
|
||||
if (cpu_info.has(Cpu::tAVX512BW)) f |= HostFeature::AVX512BW;
|
||||
if (cpu_info.has(Cpu::tAVX512DQ)) f |= HostFeature::AVX512DQ;
|
||||
if (cpu_info.has(Cpu::tAVX512_BITALG)) f |= HostFeature::AVX512BITALG;
|
||||
if (cpu_info.has(Cpu::tAVX512VBMI)) f |= HostFeature::AVX512VBMI;
|
||||
if (cpu_info.has(Cpu::tPCLMULQDQ)) f |= HostFeature::PCLMULQDQ;
|
||||
if (cpu_info.has(Cpu::tF16C)) f |= HostFeature::F16C;
|
||||
if (cpu_info.has(Cpu::tFMA)) f |= HostFeature::FMA;
|
||||
if (cpu_info.has(Cpu::tAESNI)) f |= HostFeature::AES;
|
||||
if (cpu_info.has(Cpu::tSHA)) f |= HostFeature::SHA;
|
||||
if (cpu_info.has(Cpu::tPOPCNT)) f |= HostFeature::POPCNT;
|
||||
if (cpu_info.has(Cpu::tBMI1)) f |= HostFeature::BMI1;
|
||||
if (cpu_info.has(Cpu::tBMI2)) f |= HostFeature::BMI2;
|
||||
if (cpu_info.has(Cpu::tLZCNT)) f |= HostFeature::LZCNT;
|
||||
if (cpu_info.has(Cpu::tGFNI)) f |= HostFeature::GFNI;
|
||||
if (cpu_info.has(Cpu::tWAITPKG)) f |= HostFeature::WAITPKG;
|
||||
if (cpu_info.has(Cpu::tSSSE3))
|
||||
features |= HostFeature::SSSE3;
|
||||
if (cpu_info.has(Cpu::tSSE41))
|
||||
features |= HostFeature::SSE41;
|
||||
if (cpu_info.has(Cpu::tSSE42))
|
||||
features |= HostFeature::SSE42;
|
||||
if (cpu_info.has(Cpu::tAVX))
|
||||
features |= HostFeature::AVX;
|
||||
if (cpu_info.has(Cpu::tAVX2))
|
||||
features |= HostFeature::AVX2;
|
||||
if (cpu_info.has(Cpu::tAVX512F))
|
||||
features |= HostFeature::AVX512F;
|
||||
if (cpu_info.has(Cpu::tAVX512CD))
|
||||
features |= HostFeature::AVX512CD;
|
||||
if (cpu_info.has(Cpu::tAVX512VL))
|
||||
features |= HostFeature::AVX512VL;
|
||||
if (cpu_info.has(Cpu::tAVX512BW))
|
||||
features |= HostFeature::AVX512BW;
|
||||
if (cpu_info.has(Cpu::tAVX512DQ))
|
||||
features |= HostFeature::AVX512DQ;
|
||||
if (cpu_info.has(Cpu::tAVX512_BITALG))
|
||||
features |= HostFeature::AVX512BITALG;
|
||||
if (cpu_info.has(Cpu::tAVX512VBMI))
|
||||
features |= HostFeature::AVX512VBMI;
|
||||
if (cpu_info.has(Cpu::tPCLMULQDQ))
|
||||
features |= HostFeature::PCLMULQDQ;
|
||||
if (cpu_info.has(Cpu::tF16C))
|
||||
features |= HostFeature::F16C;
|
||||
if (cpu_info.has(Cpu::tFMA))
|
||||
features |= HostFeature::FMA;
|
||||
if (cpu_info.has(Cpu::tAESNI))
|
||||
features |= HostFeature::AES;
|
||||
if (cpu_info.has(Cpu::tSHA))
|
||||
features |= HostFeature::SHA;
|
||||
if (cpu_info.has(Cpu::tPOPCNT))
|
||||
features |= HostFeature::POPCNT;
|
||||
if (cpu_info.has(Cpu::tBMI1))
|
||||
features |= HostFeature::BMI1;
|
||||
if (cpu_info.has(Cpu::tBMI2))
|
||||
features |= HostFeature::BMI2;
|
||||
if (cpu_info.has(Cpu::tLZCNT))
|
||||
features |= HostFeature::LZCNT;
|
||||
if (cpu_info.has(Cpu::tGFNI))
|
||||
features |= HostFeature::GFNI;
|
||||
if (cpu_info.has(Cpu::tWAITPKG))
|
||||
features |= HostFeature::WAITPKG;
|
||||
if (cpu_info.has(Cpu::tBMI2)) {
|
||||
// BMI2 instructions such as pdep and pext have been very slow up until Zen 3.
|
||||
// Check for Zen 3 or newer by its family (0x19).
|
||||
@@ -115,15 +138,12 @@ static const HostFeature features = []() {
|
||||
const u32 family_extended = mcl::bit::get_bits<20, 27>(data[0]);
|
||||
const u32 family = family_base + family_extended;
|
||||
if (family >= 0x19)
|
||||
f |= HostFeature::FastBMI2;
|
||||
features |= HostFeature::FastBMI2;
|
||||
} else {
|
||||
f |= HostFeature::FastBMI2;
|
||||
features |= HostFeature::FastBMI2;
|
||||
}
|
||||
}
|
||||
return f;
|
||||
#endif
|
||||
}();
|
||||
HostFeature GetHostFeatures() {
|
||||
return features;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "common/input.h"
|
||||
#include "common/param_package.h"
|
||||
#include "common/point.h"
|
||||
#include "common/quaternion.h"
|
||||
#include "common/vector_math.h"
|
||||
#include "hid_core/frontend/motion_input.h"
|
||||
#include "hid_core/hid_types.h"
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/quaternion.h"
|
||||
#include "common/vector_math.h"
|
||||
|
||||
namespace Core::HID {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/quaternion.h"
|
||||
#include "common/vector_math.h"
|
||||
#include "common/typed_address.h"
|
||||
#include "hid_core/resources/controller_base.h"
|
||||
#include "hid_core/resources/ring_lifo.h"
|
||||
|
||||
@@ -135,32 +135,25 @@ void Mouse::UpdateMotionInput() {
|
||||
|
||||
void Mouse::Move(int x, int y, int center_x, int center_y) {
|
||||
if (IsMousePanningEnabled()) {
|
||||
const auto mouse_change =
|
||||
(Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>();
|
||||
const float x_sensitivity =
|
||||
Settings::values.mouse_panning_x_sensitivity.GetValue() * default_panning_sensitivity;
|
||||
const float y_sensitivity =
|
||||
Settings::values.mouse_panning_y_sensitivity.GetValue() * default_panning_sensitivity;
|
||||
const float deadzone_counterweight =
|
||||
Settings::values.mouse_panning_deadzone_counterweight.GetValue() *
|
||||
default_deadzone_counterweight;
|
||||
|
||||
auto const mouse_change_int = Common::Vec2<int>(x, y) - Common::Vec2<int>(center_x, center_y);
|
||||
auto const mouse_change = Common::Vec2<float>(float(mouse_change_int.x), float(mouse_change_int.y));
|
||||
auto const x_sensitivity = Settings::values.mouse_panning_x_sensitivity.GetValue() * default_panning_sensitivity;
|
||||
auto const y_sensitivity = Settings::values.mouse_panning_y_sensitivity.GetValue() * default_panning_sensitivity;
|
||||
auto const deadzone_cw = Settings::values.mouse_panning_deadzone_counterweight.GetValue() * default_deadzone_counterweight;
|
||||
last_motion_change += {-mouse_change.y * x_sensitivity, -mouse_change.x * y_sensitivity, 0};
|
||||
last_mouse_change.x += mouse_change.x * x_sensitivity;
|
||||
last_mouse_change.y += mouse_change.y * y_sensitivity;
|
||||
|
||||
// Bind the mouse change to [0 <= deadzone_counterweight <= 1.0]
|
||||
// Bind the mouse change to [0 <= deadzone_cw <= 1.0]
|
||||
const float length = last_mouse_change.Length();
|
||||
if (length < deadzone_counterweight && length != 0.0f) {
|
||||
if (length < deadzone_cw && length != 0.0f) {
|
||||
last_mouse_change /= length;
|
||||
last_mouse_change *= deadzone_counterweight;
|
||||
last_mouse_change *= deadzone_cw;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (button_pressed) {
|
||||
const auto mouse_move = Common::MakeVec<int>(x, y) - mouse_origin;
|
||||
const auto mouse_move = Common::Vec2<int>(x, y) - mouse_origin;
|
||||
const float x_sensitivity =
|
||||
Settings::values.mouse_panning_x_sensitivity.GetValue() * default_stick_sensitivity;
|
||||
const float y_sensitivity =
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
@@ -12,13 +9,13 @@
|
||||
namespace VideoCommon {
|
||||
|
||||
class UsageTracker {
|
||||
// PAGE_SHIFT is a macro on FreeBSD
|
||||
static constexpr size_t BUFFER_BYTES_PER_BITSHIFT = 6;
|
||||
static constexpr size_t BUFFER_PAGE_SHIFT = 6 + BUFFER_BYTES_PER_BITSHIFT;
|
||||
static constexpr size_t BUFFER_PAGE_BYTES = 1 << BUFFER_PAGE_SHIFT;
|
||||
static constexpr size_t BYTES_PER_BIT_SHIFT = 6;
|
||||
static constexpr size_t PAGE_SHIFT = 6 + BYTES_PER_BIT_SHIFT;
|
||||
static constexpr size_t PAGE_BYTES = 1 << PAGE_SHIFT;
|
||||
|
||||
public:
|
||||
explicit UsageTracker(size_t size) {
|
||||
const size_t num_pages = (size >> BUFFER_PAGE_SHIFT) + 1;
|
||||
const size_t num_pages = (size >> PAGE_SHIFT) + 1;
|
||||
pages.resize(num_pages, 0ULL);
|
||||
}
|
||||
|
||||
@@ -27,8 +24,8 @@ public:
|
||||
}
|
||||
|
||||
void Track(u64 offset, u64 size) noexcept {
|
||||
const size_t page = offset >> BUFFER_PAGE_SHIFT;
|
||||
const size_t page_end = (offset + size) >> BUFFER_PAGE_SHIFT;
|
||||
const size_t page = offset >> PAGE_SHIFT;
|
||||
const size_t page_end = (offset + size) >> PAGE_SHIFT;
|
||||
if (page_end < page || page_end >= pages.size()) {
|
||||
return;
|
||||
}
|
||||
@@ -40,13 +37,13 @@ public:
|
||||
pages[i] = ~u64{0};
|
||||
}
|
||||
const size_t offset_end = offset + size;
|
||||
const size_t offset_end_page_aligned = Common::AlignDown(offset_end, BUFFER_PAGE_BYTES);
|
||||
const size_t offset_end_page_aligned = Common::AlignDown(offset_end, PAGE_BYTES);
|
||||
TrackPage(page_end, offset_end_page_aligned, offset_end - offset_end_page_aligned);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsUsed(u64 offset, u64 size) const noexcept {
|
||||
const size_t page = offset >> BUFFER_PAGE_SHIFT;
|
||||
const size_t page_end = (offset + size) >> BUFFER_PAGE_SHIFT;
|
||||
const size_t page = offset >> PAGE_SHIFT;
|
||||
const size_t page_end = (offset + size) >> PAGE_SHIFT;
|
||||
if (page_end < page || page_end >= pages.size()) {
|
||||
return false;
|
||||
}
|
||||
@@ -59,23 +56,23 @@ public:
|
||||
}
|
||||
}
|
||||
const size_t offset_end = offset + size;
|
||||
const size_t offset_end_page_aligned = Common::AlignDown(offset_end, BUFFER_PAGE_BYTES);
|
||||
const size_t offset_end_page_aligned = Common::AlignDown(offset_end, PAGE_BYTES);
|
||||
return IsPageUsed(page_end, offset_end_page_aligned, offset_end - offset_end_page_aligned);
|
||||
}
|
||||
|
||||
private:
|
||||
void TrackPage(u64 page, u64 offset, u64 size) noexcept {
|
||||
const size_t offset_in_page = offset % BUFFER_PAGE_BYTES;
|
||||
const size_t first_bit = offset_in_page >> BUFFER_BYTES_PER_BITSHIFT;
|
||||
const size_t num_bits = std::min<size_t>(size, BUFFER_PAGE_BYTES) >> BUFFER_BYTES_PER_BITSHIFT;
|
||||
const size_t offset_in_page = offset % PAGE_BYTES;
|
||||
const size_t first_bit = offset_in_page >> BYTES_PER_BIT_SHIFT;
|
||||
const size_t num_bits = std::min<size_t>(size, PAGE_BYTES) >> BYTES_PER_BIT_SHIFT;
|
||||
const size_t mask = ~u64{0} >> (64 - num_bits);
|
||||
pages[page] |= (~u64{0} & mask) << first_bit;
|
||||
}
|
||||
|
||||
bool IsPageUsed(u64 page, u64 offset, u64 size) const noexcept {
|
||||
const size_t offset_in_page = offset % BUFFER_PAGE_BYTES;
|
||||
const size_t first_bit = offset_in_page >> BUFFER_BYTES_PER_BITSHIFT;
|
||||
const size_t num_bits = std::min<size_t>(size, BUFFER_PAGE_BYTES) >> BUFFER_BYTES_PER_BITSHIFT;
|
||||
const size_t offset_in_page = offset % PAGE_BYTES;
|
||||
const size_t first_bit = offset_in_page >> BYTES_PER_BIT_SHIFT;
|
||||
const size_t num_bits = std::min<size_t>(size, PAGE_BYTES) >> BYTES_PER_BIT_SHIFT;
|
||||
const size_t mask = ~u64{0} >> (64 - num_bits);
|
||||
const size_t mask2 = (~u64{0} & mask) << first_bit;
|
||||
return (pages[page] & mask2) != 0;
|
||||
|
||||
@@ -2950,7 +2950,15 @@ void PlayerControlPreview::Draw3dCube(QPainter& p, QPointF center, const Common:
|
||||
};
|
||||
|
||||
for (Common::Vec3f& point : cube) {
|
||||
point.RotateFromOrigin(euler.x, euler.y, euler.z);
|
||||
float temp = point.y;
|
||||
point.y = std::cos(euler.x) * point.y - std::sin(euler.x) * point.z;
|
||||
point.z = std::sin(euler.x) * temp + std::cos(euler.x) * point.z;
|
||||
temp = point.x;
|
||||
point.x = std::cos(euler.y) * point.x + std::sin(euler.y) * point.z;
|
||||
point.z = -std::sin(euler.y) * temp + std::cos(euler.y) * point.z;
|
||||
temp = point.x;
|
||||
point.x = std::cos(euler.z) * point.x - std::sin(euler.z) * point.y;
|
||||
point.y = std::sin(euler.z) * temp + std::cos(euler.z) * point.y;
|
||||
point *= size;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user