summaryrefslogtreecommitdiff
path: root/src/JSystem/JMath
diff options
context:
space:
mode:
authorJcw87 <Jcw87@users.noreply.github.com>2026-01-07 09:53:53 -0800
committerGitHub <noreply@github.com>2026-01-07 19:53:53 +0200
commit2b52bc59d00bc83abce50c026447780d6c8ad943 (patch)
treec4689d5bef172f049c78f11b031eefd0f6d50049 /src/JSystem/JMath
parenta313c26f0bc6d11bddc2b24c4367dc1040f604a4 (diff)
JMath debug (#3023)
Diffstat (limited to 'src/JSystem/JMath')
-rw-r--r--src/JSystem/JMath/JMATrigonometric.cpp53
-rw-r--r--src/JSystem/JMath/JMath.cpp7
-rw-r--r--src/JSystem/JMath/random.cpp4
3 files changed, 38 insertions, 26 deletions
diff --git a/src/JSystem/JMath/JMATrigonometric.cpp b/src/JSystem/JMath/JMATrigonometric.cpp
index 89e36a413e..530602b8cd 100644
--- a/src/JSystem/JMath/JMATrigonometric.cpp
+++ b/src/JSystem/JMath/JMATrigonometric.cpp
@@ -15,26 +15,32 @@ struct pair {
A1 a1;
B1 b1;
pair() {
- f32 tmp = 0.0f;
- a1 = tmp;
- b1 = tmp;
- // a1 = A1();
- // b1 = B1();
+ a1 = A1();
+ b1 = B1();
}
};
} // namespace std
-inline f64 getConst() {
- return 6.2831854820251465;
-}
+namespace JMath {
+template<typename T>
+struct TAngleConstant_;
+
+template<>
+struct TAngleConstant_<f32> {
+ static f32 RADIAN_DEG180() { return M_PI;}
+ static f32 RADIAN_DEG360() { return M_PI * 2; }
+};
template<int N, typename T>
struct TSinCosTable {
std::pair<T, T> table[1 << N];
TSinCosTable() {
+ init();
+ }
+ void init() {
for (int i = 0; i < 1 << N; i++) {
- table[i].a1 = sin((i * getConst()) / (1 << N));
- table[i].b1 = cos((i * getConst()) / (1 << N));
+ table[i].a1 = sin((i * f64(TAngleConstant_<f32>::RADIAN_DEG360())) / (1 << N));
+ table[i].b1 = cos((i * f64(TAngleConstant_<f32>::RADIAN_DEG360())) / (1 << N));
}
}
};
@@ -43,37 +49,42 @@ inline f64 getConst2() {
return 9.765625E-4;
}
+template<int N, typename T>
struct TAtanTable {
- f32 table[1025];
+ T table[N + 1];
u8 pad[0x1C];
TAtanTable() {
- // (u32) cast needed for cmplwi instead of cmpwi
- for (int i = 0; i < (u32)1024; i++) {
+ init();
+ }
+ void init() {
+ for (int i = 0; i < u32(N); i++) {
table[i] = atan(getConst2() * i);
}
table[0] = 0.0f;
- table[1024] = 0.7853982; // 0.25 * PI
+ table[N] = TAngleConstant_<f32>::RADIAN_DEG180() * 0.25f; // 0.25 * PI
}
};
+template<int N, typename T>
struct TAsinAcosTable {
- f32 table[1025];
+ T table[N + 1];
u8 pad[0x1C];
TAsinAcosTable() {
- for (int i = 0; i < 1024; i++) {
+ init();
+ }
+ void init() {
+ for (int i = 0; i < N; i++) {
table[i] = asin(getConst2() * i);
}
table[0] = 0.0f;
- table[1024] = 0.7853982; // 0.25 * PI
+ table[N] = TAngleConstant_<f32>::RADIAN_DEG180() * 0.25f; // 0.25 * PI
}
};
-namespace JMath {
-
TSinCosTable<13, f32> sincosTable_ ATTRIBUTE_ALIGN(32);
-TAtanTable atanTable_ ATTRIBUTE_ALIGN(32);
+TAtanTable<1024, f32> atanTable_ ATTRIBUTE_ALIGN(32);
-TAsinAcosTable asinAcosTable_ ATTRIBUTE_ALIGN(32);
+TAsinAcosTable<1024, f32> asinAcosTable_ ATTRIBUTE_ALIGN(32);
} // namespace JMath
diff --git a/src/JSystem/JMath/JMath.cpp b/src/JSystem/JMath/JMath.cpp
index fe9a5c9cfd..40ba07e463 100644
--- a/src/JSystem/JMath/JMath.cpp
+++ b/src/JSystem/JMath/JMath.cpp
@@ -38,8 +38,9 @@ void JMAQuatLerp(__REGISTER const Quaternion* p, __REGISTER const Quaternion* q,
ps_sum0 dp, dp, dp, dp
}
#endif // clang-format on
-
- if (dp < 0.0) {
+ f32 local_78 = dp;
+ if (local_78 < 0.0) {
+ int unused;
dst->x = -t * (p->x + q->x) + p->x;
dst->y = -t * (p->y + q->y) + p->y;
dst->z = -t * (p->z + q->z) + p->z;
@@ -73,7 +74,7 @@ void JMAFastVECNormalize(__REGISTER const Vec* src, __REGISTER Vec* dst) {
void JMAVECScaleAdd(__REGISTER const Vec* vec1, __REGISTER const Vec* vec2, __REGISTER Vec* dst,
__REGISTER f32 scale) {
__REGISTER f32 v1xy;
- __REGISTER f32 v2xy = scale;
+ __REGISTER f32 v2xy;
__REGISTER f32 rxy, v1z, v2z, rz;
#ifdef __MWERKS__ // clang-format off
asm {
diff --git a/src/JSystem/JMath/random.cpp b/src/JSystem/JMath/random.cpp
index add311c729..389d614d0c 100644
--- a/src/JSystem/JMath/random.cpp
+++ b/src/JSystem/JMath/random.cpp
@@ -2,6 +2,6 @@
#include "JSystem/JMath/random.h"
-JMath::TRandom_fast_::TRandom_fast_(u32 param_0) {
- value = param_0;
+JMath::TRandom_fast_::TRandom_fast_(u32 seed) {
+ setSeed(seed);
}