diff options
Diffstat (limited to 'Source/Core/Common')
| -rw-r--r-- | Source/Core/Common/CommonPaths.h | 1 | ||||
| -rw-r--r-- | Source/Core/Common/FileUtil.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/Common/FileUtil.h | 1 | ||||
| -rw-r--r-- | Source/Core/Common/MathUtil.h | 49 | ||||
| -rw-r--r-- | Source/Core/Common/Matrix.cpp | 5 | ||||
| -rw-r--r-- | Source/Core/Common/Matrix.h | 14 |
6 files changed, 49 insertions, 23 deletions
diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index 474890c4d8..4fa4b4f34a 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -92,6 +92,7 @@ #define WIISDSYNC_DIR "WiiSDSync" #define ASSEMBLY_DIR "SavedAssembly" #define WIIBANNERS_DIR "WiiBanners" +#define SOUNDS_DIR "Sounds" // This one is only used to remove it if it was present #define SHADERCACHE_LEGACY_DIR "ShaderCache" diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index ba52f63094..50d6b036f4 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -915,6 +915,7 @@ static void RebuildUserDirectories(unsigned int dir_index) s_user_paths[F_GBABIOS_IDX] = s_user_paths[D_GBAUSER_IDX] + GBA_BIOS; s_user_paths[D_ASM_ROOT_IDX] = s_user_paths[D_USER_IDX] + ASSEMBLY_DIR DIR_SEP; + s_user_paths[D_SOUNDS_IDX] = s_user_paths[D_LOAD_IDX] + SOUNDS_DIR DIR_SEP; // The shader cache has moved to the cache directory, so remove the old one. // TODO: remove that someday. @@ -975,6 +976,7 @@ static void RebuildUserDirectories(unsigned int dir_index) s_user_paths[D_DYNAMICINPUT_IDX] = s_user_paths[D_LOAD_IDX] + DYNAMICINPUT_DIR DIR_SEP; s_user_paths[D_GRAPHICSMOD_IDX] = s_user_paths[D_LOAD_IDX] + GRAPHICSMOD_DIR DIR_SEP; s_user_paths[D_BANNERS_WIIROOT_IDX] = s_user_paths[D_LOAD_IDX] + WIIBANNERS_DIR DIR_SEP; + s_user_paths[D_SOUNDS_IDX] = s_user_paths[D_LOAD_IDX] + SOUNDS_DIR DIR_SEP; break; } } diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h index d5c8285305..9cb5fb7040 100644 --- a/Source/Core/Common/FileUtil.h +++ b/Source/Core/Common/FileUtil.h @@ -77,6 +77,7 @@ enum D_GPU_DRIVERS_FILE_REDIRECT, D_ASM_ROOT_IDX, D_BANNERS_WIIROOT_IDX, + D_SOUNDS_IDX, FIRST_FILE_USER_PATH_IDX, F_DOLPHINCONFIG_IDX = FIRST_FILE_USER_PATH_IDX, F_GCPADCONFIG_IDX, diff --git a/Source/Core/Common/MathUtil.h b/Source/Core/Common/MathUtil.h index 47440f2239..939d31b97a 100644 --- a/Source/Core/Common/MathUtil.h +++ b/Source/Core/Common/MathUtil.h @@ -8,15 +8,18 @@ #include <cmath> #include <concepts> #include <limits> +#include <numbers> #include <type_traits> #include <utility> +#include "Common/Assert.h" #include "Common/CommonTypes.h" namespace MathUtil { -constexpr double TAU = 6.2831853071795865; -constexpr double PI = TAU / 2; +template <std::floating_point T> +constexpr T TAU_v = std::numbers::pi_v<T> * 2; +constexpr double TAU = TAU_v<double>; constexpr double GRAVITY_ACCELERATION = 9.80665; template <typename T> @@ -25,12 +28,6 @@ constexpr auto Sign(const T& val) -> decltype((T{} < val) - (val < T{})) return (T{} < val) - (val < T{}); } -template <typename T, typename F> -constexpr auto Lerp(const T& x, const T& y, const F& a) -> decltype(x + (y - x) * a) -{ - return x + (y - x) * a; -} - // Casts the specified value to a Dest. The value will be clamped to fit in the destination type. // Warning: The result of SaturatingCast(NaN) is undefined. template <std::integral Dest, typename T> @@ -56,23 +53,21 @@ constexpr Dest SaturatingCast(T value) return static_cast<Dest>(value); } -template <typename T> +template <std::integral T> constexpr bool IsPow2(T imm) { - return imm > 0 && (imm & (imm - 1)) == 0; + if constexpr (std::is_signed_v<T>) + { + if (imm <= 0) + return false; + } + + return std::has_single_bit(static_cast<std::make_unsigned_t<T>>(imm)); } constexpr u32 NextPowerOf2(u32 value) { - --value; - value |= value >> 1; - value |= value >> 2; - value |= value >> 4; - value |= value >> 8; - value |= value >> 16; - ++value; - - return value; + return std::bit_ceil(value); } template <class T> @@ -173,6 +168,20 @@ private: // Rounds down. 0 -> undefined constexpr int IntLog2(u64 val) { - return 63 - std::countl_zero(val); + DEBUG_ASSERT(val != 0); + return std::bit_width(val) - 1; } + +template <std::floating_point T> +constexpr T DegreesToRadians(T degrees) +{ + return degrees * std::numbers::pi_v<T> / T(180); +} + +template <std::floating_point T> +constexpr T RadiansToDegrees(T radians) +{ + return radians / std::numbers::pi_v<T> * T(180); +} + } // namespace MathUtil diff --git a/Source/Core/Common/Matrix.cpp b/Source/Core/Common/Matrix.cpp index 9c75487111..92de573f87 100644 --- a/Source/Core/Common/Matrix.cpp +++ b/Source/Core/Common/Matrix.cpp @@ -4,8 +4,7 @@ #include "Common/Matrix.h" #include <cmath> - -#include "Common/MathUtil.h" +#include <numbers> namespace { @@ -136,7 +135,7 @@ Vec3 FromQuaternionToEuler(const Quaternion& q) const float sinp = 2 * (qw * qy - qz * qx); if (std::abs(sinp) >= 1) - result.y = std::copysign(MathUtil::PI / 2, sinp); // use 90 degrees if out of range + result.y = std::copysign(std::numbers::pi / 2, sinp); // use 90 degrees if out of range else result.y = std::asin(sinp); diff --git a/Source/Core/Common/Matrix.h b/Source/Core/Common/Matrix.h index 9aafd1bf83..b7de819934 100644 --- a/Source/Core/Common/Matrix.h +++ b/Source/Core/Common/Matrix.h @@ -37,6 +37,10 @@ union TVec3 constexpr T LengthSquared() const { return Dot(*this); } T Length() const { return std::sqrt(LengthSquared()); } TVec3 Normalized() const { return *this / Length(); } + static constexpr TVec3<T> Lerp(const TVec3<T>& a, const TVec3<T>& b, const TVec3<T>& t) + { + return {std::lerp(a.x, b.x, t.x), std::lerp(a.y, b.y, t.y), std::lerp(a.z, b.z, t.z)}; + } constexpr TVec3& operator+=(const TVec3& rhs) { @@ -163,6 +167,16 @@ union TVec4 return x == other.x && y == other.y && z == other.z && w == other.w; } + static constexpr TVec4<T> Lerp(const TVec4<T>& a, const TVec4<T>& b, const TVec4<T>& t) + { + return { + std::lerp(a.x, b.x, t.x), + std::lerp(a.y, b.y, t.y), + std::lerp(a.z, b.z, t.z), + std::lerp(a.w, b.w, t.w), + }; + } + constexpr T Dot(const TVec4& other) const { return x * other.x + y * other.y + z * other.z + w * other.w; |
