From 15eb317faaddf1a81a924b5ac2128ac842a8c991 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 12 Nov 2020 13:26:03 -0500 Subject: organize headers --- include/GScamera.h | 62 ++++++++++++++++++++++ include/GSnull.h | 8 ++- include/SDK/mtx.h | 46 +++++----------- include/code_80223694.h | 18 +++++++ include/gUnkClass12.h | 24 +++++++++ include/gUnkClass13.h | 21 ++++++++ src/GScamera.cpp | 137 ++++++++---------------------------------------- 7 files changed, 164 insertions(+), 152 deletions(-) create mode 100644 include/GScamera.h create mode 100644 include/code_80223694.h create mode 100644 include/gUnkClass12.h create mode 100644 include/gUnkClass13.h diff --git a/include/GScamera.h b/include/GScamera.h new file mode 100644 index 0000000..2b73c27 --- /dev/null +++ b/include/GScamera.h @@ -0,0 +1,62 @@ +#ifndef POKEREVO_GSCAMERA_H +#define POKEREVO_GSCAMERA_H + +#include "GSnull.h" +#include "code_801DD5C8.h" + +class GScamera : public GSnull +{ + u32 unk104; // flags + gUnkClass10* unk108; + Mtx44 unk10C; // orthographic projection matrix. TODO: this could be a C++ wrapper for Mtx44 + + // TODO: Is unk14C~unk164 an array of floats initialized to 0s with an initializer list? + // NOTE: This hack is only needed because GScamera's constructors write 0 to unk14C~unk164 + // as if they were s32's, yet other functions treat them as floats + union s32float + { + s32 i; + float f; + }; + + s32float unk14C; + s32float unk150; + s32float unk154; + s32float unk158; + s32float unk15C; + s32float unk160; + s32float unk164; + + // view volume coordinates for the orthographic projection matrix + float unk168; // top + float unk16C; // bottom + float unk170; // left + float unk174; // right + + float unk178; + + Vec unk17C; + Vec unk188; + Vec unk194; + Vec unk1A0; + Point3d unk1AC; // camera position + Vec unk1B8; // camera up vector + Point3d unk1C4; // target posiiton + GScamera* unk1D0; + Mtx unk1D4; // viewing matrix + Mtx unk204; // inverse of the viewing matrix + Mtx unk234; // inverse-transpose of the viewing matrix +public: + GScamera(); // 801DDF78 + GScamera(void* p1, gUnkClass10* p2); // 801DE084 + void func_801DE1F8(); + void func_801DE524(); + friend void func_801DEA3C(Mtx p1, GScamera* p2, Mtx p3, BOOL p4); + void lbl_801DEEF8(gUnkClass12* p1, u32 p2, float p3); + virtual ~GScamera(); // 801DE19C + virtual void func1(float p1); // 801DECBC + virtual void func2(BOOL p1); // 801DED3C + virtual void func3(); // 801DE5F8 +}; + +#endif //POKEREVO_GSCAMERA_H diff --git a/include/GSnull.h b/include/GSnull.h index 21fc2b4..e152cd8 100644 --- a/include/GSnull.h +++ b/include/GSnull.h @@ -7,7 +7,6 @@ extern "C" { #include "GSblendObject.h" -// TODO: namespace? struct gUnkClass11 { Vec unk0; @@ -36,10 +35,9 @@ protected: u8 unk12[0xBE]; Mtx unkD0; public: - // 801F1AE8 - GSnull(u8 p1); - // 801F1BC8 - GSnull(void* p1, gUnkClass10* p2); // TODO: p1 type + + GSnull(u8 p1); // 801F1AE8 + GSnull(void* p1, gUnkClass10* p2); // 801F1BC8 // TODO: p1 type virtual ~GSnull(); // 801F1F24 virtual void func1(float p1); // 801F3960 virtual void func2(BOOL p1); // 801F39E8 diff --git a/include/SDK/mtx.h b/include/SDK/mtx.h index 9bff30f..2a0845e 100644 --- a/include/SDK/mtx.h +++ b/include/SDK/mtx.h @@ -24,60 +24,40 @@ typedef struct Quaternion } Quaternion; void PSMTXTranspose(const Mtx src, Mtx xPose); -#define MTXTranspose PSMTXTranspose - void PSMTXCopy(const Mtx src, Mtx dest); -#define MTXCopy PSMTXCopy - void C_MTXLookAt(Mtx m, const Point3d* camPos, const Vec* camUp, const Point3d* target); -#define MTXLookAt C_MTXLookAt - -void PSVECAdd(const Vec* a, const Vec* b, Vec* ab); -#define VECAdd PSVECAdd - void PSMTXMultVecSR(const Mtx m, const Vec* src, Vec* dest); -#define MTXMultVecSR PSMTXMultVecSR - void PSMTXMultVec(const Mtx m, const Vec* src, Vec* dest); -#define MTXMultVec PSMTXMultVec - u32 PSMTXInverse(const Mtx src, Mtx inv); -#define MTXInverse PSMTXInverse - +void PSMTXConcat(const Mtx a, const Mtx b, Mtx ab); +void PSMTXQuat(Mtx m, const Quaternion* q); +void C_QUATRotAxisRad(Quaternion* r, const Vec* axis, float rad); +void PSMTXScale(Mtx m, float xS, float yS, float zS); +void PSMTXIdentity(Mtx m); +void PSVECAdd(const Vec* a, const Vec* b, Vec* ab); void PSVECCrossProduct(const Vec* a, const Vec* b, Vec* axb); void PSVECNormalize(const Vec* src, Vec* unit); void PSVECSubtract(const Vec* a, const Vec* b, Vec* a_b); - - - +#define MTXTranspose PSMTXTranspose +#define MTXCopy PSMTXCopy +#define MTXLookAt C_MTXLookAt +#define VECAdd PSVECAdd +#define MTXMultVecSR PSMTXMultVecSR +#define MTXMultVec PSMTXMultVec +#define MTXInverse PSMTXInverse #define MTXConcat PSMTXConcat -void PSMTXConcat(const Mtx a, const Mtx b, Mtx ab); - #define MTXQuat PSMTXQuat -void PSMTXQuat(Mtx m, const Quaternion* q); - #define QUATRotAxisRad C_QUATRotAxisRad -void C_QUATRotAxisRad(Quaternion* r, const Vec* axis, float rad); - -void PSMTXScale(Mtx m, float xS, float yS, float zS); - - - #define VECSubtract PSVECSubtract #define VECCrossProduct PSVECCrossProduct #define VECNormalize PSVECNormalize - - #define MTXIdentity PSMTXIdentity #define MTXScale PSMTXScale #define MTXCopy PSMTXCopy -void PSMTXIdentity(Mtx m); - #ifdef __cplusplus } #endif - #endif //POKEREVO_MTX_H diff --git a/include/code_80223694.h b/include/code_80223694.h new file mode 100644 index 0000000..bc8cde1 --- /dev/null +++ b/include/code_80223694.h @@ -0,0 +1,18 @@ +#ifndef POKEREVO_CODE_80223694_H +#define POKEREVO_CODE_80223694_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void func_80223694(Mtx44 m, float t, float b, float l, float r, float n, float f); // C_MTXFrustum +void func_80223698(Mtx44 m, float t, float b, float l, float r, float n, float f); // C_MTXOrtho +void func_8022369C(Mtx44 m, float fovy, float aspect, float n, float f); // C_MTXPerspective + +#ifdef __cplusplus +} +#endif + +#endif //POKEREVO_CODE_80223694_H diff --git a/include/gUnkClass12.h b/include/gUnkClass12.h new file mode 100644 index 0000000..53b57db --- /dev/null +++ b/include/gUnkClass12.h @@ -0,0 +1,24 @@ +#ifndef POKEREVO_GUNKCLASS12_H +#define POKEREVO_GUNKCLASS12_H + +#ifdef __cplusplus +extern "C" { +#endif + +// TODO: same as gUnkClass9? +// NOTE: It may be possible to use RTTI data to determine the name of this class +struct gUnkClass12 +{ + u8 unk0; // pad + u8 unk1; +}; + +// TODO: convert to member functions +void func_801E1278(gUnkClass12*, Vec*, float); +void func_801E10C0(gUnkClass12*, float*, float); + +#ifdef __cplusplus +} +#endif + +#endif //POKEREVO_GUNKCLASS12_H diff --git a/include/gUnkClass13.h b/include/gUnkClass13.h new file mode 100644 index 0000000..bafb84c --- /dev/null +++ b/include/gUnkClass13.h @@ -0,0 +1,21 @@ +#ifndef POKEREVO_GUNKCLASS13_H +#define POKEREVO_GUNKCLASS13_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct gUnkClass13 +{ + u8 unk0[0x7A]; //pad + u8 unk7A; +}; + +// TODO: determine defining module for this global variable +extern gUnkClass13* lbl_8063F788; + +#ifdef __cplusplus +} +#endif + +#endif //POKEREVO_GUNKCLASS13_H diff --git a/src/GScamera.cpp b/src/GScamera.cpp index 269462f..afc1a5d 100644 --- a/src/GScamera.cpp +++ b/src/GScamera.cpp @@ -2,76 +2,18 @@ #include #include #include "GSnull.h" -//#include "GScamera.h" // TODO +#include "gUnkClass12.h" +#include "gUnkClass13.h" +#include "code_80223694.h" +#include "GScamera.h" static ctorStruct gUnk8063F358(1, 4, 0); -extern "C" { - -// TODO: same as gUnkClass9? -// TODO: use RTTI data to find actual class name -struct gUnkClass12 -{ - u8 unk0; // pad - u8 unk1; -}; - -class GScamera : public GSnull -{ - u32 unk104; // flags - gUnkClass10* unk108; - Mtx44 unk10C; // orthographic projection matrix. TODO: this could be a C++ wrapper for Mtx44 - - // TODO: Is unk14C an array of floats initialized to 0s with an initializer list? - // GScamera's constructors write 0 to unk14C as if it's an s32, yet other functions treat - // it as a float - typedef union hack - { - s32 i; - float f; - } Hack; - - Hack unk14C; - Hack unk150; - Hack unk154; - Hack unk158; - Hack unk15C; - Hack unk160; - Hack unk164; - - // view volume coordinates for the orthographic projection matrix - float unk168; // top - float unk16C; // bottom - float unk170; // left - float unk174; // right - - float unk178; - - Vec unk17C; - Vec unk188; - Vec unk194; - Vec unk1A0; - Point3d unk1AC; // camera position - Vec unk1B8; // camera up vector - Point3d unk1C4; // target posiiton - GScamera* unk1D0; - Mtx unk1D4; // viewing matrix - Mtx unk204; // inverse of the viewing matrix - Mtx unk234; // inverse-transpose of the viewing matrix -public: - GScamera(); - GScamera(void* p1, gUnkClass10* p2); - void func_801DE1F8(); - void func_801DE524(); - friend void func_801DEA3C(Mtx p1, GScamera* p2, Mtx p3, BOOL p4); - void lbl_801DEEF8(gUnkClass12* p1, u32 p2, float p3); - virtual ~GScamera(); // 801DE19C - virtual void func1(float p1); // 801DECBC - virtual void func2(BOOL p1); // 801DED3C - virtual void func3(); // 801DE5F8 -}; +// TODO: determine defining modules for these external references +extern Vec lbl_80493614; +extern Vec lbl_80493620; +extern Mtx lbl_804932E0; -// 801DDF78 GScamera::GScamera() : GSnull(4) { float f2; @@ -132,7 +74,6 @@ GScamera::GScamera() : GSnull(4) MTXIdentity(unk234); } -// 801DE084 GScamera::GScamera(void* p1, gUnkClass10* p2) : GSnull(p1, p2) { float f2; @@ -195,30 +136,7 @@ GScamera::GScamera(void* p1, gUnkClass10* p2) : GSnull(p1, p2) MTXIdentity(unk234); } -// 801DE19C -GScamera::~GScamera() -{ - -} - -// TODO: what is this? compare with gUnkClass 9, 10, 11, 12... -struct gUnkClass13 -{ - u8 unk0[0x7A]; //pad - u8 unk7A; -}; - - -extern Vec lbl_80493614; -extern Vec lbl_80493620; -extern gUnkClass13* lbl_8063F788; // TODO: pointer to some class - -// C_MTXFrustum -void func_80223694(Mtx44 m, float t, float b, float l, float r, float n, float f); -// C_MTXOrtho -void func_80223698(Mtx44 m, float t, float b, float l, float r, float n, float f); -// C_MTXPerspective -void func_8022369C(Mtx44 m, float fovy, float aspect, float n, float f); +GScamera::~GScamera() { } void GScamera::func_801DE1F8() { @@ -239,11 +157,11 @@ void GScamera::func_801DE1F8() f31 = unk178; switch (unk104 & 0x3) { case 2: - // TODO: inline function? + // inline function? f8 = 0.5f * ((1.0f - f30) * (unk174 - unk170)); if (f31 > 1.0f) { f31 = (1.0f / f31); - // func_80223698 is a thunk to C_MTXOrtho + // C_MTXOrtho func_80223698(unk10C, unk168*f31, unk16C*f31, f8 + unk170*f30, f8 + unk174*f30, unk17C.x, unk17C.y); } else { f31 *= f30; @@ -261,7 +179,7 @@ void GScamera::func_801DE1F8() f8 = 0.5f * ((1.0f - f30) * (unk174 - unk170)); if (f31 > 1.0f) { f31 = 1.0f / f31; - // func_80223694 is a thunk to C_MTXFrustum + // C_MTXFrustum func_80223694(unk10C, unk168*f31, unk16C*f31, f8 + unk170*f30, f8 + unk174*f30, unk17C.x, unk17C.y); } else { f31 *= f30; @@ -277,13 +195,13 @@ void GScamera::func_801DE1F8() break; case 0: case 1: default: if (unk104 & 0x80 && f31 > 1.0f) { - // TODO: degree->radian conversion? 0.017453292f is pi/180 + // degree->radian conversion? 0.017453292f is pi/180 float f0 = static_cast(tan(0.017453292f*(0.5f*unk168))); float f3 = static_cast(atan2(f0/f31, 1.0)); float f5 = f3*2.0f; f31 *= f30; - // TODO: radian->degree conversion? 57.29578f is 180/pi - // func_8022369C is a thunk to C_MTXPerspective + // radian->degree conversion? 57.29578f is 180/pi + // C_MTXPerspective float rad2deg = f5*57.29578f; func_8022369C(unk10C, rad2deg, unk16C*f31, unk17C.x, unk17C.y); } else { @@ -407,7 +325,6 @@ void GScamera::func3() unk1C4 = sp14; // if unk1B8 is a zero vector, assign lbl_80493614 to it - // TODO: inline this? BOOL flag; if (!(unk1B8.x < 0.00001f && unk1B8.x > -0.00001f && unk1B8.y < 0.00001f && unk1B8.y > -0.00001f && @@ -445,8 +362,6 @@ void GScamera::func3() } } -extern Mtx lbl_804932E0; - static inline float InlineFunc1(const Mtx m, u32 col) { float f1 = (m[0][col]*m[0][col] + m[1][col]*m[1][col] + m[2][col]*m[2][col]); @@ -456,8 +371,9 @@ static inline float InlineFunc1(const Mtx m, u32 col) return static_cast(sqrt(f1)); } -#define NONMATCHING #ifdef NONMATCHING +// There is an instruction ordering issue at the very beginning of the function. We need +// the compiler to interleave the function prologue with the function body. // NOTE: The inline asm for this function contains hard-coded offsets into .sdata2, preventing shiftability void func_801DEA3C(Mtx p1, GScamera* p2, Mtx p3, BOOL p4) { @@ -465,10 +381,10 @@ void func_801DEA3C(Mtx p1, GScamera* p2, Mtx p3, BOOL p4) Mtx sp40; Vec sp30; Vec sp24; - float sp18[3] = { InlineFunc1(p3, 0), InlineFunc1(p3, 1), InlineFunc1(p3, 2) }; + Vec sp18 = { InlineFunc1(p3, 0), InlineFunc1(p3, 1), InlineFunc1(p3, 2) }; Quaternion sp8; - MTXScale(sp70, sp18[0], sp18[1], sp18[2]); + MTXScale(sp70, sp18.x, sp18.y, sp18.z); float f0, f1, f2; f2 = p3[0][3]; @@ -480,7 +396,7 @@ void func_801DEA3C(Mtx p1, GScamera* p2, Mtx p3, BOOL p4) if (p4) { VECSubtract(&p2->unk1AC, &sp30, &sp24); sp24.y = 0.0f; - BOOL flag; // indicates sp24 is a zero vector? + BOOL flag; if (!(sp24.x < 0.00001f && sp24.x > -0.00001f && sp24.y < 0.00001f && sp24.y > -0.00001f && sp24.z < 0.00001f && sp24.z > -0.00001f)) @@ -713,7 +629,6 @@ void GScamera::func1(float p1) func_801F3904(this, f31); } -// 801DED3C void GScamera::func2(BOOL p1) { GSnull::func2(p1); @@ -727,8 +642,8 @@ void GScamera::func2(BOOL p1) case 2: unk168 = 0.0f; unk170 = 0.0f; - unk174 = unk108->unk34; // float - unk16C = unk108->unk34 / unk108->unk38; // float + unk174 = unk108->unk34; + unk16C = unk108->unk34 / unk108->unk38; break; case 3: float f1 = (0.5f * unk108->unk34); @@ -769,12 +684,8 @@ void GScamera::func2(BOOL p1) } } -// TODO: move to header -void func_801E1278(gUnkClass12*, Vec*, float); -void func_801E10C0(gUnkClass12*, float*, float); - // TODO: determine if there's any relationship between this -// function and the unkC callback in gUnkClass9, called in func_801DD7FC +// function and the unkC callback member of gUnkClass9, called in func_801DD7FC void GScamera::lbl_801DEEF8(gUnkClass12* p1, u32 p2, float p3) { if (!p2) { @@ -816,5 +727,3 @@ void GScamera::lbl_801DEEF8(gUnkClass12* p1, u32 p2, float p3) } } } - -} // extern "C" -- cgit v1.2.3