Reorganize library code into libs/ (#3119)

* Reorganize files into libs/{dolphin,JSystem,PowerPC_EABI_Support,revolution,TRK_MINNOW_DOLPHIN}

* Update configure.py and project.py for new libs structure

* Refactor `#include <dolphin/x.h>` -> `<x.h>`

* Remove `__REVOLUTION_SDK__` forwards from dolphin

* Fix dolphin/ references in revolution

* Wrap `#include <dolphin.h>` in `!__REVOLUTION_SDK__`

* Always build TRK against dolphin headers

* Resolve revolution SDK header resolution issues
This commit is contained in:
Luke Street
2026-03-01 15:35:36 -07:00
committed by GitHub
parent c9a46bd65b
commit 4df8ccc871
1740 changed files with 583 additions and 825 deletions
@@ -0,0 +1,183 @@
#ifndef JMATRIGONOMETRIC_H
#define JMATRIGONOMETRIC_H
#include <types.h>
#include <cmath>
#include <utility>
#ifdef __cplusplus
extern "C" {
#endif
extern double asin(double);
extern double atan(double);
#ifdef __cplusplus
}
#endif
namespace JMath {
template<typename T>
struct TAngleConstant_;
/**
* @ingroup jsystem-jmath
*
*/
template<>
struct TAngleConstant_<f32> {
static f32 RADIAN_DEG090() { return 1.5707964f; }
static f32 RADIAN_DEG180() { return 3.1415927f; }
static f32 RADIAN_DEG360() { return 6.2831855f; }
static f32 RADIAN_TO_DEGREE_FACTOR() { return 180.0f / RADIAN_DEG180(); }
};
/**
* @ingroup jsystem-jmath
*
*/
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].first = sin((i * f64(TAngleConstant_<f32>::RADIAN_DEG360())) / (1 << N));
table[i].second = cos((i * f64(TAngleConstant_<f32>::RADIAN_DEG360())) / (1 << N));
}
}
T sinShort(s16 v) const { return table[(u16)v >> (16U - N)].first; }
T cosShort(s16 v) const { return table[(u16)v >> (16U - N)].second; }
inline T sinLap(T v) const {
if (v < (T)0.0) {
return -table[(u16)(-(T)(1 << N) * v) & ((1 << N) - 1)].first;
}
return table[(u16)((T)(1 << N) * v) & ((1 << N) - 1)].first;
}
inline T sinDegree(T degree) const {
if (degree < (T)0.0) {
return -table[(u16)(-((T)(1 << N) / (T)360.0) * degree) & ((1 << N) - 1)].first;
}
return table[(u16)(((T)(1 << N) / (T)360.0) * degree) & ((1 << N) - 1)].first;
}
inline T cosDegree(T degree) const {
if (degree < (T)0.0) {
degree = -degree;
}
return table[(u16)(((T)(1 << N) / (T)360.0) * degree) & ((1 << N) - 1)].second;
}
inline T sinRadian(T radian) const {
if (radian < (T)0.0) {
return -table[(u16)(-(T)(1 << N) / TAngleConstant_<T>::RADIAN_DEG360() * radian) & ((1 << N) - 1)].first;
}
return table[(u16)((T)(1 << N) / TAngleConstant_<T>::RADIAN_DEG360() * radian) & ((1 << N) - 1)].first;
}
};
/**
* @ingroup jsystem-jmath
*
*/
template<int N, typename T>
struct TAtanTable {
T table[N + 1];
u8 pad[0x1C];
TAtanTable() {
init();
}
void init() {
// u32 cast needed for cmplwi instead of cmpwi
for (int i = 0; i < (u32)N; i++) {
table[i] = atan(i / (f64)N);
}
table[0] = 0.0f;
table[N] = TAngleConstant_<T>::RADIAN_DEG180() / 4.0f;
}
};
/**
* @ingroup jsystem-jmath
*
*/
template<int N, typename T>
struct TAsinAcosTable {
T table[N + 1];
u8 pad[0x1C];
TAsinAcosTable() {
init();
}
void init() {
for (int i = 0; i < 1024; i++) {
table[i] = asin(i / (f64)N);
}
table[0] = 0.0f;
table[N] = TAngleConstant_<T>::RADIAN_DEG180() / 4.0f;
}
T acos_(T x) const {
if (x >= 1.0f) {
return 0.0f;
} else if (x <= -1.0f) {
return TAngleConstant_<T>::RADIAN_DEG180();
} else if (x < 0.0f) {
return table[(u32)(-x * 1023.5f)] + TAngleConstant_<T>::RADIAN_DEG090();
} else {
return TAngleConstant_<T>::RADIAN_DEG090() - table[(u32)(x * 1023.5f)];
}
}
T acosDegree(T x) const {
return acos_(x) * TAngleConstant_<T>::RADIAN_TO_DEGREE_FACTOR();
}
};
extern TSinCosTable<13, f32> sincosTable_;
extern TAtanTable<1024, f32> atanTable_;
extern TAsinAcosTable<1024, f32> asinAcosTable_;
inline f32 acosDegree(f32 x) {
return asinAcosTable_.acosDegree(x);
}
}; // namespace JMath
inline f32 JMACosShort(s16 v) {
return JMath::sincosTable_.cosShort(v);
}
inline f32 JMASinShort(s16 v) {
return JMath::sincosTable_.sinShort(v);
}
inline f32 JMASCos(s16 v) {
return JMACosShort(v);
}
inline f32 JMASSin(s16 v) {
return JMASinShort(v);
}
inline f32 JMASinLap(f32 v) {
return JMath::sincosTable_.sinLap(v);
}
inline f32 JMASinDegree(f32 degree) {
return JMath::sincosTable_.sinDegree(degree);
}
inline f32 JMACosDegree(f32 degree) {
return JMath::sincosTable_.cosDegree(degree);
}
inline f32 JMASinRadian(f32 radian) {
return JMath::sincosTable_.sinRadian(radian);
}
#endif /* JMATRIGONOMETRIC_H */
+286
View File
@@ -0,0 +1,286 @@
#ifndef JMATH_H
#define JMATH_H
#include <mtx.h>
#include <cmath>
void JMAMTXApplyScale(const Mtx, Mtx, f32, f32, f32);
void JMAEulerToQuat(s16 param_0, s16 param_1, s16 param_2, Quaternion* param_3);
void JMAQuatLerp(const Quaternion*, const Quaternion*, f32, Quaternion*);
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);
inline int JMAAbs(int value) {
#ifdef __MWERKS__
return __abs(value);
#endif
}
inline f32 JMAAbs(f32 x) {
#ifdef __MWERKS__
return __fabsf(x);
#endif
}
inline f32 JMAFastReciprocal(f32 value) {
#ifdef __MWERKS__
return __fres(value);
#endif
}
inline float __frsqrtes(__REGISTER double f) {
#ifdef __MWERKS__
__REGISTER float out;
// clang-format off
asm {
frsqrte out, f
}
// clang-format on
return out;
#endif
}
inline f32 JMAFastSqrt(__REGISTER const f32 input) {
#ifdef __MWERKS__
if (input > 0.0f) {
__REGISTER f32 out;
asm {
frsqrte out, input
}
return out * input;
} else {
return input;
}
#endif
}
inline f32 JMAHermiteInterpolation(__REGISTER f32 p1, __REGISTER f32 p2, __REGISTER f32 p3,
__REGISTER f32 p4, __REGISTER f32 p5, __REGISTER f32 p6,
__REGISTER f32 p7) {
#ifdef __MWERKS__
__REGISTER f32 ff25;
__REGISTER f32 ff31;
__REGISTER f32 ff30;
__REGISTER f32 ff29;
__REGISTER f32 ff28;
__REGISTER f32 ff27;
__REGISTER f32 ff26;
// clang-format off
asm {
fsubs ff31, p1, p2
fsubs ff30, p5, p2
fdivs ff29, ff31, ff30
fmuls ff28,ff29,ff29
fadds ff25,ff29,ff29
fsubs ff27,ff28,ff29
fsubs ff30, p3, p6
fmsubs ff26,ff25,ff27,ff28
fmadds ff25,p4,ff27,p4
fmadds ff26,ff26,ff30,p3
fmadds ff25,p7,ff27,ff25
fmsubs ff25,ff29,p4,ff25
fnmsubs ff25,ff31,ff25,ff26
}
// clang-format on
return ff25;
#endif
}
namespace JMath {
template <typename T>
inline T fastSqrt(T value) {
return JMAFastSqrt(value);
}
inline f32 fastReciprocal(f32 value) {
return JMAFastReciprocal(value);
}
inline void fastVECNormalize(const Vec* src, Vec* dst) {
return JMAFastVECNormalize(src, dst);
}
inline void gekko_ps_copy3(__REGISTER void* dst, __REGISTER const void* src) {
#ifdef __MWERKS__
__REGISTER f32 src0;
__REGISTER f32 src1;
asm {
psq_l src0, 0(src), 0, 0
lfs src1, 8(src)
psq_st src0, 0(dst), 0, 0
stfs src1, 8(dst)
};
#endif
}
inline void gekko_ps_copy6(__REGISTER void* dst, __REGISTER const void* src) {
#ifdef __MWERKS__
__REGISTER f32 src0;
__REGISTER f32 src1;
__REGISTER f32 src2;
asm {
psq_l src0, 0(src), 0, 0
psq_l src1, 8(src), 0, 0
psq_l src2, 16(src), 0, 0
psq_st src0, 0(dst), 0, 0
psq_st src1, 8(dst), 0, 0
psq_st src2, 16(dst), 0, 0
};
#endif
}
inline void gekko_ps_copy12(__REGISTER void* dst, __REGISTER const void* src) {
#ifdef __MWERKS__
__REGISTER f32 src0;
__REGISTER f32 src1;
__REGISTER f32 src2;
__REGISTER f32 src3;
__REGISTER f32 src4;
__REGISTER f32 src5;
asm {
psq_l src0, 0(src), 0, 0
psq_l src1, 8(src), 0, 0
psq_l src2, 16(src), 0, 0
psq_l src3, 24(src), 0, 0
psq_l src4, 32(src), 0, 0
psq_l src5, 40(src), 0, 0
psq_st src0, 0(dst), 0, 0
psq_st src1, 8(dst), 0, 0
psq_st src2, 16(dst), 0, 0
psq_st src3, 24(dst), 0, 0
psq_st src4, 32(dst), 0, 0
psq_st src5, 40(dst), 0, 0
};
#endif
}
inline void gekko_ps_copy16(__REGISTER void* dst, __REGISTER const void* src) {
#ifdef __MWERKS__
__REGISTER f32 src0;
__REGISTER f32 src1;
__REGISTER f32 src2;
__REGISTER f32 src3;
__REGISTER f32 src4;
__REGISTER f32 src5;
__REGISTER f32 src6;
__REGISTER f32 src7;
asm {
psq_l src0, 0(src), 0, 0
psq_l src1, 8(src), 0, 0
psq_l src2, 16(src), 0, 0
psq_l src3, 24(src), 0, 0
psq_l src4, 32(src), 0, 0
psq_l src5, 40(src), 0, 0
psq_l src6, 48(src), 0, 0
psq_l src7, 56(src), 0, 0
psq_st src0, 0(dst), 0, 0
psq_st src1, 8(dst), 0, 0
psq_st src2, 16(dst), 0, 0
psq_st src3, 24(dst), 0, 0
psq_st src4, 32(dst), 0, 0
psq_st src5, 40(dst), 0, 0
psq_st src6, 48(dst), 0, 0
psq_st src7, 56(dst), 0, 0
};
#endif
}
}; // namespace JMath
namespace JMathInlineVEC {
inline void C_VECAdd(__REGISTER const Vec* a, __REGISTER const Vec* b, __REGISTER Vec* ab) {
#ifdef __MWERKS__
__REGISTER f32 axy;
__REGISTER f32 bxy;
__REGISTER f32 sumab;
__REGISTER f32 az;
__REGISTER f32 bz;
__REGISTER f32 sumz;
asm {
psq_l axy, 0(a), 0, 0
psq_l bxy, 0(b), 0, 0
ps_add sumab, axy, bxy
psq_st sumab, 0(ab), 0, 0
psq_l az, 8(a), 1, 0
psq_l bz, 8(b), 1, 0
ps_add sumz, az, bz
psq_st sumz, 8(ab), 1, 0
}
#endif
}
inline void C_VECSubtract(__REGISTER const Vec* a, __REGISTER const Vec* b, __REGISTER Vec* ab) {
#ifdef __MWERKS__
__REGISTER f32 axy;
__REGISTER f32 bxy;
__REGISTER f32 az;
__REGISTER f32 subz;
__REGISTER f32 bz;
asm {
psq_l axy, 0(a), 0, 0
psq_l bxy, 0(b), 0, 0
ps_sub bxy, axy, bxy
psq_st bxy, 0(ab), 0, 0
psq_l az, 8(a), 1, 0
psq_l bz, 8(b), 1, 0
ps_sub subz, az, bz
psq_st subz, 8(ab), 1, 0
}
#endif
}
inline f32 C_VECSquareMag(__REGISTER const Vec* v) {
#ifdef __MWERKS__
__REGISTER f32 x_y;
__REGISTER f32 z;
__REGISTER f32 res;
asm {
psq_l x_y, 0(v), 0, 0
ps_mul x_y, x_y, x_y
lfs z, 8(v)
ps_madd res, z, z, x_y
ps_sum0 res, res, x_y, x_y
}
return res;
#endif
}
inline f32 C_VECDotProduct(__REGISTER const Vec *a, __REGISTER const Vec *b) {
#ifdef __MWERKS__
__REGISTER f32 res;
__REGISTER f32 thisyz;
__REGISTER f32 otheryz;
__REGISTER f32 otherxy;
__REGISTER f32 thisxy;
asm {
psq_l thisyz, 4(a), 0, 0
psq_l otheryz, 4(b), 0, 0
ps_mul thisyz, thisyz, otheryz
psq_l thisxy, 0(a), 0, 0
psq_l otherxy, 0(b), 0, 0
ps_madd otheryz, thisxy, otherxy, thisyz
ps_sum0 res, otheryz, thisyz, thisyz
};
return res;
#endif
}
};
template<typename T>
inline T JMAMax(T param_0, T param_1) {
T ret;
if (param_0 > param_1) {
ret = param_0;
} else {
ret = param_1;
}
return ret;
}
#endif /* JMATH_H */
@@ -0,0 +1,51 @@
#ifndef RANDOM_H
#define RANDOM_H
#include <types.h>
namespace JMath {
/**
* @ingroup jsystem-jmath
*
*/
struct TRandom_fast_ {
u32 value;
TRandom_fast_(u32 value);
u32 get(void) {
value = (value * 0x19660d) + 0x3c6ef35f;
return value;
}
u32 get_bit32(void) { return this->get(); }
// due to the float constant, having this function inlined adds that float to data,
// making it not match
float get_ufloat_1(void) {
// !@bug UB: in C++ it's not legal to read from an union member other
// than the last one that was written to.
union {
f32 f;
u32 s;
} out;
out.s = (this->get() >> 9) | 0x3f800000;
return out.f - 1;
}
void setSeed(u32 seed) { value = seed; }
};
template <class RandomT>
class TRandom_ : public RandomT {
public:
TRandom_(u32 value) : RandomT(value) {}
u8 get_uint8(u8 param_0) {
return this->get_ufloat_1() * param_0;
}
};
} // namespace JMath
#endif /* RANDOM_H */