diff --git a/extern/aurora b/extern/aurora index 95803b7e7d..156f9a65e3 160000 --- a/extern/aurora +++ b/extern/aurora @@ -1 +1 @@ -Subproject commit 95803b7e7d6f1580de8a637c0e2ce3d5973f6bcb +Subproject commit 156f9a65e38db18a8fc93b30271703e58fa339f5 diff --git a/files.cmake b/files.cmake index 9a8de3244d..cae7f66aed 100644 --- a/files.cmake +++ b/files.cmake @@ -117,6 +117,7 @@ set(DOLZEL_FILES src/d/d_bg_plc.cpp src/d/d_bg_s.cpp src/d/d_bg_s_acch.cpp + src/d/d_bg_s_capt_poly.cpp src/d/d_bg_s_chk.cpp src/d/d_bg_s_gnd_chk.cpp src/d/d_bg_s_grp_pass_chk.cpp diff --git a/include/SSystem/SComponent/c_angle.h b/include/SSystem/SComponent/c_angle.h index d3a81eefd1..f851033eab 100644 --- a/include/SSystem/SComponent/c_angle.h +++ b/include/SSystem/SComponent/c_angle.h @@ -10,7 +10,11 @@ #define S2RAD_CONSTANT (M_PI / 0x8000) #define RAD2S_CONSTANT (0x8000 / M_PI) +#if TARGET_PC +#define DEG2S(x) cAngle_degreeToS16((x)) +#else #define DEG2S(x) ((s16)((x) * DEG2S_CONSTANT)) +#endif #define S2DEG(x) ((x) * S2DEG_CONSTANT) #define S2RAD(x) ((x) * S2RAD_CONSTANT) #define RAD2S(x) ((x) * RAD2S_CONSTANT) diff --git a/include/SSystem/SComponent/c_bg_s_lin_chk.h b/include/SSystem/SComponent/c_bg_s_lin_chk.h index 1c0b26c4a5..bf71667131 100644 --- a/include/SSystem/SComponent/c_bg_s_lin_chk.h +++ b/include/SSystem/SComponent/c_bg_s_lin_chk.h @@ -36,7 +36,7 @@ public: void SetHit() { mStts |= STTS_HIT; } u32 ChkHit() const { return mStts & STTS_HIT; } void SetCross(const cXyz& pos) { mLin.SetEnd(pos); } - cXyz* GetCrossP() { return &mLin.GetEndP(); } + cXyz* GetCrossP() { return mLin.GetEndP(); } cM3dGLin* GetLinP() { return &mLin; } bool ChkBackFlag() const { return mBackFlag; } void OnBackFlag() { mBackFlag = true; } @@ -45,13 +45,17 @@ public: bool GetPreWallChk() const { return mPreWallChk; } bool GetPreGroundChk() const { return mPreGroundChk; } bool GetPreRoofChk() const { return mPreRoofChk; } - cXyz* GetStartP() { return &mLin.GetStartP(); } + cXyz* GetStartP() { return mLin.GetStartP(); } void ClrSttsRoofOff() { mStts &= ~STTS_ROOF_OFF; } void SetSttsRoofOff() { mStts |= STTS_ROOF_OFF; } void ClrSttsWallOff() { mStts &= ~STTS_WALL_OFF; } void SetSttsWallOff() { mStts |= STTS_WALL_OFF; } void ClrSttsGroundOff() { mStts &= ~STTS_GROUND_OFF; } void SetSttsGroundOff() { mStts |= STTS_GROUND_OFF; } + void ClearCheckIndex() { ClearPi(); } + bool ChkSttsWallOff() const { return (mStts & STTS_WALL_OFF); } + bool ChkSttsGroundOff() const { return (mStts & STTS_GROUND_OFF); } + bool ChkSttsRoofOff() const { return (mStts & STTS_ROOF_OFF); } }; #endif /* C_BG_S_LIN_CHK_H */ diff --git a/include/SSystem/SComponent/c_bg_s_shdw_draw.h b/include/SSystem/SComponent/c_bg_s_shdw_draw.h index e99a933b70..9ec3023306 100644 --- a/include/SSystem/SComponent/c_bg_s_shdw_draw.h +++ b/include/SSystem/SComponent/c_bg_s_shdw_draw.h @@ -20,6 +20,9 @@ public: /* 0x14 */ cM3dGAab mM3dGAab; /* 0x30 */ cBgS_ShdwDraw_Callback mCallbackFun; + #if DEBUG + /* 0x34 */ int field_0x34; + #endif }; #endif /* C_BG_S_SHDW_DRAW_H */ diff --git a/include/SSystem/SComponent/c_bg_w.h b/include/SSystem/SComponent/c_bg_w.h index f1d5e291b4..23c6747d15 100644 --- a/include/SSystem/SComponent/c_bg_w.h +++ b/include/SSystem/SComponent/c_bg_w.h @@ -18,7 +18,7 @@ public: cBgW_BgId() { Ct(); } void Ct() { m_id = 0x100; } - u16 GetId() const { return m_id; } + int GetId() const { return m_id; } }; bool cBgW_CheckBGround(float a1); diff --git a/include/SSystem/SComponent/c_cc_d.h b/include/SSystem/SComponent/c_cc_d.h index 141dd33bad..66c71a4ead 100644 --- a/include/SSystem/SComponent/c_cc_d.h +++ b/include/SSystem/SComponent/c_cc_d.h @@ -188,6 +188,7 @@ public: cXyz* GetCCMoveP() { return &m_cc_move; } fpc_ProcID GetApid() const { return m_apid; } u8 GetDmg() const { return m_dmg; } + void ClrCo() { ClrCcMove(); } }; // Size = 0x1C STATIC_ASSERT(0x1C == sizeof(cCcD_Stts)); @@ -213,7 +214,7 @@ public: void ct(); void SetSPrm(u32 sprm) { mSPrm = sprm; } s32 getSPrm() const { return mSPrm; } - void setRPrm(s32 rprm) { mRPrm = rprm; } + void SetRPrm(u32 rprm) { mRPrm = rprm; } s32 getRPrm() const { return mRPrm; } cCcD_Obj* GetHitObj() { return mHitObj; } const cCcD_Obj* GetHitObj() const { return mHitObj; } @@ -222,6 +223,9 @@ public: void OnSPrmBit(u32 flag) { mSPrm |= flag; } void OffSPrmBit(u32 flag) { mSPrm &= ~flag; } u32 ChkSPrm(u32 prm) const { return MskSPrm(prm) != 0; } + void SetHitObj(cCcD_Obj* pobj) { mHitObj = pobj; } + void ClrRPrm(u32 prm) { mRPrm &= ~prm; } + void ClrObj() { mHitObj = NULL; } void Set(cCcD_SrcObjCommonBase const& src) { mSPrm = src.mSPrm; } }; @@ -240,7 +244,7 @@ public: void ClrHit(); int GetType() const { return mType; } u32 GetGrp() const { return MskSPrm(0x1E); } - bool ChkSet() const { return MskSPrm(1); } + BOOL ChkSet() const { return MskSPrm(1); } u8 GetAtp() const { return mAtp; } u32 MskType(u32 msk) const { return mType & msk; } void SetType(u32 type) { mType = type; } @@ -269,7 +273,7 @@ public: int GetType() const { return mType; } void SetType(u32 type) { mType = type; } u32 GetGrp() const { return MskSPrm(0x1E); } - bool ChkSet() const { return MskSPrm(1); } + BOOL ChkSet() const { return MskSPrm(1); } void ClrSet() { OffSPrmBit(1); } u32 ChkHit() const { return MskRPrm(1); } @@ -289,7 +293,7 @@ public: void SetIGrp(u32); void SetVsGrp(u32); u32 GetGrp() const { return MskSPrm(0x1E); } - bool ChkSet() const { return MskSPrm(1); } + BOOL ChkSet() const { return MskSPrm(1); } u32 GetVsGrp() const { return MskSPrm(0x70); } u32 GetIGrp() const { return MskSPrm(0xE); } u32 ChkNoCrr() const { return MskSPrm(0x100); } @@ -323,10 +327,10 @@ public: u32 GetCoGrp() const { return mObjCo.GetGrp(); } int GetTgType() const { return mObjTg.GetType(); } u32 GetAtType() const { return mObjAt.GetType(); } - bool ChkTgSet() const { return mObjTg.ChkSet(); } - bool ChkAtSet() const { return mObjAt.ChkSet(); } - bool ChkCoSet() const { return mObjCo.ChkSet(); } - u32 ChkCoSameActorHit() const { return mObjCo.ChkCoSameActorHit(); } + BOOL ChkTgSet() const { return mObjTg.ChkSet(); } + BOOL ChkAtSet() const { return mObjAt.ChkSet(); } + BOOL ChkCoSet() const { return mObjCo.ChkSet(); } + u32 ChkCoSameActorHit() { return mObjCo.MskSPrm(0x400); } void OnCoSameActorHit() { mObjCo.OnCoSameActorHit(); } void OffCoSameActorHit() { mObjCo.OffCoSameActorHit(); } u32 GetCoVsGrp() const { return mObjCo.GetVsGrp(); } @@ -334,8 +338,8 @@ public: u8 GetAtAtp() const { return mObjAt.GetAtp(); } u32 ChkAtNoTgHitInfSet() const { return mObjAt.MskSPrm(0x20); } u32 ChkTgNoAtHitInfSet() const { return mObjTg.MskSPrm(0x20); } - u32 ChkCoNoCoHitInfSet() const { return mObjCo.MskSPrm(0x200); } - bool ChkTgNoSlingHitInfSet() const { return mObjTg.MskSPrm(0x40); } + u32 ChkCoNoCoHitInfSet() { return mObjCo.MskSPrm(0x200); } + BOOL ChkTgNoSlingHitInfSet() { return mObjTg.MskSPrm(0x40); } void SetAtHit(cCcD_Obj* obj) { mObjAt.SetHit(obj); } void SetTgHit(cCcD_Obj* obj) { mObjTg.SetHit(obj); } void SetCoHit(cCcD_Obj* obj) { mObjCo.SetHit(obj); } @@ -430,7 +434,6 @@ public: /* vt[21]*/ virtual void getShapeAccess(cCcD_ShapeAttr::Shape*) const; cM3dGAab& GetWorkAab() { return mAab; } - cM3dGAab const& GetWorkAab() const { return mAab; } static cXyz m_virtual_center; }; @@ -456,7 +459,7 @@ public: void SetStts(cCcD_Stts* stts) { mStts = stts; } cCcD_DivideInfo& GetDivideInfo() { return mDivideInfo; } cCcD_DivideInfo* GetPDivideInfo() { return &mDivideInfo; } - int ChkBsRevHit() const { return mFlags & 2; } + int ChkBsRevHit() { return mFlags & 2; } private: /* 0x040 */ int mFlags; diff --git a/include/SSystem/SComponent/c_cc_s.h b/include/SSystem/SComponent/c_cc_s.h index 334f7351d8..62815fb3b6 100644 --- a/include/SSystem/SComponent/c_cc_s.h +++ b/include/SSystem/SComponent/c_cc_s.h @@ -16,18 +16,16 @@ public: /* 0x1000 */ cCcD_Obj* mpObjCo[0x100]; /* 0x1400 */ cCcD_Obj* mpObj[0x500]; #if DEBUG - /* 0x2800 */ int m_debug_code; + /* 0x2800 */ u32 m_debug_code; #endif /* 0x2800 */ u16 mObjAtCount; /* 0x2802 */ u16 mObjTgCount; /* 0x2804 */ u16 mObjCoCount; /* 0x2806 */ u16 mObjCount; -#if DEBUG /* 0x280C */ u16 field_0x280c; /* 0x280E */ u16 field_0x280e; /* 0x2810 */ u16 field_0x2810; /* 0x2812 */ u16 field_0x2812; -#endif /* 0x2808 */ cCcD_DivideArea mDivideArea; /* 0x2848 vtable */ diff --git a/include/SSystem/SComponent/c_m3d_g_aab.h b/include/SSystem/SComponent/c_m3d_g_aab.h index 6317065a31..a685efb007 100644 --- a/include/SSystem/SComponent/c_m3d_g_aab.h +++ b/include/SSystem/SComponent/c_m3d_g_aab.h @@ -18,33 +18,33 @@ public: bool CrossY(const cXyz*) const; bool UnderPlaneYUnder(f32) const; bool TopPlaneYUnder(f32) const; - void ClearForMinMax(void); + void ClearForMinMax(); void SetMinMax(const cXyz&); void SetMinMax(const cM3dGAab&); void SetMin(const cXyz&); void SetMax(const cXyz&); void CalcCenter(cXyz*) const; void PlusR(f32); - const cXyz* GetMaxP(void) const { return &mMax; } - cXyz* GetMaxP(void) { return &mMax; } - const cXyz* GetMinP(void) const { return &mMin; } - cXyz* GetMinP(void) { return &mMin; } - const f32 GetMaxX(void) const { return mMax.x; } - const f32 GetMaxY(void) const { return mMax.y; } - const f32 GetMaxZ(void) const { return mMax.z; } - const f32 GetMinX(void) const { return mMin.x; } - const f32 GetMinY(void) const { return mMin.y; } - const f32 GetMinZ(void) const { return mMin.z; } - bool Cross(const cM3dGLin *param_1) { - return cM3d_Cross_MinMaxBoxLine(GetMinP(), GetMaxP(), (Vec*)¶m_1->GetStartP(), (Vec*)¶m_1->GetEndP()); + const cXyz* GetMaxP() const { return &mMax; } + cXyz* GetMaxP() { return &mMax; } + const cXyz* GetMinP() const { return &mMin; } + cXyz* GetMinP() { return &mMin; } + const f32 GetMaxX() const { return mMax.x; } + const f32 GetMaxY() const { return mMax.y; } + const f32 GetMaxZ() const { return mMax.z; } + const f32 GetMinX() const { return mMin.x; } + const f32 GetMinY() const { return mMin.y; } + const f32 GetMinZ() const { return mMin.z; } + bool Cross(const cM3dGLin *param_1) const { + return cM3d_Cross_MinMaxBoxLine(GetMinP(), GetMaxP(), param_1->GetStartP(), param_1->GetEndP()); } - bool Cross(const cM3dGAab *param_1) { + bool Cross(const cM3dGAab *param_1) const { return cM3d_Cross_AabAab(this, param_1); } - bool Cross(const cM3dGCyl *param_1) { + bool Cross(const cM3dGCyl *param_1) const { return cM3d_Cross_AabCyl(this, param_1); } - bool Cross(const cM3dGSph *param_1) { + bool Cross(const cM3dGSph *param_1) const { return cM3d_Cross_AabSph(this, param_1); } }; // Size = 0x1C diff --git a/include/SSystem/SComponent/c_m3d_g_cir.h b/include/SSystem/SComponent/c_m3d_g_cir.h index eccd553c86..af837d47d6 100644 --- a/include/SSystem/SComponent/c_m3d_g_cir.h +++ b/include/SSystem/SComponent/c_m3d_g_cir.h @@ -30,6 +30,8 @@ public: cM3dGCir(void); virtual ~cM3dGCir(void); void Set(f32, f32, f32, f32); + + f32 GetHeight() const { return mPosZ; } }; #endif /* C_M3D_G_CIR_H */ diff --git a/include/SSystem/SComponent/c_m3d_g_cps.h b/include/SSystem/SComponent/c_m3d_g_cps.h index 5147e02114..f24b352dae 100644 --- a/include/SSystem/SComponent/c_m3d_g_cps.h +++ b/include/SSystem/SComponent/c_m3d_g_cps.h @@ -3,6 +3,7 @@ #include "SSystem/SComponent/c_m3d.h" #include "SSystem/SComponent/c_m3d_g_lin.h" +#include "SSystem/SComponent/c_m3d_g_tri.h" struct cM3dGCpsS { /* 0x00 */ Vec mStart; @@ -14,8 +15,8 @@ class cM3dGCps : public cM3dGLin { public: /* 0x1C */ f32 mRadius; - cM3dGCps(void); - virtual ~cM3dGCps(void); + cM3dGCps(); + virtual ~cM3dGCps(); void Set(const cXyz&, const cXyz&, f32); void Set(const cM3dGCpsS&); void SetCps(const cM3dGCps&); @@ -24,6 +25,7 @@ public: } bool Cross(cM3dGCyl const* cyl, cXyz* xyz) const { return cM3d_Cross_CpsCyl(*this, *cyl, xyz); } bool Cross(cM3dGSph const* sph, cXyz* xyz) const { return cM3d_Cross_CpsSph(*this, *sph, xyz); } + bool Cross(cM3dGTri const& tri, cXyz* xyz) const { return cM3d_Cross_CpsTri(*this, tri, xyz); } void SetR(f32 r) { mRadius = r; } f32 GetR() const { return mRadius; } diff --git a/include/SSystem/SComponent/c_m3d_g_cyl.h b/include/SSystem/SComponent/c_m3d_g_cyl.h index 5d5f3a395b..4983084d83 100644 --- a/include/SSystem/SComponent/c_m3d_g_cyl.h +++ b/include/SSystem/SComponent/c_m3d_g_cyl.h @@ -40,8 +40,8 @@ public: bool Cross(const cM3dGCps* cps, cXyz* xyz) const { return cM3d_Cross_CpsCyl(*cps, *this, xyz); } bool Cross(const cM3dGTri& tri, cXyz* xyz) const { return cM3d_Cross_CylTri(this, &tri, xyz); } - bool Cross(const cM3dGCyl* other, f32* f) const { return cM3d_Cross_CylCyl(this, other, f); } - bool Cross(const cM3dGSph* sph, f32* f) const { return cM3d_Cross_CylSph(this, sph, f); } + bool cross(const cM3dGCyl* other, f32* f) const { return cM3d_Cross_CylCyl(this, other, f); } + bool cross(const cM3dGSph* sph, f32* f) const { return cM3d_Cross_CylSph(this, sph, f); } }; // Size = 0x18 STATIC_ASSERT(0x18 == sizeof(cM3dGCyl)); diff --git a/include/SSystem/SComponent/c_m3d_g_lin.h b/include/SSystem/SComponent/c_m3d_g_lin.h index d6b86ebcf0..fbe65d9b33 100644 --- a/include/SSystem/SComponent/c_m3d_g_lin.h +++ b/include/SSystem/SComponent/c_m3d_g_lin.h @@ -22,13 +22,13 @@ public: void SetEnd(const cXyz&); void set(const Vec& i_start, const Vec& i_end) { SetStartEnd(i_start, i_end); } - const cXyz& GetStartP(void) const { return mStart; } - cXyz& GetStartP(void) { return mStart; } + const cXyz* GetStartP() const { return &mStart; } + cXyz* GetStartP() { return &mStart; } cXyz& GetStart() { return mStart; } const cXyz& GetStart() const { return mStart; } - const cXyz& GetEndP(void) const { return mEnd; } - cXyz& GetEndP(void) { return mEnd; } + const cXyz* GetEndP() const { return &mEnd; } + cXyz* GetEndP() { return &mEnd; } cXyz& GetEnd() { return mEnd; } const cXyz& GetEnd() const { return mEnd; } f32 GetLen() const { return PSVECDistance(&mStart, &mEnd); } diff --git a/include/SSystem/SComponent/c_m3d_g_pla.h b/include/SSystem/SComponent/c_m3d_g_pla.h index 7f25724b55..e2b0eefb55 100644 --- a/include/SSystem/SComponent/c_m3d_g_pla.h +++ b/include/SSystem/SComponent/c_m3d_g_pla.h @@ -31,8 +31,8 @@ public: cM3d_CalcPla(v1, v2, v3, &mNormal, &mD); } - f32 getCrossY_NonIsZero(const cXyz *param_1) { - return ((-mNormal.x * param_1->x - mNormal.z * param_1->z) - mD) / mNormal.y; + f32 getCrossY_NonIsZero(const cXyz& param_1) const { + return ((-mNormal.x * param_1.x - mNormal.z * param_1.z) - mD) / mNormal.y; } bool cross(cM3dGLin const& line, Vec& point) { diff --git a/include/SSystem/SComponent/c_m3d_g_sph.h b/include/SSystem/SComponent/c_m3d_g_sph.h index b8f868b8a5..9a9248d0a4 100644 --- a/include/SSystem/SComponent/c_m3d_g_sph.h +++ b/include/SSystem/SComponent/c_m3d_g_sph.h @@ -39,9 +39,10 @@ public: f32 GetCY(void) const { return mCenter.y; } f32 GetCZ(void) const { return mCenter.z; } - bool Cross(const cM3dGSph* other, f32* f) const { return cM3d_Cross_SphSph(this, other, f); } + bool cross(const cM3dGSph* other, f32* f) const { return cM3d_Cross_SphSph(this, other, f); } bool Cross(const cM3dGCps* cps, cXyz* xyz) const { return cM3d_Cross_CpsSph(*cps, *this, xyz); } - bool Cross(const cM3dGCyl* cyl, f32* f) const { return cM3d_Cross_CylSph(cyl, this, f); } + bool cross(const cM3dGCyl* cyl, f32* f) const { return cM3d_Cross_CylSph(cyl, this, f); } + bool Cross(const cM3dGTri& tri, cXyz* xyz) const { return cM3d_Cross_SphTri(this, &tri, xyz); } }; // Size = 0x14 STATIC_ASSERT(0x14 == sizeof(cM3dGSph)); diff --git a/include/SSystem/SComponent/c_m3d_g_tri.h b/include/SSystem/SComponent/c_m3d_g_tri.h index ff780046b8..cac178e064 100644 --- a/include/SSystem/SComponent/c_m3d_g_tri.h +++ b/include/SSystem/SComponent/c_m3d_g_tri.h @@ -26,10 +26,10 @@ public: void setPos(const Vec*, const Vec*, const Vec*); void setBg(const Vec*, const Vec*, const Vec*, const cM3dGPla*); void set(const Vec*, const Vec*, const Vec*, const Vec*); - bool Cross(cM3dGCps const& cps, cXyz* xyz) const { return cM3d_Cross_CpsTri(cps, *this, xyz); } - bool Cross(cM3dGCyl const& cyl, cXyz* xyz) const { return this->cross(&cyl, xyz); } - bool Cross(cM3dGSph const& sph, cXyz* xyz) const { return cM3d_Cross_SphTri(&sph, this, xyz); } - bool Cross(cM3dGTri const& other, cXyz* xyz) const { + bool Cross(cM3dGCps const& cps, Vec* xyz) const { return cM3d_Cross_CpsTri(cps, *this, xyz); } + bool Cross(cM3dGCyl const& cyl, Vec* xyz) const { return this->cross(&cyl, xyz); } + bool Cross(cM3dGSph const& sph, Vec* xyz) const { return cM3d_Cross_SphTri(&sph, this, xyz); } + bool Cross(cM3dGTri const& other, Vec* xyz) const { return cM3d_Cross_TriTri(*this, other, xyz); } bool cross(const cM3dGLin* lin, Vec* xyz, bool param_2, bool param_3) const { diff --git a/include/SSystem/SComponent/c_math.h b/include/SSystem/SComponent/c_math.h index 0203b4e2f1..e65daa81e1 100644 --- a/include/SSystem/SComponent/c_math.h +++ b/include/SSystem/SComponent/c_math.h @@ -2,6 +2,9 @@ #define C_MATH_H #include "JSystem/JMath/JMATrigonometric.h" +#if TARGET_PC +#include "angle_utils.h" +#endif #ifndef __MWERKS__ #include @@ -32,7 +35,11 @@ inline f32 cM_ssin(s16 x) { } inline s16 cM_deg2s(f32 deg) { +#if TARGET_PC + return cAngle_degreeToS16(deg); +#else return deg * 182.04445f; +#endif } inline s16 i_cM_deg2s(f32 deg) { diff --git a/include/angle_utils.h b/include/angle_utils.h index b2406c45a7..043d0c565a 100644 --- a/include/angle_utils.h +++ b/include/angle_utils.h @@ -85,4 +85,15 @@ #define ANGLE_SUB_2 S16_SUB_2 #define ANGLE_MULT_2 S16_MULT_2 +#if TARGET_PC +static inline s16 cAngle_degreeToS16(f32 deg) { + s32 angle = (s32)(deg * (0x8000 / 180.0f)); + angle &= 0xFFFF; + if (angle >= 0x8000) { + angle -= 0x10000; + } + return (s16)angle; +} +#endif + #endif // !_ANGLE_UTILS_H_ diff --git a/include/d/actor/d_a_e_hz.h b/include/d/actor/d_a_e_hz.h index 7e5902e016..539d808cf5 100644 --- a/include/d/actor/d_a_e_hz.h +++ b/include/d/actor/d_a_e_hz.h @@ -87,7 +87,7 @@ private: /* 0x6B4 */ s16 field_0x6b4; /* 0x6B6 */ s16 field_0x6b6; /* 0x6B8 */ u8 field_0x6B8[0x6BC - 0x6B8]; - /* 0x6BC */ char* mpName; + /* 0x6BC */ const char* mpName; /* 0x6C0 */ s32 mAction; /* 0x6C4 */ s32 mPrevAction; /* 0x6C8 */ s32 mMode; // That's just a guess. Might need a better name for it's usage diff --git a/include/d/actor/d_a_npc2.h b/include/d/actor/d_a_npc2.h index ea5548696a..d1d06d7764 100644 --- a/include/d/actor/d_a_npc2.h +++ b/include/d/actor/d_a_npc2.h @@ -134,7 +134,7 @@ public: /* 0x842 */ u16 field_0x842; /* 0x844 */ u8 field_0x844; /* 0x845 */ u8 field_0x845[0x848 - 0x845]; - /* 0x848 */ s32 field_0x848; + /* 0x848 */ s32 mFlowID; /* 0x84C */ dMsgFlow_c mMsgFlow; /* 0x898 */ u8 field_0x898[0x89A - 0x898]; /* 0x89A */ s16 mEvtIdx; diff --git a/include/d/actor/d_a_npc_bouS.h b/include/d/actor/d_a_npc_bouS.h index bd3b1ff0b6..27eafb48fd 100644 --- a/include/d/actor/d_a_npc_bouS.h +++ b/include/d/actor/d_a_npc_bouS.h @@ -72,7 +72,7 @@ public: void setExpression(int, f32); bool talk(void*); bool demo(void*); - inline fopAc_ac_c* searchInstructionTag(); + inline fopAc_ac_c* searchInstructionTag(); bool instruction(void*); bool checkIntroDemoStart(); int EvCut_BousIntroSumo1(int); diff --git a/include/d/actor/d_a_npc_cd.h b/include/d/actor/d_a_npc_cd.h index 2e86c867c6..3f942a5988 100644 --- a/include/d/actor/d_a_npc_cd.h +++ b/include/d/actor/d_a_npc_cd.h @@ -58,8 +58,8 @@ struct daNpcCd_HIO_Jnt_c : public JORReflexible { void genMessage(JORMContext*); #endif - /* 0x04 */ Vec jntT; - /* 0x10 */ SVec jntR; + /* 0x04 */ BE(Vec) jntT; + /* 0x10 */ struct { BE(s16) x, y, z; } jntR; }; struct daNpcCd_HIO_Child_c : public JORReflexible { @@ -71,17 +71,17 @@ struct daNpcCd_HIO_Child_c : public JORReflexible { #endif /* 0x004 */ daNpcCd_HIO_Jnt_c field_0x4[12]; - /* 0x124 */ s16 field_0x124[0x0C]; - /* 0x13C */ f32 mObjScale; - /* 0x140 */ s16 mAtn; - /* 0x144 */ f32 mAnmPlaySpeed; - /* 0x148 */ f32 mWalkAnmPlaySpeed; - /* 0x14C */ f32 mMaxSpeed; - /* 0x150 */ f32 mWalkMaxSpeed; - /* 0x154 */ f32 mCylH; - /* 0x158 */ f32 mCylR; - /* 0x15C */ f32 mChkWallH; - /* 0x160 */ f32 mChkWallR; + /* 0x124 */ BE(s16) field_0x124[0x0C]; + /* 0x13C */ BE(f32) mObjScale; + /* 0x140 */ BE(s16) mAtn; + /* 0x144 */ BE(f32) mAnmPlaySpeed; + /* 0x148 */ BE(f32) mWalkAnmPlaySpeed; + /* 0x14C */ BE(f32) mMaxSpeed; + /* 0x150 */ BE(f32) mWalkMaxSpeed; + /* 0x154 */ BE(f32) mCylH; + /* 0x158 */ BE(f32) mCylR; + /* 0x15C */ BE(f32) mChkWallH; + /* 0x160 */ BE(f32) mChkWallR; }; STATIC_ASSERT(sizeof(daNpcCd_HIO_Child_c) == 0x164); diff --git a/include/d/actor/d_a_npc_gra.h b/include/d/actor/d_a_npc_gra.h index 3209329a76..236755aba7 100644 --- a/include/d/actor/d_a_npc_gra.h +++ b/include/d/actor/d_a_npc_gra.h @@ -160,7 +160,7 @@ private: /* 0x14B0 */ int field_0x1460; /* 0x1464 */ int field_0x1464; /* 0x1468 */ int field_0x1468; - /* 0x146C */ int field_0x146C; + /* 0x146C */ int mFlowID; /* 0x1470 */ s16 mLookMode; /* 0x1472 */ u16 field_0x1472; /* 0x1474 */ u8 mType; diff --git a/include/d/actor/d_a_npc_grs.h b/include/d/actor/d_a_npc_grs.h index 202dd25267..d2a0c5359d 100644 --- a/include/d/actor/d_a_npc_grs.h +++ b/include/d/actor/d_a_npc_grs.h @@ -103,7 +103,7 @@ private: /* 0xE00 */ int field_0xe00; /* 0xE04 */ int field_0xe04; /* 0xE08 */ int field_0xe08; - /* 0xE0C */ int field_0xe0c; + /* 0xE0C */ int mFlowID; /* 0xE10 */ s16 mLookMode; /* 0xE12 */ u16 mActionState; /* 0xE14 */ u8 mType; diff --git a/include/d/actor/d_a_npc_gwolf.h b/include/d/actor/d_a_npc_gwolf.h index adcdb75adb..fcf5d804d0 100644 --- a/include/d/actor/d_a_npc_gwolf.h +++ b/include/d/actor/d_a_npc_gwolf.h @@ -121,7 +121,7 @@ private: /* 0xDFC */ int field_0xdfc; /* 0xE00 */ int field_0xe00; /* 0xE04 */ int field_0xe04; - /* 0xE08 */ int field_0xe08; + /* 0xE08 */ int mFlowID; /* 0xE0C */ s16 mLookMode; /* 0xE0E */ u16 mMode; /* 0xE10 */ u8 mType; diff --git a/include/d/actor/d_a_npc_kasi_hana.h b/include/d/actor/d_a_npc_kasi_hana.h index 54b0cf914b..e355ed8c55 100644 --- a/include/d/actor/d_a_npc_kasi_hana.h +++ b/include/d/actor/d_a_npc_kasi_hana.h @@ -182,7 +182,8 @@ public: s16 getMessageNo() { return s16(home.angle.x); } s8 getType() { s8 rv = fopAcM_GetParam(this) & 0xFF; - + + // !@bug Comparison of s8 with 0xFF will always evaluate to false if (rv == 0xFF) { rv = 0; } diff --git a/include/d/actor/d_a_npc_kasi_kyu.h b/include/d/actor/d_a_npc_kasi_kyu.h index 9ca549e46c..0387c563b7 100644 --- a/include/d/actor/d_a_npc_kasi_kyu.h +++ b/include/d/actor/d_a_npc_kasi_kyu.h @@ -98,7 +98,8 @@ public: s8 getType() { s8 rv = fopAcM_GetParam(this) & 0xFF; - + + // !@bug Comparison of s8 with 0xFF will always evaluate to false if (rv == 0xFF) { rv = 0; } diff --git a/include/d/actor/d_a_npc_kasi_mich.h b/include/d/actor/d_a_npc_kasi_mich.h index 9f38d3dd1c..e3782f1b27 100644 --- a/include/d/actor/d_a_npc_kasi_mich.h +++ b/include/d/actor/d_a_npc_kasi_mich.h @@ -99,7 +99,8 @@ public: s8 getType() { s8 rv = fopAcM_GetParam(this) & 0xFF; - + + // !@bug Comparison of s8 with 0xFF will always evaluate to false if (rv == 0xFF) { rv = 0; } diff --git a/include/d/actor/d_a_npc_kn.h b/include/d/actor/d_a_npc_kn.h index a14a89aefe..e97431baef 100644 --- a/include/d/actor/d_a_npc_kn.h +++ b/include/d/actor/d_a_npc_kn.h @@ -77,7 +77,7 @@ public: class daNpc_Kn_prtclMngr_c { public: - /* 0x00 */ bool mpModel; + /* 0x00 */ bool field_0x00; /* 0x04 */ cXyz mPos; /* 0x10 */ csXyz mAngle; /* 0x18 */ cXyz mScale; diff --git a/include/d/actor/d_a_npc_ks.h b/include/d/actor/d_a_npc_ks.h index ba14540735..7ec5fd129d 100644 --- a/include/d/actor/d_a_npc_ks.h +++ b/include/d/actor/d_a_npc_ks.h @@ -89,7 +89,7 @@ public: /* 0x5B7 */ u8 field_0x5b7; /* 0x5B8 */ int order; /* 0x5BC */ int bitTRB; - /* 0x5C0 */ char* res_name; + /* 0x5C0 */ const char* res_name; /* 0x5C4 */ f32 dis; /* 0x5C8 */ s16 target_angle; /* 0x5CC */ mDoExt_McaMorfSO* model; diff --git a/include/d/actor/d_a_npc_myna2.h b/include/d/actor/d_a_npc_myna2.h index bf97f43124..ac6af4d8f7 100644 --- a/include/d/actor/d_a_npc_myna2.h +++ b/include/d/actor/d_a_npc_myna2.h @@ -104,7 +104,7 @@ public: /* 0xDF8 */ int field_0xdf8; /* 0xDFC */ int field_0xdfc; /* 0xE00 */ int field_0xe00; - /* 0xE04 */ int field_0xe04; + /* 0xE04 */ int mFlowID; /* 0xE08 */ s16 mLookMode; /* 0xE0A */ u16 mMode; /* 0xE0C */ u8 mType; diff --git a/include/d/actor/d_a_npc_ne.h b/include/d/actor/d_a_npc_ne.h index 10474cc828..51f9f06e81 100644 --- a/include/d/actor/d_a_npc_ne.h +++ b/include/d/actor/d_a_npc_ne.h @@ -95,7 +95,7 @@ public: /* 0x5D8 */ f32 mDistToTarget; /* 0x5DC */ s16 mAngleToPlayer; /* 0x5E0 */ f32 mDistScale; - /* 0x5E4 */ char* mResName; + /* 0x5E4 */ const char* mResName; /* 0x5E8 */ mDoExt_McaMorf* mpMorf; /* 0x5EC */ mDoExt_btkAnm* mpBtkAnm; /* 0x5F0 */ mDoExt_btpAnm* mpBtpAnm; diff --git a/include/d/actor/d_a_obj_iceblock.h b/include/d/actor/d_a_obj_iceblock.h index 42b7b41c7e..ba74c43e0e 100644 --- a/include/d/actor/d_a_obj_iceblock.h +++ b/include/d/actor/d_a_obj_iceblock.h @@ -37,7 +37,7 @@ public: ACTION_DEAD_e, }; - static void PPCallBack(fopAc_ac_c*, fopAc_ac_c*, s16, dBgW_Base::PushPullLabel); + static fopAc_ac_c* PPCallBack(fopAc_ac_c*, fopAc_ac_c*, s16, dBgW_Base::PushPullLabel); void initBaseMtx(); void setBaseMtx(); u16 getPointNo(); diff --git a/include/d/actor/d_a_passer_mng.h b/include/d/actor/d_a_passer_mng.h index 7a628ebead..230432336c 100644 --- a/include/d/actor/d_a_passer_mng.h +++ b/include/d/actor/d_a_passer_mng.h @@ -251,12 +251,13 @@ public: return paramLow << 8; } + // SizedGroup in d_a_passer_mng.cpp relies on this layout, any changes here should also be changed there struct Group { u8 field_0x00; int field_0x04[0]; }; - static Group* mGroupTbl[4]; + static const Group* mGroupTbl[4]; private: /* 0x568 */ fpc_ProcID* childProcIds; diff --git a/include/d/actor/d_a_tag_push.h b/include/d/actor/d_a_tag_push.h index 3a20b5ed77..a1f0b75b22 100644 --- a/include/d/actor/d_a_tag_push.h +++ b/include/d/actor/d_a_tag_push.h @@ -24,6 +24,9 @@ public: u8 getBitSW2() { return (fopAcM_GetParam(this) & 0xFF00) >> 8; } u32 getFlowNodeNo() { + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { return (u16)home.angle.x; } diff --git a/include/d/actor/d_a_tag_shop_item.h b/include/d/actor/d_a_tag_shop_item.h index 826f867ad8..1b04b6ef8e 100644 --- a/include/d/actor/d_a_tag_shop_item.h +++ b/include/d/actor/d_a_tag_shop_item.h @@ -19,6 +19,10 @@ public: u32 getProcessID() { return mProcessID; } + int getFlowNodeNum() { + return (u16)home.angle.x == 0xFFFF ? -1 : (u16)home.angle.x; + } + /* 0x56C */ u32 mProcessID; /* 0x570 */ s16 mCreateTimer; /* 0x572 */ u8 field_0x572; diff --git a/include/d/d_bg_s.h b/include/d/d_bg_s.h index 315a7be614..498dfede91 100644 --- a/include/d/d_bg_s.h +++ b/include/d/d_bg_s.h @@ -13,7 +13,7 @@ class cBgS_ChkElm { public: /* 0x00 */ dBgW_Base* m_bgw_base_ptr; /* 0x04 */ bool m_used; - /* 0x08 */ u32 m_actor_id; + /* 0x08 */ fpc_ProcID m_actor_id; /* 0x0C */ fopAc_ac_c* m_actor_ptr; /* 0x10 vtable */ @@ -50,6 +50,7 @@ public: bool GetTriPnt(cBgS_PolyInfo const&, cXyz*, cXyz*, cXyz*) const; void ShdwDraw(cBgS_ShdwDraw*); u32 GetGrpInf(cBgS_PolyInfo const&) const; + void Draw(); virtual ~cBgS() {} virtual void Ct(); @@ -66,41 +67,121 @@ u8 dKy_pol_sound_get(cBgS_PolyInfo const* param_0); class dBgS_HIO : public JORReflexible { public: -#if DEBUG + enum flags_e { + FLAG_ACCH_WALL_OFF_e = 0x2, + FLAG_CHECK_COUNTER_e = 0x4, + FLAG_ACCH_WALL_TIMER_e = 0x8, + FLAG_OBJ_LINE_CHECK_e = 0x10, + FLAG_ACCH_DRAW_WALL_e = 0x400, + FLAG_ROOF_TIMER_e = 0x2000, + FLAG_ROOF_OFF_e = 0x4000, + + FLAG2_GND_CHK_e = 0x1, + FLAG2_SHAPE_DISP_e = 0x2, + FLAG2_GROUND_CHECK_TIMER_e = 0x4, + FLAG2_SPL_OFF_e = 0x8, + FLAG2_SPL_TIMER_e = 0x10, + FLAG2_LINE_OFF_e = 0x40, + FLAG2_LINE_TIMER_e = 0x80, + FLAG2_SHDW_DRAW_OFF_e = 0x100, + FLAG2_SHDW_DRAW_TIMER_e = 0x200, + FLAG2_CAPTPOLY_OFF_e = 0x800, + FLAG2_CAPTPOLY_TIMER_e = 0x1000, + FLAG2_SPH_CHK_OFF_e = 0x2000, + FLAG2_SPH_CHK_TIMER_e = 0x4000, + }; + dBgS_HIO() { - field_0x6 = 0; - field_0x8 = 0; + m_flags = 0; + m_flags2 = 0; - field_0xc.x = field_0xc.y = field_0xc.z = 0.0f; - field_0x18.x = field_0x18.y = field_0x18.z = 0.0f; - field_0x24.x = field_0x24.y = field_0x24.z = 0.0f; + m_linecheck_start.x = m_linecheck_start.y = m_linecheck_start.z = 0.0f; + m_linecheck_end.x = m_linecheck_end.y = m_linecheck_end.z = 0.0f; + m_gndcheck_pos.x = m_gndcheck_pos.y = m_gndcheck_pos.z = 0.0f; - field_0x30 = -1; + m_errorCheck_actor_num = -1; } virtual void genMessage(JORMContext*); - virtual ~dBgS_HIO(); + virtual ~dBgS_HIO() {} - BOOL ChkLineOff(); - BOOL ChkCheckCounter(); - BOOL ChkLineTimer(); - BOOL ChkGroundCheckTimer(); + bool ChkLineOff() { return m_flags2 & FLAG2_LINE_OFF_e; } + bool ChkCheckCounter() { return m_flags & FLAG_CHECK_COUNTER_e; } + bool ChkLineTimer() { return m_flags2 & FLAG2_LINE_TIMER_e; } + bool ChkGroundCheckTimer() { return m_flags2 & FLAG2_GROUND_CHECK_TIMER_e; } + bool ChkObjLineCheck() { return m_flags & FLAG_OBJ_LINE_CHECK_e; } + bool ChkGndCheck() { return m_flags2 & FLAG2_GND_CHK_e; } + bool ChkCaptPolyTimer() { return m_flags2 & FLAG2_CAPTPOLY_TIMER_e; } + bool ChkCaptPolyOff() { return m_flags2 & FLAG2_CAPTPOLY_OFF_e; } + bool ChkShdwDrawOff() { return m_flags2 & FLAG2_SHDW_DRAW_OFF_e; } + bool ChkShdwDrawTimer() { return m_flags2 & FLAG2_SHDW_DRAW_TIMER_e; } + bool ChkAcchWallOff() { return m_flags & FLAG_ACCH_WALL_OFF_e; } + bool ChkAcchWallTimer() { return m_flags & FLAG_ACCH_WALL_TIMER_e; } + bool ChkRoofTimer() { return m_flags & FLAG_ROOF_TIMER_e; } + bool ChkRoofOff() { return m_flags & FLAG_ROOF_OFF_e; } + bool ChkSplOff() { return m_flags2 & FLAG2_SPL_OFF_e; } + bool ChkSplTimer() { return m_flags2 & FLAG2_SPL_TIMER_e; } + bool ChkSphChkOff() { return m_flags2 & FLAG2_SPH_CHK_OFF_e; } + bool ChkSphChkTimer() { return m_flags2 & FLAG2_SPH_CHK_TIMER_e; } + bool ChkShapeDisp() { return m_flags2 & FLAG2_SHAPE_DISP_e; } + bool ChkAcchDrawWall() { return m_flags & FLAG_ACCH_DRAW_WALL_e; } - /* 0x04 */ u8 field_0x4[0x6 - 0x4]; - /* 0x06 */ u16 field_0x6; - /* 0x08 */ u16 field_0x8; - /* 0x0C */ cXyz field_0xc; - /* 0x18 */ cXyz field_0x18; - /* 0x24 */ cXyz field_0x24; - /* 0x30 */ int field_0x30; -#endif + /* 0x04 */ s8 id; + /* 0x06 */ u16 m_flags; + /* 0x08 */ u16 m_flags2; + /* 0x0C */ cXyz m_linecheck_start; + /* 0x18 */ cXyz m_linecheck_end; + /* 0x24 */ cXyz m_gndcheck_pos; + /* 0x30 */ s32 m_errorCheck_actor_num; }; -extern int g_line_counter; -extern OSStopwatch s_line_sw; +class dBgS_InsideHIO : public JORReflexible { +public: + enum flags_e { + FLAG_DISP_POLY_e = 0x1, + FLAG_DISP_DP_AREA_e = 0x2, + FLAG_WHITE_WIRE_e = 0x4, + FLAG_PLAYER_AROUND_e = 0x8, + FLAG_DISP_WATER_POLY_e = 0x10, + FLAG_GROUND_OFF_e = 0x20, + FLAG_WALL_OFF_e = 0x40, + FLAG_ROOF_OFF_e = 0x80, + FLAG_GNDCHK_PLAYER_UNDER_e = 0x100, + }; -extern int g_ground_counter; -extern OSStopwatch s_ground_sw; + dBgS_InsideHIO() { + m_flags = FLAG_PLAYER_AROUND_e; + + m_raise_amount = 1.0f; + + m_p0.x = 100.0f; + m_p0.y = 0.0f; + m_p0.z = 0.0f; + + m_p1.x = 0.0f; + m_p1.y = 0.0f; + m_p1.z = 0.0f; + } + + virtual void genMessage(JORMContext*); + virtual ~dBgS_InsideHIO(); + + BOOL ChkWallOff() { return m_flags & FLAG_WALL_OFF_e; } + BOOL ChkRoofOff() { return m_flags & FLAG_ROOF_OFF_e; } + BOOL ChkGroundOff() { return m_flags & FLAG_GROUND_OFF_e; } + BOOL ChkGndChkPlayerUnder() { return m_flags & FLAG_GNDCHK_PLAYER_UNDER_e; } + BOOL ChkWhiteWire() { return m_flags & FLAG_WHITE_WIRE_e; } + BOOL ChkDispWaterPoly() { return m_flags & FLAG_DISP_WATER_POLY_e; } + BOOL ChkDispDpArea() { return m_flags & FLAG_DISP_DP_AREA_e; } + BOOL ChkPlayerAround() { return m_flags & FLAG_PLAYER_AROUND_e; } + BOOL ChkDispPoly() { return m_flags & FLAG_DISP_POLY_e; } + + /* 0x04 */ s8 id; + /* 0x06 */ u16 m_flags; + /* 0x08 */ f32 m_raise_amount; + /* 0x0C */ cXyz m_p0; + /* 0x18 */ cXyz m_p1; +}; class dBgS : public cBgS { public: @@ -149,58 +230,32 @@ public: bool WaterChk(dBgS_SplGrpChk* chk) { return SplGrpChk(chk); } u32 GetMtrlSndId(const cBgS_PolyInfo& param_0) { return dKy_pol_sound_get(¶m_0); } - void DebugDrawPoly(dBgW_Base *param_1) {} - void DebugDrawPoly(dBgW_Base const& param_1) {} void DrawPoly(cBgS_PolyInfo const& param_0, GXColor const& param_1); fopAc_ac_c* GetActorPointer(cBgS_PolyInfo const& param_0) const { return cBgS::GetActorPointer(param_0); } + + void DebugDrawPoly(const dBgW_Base& param_1); + + #if DEBUG + bool LineCross(cBgS_LinChk* i_linChk); + f32 GroundCross(cBgS_GndChk* i_gndChk); + void ShdwDraw(cBgS_ShdwDraw*); + #else bool LineCross(cBgS_LinChk* i_linChk) { - #if DEBUG - if (m_hio.ChkLineOff()) { - return false; - } - if (m_hio.ChkCheckCounter()) { - g_line_counter++; - } - if (m_hio.ChkLineTimer()) { - OSStartStopwatch(&s_line_sw); - } - bool rt = cBgS::LineCross(i_linChk); - if (m_hio.ChkLineTimer()) { - OSStopStopwatch(&s_line_sw); - OSDumpStopwatch(&s_line_sw); - } - return rt; - #else return cBgS::LineCross(i_linChk); - #endif } + f32 GroundCross(cBgS_GndChk* i_gndChk) { - #if DEBUG - if (m_hio.ChkCheckCounter()) { - g_ground_counter++; - } - if (m_hio.ChkGroundCheckTimer()) { - OSStartStopwatch(&s_ground_sw); - } - f32 rt = cBgS::GroundCross(i_gndChk); - if (m_hio.ChkGroundCheckTimer()) { - OSStopStopwatch(&s_ground_sw); - OSDumpStopwatch(&s_ground_sw); - } - return rt; - #else return cBgS::GroundCross(i_gndChk); - #endif } + #endif void ChkDeleteActorRegist(fopAc_ac_c*); void Draw(); + void CaptPoly(dBgS_CaptPoly&); -#if DEBUG /* 0x1404 */ u8 field_0x1404[0x1408 - 0x1404]; /* 0x1408 */ dBgS_HIO m_hio; -#endif }; // Size: 0x1404 bool dBgS_CheckBGroundPoly(cBgS_PolyInfo const&); diff --git a/include/d/d_bg_s_acch.h b/include/d/d_bg_s_acch.h index 4f97961dde..33bca24c0a 100644 --- a/include/d/d_bg_s_acch.h +++ b/include/d/d_bg_s_acch.h @@ -25,7 +25,7 @@ private: public: enum { - /* 0x2 */ WALL_HIT = 2, + /* 0x2 */ FLAG_WALL_HIT = 2, /* 0x4 */ WALL_H_DIRECT = 4, }; @@ -42,16 +42,18 @@ public: virtual ~dBgS_AcchCir() {} #endif + void SetWallPolyIndex(int index) { SetPolyIndex(index); } + f32 GetWallH() { return m_wall_h; } f32 GetWallR() { return m_wall_r; } void SetWallH(f32 h) { m_wall_h = h; } void ClrWallHDirect() { m_flags &= ~WALL_H_DIRECT; } - bool ChkWallHit() { return (m_flags & WALL_HIT) != 0; } + bool ChkWallHit() { return (m_flags & FLAG_WALL_HIT) != 0; } s16 GetWallAngleY() { return m_wall_angle_y; } - bool ChkWallHDirect() { return (m_flags & WALL_H_DIRECT) != 0; } + BOOL ChkWallHDirect() { return (m_flags & WALL_H_DIRECT); } f32 GetWallHDirect() { return m_wall_h_direct; } f32 GetWallRR() { return m_wall_rr; } - void SetWallHit() { m_flags |= WALL_HIT; } + void SetWallHit() { m_flags |= FLAG_WALL_HIT; } void SetWallAngleY(s16 i_angle) { m_wall_angle_y = i_angle; } cM3dGCir* GetCirP() { return &m_cir; } @@ -62,26 +64,26 @@ class dBgS; class dBgS_Acch : public cBgS_Chk, public dBgS_Chk { public: enum { - /* 0x000002 */ GRND_NONE = (1 << 1), - /* 0x000004 */ WALL_NONE = (1 << 2), - /* 0x000008 */ ROOF_NONE = (1 << 3), - /* 0x000010 */ WALL_HIT = (1 << 4), - /* 0x000020 */ GROUND_HIT = (1 << 5), - /* 0x000040 */ GROUND_FIND = (1 << 6), - /* 0x000080 */ GROUND_LANDING = (1 << 7), - /* 0x000100 */ GROUND_AWAY = (1 << 8), - /* 0x000200 */ ROOF_HIT = (1 << 9), - /* 0x000400 */ WATER_NONE = (1 << 10), - /* 0x000800 */ WATER_HIT = (1 << 11), - /* 0x001000 */ WATER_IN = (1 << 12), - /* 0x002000 */ LINE_CHECK = (1 << 13), - /* 0x004000 */ LINE_CHECK_NONE = (1 << 14), - /* 0x008000 */ CLR_SPEED_Y = (1 << 15), - /* 0x010000 */ LINE_CHECK_HIT = (1 << 16), - /* 0x100000 */ MOVE_BG_ONLY = (1 << 20), - /* 0x200000 */ GND_THIN_CELLING_OFF = (1 << 21), - /* 0x400000 */ WALL_SORT = (1 << 22), - /* 0x800000 */ LINE_DOWN = (1 << 23), + /* 0x000002 */ FLAG_GRND_NONE = (1 << 1), + /* 0x000004 */ FLAG_WALL_NONE = (1 << 2), + /* 0x000008 */ FLAG_ROOF_NONE = (1 << 3), + /* 0x000010 */ FLAG_WALL_HIT = (1 << 4), + /* 0x000020 */ FLAG_GROUND_HIT = (1 << 5), + /* 0x000040 */ FLAG_GROUND_FIND = (1 << 6), + /* 0x000080 */ FLAG_GROUND_LANDING = (1 << 7), + /* 0x000100 */ FLAG_GROUND_AWAY = (1 << 8), + /* 0x000200 */ FLAG_ROOF_HIT = (1 << 9), + /* 0x000400 */ FLAG_WATER_NONE = (1 << 10), + /* 0x000800 */ FLAG_WATER_HIT = (1 << 11), + /* 0x001000 */ FLAG_WATER_IN = (1 << 12), + /* 0x002000 */ FLAG_LINE_CHECK = (1 << 13), + /* 0x004000 */ FLAG_LINE_CHECK_NONE = (1 << 14), + /* 0x008000 */ FLAG_CLR_SPEED_Y = (1 << 15), + /* 0x010000 */ FLAG_LINE_CHECK_HIT = (1 << 16), + /* 0x100000 */ FLAG_MOVE_BG_ONLY = (1 << 20), + /* 0x200000 */ FLAG_GND_THIN_CELLING_OFF = (1 << 21), + /* 0x400000 */ FLAG_WALL_SORT = (1 << 22), + /* 0x800000 */ FLAG_LINE_DOWN = (1 << 23), }; dBgS_Acch(); @@ -124,56 +126,56 @@ public: f32 GetRoofHeight() const { return m_roof_height; } int GetTblSize() { return m_tbl_size; } void SetLin() { m_lin.SetStartEnd(*pm_old_pos, *pm_pos); } - bool ChkGroundFind() { return (m_flags & GROUND_FIND) != 0; } - bool ChkGroundHit() const { return (m_flags & GROUND_HIT) != 0; } - bool ChkGroundLanding() const { return (m_flags & GROUND_LANDING) != 0; } - void ClrGroundLanding() { m_flags &= ~GROUND_LANDING; } - void ClrGroundAway() { m_flags &= ~GROUND_AWAY; } - void ClrWallHit() { m_flags &= ~WALL_HIT; } - void SetRoofNone() { m_flags |= ROOF_NONE; } - void SetRoofHit() { m_flags |= ROOF_HIT; } - void SetWaterNone() { m_flags |= WATER_NONE; } - u32 ChkWallHit() const { return m_flags & WALL_HIT; } - void OffLineCheckHit() { m_flags &= ~LINE_CHECK_HIT; } - void OffLineCheck() { m_flags &= ~LINE_CHECK; } - u32 ChkLineCheckNone() const { return (m_flags & LINE_CHECK_NONE) != 0; } - u32 ChkLineCheck() const { return (m_flags & LINE_CHECK) != 0; } - void ClrRoofHit() { m_flags &= ~ROOF_HIT; } - void ClrWaterHit() { m_flags &= ~WATER_HIT; } - void SetWaterHit() { m_flags |= WATER_HIT; } - void ClrWaterIn() { m_flags &= ~WATER_IN; } - void SetWaterIn() { m_flags |= WATER_IN; } - const u32 MaskWaterIn() const { return m_flags & WATER_IN; } + bool ChkGroundFind() { return (m_flags & FLAG_GROUND_FIND) != 0; } + bool ChkGroundHit() const { return (m_flags & FLAG_GROUND_HIT) != 0; } + bool ChkGroundLanding() const { return (m_flags & FLAG_GROUND_LANDING) != 0; } + void ClrGroundLanding() { m_flags &= ~FLAG_GROUND_LANDING; } + void ClrGroundAway() { m_flags &= ~FLAG_GROUND_AWAY; } + void ClrWallHit() { m_flags &= ~FLAG_WALL_HIT; } + void SetRoofNone() { m_flags |= FLAG_ROOF_NONE; } + void SetRoofHit() { m_flags |= FLAG_ROOF_HIT; } + void SetWaterNone() { m_flags |= FLAG_WATER_NONE; } + u32 ChkWallHit() const { return m_flags & FLAG_WALL_HIT; } + void OffLineCheckHit() { m_flags &= ~FLAG_LINE_CHECK_HIT; } + void OffLineCheck() { m_flags &= ~FLAG_LINE_CHECK; } + u32 ChkLineCheckNone() const { return (m_flags & FLAG_LINE_CHECK_NONE); } + u32 ChkLineCheck() const { return (m_flags & FLAG_LINE_CHECK); } + void ClrRoofHit() { m_flags &= ~FLAG_ROOF_HIT; } + void ClrWaterHit() { m_flags &= ~FLAG_WATER_HIT; } + void SetWaterHit() { m_flags |= FLAG_WATER_HIT; } + void ClrWaterIn() { m_flags &= ~FLAG_WATER_IN; } + void SetWaterIn() { m_flags |= FLAG_WATER_IN; } + const u32 MaskWaterIn() const { return m_flags & FLAG_WATER_IN; } const bool ChkWaterIn() const { return MaskWaterIn() != 0; } - void ClrGroundFind() { m_flags &= ~GROUND_FIND; } - u32 MaskRoofHit() const { return m_flags & ROOF_HIT; } + void ClrGroundFind() { m_flags &= ~FLAG_GROUND_FIND; } + u32 MaskRoofHit() const { return m_flags & FLAG_ROOF_HIT; } bool ChkRoofHit() const { return MaskRoofHit() != 0; } - void OffClrSpeedY() { m_flags |= CLR_SPEED_Y; } - void OnClrSpeedY() { m_flags &= ~CLR_SPEED_Y; } - bool ChkClrSpeedY() const { return !(m_flags & CLR_SPEED_Y); } - void SetGroundFind() { m_flags |= GROUND_FIND; } - void SetGroundHit() { m_flags |= GROUND_HIT; } - void SetGroundLanding() { m_flags |= GROUND_LANDING; } - void SetGroundAway() { m_flags |= GROUND_AWAY; } - const u32 MaskWaterHit() const { return m_flags & WATER_HIT; } + void OffClrSpeedY() { m_flags |= FLAG_CLR_SPEED_Y; } + void OnClrSpeedY() { m_flags &= ~FLAG_CLR_SPEED_Y; } + bool ChkClrSpeedY() const { return !(m_flags & FLAG_CLR_SPEED_Y); } + void SetGroundFind() { m_flags |= FLAG_GROUND_FIND; } + void SetGroundHit() { m_flags |= FLAG_GROUND_HIT; } + void SetGroundLanding() { m_flags |= FLAG_GROUND_LANDING; } + void SetGroundAway() { m_flags |= FLAG_GROUND_AWAY; } + const u32 MaskWaterHit() const { return m_flags & FLAG_WATER_HIT; } const bool ChkWaterHit() const { return MaskWaterHit() != 0; } - void ClrWaterNone() { m_flags &= ~WATER_NONE; } + void ClrWaterNone() { m_flags &= ~FLAG_WATER_NONE; } void SetWaterCheckOffset(f32 offset) { m_wtr_chk_offset = offset; } - void OnLineCheck() { m_flags |= LINE_CHECK; } - void ClrRoofNone() { m_flags &= ~ROOF_NONE; } + void OnLineCheck() { m_flags |= FLAG_LINE_CHECK; } + void ClrRoofNone() { m_flags &= ~FLAG_ROOF_NONE; } void SetRoofCrrHeight(f32 height) { m_roof_crr_height = height; } void SetWtrChkMode(int mode) { m_wtr_mode = mode; } - void SetGrndNone() { m_flags |= GRND_NONE; } - void ClrGrndNone() { m_flags &= ~GRND_NONE; } - bool ChkMoveBGOnly() const { return (m_flags & MOVE_BG_ONLY) != 0; } - void SetWallHit() { m_flags |= WALL_HIT; } - void ClrWallNone() { m_flags &= ~WALL_NONE; } - void OnLineCheckNone() { m_flags |= LINE_CHECK_NONE; } - void OffLineCheckNone() { m_flags &= ~LINE_CHECK_NONE; } - void SetWallNone() { m_flags |= WALL_NONE; } - void OnLineCheckHit() { m_flags |= LINE_CHECK_HIT; } - bool ChkGroundAway() const { return (m_flags & GROUND_AWAY) != 0; } - void ClrGroundHit() { m_flags &= ~GROUND_HIT; } + void SetGrndNone() { m_flags |= FLAG_GRND_NONE; } + void ClrGrndNone() { m_flags &= ~FLAG_GRND_NONE; } + bool ChkMoveBGOnly() const { return (m_flags & FLAG_MOVE_BG_ONLY) != 0; } + void SetWallHit() { m_flags |= FLAG_WALL_HIT; } + void ClrWallNone() { m_flags &= ~FLAG_WALL_NONE; } + void OnLineCheckNone() { m_flags |= FLAG_LINE_CHECK_NONE; } + void OffLineCheckNone() { m_flags &= ~FLAG_LINE_CHECK_NONE; } + void SetWallNone() { m_flags |= FLAG_WALL_NONE; } + void OnLineCheckHit() { m_flags |= FLAG_LINE_CHECK_HIT; } + bool ChkGroundAway() const { return (m_flags & FLAG_GROUND_AWAY) != 0; } + void ClrGroundHit() { m_flags &= ~FLAG_GROUND_HIT; } void SetGroundCheckOffset(f32 offset) { m_gnd_chk_offset = offset; } cM3dGCyl* GetWallBmdCylP() { return &m_wall_cyl; } @@ -186,7 +188,7 @@ public: f32 GetWallH(int i_no) { return pm_acch_cir[i_no].GetWallH(); } f32 GetWallR(int i_no) { return pm_acch_cir[i_no].GetWallR(); } - bool ChkWallHDirect(int i_no) { return pm_acch_cir[i_no].ChkWallHDirect(); } + BOOL ChkWallHDirect(int i_no) { return pm_acch_cir[i_no].ChkWallHDirect(); } f32 GetWallHDirect(int i_no) { return pm_acch_cir[i_no].GetWallHDirect(); } f32 GetWallRR(int i_no) { return pm_acch_cir[i_no].GetWallRR(); } void SetWallCirHit(int i_no) { pm_acch_cir[i_no].SetWallHit(); } diff --git a/include/d/d_bg_s_cap_poly.h b/include/d/d_bg_s_cap_poly.h deleted file mode 100644 index 0cda04c739..0000000000 --- a/include/d/d_bg_s_cap_poly.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef D_BG_D_BG_S_CAPT_POLY_H -#define D_BG_D_BG_S_CAPT_POLY_H - -#include "d/d_bg_s_chk.h" -#include "SSystem/SComponent/c_m3d_g_aab.h" - -struct dBgS_CaptPoly; - -typedef void (*CaptPolyCallback)(dBgS_CaptPoly&, cBgD_Vtx_t*, u16, u16, u16, cM3dGPla*); - -struct dBgS_CaptPoly : public cBgS_Chk, public dBgS_Chk { -public: - cM3dGAab* GetBndP() { return &m_pos;} - - /* 0x2C */ cM3dGAab m_pos; - /* 0x48 */ CaptPolyCallback m_callback; -}; - -#endif diff --git a/include/d/d_bg_s_capt_poly.h b/include/d/d_bg_s_capt_poly.h index 69a36ce247..9e61d74336 100644 --- a/include/d/d_bg_s_capt_poly.h +++ b/include/d/d_bg_s_capt_poly.h @@ -1,18 +1,24 @@ -#ifndef _D_BG_S_CAPT_POLY_H -#define _D_BG_S_CAPT_POLY_H +#ifndef D_BG_D_BG_S_CAPT_POLY_H +#define D_BG_D_BG_S_CAPT_POLY_H #include "d/d_bg_s_chk.h" #include "SSystem/SComponent/c_m3d_g_aab.h" -#include "SSystem/SComponent/c_xyz.h" -class dBgS_CaptPoly : public cBgS_Chk, public dBgS_Chk { +struct dBgS_CaptPoly; + +typedef int (*CaptPolyCallback)(dBgS_CaptPoly*, cBgD_Vtx_t*, int, int, int, cM3dGPla*); + +struct dBgS_CaptPoly : public cBgS_Chk, public dBgS_Chk { public: dBgS_CaptPoly(); ~dBgS_CaptPoly() {} void Set(cXyz&, cXyz&); - /* 0x24 */ cM3dGAab aab; - /* 0x48 */ int field_0x48; + void SetCallback(CaptPolyCallback callback) { m_callback = callback; } + cM3dGAab* GetBndP() { return &m_bnd;} + + /* 0x2C */ cM3dGAab m_bnd; + /* 0x48 */ CaptPolyCallback m_callback; }; -#endif /* _D_BG_S_CAPT_POLY_H */ +#endif diff --git a/include/d/d_bg_s_grp_pass_chk.h b/include/d/d_bg_s_grp_pass_chk.h index c58300e68b..eea3414b98 100644 --- a/include/d/d_bg_s_grp_pass_chk.h +++ b/include/d/d_bg_s_grp_pass_chk.h @@ -20,6 +20,7 @@ public: void OffWaterGrp() { mGrp &= ~WATER_GRP; } void OnNormalGrp() { mGrp |= NORMAL_GRP; } void OffNormalGrp() { mGrp &= ~NORMAL_GRP; } + void OnFullGrp() { mGrp |= FULL_GRP; } void OffFullGrp() { mGrp &= ~FULL_GRP; } void OnAll() { mGrp |= FULL_GRP; } u32 MaskNormalGrp() { return mGrp & NORMAL_GRP; } diff --git a/include/d/d_bg_s_sph_chk.h b/include/d/d_bg_s_sph_chk.h index a7734563c6..200a46d89b 100644 --- a/include/d/d_bg_s_sph_chk.h +++ b/include/d/d_bg_s_sph_chk.h @@ -15,6 +15,7 @@ public: dBgS_SphChk(); virtual ~dBgS_SphChk(); + void Init() { ClearPi(); } void SetCallback(SphChk_Callback i_callback) { mCallback = i_callback; } /* 0x50 */ SphChk_Callback mCallback; diff --git a/include/d/d_bg_s_spl_grp_chk.h b/include/d/d_bg_s_spl_grp_chk.h index bc8567eec5..447bbf4d73 100644 --- a/include/d/d_bg_s_spl_grp_chk.h +++ b/include/d/d_bg_s_spl_grp_chk.h @@ -24,7 +24,7 @@ public: void OffMoveBGOnly() { m_flags &= ~MOVE_BG_ONLY; } void OnMoveBGOnly() { m_flags |= MOVE_BG_ONLY; } void OnFind() { m_flags |= FIND; } - bool ChkMoveBGOnly() { return m_flags & MOVE_BG_ONLY; } + BOOL ChkMoveBGOnly() { return m_flags & MOVE_BG_ONLY; } void SetHeight(f32 height) { m_height = height; } f32 GetHeight() { return m_height; } cXyz& GetPosP() { return m_ground; } diff --git a/include/d/d_bg_w.h b/include/d/d_bg_w.h index 2b24bf12c8..580e22d904 100644 --- a/include/d/d_bg_w.h +++ b/include/d/d_bg_w.h @@ -156,6 +156,10 @@ public: u32 GetMaskPolyInf1_NoShift(int, u32) const; u32 GetPolyInf2(int, u32, u32) const; int GetTriGrp(int) const; + + #if DEBUG + void DebugLocalPos(); + #endif virtual ~cBgW(); virtual bool ChkMemoryError(); @@ -218,23 +222,23 @@ public: virtual bool ChkShdwDrawThrough(int, cBgS_PolyPassChk*); virtual bool ChkGrpThrough(int, cBgS_GrpPassChk*, int); - u32 GetOldInvMtx(Mtx m) { return MTXInverse(m_inv_mtx, m); } - MtxP GetBaseMtxP() { return pm_base; } - bool ChkNoCalcVtx() { return mFlags & NO_CALC_VTX_e; } - bool ChkFlush() { return field_0x91 & 8; } + u32 GetOldInvMtx(Mtx m) const { return PSMTXInverse(m_inv_mtx, m); } + MtxP GetBaseMtxP() { return *pm_base; } + BOOL ChkNoCalcVtx() { return mFlags & NO_CALC_VTX_e; } + BOOL ChkFlush() { return field_0x91 & 8; } void SetLock() { mFlags |= (u8)LOCK_e; } void OffRoofRegist() { field_0x91 |= (u8)0x4; } void OnRoofRegist() { field_0x91 &= ~0x04; } - bool ChkRoofRegist() { return field_0x91 & 4;} + bool ChkRoofRegist() { return (field_0x91 & 4) == 0;} cBgD_Vtx_t* GetVtxTbl() const { return pm_vtx_tbl; } int GetVtxNum() const { return pm_bgd->m_v_num; } void ClrNoCalcVtx() { mFlags &= ~NO_CALC_VTX_e; } - void SetBaseMtxP(MtxP mtx) { pm_base = mtx; } + void SetBaseMtxP(Mtx* mtx) { pm_base = mtx; } void SetNoCalcVtx() { mFlags |= NO_CALC_VTX_e; } cBgD_t* GetBgd() const { return pm_bgd; } public: - /* 0x18 */ MtxP pm_base; // Model Matrix + /* 0x18 */ Mtx* pm_base; // Model Matrix /* 0x1C */ Mtx m_inv_mtx; /* 0x4C */ Mtx m_mtx; /* 0x7C */ cXyz mTransVel; @@ -333,10 +337,14 @@ public: virtual bool ChkShdwDrawThrough(int, cBgS_PolyPassChk*); virtual bool ChkGrpThrough(int, cBgS_GrpPassChk*, int); + void DrawBox() const; + void DebugDraw() const; + void DrawPoly(const cBgS_PolyInfo&, const GXColor&) const; + void SetCrrFunc(dBgW_CrrFunc func) { m_crr_func = func; } void SetRideCallback(dBgW_RideCallback func) { m_ride_callback = func; } void SetArrowStickCallback(dBgW_ArrowStickCallback func) { m_arrow_stick_callback = func; } - void OnMoveFlag() { m_flags |= 1; } + void OnMoveFlag() { m_flags |= (u8)1; } private: /* 0xB0 */ dBgW_CrrFunc m_crr_func; @@ -347,4 +355,8 @@ private: dBgW* dBgW_NewSet(cBgD_t* pbgd, u32 flags, Mtx* pbase_mtx); +#if DEBUG +extern u8 lbl_8074C7F0; +#endif + #endif /* D_BG_D_BG_W_H */ diff --git a/include/d/d_bg_w_base.h b/include/d/d_bg_w_base.h index 762d3bb707..6940df06fa 100644 --- a/include/d/d_bg_w_base.h +++ b/include/d/d_bg_w_base.h @@ -105,17 +105,15 @@ public: virtual void CallRideCallBack(fopAc_ac_c*, fopAc_ac_c*); virtual void CallArrowStickCallBack(fopAc_ac_c*, fopAc_ac_c*, cXyz&); - #if DEBUG - virtual void DebugDraw() {} - virtual void DrawPoly(cBgS_PolyInfo const& param_0, GXColor const& param_1) {} - virtual void DebugBox() {} - #endif + virtual void DebugDraw() const {} + virtual void DrawPoly(cBgS_PolyInfo const& param_0, GXColor const& param_1) const {} + virtual void DrawBox() const {} PushPull_CallBack GetPushPullCallback() const { return m_pushPull_Callback; } s16 GetDiffShapeAngleY() { return m_diff_ShapeAngleY; } int GetRoomId() { return m_roomId; } - bool chkStickWall() { return field_0xb & 1; } - bool chkStickRoof() { return field_0xb & 2; } + BOOL chkStickWall() { return field_0xb & 1; } + BOOL chkStickRoof() { return field_0xb & 2; } bool ChkPushPullOk() const { return m_pushPull_Ok; } void SetPushPullCallback(PushPull_CallBack i_callBack) { m_pushPull_Callback = i_callBack; } void SetRoomId(int id) { m_roomId = id; } diff --git a/include/d/d_cc_d.h b/include/d/d_cc_d.h index 7c6b438a4d..19f0430498 100644 --- a/include/d/d_cc_d.h +++ b/include/d/d_cc_d.h @@ -144,7 +144,7 @@ public: void ClrEffCounter() { mEffCounter = 0; } u32 GetGFlag() const { return mGFlag; } u32 GetRPrm() const { return mRPrm; } - u32 MskSPrm(u32 mask) const { return mGFlag & mask; } + u32 MskSPrm(u32 mask) { return mGFlag & mask; } u32 MskRPrm(u32 mask) const { return mRPrm & mask; } bool ChkSPrm(u32 mask) { return MskSPrm(mask); } void OnSPrm(u32 flag) { mGFlag |= flag; } @@ -173,7 +173,7 @@ public: u8 GetSe() { return mSe; } dCcG_At_Spl GetSpl() { return (dCcG_At_Spl)mSpl; } u8 GetMtrl() { return mMtrl; } - u8 GetHitMark() { return mHitMark; } + int GetHitMark() { return mHitMark; } void SetRVec(cXyz& vec) { mRVec = vec; } void SetHitPos(cXyz& pos) { mHitPos = pos; } cXyz* GetHitPosP() { return &mHitPos; } @@ -203,10 +203,10 @@ public: void SetHitMark(CcG_Tg_HitMark mark) { mHitMark = mark; } s16* GetShieldFrontRangeYAngle() { return mShieldFrontRangeYAngle; } s16 GetShieldRange() { return mShieldRange; } - u8 GetSpl() { return mSpl; } + int GetSpl() { return mSpl; } void SetSpl(dCcG_Tg_Spl tg_spl) { mSpl = tg_spl; } void SetSpl(u8 tg_spl) { mSpl = tg_spl; } - u8 GetHitMark() { return mHitMark; } + int GetHitMark() { return mHitMark; } void SetRVec(cXyz& vec) { mRVec = vec; } cXyz* GetVecP() { return &mVec; } cXyz* GetRVecP() { return &mRVec; } @@ -250,7 +250,7 @@ public: void SetRoomId(int id) { mRoomId = id; } fpc_ProcID GetAtOldApid() { return mAtOldApid; } fpc_ProcID GetTgOldApid() { return mTgOldApid; } - bool ChkNoActor() { return field_0x1C & 1;} + BOOL ChkNoActor() { return field_0x1C & 1;} bool ChkNoneActorPerfTblId() { return field_0x08 == 0xFFFF; } dCcG_At_Spl GetAtSpl() { return (dCcG_At_Spl)mAt; } void SetAtSpl(dCcG_At_Spl spl) { mAt = spl; } @@ -451,9 +451,7 @@ public: void CalcTgVec(); virtual ~dCcD_Cps() {} dCcD_Cps() {} - #if DEBUG virtual void Draw(const GXColor& color); - #endif }; // Size = 0x144 // Triangle @@ -463,9 +461,7 @@ public: cCcD_ShapeAttr* GetShapeAttr(); virtual ~dCcD_Tri() {} dCcD_Tri() {} - #if DEBUG virtual void Draw(const GXColor& color); - #endif }; // Cylinder @@ -478,9 +474,7 @@ public: void MoveCTg(cXyz&); virtual ~dCcD_Cyl() {} dCcD_Cyl() {} - #if DEBUG virtual void Draw(const GXColor& color); - #endif }; // Size = 0x13C // Sphere @@ -492,9 +486,7 @@ public: void MoveCAt(cXyz&); virtual cCcD_ShapeAttr* GetShapeAttr(); virtual ~dCcD_Sph() {} - #if DEBUG virtual void Draw(const GXColor& color); - #endif }; // Size = 0x138 dCcD_GObjInf* dCcD_GetGObjInf(cCcD_Obj* param_0); diff --git a/include/d/d_cc_mass_s.h b/include/d/d_cc_mass_s.h index c5d6186014..672adb913a 100644 --- a/include/d/d_cc_mass_s.h +++ b/include/d/d_cc_mass_s.h @@ -9,7 +9,7 @@ class dCcMassS_Obj { private: /* 0x00 */ cCcD_Obj* mpObj; /* 0x04 */ u8 mPriority; - /* 0x08 */ dCcMassS_ObjCallback mpCallback; + /* 0x08 */ dCcMassS_ObjCallback mpAreaCheckFunc; /* 0x0C */ cCcD_DivideInfo mDivideInfo; /* 0x1C vtable */ @@ -19,10 +19,10 @@ public: void Set(cCcD_Obj* p_obj, u8 priority, dCcMassS_ObjCallback callback); void Clear(); - cCcD_Obj* GetObj() { return mpObj; } + cCcD_Obj* GetObj() const { return mpObj; } u8 GetPriority() const { return mPriority; } - dCcMassS_ObjCallback GetCallback() const { return mpCallback; } - cCcD_DivideInfo& GetDivideInfo() { return mDivideInfo; } + dCcMassS_ObjCallback GetAreaCheckFunc() const { return mpAreaCheckFunc; } + cCcD_DivideInfo* GetPDivideInfo() { return &mDivideInfo; } }; // Size = 0x20 STATIC_ASSERT(0x20 == sizeof(dCcMassS_Obj)); diff --git a/include/d/d_cc_s.h b/include/d/d_cc_s.h index dbd3c18285..b4d90787ae 100644 --- a/include/d/d_cc_s.h +++ b/include/d/d_cc_s.h @@ -44,6 +44,16 @@ public: virtual void MoveAfterCheck(); virtual void CalcParticleAngle(dCcD_GObjInf*, cCcD_Stts*, cCcD_Stts*, csXyz*); + #if DEBUG + void OnMassAllTimer() { + m_is_mass_all_timer = 1; + } + + void OffMassAllTimer() { + m_is_mass_all_timer = 0; + } + #endif + void SetMass(cCcD_Obj* i_obj, u8 i_priority) { mMass_Mng.Set(i_obj, i_priority); } void SetMassCam(cM3dGCps& i_cps) { mMass_Mng.SetCam(i_cps); } u32 GetMassResultCam() { return mMass_Mng.GetResultCam(); } @@ -70,7 +80,7 @@ public: // /* 0x0000 */ cCcS mCCcS; /* 0x284C */ dCcMassS_Mng mMass_Mng; #if DEBUG - /* 0x2AD0 */ u8 field_0x2ad0; + /* 0x2AD0 */ u8 m_is_mass_all_timer; #endif }; // Size = 0x2AC4 diff --git a/include/d/d_com_inf_game.h b/include/d/d_com_inf_game.h index 5f578dd658..fc60c5d107 100644 --- a/include/d/d_com_inf_game.h +++ b/include/d/d_com_inf_game.h @@ -616,6 +616,7 @@ public: void setItemMaxMagicCount(s16 max) { mItemInfo.mItemMaxMagicCount += max; } s32 getItemOilCount() { return mItemInfo.mItemOilCount; } void setItemOilCount(s32 oil) { mItemInfo.mItemOilCount += oil; } + void setItemMaxOilCount(s32 oil) { mItemInfo.mItemMaxOilCount += oil; } void clearItemOilCount() { mItemInfo.mItemOilCount = 0; } s32 getItemNowOil() { return mItemInfo.mItemNowOil; } void setItemNowOil(s32 oil) { mItemInfo.mItemNowOil = oil; } @@ -630,6 +631,7 @@ public: s32 getOxygenCount() { return mItemInfo.mOxygenCount; } void setOxygenCount(s32 oxygen) { mItemInfo.mOxygenCount += oxygen; } void clearOxygenCount() { mItemInfo.mOxygenCount = 0; } + void setMaxOxygenCount(s32 oxygen) { mItemInfo.mMaxOxygenCount += oxygen; } s32 getMaxOxygenCount() { return mItemInfo.mMaxOxygenCount; } void clearMaxOxygenCount() { mItemInfo.mMaxOxygenCount = 0; } s16 getItemArrowNumCount() { return mItemInfo.mItemArrowNumCount; } @@ -1084,7 +1086,11 @@ s32 dComIfGs_isDungeonItemWarp(int i_stageNo); void dComIfGs_BossLife_public_Set(s8); s8 dComIfGs_sense_type_change_Get(); void dComIfGs_sense_type_change_Set(s8); +#if TARGET_PC +cXyz dComIfGs_getWarpPlayerPos(); +#else cXyz& dComIfGs_getWarpPlayerPos(); +#endif const char* dComIfGs_getWarpStageName(); s16 dComIfGs_getWarpPlayerAngleY(); s8 dComIfGs_getWarpRoomNo(); @@ -1174,7 +1180,11 @@ void dComIfGs_setWarpItemData(char const* stage, cXyz pos, s16 angle, s8 roomNo, u8 param_5); void dComIfGs_setLastWarpMarkItemData(const char* stage, cXyz pos, s16 angle, s8 roomNo, u8, u8); const char* dComIfGs_getWarpStageName(); +#if TARGET_PC +cXyz dComIfGs_getWarpPlayerPos(); +#else cXyz& dComIfGs_getWarpPlayerPos(); +#endif s16 dComIfGs_getWarpPlayerAngleY(); s8 dComIfGs_getWarpRoomNo(); u8 dComIfGs_getWarpMarkFlag(); @@ -1420,7 +1430,11 @@ inline BOOL dComIfGs_isTransformLV(int i_no) { return g_dComIfG_gameInfo.info.getPlayer().getPlayerStatusB().isTransformLV(i_no); } +#if TARGET_PC +inline cXyz dComIfGs_getHorseRestartPos() { +#else inline cXyz& dComIfGs_getHorseRestartPos() { +#endif return g_dComIfG_gameInfo.info.getPlayer().getHorsePlace().getPos(); } @@ -1441,7 +1455,11 @@ inline void dComIfGs_setHorseRestart(const char* i_stageName, cXyz& i_pos, s16 i g_dComIfG_gameInfo.info.getPlayer().getHorsePlace().set(i_stageName, i_pos, i_angle, i_roomNo); } +#if TARGET_PC +inline cXyz dComIfGs_getPlayerFieldLastStayPos() { +#else inline cXyz& dComIfGs_getPlayerFieldLastStayPos() { +#endif return g_dComIfG_gameInfo.info.getPlayer().getPlayerFieldLastStayInfo().getPos(); } @@ -1483,7 +1501,11 @@ inline void dComIfGs_setPlayerFieldLastStayInfo(const char* i_stage, cXyz& i_pos i_point, i_region); } +#if TARGET_PC +inline cXyz dComIfGs_getLastWarpMarkPlayerPos() { +#else inline cXyz& dComIfGs_getLastWarpMarkPlayerPos() { +#endif return g_dComIfG_gameInfo.info.getPlayer().getPlayerLastMarkInfo().getPos(); } @@ -1676,6 +1698,10 @@ inline u8 dComIfGs_getBombMax(u8 i_bombType) { return g_dComIfG_gameInfo.info.getPlayer().getItemMax().getBombNum(i_bombType); } +inline void dComIfGs_setPohSpiritNum(u8 i_num) { + g_dComIfG_gameInfo.info.getPlayer().getCollect().setPohNum(i_num); +} + inline u8 dComIfGs_getPohSpiritNum() { return g_dComIfG_gameInfo.info.getPlayer().getCollect().getPohNum(); } @@ -1684,6 +1710,10 @@ inline void dComIfGs_addPohSpiritNum() { g_dComIfG_gameInfo.info.getPlayer().getCollect().addPohNum(); } +inline BOOL dComIfGs_isCollectClothes(u8 i_clothesNo) { + return g_dComIfG_gameInfo.info.getPlayer().getCollect().isCollect(COLLECT_CLOTHING, i_clothesNo); +} + inline void dComIfGs_setCollectClothes(u8 i_clothesNo) { g_dComIfG_gameInfo.info.getPlayer().getCollect().setCollect(COLLECT_CLOTHING, i_clothesNo); } @@ -1701,18 +1731,34 @@ inline BOOL dComIfGs_isCollectClothing(u8 i_clothesNo) { i_clothesNo); } +inline void dComIfGs_offCollectClothes(u8 i_clothesNo) { + g_dComIfG_gameInfo.info.getPlayer().getCollect().offCollect(COLLECT_CLOTHING, i_clothesNo); +} + inline BOOL dComIfGs_isCollectSword(u8 i_swordNo) { return g_dComIfG_gameInfo.info.getPlayer().getCollect().isCollect(COLLECT_SWORD, i_swordNo); } +inline void dComIfGs_offCollectSword(u8 i_swordNo) { + g_dComIfG_gameInfo.info.getPlayer().getCollect().offCollect(COLLECT_SWORD, i_swordNo); +} + inline BOOL dComIfGs_isCollectShield(u8 i_item) { return g_dComIfG_gameInfo.info.getPlayer().getCollect().isCollect(COLLECT_SHIELD, i_item); } +inline void dComIfGs_offCollectShield(u8 i_shieldNo) { + g_dComIfG_gameInfo.info.getPlayer().getCollect().offCollect(COLLECT_SHIELD, i_shieldNo); +} + inline void dComIfGs_onCollectCrystal(u8 i_item) { g_dComIfG_gameInfo.info.getPlayer().getCollect().onCollectCrystal(i_item); } +inline void dComIfGs_offCollectCrystal(u8 i_item) { + g_dComIfG_gameInfo.info.getPlayer().getCollect().offCollectCrystal(i_item); +} + inline bool dComIfGs_isCollectCrystal(u8 i_item) { return g_dComIfG_gameInfo.info.getPlayer().getCollect().isCollectCrystal(i_item); } @@ -1721,6 +1767,10 @@ inline void dComIfGs_onCollectMirror(u8 i_item) { g_dComIfG_gameInfo.info.getPlayer().getCollect().onCollectMirror(i_item); } +inline void dComIfGs_offCollectMirror(u8 i_item) { + g_dComIfG_gameInfo.info.getPlayer().getCollect().offCollectMirror(i_item); +} + inline bool dComIfGs_isCollectMirror(u8 i_item) { return g_dComIfG_gameInfo.info.getPlayer().getCollect().isCollectMirror(i_item); } @@ -3518,7 +3568,7 @@ inline u8 dComIfGp_getItemLifeCountType() { return g_dComIfG_gameInfo.play.getItemLifeCountType(); } -inline void dComIfGp_setItemLifeCount(float amount, u8 type) { +inline void dComIfGp_setItemLifeCount(f32 amount, u8 type) { g_dComIfG_gameInfo.play.setItemLifeCount(amount, type); } @@ -3582,6 +3632,10 @@ inline void dComIfGp_setItemOilCount(s32 oil) { g_dComIfG_gameInfo.play.setItemOilCount(oil); } +inline void dComIfGp_setItemMaxOilCount(s32 oil) { + g_dComIfG_gameInfo.play.setItemMaxOilCount(oil); +} + inline void dComIfGp_clearItemOilCount() { g_dComIfG_gameInfo.play.clearItemOilCount(); } @@ -3638,6 +3692,10 @@ inline void dComIfGp_clearOxygenCount() { g_dComIfG_gameInfo.play.clearOxygenCount(); } +inline void dComIfGp_setMaxOxygenCount(s32 oxygen) { + g_dComIfG_gameInfo.play.setMaxOxygenCount(oxygen); +} + inline s32 dComIfGp_getMaxOxygenCount() { return g_dComIfG_gameInfo.play.getMaxOxygenCount(); } diff --git a/include/d/d_demo.h b/include/d/d_demo.h index 9b9d2325ac..e72698ed9a 100644 --- a/include/d/d_demo.h +++ b/include/d/d_demo.h @@ -340,27 +340,6 @@ public: virtual JPABaseEmitter* emitter_create(u32); }; -namespace { -class jstudio_tAdaptor_message : public JStudio::TAdaptor_message { -public: - typedef JStudio::TObject_message ObjectType; - - jstudio_tAdaptor_message() {} - - virtual ~jstudio_tAdaptor_message(); - virtual void adaptor_do_MESSAGE(JStudio::data::TEOperationData, const void*, u32); -}; - -class jstudio_tCreateObject_message : public JStudio::TCreateObject { -public: - jstudio_tCreateObject_message() {} - - virtual ~jstudio_tCreateObject_message(); - virtual bool create(JStudio::TObject**, const JStudio::stb::data::TParse_TBlock_object&); -}; - -}; // namespace - int dDemo_setDemoData(fopAc_ac_c*, u8, mDoExt_McaMorf*, char const*, int, u16*, u32, s8); class dDemo_c { @@ -409,7 +388,7 @@ public: static JStudio_JStage::TCreateObject* m_stage; static JStudio_JAudio2::TCreateObject* m_audio; static dDemo_particle_c* m_particle; - static jstudio_tCreateObject_message* m_message; + static JStudio::TCreateObject* m_message; static JStudio::TFactory* m_factory; static jmessage_tControl* m_mesgControl; static dDemo_object_c* m_object; diff --git a/include/d/d_jnt_col.h b/include/d/d_jnt_col.h index c239bf8a69..cc67b7104d 100644 --- a/include/d/d_jnt_col.h +++ b/include/d/d_jnt_col.h @@ -33,7 +33,7 @@ public: void offPassNum(int num) { field_0xc &= ~(1 << num); } bool checkShieldType(int i) { return getType(i) == 3; } - s8 getType(int i) { return mData[i].mType; } + int getType(int i) { return mData[i].mType; } int getJntNum(int i) { return (s16)mData[i].mJntNum; } /* 0x00 */ const dJntColData_c* mData; @@ -64,4 +64,9 @@ public: }; +#if DEBUG +void dJntCol_setDebugHIO(); +void dJntCol_deleteDebugHIO(); +#endif + #endif /* D_D_JNT_COL_H */ diff --git a/include/d/d_menu_window.h b/include/d/d_menu_window.h index 35c6789127..65e415077d 100644 --- a/include/d/d_menu_window.h +++ b/include/d/d_menu_window.h @@ -190,7 +190,7 @@ public: bool isPauseWindow() { return mPauseWindow != false; } void onShowFlag() { mShowFlag |= 1; } void offShowFlag() { mShowFlag &= ~1; } - bool isShowFlag() { return mShowFlag & 1 != 0; } + bool isShowFlag() { return (mShowFlag & 1) != 0; } bool isFadeNowCheck() { return mDoGph_gInf_c::getFader()->getStatus() == 1; } private: diff --git a/include/d/d_menu_window_HIO.h b/include/d/d_menu_window_HIO.h index 1df1b5cb72..b5d5c81fb4 100644 --- a/include/d/d_menu_window_HIO.h +++ b/include/d/d_menu_window_HIO.h @@ -1,75 +1,83 @@ #ifndef D_MENU_D_MENU_WINDOW_HIO_H #define D_MENU_D_MENU_WINDOW_HIO_H -#include +#include "JSystem/JHostIO/JORReflexible.h" -class dMw_DHIO_c { +class dMw_DHIO_c : public JORReflexible { public: dMw_DHIO_c(); virtual ~dMw_DHIO_c() {} + void genMessage(JORMContext*); + + void bitCheck(); /* 0x004 */ s8 field_0x4; - /* 0x005 */ bool mMap[32]; - /* 0x025 */ bool mCompass[32]; - /* 0x045 */ bool mBossKey[32]; - /* 0x065 */ bool mBossClear[32]; - /* 0x085 */ bool mHeartContainer[32]; - /* 0x0A5 */ bool mBossDemo[32]; - /* 0x0C5 */ bool mPortal[32]; - /* 0x0E5 */ bool mMidBossClear[32]; - /* 0x105 */ bool mMapCopy[32]; - /* 0x125 */ bool mCompassCopy[32]; - /* 0x145 */ bool mBossKeyCopy[32]; - /* 0x165 */ bool mBossClearCopy[32]; - /* 0x185 */ bool mHeartContainerCopy[32]; - /* 0x1A5 */ bool mBossDemoCopy[32]; - /* 0x1C5 */ bool mPortalCopy[32]; - /* 0x1E5 */ bool mMidBossClearCopy[32]; + /* 0x005 */ u8 mMap[32]; + /* 0x025 */ u8 mCompass[32]; + /* 0x045 */ u8 mBossKey[32]; + /* 0x065 */ u8 mBossClear[32]; + /* 0x085 */ u8 mHeartContainer[32]; + /* 0x0A5 */ u8 mBossDemo[32]; + /* 0x0C5 */ u8 mPortal[32]; + /* 0x0E5 */ u8 mMidBossClear[32]; + /* 0x105 */ u8 mMapCopy[32]; + /* 0x125 */ u8 mCompassCopy[32]; + /* 0x145 */ u8 mBossKeyCopy[32]; + /* 0x165 */ u8 mBossClearCopy[32]; + /* 0x185 */ u8 mHeartContainerCopy[32]; + /* 0x1A5 */ u8 mBossDemoCopy[32]; + /* 0x1C5 */ u8 mPortalCopy[32]; + /* 0x1E5 */ u8 mMidBossClearCopy[32]; }; extern dMw_DHIO_c g_mwDHIO; -class dMw_HIO_c { +class dMw_HIO_c : public JORReflexible { public: dMw_HIO_c(); void init(); - bool getBombFlag(); - bool getArrowFlag(); - bool getPachinkoFlag(); + u8 getBombFlag(); + u8 getArrowFlag(); + u8 getPachinkoFlag(); void update(); + void playerStatusHIO(); + void itemBitCheck(); + void itemNumHIO(); + void itemHIO(); void setArrowFlag(u8 i_flag) { mArrowFlag = i_flag; } void setPachinkoFlag(u8 i_flag) { mPachinkoFlag = i_flag; } void setBombFlag(u8 i_flag) { mBombFlag = i_flag; } virtual ~dMw_HIO_c() {} + void genMessage(JORMContext*); /* 0x004 */ s8 field_0x4; - /* 0x006 */ u16 mLife; - /* 0x008 */ u16 mMaxLife; + /* 0x006 */ s16 mLife; + /* 0x008 */ s16 mMaxLife; /* 0x00A */ u8 mMagic; /* 0x00B */ u8 mMaxMagic; /* 0x00C */ s32 mOil; /* 0x010 */ s32 mMaxOil; /* 0x014 */ s32 mOxygen; /* 0x018 */ s32 mMaxOxygen; - /* 0x01C */ bool mEnableMagic; - /* 0x01D */ bool mEnableArrowDrops; + /* 0x01C */ u8 mEnableMagic; + /* 0x01D */ u8 mEnableArrowDrops; /* 0x01E */ s16 mRupees; /* 0x020 */ s16 mWalletSize; /* 0x022 */ u8 mKeys; /* 0x023 */ u8 field_0x23; - /* 0x024 */ u16 mLifeCopy; - /* 0x026 */ u16 mMaxLifeCopy; + /* 0x024 */ s16 mLifeCopy; + /* 0x026 */ s16 mMaxLifeCopy; /* 0x028 */ u8 mMagicCopy; /* 0x029 */ u8 mMaxMagicCopy; /* 0x02C */ s32 mOilCopy; /* 0x030 */ s32 mMaxOilCopy; /* 0x034 */ s32 mOxygenCopy; /* 0x038 */ s32 mMaxOxygenCopy; - /* 0x03C */ bool mEnableMagicCopy; - /* 0x03D */ bool mEnableArrowDropsCopy; + /* 0x03C */ u8 mEnableMagicCopy; + /* 0x03D */ u8 mEnableArrowDropsCopy; /* 0x03E */ s16 mRupeesCopy; /* 0x040 */ s16 mWalletSizeCopy; /* 0x042 */ s16 mDonationAmount; @@ -81,23 +89,23 @@ public: /* 0x04A */ u8 mItems[24]; /* 0x062 */ u8 mItemsCopy[24]; /* 0x07A */ u8 field_0x7a[24]; - /* 0x092 */ bool mSwords[4]; - /* 0x096 */ bool mShields[3]; - /* 0x099 */ bool mClothes[3]; - /* 0x09C */ bool mSwordsCopy[4]; - /* 0x0A0 */ bool mShieldsCopy[3]; - /* 0x0A3 */ bool mClothesCopy[3]; + /* 0x092 */ u8 mSwords[4]; + /* 0x096 */ u8 mShields[3]; + /* 0x099 */ u8 mClothes[3]; + /* 0x09C */ u8 mSwordsCopy[4]; + /* 0x0A0 */ u8 mShieldsCopy[3]; + /* 0x0A3 */ u8 mClothesCopy[3]; /* 0x0A6 */ u8 mScent; /* 0x0A7 */ u8 mScentCopy; /* 0x0A8 */ u8 field_0xa8; - /* 0x0A9 */ bool mBombBagLV2; - /* 0x0AA */ bool mBombBagLV2Copy; - /* 0x0AB */ bool mLV2KeyShards[3]; - /* 0x0AE */ bool mLV2KeyShardsCopy[3]; - /* 0x0B1 */ bool mLV5Item[2]; - /* 0x0B3 */ bool mLV5ItemCopy[2]; - /* 0x0B5 */ bool mGoldBug[24]; - /* 0x0CD */ bool mGoldBugCopy[24]; + /* 0x0A9 */ u8 mBombBagLV2; + /* 0x0AA */ u8 mBombBagLV2Copy; + /* 0x0AB */ u8 mLV2KeyShards[3]; + /* 0x0AE */ u8 mLV2KeyShardsCopy[3]; + /* 0x0B1 */ u8 mLV5Item[2]; + /* 0x0B3 */ u8 mLV5ItemCopy[2]; + /* 0x0B5 */ u8 mGoldBug[24]; + /* 0x0CD */ u8 mGoldBugCopy[24]; /* 0x0E5 */ u8 mArrowNum; /* 0x0E6 */ u8 mSeedNum; /* 0x0E7 */ u8 mBombNum[3]; @@ -112,15 +120,15 @@ public: /* 0x101 */ u8 field_0x101[8]; /* 0x109 */ u8 field_0x109[8]; /* 0x111 */ u8 field_0x111[8]; - /* 0x119 */ bool mEnableOxygenMeter; - /* 0x11A */ bool mEnableOxygenMeterCopy; + /* 0x119 */ u8 mEnableOxygenMeter; + /* 0x11A */ u8 mEnableOxygenMeterCopy; /* 0x11B */ u8 mArrowFlag; /* 0x11C */ u8 mPachinkoFlag; /* 0x11D */ u8 mBombFlag; - /* 0x11E */ bool mFusedShadow[4]; - /* 0x122 */ bool mFusedShadowCopy[4]; - /* 0x126 */ bool mMirrorShard[4]; - /* 0x12A */ bool mMirrorShardCopy[4]; + /* 0x11E */ u8 mFusedShadow[4]; + /* 0x122 */ u8 mFusedShadowCopy[4]; + /* 0x126 */ u8 mMirrorShard[4]; + /* 0x12A */ u8 mMirrorShardCopy[4]; }; // Size: 0x130 extern dMw_HIO_c g_mwHIO; diff --git a/include/d/d_msg_object.h b/include/d/d_msg_object.h index 2ef3f0ad69..45606e4e81 100644 --- a/include/d/d_msg_object.h +++ b/include/d/d_msg_object.h @@ -557,6 +557,11 @@ inline bool dMsgObject_isSelectTalkNowCheck() { return dMsgObject_getMsgObjectClass()->getStatus() != 8 || (dMsgObject_getMsgObjectClass()->getStatus() != 9 && dMsgObject_getMsgObjectClass()->getStatus() != 20); } +inline void dMsgObject_setOffering(u16 i_num) { + dComIfGs_setEventReg(0xF7FF, i_num >> 8); + dComIfGs_setEventReg(0xF8FF, i_num & 0xFF); +} + class dMsgObject_HowlHIO_c { public: dMsgObject_HowlHIO_c(); diff --git a/include/d/d_msg_scrn_howl.h b/include/d/d_msg_scrn_howl.h index aa51249e17..bf28682d42 100644 --- a/include/d/d_msg_scrn_howl.h +++ b/include/d/d_msg_scrn_howl.h @@ -112,7 +112,4 @@ struct dMsgScrnHowl_c : public dMsgScrnBase_c { /* 0x27A8 */ f32 field_0x27a8; }; -#define LINE_MAX 30 -#define PLOT_BUFFER_MAX_e 0x300 - #endif /* MSG_SCRN_D_MSG_SCRN_HOWL_H */ diff --git a/include/d/d_save.h b/include/d/d_save.h index 4b21e6673e..4511bc47e8 100644 --- a/include/d/d_save.h +++ b/include/d/d_save.h @@ -219,13 +219,21 @@ public: void init(); void set(const char* i_name, const cXyz& i_pos, s16 i_angle, s8 i_roomNo); +#if TARGET_PC + cXyz getPos() { return cXyz(mPos); } +#else cXyz& getPos() { return mPos; } +#endif s16 getAngleY() const { return mAngleY; } const char* getStageName() const { return mName; } s8 getRoomNo() const { return mRoomNo; } private: +#if TARGET_PC + /* 0x00 */ BE(Vec) mPos; +#else /* 0x00 */ cXyz mPos; +#endif /* 0x0C */ BE(s16) mAngleY; /* 0x0E */ char mName[8]; /* 0x16 */ u8 mSpawnId; @@ -257,7 +265,11 @@ public: void onRegionBit(int i_region); void set(const char* i_name, const cXyz& i_pos, s16 i_angle, s8 i_spawn, u8 i_regionNo); +#if TARGET_PC + cXyz getPos() { return cXyz(mPos); } +#else cXyz& getPos() { return mPos; } +#endif s16 getAngleY() { return mAngleY; } char* getName() { return mName; } u8 getRegionNo() const { return mRegionNo; } @@ -267,7 +279,11 @@ public: private: +#if TARGET_PC + /* 0x00 */ BE(Vec) mPos; +#else /* 0x00 */ cXyz mPos; +#endif /* 0x0C */ BE(s16) mAngleY; /* 0x0E */ char mName[8]; /* 0x16 */ s8 mLastSpawnId; @@ -284,7 +300,11 @@ public: void init(); void setWarpItemData(const char* i_name, const cXyz& i_pos, s16 i_angle, s8 i_roomNo, u8, u8); +#if TARGET_PC + cXyz getPos() { return cXyz(mPos); } +#else cXyz& getPos() { return mPos; } +#endif s16 getAngleY() const { return mAngleY; } const char* getName() { return mName; } s8 getRoomNo() const { return mRoomNo; } @@ -293,7 +313,11 @@ public: void resetWarpAcceptStage() { mWarpAcceptStage = -1; } private: +#if TARGET_PC + /* 0x00 */ BE(Vec) mPos; +#else /* 0x00 */ cXyz mPos; +#endif /* 0x0C */ BE(s16) mAngleY; /* 0x0E */ char mName[8]; /* 0x16 */ u8 mSpawnId; @@ -396,12 +420,14 @@ public: void offCollectMirror(u8 i_item); BOOL isCollectMirror(u8 i_item) const; + void setPohNum(u8 i_num) { mPohNum = i_num; } u8 getPohNum() const { return mPohNum; } + void addPohNum() { if (mPohNum < 0xFF) { mPohNum++; } - }; + } private: /* 0x0 */ u8 mItem[8]; diff --git a/include/f_op/f_op_actor_mng.h b/include/f_op/f_op_actor_mng.h index 2251a23aea..5b11f0e57a 100644 --- a/include/f_op/f_op_actor_mng.h +++ b/include/f_op/f_op_actor_mng.h @@ -437,11 +437,11 @@ inline void fopAcM_SetAngle(fopAc_ac_c* i_actor, s16 x, s16 y, s16 z) { i_actor->current.angle.set(x, y, z); } -inline void dComIfGs_onSwitch(int i_no, int i_roomNo); -inline void dComIfGs_offSwitch(int i_no, int i_roomNo); -inline void dComIfGs_revSwitch(int i_no, int i_roomNo); -inline BOOL dComIfGs_isSwitch(int i_no, int i_roomNo); -inline void dComIfGs_offActor(int i_no, int i_roomNo); +void dComIfGs_onSwitch(int i_no, int i_roomNo); +void dComIfGs_offSwitch(int i_no, int i_roomNo); +void dComIfGs_revSwitch(int i_no, int i_roomNo); +BOOL dComIfGs_isSwitch(int i_no, int i_roomNo); +void dComIfGs_offActor(int i_no, int i_roomNo); inline void fopAcM_onSwitch(const fopAc_ac_c* i_actor, int sw) { return dComIfGs_onSwitch(sw, fopAcM_GetHomeRoomNo(i_actor)); @@ -463,12 +463,12 @@ inline fopAc_ac_c* fopAcM_SearchByName(s16 proc_id) { return (fopAc_ac_c*)fopAcIt_Judge(fpcSch_JudgeForPName, &proc_id); } -inline void dComIfGs_onItem(int bitNo, int roomNo); +void dComIfGs_onItem(int bitNo, int roomNo); inline void fopAcM_onItem(const fopAc_ac_c* item, int bitNo) { dComIfGs_onItem(bitNo, fopAcM_GetHomeRoomNo(item)); } -inline bool dComIfGs_isItem(int bitNo, int roomNo); +bool dComIfGs_isItem(int bitNo, int roomNo); inline bool fopAcM_isItem(const fopAc_ac_c* item, int bitNo) { return dComIfGs_isItem(bitNo, fopAcM_GetHomeRoomNo(item)); } @@ -481,7 +481,7 @@ inline int fopAcM_GetSetId(const fopAc_ac_c* i_actor) { return i_actor->setID; } -inline void dComIfGs_onActor(int bitNo, int roomNo); +void dComIfGs_onActor(int bitNo, int roomNo); inline void fopAcM_onActor(const fopAc_ac_c* i_actor) { dComIfGs_onActor(fopAcM_GetSetId(i_actor), fopAcM_GetHomeRoomNo(i_actor)); @@ -716,7 +716,7 @@ inline void make_prm_warp_hole(u32* o_params, u8 prm1, u8 prm2, u8 prm3) { *o_params = pprm2 | pprm3 | pprm1; } -inline fopAc_ac_c* dComIfGp_getPlayer(int); +fopAc_ac_c* dComIfGp_getPlayer(int); inline s16 fopAcM_searchPlayerAngleY(const fopAc_ac_c* actor) { return fopAcM_searchActorAngleY(actor, dComIfGp_getPlayer(0)); diff --git a/include/global.h b/include/global.h index 36fb40dfb1..df3723bd57 100644 --- a/include/global.h +++ b/include/global.h @@ -133,7 +133,7 @@ static const float INF = 2000000000.0f; #define NO_INLINE #endif #endif - + // Hack to trick the compiler into not inlining functions that use this macro. #define FORCE_DONT_INLINE \ (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \ @@ -203,6 +203,17 @@ static const float INF = 2000000000.0f; using std::isnan; #endif +// Comparing a non-volatile reference type to NULL is tautological +// and triggers a warning on modern compilers, but in some cases is +// required to match the original assembly. +#if defined(__MWERKS__) || defined(DECOMPCTX) +#define IS_REF_NULL(r) (&(r) == NULL) +#define IS_REF_NONNULL(r) (&(r) != NULL) +#else +#define IS_REF_NULL(r) (0) +#define IS_REF_NONNULL(r) (1) +#endif + #define CRASH(msg, ...) OSPanic(__FILE__, __LINE__, msg, __VA_ARGS__) #endif diff --git a/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DAnimation.h b/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DAnimation.h index 84b27ea969..3c5133e880 100644 --- a/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DAnimation.h +++ b/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DAnimation.h @@ -650,13 +650,13 @@ public: */ class J3DAnmCluster : public J3DAnmBase { public: - J3DAnmCluster(s16 frameMax, f32* pWeight) : J3DAnmBase(frameMax) { mWeight = pWeight; } + J3DAnmCluster(s16 frameMax, BE(f32)* pWeight) : J3DAnmBase(frameMax) { mWeight = pWeight; } virtual ~J3DAnmCluster() {} virtual s32 getKind() const { return 3; } virtual f32 getWeight(u16) const { return 1.0f; } - /* 0x0C */ f32* mWeight; + /* 0x0C */ BE(f32)* mWeight; }; // Size: 0x10 /** diff --git a/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DCluster.h b/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DCluster.h index 4680cd1fff..2a71ada3dd 100644 --- a/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DCluster.h +++ b/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DCluster.h @@ -108,8 +108,8 @@ public: J3D_ASSERT_RANGE(199, (i < mClusterKeyNum)); return &mClusterKeyPointer[i]; } - f32* getVtxPos() { return mVtxPos; } - f32* getVtxNrm() { return mVtxNrm; } + BE(f32)* getVtxPos() { return mVtxPos; } + BE(f32)* getVtxNrm() { return mVtxNrm; } /* 0x00 */ u16 mClusterNum; /* 0x02 */ u16 mClusterKeyNum; @@ -119,8 +119,8 @@ public: /* 0x10 */ J3DClusterVertex* mClusterVertex; /* 0x14 */ u16 mVtxPosNum; /* 0x16 */ u16 mVtxNrmNum; - /* 0x18 */ f32* mVtxPos; - /* 0x1C */ f32* mVtxNrm; + /* 0x18 */ BE(f32)* mVtxPos; + /* 0x1C */ BE(f32)* mVtxNrm; /* 0x20 */ JUTNameTab* mClusterName; /* 0x24 */ JUTNameTab* mClusterKeyName; diff --git a/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h b/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h index ff41bc4f01..4c3f0f75bb 100644 --- a/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h +++ b/libs/JSystem/include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h @@ -3,6 +3,8 @@ #include "JSystem/J3DGraphAnimator/J3DAnimation.h" +class J3DMaterial; + /** * @ingroup jsystem-j3d * diff --git a/libs/JSystem/include/JSystem/J3DGraphBase/J3DMatBlock.h b/libs/JSystem/include/JSystem/J3DGraphBase/J3DMatBlock.h index 402c5040b8..a959609f45 100644 --- a/libs/JSystem/include/JSystem/J3DGraphBase/J3DMatBlock.h +++ b/libs/JSystem/include/JSystem/J3DGraphBase/J3DMatBlock.h @@ -116,7 +116,13 @@ public: // same logic but without the bug. // See J3DMaterialFactory::newColorChan - both the bugged and correct behavior are present there, as it calls // both constructors. +#if TARGET_PC + // The faulty comparison is EXTREMELY noisy in the build due to warnings being emitted for + // every TU that includes it - best to just remove it since it doesn't do anything anyway. + u32 ambSrc = info.mAmbSrc; +#else u32 ambSrc = info.mAmbSrc == 0xFFFF ? 0 : info.mAmbSrc; +#endif mColorChanID = calcColorChanID(info.mEnable, info.mMatSrc, info.mLightMask, info.mDiffuseFn, info.mAttnFn, ambSrc); } diff --git a/libs/JSystem/include/JSystem/JHostIO/JOREntry.h b/libs/JSystem/include/JSystem/JHostIO/JOREntry.h index 197b6f9998..55bcaeabd6 100644 --- a/libs/JSystem/include/JSystem/JHostIO/JOREntry.h +++ b/libs/JSystem/include/JSystem/JHostIO/JOREntry.h @@ -99,7 +99,12 @@ public: static JHIComPortManager* getInstance() { return instance; } +#ifdef __MWERKS__ static JHIComPortManager* instance; +#else + // C++17 allows in-class instantiation + static inline JHIComPortManager* instance = nullptr; +#endif /* 0x00000 */ T port; /* 0x0000C */ JHIpvector*, 10> field_0xc; diff --git a/libs/JSystem/src/J3DGraphAnimator/J3DCluster.cpp b/libs/JSystem/src/J3DGraphAnimator/J3DCluster.cpp index 8144ea04a5..77dc45365b 100644 --- a/libs/JSystem/src/J3DGraphAnimator/J3DCluster.cpp +++ b/libs/JSystem/src/J3DGraphAnimator/J3DCluster.cpp @@ -104,8 +104,8 @@ void J3DDeformer::deform_VtxPosF32(J3DVertexBuffer* i_buffer, J3DCluster* i_clus int posNum = i_cluster->mPosNum; int keyNum = i_cluster->mKeyNum; f32* vtxPosArray = (f32*)i_buffer->getVtxPosArrayPointer(0); - f32* deformVtxPos = mDeformData->getVtxPos(); - u16* iVar9 = CALC_OFFSET(i_cluster->field_0x18, u16, mBlockBase); + BE(f32)* deformVtxPos = mDeformData->getVtxPos(); + BE(u16)* iVar9 = CALC_OFFSET(i_cluster->field_0x18, BE(u16), mBlockBase); for (int i = 0; i < posNum; i++) { int index = iVar9[i] * 3; @@ -117,12 +117,12 @@ void J3DDeformer::deform_VtxPosF32(J3DVertexBuffer* i_buffer, J3DCluster* i_clus f32 local_58[2] = {1.0f, -1.0f}; for (u16 i = 0; i < posNum; i++) { - int index = CALC_OFFSET(i_cluster->field_0x18, u16, mBlockBase)[i] * 3; + int index = CALC_OFFSET(i_cluster->field_0x18, BE(u16), mBlockBase)[i] * 3; for (u16 j = 0; j < keyNum; j++) { int uVar8; int uVar7; key = &i_key[j]; - uVar8 = uVar7 = CALC_OFFSET(key->field_0x4, u16, mBlockBase)[i]; + uVar8 = uVar7 = CALC_OFFSET(key->field_0x4, BE(u16), mBlockBase)[i]; uVar7 &= ~0xE000; uVar7 *= 3; f32 deform0 = deformVtxPos[uVar7]; @@ -142,7 +142,7 @@ void J3DDeformer::deform_VtxPosF32(J3DVertexBuffer* i_buffer, J3DCluster* i_clus void J3DDeformer::deform_VtxNrmF32(J3DVertexBuffer* i_buffer, J3DCluster* i_cluster, J3DClusterKey* i_key, f32* i_weights) { f32* vtxNrmArray = (f32*)i_buffer->getVtxNrmArrayPointer(0); - f32* deformVtxNrm = mDeformData->getVtxNrm(); + BE(f32)* deformVtxNrm = mDeformData->getVtxNrm(); f32* iVar13 = field_0xc; u16 keyNum = i_cluster->mKeyNum; int uVar2 = i_cluster->field_0x16; @@ -154,7 +154,7 @@ void J3DDeformer::deform_VtxNrmF32(J3DVertexBuffer* i_buffer, J3DCluster* i_clus iVar13[index + 2] = 0.0f; for (u16 j = 0; j < keyNum; j++) { J3DClusterKey* key = &i_key[j]; - int uVar3 = CALC_OFFSET(key->field_0x8, u16, mBlockBase)[i]; + int uVar3 = CALC_OFFSET(key->field_0x8, BE(u16), mBlockBase)[i]; int uVar4 = uVar3; uVar3 &= ~0xE000; uVar3 *= 3; @@ -189,7 +189,7 @@ void J3DDeformer::deform_VtxNrmF32(J3DVertexBuffer* i_buffer, J3DCluster* i_clus vec.z = 0.0f; f32 scale = 1.0f / clusterVtx->mNum; for (u16 j = 0; j < clusterVtx->mNum; j++) { - int index = CALC_OFFSET(clusterVtx->field_0x4, u16, mBlockBase)[j] * 3; + int index = CALC_OFFSET(clusterVtx->field_0x4, BE(u16), mBlockBase)[j] * 3; vec.x += scale * iVar13[index]; vec.y += scale * iVar13[index + 1]; vec.z += scale * iVar13[index + 2]; @@ -197,12 +197,12 @@ void J3DDeformer::deform_VtxNrmF32(J3DVertexBuffer* i_buffer, J3DCluster* i_clus normalize((f32*)&vec); for (u16 j = 0; j < clusterVtx->mNum; j++) { - u16 tmp = CALC_OFFSET(clusterVtx->field_0x8, u16, mBlockBase)[j]; + u16 tmp = CALC_OFFSET(clusterVtx->field_0x8, BE(u16), mBlockBase)[j]; if (tmp == 0xffff) { continue; } int index = tmp * 3; - u16 iVar4 = CALC_OFFSET(clusterVtx->field_0x4, u16, mBlockBase)[j]; + u16 iVar4 = CALC_OFFSET(clusterVtx->field_0x4, BE(u16), mBlockBase)[j]; int index2 = iVar4 * 3; f32 dot = vec.x * iVar13[index2] + vec.y * iVar13[index2 + 1] diff --git a/libs/JSystem/src/J3DGraphLoader/J3DAnmLoader.cpp b/libs/JSystem/src/J3DGraphLoader/J3DAnmLoader.cpp index 0e9820a8a9..e4456750eb 100644 --- a/libs/JSystem/src/J3DGraphLoader/J3DAnmLoader.cpp +++ b/libs/JSystem/src/J3DGraphLoader/J3DAnmLoader.cpp @@ -354,7 +354,7 @@ void J3DAnmFullLoader_v15::setAnmCluster(J3DAnmClusterFull* param_1, param_1->mFrame = 0.0f; param_1->mAnmTable = JSUConvertOffsetToPtr(param_2, param_2->mTableOffset); - param_1->mWeight = JSUConvertOffsetToPtr(param_2, param_2->mWeightOffset); + param_1->mWeight = JSUConvertOffsetToPtr(param_2, param_2->mWeightOffset); } void J3DAnmFullLoader_v15::readAnmVtxColor(const J3DAnmVtxColorFullData* param_1) { @@ -618,7 +618,7 @@ void J3DAnmKeyLoader_v15::setAnmCluster(J3DAnmClusterKey* param_1, param_1->mFrame = 0.0f; param_1->mAnmTable = JSUConvertOffsetToPtr(param_2, param_2->mTableOffset); - param_1->mWeight = JSUConvertOffsetToPtr(param_2, param_2->mWeightOffset); + param_1->mWeight = JSUConvertOffsetToPtr(param_2, param_2->mWeightOffset); } diff --git a/libs/JSystem/src/J3DGraphLoader/J3DClusterLoader.cpp b/libs/JSystem/src/J3DGraphLoader/J3DClusterLoader.cpp index 6d54a14d06..45dbcc9155 100644 --- a/libs/JSystem/src/J3DGraphLoader/J3DClusterLoader.cpp +++ b/libs/JSystem/src/J3DGraphLoader/J3DClusterLoader.cpp @@ -56,21 +56,21 @@ void J3DClusterLoader_v15::readCluster(const J3DClusterBlock* block) { mpDeformData->mVtxNrmNum = block->mVtxNrmNum; mpDeformData->mClusterVertexNum = block->mClusterVertexNum; - if (block->mClusterName != NULL) { + if ((uintptr_t)block->mClusterName != (uintptr_t)NULL) { mpDeformData->mClusterName = JKR_NEW JUTNameTab(JSUConvertOffsetToPtr(block, block->mClusterName)); } else { mpDeformData->mClusterName = NULL; } - if (block->mClusterKeyName != NULL) { + if ((uintptr_t)block->mClusterKeyName != (uintptr_t)NULL) { mpDeformData->mClusterKeyName = JKR_NEW JUTNameTab(JSUConvertOffsetToPtr(block, block->mClusterKeyName)); } else { mpDeformData->mClusterKeyName = NULL; } - mpDeformData->mVtxPos = JSUConvertOffsetToPtr(block, block->mVtxPos); - mpDeformData->mVtxNrm = JSUConvertOffsetToPtr(block, block->mVtxNrm); + mpDeformData->mVtxPos = JSUConvertOffsetToPtr(block, block->mVtxPos); + mpDeformData->mVtxNrm = JSUConvertOffsetToPtr(block, block->mVtxNrm); intptr_t clusterPointer = (intptr_t) block->mClusterPointer; int clusterKeyPointerSize = (intptr_t)block->mClusterKeyPointer - (intptr_t)block->mClusterPointer; diff --git a/libs/JSystem/src/J3DGraphLoader/J3DMaterialFactory.cpp b/libs/JSystem/src/J3DGraphLoader/J3DMaterialFactory.cpp index f7f9d92338..4383632da7 100644 --- a/libs/JSystem/src/J3DGraphLoader/J3DMaterialFactory.cpp +++ b/libs/JSystem/src/J3DGraphLoader/J3DMaterialFactory.cpp @@ -14,7 +14,7 @@ J3DMaterialFactory::J3DMaterialFactory(J3DMaterialBlock const& i_block) { mMaterialNum = i_block.mMaterialNum; mpMaterialInitData = JSUConvertOffsetToPtr(&i_block, i_block.mpMaterialInitData); mpMaterialID = JSUConvertOffsetToPtr(&i_block, i_block.mpMaterialID); - if (i_block.mpIndInitData != NULL && (uintptr_t)i_block.mpIndInitData - (uintptr_t)i_block.mpNameTable > 4) { + if (i_block.mpIndInitData != (uintptr_t)NULL && (uintptr_t)i_block.mpIndInitData - (uintptr_t)i_block.mpNameTable > 4) { mpIndInitData = JSUConvertOffsetToPtr(&i_block, i_block.mpIndInitData); } else { mpIndInitData = NULL; diff --git a/libs/JSystem/src/J3DGraphLoader/J3DModelLoader.cpp b/libs/JSystem/src/J3DGraphLoader/J3DModelLoader.cpp index b59a245c08..b8e412415d 100644 --- a/libs/JSystem/src/J3DGraphLoader/J3DModelLoader.cpp +++ b/libs/JSystem/src/J3DGraphLoader/J3DModelLoader.cpp @@ -399,13 +399,13 @@ void J3DModelLoader::readVertex(J3DVertexBlock const* i_block) { if (vertex_data.mVtxTexCoordArray[0] == NULL) { vertex_data.mTexCoordNum = 0; - return; - } - if (local_28) { - vertex_data.mTexCoordNum = (local_28 - (uintptr_t)vertex_data.mVtxTexCoordArray[0]) / 8 + 1; } else { - vertex_data.mTexCoordNum = - (i_block->mBlockSize - (uintptr_t)i_block->mpVtxTexCoordArray[0]) / 8 + 1; + if (local_28) { + vertex_data.mTexCoordNum = (local_28 - (uintptr_t)vertex_data.mVtxTexCoordArray[0]) / 8 + 1; + } else { + vertex_data.mTexCoordNum = + (i_block->mBlockSize - (uintptr_t)i_block->mpVtxTexCoordArray[0]) / 8 + 1; + } } #if TARGET_PC @@ -603,7 +603,7 @@ void J3DModelLoader::readJoint(J3DJointBlock const* i_block) { J3D_ASSERT_NULLPTR(781, i_block); J3DJointFactory factory(*i_block); mpModelData->getJointTree().mJointNum = i_block->mJointNum; - if (i_block->mpNameTable != NULL) { + if (i_block->mpNameTable != (uintptr_t)NULL) { mpModelData->getJointTree().mJointName = JKR_NEW JUTNameTab(JSUConvertOffsetToPtr(i_block, i_block->mpNameTable)); J3D_ASSERT_ALLOCMEM(791, mpModelData->getJointTree().mJointName); @@ -623,7 +623,7 @@ void J3DModelLoader_v26::readMaterial(J3DMaterialBlock const* i_block, u32 i_fla J3DMaterialFactory factory(*i_block); mpMaterialTable->mMaterialNum = i_block->mMaterialNum; mpMaterialTable->mUniqueMatNum = factory.countUniqueMaterials(); - if (i_block->mpNameTable != NULL) { + if (i_block->mpNameTable != (uintptr_t)NULL) { mpMaterialTable->mMaterialName = JKR_NEW JUTNameTab(JSUConvertOffsetToPtr(i_block, i_block->mpNameTable)); J3D_ASSERT_ALLOCMEM(832, mpMaterialTable->mMaterialName); @@ -669,7 +669,7 @@ void J3DModelLoader_v21::readMaterial_v21(J3DMaterialBlock_v21 const* i_block, u J3DMaterialFactory_v21 factory(*i_block); mpMaterialTable->mMaterialNum = i_block->mMaterialNum; mpMaterialTable->mUniqueMatNum = factory.countUniqueMaterials(); - if (i_block->mpNameTable != NULL) { + if (i_block->mpNameTable != (uintptr_t)NULL) { mpMaterialTable->mMaterialName = JKR_NEW JUTNameTab(JSUConvertOffsetToPtr(i_block, i_block->mpNameTable)); J3D_ASSERT_ALLOCMEM(930, mpMaterialTable->mMaterialName); @@ -713,7 +713,7 @@ void J3DModelLoader::readShape(J3DShapeBlock const* i_block, u32 i_flags) { J3DShapeTable* shape_table = mpModelData->getShapeTable(); J3DShapeFactory factory(*i_block); shape_table->mShapeNum = i_block->mShapeNum; - if (i_block->mpNameTable != NULL) { + if (i_block->mpNameTable != (uintptr_t)NULL) { shape_table->mShapeName = JKR_NEW JUTNameTab(JSUConvertOffsetToPtr(i_block, i_block->mpNameTable)); J3D_ASSERT_ALLOCMEM(1026, shape_table->mShapeName); @@ -738,7 +738,7 @@ void J3DModelLoader::readTexture(J3DTextureBlock const* i_block) { J3D_ASSERT_NULLPTR(1067, i_block); u16 texture_num = i_block->mTextureNum; ResTIMG* texture_res = JSUConvertOffsetToPtr(i_block, i_block->mpTextureRes); - if (i_block->mpNameTable != NULL) { + if (i_block->mpNameTable != (uintptr_t)NULL) { mpMaterialTable->mTextureName = JKR_NEW JUTNameTab(JSUConvertOffsetToPtr(i_block, i_block->mpNameTable)); J3D_ASSERT_ALLOCMEM(1077, mpMaterialTable->mTextureName); @@ -753,7 +753,7 @@ void J3DModelLoader_v26::readMaterialTable(J3DMaterialBlock const* i_block, u32 J3D_ASSERT_NULLPTR(1101, i_block); J3DMaterialFactory factory(*i_block); mpMaterialTable->mMaterialNum = i_block->mMaterialNum; - if (i_block->mpNameTable != NULL) { + if (i_block->mpNameTable != (uintptr_t)NULL) { mpMaterialTable->mMaterialName = JKR_NEW JUTNameTab(JSUConvertOffsetToPtr(i_block, i_block->mpNameTable)); J3D_ASSERT_ALLOCMEM(1114, mpMaterialTable->mMaterialName); @@ -776,7 +776,7 @@ void J3DModelLoader_v21::readMaterialTable_v21(J3DMaterialBlock_v21 const* i_blo J3D_ASSERT_NULLPTR(1152, i_block); J3DMaterialFactory_v21 factory(*i_block); mpMaterialTable->mMaterialNum = i_block->mMaterialNum; - if (i_block->mpNameTable != NULL) { + if (i_block->mpNameTable != (uintptr_t)NULL) { mpMaterialTable->mMaterialName = JKR_NEW JUTNameTab(JSUConvertOffsetToPtr(i_block, i_block->mpNameTable)); J3D_ASSERT_ALLOCMEM(1165, mpMaterialTable->mMaterialName); @@ -799,7 +799,7 @@ void J3DModelLoader::readTextureTable(J3DTextureBlock const* i_block) { J3D_ASSERT_NULLPTR(1200, i_block); u16 texture_num = i_block->mTextureNum; ResTIMG* texture_res = JSUConvertOffsetToPtr(i_block, i_block->mpTextureRes); - if (i_block->mpNameTable != NULL) { + if (i_block->mpNameTable != (uintptr_t)NULL) { mpMaterialTable->mTextureName = JKR_NEW JUTNameTab(JSUConvertOffsetToPtr(i_block, i_block->mpNameTable)); J3D_ASSERT_ALLOCMEM(1211, mpMaterialTable->mTextureName); @@ -815,7 +815,7 @@ void J3DModelLoader::readPatchedMaterial(J3DMaterialBlock const* i_block, u32 i_ J3DMaterialFactory factory(*i_block); mpMaterialTable->mMaterialNum = i_block->mMaterialNum; mpMaterialTable->mUniqueMatNum = factory.countUniqueMaterials(); - if (i_block->mpNameTable != NULL) { + if (i_block->mpNameTable != (uintptr_t)NULL) { mpMaterialTable->mMaterialName = JKR_NEW JUTNameTab(JSUConvertOffsetToPtr(i_block, i_block->mpNameTable)); J3D_ASSERT_ALLOCMEM(1251, mpMaterialTable->mMaterialName); @@ -841,7 +841,7 @@ void J3DModelLoader::readMaterialDL(J3DMaterialDLBlock const* i_block, u32 i_fla mpMaterialTable->field_0x1c = 1; mpMaterialTable->mMaterialNum = i_block->mMaterialNum; mpMaterialTable->mUniqueMatNum = i_block->mMaterialNum; - if (i_block->mpNameTable != NULL) { + if (i_block->mpNameTable != (uintptr_t)NULL) { mpMaterialTable->mMaterialName = JKR_NEW JUTNameTab(JSUConvertOffsetToPtr(i_block, i_block->mpNameTable)); J3D_ASSERT_ALLOCMEM(1312, mpMaterialTable->mMaterialName); diff --git a/libs/JSystem/src/J3DGraphLoader/J3DModelLoaderCalcSize.cpp b/libs/JSystem/src/J3DGraphLoader/J3DModelLoaderCalcSize.cpp index e332b491fc..6f4a86aa83 100644 --- a/libs/JSystem/src/J3DGraphLoader/J3DModelLoaderCalcSize.cpp +++ b/libs/JSystem/src/J3DGraphLoader/J3DModelLoaderCalcSize.cpp @@ -222,7 +222,7 @@ u32 J3DModelLoader_v26::calcSizeMaterial(const J3DMaterialBlock* block, u32 flag J3DMaterialFactory factory(*block); u32 count = block->mMaterialNum; int uniqueCount = factory.countUniqueMaterials(); - if (block->mpNameTable != NULL) { + if (block->mpNameTable != (uintptr_t)NULL) { size += 0x10; } size += (count * sizeof(J3DMaterial*)); diff --git a/libs/JSystem/src/JAudio2/JASAramStream.cpp b/libs/JSystem/src/JAudio2/JASAramStream.cpp index 56e3e6effd..64ddfc467e 100644 --- a/libs/JSystem/src/JAudio2/JASAramStream.cpp +++ b/libs/JSystem/src/JAudio2/JASAramStream.cpp @@ -472,7 +472,7 @@ void JASAramStream::updateChannel(u32 i_callbackType, JASChannel* i_channel, mChannelUpdateFlags |= CHANNEL_UPDATE_LOOP_START; #if !TARGET_PC // The variable assigned here is never used. if (field_0x0c4 < 0xffffffff) { - field_0x0c4++; + field_0x0c4 += 1; } #endif mEndSetup = false; diff --git a/libs/JSystem/src/JAudio2/JASAudioThread.cpp b/libs/JSystem/src/JAudio2/JASAudioThread.cpp index 943a3e5cfe..baa3d8b42e 100644 --- a/libs/JSystem/src/JAudio2/JASAudioThread.cpp +++ b/libs/JSystem/src/JAudio2/JASAudioThread.cpp @@ -96,7 +96,7 @@ void* JASAudioThread::run() { case AUDIOMSG_DSP: JUT_ASSERT(125, snIntCount != 0); - snIntCount--; + snIntCount -= 1; if (snIntCount == 0) { JASProbe::stop(7); JASDriver::finishDSPFrame(); diff --git a/libs/JSystem/src/JAudio2/JASBasicBank.cpp b/libs/JSystem/src/JAudio2/JASBasicBank.cpp index e7304d4d32..936c7829e8 100644 --- a/libs/JSystem/src/JAudio2/JASBasicBank.cpp +++ b/libs/JSystem/src/JAudio2/JASBasicBank.cpp @@ -21,7 +21,7 @@ bool JASBasicBank::getInstParam(int prg_no, int param_1, int param_2, JASInstParam* o_param) const { JASInst* inst = getInst(prg_no); if (inst == NULL) { - return NULL; + return false; } return inst->getParam(param_1, param_2, o_param); } diff --git a/libs/JSystem/src/JAudio2/JASCalc.cpp b/libs/JSystem/src/JAudio2/JASCalc.cpp index 9ac209c96b..906fee2c3d 100644 --- a/libs/JSystem/src/JAudio2/JASCalc.cpp +++ b/libs/JSystem/src/JAudio2/JASCalc.cpp @@ -5,7 +5,7 @@ #include void JASCalc::imixcopy(const s16* s1, const s16* s2, s16* dst, u32 n) { - for (n; n != 0; n--) { + for (; n != 0; n--) { *dst++ = *(s1)++; *dst++ = *(s2)++; } diff --git a/libs/JSystem/src/JAudio2/JASSeqParser.cpp b/libs/JSystem/src/JAudio2/JASSeqParser.cpp index 05e63acc05..7b417f2c82 100644 --- a/libs/JSystem/src/JAudio2/JASSeqParser.cpp +++ b/libs/JSystem/src/JAudio2/JASSeqParser.cpp @@ -295,7 +295,7 @@ u32 JASSeqParser::readReg(JASTrack* param_0, u32 param_1) const { case 0x6a: result = param_0->getReleasePrio(); // @bug this should have been <<= - result << 8; + (void)(result << 8); result |= param_0->getNoteOnPrio(); break; case 0x6b: diff --git a/libs/JSystem/src/JAudio2/JAUSoundTable.cpp b/libs/JSystem/src/JAudio2/JAUSoundTable.cpp index b398d8c1c0..cab2e45a3c 100644 --- a/libs/JSystem/src/JAudio2/JAUSoundTable.cpp +++ b/libs/JSystem/src/JAudio2/JAUSoundTable.cpp @@ -15,6 +15,11 @@ void JAUSoundTable::init(void const* param_0) { } u8 JAUSoundTable::getTypeID(JAISoundID param_0) const { +#if DUSK_AUDIO_DISABLED + if (this == NULL) { + return 0xff; + } +#endif if (param_0.isAnonymous()) { return 0xff; } @@ -30,6 +35,11 @@ u8 JAUSoundTable::getTypeID(JAISoundID param_0) const { } JAUSoundTableItem* JAUSoundTable::getData(JAISoundID param_0) const { +#if DUSK_AUDIO_DISABLED + if (this == NULL) { + return NULL; + } +#endif if (param_0.isAnonymous()) { return NULL; } diff --git a/libs/JSystem/src/JFramework/JFWDisplay.cpp b/libs/JSystem/src/JFramework/JFWDisplay.cpp index 6812a81880..b55649a1bc 100644 --- a/libs/JSystem/src/JFramework/JFWDisplay.cpp +++ b/libs/JSystem/src/JFramework/JFWDisplay.cpp @@ -227,10 +227,6 @@ void JFWDisplay::endGX() { } void JFWDisplay::beginRender() { -#if TARGET_PC - aurora_begin_frame(); -#endif - if (field_0x40) { JUTProcBar::getManager()->wholeLoopEnd(); } @@ -342,10 +338,6 @@ void JFWDisplay::endFrame() { JUTProcBar::getManager()->setCostFrame(retrace_cnt - prevFrame); prevFrame = retrace_cnt; } - -#if TARGET_PC - aurora_end_frame(); -#endif } void JFWDisplay::waitBlanking(int param_0) { diff --git a/libs/JSystem/src/JParticle/JPABaseShape.cpp b/libs/JSystem/src/JParticle/JPABaseShape.cpp index fffcf05cad..f28add564e 100644 --- a/libs/JSystem/src/JParticle/JPABaseShape.cpp +++ b/libs/JSystem/src/JParticle/JPABaseShape.cpp @@ -1260,7 +1260,7 @@ JPABaseShape::JPABaseShape(u8 const* pData, JKRHeap* pHeap) { } if (isTexAnm()) { - JUT_ASSERT(1698, pBsd->texAnmKeyNum != NULL); + JUT_ASSERT(1698, pBsd->texAnmKeyNum != 0); u32 offs = sizeof(JPABaseShapeData); if (isTexCrdAnm()) { offs += 0x28; @@ -1271,7 +1271,7 @@ JPABaseShape::JPABaseShape(u8 const* pData, JKRHeap* pHeap) { } if (isPrmAnm()) { - JUT_ASSERT(1707, pBsd->prmAnmKeyNum != NULL); + JUT_ASSERT(1707, pBsd->prmAnmKeyNum != 0); JPAClrAnmKeyData* anmKeyData = (JPAClrAnmKeyData*)(pData + pBsd->mClrPrmAnmOffset); makeColorTable(&mpPrmClrAnmTbl, anmKeyData, pBsd->prmAnmKeyNum, pBsd->mClrAnmFrmMax, pHeap); @@ -1280,7 +1280,7 @@ JPABaseShape::JPABaseShape(u8 const* pData, JKRHeap* pHeap) { } if (isEnvAnm()) { - JUT_ASSERT(1716, pBsd->envAnmKeyNum != NULL); + JUT_ASSERT(1716, pBsd->envAnmKeyNum != 0); JPAClrAnmKeyData* anmKeyData = (JPAClrAnmKeyData*)(pData + pBsd->mClrEnvAnmOffset); makeColorTable(&mpEnvClrAnmTbl, anmKeyData, pBsd->envAnmKeyNum, pBsd->mClrAnmFrmMax, pHeap); diff --git a/libs/JSystem/src/JStudio/JStudio/jstudio-object.cpp b/libs/JSystem/src/JStudio/JStudio/jstudio-object.cpp index ebf7ab364e..3b87a6e34a 100644 --- a/libs/JSystem/src/JStudio/JStudio/jstudio-object.cpp +++ b/libs/JSystem/src/JStudio/JStudio/jstudio-object.cpp @@ -2,6 +2,8 @@ #include "JSystem/JStudio/JStudio/jstudio-object.h" +#include "dusk/audio.h" + namespace JStudio { namespace { @@ -1103,6 +1105,8 @@ u32 const JStudio::TAdaptor_sound::sauVariableValue_3_POSITION_XYZ[3] = { }; void JStudio::TObject_sound::do_paragraph(u32 param_1, void const* param_2, u32 param_3) { + DUSK_AUDIO_SKIP() + TAdaptor* adaptor = getAdaptor(); TControl* control; if (adaptor == NULL) { diff --git a/libs/JSystem/src/JStudio/JStudio_JStage/control.cpp b/libs/JSystem/src/JStudio/JStudio_JStage/control.cpp index 5ba81c8fc9..641348b87b 100644 --- a/libs/JSystem/src/JStudio/JStudio_JStage/control.cpp +++ b/libs/JSystem/src/JStudio/JStudio_JStage/control.cpp @@ -37,7 +37,7 @@ bool JStudio_JStage::TCreateObject::create( eObject = JStage::OBJECT_FOG; break; default: - return NULL; + return false; } JUT_ASSERT(99, pfnCreateObject!=NULL); JUT_ASSERT(100, eObject!=JStage::OBJECT_UNDEFINED); diff --git a/libs/JSystem/src/JUtility/JUTConsole.cpp b/libs/JSystem/src/JUtility/JUTConsole.cpp index b2d350f0d5..3be4a370ef 100644 --- a/libs/JSystem/src/JUtility/JUTConsole.cpp +++ b/libs/JSystem/src/JUtility/JUTConsole.cpp @@ -181,7 +181,7 @@ void JUTConsole::doDraw(JUTConsole::EConsoleType consoleType) const { mFont->drawString_scale((int)f31, sp94, mFontSizeX, mFontSizeY, mVisible ? "[ON]" : "[OFF]", TRUE); f31 += (int)(mFontSizeX * 6.0f); - if (this == NULL) // ???? + if (IS_REF_NULL(*this)) // ???? { mFont->setCharColor(JUtility::TColor(0xff, 0xff, 0x64, 0xff)); mFont->drawString_scale((int)(f31 - mFontSizeX), mFontSizeX, mFontSizeY, sp94, diff --git a/libs/JSystem/src/JUtility/JUTException.cpp b/libs/JSystem/src/JUtility/JUTException.cpp index e34b56c710..509acbfb3e 100644 --- a/libs/JSystem/src/JUtility/JUTException.cpp +++ b/libs/JSystem/src/JUtility/JUTException.cpp @@ -949,7 +949,7 @@ bool JUTException::queryMapAddress_single(char* mapPath, u32 address, s32 sectio dst--; i--; } - (void)*src; // needed to match debug + UNUSED(*src); // needed to match debug *dst = 0; if (print) { if (begin_with_newline) { diff --git a/libs/JSystem/src/JUtility/JUTFader.cpp b/libs/JSystem/src/JUtility/JUTFader.cpp index 35bcb09d87..754979115c 100644 --- a/libs/JSystem/src/JUtility/JUTFader.cpp +++ b/libs/JSystem/src/JUtility/JUTFader.cpp @@ -25,12 +25,18 @@ void JUTFader::control() { if (mStatus == 1) { return; } - + switch (mStatus) { case 0: mColor.a = 0xFF; break; case 2: + #if AVOID_UB + if (field_0x8 == 0) { + mStatus = 1; + break; + } + #endif mColor.a = 0xFF - ((++field_0xa * 0xFF) / field_0x8); if (field_0xa >= field_0x8) { @@ -39,6 +45,12 @@ void JUTFader::control() { break; case 3: + #if AVOID_UB + if (field_0x8 == 0) { + mStatus = 0; + break; + } + #endif mColor.a = ((++field_0xa * 0xFF) / field_0x8); if (field_0xa >= field_0x8) { diff --git a/src/SSystem/SComponent/c_bg_s_gnd_chk.cpp b/src/SSystem/SComponent/c_bg_s_gnd_chk.cpp index 687bf217fe..8ef7c7fe32 100644 --- a/src/SSystem/SComponent/c_bg_s_gnd_chk.cpp +++ b/src/SSystem/SComponent/c_bg_s_gnd_chk.cpp @@ -5,6 +5,12 @@ #include "SSystem/SComponent/c_bg_s_gnd_chk.h" #include "f_pc/f_pc_manager.h" +#include "JSystem/JUtility/JUTAssert.h" + +#define CHECK_FLOAT_CLASS(line, x) JUT_ASSERT(line, !isnan(x)); +#define CHECK_FLOAT_RANGE(line, x) JUT_ASSERT(line, -INF < x && x < INF); +#define CHECK_FLOAT_MIN(line, x) JUT_ASSERT(line, -INF < x); +#define CHECK_FLOAT_MAX(line, x) JUT_ASSERT(line, x < INF); cBgS_GndChk::cBgS_GndChk() { m_pos = cXyz::Zero; @@ -15,11 +21,31 @@ cBgS_GndChk::cBgS_GndChk() { cBgS_GndChk::~cBgS_GndChk() {} void cBgS_GndChk::SetPos(Vec const* pos) { - m_pos = *pos; + m_pos.x = pos->x; + m_pos.y = pos->y; + m_pos.z = pos->z; + + CHECK_FLOAT_CLASS(37, m_pos.x); + CHECK_FLOAT_CLASS(38, m_pos.y); + CHECK_FLOAT_CLASS(39, m_pos.z); + + CHECK_FLOAT_RANGE(43, m_pos.x); + CHECK_FLOAT_MIN(44, m_pos.y); + CHECK_FLOAT_MAX(45, m_pos.y); + CHECK_FLOAT_RANGE(46, m_pos.z); } void cBgS_GndChk::SetPos(cXyz const* pos) { m_pos = *pos; + + CHECK_FLOAT_CLASS(59, m_pos.x); + CHECK_FLOAT_CLASS(60, m_pos.y); + CHECK_FLOAT_CLASS(61, m_pos.z); + + CHECK_FLOAT_RANGE(65, m_pos.x); + CHECK_FLOAT_MIN(66, m_pos.y); + CHECK_FLOAT_MAX(67, m_pos.y); + CHECK_FLOAT_RANGE(68, m_pos.z); } void cBgS_GndChk::PreCheck() { diff --git a/src/SSystem/SComponent/c_bg_s_lin_chk.cpp b/src/SSystem/SComponent/c_bg_s_lin_chk.cpp index ddfd9274b6..cb207254ea 100644 --- a/src/SSystem/SComponent/c_bg_s_lin_chk.cpp +++ b/src/SSystem/SComponent/c_bg_s_lin_chk.cpp @@ -28,11 +28,11 @@ void cBgS_LinChk::Set2(cXyz const* startPos, cXyz const* endPos, unsigned int ac field_0x40 = *endPos; SetActorPid(actorPid); mStts &= ~STTS_HIT; - ClearPi(); + ClearCheckIndex(); } void cBgS_LinChk::PreCalc() { - mPreWallChk = !(mStts & STTS_WALL_OFF); - mPreGroundChk = !(mStts & STTS_GROUND_OFF); - mPreRoofChk = !(mStts & STTS_ROOF_OFF); + mPreWallChk = !ChkSttsWallOff(); + mPreGroundChk = !ChkSttsGroundOff(); + mPreRoofChk = !ChkSttsRoofOff(); } diff --git a/src/SSystem/SComponent/c_cc_d.cpp b/src/SSystem/SComponent/c_cc_d.cpp index 5326338602..569d64e5e7 100644 --- a/src/SSystem/SComponent/c_cc_d.cpp +++ b/src/SSystem/SComponent/c_cc_d.cpp @@ -218,9 +218,7 @@ void cCcD_Stts::PlusCcMove(f32 x, f32 y, f32 z) { } void cCcD_Stts::ClrCcMove() { - m_cc_move.z = 0.0f; - m_cc_move.y = 0.0f; - m_cc_move.x = 0.0f; + m_cc_move.x = m_cc_move.y = m_cc_move.z = 0.0f; } void cCcD_Stts::PlusDmg(int dmg) { @@ -231,7 +229,8 @@ void cCcD_Stts::PlusDmg(int dmg) { } f32 cCcD_Stts::GetWeightF() const { - return (s32)m_weight; + int weighti = GetWeightUc(); + return weighti; } void cCcD_ObjCommonBase::ct() { @@ -259,17 +258,13 @@ fopAc_ac_c* cCcD_Obj::GetAc() { if (mStts == NULL) { return NULL; } else { - return mStts->GetAc(); + return mStts->GetActor(); } } void cCcD_ShapeAttr::getShapeAccess(cCcD_ShapeAttr::Shape* pshape) const { pshape->_0 = 2; - pshape->_14 = 0.0f; - pshape->_10 = 0.0f; - pshape->_4.z = 0.0f; - pshape->_4.y = 0.0f; - pshape->_4.x = 0.0f; + pshape->_4.x = pshape->_4.y = pshape->_4.z = pshape->_10 = pshape->_14 = 0.0f; } bool cCcD_PntAttr::GetNVec(cXyz const& param_0, cXyz* param_1) const { @@ -321,19 +316,20 @@ bool cCcD_TriAttr::CrossAtTg(const cCcD_TriAttr& other, cXyz* pxyz) const { } void cCcD_TriAttr::CalcAabBox() { - mAab.ClearForMinMax(); - mAab.SetMinMax(mA); - mAab.SetMinMax(mB); - mAab.SetMinMax(mC); + GetWorkAab().ClearForMinMax(); + GetWorkAab().SetMinMax(mA); + GetWorkAab().SetMinMax(mB); + GetWorkAab().SetMinMax(mC); } bool cCcD_TriAttr::GetNVec(const cXyz& param_0, cXyz* pOut) const { if (getPlaneFunc(¶m_0) >= 0.0f) { - *pOut = mNormal; + *pOut = *GetNP(); } else { - *pOut = mNormal; - VECScale(pOut, pOut, -1.0f); + *pOut = *GetNP(); + PSVECScale(pOut, pOut, -1.0f); } + return true; } @@ -362,7 +358,7 @@ bool cCcD_CpsAttr::CrossAtTg(const cCcD_SphAttr& sphAttr, cXyz* pxyz) const { } bool cCcD_CpsAttr::CrossAtTg(const cCcD_TriAttr& triAttr, cXyz* pxyz) const { - if (triAttr.cM3dGTri::Cross(*this, pxyz)) { + if (cM3dGCps::Cross(triAttr, pxyz)) { return true; } else { return false; @@ -400,44 +396,47 @@ bool cCcD_CpsAttr::CrossCo(const cCcD_SphAttr& sphAttr, f32* param_1) const { } void cCcD_CpsAttr::CalcAabBox() { - mAab.ClearForMinMax(); - mAab.SetMinMax(mStart); - mAab.SetMinMax(mEnd); - mAab.PlusR(mRadius); + GetWorkAab().ClearForMinMax(); + GetWorkAab().SetMinMax(*GetStartP()); + GetWorkAab().SetMinMax(*GetEndP()); + GetWorkAab().PlusR(GetR()); } bool cCcD_CpsAttr::GetNVec(const cXyz& param_0, cXyz* param_1) const { - Vec diff; - const cXyz& endP = GetEndP(); - VECSubtract(&endP, &mStart, &diff); + cXyz diff; + PSVECSubtract(GetEndP(), GetStartP(), &diff); - f32 diffLen = VECDotProduct(&diff, &diff); + f32 diffLen = PSVECDotProduct(&diff, &diff); if (cM3d_IsZero(diffLen)) { return false; - } else { - Vec vec1, vec2; - VECSubtract(¶m_0, &mStart, &vec1); - f32 vec1Len = VECDotProduct(&vec1, &diff) / diffLen; - if (vec1Len < 0.0f) { - vec2 = mStart; - } else { - if (vec1Len > 1.0f) { - vec2 = endP; - } else { - VECScale(&diff, &diff, vec1Len); - VECAdd(&diff, &mStart, &vec2); - } - } + } - VECSubtract(¶m_0, &vec2, param_1); - if (cM3d_IsZero(VECMag(param_1))) { - param_1->set(0.0f, 0.0f, 0.0f); - return false; + cXyz vec1; + PSVECSubtract(¶m_0, GetStartP(), &vec1); + f32 vec1Len = PSVECDotProduct(&vec1, &diff) / diffLen; + + cXyz vec2; + if (vec1Len < 0.0f) { + vec2 = *GetStartP(); + } else { + if (vec1Len > 1.0f) { + vec2 = *GetEndP(); } else { - VECNormalize(param_1, param_1); - return true; + PSVECScale(&diff, &diff, vec1Len); + PSVECAdd(&diff, GetStartP(), &vec2); } } + + PSVECSubtract(¶m_0, &vec2, param_1); + if (cM3d_IsZero(PSVECMag(param_1))) { + param_1->x = 0.0f; + param_1->y = 0.0f; + param_1->z = 0.0f; + return false; + } else { + PSVECNormalize(param_1, param_1); + return true; + } } bool cCcD_CylAttr::CrossAtTg(const cCcD_CpsAttr& cpsAttr, cXyz* pxyz) const { @@ -473,7 +472,7 @@ bool cCcD_CylAttr::CrossAtTg(const cCcD_TriAttr& triAttr, cXyz* pxyz) const { } bool cCcD_CylAttr::CrossCo(const cCcD_CylAttr& other, f32* f) const { - if (cM3dGCyl::Cross(&other, f)) { + if (cM3dGCyl::cross(&other, f)) { return true; } else { return false; @@ -481,7 +480,7 @@ bool cCcD_CylAttr::CrossCo(const cCcD_CylAttr& other, f32* f) const { } bool cCcD_CylAttr::CrossCo(const cCcD_SphAttr& sphAttr, f32* f) const { - if (cM3dGCyl::Cross(&sphAttr, f)) { + if (cM3dGCyl::cross(&sphAttr, f)) { return true; } else { return false; @@ -507,51 +506,51 @@ void cCcD_CylAttr::CalcAabBox() { max.x = GetCP()->x + GetR(); max.y = GetCP()->y + GetH(); max.z = GetCP()->z + GetR(); - mAab.Set(&min, &max); + GetWorkAab().Set(&min, &max); } bool cCcD_CylAttr::GetNVec(const cXyz& param_0, cXyz* param_1) const { - Vec vec; - if (GetCP()->y > param_0.y) { - vec = mCenter; + const cXyz* cp = GetCP(); + cXyz vec; + if (cp->y > param_0.y) { + vec = *cp; } else { - if (GetCP()->y + GetH() < param_0.y) { - vec.x = GetCP()->x; - vec.y = GetCP()->y; - vec.z = GetCP()->z; - vec.y = GetCP()->y + GetH(); + if (cp->y + GetH() < param_0.y) { + vec = *cp; + vec.y += GetH(); } else { - vec = mCenter; + vec = *cp; vec.y = param_0.y; } } - VECSubtract(¶m_0, &vec, param_1); - if (cM3d_IsZero(VECMag(param_1))) { - param_1->set(0.0f, 0.0f, 0.0f); + PSVECSubtract(¶m_0, &vec, param_1); + if (cM3d_IsZero(PSVECMag(param_1))) { + param_1->x = 0.0f; + param_1->y = 0.0f; + param_1->z = 0.0f; return false; } else { - VECNormalize(param_1, param_1); + PSVECNormalize(param_1, param_1); return true; } + return false; } void cCcD_CylAttr::getShapeAccess(cCcD_ShapeAttr::Shape* pshape) const { pshape->_0 = 1; - pshape->_4.x = mCenter.x; - pshape->_4.y = mCenter.y; - pshape->_4.z = mCenter.z; - pshape->_10 = mRadius; - pshape->_14 = mHeight; -} -inline bool inlineCross(const cM3dGSph& sph, const cM3dGCps* pcps, cXyz* pxyz) { - return cM3d_Cross_CpsSph(*pcps, sph, pxyz); + const cXyz& center = GetC(); + pshape->_4.x = center.x; + pshape->_4.y = center.y; + pshape->_4.z = center.z; + pshape->_10 = GetR(); + pshape->_14 = GetH(); } bool cCcD_SphAttr::CrossAtTg(const cCcD_CpsAttr& cpsAttr, cXyz* pxyz) const { - if (inlineCross(*this, &cpsAttr, pxyz)) { + if (cM3dGSph::Cross(&cpsAttr, pxyz)) { return true; } else { return false; @@ -575,7 +574,7 @@ bool cCcD_SphAttr::CrossAtTg(const cCcD_SphAttr& sphAttr, cXyz* pxyz) const { } bool cCcD_SphAttr::CrossAtTg(const cCcD_TriAttr& triAttr, cXyz* pxyz) const { - if (triAttr.cM3dGTri::Cross(*this, pxyz)) { + if (cM3dGSph::Cross(triAttr, pxyz)) { return true; } else { return false; @@ -583,7 +582,7 @@ bool cCcD_SphAttr::CrossAtTg(const cCcD_TriAttr& triAttr, cXyz* pxyz) const { } bool cCcD_SphAttr::CrossCo(const cCcD_CylAttr& cylAttr, f32* f) const { - if (cM3dGSph::Cross(&cylAttr, f)) { + if (cM3dGSph::cross(&cylAttr, f)) { return true; } else { return false; @@ -591,7 +590,7 @@ bool cCcD_SphAttr::CrossCo(const cCcD_CylAttr& cylAttr, f32* f) const { } bool cCcD_SphAttr::CrossCo(const cCcD_SphAttr& sphAttr, f32* f) const { - if (cM3dGSph::Cross(&sphAttr, f)) { + if (cM3dGSph::cross(&sphAttr, f)) { return true; } else { return false; @@ -622,37 +621,40 @@ void cCcD_SphAttr::CalcAabBox() { max.y += GetR(); max.z += GetR(); - mAab.Set(&min, &max); + GetWorkAab().Set(&min, &max); } bool cCcD_SphAttr::GetNVec(const cXyz& param_0, cXyz* param_1) const { - param_1->x = param_0.x - mCenter.x; - param_1->y = param_0.y - mCenter.y; - param_1->z = param_0.z - mCenter.z; + const cXyz& center = GetC(); + param_1->x = param_0.x - center.x; + param_1->y = param_0.y - center.y; + param_1->z = param_0.z - center.z; - if (cM3d_IsZero(VECMag(param_1))) { + if (cM3d_IsZero(PSVECMag(param_1))) { param_1->x = 0.0f; param_1->y = 0.0f; param_1->z = 0.0f; return false; } else { - VECNormalize(param_1, param_1); + PSVECNormalize(param_1, param_1); return true; } } void cCcD_SphAttr::getShapeAccess(cCcD_ShapeAttr::Shape* pshape) const { pshape->_0 = 0; - pshape->_4.x = mCenter.x; - pshape->_4.y = mCenter.y; - pshape->_4.z = mCenter.z; - pshape->_10 = mRadius; + + const cXyz& center = GetC(); + pshape->_4.x = center.x; + pshape->_4.y = center.y; + pshape->_4.z = center.z; + pshape->_10 = GetR(); pshape->_14 = 0.0f; } void cCcD_ObjAt::SetHit(cCcD_Obj* pObj) { - mRPrm = 1; - mHitObj = pObj; + SetRPrm(1); + SetHitObj(pObj); } void cCcD_ObjAt::Set(const cCcD_SrcObjAt& src) { @@ -662,8 +664,8 @@ void cCcD_ObjAt::Set(const cCcD_SrcObjAt& src) { } void cCcD_ObjAt::ClrHit() { - mRPrm &= ~1; - mHitObj = NULL; + ClrRPrm(1); + ClrObj(); } void cCcD_ObjTg::Set(const cCcD_SrcObjTg& src) { @@ -672,36 +674,36 @@ void cCcD_ObjTg::Set(const cCcD_SrcObjTg& src) { } void cCcD_ObjTg::SetGrp(u32 grp) { - mSPrm &= ~0x1E; - mSPrm |= grp; + OffSPrmBit(0x1E); + OnSPrmBit(grp); } void cCcD_ObjTg::ClrHit() { - mRPrm &= ~1; - mHitObj = NULL; + ClrRPrm(1); + ClrObj(); } void cCcD_ObjTg::SetHit(cCcD_Obj* pObj) { - mRPrm = 1; - mHitObj = pObj; + SetRPrm(1); + SetHitObj(pObj); } void cCcD_ObjCo::SetHit(cCcD_Obj* pObj) { - mRPrm = 1; - mHitObj = pObj; + SetRPrm(1); + SetHitObj(pObj); } void cCcD_ObjCo::ClrHit() { - mRPrm &= ~1; - mHitObj = NULL; + ClrRPrm(1); + ClrObj(); } void cCcD_ObjCo::SetIGrp(u32 grp) { - mSPrm &= ~0xE; - mSPrm |= grp; + OffSPrmBit(0xE); + OnSPrmBit(grp); } void cCcD_ObjCo::SetVsGrp(u32 grp) { - mSPrm &= ~0x70; - mSPrm |= grp; + OffSPrmBit(0x70); + OnSPrmBit(grp); } diff --git a/src/SSystem/SComponent/c_cc_s.cpp b/src/SSystem/SComponent/c_cc_s.cpp index 72df9625d8..73b6993255 100644 --- a/src/SSystem/SComponent/c_cc_s.cpp +++ b/src/SSystem/SComponent/c_cc_s.cpp @@ -33,6 +33,10 @@ void cCcS::Ct() { *obj = NULL; } mObjCount = 0; + + #if DEBUG + m_debug_code = 1234; + #endif } void cCcS::Dt() { @@ -98,9 +102,8 @@ void cCcS::ClrCoHitInf() { if (*obj != NULL) { (*obj)->GetGObjInf()->ClrCoHit(); - cCcD_Stts* stts = (*obj)->GetStts(); - if (stts != NULL) { - stts->ClrCcMove(); + if ((*obj)->GetStts() != NULL) { + (*obj)->GetStts()->ClrCo(); } } } @@ -111,9 +114,8 @@ void cCcS::ClrTgHitInf() { if (*obj != NULL) { (*obj)->GetGObjInf()->ClrTgHit(); - cCcD_Stts* stts = (*obj)->GetStts(); - if (stts != NULL) { - stts->ClrTg(); + if ((*obj)->GetStts() != NULL) { + (*obj)->GetStts()->ClrTg(); } } } @@ -124,9 +126,8 @@ void cCcS::ClrAtHitInf() { if (*obj != NULL) { (*obj)->GetGObjInf()->ClrAtHit(); - cCcD_Stts* stts = (*obj)->GetStts(); - if (stts != NULL) { - stts->ClrAt(); + if ((*obj)->GetStts() != NULL) { + (*obj)->GetStts()->ClrAt(); } } } @@ -155,18 +156,18 @@ void cCcS::ChkAtTg() { continue; cCcD_ShapeAttr* pat_sa = (*pat_obj)->GetShapeAttr(); - JUT_ASSERT(0, pat_sa != NULL); + JUT_ASSERT(338, pat_sa != NULL); for (cCcD_Obj** ptg_obj = mpObjTg; ptg_obj < objTgEnd; ++ptg_obj) { if (*ptg_obj == NULL || !(*ptg_obj)->ChkTgSet()) continue; - if (!(*pat_obj)->GetDivideInfo().Chk((*ptg_obj)->GetDivideInfo())) + if (!(*pat_obj)->GetPDivideInfo()->Chk(*(*ptg_obj)->GetPDivideInfo())) continue; if (ChkNoHitAtTg(*pat_obj, *ptg_obj)) continue; cCcD_ShapeAttr* ptg_sa = (*ptg_obj)->GetShapeAttr(); - JUT_ASSERT(0, ptg_sa != NULL); + JUT_ASSERT(354, ptg_sa != NULL); static cXyz cross; bool didCross = pat_sa->CrossAtTg(*ptg_sa, &cross); @@ -176,9 +177,12 @@ void cCcS::ChkAtTg() { } else if (anyBsRevHit && !didCross) { cCcD_ShapeAttr* pat_sa = (*pat_obj)->GetShapeAttr(); if (pat_sa == NULL) { - cross.set(0.0f, 0.0f, 0.0f); + cross.x = 0.0f; + cross.y = 0.0f; + cross.z = 0.0f; } else { - pat_sa->GetWorkAab().CalcCenter(&cross); + cM3dGAab& aab = pat_sa->GetWorkAab(); + aab.CalcCenter(&cross); } SetAtTgCommonHitInf(*pat_obj, *ptg_obj, &cross); @@ -213,24 +217,22 @@ void cCcS::ChkCo() { continue; cCcD_ShapeAttr* pco1_sa = (*pco1_obj)->GetShapeAttr(); - JUT_ASSERT(0, pco1_sa != NULL); + JUT_ASSERT(444, pco1_sa != NULL); for (cCcD_Obj** pco2_obj = pco1_obj + 1; pco2_obj < objCoEnd; ++pco2_obj) { if (*pco2_obj == NULL || !(*pco2_obj)->ChkCoSet()) continue; - if (!(*pco1_obj)->GetDivideInfo().Chk((*pco2_obj)->GetDivideInfo())) + if (!(*pco1_obj)->GetPDivideInfo()->Chk(*(*pco2_obj)->GetPDivideInfo())) continue; if (ChkNoHitCo(*pco1_obj, *pco2_obj)) continue; cCcD_ShapeAttr* pco2_sa = (*pco2_obj)->GetShapeAttr(); - JUT_ASSERT(0, pco2_sa != NULL); + JUT_ASSERT(456, pco2_sa != NULL); f32 cross_len; if (pco1_sa->CrossCo(*pco2_sa, &cross_len)) { - cXyz& co2_center = pco2_sa->GetCoCP(); - cXyz& co1_center = pco1_sa->GetCoCP(); - SetCoCommonHitInf(*pco1_obj, &co1_center, *pco2_obj, &co2_center, cross_len); + SetCoCommonHitInf(*pco1_obj, &pco1_sa->GetCoCP(), *pco2_obj, &pco2_sa->GetCoCP(), cross_len); } } } @@ -238,7 +240,11 @@ void cCcS::ChkCo() { void cCcS::CalcTgPlusDmg(cCcD_Obj* pat_obj, cCcD_Obj* ptg_obj, cCcD_Stts* pat_stts, cCcD_Stts* ptg_stts) { - ptg_stts->PlusDmg(pat_obj->GetAtAtp()); + UNUSED(ptg_obj); + UNUSED(pat_stts); + + int atp = pat_obj->GetAtAtp(); + ptg_stts->PlusDmg(atp); } void cCcS::SetAtTgCommonHitInf(cCcD_Obj* pat_obj, cCcD_Obj* ptg_obj, cXyz* pcross) { @@ -296,8 +302,8 @@ void cCcS::SetPosCorrect(cCcD_Obj* pco1_obj, cXyz* ppos1, cCcD_Obj* pco2_obj, cX return; if (pco1_obj->GetStts() == NULL || pco2_obj->GetStts() == NULL) return; - if (pco1_obj->GetStts()->GetAc() != NULL && - pco1_obj->GetStts()->GetAc() == pco2_obj->GetStts()->GetAc()) + if (pco1_obj->GetStts()->GetActor() != NULL && + pco1_obj->GetStts()->GetActor() == pco2_obj->GetStts()->GetActor()) return; if (!(fabsf(cross_len) < (1.0f / 125.0f))) { @@ -346,12 +352,12 @@ void cCcS::SetPosCorrect(cCcD_Obj* pco1_obj, cXyz* ppos1, cCcD_Obj* pco2_obj, cX } f32 objDistLen; - Vec vec1; - Vec vec2; + cXyz vec1; + cXyz vec2; Vec objsDist; if (bothCoSph3DCrr) { - VECSubtract(ppos2, ppos1, &objsDist); - objDistLen = VECMag(&objsDist); + PSVECSubtract(ppos2, ppos1, &objsDist); + objDistLen = PSVECMag(&objsDist); } else { objsDist.x = ppos2->x - ppos1->x; objsDist.y = 0; @@ -361,10 +367,11 @@ void cCcS::SetPosCorrect(cCcD_Obj* pco1_obj, cXyz* ppos1, cCcD_Obj* pco2_obj, cX if (!cM3d_IsZero(objDistLen)) { if (bothCoSph3DCrr) { - VECScale(&objsDist, &objsDist, cross_len / objDistLen); + f32 sp1C = cross_len / objDistLen; + PSVECScale(&objsDist, &objsDist, sp1C); obj2Weight *= -1; - VECScale(&objsDist, &vec1, obj2Weight); - VECScale(&objsDist, &vec2, obj1Weight); + PSVECScale(&objsDist, &vec1, obj2Weight); + PSVECScale(&objsDist, &vec2, obj1Weight); } else { f32 pushFactor = cross_len / objDistLen; objsDist.x *= pushFactor; @@ -435,7 +442,7 @@ void cCcS::CalcArea() { for (cCcD_Obj** pset_obj = mpObj; pset_obj < mpObj + mObjCount; ++pset_obj) { if (*pset_obj != NULL) { cCcD_ShapeAttr* pset_sa = (*pset_obj)->GetShapeAttr(); - JUT_ASSERT(0, pset_sa != NULL); + JUT_ASSERT(826, pset_sa != NULL); pset_sa->CalcAabBox(); aab.SetMinMax(pset_sa->GetWorkAab()); @@ -445,10 +452,10 @@ void cCcS::CalcArea() { mDivideArea.SetArea(aab); for (cCcD_Obj** pset_obj = mpObj; pset_obj < mpObj + mObjCount; ++pset_obj) { if (*pset_obj != NULL) { - const cCcD_ShapeAttr* pset_sa = (*pset_obj)->GetShapeAttr(); - JUT_ASSERT(0, pset_sa != NULL); + cCcD_ShapeAttr* pset_sa = (*pset_obj)->GetShapeAttr(); + JUT_ASSERT(839, pset_sa != NULL); - cCcD_DivideInfo* divideInfo = &(*pset_obj)->GetDivideInfo(); + cCcD_DivideInfo* divideInfo = (*pset_obj)->GetPDivideInfo(); mDivideArea.CalcDivideInfo(divideInfo, pset_sa->GetWorkAab(), (*pset_obj)->ChkBsRevHit()); } @@ -456,10 +463,20 @@ void cCcS::CalcArea() { } void cCcS::Move() { + #if DEBUG + JUT_ASSERT(866, m_debug_code == 1234); + #endif + CalcArea(); ChkAtTg(); ChkCo(); MoveAfterCheck(); + + field_0x280c = mObjAtCount; + field_0x280e = mObjTgCount; + field_0x2810 = mObjCoCount; + field_0x2812 = mObjCount; + mObjAtCount = 0; mObjTgCount = 0; mObjCoCount = 0; diff --git a/src/SSystem/SComponent/c_m3d.cpp b/src/SSystem/SComponent/c_m3d.cpp index 8487468223..c44ea66bf8 100644 --- a/src/SSystem/SComponent/c_m3d.cpp +++ b/src/SSystem/SComponent/c_m3d.cpp @@ -66,14 +66,14 @@ bool cM3d_Len2dSqPntAndSegLine(f32 param_1, f32 param_2, f32 param_3, f32 param_ bool cM3d_Len3dSqPntAndSegLine(const cM3dGLin* pLine, const Vec* pVec, Vec* pOutVec, f32* pOutF) { bool retVal = false; Vec tmp; - VECSubtract(&pLine->GetEndP(), &pLine->GetStartP(), &tmp); + VECSubtract(pLine->GetEndP(), pLine->GetStartP(), &tmp); f32 seqLen = VECDotProduct(&tmp, &tmp); if (cM3d_IsZero(seqLen)) { *pOutF = 0.0f; return retVal; } else { Vec tmp2; - VECSubtract(pVec, &pLine->GetStartP(), &tmp2); + VECSubtract(pVec, pLine->GetStartP(), &tmp2); f32 tmpF = VECDotProduct(&tmp2, &tmp); tmpF /= seqLen; if (tmpF < 0.0f || tmpF > 1.0f) { @@ -82,7 +82,7 @@ bool cM3d_Len3dSqPntAndSegLine(const cM3dGLin* pLine, const Vec* pVec, Vec* pOut retVal = true; } VECScale(&tmp, &tmp, tmpF); - VECAdd(&tmp, &pLine->GetStartP(), pOutVec); + VECAdd(&tmp, pLine->GetStartP(), pOutVec); *pOutF = VECSquareDistance(pOutVec, pVec); return retVal; } @@ -213,7 +213,7 @@ int cM3d_Check_LinLin(const cM3dGLin* lin_a, const cM3dGLin* lin_b, f32* dst_a, VECScale(&linAVec, &linAVec, invLinALen); VECScale(&linBVec, &linBVec, invLinBLen); Vec tmp; - VECSubtract(&lin_a->GetStartP(), &lin_b->GetStartP(), &tmp); + VECSubtract(lin_a->GetStartP(), lin_b->GetStartP(), &tmp); f32 tmpF = -VECDotProduct(&linAVec, &linBVec); f32 tmpF2 = VECDotProduct(&tmp, &linAVec); VECSquareMag(&tmp); // result not used @@ -262,19 +262,19 @@ static bool cM3d_CrossInfLineVsInfPlane_proc(f32 pFloatA, f32 pFloatB, const Vec } bool cM3d_Cross_LinPla(const cM3dGLin* lin, const cM3dGPla* pla, Vec* dst, bool a, bool b) { - f32 startVal = pla->getPlaneFunc(&lin->GetStartP()); - f32 endVal = pla->getPlaneFunc(&lin->GetEndP()); + f32 startVal = pla->getPlaneFunc(lin->GetStartP()); + f32 endVal = pla->getPlaneFunc(lin->GetEndP()); if (startVal * endVal > 0.0f) { *dst = lin->GetEnd(); return false; } else { if (startVal >= 0.0f && endVal <= 0.0f) { if (a) { - return cM3d_CrossInfLineVsInfPlane_proc(startVal, endVal, &lin->GetStartP(), &lin->GetEndP(), dst); + return cM3d_CrossInfLineVsInfPlane_proc(startVal, endVal, lin->GetStartP(), lin->GetEndP(), dst); } } else { if (b) { - return cM3d_CrossInfLineVsInfPlane_proc(startVal, endVal, &lin->GetStartP(), &lin->GetEndP(), dst); + return cM3d_CrossInfLineVsInfPlane_proc(startVal, endVal, lin->GetStartP(), lin->GetEndP(), dst); } } *dst = lin->GetEnd(); @@ -1034,53 +1034,53 @@ bool cM3d_Cross_LinSph(cM3dGLin const* line, cM3dGSph const* sph, Vec* param_2) const Vec* center = sph->GetCP(); f32 max_x = center->x + sph->GetR(); - if (max_x < line->GetStartP().x && max_x < line->GetEndP().x) { + if (max_x < line->GetStartP()->x && max_x < line->GetEndP()->x) { return false; } f32 min_x = center->x - sph->GetR(); - if (min_x > line->GetStartP().x && min_x > line->GetEndP().x) { + if (min_x > line->GetStartP()->x && min_x > line->GetEndP()->x) { return false; } f32 max_y = center->y + sph->GetR(); - if (max_y < line->GetStartP().y && max_y < line->GetEndP().y) { + if (max_y < line->GetStartP()->y && max_y < line->GetEndP()->y) { return false; } f32 min_y = center->y - sph->GetR(); - if (min_y > line->GetStartP().y && min_y > line->GetEndP().y) { + if (min_y > line->GetStartP()->y && min_y > line->GetEndP()->y) { return false; } f32 max_z = center->z + sph->GetR(); - if (max_z < line->GetStartP().z && max_z < line->GetEndP().z) { + if (max_z < line->GetStartP()->z && max_z < line->GetEndP()->z) { return false; } f32 min_z = center->z - sph->GetR(); - if (min_z > line->GetStartP().z && min_z > line->GetEndP().z) { + if (min_z > line->GetStartP()->z && min_z > line->GetEndP()->z) { return false; } - VECSubtract(&line->GetEndP(), &line->GetStartP(), &lin_vec); + VECSubtract(line->GetEndP(), line->GetStartP(), &lin_vec); f32 len_sq = VECSquareMag(&lin_vec); if (cM3d_IsZero(len_sq)) { return false; } - VECSubtract(center, &line->GetStartP(), &vec); + VECSubtract(center, line->GetStartP(), &vec); f32 proj = VECDotProduct(&vec, &lin_vec) / len_sq; if (proj < 0.0f || proj > 1.0f) { - if (line->GetStartP().abs2(*center) < line->GetEndP().abs2(*center)) { - if (cM3d_Cross_SphPnt(sph, &line->GetStartP())) { - param_2->x = line->GetStartP().x; - param_2->y = line->GetStartP().y; - param_2->z = line->GetStartP().z; + if (line->GetStartP()->abs2(*center) < line->GetEndP()->abs2(*center)) { + if (cM3d_Cross_SphPnt(sph, line->GetStartP())) { + param_2->x = line->GetStartP()->x; + param_2->y = line->GetStartP()->y; + param_2->z = line->GetStartP()->z; return true; } } else { - if (cM3d_Cross_SphPnt(sph, &line->GetEndP())) { - param_2->x = line->GetEndP().x; - param_2->y = line->GetEndP().y; - param_2->z = line->GetEndP().z; + if (cM3d_Cross_SphPnt(sph, line->GetEndP())) { + param_2->x = line->GetEndP()->x; + param_2->y = line->GetEndP()->y; + param_2->z = line->GetEndP()->z; return true; } } @@ -1089,7 +1089,7 @@ bool cM3d_Cross_LinSph(cM3dGLin const* line, cM3dGSph const* sph, Vec* param_2) Vec proj_vec; VECScale(&lin_vec, &proj_vec, proj); - VECAdd(&proj_vec, &line->GetStartP(), param_2); + VECAdd(&proj_vec, line->GetStartP(), param_2); if (cM3d_LenSq(param_2, center) <= sph->GetR() * sph->GetR()) { return true; } @@ -1100,8 +1100,8 @@ int cM3d_Cross_LinSph_CrossPos(cM3dGSph const& sph, cM3dGLin const& line, Vec* p Vec* param_3) { int ret; Vec line_vec, vec; - VECSubtract(&line.GetEndP(), &line.GetStartP(), &line_vec); - VECSubtract(&line.GetStartP(), sph.GetCP(), &vec); + VECSubtract(line.GetEndP(), line.GetStartP(), &line_vec); + VECSubtract(line.GetStartP(), sph.GetCP(), &vec); f32 len_sq = VECDotProduct(&line_vec, &line_vec); f32 dVar9 = VECDotProduct(&line_vec, &vec) * 2.0f; f32 dVar6 = VECDotProduct(&vec, &vec) - sph.GetR() * sph.GetR(); @@ -1113,7 +1113,7 @@ int cM3d_Cross_LinSph_CrossPos(cM3dGSph const& sph, cM3dGLin const& line, Vec* p ret = 1; Vec vec2; VECScale(&line_vec, &vec2, -dVar6 / dVar9); - VECAdd(&vec2, &line.GetStartP(), param_2); + VECAdd(&vec2, line.GetStartP(), param_2); } } else { f32 f11 = dVar9 * dVar9 - len_sq * 4.0f * dVar6; @@ -1121,7 +1121,7 @@ int cM3d_Cross_LinSph_CrossPos(cM3dGSph const& sph, cM3dGLin const& line, Vec* p ret = 1; Vec vec2; VECScale(&line_vec, &vec2, -dVar9 / (len_sq * 2.0f)); - VECAdd(&vec2, &line.GetStartP(), param_2); + VECAdd(&vec2, line.GetStartP(), param_2); } else if (f11 < 0.0f) { ret = 0; } else { @@ -1131,9 +1131,9 @@ int cM3d_Cross_LinSph_CrossPos(cM3dGSph const& sph, cM3dGLin const& line, Vec* p f32 scale1 = f1 * (-dVar9 + sqrtf(f11)); f32 scale2 = f1 * (-dVar9 - sqrtf(f11)); VECScale(&line_vec, &vec2, scale1); - VECAdd(&vec2, &line.GetStartP(), param_2); + VECAdd(&vec2, line.GetStartP(), param_2); VECScale(&line_vec, &vec2, scale2); - VECAdd(&vec2, &line.GetStartP(), param_3); + VECAdd(&vec2, line.GetStartP(), param_3); } } @@ -1460,17 +1460,17 @@ int cM3d_Cross_CylLin(cM3dGCyl const* cyl, cM3dGLin const* line, Vec* param_2, V f2 = 0.0f; uVar11 = 0; - if (cM3d_Cross_CylPnt(cyl, &line->GetStartP()) && cM3d_Cross_CylPnt(cyl, &line->GetEndP())) { - *param_2 = line->GetStartP(); - *param_3 = line->GetEndP(); + if (cM3d_Cross_CylPnt(cyl, line->GetStartP()) && cM3d_Cross_CylPnt(cyl, line->GetEndP())) { + *param_2 = *line->GetStartP(); + *param_3 = *line->GetEndP(); return 2; } Vec vec1, vec2, vec3; Vec vec[4]; const Vec* center = cyl->GetCP(); - VECSubtract(&line->GetStartP(), center, &vec1); - VECSubtract(&line->GetEndP(), center, &vec2); + VECSubtract(line->GetStartP(), center, &vec1); + VECSubtract(line->GetEndP(), center, &vec2); VECSubtract(&vec2, &vec1, &vec3); r_sq = cyl->GetR() * cyl->GetR(); @@ -1599,7 +1599,7 @@ int cM3d_Cross_CylLin(cM3dGCyl const* cyl, cM3dGLin const* line, Vec* param_2, V if (count == 0) { *param_2 = vec[i]; } else if (count == 1) { - if (cM3d_LenSq(&line->GetStartP(), param_2) < cM3d_LenSq(&line->GetStartP(), &vec[i])) { + if (cM3d_LenSq(line->GetStartP(), param_2) < cM3d_LenSq(line->GetStartP(), &vec[i])) { *param_3 = vec[i]; } else { *param_3 = *param_2; @@ -1707,36 +1707,36 @@ inline bool cM3d_Cross_CpsCyl_Check(cM3dGCps const& cps, cM3dGCyl const& cyl, Ve bool cM3d_Cross_CpsCyl(cM3dGCps const& cps, cM3dGCyl const& cyl, Vec* param_2) { cM3dGLin line; - if (cM3d_Cross_CylPnt(&cyl, &cps.GetEndP())) { - *param_2 = cps.GetEndP(); + if (cM3d_Cross_CylPnt(&cyl, cps.GetEndP())) { + *param_2 = *cps.GetEndP(); return true; } - if (cM3d_Cross_CylPnt(&cyl, &cps.GetStartP())) { - *param_2 = cps.GetStartP(); + if (cM3d_Cross_CylPnt(&cyl, cps.GetStartP())) { + *param_2 = *cps.GetStartP(); return true; } - line.GetStartP() = *cyl.GetCP(); - line.GetEndP() = *cyl.GetCP(); - line.GetEndP().y += cyl.GetH(); + *line.GetStartP() = *cyl.GetCP(); + *line.GetEndP() = *cyl.GetCP(); + line.GetEndP()->y += cyl.GetH(); Vec vec; f32 tmp; - if (cM3d_Len3dSqPntAndSegLine(&cps, &line.GetEndP(), &vec, &tmp)) { - f32 dist = VECDistance(&line.GetEndP(), &vec); + if (cM3d_Len3dSqPntAndSegLine(&cps, line.GetEndP(), &vec, &tmp)) { + f32 dist = VECDistance(line.GetEndP(), &vec); if (dist < cps.GetR()) { - VECAdd(&line.GetEndP(), &vec, param_2); + VECAdd(line.GetEndP(), &vec, param_2); VECScale(param_2, param_2, 0.5f); - *param_2 = line.GetEndP(); + *param_2 = *line.GetEndP(); return true; } } - if (cM3d_Len3dSqPntAndSegLine(&cps, &line.GetStartP(), &vec, &tmp)) { - f32 dist = VECDistance(&line.GetStartP(), &vec); + if (cM3d_Len3dSqPntAndSegLine(&cps, line.GetStartP(), &vec, &tmp)) { + f32 dist = VECDistance(line.GetStartP(), &vec); if (dist < cps.GetR()) { - VECAdd(&line.GetStartP(), &vec, param_2); + VECAdd(line.GetStartP(), &vec, param_2); VECScale(param_2, param_2, 0.5f); return true; } @@ -1749,7 +1749,7 @@ bool cM3d_Cross_CpsCyl(cM3dGCps const& cps, cM3dGCyl const& cyl, Vec* param_2) { cM3dGSph sph; f32 tmp2; sph.SetR(cps.GetR()); - sph.SetC(cps.GetStartP()); + sph.SetC(*cps.GetStartP()); return cM3d_Cross_CylSph(&cyl, &sph, param_2, &tmp2); } else if (iVar2 == 2) { if (f1 >= 0.0f && f1 <= 1.0f && f2 >= 0.0f && f2 <= 1.0f) { @@ -1818,8 +1818,8 @@ static void cM3d_Cross_CpsSph_CrossPos(cM3dGCps const& param_1, cM3dGSph const& if (iVar5 == 1) { *param_4 = aVStack_70; } else if (iVar5 == 2) { - f32 dVar8 = VECSquareDistance(&aVStack_70, ¶m_1.GetStartP()); - f32 dVar9 = VECSquareDistance(&VStack_7c, ¶m_1.GetStartP()); + f32 dVar8 = VECSquareDistance(&aVStack_70, param_1.GetStartP()); + f32 dVar9 = VECSquareDistance(&VStack_7c, param_1.GetStartP()); if (dVar8 < dVar9) { *param_4 = aVStack_70; } else { @@ -1840,14 +1840,14 @@ static void cM3d_Cross_CpsSph_CrossPos(cM3dGCps const& param_1, cM3dGSph const& bool cM3d_Cross_CpsSph(cM3dGCps const& param_1, cM3dGSph const& param_2, Vec* param_3) { - f32 local_38 = VECDistance(¶m_1.GetStartP(), param_2.GetCP()); + f32 local_38 = VECDistance(param_1.GetStartP(), param_2.GetCP()); if (local_38 < param_1.GetR() + param_2.GetR()) { - cM3d_Cross_CpsSph_CrossPos(param_1, param_2, param_1.GetStartP(), param_3); + cM3d_Cross_CpsSph_CrossPos(param_1, param_2, *param_1.GetStartP(), param_3); return true; } - local_38 = VECDistance(¶m_1.GetEndP(), param_2.GetCP()); + local_38 = VECDistance(param_1.GetEndP(), param_2.GetCP()); if (local_38 < param_1.GetR() + param_2.GetR()) { - cM3d_Cross_CpsSph_CrossPos(param_1, param_2, param_1.GetEndP(), param_3); + cM3d_Cross_CpsSph_CrossPos(param_1, param_2, *param_1.GetEndP(), param_3); return true; } Vec auStack_34; @@ -1922,13 +1922,13 @@ inline f32 cM3d_2LinCenter(cM3dGLin const& pLinA, f32 pLinAF, cM3dGLin const& pL bool cM3d_Cross_CpsTri(cM3dGCps const& cps, cM3dGTri tri, Vec* param_2) { cM3dGSph sph; - sph.SetC(cps.GetStartP()); + sph.SetC(*cps.GetStartP()); sph.SetR(cps.GetR()); if (cM3d_Cross_SphTri(&sph, &tri, param_2)) { return true; } - sph.SetC(cps.GetEndP()); + sph.SetC(*cps.GetEndP()); sph.SetR(cps.GetR()); if (cM3d_Cross_SphTri(&sph, &tri, param_2)) { return true; @@ -2044,25 +2044,25 @@ static int cM3d_2PlaneCrossLine(const cM3dGPla& pPlaneA, const cM3dGPla& pPlaneB if (absTX >= absTY && absTX >= absTZ) { cM3d_PlaneCrossLineProcWork(pPlaneA.GetNP()->y, pPlaneA.GetNP()->z, pPlaneB.GetNP()->y, pPlaneB.GetNP()->z, tmp.x, pPlaneA.GetD(), pPlaneB.GetD(), - &pLinOut->GetStartP().y, &pLinOut->GetStartP().z); - pLinOut->GetStartP().x = 0.0f; + &pLinOut->GetStartP()->y, &pLinOut->GetStartP()->z); + pLinOut->GetStartP()->x = 0.0f; } else if (absTY >= absTX && absTY >= absTZ) { cM3d_PlaneCrossLineProcWork(pPlaneA.GetNP()->z, pPlaneA.GetNP()->x, pPlaneB.GetNP()->z, pPlaneB.GetNP()->x, tmp.y, pPlaneA.GetD(), pPlaneB.GetD(), - &pLinOut->GetStartP().z, &pLinOut->GetStartP().x); - pLinOut->GetStartP().y = 0.0f; + &pLinOut->GetStartP()->z, &pLinOut->GetStartP()->x); + pLinOut->GetStartP()->y = 0.0f; } else { cM3d_PlaneCrossLineProcWork(pPlaneA.GetNP()->x, pPlaneA.GetNP()->y, pPlaneB.GetNP()->x, pPlaneB.GetNP()->y, tmp.z, pPlaneA.GetD(), pPlaneB.GetD(), - &pLinOut->GetStartP().x, &pLinOut->GetStartP().y); - pLinOut->GetStartP().z = 0.0f; + &pLinOut->GetStartP()->x, &pLinOut->GetStartP()->y); + pLinOut->GetStartP()->z = 0.0f; } - f32 scale = VECMag(&pLinOut->GetStartP()); + f32 scale = VECMag(pLinOut->GetStartP()); if (cM3d_IsZero(scale)) { scale = 1.0f; } VECScale(&tmp, &tmp, scale); - VECAdd(&pLinOut->GetStartP(), &tmp, &pLinOut->GetEndP()); + VECAdd(pLinOut->GetStartP(), &tmp, pLinOut->GetEndP()); return 1; } } @@ -2073,10 +2073,10 @@ BOOL cM3d_3PlaneCrossPos(const cM3dGPla& pPlaneA, const cM3dGPla& pPlaneB, const if (!cM3d_2PlaneCrossLine(pPlaneA, pPlaneB, &lin)) { return false; } else { - const Vec* end = &lin.GetEndP(); - f32 tmpf1 = pPlaneC.getPlaneFunc(&lin.GetStartP()); + const Vec* end = lin.GetEndP(); + f32 tmpf1 = pPlaneC.getPlaneFunc(lin.GetStartP()); f32 tmpf2 = pPlaneC.getPlaneFunc(end); - if (!cM3d_CrossInfLineVsInfPlane_proc(tmpf1, tmpf2, &lin.GetStartP(), end, pVecOut)) { + if (!cM3d_CrossInfLineVsInfPlane_proc(tmpf1, tmpf2, lin.GetStartP(), end, pVecOut)) { return false; } else { return true; @@ -2094,10 +2094,10 @@ f32 cM3d_lineVsPosSuisenCross(const cM3dGLin* pLine, const Vec* pPoint, Vec* pVe *pVecOut = *pPoint; return 0.0f; } else { - VECSubtract(pPoint, &pLine->GetStartP(), &tmp2); + VECSubtract(pPoint, pLine->GetStartP(), &tmp2); f32 retVal = VECDotProduct(&tmp2, &tmp1) / diffLen; VECScale(&tmp1, &tmp3, retVal); - VECAdd(&tmp3, &pLine->GetStartP(), pVecOut); + VECAdd(&tmp3, pLine->GetStartP(), pVecOut); return retVal; } } diff --git a/src/Z2AudioLib/Z2SceneMgr.cpp b/src/Z2AudioLib/Z2SceneMgr.cpp index 9e3bf2c91c..300da403b2 100644 --- a/src/Z2AudioLib/Z2SceneMgr.cpp +++ b/src/Z2AudioLib/Z2SceneMgr.cpp @@ -1718,11 +1718,16 @@ void Z2SceneMgr::setSceneName(char* spot, s32 room, s32 layer) { if (Z2GetSoundMgr()->getStreamMgr()->isActive()) { JAUSoundTable* sound_table = JAUSoundTable::getInstance(); - JSUList* stream_list = Z2GetSoundMgr()->getStreamMgr()->getStreamList(); - JSULink* stream; - for (stream = stream_list->getFirst(); stream != NULL; stream = stream->getNext()) { - if (bVar2 || sound_table->getTypeID(stream->getObject()->getID()) != 0x71) { - stream->getObject()->stop(Z2Param::SCENE_CHANGE_BGM_FADEOUT_TIME); +#if DUSK_AUDIO_DISABLED + if (sound_table->isValid()) +#endif + { + JSUList* stream_list = Z2GetSoundMgr()->getStreamMgr()->getStreamList(); + JSULink* stream; + for (stream = stream_list->getFirst(); stream != NULL; stream = stream->getNext()) { + if (bVar2 || sound_table->getTypeID(stream->getObject()->getID()) != 0x71) { + stream->getObject()->stop(Z2Param::SCENE_CHANGE_BGM_FADEOUT_TIME); + } } } } diff --git a/src/Z2AudioLib/Z2SoundObject.cpp b/src/Z2AudioLib/Z2SoundObject.cpp index 4581ca389e..1c81be0f17 100644 --- a/src/Z2AudioLib/Z2SoundObject.cpp +++ b/src/Z2AudioLib/Z2SoundObject.cpp @@ -136,6 +136,8 @@ Z2SoundHandlePool* Z2SoundObjBase::startSound(JAISoundID soundID, u32 mapinfo, s } Z2SoundHandlePool* Z2SoundObjBase::startLevelSound(JAISoundID soundID, u32 mapinfo, s8 reverb) { + DUSK_AUDIO_SKIP(NULL); + if (!alive_) { return NULL; } diff --git a/src/d/actor/d_a_alink.cpp b/src/d/actor/d_a_alink.cpp index 493d788a52..54766adfc7 100644 --- a/src/d/actor/d_a_alink.cpp +++ b/src/d/actor/d_a_alink.cpp @@ -15717,7 +15717,7 @@ int daAlink_c::procMoveTurnInit(int param_0) { dComIfGp_setPlayerStatus0(0, 0x800); if (param_0 != 0) { - mProcVar3.field_0x300e = (mpHIO->mMove.m.mMaxTurnAngle * 4) + 19030; + mProcVar3.field_0x300e = (s16)((mpHIO->mMove.m.mMaxTurnAngle * 4) + 19030); mProcVar4.field_0x3010 = mpHIO->mMove.m.mMaxTurnAngle * 2; mProcVar1.field_0x300a = 2; current.angle.y = mMoveAngle; diff --git a/src/d/actor/d_a_b_bq.cpp b/src/d/actor/d_a_b_bq.cpp index 07b2ca4439..f109c11509 100644 --- a/src/d/actor/d_a_b_bq.cpp +++ b/src/d/actor/d_a_b_bq.cpp @@ -1872,7 +1872,7 @@ static void demo_camera(b_bq_class* i_this) { spFC.set(BREG_F(5) + -30.0f, 0.0f, BREG_F(6) + 1938.0f); } - daPy_getPlayerActorClass()->setPlayerPosAndAngle(&spFC, BREG_S(5) + 0x8000, 0); + daPy_getPlayerActorClass()->setPlayerPosAndAngle(&spFC, (s16)(BREG_S(5) + 0x8000), 0); if (i_this->field_0x5c8 != 0) { i_this->field_0x5cc.y += i_this->field_0x5d8; diff --git a/src/d/actor/d_a_b_mgn.cpp b/src/d/actor/d_a_b_mgn.cpp index e9c2235039..169db10cd3 100644 --- a/src/d/actor/d_a_b_mgn.cpp +++ b/src/d/actor/d_a_b_mgn.cpp @@ -1325,6 +1325,7 @@ void daB_MGN_c::executeDash() { } if (mMoveMode == 11) { + // @bug - parenthesis should not be on the condition if (abs((s16)(angle - field_0xa90) < 0x1800) != 0) { if ((s16)(angle - field_0xa90) < 0) { angle = field_0xa90 - 0x1800; diff --git a/src/d/actor/d_a_bg_obj.cpp b/src/d/actor/d_a_bg_obj.cpp index c7f5280df1..4c7fb4d03e 100644 --- a/src/d/actor/d_a_bg_obj.cpp +++ b/src/d/actor/d_a_bg_obj.cpp @@ -881,7 +881,7 @@ void daBgObj_c::setParticle() { for (; partNum != 0; partNum--) { u32 flags = *(BE(u32)*)partBlockItems++; u16 res_id = *(BE(u32)*)partBlockItems; - *partBlockItems++; + partBlockItems++; GXColor prmColor = { 0xFF, 0xFF, 0xFF, 0xFF }; GXColor envColor = { 0xFF, 0xFF, 0xFF, 0xFF }; diff --git a/src/d/actor/d_a_door_boss.cpp b/src/d/actor/d_a_door_boss.cpp index c1a135d42a..476a9c8ad6 100644 --- a/src/d/actor/d_a_door_boss.cpp +++ b/src/d/actor/d_a_door_boss.cpp @@ -254,7 +254,7 @@ BOOL daBdoor_c::checkArea() { if (fabsf(vec.z) > 100.0f) { return false; } - return (s16)fabs(current.angle.y - 0x7fff - player->current.angle.y) <= 0x4000 ? 1 : 0; + return (s16)fabs((f64)(current.angle.y - 0x7fff - player->current.angle.y)) <= 0x4000 ? 1 : 0; } BOOL daBdoor_c::checkFront() { diff --git a/src/d/actor/d_a_door_bossL1.cpp b/src/d/actor/d_a_door_bossL1.cpp index f187412a0b..a756cc6fd2 100644 --- a/src/d/actor/d_a_door_bossL1.cpp +++ b/src/d/actor/d_a_door_bossL1.cpp @@ -825,7 +825,7 @@ int daBdoorL1_c::checkArea() { if (fabsf(local_48.z) > 100.0f) { return 0; } - if ((s16)fabs(current.angle.y - 0x7fff - player->current.angle.y) <= 0x4000) { + if ((s16)fabs((f64)(current.angle.y - 0x7fff - player->current.angle.y)) <= 0x4000) { return 1; } else { return 0; diff --git a/src/d/actor/d_a_door_bossL5.cpp b/src/d/actor/d_a_door_bossL5.cpp index 3299c91216..d71fddad1f 100644 --- a/src/d/actor/d_a_door_bossL5.cpp +++ b/src/d/actor/d_a_door_bossL5.cpp @@ -348,7 +348,7 @@ int daBdoorL5_c::checkArea() { if (fabsf(local_48.z) > 100.0f) { return 0; } - if ((s16)fabs(current.angle.y - 0x7fff - player->current.angle.y) <= 0x4000) { + if ((s16)fabs((f64)(current.angle.y - 0x7fff - player->current.angle.y)) <= 0x4000) { return 1; } else { return 0; diff --git a/src/d/actor/d_a_door_mbossL1.cpp b/src/d/actor/d_a_door_mbossL1.cpp index a42aabd022..1f37fbcc7b 100644 --- a/src/d/actor/d_a_door_mbossL1.cpp +++ b/src/d/actor/d_a_door_mbossL1.cpp @@ -1318,7 +1318,7 @@ int daMBdoorL1_c::checkArea() { return 0; } - if ((s16)fabs(angle - 0x7fff - player->current.angle.y) > 0x4000) { + if ((s16)fabs((f64)(angle - 0x7fff - player->current.angle.y)) > 0x4000) { return 0; } else { return 1; diff --git a/src/d/actor/d_a_door_push.cpp b/src/d/actor/d_a_door_push.cpp index aac4ebde8b..78e9156294 100644 --- a/src/d/actor/d_a_door_push.cpp +++ b/src/d/actor/d_a_door_push.cpp @@ -11,7 +11,7 @@ #include "f_pc/f_pc_name.h" #include "f_op/f_op_actor_mng.h" -static void PPCallBack(fopAc_ac_c* i_this, fopAc_ac_c* i_unused, s16 i_unused2, +static fopAc_ac_c* PPCallBack(fopAc_ac_c* i_this, fopAc_ac_c* i_unused, s16 i_unused2, dBgW_Base::PushPullLabel param_3) { if (cLib_checkBit(param_3, dBgW_Base::PPLABEL_PUSH) != 0) { daDoorPush_c* l_this = (daDoorPush_c*)i_this; @@ -19,9 +19,11 @@ static void PPCallBack(fopAc_ac_c* i_this, fopAc_ac_c* i_unused, s16 i_unused2, l_this->field_0x62e[1] = 0; l_this->field_0x62c[0] = 1; } + + return i_this; } -static void PPCallBack2(fopAc_ac_c* i_this, fopAc_ac_c* i_unused, s16 i_unused2, +static fopAc_ac_c* PPCallBack2(fopAc_ac_c* i_this, fopAc_ac_c* i_unused, s16 i_unused2, dBgW_Base::PushPullLabel param_3) { if (cLib_checkBit(param_3, dBgW_Base::PPLABEL_PUSH) != 0) { daDoorPush_c* l_this = (daDoorPush_c*)i_this; @@ -29,6 +31,8 @@ static void PPCallBack2(fopAc_ac_c* i_this, fopAc_ac_c* i_unused, s16 i_unused2, l_this->field_0x62e[0] = 0; l_this->field_0x62c[1] = 1; } + + return i_this; } void daDoorPush_c::initBaseMtx() { diff --git a/src/d/actor/d_a_e_hz.cpp b/src/d/actor/d_a_e_hz.cpp index 86a0260e91..f2fb7d12b8 100644 --- a/src/d/actor/d_a_e_hz.cpp +++ b/src/d/actor/d_a_e_hz.cpp @@ -1934,7 +1934,13 @@ int daE_HZ_c::CreateHeap() { return 0; } + // This happens to work with MWCC since the member will only ever be initialized a pointer to a + // string in this TU's .data section, but comparing against a string literal is still UB. +#if AVOID_UB + if (strcmp(mpName, "E_hzp") == 0) { +#else if (mpName == "E_hzp") { +#endif modelData = (J3DModelData*)dComIfG_getObjectRes(mpName, 3); } else { modelData = (J3DModelData*)dComIfG_getObjectRes(mpName, 3); diff --git a/src/d/actor/d_a_e_kr.cpp b/src/d/actor/d_a_e_kr.cpp index de277a0e33..f21c83b50a 100644 --- a/src/d/actor/d_a_e_kr.cpp +++ b/src/d/actor/d_a_e_kr.cpp @@ -496,6 +496,7 @@ static s8 e_kr_path_move(e_kr_class* i_this) { if (totalDiff < 10.0f * TREG_F(10) + 300.0f) { point = &i_this->field_0x6e4->m_points[i_this->field_0x6e2]; u8 pointArg1 = point->mArg1; + // !@bug Comparison of u8 with -1 will always evaluate to false if (pointArg1 == -1) { i_this->field_0x684 = 50.0f * 1.2f; } else { diff --git a/src/d/actor/d_a_e_mm_mt.cpp b/src/d/actor/d_a_e_mm_mt.cpp index b745fa31c9..205cebab78 100644 --- a/src/d/actor/d_a_e_mm_mt.cpp +++ b/src/d/actor/d_a_e_mm_mt.cpp @@ -370,7 +370,7 @@ static void e_mm_mt_drop(e_mm_mt_class* i_this) { i_this->enemy.speed.y += -5.0f; i_this->enemy.eyePos = i_this->enemy.current.pos; i_this->enemy.attention_info.position = i_this->enemy.current.pos; - cLib_addCalcAngleS2(&i_this->m_rotation.z, (TREG_S(6)+0x10000)-0x8000, 1, 0x1000); + cLib_addCalcAngleS2(&i_this->m_rotation.z, (s16)((TREG_S(6) + 0x10000) - 0x8000), 1, 0x1000); cLib_onBit(i_this->enemy.attention_info.flags, fopAc_AttnFlag_CARRY_e); i_this->enemy.attention_info.distances[fopAc_attn_CARRY_e] = 7; i_this->m_rotation.y += i_this->m_spin; diff --git a/src/d/actor/d_a_e_oc.cpp b/src/d/actor/d_a_e_oc.cpp index 0403896e70..01f282b0ea 100644 --- a/src/d/actor/d_a_e_oc.cpp +++ b/src/d/actor/d_a_e_oc.cpp @@ -724,7 +724,13 @@ void daE_OC_c::damage_check() { } else if (mAtInfo.mpCollider->ChkAtType(AT_TYPE_40)) { S16_ADD(health, 10); } else if (mAtInfo.mpCollider->ChkAtType(AT_TYPE_SLINGSHOT)) { + // This happens to work with MWCC since the member will only ever be initialized a pointer to a + // string in this TU's .data section, but comparing against a string literal is still UB. +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif S16_SUB(health, 5); if (health < 0) { health = 0; @@ -855,7 +861,12 @@ void daE_OC_c::setDashSound() { } else if (mpMorf->checkFrame(8.5f)) { mSound.startCreatureSound(Z2SE_EN_OC_FOOTNOTE_R, 0, -1); } + // See comment in damage_check +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif mSound.startCreatureSoundLevel(Z2SE_EN_OC_CLUB_DAGGLE, 0, -1); } else { mSound.startCreatureSoundLevel(Z2SE_EN_OC_NATA_DAGGLE, 0, -1); @@ -1421,7 +1432,12 @@ void daE_OC_c::executeAttack() { } else if (mpMorf->checkFrame(12.5f)) { mSound.startCreatureSound(Z2SE_EN_OC_ATTACK_B, 0, -1); } else if (mpMorf->checkFrame(19.0f)) { + // See comment in damage_check +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif mSound.startCreatureSound(Z2SE_EN_OC_CLUB_HIT, 0, -1); } else { mSound.startCreatureSound(Z2SE_EN_OC_NATA_HIT, 0, -1); @@ -1843,7 +1859,12 @@ void daE_OC_c::executeDeath() { case 2: cLib_chaseF(&speedF, 0.0f, 1.0f); if (field_0x6c0 == 0) { + // See comment in damage_check +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif fopAcM_createDisappear(this, ¤t.pos, 10, 0, 4); } else { fopAcM_createDisappear(this, ¤t.pos, 10, 0, 0x34); @@ -1917,7 +1938,12 @@ void daE_OC_c::executeWaterDeath() { } if (mpMorf->isStop()) { + // See comment in damage_check +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif fopAcM_createDisappear(this, ¤t.pos, 10, 0, 4); } else { fopAcM_createDisappear(this, ¤t.pos, 10, 0, 0x34); @@ -2741,7 +2767,12 @@ cPhs_Step daE_OC_c::create() { mAcchCir.SetWallH(70.0f); } mAcchCir.SetWallR(100.0f); + // See comment in damage_check +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif field_0x560 = health = 40; } else { field_0x560 = health = 220; @@ -2756,7 +2787,12 @@ cPhs_Step daE_OC_c::create() { mSphs_at[0].SetStts(&mStts); mSphs_at[1].Set(E_OC_n::at_sph_src); mSphs_at[1].SetStts(&mStts); + // See comment in damage_check +#if AVOID_UB + if (strcmp(mName, "E_OC") == 0) { +#else if (mName == "E_OC") { +#endif mSphs_at[0].SetAtAtp(1); mSphs_at[1].SetAtAtp(1); fopAcM_OnStatus(this, fopAcStts_UNK_0x10000_e); diff --git a/src/d/actor/d_a_e_rdy.cpp b/src/d/actor/d_a_e_rdy.cpp index 4e13d7e3ed..305fc55efe 100644 --- a/src/d/actor/d_a_e_rdy.cpp +++ b/src/d/actor/d_a_e_rdy.cpp @@ -2155,7 +2155,7 @@ static void e_rdy_damage(e_rdy_class* i_this) { case 1: if (i_this->mAcch.ChkWallHit() && i_this->mTimer[0] == 0) { - if (check = kado_check(i_this)) { + if ((check = kado_check(i_this))) { OS_REPORT(" ..KADO KABE ..%x\n", check); if (check == 2) { i_this->field_0xac6 = 0x1000; @@ -4721,7 +4721,7 @@ static int daE_RDY_Execute(e_rdy_class* i_this) { } MTXCopy(i_this->mpMorf->getModel()->getAnmMtx(JNT_HAND_R), *calc_mtx); MtxTrans(20.0f + NREG_F(0), 5.0f + NREG_F(1), -10.0f + NREG_F(2), 1); - cMtx_XrotM(*calc_mtx, NREG_S(0) + 0x8000); + cMtx_XrotM(*calc_mtx, (s16)(NREG_S(0) + 0x8000)); cMtx_YrotM(*calc_mtx, NREG_S(1) + ang_y + -0x15cd); cMtx_ZrotM(*calc_mtx, NREG_S(2) + 0x28cd); i_this->mpHawkGrassModel->setBaseTRMtx(*calc_mtx); diff --git a/src/d/actor/d_a_e_wb.cpp b/src/d/actor/d_a_e_wb.cpp index 6ff349c4a6..819439879e 100644 --- a/src/d/actor/d_a_e_wb.cpp +++ b/src/d/actor/d_a_e_wb.cpp @@ -1100,7 +1100,7 @@ static void e_wb_f_run(e_wb_class* i_this) { } else { e_rd_class* local_90 = (e_rd_class*)fopAcM_SearchByID(i_this->rd_id); int saku; - if (saku = e_wb_saku_check(i_this)) { + if ((saku = e_wb_saku_check(i_this))) { i_this->field_0x6d4 = 60; if ((saku & 2) != 0) { i_this->field_0x6d6 = 0x3000; diff --git a/src/d/actor/d_a_e_yg.cpp b/src/d/actor/d_a_e_yg.cpp index 6e02f7cb0b..43f91ee793 100644 --- a/src/d/actor/d_a_e_yg.cpp +++ b/src/d/actor/d_a_e_yg.cpp @@ -1235,7 +1235,7 @@ static int daE_YG_Execute(e_yg_class* i_this) { MTXCopy(daPy_getLinkPlayerActorClass()->getWolfMouthMatrix(), mDoMtx_stack_c::get()); mDoMtx_stack_c::multVecZero(&actor->current.pos); mDoMtx_stack_c::YrotM(KREG_S(0)); - mDoMtx_stack_c::XrotM(KREG_S(1) + 0x8000); + mDoMtx_stack_c::XrotM((s16)(KREG_S(1) + 0x8000)); mDoMtx_stack_c::ZrotM(KREG_S(2) + 2500); mDoMtx_stack_c::transM(KREG_F(0) + 10.0f, KREG_F(1) + -60.0f, KREG_F(2) + -20.0f); model->setBaseTRMtx(mDoMtx_stack_c::get()); diff --git a/src/d/actor/d_a_e_yh.cpp b/src/d/actor/d_a_e_yh.cpp index d37bdd1749..bbbd3e5129 100644 --- a/src/d/actor/d_a_e_yh.cpp +++ b/src/d/actor/d_a_e_yh.cpp @@ -1930,7 +1930,7 @@ static void eff_set(e_yh_class* i_this) { dComIfGp_particle_set(i_this->mParticleIds2[2], dPa_RM(ID_ZI_S_YD_YODAHIT_A), &a_this->current.pos, 0, NULL); { - JPABaseEmitter* emitter = dComIfGp_particle_getEmitter(i_this->mParticleIds[5]); + JPABaseEmitter* emitter = dComIfGp_particle_getEmitter(i_this->mParticleIds2[2]); if (emitter != NULL) { MTXCopy(model->getAnmMtx(1), *calc_mtx); emitter->setGlobalRTMatrix(*calc_mtx); diff --git a/src/d/actor/d_a_e_ymb.cpp b/src/d/actor/d_a_e_ymb.cpp index 7a18b75a2c..e107b2a8b9 100644 --- a/src/d/actor/d_a_e_ymb.cpp +++ b/src/d/actor/d_a_e_ymb.cpp @@ -516,7 +516,7 @@ void daE_YMB_c::checkWaterPos() { field_0x6cc = wtr_pos; field_0x69c.y = wtr_pos + 1000.0f + l_HIO.fly_height_adjust; - std::fabsf(field_0x6cc - current.pos.y); + UNUSED(std::fabsf(field_0x6cc - current.pos.y)); if (current.pos.y < (200.0f + field_0x6cc)) { if (field_0x715 == 0) { setWaterEffect1(); diff --git a/src/d/actor/d_a_e_zh.cpp b/src/d/actor/d_a_e_zh.cpp index fb64be0f5e..827a8fd36a 100644 --- a/src/d/actor/d_a_e_zh.cpp +++ b/src/d/actor/d_a_e_zh.cpp @@ -542,7 +542,7 @@ bool daE_ZH_c::mBallBgLineCheck() { bool daE_ZH_c::mSearchMove(u8 param_1) { if (mS_Ball == NULL) { setActionMode(ACTION_EXECUTE_FLY_DELETE, 0); - return NULL; + return false; } cXyz sp50, sp5c; diff --git a/src/d/actor/d_a_horse.cpp b/src/d/actor/d_a_horse.cpp index 14090b75d6..976e398616 100644 --- a/src/d/actor/d_a_horse.cpp +++ b/src/d/actor/d_a_horse.cpp @@ -51,9 +51,10 @@ #define ANM_HS_WALK_FAST 34 #define ANM_HS_WALK_SLOW 35 -static f32* strippedFunc() { - f32 v[3] = {}; - return v; +static void strippedFunc() { + extern void F(f32*); + f32 v[3] = {0.0f}; + F(v); } static char const l_arcName[] = "Horse"; @@ -3447,17 +3448,25 @@ int daHorse_c::callHorseSubstance(cXyz const* i_pos) { if (m_path != NULL && (checkStateFlg0(FLG0_NO_DRAW_WAIT) || dist_xz2 > initDistance2)) { daAlink_c* player = daAlink_getAlinkActorClass(); - BE(Vec)* farthest_pos; - BE(Vec)* path_pnt_pos; - + #if TARGET_PC + Vec farthest_pos; + Vec path_pnt_pos; + f32 farthest_sqdist = 0; + #else + Vec* farthest_pos; + Vec* path_pnt_pos; + #endif + for (int i = 0; i < m_path->m_num; i++) { + #if TARGET_PC + path_pnt_pos = m_path->m_points[i].m_position; + f32 x_dist = path_pnt_pos.x - i_pos->x; + f32 z_dist = path_pnt_pos.z - i_pos->z; + #else path_pnt_pos = &m_path->m_points[i].m_position; f32 x_dist = path_pnt_pos->x - i_pos->x; f32 z_dist = path_pnt_pos->z - i_pos->z; f32 farthest_sqdist; - - #if AVOID_UB - farthest_sqdist = 0; #endif f32 sqdist = (x_dist * x_dist) + (z_dist * z_dist); @@ -3468,7 +3477,11 @@ int daHorse_c::callHorseSubstance(cXyz const* i_pos) { } } + #if TARGET_PC + cXyz pos(farthest_pos.x, farthest_pos.y, farthest_pos.z); + #else cXyz pos(farthest_pos->x, farthest_pos->y, farthest_pos->z); + #endif setHorsePosAndAngle(&pos, shape_angle.y); rt = 1; } else if (dist_xz2 <= SQUARE(800.0f)) { diff --git a/src/d/actor/d_a_kytag12.cpp b/src/d/actor/d_a_kytag12.cpp index f10c5774f0..58bd2963d9 100644 --- a/src/d/actor/d_a_kytag12.cpp +++ b/src/d/actor/d_a_kytag12.cpp @@ -704,8 +704,13 @@ static int daKytag12_Execute_R00(kytag12_class* i_this) { daPy_py_c* player = (daPy_py_c*)dComIfGp_getPlayer(0); dKankyo_evil_Packet* temp_r25 = dKy_getEnvlight()->mpEvilPacket; +#if AVOID_UB + f32 var_f26 = 0; + f32 var_f25 = 0; +#else f32 var_f26; f32 var_f25; +#endif int var_r24 = 0; diff --git a/src/d/actor/d_a_mg_rod.cpp b/src/d/actor/d_a_mg_rod.cpp index 1fae2979fe..96ad7aa148 100644 --- a/src/d/actor/d_a_mg_rod.cpp +++ b/src/d/actor/d_a_mg_rod.cpp @@ -2977,8 +2977,8 @@ static void hook_set(dmg_rod_class* i_this, cXyz* param_1, int param_2) { mDoMtx_stack_c::XrotM(-0x4000); if (param_2 == 1 && (i_this->action <= ACTION_LURE_STANDBY || (i_this->lure_type != MG_LURE_SP && i_this->action == ACTION_LURE_CATCH))) { - sp38.x = fabsf(hook->field_0x18.y); - sp38.z = fabsf(hook->field_0x18.x - 0x4000); + sp38.x = fabsf((f32)hook->field_0x18.y); + sp38.z = fabsf((f32)(hook->field_0x18.x - 0x4000)); f32 var_f31 = JMAFastSqrt(SQUARE(sp38.x) + SQUARE(sp38.z)); if (var_f31 > 7000.0f) { diff --git a/src/d/actor/d_a_mirror.cpp b/src/d/actor/d_a_mirror.cpp index b66a095d5c..5468d70f87 100644 --- a/src/d/actor/d_a_mirror.cpp +++ b/src/d/actor/d_a_mirror.cpp @@ -208,6 +208,9 @@ void dMirror_packet_c::modelDraw(J3DModel* i_model, Mtx param_1) { color.a = kankyo->bg_amb_col[0].a; J3DModelData* modelData = i_model->getModelData(); +#if TARGET_PC + j3dSys.setTexture(modelData->getTexture()); +#endif u16 materialNum = modelData->getMaterialNum(); for (u16 i = 0; i < materialNum; i++) { J3DMatPacket* matPacket = i_model->getMatPacket(i); diff --git a/src/d/actor/d_a_nbomb.cpp b/src/d/actor/d_a_nbomb.cpp index 070fdc2c7f..4a185c9561 100644 --- a/src/d/actor/d_a_nbomb.cpp +++ b/src/d/actor/d_a_nbomb.cpp @@ -986,7 +986,7 @@ BOOL daNbomb_c::procWait() { speedF *= player->getBombBoundRate(); current.angle.y = (mAcchCir.GetWallAngleY() * 2) - (current.angle.y + 0x8000); } else if (mAcch.ChkGroundLanding() && speedF > 5.0f && cM_deg2s(50.0f) <= field_0xb5a) { - if ((f32)fabs(var_r28) >= (f32)0x4000) { + if ((f32)fabs((f64)var_r28) >= (f32)0x4000) { speedF *= player->getBombBoundRate(); current.angle.y = (var_r27 * 2) - (current.angle.y + 0x8000); mAcch.ClrGroundLanding(); diff --git a/src/d/actor/d_a_npc.cpp b/src/d/actor/d_a_npc.cpp index 123bf66800..b903ce8c8f 100644 --- a/src/d/actor/d_a_npc.cpp +++ b/src/d/actor/d_a_npc.cpp @@ -2695,9 +2695,15 @@ BOOL daNpcT_chkActorInScreen(fopAc_ac_c* i_ActorP, f32 param_1, f32 param_2, f32 for (int i = 0; i < 8; i++) { mDoLib_project(&pos_array[i], &proj); +#if TARGET_PC + if (0.0f < proj.x && proj.x < mDoGph_gInf_c::getWidth() && 0.0f < proj.y && proj.y < mDoGph_gInf_c::getHeight()) { + continue; + } +#else if (0.0f < proj.x && proj.x < FB_WIDTH && 0.0f < proj.y && proj.y < FB_HEIGHT) { continue; } +#endif return false; } diff --git a/src/d/actor/d_a_npc2.cpp b/src/d/actor/d_a_npc2.cpp index 9d5d0beee8..f629c0b562 100644 --- a/src/d/actor/d_a_npc2.cpp +++ b/src/d/actor/d_a_npc2.cpp @@ -544,7 +544,7 @@ void daBaseNpc_c::orderEvent(int param_0, char* i_evtName) { if (i_evtName != NULL) { mEvtIdx = dComIfGp_getEventManager().getEventIdx(this, i_evtName, -1); fopAcM_orderOtherEventId(this, mEvtIdx, 0xFF, 0xFFFF, 0, 1); - } else if (field_0x848 >= 0 && attention_info.flags == (fopAc_AttnFlag_SPEAK_e | fopAc_AttnFlag_TALK_e)) { + } else if (mFlowID >= 0 && attention_info.flags == (fopAc_AttnFlag_SPEAK_e | fopAc_AttnFlag_TALK_e)) { eventInfo.onCondition(1); if (param_0 != 0) { fopAcM_orderSpeakEvent(this, 0, 0); diff --git a/src/d/actor/d_a_npc_bou.cpp b/src/d/actor/d_a_npc_bou.cpp index f5b94392e5..775bfd7c4c 100644 --- a/src/d/actor/d_a_npc_bou.cpp +++ b/src/d/actor/d_a_npc_bou.cpp @@ -635,7 +635,7 @@ void daNpc_Bou_c::action() { hit_actor = field_0xba0.getActorP(); if (hit_actor != NULL) { - abs( (s16)(fopAcM_searchPlayerAngleY(this) - mCurAngle.y) ); + UNUSED(abs((s16)(fopAcM_searchPlayerAngleY(this) - mCurAngle.y))); switch (((daTag_Push_c*) hit_actor)->getId()) { case 7: { mEvtNo = 8; diff --git a/src/d/actor/d_a_npc_chat.cpp b/src/d/actor/d_a_npc_chat.cpp index 8a963d2497..39ebb0313c 100644 --- a/src/d/actor/d_a_npc_chat.cpp +++ b/src/d/actor/d_a_npc_chat.cpp @@ -2628,7 +2628,7 @@ BOOL daNpcChat_c::setAttention(int param_1) { cXyz(0.0f, 10.0f, 0.0f), }; - int jointNo = isM_() ? JNTM_HEAD : JNTW_HEAD; + int jointNo = isM_() ? (int)JNTM_HEAD : (int)JNTW_HEAD; mDoMtx_stack_c::copy(mAnm_p->getModel()->getAnmMtx(jointNo)); mDoMtx_stack_c::multVec(&a_eyeOfsTbl[param_1], &eyePos); mBaseAttnPos.set(current.pos.x, current.pos.y + AtnOfs(param_1), current.pos.z); diff --git a/src/d/actor/d_a_npc_coach.cpp b/src/d/actor/d_a_npc_coach.cpp index abd3dac290..51a5019088 100644 --- a/src/d/actor/d_a_npc_coach.cpp +++ b/src/d/actor/d_a_npc_coach.cpp @@ -517,8 +517,7 @@ BOOL daNpcChPath_c::setPath(int path_index, int room_no, cXyz& i_vec, bool param mCurrentID = path_index; mPntIndex = 0; - // Is this really what the Nintendo devs wrote?? The debug ROM suggests as such. - if (param_4 && &i_vec) { + if (param_4 && IS_REF_NONNULL(i_vec)) { f32 fVar1 = G_CM3D_F_INF; for (int pnt_index = 0; pnt_index < mpPath->m_num; pnt_index++) { dPnt* pnt = dPath_GetPnt(mpPath, pnt_index); @@ -534,8 +533,7 @@ BOOL daNpcChPath_c::setPath(int path_index, int room_no, cXyz& i_vec, bool param field_0x8 = G_CM3D_F_INF; - // ditto. - if (&i_vec) { + if (IS_REF_NONNULL(i_vec)) { field_0x4 = &i_vec; cXyz targetPoint; getTargetPoint(targetPoint); diff --git a/src/d/actor/d_a_npc_gra.cpp b/src/d/actor/d_a_npc_gra.cpp index 03c6e2279b..e1db3b4568 100644 --- a/src/d/actor/d_a_npc_gra.cpp +++ b/src/d/actor/d_a_npc_gra.cpp @@ -343,10 +343,13 @@ BOOL daNpc_grA_c::create() { mType = getTypeFromParam(); mMode = getMode(); mSwBit = getSwBit(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xffff) { - field_0x146C = home.angle.x; + mFlowID = home.angle.x; } else{ - field_0x146C = -1; + mFlowID = -1; } if (isDelete()) { return cPhs_ERROR_e; @@ -2146,7 +2149,7 @@ BOOL daNpc_grA_c::ECut_talkSpa(int i_staffID) { setLookMode(5); break; case 1: - initTalk(field_0x146C, arr); + initTalk(mFlowID, arr); break; case 2: if (daNpcF_chkEvtBit(6) && daNpcF_chkEvtBit(0x3e) == FALSE) { @@ -3020,7 +3023,7 @@ BOOL daNpc_grA_c::ECut_rollRockCrash(int i_staffID) { break; case 0x14: { setLookMode(0); - initTalk(field_0x146C, NULL); + initTalk(mFlowID, NULL); cXyz c(200.0f, 100.0f, 0.0f); mDoMtx_stack_c::YrotS(home.angle.y); mDoMtx_stack_c::multVec(&c, &c); @@ -3588,7 +3591,7 @@ BOOL daNpc_grA_c::waitSpaWater(void*) { } setLookMode(0); mTurnMode = 0; - field_0x146C = 0x28; + mFlowID = 0x28; field_0x1472 = 2; field_0x9ea = 1; // fallthrough @@ -3968,7 +3971,7 @@ BOOL daNpc_grA_c::talk(void*) { setGateWalk(); } } else { - r27 = field_0x146C; + r27 = mFlowID; } initTalk(r27, NULL); field_0x1484 = fopAcM_searchPlayerAngleY(this); diff --git a/src/d/actor/d_a_npc_grc.cpp b/src/d/actor/d_a_npc_grc.cpp index cf4a2b58a7..f41578bcaa 100644 --- a/src/d/actor/d_a_npc_grc.cpp +++ b/src/d/actor/d_a_npc_grc.cpp @@ -308,6 +308,9 @@ cPhs_Step daNpc_grC_c::create() { mTwilight = dKy_darkworld_check(); mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { mFlowID = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_grd.cpp b/src/d/actor/d_a_npc_grd.cpp index 5075c0b22a..8f006bf4cf 100644 --- a/src/d/actor/d_a_npc_grd.cpp +++ b/src/d/actor/d_a_npc_grd.cpp @@ -172,6 +172,9 @@ int daNpc_Grd_c::create() { mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xffff) { mFlowID = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_gro.cpp b/src/d/actor/d_a_npc_gro.cpp index 7b20d908d4..785136559f 100644 --- a/src/d/actor/d_a_npc_gro.cpp +++ b/src/d/actor/d_a_npc_gro.cpp @@ -396,6 +396,9 @@ cPhs_Step daNpc_grO_c::create() { mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { mMsgNo = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_grr.cpp b/src/d/actor/d_a_npc_grr.cpp index 4942aec8ae..39689144f4 100644 --- a/src/d/actor/d_a_npc_grr.cpp +++ b/src/d/actor/d_a_npc_grr.cpp @@ -264,6 +264,9 @@ cPhs_Step daNpc_grR_c::create() { mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { mFlowID = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_grs.cpp b/src/d/actor/d_a_npc_grs.cpp index 1ab19544cf..401634d2ab 100644 --- a/src/d/actor/d_a_npc_grs.cpp +++ b/src/d/actor/d_a_npc_grs.cpp @@ -138,10 +138,13 @@ int daNpc_grS_c::create() { mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xffff) { - field_0xe0c = home.angle.x; + mFlowID = home.angle.x; } else { - field_0xe0c = -1; + mFlowID = -1; } if (isDelete()) { @@ -856,7 +859,7 @@ int daNpc_grS_c::selectAction() { mpNextActionFn = &daNpc_grS_c::test; } else { - (int)mType; + UNUSED((int)mType); mpNextActionFn = &daNpc_grS_c::wait; } @@ -936,7 +939,7 @@ int daNpc_grS_c::doEvent() { if (eventInfo.checkCommandDemoAccrpt() && mEventIdx != -1 && eventManager->endCheck(mEventIdx)) { - (int)mOrderEvtNo; + UNUSED((int)mOrderEvtNo); dComIfGp_event_reset(); mOrderEvtNo = 0; mEventIdx = -1; @@ -1157,7 +1160,7 @@ int daNpc_grS_c::talk(void* param_0) { daNpcF_offTmpBit(11); } - unkInt1 = field_0xe0c; + unkInt1 = mFlowID; mIsSpeaking = false; initTalk(unkInt1, NULL); mTurnMode = 0; diff --git a/src/d/actor/d_a_npc_grz.cpp b/src/d/actor/d_a_npc_grz.cpp index e417f1d47b..c245340c4c 100644 --- a/src/d/actor/d_a_npc_grz.cpp +++ b/src/d/actor/d_a_npc_grz.cpp @@ -455,6 +455,9 @@ cPhs_Step daNpc_Grz_c::create() { mType = getTypeFromParam(); mSwNo = fopAcM_GetParam(this) >> 16; + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { mMsgNo = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_gwolf.cpp b/src/d/actor/d_a_npc_gwolf.cpp index 45c1025e0e..9956468e41 100644 --- a/src/d/actor/d_a_npc_gwolf.cpp +++ b/src/d/actor/d_a_npc_gwolf.cpp @@ -291,10 +291,13 @@ cPhs_Step daNpc_GWolf_c::create() { mExitId = fopAcM_GetParam(this) >> 24; + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { - field_0xe08 = home.angle.x; + mFlowID = home.angle.x; } else { - field_0xe08 = -1; + mFlowID = -1; } swBit = getSwBitFromParam(); @@ -1817,7 +1820,7 @@ BOOL daNpc_GWolf_c::talk(void* param_1) { break; } - int msgNo = field_0xe08; + int msgNo = mFlowID; mOrderSpeakEvt = false; initTalk(msgNo, NULL); mTurnMode = 0; diff --git a/src/d/actor/d_a_npc_kn.cpp b/src/d/actor/d_a_npc_kn.cpp index 3a39a0b196..63db584cda 100644 --- a/src/d/actor/d_a_npc_kn.cpp +++ b/src/d/actor/d_a_npc_kn.cpp @@ -4961,11 +4961,11 @@ int daNpc_Kn_c::setPrtcl() { // cXyz* pos = mParticleMngr[i].mpModel == true ? &mParticleMngr[i].mPos : NULL; mParticleMngr[i].mManager.setEffectCenter(&tevStr, &mParticleMngr[i].mPos, check, sp_0x18, - mParticleMngr[i].mpModel == true ? &mParticleMngr[i].mPos : NULL, - mParticleMngr[i].mpModel == true ? &mParticleMngr[i].mAngle : NULL, + mParticleMngr[i].field_0x00 == true ? &mParticleMngr[i].mPos : NULL, + mParticleMngr[i].field_0x00 == true ? &mParticleMngr[i].mAngle : NULL, 0, fopAcM_GetRoomNo(this), 0.0f, speedF); - if (mParticleMngr[i].mpModel != false) { + if (mParticleMngr[i].field_0x00 != false) { emitter = mParticleMngr[i].mManager.getCenterEmitter(0, 0); if (emitter != NULL) { switch (i) { @@ -4984,7 +4984,7 @@ int daNpc_Kn_c::setPrtcl() { } } - mParticleMngr[i].mpModel = NULL; + mParticleMngr[i].field_0x00 = false; } return 1; @@ -4996,21 +4996,21 @@ int daNpc_Kn_c::setSlipPrtcl() { mParticleMngr[0].mPos.y -= 20.0f; mParticleMngr[0].mAngle = current.angle; ANGLE_SUB_2(mParticleMngr[0].mAngle.y, 0x8000); - mParticleMngr[0].mpModel = true; + mParticleMngr[0].field_0x00 = true; mDoMtx_stack_c::copy(mpModelMorf[0]->getModel()->getAnmMtx(0x1b)); mDoMtx_stack_c::multVecZero(&mParticleMngr[1].mPos); mParticleMngr[1].mPos.y -= 20.0f; mParticleMngr[1].mAngle = current.angle; ANGLE_SUB_2(mParticleMngr[1].mAngle.y, 0x8000); - mParticleMngr[1].mpModel = true; + mParticleMngr[1].field_0x00 = true; return 1; } int daNpc_Kn_c::setLandingPrtcl() { mParticleMngr[2].mPos = current.pos; mParticleMngr[2].mAngle = mCurAngle; - mParticleMngr[2].mpModel = true; + mParticleMngr[2].field_0x00 = true; return 1; } diff --git a/src/d/actor/d_a_npc_ks.cpp b/src/d/actor/d_a_npc_ks.cpp index 7d7dc1802b..1d60f5a10a 100644 --- a/src/d/actor/d_a_npc_ks.cpp +++ b/src/d/actor/d_a_npc_ks.cpp @@ -250,7 +250,13 @@ static int daNpc_Ks_Draw(npc_ks_class* i_this) { fopAc_ac_c* actor = &i_this->actor; J3DModel* model = i_this->model->getModel(); + // This happens to work with MWCC since the member will only ever be initialized a pointer to a + // string in this TU's .data section, but comparing against a string literal is still UB. +#if AVOID_UB + if (strcmp(i_this->res_name, "Npc_kst") == 0) { +#else if (i_this->res_name == "Npc_kst") { +#endif g_env_light.settingTevStruct(4, &actor->current.pos, &actor->tevStr); } else { g_env_light.settingTevStruct(0, &actor->current.pos, &actor->tevStr); diff --git a/src/d/actor/d_a_npc_myna2.cpp b/src/d/actor/d_a_npc_myna2.cpp index f7d8b7f048..d78b94fc5f 100644 --- a/src/d/actor/d_a_npc_myna2.cpp +++ b/src/d/actor/d_a_npc_myna2.cpp @@ -189,10 +189,13 @@ int daNpc_myna2_c::create() { mType = getTypeFromParam(); field_0xe0d = (fopAcM_GetParam(this) & 0xFF00) >> 8; + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { - field_0xe04 = home.angle.x; + mFlowID = home.angle.x; } else { - field_0xe04 = -1; + mFlowID = -1; } if (isDelete()) { @@ -928,7 +931,7 @@ int daNpc_myna2_c::talk(void* param_0) { switch (mMode) { case 0: if (!mIsDamaged) { - initTalk(field_0xe04, NULL); + initTalk(mFlowID, NULL); mTurnMode = 0; mAnm_p->setPlaySpeed(1.0f); mMode = 2; @@ -1014,7 +1017,7 @@ int daNpc_myna2_c::ECut_firstTalk(int i_staffId) { case 10: break; case 20: - initTalk(field_0xe04, NULL); + initTalk(mFlowID, NULL); break; } } @@ -1063,7 +1066,7 @@ int daNpc_myna2_c::ECut_gameFailure(int i_staffId) { case 20: break; case 10: - initTalk(field_0xe04, NULL); + initTalk(mFlowID, NULL); break; } } @@ -1121,7 +1124,7 @@ int daNpc_myna2_c::ECut_gameGoal(int i_staffId) { } break; case 10: - initTalk(field_0xe04, NULL); + initTalk(mFlowID, NULL); break; case 20: break; @@ -1183,7 +1186,7 @@ int daNpc_myna2_c::ECut_gameGoalSuccess(int i_staffId) { } break; case 10: - initTalk(field_0xe04, NULL); + initTalk(mFlowID, NULL); break; case 20: { int itemNo = 0; @@ -1193,7 +1196,7 @@ int daNpc_myna2_c::ECut_gameGoalSuccess(int i_staffId) { break; } case 25: - initTalk(field_0xe04, NULL); + initTalk(mFlowID, NULL); break; case 30: break; diff --git a/src/d/actor/d_a_npc_ne.cpp b/src/d/actor/d_a_npc_ne.cpp index 0ff4c01d41..ae43981593 100644 --- a/src/d/actor/d_a_npc_ne.cpp +++ b/src/d/actor/d_a_npc_ne.cpp @@ -135,7 +135,13 @@ static int daNpc_Ne_Draw(npc_ne_class* i_this) { } J3DModel* model = i_this->mpMorf->getModel(); + // This happens to work with MWCC since the member will only ever be initialized a pointer to a + // string in this TU's .data section, but comparing against a string literal is still UB. +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") == 0) { +#else if (i_this->mResName == "Npc_net") { +#endif if (!dComIfGs_wolfeye_effect_check()) { return 1; } @@ -426,7 +432,12 @@ static void npc_ne_wait(npc_ne_class* i_this) { daPy_py_c* player = static_cast(dComIfGp_getPlayer(0)); cLib_addCalc0(&_this->speedF, 1.0f, 1.3f); + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") == 0) { +#else if (i_this->mResName == "Npc_net") { +#endif switch (i_this->mMode) { case 0: i_this->mTargetAngleY = cM_rndF(0x10000); @@ -2173,7 +2184,12 @@ static void action(npc_ne_class* i_this) { _this->gravity = -7.0f; + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") == 0) { +#else if (i_this->mResName == "Npc_net") { +#endif i_this->mDistToTarget = 10000.0f; } else { i_this->mDistToTarget = i_this->mDistScale * fopAcM_searchPlayerDistance(_this); @@ -2298,9 +2314,15 @@ static void action(npc_ne_class* i_this) { break; } + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") != 0) { +#else if (i_this->mResName != "Npc_net") { - if (i_this->mMessageState == 1 && daPy_py_c::checkNowWolf() - && i_this->mDistToTarget < 300.0f) { +#endif + if (i_this->mMessageState == 1 && + daPy_py_c::checkNowWolf() && + i_this->mDistToTarget < 300.0f) { i_this->mAction = npc_ne_class::ACT_MESSAGE; i_this->mMode = 0; bird_check = false; @@ -2846,8 +2868,15 @@ static void demo_camera(npc_ne_class* i_this) { } static int message(npc_ne_class* i_this) { - if (i_this->mResName == "Npc_net" && !dComIfGs_wolfeye_effect_check()) { - i_this->mMessageState = 0; + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") == 0) { +#else + if (i_this->mResName == "Npc_net") { +#endif + if (!dComIfGs_wolfeye_effect_check()) { + i_this->mMessageState = 0; + } } if (i_this->mIsTalking) { @@ -2872,7 +2901,12 @@ static int message(npc_ne_class* i_this) { !fopAcM_otherBgCheck(daPy_getLinkPlayerActorClass(), i_this)) { fopAcM_OnStatus(i_this, 0); cLib_onBit(i_this->attention_info.flags, fopAc_AttnFlag_SPEAK_e | fopAc_AttnFlag_TALK_e); + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") == 0) { +#else if (i_this->mResName == "Npc_net") { +#endif cLib_onBit(i_this->attention_info.flags, fopAc_AttnFlag_UNK_0x800000 | fopAc_AttnFlag_UNK_0x400000); } i_this->eventInfo.onCondition(dEvtCnd_CANTALK_e); @@ -2978,14 +3012,21 @@ static int daNpc_Ne_Execute(npc_ne_class* i_this) { message(i_this); demo_camera(i_this); - if (i_this->mResName == "Npc_net" && !dComIfGs_wolfeye_effect_check()) { - static u16 e_name[2] = {0x8497, 0x8498}; - for (int i = 0; i < 2; i++) { - i_this->mParticle[i] = dComIfGp_particle_set(i_this->mParticle[i], e_name[i], - &i_this->eyePos, NULL, NULL); - JPABaseEmitter* emitter = dComIfGp_particle_getEmitter(i_this->mParticle[i]); - if (emitter != NULL) { - emitter->setGlobalAlpha(!dComIfGs_wolfeye_effect_check() ? 0xff : 0); + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(i_this->mResName, "Npc_net") == 0) { +#else + if (i_this->mResName == "Npc_net") { +#endif + if (!dComIfGs_wolfeye_effect_check()) { + static u16 e_name[2] = {0x8497, 0x8498}; + for (int i = 0; i < 2; i++) { + i_this->mParticle[i] = dComIfGp_particle_set(i_this->mParticle[i], e_name[i], + &i_this->eyePos, NULL, NULL); + JPABaseEmitter* emitter = dComIfGp_particle_getEmitter(i_this->mParticle[i]); + if (emitter != NULL) { + emitter->setGlobalAlpha(!dComIfGs_wolfeye_effect_check() ? 0xff : 0); + } } } } @@ -3231,7 +3272,12 @@ static cPhs_Step daNpc_Ne_Create(fopAc_ac_c* i_this) { _this->mAcchCir.SetWall(_this->mBaseScale.y * 30.0f, _this->mBaseScale.z * 35.0f); _this->mDistScale = cM_rndFX(0.2f) + 1.0f; _this->mGroundY = i_this->current.pos.y; + // See comment in daNpc_Ne_Draw +#if AVOID_UB + if (strcmp(_this->mResName, "Npc_net") == 0) { +#else if (_this->mResName == "Npc_net") { +#endif _this->mAction = npc_ne_class::ACT_WAIT; _this->mMode = 0; } diff --git a/src/d/actor/d_a_npc_pachi_maro.cpp b/src/d/actor/d_a_npc_pachi_maro.cpp index b87bfcb32a..9631bd42ba 100644 --- a/src/d/actor/d_a_npc_pachi_maro.cpp +++ b/src/d/actor/d_a_npc_pachi_maro.cpp @@ -1098,7 +1098,7 @@ int daNpc_Pachi_Maro_c::wait(void* param_1) { } if (mJntAnm.getMode() == 0) { - (s32)mType; + UNUSED((int)mType); } } break; diff --git a/src/d/actor/d_a_npc_pachi_taro.cpp b/src/d/actor/d_a_npc_pachi_taro.cpp index 6ceb762239..1da06ded50 100644 --- a/src/d/actor/d_a_npc_pachi_taro.cpp +++ b/src/d/actor/d_a_npc_pachi_taro.cpp @@ -1464,7 +1464,7 @@ int daNpc_Pachi_Taro_c::wait(void* param_1) { // ??? if (mJntAnm.getMode() == 0) { - (int)mType; + UNUSED((int)mType); } if (field_0x1004 == 0) { diff --git a/src/d/actor/d_a_npc_post.cpp b/src/d/actor/d_a_npc_post.cpp index b6333d699e..e47d4c3e13 100644 --- a/src/d/actor/d_a_npc_post.cpp +++ b/src/d/actor/d_a_npc_post.cpp @@ -696,7 +696,7 @@ BOOL daNpc_Post_c::checkChangeEvt() { return TRUE; } - (int)mType; + UNUSED((int)mType); } return FALSE; diff --git a/src/d/actor/d_a_npc_soldierA.cpp b/src/d/actor/d_a_npc_soldierA.cpp index 54718eb9f7..14e188e4a8 100644 --- a/src/d/actor/d_a_npc_soldierA.cpp +++ b/src/d/actor/d_a_npc_soldierA.cpp @@ -206,6 +206,9 @@ cPhs_Step daNpc_SoldierA_c::create() { mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { mMsgNo = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_soldierB.cpp b/src/d/actor/d_a_npc_soldierB.cpp index c1eddb23c8..8ee1762ca4 100644 --- a/src/d/actor/d_a_npc_soldierB.cpp +++ b/src/d/actor/d_a_npc_soldierB.cpp @@ -171,6 +171,9 @@ cPhs_Step daNpc_SoldierB_c::create() { mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xFFFF) { mMsgNo = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_theB.cpp b/src/d/actor/d_a_npc_theB.cpp index 6cdb85a3fe..71704f9717 100644 --- a/src/d/actor/d_a_npc_theB.cpp +++ b/src/d/actor/d_a_npc_theB.cpp @@ -244,6 +244,9 @@ cPhs_Step daNpcTheB_c::create() { return cPhs_ERROR_e; } + // !@bug The return value (an s16) is promoted to a 32-bit signed + // integer prior to being compared, so the compared value can + // never exceed SHORT_MAX and the condition always passes. if (getMessageNo() != 0xFFFF) { mMsgNo = getMessageNo(); } else { diff --git a/src/d/actor/d_a_npc_wrestler.cpp b/src/d/actor/d_a_npc_wrestler.cpp index 40eae8e827..81b50c8338 100644 --- a/src/d/actor/d_a_npc_wrestler.cpp +++ b/src/d/actor/d_a_npc_wrestler.cpp @@ -2219,8 +2219,8 @@ bool daNpcWrestler_c::sumouReady(void* param_1) { // fallthrough case 2: field_0xe5e += field_0xbd8->field_0xac; - field_0xe54 -= fabsf(field_0xbd8->field_0xac); - if (field_0xe54 < fabsf(field_0xbd8->field_0xac)) { + field_0xe54 -= fabsf((f32)field_0xbd8->field_0xac); + if (field_0xe54 < fabsf((f32)field_0xbd8->field_0xac)) { field_0xe80 = 1; field_0xe84++; } diff --git a/src/d/actor/d_a_npc_zra.cpp b/src/d/actor/d_a_npc_zra.cpp index ad35527516..15ed62157e 100644 --- a/src/d/actor/d_a_npc_zra.cpp +++ b/src/d/actor/d_a_npc_zra.cpp @@ -493,6 +493,9 @@ cPhs_Step daNpc_zrA_c::create() { fopAcM_ct(this, daNpc_zrA_c); mType = getTypeFromArgument(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xffff) { mFlowID = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_zrc.cpp b/src/d/actor/d_a_npc_zrc.cpp index 738f585127..d7f2ebc372 100644 --- a/src/d/actor/d_a_npc_zrc.cpp +++ b/src/d/actor/d_a_npc_zrc.cpp @@ -222,6 +222,9 @@ cPhs_Step daNpc_zrC_c::create() { fopAcM_ct(this, daNpc_zrC_c); mType = getTypeFromParam(); + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xffff) { mFlowID = home.angle.x; } else { diff --git a/src/d/actor/d_a_npc_zrz.cpp b/src/d/actor/d_a_npc_zrz.cpp index 37656be3bf..7e71ef130e 100644 --- a/src/d/actor/d_a_npc_zrz.cpp +++ b/src/d/actor/d_a_npc_zrz.cpp @@ -203,6 +203,9 @@ cPhs_Step daNpc_zrZ_c::create() { mSwitch1 = home.angle.z & 0xff; mSwitch2 = (home.angle.z >> 8) & 0xff; mSwitch3 = fopAcM_GetParam(this) >> 0x18; + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.x != 0xffff) { mFlowID = home.angle.x; } else { diff --git a/src/d/actor/d_a_obj_brg.cpp b/src/d/actor/d_a_obj_brg.cpp index 5df34b03e0..d0dea6cf98 100644 --- a/src/d/actor/d_a_obj_brg.cpp +++ b/src/d/actor/d_a_obj_brg.cpp @@ -20,7 +20,8 @@ static void ride_call_back(dBgW* i_bgw, fopAc_ac_c* i_bgActor, fopAc_ac_c* i_rid obj_brg_class* a_this = (obj_brg_class*)i_bgActor; cXyz sp74 = a_this->mBr[0].field_0x0bc - i_rideActor->current.pos; - int var_r27 = JMAFastSqrt(sp74.x * sp74.x + sp74.z * sp74.z) / (a_this->field_0xaedc * 51.0f) - -0.5f; + f32 var_f28 = JMAFastSqrt(sp74.x * sp74.x + sp74.z * sp74.z); + int var_r27 = var_f28 / (a_this->field_0xaedc * 51.0f) - -0.5f; if (var_r27 > a_this->field_0xb1ea - 1) { var_r27 = a_this->field_0xb1ea - 1; @@ -37,7 +38,7 @@ static void ride_call_back(dBgW* i_bgw, fopAc_ac_c* i_bgActor, fopAc_ac_c* i_rid if (a_this->mType & 5) { var_f30 = 0.85f; } else if (a_this->field_0xb1ed == 2) { - var_f30 = KREG_F(7) + 0.1f; + var_f30 = KREG_F(4) + 0.1f; } else { var_f30 = 1.0f; } @@ -665,8 +666,8 @@ static void obj_brg_move(obj_brg_class* i_this) { if ((i_this->mType & 1) == 1) { i_this->mBr[i].field_0x0e0 = 1.0f; } else { - var_f27 = ( f32(i) / (i_this->field_0xb1ea - 1)) * M_PI; - i_this->mBr[i].field_0x0e0 = fabsf(sin(var_f27)); + var_f27 = ((f32)i / (i_this->field_0xb1ea - 1)) * M_PI; + i_this->mBr[i].field_0x0e0 = fabsf(sinf(var_f27)); } i_this->mBr[i].field_0x704 = i_this->mBr[i].field_0x705 = 3; @@ -993,11 +994,11 @@ static int daObj_Brg_Execute(obj_brg_class* i_this) { f32 dbg_0x5c; for (int i = 0; i < i_this->field_0xb1ea; i++, part++) { if (i_this->field_0xb1ed == 2) { - dbg_0x5c = f32(i) / f32(i_this->field_0xb1ea - 1) * M_PI; - var_f26 = (-300.0f + WREG_F(15)) * f32(sin(dbg_0x5c)); + dbg_0x5c = (f32)i / (f32)(i_this->field_0xb1ea - 1) * M_PI; + var_f26 = (-300.0f + WREG_F(15)) * (f32)sin(dbg_0x5c); } else if (i_this->field_0xb1ed == 1) { - dbg_0x5c = f32(i) / f32(i_this->field_0xb1ea - 1) * M_PI; - var_f26 = (-100.0f + WREG_F(13)) * f32(sin(dbg_0x5c)); + dbg_0x5c = (f32)i / (f32)(i_this->field_0xb1ea - 1) * M_PI; + var_f26 = (-100.0f + WREG_F(13)) * (f32)sin(dbg_0x5c); } MtxTrans(part->field_0x0bc.x, part->field_0x0bc.y, part->field_0x0bc.z, 0); @@ -1794,7 +1795,7 @@ static int daObj_Brg_Create(fopAc_ac_c* i_this) { }; for (brno = 0; brno < a_this->field_0xb1ea; brno++) { - a_this->mBr[brno].field_0x098[2] = brg_init_pos[brno]; + a_this->mBr[brno].field_0x0b0 = brg_init_pos[brno]; } } diff --git a/src/d/actor/d_a_obj_cwall.cpp b/src/d/actor/d_a_obj_cwall.cpp index 0b6367505f..6bf0b480a5 100644 --- a/src/d/actor/d_a_obj_cwall.cpp +++ b/src/d/actor/d_a_obj_cwall.cpp @@ -333,6 +333,10 @@ void daObjCwall_c::getChainBasePos(cXyz* pBasePos) { void daObjCwall_c::setChainMtx() { chain_s* pChain = mChains; s16 sVar7 = home.angle.y; + + // !@bug The variable is promoted to a 32-bit signed integer prior + // to being compared to 0xC000, so the compared value can never + // exceed SHORT_MAX and the subcondition fails. if (sVar7 == 0x4000 || sVar7 == 0xc000) { sVar7 += 0x4000; } diff --git a/src/d/actor/d_a_obj_gra2.cpp b/src/d/actor/d_a_obj_gra2.cpp index 5f03df755f..4eca318eb9 100644 --- a/src/d/actor/d_a_obj_gra2.cpp +++ b/src/d/actor/d_a_obj_gra2.cpp @@ -277,7 +277,10 @@ cPhs_Step daObj_GrA_c::create() { } } - field_0x848 = ((int)home.angle.x == 0xFFFF) ? -1 : home.angle.x; + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always fails. + mFlowID = home.angle.x == 0xFFFF ? -1 : home.angle.x; field_0x1fe8 = (fopAcM_GetParam(this) & 0xC0000000) >> 30; field_0xa7f = home.angle.z & 0xFF; @@ -1435,7 +1438,7 @@ int daObj_GrA_c::talk(void* param_1) { int iVar1, iVar2; int rv = 0; int iVar3; - int iVar4 = field_0x848; + int iVar4 = mFlowID; s16 sVar1; switch (field_0xa7c) { case 0: @@ -2013,7 +2016,7 @@ int daObj_GrA_c::face999(int param_1) { } int daObj_GrA_c::evtcutTalk(int param_1, int param_2) { - s32 sVar1 = field_0x848; + s32 sVar1 = mFlowID; if (param_2 != 0) { mMsgFlow.init(this, sVar1, 0, NULL); field_0xaa0 = 0; diff --git a/src/d/actor/d_a_obj_gra2_soldier.inc b/src/d/actor/d_a_obj_gra2_soldier.inc index e36d7ec350..53100dafcd 100644 --- a/src/d/actor/d_a_obj_gra2_soldier.inc +++ b/src/d/actor/d_a_obj_gra2_soldier.inc @@ -768,7 +768,7 @@ int daObj_GrA_c::rollDemo(void* param_1) { field_0x91a.y = current.angle.y; if (mDemoCamMode >= 5) { - field_0x848 = 4; + mFlowID = 4; evtcutTalk(-1, 1); field_0x2000 = 0; } @@ -1169,7 +1169,7 @@ int daObj_GrA_c::rollAttacked(void* param_1) { case 2: if (mDemoCamMode >= 5) { - field_0x848 = 5; + mFlowID = 5; evtcutTalk(-1, 1); field_0x2018 = 3; } diff --git a/src/d/actor/d_a_obj_iceblock.cpp b/src/d/actor/d_a_obj_iceblock.cpp index 62a6dbb966..81a72b85e7 100644 --- a/src/d/actor/d_a_obj_iceblock.cpp +++ b/src/d/actor/d_a_obj_iceblock.cpp @@ -25,7 +25,7 @@ enum WALK_TYPE { WALK_IRON_BALL_HIT, }; -void daObjIceBlk_c::PPCallBack(fopAc_ac_c* i_bgActor, fopAc_ac_c* i_pushActor, s16 i_angle, +fopAc_ac_c* daObjIceBlk_c::PPCallBack(fopAc_ac_c* i_bgActor, fopAc_ac_c* i_pushActor, s16 i_angle, dBgW_Base::PushPullLabel i_label) { bool temp_r3 = cLib_checkBit(i_label, dBgW::PPLABEL_PUSH) != 0; bool temp_r3_2 = cLib_checkBit(i_label, dBgW::PPLABEL_PUSH) != 0; @@ -54,6 +54,7 @@ void daObjIceBlk_c::PPCallBack(fopAc_ac_c* i_bgActor, fopAc_ac_c* i_pushActor, s } ((daObjIceBlk_c*)i_bgActor)->mPPLabel = i_label; + return i_bgActor; } static void rideCallBack(dBgW* i_bgw, fopAc_ac_c* i_bgActor, fopAc_ac_c* i_rideActor) { diff --git a/src/d/actor/d_a_obj_ladder.cpp b/src/d/actor/d_a_obj_ladder.cpp index dc88e5cf15..bb2b145fc6 100644 --- a/src/d/actor/d_a_obj_ladder.cpp +++ b/src/d/actor/d_a_obj_ladder.cpp @@ -380,7 +380,10 @@ int Act_c::Draw() { dComIfGd_setListBG(); mDoExt_modelUpdateDL(mModel); dComIfGd_setList(); - dComIfG_Bgsp().DebugDrawPoly(mpBgW); + + #if DEBUG + dComIfG_Bgsp().DebugDrawPoly(*mpBgW); + #endif return 1; } diff --git a/src/d/actor/d_a_obj_magne_arm.cpp b/src/d/actor/d_a_obj_magne_arm.cpp index 1c1c152c00..54a734c35d 100644 --- a/src/d/actor/d_a_obj_magne_arm.cpp +++ b/src/d/actor/d_a_obj_magne_arm.cpp @@ -947,7 +947,7 @@ void daObjMarm_c::calcHimo() { getRopeStartPos(&offset1); getFpartsOffset(&offset2); - fabs(offset1.y - offset2.y); + UNUSED(fabs(offset1.y - offset2.y)); cXyz* line_mat1_pos = mpRope1->getPos(0); *line_mat1_pos = offset1; diff --git a/src/d/actor/d_a_obj_pumpkin.cpp b/src/d/actor/d_a_obj_pumpkin.cpp index ff90ed6a74..6dcd0988f7 100644 --- a/src/d/actor/d_a_obj_pumpkin.cpp +++ b/src/d/actor/d_a_obj_pumpkin.cpp @@ -288,8 +288,9 @@ int daObj_Pumpkin_c::Execute() { if (field_0xBAE) { int item_table_no = getItemTableNo(); if (item_table_no >= 0 && mItemProcId == fpcM_ERROR_PROCESS_ID_e) { - mItemProcId = fopAcM_createItemFromTable(¤t.pos, item_table_no, -1, fopAcM_GetRoomNo(this), - NULL, 0, NULL, NULL, NULL, NULL); + mItemProcId = fopAcM_createItemFromTable(¤t.pos, item_table_no, -1, + fopAcM_GetRoomNo(this), NULL, 0, NULL, NULL, + NULL, false); } if (mItemProcId == fpcM_ERROR_PROCESS_ID_e || fopAcM_IsExecuting(mItemProcId)) { diff --git a/src/d/actor/d_a_obj_sekidoor.cpp b/src/d/actor/d_a_obj_sekidoor.cpp index 7be65ab45b..498282f4b4 100644 --- a/src/d/actor/d_a_obj_sekidoor.cpp +++ b/src/d/actor/d_a_obj_sekidoor.cpp @@ -112,7 +112,9 @@ int daObj_SekiDoor_c::Execute(Mtx** i_mtx) { if (mOpening != 0) { if (mDestroyed != 0) { - if(!dComIfGp_event_runCheck){ + // !@bug Missing parentheses - the function is not callled and + // this always evaluates to false. + if (!dComIfGp_event_runCheck) { fopAcM_delete(this); } } diff --git a/src/d/actor/d_a_obj_sekizoa.cpp b/src/d/actor/d_a_obj_sekizoa.cpp index 7a32754658..19f4446b87 100644 --- a/src/d/actor/d_a_obj_sekizoa.cpp +++ b/src/d/actor/d_a_obj_sekizoa.cpp @@ -1008,9 +1008,14 @@ bool daObj_Sekizoa_c::afterSetMotionAnm(int i_frame, int i_mode, f32 i_morf, int if (mBtkAnm.getBtkAnm() == anm_text) { mAnmFlags |= ANM_PLAY_BTK; } else { - if (setBtkAnm(anm_text, mpMorf[0]->getModel()->getModelData(), 1.0f, - btkAnmData[4].field_0x4)) - { +#if AVOID_UB + // negative attribute values are ignored in favor of the animation's default value + if (setBtkAnm(anm_text, mpMorf[0]->getModel()->getModelData(), 1.0f, -1)) { +#else + // !@bug Out-of-bounds array read, in practice this ends up reading from a jump table + // positioned immediately after btkAnmData in .data. + if (setBtkAnm(anm_text, mpMorf[0]->getModel()->getModelData(), 1.0f, btkAnmData[4].field_0x4)) { +#endif if (frame_1 == 3) { mBtkAnm.setPlaySpeed(0.0f); } @@ -1032,8 +1037,15 @@ bool daObj_Sekizoa_c::afterSetMotionAnm(int i_frame, int i_mode, f32 i_morf, int if (mBrkAnm.getBrkAnm() == anm_tev) { mAnmFlags |= ANM_PLAY_BRK; } else { - frame_1 = setBrkAnm(anm_tev, mpMorf[0]->getModel()->getModelData(), 1.0, + // !@bug OoB index into brkAnmData ends up indexing into btkAnmData instead. + // This was probably supposed to use brkAnmData[5] instead. +#if AVOID_UB + frame_1 = setBrkAnm(anm_tev, mpMorf[0]->getModel()->getModelData(), 1.0f, + btkAnmData[0].field_0x4); +#else + frame_1 = setBrkAnm(anm_tev, mpMorf[0]->getModel()->getModelData(), 1.0f, brkAnmData[6].field_0x4); +#endif if (frame_1 != 0) { if (frame_2 == 5) { mBrkAnm.setPlaySpeed(0.0f); diff --git a/src/d/actor/d_a_obj_ss_drink.cpp b/src/d/actor/d_a_obj_ss_drink.cpp index 1327de2255..a2b68af17e 100644 --- a/src/d/actor/d_a_obj_ss_drink.cpp +++ b/src/d/actor/d_a_obj_ss_drink.cpp @@ -384,6 +384,7 @@ int daObj_SSDrink_c::chkEvent() { } int daObj_SSDrink_c::orderEvent() { + // !@bug Comparison of u16 (getFlowNodeNum()) with -1 always evaluates to false if (!daPy_py_c::checkNowWolf() && field_0xb0c != 0x60 && getFlowNodeNum() != -1) { attention_info.flags = fopAc_AttnFlag_TALKREAD_e | fopAc_AttnFlag_SPEAK_e; } else { diff --git a/src/d/actor/d_a_obj_swpush.cpp b/src/d/actor/d_a_obj_swpush.cpp index e71033b979..b6d465744e 100644 --- a/src/d/actor/d_a_obj_swpush.cpp +++ b/src/d/actor/d_a_obj_swpush.cpp @@ -240,7 +240,7 @@ cPhs_Step daObjSwpush::Act_c::Mthd_Create() { mDoMtx_stack_c::scaleM(field_0x5f8); MTXCopy(mDoMtx_stack_c::get(), mMtx); mpBgW->ClrNoCalcVtx(); - mpBgW->SetBaseMtxP(mMtx); + mpBgW->SetBaseMtxP(&mMtx); mpBgW->GlobalVtx(); mpBgW->SetBaseMtxP(NULL); mpBgW->SetNoCalcVtx(); diff --git a/src/d/actor/d_a_passer_mng.cpp b/src/d/actor/d_a_passer_mng.cpp index 51eb0d1894..fe57254149 100644 --- a/src/d/actor/d_a_passer_mng.cpp +++ b/src/d/actor/d_a_passer_mng.cpp @@ -38,33 +38,40 @@ int daPasserMng_c::execute() { return 1; } -static u8 const groupA[32] = { - 0x07, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x04, 0x50, 0x00, 0x00, 0x06, 0x01, 0x00, 0x00, 0x07, - 0x01, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x1B, 0x01, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x1D, +// this is based off of daPasserMng_c::Group, any changes here should also be changed there +template +struct SizedGroup { + u8 field_0x00; + int field_0x04[N]; }; -static u8 const groupB[36] = { - 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x11, - 0x11, 0x00, 0x00, 0x12, 0x10, 0x00, 0x00, 0x13, 0x40, 0x00, 0x00, 0x09, - 0x40, 0x00, 0x00, 0x08, 0x50, 0x00, 0x00, 0x0A, 0x01, 0x00, 0x00, 0x0B, +static SizedGroup<7> const groupA = { + 7, + {0x11000004, 0x50000006, 0x01000007, 0x01000005, 0x0100001B, 0x0100001C, 0x0000001D}, }; -static u8 const groupC[36] = { - 0x08, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x01, - 0x50, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x03, 0x21, 0x00, 0x00, 0x17, - 0x10, 0x00, 0x00, 0x18, 0x01, 0x00, 0x00, 0x19, 0x10, 0x00, 0x00, 0x1A, +static SizedGroup<8> const groupB = { + 8, + {0x01000010, 0x10000011, 0x11000012, 0x10000013, 0x40000009, 0x40000008, 0x5000000A, + 0x0100000B}, }; -static u8 const groupD[32] = { - 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x14, 0x21, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x16, - 0x11, 0x00, 0x00, 0x0C, 0x50, 0x00, 0x00, 0x0E, 0x40, 0x00, 0x00, 0x0F, 0x01, 0x00, 0x00, 0x0D, +static SizedGroup<8> const groupC = { + 8, + {0x11000000, 0x11000001, 0x50000002, 0x01000003, 0x21000017, 0x10000018, 0x01000019, + 0x1000001A}, }; -daPasserMng_c::Group* daPasserMng_c::mGroupTbl[4] = { - (Group*)groupA, - (Group*)groupB, - (Group*)groupC, - (Group*)groupD, +static SizedGroup<7> const groupD = { + 7, + {0x01000014, 0x21000015, 0x00000016, 0x1100000C, 0x5000000E, 0x4000000F, 0x0100000D}, +}; + +const daPasserMng_c::Group* daPasserMng_c::mGroupTbl[4] = { + (const Group*)&groupA, + (const Group*)&groupB, + (const Group*)&groupC, + (const Group*)&groupD, }; int daPasserMng_c::getPasserParam() { @@ -84,7 +91,7 @@ int daPasserMng_c::getPasserParam() { } else { groupInd = 0; } - Group* pGroup = mGroupTbl[groupInd]; + const Group* pGroup = mGroupTbl[groupInd]; int iVar5; do { iVar5 = cLib_getRndValue(0, (int)pGroup->field_0x00); diff --git a/src/d/actor/d_a_tag_evt.cpp b/src/d/actor/d_a_tag_evt.cpp index 2552f59e24..8dc5954ef0 100644 --- a/src/d/actor/d_a_tag_evt.cpp +++ b/src/d/actor/d_a_tag_evt.cpp @@ -168,6 +168,7 @@ int daTag_Evt_c::isDelete() { if (field_0x5DD == 0xFF || (field_0x5DD != 0xFF && dComIfGs_isSwitch(field_0x5DD, fopAcM_GetRoomNo(this)) != 0)) { + // !@bug Comparison of u8 field with 0xFFF will always evaluate to false if (field_0x5DE != 0xFFF) { return dComIfGs_isSwitch(field_0x5DE, fopAcM_GetRoomNo(this)); } else { diff --git a/src/d/actor/d_a_tag_evtmsg.cpp b/src/d/actor/d_a_tag_evtmsg.cpp index 8a2035f147..b5e71f00e3 100644 --- a/src/d/actor/d_a_tag_evtmsg.cpp +++ b/src/d/actor/d_a_tag_evtmsg.cpp @@ -36,6 +36,9 @@ int daTag_EvtMsg_c::create() { scale.y *= 100.0f; scale.z = scale.x; + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.z != 0xFFFF) { mFlowID = home.angle.z; } else { diff --git a/src/d/actor/d_a_tag_lantern.cpp b/src/d/actor/d_a_tag_lantern.cpp index 264a0c1987..88660a029d 100644 --- a/src/d/actor/d_a_tag_lantern.cpp +++ b/src/d/actor/d_a_tag_lantern.cpp @@ -126,6 +126,9 @@ void daTag_Lantern_c::initialize() { mpHIO->entryHIO("カンテラチェックタグ"); #endif + // !@bug home.angle.x is promoted to a 32-bit signed integer prior + // to being compared, so the compared value can never exceed + // SHORT_MAX and the condition always passes. if (home.angle.z != 0xFFFF) { mFlowIndex = home.angle.z; } else { diff --git a/src/d/actor/d_a_tag_setrestart.cpp b/src/d/actor/d_a_tag_setrestart.cpp index c7134fbae4..4230abb920 100644 --- a/src/d/actor/d_a_tag_setrestart.cpp +++ b/src/d/actor/d_a_tag_setrestart.cpp @@ -163,7 +163,7 @@ static int daTagRestart_Execute(daTagRestart_c* i_this) { } static int daTagRestart_Delete(daTagRestart_c* i_this) { - ("Delete -> TagRestart( =%d)\n", fopAcM_GetID(i_this)); + fopAcM_RegisterDeleteID(i_this, "TagRestart"); return i_this->_delete(); } diff --git a/src/d/actor/d_a_tag_sppath.cpp b/src/d/actor/d_a_tag_sppath.cpp index b40908b387..81fbe04184 100644 --- a/src/d/actor/d_a_tag_sppath.cpp +++ b/src/d/actor/d_a_tag_sppath.cpp @@ -97,7 +97,7 @@ int daTagSppath_c::getNearPathPos(cXyz* i_result, dPath* i_path) { if (flatness > 0.001f) { flatness = 30.0f / flatness; if (segLen > flatness) { - line.GetStartP() = line.GetStart() + pntDiff * flatness; + *line.GetStartP() = line.GetStart() + pntDiff * flatness; } } } @@ -111,7 +111,7 @@ int daTagSppath_c::getNearPathPos(cXyz* i_result, dPath* i_path) { if (flatness > 0.001f) { flatness = 30.0f / flatness; if (segLen > flatness) { - line.GetEndP() = line.GetEnd() + pntDiff * flatness; + *line.GetEndP() = line.GetEnd() + pntDiff * flatness; } } } diff --git a/src/d/actor/d_a_tag_ss_drink.cpp b/src/d/actor/d_a_tag_ss_drink.cpp index 8916feae7a..8f2ee55815 100644 --- a/src/d/actor/d_a_tag_ss_drink.cpp +++ b/src/d/actor/d_a_tag_ss_drink.cpp @@ -136,7 +136,7 @@ int daTag_SSDrink_c::chkEvent() { if (!dComIfGp_getEvent()->isOrderOK()) { retVal = 0; if (eventInfo.checkCommandTalk()) { - if (!checkProcess(&daTag_SSDrink_c::talk) == 0) { + if (checkProcess(&daTag_SSDrink_c::talk) != 0) { retVal = (this->*mProcessFunc)(0); } else { if (dComIfGp_event_chkTalkXY() == 0 || dComIfGp_evmng_ChkPresentEnd() != 0) { diff --git a/src/d/actor/d_a_tag_theB_hint.cpp b/src/d/actor/d_a_tag_theB_hint.cpp index d368d726df..58887f976e 100644 --- a/src/d/actor/d_a_tag_theB_hint.cpp +++ b/src/d/actor/d_a_tag_theB_hint.cpp @@ -23,6 +23,7 @@ int daTagTheBHint_c::execute() { if (fopAcM_searchPlayerDistanceXZ2(this) < field_0x568) { daNpcTheB_c* the_b = (daNpcTheB_c*)fpcM_SearchByName(fpcNm_NPC_THEB_e); if (the_b) { + // !@bug Comparison of s8 (getRoomNo) with 0xFF always evaluates to false int roomNo = getRoomNo() == 0xff ? fopAcM_GetRoomNo(this) : getRoomNo(); the_b->setHintEvent(getMessageNo(), getLinkID(), roomNo); diff --git a/src/d/d_bg_s.cpp b/src/d/d_bg_s.cpp index d4d675b732..f218424d30 100644 --- a/src/d/d_bg_s.cpp +++ b/src/d/d_bg_s.cpp @@ -12,86 +12,259 @@ #include "f_op/f_op_actor_mng.h" #include "dusk/offset_ptr.h" +#include "d/d_debug_viewer.h" +#include "d/d_bg_s_capt_poly.h" + +#include "dusk/imgui/ImGuiConsole.hpp" + +#if DEBUG +int g_ground_counter; +int g_line_counter; +int g_acch_wall_counter; +int g_roof_counter; +int g_spl_counter; +int g_shdw_counter; +int g_sph_counter; +int g_capt_poly_counter; +#endif + + +void dBgS_HIO::genMessage(JORMContext* mctx) { +#if DEBUG + mctx->genLabel("zelda地形チェック", 0); + + mctx->genLabel("チェック回数 ----------", 0); + mctx->genCheckBox("チェックカウンター", &m_flags, FLAG_CHECK_COUNTER_e); + + mctx->genLabel("平均処理時間(Mean) -----------", 0); + mctx->genCheckBox("ラインチェック時間(->terminal)", &m_flags2, FLAG2_LINE_TIMER_e); + mctx->genCheckBox("アクターチェック時間[壁、床(+天井、水面)](->terminal)", &m_flags, 1); + mctx->genCheckBox("アクターチェック 壁チェック時間(->terminal)", &m_flags, FLAG_ACCH_WALL_TIMER_e); + mctx->genCheckBox("天井チェック時間(->terminal)", &m_flags, FLAG_ROOF_TIMER_e); + mctx->genCheckBox("Splチェック(水、溶岩、毒水面)時間(->terminal)", &m_flags2, FLAG2_SPL_TIMER_e); + mctx->genCheckBox("床チェック時間(->terminal)", &m_flags2, FLAG2_GROUND_CHECK_TIMER_e); + mctx->genCheckBox("リアル影描画時間(->terminal)", &m_flags2, FLAG2_SHDW_DRAW_TIMER_e); + mctx->genCheckBox("球チェック時間[コールバック処理含む](->terminal)", &m_flags2, FLAG2_SPH_CHK_TIMER_e); + mctx->genCheckBox("ポリゴンキャプチャ時間", &m_flags2, FLAG2_CAPTPOLY_TIMER_e); + + mctx->genLabel("処理off ----------", 0); + mctx->genCheckBox("ライン off", &m_flags2, FLAG2_LINE_OFF_e); + mctx->genCheckBox("アクターチェック 壁処理off", &m_flags, FLAG_ACCH_WALL_OFF_e); + mctx->genCheckBox("天井チェックoff", &m_flags, FLAG_ROOF_OFF_e); + mctx->genCheckBox("Splチェック(水、溶岩、毒水面)off", &m_flags2, FLAG2_SPL_OFF_e); + mctx->genCheckBox("リアル影処理Off", &m_flags2, FLAG2_SHDW_DRAW_OFF_e); + mctx->genCheckBox("球チェックOff", &m_flags2, FLAG2_SPH_CHK_OFF_e); + mctx->genCheckBox("ポリゴンキャプチャOff", &m_flags2, FLAG2_CAPTPOLY_OFF_e); + + mctx->genLabel("当たりチェック ----------", 0); + mctx->genCheckBox("ラインチェック", &m_flags, FLAG_OBJ_LINE_CHECK_e); + mctx->genSlider("start x", &m_linecheck_start.x, -450000.0, 450000.0); + mctx->genSlider("start y", &m_linecheck_start.y, -450000.0, 450000.0); + mctx->genSlider("start z", &m_linecheck_start.z, -450000.0, 450000.0); + mctx->genSlider("end x", &m_linecheck_end.x, -450000.0, 450000.0); + mctx->genSlider("end y", &m_linecheck_end.y, -450000.0, 450000.0); + mctx->genSlider("end z", &m_linecheck_end.z, -450000.0, 450000.0); + mctx->genCheckBox("Obj床チェック", &m_flags2, FLAG2_GND_CHK_e); + mctx->genSlider("gnd x", &m_gndcheck_pos.x, -450000.0, 450000.0); + mctx->genSlider("gnd y", &m_gndcheck_pos.y, -450000.0, 450000.0); + mctx->genSlider("gnd z", &m_gndcheck_pos.z, -450000.0, 450000.0); + + mctx->genLabel("抜けチェック ----------", 0); + mctx->genCheckBox("アクターチェック 抜けチェック", &m_flags, 0x200); + mctx->genSlider("抜けチェックアクター番号 ", &m_errorCheck_actor_num, -1, 3000); + mctx->genCheckBox("プレイヤーのアクター地形チェックの床法線ベクトル", &m_flags2, 0x400); + + mctx->genLabel("デバッグ表示 ----------", 0); + mctx->genCheckBox("アクターチェック 壁当たり範囲表示", &m_flags, 0x400); + mctx->genCheckBox("BoundingBox描画", &m_flags, 0x8000); + mctx->genCheckBox("当たり表示On", &m_flags2, FLAG2_SHAPE_DISP_e); + + mctx->genLabel("その他 ----------", 0); + mctx->genCheckBox("作業1", &m_flags, 0x20); + mctx->genCheckBox("作業2", &m_flags, 0x40); + mctx->genCheckBox("作業3", &m_flags, 0x80); + mctx->genCheckBox("作業4", &m_flags, 0x100); +#endif +} + +dBgS_InsideHIO::~dBgS_InsideHIO() {} + +void dBgS_InsideHIO::genMessage(JORMContext* mctx) { +#if DEBUG + mctx->genLabel("デバッグポリゴン描画 -----", 0); + mctx->genCheckBox("デバッグポリゴン描画", &m_flags, FLAG_DISP_POLY_e); + + mctx->genLabel("-----", 0); + mctx->genCheckBox("範囲描画(青い箱)", &m_flags, FLAG_DISP_DP_AREA_e); + mctx->genCheckBox("プレイヤー位置(±p0 x)", &m_flags, FLAG_PLAYER_AROUND_e); + + mctx->genLabel("-----", 0); + mctx->genCheckBox("白ワイヤーフレーム", &m_flags, FLAG_WHITE_WIRE_e); + + mctx->genLabel("-----", 0); + mctx->genCheckBox("水面ポリゴンのみ", &m_flags, FLAG_DISP_WATER_POLY_e); + + mctx->genLabel("-----", 0); + mctx->genCheckBox("床Off", &m_flags, FLAG_GROUND_OFF_e); + mctx->genCheckBox("壁Off", &m_flags, FLAG_WALL_OFF_e); + mctx->genCheckBox("天井Off", &m_flags, FLAG_ROOF_OFF_e); + + mctx->genLabel("-----", 0); + mctx->genSlider("p0 x", &m_p0.x, -100000.0, 100000.0); + mctx->genSlider("p0 y", &m_p0.y, -100000.0, 100000.0); + mctx->genSlider("p0 z", &m_p0.z, -100000.0, 100000.0); + mctx->genSlider("p1 x", &m_p1.x, -100000.0, 100000.0); + mctx->genSlider("p1 y", &m_p1.y, -100000.0, 100000.0); + mctx->genSlider("p1 z", &m_p1.z, -100000.0, 100000.0); + mctx->genSlider("持ち上げ量", &m_raise_amount, -10.0, 30.0); + + mctx->genLabel("-----", 0); + mctx->genCheckBox("Obj床 プレイヤー下", &m_flags, FLAG_GNDCHK_PLAYER_UNDER_e); +#endif +} + void cBgS_ChkElm::Init() { m_bgw_base_ptr = NULL; m_used = false; m_actor_ptr = NULL; - m_actor_id = 0xFFFFFFFF; + m_actor_id = fpcM_ERROR_PROCESS_ID_e; } -void cBgS_ChkElm::Regist2(dBgW_Base* p_data, fpc_ProcID actor_id, void* p_actor) { +void cBgS_ChkElm::Regist2(dBgW_Base* pbgw, fpc_ProcID actor_id, void* pactor) { m_used = true; - m_bgw_base_ptr = p_data; + m_bgw_base_ptr = pbgw; m_actor_id = actor_id; - m_actor_ptr = (fopAc_ac_c*)p_actor; + m_actor_ptr = (fopAc_ac_c*)pactor; } void cBgS_ChkElm::Release() { m_used = false; m_bgw_base_ptr = NULL; - m_actor_id = 0xFFFFFFFF; + m_actor_id = fpcM_ERROR_PROCESS_ID_e; m_actor_ptr = NULL; } static int l_SetCounter; -bool cBgS::Regist(dBgW_Base* p_data, fpc_ProcID actor_id, void* p_actor) { - if (p_data == NULL) { +bool cBgS::Regist(dBgW_Base* pbgw, fpc_ProcID actor_id, void* pactor) { + if (pbgw == NULL) { + // "cBgS::Regist() data is Null" + OS_REPORT_ERROR("cBgS::Regist() データがNull\n"); return true; - } else if (p_data->ChkUsed()) { + } else if (pbgw->ChkUsed()) { + // "cBgS::Regist() check duplicate entry." + OS_REPORT_ERROR("cBgS::Regist() チェック二重登録。\n"); return true; - } else if (p_data->ChkMemoryError()) { + } else if (pbgw->ChkMemoryError()) { + // "cBgS::Regist() registration rejected (dBgW_Base=%x)" + OS_REPORT_ERROR("cBgS::Regist() 登録拒否(dBgW_Base=%x)\n", pbgw); return true; - } else { - int i = l_SetCounter; - do { - if (!m_chk_element[i].m_used) { - m_chk_element[i].Regist2(p_data, actor_id, p_actor); - p_data->Regist(i); - - l_SetCounter = i + 1; - if (l_SetCounter >= 0x100) { - l_SetCounter = 0; - } - return false; - } - - i++; - if (i >= 0x100) { - i = 0; - } - } while (l_SetCounter != i); - p_data->Release(); } + + #if DEBUG + for (int i = 0; i < 0x100; i++) { + if (m_chk_element[i].ChkUsed() && m_chk_element[i].m_bgw_base_ptr == pbgw) { + // "cBgS::Regist() will continue processing, but an entry with the same address (address:%x, id = %d) is already registered. This is probably a duplicate entry. Duplicate registrations are dangerous. !!" + OS_REPORT_ERROR("cBgS::Regist() 処理は続けますが、同じアドレスのもの(address:%x, id = %d)がすでに登録されています。多分ですが多重登録です。多重登録ならキケンです。!!\n", pbgw, i); + JUT_WARN(368, "%s", "cBgS::Regist() double regist"); + } + } + #endif + + int i = l_SetCounter; + JUT_ASSERT(376, 0 <= i && i < 256); + + do { + if (!m_chk_element[i].ChkUsed()) { + m_chk_element[i].Regist2(pbgw, actor_id, pactor); + pbgw->Regist(i); + + l_SetCounter = i + 1; + if (l_SetCounter >= 0x100) { + l_SetCounter = 0; + } + return false; + } + + i++; + if (i >= 0x100) { + i = 0; + } + } while (l_SetCounter != i); + + JUT_WARN(398, "%s", "cBgS::Regist() regist over."); + OS_REPORT_ERROR("[ERROR] cBgS::Regist() table is no empty\n"); + pbgw->Release(); return true; } -bool cBgS::Release(dBgW_Base* p_data) { - if (p_data == NULL) { +bool cBgS::Release(dBgW_Base* pbgw) { + if (pbgw == NULL) { return 1; } - int id = p_data->GetId(); - if (p_data->ChkUsed() && id >= 0 && id < 0x100 && m_chk_element[id].ChkUsed()) { + int id = pbgw->GetId(); + if (pbgw->ChkUsed() && id >= 0 && id < 0x100 && m_chk_element[id].ChkUsed()) { + #if DEBUG + if (m_chk_element[id].m_bgw_base_ptr != pbgw) { + // "[ERROR] cBgS::Release() the work area pointer registered to %d differs from pointer passed as an argument to Release(). (%x,%x) [Releasing]" + OS_REPORT_ERROR("[ERROR] cBgS::Release() %dに登録されている作業領域のポインターと、Release()に引数で渡されているポインターが異なる。(%x,%x) [解放実行]", id, m_chk_element[id].m_bgw_base_ptr, pbgw); + JUT_WARN(431, "%s", "cBgS::Release() data error."); + } + #endif + m_chk_element[id].Release(); - p_data->Release(); + pbgw->Release(); } else { + #if DEBUG + if (id == 0x100) { + // "cBgS::Release() attempting to release unregistered terrain. operation won't be processed." + OS_WARNING("cBgS::Release() 登録していない地形をReleaseしようとしています。処理しません。\n"); + } else { + // "[Error] cBgS::Release() Error[Check id=%d won't be released.](dBgW_Base=%x)" + OS_REPORT_ERROR("[Error] cBgS::Release() Error[id=%d番のチェックはリリースしません。](dBgW_Base=%x)\n", id, pbgw); + + if (!pbgw->ChkUsed()) { + // "Data [%d] is not being used." + OS_REPORT_ERROR("データ[%d]は使っていません。\n", id); + } + + if (!m_chk_element[id].ChkUsed()) { + // "Table [%d] is not being used." + OS_REPORT_ERROR("テーブル[%d]は使っていません。\n", id); + } + } + #endif + return 1; } return 0; } +#if DEBUG +u8 lbl_8074C7F0; // belongs in d_bg_w? +static u8 lbl_8074C7F8; +#endif + void cBgS::Ct() { l_SetCounter = 0; for (int i = 0; i < 0x100; i++) { m_chk_element[i].Init(); } + + #if DEBUG + lbl_8074C7F8 = 0; + lbl_8074C7F0 = 0; + #endif } void cBgS::Dt() { for (int i = 0; i < 0x100; i++) { if (m_chk_element[i].ChkUsed()) { + JUT_WARN(499, "%s", "cBgS::Dt() release error."); + OS_REPORT_ERROR("[ERROR] ========== cBgS::Dt() 消し残し地形チェックがあります。id=%d ==========\n", i); + OS_REPORT_ERROR("!!!!!!!!! 勝手に消しときます !!!!!!!!\n"); m_chk_element[i].Release(); } } @@ -101,41 +274,41 @@ void cBgS::Dt() { } } -bool cBgS::LineCross(cBgS_LinChk* p_line) { - p_line->ClearPi(); - p_line->ClrHit(); - p_line->PreCalc(); +bool cBgS::LineCross(cBgS_LinChk* plinchk) { + plinchk->ClearPi(); + plinchk->ClrHit(); + plinchk->PreCalc(); cBgS_ChkElm* elm = m_chk_element; for (int i = 0; i < 0x100; i++) { if (elm->ChkUsed() && !elm->m_bgw_base_ptr->ChkNotReady() && - !p_line->ChkSameActorPid(elm->m_actor_id) && elm->m_bgw_base_ptr->LineCheck(p_line)) + !plinchk->ChkSameActorPid(elm->m_actor_id) && elm->m_bgw_base_ptr->LineCheck(plinchk)) { - p_line->SetActorInfo(i, elm->m_bgw_base_ptr, elm->m_actor_id); - p_line->SetHit(); + plinchk->SetActorInfo(i, elm->m_bgw_base_ptr, elm->m_actor_id); + plinchk->SetHit(); } elm++; } - return p_line->ChkHit(); + return plinchk->ChkHit(); } -f32 cBgS::GroundCross(cBgS_GndChk* p_gnd) { - p_gnd->SetNowY(-G_CM3D_F_INF); - p_gnd->ClearPi(); - p_gnd->PreCheck(); +f32 cBgS::GroundCross(cBgS_GndChk* pgndchk) { + pgndchk->SetNowY(-G_CM3D_F_INF); + pgndchk->ClearPi(); + pgndchk->PreCheck(); cBgS_ChkElm* elm = m_chk_element; for (int i = 0; i < 0x100; i++) { if (elm->ChkUsed() && !elm->m_bgw_base_ptr->ChkNotReady() && - !p_gnd->ChkSameActorPid(elm->m_actor_id) && elm->m_bgw_base_ptr->GroundCross(p_gnd)) + !pgndchk->ChkSameActorPid(elm->m_actor_id) && elm->m_bgw_base_ptr->GroundCross(pgndchk)) { - p_gnd->SetActorInfo(i, elm->m_bgw_base_ptr, elm->m_actor_id); + pgndchk->SetActorInfo(i, elm->m_bgw_base_ptr, elm->m_actor_id); } elm++; } - return p_gnd->GetNowY(); + return pgndchk->GetNowY(); } template <> @@ -145,25 +318,25 @@ void be_swap(cBgD_Vtx_t& val) { be_swap(val.z); } -void* cBgS::ConvDzb(void* p_dzb) { - cBgD_t* pbgd = (cBgD_t*)p_dzb; +void* cBgS::ConvDzb(void* pdzb) { + cBgD_t* pbgd = (cBgD_t*)pdzb; if (((pbgd->mFlags & 0x80000000) == 0)) { pbgd->mFlags |= 0x80000000; } else { - return p_dzb; + return pdzb; } #if TARGET_PC - pbgd->m_v_tbl.setBase(p_dzb); - pbgd->m_t_tbl.setBase(p_dzb); - pbgd->m_b_tbl.setBase(p_dzb); - pbgd->m_tree_tbl.setBase(p_dzb); - pbgd->m_g_tbl.setBase(p_dzb); - pbgd->m_ti_tbl.setBase(p_dzb); + pbgd->m_v_tbl.setBase(pdzb); + pbgd->m_t_tbl.setBase(pdzb); + pbgd->m_b_tbl.setBase(pdzb); + pbgd->m_tree_tbl.setBase(pdzb); + pbgd->m_g_tbl.setBase(pdzb); + pbgd->m_ti_tbl.setBase(pdzb); for (int i = 0; i < pbgd->m_g_num; i++) { - ((cBgD_Grp_t*)pbgd->m_g_tbl)[i].m_name.setBase(p_dzb); + ((cBgD_Grp_t*)pbgd->m_g_tbl)[i].m_name.setBase(pdzb); } #if TARGET_LITTLE_ENDIAN @@ -174,30 +347,30 @@ void* cBgS::ConvDzb(void* p_dzb) { #else if (pbgd->m_v_tbl != 0) { - pbgd->m_v_tbl += (uintptr_t)p_dzb; + pbgd->m_v_tbl += (uintptr_t)pdzb; } - pbgd->m_t_tbl += (uintptr_t)p_dzb; - pbgd->m_b_tbl += (uintptr_t)p_dzb; - pbgd->m_tree_tbl += (uintptr_t)p_dzb; - pbgd->m_g_tbl += (uintptr_t)p_dzb; - pbgd->m_ti_tbl += (uintptr_t)p_dzb; + pbgd->m_t_tbl += (uintptr_t)pdzb; + pbgd->m_b_tbl += (uintptr_t)pdzb; + pbgd->m_tree_tbl += (uintptr_t)pdzb; + pbgd->m_g_tbl += (uintptr_t)pdzb; + pbgd->m_ti_tbl += (uintptr_t)pdzb; for (int i = 0; i < pbgd->m_g_num; i++) { - ((cBgD_Grp_t_*)pbgd->m_g_tbl)[i].strOffset = - (uintptr_t)p_dzb + ((cBgD_Grp_t_*)pbgd->m_g_tbl)[i].strOffset; + ((cBgD_Grp_t_*)pbgd->m_g_tbl)[i].strOffset = (uintptr_t)pdzb + ((cBgD_Grp_t_*)pbgd->m_g_tbl)[i].strOffset; } #endif - return p_dzb; + return pdzb; } fopAc_ac_c* cBgS::GetActorPointer(int actor_index) const { + JUT_ASSERT(631, 0 <= actor_index && actor_index < 256); return m_chk_element[actor_index].m_actor_ptr; } -dBgW_Base* cBgS::GetBgWBasePointer(cBgS_PolyInfo const& poly) const { - int bg_index = poly.GetBgIndex(); +dBgW_Base* cBgS::GetBgWBasePointer(const cBgS_PolyInfo& polyinfo) const { + int bg_index = polyinfo.GetBgIndex(); if (bg_index < 0 || bg_index >= 0x100 || !m_chk_element[bg_index].ChkUsed()) { return NULL; @@ -205,83 +378,147 @@ dBgW_Base* cBgS::GetBgWBasePointer(cBgS_PolyInfo const& poly) const { return m_chk_element[bg_index].m_bgw_base_ptr; } -bool cBgS::ChkPolySafe(cBgS_PolyInfo const& poly) { - if (!poly.ChkSetInfo()) { +bool cBgS::ChkPolySafe(const cBgS_PolyInfo& polyinfo) { + if (!polyinfo.ChkSetInfo()) { return false; } - int bg_index = poly.GetBgIndex(); + int bg_index = polyinfo.GetBgIndex(); if (bg_index < 0 || bg_index >= 0x100) { return false; - } else { - if (m_chk_element[bg_index].ChkUsed()) { - return poly.ChkSafe(m_chk_element[bg_index].m_bgw_base_ptr, - m_chk_element[bg_index].m_actor_id); - } else { - return false; - } } + + if (!m_chk_element[bg_index].ChkUsed()) { + return false; + } + + return polyinfo.ChkSafe(m_chk_element[bg_index].m_bgw_base_ptr, m_chk_element[bg_index].m_actor_id); } -s32 cBgS::GetGrpRoomId(cBgS_PolyInfo const& poly) const { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetGrpRoomIndex(poly); - } else { +s32 cBgS::GetGrpRoomId(const cBgS_PolyInfo& polyinfo) const { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(697, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { return 0xFF; } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetGrpRoomIndex(polyinfo); } -bool cBgS::GetTriPla(cBgS_PolyInfo const& poly, cM3dGPla* p_pla) const { - int bg_index = poly.GetBgIndex(); +bool cBgS::GetTriPla(const cBgS_PolyInfo& polyinfo, cM3dGPla* ppla) const { + int bg_index = polyinfo.GetBgIndex(); if (bg_index < 0 || bg_index >= 0x100 || !m_chk_element[bg_index].ChkUsed()) { return false; } - *p_pla = m_chk_element[bg_index].m_bgw_base_ptr->GetTriPla(poly); + *ppla = m_chk_element[bg_index].m_bgw_base_ptr->GetTriPla(polyinfo); return true; } -bool cBgS::GetTriPnt(cBgS_PolyInfo const& poly, cXyz* param_1, cXyz* param_2, cXyz* param_3) const { - int id = poly.GetBgIndex(); +bool cBgS::GetTriPnt(const cBgS_PolyInfo& polyinfo, cXyz* ppnt0, cXyz* ppnt1, cXyz* ppnt2) const { + int id = polyinfo.GetBgIndex(); + JUT_ASSERT(737, 0 <= id && id < 256); + if (!m_chk_element[id].ChkUsed()) { return false; } - return m_chk_element[id].m_bgw_base_ptr->GetTriPnt(poly, param_1, param_2, param_3); + return m_chk_element[id].m_bgw_base_ptr->GetTriPnt(polyinfo, ppnt0, ppnt1, ppnt2); } -void cBgS::ShdwDraw(cBgS_ShdwDraw* p_shdw) { +void cBgS::Draw() {} + +void cBgS::ShdwDraw(cBgS_ShdwDraw* pshdw) { cBgS_ChkElm* elm = m_chk_element; for (int i = 0; i < 0x100; i++) { if (elm->ChkUsed()) { - elm->m_bgw_base_ptr->ShdwDraw(p_shdw); + elm->m_bgw_base_ptr->ShdwDraw(pshdw); } elm++; } } -u32 cBgS::GetGrpInf(cBgS_PolyInfo const& poly) const { - int id = poly.GetBgIndex(); - if (!m_chk_element[id].ChkUsed()) { +u32 cBgS::GetGrpInf(const cBgS_PolyInfo& polyinfo) const { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(803, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { return -1; } - return m_chk_element[id].m_bgw_base_ptr->GetGrpInf(poly); + return m_chk_element[bg_index].m_bgw_base_ptr->GetGrpInf(polyinfo); } +#if DEBUG +static OSStopwatch s_ground_sw; +static OSStopwatch s_line_sw; +static OSStopwatch s_wall_correct_sw; +static OSStopwatch s_roof_sw; +static OSStopwatch s_spl_sw; +static OSStopwatch s_shdw_sw; +static OSStopwatch s_sph_chk_sw; +static OSStopwatch s_capt_poly_sw; +#endif + +static dBgS_InsideHIO s_InsideHio; + void dBgS::Ct() { cBgS::Ct(); + + #if DEBUG + g_ground_counter = 0; + g_line_counter = 0; + g_acch_wall_counter = 0; + g_roof_counter = 0; + g_spl_counter = 0; + g_shdw_counter = 0; + g_sph_counter = 0; + g_capt_poly_counter = 0; + + m_hio.id = mDoHIO_CREATE_CHILD("zelda地形チェック", &m_hio); + s_InsideHio.id = mDoHIO_CREATE_CHILD("zelda地形チェック内部", &s_InsideHio); + + OSInitStopwatch(&s_ground_sw, "GroundCheck"); + OSResetStopwatch(&s_ground_sw); + + OSInitStopwatch(&s_line_sw, "LineCheck"); + OSResetStopwatch(&s_line_sw); + + OSInitStopwatch(&s_wall_correct_sw, "WallCorrect()"); + OSResetStopwatch(&s_wall_correct_sw); + + OSInitStopwatch(&s_roof_sw, "RoofChk()"); + OSResetStopwatch(&s_roof_sw); + + OSInitStopwatch(&s_spl_sw, "SplGrpChk()"); + OSResetStopwatch(&s_spl_sw); + + OSInitStopwatch(&s_shdw_sw, "ShdwDraw()"); + OSResetStopwatch(&s_shdw_sw); + + OSInitStopwatch(&s_sph_chk_sw, "SphChk()"); + OSResetStopwatch(&s_sph_chk_sw); + + OSInitStopwatch(&s_capt_poly_sw, "CaptPoly()"); + OSResetStopwatch(&s_capt_poly_sw); + #endif } void dBgS::Dt() { cBgS::Dt(); + + #if DEBUG + mDoHIO_DELETE_CHILD(m_hio.id); + mDoHIO_DELETE_CHILD(s_InsideHio.id); + #endif } void dBgS::ClrMoveFlag() { for (int i = 0; i < 0x100; i++) { if (m_chk_element[i].ChkUsed()) { - m_chk_element[i].m_bgw_base_ptr->OffMoveFlag(); + dBgW_Base* bgw_base = m_chk_element[i].m_bgw_base_ptr; + bgw_base->OffMoveFlag(); } } } @@ -290,37 +527,334 @@ void dBgS::Move() { cBgS_ChkElm* elm = m_chk_element; for (int i = 0; i < 0x100; i++) { if (elm->ChkUsed()) { - elm->m_bgw_base_ptr->CalcDiffShapeAngleY(elm->m_actor_ptr->shape_angle.y); + fopAc_ac_c* bgw_actor = elm->m_actor_ptr; + elm->m_bgw_base_ptr->CalcDiffShapeAngleY(bgw_actor->shape_angle.y); } elm++; } + + #if DEBUG + if (lbl_8074C7F8 == TRUE) { + JUTReport(20, 100, "WARNING:kcl:WCS(wall/roof poly num) is over."); + } + + if (lbl_8074C7F0 == TRUE) { + JUTReport(20, 200, "WARNING:dzb:wcs(wall/roof poly num) is over."); + } + #endif } -bool dBgS::Regist(dBgW_Base* pbgw, fopAc_ac_c* p_actor) { +void dBgS_AabDraw(cM3dGAab& aab, GXColor& color) { + cXyz points[8]; + + points[0].x = aab.GetMinP()->x; + points[0].y = aab.GetMaxP()->y; + points[0].z = aab.GetMinP()->z; + + points[1].x = aab.GetMaxP()->x; + points[1].y = aab.GetMaxP()->y; + points[1].z = aab.GetMinP()->z; + + points[2].x = aab.GetMinP()->x; + points[2].y = aab.GetMaxP()->y; + points[2].z = aab.GetMaxP()->z; + + points[3].x = aab.GetMaxP()->x; + points[3].y = aab.GetMaxP()->y; + points[3].z = aab.GetMaxP()->z; + + points[4].x = aab.GetMinP()->x; + points[4].y = aab.GetMinP()->y; + points[4].z = aab.GetMinP()->z; + + points[5].x = aab.GetMaxP()->x; + points[5].y = aab.GetMinP()->y; + points[5].z = aab.GetMinP()->z; + + points[6].x = aab.GetMinP()->x; + points[6].y = aab.GetMinP()->y; + points[6].z = aab.GetMaxP()->z; + + points[7].x = aab.GetMaxP()->x; + points[7].y = aab.GetMinP()->y; + points[7].z = aab.GetMaxP()->z; + + dDbVw_drawCube8pOpa(points, color); +} + +static int white_draw(dBgS_CaptPoly* capt, cBgD_Vtx_t* vtxList, int v0, int v1, int v2, cM3dGPla* plane) { + cXyz raise; + PSVECScale(&plane->mNormal, &raise, s_InsideHio.m_raise_amount + 1.0f); + + cXyz start; + start.set(vtxList[v0]); + cXyz end; + end.set(vtxList[v1]); + PSVECAdd(&raise, &start, &start); + PSVECAdd(&raise, &end, &end); + + GXColor color = {0xFF, 0xFF, 0xFF, 0xFF}; + dDbVw_drawLineOpa(start, end, color, TRUE, 12); + + start.set(vtxList[v1]); + end.set(vtxList[v2]); + PSVECAdd(&raise, &start, &start); + PSVECAdd(&raise, &end, &end); + dDbVw_drawLineOpa(start, end, color, TRUE, 12); + + start.set(vtxList[v2]); + end.set(vtxList[v0]); + PSVECAdd(&raise, &start, &start); + PSVECAdd(&raise, &end, &end); + dDbVw_drawLineOpa(start, end, color, TRUE, 12); + return 0; +} + +static int poly_draw(dBgS_CaptPoly* capt, cBgD_Vtx_t* vtxList, int v0, int v1, int v2, cM3dGPla* plane) { + UNUSED(capt); + + cXyz points[3]; + GXColor ground_color = {0xFF, 0, 0, 0xFF}; + GXColor roof_color = {0, 0, 0xFF, 0xFF}; + GXColor wall_color = {0, 0xFF, 0, 0xFF}; + +#if TARGET_PC + dusk::ImGuiMenuTools::CollisionViewSettings collisionViewSettings = dusk::g_imguiConsole.getCollisionViewSettings(); + f32 view_opacity = 255 * (collisionViewSettings.m_terrainViewOpacity / 100.0f); + ground_color.a = view_opacity; + roof_color.a = view_opacity; + wall_color.a = view_opacity; +#endif + + cXyz raise; + PSVECScale(&plane->mNormal, &raise, s_InsideHio.m_raise_amount); + + points[0] = vtxList[v0]; + points[1] = vtxList[v1]; + points[2] = vtxList[v2]; + + PSVECAdd(&points[0], &raise, &points[0]); + PSVECAdd(&points[1], &raise, &points[1]); + PSVECAdd(&points[2], &raise, &points[2]); + + if (cBgW_CheckBGround(plane->mNormal.y)) { + if (!s_InsideHio.ChkGroundOff()) { + dDbVw_drawTriangleOpa(points, ground_color, TRUE); + } + } else if (cBgW_CheckBRoof(plane->mNormal.y)) { + if (!s_InsideHio.ChkRoofOff()) { + dDbVw_drawTriangleOpa(points, roof_color, TRUE); + } + } else { + if (!s_InsideHio.ChkWallOff()) { + dDbVw_drawTriangleOpa(points, wall_color, TRUE); + } + } + + return 0; +} + +void dBgS::Draw() { + cBgS::Draw(); + +#if TARGET_PC + #define IMGUI_TOGGLE_HIO_FLAG(status, flag) \ + if (status) { \ + s_InsideHio.m_flags |= flag; \ + } else { \ + s_InsideHio.m_flags &= ~flag; \ + } + + dusk::ImGuiMenuTools::CollisionViewSettings collisionViewSettings = dusk::g_imguiConsole.getCollisionViewSettings(); + IMGUI_TOGGLE_HIO_FLAG(collisionViewSettings.m_enableTerrainView, dBgS_InsideHIO::FLAG_DISP_POLY_e); + IMGUI_TOGGLE_HIO_FLAG(collisionViewSettings.m_enableWireframe, dBgS_InsideHIO::FLAG_WHITE_WIRE_e); +#endif + + if (s_InsideHio.ChkDispPoly()) { + cM3dGAab aab; + if (s_InsideHio.ChkPlayerAround()) { + fopAc_ac_c* player = dComIfGp_getPlayer(0); + cXyz min; + cXyz max; + + f32 var_f31 = fabsf(s_InsideHio.m_p0.x); + +#if TARGET_PC + dusk::ImGuiMenuTools::CollisionViewSettings collisionViewSettings = dusk::g_imguiConsole.getCollisionViewSettings(); + var_f31 = collisionViewSettings.m_drawRange; +#endif + + min.x = player->current.pos.x - var_f31; + min.y = player->current.pos.y - var_f31; + min.z = player->current.pos.z - var_f31; + max.x = player->current.pos.x + var_f31; + max.y = player->current.pos.y + var_f31; + max.z = player->current.pos.z + var_f31; + + aab.Set(&min, &max); + } else { + aab.ClearForMinMax(); + aab.SetMinMax(s_InsideHio.m_p0); + aab.SetMinMax(s_InsideHio.m_p1); + } + + if (s_InsideHio.ChkDispDpArea()) { + static GXColor l_color = {0, 0, 0xFF, 0x80}; + dBgS_AabDraw(aab, l_color); + } + + dBgS_CaptPoly capt; + capt.Set(*aab.GetMinP(), *aab.GetMaxP()); + + if (s_InsideHio.ChkDispWaterPoly()) { + capt.OffFullGrp(); + capt.OnWaterGrp(); + } else { + capt.OnFullGrp(); + } + + if (s_InsideHio.ChkWhiteWire()) { + capt.SetCallback(white_draw); + CaptPoly(capt); + } + + capt.SetCallback(poly_draw); + CaptPoly(capt); + } + + #if DEBUG + if (m_hio.ChkCheckCounter()) { + OSReport("ラインチェック %d回\n", g_line_counter); + g_line_counter = 0; + + OSReport("アクター地形チェック壁処理 %d回\n", g_acch_wall_counter); + g_acch_wall_counter = 0; + + OSReport("天井チェック %d回\n", g_roof_counter); + g_roof_counter = 0; + + OSReport("Splチェック %d回\n", g_spl_counter); + g_spl_counter = 0; + + OSReport("床チェック %d回\n", g_ground_counter); + g_ground_counter = 0; + + OSReport("リアル影 %d回\n", g_shdw_counter); + g_shdw_counter = 0; + + OSReport("球チェック %d回\n", g_sph_counter); + g_sph_counter = 0; + + OSReport("ポリゴンキャプチャ %d\n", g_capt_poly_counter); + g_capt_poly_counter = 0; + } + #endif + + if (m_hio.ChkObjLineCheck()) { + dBgS_LinChk linechk; + linechk.Set(&m_hio.m_linecheck_start, &m_hio.m_linecheck_end, NULL); + + dDbVw_drawLineOpa(m_hio.m_linecheck_start, m_hio.m_linecheck_end, COMPOUND_LITERAL(GXColor){0xFF, 0xFF, 0xFF, 0xFF}, TRUE, 12); + dDbVw_drawSphereOpa(m_hio.m_linecheck_start, 10.0f, COMPOUND_LITERAL(GXColor){0xFF, 0, 0, 0xFF}, TRUE); + dDbVw_drawSphereOpa(m_hio.m_linecheck_end, 10.0f, COMPOUND_LITERAL(GXColor){0, 0, 0xFF, 0xFF}, TRUE); + + if (LineCross(&linechk)) { + dDbVw_drawSphereOpa(*linechk.GetCrossP(), 10.0f, COMPOUND_LITERAL(GXColor){0, 0xFF, 0, 0xFF}, TRUE); + } + } + + if (m_hio.ChkGndCheck()) { + dBgS_ObjGndChk gndchk; + cXyz sp54; + + if (!s_InsideHio.ChkGndChkPlayerUnder()) { + sp54 = m_hio.m_gndcheck_pos; + } else { + fopAc_ac_c* player = dComIfGp_getPlayer(0); + cXyz sp48(player->current.pos); + sp48.y += 200.0f; + } + + gndchk.SetPos(&sp54); + f32 var_f30 = dComIfG_Bgsp().GroundCross(&gndchk); + + cXyz sp3C; + sp3C = sp54; + sp3C.y = var_f30; + + dDbVw_drawLineOpa(sp54, sp3C, COMPOUND_LITERAL(GXColor){0, 0xFF, 0, 0xFF}, TRUE, 12); + dDbVw_drawPointOpa(sp3C, COMPOUND_LITERAL(GXColor){0xFF, 0, 0, 0xFF}, TRUE, 12); + + if (var_f30 != G_CM3D_F_INF) { + DrawPoly(gndchk, COMPOUND_LITERAL(GXColor){0xFF, 0xFF, 0, 0xFF}); + } + } +} + +void dBgS::CaptPoly(dBgS_CaptPoly& capt) { + if (!m_hio.ChkCaptPolyOff()) { + #if DEBUG + if (m_hio.ChkCheckCounter()) { + g_capt_poly_counter++; + } + + if (m_hio.ChkCaptPolyTimer()) { + OSStartStopwatch(&s_capt_poly_sw); + } + #endif + + cBgS_ChkElm* elm = m_chk_element; + for (int i = 0; i < 0x100; i++) { + if (elm->ChkUsed()) { + elm->m_bgw_base_ptr->CaptPoly(capt); + } + elm++; + } + + #if DEBUG + if (m_hio.ChkCaptPolyTimer()) { + OSStopStopwatch(&s_capt_poly_sw); + OSDumpStopwatch(&s_capt_poly_sw); + } + #endif + } +} + +void dBgS::ChkDeleteActorRegist(fopAc_ac_c* actor) { + for (int i = 0; i < 0x100; i++) { + if (m_chk_element[i].ChkUsed() && actor == m_chk_element[i].m_actor_ptr) { + OS_REPORT_ERROR("dBgS::ChkDeleteActorRegist() [%d]削除されたアクターのポインターが、まだ登録されています。\n", i); + } + } +} + +bool dBgS::Regist(dBgW_Base* pbgw, fopAc_ac_c* pactor) { if (pbgw == NULL) { + OS_REPORT_ERROR("dBgS::Regist() pbgwがNULLのため登録できません。\n"); return true; } - if (p_actor != NULL && pbgw->ChkMoveBg()) { - pbgw->SetOldShapeAngleY(p_actor->shape_angle.y); - pbgw->SetRoomId(fopAcM_GetRoomNo(p_actor)); + if (pactor != NULL && pbgw->ChkMoveBg()) { + fopAc_ac_c* actor = pactor; + pbgw->SetOldShapeAngleY(actor->shape_angle.y); + pbgw->SetRoomId(fopAcM_GetRoomNo(actor)); } - return cBgS::Regist(pbgw, fopAcM_GetID(p_actor), p_actor); + return cBgS::Regist(pbgw, fopAcM_GetID(pactor), pactor); } void dBgW_Base::SetOldShapeAngleY(s16 shape_angle) { m_old_ShapeAngleY = shape_angle; } -bool dBgS::ChkMoveBG(cBgS_PolyInfo const& poly) { - dBgW_Base* base = dComIfG_Bgsp().GetBgWBasePointer(poly); - if (base != NULL) { - if (base->ChkLock()) { +bool dBgS::ChkMoveBG(const cBgS_PolyInfo& polyinfo) { + dBgW_Base* pbgw = dComIfG_Bgsp().GetBgWBasePointer(polyinfo); + if (pbgw != NULL) { + if (pbgw->ChkLock()) { return false; } - if (base->ChkMoveBg()) { + if (pbgw->ChkMoveBg()) { return true; } } @@ -328,182 +862,216 @@ bool dBgS::ChkMoveBG(cBgS_PolyInfo const& poly) { return false; } -bool dBgS::ChkMoveBG_NoDABg(cBgS_PolyInfo const& poly) { - dBgW_Base* base = dComIfG_Bgsp().GetBgWBasePointer(poly); - if (base != NULL && base->ChkMoveBg()) { +bool dBgS::ChkMoveBG_NoDABg(const cBgS_PolyInfo& polyinfo) { + dBgW_Base* pbgw = dComIfG_Bgsp().GetBgWBasePointer(polyinfo); + if (pbgw != NULL && pbgw->ChkMoveBg()) { return true; } return false; } -s32 dBgS::GetExitId(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetExitId(poly); - } else { +s32 dBgS::GetExitId(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1421, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { return 0x3F; } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetExitId(polyinfo); } -s32 dBgS::GetPolyColor(cBgS_PolyInfo const& poly) { - if (!poly.ChkSetInfo()) { +s32 dBgS::GetPolyColor(const cBgS_PolyInfo& polyinfo) { + if (!polyinfo.ChkSetInfo()) { return 0xFF; } - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetPolyColor(poly); - } + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1443, 0 <= bg_index && bg_index < 256); - return 0xFF; -} - -BOOL dBgS::GetHorseNoEntry(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetHorseNoEntry(poly); - } - - return false; -} - -int dBgS::GetSpecialCode(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetSpecialCode(poly); - } - - return 0; -} - -int dBgS::GetMagnetCode(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetMagnetCode(poly); - } - - return 0; -} - -int dBgS::GetMonkeyBarsCode(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetMonkeyBarsCode(poly); - } - - return 0; -} - -u32 dBgS::GetUnderwaterRoofCode(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetUnderwaterRoofCode(poly.GetPolyIndex()); - } - - return 0; -} - -s32 dBgS::GetWallCode(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetWallCode(poly); - } - - return 0; -} - -int dBgS::GetPolyAtt0(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetPolyAtt0(poly); - } - - return 0; -} - -int dBgS::GetPolyAtt1(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetPolyAtt1(poly); - } - - return 0; -} - -int dBgS::GetGroundCode(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetGroundCode(poly); - } - - return 0; -} - -s32 dBgS::GetCamMoveBG(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetCamMoveBG(poly); - } - - return 0xFF; -} - -s32 dBgS::GetRoomCamId(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetRoomCamId(poly); - } - - return 0xFF; -} - -s32 dBgS::GetRoomPathId(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetRoomPathId(poly); - } - - return 0xFF; -} - -s32 dBgS::GetRoomPathPntNo(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - return m_chk_element[bg_index].m_bgw_base_ptr->GetRoomPathPntNo(poly); - } - - return 0xFF; -} - -int dBgS::GetGrpSoundId(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); - JUT_ASSERT(1761, 0 <= bg_index && bg_index < 256); if (!m_chk_element[bg_index].ChkUsed()) { return 0xFF; } - dBgW_Base* r30 = m_chk_element[bg_index].m_bgw_base_ptr; - return r30->GetGrpSoundId(poly); + + return m_chk_element[bg_index].m_bgw_base_ptr->GetPolyColor(polyinfo); } -u32 dBgS::ChkGrpInf(cBgS_PolyInfo const& poly, u32 param_1) { - u32 grp_inf = GetGrpInf(poly); - return grp_inf & param_1; +BOOL dBgS::GetHorseNoEntry(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1460, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return false; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetHorseNoEntry(polyinfo); } -int dBgS::GetRoomId(cBgS_PolyInfo const& poly) { - if (!poly.ChkSetInfo()) { +int dBgS::GetSpecialCode(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1477, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetSpecialCode(polyinfo); +} + +int dBgS::GetMagnetCode(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1494, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetMagnetCode(polyinfo); +} + +int dBgS::GetMonkeyBarsCode(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1509, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetMonkeyBarsCode(polyinfo); +} + +u32 dBgS::GetUnderwaterRoofCode(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1524, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetUnderwaterRoofCode(polyinfo.GetPolyIndex()); +} + +s32 dBgS::GetWallCode(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1574, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetWallCode(polyinfo); +} + +int dBgS::GetPolyAtt0(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1591, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetPolyAtt0(polyinfo); +} + +int dBgS::GetPolyAtt1(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1608, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetPolyAtt1(polyinfo); +} + +int dBgS::GetGroundCode(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1625, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetGroundCode(polyinfo); +} + +s32 dBgS::GetCamMoveBG(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1667, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0xFF; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetCamMoveBG(polyinfo); +} + +s32 dBgS::GetRoomCamId(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1684, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0xFF; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetRoomCamId(polyinfo); +} + +s32 dBgS::GetRoomPathId(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1700, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0xFF; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetRoomPathId(polyinfo); +} + +s32 dBgS::GetRoomPathPntNo(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1717, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0xFF; + } + + return m_chk_element[bg_index].m_bgw_base_ptr->GetRoomPathPntNo(polyinfo); +} + +int dBgS::GetGrpSoundId(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(1761, 0 <= bg_index && bg_index < 256); + + if (!m_chk_element[bg_index].ChkUsed()) { + return 0xFF; + } + + dBgW_Base* pbgw = m_chk_element[bg_index].m_bgw_base_ptr; + return pbgw->GetGrpSoundId(polyinfo); +} + +u32 dBgS::ChkGrpInf(const cBgS_PolyInfo& polyinfo, u32 mask) { + u32 grp_inf = GetGrpInf(polyinfo); + return grp_inf & mask; +} + +int dBgS::GetRoomId(const cBgS_PolyInfo& polyinfo) { + if (!polyinfo.ChkSetInfo()) { return -1; } - int id = poly.GetBgIndex(); - if (!ChkPolySafe(poly)) { + int id = polyinfo.GetBgIndex(); + JUT_ASSERT(1804, 0 <= id && id < 256); + if (!ChkPolySafe(polyinfo)) { return -1; } - s32 roomId = m_chk_element[id].m_bgw_base_ptr->GetRoomId(); + dBgW_Base* pbgw = m_chk_element[id].m_bgw_base_ptr; + int roomId = pbgw->GetRoomId(); if (roomId == 0xFF) { - roomId = GetGrpRoomId(poly); + roomId = GetGrpRoomId(polyinfo); if (roomId == 0xFF) { roomId = -1; } @@ -512,29 +1080,110 @@ int dBgS::GetRoomId(cBgS_PolyInfo const& poly) { return roomId; } -bool dBgS::GetPolyAttackThrough(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); +bool dBgS::GetPolyAttackThrough(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); JUT_ASSERT(1894, 0 <= bg_index && bg_index < 256); + if (!m_chk_element[bg_index].ChkUsed()) { return false; } - dBgW_Base* r30 = m_chk_element[bg_index].m_bgw_base_ptr; - return r30->GetAttackThrough(poly.GetPolyIndex()) != 0; + + dBgW_Base* pbgw = m_chk_element[bg_index].m_bgw_base_ptr; + return pbgw->GetAttackThrough(polyinfo.GetPolyIndex()) != 0; } -u32 dBgS::ChkPolyHSStick(cBgS_PolyInfo const& poly) { - int bg_index = poly.GetBgIndex(); +u32 dBgS::ChkPolyHSStick(const cBgS_PolyInfo& polyinfo) { + int bg_index = polyinfo.GetBgIndex(); JUT_ASSERT(1912, 0 <= bg_index && bg_index < 256); + if (!m_chk_element[bg_index].ChkUsed()) { return 0; } - dBgW_Base* r30 = m_chk_element[bg_index].m_bgw_base_ptr; - return r30->GetPolyHSStick(poly.GetPolyIndex()); + + dBgW_Base* pbgw = m_chk_element[bg_index].m_bgw_base_ptr; + return pbgw->GetPolyHSStick(polyinfo.GetPolyIndex()); } -void dBgS::WallCorrect(dBgS_Acch* p_acch) { - p_acch->CalcWallRR(); - p_acch->CalcMovePosWork(); +// these don't appear to be inlined based on the static var usage and location within the TU, +// but if they're not inlined then the calls in retail don't resolve to cBgS variants. +// Ifdef'ing for now to preserve both versions behavior +#if DEBUG +f32 dBgS::GroundCross(cBgS_GndChk* pgndchk) { + if (m_hio.ChkCheckCounter()) { + g_ground_counter++; + } + + if (m_hio.ChkGroundCheckTimer()) { + OSStartStopwatch(&s_ground_sw); + } + + f32 rt = cBgS::GroundCross(pgndchk); + if (m_hio.ChkGroundCheckTimer()) { + OSStopStopwatch(&s_ground_sw); + OSDumpStopwatch(&s_ground_sw); + } + + return rt; +} + +bool dBgS::LineCross(cBgS_LinChk* plinchk) { + if (m_hio.ChkLineOff()) { + return false; + } + + if (m_hio.ChkCheckCounter()) { + g_line_counter++; + } + + if (m_hio.ChkLineTimer()) { + OSStartStopwatch(&s_line_sw); + } + + bool rt = cBgS::LineCross(plinchk); + if (m_hio.ChkLineTimer()) { + OSStopStopwatch(&s_line_sw); + OSDumpStopwatch(&s_line_sw); + } + + return rt; +} + +void dBgS::ShdwDraw(cBgS_ShdwDraw* pshdwDraw) { + if (!m_hio.ChkShdwDrawOff()) { + if (m_hio.ChkCheckCounter()) { + g_shdw_counter++; + } + + if (m_hio.ChkShdwDrawTimer()) { + OSStartStopwatch(&s_shdw_sw); + } + + cBgS::ShdwDraw(pshdwDraw); + if (m_hio.ChkShdwDrawTimer()) { + OSStopStopwatch(&s_shdw_sw); + OSDumpStopwatch(&s_shdw_sw); + } + } +} +#endif + +void dBgS::WallCorrect(dBgS_Acch* pacch) { + #if DEBUG + if (m_hio.ChkAcchWallOff()) { + return; + } + + if (m_hio.ChkCheckCounter()) { + g_acch_wall_counter++; + } + + if (m_hio.ChkAcchWallTimer()) { + OSStartStopwatch(&s_wall_correct_sw); + } + #endif + + pacch->CalcWallRR(); + pacch->CalcMovePosWork(); for (int i = 0; i < 3; i++) { cBgS_ChkElm* elm = m_chk_element; @@ -543,21 +1192,42 @@ void dBgS::WallCorrect(dBgS_Acch* p_acch) { if (elm->ChkUsed() && !elm->m_bgw_base_ptr->ChkNotReady()) { dBgW_Base* pbgw = elm->m_bgw_base_ptr; - if (pbgw->ChkPriority(i) && !p_acch->ChkSameActorPid(elm->m_actor_id)) { - if (!p_acch->ChkMoveBGOnly() || (pbgw->ChkMoveBg() && !pbgw->ChkLock())) { - p_acch->SetNowActorInfo(j, elm->m_bgw_base_ptr, elm->m_actor_id); - pbgw->WallCorrect(p_acch); + if (pbgw->ChkPriority(i) && !pacch->ChkSameActorPid(elm->m_actor_id)) { + if (!pacch->ChkMoveBGOnly() || (pbgw->ChkMoveBg() && !pbgw->ChkLock())) { + pacch->SetNowActorInfo(j, elm->m_bgw_base_ptr, elm->m_actor_id); + pbgw->WallCorrect(pacch); } } } elm++; } } + + #if DEBUG + if (m_hio.ChkAcchWallTimer()) { + OSStopStopwatch(&s_wall_correct_sw); + OSDumpStopwatch(&s_wall_correct_sw); + } + #endif } -void dBgS::WallCorrectSort(dBgS_Acch* p_acch) { - p_acch->CalcWallRR(); - p_acch->CalcMovePosWork(); +void dBgS::WallCorrectSort(dBgS_Acch* pacch) { + #if DEBUG + if (m_hio.ChkAcchWallOff()) { + return; + } + + if (m_hio.ChkCheckCounter()) { + g_acch_wall_counter++; + } + + if (m_hio.ChkAcchWallTimer()) { + OSStartStopwatch(&s_wall_correct_sw); + } + #endif + + pacch->CalcWallRR(); + pacch->CalcMovePosWork(); for (int i = 0; i < 3; i++) { cBgS_ChkElm* elm = m_chk_element; @@ -566,53 +1236,95 @@ void dBgS::WallCorrectSort(dBgS_Acch* p_acch) { if (elm->ChkUsed() && !elm->m_bgw_base_ptr->ChkNotReady()) { dBgW_Base* pbgw = elm->m_bgw_base_ptr; - if (pbgw->ChkPriority(i) && !p_acch->ChkSameActorPid(elm->m_actor_id)) { - if (!p_acch->ChkMoveBGOnly() || (pbgw->ChkMoveBg() && !pbgw->ChkLock())) { - p_acch->SetNowActorInfo(j, elm->m_bgw_base_ptr, elm->m_actor_id); - pbgw->WallCorrectSort(p_acch); + if (pbgw->ChkPriority(i) && !pacch->ChkSameActorPid(elm->m_actor_id)) { + if (!pacch->ChkMoveBGOnly() || (pbgw->ChkMoveBg() && !pbgw->ChkLock())) { + pacch->SetNowActorInfo(j, elm->m_bgw_base_ptr, elm->m_actor_id); + pbgw->WallCorrectSort(pacch); } } } elm++; } } + + #if DEBUG + if (m_hio.ChkAcchWallTimer()) { + OSStopStopwatch(&s_wall_correct_sw); + OSDumpStopwatch(&s_wall_correct_sw); + } + #endif } -f32 dBgS::RoofChk(dBgS_RoofChk* p_roof) { - p_roof->Init(); +f32 dBgS::RoofChk(dBgS_RoofChk* proof) { + #if DEBUG + if (m_hio.ChkRoofOff()) { + return G_CM3D_F_INF; + } + + if (m_hio.ChkCheckCounter()) { + g_roof_counter++; + } + + if (m_hio.ChkRoofTimer()) { + OSStartStopwatch(&s_roof_sw); + } + #endif + + proof->Init(); cBgS_ChkElm* elm = m_chk_element; for (int i = 0; i < 0x100; i++) { if (elm->ChkUsed() && !elm->m_bgw_base_ptr->ChkNotReady()) { - if (!p_roof->ChkSameActorPid(elm->m_actor_id)) { + if (!proof->ChkSameActorPid(elm->m_actor_id)) { dBgW_Base* pbgw = elm->m_bgw_base_ptr; - if (pbgw->RoofChk(p_roof)) { - p_roof->SetActorInfo(i, elm->m_bgw_base_ptr, elm->m_actor_id); + if (pbgw->RoofChk(proof)) { + proof->SetActorInfo(i, elm->m_bgw_base_ptr, elm->m_actor_id); } } } elm++; } - return p_roof->GetNowY(); + #if DEBUG + if (m_hio.ChkAcchWallTimer()) { + OSStopStopwatch(&s_roof_sw); + OSDumpStopwatch(&s_roof_sw); + } + #endif + + return proof->GetNowY(); } -bool dBgS::SplGrpChk(dBgS_SplGrpChk* p_grp) { +bool dBgS::SplGrpChk(dBgS_SplGrpChk* pspl) { + #if DEBUG + if (m_hio.ChkSplOff()) { + return false; + } + + if (m_hio.ChkCheckCounter()) { + g_spl_counter++; + } + + if (m_hio.ChkSplTimer()) { + OSStartStopwatch(&s_spl_sw); + } + #endif + bool ret = false; - p_grp->Init(); + pspl->Init(); cBgS_ChkElm* elm = m_chk_element; for (int i = 0; i < 0x100; i++) { if (elm->ChkUsed() && !elm->m_bgw_base_ptr->ChkNotReady()) { - if (!p_grp->ChkSameActorPid(elm->m_actor_id)) { + if (!pspl->ChkSameActorPid(elm->m_actor_id)) { dBgW_Base* pbgw = elm->m_bgw_base_ptr; - if (!p_grp->ChkMoveBGOnly() || (pbgw->ChkMoveBg() && !pbgw->ChkLock())) { - if (pbgw->SplGrpChk(p_grp)) { + if (!pspl->ChkMoveBGOnly() || (pbgw->ChkMoveBg() && !pbgw->ChkLock())) { + if (pbgw->SplGrpChk(pspl)) { ret = true; - p_grp->SetActorInfo(i, elm->m_bgw_base_ptr, elm->m_actor_id); - p_grp->OnFind(); + pspl->SetActorInfo(i, elm->m_bgw_base_ptr, elm->m_actor_id); + pspl->OnFind(); } } } @@ -620,25 +1332,46 @@ bool dBgS::SplGrpChk(dBgS_SplGrpChk* p_grp) { elm++; } + #if DEBUG + if (m_hio.ChkAcchWallTimer()) { + OSStopStopwatch(&s_spl_sw); + OSDumpStopwatch(&s_spl_sw); + } + #endif + return ret; } -bool dBgS::SphChk(dBgS_SphChk* p_sph, void* param_1) { - if (p_sph->mCallback == NULL) { +bool dBgS::SphChk(dBgS_SphChk* psphchk, void* param_1) { + if (psphchk->mCallback == NULL) { return false; } + #if DEBUG + if (m_hio.ChkSphChkOff()) { + return false; + } + + if (m_hio.ChkCheckCounter()) { + g_sph_counter++; + } + + if (m_hio.ChkSphChkTimer()) { + OSStartStopwatch(&s_sph_chk_sw); + } + #endif + bool ret = false; - p_sph->ClearPi(); + psphchk->Init(); cBgS_ChkElm* elm = m_chk_element; for (int i = 0; i < 0x100; i++) { if (elm->ChkUsed() && !elm->m_bgw_base_ptr->ChkNotReady()) { - if (!p_sph->ChkSameActorPid(elm->m_actor_id)) { + if (!psphchk->ChkSameActorPid(elm->m_actor_id)) { dBgW_Base* pbgw = elm->m_bgw_base_ptr; - if (pbgw->SphChk(p_sph, param_1)) { - p_sph->SetActorInfo(i, elm->m_bgw_base_ptr, elm->m_actor_id); + if (pbgw->SphChk(psphchk, param_1)) { + psphchk->SetActorInfo(i, elm->m_bgw_base_ptr, elm->m_actor_id); ret = true; } } @@ -646,81 +1379,109 @@ bool dBgS::SphChk(dBgS_SphChk* p_sph, void* param_1) { elm++; } + #if DEBUG + if (m_hio.ChkAcchWallTimer()) { + OSStopStopwatch(&s_sph_chk_sw); + OSDumpStopwatch(&s_sph_chk_sw); + } + #endif + return ret; } -void dBgS::MoveBgCrrPos(cBgS_PolyInfo const& i_poly, bool param_1, cXyz* i_pos, csXyz* i_angle, +void dBgS::MoveBgCrrPos(const cBgS_PolyInfo& i_poly, bool param_1, cXyz* i_pos, csXyz* i_angle, csXyz* i_shapeAngle, bool param_5, bool param_6) { if (!param_1 || !i_poly.ChkBgIndex()) { return; } int bg_index = i_poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - dBgW_Base* bgw_p = m_chk_element[bg_index].m_bgw_base_ptr; + JUT_ASSERT(2414, 0 <= bg_index && bg_index < 256); - if ((!param_5 || bgw_p->chkStickWall()) && (!param_6 || bgw_p->chkStickRoof()) && - bgw_p->ChkMoveFlag() && ChkPolySafe(i_poly)) + dBgW_Base* pbgw; + if (m_chk_element[bg_index].ChkUsed()) { + pbgw = m_chk_element[bg_index].m_bgw_base_ptr; + + if ((!param_5 || pbgw->chkStickWall()) && (!param_6 || pbgw->chkStickRoof()) && + pbgw->ChkMoveFlag() && ChkPolySafe(i_poly)) { - bgw_p->CrrPos(i_poly, m_chk_element[bg_index].m_actor_ptr, param_1, i_pos, i_angle, + pbgw->CrrPos(i_poly, m_chk_element[bg_index].m_actor_ptr, param_1, i_pos, i_angle, i_shapeAngle); } } } -void dBgS::MoveBgTransPos(cBgS_PolyInfo const& i_poly, bool param_1, cXyz* i_pos, csXyz* i_angle, +void dBgS::MoveBgTransPos(const cBgS_PolyInfo& i_poly, bool param_1, cXyz* i_pos, csXyz* i_angle, csXyz* i_shapeAngle) { if (!param_1 || !i_poly.ChkBgIndex()) { return; } int bg_index = i_poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - dBgW_Base* bgw_p = m_chk_element[bg_index].m_bgw_base_ptr; + JUT_ASSERT(2466, 0 <= bg_index && bg_index < 256); - if (bgw_p->ChkMoveFlag() && ChkPolySafe(i_poly)) { - bgw_p->TransPos(i_poly, m_chk_element[bg_index].m_actor_ptr, param_1, i_pos, i_angle, + dBgW_Base* pbgw; + if (m_chk_element[bg_index].ChkUsed()) { + pbgw = m_chk_element[bg_index].m_bgw_base_ptr; + + if (pbgw->ChkMoveFlag() && ChkPolySafe(i_poly)) { + pbgw->TransPos(i_poly, m_chk_element[bg_index].m_actor_ptr, param_1, i_pos, i_angle, i_shapeAngle); } } } -void dBgS::MoveBgMatrixCrrPos(cBgS_PolyInfo const& i_poly, bool param_1, cXyz* i_pos, +void dBgS::MoveBgMatrixCrrPos(const cBgS_PolyInfo& i_poly, bool param_1, cXyz* i_pos, csXyz* i_angle, csXyz* i_shapeAngle) { if (!param_1 || !i_poly.ChkBgIndex()) { return; } int bg_index = i_poly.GetBgIndex(); - if (m_chk_element[bg_index].ChkUsed()) { - dBgW_Base* bgw_p = m_chk_element[bg_index].m_bgw_base_ptr; + JUT_ASSERT(2509, 0 <= bg_index && bg_index < 256); - if (bgw_p->ChkMoveFlag()) { - bgw_p->MatrixCrrPos(i_poly, m_chk_element[bg_index].m_actor_ptr, param_1, i_pos, + dBgW_Base* pbgw; + if (m_chk_element[bg_index].ChkUsed()) { + pbgw = m_chk_element[bg_index].m_bgw_base_ptr; + + if (pbgw->ChkMoveFlag()) { + pbgw->MatrixCrrPos(i_poly, m_chk_element[bg_index].m_actor_ptr, param_1, i_pos, i_angle, i_shapeAngle); } } } -void dBgS_MoveBGProc_Typical(dBgW* i_bgw, void* i_actor_ptr, cBgS_PolyInfo const& i_poly, +void dBgS_MoveBGProc_Typical(dBgW* pbgw, void* i_actor_ptr, const cBgS_PolyInfo& i_poly, bool param_3, cXyz* i_pos, csXyz* i_angle, csXyz* i_shapeAngle) { - Mtx m; - if (i_bgw->GetOldInvMtx(m) != 0) { - cXyz move_old; - MTXMultVec(m, i_pos, &move_old); + UNUSED(i_actor_ptr); + UNUSED(i_poly); + UNUSED(param_3); + UNUSED(i_angle); + UNUSED(i_shapeAngle); - cXyz move_pos; - MTXMultVec(i_bgw->GetBaseMtxP(), &move_old, &move_pos); - i_pos->x = move_pos.x; - i_pos->y = move_pos.y; - i_pos->z = move_pos.z; + Mtx m; + if (pbgw->GetOldInvMtx(m) == 0) { + return; } + + cXyz move_old; + cXyz move_pos; + + PSMTXMultVec(m, i_pos, &move_old); + PSMTXMultVec(pbgw->GetBaseMtxP(), &move_old, &move_pos); + + *i_pos = move_pos; } -static void dBgS_MoveBGProc_RotY(dBgW* i_bgw, void* i_actor_ptr, cBgS_PolyInfo const& i_poly, +static void dBgS_MoveBGProc_RotY(dBgW* pbgw, void* i_actor_ptr, const cBgS_PolyInfo& i_poly, bool param_3, cXyz* i_pos, csXyz* i_angle, csXyz* i_shapeAngle) { + UNUSED(i_actor_ptr); + UNUSED(i_poly); + UNUSED(param_3); + UNUSED(i_pos); + if (i_shapeAngle != NULL) { - s16 y = i_bgw->GetDiffShapeAngleY(); + s16 y = pbgw->GetDiffShapeAngleY(); if (i_shapeAngle != NULL) { i_shapeAngle->y += y; @@ -732,101 +1493,124 @@ static void dBgS_MoveBGProc_RotY(dBgW* i_bgw, void* i_actor_ptr, cBgS_PolyInfo c } } -void dBgS_MoveBGProc_TypicalRotY(dBgW* i_bgw, void* i_actor_ptr, cBgS_PolyInfo const& i_poly, +void dBgS_MoveBGProc_TypicalRotY(dBgW* pbgw, void* i_actor_ptr, const cBgS_PolyInfo& i_poly, bool param_3, cXyz* i_pos, csXyz* i_angle, csXyz* i_shapeAngle) { - dBgS_MoveBGProc_Typical(i_bgw, i_actor_ptr, i_poly, param_3, i_pos, i_angle, i_shapeAngle); - dBgS_MoveBGProc_RotY(i_bgw, i_actor_ptr, i_poly, param_3, i_pos, i_angle, i_shapeAngle); + dBgS_MoveBGProc_Typical(pbgw, i_actor_ptr, i_poly, param_3, i_pos, i_angle, i_shapeAngle); + dBgS_MoveBGProc_RotY(pbgw, i_actor_ptr, i_poly, param_3, i_pos, i_angle, i_shapeAngle); } -void dBgS_MoveBGProc_Trans(dBgW* i_bgw, void* i_actor_ptr, cBgS_PolyInfo const& i_poly, +void dBgS_MoveBGProc_Trans(dBgW* pbgw, void* i_actor_ptr, const cBgS_PolyInfo& i_poly, bool param_3, cXyz* i_pos, csXyz* i_angle, csXyz* i_shapeAngle) { + UNUSED(i_actor_ptr); + UNUSED(i_poly); + UNUSED(param_3); + UNUSED(i_angle); + UNUSED(i_shapeAngle); + cXyz trans; - i_bgw->GetTrans(&trans); + pbgw->GetTrans(&trans); - VECAdd(i_pos, &trans, i_pos); + PSVECAdd(i_pos, &trans, i_pos); } -void dBgS::RideCallBack(cBgS_PolyInfo const& poly, fopAc_ac_c* param_1) { - int bg_index = poly.GetBgIndex(); - dBgW_Base* base = m_chk_element[bg_index].m_bgw_base_ptr; - if (base->ChkUsed()) { - base->CallRideCallBack(m_chk_element[bg_index].m_actor_ptr, param_1); +void dBgS::RideCallBack(const cBgS_PolyInfo& polyinfo, fopAc_ac_c* param_1) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(2682, 0 <= bg_index && bg_index < 256); + + dBgW_Base* pbgw = m_chk_element[bg_index].m_bgw_base_ptr; + if (!pbgw->ChkUsed()) { + OS_REPORT_ERROR("dBgS::RideCallBack() Error\n"); + } else { + pbgw->CallRideCallBack(m_chk_element[bg_index].m_actor_ptr, param_1); } } -void dBgS::ArrowStickCallBack(cBgS_PolyInfo const& poly, fopAc_ac_c* param_1, cXyz& param_2) { - int bg_index = poly.GetBgIndex(); - dBgW_Base* base = m_chk_element[bg_index].m_bgw_base_ptr; - if (base->ChkUsed()) { - base->CallArrowStickCallBack(m_chk_element[bg_index].m_actor_ptr, param_1, param_2); +void dBgS::ArrowStickCallBack(const cBgS_PolyInfo& polyinfo, fopAc_ac_c* param_1, cXyz& param_2) { + int bg_index = polyinfo.GetBgIndex(); + JUT_ASSERT(2704, 0 <= bg_index && bg_index < 256); + + dBgW_Base* pbgw = m_chk_element[bg_index].m_bgw_base_ptr; + if (!pbgw->ChkUsed()) { + OS_REPORT_ERROR("dBgS::ArrowStickCallBack() Used Error\n"); + } else { + pbgw->CallArrowStickCallBack(m_chk_element[bg_index].m_actor_ptr, param_1, param_2); } } -fopAc_ac_c* dBgS::PushPullCallBack(cBgS_PolyInfo const& param_0, fopAc_ac_c* i_pushActor, s16 i_angle, +fopAc_ac_c* dBgS::PushPullCallBack(const cBgS_PolyInfo& param_0, fopAc_ac_c* i_pushActor, s16 i_angle, dBgW_Base::PushPullLabel i_label) { int bg_index = param_0.GetBgIndex(); - dBgW_Base* base = m_chk_element[bg_index].m_bgw_base_ptr; - if (!base->ChkUsed()) { + JUT_ASSERT(2733, 0 <= bg_index && bg_index < 256); + + dBgW_Base* pbgw = m_chk_element[bg_index].m_bgw_base_ptr; + if (!pbgw->ChkUsed()) { + OS_REPORT_ERROR("dBgS::PushPullCallBack() Error\n"); return NULL; } - if (m_chk_element[bg_index].m_actor_ptr == NULL) { + fopAc_ac_c* bg_actor = m_chk_element[bg_index].m_actor_ptr; + if (bg_actor == NULL) { return NULL; } - if (base->GetPushPullCallback() == NULL) { + dBgW::PushPull_CallBack callback = pbgw->GetPushPullCallback(); + if (callback == NULL) { return NULL; } - return base->GetPushPullCallback()(m_chk_element[bg_index].m_actor_ptr, i_pushActor, i_angle, - i_label); + return callback(bg_actor, i_pushActor, i_angle, i_label); } -#if DEBUG +void dBgS::DebugDrawPoly(const dBgW_Base& param_1) { + if (m_hio.ChkShapeDisp()) { + param_1.DebugDraw(); + } +} -void dBgS::DrawPoly(cBgS_PolyInfo const& polyInfo, GXColor const& color) { +void dBgS::DrawPoly(const cBgS_PolyInfo& polyInfo, GXColor const& color) { dBgW_Base* pdBgw = dComIfG_Bgsp().GetBgWBasePointer(polyInfo); if (pdBgw != NULL) { pdBgw->DrawPoly(polyInfo, color); } } -#endif - -bool dBgS_CheckBWallPoly(cBgS_PolyInfo const& poly) { +bool dBgS_CheckBWallPoly(const cBgS_PolyInfo& polyinfo) { cM3dGPla pla; - if (!dComIfG_Bgsp().GetTriPla(poly, &pla)) { + bool rt = dComIfG_Bgsp().GetTriPla(polyinfo, &pla); + if (!rt) { return false; } return cBgW_CheckBWall(pla.mNormal.y); } -bool dBgS_CheckBGroundPoly(cBgS_PolyInfo const& poly) { +bool dBgS_CheckBGroundPoly(const cBgS_PolyInfo& polyinfo) { cM3dGPla pla; - if (!dComIfG_Bgsp().GetTriPla(poly, &pla)) { + bool rt = dComIfG_Bgsp().GetTriPla(polyinfo, &pla); + if (!rt) { return false; } return cBgW_CheckBGround(pla.mNormal.y); } -bool dBgS_CheckBRoofPoly(cBgS_PolyInfo const& poly) { +bool dBgS_CheckBRoofPoly(const cBgS_PolyInfo& polyinfo) { cM3dGPla pla; - if (!dComIfG_Bgsp().GetTriPla(poly, &pla)) { + bool rt = dComIfG_Bgsp().GetTriPla(polyinfo, &pla); + if (!rt) { return false; } return cBgW_CheckBRoof(pla.mNormal.y); } -f32 dBgS_GetNY(cBgS_PolyInfo const& poly) { +f32 dBgS_GetNY(const cBgS_PolyInfo& polyinfo) { cM3dGPla pla; - dComIfG_Bgsp().GetTriPla(poly, &pla); + dComIfG_Bgsp().GetTriPla(polyinfo, &pla); return pla.mNormal.y; } diff --git a/src/d/d_bg_s_acch.cpp b/src/d/d_bg_s_acch.cpp index 0259c3f55d..7ff969fde0 100644 --- a/src/d/d_bg_s_acch.cpp +++ b/src/d/d_bg_s_acch.cpp @@ -11,6 +11,10 @@ #include "d/d_com_inf_game.h" #include "global.h" +#if DEBUG +#include "d/d_debug_viewer.h" +#endif + dBgS_AcchCir::dBgS_AcchCir() { m_flags = 0; m_wall_rr = 0.0f; @@ -22,26 +26,26 @@ dBgS_AcchCir::dBgS_AcchCir() { } void dBgS_AcchCir::ClrWallHit() { - m_flags &= ~WALL_HIT; + m_flags &= ~FLAG_WALL_HIT; ClearPi(); } -void dBgS_AcchCir::SetWallR(f32 i_wall_r) { - m_wall_r = i_wall_r; +void dBgS_AcchCir::SetWallR(f32 wall_r) { + m_wall_r = wall_r; } void dBgS_AcchCir::CalcWallRR() { m_wall_rr = m_wall_r * m_wall_r; } -void dBgS_AcchCir::SetWall(f32 i_wall_h, f32 i_wall_r) { - SetWallH(i_wall_h); - SetWallR(i_wall_r); +void dBgS_AcchCir::SetWall(f32 wall_h, f32 wall_r) { + SetWallH(wall_h); + SetWallR(wall_r); } -void dBgS_AcchCir::SetWallHDirect(f32 i_h_direct) { +void dBgS_AcchCir::SetWallHDirect(f32 h_direct) { m_flags |= WALL_H_DIRECT; - m_wall_h_direct = i_h_direct; + m_wall_h_direct = h_direct; } dBgS_Acch::~dBgS_Acch() {} @@ -89,40 +93,43 @@ void dBgS_Acch::Init() { } } -void dBgS_Acch::Set(cXyz* i_pos, cXyz* i_old_pos, fopAc_ac_c* i_actor, int i_tbl_size, - dBgS_AcchCir* i_acchcir, cXyz* i_speed, csXyz* i_angle, csXyz* i_shape_angle) { - pm_pos = i_pos; - pm_old_pos = i_old_pos; +void dBgS_Acch::Set(cXyz* ppos, cXyz* pold_pos, fopAc_ac_c* pactor, int tbl_size, + dBgS_AcchCir* pacchcir, cXyz* pspeed, csXyz* pangle, csXyz* pshape_angle) { + pm_pos = ppos; + pm_old_pos = pold_pos; JUT_ASSERT(246, pm_pos != NULL); JUT_ASSERT(247, pm_old_pos != NULL); - m_my_ac = i_actor; - fpc_ProcID id = fopAcM_GetID(i_actor); + m_my_ac = pactor; + + fpc_ProcID id = fopAcM_GetID(pactor); SetActorPid(id); - pm_speed = i_speed; - m_tbl_size = i_tbl_size; - pm_acch_cir = i_acchcir; - pm_angle = i_angle; - pm_shape_angle = i_shape_angle; + + pm_speed = pspeed; + m_tbl_size = tbl_size; + pm_acch_cir = pacchcir; + pm_angle = pangle; + pm_shape_angle = pshape_angle; } -void dBgS_Acch::Set(fopAc_ac_c* i_actor, int i_tbl_size, dBgS_AcchCir* i_acchcir) { - m_tbl_size = i_tbl_size; - pm_acch_cir = i_acchcir; - m_my_ac = i_actor; +void dBgS_Acch::Set(fopAc_ac_c* pactor, int tbl_size, dBgS_AcchCir* pacchcir) { + m_tbl_size = tbl_size; + pm_acch_cir = pacchcir; + m_my_ac = pactor; - SetActorPid(fopAcM_GetID(i_actor)); - pm_pos = fopAcM_GetPosition_p(i_actor); - pm_old_pos = fopAcM_GetOldPosition_p(i_actor); - pm_speed = fopAcM_GetSpeed_p(i_actor); - pm_angle = fopAcM_GetAngle_p(i_actor); - pm_shape_angle = fopAcM_GetShapeAngle_p(i_actor); + SetActorPid(fopAcM_GetID(pactor)); + pm_pos = fopAcM_GetPosition_p(pactor); + pm_old_pos = fopAcM_GetOldPosition_p(pactor); + pm_speed = fopAcM_GetSpeed_p(pactor); + pm_angle = fopAcM_GetAngle_p(pactor); + pm_shape_angle = fopAcM_GetShapeAngle_p(pactor); } -void dBgS_Acch::GroundCheckInit(dBgS& i_bgs) { - UNUSED(i_bgs); - if (!(m_flags & 2)) { +void dBgS_Acch::GroundCheckInit(dBgS& bgs) { + UNUSED(bgs); + + if (!(m_flags & FLAG_GRND_NONE)) { m_ground_h = -G_CM3D_F_INF; m_gnd.SetExtChk(*this); field_0xb4 = ChkGroundHit(); @@ -132,8 +139,8 @@ void dBgS_Acch::GroundCheckInit(dBgS& i_bgs) { } } -void dBgS_Acch::GroundCheck(dBgS& i_bgs) { - if (!(m_flags & GRND_NONE)) { +void dBgS_Acch::GroundCheck(dBgS& bgs) { + if (!(m_flags & FLAG_GRND_NONE)) { cXyz grnd_pos; grnd_pos = *pm_pos; grnd_pos.y += field_0x94 + (m_gnd_chk_offset - field_0x90); @@ -143,15 +150,15 @@ void dBgS_Acch::GroundCheck(dBgS& i_bgs) { tmpRoofChk.SetActorPid(m_gnd.GetActorPid()); tmpRoofChk.SetPos(*pm_pos); - f32 roof_chk = i_bgs.RoofChk(&tmpRoofChk); - if (grnd_pos.y > roof_chk) { - grnd_pos.y = roof_chk; + f32 roof_y = bgs.RoofChk(&tmpRoofChk); + if (grnd_pos.y > roof_y) { + grnd_pos.y = roof_y; } } field_0x94 = 0.0f; m_gnd.SetPos(&grnd_pos); - m_ground_h = i_bgs.GroundCross(&m_gnd); + m_ground_h = bgs.GroundCross(&m_gnd); if (m_ground_h != -G_CM3D_F_INF) { field_0xbc = m_ground_h + field_0x90; @@ -162,13 +169,13 @@ void dBgS_Acch::GroundCheck(dBgS& i_bgs) { pm_speed->y = 0.0f; } - i_bgs.GetTriPla(m_gnd, &field_0xa0); + bgs.GetTriPla(m_gnd, &field_0xa0); SetGroundFind(); SetGroundHit(); if (field_0xc0 == 0) { field_0xc0 = 1; - i_bgs.RideCallBack(m_gnd, m_my_ac); + bgs.RideCallBack(m_gnd, m_my_ac); } if (field_0xb4 == 0) { @@ -183,28 +190,28 @@ void dBgS_Acch::GroundCheck(dBgS& i_bgs) { } } -void dBgS_Acch::GroundRoofProc(dBgS& i_bgs) { +void dBgS_Acch::GroundRoofProc(dBgS& bgs) { if (m_ground_h != -G_CM3D_F_INF) { if (field_0xbc < field_0xcc && field_0xcc < pm_pos->y) { pm_pos->y = field_0xcc; } - if (!(m_flags & ROOF_NONE) && m_ground_h >= m_roof_height) { + if (!(m_flags & FLAG_ROOF_NONE) && m_ground_h >= m_roof_height) { m_roof.SetExtChk(*this); ClrRoofHit(); cXyz roof_pos(*pm_pos); m_roof.SetPos(roof_pos); - m_roof_height = i_bgs.RoofChk(&m_roof); + m_roof_height = bgs.RoofChk(&m_roof); } } } -void dBgS_Acch::LineCheck(dBgS& i_bgs) { +void dBgS_Acch::LineCheck(dBgS& bgs) { dBgS_RoofChk roof_chk; roof_chk.SetActorPid(m_gnd.GetActorPid()); roof_chk.SetPos(*GetOldPos()); - f32 temp_f31 = dComIfG_Bgsp().RoofChk(&roof_chk); + f32 roof_y = dComIfG_Bgsp().RoofChk(&roof_chk); f32 var_f30 = G_CM3D_F_INF; bool var_r30 = false; @@ -218,22 +225,22 @@ void dBgS_Acch::LineCheck(dBgS& i_bgs) { old_pos = *GetOldPos(); pos = *GetPos(); - f32 var_f2 = GetWallH(i); - if (temp_f31 < old_pos.y + var_f2) { + f32 wall_h = GetWallH(i); + if (roof_y < old_pos.y + wall_h) { if (var_r29) { continue; } else { - var_f2 = (temp_f31 - old_pos.y) - 1.0f; + wall_h = (roof_y - old_pos.y) - 1.0f; var_r29 = true; } } - if (var_f30 > var_f2) { - var_f30 = var_f2; + if (var_f30 > wall_h) { + var_f30 = wall_h; } - old_pos.y += var_f2; - pos.y += var_f2; + old_pos.y += wall_h; + pos.y += wall_h; if (GetSpeedY() < 0.0f) { if (m_my_ac != NULL && fopAcM_GetName(m_my_ac) == fpcNm_ALINK_e && @@ -246,7 +253,7 @@ void dBgS_Acch::LineCheck(dBgS& i_bgs) { lin_chk.Set2(&old_pos, &pos, GetActorPid()); lin_chk.SetExtChk(*this); - if (i_bgs.LineCross(&lin_chk)) { + if (bgs.LineCross(&lin_chk)) { *GetPos() = lin_chk.GetCross(); OnLineCheckHit(); @@ -254,10 +261,10 @@ void dBgS_Acch::LineCheck(dBgS& i_bgs) { *pm_out_poly_info = lin_chk; cM3dGPla plane; - i_bgs.GetTriPla(lin_chk, &plane); + bgs.GetTriPla(lin_chk, &plane); if (!cBgW_CheckBGround(plane.mNormal.y)) { PSVECAdd(GetPos(), &plane.mNormal, GetPos()); - f32 var_f28 = JMAFastSqrt(plane.mNormal.x * plane.mNormal.x + plane.mNormal.z * plane.mNormal.z); + f32 var_f28 = JMAFastSqrt(SQUARE(plane.mNormal.x) + SQUARE(plane.mNormal.z)); if (!cM3d_IsZero(var_f28)) { pm_acch_cir[i].SetWallHDirect(GetPos()->y); } @@ -265,7 +272,7 @@ void dBgS_Acch::LineCheck(dBgS& i_bgs) { GetPos()->y -= GetWallH(i); } else { GetPos()->y -= 1.0f; - GroundCheck(i_bgs); + GroundCheck(bgs); var_r30 = true; } } @@ -273,7 +280,6 @@ void dBgS_Acch::LineCheck(dBgS& i_bgs) { if (ChkLineDown()) { f32 temp_f1 = GetOldPos()->y - GetPos()->y; - if (var_f30 != G_CM3D_F_INF && !var_r30 && !cM3d_IsZero(temp_f1)) { cBgS_LinChk lin_chk; cXyz old_pos; @@ -287,7 +293,7 @@ void dBgS_Acch::LineCheck(dBgS& i_bgs) { lin_chk.Set2(&old_pos, &pos, GetActorPid()); lin_chk.SetExtChk(*this); - if (i_bgs.LineCross(&lin_chk)) { + if (bgs.LineCross(&lin_chk)) { *GetPos() = lin_chk.GetCross(); OnLineCheckHit(); @@ -295,13 +301,13 @@ void dBgS_Acch::LineCheck(dBgS& i_bgs) { *pm_out_poly_info = lin_chk; GetPos()->y -= 1.0f; - GroundCheck(i_bgs); + GroundCheck(bgs); } } } } -void dBgS_Acch::CrrPos(dBgS& i_bgs) { +void dBgS_Acch::CrrPos(dBgS& bgs) { bool bvar9; if (!(m_flags & 1)) { JUT_ASSERT(792, pm_pos != NULL); @@ -316,7 +322,7 @@ void dBgS_Acch::CrrPos(dBgS& i_bgs) { JUT_ASSERT(839, pm_pos->y < 1.0e32f); JUT_ASSERT(840, -1.0e32f < pm_pos->z && pm_pos->z < 1.0e32f); - i_bgs.MoveBgCrrPos(m_gnd, ChkGroundHit(), pm_pos, pm_angle, pm_shape_angle, false, false); + bgs.MoveBgCrrPos(m_gnd, ChkGroundHit(), pm_pos, pm_angle, pm_shape_angle, false, false); if (!ChkGroundHit()) { bvar9 = false; @@ -324,7 +330,7 @@ void dBgS_Acch::CrrPos(dBgS& i_bgs) { if (ChkWallHit()) { for (int i = 0; i < m_tbl_size; i++) { if (pm_acch_cir[i].ChkWallHit()) { - i_bgs.MoveBgCrrPos(pm_acch_cir[i], true, pm_pos, pm_angle, pm_shape_angle, + bgs.MoveBgCrrPos(pm_acch_cir[i], true, pm_pos, pm_angle, pm_shape_angle, true, false); bvar9 = true; break; @@ -333,89 +339,86 @@ void dBgS_Acch::CrrPos(dBgS& i_bgs) { } if (!bvar9 && ChkRoofHit()) { - i_bgs.MoveBgCrrPos(m_roof, true, pm_pos, pm_angle, pm_shape_angle, false, true); + bgs.MoveBgCrrPos(m_roof, true, pm_pos, pm_angle, pm_shape_angle, false, true); } } - GroundCheckInit(i_bgs); + GroundCheckInit(bgs); Init(); - f32 tmp = GetWallAllLowH_R(); - f32 dvar10 = GetOldPos()->abs2XZ(*GetPos()); - f32 dvar11 = GetOldPos()->y - GetPos()->y; - f32 tmp2 = GetWallAllLowH(); + f32 wall_all_low_h_r = GetWallAllLowH_R(); + f32 old_pos_dist2XZ = GetOldPos()->abs2XZ(*GetPos()); + f32 old_pos_dist_y = GetOldPos()->y - GetPos()->y; + f32 wall_all_low_h = GetWallAllLowH(); field_0xb8 = GetPos()->y; field_0xc0 = 0; - f32 fvar12 = tmp2 + GetOldPos()->y; + f32 fvar12 = wall_all_low_h + GetOldPos()->y; f32 fvar1 = m_gnd_chk_offset + GetPos()->y; bool bvar2 = false; OffLineCheckHit(); - if (!ChkLineCheckNone() && !cM3d_IsZero(tmp) && - (dvar10 > (tmp * tmp) || fvar12 > fvar1 || dvar11 > m_gnd_chk_offset || ChkLineCheck())) + if (!ChkLineCheckNone() && !cM3d_IsZero(wall_all_low_h_r) && + (old_pos_dist2XZ > SQUARE(wall_all_low_h_r) || fvar12 > fvar1 || old_pos_dist_y > m_gnd_chk_offset || ChkLineCheck())) { bvar2 = true; - LineCheck(i_bgs); + LineCheck(bgs); } - if (!(m_flags & WALL_NONE)) { + if (!(m_flags & FLAG_WALL_NONE)) { if (ChkWallSort()) { - i_bgs.WallCorrectSort(this); + bgs.WallCorrectSort(this); } else { - i_bgs.WallCorrect(this); + bgs.WallCorrect(this); } } if (ChkWallHit() && bvar2) { - LineCheck(i_bgs); + LineCheck(bgs); } + field_0xcc = G_CM3D_F_INF; - if (!(m_flags & ROOF_NONE)) { + if (!(m_flags & FLAG_ROOF_NONE)) { m_roof.SetExtChk(*this); ClrRoofHit(); - cXyz roof_pos; - roof_pos.x = pm_pos->x; - roof_pos.y = pm_pos->y; - roof_pos.z = pm_pos->z; + cXyz roof_pos(*pm_pos); m_roof.SetPos(roof_pos); - m_roof_height = i_bgs.RoofChk(&m_roof); + m_roof_height = bgs.RoofChk(&m_roof); if (m_roof_height != G_CM3D_F_INF) { - f32 y = pm_pos->y; - - if (y + m_roof_crr_height > m_roof_height) { + if (pm_pos->y + m_roof_crr_height > m_roof_height) { field_0xcc = m_roof_height - m_roof_crr_height; SetRoofHit(); } } } - if (!(m_flags & GRND_NONE)) { + if (!(m_flags & FLAG_GRND_NONE)) { ClrGroundFind(); - GroundCheck(i_bgs); - GroundRoofProc(i_bgs); + GroundCheck(bgs); + GroundRoofProc(bgs); } else { if (field_0xcc < pm_pos->y) { pm_pos->y = field_0xcc; } } - if (!(m_flags & 0x400)) { + if (!(m_flags & FLAG_WATER_NONE)) { ClrWaterHit(); ClrWaterIn(); m_wtr.SetHeight(-G_CM3D_F_INF); + bool spD = false; + f32 var_f29; f32 top; - - f32 temp_f1_5 = m_ground_h; - if (temp_f1_5 == -G_CM3D_F_INF) { + if (m_ground_h == -G_CM3D_F_INF) { var_f29 = pm_pos->y - 50.0f; + spD = true; } else { - var_f29 = temp_f1_5; + var_f29 = m_ground_h; } if (m_wtr_mode == 1) { @@ -425,7 +428,7 @@ void dBgS_Acch::CrrPos(dBgS& i_bgs) { roof_chk.SetUnderwaterRoof(); roof_chk.SetPos(*pm_pos); - top = i_bgs.RoofChk(&roof_chk); + top = bgs.RoofChk(&roof_chk); if (top == G_CM3D_F_INF) { top = pm_pos->y + 1000000.0f; } @@ -438,7 +441,7 @@ void dBgS_Acch::CrrPos(dBgS& i_bgs) { m_wtr.Set(ground, top); m_wtr.SetPassChkInfo(*this); - if (i_bgs.WaterChk(&m_wtr)) { + if (bgs.WaterChk(&m_wtr)) { SetWaterHit(); if (m_wtr.GetHeight() > pm_pos->y) { SetWaterIn(); @@ -460,15 +463,15 @@ void dBgS_Acch::CrrPos(dBgS& i_bgs) { } f32 dBgS_Acch::GetWallAllR() { - f32 ret = 0.0f; + f32 rt = 0.0f; for (int i = 0; i < m_tbl_size; i++) { - f32 wall_r = pm_acch_cir[i].GetWallR(); - if (ret < wall_r) { - ret = wall_r; + if (rt < pm_acch_cir[i].GetWallR()) { + rt = pm_acch_cir[i].GetWallR(); } } - return ret; + + return rt; } void dBgS_Acch::SetWallCir() { @@ -481,31 +484,26 @@ void dBgS_Acch::CalcWallBmdCyl() { if (m_tbl_size <= 0) { m_wall_cyl.Set(*pm_pos, 0.0f, 0.0f); } else { - f32 dvar8 = GetWallAllR(); - f32 dvar9 = pm_acch_cir->GetWallH(); - f32 dvar10 = pm_acch_cir->GetWallH(); + f32 wall_all_r = GetWallAllR(); + f32 wall_h_max = pm_acch_cir->GetWallH(); + f32 wall_h_min = pm_acch_cir->GetWallH(); if (m_tbl_size >= 1) { for (int i = 0; i < m_tbl_size; i++) { - f32 tmp = pm_acch_cir[i].GetWallH(); - if (dvar9 > tmp) { - dvar9 = pm_acch_cir[i].GetWallH(); + if (wall_h_max > pm_acch_cir[i].GetWallH()) { + wall_h_max = pm_acch_cir[i].GetWallH(); } - f32 tmp2 = pm_acch_cir[i].GetWallH(); - if (dvar10 < tmp2) { - dvar10 = pm_acch_cir[i].GetWallH(); + if (wall_h_min < pm_acch_cir[i].GetWallH()) { + wall_h_min = pm_acch_cir[i].GetWallH(); } } } - cXyz xyz; - xyz.x = pm_pos->x; - xyz.y = pm_pos->y; - xyz.z = pm_pos->z; - xyz.y += dvar9; + cXyz xyz(*pm_pos); + xyz.y += wall_h_max; - m_wall_cyl.Set(xyz, dvar8, dvar10 - dvar9); + m_wall_cyl.Set(xyz, wall_all_r, wall_h_min - wall_h_max); } } @@ -519,15 +517,14 @@ f32 dBgS_Acch::GetWallAllLowH() { return 0.0f; } - f32 tmp = pm_acch_cir->GetWallH(); + f32 wall_low_h = pm_acch_cir->GetWallH(); for (int i = 1; i < m_tbl_size; i++) { - f32 tmp2 = pm_acch_cir[i].GetWallH(); - if (tmp > tmp2) { - tmp = pm_acch_cir[i].GetWallH(); + if (wall_low_h > pm_acch_cir[i].GetWallH()) { + wall_low_h = pm_acch_cir[i].GetWallH(); } } - return tmp; + return wall_low_h; } f32 dBgS_Acch::GetWallAllLowH_R() { @@ -536,11 +533,10 @@ f32 dBgS_Acch::GetWallAllLowH_R() { } int index = 0; - f32 tmp = pm_acch_cir->GetWallH(); + f32 wall_h = pm_acch_cir->GetWallH(); for (int i = 1; i < m_tbl_size; i++) { - f32 tmp2 = pm_acch_cir[i].GetWallH(); - if (tmp > tmp2) { - tmp = pm_acch_cir[i].GetWallH(); + if (wall_h > pm_acch_cir[i].GetWallH()) { + wall_h = pm_acch_cir[i].GetWallH(); index = i; } } @@ -556,6 +552,49 @@ f32 dBgS_Acch::GetSpeedY() { return 0.0f; } +#if DEBUG +static GXColor blue = {0, 0, 0xFF, 0x80}; +static GXColor red = {0xFF, 0, 0, 0x80}; + +void dBgS_Acch::DrawWall(dBgS& bgs) { + if (bgs.m_hio.ChkAcchDrawWall()) { + if (!(m_flags & FLAG_WALL_NONE)) { + for (int i = 0; i < m_tbl_size; i++) { + cM3dGCir cir; + cir = *pm_acch_cir[i].GetCirP(); + + cXyz pos; + pos.x = cir.GetCx(); + pos.y = cir.GetHeight(); + pos.z = cir.GetCy(); + + f32 radius = cir.GetR(); + dDbVw_drawCylinderXlu(pos, radius, 3.0f, blue, TRUE); + + if (pm_acch_cir[i].ChkWallHit()) { + bgs.DrawPoly(pm_acch_cir[i], blue); + } + } + } else { + SetWallCir(); + + for (int i = 0; i < m_tbl_size; i++) { + cM3dGCir cir; + cir = *pm_acch_cir[i].GetCirP(); + + cXyz pos; + pos.x = cir.GetCx(); + pos.y = cir.GetHeight(); + pos.z = cir.GetCy(); + + f32 radius = cir.GetR(); + dDbVw_drawCylinderXlu(pos, radius, 3.0f, red, TRUE); + } + } + } +} +#endif + f32 dBgS_Acch::GetWallAddY(Vec& param_0) { if (!ChkGroundFind() || field_0xa0.mNormal.y < 0.5f) { return 0.0f; @@ -572,15 +611,17 @@ f32 dBgS_Acch::GetWallAddY(Vec& param_0) { return 0.0f; } -void dBgS_Acch::SetNowActorInfo(int bg_index, void* param_1, fpc_ProcID param_2) { +void dBgS_Acch::SetNowActorInfo(int bg_index, void* param_1, fpc_ProcID proc_id) { m_bg_index = bg_index; field_0x7c = param_1; - field_0x80 = param_2; + field_0x80 = proc_id; } void dBgS_Acch::SetWallPolyIndex(int index, int poly_index) { + JUT_ASSERT(1534, index <= m_tbl_size); + pm_acch_cir[index].SetActorInfo(m_bg_index, field_0x7c, field_0x80); - pm_acch_cir[index].SetPolyIndex(poly_index); + pm_acch_cir[index].SetWallPolyIndex(poly_index); } void dBgS_Acch::CalcMovePosWork() { @@ -596,35 +637,35 @@ void dBgS_Acch::CalcWallRR() { } void dBgS_Acch::SetMoveBGOnly() { - m_flags |= MOVE_BG_ONLY; + m_flags |= FLAG_MOVE_BG_ONLY; m_wtr.OnMoveBGOnly(); } void dBgS_Acch::ClrMoveBGOnly() { - m_flags &= ~MOVE_BG_ONLY; + m_flags &= ~FLAG_MOVE_BG_ONLY; m_wtr.OffMoveBGOnly(); } void dBgS_Acch::SetGndThinCellingOff() { - m_flags |= GND_THIN_CELLING_OFF; + m_flags |= FLAG_GND_THIN_CELLING_OFF; } void dBgS_Acch::ClrGndThinCellingOff() { - m_flags &= ~GND_THIN_CELLING_OFF; + m_flags &= ~FLAG_GND_THIN_CELLING_OFF; } bool dBgS_Acch::ChkGndThinCellingOff() { - return m_flags & GND_THIN_CELLING_OFF; + return m_flags & FLAG_GND_THIN_CELLING_OFF; } void dBgS_Acch::OnWallSort() { - m_flags |= WALL_SORT; + m_flags |= FLAG_WALL_SORT; } bool dBgS_Acch::ChkWallSort() { - return m_flags & WALL_SORT; + return m_flags & FLAG_WALL_SORT; } bool dBgS_Acch::ChkLineDown() { - return m_flags & LINE_DOWN; + return m_flags & FLAG_LINE_DOWN; } diff --git a/src/d/d_bg_s_capt_poly.cpp b/src/d/d_bg_s_capt_poly.cpp index 287db6ef59..1178947624 100644 --- a/src/d/d_bg_s_capt_poly.cpp +++ b/src/d/d_bg_s_capt_poly.cpp @@ -7,11 +7,11 @@ dBgS_CaptPoly::dBgS_CaptPoly() { SetPolyPassChk(GetPolyPassChkInfo()); SetGrpPassChk(GetGrpPassChkInfo()); - field_0x48 = 0; + m_callback = NULL; } void dBgS_CaptPoly::Set(cXyz& min, cXyz& max) { - aab.Set(&min, &max); + m_bnd.Set(&min, &max); JUT_ASSERT(36, !(fpclassify(min.x) == FP_QNAN)); JUT_ASSERT(37, !(fpclassify(min.y) == FP_QNAN)); diff --git a/src/d/d_bg_s_movebg_actor.cpp b/src/d/d_bg_s_movebg_actor.cpp index a3030349f6..176beadb73 100644 --- a/src/d/d_bg_s_movebg_actor.cpp +++ b/src/d/d_bg_s_movebg_actor.cpp @@ -14,8 +14,9 @@ dBgS_MoveBgActor::dBgS_MoveBgActor() { mpBgW = NULL; } -static int CheckCreateHeap(fopAc_ac_c* p_actor) { - return static_cast(p_actor)->MoveBGCreateHeap(); +static int CheckCreateHeap(fopAc_ac_c* actor) { + dBgS_MoveBgActor* i_this = (dBgS_MoveBgActor*)actor; + return i_this->MoveBGCreateHeap(); } int dBgS_MoveBgActor::CreateHeap() { @@ -68,8 +69,7 @@ int dBgS_MoveBgActor::MoveBGCreateHeap() { mpBgW = JKR_NEW dBgW(); if (mpBgW != NULL) { - cBgD_t* res = (cBgD_t*)dComIfG_getObjectRes(m_name, m_dzb_id); - if (!mpBgW->Set(res, cBgW::MOVE_BG_e, &mBgMtx)) { + if (!mpBgW->Set((cBgD_t*)dComIfG_getObjectRes(m_name, m_dzb_id), cBgW::MOVE_BG_e, &mBgMtx)) { if (m_set_func != NULL) { mpBgW->SetCrrFunc(m_set_func); } @@ -87,6 +87,8 @@ int dBgS_MoveBgActor::MoveBGCreateHeap() { int dBgS_MoveBgActor::MoveBGCreate(char const* i_arcName, int i_dzb_id, MoveBGActor_SetFunc i_setFunc, u32 i_heapSize, Mtx* i_bgMtx) { + bool var_r28 = true; + if (i_bgMtx == NULL) { mDoMtx_stack_c::transS(current.pos.x, current.pos.y, current.pos.z); mDoMtx_stack_c::YrotM(shape_angle.y); @@ -104,6 +106,15 @@ int dBgS_MoveBgActor::MoveBGCreate(char const* i_arcName, int i_dzb_id, return cPhs_ERROR_e; } + #if DEBUG + if (mpBgW != NULL && mpBgW->ChkUsed()) { + BOOL isDebugPad = mDoCPd_c::isConnect(PAD_3); + if (isDebugPad) { + JUT_WARN(185, "%s", "dBgS_MoveBgActor::MoveBGCreate() Don't Regist CreateHeap\n"); + } + } + #endif + if (mpBgW != NULL && dComIfG_Bgsp().Regist(mpBgW, this)) { return cPhs_ERROR_e; } @@ -116,7 +127,10 @@ int dBgS_MoveBgActor::MoveBGDelete() { int ret = Delete(); if (mpBgW != NULL && mpBgW->ChkUsed()) { - dComIfG_Bgsp().Release(mpBgW); + bool rt = dComIfG_Bgsp().Release(mpBgW); + if (rt != 0) { + OS_REPORT("Release Error\n"); + } } return ret; } diff --git a/src/d/d_bg_s_poly_pass_chk.cpp b/src/d/d_bg_s_poly_pass_chk.cpp index 1433540464..18b60eb36b 100644 --- a/src/d/d_bg_s_poly_pass_chk.cpp +++ b/src/d/d_bg_s_poly_pass_chk.cpp @@ -84,7 +84,10 @@ bool dBgS_PolyPassChk::ChkNoHorse() { return true; } - return !ChkHorse(); + if (!ChkHorse()) + return true; + + return false; } void dBgS_PolyPassChk::SetStatue() { diff --git a/src/d/d_bg_s_spl_grp_chk.cpp b/src/d/d_bg_s_spl_grp_chk.cpp index 2915686a47..b09ce3c7b5 100644 --- a/src/d/d_bg_s_spl_grp_chk.cpp +++ b/src/d/d_bg_s_spl_grp_chk.cpp @@ -10,6 +10,17 @@ void dBgS_SplGrpChk::Set(cXyz& ground, f32 roof) { m_ground = ground; m_roof = roof; + + JUT_ASSERT(23, !isnan(m_ground.x)); + JUT_ASSERT(24, !isnan(m_ground.y)); + JUT_ASSERT(25, !isnan(m_ground.z)); + + JUT_ASSERT(29, -INF < m_ground.x && m_ground.x < INF); + JUT_ASSERT(30, -INF < m_ground.y && m_ground.y < INF); + JUT_ASSERT(31, -INF < m_ground.z && m_ground.z < INF); + + JUT_ASSERT(33, !isnan(m_roof)); + JUT_ASSERT(34, -INF < m_roof && m_roof < INF); } dBgS_SplGrpChk::dBgS_SplGrpChk() { diff --git a/src/d/d_bg_w.cpp b/src/d/d_bg_w.cpp index 5e9f9183ef..ecbc7fa6d3 100644 --- a/src/d/d_bg_w.cpp +++ b/src/d/d_bg_w.cpp @@ -9,11 +9,41 @@ #include "SSystem/SComponent/c_bg_s_shdw_draw.h" #include "SSystem/SComponent/c_m2d.h" #include "SSystem/SComponent/c_math.h" -#include "d/d_bg_s_cap_poly.h" +#include "d/d_bg_s_capt_poly.h" #include "d/d_bg_s_sph_chk.h" #include "d/d_com_inf_game.h" #include "d/actor/d_a_horse.h" +#include "d/d_debug_viewer.h" + +#if DEBUG +static void ASSERT_SOLDHEAP() { + JKRHeap* currentHeap = JKRGetCurrentHeap(); + u32 type = currentHeap->getHeapType(); + if (type != 'SLID') { + /** + * ******* THIS IS A BUG ******* + * ******* THIS IS A BUG ******* + * ******* THIS IS A BUG ******* + * cBgW will crash if the current heap is not a solid heap. + * Make sure to set the current heap to a solide heap. + * The memory allocated here will never be freed. + * This will cause memory leaks and certainly other bugs. + * Please fix immediately. The actor's name should be listed in the blue message below. + */ + OS_REPORT_ERROR( + "*******Aバグです*******\n" + "*******Aバグです*******\n" + "*******Aバグです*******\n" + "cBgWはカレントヒープがソリッドヒープ以外だと破綻します。\n" + "必ず、カレントヒープをソリッドヒープにしてください。\n" + "ここでnewされた領域は二度と開放されることはありません。\n" + "慢性的にメモリーリークを繰り返し、いずれ確実にAバグを引き起こすことでしょう。\n" + "必ず修正してください。この下の水色のメッセージにアクターの名前が書いてあるはずです。\n"); + } +} +#endif + cBgW_RwgElm::cBgW_RwgElm() {} cBgW_RwgElm::~cBgW_RwgElm() {} @@ -27,7 +57,10 @@ cBgW::cBgW() { mFlags = GLOBAL_e; mNeedsFullTransform = 1; mMoveCounter = 0; - mTransVel.set(0.0f, 0.0f, 0.0f); + + mTransVel.x = 0.0f; + mTransVel.y = 0.0f; + mTransVel.z = 0.0f; pm_tri = NULL; pm_rwg = NULL; @@ -60,24 +93,50 @@ void cBgW::GlobalVtx() { if (pm_base != NULL) { if (!mNeedsFullTransform) { for (int i = 0; i < pm_bgd->m_v_num; i++) { - Vec* vtx = &pm_vtx_tbl[i]; - VECAdd(vtx, &mTransVel, vtx); + PSVECAdd(&pm_vtx_tbl[i], &mTransVel, &pm_vtx_tbl[i]); } } else { + // TODO: supposed to be *pm_base, type must be wrong + JUT_ASSERT(201, + !isnan((*pm_base)[0][0]) && + !isnan((*pm_base)[0][1]) && + !isnan((*pm_base)[0][2]) && + !isnan((*pm_base)[0][3]) && + !isnan((*pm_base)[1][0]) && + !isnan((*pm_base)[1][1]) && + !isnan((*pm_base)[1][2]) && + !isnan((*pm_base)[1][3]) && + !isnan((*pm_base)[2][0]) && + !isnan((*pm_base)[2][1]) && + !isnan((*pm_base)[2][2]) && + !isnan((*pm_base)[2][3])); + for (int i = 0; i < pm_bgd->m_v_num; i++) { - MTXMultVec(pm_base, &pm_bgd->m_v_tbl[i], &pm_vtx_tbl[i]); + PSMTXMultVec(*pm_base, &pm_bgd->m_v_tbl[i], &pm_vtx_tbl[i]); } } } } +#if DEBUG +// stripped func, needed for string data +void cBgW::DebugLocalPos() { + OSReport("cBgW::DebugLocalPos() {%ff, %ff, %ff}, {%ff, %ff, %ff}\n"); +} +#endif + bool cBgW::SetVtx() { + #if DEBUG + ASSERT_SOLDHEAP(); + #endif + if (mFlags & NO_VTX_TBL_e) { pm_vtx_tbl = NULL; } else if (mFlags & MOVE_BG_e) { pm_vtx_tbl = (cBgD_Vtx_t*)JKR_NEW_ARRAY(Vec, pm_bgd->m_v_num); if (pm_vtx_tbl == NULL) { + OS_REPORT_ERROR("c_bg_w.cpp[%d] メモリ確保できません。\n", 272); return true; } @@ -103,7 +162,7 @@ void cBgW::CalcPlane() { if (pm_vtx_tbl != NULL) { if (!mNeedsFullTransform) { for (int i = 0; i < pm_bgd->m_t_num; i++) { - pm_tri[i].m_plane.mD -= VECDotProduct(&pm_tri[i].m_plane.mNormal, &mTransVel); + pm_tri[i].m_plane.mD -= PSVECDotProduct(&pm_tri[i].m_plane.mNormal, &mTransVel); } } else { for (int i = 0; i < pm_bgd->m_t_num; i++) { @@ -119,6 +178,15 @@ void cBgW::CalcPlane() { pm_tri[i].m_plane.SetupFrom3Vtx(&pm_vtx_tbl[tri[i].m_vtx_idx0], &pm_vtx_tbl[tri[i].m_vtx_idx1], &pm_vtx_tbl[tri[i].m_vtx_idx2]); + + #if DEBUG + cXyz vec; + vec = pm_tri[i].m_plane.mNormal; + + JUT_ASSERT(327, -1.1f <= vec.x && vec.x <= 1.1f); + JUT_ASSERT(328, -1.1f <= vec.y && vec.y <= 1.1f); + JUT_ASSERT(329, -1.1f <= vec.z && vec.z <= 1.1f); + #endif #endif } } @@ -126,9 +194,14 @@ void cBgW::CalcPlane() { } bool cBgW::SetTri() { + #if DEBUG + ASSERT_SOLDHEAP(); + #endif + pm_tri = JKR_NEW_ARRAY(cBgW_TriElm, pm_bgd->m_t_num); if (pm_tri == NULL) { + OS_REPORT_ERROR("c_bg_w.cpp[%d] メモリ確保できません\n", 353); return true; } @@ -140,17 +213,17 @@ cBgW_TriElm::~cBgW_TriElm() {} cBgW_TriElm::cBgW_TriElm() {} -void cBgW::BlckConnect(u16* i_start_idx, int* i_prev_idx, int i_idx) { - if (*i_start_idx == 0xFFFF) { - *i_start_idx = i_idx; +void cBgW::BlckConnect(u16* pstart_index, int* pprev_index, int index) { + if (*pstart_index == 0xFFFF) { + *pstart_index = index; } - if (*i_prev_idx != 0xFFFF) { - pm_rwg[*i_prev_idx].m_next = i_idx; + if (*pprev_index != 0xFFFF) { + pm_rwg[*pprev_index].m_next = index; } - *i_prev_idx = i_idx; - pm_rwg[*i_prev_idx].m_next = 0xFFFF; + *pprev_index = index; + pm_rwg[*pprev_index].m_next = 0xFFFF; } void cBgW::ClassifyPlane() { @@ -183,7 +256,7 @@ void cBgW::ClassifyPlane() { if (cBgW_CheckBGround(norm_y)) { BlckConnect(&pm_blk[i].m_gnd_idx, &blk_gnd_idx, j); } else if (cBgW_CheckBRoof(norm_y)) { - if (!ChkRoofRegist()) { + if (ChkRoofRegist()) { BlckConnect(&pm_blk[i].m_roof_idx, &blk_roof_idx, j); } } else { @@ -194,117 +267,110 @@ void cBgW::ClassifyPlane() { } } -void cBgW::MakeBlckTransMinMax(cXyz* i_min, cXyz* i_max) { - VECAdd(i_min, &mTransVel, i_min); - VECAdd(i_max, &mTransVel, i_max); +void cBgW::MakeBlckTransMinMax(cXyz* pmin, cXyz* pmax) { + PSVECAdd(pmin, &mTransVel, pmin); + PSVECAdd(pmax, &mTransVel, pmax); } -void cBgW::MakeBlckMinMax(int vtx_index, cXyz* i_min, cXyz* i_max) { +void cBgW::MakeBlckMinMax(int vtx_index, cXyz* pmin, cXyz* pmax) { cBgD_Vtx_t* vtx = &pm_vtx_tbl[vtx_index]; - if (i_min->x > vtx->x) { - i_min->x = vtx->x; + if (pmin->x > vtx->x) { + pmin->x = vtx->x; } - if (i_max->x < vtx->x) { - i_max->x = vtx->x; + if (pmax->x < vtx->x) { + pmax->x = vtx->x; } - if (i_min->y > vtx->y) { - i_min->y = vtx->y; + if (pmin->y > vtx->y) { + pmin->y = vtx->y; } - if (i_max->y < vtx->y) { - i_max->y = vtx->y; + if (pmax->y < vtx->y) { + pmax->y = vtx->y; } - if (i_min->z > vtx->z) { - i_min->z = vtx->z; + if (pmin->z > vtx->z) { + pmin->z = vtx->z; } - if (i_max->z < vtx->z) { - i_max->z = vtx->z; + if (pmax->z < vtx->z) { + pmax->z = vtx->z; } } -void cBgW::MakeBlckBnd(int i_blk_idx, cXyz* i_min, cXyz* i_max) { - int start = pm_bgd->m_b_tbl[i_blk_idx].field_0x0; +void cBgW::MakeBlckBnd(int blck_index, cXyz* pmin, cXyz* pmax) { + int start = pm_bgd->m_b_tbl[blck_index].field_0x0; int max; - if (i_blk_idx != pm_bgd->m_b_num - 1) { - max = pm_bgd->m_b_tbl[i_blk_idx + 1].field_0x0 - 1; + if (blck_index != pm_bgd->m_b_num - 1) { + max = pm_bgd->m_b_tbl[blck_index + 1].field_0x0 - 1; } else { max = pm_bgd->m_t_num - 1; } if (mNeedsFullTransform == 0) { - MakeBlckTransMinMax(i_min, i_max); + MakeBlckTransMinMax(pmin, pmax); } else { - i_min->z = G_CM3D_F_INF; - i_min->y = G_CM3D_F_INF; - i_min->x = G_CM3D_F_INF; - i_max->z = -G_CM3D_F_INF; - i_max->y = -G_CM3D_F_INF; - i_max->x = -G_CM3D_F_INF; + pmin->x = pmin->y = pmin->z = G_CM3D_F_INF; + pmax->x = pmax->y = pmax->z =-G_CM3D_F_INF; for (int i = start; i <= max; i++) { - MakeBlckMinMax(pm_bgd->m_t_tbl[i].m_vtx_idx0, i_min, i_max); - MakeBlckMinMax(pm_bgd->m_t_tbl[i].m_vtx_idx1, i_min, i_max); - MakeBlckMinMax(pm_bgd->m_t_tbl[i].m_vtx_idx2, i_min, i_max); + MakeBlckMinMax(pm_bgd->m_t_tbl[i].m_vtx_idx0, pmin, pmax); + MakeBlckMinMax(pm_bgd->m_t_tbl[i].m_vtx_idx1, pmin, pmax); + MakeBlckMinMax(pm_bgd->m_t_tbl[i].m_vtx_idx2, pmin, pmax); } - i_min->x -= 1.0f; - i_min->y -= 1.0f; - i_min->z -= 1.0f; - i_max->x += 1.0f; - i_max->y += 1.0f; - i_max->z += 1.0f; + pmin->x -= 1.0f; + pmin->y -= 1.0f; + pmin->z -= 1.0f; + pmax->x += 1.0f; + pmax->y += 1.0f; + pmax->z += 1.0f; } } -void cBgW::MakeNodeTreeRp(int i_tree_idx) { - cBgD_Tree_t* tree_data = &pm_bgd->m_tree_tbl[i_tree_idx]; +void cBgW::MakeNodeTreeRp(int node_index) { + cBgD_Tree_t* pnode = &pm_bgd->m_tree_tbl[node_index]; - if (tree_data->m_flag & 1) { - int child_idx = tree_data->m_id[0]; + if (pnode->m_flag & 1) { + int child_idx = pnode->m_id[0]; if (child_idx != 0xFFFF) { - cXyz* max = (cXyz*)pm_node_tree[i_tree_idx].GetMaxP(); - cXyz* min = (cXyz*)pm_node_tree[i_tree_idx].GetMinP(); - - MakeBlckBnd(child_idx, min, max); + MakeBlckBnd(child_idx, pm_node_tree[node_index].GetMinP(), pm_node_tree[node_index].GetMaxP()); } } else { - pm_node_tree[i_tree_idx].ClearForMinMax(); + pm_node_tree[node_index].ClearForMinMax(); for (int i = 0; i < 8; i++) { - int child_idx = tree_data->m_id[i]; + int child_idx = pnode->m_id[i]; if (child_idx != 0xFFFF) { MakeNodeTreeRp(child_idx); - pm_node_tree[i_tree_idx].SetMinMax(*pm_node_tree[child_idx].GetMinP()); - pm_node_tree[i_tree_idx].SetMinMax(*pm_node_tree[child_idx].GetMaxP()); + pm_node_tree[node_index].SetMinMax(*pm_node_tree[child_idx].GetMinP()); + pm_node_tree[node_index].SetMinMax(*pm_node_tree[child_idx].GetMaxP()); } } } } -void cBgW::MakeNodeTreeGrpRp(int i_grp_idx) { - if (pm_bgd->m_g_tbl[i_grp_idx].m_tree_idx != 0xFFFF) { - MakeNodeTreeRp(pm_bgd->m_g_tbl[i_grp_idx].m_tree_idx); - pm_grp[i_grp_idx].m_aab.SetMin( - *pm_node_tree[pm_bgd->m_g_tbl[i_grp_idx].m_tree_idx].GetMinP()); - pm_grp[i_grp_idx].m_aab.SetMax( - *pm_node_tree[pm_bgd->m_g_tbl[i_grp_idx].m_tree_idx].GetMaxP()); +void cBgW::MakeNodeTreeGrpRp(int g) { + if (pm_bgd->m_g_tbl[g].m_tree_idx != 0xFFFF) { + MakeNodeTreeRp(pm_bgd->m_g_tbl[g].m_tree_idx); + pm_grp[g].m_aab.SetMin( + *pm_node_tree[pm_bgd->m_g_tbl[g].m_tree_idx].GetMinP()); + pm_grp[g].m_aab.SetMax( + *pm_node_tree[pm_bgd->m_g_tbl[g].m_tree_idx].GetMaxP()); } - int child_idx = pm_bgd->m_g_tbl[i_grp_idx].m_first_child; + int child_idx = pm_bgd->m_g_tbl[g].m_first_child; while (true) { if (child_idx == 0xFFFF) break; MakeNodeTreeGrpRp(child_idx); - pm_grp[i_grp_idx].m_aab.SetMin(*pm_grp[child_idx].m_aab.GetMinP()); - pm_grp[i_grp_idx].m_aab.SetMax(*pm_grp[child_idx].m_aab.GetMaxP()); + pm_grp[g].m_aab.SetMin(*pm_grp[child_idx].m_aab.GetMinP()); + pm_grp[g].m_aab.SetMax(*pm_grp[child_idx].m_aab.GetMaxP()); child_idx = pm_bgd->m_g_tbl[child_idx].m_next_sibling; } } @@ -343,6 +409,10 @@ bool cBgW::ChkMemoryError() { } bool cBgW::Set(cBgD_t* pbgd, u32 flags, Mtx* pbase_mtx) { + #if DEBUG + ASSERT_SOLDHEAP(); + #endif + mFlags = GLOBAL_e; pm_vtx_tbl = NULL; pm_tri = NULL; @@ -350,7 +420,7 @@ bool cBgW::Set(cBgD_t* pbgd, u32 flags, Mtx* pbase_mtx) { pm_blk = NULL; pm_node_tree = NULL; pm_grp = NULL; - mMoveCounter = cM_rndF(128.0f); + mMoveCounter = (int)cM_rndF(128.0f) & 0xFF; if (pbgd == NULL) { return true; @@ -362,38 +432,43 @@ bool cBgW::Set(cBgD_t* pbgd, u32 flags, Mtx* pbase_mtx) { MTXIdentity(m_inv_mtx); MTXIdentity(m_mtx); } else { - pm_base = *pbase_mtx; - MTXCopy(pm_base, m_inv_mtx); - MTXCopy(pm_base, m_mtx); + pm_base = pbase_mtx; + PSMTXCopy(*pm_base, m_inv_mtx); + PSMTXCopy(*pm_base, m_mtx); } pm_bgd = pbgd; if (SetVtx() || SetTri()) { FreeArea(); + OS_REPORT_ERROR("cBgW::Set() メモリ足りません。\n"); return true; } pm_rwg = JKR_NEW_ARRAY(cBgW_RwgElm, pm_bgd->m_t_num); if (pm_rwg == NULL) { + OS_REPORT_ERROR("c_bg_w.cpp[%d] メモリ確保できません。\n", 892); FreeArea(); return true; } pm_blk = JKR_NEW_ARRAY(cBgW_BlkElm, pm_bgd->m_b_num); if (pm_blk == NULL) { + OS_REPORT_ERROR("c_bg_w.cpp[%d] メモリ確保できません。\n", 914); FreeArea(); return true; } pm_node_tree = JKR_NEW_ARRAY(cBgW_NodeTree, pm_bgd->m_tree_num); if (pm_node_tree == NULL) { + OS_REPORT_ERROR("c_bg_w.cpp[%d] メモリ確保できません\n", 936); FreeArea(); return true; } pm_grp = JKR_NEW_ARRAY(cBgW_GrpElm, pm_bgd->m_g_num); if (pm_grp == NULL) { + OS_REPORT_ERROR("c_bg_w.cpp[%d] メモリ確保できません\n", 958); FreeArea(); return true; } @@ -408,62 +483,73 @@ cBgW_GrpElm::~cBgW_GrpElm() {} cBgW_GrpElm::cBgW_GrpElm() {} -bool cBgW::RwgLineCheck(u16 i_poly_index, cBgS_LinChk* i_linchk) { +bool cBgW::RwgLineCheck(u16 poly_index, cBgS_LinChk* plinchk) { bool chk = false; cM3dGTri tri; while (true) { - cBgD_Tri_t* tri_t = &pm_bgd->m_t_tbl[i_poly_index]; + cBgD_Tri_t* tri_t = &pm_bgd->m_t_tbl[poly_index]; tri.setBg(&pm_vtx_tbl[tri_t->m_vtx_idx0], &pm_vtx_tbl[tri_t->m_vtx_idx1], - &pm_vtx_tbl[tri_t->m_vtx_idx2], &pm_tri[i_poly_index].m_plane); + &pm_vtx_tbl[tri_t->m_vtx_idx2], &pm_tri[poly_index].m_plane); - cXyz cross_pos; - if (tri.cross(i_linchk->GetLinP(), &cross_pos, i_linchk->ChkFrontFlag(), - i_linchk->ChkBackFlag())) + cXyz cross; + if (tri.cross(plinchk->GetLinP(), &cross, plinchk->ChkFrontFlag(), + plinchk->ChkBackFlag())) { - if (!ChkPolyThrough(i_poly_index, i_linchk->GetPolyPassChk())) { - i_linchk->SetCross(cross_pos); - i_linchk->SetPolyIndex(i_poly_index); + if (!ChkPolyThrough(poly_index, plinchk->GetPolyPassChk())) { + JUT_ASSERT(1080, !isnan(cross.x)); + JUT_ASSERT(1081, !isnan(cross.y)); + JUT_ASSERT(1082, !isnan(cross.z)); + JUT_ASSERT(1088, -INF < cross.x && cross.x < INF && -INF < cross.y && cross.y < INF && -INF < cross.z && cross.z < INF); + + plinchk->SetCross(cross); + plinchk->SetPolyIndex(poly_index); chk = true; } } - if (pm_rwg[i_poly_index].m_next == 0xFFFF) { + cBgW_RwgElm* element = &pm_rwg[poly_index]; + if (element->m_next == 0xFFFF) { break; } - i_poly_index = pm_rwg[i_poly_index].m_next; + + poly_index = element->m_next; } return chk; } -bool cBgW::LineCheckRp(cBgS_LinChk* i_linchk, int i_idx) { - cBgW_NodeTree* node = &pm_node_tree[i_idx]; +bool cBgW::LineCheckRp(cBgS_LinChk* plinchk, int node_index) { + cBgW_NodeTree* node = &pm_node_tree[node_index]; if (!cM3d_Cross_MinMaxBoxLine(node->GetMinP(), node->GetMaxP(), - &i_linchk->GetLinP()->GetStartP(), - &i_linchk->GetLinP()->GetEndP())) + plinchk->GetLinP()->GetStartP(), + plinchk->GetLinP()->GetEndP())) { return false; } - cBgD_Tree_t* tree = &pm_bgd->m_tree_tbl[i_idx]; + cBgD_Tree_t* pnode = &pm_bgd->m_tree_tbl[node_index]; bool chk = false; - if (tree->m_flag & 1) { - if (i_linchk->GetPreWallChk() && pm_blk[tree->m_id[0]].m_wall_idx != 0xFFFF && - RwgLineCheck(pm_blk[tree->m_id[0]].m_wall_idx, i_linchk)) + if (pnode->m_flag & 1) { + JUT_ASSERT(1140, pnode->m_id[0] != 0xffff); + + JUT_ASSERT(1142, pnode->m_id[0] >= 0 && pnode->m_id[0] < pm_bgd->m_b_num); + + if (plinchk->GetPreWallChk() && pm_blk[pnode->m_id[0]].m_wall_idx != 0xFFFF && + RwgLineCheck(pm_blk[pnode->m_id[0]].m_wall_idx, plinchk)) { chk = true; } - if (i_linchk->GetPreGroundChk() && pm_blk[tree->m_id[0]].m_gnd_idx != 0xFFFF && - RwgLineCheck(pm_blk[tree->m_id[0]].m_gnd_idx, i_linchk)) + if (plinchk->GetPreGroundChk() && pm_blk[pnode->m_id[0]].m_gnd_idx != 0xFFFF && + RwgLineCheck(pm_blk[pnode->m_id[0]].m_gnd_idx, plinchk)) { chk = true; } - if (i_linchk->GetPreRoofChk() && pm_blk[tree->m_id[0]].m_roof_idx != 0xFFFF && - RwgLineCheck(pm_blk[tree->m_id[0]].m_roof_idx, i_linchk)) + if (plinchk->GetPreRoofChk() && pm_blk[pnode->m_id[0]].m_roof_idx != 0xFFFF && + RwgLineCheck(pm_blk[pnode->m_id[0]].m_roof_idx, plinchk)) { chk = true; } @@ -472,7 +558,7 @@ bool cBgW::LineCheckRp(cBgS_LinChk* i_linchk, int i_idx) { } for (int i = 0; i < 8; i++) { - if (tree->m_id[i] != 0xFFFF && LineCheckRp(i_linchk, tree->m_id[i])) { + if (pnode->m_id[i] != 0xFFFF && LineCheckRp(plinchk, pnode->m_id[i])) { chk = true; } } @@ -480,30 +566,31 @@ bool cBgW::LineCheckRp(cBgS_LinChk* i_linchk, int i_idx) { return chk; } -bool cBgW::LineCheckGrpRp(cBgS_LinChk* i_linchk, int i_grp_idx, int depth) { - cM3dGLin* pline = i_linchk->GetLinP(); - if (!pm_grp[i_grp_idx].m_aab.Cross(pline)) { +bool cBgW::LineCheckGrpRp(cBgS_LinChk* plinchk, int g, int depth) { + if (!pm_grp[g].m_aab.Cross(plinchk->GetLinP())) { return false; } - if (ChkGrpThrough(i_grp_idx, i_linchk->GetGrpPassChk(), depth)) { + if (ChkGrpThrough(g, plinchk->GetGrpPassChk(), depth)) { return false; } bool chk = false; - if (pm_bgd->m_g_tbl[i_grp_idx].m_tree_idx != 0xFFFF && - LineCheckRp(i_linchk, pm_bgd->m_g_tbl[i_grp_idx].m_tree_idx)) + if (pm_bgd->m_g_tbl[g].m_tree_idx != 0xFFFF && + LineCheckRp(plinchk, pm_bgd->m_g_tbl[g].m_tree_idx)) { chk = true; } - int child_idx = pm_bgd->m_g_tbl[i_grp_idx].m_first_child; + int child_idx = pm_bgd->m_g_tbl[g].m_first_child; + depth++; + while (true) { if (child_idx == 0xFFFF) break; - if (LineCheckGrpRp(i_linchk, child_idx, depth + 1)) { + if (LineCheckGrpRp(plinchk, child_idx, depth)) { chk = true; } child_idx = pm_bgd->m_g_tbl[child_idx].m_next_sibling; @@ -512,19 +599,23 @@ bool cBgW::LineCheckGrpRp(cBgS_LinChk* i_linchk, int i_grp_idx, int depth) { return chk; } -bool cBgW::LineCheck(cBgS_LinChk* i_linchk) { - return LineCheckGrpRp(i_linchk, m_rootGrpIdx, 1); +bool cBgW::LineCheck(cBgS_LinChk* plinchk) { + return LineCheckGrpRp(plinchk, m_rootGrpIdx, 1); } -bool cBgW::RwgGroundCheckCommon(f32 i_yPos, u16 i_poly_idx, cBgS_GndChk* i_gndchk) { - if (i_yPos < i_gndchk->GetPointP().y && i_yPos > i_gndchk->GetNowY()) { - cBgD_Tri_t* tri = &pm_bgd->m_t_tbl[i_poly_idx]; +bool cBgW::RwgGroundCheckCommon(f32 cy, u16 poly_index, cBgS_GndChk* pgndchk) { + if (cy < pgndchk->GetPointP().y && cy > pgndchk->GetNowY()) { + cBgD_Tri_t* tri = &pm_bgd->m_t_tbl[poly_index]; if (cM3d_CrossY_Tri_Front(pm_vtx_tbl[tri->m_vtx_idx0], pm_vtx_tbl[tri->m_vtx_idx1], - pm_vtx_tbl[tri->m_vtx_idx2], (const Vec*)&i_gndchk->GetPointP())) + pm_vtx_tbl[tri->m_vtx_idx2], (const Vec*)&pgndchk->GetPointP())) { - if (!ChkPolyThrough(i_poly_idx, i_gndchk->GetPolyPassChk())) { - i_gndchk->SetNowY(i_yPos); - i_gndchk->SetPolyIndex(i_poly_idx); + if (!ChkPolyThrough(poly_index, pgndchk->GetPolyPassChk())) { + pgndchk->SetNowY(cy); + pgndchk->SetPolyIndex(poly_index); + + JUT_ASSERT(1278, !isnan(cy)); + + JUT_ASSERT(1280, -INF < cy && cy < INF); return true; } } @@ -533,55 +624,61 @@ bool cBgW::RwgGroundCheckCommon(f32 i_yPos, u16 i_poly_idx, cBgS_GndChk* i_gndch return false; } -bool cBgW::RwgGroundCheckGnd(u16 i_poly_idx, cBgS_GndChk* i_gndchk) { +bool cBgW::RwgGroundCheckGnd(u16 poly_index, cBgS_GndChk* pgndchk) { bool chk = false; while (true) { - cBgW_RwgElm* rwg = &pm_rwg[i_poly_idx]; - f32 tri_y = pm_tri[i_poly_idx].m_plane.getCrossY_NonIsZero(&i_gndchk->GetPointP()); - if (RwgGroundCheckCommon(tri_y, (u32)i_poly_idx, i_gndchk)) { + cBgW_RwgElm* rwg = &pm_rwg[poly_index]; + f32 tri_y = pm_tri[poly_index].m_plane.getCrossY_NonIsZero(pgndchk->GetPointP()); + if (RwgGroundCheckCommon(tri_y, (u32)poly_index, pgndchk)) { chk = true; } if (rwg->m_next == 0xFFFF) break; - i_poly_idx = rwg->m_next; + poly_index = rwg->m_next; } return chk; } -bool cBgW::RwgGroundCheckWall(u16 i_poly_idx, cBgS_GndChk* i_gndchk) { +bool cBgW::RwgGroundCheckWall(u16 poly_index, cBgS_GndChk* pgndchk) { bool chk = false; while (true) { - cBgW_TriElm* tri = &pm_tri[i_poly_idx]; - cBgW_RwgElm* rwg = &pm_rwg[i_poly_idx]; + cBgW_TriElm* tri = &pm_tri[poly_index]; + cBgW_RwgElm* rwg = &pm_rwg[poly_index]; if (tri->m_plane.mNormal.y >= 0.014f) { - f32 tri_y = tri->m_plane.getCrossY_NonIsZero(&i_gndchk->GetPointP()); - if (RwgGroundCheckCommon(tri_y, (u32)i_poly_idx, i_gndchk)) { + f32 tri_y = tri->m_plane.getCrossY_NonIsZero(pgndchk->GetPointP()); + if (RwgGroundCheckCommon(tri_y, (u32)poly_index, pgndchk)) { chk = true; } } if (rwg->m_next == 0xFFFF) break; - i_poly_idx = rwg->m_next; + poly_index = rwg->m_next; } return chk; } -bool cBgW::GroundCrossRp(cBgS_GndChk* i_gndchk, int i_idx) { +bool cBgW::GroundCrossRp(cBgS_GndChk* pgndchk, int node_index) { + JUT_ASSERT(1376, 0 <= node_index && node_index < pm_bgd->m_tree_num); + bool chk = false; - cBgD_Tree_t* tree = &pm_bgd->m_tree_tbl[i_idx]; - if ((tree->m_flag & 1)) { - if (pm_blk[tree->m_id[0]].m_gnd_idx != 0xFFFF && - RwgGroundCheckGnd(pm_blk[tree->m_id[0]].m_gnd_idx, i_gndchk)) + cBgD_Tree_t* pnode = &pm_bgd->m_tree_tbl[node_index]; + if ((pnode->m_flag & 1)) { + JUT_ASSERT(1386, pnode->m_id[0] != 0xffff); + + JUT_ASSERT(1387, pnode->m_id[0] >= 0 && pnode->m_id[0] < pm_bgd->m_b_num); + + if (pm_blk[pnode->m_id[0]].m_gnd_idx != 0xFFFF && + RwgGroundCheckGnd(pm_blk[pnode->m_id[0]].m_gnd_idx, pgndchk)) { chk = true; } - if (i_gndchk->GetWallPrecheck() && pm_blk[tree->m_id[0]].m_wall_idx != 0xFFFF && - RwgGroundCheckWall(pm_blk[tree->m_id[0]].m_wall_idx, i_gndchk)) + if (pgndchk->GetWallPrecheck() && pm_blk[pnode->m_id[0]].m_wall_idx != 0xFFFF && + RwgGroundCheckWall(pm_blk[pnode->m_id[0]].m_wall_idx, pgndchk)) { chk = true; } @@ -589,12 +686,12 @@ bool cBgW::GroundCrossRp(cBgS_GndChk* i_gndchk, int i_idx) { } for (int i = 0; i < 8; i++) { - if (tree->m_id[i] != 0xFFFF) { - cM3dGAab* aab = &pm_node_tree[tree->m_id[i]]; - if (aab->CrossY(&i_gndchk->GetPointP())) { - if (aab->UnderPlaneYUnder(i_gndchk->GetPointP().y)) { - if (!aab->TopPlaneYUnder(i_gndchk->GetNowY()) && - GroundCrossRp(i_gndchk, tree->m_id[i])) + if (pnode->m_id[i] != 0xFFFF) { + cM3dGAab* aab = &pm_node_tree[pnode->m_id[i]]; + if (aab->CrossY(&pgndchk->GetPointP())) { + if (aab->UnderPlaneYUnder(pgndchk->GetPointP().y)) { + if (!aab->TopPlaneYUnder(pgndchk->GetNowY()) && + GroundCrossRp(pgndchk, pnode->m_id[i])) { chk = true; } @@ -606,33 +703,36 @@ bool cBgW::GroundCrossRp(cBgS_GndChk* i_gndchk, int i_idx) { return chk; } -bool cBgW::GroundCrossGrpRp(cBgS_GndChk* i_gndchk, int i_grp_idx, int i_depth) { - cBgW_GrpElm* grp = &pm_grp[i_grp_idx]; - if (!grp->m_aab.CrossY(&i_gndchk->GetPointP()) || - !grp->m_aab.UnderPlaneYUnder(i_gndchk->GetPointP().y) || - grp->m_aab.TopPlaneYUnder(i_gndchk->GetNowY())) +bool cBgW::GroundCrossGrpRp(cBgS_GndChk* pgndchk, int g, int depth) { + JUT_ASSERT(1441, 0 <= g && g < pm_bgd->m_g_num); + + cBgW_GrpElm* grp = &pm_grp[g]; + if (!grp->m_aab.CrossY(&pgndchk->GetPointP()) || + !grp->m_aab.UnderPlaneYUnder(pgndchk->GetPointP().y) || + grp->m_aab.TopPlaneYUnder(pgndchk->GetNowY())) { return false; } - if (ChkGrpThrough(i_grp_idx, i_gndchk->GetGrpPassChk(), i_depth)) { + if (ChkGrpThrough(g, pgndchk->GetGrpPassChk(), depth)) { return false; } bool chk = false; - if (pm_bgd->m_g_tbl[i_grp_idx].m_tree_idx != 0xFFFF && - GroundCrossRp(i_gndchk, pm_bgd->m_g_tbl[i_grp_idx].m_tree_idx)) + if (pm_bgd->m_g_tbl[g].m_tree_idx != 0xFFFF && + GroundCrossRp(pgndchk, pm_bgd->m_g_tbl[g].m_tree_idx)) { chk = true; } - int child_idx = pm_bgd->m_g_tbl[i_grp_idx].m_first_child; + int child_idx = pm_bgd->m_g_tbl[g].m_first_child; + depth++; while (true) { if (child_idx == 0xFFFF) break; - if (GroundCrossGrpRp(i_gndchk, child_idx, i_depth + 1)) { + if (GroundCrossGrpRp(pgndchk, child_idx, depth)) { chk = true; } @@ -642,38 +742,38 @@ bool cBgW::GroundCrossGrpRp(cBgS_GndChk* i_gndchk, int i_grp_idx, int i_depth) { return chk; } -bool cBgW::GroundCross(cBgS_GndChk* i_gndchk) { - return GroundCrossGrpRp(i_gndchk, m_rootGrpIdx, 1); +bool cBgW::GroundCross(cBgS_GndChk* pgndchk) { + return GroundCrossGrpRp(pgndchk, m_rootGrpIdx, 1); } void cBgW::CopyOldMtx() { if (pm_base != NULL) { - MTXCopy(m_mtx, m_inv_mtx); - MTXCopy(pm_base, m_mtx); + PSMTXCopy(m_mtx, m_inv_mtx); + PSMTXCopy(*pm_base, m_mtx); } } void cBgW::Move() { if (!ChkLock() && (mFlags & MOVE_BG_e)) { if (!ChkNoCalcVtx()) { - if (mMoveCounter >= 0xFF || m_mtx[0][0] != pm_base[0][0] || - m_mtx[0][1] != pm_base[0][1] || m_mtx[0][2] != pm_base[0][2] || - m_mtx[1][0] != pm_base[1][0] || m_mtx[1][1] != pm_base[1][1] || - m_mtx[1][2] != pm_base[1][2] || m_mtx[2][0] != pm_base[2][0] || - m_mtx[2][1] != pm_base[2][1] || m_mtx[2][2] != pm_base[2][2]) + if (mMoveCounter >= 0xFF || m_mtx[0][0] != (*pm_base)[0][0] || + m_mtx[0][1] != (*pm_base)[0][1] || m_mtx[0][2] != (*pm_base)[0][2] || + m_mtx[1][0] != (*pm_base)[1][0] || m_mtx[1][1] != (*pm_base)[1][1] || + m_mtx[1][2] != (*pm_base)[1][2] || m_mtx[2][0] != (*pm_base)[2][0] || + m_mtx[2][1] != (*pm_base)[2][1] || m_mtx[2][2] != (*pm_base)[2][2]) { mNeedsFullTransform = 1; - } else if (m_mtx[0][3] == pm_base[0][3] && m_mtx[1][3] == pm_base[1][3] && - m_mtx[2][3] == pm_base[2][3]) + } else if (m_mtx[0][3] == (*pm_base)[0][3] && m_mtx[1][3] == (*pm_base)[1][3] && + m_mtx[2][3] == (*pm_base)[2][3]) { - MTXCopy(pm_base, m_inv_mtx); + PSMTXCopy(*pm_base, m_inv_mtx); if (!ChkFlush()) { return; } } else { - mTransVel.x = pm_base[0][3] - m_mtx[0][3]; - mTransVel.y = pm_base[1][3] - m_mtx[1][3]; - mTransVel.z = pm_base[2][3] - m_mtx[2][3]; + mTransVel.x = (*pm_base)[0][3] - m_mtx[0][3]; + mTransVel.y = (*pm_base)[1][3] - m_mtx[1][3]; + mTransVel.z = (*pm_base)[2][3] - m_mtx[2][3]; mNeedsFullTransform = 0; } @@ -692,63 +792,80 @@ void cBgW::Move() { } } -void cBgW::RwgShdwDraw(int i_idx, cBgS_ShdwDraw* i_shdw) { +static void dummyString() { + OSReport("Label:%s\n"); + OSReport("cBgW:%x\n"); + OSReport("vtx num:%d\n"); + OSReport("(%f,%f,%f)\n"); +} + +void cBgW::RwgShdwDraw(int index, cBgS_ShdwDraw* pshdw) { + cBgW_RwgElm* rwg; + while (true) { - cBgW_RwgElm* rwg = &pm_rwg[i_idx]; - if (!ChkShdwDrawThrough(i_idx, i_shdw->GetPolyPassChk())) { - (i_shdw->mCallbackFun)(i_shdw, pm_vtx_tbl, pm_bgd->m_t_tbl[i_idx].m_vtx_idx0, - pm_bgd->m_t_tbl[i_idx].m_vtx_idx1, - pm_bgd->m_t_tbl[i_idx].m_vtx_idx2, &pm_tri[i_idx].m_plane); + rwg = &pm_rwg[index]; + if (!ChkShdwDrawThrough(index, pshdw->GetPolyPassChk())) { + #if DEBUG + pshdw->field_0x34++; + #endif + + (pshdw->mCallbackFun)(pshdw, pm_vtx_tbl, pm_bgd->m_t_tbl[index].m_vtx_idx0, + pm_bgd->m_t_tbl[index].m_vtx_idx1, + pm_bgd->m_t_tbl[index].m_vtx_idx2, &pm_tri[index].m_plane); } if (rwg->m_next == 0xFFFF) break; - i_idx = rwg->m_next; + + index = rwg->m_next; + JUT_ASSERT(1681, 0 <= index && index < pm_bgd->m_t_num); } } -void cBgW::ShdwDrawRp(cBgS_ShdwDraw* i_shdw, int i_idx) { - if (pm_node_tree[i_idx].Cross(i_shdw->GetBndP())) { - cBgD_Tree_t* tree = &pm_bgd->m_tree_tbl[i_idx]; +void cBgW::ShdwDrawRp(cBgS_ShdwDraw* pshdw, int node_index) { + if (pm_node_tree[node_index].Cross(pshdw->GetBndP())) { + cBgD_Tree_t* tree = &pm_bgd->m_tree_tbl[node_index]; if ((tree->m_flag & 1)) { if (pm_blk[tree->m_id[0]].m_wall_idx != 0xFFFF) { - RwgShdwDraw(pm_blk[tree->m_id[0]].m_wall_idx, i_shdw); + RwgShdwDraw(pm_blk[tree->m_id[0]].m_wall_idx, pshdw); } if (pm_blk[tree->m_id[0]].m_roof_idx != 0xFFFF) { - RwgShdwDraw(pm_blk[tree->m_id[0]].m_roof_idx, i_shdw); + RwgShdwDraw(pm_blk[tree->m_id[0]].m_roof_idx, pshdw); } if (pm_blk[tree->m_id[0]].m_gnd_idx != 0xFFFF) { - RwgShdwDraw(pm_blk[tree->m_id[0]].m_gnd_idx, i_shdw); + RwgShdwDraw(pm_blk[tree->m_id[0]].m_gnd_idx, pshdw); } } else { for (int i = 0; i < 8; i++) { if (tree->m_id[i] != 0xFFFF) { - ShdwDrawRp(i_shdw, tree->m_id[i]); + ShdwDrawRp(pshdw, tree->m_id[i]); } } } } } -void cBgW::ShdwDrawGrpRp(cBgS_ShdwDraw* i_shdw, int i_idx) { - if (pm_grp[i_idx].m_aab.Cross(i_shdw->GetBndP())) { - if (pm_bgd->m_g_tbl[i_idx].m_tree_idx != 0xFFFF) { - ShdwDrawRp(i_shdw, pm_bgd->m_g_tbl[i_idx].m_tree_idx); +void cBgW::ShdwDrawGrpRp(cBgS_ShdwDraw* pshdw, int node_index) { + int child_idx; + + if (pm_grp[node_index].m_aab.Cross(pshdw->GetBndP())) { + if (pm_bgd->m_g_tbl[node_index].m_tree_idx != 0xFFFF) { + ShdwDrawRp(pshdw, pm_bgd->m_g_tbl[node_index].m_tree_idx); } - int child_idx = pm_bgd->m_g_tbl[i_idx].m_first_child; + child_idx = pm_bgd->m_g_tbl[node_index].m_first_child; while (true) { if (child_idx == 0xFFFF) { break; } - ShdwDrawGrpRp(i_shdw, child_idx); + ShdwDrawGrpRp(pshdw, child_idx); child_idx = pm_bgd->m_g_tbl[child_idx].m_next_sibling; } } } -void cBgW::ShdwDraw(cBgS_ShdwDraw* i_shdw) { - ShdwDrawGrpRp(i_shdw, m_rootGrpIdx); +void cBgW::ShdwDraw(cBgS_ShdwDraw* pshdw) { + ShdwDrawGrpRp(pshdw, m_rootGrpIdx); } bool cBgW::ChkPolyThrough(int param_0, cBgS_PolyPassChk* param_1) { @@ -763,16 +880,18 @@ bool cBgW::ChkGrpThrough(int param_0, cBgS_GrpPassChk* param_1, int param_2) { return false; } -int cBgW::GetGrpRoomIndex(cBgS_PolyInfo const& poly) const { - int grp_index = GetTriGrp(poly.GetPolyIndex()); +int cBgW::GetGrpRoomIndex(const cBgS_PolyInfo& polyinfo) const { + int poly_index = polyinfo.GetPolyIndex(); + JUT_ASSERT(1848, 0 <= poly_index && poly_index < pm_bgd->m_t_num); - u16 parent_idx = pm_bgd->m_g_tbl[grp_index].m_parent; + int grp_index = GetTriGrp(poly_index); + JUT_ASSERT(1850, 0 <= grp_index && grp_index < pm_bgd->m_g_num); - if (parent_idx == 0xFFFF || pm_bgd->m_g_tbl[parent_idx].m_parent == 0xFFFF) { + if (pm_bgd->m_g_tbl[grp_index].m_parent == 0xFFFF || pm_bgd->m_g_tbl[pm_bgd->m_g_tbl[grp_index].m_parent].m_parent == 0xFFFF) { return 0xFF; } - int room_index = pm_bgd->m_g_tbl[pm_bgd->m_g_tbl[parent_idx].m_parent].m_room_id; + int room_index = pm_bgd->m_g_tbl[pm_bgd->m_g_tbl[pm_bgd->m_g_tbl[grp_index].m_parent].m_parent].m_room_id; if (room_index >= 0xFF) { room_index = 0xFF; } @@ -784,79 +903,91 @@ cM3dGAab* cBgW::GetBnd() const { return &pm_grp[m_rootGrpIdx].m_aab; } -void cBgW::GetTrans(cXyz* o_trans) const { - MtxP base = pm_base; - o_trans->x = base[0][3] - m_inv_mtx[0][3]; - o_trans->y = base[1][3] - m_inv_mtx[1][3]; - o_trans->z = base[2][3] - m_inv_mtx[2][3]; +void cBgW::GetTrans(cXyz* ptrans) const { + ptrans->x = (*pm_base)[0][3] - m_inv_mtx[0][3]; + ptrans->y = (*pm_base)[1][3] - m_inv_mtx[1][3]; + ptrans->z = (*pm_base)[2][3] - m_inv_mtx[2][3]; } -bool cBgW::GetTriPnt(cBgS_PolyInfo const& poly, cXyz* o_pntA, cXyz* o_pntB, cXyz* o_pntC) const { - int poly_index = poly.GetPolyIndex(); +bool cBgW::GetTriPnt(const cBgS_PolyInfo& polyinfo, cXyz* ppnt0, cXyz* ppnt1, cXyz* ppnt2) const { + JUT_ASSERT(1923, pm_bgd != NULL); + + int poly_index = polyinfo.GetPolyIndex(); cBgD_Tri_t* tri = &pm_bgd->m_t_tbl[poly_index]; - o_pntA->set(pm_vtx_tbl[tri->m_vtx_idx0]); - o_pntB->set(pm_vtx_tbl[tri->m_vtx_idx1]); - o_pntC->set(pm_vtx_tbl[tri->m_vtx_idx2]); + ppnt0->set(pm_vtx_tbl[tri->m_vtx_idx0]); + ppnt1->set(pm_vtx_tbl[tri->m_vtx_idx1]); + ppnt2->set(pm_vtx_tbl[tri->m_vtx_idx2]); return true; } -void cBgW::GetTopUnder(f32* o_top, f32* o_under) const { - *o_under = pm_grp[m_rootGrpIdx].m_aab.GetMinP()->y; - *o_top = pm_grp[m_rootGrpIdx].m_aab.GetMaxP()->y; +void cBgW::GetTopUnder(f32* ptop, f32* punder) const { + *punder = pm_grp[m_rootGrpIdx].m_aab.GetMinP()->y; + *ptop = pm_grp[m_rootGrpIdx].m_aab.GetMaxP()->y; } -cM3dGPla cBgW::GetTriPla(cBgS_PolyInfo const& poly) const { - int poly_index = poly.GetPolyIndex(); +cM3dGPla cBgW::GetTriPla(const cBgS_PolyInfo& polyinfo) const { + int poly_index = polyinfo.GetPolyIndex(); JUT_ASSERT(1956, 0 <= poly_index && poly_index < pm_bgd->m_t_num); return pm_tri[poly_index].m_plane; } -u32 cBgW::GetGrpInf(cBgS_PolyInfo const& poly) const { - int grp = GetTriGrp(poly.GetPolyIndex()); - return pm_bgd->m_g_tbl[grp].m_info; +u32 cBgW::GetGrpInf(const cBgS_PolyInfo& polyinfo) const { + int poly_index = polyinfo.GetPolyIndex(); + JUT_ASSERT(1969, 0 <= poly_index && poly_index < pm_bgd->m_t_num); + + int grp_id = GetTriGrp(poly_index); + JUT_ASSERT(1971, 0 <= grp_id && grp_id < pm_bgd->m_g_num); + + return pm_bgd->m_g_tbl[grp_id].m_info; } int cBgW::GetPolyInfId(int poly_index) const { + JUT_ASSERT(1983, 0 <= poly_index && poly_index < pm_bgd->m_t_num); + return pm_bgd->m_t_tbl[poly_index].m_id; } u32 cBgW::GetPolyInf0(int poly_index, u32 mask, u32 shift) const { int id = GetPolyInfId(poly_index); + JUT_ASSERT(2024, 0 <= id && id < pm_bgd->m_ti_num); + return (pm_bgd->m_ti_tbl[id].m_info0 & mask) >> shift; } u32 cBgW::GetMaskPolyInf0_NoShift(int poly_index, u32 mask) const { int id = GetPolyInfId(poly_index); + JUT_ASSERT(2039, 0 <= id && id < pm_bgd->m_ti_num); + return (pm_bgd->m_ti_tbl[id].m_info0 & mask); } -int dBgW::GetExitId(cBgS_PolyInfo const& poly) { - return GetPolyInf0(poly.GetPolyIndex(), 0x3F, 0); +int dBgW::GetExitId(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf0(polyinfo.GetPolyIndex(), 0x3F, 0); } -int dBgW::GetPolyColor(cBgS_PolyInfo const& poly) { - return GetPolyInf0(poly.GetPolyIndex(), 0x3FC0, 6); +int dBgW::GetPolyColor(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf0(polyinfo.GetPolyIndex(), 0x3FC0, 6); } -BOOL dBgW::GetHorseNoEntry(cBgS_PolyInfo const& poly) { - return GetPolyInf0(poly.GetPolyIndex(), 0x200000, 21); +BOOL dBgW::GetHorseNoEntry(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf0(polyinfo.GetPolyIndex(), 0x200000, 21); } -int dBgW::GetSpecialCode(cBgS_PolyInfo const& poly) { - return GetSpecialCode(poly.GetPolyIndex()); +int dBgW::GetSpecialCode(const cBgS_PolyInfo& polyinfo) { + return GetSpecialCode(polyinfo.GetPolyIndex()); } int dBgW::GetSpecialCode(int poly_index) { return GetPolyInf0(poly_index, 0xF000000, 24); } -int dBgW::GetMagnetCode(cBgS_PolyInfo const& poly) { - return GetPolyInf0(poly.GetPolyIndex(), 0x30000000, 28); +int dBgW::GetMagnetCode(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf0(polyinfo.GetPolyIndex(), 0x30000000, 28); } -int dBgW::GetMonkeyBarsCode(cBgS_PolyInfo const& poly) { - return GetPolyInf0(poly.GetPolyIndex(), 0x80000000, 31); +int dBgW::GetMonkeyBarsCode(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf0(polyinfo.GetPolyIndex(), 0x80000000, 31); } u32 dBgW::GetPolyObjThrough(int poly_index) { @@ -901,31 +1032,35 @@ u32 dBgW::GetUnderwaterRoofCode(int poly_index) { u32 cBgW::GetPolyInf1(int poly_index, u32 mask, u32 shift) const { int id = GetPolyInfId(poly_index); + JUT_ASSERT(2259, 0 <= id && id < pm_bgd->m_ti_num); + return (pm_bgd->m_ti_tbl[id].m_info1 & mask) >> shift; } -int dBgW::GetLinkNo(cBgS_PolyInfo const& poly) { - return GetPolyInf1(poly.GetPolyIndex(), 0xFF, 0); +int dBgW::GetLinkNo(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf1(polyinfo.GetPolyIndex(), 0xFF, 0); } -int dBgW::GetWallCode(cBgS_PolyInfo const& poly) { - return GetPolyInf1(poly.GetPolyIndex(), 0xF00, 8); +int dBgW::GetWallCode(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf1(polyinfo.GetPolyIndex(), 0xF00, 8); } -int dBgW::GetPolyAtt0(cBgS_PolyInfo const& poly) { - return GetPolyInf1(poly.GetPolyIndex(), 0xF000, 12); +int dBgW::GetPolyAtt0(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf1(polyinfo.GetPolyIndex(), 0xF000, 12); } -int dBgW::GetPolyAtt1(cBgS_PolyInfo const& poly) { - return GetPolyInf1(poly.GetPolyIndex(), 0x70000, 16); +int dBgW::GetPolyAtt1(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf1(polyinfo.GetPolyIndex(), 0x70000, 16); } -int dBgW::GetGroundCode(cBgS_PolyInfo const& poly) { - return GetPolyInf1(poly.GetPolyIndex(), 0xF80000, 19); +int dBgW::GetGroundCode(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf1(polyinfo.GetPolyIndex(), 0xF80000, 19); } u32 cBgW::GetMaskPolyInf1_NoShift(int poly_index, u32 mask) const { int id = GetPolyInfId(poly_index); + JUT_ASSERT(2324, 0 <= id && id < pm_bgd->m_ti_num); + return (pm_bgd->m_ti_tbl[id].m_info1 & mask); } @@ -939,26 +1074,30 @@ u32 dBgW::GetAttackThrough(int poly_index) { u32 cBgW::GetPolyInf2(int poly_index, u32 mask, u32 shift) const { int id = GetPolyInfId(poly_index); + JUT_ASSERT(2368, 0 <= id && id < pm_bgd->m_ti_num); + return (pm_bgd->m_ti_tbl[id].m_info2 & mask) >> shift; } -int dBgW::GetCamMoveBG(cBgS_PolyInfo const& poly) { - return GetPolyInf2(poly.GetPolyIndex(), 0xFF, 0); +int dBgW::GetCamMoveBG(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf2(polyinfo.GetPolyIndex(), 0xFF, 0); } -int dBgW::GetRoomCamId(cBgS_PolyInfo const& poly) { - return GetPolyInf2(poly.GetPolyIndex(), 0xFF00, 8); +int dBgW::GetRoomCamId(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf2(polyinfo.GetPolyIndex(), 0xFF00, 8); } -int dBgW::GetRoomPathId(cBgS_PolyInfo const& poly) { - return GetPolyInf2(poly.GetPolyIndex(), 0xFF0000, 16); +int dBgW::GetRoomPathId(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf2(polyinfo.GetPolyIndex(), 0xFF0000, 16); } -int dBgW::GetRoomPathPntNo(cBgS_PolyInfo const& poly) { - return GetPolyInf2(poly.GetPolyIndex(), 0xFF000000, 24); +int dBgW::GetRoomPathPntNo(const cBgS_PolyInfo& polyinfo) { + return GetPolyInf2(polyinfo.GetPolyIndex(), 0xFF000000, 24); } int cBgW::GetTriGrp(int poly_index) const { + JUT_ASSERT(2440, 0 <= poly_index && poly_index < pm_bgd->m_t_num); + return pm_bgd->m_t_tbl[poly_index].m_grp; } @@ -974,6 +1113,109 @@ bool cBgW::ChkMoveBg() const { return mFlags & MOVE_BG_e; } +void dBgW::DrawBox() const { + cXyz min; + cXyz max; + cXyz points[8]; + + min = *pm_grp[m_rootGrpIdx].m_aab.GetMinP(); + max = *pm_grp[m_rootGrpIdx].m_aab.GetMaxP(); + + points[0].x = min.x; + points[0].y = max.y; + points[0].z = min.z; + + points[1].x = max.x; + points[1].y = max.y; + points[1].z = min.z; + + points[2].x = min.x; + points[2].y = max.y; + points[2].z = max.z; + + points[3].x = max.x; + points[3].y = max.y; + points[3].z = max.z; + + points[4].x = min.x; + points[4].y = min.y; + points[4].z = min.z; + + points[5].x = max.x; + points[5].y = min.y; + points[5].z = min.z; + + points[6].x = min.x; + points[6].y = min.y; + points[6].z = max.z; + + points[7].x = max.x; + points[7].y = min.y; + points[7].z = max.z; + + dDbVw_drawCube8pXlu(points, COMPOUND_LITERAL(GXColor){0, 0xFF, 0, 0x64}); +} + +void dBgW::DebugDraw() const { + GXColor ground_color = {0xFF, 0, 0, 0x80}; + GXColor roof_color = {0, 0, 0xFF, 0x80}; + GXColor wall_color = {0, 0xFF, 0, 0x80}; + + cBgD_Tri_t* t_tbl = pm_bgd->m_t_tbl; + for (int i = 0; i < pm_bgd->m_t_num; i++) { + cXyz normal; + normal = pm_tri[i].m_plane.mNormal; + + cBgD_Vtx_t* v0 = &pm_vtx_tbl[t_tbl[i].m_vtx_idx0]; + cBgD_Vtx_t* v1 = &pm_vtx_tbl[t_tbl[i].m_vtx_idx1]; + cBgD_Vtx_t* v2 = &pm_vtx_tbl[t_tbl[i].m_vtx_idx2]; + + cXyz points[3]; + points[0].set(*v0); + points[1].set(*v1); + points[2].set(*v2); + + points[0] += normal; + points[1] += normal; + points[2] += normal; + + GXColor* pcolor; + if (cBgW_CheckBGround(normal.y)) { + pcolor = &ground_color; + } else if (cBgW_CheckBRoof(normal.y)) { + pcolor = &roof_color; + } else { + pcolor = &wall_color; + } + + dDbVw_drawTriangleXlu(points, *pcolor, TRUE); + } +} + +void dBgW::DrawPoly(const cBgS_PolyInfo& polyinfo, const GXColor& color) const { + int poly_index = polyinfo.GetPolyIndex(); + JUT_ASSERT(2579, 0 <= poly_index && poly_index < pm_bgd->m_t_num); + + cXyz normal; + normal = pm_tri[poly_index].m_plane.mNormal; + + cBgD_Tri_t* t_tbl = pm_bgd->m_t_tbl; + cBgD_Vtx_t* v0 = &pm_vtx_tbl[t_tbl[poly_index].m_vtx_idx0]; + cBgD_Vtx_t* v1 = &pm_vtx_tbl[t_tbl[poly_index].m_vtx_idx1]; + cBgD_Vtx_t* v2 = &pm_vtx_tbl[t_tbl[poly_index].m_vtx_idx2]; + + cXyz points[3]; + points[0].set(*v0); + points[1].set(*v1); + points[2].set(*v2); + + points[0] += normal; + points[1] += normal; + points[2] += normal; + + dDbVw_drawTriangleXlu(points, color, TRUE); +} + dBgW::dBgW() { m_crr_func = NULL; m_ride_callback = NULL; @@ -986,41 +1228,44 @@ void dBgW::Move() { cBgW::Move(); } -void dBgW::positionWallCorrect(dBgS_Acch* i_acch, f32 i_dist, cM3dGPla& plane, cXyz* pupper_pos, +void dBgW::positionWallCorrect(dBgS_Acch* pwi, f32 dist, cM3dGPla& plane, cXyz* pupper_pos, f32 speed) { - i_acch->SetWallHit(); + pwi->SetWallHit(); - f32 speed_correct = speed - 1.0f; - if (speed_correct < 0.0f) { - speed_correct = 0.0f; + speed -= 1.0f; + if (speed < 0.0f) { + speed = 0.0f; } - f32 move = speed_correct * i_dist; - pupper_pos->x += move * plane.mNormal.x; - pupper_pos->z += move * plane.mNormal.z; + f32 move = speed * dist; + pupper_pos->x += move * plane.GetNP()->x; + pupper_pos->z += move * plane.GetNP()->z; + + JUT_ASSERT(2682, !isnan(pupper_pos->x)); + JUT_ASSERT(2683, !isnan(pupper_pos->z)); } -bool dBgW::RwgWallCorrect(dBgS_Acch* pwi, u16 i_poly_idx) { +bool dBgW::RwgWallCorrect(dBgS_Acch* pwi, u16 poly_index) { bool correct = false; while (true) { - cBgW_RwgElm* rwg_elm = &pm_rwg[i_poly_idx]; + cBgW_RwgElm* rwg_elm = &pm_rwg[poly_index]; - if (!ChkPolyThrough(i_poly_idx, pwi->GetPolyPassChk())) { - cBgW_TriElm* tri = &pm_tri[i_poly_idx]; + if (!ChkPolyThrough(poly_index, pwi->GetPolyPassChk())) { + cBgW_TriElm* tri = &pm_tri[poly_index]; f32 sp68 = JMAFastSqrt(tri->m_plane.GetNP()->x * tri->m_plane.GetNP()->x + tri->m_plane.GetNP()->z * tri->m_plane.GetNP()->z); if (cM3d_IsZero(sp68)) { if (rwg_elm->m_next != 0xFFFF) { - i_poly_idx = rwg_elm->m_next; + poly_index = rwg_elm->m_next; continue; } break; } f32 sp6C = 1.0f / sp68; - cBgD_Tri_t* tri_data = &pm_bgd->m_t_tbl[i_poly_idx]; + cBgD_Tri_t* tri_data = &pm_bgd->m_t_tbl[poly_index]; int cir_index = 0; while (cir_index < pwi->GetTblSize()) { @@ -1129,10 +1374,10 @@ bool dBgW::RwgWallCorrect(dBgS_Acch* pwi, u16 i_poly_idx) { JMAFastSqrt(spC8)); pwi->CalcMovePosWork(); pwi->SetWallCirHit(cir_index); - pwi->SetWallPolyIndex(cir_index, i_poly_idx); - pwi->SetWallAngleY(cir_index, - cM_atan2s(tri->m_plane.GetNP()->x, - tri->m_plane.GetNP()->z)); + pwi->SetWallPolyIndex(cir_index, poly_index); + + s16 sp10 = cM_atan2s(tri->m_plane.GetNP()->x, tri->m_plane.GetNP()->z); + pwi->SetWallAngleY(cir_index, sp10); correct = true; } else { cx0 -= sp50.x; @@ -1140,9 +1385,9 @@ bool dBgW::RwgWallCorrect(dBgS_Acch* pwi, u16 i_poly_idx) { cx1 -= sp50.x; cy1 -= sp50.z; - JUT_ASSERT(0, pwi->GetPos()->x == + JUT_ASSERT(2920, pwi->GetPos()->x == pwi->GetWallCirP(cir_index)->GetCx()); - JUT_ASSERT(0, pwi->GetPos()->z == + JUT_ASSERT(2922, pwi->GetPos()->z == pwi->GetWallCirP(cir_index)->GetCy()); f32 spE0 = @@ -1153,12 +1398,12 @@ bool dBgW::RwgWallCorrect(dBgS_Acch* pwi, u16 i_poly_idx) { f32 onx = -tri->m_plane.GetNP()->x; f32 ony = -tri->m_plane.GetNP()->z; - JUT_ASSERT(0, !(cM3d_IsZero(onx) && cM3d_IsZero(ony))); + JUT_ASSERT(2938, !(cM3d_IsZero(onx) && cM3d_IsZero(ony))); if (spE0 < spE4) { if (!(spE0 > spDC) && !(fabsf(spE0 - spDC) < 0.008f)) { - JUT_ASSERT(0, !isnan(cx0)); - JUT_ASSERT(0, !isnan(cy0)); + JUT_ASSERT(2950, !isnan(cx0)); + JUT_ASSERT(2951, !isnan(cy0)); f32 spF0, spF4; cM2d_CrossCirLin(*pwi->GetWallCirP(cir_index), cx0, cy0, @@ -1166,21 +1411,20 @@ bool dBgW::RwgWallCorrect(dBgS_Acch* pwi, u16 i_poly_idx) { pwi->GetPos()->x += cx0 - spF0; pwi->GetPos()->z += cy0 - spF4; - JUT_ASSERT(0, !isnan(pwi->GetPos()->x)); - JUT_ASSERT(0, !isnan(pwi->GetPos()->z)); + JUT_ASSERT(2968, !isnan(pwi->GetPos()->x)); + JUT_ASSERT(2969, !isnan(pwi->GetPos()->z)); pwi->CalcMovePosWork(); pwi->SetWallCirHit(cir_index); - pwi->SetWallPolyIndex(cir_index, i_poly_idx); - pwi->SetWallAngleY(cir_index, - cM_atan2s(tri->m_plane.GetNP()->x, - tri->m_plane.GetNP()->z)); + pwi->SetWallPolyIndex(cir_index, poly_index); + s16 spE = cM_atan2s(tri->m_plane.GetNP()->x, tri->m_plane.GetNP()->z); + pwi->SetWallAngleY(cir_index, spE); correct = true; pwi->SetWallHit(); } } else if (!(spE4 > spDC) && !(fabsf(spE4 - spDC) < 0.008f)) { - JUT_ASSERT(0, !isnan(cx1)); - JUT_ASSERT(0, !isnan(cy1)); + JUT_ASSERT(2999, !isnan(cx1)); + JUT_ASSERT(3000, !isnan(cy1)); f32 spF8, spFC; cM2d_CrossCirLin(*pwi->GetWallCirP(cir_index), cx1, cy1, @@ -1188,15 +1432,15 @@ bool dBgW::RwgWallCorrect(dBgS_Acch* pwi, u16 i_poly_idx) { pwi->GetPos()->x += cx1 - spF8; pwi->GetPos()->z += cy1 - spFC; - JUT_ASSERT(0, !isnan(pwi->GetPos()->x)); - JUT_ASSERT(0, !isnan(pwi->GetPos()->z)); + JUT_ASSERT(3016, !isnan(pwi->GetPos()->x)); + JUT_ASSERT(3017, !isnan(pwi->GetPos()->z)); pwi->CalcMovePosWork(); pwi->SetWallCirHit(cir_index); - pwi->SetWallPolyIndex(cir_index, i_poly_idx); - pwi->SetWallAngleY(cir_index, - cM_atan2s(tri->m_plane.GetNP()->x, - tri->m_plane.GetNP()->z)); + pwi->SetWallPolyIndex(cir_index, poly_index); + + s16 spC = cM_atan2s(tri->m_plane.GetNP()->x, tri->m_plane.GetNP()->z); + pwi->SetWallAngleY(cir_index, spC); correct = true; pwi->SetWallHit(); } @@ -1214,27 +1458,34 @@ bool dBgW::RwgWallCorrect(dBgS_Acch* pwi, u16 i_poly_idx) { break; } - i_poly_idx = rwg_elm->m_next; + poly_index = rwg_elm->m_next; } return correct; } -bool dBgW::WallCorrectRp(dBgS_Acch* i_acch, int i_idx) { - if (!pm_node_tree[i_idx].Cross(i_acch->GetWallBmdCylP())) { +bool dBgW::WallCorrectRp(dBgS_Acch* pwi, int node_index) { + JUT_ASSERT(3060, 0 <= node_index && node_index < pm_bgd->m_tree_num); + + cBgW_NodeTree* tree = &pm_node_tree[node_index]; + if (!tree->Cross(pwi->GetWallBmdCylP())) { return false; } - cBgD_Tree_t* tree = &pm_bgd->m_tree_tbl[i_idx]; + cBgD_Tree_t* pnode = &pm_bgd->m_tree_tbl[node_index]; bool chk = false; - if ((tree->m_flag & 1)) { - if (pm_blk[tree->m_id[0]].m_wall_idx != 0xFFFF && - RwgWallCorrect(i_acch, pm_blk[tree->m_id[0]].m_wall_idx)) + if ((pnode->m_flag & 1)) { + JUT_ASSERT(3076, pnode->m_id[0] != 0xffff); + + JUT_ASSERT(3078, pnode->m_id[0] >= 0 && pnode->m_id[0] < pm_bgd->m_b_num); + + if (pm_blk[pnode->m_id[0]].m_wall_idx != 0xFFFF && + RwgWallCorrect(pwi, pm_blk[pnode->m_id[0]].m_wall_idx)) { chk = true; } - if (pm_blk[tree->m_id[0]].m_roof_idx != 0xFFFF && - RwgWallCorrect(i_acch, pm_blk[tree->m_id[0]].m_roof_idx)) + if (pm_blk[pnode->m_id[0]].m_roof_idx != 0xFFFF && + RwgWallCorrect(pwi, pm_blk[pnode->m_id[0]].m_roof_idx)) { chk = true; } @@ -1242,7 +1493,7 @@ bool dBgW::WallCorrectRp(dBgS_Acch* i_acch, int i_idx) { } for (int i = 0; i < 8; i++) { - if (tree->m_id[i] != 0xFFFF && WallCorrectRp(i_acch, tree->m_id[i])) { + if (pnode->m_id[i] != 0xFFFF && WallCorrectRp(pwi, pnode->m_id[i])) { chk = true; } } @@ -1250,28 +1501,31 @@ bool dBgW::WallCorrectRp(dBgS_Acch* i_acch, int i_idx) { return chk; } -bool dBgW::WallCorrectGrpRp(dBgS_Acch* i_acch, int i_idx, int i_depth) { - if (!pm_grp[i_idx].m_aab.Cross(i_acch->GetWallBmdCylP())) { +bool dBgW::WallCorrectGrpRp(dBgS_Acch* pwi, int g, int depth) { + JUT_ASSERT(3117, 0 <= g && g < pm_bgd->m_g_num); + + if (!pm_grp[g].m_aab.Cross(pwi->GetWallBmdCylP())) { return false; } - if (ChkGrpThrough(i_idx, i_acch->GetGrpPassChk(), i_depth)) { + if (ChkGrpThrough(g, pwi->GetGrpPassChk(), depth)) { return false; } bool chk = false; - if (pm_bgd->m_g_tbl[i_idx].m_tree_idx != 0xFFFF && - WallCorrectRp(i_acch, pm_bgd->m_g_tbl[i_idx].m_tree_idx)) + if (pm_bgd->m_g_tbl[g].m_tree_idx != 0xFFFF && + WallCorrectRp(pwi, pm_bgd->m_g_tbl[g].m_tree_idx)) { chk = true; } - int child_idx = pm_bgd->m_g_tbl[i_idx].m_first_child; + int child_idx = pm_bgd->m_g_tbl[g].m_first_child; + depth++; while (true) { if (child_idx == 0xFFFF) { break; } - if (WallCorrectGrpRp(i_acch, child_idx, i_depth + 1)) { + if (WallCorrectGrpRp(pwi, child_idx, depth)) { chk = true; } child_idx = pm_bgd->m_g_tbl[child_idx].m_next_sibling; @@ -1280,8 +1534,8 @@ bool dBgW::WallCorrectGrpRp(dBgS_Acch* i_acch, int i_idx, int i_depth) { return chk; } -bool dBgW::WallCorrect(dBgS_Acch* pacch) { - return WallCorrectGrpRp(pacch, m_rootGrpIdx, 1); +bool dBgW::WallCorrect(dBgS_Acch* pwi) { + return WallCorrectGrpRp(pwi, m_rootGrpIdx, 1); } struct wcs_data { @@ -1296,24 +1550,24 @@ static wcs_data* l_start; static int l_wcsbuf_num; -void dBgW::RwgWallCorrectSort(dBgS_Acch* i_acch, u16 i_poly_idx) { +void dBgW::RwgWallCorrectSort(dBgS_Acch* pwi, u16 poly_index) { while (true) { - cBgW_RwgElm* rwg_elm = &pm_rwg[i_poly_idx]; + cBgW_RwgElm* rwg_elm = &pm_rwg[poly_index]; - if (!ChkPolyThrough(i_poly_idx, i_acch->GetPolyPassChk())) { - cBgW_TriElm* tri_elm = &pm_tri[i_poly_idx]; + if (!ChkPolyThrough(poly_index, pwi->GetPolyPassChk())) { + cBgW_TriElm* tri_elm = &pm_tri[poly_index]; f32 var_f30 = JMAFastSqrt(tri_elm->m_plane.GetNP()->x * tri_elm->m_plane.GetNP()->x + tri_elm->m_plane.GetNP()->z * tri_elm->m_plane.GetNP()->z); if (cM3d_IsZero(var_f30)) { if (rwg_elm->m_next != 0xFFFF) { - i_poly_idx = rwg_elm->m_next; + poly_index = rwg_elm->m_next; continue; } break; } - fopAc_ac_c* actor = i_acch->getMyAc(); + fopAc_ac_c* actor = pwi->getMyAc(); cXyz sp88; sp88.x = cM_ssin(actor->current.angle.y); sp88.z = cM_scos(actor->current.angle.y); @@ -1322,52 +1576,67 @@ void dBgW::RwgWallCorrectSort(dBgS_Acch* i_acch, u16 i_poly_idx) { f32 var_f31 = var_f29 * ((sp88.x * tri_elm->m_plane.GetNP()->x) + (sp88.z * tri_elm->m_plane.GetNP()->z)); - wcs_data* data = l_start; - if (data == NULL) { + if (l_start == NULL) { if (l_wcsbuf_num < 84) { l_wcsbuf[l_wcsbuf_num].field_0x0 = var_f31; - l_wcsbuf[l_wcsbuf_num].poly_idx = i_poly_idx; + l_wcsbuf[l_wcsbuf_num].poly_idx = poly_index; l_wcsbuf[l_wcsbuf_num].next = NULL; l_start = &l_wcsbuf[l_wcsbuf_num]; l_wcsbuf_num++; + } else { + #if DEBUG + lbl_8074C7F0 = 1; + #endif } - } else if (i_poly_idx != l_start->poly_idx) { + } else if (poly_index != l_start->poly_idx) { if (var_f31 > l_start->field_0x0) { if (l_wcsbuf_num < 84) { l_wcsbuf[l_wcsbuf_num].field_0x0 = var_f31; - l_wcsbuf[l_wcsbuf_num].poly_idx = i_poly_idx; + l_wcsbuf[l_wcsbuf_num].poly_idx = poly_index; l_wcsbuf[l_wcsbuf_num].next = l_start; l_start = &l_wcsbuf[l_wcsbuf_num]; l_wcsbuf_num++; + } else { + #if DEBUG + lbl_8074C7F0 = 1; + #endif } } else { + wcs_data* data = l_start; while (true) { - wcs_data* tmp_data = data->next; - if (tmp_data == NULL) { + if (data->next == NULL) { if (l_wcsbuf_num < 84) { l_wcsbuf[l_wcsbuf_num].field_0x0 = var_f31; - l_wcsbuf[l_wcsbuf_num].poly_idx = i_poly_idx; + l_wcsbuf[l_wcsbuf_num].poly_idx = poly_index; l_wcsbuf[l_wcsbuf_num].next = NULL; data->next = &l_wcsbuf[l_wcsbuf_num]; l_wcsbuf_num++; + } else { + #if DEBUG + lbl_8074C7F0 = 1; + #endif } break; - } else if (i_poly_idx == tmp_data->poly_idx) { + } else if (poly_index == data->next->poly_idx) { break; } - if (var_f31 > tmp_data->field_0x0) { + if (var_f31 > data->next->field_0x0) { if (l_wcsbuf_num < 84) { l_wcsbuf[l_wcsbuf_num].field_0x0 = var_f31; - l_wcsbuf[l_wcsbuf_num].poly_idx = i_poly_idx; + l_wcsbuf[l_wcsbuf_num].poly_idx = poly_index; l_wcsbuf[l_wcsbuf_num].next = data->next; data->next = &l_wcsbuf[l_wcsbuf_num]; l_wcsbuf_num++; + } else { + #if DEBUG + lbl_8074C7F0 = 1; + #endif } break; } - data = tmp_data; + data = data->next; } } } @@ -1377,52 +1646,64 @@ void dBgW::RwgWallCorrectSort(dBgS_Acch* i_acch, u16 i_poly_idx) { return; } - i_poly_idx = rwg_elm->m_next; + poly_index = rwg_elm->m_next; } } -void dBgW::WallCorrectRpSort(dBgS_Acch* i_acch, int i_idx) { - if (!pm_node_tree[i_idx].Cross(i_acch->GetWallBmdCylP())) { +void dBgW::WallCorrectRpSort(dBgS_Acch* pwi, int node_index) { + JUT_ASSERT(3330, 0 <= node_index && node_index < pm_bgd->m_tree_num); + + cBgW_NodeTree* tree = &pm_node_tree[node_index]; + if (!tree->Cross(pwi->GetWallBmdCylP())) { return; } - cBgD_Tree_t* tree = &pm_bgd->m_tree_tbl[i_idx]; - if ((tree->m_flag & 1)) { - if (pm_blk[tree->m_id[0]].m_wall_idx != 0xFFFF) { - RwgWallCorrectSort(i_acch, pm_blk[tree->m_id[0]].m_wall_idx); + cBgD_Tree_t* pnode = &pm_bgd->m_tree_tbl[node_index]; + if ((pnode->m_flag & 1)) { + JUT_ASSERT(3345, pnode->m_id[0] != 0xffff); + + JUT_ASSERT(3347, pnode->m_id[0] >= 0 && pnode->m_id[0] < pm_bgd->m_b_num); + + if (pm_blk[pnode->m_id[0]].m_wall_idx != 0xFFFF) { + RwgWallCorrectSort(pwi, pm_blk[pnode->m_id[0]].m_wall_idx); } - if (pm_blk[tree->m_id[0]].m_roof_idx != 0xFFFF) { - RwgWallCorrectSort(i_acch, pm_blk[tree->m_id[0]].m_roof_idx); + if (pm_blk[pnode->m_id[0]].m_roof_idx != 0xFFFF) { + RwgWallCorrectSort(pwi, pm_blk[pnode->m_id[0]].m_roof_idx); } return; } for (int i = 0; i < 8; i++) { - if (tree->m_id[i] != 0xFFFF) { - WallCorrectRpSort(i_acch, tree->m_id[i]); + if (pnode->m_id[i] != 0xFFFF) { + WallCorrectRpSort(pwi, pnode->m_id[i]); } } } -bool dBgW::WallCorrectGrpRpSort(dBgS_Acch* i_acch, int i_idx, int i_depth) { - if (!pm_grp[i_idx].m_aab.Cross(i_acch->GetWallBmdCylP())) { +bool dBgW::WallCorrectGrpRpSort(dBgS_Acch* pwi, int g, int depth) { + JUT_ASSERT(3378, 0 <= g && g < pm_bgd->m_g_num); + + if (!pm_grp[g].m_aab.Cross(pwi->GetWallBmdCylP())) { return false; } - if (ChkGrpThrough(i_idx, i_acch->GetGrpPassChk(), i_depth)) { + if (ChkGrpThrough(g, pwi->GetGrpPassChk(), depth)) { return false; } - if (pm_bgd->m_g_tbl[i_idx].m_tree_idx != 0xFFFF) { - WallCorrectRpSort(i_acch, pm_bgd->m_g_tbl[i_idx].m_tree_idx); + bool var_r25 = false; + + if (pm_bgd->m_g_tbl[g].m_tree_idx != 0xFFFF) { + WallCorrectRpSort(pwi, pm_bgd->m_g_tbl[g].m_tree_idx); } - int child_idx = pm_bgd->m_g_tbl[i_idx].m_first_child; + int child_idx = pm_bgd->m_g_tbl[g].m_first_child; + depth++; while (true) { if (child_idx == 0xFFFF) { break; } - WallCorrectGrpRpSort(i_acch, child_idx, i_depth + 1); + WallCorrectGrpRpSort(pwi, child_idx, depth); child_idx = pm_bgd->m_g_tbl[child_idx].m_next_sibling; } @@ -1556,8 +1837,8 @@ bool dBgW::WallCorrectSort(dBgS_Acch* pwi) { pwi->CalcMovePosWork(); pwi->SetWallCirHit(cir_index); pwi->SetWallPolyIndex(cir_index, poly_index); - pwi->SetWallAngleY(cir_index, cM_atan2s(tri->m_plane.GetNP()->x, - tri->m_plane.GetNP()->z)); + s16 sp10 = cM_atan2s(tri->m_plane.GetNP()->x, tri->m_plane.GetNP()->z); + pwi->SetWallAngleY(cir_index, sp10); correct = true; } else { cx0 -= sp50.x; @@ -1565,9 +1846,9 @@ bool dBgW::WallCorrectSort(dBgS_Acch* pwi) { cx1 -= sp50.x; cy1 -= sp50.z; - JUT_ASSERT(0, pwi->GetPos()->x == + JUT_ASSERT(3625, pwi->GetPos()->x == pwi->GetWallCirP(cir_index)->GetCx()); - JUT_ASSERT(0, pwi->GetPos()->z == + JUT_ASSERT(3627, pwi->GetPos()->z == pwi->GetWallCirP(cir_index)->GetCy()); f32 spE0 = @@ -1578,12 +1859,12 @@ bool dBgW::WallCorrectSort(dBgS_Acch* pwi) { f32 onx = -tri->m_plane.GetNP()->x; f32 ony = -tri->m_plane.GetNP()->z; - JUT_ASSERT(0, !(cM3d_IsZero(onx) && cM3d_IsZero(ony))); + JUT_ASSERT(3643, !(cM3d_IsZero(onx) && cM3d_IsZero(ony))); if (spE0 < spE4) { if (!(spE0 > spDC) && !(fabsf(spE0 - spDC) < 0.008f)) { - JUT_ASSERT(0, !isnan(cx0)); - JUT_ASSERT(0, !isnan(cy0)); + JUT_ASSERT(3655, !isnan(cx0)); + JUT_ASSERT(3656, !isnan(cy0)); f32 spF0, spF4; cM2d_CrossCirLin(*pwi->GetWallCirP(cir_index), cx0, cy0, @@ -1591,21 +1872,20 @@ bool dBgW::WallCorrectSort(dBgS_Acch* pwi) { pwi->GetPos()->x += cx0 - spF0; pwi->GetPos()->z += cy0 - spF4; - JUT_ASSERT(0, !isnan(pwi->GetPos()->x)); - JUT_ASSERT(0, !isnan(pwi->GetPos()->z)); + JUT_ASSERT(3666, !isnan(pwi->GetPos()->x)); + JUT_ASSERT(3667, !isnan(pwi->GetPos()->z)); pwi->CalcMovePosWork(); pwi->SetWallCirHit(cir_index); pwi->SetWallPolyIndex(cir_index, poly_index); - pwi->SetWallAngleY(cir_index, - cM_atan2s(tri->m_plane.GetNP()->x, - tri->m_plane.GetNP()->z)); + s16 spE = cM_atan2s(tri->m_plane.GetNP()->x, tri->m_plane.GetNP()->z); + pwi->SetWallAngleY(cir_index, spE); correct = true; pwi->SetWallHit(); } } else if (!(spE4 > spDC) && !(fabsf(spE4 - spDC) < 0.008f)) { - JUT_ASSERT(0, !isnan(cx1)); - JUT_ASSERT(0, !isnan(cy1)); + JUT_ASSERT(3697, !isnan(cx1)); + JUT_ASSERT(3698, !isnan(cy1)); f32 spF8, spFC; cM2d_CrossCirLin(*pwi->GetWallCirP(cir_index), cx1, cy1, onx, @@ -1613,15 +1893,14 @@ bool dBgW::WallCorrectSort(dBgS_Acch* pwi) { pwi->GetPos()->x += cx1 - spF8; pwi->GetPos()->z += cy1 - spFC; - JUT_ASSERT(0, !isnan(pwi->GetPos()->x)); - JUT_ASSERT(0, !isnan(pwi->GetPos()->z)); + JUT_ASSERT(3707, !isnan(pwi->GetPos()->x)); + JUT_ASSERT(3708, !isnan(pwi->GetPos()->z)); pwi->CalcMovePosWork(); pwi->SetWallCirHit(cir_index); pwi->SetWallPolyIndex(cir_index, poly_index); - pwi->SetWallAngleY(cir_index, - cM_atan2s(tri->m_plane.GetNP()->x, - tri->m_plane.GetNP()->z)); + s16 spC = cM_atan2s(tri->m_plane.GetNP()->x, tri->m_plane.GetNP()->z); + pwi->SetWallAngleY(cir_index, spC); correct = true; pwi->SetWallHit(); } @@ -1640,46 +1919,58 @@ bool dBgW::WallCorrectSort(dBgS_Acch* pwi) { return correct; } -bool dBgW::RwgRoofChk(u16 i_poly_idx, dBgS_RoofChk* i_roofchk) { +bool dBgW::RwgRoofChk(u16 poly_index, dBgS_RoofChk* proofchk) { bool chk = false; - f32 crossY; + f32 cy; while (true) { - if (pm_tri[i_poly_idx].m_plane.getCrossY(*i_roofchk->GetPosP(), &crossY) && - crossY > i_roofchk->GetPosP()->y && crossY < i_roofchk->GetNowY()) + if (pm_tri[poly_index].m_plane.getCrossY(*proofchk->GetPosP(), &cy) && + cy > proofchk->GetPosP()->y && cy < proofchk->GetNowY()) { - cBgD_Tri_t* tri = &pm_bgd->m_t_tbl[i_poly_idx]; + cBgD_Tri_t* tri = &pm_bgd->m_t_tbl[poly_index]; if (cM3d_CrossY_Tri(pm_vtx_tbl[tri->m_vtx_idx0], pm_vtx_tbl[tri->m_vtx_idx1], - pm_vtx_tbl[tri->m_vtx_idx2], pm_tri[i_poly_idx].m_plane, - (const Vec*)i_roofchk->GetPosP())) + pm_vtx_tbl[tri->m_vtx_idx2], pm_tri[poly_index].m_plane, + (const Vec*)proofchk->GetPosP())) { - if (!ChkPolyThrough(i_poly_idx, i_roofchk->GetPolyPassChk())) { - i_roofchk->SetNowY(crossY); - i_roofchk->SetPolyIndex(i_poly_idx); + if (!ChkPolyThrough(poly_index, proofchk->GetPolyPassChk())) { + proofchk->SetNowY(cy); + proofchk->SetPolyIndex(poly_index); chk = true; + + JUT_ASSERT(3774, !isnan(cy)); + + JUT_ASSERT(3776, -INF < cy && cy < INF); } } } - if (pm_rwg[i_poly_idx].m_next == 0xFFFF) + cBgW_RwgElm* element = &pm_rwg[poly_index]; + if (element->m_next == 0xFFFF) break; - i_poly_idx = pm_rwg[i_poly_idx].m_next; + + poly_index = element->m_next; } return chk; } -bool dBgW::RoofChkRp(dBgS_RoofChk* i_roofchk, int i_idx) { - cBgW_NodeTree* node = &pm_node_tree[i_idx]; - if (!node->CrossY(i_roofchk->GetPosP()) || !node->UnderPlaneYUnder(i_roofchk->GetNowY()) || - node->TopPlaneYUnder(i_roofchk->GetPosP()->y)) +bool dBgW::RoofChkRp(dBgS_RoofChk* proofchk, int node_index) { + JUT_ASSERT(3802, 0 <= node_index && node_index < pm_bgd->m_tree_num); + + cBgW_NodeTree* node = &pm_node_tree[node_index]; + if (!node->CrossY(proofchk->GetPosP()) || !node->UnderPlaneYUnder(proofchk->GetNowY()) || + node->TopPlaneYUnder(proofchk->GetPosP()->y)) { return false; } - cBgD_Tree_t* tree = &pm_bgd->m_tree_tbl[i_idx]; - if ((tree->m_flag & 1)) { - if (pm_blk[tree->m_id[0]].m_roof_idx != 0xFFFF && - RwgRoofChk(pm_blk[tree->m_id[0]].m_roof_idx, i_roofchk)) + cBgD_Tree_t* pnode = &pm_bgd->m_tree_tbl[node_index]; + if ((pnode->m_flag & 1)) { + JUT_ASSERT(3819, pnode->m_id[0] != 0xffff); + + JUT_ASSERT(3821, pnode->m_id[0] >= 0 && pnode->m_id[0] < pm_bgd->m_b_num); + + if (pm_blk[pnode->m_id[0]].m_roof_idx != 0xFFFF && + RwgRoofChk(pm_blk[pnode->m_id[0]].m_roof_idx, proofchk)) { return true; } @@ -1688,7 +1979,7 @@ bool dBgW::RoofChkRp(dBgS_RoofChk* i_roofchk, int i_idx) { bool chk = false; for (int i = 0; i < 8; i++) { - if (tree->m_id[i] != 0xFFFF && RoofChkRp(i_roofchk, tree->m_id[i])) { + if (pnode->m_id[i] != 0xFFFF && RoofChkRp(proofchk, pnode->m_id[i])) { chk = true; } } @@ -1696,31 +1987,34 @@ bool dBgW::RoofChkRp(dBgS_RoofChk* i_roofchk, int i_idx) { return chk; } -bool dBgW::RoofChkGrpRp(dBgS_RoofChk* i_roofchk, int i_idx, int i_depth) { - cBgW_GrpElm* grp = &pm_grp[i_idx]; - if (!grp->m_aab.CrossY(i_roofchk->GetPosP()) || - !grp->m_aab.UnderPlaneYUnder(i_roofchk->GetNowY()) || - grp->m_aab.TopPlaneYUnder(i_roofchk->GetPosP()->y)) +bool dBgW::RoofChkGrpRp(dBgS_RoofChk* proofchk, int g, int depth) { + JUT_ASSERT(3856, 0 <= g && g < pm_bgd->m_g_num); + + cBgW_GrpElm* grp = &pm_grp[g]; + if (!grp->m_aab.CrossY(proofchk->GetPosP()) || + !grp->m_aab.UnderPlaneYUnder(proofchk->GetNowY()) || + grp->m_aab.TopPlaneYUnder(proofchk->GetPosP()->y)) { return false; } - if (ChkGrpThrough(i_idx, i_roofchk->GetGrpPassChk(), i_depth)) { + if (ChkGrpThrough(g, proofchk->GetGrpPassChk(), depth)) { return false; } bool chk = false; - cBgD_Grp_t* data = &pm_bgd->m_g_tbl[i_idx]; - if (data->m_tree_idx != 0xFFFF && RoofChkRp(i_roofchk, data->m_tree_idx)) { + cBgD_Grp_t* data = &pm_bgd->m_g_tbl[g]; + if (data->m_tree_idx != 0xFFFF && RoofChkRp(proofchk, data->m_tree_idx)) { chk = true; } + depth++; int child_idx = data->m_first_child; while (true) { if (child_idx == 0xFFFF) { break; } - if (RoofChkGrpRp(i_roofchk, child_idx, i_depth + 1)) { + if (RoofChkGrpRp(proofchk, child_idx, depth)) { chk = true; } child_idx = pm_bgd->m_g_tbl[child_idx].m_next_sibling; @@ -1729,50 +2023,62 @@ bool dBgW::RoofChkGrpRp(dBgS_RoofChk* i_roofchk, int i_idx, int i_depth) { return chk; } -bool dBgW::RoofChk(dBgS_RoofChk* pchk) { - return RoofChkGrpRp(pchk, m_rootGrpIdx, 1); +bool dBgW::RoofChk(dBgS_RoofChk* proofchk) { + return RoofChkGrpRp(proofchk, m_rootGrpIdx, 1); } -bool dBgW::RwgSplGrpChk(u16 i_poly_idx, dBgS_SplGrpChk* i_splchk) { +bool dBgW::RwgSplGrpChk(u16 poly_index, dBgS_SplGrpChk* psplchk) { bool chk = false; - f32 crossY; + f32 cy; while (true) { - if (pm_tri[i_poly_idx].m_plane.getCrossY(i_splchk->GetPosP(), &crossY) && - crossY < i_splchk->GetRoof() && crossY > i_splchk->GetHeight()) + if (pm_tri[poly_index].m_plane.getCrossY(psplchk->GetPosP(), &cy) && + cy < psplchk->GetRoof() && cy > psplchk->GetHeight()) { - cBgD_Tri_t* tri = &pm_bgd->m_t_tbl[i_poly_idx]; + cBgD_Tri_t* tri = &pm_bgd->m_t_tbl[poly_index]; if (cM3d_CrossY_Tri(pm_vtx_tbl[tri->m_vtx_idx0], pm_vtx_tbl[tri->m_vtx_idx1], - pm_vtx_tbl[tri->m_vtx_idx2], pm_tri[i_poly_idx].m_plane, - (const Vec*)&i_splchk->GetPosP())) + pm_vtx_tbl[tri->m_vtx_idx2], pm_tri[poly_index].m_plane, + (const Vec*)&psplchk->GetPosP())) { - if (!ChkPolyThrough(i_poly_idx, i_splchk->GetPolyPassChk())) { - i_splchk->SetHeight(crossY); - i_splchk->SetPolyIndex(i_poly_idx); + if (!ChkPolyThrough(poly_index, psplchk->GetPolyPassChk())) { + psplchk->SetHeight(cy); + psplchk->SetPolyIndex(poly_index); chk = true; + + JUT_ASSERT(3951, !isnan(cy)); + + JUT_ASSERT(3953, -INF < cy && cy < INF); } } } - if (pm_rwg[i_poly_idx].m_next == 0xFFFF) + cBgW_RwgElm* element = &pm_rwg[poly_index]; + if (element->m_next == 0xFFFF) break; - i_poly_idx = pm_rwg[i_poly_idx].m_next; + + poly_index = element->m_next; } return chk; } -bool dBgW::SplGrpChkRp(dBgS_SplGrpChk* i_splchk, int i_idx) { - cBgW_NodeTree* node = &pm_node_tree[i_idx]; - if (!node->CrossY(&i_splchk->GetPosP()) || !node->UnderPlaneYUnder(i_splchk->GetRoof()) || - node->TopPlaneYUnder(i_splchk->GetHeight())) +bool dBgW::SplGrpChkRp(dBgS_SplGrpChk* psplchk, int node_index) { + JUT_ASSERT(3980, 0 <= node_index && node_index < pm_bgd->m_tree_num); + + cBgW_NodeTree* node = &pm_node_tree[node_index]; + if (!node->CrossY(&psplchk->GetPosP()) || !node->UnderPlaneYUnder(psplchk->GetRoof()) || + node->TopPlaneYUnder(psplchk->GetHeight())) { return false; } - cBgD_Tree_t* tree = &pm_bgd->m_tree_tbl[i_idx]; - if ((tree->m_flag & 1)) { - if (pm_blk[tree->m_id[0]].m_gnd_idx != 0xFFFF && - RwgSplGrpChk(pm_blk[tree->m_id[0]].m_gnd_idx, i_splchk)) + cBgD_Tree_t* pnode = &pm_bgd->m_tree_tbl[node_index]; + if ((pnode->m_flag & 1)) { + JUT_ASSERT(3996, pnode->m_id[0] != 0xffff); + + JUT_ASSERT(3998, pnode->m_id[0] >= 0 && pnode->m_id[0] < pm_bgd->m_b_num); + + if (pm_blk[pnode->m_id[0]].m_gnd_idx != 0xFFFF && + RwgSplGrpChk(pm_blk[pnode->m_id[0]].m_gnd_idx, psplchk)) { return true; } @@ -1781,7 +2087,7 @@ bool dBgW::SplGrpChkRp(dBgS_SplGrpChk* i_splchk, int i_idx) { bool chk = false; for (int i = 0; i < 8; i++) { - if (tree->m_id[i] != 0xFFFF && SplGrpChkRp(i_splchk, tree->m_id[i])) { + if (pnode->m_id[i] != 0xFFFF && SplGrpChkRp(psplchk, pnode->m_id[i])) { chk = true; } } @@ -1789,31 +2095,34 @@ bool dBgW::SplGrpChkRp(dBgS_SplGrpChk* i_splchk, int i_idx) { return chk; } -bool dBgW::SplGrpChkGrpRp(dBgS_SplGrpChk* i_splchk, int i_idx, int i_depth) { - cBgW_GrpElm* grp = &pm_grp[i_idx]; - if (!grp->m_aab.CrossY(&i_splchk->GetPosP()) || - !grp->m_aab.UnderPlaneYUnder(i_splchk->GetRoof()) || - grp->m_aab.TopPlaneYUnder(i_splchk->GetHeight())) +bool dBgW::SplGrpChkGrpRp(dBgS_SplGrpChk* psplchk, int g, int depth) { + JUT_ASSERT(4030, 0 <= g && g < pm_bgd->m_g_num); + + cBgW_GrpElm* grp = &pm_grp[g]; + if (!grp->m_aab.CrossY(&psplchk->GetPosP()) || + !grp->m_aab.UnderPlaneYUnder(psplchk->GetRoof()) || + grp->m_aab.TopPlaneYUnder(psplchk->GetHeight())) { return false; } - if (ChkGrpThrough(i_idx, i_splchk->GetGrpPassChk(), i_depth)) { + if (ChkGrpThrough(g, psplchk->GetGrpPassChk(), depth)) { return false; } bool chk = false; - cBgD_Grp_t* data = &pm_bgd->m_g_tbl[i_idx]; - if (data->m_tree_idx != 0xFFFF && SplGrpChkRp(i_splchk, data->m_tree_idx)) { + cBgD_Grp_t* data = &pm_bgd->m_g_tbl[g]; + if (data->m_tree_idx != 0xFFFF && SplGrpChkRp(psplchk, data->m_tree_idx)) { chk = true; } + depth++; int child_idx = data->m_first_child; while (true) { if (child_idx == 0xFFFF) { break; } - if (SplGrpChkGrpRp(i_splchk, child_idx, i_depth + 1)) { + if (SplGrpChkGrpRp(psplchk, child_idx, depth)) { chk = true; } child_idx = pm_bgd->m_g_tbl[child_idx].m_next_sibling; @@ -1822,38 +2131,41 @@ bool dBgW::SplGrpChkGrpRp(dBgS_SplGrpChk* i_splchk, int i_idx, int i_depth) { return chk; } -bool dBgW::SplGrpChk(dBgS_SplGrpChk* pchk) { - return SplGrpChkGrpRp(pchk, m_rootGrpIdx, 1); +bool dBgW::SplGrpChk(dBgS_SplGrpChk* psplchk) { + return SplGrpChkGrpRp(psplchk, m_rootGrpIdx, 1); } -void dBgW::RwgCaptPoly(int i_idx, dBgS_CaptPoly& i_captpoly) { +void dBgW::RwgCaptPoly(int index, dBgS_CaptPoly& capt) { + cBgW_RwgElm* rwg; while (true) { - cBgW_RwgElm* rwg = &pm_rwg[i_idx]; - i_captpoly.m_callback(i_captpoly, pm_vtx_tbl, pm_bgd->m_t_tbl[i_idx].m_vtx_idx0, - pm_bgd->m_t_tbl[i_idx].m_vtx_idx1, pm_bgd->m_t_tbl[i_idx].m_vtx_idx2, - &pm_tri[i_idx].m_plane); + rwg = &pm_rwg[index]; + capt.m_callback(&capt, pm_vtx_tbl, pm_bgd->m_t_tbl[index].m_vtx_idx0, + pm_bgd->m_t_tbl[index].m_vtx_idx1, pm_bgd->m_t_tbl[index].m_vtx_idx2, + &pm_tri[index].m_plane); if (rwg->m_next == 0xFFFF) break; - i_idx = rwg->m_next; + index = rwg->m_next; + + JUT_ASSERT(4110, 0 <= index && index < pm_bgd->m_t_num); } } -void dBgW::CaptPolyRp(dBgS_CaptPoly& i_captpoly, int i_idx) { - if (!pm_node_tree[i_idx].Cross(i_captpoly.GetBndP())) { +void dBgW::CaptPolyRp(dBgS_CaptPoly& capt, int node_index) { + if (!pm_node_tree[node_index].Cross(capt.GetBndP())) { return; } - cBgD_Tree_t* tree_data = &pm_bgd->m_tree_tbl[i_idx]; + cBgD_Tree_t* tree_data = &pm_bgd->m_tree_tbl[node_index]; if (tree_data->m_flag & 1) { if (pm_blk[tree_data->m_id[0]].m_wall_idx != 0xFFFF) { - RwgCaptPoly(pm_blk[tree_data->m_id[0]].m_wall_idx, i_captpoly); + RwgCaptPoly(pm_blk[tree_data->m_id[0]].m_wall_idx, capt); } if (pm_blk[tree_data->m_id[0]].m_roof_idx != 0xFFFF) { - RwgCaptPoly(pm_blk[tree_data->m_id[0]].m_roof_idx, i_captpoly); + RwgCaptPoly(pm_blk[tree_data->m_id[0]].m_roof_idx, capt); } if (pm_blk[tree_data->m_id[0]].m_gnd_idx != 0xFFFF) { - RwgCaptPoly(pm_blk[tree_data->m_id[0]].m_gnd_idx, i_captpoly); + RwgCaptPoly(pm_blk[tree_data->m_id[0]].m_gnd_idx, capt); } return; } @@ -1862,90 +2174,90 @@ void dBgW::CaptPolyRp(dBgS_CaptPoly& i_captpoly, int i_idx) { if (tree_data->m_id[i] == 0xFFFF) { continue; } - CaptPolyRp(i_captpoly, tree_data->m_id[i]); + CaptPolyRp(capt, tree_data->m_id[i]); } } -void dBgW::CaptPolyGrpRp(dBgS_CaptPoly& i_captpoly, int i_idx, int i_depth) { - cBgW_GrpElm* grp = &pm_grp[i_idx]; - if (!grp->m_aab.Cross(i_captpoly.GetBndP())) { +void dBgW::CaptPolyGrpRp(dBgS_CaptPoly& capt, int node_index, int depth) { + if (!pm_grp[node_index].m_aab.Cross(capt.GetBndP())) { return; } - if (ChkGrpThrough(i_idx, i_captpoly.GetGrpPassChk(), i_depth)) { + if (ChkGrpThrough(node_index, capt.GetGrpPassChk(), depth)) { return; } - cBgD_Grp_t* data = &pm_bgd->m_g_tbl[i_idx]; - if (pm_bgd->m_g_tbl[i_idx].m_tree_idx != 0xFFFF) { - CaptPolyRp(i_captpoly, pm_bgd->m_g_tbl[i_idx].m_tree_idx); + if (pm_bgd->m_g_tbl[node_index].m_tree_idx != 0xFFFF) { + CaptPolyRp(capt, pm_bgd->m_g_tbl[node_index].m_tree_idx); } - int child_idx = pm_bgd->m_g_tbl[i_idx].m_first_child; + depth++; + int child_idx = pm_bgd->m_g_tbl[node_index].m_first_child; while (true) { if (child_idx == 0xFFFF) { break; } - CaptPolyGrpRp(i_captpoly, child_idx, i_depth + 1); + CaptPolyGrpRp(capt, child_idx, depth); child_idx = pm_bgd->m_g_tbl[child_idx].m_next_sibling; } } -void dBgW::CaptPoly(dBgS_CaptPoly& i_captpoly) { - CaptPolyGrpRp(i_captpoly, m_rootGrpIdx, 1); +void dBgW::CaptPoly(dBgS_CaptPoly& capt) { + CaptPolyGrpRp(capt, m_rootGrpIdx, 1); } -bool dBgW::RwgSphChk(u16 i_poly_idx, dBgS_SphChk* i_sphchk, void* i_data) { +bool dBgW::RwgSphChk(u16 poly_index, dBgS_SphChk* psphchk, void* i_data) { cM3dGTri tri; cBgW_RwgElm* rwg; cBgD_Tri_t* tri_t; bool chk = false; while (true) { - rwg = &pm_rwg[i_poly_idx]; - if (!ChkPolyThrough(i_poly_idx, i_sphchk->GetPolyPassChk())) { - tri_t = &pm_bgd->m_t_tbl[i_poly_idx]; + rwg = &pm_rwg[poly_index]; + if (!ChkPolyThrough(poly_index, psphchk->GetPolyPassChk())) { + tri_t = &pm_bgd->m_t_tbl[poly_index]; tri.setBg(&pm_vtx_tbl[tri_t->m_vtx_idx0], &pm_vtx_tbl[tri_t->m_vtx_idx1], - &pm_vtx_tbl[tri_t->m_vtx_idx2], &pm_tri[i_poly_idx].m_plane); + &pm_vtx_tbl[tri_t->m_vtx_idx2], &pm_tri[poly_index].m_plane); - if (i_sphchk->cross(&tri)) { - i_sphchk->mCallback(i_sphchk, pm_vtx_tbl, tri_t->m_vtx_idx0, tri_t->m_vtx_idx1, - tri_t->m_vtx_idx2, &pm_tri[i_poly_idx].m_plane, i_data); - i_sphchk->SetPolyIndex(i_poly_idx); + if (psphchk->cross(&tri)) { + psphchk->mCallback(psphchk, pm_vtx_tbl, tri_t->m_vtx_idx0, tri_t->m_vtx_idx1, + tri_t->m_vtx_idx2, &pm_tri[poly_index].m_plane, i_data); + psphchk->SetPolyIndex(poly_index); chk = true; } } if (rwg->m_next == 0xFFFF) break; - i_poly_idx = rwg->m_next; + poly_index = rwg->m_next; } return chk; } -bool dBgW::SphChkRp(dBgS_SphChk* i_sphchk, void* i_data, int i_idx) { - if (!pm_node_tree[i_idx].Cross(i_sphchk)) { +bool dBgW::SphChkRp(dBgS_SphChk* psphchk, void* i_data, int node_index) { + cBgW_NodeTree* tree = &pm_node_tree[node_index]; + if (!tree->Cross(psphchk)) { return false; } - cBgD_Tree_t* tree_data = &pm_bgd->m_tree_tbl[i_idx]; + cBgD_Tree_t* tree_data = &pm_bgd->m_tree_tbl[node_index]; bool chk = false; if (tree_data->m_flag & 1) { if (pm_blk[tree_data->m_id[0]].m_gnd_idx != 0xFFFF && - RwgSphChk(pm_blk[tree_data->m_id[0]].m_gnd_idx, i_sphchk, i_data)) + RwgSphChk(pm_blk[tree_data->m_id[0]].m_gnd_idx, psphchk, i_data)) { chk = true; } if (pm_blk[tree_data->m_id[0]].m_roof_idx != 0xFFFF && - RwgSphChk(pm_blk[tree_data->m_id[0]].m_roof_idx, i_sphchk, i_data)) + RwgSphChk(pm_blk[tree_data->m_id[0]].m_roof_idx, psphchk, i_data)) { chk = true; } if (pm_blk[tree_data->m_id[0]].m_wall_idx != 0xFFFF && - RwgSphChk(pm_blk[tree_data->m_id[0]].m_wall_idx, i_sphchk, i_data)) + RwgSphChk(pm_blk[tree_data->m_id[0]].m_wall_idx, psphchk, i_data)) { chk = true; } @@ -1957,34 +2269,36 @@ bool dBgW::SphChkRp(dBgS_SphChk* i_sphchk, void* i_data, int i_idx) { if (tree_data->m_id[i] == 0xFFFF) { continue; } - if (SphChkRp(i_sphchk, i_data, tree_data->m_id[i])) { + if (SphChkRp(psphchk, i_data, tree_data->m_id[i])) { chk = true; } } return chk; } -bool dBgW::SphChkGrpRp(dBgS_SphChk* i_sphchk, void* i_data, int i_idx, int i_depth) { - if (!pm_grp[i_idx].m_aab.Cross(i_sphchk)) { +bool dBgW::SphChkGrpRp(dBgS_SphChk* psphchk, void* i_data, int node_index, int depth) { + cBgW_GrpElm* pnode = &pm_grp[node_index]; + if (!pnode->m_aab.Cross(psphchk)) { return false; } - if (ChkGrpThrough(i_idx, i_sphchk->GetGrpPassChk(), i_depth)) { + if (ChkGrpThrough(node_index, psphchk->GetGrpPassChk(), depth)) { return false; } bool chk = false; - cBgD_Grp_t* data = &pm_bgd->m_g_tbl[i_idx]; - if (data->m_tree_idx != 0xFFFF && SphChkRp(i_sphchk, i_data, data->m_tree_idx)) { + cBgD_Grp_t* data = &pm_bgd->m_g_tbl[node_index]; + if (data->m_tree_idx != 0xFFFF && SphChkRp(psphchk, i_data, data->m_tree_idx)) { chk = true; } + depth++; int child_idx = data->m_first_child; while (true) { if (child_idx == 0xFFFF) { break; } - if (SphChkGrpRp(i_sphchk, i_data, child_idx, i_depth + 1)) { + if (SphChkGrpRp(psphchk, i_data, child_idx, depth)) { chk = true; } child_idx = pm_bgd->m_g_tbl[child_idx].m_next_sibling; @@ -1993,35 +2307,39 @@ bool dBgW::SphChkGrpRp(dBgS_SphChk* i_sphchk, void* i_data, int i_idx, int i_dep return chk; } -bool dBgW::SphChk(dBgS_SphChk* pchk, void* i_data) { - return SphChkGrpRp(pchk, i_data, m_rootGrpIdx, 1); +bool dBgW::SphChk(dBgS_SphChk* psphchk, void* i_data) { + return SphChkGrpRp(psphchk, i_data, m_rootGrpIdx, 1); } -u8 dBgW::GetPolyGrpRoomInfId(cBgS_PolyInfo const& poly) { - return GetGrpInf(poly) & 0xFF; +u8 dBgW::GetPolyGrpRoomInfId(const cBgS_PolyInfo& polyinfo) { + u32 inf = GetGrpInf(polyinfo); + u8 id = inf & 0xFF; + return id; } -int dBgW::GetGrpSoundId(cBgS_PolyInfo const& poly) { - return (GetGrpInf(poly) >> 11) & 0xFF; +int dBgW::GetGrpSoundId(const cBgS_PolyInfo& polyinfo) { + u32 inf = GetGrpInf(polyinfo); + int id = (inf >> 11) & 0xFF; + return id; } -void dBgW::CrrPos(cBgS_PolyInfo const& i_poly, void* i_actor_ptr, bool param_2, cXyz* i_pos, - csXyz* i_angle, csXyz* i_shapeAngle) { +void dBgW::CrrPos(const cBgS_PolyInfo& polyinfo, void* actor_ptr, bool param_2, cXyz* ppos, + csXyz* pangle, csXyz* pshapeangle) { if (m_crr_func) { - m_crr_func(this, i_actor_ptr, i_poly, param_2, i_pos, i_angle, i_shapeAngle); + m_crr_func(this, actor_ptr, polyinfo, param_2, ppos, pangle, pshapeangle); } } -void dBgW::TransPos(cBgS_PolyInfo const& i_poly, void* i_actor_ptr, bool param_2, cXyz* i_pos, - csXyz* i_angle, csXyz* i_shapeAngle) { +void dBgW::TransPos(const cBgS_PolyInfo& polyinfo, void* actor_ptr, bool param_2, cXyz* ppos, + csXyz* pangle, csXyz* pshapeangle) { if (m_crr_func) { - m_crr_func(this, i_actor_ptr, i_poly, param_2, i_pos, i_angle, i_shapeAngle); + m_crr_func(this, actor_ptr, polyinfo, param_2, ppos, pangle, pshapeangle); } } -void dBgW::MatrixCrrPos(cBgS_PolyInfo const& i_poly, void* i_actor_ptr, bool param_2, cXyz* i_pos, - csXyz* i_angle, csXyz* i_shapeAngle) { - CrrPos(i_poly, i_actor_ptr, param_2, i_pos, i_angle, i_shapeAngle); +void dBgW::MatrixCrrPos(const cBgS_PolyInfo& polyinfo, void* actor_ptr, bool param_2, cXyz* ppos, + csXyz* pangle, csXyz* pshapeangle) { + CrrPos(polyinfo, actor_ptr, param_2, ppos, pangle, pshapeangle); } bool dBgW::ChkPolyThrough(int poly_index, cBgS_PolyPassChk* ppass_chk) { @@ -2076,7 +2394,8 @@ bool dBgW::ChkPolyThrough(int poly_index, cBgS_PolyPassChk* ppass_chk) { cXyz pos(pm_tri[poly_index].m_plane.mNormal); if (chk->ChkHorse() && dComIfGp_getHorseActor() != NULL) { - if (!dComIfGp_getHorseActor()->checkSpecialWallHit(pos)) { + daHorse_c* horse = dComIfGp_getHorseActor(); + if (!horse->checkSpecialWallHit(pos)) { return true; } } @@ -2093,26 +2412,35 @@ bool dBgW::ChkPolyThrough(int poly_index, cBgS_PolyPassChk* ppass_chk) { return false; } -bool dBgW::ChkShdwDrawThrough(int poly_index, cBgS_PolyPassChk*) { +bool dBgW::ChkShdwDrawThrough(int poly_index, cBgS_PolyPassChk* ppchk) { + UNUSED(ppchk); + if (GetShdwThrough(poly_index)) { return true; } - return GetPolyArrowThrough(poly_index); + if (GetPolyArrowThrough(poly_index)) { + return true; + } + + return false; } -bool dBgW::ChkGrpThrough(int i_grp_idx, cBgS_GrpPassChk* i_passChk, int i_depth) { - if (i_depth != 2 || i_passChk == NULL) { +bool dBgW::ChkGrpThrough(int g, cBgS_GrpPassChk* ppasschk, int depth) { + if (depth != 2 || ppasschk == NULL) { return false; } - if ((pm_bgd->m_g_tbl[i_grp_idx].m_info & 0x100) == 0 && - ((dBgS_GrpPassChk*)i_passChk)->MaskNormalGrp()) + + dBgS_GrpPassChk* var_r31 = (dBgS_GrpPassChk*)ppasschk; + + u32 var_r29 = pm_bgd->m_g_tbl[g].m_info & 0x100; + if (!var_r29 && var_r31->MaskNormalGrp()) { return false; } - if ((pm_bgd->m_g_tbl[i_grp_idx].m_info & 0x100) && - ((dBgS_GrpPassChk*)i_passChk)->MaskWaterGrp()) + u32 var_r28 = pm_bgd->m_g_tbl[g].m_info & 0x100; + if (var_r28 && var_r31->MaskWaterGrp()) { return false; } @@ -2133,7 +2461,7 @@ void dBgW::CallArrowStickCallBack(fopAc_ac_c* param_0, fopAc_ac_c* param_1, cXyz } void dBgW::OffMoveFlag() { - m_flags &= ~1; + m_flags &= (u8)~1; } u32 dBgW::ChkMoveFlag() const { @@ -2144,10 +2472,13 @@ dBgW* dBgW_NewSet(cBgD_t* pbgd, u32 flags, Mtx* pbase_mtx) { dBgW* nw = JKR_NEW dBgW(); if (nw == NULL) { + OS_REPORT_ERROR("dBgW_NewSet():dBgWの確保失敗\n"); return NULL; } - if (nw->Set(pbgd, flags, pbase_mtx)) { + bool rt = nw->Set(pbgd, flags, pbase_mtx); + if (rt) { + OS_REPORT_ERROR("dBgW_NewSet():dBgWのSet失敗\n"); return NULL; } diff --git a/src/d/d_bg_w_kcol.cpp b/src/d/d_bg_w_kcol.cpp index 17ec0298c1..46e5e5dd21 100644 --- a/src/d/d_bg_w_kcol.cpp +++ b/src/d/d_bg_w_kcol.cpp @@ -3,7 +3,7 @@ #include "d/d_bg_w_kcol.h" #include "d/d_com_inf_game.h" #include "d/actor/d_a_horse.h" -#include "d/d_bg_s_cap_poly.h" +#include "d/d_bg_s_capt_poly.h" #include #include @@ -937,8 +937,8 @@ void dBgWKCol::CaptPoly(dBgS_CaptPoly& i_captpoly) { int sp34; int sp30; if (sp4C < sp48) { - u16* sp2C = NULL; - u16* sp28 = NULL; + BE(u16)* sp2C = NULL; + BE(u16)* sp28 = NULL; int sp24 = sp4C; do { @@ -951,21 +951,21 @@ void dBgWKCol::CaptPoly(dBgS_CaptPoly& i_captpoly) { int sp1C = sp5C; do { - u16* sp18 = (u16*)m_pkc_head->m_block_data; + BE(u16)* sp18 = (BE(u16)*)m_pkc_head->m_block_data; int r29 = m_pkc_head->m_block_width_shift; int sp14 = 4 * (((u32)sp24 >> r29) << m_pkc_head->m_area_xy_blocks_shift | ((u32)sp20 >> r29) << m_pkc_head->m_area_x_blocks_shift | (u32)sp1C >> r29); - while ((sp14 = (*(int*)((intptr_t)sp18 + sp14))) >= 0) { - sp18 = (u16*)((intptr_t)sp18 + sp14); + while ((sp14 = (*(BE(u32)*)((intptr_t)sp18 + sp14))) >= 0) { + sp18 = (BE(u16)*)((intptr_t)sp18 + sp14); r29--; sp14 = (((u32)sp24 >> r29 & 1) << 2 | ((u32)sp20 >> r29 & 1) << 1 | ((u32)sp1C >> r29 & 1) << 0) << 2; } - u16* r28 = (u16*)((intptr_t)sp18 + (sp14 & 0x7FFFFFFF)); + BE(u16)* r28 = (BE(u16)*)((intptr_t)sp18 + (sp14 & 0x7FFFFFFF)); r29 = 1 << r29; int sp10 = r29 - 1; @@ -1009,7 +1009,7 @@ void dBgWKCol::CaptPoly(dBgS_CaptPoly& i_captpoly) { cM3dGPla plane; plane = GetTriPla(r28[0]); - i_captpoly.m_callback(i_captpoly, (cBgD_Vtx_t*)&vtx_tbl, 0, 1, 2, &plane); + i_captpoly.m_callback(&i_captpoly, (cBgD_Vtx_t*)&vtx_tbl, 0, 1, 2, &plane); } } } @@ -1588,9 +1588,9 @@ bool dBgWKCol::WallCorrect(dBgS_Acch* pwi) { while ((idx = *(BE(u32)*)(block + idx)) >= 0) { block += idx; shift--; - idx = ((((u32)spBC >> idx) & 1) << 2 | - (((u32)spB8 >> idx) & 1) << 1 | - (((u32)spB4 >> idx) & 1) << 0) * 4; + idx = ((((u32)spBC >> shift) & 1) << 2 | + (((u32)spB8 >> shift) & 1) << 1 | + (((u32)spB4 >> shift) & 1) << 0) * 4; } BE(u16)* p_prismlist = (BE(u16)*)(block + (idx & 0x7FFFFFFF)); @@ -1909,17 +1909,16 @@ bool dBgWKCol::RoofChk(dBgS_RoofChk* param_0) { bool sp0A = false; u32 sp30 = ~m_pkc_head->m_area_y_width_mask; do { - uintptr_t block = (uintptr_t)(BE(u32)*)m_pkc_head->m_block_data; + uintptr_t block = (uintptr_t)(BE(s32)*)m_pkc_head->m_block_data; u32 shift = m_pkc_head->m_block_width_shift; int idx = 4 * (((u32)z >> shift) << m_pkc_head->m_area_xy_blocks_shift | ((u32)y >> shift) << m_pkc_head->m_area_x_blocks_shift | (u32)x >> shift); - - while ((idx = (*(BE(u32)*)(block + (idx & 0x7fffffff)))) >= 0) { + while ((idx = (*(BE(s32)*)(block + (idx & 0x7fffffff)))) >= 0) { block += idx; shift--; idx = (((u32)z >> shift & 1) << 2 | ((u32)y >> shift & 1) << 1 | - ((u32)z >> shift & 1) << 0) + ((u32)x >> shift & 1) << 0) << 2; } diff --git a/src/d/d_cc_d.cpp b/src/d/d_cc_d.cpp index 3c1acd7d5a..6cc5ab63e3 100644 --- a/src/d/d_cc_d.cpp +++ b/src/d/d_cc_d.cpp @@ -4,9 +4,7 @@ #include "f_op/f_op_actor_mng.h" #include "f_pc/f_pc_searcher.h" -#if DEBUG #include "d/d_debug_viewer.h" -#endif void dCcD_GAtTgCoCommonBase::ClrActorInfo() { mApid = -1; @@ -354,8 +352,6 @@ void dCcD_Cps::CalcTgVec() { CalcVec(dest); } -#if DEBUG - void dCcD_Cps::Draw(const GXColor& color) { Mtx auStack_68; Mtx auStack_98; @@ -365,7 +361,7 @@ void dCcD_Cps::Draw(const GXColor& color) { cXyz cStack_d8; CalcVec(&cStack_d8); - cMtx_trans(auStack_98, GetStartP().x, GetStartP().y, GetStartP().z); + cMtx_trans(auStack_98, GetStartP()->x, GetStartP()->y, GetStartP()->z); cM3d_UpMtx(cStack_d8, auStack_c8); cMtx_concat(auStack_98, auStack_c8, auStack_68); cMtx_scale(auStack_98, GetR(), 0.5f * GetLen(), GetR()); @@ -375,12 +371,10 @@ void dCcD_Cps::Draw(const GXColor& color) { cMtx_XrotS(auStack_98, 0x4000); cMtx_concat(auStack_68, auStack_98, auStack_68); dDbVw_drawCylinderMXlu(auStack_68, color, 1); - dDbVw_drawSphereXlu(GetStartP(), GetR(), color, 1); - dDbVw_drawSphereXlu(GetEndP(), GetR(), color, 1); + dDbVw_drawSphereXlu(*GetStartP(), GetR(), color, 1); + dDbVw_drawSphereXlu(*GetEndP(), GetR(), color, 1); } -#endif - void dCcD_Tri::Set(dCcD_SrcTri const& src) { dCcD_GObjInf::Set(src.mObjInf); cCcD_TriAttr* attr = this; @@ -390,8 +384,6 @@ cCcD_ShapeAttr* dCcD_Tri::GetShapeAttr() { return this; } -#if DEBUG - void dCcD_Tri::Draw(const GXColor& color) { cXyz cStack_34[3]; cStack_34[0] = mA; @@ -400,8 +392,6 @@ void dCcD_Tri::Draw(const GXColor& color) { dDbVw_drawTriangleXlu(cStack_34, color, 1); } -#endif - void dCcD_Cyl::Set(dCcD_SrcCyl const& src) { dCcD_GObjInf::Set(src.mObjInf); cCcD_CylAttr::Set(src.mCylAttr); @@ -433,14 +423,10 @@ void dCcD_Cyl::MoveCTg(cXyz& pos) { SetC(pos); } -#if DEBUG - void dCcD_Cyl::Draw(const GXColor& color) { dDbVw_drawCylinderXlu(*GetCP(), GetR(), GetH(), color, 1); } -#endif - void dCcD_Sph::Set(dCcD_SrcSph const& src) { dCcD_GObjInf::Set(src.mObjInf); cCcD_SphAttr::Set(src.mSphAttr); @@ -464,10 +450,6 @@ cCcD_ShapeAttr* dCcD_Sph::GetShapeAttr() { return this; } -#if DEBUG - void dCcD_Sph::Draw(const GXColor& color) { dDbVw_drawSphereXlu(*GetCP(), GetR(), color, 1); } - -#endif diff --git a/src/d/d_cc_mass_s.cpp b/src/d/d_cc_mass_s.cpp index 3a8ecdc7b2..1bc43a4565 100644 --- a/src/d/d_cc_mass_s.cpp +++ b/src/d/d_cc_mass_s.cpp @@ -10,16 +10,16 @@ #include "d/d_cc_d.h" #include "f_op/f_op_actor.h" -void dCcMassS_Obj::Set(cCcD_Obj* p_obj, u8 priority, dCcMassS_ObjCallback callback) { - mpObj = p_obj; - mPriority = priority; - mpCallback = callback; +void dCcMassS_Obj::Set(cCcD_Obj* pobj, u8 priority, dCcMassS_ObjCallback callback) { + mpObj = pobj; + mPriority = (u8)priority; + mpAreaCheckFunc = callback; } void dCcMassS_Obj::Clear() { mpObj = NULL; mPriority = 5; - mpCallback = NULL; + mpAreaCheckFunc = NULL; mDivideInfo.Set(0, 0, 0); } @@ -53,24 +53,30 @@ void dCcMassS_Mng::Ct() { void dCcMassS_Mng::SetAttr(f32 radius, f32 height, u8 param_2, u8 param_3) { mCylAttr.SetR(radius); mCylAttr.SetH(height); - field_0x200 = param_2; - field_0x201 = param_3; + field_0x200 = (u8)param_2; + field_0x201 = (u8)param_3; } void dCcMassS_Mng::Prepare() { cM3dGAab aab; aab.ClearForMinMax(); - for (dCcMassS_Obj* pObj = mMassObjs; pObj < mMassObjs + mMassObjCount; ++pObj) { - cCcD_ShapeAttr* objShape = pObj->GetObj()->GetShapeAttr(); - objShape->CalcAabBox(); - aab.SetMinMax(objShape->GetWorkAab()); + for (dCcMassS_Obj* i = mMassObjs; i < mMassObjs + mMassObjCount; ++i) { + cCcD_Obj* pobj = i->GetObj(); + JUT_ASSERT(123, pobj != NULL); + + cCcD_ShapeAttr* shape = pobj->GetShapeAttr(); + shape->CalcAabBox(); + aab.SetMinMax(shape->GetWorkAab()); } - for (dCcMassS_Obj* pObj = mMassAreas; pObj < mMassAreas + mMassAreaCount; ++pObj) { - cCcD_ShapeAttr* objShape = pObj->GetObj()->GetShapeAttr(); - objShape->CalcAabBox(); - aab.SetMinMax(objShape->GetWorkAab()); + for (dCcMassS_Obj* i = mMassAreas; i < mMassAreas + mMassAreaCount; ++i) { + cCcD_Obj* parea = i->GetObj(); + JUT_ASSERT(135, parea != NULL); + + cCcD_ShapeAttr* shape = parea->GetShapeAttr(); + shape->CalcAabBox(); + aab.SetMinMax(shape->GetWorkAab()); } if (field_0x202 & 1) { @@ -79,16 +85,23 @@ void dCcMassS_Mng::Prepare() { } mDivideArea.SetArea(aab); - for (dCcMassS_Obj* pObj = mMassObjs; pObj < mMassObjs + mMassObjCount; ++pObj) { - cCcD_ShapeAttr* objShape = pObj->GetObj()->GetShapeAttr(); - cCcD_DivideInfo* divideInfo = &pObj->GetDivideInfo(); - mDivideArea.CalcDivideInfo(divideInfo, objShape->GetWorkAab(), 0); + + for (dCcMassS_Obj* i = mMassObjs; i < mMassObjs + mMassObjCount; ++i) { + cCcD_Obj* pobj = i->GetObj(); + JUT_ASSERT(155, pobj != NULL); + + cCcD_ShapeAttr* shape = pobj->GetShapeAttr(); + cCcD_DivideInfo* pdivinfo = i->GetPDivideInfo(); + mDivideArea.CalcDivideInfo(pdivinfo, shape->GetWorkAab(), 0); } - for (dCcMassS_Obj* pObj = mMassAreas; pObj < mMassAreas + mMassAreaCount; ++pObj) { - cCcD_ShapeAttr* objShape = pObj->GetObj()->GetShapeAttr(); - cCcD_DivideInfo* divideInfo = &pObj->GetDivideInfo(); - mDivideArea.CalcDivideInfo(divideInfo, objShape->GetWorkAab(), 0); + for (dCcMassS_Obj* i = mMassAreas; i < mMassAreas + mMassAreaCount; ++i) { + cCcD_Obj* parea = i->GetObj(); + JUT_ASSERT(166, parea != NULL); + + cCcD_ShapeAttr* shape = parea->GetShapeAttr(); + cCcD_DivideInfo* pdivinfo = i->GetPDivideInfo(); + mDivideArea.CalcDivideInfo(pdivinfo, shape->GetWorkAab(), 0); } if (field_0x202 & 1) { @@ -106,32 +119,36 @@ void dCcMassS_Mng::Prepare() { mCamBottomDist = G_CM3D_F_INF; } -u32 dCcMassS_Mng::Chk(cXyz* p_xyz, fopAc_ac_c** p_actor, dCcMassS_HitInf* p_hitInf) { +u32 dCcMassS_Mng::Chk(cXyz* ppos, fopAc_ac_c** ppactor, dCcMassS_HitInf* phitinf) { cCcD_DivideInfo divideInfo; u32 flagsMaybe = 0; - *p_actor = NULL; + *ppactor = NULL; - mCylAttr.SetC(*p_xyz); + mCylAttr.SetC(*ppos); mCylAttr.CalcAabBox(); mDivideArea.CalcDivideInfoOverArea(÷Info, mCylAttr.GetWorkAab()); - p_hitInf->ClearPointer(); + phitinf->ClearPointer(); if (field_0x200 & 8) { for (dCcMassS_Obj* massObj = mMassAreas; massObj < mMassAreas + mMassAreaCount; ++massObj) { - if (massObj->GetDivideInfo().Chk(divideInfo)) { - cCcD_Obj* obj = massObj->GetObj(); - cCcD_ShapeAttr* objShape = obj->GetShapeAttr(); + cCcD_DivideInfo* pdivinfo = massObj->GetPDivideInfo(); + if (pdivinfo->Chk(divideInfo)) { + cCcD_Obj* pobj = massObj->GetObj(); + JUT_ASSERT(226, pobj != NULL); + + cCcD_ShapeAttr* shape = pobj->GetShapeAttr(); f32 f; - if (obj->ChkCoSet() && mCylAttr.CrossCo(*objShape, &f)) { + if (pobj->ChkCoSet() && mCylAttr.CrossCo(*shape, &f)) { flagsMaybe |= 4; - *p_actor = obj->GetStts()->GetAc(); - if (p_hitInf != NULL) { - p_hitInf->SetAreaHitObj(obj); + *ppactor = pobj->GetStts()->GetActor(); + if (phitinf != NULL) { + phitinf->SetAreaHitObj(pobj); } - if (massObj->GetCallback() != NULL) { - massObj->GetCallback()(obj->GetStts()->GetAc(), p_xyz, field_0x201); + if (massObj->GetAreaCheckFunc() != NULL) { + dCcMassS_ObjCallback sp1C = massObj->GetAreaCheckFunc(); + sp1C(pobj->GetStts()->GetActor(), ppos, field_0x201); } } } @@ -139,42 +156,46 @@ u32 dCcMassS_Mng::Chk(cXyz* p_xyz, fopAc_ac_c** p_actor, dCcMassS_HitInf* p_hitI } for (dCcMassS_Obj* massObj = mMassObjs; massObj < mMassObjs + mMassObjCount; ++massObj) { - if (massObj->GetDivideInfo().Chk(divideInfo)) { - cCcD_Obj* obj = massObj->GetObj(); - dCcD_GObjInf* gobjInf = (dCcD_GObjInf*)obj->GetGObjInf(); - cCcD_ShapeAttr* objShape = obj->GetShapeAttr(); + cCcD_DivideInfo* pdivinfo = massObj->GetPDivideInfo(); + if (pdivinfo->Chk(divideInfo)) { cXyz unusedVec; - if (obj->ChkAtSet() && !gobjInf->ChkAtNoMass() && - mCylAttr.CrossAtTg(*objShape, &unusedVec) && (field_0x200 & 1)) + cCcD_Obj* pobj = massObj->GetObj(); + dCcD_GObjInf* gobjInf = (dCcD_GObjInf*)pobj->GetGObjInf(); + JUT_ASSERT(266, pobj != NULL); + + cCcD_ShapeAttr* shape = pobj->GetShapeAttr(); + + if (pobj->ChkAtSet() && !gobjInf->ChkAtNoMass() && + mCylAttr.CrossAtTg(*shape, &unusedVec) && (field_0x200 & 1)) { flagsMaybe |= 1; - *p_actor = obj->GetStts()->GetAc(); - if (p_hitInf != NULL) { - p_hitInf->SetAtHitObj(obj); + *ppactor = pobj->GetStts()->GetActor(); + if (phitinf != NULL) { + phitinf->SetAtHitObj(pobj); } } f32 f; - if (obj->ChkCoSet() && mCylAttr.CrossCo(*objShape, &f) && (field_0x200 & 2)) { + if (pobj->ChkCoSet() && mCylAttr.CrossCo(*shape, &f) && (field_0x200 & 2)) { flagsMaybe |= 2; - *p_actor = obj->GetStts()->GetAc(); + *ppactor = pobj->GetStts()->GetActor(); if (field_0x200 & 0x10) { - Vec vec; - VECSubtract(&(*p_actor)->current.pos, p_xyz, &vec); + cXyz vec; + PSVECSubtract(&(*ppactor)->current.pos, ppos, &vec); vec.y = 0; - f32 vecMag = VECMag(&vec); + f32 vecMag = PSVECMag(&vec); if (cM3d_IsZero(vecMag)) { vec.x = 1; } else { - VECScale(&vec, &vec, f / vecMag); + PSVECScale(&vec, &vec, f / vecMag); } - obj->GetStts()->PlusCcMove(vec.x, vec.y, vec.z); + pobj->GetStts()->PlusCcMove(vec.x, vec.y, vec.z); } - if (p_hitInf != NULL) { - p_hitInf->SetCoHitObj(obj); - p_hitInf->SetCoHitLen(f); + if (phitinf != NULL) { + phitinf->SetCoHitObj(pobj); + phitinf->SetCoHitLen(f); } } } @@ -182,18 +203,18 @@ u32 dCcMassS_Mng::Chk(cXyz* p_xyz, fopAc_ac_c** p_actor, dCcMassS_HitInf* p_hitI f32 f; if ((field_0x202 & 1) && mDivideInfo.Chk(divideInfo) && mCylAttr.CrossCo(mCpsAttr, &f)) { - mResultCam |= 1; - mResultCam |= 1 << (field_0x201 + 1); + mResultCam |= (u8)1; + mResultCam |= (1 << (field_0x201 + 1)); if ((mResultCam & 2) || (mResultCam & 8)) { - cXyz tmpVec; - f32 plusH = p_xyz->y + mCylAttr.GetH(); - tmpVec.x = p_xyz->x; + Vec tmpVec; + f32 plusH = ppos->y + mCylAttr.GetH(); + tmpVec.x = ppos->x; tmpVec.y = plusH; - tmpVec.z = p_xyz->z; + tmpVec.z = ppos->z; if (mCamTopPos.y < (20.0f + plusH)) { - f32 newCamTopDist = VECSquareDistance(&tmpVec, &mCpsAttr.GetStartP()); + f32 newCamTopDist = PSVECSquareDistance(&tmpVec, mCpsAttr.GetStartP()); if (mCamTopDist > newCamTopDist) { mCamTopDist = newCamTopDist; mCamTopPos = tmpVec; @@ -201,7 +222,7 @@ u32 dCcMassS_Mng::Chk(cXyz* p_xyz, fopAc_ac_c** p_actor, dCcMassS_HitInf* p_hitI } if (mCamBottomPos.y < (20.0f + plusH)) { - f32 newCamBottomDist = VECSquareDistance(&tmpVec, &mCpsAttr.GetEndP()); + f32 newCamBottomDist = PSVECSquareDistance(&tmpVec, mCpsAttr.GetEndP()); if (mCamBottomDist > newCamBottomDist) { mCamBottomDist = newCamBottomDist; mCamBottomPos = tmpVec; @@ -231,24 +252,24 @@ void dCcMassS_Mng::Clear() { field_0x201 = 4; } -void dCcMassS_Mng::Set(cCcD_Obj* p_obj, u8 priority) { +void dCcMassS_Mng::Set(cCcD_Obj* pobj, u8 priority) { if (mMassObjCount >= ARRAY_SIZE(mMassObjs)) { for (int i = 0; i < ARRAY_SIZE(mMassObjs); ++i) { int prevPrio = mMassObjs[i].GetPriority(); if (prevPrio > priority || (prevPrio == priority && cM_rndF(1.0f) < 0.5f)) { - mMassObjs[i].Set(p_obj, priority, NULL); + mMassObjs[i].Set(pobj, priority, NULL); break; } } } else { - mMassObjs[mMassObjCount].Set(p_obj, priority, NULL); + mMassObjs[mMassObjCount].Set(pobj, priority, NULL); mMassObjCount++; } } -void dCcMassS_Mng::SetCam(cM3dGCps const& cps) { +void dCcMassS_Mng::SetCam(const cM3dGCps& cps) { mCpsAttr.SetCps(cps); - field_0x202 |= 1; + field_0x202 |= (u8)1; mResultCam = 0; } @@ -256,6 +277,6 @@ u32 dCcMassS_Mng::GetResultCam() const { return mResultCam; } -void dCcMassS_Mng::GetCamTopPos(Vec* p_out) { - *p_out = mCamTopPos; +void dCcMassS_Mng::GetCamTopPos(Vec* ppos) { + *ppos = mCamTopPos; } diff --git a/src/d/d_cc_s.cpp b/src/d/d_cc_s.cpp index ccb8501542..ab71f08aaa 100644 --- a/src/d/d_cc_s.cpp +++ b/src/d/d_cc_s.cpp @@ -10,13 +10,119 @@ #include "d/d_jnt_col.h" #include "f_op/f_op_actor_mng.h" +#include "dusk/imgui/ImGuiConsole.hpp" + +class dCcS_HIO : public JORReflexible { +public: + enum flags_e { + FLAG_CAM_COL_DISP_e = 0x1, + FLAG_AT_ON_e = 0x2, + FLAG_TG_ON_e = 0x4, + FLAG_CO_ON_e = 0x8, + FLAG_DRAW_CLEAR_OFF_e = 0x10, + FLAG_COUNTER_e = 0x20, + FLAG_MOVE_OFF_e = 0x40, + FLAG_MASS_OFF_e = 0x80, + FLAG_MOVE_TIMER_e = 0x100, + FLAG_MASS_TIMER_e = 0x200, + FLAG_MASS_COUNTER_e = 0x400, + FLAG_ALL_MASS_TIMER_e = 0x800, + + }; + + dCcS_HIO() { + m_flags = 0; + m_shield_range = 0x4000; + } + + virtual ~dCcS_HIO(); + + void genMessage(JORMContext*); + + BOOL ChkMoveTimer() { return m_flags & FLAG_MOVE_TIMER_e; } + BOOL ChkMoveOff() { return m_flags & FLAG_MOVE_OFF_e; } + BOOL ChkAllMassTimer() { return m_flags & FLAG_ALL_MASS_TIMER_e; } + BOOL ChkDrawClearOff() { return m_flags & FLAG_DRAW_CLEAR_OFF_e; } + BOOL ChkCounter() { return m_flags & FLAG_COUNTER_e; } + BOOL ChkCamColDisp() { return m_flags & FLAG_CAM_COL_DISP_e; } + BOOL CheckCoOn() { return m_flags & FLAG_CO_ON_e; } + BOOL CheckTgOn() { return m_flags & FLAG_TG_ON_e; } + BOOL CheckAtOn() { return m_flags & FLAG_AT_ON_e; } + BOOL ChkMassCounter() { return m_flags & FLAG_MASS_COUNTER_e; } + BOOL ChkMassOff() { return m_flags & FLAG_MASS_OFF_e; } + BOOL ChkMassTimer() { return m_flags & FLAG_MASS_TIMER_e; } + + /* 0x4 */ s8 id; + /* 0x6 */ u16 m_flags; + /* 0x8 */ s16 m_shield_range; +}; + + +dCcS_HIO::~dCcS_HIO() {} + +void dCcS_HIO::genMessage(JORMContext* mctx) { +#if DEBUG + mctx->genLabel("処理関係 -----", 0); + mctx->genCheckBox("処理Off", &m_flags, 0x40); + mctx->genCheckBox("多数ヒットチェック(草木花)Off", &m_flags, 0x80); + mctx->genCheckBox("多数ヒット 1回時間", &m_flags, 0x200); + mctx->genCheckBox("多数ヒット 通しの処理時間(->terminal)", &m_flags, 0x800); + mctx->genCheckBox("多数ヒット チェックカウンタ", &m_flags, 0x400); + mctx->genCheckBox("処理時間(->terminal)", &m_flags, 0x100); + + mctx->genLabel("描画関係 -----", 0); + mctx->genCheckBox("At 描画", &m_flags, 2); + mctx->genCheckBox("Tg 描画", &m_flags, 4); + mctx->genCheckBox("Co 描画", &m_flags, 8); + mctx->genCheckBox("カメラCo描画", &m_flags, 1); + mctx->genCheckBox("クリアOff", &m_flags, 0x10); + + mctx->genLabel("情報(->terminal) -----", 0); + mctx->genCheckBox("個数", &m_flags, 0x20); + + mctx->genLabel("特殊-----", 0); + mctx->genSlider("盾範囲(max=360度)", &m_shield_range, 0, 0x7FFF); +#endif +} + +#if DEBUG +static OSStopwatch s_move_timer; +static OSStopwatch s_mass_timer; + +int g_mass_counter; +#endif + +static dCcS_HIO s_Hio; + void dCcS::Ct() { cCcS::Ct(); + + #if DEBUG + m_is_mass_all_timer = 0; + s_Hio.id = mDoHIO_CREATE_CHILD("zelda コリジョンシステム", &s_Hio); + + OSInitStopwatch(&s_move_timer, "CollsionCheckMove"); + OSResetStopwatch(&s_move_timer); + OSInitStopwatch(&s_mass_timer, "MassCheck"); + OSResetStopwatch(&s_mass_timer); + + g_mass_counter = 0; + #endif + mMass_Mng.Ct(); + + #if DEBUG + dJntCol_setDebugHIO(); + #endif } void dCcS::Dt() { cCcS::Dt(); + + #if DEBUG + mDoHIO_DELETE_CHILD(s_Hio.id); + dJntCol_deleteDebugHIO(); + #endif } bool dCcS::ChkShieldFrontRange(cCcD_Obj* i_atObj, cCcD_Obj* i_tgObj, int param_2, @@ -110,11 +216,11 @@ void dCcS::CalcTgPlusDmg(cCcD_Obj* i_atObj, cCcD_Obj* i_tgObj, cCcD_Stts* i_atSt bool dCcS::ChkAtTgHitAfterCross(bool i_setAt, bool i_setTg, cCcD_GObjInf const* i_atObjInf, cCcD_GObjInf const* i_tgObjInf, cCcD_Stts* i_atStts, cCcD_Stts* i_tgStts, cCcD_GStts* i_atGStts, cCcD_GStts* i_tgGStts) { - dCcD_GObjInf* atObjInf = (dCcD_GObjInf*)i_atObjInf; - dCcD_GObjInf* tgObjInf = (dCcD_GObjInf*)i_tgObjInf; - fpc_ProcID tgApid = i_atStts->GetApid(); fpc_ProcID atApid = i_tgStts->GetApid(); + + dCcD_GObjInf* atObjInf = (dCcD_GObjInf*)i_atObjInf; + dCcD_GObjInf* tgObjInf = (dCcD_GObjInf*)i_tgObjInf; if (i_setAt) { static_cast(i_atGStts)->SetAtApid(atApid); @@ -269,9 +375,10 @@ void dCcS::SetPosCorrect(cCcD_Obj* i_co1Obj, cXyz* i_pos1, cCcD_Obj* i_co2Obj, c int co1_rank = GetRank(i_co1Obj->GetStts()->GetWeightUc()); int co2_rank = GetRank(i_co2Obj->GetStts()->GetWeightUc()); u8 rank = rank_tbl[co1_rank][co2_rank]; + u8 var_r22 = 100 - rank; f32 fvar1 = rank * 0.01f; - f32 fvar2 = (u8)(100 - rank) * 0.01f; + f32 fvar2 = var_r22 * 0.01f; cXyz co1_move; cXyz co2_move; @@ -279,8 +386,8 @@ void dCcS::SetPosCorrect(cCcD_Obj* i_co1Obj, cXyz* i_pos1, cCcD_Obj* i_co2Obj, c f32 fvar14; if (bvar2) { - VECSubtract(i_pos2, i_pos1, &local_c8); - fvar14 = VECMag(&local_c8); + PSVECSubtract(i_pos2, i_pos1, &local_c8); + fvar14 = PSVECMag(&local_c8); } else { local_c8.x = i_pos2->x - i_pos1->x; local_c8.y = 0.0f; @@ -290,14 +397,15 @@ void dCcS::SetPosCorrect(cCcD_Obj* i_co1Obj, cXyz* i_pos1, cCcD_Obj* i_co2Obj, c if (!cM3d_IsZero(fvar14)) { if (bvar2) { - VECScale(&local_c8, &local_c8, i_cross_len / fvar14); + f32 var_f26 = i_cross_len / fvar14; + PSVECScale(&local_c8, &local_c8, var_f26); fvar1 *= -1.0f; - VECScale(&local_c8, &co1_move, fvar1); - VECScale(&local_c8, &co2_move, fvar2); + PSVECScale(&local_c8, &co1_move, fvar1); + PSVECScale(&local_c8, &co2_move, fvar2); } else { - fvar14 = i_cross_len / fvar14; - local_c8.x *= fvar14; - local_c8.z *= fvar14; + f32 var_f27 = i_cross_len / fvar14; + local_c8.x *= var_f27; + local_c8.z *= var_f27; co1_move.x = -local_c8.x * fvar1; co1_move.y = 0.0f; @@ -332,27 +440,25 @@ void dCcS::CalcParticleAngle(dCcD_GObjInf* i_atObjInf, cCcD_Stts* i_atStts, cCcD csXyz* o_angle) { cXyz vec(*i_atObjInf->GetAtVecP()); - if (cM3d_IsZero(VECMag(&vec))) { + if (cM3d_IsZero(PSVECMag(&vec))) { fopAc_ac_c* atActor = i_atStts->GetActor(); fopAc_ac_c* tgActor = i_tgStts->GetActor(); if (atActor == NULL || tgActor == NULL) { - vec.z = 0.0f; - vec.x = 0.0f; + vec.x = vec.z = 0.0f; vec.y = -1.0f; } else { - VECSubtract(&tgActor->current.pos, &atActor->current.pos, &vec); + PSVECSubtract(&tgActor->current.pos, &atActor->current.pos, &vec); - if (cM3d_IsZero(VECMag(&vec))) { - vec.z = 0.0f; - vec.x = 0.0f; + if (cM3d_IsZero(PSVECMag(&vec))) { + vec.x = vec.z = 0.0f; vec.y = -1.0f; } else { - VECNormalize(&vec, &vec); + PSVECNormalize(&vec, &vec); } } } else { - VECNormalize(&vec, &vec); + PSVECNormalize(&vec, &vec); } cM3d_CalcVecZAngle(vec, o_angle); @@ -441,9 +547,9 @@ void dCcS::SetAtTgGObjInf(bool i_setAt, bool i_setTg, cCcD_Obj* i_atObj, cCcD_Ob atObjInf->SetAtHitApid(i_tgStts->GetApid()); - if (chk_shield || tgObjInf->GetTgHitMark() == 8 && atObjInf->GetAtMtrl() != dCcD_MTRL_ICE && + if (chk_shield || (tgObjInf->GetTgHitMark() == 8 && atObjInf->GetAtMtrl() != dCcD_MTRL_ICE && (atObjInf->GetAtSpl() == 0 || atObjInf->GetAtSpl() == 5 || - atObjInf->GetAtSpl() == 8)) + atObjInf->GetAtSpl() == 8))) { atObjInf->OnAtShieldHit(); } @@ -466,7 +572,8 @@ void dCcS::SetAtTgGObjInf(bool i_setAt, bool i_setTg, cCcD_Obj* i_atObj, cCcD_Ob if (chk_shield) { tgObjInf->OnTgShieldHit(); } else { - i_tgStts->PlusDmg(i_atObj->GetAtAtp()); + int atp = i_atObj->GetAtAtp(); + i_tgStts->PlusDmg(atp); } if (at_gstts->ChkNoActor()) { @@ -523,9 +630,10 @@ bool dCcS::ChkCamera(cXyz& param_0, cXyz& param_1, f32 param_2, fopAc_ac_c* para dCcD_GObjInf* obj = (dCcD_GObjInf*)(*i)->GetGObjInf(); if (obj == NULL || !obj->ChkCoNoCamHit()) { - cCcD_ShapeAttr* shapeAttr = (*i)->GetShapeAttr(); + cCcD_ShapeAttr* pco_sa = (*i)->GetShapeAttr(); + JUT_ASSERT(1058, pco_sa != NULL); - if (sp48.CrossCo(*shapeAttr, &sp14)) { + if (sp48.CrossCo(*pco_sa, &sp14)) { return true; } } @@ -604,10 +712,11 @@ bool dCcS::chkCameraPoint(cXyz const& param_0, cCcD_ShapeAttr::Shape* param_1, f dCcD_GObjInf* obj = (dCcD_GObjInf*)(*i)->GetGObjInf(); if (obj == NULL || !obj->ChkCoNoCamHit()) { - cCcD_ShapeAttr* shapeAttr = (*i)->GetShapeAttr(); + cCcD_ShapeAttr* pco_sa = (*i)->GetShapeAttr(); + JUT_ASSERT(1196, pco_sa != NULL); - if (sp48.CrossCo(*shapeAttr, &sp14)) { - shapeAttr->getShapeAccess(param_1); + if (sp48.CrossCo(*pco_sa, &sp14)) { + pco_sa->getShapeAccess(param_1); if (param_1->_0 != 2) { return true; @@ -626,12 +735,134 @@ void dCcS::MoveAfterCheck() {} void dCcS::DrawAfter() {} void dCcS::Move() { + #if DEBUG + if (s_Hio.ChkAllMassTimer()) { + OnMassAllTimer(); + } else { + OffMassAllTimer(); + } + + if (s_Hio.ChkMoveOff()) { + return; + } + + if (s_Hio.ChkMoveTimer()) { + OSStartStopwatch(&s_move_timer); + } + #endif + cCcS::Move(); + + #if DEBUG + if (s_Hio.ChkMoveTimer()) { + OSStopStopwatch(&s_move_timer); + OSDumpStopwatch(&s_move_timer); + } + #endif } void dCcS::Draw() { + #if DEBUG + if (s_Hio.ChkMassCounter()) { + OS_REPORT("Mass Counter %d\n", g_mass_counter); + g_mass_counter = 0; + } + #endif + +#if TARGET_PC +#define IMGUI_TOGGLE_HIO_FLAG(status, flag) \ + if (status) { \ + s_Hio.m_flags |= flag; \ + } else { \ + s_Hio.m_flags &= ~flag; \ + } + + dusk::ImGuiMenuTools::CollisionViewSettings collisionViewSettings = dusk::g_imguiConsole.getCollisionViewSettings(); + IMGUI_TOGGLE_HIO_FLAG(collisionViewSettings.m_enableAtView, dCcS_HIO::FLAG_AT_ON_e); + IMGUI_TOGGLE_HIO_FLAG(collisionViewSettings.m_enableTgView, dCcS_HIO::FLAG_TG_ON_e); + IMGUI_TOGGLE_HIO_FLAG(collisionViewSettings.m_enableCoView, dCcS_HIO::FLAG_CO_ON_e); + + f32 view_opacity = 255 * (collisionViewSettings.m_colliderViewOpacity / 100.0f); +#endif + + if (s_Hio.CheckAtOn()) { + for (int i = 0; i < field_0x280c; i++) { + if (mpObjAt[i] != NULL && mpObjAt[i]->ChkAtSet()) { + dCcD_GObjInf* gobj = (dCcD_GObjInf*)mpObjAt[i]->GetGObjInf(); + if (gobj->ChkAtHit()) { + GXColor color = {0xFF, 0, 0, 0xB4}; + color.a = view_opacity; + mpObjAt[i]->Draw(color); + } else { + GXColor color = {0xFF, 0, 0, 0x50}; + color.a = view_opacity; + mpObjAt[i]->Draw(color); + } + } + } + } + + if (s_Hio.CheckTgOn()) { + for (int i = 0; i < field_0x280e; i++) { + if (mpObjTg[i] != NULL && mpObjTg[i]->ChkTgSet()) { + dCcD_GObjInf* gobj = (dCcD_GObjInf*)mpObjTg[i]->GetGObjInf(); + if (gobj->ChkTgHit()) { + GXColor color = {0, 0xFF, 0, 0xB4}; + color.a = view_opacity; + mpObjTg[i]->Draw(color); + } else { + GXColor color = {0, 0xFF, 0, 0x50}; + color.a = view_opacity; + mpObjTg[i]->Draw(color); + } + } + } + } + + if (s_Hio.CheckCoOn()) { + for (int i = 0; i < field_0x2810; i++) { + if (mpObjCo[i] != NULL && mpObjCo[i]->ChkCoSet()) { + dCcD_GObjInf* gobj = (dCcD_GObjInf*)mpObjCo[i]->GetGObjInf(); + if (gobj->ChkCoHit()) { + GXColor color = {0xFF, 0xFF, 0xFF, 0xB4}; + color.a = view_opacity; + mpObjCo[i]->Draw(color); + } else { + GXColor color = {0xFF, 0xFF, 0xFF, 0x50}; + color.a = view_opacity; + mpObjCo[i]->Draw(color); + } + } + } + } + + if (s_Hio.ChkCamColDisp()) { + for (int i = 0; i < field_0x2810; i++) { + if (mpObjCo[i] != NULL && mpObjCo[i]->ChkCoSet()) { + dCcD_GObjInf* gobj = (dCcD_GObjInf*)mpObjCo[i]->GetGObjInf(); + if (!gobj->ChkCoNoCamHit()) { + GXColor color = {0xFF, 0xFF, 0, 0x50}; + mpObjCo[i]->Draw(color); + } + } + } + } + + #if DEBUG + if (s_Hio.ChkCounter()) { + OS_REPORT("At:%d,Tg:%d,Co:%d\n", field_0x280c, field_0x280e, field_0x2810); + } + #endif + DrawAfter(); - DrawClear(); + + #if DEBUG + if (!s_Hio.ChkDrawClearOff()) + #endif + { + DrawClear(); + } + mMass_Mng.Clear(); } @@ -657,7 +888,10 @@ BOOL dCcS::ChkAtTgMtrlHit(u8 i_atMtrl, u8 i_tgMtrl) { } bool dCcS::ChkNoHitGAtTg(cCcD_GObjInf const* i_atObjInf, cCcD_GObjInf const* i_tgObjInf, - cCcD_GStts*, cCcD_GStts*) { + cCcD_GStts* i_atStts, cCcD_GStts* i_tgStts) { + UNUSED(i_atStts); + UNUSED(i_tgStts); + dCcD_GObjInf* atObjInf = (dCcD_GObjInf*)i_atObjInf; dCcD_GObjInf* tgObjInf = (dCcD_GObjInf*)i_tgObjInf; diff --git a/src/d/d_com_inf_game.cpp b/src/d/d_com_inf_game.cpp index 4e0f8da165..8da33212cf 100644 --- a/src/d/d_com_inf_game.cpp +++ b/src/d/d_com_inf_game.cpp @@ -2660,7 +2660,11 @@ const char* dComIfGs_getWarpStageName() { return dComIfGs_getLastWarpMarkStageName(); } +#if TARGET_PC +cXyz dComIfGs_getWarpPlayerPos() { +#else cXyz& dComIfGs_getWarpPlayerPos() { +#endif return dComIfGs_getLastWarpMarkPlayerPos(); } diff --git a/src/d/d_debug_camera.cpp b/src/d/d_debug_camera.cpp index d01f77a298..131a2c05ae 100644 --- a/src/d/d_debug_camera.cpp +++ b/src/d/d_debug_camera.cpp @@ -1719,7 +1719,7 @@ JUtility::TColor get_color(JUtility::TColor color) { JUtility::TColor(0x80, 0x80, 0xFF, 0xFF), }; - (void)(u32)color; + UNUSED((u32)color); int var_r30 = 1; if (var_r30 && (u32)color < 9) { diff --git a/src/d/d_demo.cpp b/src/d/d_demo.cpp index 370da262a5..d6425848d3 100644 --- a/src/d/d_demo.cpp +++ b/src/d/d_demo.cpp @@ -14,6 +14,24 @@ s16 dDemo_c::m_branchId = -1; namespace { +class jstudio_tAdaptor_message : public JStudio::TAdaptor_message { +public: + typedef JStudio::TObject_message ObjectType; + + jstudio_tAdaptor_message() {} + + virtual ~jstudio_tAdaptor_message(); + virtual void adaptor_do_MESSAGE(JStudio::data::TEOperationData, const void*, u32); +}; + +class jstudio_tCreateObject_message : public JStudio::TCreateObject { +public: + jstudio_tCreateObject_message() {} + + virtual ~jstudio_tCreateObject_message(); + virtual bool create(JStudio::TObject**, const JStudio::stb::data::TParse_TBlock_object&); +}; + jstudio_tAdaptor_message::~jstudio_tAdaptor_message() {} void jstudio_tAdaptor_message::adaptor_do_MESSAGE(JStudio::data::TEOperationData iType, @@ -168,7 +186,7 @@ JStudio_JAudio2::TCreateObject* dDemo_c::m_audio; dDemo_particle_c* dDemo_c::m_particle; -jstudio_tCreateObject_message* dDemo_c::m_message; +JStudio::TCreateObject* dDemo_c::m_message; JStudio::TFactory* dDemo_c::m_factory; diff --git a/src/d/d_drawlist.cpp b/src/d/d_drawlist.cpp index fefbd4e885..ee6b01f9fd 100644 --- a/src/d/d_drawlist.cpp +++ b/src/d/d_drawlist.cpp @@ -1853,7 +1853,7 @@ int dDlst_list_c::set(dDlst_base_c**& p_start, dDlst_base_c**& p_end, dDlst_base return 0; } *p_start = p_newDlst; - *p_start++; + UNUSED(*p_start++); return 1; } diff --git a/src/d/d_ev_camera.cpp b/src/d/d_ev_camera.cpp index 6be0bf991e..442c8cc4af 100644 --- a/src/d/d_ev_camera.cpp +++ b/src/d/d_ev_camera.cpp @@ -2167,7 +2167,7 @@ bool dCamera_c::gameOverEvCamera() { mViewCache.mEye = sp230; gover_p->field_0x0++; mViewCache.mFovy = 75.0f; - bVar9 = 75.0f; + bVar9 = true; } // fallthrough intentional. case 4: { diff --git a/src/d/d_jnt_col.cpp b/src/d/d_jnt_col.cpp index 0404225b3c..b88a298250 100644 --- a/src/d/d_jnt_col.cpp +++ b/src/d/d_jnt_col.cpp @@ -376,8 +376,8 @@ int dJntCol_c::searchNearPos(cM3dGLin const* param_1, cXyz const* param_2, cXyz* mDoMtx_stack_c::YrotM(cM_atan2s(-sp1AC.x, sp1AC.z)); mDoMtx_stack_c::transM(-sp188.x, -sp188.y, -sp188.z); mDoMtx_stack_c::multVec(&sp17C, &sp194); - mDoMtx_stack_c::multVec(¶m_1->GetStartP(), &sp170); - mDoMtx_stack_c::multVec(¶m_1->GetEndP(), &sp164); + mDoMtx_stack_c::multVec(param_1->GetStartP(), &sp170); + mDoMtx_stack_c::multVec(param_1->GetEndP(), &sp164); sp1C4.SetStartEnd(sp170, sp164); sp1C = 1; } else { diff --git a/src/d/d_kankyo.cpp b/src/d/d_kankyo.cpp index 8c6d3215ea..a74ca3c9db 100644 --- a/src/d/d_kankyo.cpp +++ b/src/d/d_kankyo.cpp @@ -10490,7 +10490,7 @@ BOOL dKy_camera_water_in_status_check() { u8 dKy_pol_efftype_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10520,7 +10520,7 @@ u8 dKy_pol_efftype_get(const cBgS_PolyInfo* polyinfo_p) { u8 dKy_pol_efftype2_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10550,7 +10550,7 @@ u8 dKy_pol_efftype2_get(const cBgS_PolyInfo* polyinfo_p) { u8 dKy_pol_sound_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0; } @@ -10581,7 +10581,7 @@ u8 dKy_pol_sound_get(const cBgS_PolyInfo* polyinfo_p) { u8 dKy_pol_argument_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0; } @@ -10606,7 +10606,7 @@ u8 dKy_pol_argument_get(const cBgS_PolyInfo* polyinfo_p) { u8 dKy_pol_eff_prim_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); u8 eff_id = 0; - if (polyinfo_p == NULL || out_color_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || out_color_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10643,7 +10643,7 @@ u8 dKy_pol_eff_prim_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) { u8 dKy_pol_eff_env_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); u8 eff_id = 0; - if (polyinfo_p == NULL || out_color_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || out_color_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10680,7 +10680,7 @@ u8 dKy_pol_eff_env_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) { u8 dKy_pol_eff2_prim_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); u8 eff_id = 0; - if (polyinfo_p == NULL || out_color_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || out_color_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10717,7 +10717,7 @@ u8 dKy_pol_eff2_prim_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) u8 dKy_pol_eff2_env_get(const cBgS_PolyInfo* polyinfo_p, GXColor* out_color_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); u8 eff_id = 0; - if (polyinfo_p == NULL || out_color_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || out_color_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10755,7 +10755,7 @@ u8 dKy_pol_eff_alpha_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); int z0; u8 eff_id = 0; - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10792,7 +10792,7 @@ f32 dKy_pol_eff_ratio_get(const cBgS_PolyInfo* polyinfo_p) { u8 eff_id; f32 ratio = 0.0f; - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0.0f; } @@ -10829,7 +10829,7 @@ u8 dKy_pol_eff2_alpha_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); int z0; u8 retval = 0; - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0xFF; } @@ -10865,7 +10865,7 @@ f32 dKy_pol_eff2_ratio_get(const cBgS_PolyInfo* polyinfo_p) { dScnKy_env_light_c* kankyo = dKy_getEnvlight(); f32 ratio = 0.0f; - if (polyinfo_p == NULL || &dComIfG_Bgsp() == NULL) { + if (polyinfo_p == NULL || IS_REF_NULL(dComIfG_Bgsp())) { return 0.0f; } diff --git a/src/d/d_lib.cpp b/src/d/d_lib.cpp index 8f3597a55b..34c626ea75 100644 --- a/src/d/d_lib.cpp +++ b/src/d/d_lib.cpp @@ -108,7 +108,7 @@ u8 STControl::checkTrigger() { f32 stickValue = getValueStick(); s16 stickAngle = getAngleStick(); u8 var_r6 = 0; - s16 temp_r7 = 0x2000 - field_0x26 >> 1; + s16 temp_r7 = (0x2000 - field_0x26) >> 1; if (!cM3d_IsZero(stickValue)) { if (stickAngle < field_0x22 - 0x7000 + temp_r7) { diff --git a/src/d/d_map_path_dmap.cpp b/src/d/d_map_path_dmap.cpp index a5a9eadf38..cd76155327 100644 --- a/src/d/d_map_path_dmap.cpp +++ b/src/d/d_map_path_dmap.cpp @@ -199,10 +199,10 @@ void dMapInfo_n::getRoomMinMaxXZ(int i_roomNo, f32* i_roomLeftX, f32* i_roomInne void dMapInfo_n::getFloorParameter(f32 param_0, s8* i_floorNo, f32* param_2, f32* param_3, f32* param_4, f32* param_5) { - f32 gap_level = dStage_stagInfo_GetGapLevel(dComIfGp_getStageStagInfo()); - f32 range_up = fabsf(dStage_stagInfo_GetRangeUp(dComIfGp_getStageStagInfo())); - f32 range_down = fabsf(dStage_stagInfo_GetRangeDown(dComIfGp_getStageStagInfo())); - s8 floorNo = (f32)floor(param_0 / gap_level); + f32 gap_level = (f32)dStage_stagInfo_GetGapLevel(dComIfGp_getStageStagInfo()); + f32 range_up = fabsf((f32)dStage_stagInfo_GetRangeUp(dComIfGp_getStageStagInfo())); + f32 range_down = fabsf((f32)dStage_stagInfo_GetRangeDown(dComIfGp_getStageStagInfo())); + s8 floorNo = (s8)(f32)floor(param_0 / gap_level); if (i_floorNo != NULL) { *i_floorNo = floorNo; diff --git a/src/d/d_menu_letter.cpp b/src/d/d_menu_letter.cpp index 6997655860..d0017558b3 100644 --- a/src/d/d_menu_letter.cpp +++ b/src/d/d_menu_letter.cpp @@ -18,9 +18,9 @@ #include "d/d_lib.h" #if VERSION == VERSION_GCN_JPN -#define LINE_MAX 9 +#define D_MENU_LETTER_LINE_MAX 9 #else -#define LINE_MAX 12 +#define D_MENU_LETTER_LINE_MAX 12 #endif typedef void (dMenu_Letter_c::*initFunc)(); @@ -258,8 +258,8 @@ void dMenu_Letter_c::_draw() { uVar10 = (J2DTextBox*)field_0x2f4[i]->getPanePtr(); } J2DTextBox* uVar18 = (J2DTextBox*)field_0x2ec[i]->getPanePtr(); - mpString->getStringPage(dMenu_Letter::getLetterText(dVar1), field_0x3e3 - 1, LINE_MAX, - uVar18, uVar10, NULL, NULL, 0); + mpString->getStringPage(dMenu_Letter::getLetterText(dVar1), field_0x3e3 - 1, + D_MENU_LETTER_LINE_MAX, uVar18, uVar10, NULL, NULL, 0); } mpString->drawOutFont((J2DTextBox*)field_0x2ec[1]->getPanePtr(), -1.0f); if (mProcess == 4) { @@ -491,10 +491,10 @@ void dMenu_Letter_c::read_open_init() { text1 = (J2DTextBox*)field_0x2f4[i]->getPanePtr(); } J2DTextBox* text2 = (J2DTextBox*)field_0x2ec[i]->getPanePtr(); - mpString->getStringPage(dMenu_Letter::getLetterText(idx), field_0x3e3 - 1, LINE_MAX, text2, text1, - NULL, NULL, 0); + mpString->getStringPage(dMenu_Letter::getLetterText(idx), field_0x3e3 - 1, + D_MENU_LETTER_LINE_MAX, text2, text1, NULL, NULL, 0); } - field_0x3e2 = mpString->getPageMax(LINE_MAX); + field_0x3e2 = mpString->getPageMax(D_MENU_LETTER_LINE_MAX); if (field_0x3e2 > 1) { char acStack_30[20]; sprintf(acStack_30, "%d/%d", field_0x3e3, field_0x3e2); @@ -642,7 +642,8 @@ void dMenu_Letter_c::read_next_fadein_init() { text1 = (J2DTextBox*)field_0x2f4[i]->getPanePtr(); } J2DTextBox* text2 = (J2DTextBox*)field_0x2ec[i]->getPanePtr(); - mpString->getStringPage(dMenu_Letter::getLetterText(idx), field_0x3e3 - 1, LINE_MAX, text2, text1, NULL, NULL, 0); + mpString->getStringPage(dMenu_Letter::getLetterText(idx), field_0x3e3 - 1, + D_MENU_LETTER_LINE_MAX, text2, text1, NULL, NULL, 0); } char acStack_30[10]; sprintf(acStack_30, "%d/%d", field_0x3e3, field_0x3e2); diff --git a/src/d/d_menu_ring.cpp b/src/d/d_menu_ring.cpp index d1fa57dd4d..cad04d6ab6 100644 --- a/src/d/d_menu_ring.cpp +++ b/src/d/d_menu_ring.cpp @@ -1507,6 +1507,8 @@ void dMenu_Ring_c::setSelectItem(int i_idx, u8 i_itemNo) { } else { field_0x6be[i_idx] = 0; } + // !@bug Out-of-bounds access into mpSelectItemTexBuf + // (innermost dimension is 2, we take index 2 which is invalid) field_0x686[i_idx] = dMeter2Info_readItemTexture( i_itemNo, mpSelectItemTexBuf[i_idx][field_0x6be[i_idx]][0], mpSelectItemTex[i_idx][0], mpSelectItemTexBuf[i_idx][field_0x6be[i_idx]][1], mpSelectItemTex[i_idx][1], diff --git a/src/d/d_menu_window_HIO.cpp b/src/d/d_menu_window_HIO.cpp index c48e62d0a8..053aeaf837 100644 --- a/src/d/d_menu_window_HIO.cpp +++ b/src/d/d_menu_window_HIO.cpp @@ -7,6 +7,13 @@ #include "d/d_menu_window_HIO.h" #include "d/d_com_inf_game.h" +#include "d/d_msg_object.h" +#include "d/d_meter2_info.h" + +#if DEBUG +#include "JSystem/JHostIO/JORServer.h" +#include "d/d_s_menu.h" +#endif dMw_HIO_c::dMw_HIO_c() { init(); @@ -21,126 +28,1057 @@ void dMw_HIO_c::init() { mBombFlag = 0; mPachinkoFlag = 0; - mLifeCopy = 0; - mLife = 0; - mMaxLifeCopy = 0; - mMaxLife = 0; - mMagicCopy = 0; - mMagic = 0; - mMaxMagicCopy = 0; - mMaxMagic = 0; - mOilCopy = 0; - mOil = 0; - mMaxOilCopy = 0; - mMaxOil = 0; - mOxygenCopy = 0; - mOxygen = 0; - mMaxOxygenCopy = 0; - mMaxOxygen = 0; - mEnableMagicCopy = false; - mEnableMagic = false; - mEnableArrowDropsCopy = false; - mEnableArrowDrops = false; - mRupeesCopy = 0; - mRupees = 0; - mWalletSizeCopy = WALLET; - mWalletSize = WALLET; - mKeysCopy = 0; - mKeys = 0; - field_0x47 = 0; - field_0x23 = 0; - mEnableOxygenMeterCopy = false; - mEnableOxygenMeter = false; - mPoesCopy = 0; - mPoes = 0; - mDonationAmountCopy = 0; - mDonationAmount = 0; + mLife = mLifeCopy = 0; + mMaxLife = mMaxLifeCopy = 0; + mMagic = mMagicCopy = 0; + mMaxMagic = mMaxMagicCopy = 0; + mOil = mOilCopy = 0; + mMaxOil = mMaxOilCopy = 0; + mOxygen = mOxygenCopy = 0; + mMaxOxygen = mMaxOxygenCopy = 0; + mEnableMagic = mEnableMagicCopy = false; + mEnableArrowDrops = mEnableArrowDropsCopy = false; + mRupees = mRupeesCopy = 0; + mWalletSize = mWalletSizeCopy = WALLET; + mKeys = mKeysCopy = 0; + field_0x23 = field_0x47 = 0; + mEnableOxygenMeter = mEnableOxygenMeterCopy = false; + mPoes = mPoesCopy = 0; + mDonationAmount = mDonationAmountCopy = 0; for (int i = 0; i < 24; i++) { - mItemsCopy[i] = dItemNo_NONE_e; - mItems[i] = dItemNo_NONE_e; + mItems[i] = mItemsCopy[i] = dItemNo_NONE_e; field_0x7a[i] = 0; } for (int i = 0; i < 4; i++) { - mBottleNumCopy[i] = 0; - mBottleNum[i] = 0; + mBottleNum[i] = mBottleNumCopy[i] = 0; } for (int i = 0; i < 3; i++) { - mBombNumCopy[i] = 0; - mBombNum[i] = 0; + mBombNum[i] = mBombNumCopy[i] = 0; } - mScentCopy = dItemNo_NONE_e; - mScent = dItemNo_NONE_e; + mScent = mScentCopy = dItemNo_NONE_e; field_0xa8 = 0; - field_0xf4 = 0; - field_0xea = 0; + field_0xea = field_0xf4 = 0; for (int i = 0; i < 4; i++) { - bool swordBit = dComIfGs_isItemFirstBit(m_sword_item[i]); - mSwordsCopy[i] = swordBit; - mSwords[i] = swordBit; + mSwords[i] = mSwordsCopy[i] = dComIfGs_isItemFirstBit(m_sword_item[i]) ? 1 : 0; } for (int i = 0; i < 3; i++) { - bool shieldBit = dComIfGs_isItemFirstBit(m_shield_item[i]); - mShieldsCopy[i] = shieldBit; - mShields[i] = shieldBit; - - bool clothesBit = dComIfGs_isItemFirstBit(m_cloth_item[i]); - mClothesCopy[i] = clothesBit; - mClothes[i] = clothesBit; + mShields[i] = mShieldsCopy[i] = dComIfGs_isItemFirstBit(m_shield_item[i]) ? 1 : 0; + mClothes[i] = mClothesCopy[i] = dComIfGs_isItemFirstBit(m_cloth_item[i]) ? 1 : 0; } - mBombBagLV2Copy = false; - mBombBagLV2 = false; + mBombBagLV2 = mBombBagLV2Copy = false; for (int i = 0; i < 3; i++) { - mLV2KeyShardsCopy[i] = false; - mLV2KeyShards[i] = false; + mLV2KeyShards[i] = mLV2KeyShardsCopy[i] = false; } for (int i = 0; i < 2; i++) { - mLV5ItemCopy[i] = false; - mLV5Item[i] = false; + mLV5Item[i] = mLV5ItemCopy[i] = false; } for (int i = 0; i < 24; i++) { - mGoldBugCopy[i] = false; - mGoldBug[i] = false; + mGoldBug[i] = mGoldBugCopy[i] = false; } for (int i = 0; i < 8; i++) { - field_0x101[i] = 0; - field_0xf9[i] = 0; - field_0x111[i] = 0; - field_0x109[i] = 0; + field_0xf9[i] = field_0x101[i] = 0; + field_0x109[i] = field_0x111[i] = 0; } for (int i = 0; i < 4; i++) { - mFusedShadowCopy[i] = false; - mFusedShadow[i] = false; + mFusedShadow[i] = mFusedShadowCopy[i] = false; } for (int i = 0; i < 4; i++) { - mMirrorShardCopy[i] = false; - mMirrorShard[i] = false; + mMirrorShard[i] = mMirrorShardCopy[i] = false; } } -bool dMw_HIO_c::getBombFlag() { - return false; +#if DEBUG +void dMw_HIO_c::genMessage(JORMContext* mctx) { + // "*****Player Status*****" + mctx->genLabel("\n*****プレイヤーの状態*****", 0); + mctx->genCheckBox("魔法使える", &mEnableMagic, 1); + mctx->genCheckBox("矢補給", &mEnableArrowDrops, 1); + mctx->genCheckBox("矢の数無限", &mArrowFlag, 1); + mctx->genCheckBox("パチンコ玉の数無限", &mPachinkoFlag, 1); + mctx->genCheckBox("爆弾の数無限", &mBombFlag, 1); + mctx->genSlider("ライフ", (s16*)&mLife, 0, 80); + mctx->genSlider("ライフ最大", (s16*)&mMaxLife, 0, 100); + mctx->genSlider("魔法メーター", &mMagic, 0, 32); + mctx->genSlider("魔法メーター最大", &mMaxMagic, 0, 32); + mctx->genSlider("カンテラ油", &mOil, 0, 100000); + mctx->genSlider("カンテラ油最大", &mMaxOil, 0, 100000); + mctx->genCheckBox("酸素メーターON", &mEnableOxygenMeter, 1); + mctx->genSlider("酸素メーター", &mOxygen, 0, 100000); + mctx->genSlider("酸素メーター最大", &mMaxOxygen, 0, 100000); + mctx->genSlider("ルピ−", &mRupees, 0, 5000); + mctx->genSlider("財布", &mWalletSize, 0, 2); + mctx->genSlider("鍵", &mKeys, 0, 99); + mctx->genSlider("ゴースト", &mPoes, 0, 60); + mctx->genSlider("お布施総額", &mDonationAmount, 0, 10000); + mctx->genCheckBox("爆弾袋LV2", &mBombBagLV2, 1); + + // "*****Item*****" + mctx->genLabel("\n*****アイテム*****", 0); + mctx->startComboBox("風のロッド", &mItems[0], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("風のロッド", dItemNo_BOOMERANG_e); + mctx->endComboBox(); + + mctx->startComboBox("カンテラ", &mItems[1], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("カンテラ", dItemNo_KANTERA_e); + mctx->endComboBox(); + + mctx->startComboBox("スピナー", &mItems[2], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("スピナー", dItemNo_SPINNER_e); + mctx->endComboBox(); + + mctx->startComboBox("アイアンブーツ", &mItems[3], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("アイアンブーツ", dItemNo_HVY_BOOTS_e); + mctx->endComboBox(); + + mctx->startComboBox("弓矢", &mItems[4], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("弓矢", dItemNo_BOW_e); + mctx->genComboBoxItem("光の矢", dItemNo_LIGHT_ARROW_e); + mctx->genComboBoxItem("ホークアイ+矢", dItemNo_HAWK_ARROW_e); + mctx->genComboBoxItem("爆弾+矢", dItemNo_BOMB_ARROW_e); + mctx->endComboBox(); + + mctx->genSlider("矢の数", &mArrowNum, 0, 100); + + mctx->startComboBox("ホークアイ", &mItems[5], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("ホークアイ", dItemNo_HAWK_EYE_e); + mctx->endComboBox(); + + mctx->startComboBox("鉄球", &mItems[6], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("鉄球", dItemNo_IRONBALL_e); + mctx->endComboBox(); + + mctx->startComboBox("ミラーシールド", &mItems[7], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->endComboBox(); + + mctx->startComboBox("コピーロッド", &mItems[8], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("コピーロッド", dItemNo_COPY_ROD_e); + mctx->endComboBox(); + + mctx->startComboBox("フックショット", &mItems[9], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("フックショット", dItemNo_HOOKSHOT_e); + mctx->endComboBox(); + + mctx->startComboBox("Wフックショット", &mItems[10], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("Wフックショット", dItemNo_W_HOOKSHOT_e); + mctx->endComboBox(); + + for (int i = 0; i < 4; i = i + 1) { + char sp30[8]; + sprintf(sp30, "ビン%d", i + 1); + mctx->startComboBox(sp30, &mItems[11 + i], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("空きビン", dItemNo_EMPTY_BOTTLE_e); + mctx->genComboBoxItem("赤い薬入りビン", dItemNo_RED_BOTTLE_e); + mctx->genComboBoxItem("緑の薬入りビン", dItemNo_GREEN_BOTTLE_e); + mctx->genComboBoxItem("青い薬入りビン", dItemNo_BLUE_BOTTLE_e); + mctx->genComboBoxItem("水入りビン", dItemNo_WATER_BOTTLE_e); + mctx->genComboBoxItem("妖精入りビン", dItemNo_FAIRY_e); + mctx->genComboBoxItem("牛乳入りビン", dItemNo_MILK_BOTTLE_e); + mctx->genComboBoxItem("牛乳半分入りビン", dItemNo_HALF_MILK_BOTTLE_e); + mctx->genComboBoxItem("油入りビン", dItemNo_OIL_BOTTLE_e); + mctx->genComboBoxItem("まずいスープ", dItemNo_UGLY_SOUP_e); + mctx->genComboBoxItem("温泉水入りビン", dItemNo_HOT_SPRING_e); + mctx->genComboBoxItem("最初にもらうスープ", dItemNo_LV1_SOUP_e); + mctx->genComboBoxItem("材料が1つ入ったスープ", dItemNo_LV2_SOUP_e); + mctx->genComboBoxItem("完成したスープ", dItemNo_LV3_SOUP_e); + mctx->genComboBoxItem("ポウの炎1", dItemNo_POU_FIRE1_e); + mctx->genComboBoxItem("ポウの炎2", dItemNo_POU_FIRE2_e); + mctx->genComboBoxItem("ポウの炎3", dItemNo_POU_FIRE3_e); + mctx->genComboBoxItem("ポウの炎4", dItemNo_POU_FIRE4_e); + mctx->genComboBoxItem("チュチュゼリー赤", dItemNo_CHUCHU_RED_e); + mctx->genComboBoxItem("チュチュゼリー青", dItemNo_CHUCHU_BLUE_e); + mctx->genComboBoxItem("チュチュゼリー緑", dItemNo_CHUCHU_GREEN_e); + mctx->genComboBoxItem("チュチュゼリー黄", dItemNo_CHUCHU_YELLOW_e); + mctx->genComboBoxItem("チュチュゼリー紫", dItemNo_CHUCHU_PURPLE_e); + mctx->genComboBoxItem("チュチュゼリーレア", dItemNo_CHUCHU_RARE_e); + mctx->genComboBoxItem("チュチュゼリー黒", dItemNo_CHUCHU_BLACK_e); + mctx->genComboBoxItem("妖精", dItemNo_FAIRY_e); + mctx->genComboBoxItem("カブトムシ♂", dItemNo_M_BEETLE_e); + mctx->genComboBoxItem("カブトムシ♀", dItemNo_F_BEETLE_e); + mctx->genComboBoxItem("チョウチョ♂", dItemNo_M_BUTTERFLY_e); + mctx->genComboBoxItem("チョウチョ♀", dItemNo_F_BUTTERFLY_e); + mctx->genComboBoxItem("クワガタ♂", dItemNo_M_STAG_BEETLE_e); + mctx->genComboBoxItem("クワガタ♀", dItemNo_F_STAG_BEETLE_e); + mctx->genComboBoxItem("バッタ♂", dItemNo_M_GRASSHOPPER_e); + mctx->genComboBoxItem("バッタ♀", dItemNo_F_GRASSHOPPER_e); + mctx->genComboBoxItem("ナナフシ♂", dItemNo_M_NANAFUSHI_e); + mctx->genComboBoxItem("ナナフシ♀", dItemNo_F_NANAFUSHI_e); + mctx->genComboBoxItem("ダンゴムシ♂", dItemNo_M_DANGOMUSHI_e); + mctx->genComboBoxItem("ダンゴムシ♀", dItemNo_F_DANGOMUSHI_e); + mctx->genComboBoxItem("カマキリ♂", dItemNo_M_MANTIS_e); + mctx->genComboBoxItem("カマキリ♀", dItemNo_F_MANTIS_e); + mctx->genComboBoxItem("テントウムシ♂", dItemNo_M_LADYBUG_e); + mctx->genComboBoxItem("テントウムシ♀", dItemNo_F_LADYBUG_e); + mctx->genComboBoxItem("カタツムリ♂", dItemNo_M_SNAIL_e); + mctx->genComboBoxItem("カタツムリ♀", dItemNo_F_SNAIL_e); + mctx->genComboBoxItem("トンボ♂", dItemNo_M_DRAGONFLY_e); + mctx->genComboBoxItem("トンボ♀", dItemNo_F_DRAGONFLY_e); + mctx->genComboBoxItem("アリ♂", dItemNo_M_ANT_e); + mctx->genComboBoxItem("アリ♀", dItemNo_F_ANT_e); + mctx->genComboBoxItem("カゲロウ♂", dItemNo_M_MAYFLY_e); + mctx->genComboBoxItem("カゲロウ♀", dItemNo_F_MAYFLY_e); + mctx->genComboBoxItem("蜂の子", dItemNo_BEE_CHILD_e); + mctx->genComboBoxItem("みみず", dItemNo_WORM_e); + mctx->genComboBoxItem("大妖精の滴", dItemNo_FAIRY_DROP_e); + mctx->endComboBox(); + + mctx->genSlider("アイテムの数", &mBottleNum[i], 0, 10); + } + + for (int i = 0; i < 3; i = i + 1) { + char sp38[8]; + sprintf(sp38, "爆弾袋%d", i + 1); + mctx->startComboBox(sp38, &mItems[15 + i], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("爆弾袋", dItemNo_BOMB_BAG_LV1_e); + mctx->genComboBoxItem("ノーマル爆弾", dItemNo_NORMAL_BOMB_e); + mctx->genComboBoxItem("水中爆弾", dItemNo_WATER_BOMB_e); + mctx->genComboBoxItem("ポケ虫", dItemNo_POKE_BOMB_e); + mctx->endComboBox(); + + mctx->genSlider("爆弾の数", &mBombNum[i], 0, 99); + } + + mctx->startComboBox("天空人", &mItems[18], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("天空人", dItemNo_DUNGEON_EXIT_e); + mctx->genComboBoxItem("天空人の息子", dItemNo_DUNGEON_BACK_e); + mctx->genComboBoxItem("天空人の書置き", dItemNo_TKS_LETTER_e); + mctx->genComboBoxItem("再開時の天空人", dItemNo_DUNGEON_EXIT_2_e); + mctx->endComboBox(); + + mctx->startComboBox("メモ", &mItems[19], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("ラフレルのメモ", dItemNo_RAFRELS_MEMO_e); + mctx->genComboBoxItem("アッシュの走り書き", dItemNo_ASHS_SCRIBBLING_e); + mctx->endComboBox(); + + mctx->startComboBox("釣竿", &mItems[20], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("珊瑚の耳飾り", dItemNo_ZORAS_JEWEL_e); + mctx->genComboBoxItem("釣竿", dItemNo_FISHING_ROD_1_e); + mctx->genComboBoxItem("釣竿+蜂の子", dItemNo_BEE_ROD_e); + mctx->genComboBoxItem("釣竿+みみず", dItemNo_WORM_ROD_e); + mctx->genComboBoxItem("珊瑚+釣竿", dItemNo_JEWEL_ROD_e); + mctx->genComboBoxItem("珊瑚+釣竿+蜂の子", dItemNo_JEWEL_BEE_ROD_e); + mctx->genComboBoxItem("珊瑚+釣竿+みみず", dItemNo_JEWEL_WORM_ROD_e); + mctx->endComboBox(); + + mctx->startComboBox("わらしべアイテム", &mItems[21], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("レナードの手紙", dItemNo_LETTER_e); + mctx->genComboBoxItem("請求書", dItemNo_BILL_e); + mctx->genComboBoxItem("木彫りの像", dItemNo_WOOD_STATUE_e); + mctx->genComboBoxItem("イリアのペンダント", dItemNo_IRIAS_PENDANT_e); + mctx->genComboBoxItem("馬笛", dItemNo_HORSE_FLUTE_e); + mctx->endComboBox(); + + mctx->startComboBox("古文書", &mItems[22], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("天空の古文書", dItemNo_ANCIENT_DOCUMENT_e); + mctx->genComboBoxItem("天空文字", dItemNo_AIR_LETTER_e); + mctx->genComboBoxItem("解封の古文書", dItemNo_ANCIENT_DOCUMENT2_e); + mctx->endComboBox(); + + char sp40[8]; + sprintf(sp40, "パチンコ"); + mctx->startComboBox(sp40, &mItems[23], 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("未装備", dItemNo_NONE_e); + mctx->genComboBoxItem("パチンコ", dItemNo_PACHINKO_e); + mctx->endComboBox(); + + mctx->genSlider("パチンコ玉の数", &mSeedNum, 0, 50); + + // "*****Collect*****" + mctx->genLabel("\n*****コレクト*****", 0); + mctx->genCheckBox("コキリの服", &mClothes[0], 1); + mctx->genCheckBox("装甲服", &mClothes[1], 1); + mctx->genCheckBox("ゾーラの服", &mClothes[2], 1); + mctx->genCheckBox("木刀", &mSwords[3], 1); + mctx->genCheckBox("金剛の剣", &mSwords[0], 1); + mctx->genCheckBox("マスターソード", &mSwords[1], 1); + mctx->genCheckBox("ライトニングソード", &mSwords[2], 1); + mctx->genCheckBox("木彫りの盾", &mShields[2], 1); + mctx->genCheckBox("木の盾", &mShields[0], 1); + mctx->genCheckBox("ハイリアの盾", &mShields[1], 1); + mctx->genCheckBox("LV2ボス鍵かけら1", &mLV2KeyShards[0], 1); + mctx->genCheckBox("LV2ボス鍵かけら2", &mLV2KeyShards[1], 1); + mctx->genCheckBox("LV2ボス鍵かけら3", &mLV2KeyShards[2], 1); + mctx->genCheckBox("かぼちゃ", &mLV5Item[0], 1); + mctx->genCheckBox("トアル産チーズ", &mLV5Item[1], 1); + + mctx->startComboBox("におい", &mScent, 0, NULL, 0xFFFF, 0xFFFF, 256, 26); + mctx->genComboBoxItem("覚えてない", dItemNo_NONE_e); + mctx->genComboBoxItem("かぼちゃのにおい(削除)", dItemNo_SMELL_PUMPKIN_e); + mctx->genComboBoxItem("イリアのポーチのにおい", dItemNo_SMELL_YELIA_POUCH_e); + mctx->genComboBoxItem("魚のにおい", dItemNo_SMELL_FISH_e); + mctx->genComboBoxItem("ポウのにおい", dItemNo_SMELL_POH_e); + mctx->genComboBoxItem("子供のにおい", dItemNo_SMELL_CHILDREN_e); + mctx->genComboBoxItem("薬品のにおい", dItemNo_SMELL_MEDICINE_e); + mctx->endComboBox(); + + for (int i = 0; i < 24; i = i + 1) { + static const char* insect_name[] = { + "カブトムシ♂", "カブトムシ♀", + "チョウチョ♂", "チョウチョ♀", + "クワガタ♂", "クワガタ♀", + "バッタ♂", "バッタ♀", + "ナナフシ♂", "ナナフシ♀", + "ダンゴムシ♂", "ダンゴムシ♀", + "カマキリ♂", "カマキリ♀", + "テントウムシ♂", "テントウムシ♀", + "カタツムリ♂", "カタツムリ♀", + "トンボ♂", "トンボ♀", + "アリ♂", "アリ♀", + "カゲロウ♂", "カゲロウ♀", + }; + + mctx->genCheckBox(insect_name[i], &mGoldBug[i], 1); + } + + // "*****Fused Shadows*****" + mctx->genLabel("\n*****影の水晶石*****", 0); + char sp28[24]; + for (int i = 0; i < 4; i = i + 1) { + sprintf(sp28, "影の水晶石%d", i + 1); + mctx->genCheckBox(sp28, &mFusedShadow[i], 1); + } + + // "*****Mirror Shards*****" + mctx->genLabel("\n*****陰りの鏡*****", 0); + for (int i = 0; i < 4; i = i + 1) { + sprintf(sp28, "陰りの鏡%d", i + 1); + mctx->genCheckBox(sp28, &mMirrorShard[i], 1); + } } -bool dMw_HIO_c::getArrowFlag() { - return false; +void dMw_HIO_c::update() { + JORMContext* mctx = attachJORMContext(8); + mctx->startUpdateNode(this); + mctx->updateCheckBox(2, &mArrowFlag, 1, 0); + mctx->updateCheckBox(2, &mBombFlag, 1, 0); + mctx->endUpdateNode(); + releaseJORMContext(mctx); } -bool dMw_HIO_c::getPachinkoFlag() { - return false; +void dMw_HIO_c::playerStatusHIO() { + JORMContext* mctx = attachJORMContext(8); + + if (mLife != mLifeCopy) { + s16 sp10 = mLife - dComIfGs_getLife(); + dComIfGp_clearItemLifeCount(); + dComIfGp_setItemLifeCount(sp10, 0); + mLifeCopy = mLife; + } else if (mLifeCopy != dComIfGs_getLife()) { + mLife = mLifeCopy = dComIfGs_getLife(); + mctx->updateSlider(2, &mLife, 0, 0, 0); + } + + if (mMaxLifeCopy != mMaxLife) { + s16 spE = mMaxLife - dComIfGs_getMaxLife(); + dComIfGp_clearItemMaxLifeCount(); + dComIfGp_setItemMaxLifeCount(spE); + mMaxLifeCopy = mMaxLife; + } else if (mMaxLifeCopy != dComIfGs_getMaxLife()) { + mMaxLife = mMaxLifeCopy = dComIfGs_getMaxLife(); + mctx->updateSlider(2, &mMaxLife, 0, 0, 0); + } + + if (mMagicCopy != mMagic) { + s16 spC = mMagic - dComIfGs_getMagic(); + dComIfGp_setItemMagicCount(spC); + mMagicCopy = mMagic; + } else if (mMagicCopy != dComIfGs_getMagic()) { + mMagic = mMagicCopy = dComIfGs_getMagic(); + mctx->updateSlider(2, &mMagic, 0, 0, 0); + } + + if (mMaxMagicCopy != mMaxMagic) { + s16 spB = mMaxMagic - dComIfGs_getMaxMagic(); + dComIfGp_setItemMaxMagicCount(spB); + mMaxMagicCopy = mMaxMagic; + } else if (mMaxMagicCopy != dComIfGs_getMaxMagic()) { + mMaxMagic = mMaxMagicCopy = dComIfGs_getMaxMagic(); + mctx->updateSlider(2, &mMaxMagic, 0, 0, 0); + } + + if (mOilCopy != mOil) { + s32 sp2C = mOil - dComIfGs_getOil(); + dComIfGp_setItemOilCount(sp2C); + mOilCopy = mOil; + } else if (mOilCopy != dComIfGs_getOil()) { + mOil = mOilCopy = dComIfGs_getOil(); + mctx->updateSlider(2, &mOil, 0, 0, 0); + } + + if (mMaxOilCopy != mMaxOil) { + s32 sp30 = mMaxOil - dComIfGs_getMaxOil(); + dComIfGp_setItemMaxOilCount(sp30); + mMaxOilCopy = mMaxOil; + } else if (mMaxOilCopy != dComIfGs_getMaxOil()) { + mMaxOil = mMaxOilCopy = dComIfGs_getMaxOil(); + mctx->updateSlider(2, &mMaxOil, 0, 0, 0); + } + + if (mEnableOxygenMeterCopy != mEnableOxygenMeter) { + if (mEnableOxygenMeter) { + dComIfGp_onOxygenShowFlag(); + } else { + dComIfGp_offOxygenShowFlag(); + } + mEnableOxygenMeterCopy = mEnableOxygenMeter; + } else if (mEnableOxygenMeterCopy != dComIfGp_getOxygenShowFlag()) { + mEnableOxygenMeter = mEnableOxygenMeterCopy = dComIfGp_getOxygenShowFlag(); + mctx->updateSlider(2, &mEnableOxygenMeter, 0, 0, 0); + } + + if (mOxygenCopy != mOxygen) { + s32 sp30 = mOxygen - dComIfGp_getOxygen(); + dComIfGp_setOxygenCount(sp30); + mOxygenCopy = mOxygen; + } else if (mOxygenCopy != dComIfGp_getOxygen()) { + mOxygen = mOxygenCopy = dComIfGp_getOxygen(); + mctx->updateSlider(2, &mOxygen, 0, 0, 0); + } + + if (mMaxOxygenCopy != mMaxOxygen) { + s32 sp30 = mMaxOxygen - dComIfGp_getMaxOxygen(); + dComIfGp_setMaxOxygenCount(sp30); + mMaxOxygenCopy = mMaxOxygen; + } else if (mMaxOxygenCopy != dComIfGp_getMaxOxygen()) { + mMaxOxygen = mMaxOxygenCopy = dComIfGp_getMaxOxygen(); + mctx->updateSlider(2, &mMaxOxygen, 0, 0, 0); + } + + if (mRupeesCopy != mRupees) { + s32 sp30 = mRupees - dComIfGs_getRupee(); + dComIfGp_clearItemRupeeCount(); + dComIfGp_setItemRupeeCount(sp30); + mRupeesCopy = mRupees; + } else if (mRupeesCopy != dComIfGs_getRupee()) { + mRupees = mRupeesCopy = dComIfGs_getRupee(); + mctx->updateSlider(2, &mRupees, 0, 0, 0); + } + + if (mWalletSizeCopy != mWalletSize) { + mWalletSizeCopy = mWalletSize; + dComIfGs_setWalletSize(mWalletSize); + } else if (mWalletSizeCopy != (s16)dComIfGs_getWalletSize()) { + mWalletSize = mWalletSizeCopy = dComIfGs_getWalletSize(); + mctx->updateSlider(2, &mWalletSize, 0, 0, 0); + } + + if (mKeysCopy != mKeys) { + s16 sp30 = mKeys - dComIfGs_getKeyNum(); + dComIfGp_clearItemKeyNumCount(); + dComIfGp_setItemKeyNumCount(sp30); + mKeysCopy = mKeys; + } else if (mKeysCopy != dComIfGs_getKeyNum()) { + mKeys = mKeysCopy = dComIfGs_getKeyNum(); + mctx->updateSlider(2, &mKeys, 0, 0, 0); + } + + if (mPoesCopy != mPoes) { + dComIfGs_setPohSpiritNum(mPoes); + mPoesCopy = mPoes; + } else if (mPoesCopy != dComIfGs_getPohSpiritNum()) { + mPoes = mPoesCopy = dComIfGs_getPohSpiritNum(); + mctx->updateSlider(2, &mPoes, 0, 0, 0); + } + + if (mDonationAmountCopy != mDonationAmount) { + dMsgObject_setOffering(mDonationAmount); + mDonationAmountCopy = mDonationAmount; + } else if (mDonationAmountCopy != dMsgObject_getOffering()) { + mDonationAmount = mDonationAmountCopy = dMsgObject_getOffering(); + mctx->updateSlider(2, &mDonationAmount, 0, 0, 0); + } + + releaseJORMContext(mctx); } +#endif + +u8 dMw_HIO_c::getBombFlag() { + #if DEBUG + if (mDoCPd_c::isConnect(PAD_3)) { + return mBombFlag; + } else if (mDoCPd_c::isConnect(PAD_3)) { + return mBombFlag; + } else { + return false; + } + #else + return false; + #endif +} + +u8 dMw_HIO_c::getArrowFlag() { + #if DEBUG + if (mDoCPd_c::isConnect(PAD_3)) { + return mArrowFlag; + } else { + return false; + } + #else + return false; + #endif +} + +u8 dMw_HIO_c::getPachinkoFlag() { + #if DEBUG + if (mDoCPd_c::isConnect(PAD_3)) { + return mPachinkoFlag; + } else { + return false; + } + #else + return false; + #endif +} + +#if DEBUG +void dMw_HIO_c::itemBitCheck() { + JORMContext* mctx = attachJORMContext(8); + u8 var_r29; + + if (dComIfGs_isGetMagicUseFlag()) + var_r29 = 1; + else + var_r29 = 0; + + if (mEnableMagicCopy != var_r29) { + mEnableMagicCopy = mEnableMagic; + mEnableMagic = var_r29; + mctx->updateSlider(2, &mEnableMagic, 0, 0, 0); + } + + if (mEnableArrowDrops != mEnableArrowDropsCopy) { + mEnableArrowDropsCopy = mEnableArrowDrops; + if (mEnableArrowDrops) { + dComIfGs_onItemFirstBit(dItemNo_BOW_e); + } else { + dComIfGs_offItemFirstBit(dItemNo_BOW_e); + } + } + + if (mEnableArrowDrops != (u8)dComIfGs_isItemFirstBit(dItemNo_BOW_e)) { + mEnableArrowDrops = mEnableArrowDropsCopy = dComIfGs_isItemFirstBit(dItemNo_BOW_e); + + JORMContext* mctx = attachJORMContext(8); + mctx->startUpdateNode(this); + mctx->updateCheckBox(2, &mEnableArrowDrops, 1, 0); + mctx->endUpdateNode(); + releaseJORMContext(mctx); + } + + for (int i = 0; i < 24; i++) { + if (mItemsCopy[i] != dComIfGs_getItem((u8)i, false)) { + field_0x7a[i] = 1; + mItemsCopy[i] = mItems[i]; + mItems[i] = dComIfGs_getItem((u8)i, false); + mctx->updateComboBox(2, &mItems[i], 0); + } + } + + if (mScentCopy != dComIfGs_getCollectSmell()) { + field_0xa8 = 1; + mScentCopy = mScent; + mScent = dComIfGs_getCollectSmell(); + mctx->updateComboBox(2, &mScent, 0); + } + + var_r29 = field_0x101[0]; + if (dComIfGs_isCollectClothes(2)) { + var_r29 = 3; + } else if (dComIfGs_isCollectClothes(1)) { + var_r29 = 2; + } else if (dComIfGs_isCollectClothes(0)) { + var_r29 = 1; + } else { + var_r29 = 0; + } + + if (field_0x101[0] != var_r29) { + field_0x101[0] = field_0xf9[0]; + field_0xf9[0] = var_r29; + mctx->updateComboBox(2, &field_0xf9[0], 0); + } + + for (int i = 0; i < 4; i++) { + static u8 m_sword_item[] = {dItemNo_SWORD_e, dItemNo_MASTER_SWORD_e, dItemNo_LIGHT_SWORD_e, dItemNo_WOOD_STICK_e}; + if (dComIfGs_isItemFirstBit(m_sword_item[i])) + var_r29 = 1; + else + var_r29 = 0; + + if (mSwordsCopy[i] != var_r29) { + mSwordsCopy[i] = mSwords[i]; + mSwords[i] = var_r29; + mctx->updateSlider(2, &mSwords[i], 0, 0, 0); + } + } + + for (int i = 0; i < 3; i++) { + static u8 m_cloth_item[] = {dItemNo_WEAR_KOKIRI_e, dItemNo_ARMOR_e, dItemNo_WEAR_ZORA_e}; + if (dComIfGs_isItemFirstBit(m_cloth_item[i])) + var_r29 = 1; + else + var_r29 = 0; + + if (mClothesCopy[i] != var_r29) { + mClothesCopy[i] = mClothes[i]; + mClothes[i] = var_r29; + mctx->updateSlider(2, &mClothes[i], 0, 0, 0); + } + + static u8 m_shield_item[] = {dItemNo_SHIELD_e, dItemNo_HYLIA_SHIELD_e, dItemNo_WOOD_SHIELD_e}; + if (dComIfGs_isItemFirstBit(m_shield_item[i])) + var_r29 = 1; + else + var_r29 = 0; + + if (mShieldsCopy[i] != var_r29) { + mShieldsCopy[i] = mShields[i]; + mShields[i] = var_r29; + mctx->updateSlider(2, &mShields[i], 0, 0, 0); + } + } + + if (dComIfGs_isItemFirstBit(dItemNo_BOMB_BAG_LV2_e)) + var_r29 = 1; + else + var_r29 = 0; + + if (mBombBagLV2Copy != var_r29) { + mBombBagLV2Copy = mBombBagLV2; + mBombBagLV2 = var_r29; + mctx->updateSlider(2, &mBombBagLV2, 0, 0, 0); + } + + for (int i = 0; i < 3; i++) { + static u8 m_lv2_dun_key[] = {dItemNo_L2_KEY_PIECES1_e, dItemNo_L2_KEY_PIECES2_e, dItemNo_L2_KEY_PIECES3_e}; + if (dComIfGs_isItemFirstBit(m_lv2_dun_key[i])) + var_r29 = 1; + else + var_r29 = 0; + + if (mLV2KeyShardsCopy[i] != var_r29) { + mLV2KeyShardsCopy[i] = mLV2KeyShards[i]; + mLV2KeyShards[i] = var_r29; + mctx->updateSlider(2, &mLV2KeyShards[i], 0, 0, 0); + } + } + + for (int i = 0; i < 2; i++) { + static u8 m_lv5_dun_item[] = {dItemNo_TOMATO_PUREE_e, dItemNo_TASTE_e}; + if (dComIfGs_isItemFirstBit(m_lv5_dun_item[i])) + var_r29 = 1; + else + var_r29 = 0; + + if (mLV5ItemCopy[i] != var_r29) { + mLV5ItemCopy[i] = mLV5Item[i]; + mLV5Item[i] = var_r29; + mctx->updateSlider(2, &mLV5Item[i], 0, 0, 0); + } + } + + for (int i = 0; i < 24; i++) { + if (dComIfGs_isItemFirstBit(i + dItemNo_M_BEETLE_e)) + var_r29 = 1; + else + var_r29 = 0; + + if (mGoldBugCopy[i] != var_r29) { + mGoldBugCopy[i] = mGoldBug[i]; + mGoldBug[i] = var_r29; + mctx->updateSlider(2, &mGoldBug[i], 0, 0, 0); + } + } + + var_r29 = field_0x101[1]; + if (dComIfGs_isCollectSword(1)) { + var_r29 = 2; + } else if (dComIfGs_isCollectSword(0)) { + var_r29 = 1; + } else if (dComIfGs_isCollectSword(2)) { + var_r29 = 3; + } else if (dComIfGs_isCollectSword(3)) { + var_r29 = 4; + } else { + var_r29 = 0; + } + + if (field_0x101[1] != var_r29) { + field_0x101[1] = field_0xf9[1]; + field_0xf9[1] = var_r29; + mctx->updateComboBox(2, &field_0xf9[1], 0); + } + + var_r29 = field_0x101[2]; + if (dComIfGs_isCollectShield(3)) { + var_r29 = 4; + } else if (dComIfGs_isCollectShield(2)) { + var_r29 = 3; + } else if (dComIfGs_isCollectShield(1)) { + var_r29 = 2; + } else if (dComIfGs_isCollectShield(0)) { + var_r29 = 1; + } else { + var_r29 = 0; + } + + if (field_0x101[2] != var_r29) { + field_0x101[2] = field_0xf9[2]; + field_0xf9[2] = var_r29; + mctx->updateComboBox(2, &field_0xf9[2], 0); + } + + for (int i = 0; i < 4; i++) { + if (dComIfGs_isCollectCrystal(i)) + var_r29 = 1; + else + var_r29 = 0; + + if (mFusedShadowCopy[i] != var_r29) { + mFusedShadowCopy[i] = mFusedShadow[i]; + mFusedShadow[i] = var_r29; + mctx->updateSlider(2, &mFusedShadow[i], 0, 0, 0); + } + } + + for (int i = 0; i < 4; i++) { + if (dComIfGs_isCollectMirror(i)) + var_r29 = 1; + else + var_r29 = 0; + + if (mMirrorShardCopy[i] != var_r29) { + mMirrorShardCopy[i] = mMirrorShard[i]; + mMirrorShard[i] = var_r29; + mctx->updateSlider(2, &mMirrorShard[i], 0, 0, 0); + } + } + + releaseJORMContext(mctx); +} + +void dMw_HIO_c::itemNumHIO() { + JORMContext* mctx = attachJORMContext(8); + + if (mArrowNumCopy != mArrowNum) { + s16 count = mArrowNum - dComIfGs_getArrowNum(); + dComIfGp_setItemArrowNumCount(count); + mArrowNumCopy = mArrowNum; + } else if (mArrowNumCopy != dComIfGs_getArrowNum()) { + mArrowNum = mArrowNumCopy = dComIfGs_getArrowNum(); + mctx->updateSlider(2, &mArrowNum, 0, 0, 0); + } + + for (int i = 0; i < 4; i++) { + if (mBottleNumCopy[i] != mBottleNum[i]) { + s16 count = mBottleNum[i] - dComIfGs_getBottleNum(i); + dComIfGs_addBottleNum(i, count); + mBottleNumCopy[i] = mBottleNum[i]; + } else if (mBottleNumCopy[i] != dComIfGs_getBottleNum(i)) { + mBottleNum[i] = mBottleNumCopy[i] = dComIfGs_getBottleNum(i); + mctx->updateSlider(2, &mBottleNum[i], 0, 0, 0); + } + } + + for (int i = 0; i < 3; i++) { + if (mBombNumCopy[i] != mBombNum[i]) { + s16 count = mBombNum[i] - dComIfGs_getBombNum(i); + dComIfGp_setItemBombNumCount(i, count); + mBombNumCopy[i] = mBombNum[i]; + } else if (mBombNumCopy[i] != dComIfGs_getBombNum(i)) { + mBombNum[i] = mBombNumCopy[i] = dComIfGs_getBombNum(i); + mctx->updateSlider(2, &mBombNum[i], 0, 0, 0); + } + } + + if (mSeedNumCopy != mSeedNum) { + s16 count = mSeedNum - dComIfGs_getPachinkoNum(); + dComIfGp_setItemPachinkoNumCount(count); + mSeedNumCopy = mSeedNum; + } else if (mSeedNumCopy != dComIfGs_getPachinkoNum()) { + mSeedNum = mSeedNumCopy = dComIfGs_getPachinkoNum(); + mctx->updateSlider(2, &mSeedNum, 0, 0, 0); + } + + releaseJORMContext(mctx); +} + +void dMw_HIO_c::itemHIO() { + playerStatusHIO(); + itemNumHIO(); + itemBitCheck(); + + JORMContext* mctx = attachJORMContext(8); + + if (mEnableMagic != mEnableMagicCopy) { + mEnableMagicCopy = mEnableMagic; + if (mEnableMagic) { + dComIfGs_onGetMagicUseFlag(); + } else { + dComIfGs_offGetMagicUseFlag(); + } + } + + if (mEnableMagic != (u8)dComIfGs_isGetMagicUseFlag()) { + mEnableMagic = mEnableMagicCopy = dComIfGs_isGetMagicUseFlag(); + + JORMContext* mctx = attachJORMContext(8); + mctx->startUpdateNode(this); + mctx->updateCheckBox(2, &mEnableMagic, 1, 0); + mctx->endUpdateNode(); + releaseJORMContext(mctx); + } + + if (mEnableArrowDrops != mEnableArrowDropsCopy) { + mEnableArrowDropsCopy = mEnableArrowDrops; + if (mEnableArrowDrops) { + dComIfGs_onItemFirstBit(dItemNo_BOW_e); + } else { + dComIfGs_offItemFirstBit(dItemNo_BOW_e); + } + } + + if (mEnableArrowDrops != (u8)dComIfGs_isItemFirstBit(dItemNo_BOW_e)) { + mEnableArrowDrops = mEnableArrowDropsCopy = dComIfGs_isItemFirstBit(dItemNo_BOW_e); + + JORMContext* mctx = attachJORMContext(8); + mctx->startUpdateNode(this); + mctx->updateCheckBox(2, &mEnableArrowDrops, 1, 0); + mctx->endUpdateNode(); + releaseJORMContext(mctx); + } + + for (int i = 0; i < 24; i++) { + if (mItems[i] != mItemsCopy[i]) { + if (i == 20 && field_0x7a[i] == 0) { + switch (mItems[i]) { + case dItemNo_NONE_e: + case dItemNo_FISHING_ROD_1_e: + case dItemNo_BEE_ROD_e: + case dItemNo_WORM_ROD_e: + dComIfGs_offItemFirstBit(dItemNo_ZORAS_JEWEL_e); + break; + case dItemNo_JEWEL_ROD_e: + case dItemNo_JEWEL_BEE_ROD_e: + case dItemNo_JEWEL_WORM_ROD_e: + case dItemNo_ZORAS_JEWEL_e: + dComIfGs_onItemFirstBit(dItemNo_ZORAS_JEWEL_e); + break; + } + } + + dComIfGs_setItem((u8)i, mItems[i]); + + if (mItems[i] == dItemNo_HOT_SPRING_e) { + dMeter2Info_setHotSpringTimer(i); + } + + if (mItems[i] == dItemNo_BEE_CHILD_e && field_0x7a[i] == 0) { + dComIfGs_setBottleNum(i - 11, dComIfGs_getBottleMax()); + } + + mItemsCopy[i] = mItems[i]; + field_0x7a[i] = 0; + } + } + + if (mScent != mScentCopy) { + dMsgObject_setSmellType(mScent); + mScentCopy = mScent; + field_0xa8 = 0; + } + + for (int i = 0; i < 4; i++) { + if (mSwords[i] != mSwordsCopy[i]) { + static u8 m_sword_item[] = {dItemNo_SWORD_e, dItemNo_MASTER_SWORD_e, dItemNo_LIGHT_SWORD_e, dItemNo_WOOD_STICK_e}; + if (mSwords[i] != 0) { + dComIfGs_onItemFirstBit(m_sword_item[i]); + } else { + dComIfGs_offItemFirstBit(m_sword_item[i]); + if (m_sword_item[i] == dComIfGs_getSelectEquipSword()) { + dMeter2Info_setSword(dItemNo_NONE_e, false); + } + } + + mSwordsCopy[i] = mSwords[i]; + } + } + + for (int i = 0; i < 3; i++) { + if (mClothes[i] != mClothesCopy[i]) { + static u8 m_cloth_item[] = {dItemNo_WEAR_KOKIRI_e, dItemNo_ARMOR_e, dItemNo_WEAR_ZORA_e}; + if (mClothes[i] != 0) { + dComIfGs_onItemFirstBit(m_cloth_item[i]); + } else { + dComIfGs_offItemFirstBit(m_cloth_item[i]); + + } + mClothesCopy[i] = mClothes[i]; + } + + if (mShields[i] != mShieldsCopy[i]) { + static u8 m_shield_item[] = {dItemNo_SHIELD_e, dItemNo_HYLIA_SHIELD_e, dItemNo_WOOD_SHIELD_e}; + if (mShields[i] != 0) { + dComIfGs_onItemFirstBit(m_shield_item[i]); + } else { + dComIfGs_offItemFirstBit(m_shield_item[i]); + + } + mShieldsCopy[i] = mShields[i]; + } + } + + if (mBombBagLV2 != mBombBagLV2Copy) { + if (mBombBagLV2) { + dComIfGs_onItemFirstBit(dItemNo_BOMB_BAG_LV2_e); + } else { + dComIfGs_offItemFirstBit(dItemNo_BOMB_BAG_LV2_e); + } + mBombBagLV2Copy = mBombBagLV2; + } + + for (int i = 0; i < 3; i++) { + static u8 m_lv2_dun_key[] = {dItemNo_L2_KEY_PIECES1_e, dItemNo_L2_KEY_PIECES2_e, dItemNo_L2_KEY_PIECES3_e}; + if (mLV2KeyShards[i] != mLV2KeyShardsCopy[i]) { + if (mLV2KeyShards[i] != 0) { + dComIfGs_onItemFirstBit(m_lv2_dun_key[i]); + } else { + dComIfGs_offItemFirstBit(m_lv2_dun_key[i]); + } + mLV2KeyShardsCopy[i] = mLV2KeyShards[i]; + } + } + + for (int i = 0; i < 2; i++) { + static u8 m_lv5_dun_item[] = {dItemNo_TOMATO_PUREE_e, dItemNo_TASTE_e}; + if (mLV5Item[i] != mLV5ItemCopy[i]) { + if (mLV5Item[i] != 0) { + dComIfGs_onItemFirstBit(m_lv5_dun_item[i]); + } else { + dComIfGs_offItemFirstBit(m_lv5_dun_item[i]); + } + mLV5ItemCopy[i] = mLV5Item[i]; + } + } + + for (int i = 0; i < 24; i++) { + if (mGoldBug[i] != mGoldBugCopy[i]) { + if (mGoldBug[i] != 0) { + dComIfGs_onItemFirstBit(i + dItemNo_M_BEETLE_e); + } else { + dComIfGs_offItemFirstBit(i + dItemNo_M_BEETLE_e); + } + mGoldBugCopy[i] = mGoldBug[i]; + } + } + + for (int i = 0; i < 3; i++) { + if (i == 0) { + if (g_playerKind == 2) { + field_0xf9[i] = 0; + } else if (g_playerKind == 3) { + field_0xf9[i] = 1; + } else if (g_playerKind == 4) { + field_0xf9[i] = 2; + } + } + + if (field_0xf9[i] != field_0x101[i]) { + switch (i) { + case 0: + for (int j = 0; j < 8; j++) { + dComIfGs_offCollectClothes(j); + } + + if (field_0xf9[i] != 0) { + dComIfGs_setCollectClothes(field_0xf9[i] - 1); + } else { + dComIfGs_setSelectEquipClothes(dItemNo_WEAR_CASUAL_e); + } + break; + case 1: + for (int j = 0; j < 8; j++) { + dComIfGs_offCollectSword(j); + } + + if (field_0xf9[i] != 0) { + dComIfGs_setCollectSword(field_0xf9[i] - 1); + } else { + dComIfGs_setSelectEquipSword(dItemNo_NONE_e); + } + break; + case 2: + for (int j = 0; j < 8; j++) { + dComIfGs_offCollectShield(j); + } + + if (field_0xf9[i] != 0) { + dComIfGs_setCollectShield(field_0xf9[i] - 1); + } else { + dComIfGs_setSelectEquipShield(dItemNo_NONE_e); + } + break; + } + + field_0x101[i] = field_0xf9[i]; + } + } + + for (int i = 0; i < 4; i++) { + if (mFusedShadow[i] != mFusedShadowCopy[i]) { + if (mFusedShadow[i] != 0) { + dComIfGs_onCollectCrystal(i); + } else { + dComIfGs_offCollectCrystal(i); + } + mFusedShadowCopy[i] = mFusedShadow[i]; + } + } + + for (int i = 0; i < 4; i++) { + if (mMirrorShard[i] != mMirrorShardCopy[i]) { + if (mMirrorShard[i] != 0) { + dComIfGs_onCollectMirror(i); + } else { + dComIfGs_offCollectMirror(i); + } + mMirrorShardCopy[i] = mMirrorShard[i]; + } + } + + releaseJORMContext(mctx); +} +#endif dMw_DHIO_c::dMw_DHIO_c() { for (int i = 0; i < 32; i++) { @@ -163,6 +1101,226 @@ dMw_DHIO_c::dMw_DHIO_c() { } } +#if DEBUG +void dMw_DHIO_c::genMessage(JORMContext* mctx) { + static const char* name_str[] = { + "\n*****0 ラトアーヌ地方*****", + "\n*****1 ハイラル城*****", + "\n*****2 フィローネ地方*****", + "\n*****3 オルディン地方*****", + "\n*****4 ラネール地方*****", + "\n*****5 影の世界*****", + "\n*****6 環状フィールド*****", + "\n*****7 空き*****", + "\n*****8 空き*****", + "\n*****9 空き*****", + "\n*****10 空き*****", + "\n*****11 空き*****", + "\n*****12 空き*****", + "\n*****13 空き*****", + "\n*****14 空き*****", + "\n*****15 空き*****", + "\n*****16 L-1ダンジョン*****", + "\n*****17 L-2ダンジョン*****", + "\n*****18 L-3ダンジョン*****", + "\n*****19 L-4ダンジョン*****", + "\n*****20 L-5ダンジョン*****", + "\n*****21 L-6ダンジョン*****", + "\n*****22 L-7ダンジョン*****", + "\n*****23 L-8ダンジョン*****", + "\n*****24 最終ダンジョン*****", + "\n*****25 空き*****", + "\n*****26 空き*****", + "\n*****27 空き*****", + "\n*****28 空き*****", + "\n*****29 空き*****", + "\n*****30 空き*****", + "\n*****31 デフォルト*****", + }; + + for (int i = 16; i < 25; i++) { + mctx->genLabel(name_str[i], 0); + mctx->genCheckBox("マップ", &mMap[i], 1); + mctx->genCheckBox("コンパス", &mCompass[i], 1); + mctx->genCheckBox("ボス鍵", &mBossKey[i], 1); + mctx->genCheckBox("ワープ", &mPortal[i], 1); + mctx->genCheckBox("中ボス攻略", &mMidBossClear[i], 1); + mctx->genCheckBox("ボス攻略", &mBossClear[i], 1); + mctx->genCheckBox("ハートの器", &mHeartContainer[i], 1); + mctx->genCheckBox("ボスデモ", &mBossDemo[i], 1); + } +} + +void dMw_DHIO_c::bitCheck() { + JORMContext* mctx = attachJORMContext(8); + u8 var_r28; + + for (int i = 0; i < 32; i++) { + if (dComIfGs_isDungeonItemMap(i)) + var_r28 = 1; + else + var_r28 = 0; + + if (mMapCopy[i] != var_r28) { + mMapCopy[i] = mMap[i]; + mMap[i] = var_r28; + mctx->updateSlider(2, &mMap[i], 0, 0, 0); + } + + if (mMap[i] != mMapCopy[i]) { + if (mMap[i] != 0) { + dComIfGs_onDungeonItemMap(i); + } else { + dComIfGs_offDungeonItemMap(i); + } + mMapCopy[i] = mMap[i]; + } + + if (dComIfGs_isDungeonItemCompass(i)) + var_r28 = 1; + else + var_r28 = 0; + + if (mCompassCopy[i] != var_r28) { + mCompassCopy[i] = mCompass[i]; + mCompass[i] = var_r28; + mctx->updateSlider(2, &mCompass[i], 0, 0, 0); + } + + if (mCompass[i] != mCompassCopy[i]) { + if (mCompass[i] != 0) { + dComIfGs_onDungeonItemCompass(i); + } else { + dComIfGs_offDungeonItemCompass(i); + } + mCompassCopy[i] = mCompass[i]; + } + + if (dComIfGs_isDungeonItemBossKey(i)) + var_r28 = 1; + else + var_r28 = 0; + + if (mBossKeyCopy[i] != var_r28) { + mBossKeyCopy[i] = mBossKey[i]; + mBossKey[i] = var_r28; + mctx->updateSlider(2, &mBossKey[i], 0, 0, 0); + } + + if (mBossKey[i] != mBossKeyCopy[i]) { + if (mBossKey[i] != 0) { + dComIfGs_onDungeonItemBossKey(i); + } else { + dComIfGs_offDungeonItemBossKey(i); + } + mBossKeyCopy[i] = mBossKey[i]; + } + + if (dComIfGs_isDungeonItemWarp(i)) + var_r28 = 1; + else + var_r28 = 0; + + if (mPortalCopy[i] != var_r28) { + mPortalCopy[i] = mPortal[i]; + mPortal[i] = var_r28; + mctx->updateSlider(2, &mPortal[i], 0, 0, 0); + } + + if (mPortal[i] != mPortalCopy[i]) { + if (mPortal[i] != 0) { + dComIfGs_onDungeonItemWarp(i); + } else { + dComIfGs_offDungeonItemWarp(i); + } + mPortalCopy[i] = mPortal[i]; + } + + if (dComIfGs_isStageBossEnemy(i)) + var_r28 = 1; + else + var_r28 = 0; + + if (mBossClearCopy[i] != var_r28) { + mBossClearCopy[i] = mBossClear[i]; + mBossClear[i] = var_r28; + mctx->updateSlider(2, &mBossClear[i], 0, 0, 0); + } + + if (mBossClear[i] != mBossClearCopy[i]) { + if (mBossClear[i] != 0) { + dComIfGs_onStageBossEnemy(i); + } else { + dComIfGs_offStageBossEnemy(i); + } + mBossClearCopy[i] = mBossClear[i]; + } + + if (dComIfGs_isStageMiddleBoss(i)) + var_r28 = 1; + else + var_r28 = 0; + + if (mMidBossClearCopy[i] != var_r28) { + mMidBossClearCopy[i] = mMidBossClear[i]; + mMidBossClear[i] = var_r28; + mctx->updateSlider(2, &mMidBossClear[i], 0, 0, 0); + } + + if (mMidBossClear[i] != mMidBossClearCopy[i]) { + if (mMidBossClear[i] != 0) { + dComIfGs_onStageMiddleBoss(i); + } else { + dComIfGs_offStageMiddleBoss(i); + } + mMidBossClearCopy[i] = mMidBossClear[i]; + } + + if (dComIfGs_isStageLife(i)) + var_r28 = 1; + else + var_r28 = 0; + + if (mHeartContainerCopy[i] != var_r28) { + mHeartContainerCopy[i] = mHeartContainer[i]; + mHeartContainer[i] = var_r28; + mctx->updateSlider(2, &mHeartContainer[i], 0, 0, 0); + } + + if (mHeartContainer[i] != mHeartContainerCopy[i]) { + if (mHeartContainer[i] != 0) { + dComIfGs_onStageLife(i); + } else { + dComIfGs_offStageLife(i); + } + mHeartContainerCopy[i] = mHeartContainer[i]; + } + + if (dComIfGs_isStageBossDemo(i)) + var_r28 = 1; + else + var_r28 = 0; + + if (mBossDemoCopy[i] != var_r28) { + mBossDemoCopy[i] = mBossDemo[i]; + mBossDemo[i] = var_r28; + mctx->updateSlider(2, &mBossDemo[i], 0, 0, 0); + } + + if (mBossDemo[i] != mBossDemoCopy[i]) { + if (mBossDemo[i] != 0) { + dComIfGs_onStageBossDemo(i); + } else { + dComIfGs_offStageBossDemo(i); + } + mBossDemoCopy[i] = mBossDemo[i]; + } + } + + releaseJORMContext(mctx); +} +#endif + dMw_HIO_c g_mwHIO; dMw_DHIO_c g_mwDHIO; diff --git a/src/d/d_msg_flow.cpp b/src/d/d_msg_flow.cpp index 827c92bf6e..d487b8f7bd 100644 --- a/src/d/d_msg_flow.cpp +++ b/src/d/d_msg_flow.cpp @@ -2008,7 +2008,7 @@ int dMsgFlow_c::event015(mesg_flow_node_event* i_flowNode_p, fopAc_ac_c* i_speak int dMsgFlow_c::event016(mesg_flow_node_event* i_flowNode_p, fopAc_ac_c* i_speaker_p) { dShopSystem_c* shop = (dShopSystem_c*)i_speaker_p; - shop->setEventParam(*(u32*)i_flowNode_p->params); + shop->setEventParam(*(BE(u32)*)i_flowNode_p->params); u8 prm[4]; getParam(prm, i_flowNode_p->params); diff --git a/src/d/d_msg_object.cpp b/src/d/d_msg_object.cpp index 37ca9cff28..9a8f6d594a 100644 --- a/src/d/d_msg_object.cpp +++ b/src/d/d_msg_object.cpp @@ -1602,9 +1602,15 @@ u8 dMsgObject_c::isSend() { } void dMsgObject_c::readMessageGroupLocal(mDoDvdThd_mountXArchive_c** p_arcMount) { -#if TARGET_PC +#if AVOID_UB + // largest possible value msgGroup appears to be 99, but just in case + // we leave enough space to fit INT_MAX static char arcName[32]; #else + // We write at least 23 bytes into this which causes an overflow, + // but in practice arcName is followed by two bytes of padding + // at the end of .bss which mitigates the problem. + static char arcName[22]; #endif int msgGroup = dStage_stagInfo_GetMsgGroup(dComIfGp_getStage()->getStagInfo()); @@ -2141,7 +2147,7 @@ u16 dMsgObject_c::getSmellTypeMessageIDLocal() { if (smell < dItemNo_SMELL_MEDICINE_e + 1 && smell >= dItemNo_SMELL_YELIA_POUCH_e) { msgId = smell + 0x165; } else { - if (dComIfGs_getCollectSmell() != -1) { + if (dComIfGs_getCollectSmell() != 0xFF) { OS_REPORT("smell type ====> %d\n", dComIfGs_getCollectSmell()); JUT_WARN(4858, "smell type no entry!"); } diff --git a/src/d/d_msg_scrn_howl.cpp b/src/d/d_msg_scrn_howl.cpp index 58e70e84ff..07018b376d 100644 --- a/src/d/d_msg_scrn_howl.cpp +++ b/src/d/d_msg_scrn_howl.cpp @@ -19,6 +19,16 @@ #include "JSystem/J2DGraph/J2DScreen.h" #include "Z2AudioLib/Z2WolfHowlMgr.h" +// POSIX already defines a macro with this name, but we know that this specific name is +// used in TP based on assertion messages. This redefinition is scoped to this TU which +// is unlikely to ever actually need the POSIX define, so we can just redefine it. +#if defined(LINE_MAX) +#undef LINE_MAX +#endif +#define LINE_MAX 30 +//TODO: This is likely an enum value based on its name +#define PLOT_BUFFER_MAX_e 0x300 + typedef void (dMsgScrnHowl_c::*dMsgScrnHowl_cFunc)(); static dMsgScrnHowl_cFunc init_proc[5] = { diff --git a/src/d/d_particle.cpp b/src/d/d_particle.cpp index 1e41a0c7ef..2a8e75d82e 100644 --- a/src/d/d_particle.cpp +++ b/src/d/d_particle.cpp @@ -512,7 +512,7 @@ bool dPa_modelEcallBack::model_c::set(J3DModelData* i_modelData, dKy_tevstr_c co field_0x8.field_0x344 = param_1.field_0x344; typedef struct Arr{ int field_0x0[2]; - }; + } Arr; *(Arr*)&field_0x8.AmbCol = *(Arr*)¶m_1.AmbCol; *(Arr*)&field_0x8.FogCol = *(Arr*)¶m_1.FogCol; *(Arr*)&field_0x8.TevColor = *(Arr*)¶m_1.TevColor; @@ -844,11 +844,11 @@ u32 dPa_simpleEcallBack::set(cXyz const* i_pos, dKy_tevstr_c const* param_2, u8 GXColor local_60; GXColor local_64 = {0xff, 0xff, 0xff, 0xff}; GXColor local_68 = {0xff, 0xff, 0xff, 0xff}; - if (¶m_5 != NULL) { + if (IS_REF_NONNULL(param_5)) { local_64 = param_5; } - if (¶m_4 != NULL) { + if (IS_REF_NONNULL(param_4)) { local_68 = param_4; } @@ -865,11 +865,11 @@ u32 dPa_simpleEcallBack::set(cXyz const* i_pos, dKy_tevstr_c const* param_2, u8 GXColor local_70; GXColor local_74 = {0xff, 0xff, 0xff, 0xff}; GXColor local_78 = {0xff, 0xff, 0xff, 0xff}; - if (¶m_5 != NULL) { + if (IS_REF_NONNULL(param_5)) { local_74 = param_5; } - if (¶m_4 != NULL) { + if (IS_REF_NONNULL(param_4)) { local_78 = param_4; } @@ -887,13 +887,13 @@ u32 dPa_simpleEcallBack::set(cXyz const* i_pos, dKy_tevstr_c const* param_2, u8 pData->field_0x10.g = local_6c.g; pData->field_0x10.b = local_6c.b; } else { - if (¶m_4 != NULL) { + if (IS_REF_NONNULL(param_4)) { pData->field_0x0c.r = param_4.r; pData->field_0x0c.g = param_4.g; pData->field_0x0c.b = param_4.b; } - if (¶m_5 != NULL) { + if (IS_REF_NONNULL(param_5)) { pData->field_0x10.r = param_5.r; pData->field_0x10.g = param_5.g; pData->field_0x10.b = param_5.b; diff --git a/src/d/d_s_play.cpp b/src/d/d_s_play.cpp index 64811ef8e2..3ef8ea7eb2 100644 --- a/src/d/d_s_play.cpp +++ b/src/d/d_s_play.cpp @@ -669,8 +669,9 @@ static int dScnPly_Draw(dScnPly_c* i_this) { #endif dComIfG_Ccsp()->Draw(); - #if DEBUG dComIfG_Bgsp().Draw(); + + #if DEBUG dPath_Draw(); #endif @@ -1426,7 +1427,7 @@ static int phase_4(dScnPly_c* i_this) { dComIfGd_setViewport(NULL); dComIfGd_setView(NULL); - JKRExpHeap* heap = fopMsgM_createExpHeap(HEAP_SIZE(0xBB800, 0xF0000), NULL); + JKRExpHeap* heap = fopMsgM_createExpHeap(HEAP_SIZE(0xBB800, 0x177000), NULL); #if TARGET_PC heap->setName("Scene2DHeap"); #endif diff --git a/src/d/d_save.cpp b/src/d/d_save.cpp index 52daf21404..06b92994db 100644 --- a/src/d/d_save.cpp +++ b/src/d/d_save.cpp @@ -197,7 +197,11 @@ BOOL dSv_player_status_b_c::isTransformLV(int i_no) const { void dSv_horse_place_c::init() { strcpy(mName, ""); +#if TARGET_PC + mPos = BE(0.0f, 0.0f, 0.0f); +#else mPos.set(0.0f, 0.0f, 0.0f); +#endif mAngleY = 0; mSpawnId = 0; mRoomNo = 0; @@ -228,7 +232,11 @@ void dSv_player_return_place_c::set(const char* i_name, s8 i_roomNo, u8 i_status void dSv_player_field_last_stay_info_c::init() { strcpy(mName, ""); +#if TARGET_PC + mPos = BE(0.0f, 0.0f, 0.0f); +#else mPos.set(0.0f, 0.0f, 0.0f); +#endif mAngleY = 0; mLastSpawnId = 0; mRegionNo = 1; @@ -244,7 +252,11 @@ void dSv_player_field_last_stay_info_c::set(const char* i_name, const cXyz& i_po s8 i_spawn, u8 i_regionNo) { JUT_ASSERT(468, strlen(i_name) <= 7); strcpy(mName, i_name); +#if TARGET_PC + mPos = i_pos; +#else mPos.set(i_pos); +#endif mAngleY = i_angle; mLastSpawnId = i_spawn; mRegionNo = i_regionNo; @@ -269,7 +281,11 @@ BOOL dSv_player_field_last_stay_info_c::isRegionBit(int i_region) const { void dSv_player_last_mark_info_c::init() { strcpy(mName, ""); +#if TARGET_PC + mPos = BE(0.0f, 0.0f, 0.0f); +#else mPos.set(0.0f, 0.0f, 0.0f); +#endif mAngleY = 0; mRoomNo = 0; mSpawnId = 0; @@ -283,7 +299,11 @@ void dSv_player_last_mark_info_c::init() { void dSv_player_last_mark_info_c::setWarpItemData(const char* i_name, const cXyz& i_pos, s16 i_angle, s8 i_roomNo, u8 unk_4, u8 unk_5) { strcpy(mName, i_name); +#if TARGET_PC + mPos = i_pos; +#else mPos.set(i_pos); +#endif mAngleY = i_angle; mRoomNo = i_roomNo; @@ -1790,7 +1810,7 @@ int dSv_info_c::memory_to_card(char* card_ptr, int dataNum) { OS_REPORT("(dSv_reserve_c) size %d\n", sizeof(dSv_reserve_c)); OS_REPORT("(dSv_MiniGame_c) size %d\n", sizeof(dSv_MiniGame_c)); OS_REPORT("セーブ全体情報(dSv_save_c) size %d\n", sizeof(dSv_save_c)); - printf("Write size:%d\n", card_ptr - var_r29); + printf("Write size:%d\n", (int)(card_ptr - var_r29)); // Now that we've saved, reset events if needed if (lantern_not_recovered == true) { @@ -1809,11 +1829,11 @@ int dSv_info_c::memory_to_card(char* card_ptr, int dataNum) { } if (card_ptr - var_r29 > (QUEST_LOG_SIZE - 8)) { - printf("SAVE size over(%d/%d)\n", (QUEST_LOG_SIZE - 8), card_ptr - var_r29); + printf("SAVE size over(%d/%d)\n", (QUEST_LOG_SIZE - 8), (int)(card_ptr - var_r29)); return -1; } - printf("SAVE size:%d\n", card_ptr - var_r29); + printf("SAVE size:%d\n", (int)(card_ptr - var_r29)); return 0; } @@ -1859,11 +1879,11 @@ int dSv_info_c::card_to_memory(char* i_cardPtr, int i_dataNum) { OS_REPORT("########### save stage ====> %s\n", dMeter2Info_getSaveStageName()); if (i_cardPtr - var_r30 > (QUEST_LOG_SIZE - 8)) { - printf("LOAD size over(%d/%d)\n", (QUEST_LOG_SIZE - 8), i_cardPtr - var_r30); + printf("LOAD size over(%d/%d)\n", (QUEST_LOG_SIZE - 8), (int)(i_cardPtr - var_r30)); return -1; } - printf("LOAD size:%d\n", i_cardPtr - var_r30); + printf("LOAD size:%d\n", (int)(i_cardPtr - var_r30)); return 0; } @@ -1880,11 +1900,11 @@ int dSv_info_c::initdata_to_card(char* i_cardPtr, int i_dataNum) { i_cardPtr += sizeof(dSv_save_c); if (i_cardPtr - var_r30 > (QUEST_LOG_SIZE - 8)) { - printf("INIT size over %d/%d\n", (QUEST_LOG_SIZE - 8), i_cardPtr - var_r30); + printf("INIT size over %d/%d\n", (QUEST_LOG_SIZE - 8), (int)(i_cardPtr - var_r30)); return -1; } - printf("INIT size:%d\n", i_cardPtr - var_r30); + printf("INIT size:%d\n", (int)(i_cardPtr - var_r30)); return 0; } diff --git a/src/d/d_shop_system.cpp b/src/d/d_shop_system.cpp index 779fe75d4d..f1636bb093 100644 --- a/src/d/d_shop_system.cpp +++ b/src/d/d_shop_system.cpp @@ -855,7 +855,11 @@ int dShopSystem_c::seq_wait(fopAc_ac_c* param_0, dMsgFlow_c* param_1) { } inline void pos3Dto2D(Vec* a, Vec* b) { +#if TARGET_PC + mDoLib_project(a, b, {0, 0, FB_WIDTH, FB_HEIGHT}); +#else mDoLib_project(a, b); +#endif } int dShopSystem_c::seq_start(fopAc_ac_c* actor, dMsgFlow_c* i_flow) { @@ -1459,9 +1463,8 @@ bool dShopSystem_c::searchItemActor() { for (int i = 0; i < dShopSystem_sellItemMax; i++) { u32 processId = dShopSystem_itemActor[i]->getProcessID(); mItemCtrl.setItemIndex(i, processId); - mItemCtrl.setMessageIndex(i, (u16)dShopSystem_itemActor[i]->home.angle.x != 0xFFFF ? - (u16)dShopSystem_itemActor[i]->home.angle.x : - -1); + int itemFlowId = dShopSystem_itemActor[i]->getFlowNodeNum(); + mItemCtrl.setMessageIndex(i, itemFlowId); if (processId + 0x10000 == 0xFFFF) { onFlag(i); diff --git a/src/d/d_stage.cpp b/src/d/d_stage.cpp index 87fbd9e40b..9ada8b57b6 100644 --- a/src/d/d_stage.cpp +++ b/src/d/d_stage.cpp @@ -21,6 +21,10 @@ #include "m_Do/m_Do_Reset.h" #include #include +#if TARGET_PC +#include +#include +#endif void dStage_nextStage_c::set(const char* i_stage, s8 i_roomId, s16 i_point, s8 i_layer, s8 i_wipe, u8 i_speed) { @@ -1668,7 +1672,20 @@ static int dStage_playerInit(dStage_dt_c* i_stage, void* i_data, int num, void* player_data++; } if (i == num) { +#if TARGET_PC + std::vector valid_points; + valid_points.reserve(num); + player_data = player->m_entries; + for (i = 0; i < num; i++) { + valid_points.push_back(player_data->base.angle.z); + player_data++; + } + std::ranges::sort(valid_points); + DuskLog.fatal("Failed to find player start point for next stage! Requested point: {}, Valid points: [{}]", + point, fmt::join(valid_points, ", ")); +#else OS_REPORT_ERROR("プレイヤーが発見できません。[No.%d]\n切り替えの情報や処理の確認をお願いします。\n", point); +#endif } JUT_ASSERT(1636, i != num); diff --git a/src/d/d_vibration.cpp b/src/d/d_vibration.cpp index d3bd59c5cf..70a1a04779 100644 --- a/src/d/d_vibration.cpp +++ b/src/d/d_vibration.cpp @@ -25,7 +25,12 @@ u16* makedata(u16* data, u32 pattern, s32 length) { } s32 rollshift(u32 pattern, s32 length, s32 index) { +#if AVOID_UB + if (length == 0) + index = 0; +#else index %= length; +#endif return (pattern >> index) | (pattern << (length - index)); } diff --git a/src/dusk/imgui/ImGuiConsole.cpp b/src/dusk/imgui/ImGuiConsole.cpp index d23280ba80..003d5e5f62 100644 --- a/src/dusk/imgui/ImGuiConsole.cpp +++ b/src/dusk/imgui/ImGuiConsole.cpp @@ -95,6 +95,10 @@ namespace dusk { m_menuGame.draw(); m_menuTools.draw(); + ImGui::SetCursorPosX(ImGui::GetWindowWidth() - 80.0f); + ImGuiIO& io = ImGui::GetIO(); + ImGuiStringViewText(fmt::format(FMT_STRING("FPS: {:.2f}\n"), io.Framerate)); + ImGui::EndMainMenuBar(); } } diff --git a/src/dusk/imgui/ImGuiConsole.hpp b/src/dusk/imgui/ImGuiConsole.hpp index 96fd1dd7fc..47fa435626 100644 --- a/src/dusk/imgui/ImGuiConsole.hpp +++ b/src/dusk/imgui/ImGuiConsole.hpp @@ -14,6 +14,9 @@ namespace dusk { ImGuiConsole(); void draw(); + bool isBloomEnabled() { return m_menuGame.isBloomEnabled(); } + ImGuiMenuTools::CollisionViewSettings& getCollisionViewSettings() { return m_menuTools.getCollisionViewSettings(); } + static bool CheckMenuViewToggle(ImGuiKey key, bool& active); private: diff --git a/src/dusk/imgui/ImGuiMenuGame.cpp b/src/dusk/imgui/ImGuiMenuGame.cpp index a92db0cdd1..3d9af4fdc5 100644 --- a/src/dusk/imgui/ImGuiMenuGame.cpp +++ b/src/dusk/imgui/ImGuiMenuGame.cpp @@ -4,8 +4,10 @@ #include "ImGuiConsole.hpp" #include "ImGuiMenuGame.hpp" +#include #include "JSystem/JUtility/JUTGamePad.h" +#include "m_Do/m_Do_controller_pad.h" #include "m_Do/m_Do_audio.h" namespace dusk { @@ -20,6 +22,7 @@ namespace dusk { ImGui::Separator(); if (ImGui::BeginMenu("Graphics")) { + ImGui::Checkbox("Native Bloom", &m_graphicsSettings.m_enableBloom); ImGui::EndMenu(); } @@ -65,23 +68,363 @@ namespace dusk { } } + // from https://github.com/ocornut/imgui/issues/1496#issuecomment-569892444 + void ImGuiBeginGroupPanel(const char* name, const ImVec2& size) { + ImGui::BeginGroup(); + + auto cursorPos = ImGui::GetCursorScreenPos(); + auto itemSpacing = ImGui::GetStyle().ItemSpacing; + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f)); + + auto frameHeight = ImGui::GetFrameHeight(); + ImGui::BeginGroup(); + + ImVec2 effectiveSize = size; + if (size.x < 0.0f) + effectiveSize.x = ImGui::GetContentRegionAvail().x; + else + effectiveSize.x = size.x; + ImGui::Dummy(ImVec2(effectiveSize.x, 0.0f)); + + ImGui::Dummy(ImVec2(frameHeight * 0.5f, 0.0f)); + ImGui::SameLine(0.0f, 0.0f); + ImGui::BeginGroup(); + ImGui::Dummy(ImVec2(frameHeight * 0.5f, 0.0f)); + ImGui::SameLine(0.0f, 0.0f); + ImGui::TextUnformatted(name); + ImGui::SameLine(0.0f, 0.0f); + ImGui::Dummy(ImVec2(0.0, frameHeight + itemSpacing.y)); + ImGui::BeginGroup(); + + ImGui::PopStyleVar(2); + + ImGui::GetCurrentWindow()->ContentRegionRect.Max.x -= frameHeight * 0.5f; + ImGui::GetCurrentWindow()->WorkRect.Max.x -= frameHeight * 0.5f; + ImGui::GetCurrentWindow()->Size.x -= frameHeight; + + ImGui::PushItemWidth(effectiveSize.x - frameHeight); + } + + // from https://github.com/ocornut/imgui/issues/1496#issuecomment-569892444 + void ImGuiEndGroupPanel() { + ImGui::PopItemWidth(); + + auto itemSpacing = ImGui::GetStyle().ItemSpacing; + + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f)); + + auto frameHeight = ImGui::GetFrameHeight(); + + // workaround for incorrect capture of columns/table width by placing + // zero-sized dummy element in the same group, this ensure + // max X cursor position is updated correctly + ImGui::SameLine(0.0f, 0.0f); + ImGui::Dummy(ImVec2(0.0f, 0.0f)); + + ImGui::EndGroup(); + ImGui::EndGroup(); + + ImGui::SameLine(0.0f, 0.0f); + ImGui::Dummy(ImVec2(frameHeight * 0.5f, 0.0f)); + ImGui::Dummy(ImVec2(0.0, frameHeight - frameHeight * 0.5f - itemSpacing.y)); + + ImGui::EndGroup(); + + auto itemMin = ImGui::GetItemRectMin(); + auto itemMax = ImGui::GetItemRectMax(); + + ImVec2 halfFrame = ImVec2((frameHeight * 0.25f) * 0.5f, frameHeight * 0.5f); + ImGui::GetWindowDrawList()->AddRect( + ImVec2(itemMin.x + halfFrame.x, itemMin.y + halfFrame.y), + ImVec2(itemMax.x - halfFrame.x, itemMax.y), + ImColor(ImGui::GetStyleColorVec4(ImGuiCol_Border)), + halfFrame.x); + + ImGui::PopStyleVar(2); + + ImGui::GetCurrentWindow()->ContentRegionRect.Max.x += frameHeight * 0.5f; + ImGui::GetCurrentWindow()->WorkRect.Max.x += frameHeight * 0.5f; + ImGui::GetCurrentWindow()->Size.x += frameHeight; + + ImGui::Dummy(ImVec2(0.0f, 0.0f)); + + ImGui::EndGroup(); + } + + static void drawVirtualStick(const char* id, const ImVec2& stick) { + ImGui::SetCursorPos(ImVec2(ImGui::GetCursorPos().x + 5, ImGui::GetCursorPos().y)); + + ImGui::BeginChild(id, ImVec2(80, 80)); + ImDrawList* dl = ImGui::GetWindowDrawList(); + ImVec2 p = ImGui::GetCursorScreenPos(); + + float radius = ImGui::GetCurrentContext()->CurrentDpiScale * 30.0f; + ImVec2 pos = ImVec2(p.x + radius, p.y + radius); + + constexpr ImU32 stickGray = IM_COL32(150, 150, 150, 255); + constexpr ImU32 white = IM_COL32(255, 255, 255, 255); + constexpr ImU32 red = IM_COL32(230, 0, 0, 255); + + dl->AddCircleFilled(pos, radius, stickGray, 8); + dl->AddCircleFilled(ImVec2(pos.x + stick.x * (radius), pos.y + -stick.y * (radius)), 3, red); + ImGui::EndChild(); + } + void ImGuiMenuGame::windowControllerConfig() { if (!m_showControllerConfig) { return; } + // if pending for an input mapping, check to set new input + if (m_controllerConfig.m_pendingMapping != nullptr) { + s32 nativeButton = PADGetNativeButtonPressed(m_controllerConfig.m_pendingPort); + if (nativeButton != -1) { + m_controllerConfig.m_pendingMapping->nativeButton = nativeButton; + m_controllerConfig.m_pendingMapping = nullptr; + m_controllerConfig.m_pendingPort = -1; + PADBlockInput(false); + } + } + ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize; ImGui::SetNextWindowBgAlpha(0.65f); - ImGui::SetNextWindowSizeConstraints(ImVec2(500, 200), ImVec2(1000, 200)); + ImGui::SetNextWindowSizeConstraints(ImVec2(850, 400), ImVec2(850, 400)); if (!ImGui::Begin("Controller Config", nullptr, windowFlags)) { ImGui::End(); return; } + // port tabs + ImGui::BeginTabBar("##ControllerTabs"); + for (int i = PAD_1; i <= PAD_4; i++) { + if (ImGui::BeginTabItem(fmt::format("Port {}", i + 1).c_str())) { + m_controllerConfig.m_selectedPort = i; + ImGui::EndTabItem(); + } + } + ImGui::EndTabBar(); + + // if tab is changed while waiting for input, cancel pending + if (m_controllerConfig.m_pendingMapping != nullptr && + m_controllerConfig.m_pendingPort != m_controllerConfig.m_selectedPort) + { + m_controllerConfig.m_pendingMapping = nullptr; + m_controllerConfig.m_pendingPort = -1; + PADBlockInput(false); + } + + // get a list of all available controller's names + std::vector controllerList; + controllerList.push_back("None"); + for (int i = 0; i < PADCount(); i++) { + // attach index to name for unique name + controllerList.push_back(fmt::format("{}-{}", PADGetNameForControllerIndex(i), i)); + } + + // get current controller name + const char* tmpName = PADGetName(m_controllerConfig.m_selectedPort); + std::string currentName = "None"; + if (tmpName != nullptr) { + currentName = fmt::format("{}-{}", tmpName, PADGetIndexForPort(m_controllerConfig.m_selectedPort)); + } + + // controller selection combo box + bool changedController = false; + int changedControllerIndex = 0; + if (ImGui::BeginCombo("##ControllerDeviceList", currentName.c_str())) { + for (int i = 0; const auto& name : controllerList) { + if (ImGui::Selectable(name.c_str(), currentName == name)) { + changedControllerIndex = i; + changedController = true; + } + i++; + } + ImGui::EndCombo(); + } + + // handle controller change + if (changedController) { + if (changedControllerIndex > 0) { + PADSetPortForIndex(changedControllerIndex - 1, m_controllerConfig.m_selectedPort); + } + else if (changedControllerIndex == 0) { + // if "None" selected + PADClearPort(m_controllerConfig.m_selectedPort); + } + } + + // save mappings button + ImGui::SameLine(); + if (ImGui::Button("Save")) { + PADSerializeMappings(); + } + + // restore defaults button + ImGui::SameLine(); + if (ImGui::Button("Default")) { + PADRestoreDefaultMapping(m_controllerConfig.m_selectedPort); + } + + // buttons panel + constexpr float buttonSize = 40; + + ImGuiBeginGroupPanel("Buttons", ImVec2(150, 20)); + + u32 buttonCount; + PADButtonMapping* mappingList = PADGetButtonMappings(m_controllerConfig.m_selectedPort, &buttonCount); + if (mappingList != nullptr) { + for (int i = 0; i < buttonCount; i++) { + const char* btnName = PADGetButtonName(mappingList[i].padButton); + ImVec2 len = ImGui::CalcTextSize(btnName); + ImVec2 pos = ImGui::GetCursorPos(); + + ImGui::SetCursorPosY(pos.y + len.y / 4); + ImGui::SetCursorPosX(pos.x + abs(len.x - buttonSize)); + ImGui::Text("%s", btnName); + ImGui::SameLine(); + + ImGui::SetCursorPosY(pos.y); + + bool pressed = ImGui::Button(m_controllerConfig.m_isReading && m_controllerConfig.m_pendingMapping == &mappingList[i] + ? fmt::format("Press a Key...##{}", btnName).c_str() + : fmt::format("{0}##-{1}", PADGetNativeButtonName(mappingList[i].nativeButton), i).c_str(), + ImVec2(100.0f, 20.0f)); + + if (pressed) { + m_controllerConfig.m_isReading = true; + m_controllerConfig.m_pendingPort = m_controllerConfig.m_selectedPort; + m_controllerConfig.m_pendingMapping = &mappingList[i]; + PADBlockInput(true); + } + } + } + + ImGuiEndGroupPanel(); + ImGui::SameLine(); + + int port = m_controllerConfig.m_selectedPort; + + const char* stickDirections[] = { + "Up", + "Down", + "Left", + "Right", + }; + + // main stick panel + ImGuiBeginGroupPanel("Control Stick", ImVec2(150, 20)); + + drawVirtualStick("##mainStick", ImVec2{ mDoCPd_c::getStickX(port), mDoCPd_c::getStickY(port) }); + + { + for (int i = 0; i < 4; i++) { + const char* label = stickDirections[i]; + ImVec2 len = ImGui::CalcTextSize(label); + ImVec2 pos = ImGui::GetCursorPos(); + + ImGui::SetCursorPosY(pos.y + len.y / 4); + ImGui::SetCursorPosX(pos.x + abs(len.x - buttonSize)); + ImGui::Text("%s", label); + ImGui::SameLine(); + + ImGui::SetCursorPosY(pos.y); + + bool pressed = ImGui::Button(fmt::format("Temp##{}", label).c_str(), ImVec2(100.0f, 20.0f)); + } + } + + PADDeadZones* deadZones = PADGetDeadZones(port); + + if (deadZones != nullptr) { + ImGui::Text("Dead Zone"); + { + float tmp = static_cast(deadZones->stickDeadZone * 100.f) / 32767.f; + if (ImGui::DragFloat("##mainDeadZone", &tmp, 0.5f, 0.f, 100.f, "%.3f%%")) { + deadZones->stickDeadZone = static_cast((tmp / 100.f) * 32767); + } + } + } + + ImGuiEndGroupPanel(); + ImGui::SameLine(); + + // sub stick panel + ImGuiBeginGroupPanel("C Stick", ImVec2(150, 20)); + + drawVirtualStick("##subStick", ImVec2{ mDoCPd_c::getSubStickX(port), mDoCPd_c::getSubStickY(port) }); + + { + for (int i = 0; i < 4; i++) { + const char* label = stickDirections[i]; + ImVec2 len = ImGui::CalcTextSize(label); + ImVec2 pos = ImGui::GetCursorPos(); + + ImGui::SetCursorPosY(pos.y + len.y / 4); + ImGui::SetCursorPosX(pos.x + abs(len.x - buttonSize)); + ImGui::Text("%s", label); + ImGui::SameLine(); + + ImGui::SetCursorPosY(pos.y); + + bool pressed = ImGui::Button(fmt::format("Temp##sub{}", label).c_str(), ImVec2(100.0f, 20.0f)); + } + } + + if (deadZones != nullptr) { + ImGui::Text("Dead Zone"); + { + float tmp = static_cast(deadZones->substickDeadZone * 100.f) / 32767.f; + if (ImGui::DragFloat("##subDeadZone", &tmp, 0.5f, 0.f, 100.f, "%.3f%%")) { + deadZones->substickDeadZone = static_cast((tmp / 100.f) * 32767); + } + } + } + + ImGuiEndGroupPanel(); + ImGui::SameLine(); + + // Triggers Panel + ImGuiBeginGroupPanel("Triggers", ImVec2(150, 20)); + + if (deadZones != nullptr) { + ImGui::Text("L Threshold"); + { + float tmp = static_cast(deadZones->leftTriggerActivationZone * 100.f) / 32767.f; + if (ImGui::DragFloat("##LThreshold", &tmp, 0.5f, 0.f, 100.f, "%.3f%%")) { + deadZones->leftTriggerActivationZone = static_cast((tmp / 100.f) * 32767); + } + } + } + + if (deadZones != nullptr) { + ImGui::Text("R Threshold"); + { + float tmp = static_cast(deadZones->rightTriggerActivationZone * 100.f) / 32767.f; + if (ImGui::DragFloat("##RThreshold", &tmp, 0.5f, 0.f, 100.f, "%.3f%%")) { + deadZones->rightTriggerActivationZone = static_cast((tmp / 100.f) * 32767); + } + } + } + + ImGuiEndGroupPanel(); + ImGui::SameLine(); + + // Options panel + ImGuiBeginGroupPanel("Options", ImVec2(150, 20)); + + if (deadZones != nullptr) { + ImGui::Checkbox("Enable Dead Zones", &deadZones->useDeadzones); + ImGui::Checkbox("Emulate Triggers", &deadZones->emulateTriggers); + } + + ImGuiEndGroupPanel(); + ImGui::End(); } -} \ No newline at end of file +} diff --git a/src/dusk/imgui/ImGuiMenuGame.hpp b/src/dusk/imgui/ImGuiMenuGame.hpp index 3b09a62da3..a76a20f7c4 100644 --- a/src/dusk/imgui/ImGuiMenuGame.hpp +++ b/src/dusk/imgui/ImGuiMenuGame.hpp @@ -2,6 +2,7 @@ #define DUSK_IMGUI_MENUGAME_HPP #include +#include #include #include "imgui.h" @@ -11,6 +12,7 @@ namespace dusk { public: ImGuiMenuGame(); void draw(); + bool isBloomEnabled() { return m_graphicsSettings.m_enableBloom; } void windowInputViewer(); void windowControllerConfig(); @@ -24,6 +26,17 @@ namespace dusk { float m_fanfareVolume = 1.0f; } m_audioSettings; + struct { + int m_selectedPort = 0; + bool m_isReading = false; + PADButtonMapping* m_pendingMapping = nullptr; + int m_pendingPort = -1; + } m_controllerConfig; + + struct { + bool m_enableBloom = 1; + } m_graphicsSettings; + bool m_showControllerConfig = false; bool m_showInputViewer = false; diff --git a/src/dusk/imgui/ImGuiMenuTools.cpp b/src/dusk/imgui/ImGuiMenuTools.cpp index fe21a9088a..1c9e7a6f15 100644 --- a/src/dusk/imgui/ImGuiMenuTools.cpp +++ b/src/dusk/imgui/ImGuiMenuTools.cpp @@ -5,27 +5,60 @@ #include "ImGuiConsole.hpp" #include "ImGuiMenuTools.hpp" +#include "m_Do/m_Do_main.h" +#include "d/d_com_inf_game.h" +#include "d/actor/d_a_alink.h" +#include "d/actor/d_a_horse.h" + namespace dusk { ImGuiMenuTools::ImGuiMenuTools() {} void ImGuiMenuTools::draw() { + bool isToggleDevelopmentMode = false; + if (ImGui::BeginMenu("Tools")) { + if (ImGui::Checkbox("Development Mode", &m_isDevelopmentMode)) { + isToggleDevelopmentMode = true; + } + + ImGui::Separator(); + + if (ImGui::BeginMenu("Collision View")) { + ImGui::Checkbox("Enable Terrain view", &m_collisionViewSettings.m_enableTerrainView); + // can't use wireframe atm because aurora doesn't support GX_LINES + //ImGui::Checkbox("Enable wireframe view", &m_collisionViewSettings.m_enableWireframe); + ImGui::SliderFloat("Opacity##terrain", &m_collisionViewSettings.m_terrainViewOpacity, 0.0f, 100.0f); + ImGui::SliderFloat("Draw Range", &m_collisionViewSettings.m_drawRange, 0.0f, 1000.0f); + ImGui::Separator(); + ImGui::Checkbox("Enable Attack Collider view", &m_collisionViewSettings.m_enableAtView); + ImGui::Checkbox("Enable Target Collider view", &m_collisionViewSettings.m_enableTgView); + ImGui::Checkbox("Enable Push Collider view", &m_collisionViewSettings.m_enableCoView); + ImGui::SliderFloat("Opacity##colliders", &m_collisionViewSettings.m_colliderViewOpacity, 0.0f, 100.0f); + ImGui::EndMenu(); + } + ImGui::MenuItem("Process Management", "F2", &m_showProcessManagement); ImGui::MenuItem("Debug Overlay", "F3", &m_showDebugOverlay); - ImGui::MenuItem("Heaps", "F4", &m_showHeapOverlay); + ImGui::MenuItem("Heap Viewer", "F4", &m_showHeapOverlay); ImGui::MenuItem("Stub Log", "F5", &m_showStubLog); - ImGui::MenuItem("Camera", "F6", &m_showCameraOverlay); + ImGui::MenuItem("Debug Camera", "F6", &m_showCameraOverlay); ImGui::MenuItem("Map Loader", nullptr, &m_showMapLoader); + ImGui::MenuItem("Player Info", nullptr, &m_showPlayerInfo); ImGui::MenuItem("Audio Debug", "F7", &m_showAudioDebug); ImGui::EndMenu(); } + if (isToggleDevelopmentMode) { + mDoMain::developmentMode = m_isDevelopmentMode ? 1 : -1; + } + ShowDebugOverlay(); ShowCameraOverlay(); ShowProcessManager(); ShowHeapOverlay(); ShowStubLog(); ShowMapLoader(); + ShowPlayerInfo(); ShowAudioDebug(); DuskDebugPad(); // temporary, remove later @@ -93,4 +126,62 @@ namespace dusk { } ImGui::End(); } + + void ImGuiMenuTools::ShowPlayerInfo() { + if (!m_showPlayerInfo) { + return; + } + + ImGuiIO& io = ImGui::GetIO(); + ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoResize; + + ImGui::SetNextWindowBgAlpha(0.65f); + ImGui::SetNextWindowSizeConstraints(ImVec2(300, 200), ImVec2(300, 200)); + + if (ImGui::Begin("Player Info", nullptr, windowFlags)) { + daAlink_c* player = (daAlink_c*)dComIfGp_getPlayer(0); + daHorse_c* horse = dComIfGp_getHorseActor(); + + ImGui::Text("Link"); + ImGuiStringViewText( + player != nullptr + ? fmt::format("Position: {: .2f}, {: .2f}, {: .2f}\n", player->current.pos.x, player->current.pos.y, player->current.pos.z) + : "Position: ?, ?, ?\n" + ); + + ImGuiStringViewText( + player != nullptr + ? fmt::format("Angle: {0}\n", player->shape_angle.y) + : "Angle: ?\n" + ); + + ImGuiStringViewText( + player != nullptr + ? fmt::format("Speed: {0}\n", player->speedF) + : "Speed: ?\n" + ); + + ImGui::Separator(); + ImGui::Text("Epona"); + ImGuiStringViewText( + horse != nullptr + ? fmt::format("Position: {: .2f}, {: .2f}, {: .2f}\n", horse->current.pos.x, horse->current.pos.y, horse->current.pos.z) + : "Position: ?, ?, ?\n" + ); + + ImGuiStringViewText( + horse != nullptr + ? fmt::format("Angle: {0}\n", horse->shape_angle.y) + : "Angle: ?\n" + ); + + ImGuiStringViewText( + horse != nullptr + ? fmt::format("Speed: {0}\n", horse->speedF) + : "Speed: ?\n" + ); + } + + ImGui::End(); + } } \ No newline at end of file diff --git a/src/dusk/imgui/ImGuiMenuTools.hpp b/src/dusk/imgui/ImGuiMenuTools.hpp index d5905cd2f9..950e35f5b8 100644 --- a/src/dusk/imgui/ImGuiMenuTools.hpp +++ b/src/dusk/imgui/ImGuiMenuTools.hpp @@ -9,6 +9,17 @@ namespace dusk { class ImGuiMenuTools { public: + struct CollisionViewSettings { + bool m_enableTerrainView = false; + bool m_enableWireframe = false; + bool m_enableAtView = false; + bool m_enableTgView = false; + bool m_enableCoView = false; + float m_terrainViewOpacity = 50.0f; + float m_colliderViewOpacity = 50.0f; + float m_drawRange = 100.0f; + }; + ImGuiMenuTools(); void draw(); @@ -18,8 +29,11 @@ namespace dusk { void ShowHeapOverlay(); void ShowStubLog(); void ShowMapLoader(); + void ShowPlayerInfo(); void ShowAudioDebug(); + CollisionViewSettings& getCollisionViewSettings() { return m_collisionViewSettings; } + private: bool m_showDebugOverlay = false; int m_debugOverlayCorner = 0; // top-left @@ -47,6 +61,11 @@ namespace dusk { int layer = -1; bool showInternalNames = false; } m_mapLoaderInfo; + + bool m_isDevelopmentMode = false; + bool m_showPlayerInfo = false; + + CollisionViewSettings m_collisionViewSettings; }; } diff --git a/src/dusk/imgui/ImGuiStubLog.cpp b/src/dusk/imgui/ImGuiStubLog.cpp index 595ae655f6..5f77dccd38 100644 --- a/src/dusk/imgui/ImGuiStubLog.cpp +++ b/src/dusk/imgui/ImGuiStubLog.cpp @@ -56,7 +56,7 @@ namespace dusk { ImGui::SameLine(); ImGui::Checkbox("Pause", &StubLogPaused); - ImGui::Text("Line count (this frame): %llu", LineOffsets.size()); + ImGui::Text("Line count (this frame): %zu", LineOffsets.size()); ImGui::Separator(); @@ -88,4 +88,4 @@ namespace dusk { StubLogBuffer.clear(); LineOffsets.clear(); } -} \ No newline at end of file +} diff --git a/src/dusk/stubs.cpp b/src/dusk/stubs.cpp index 03573dfeef..73f4e93d80 100644 --- a/src/dusk/stubs.cpp +++ b/src/dusk/stubs.cpp @@ -1041,9 +1041,6 @@ GXDrawSyncCallback GXSetDrawSyncCallback(GXDrawSyncCallback cb) { STUB_LOG(); return cb; } -void GXDrawCylinder(u8 numEdges) { - STUB_LOG(); -} void GXWaitDrawDone(void) { STUB_LOG(); } diff --git a/src/f_pc/f_pc_priority.cpp b/src/f_pc/f_pc_priority.cpp index cbd62a4053..35f331d687 100644 --- a/src/f_pc/f_pc_priority.cpp +++ b/src/f_pc/f_pc_priority.cpp @@ -110,7 +110,7 @@ int fpcPi_Change(process_priority_class* i_procPriority, fpc_ProcID i_layerID, u int fpcPi_Handler() { process_priority_class* i_procPriority; - while (i_procPriority = fpcPi_GetFromQueue()) { + while ((i_procPriority = fpcPi_GetFromQueue())) { base_process_class* process = (base_process_class*)i_procPriority->base.mpTagData; layer_management_tag_class* pLayerTag = &process->layer_tag; line_tag* pLineTag = &process->line_tag_; diff --git a/src/m_Do/m_Do_dvd_thread.cpp b/src/m_Do/m_Do_dvd_thread.cpp index c5f982bc9d..08197ed30b 100644 --- a/src/m_Do/m_Do_dvd_thread.cpp +++ b/src/m_Do/m_Do_dvd_thread.cpp @@ -160,7 +160,7 @@ static void cb(void* param_0) { void mDoDvdThd_param_c::mainLoop() { mDoDvdThd_command_c* command; while (this->waitForKick() != 0) { - while (command = this->getFirstCommand()) { + while ((command = this->getFirstCommand())) { this->cut(command); if (mDoDvdThd::SyncWidthSound) { #if TARGET_PC diff --git a/src/m_Do/m_Do_ext.cpp b/src/m_Do/m_Do_ext.cpp index e82800ad51..8d46884de9 100644 --- a/src/m_Do/m_Do_ext.cpp +++ b/src/m_Do/m_Do_ext.cpp @@ -72,11 +72,11 @@ static void mDoExt_setJ3DData(Mtx mtx, const J3DTransformInfo* transformInfo, u1 *mtx_p++ *= sp0C.x; *mtx_p++ *= sp0C.x; *mtx_p++ *= sp0C.x; - *mtx_p++; + UNUSED(*mtx_p++); *mtx_p++ *= sp0C.y; *mtx_p++ *= sp0C.y; *mtx_p++ *= sp0C.y; - *mtx_p++; + UNUSED(*mtx_p++); *mtx_p++ *= sp0C.z; *mtx_p++ *= sp0C.z; *mtx_p++ *= sp0C.z; @@ -2199,6 +2199,9 @@ void mDoExt_invJntPacket::draw() { if (field_0x16) { J3DModelData* sp20 = field_0x10->getModelData(); +#if TARGET_PC + j3dSys.setTexture(sp20->getTexture()); +#endif J3DJoint* sp1C = sp20->getJointNodePointer(field_0x14); for (J3DMaterial* mesh = sp1C->getMesh(); mesh != NULL; mesh = mesh->getNext()) { @@ -2276,7 +2279,7 @@ int mDoExt_3Dline_c::init(u16 param_0, int param_1, BOOL param_2) { int sp20 = param_0 * 2; field_0x8[0] = JKR_NEW_ARRAY(cXyz, sp20); - if (field_0x8 == NULL) { + if (field_0x8[0] == NULL) { return 0; } @@ -2286,7 +2289,7 @@ int mDoExt_3Dline_c::init(u16 param_0, int param_1, BOOL param_2) { } field_0x10[0] = JKR_NEW_ARRAY(mDoExt_3Dline_field_0x10_c, sp20); - if (field_0x10 == NULL) { + if (field_0x10[0] == NULL) { return 0; } diff --git a/src/m_Do/m_Do_graphic.cpp b/src/m_Do/m_Do_graphic.cpp index 4d1327a8be..481bf8efff 100644 --- a/src/m_Do/m_Do_graphic.cpp +++ b/src/m_Do/m_Do_graphic.cpp @@ -680,6 +680,7 @@ void mDoGph_gInf_c::setWideZoomLightProjection(Mtx& m) { #if TARGET_PC void mDoGph_gInf_c::setWindowSize(AuroraWindowSize const& size) { JUTVideo::getManager()->setWindowSize(size); + dComIfGp_setWindow(0, 0.0f, 0.0f, getWidth(), getHeight(), 0.0f, 1.0f, 0, 2); mFader->mBox.set(0, 0, getWidth(), getHeight()); } #endif @@ -707,9 +708,7 @@ void mDoGph_BlankingOFF() {} static void dScnPly_BeforeOfPaint() { dComIfGd_reset(); - #if DEBUG dDbVw_deleteDrawPacketList(); - #endif } int mDoGph_BeforeOfDraw() { @@ -1135,6 +1134,11 @@ void mDoGph_gInf_c::bloom_c::remove() { } void mDoGph_gInf_c::bloom_c::draw() { +#if TARGET_PC + if (!dusk::g_imguiConsole.isBloomEnabled()) { + return; + } +#endif bool enabled = mEnable && m_buffer != NULL; if (mMonoColor.a != 0 || enabled) { #if TARGET_PC diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index 749d607071..20fc2a8aee 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -172,18 +172,24 @@ void main01(void) { VIWaitForRetrace(); +#if TARGET_PC + if (!aurora_begin_frame()) { + DuskLog.debug("aurora_begin_frame returned false, skipping draw this frame"); + continue; + } +#endif + // EXECUTE GAME LOGIC & RENDER // This calls mDoGph_Painter -> JFWDisplay -> GX Functions fapGm_Execute(); mDoAud_Execute(); + aurora_end_frame(); + #if TARGET_PC frameLimiter.Sleep(DUSK_FRAME_PERIOD); #endif - - //aurora_end_frame(); - } while (true); exit:; @@ -245,8 +251,8 @@ int game_main(int argc, char* argv[]) { if (parsed_arg_options.count("help")) { - printf((arg_options.help() + "\n").c_str()); - exit(0); + printf("%s", (arg_options.help() + "\n").c_str()); + exit(0); } } catch (const cxxopts::exceptions::exception& e) { @@ -310,13 +316,13 @@ bool JKRHeap::dump_sort() { return true; } +#ifdef __MWERKS__ template JHIComPortManager* JHIComPortManager::instance = nullptr; template <> JHIComPortManager* JHIComPortManager::instance = nullptr; -#ifdef __MWERKS__ template<> Z2WolfHowlMgr* JASGlobalInstance::sInstance JAS_GLOBAL_INSTANCE_INIT;