JMath debug (#3023)

This commit is contained in:
Jcw87 2026-01-07 09:53:53 -08:00 committed by GitHub
parent a313c26f0b
commit 2b52bc59d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 42 additions and 29 deletions

View File

@ -64,8 +64,9 @@ struct TSinCosTable {
* @ingroup jsystem-jmath
*
*/
template<int N, typename T>
struct TAtanTable {
f32 table[1025];
T table[N + 1];
u8 pad[0x1C];
};
@ -75,7 +76,7 @@ struct TAtanTable {
*/
template<int N, typename T>
struct TAsinAcosTable {
T table[1025];
T table[N + 1];
u8 pad[0x1C];
T acos_(T x) const {
@ -96,7 +97,7 @@ struct TAsinAcosTable {
};
extern TSinCosTable<13, f32> sincosTable_;
extern TAtanTable atanTable_;
extern TAtanTable<1024, f32> atanTable_;
extern TAsinAcosTable<1024, f32> asinAcosTable_;
inline f32 acosDegree(f32 x) {

View File

@ -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

View File

@ -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 {

View File

@ -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);
}