diff --git a/include/SSystem/SComponent/c_bg_s_lin_chk.h b/include/SSystem/SComponent/c_bg_s_lin_chk.h index b465cd6e4..de2d420ef 100644 --- a/include/SSystem/SComponent/c_bg_s_lin_chk.h +++ b/include/SSystem/SComponent/c_bg_s_lin_chk.h @@ -39,7 +39,7 @@ public: void SetCross(cXyz& pos) { mLin.SetEnd(pos); } cXyz& GetCross() { return mLin.GetEnd(); } - cXyz& GetCrossP() { return mLin.GetEndP(); } + cXyz* GetCrossP() { return mLin.GetEndP(); } cM3dGLin* GetLinP() { return &mLin; } void OnFrontFlag() { mFrontFlag = true; } diff --git a/include/SSystem/SComponent/c_bg_s_poly_info.h b/include/SSystem/SComponent/c_bg_s_poly_info.h index 621c070d5..b22b02724 100644 --- a/include/SSystem/SComponent/c_bg_s_poly_info.h +++ b/include/SSystem/SComponent/c_bg_s_poly_info.h @@ -60,7 +60,10 @@ public: // TODO void ChkSafe(const void*, unsigned int) const {} void ChkSetInf() const {} - void SetPolyIndex(int) {} + void SetPolyIndex(int poly_index) { + JUT_ASSERT(0x7b, 0 <= poly_index); + mPolyIndex = poly_index; + } }; // Size: 0x10 STATIC_ASSERT(sizeof(cBgS_PolyInfo) == 0x10); diff --git a/include/SSystem/SComponent/c_bg_w.h b/include/SSystem/SComponent/c_bg_w.h index d1440f033..3d00341b9 100644 --- a/include/SSystem/SComponent/c_bg_w.h +++ b/include/SSystem/SComponent/c_bg_w.h @@ -35,7 +35,7 @@ public: struct cBgD_Vtx_t; struct cBgD_Blk_t { - /* 0x0 */ u16 field_0x00; + /* 0x00 */ u16 startTri; }; struct cBgD_Ti_t { @@ -69,6 +69,15 @@ struct cBgD_Grp_t { /* 0x30 */ u32 m_info; }; // Size: 0x34 +struct cBgD_Tree_t { + /* 0x00 */ u16 mFlag; + /* 0x02 */ u16 mParent; + union { + /* 0x04 */ u16 mChild[8]; // branch + /* 0x04 */ u16 mBlock; // leaf + }; +}; // Size: 0x14 + class cBgW_NodeTree : public cM3dGAab { public: virtual ~cBgW_NodeTree(); @@ -83,7 +92,7 @@ public: /* 0x10 */ s32 m_b_num; /* 0x14 */ cBgD_Blk_t* m_b_tbl; /* 0x18 */ s32 m_tree_num; - /* 0x1C */ void* m_tree_tbl; + /* 0x1C */ cBgD_Tree_t* m_tree_tbl; /* 0x20 */ s32 m_g_num; /* 0x24 */ cBgD_Grp_t* m_g_tbl; /* 0x28 */ s32 m_ti_num; @@ -104,7 +113,13 @@ public: virtual ~cBgW_RwgElm() {} }; -class cBgW_BlkElm; +class cBgW_BlkElm { +public: + /* 0x00 */ u16 roof; + /* 0x02 */ u16 wall; + /* 0x04 */ u16 ground; +}; + class cBgW_TriElm { public: /* 0x00 */ cM3dGPla m_plane; @@ -126,6 +141,7 @@ public: MOVE_BG_e = 0x1, NO_VTX_TBL_e = 0x10, GLOBAL_e = 0x20, + UNK40_e = 0x40, LOCK_e = 0x80, }; @@ -137,8 +153,7 @@ public: void FreeArea(); void GlobalVtx(); - void SetVtx(); - + bool SetVtx(); bool SetTri(); void BlckConnect(u16*, int*, int); void MakeBlckTransMinMax(cXyz*, cXyz*); @@ -149,8 +164,8 @@ public: void MakeNodeTree(); bool ChkMemoryError(); bool Set(cBgD_t*, u32, f32(*)[3][4]); - void RwgLineCheck(u16, cBgS_LinChk*); - void LineCheckRp(cBgS_LinChk*, int); + bool RwgLineCheck(u16, cBgS_LinChk*); + bool LineCheckRp(cBgS_LinChk*, int); bool LineCheckGrpRp(cBgS_LinChk*, int, int); bool RwgGroundCheckCommon(f32, u16, cBgS_GndChk*); bool RwgGroundCheckGnd(u16, cBgS_GndChk*); @@ -247,7 +262,7 @@ public: /* 0x7C */ cXyz mTransVel; /* 0x88 */ cBgW_TriElm* pm_tri; /* 0x8C */ cBgW_RwgElm* pm_rwg; - /* 0x90 */ cXyz* pm_vtx_tbl; + /* 0x90 */ Vec* pm_vtx_tbl; /* 0x94 */ cBgD_t* pm_bgd; /* 0x98 */ cBgW_BlkElm* pm_blk; /* 0x9C */ cBgW_GrpElm* pm_grp; diff --git a/include/SSystem/SComponent/c_m3d_g_aab.h b/include/SSystem/SComponent/c_m3d_g_aab.h index b85bd6891..f629c4a60 100644 --- a/include/SSystem/SComponent/c_m3d_g_aab.h +++ b/include/SSystem/SComponent/c_m3d_g_aab.h @@ -3,6 +3,7 @@ #include "SSystem/SComponent/c_xyz.h" #include "SSystem/SComponent/c_m3d.h" +#include "SSystem/SComponent/c_m3d_g_lin.h" #include "global.h" // Axis aligned bounding box @@ -38,6 +39,9 @@ public: bool Cross(const cM3dGSph *param_1) { return cM3d_Cross_AabSph(this, param_1); } + bool Cross(const cM3dGLin *param_1) { + return cM3d_Cross_MinMaxBoxLine(GetMinP(), GetMaxP(), param_1->GetStartP(), param_1->GetEndP()); + } void CalcCenter(cXyz* pOut) const { VECAdd(&mMin, &mMax, pOut); VECScale(pOut, pOut, 0.5f); diff --git a/include/SSystem/SComponent/c_m3d_g_lin.h b/include/SSystem/SComponent/c_m3d_g_lin.h index 12492b87a..5945aa87b 100644 --- a/include/SSystem/SComponent/c_m3d_g_lin.h +++ b/include/SSystem/SComponent/c_m3d_g_lin.h @@ -26,12 +26,12 @@ public: void CalcPos(Vec*, f32) const { /* TODO */ } void CalcVec(Vec* pOut) const { VECSubtract(&this->mEnd, &this->mStart, pOut); } void SetEnd(const cXyz& pos) { mEnd = pos; } - const cXyz& GetStartP() const { return mStart; } - cXyz& GetStartP() { return mStart; } + const cXyz* GetStartP() const { return &mStart; } + cXyz* GetStartP() { return &mStart; } const cXyz& GetStart() const { return mStart; } cXyz& GetStart() { return mStart; } - const cXyz& GetEndP() const { return mEnd; } - cXyz& GetEndP() { return mEnd; } + const cXyz* GetEndP() const { return &mEnd; } + cXyz* GetEndP() { return &mEnd; } const cXyz& GetEnd() const { return mEnd; } cXyz& GetEnd() { return mEnd; } void GetLen() const { /* TODO */ } diff --git a/include/SSystem/SComponent/c_m3d_g_tri.h b/include/SSystem/SComponent/c_m3d_g_tri.h index 2b4620351..c4882fd58 100644 --- a/include/SSystem/SComponent/c_m3d_g_tri.h +++ b/include/SSystem/SComponent/c_m3d_g_tri.h @@ -46,7 +46,12 @@ public: void crossX(const Vec*, f32*) const {} void crossY(const Vec*) const {} void crossZ(const Vec*, f32*) const {} - void setBg(const Vec*, const Vec*, const Vec*, const cM3dGPla*) {} + void setBg(const Vec* a, const Vec* b, const Vec* c, const cM3dGPla* pla) { + mA = *a; + mB = *b; + mC = *c; + *((cM3dGPla*)this) = *pla; + } void setPos(const Vec*, const Vec*, const Vec*) {} void setUp() {} ~cM3dGTri() {} diff --git a/include/d/d_drawlist.h b/include/d/d_drawlist.h index a1592b8a3..96150c570 100644 --- a/include/d/d_drawlist.h +++ b/include/d/d_drawlist.h @@ -458,7 +458,6 @@ public: virtual void draw(); public: - /* 0x04 */ u32 field_0x04[3]; /* 0x10 */ Mtx mtx; }; @@ -467,7 +466,6 @@ public: virtual void draw(); public: - /* 0x04 */ u32 field_0x04[3]; /* 0x10 */ Mtx mtx; }; diff --git a/src/SSystem/SComponent/c_bg_s.cpp b/src/SSystem/SComponent/c_bg_s.cpp index 0355e87a5..3ab4cd948 100644 --- a/src/SSystem/SComponent/c_bg_s.cpp +++ b/src/SSystem/SComponent/c_bg_s.cpp @@ -165,7 +165,7 @@ void* cBgS::ConvDzb(void* work) { pbgd->m_t_tbl = (cBgD_Tri_t*)((u32)pbgd->m_t_tbl + (u32)pbgd); pbgd->m_b_tbl = (cBgD_Blk_t*)((u32)pbgd->m_b_tbl + (u32)pbgd); - pbgd->m_tree_tbl = (void*)((u32)pbgd->m_tree_tbl + (u32)pbgd); + pbgd->m_tree_tbl = (cBgD_Tree_t*)((u32)pbgd->m_tree_tbl + (u32)pbgd); pbgd->m_g_tbl = (cBgD_Grp_t*)((u32)pbgd->m_g_tbl + (u32)pbgd); pbgd->m_ti_tbl = (cBgD_Ti_t*)((u32)pbgd->m_ti_tbl + (u32)pbgd); diff --git a/src/SSystem/SComponent/c_bg_w.cpp b/src/SSystem/SComponent/c_bg_w.cpp index 5bfe65b65..fcbd010d3 100644 --- a/src/SSystem/SComponent/c_bg_w.cpp +++ b/src/SSystem/SComponent/c_bg_w.cpp @@ -5,9 +5,13 @@ #include "SSystem/SComponent/c_bg_w.h" #include "SSystem/SComponent/c_bg_s_gnd_chk.h" +#include "SSystem/SComponent/c_bg_s_lin_chk.h" +#include "SSystem/SComponent/c_bg_s_shdw_draw.h" +#include "SSystem/SComponent/c_m3d_g_tri.h" #include "JSystem/JUtility/JUTAssert.h" #include "JSystem/JKernel/JKRHeap.h" #include "m_Do/m_Do_printf.h" +#include "m_Do/m_Do_mtx.h" #include "dolphin/mtx/mtxvec.h" #include "dolphin/types.h" @@ -19,7 +23,23 @@ void ASSERT_SOLDHEAP() { /* 8024754C-8024760C .text __ct__4cBgWFv */ cBgW::cBgW() { - /* Nonmatching */ + pm_bgd = NULL; + mFlags = GLOBAL_e; + mbNeedsFullTransform = true; + mMoveCounter = 0; + mTransVel.setall(0.0f); + pm_tri = NULL; + pm_rwg = NULL; + pm_blk = NULL; + pm_node_tree = NULL; + pm_grp = NULL; + pm_vtx_tbl = NULL; + pm_base = NULL; + mDoMtx_identity(mOldMtx); + mDoMtx_identity(mCurMtx); + m_rootGrpIdx = 0xFFFF; + mWallCorrectPriority = 2; + mIgnorePlaneType = 0; } /* 8024760C-8024767C .text __dt__4cBgWFv */ @@ -51,13 +71,50 @@ void cBgW::GlobalVtx() { } /* 8024775C-80247840 .text SetVtx__4cBgWFv */ -void cBgW::SetVtx() { - /* Nonmatching */ +bool cBgW::SetVtx() { + ASSERT_SOLDHEAP(); + if (mFlags & NO_VTX_TBL_e) { + pm_vtx_tbl = NULL; + } else { + if (mFlags & MOVE_BG_e) { + pm_vtx_tbl = new Vec[pm_bgd->m_v_num]; + if (pm_vtx_tbl == NULL) + return true; + + if (mFlags & UNK40_e) { + for (s32 i = 0; i < pm_bgd->m_v_num; i++) { + pm_vtx_tbl[i].x = 0.0f; + pm_vtx_tbl[i].y = 0.0f; + pm_vtx_tbl[i].z = 0.0f; + } + } + GlobalVtx(); + } else { + pm_vtx_tbl = pm_bgd->m_v_tbl; + } + } + + return false; } /* 80247840-80247944 .text CalcPlane__4cBgWFv */ void cBgW::CalcPlane() { - /* Nonmatching */ + const cBgD_Tri_t* t_tbl = pm_bgd->m_t_tbl; + + if (pm_vtx_tbl == NULL) + return; + + if (!mbNeedsFullTransform) { + for (s32 i = 0; i < pm_bgd->m_t_num; i++) { + f32 dot = VECDotProduct(pm_tri[i].m_plane.GetNP(), &mTransVel); + pm_tri[i].m_plane.mD -= dot; + } + } else { + for (s32 i = 0; i < pm_bgd->m_t_num; i++) { + cBgW_TriElm* tri_elm = &pm_tri[i]; + cM3d_CalcPla(&pm_vtx_tbl[t_tbl[i].vtx0], &pm_vtx_tbl[t_tbl[i].vtx1], &pm_vtx_tbl[t_tbl[i].vtx2], &tri_elm->m_plane.mNormal, &tri_elm->m_plane.mD); + } + } } /* 80247944-802479D8 .text SetTri__4cBgWFv */ @@ -83,6 +140,44 @@ void cBgW::BlckConnect(u16* rwg, int* prev, int i_no) { /* 80247A24-80247BF8 .text ClassifyPlane__4cBgWFv */ void cBgW::ClassifyPlane() { /* Nonmatching */ + if (pm_vtx_tbl == NULL) + return; + + s32 i = 0; + f32 eps = G_CM3D_F_ABS_MIN; + + int roof, wall, ground; + for (; i < pm_bgd->m_b_num; i++) { + s32 startTri = pm_bgd->m_b_tbl[i].startTri; + s32 lastTri = (i != pm_bgd->m_b_num - 1) ? pm_bgd->m_b_tbl[i + 1].startTri - 1 : pm_bgd->m_t_num - 1; + + pm_blk[i].roof = 0xFFFF; + pm_blk[i].wall = 0xFFFF; + pm_blk[i].ground = 0xFFFF; + + ground = 0xFFFF; + wall = 0xFFFF; + roof = 0xFFFF; + + for (s32 j = startTri; j <= lastTri; j++) { + cBgW_TriElm* tri_elm = &pm_tri[j]; + + f32 ny = tri_elm->m_plane.mNormal.y; + if (fabsf(tri_elm->m_plane.mNormal.x) < eps && fabsf(tri_elm->m_plane.mNormal.y) < eps && fabsf(tri_elm->m_plane.mNormal.z) < eps) + continue; + + if (ny >= 0.5f) { + if (!(mIgnorePlaneType & 1)) + BlckConnect(&pm_blk[i].ground, &ground, i); + } else if (ny < -0.8f) { + if (!(mIgnorePlaneType & 4)) + BlckConnect(&pm_blk[i].roof, &roof, i); + } else { + if (!(mIgnorePlaneType & 2)) + BlckConnect(&pm_blk[i].wall, &wall, i); + } + } + } } /* 80247BF8-80247C4C .text MakeBlckTransMinMax__4cBgWFP4cXyzP4cXyz */ @@ -93,7 +188,7 @@ void cBgW::MakeBlckTransMinMax(cXyz* min, cXyz* max) { /* 80247C4C-80247CD4 .text MakeBlckMinMax__4cBgWFiP4cXyzP4cXyz */ void cBgW::MakeBlckMinMax(int i_no, cXyz* min, cXyz* max) { - cXyz * vtx = &pm_vtx_tbl[i_no]; + Vec* vtx = &pm_vtx_tbl[i_no]; if (min->x > vtx->x) min->x = vtx->x; if (max->x < vtx->x) max->x = vtx->x; if (min->y > vtx->y) min->y = vtx->y; @@ -108,8 +203,24 @@ void cBgW::MakeBlckBnd(int, cXyz*, cXyz*) { } /* 80247E48-80247F4C .text MakeNodeTreeRp__4cBgWFi */ -void cBgW::MakeNodeTreeRp(int) { +void cBgW::MakeNodeTreeRp(int i) { /* Nonmatching */ + const cBgD_Tree_t* tree = &pm_bgd->m_tree_tbl[i]; + if (tree->mFlag & 1) { + // leaf + if (tree->mBlock != 0xFFFF) { + MakeBlckBnd(tree->mBlock, &pm_node_tree[i].mMin, &pm_node_tree[i].mMax); + } + } else { + // branch + pm_node_tree[i].ClearForMinMax(); + for (s32 j = 0; j < 8; j++) { + u16 child = tree->mChild[j]; + MakeNodeTreeRp(child); + pm_node_tree[j].SetMinMax(pm_node_tree[child].mMin); + pm_node_tree[j].SetMinMax(pm_node_tree[child].mMax); + } + } } /* 80247F4C-80248078 .text MakeNodeTreeGrpRp__4cBgWFi */ @@ -122,20 +233,39 @@ void cBgW::MakeNodeTreeGrpRp(int grp_idx) { pm_grp[grp_idx].aab.SetMax(pm_node_tree[pm_bgd->m_g_tbl[grp_idx].m_tree_idx].mMax); } - u32 chld_idx = pm_bgd->m_g_tbl[grp_idx].m_first_child; + u32 child_idx = pm_bgd->m_g_tbl[grp_idx].m_first_child; while (true) { - if (chld_idx == 0xFFFF) + if (child_idx == 0xFFFF) break; - MakeNodeTreeGrpRp(chld_idx); - pm_grp[grp_idx].aab.SetMin(pm_grp[chld_idx].aab.mMin); - pm_grp[grp_idx].aab.SetMax(pm_grp[chld_idx].aab.mMax); - chld_idx = pm_bgd->m_g_tbl[chld_idx].m_next_sibling; + MakeNodeTreeGrpRp(child_idx); + pm_grp[grp_idx].aab.SetMin(pm_grp[child_idx].aab.mMin); + pm_grp[grp_idx].aab.SetMax(pm_grp[child_idx].aab.mMax); + child_idx = pm_bgd->m_g_tbl[child_idx].m_next_sibling; } } /* 80248078-80248178 .text MakeNodeTree__4cBgWFv */ void cBgW::MakeNodeTree() { - /* Nonmatching */ + if (pm_vtx_tbl == NULL) { + for (s32 i = 0; i < pm_bgd->m_g_num; i++) { + if (pm_bgd->m_g_tbl[i].m_parent == 0xFFFF) { + m_rootGrpIdx = i; + break; + } + } + } else { + for (s32 i = 0; i < pm_bgd->m_g_num; i++) { + pm_grp[i].aab.ClearForMinMax(); + } + + for (s32 i = 0; i < pm_bgd->m_g_num; i++) { + if (pm_bgd->m_g_tbl[i].m_parent == 0xFFFF) { + m_rootGrpIdx = i; + MakeNodeTreeGrpRp(i); + break; + } + } + } } /* 80248178-802481C4 .text ChkMemoryError__4cBgWFv */ @@ -151,45 +281,151 @@ bool cBgW::Set(cBgD_t*, u32, Mtx*) { } /* 80248414-802485FC .text RwgLineCheck__4cBgWFUsP11cBgS_LinChk */ -void cBgW::RwgLineCheck(u16, cBgS_LinChk*) { - /* Nonmatching */ +bool cBgW::RwgLineCheck(u16 poly_index, cBgS_LinChk* chk) { + bool ret = false; + cM3dGTri gtri; + + cM3dGLin *lin = chk->GetLinP(); + while (true) { + cBgW_TriElm* tri_elm; + cBgD_Tri_t* tri; + + tri = &pm_bgd->m_t_tbl[poly_index]; + tri_elm = &pm_tri[poly_index]; + + gtri.setBg(&pm_vtx_tbl[tri->vtx0], &pm_vtx_tbl[tri->vtx1], &pm_vtx_tbl[tri->vtx2], &tri_elm->m_plane); + bool backFlag = chk->ChkBackFlag(); + bool frontFlag = chk->ChkFrontFlag(); + + cXyz pt; + if (cM3d_Cross_LinTri(lin, >ri, &pt, frontFlag, backFlag) && !ChkPolyThrough(poly_index, chk->GetPolyPassChk())) { + chk->GetLinP()->SetEnd(pt); + chk->SetPolyIndex(poly_index); + ret = true; + } + + if (pm_rwg[poly_index].next == 0xFFFF) + break; + + poly_index = pm_rwg[poly_index].next; + } + + return ret; +} + +static void dummy() { + // 0 <= bg_index + cBgS_PolyInfo pi; + pi.SetActorInfo(-1, NULL, 0); } /* 802485FC-80248868 .text LineCheckRp__4cBgWFP11cBgS_LinChki */ -void cBgW::LineCheckRp(cBgS_LinChk*, int) { +bool cBgW::LineCheckRp(cBgS_LinChk* chk, int i) { /* Nonmatching */ + + if (!pm_node_tree[i].Cross(chk->GetLinP())) + return false; + + cBgD_Tree_t* tree = &pm_bgd->m_tree_tbl[i]; + bool ret = false; + if (tree->mFlag & 1) { + if (chk->mPreWallChk && pm_blk[tree->mBlock].wall != 0xFFFF && RwgLineCheck(pm_blk[tree->mBlock].wall, chk)) + ret = true; + if (chk->mPreGroundChk && pm_blk[tree->mBlock].ground != 0xFFFF && RwgLineCheck(pm_blk[tree->mBlock].ground, chk)) + ret = true; + if (chk->mPreRoofChk && pm_blk[tree->mBlock].roof != 0xFFFF && RwgLineCheck(pm_blk[tree->mBlock].roof, chk)) + ret = true; + return ret; + } else { + if (tree->mChild[0] != 0xFFFF && LineCheckRp(chk, tree->mChild[0])) + ret = true; + if (tree->mChild[1] != 0xFFFF && LineCheckRp(chk, tree->mChild[1])) + ret = true; + if (tree->mChild[2] != 0xFFFF && LineCheckRp(chk, tree->mChild[2])) + ret = true; + if (tree->mChild[3] != 0xFFFF && LineCheckRp(chk, tree->mChild[3])) + ret = true; + if (tree->mChild[4] != 0xFFFF && LineCheckRp(chk, tree->mChild[4])) + ret = true; + if (tree->mChild[5] != 0xFFFF && LineCheckRp(chk, tree->mChild[5])) + ret = true; + if (tree->mChild[6] != 0xFFFF && LineCheckRp(chk, tree->mChild[6])) + ret = true; + if (tree->mChild[7] != 0xFFFF && LineCheckRp(chk, tree->mChild[7])) + ret = true; + return ret; + } } /* 80248868-8024898C .text LineCheckGrpRp__4cBgWFP11cBgS_LinChkii */ -bool cBgW::LineCheckGrpRp(cBgS_LinChk*, int, int) { +bool cBgW::LineCheckGrpRp(cBgS_LinChk* chk, int grp, int depth) { /* Nonmatching */ + if (ChkGrpThrough(grp, chk->GetGrpPassChk(), depth)) + return false; + + if (!pm_grp[grp].aab.Cross(chk->GetLinP())) + return false; + + bool ret = false; + u16 tree = pm_bgd->m_g_tbl[grp].m_tree_idx; + if (tree != 0xFFFF && LineCheckRp(chk, tree)) + ret = true; + + s32 child = pm_bgd->m_g_tbl[grp].m_first_child; + while (true) { + if (child == 0xFFFF) + break; + if (LineCheckGrpRp(chk, child, depth + 1)) + ret = true; + child = pm_bgd->m_g_tbl[child].m_next_sibling; + } + + return ret; } /* 8024898C-80248AB8 .text RwgGroundCheckCommon__4cBgWFfUsP11cBgS_GndChk */ -bool cBgW::RwgGroundCheckCommon(f32 y, u16 idx, cBgS_GndChk* chk) { - /* Nonmatching */ +bool cBgW::RwgGroundCheckCommon(f32 y, u16 poly_index, cBgS_GndChk* chk) { + if (y < chk->GetPointP()->y && y > chk->GetNowY()) { + cBgD_Tri_t* tri = &pm_bgd->m_t_tbl[poly_index]; + if (cM3d_CrossY_Tri_Front(pm_vtx_tbl[tri->vtx0], pm_vtx_tbl[tri->vtx1], pm_vtx_tbl[tri->vtx2], &chk->m_pos) && !ChkPolyThrough(poly_index, chk->GetPolyPassChk())) { + chk->SetNowY(y); + chk->SetPolyIndex(poly_index); + return true; + } + } + + return false; } /* 80248AB8-80248B68 .text RwgGroundCheckGnd__4cBgWFUsP11cBgS_GndChk */ -bool cBgW::RwgGroundCheckGnd(u16 idx, cBgS_GndChk* chk) { - /* Nonmatching */ +bool cBgW::RwgGroundCheckGnd(u16 poly_index, cBgS_GndChk* chk) { bool ret = false; while (true) { - cBgW_RwgElm * rwg = &pm_rwg[idx]; - cBgW_TriElm * tri = &pm_tri[idx]; + cBgW_RwgElm* rwg = &pm_rwg[poly_index]; + cBgW_TriElm* tri = &pm_tri[poly_index]; f32 y = tri->m_plane.getCrossY_NonIsZero(*chk->GetPointP()); - if (RwgGroundCheckCommon(y, (u16)idx, chk)) + if (RwgGroundCheckCommon(y, (u16)poly_index, chk)) ret = true; - idx = rwg->next; - if (idx == 0xFFFF) + if (rwg->next == 0xFFFF) break; + poly_index = rwg->next; } return ret; } /* 80248B68-80248C38 .text RwgGroundCheckWall__4cBgWFUsP11cBgS_GndChk */ -bool cBgW::RwgGroundCheckWall(u16, cBgS_GndChk*) { - /* Nonmatching */ +bool cBgW::RwgGroundCheckWall(u16 poly_index, cBgS_GndChk* chk) { + bool ret = false; + while (true) { + cBgW_TriElm* tri = &pm_tri[poly_index]; + cBgW_RwgElm* rwg = &pm_rwg[poly_index]; + if (tri->m_plane.mNormal.y >= 0.014f && RwgGroundCheckCommon(tri->m_plane.getCrossY_NonIsZero(*chk->GetPointP()), (u16)poly_index, chk)) + ret = true; + if (rwg->next == 0xFFFF) + break; + poly_index = rwg->next; + } + return ret; } /* 80248C38-802491F4 .text GroundCrossRp__4cBgWFP11cBgS_GndChki */ @@ -216,18 +452,73 @@ void cBgW::Move() { } /* 80249584-80249698 .text RwgShdwDraw__4cBgWFiP13cBgS_ShdwDraw */ -void cBgW::RwgShdwDraw(int, cBgS_ShdwDraw*) { +void cBgW::RwgShdwDraw(int index, cBgS_ShdwDraw* shdw) { /* Nonmatching */ + while (true) { + cBgW_RwgElm* rwg = &pm_rwg[index]; + if (!ChkShdwDrawThrough(index, shdw->GetPolyPassChk())) { + const cBgD_Tri_t* tri = &pm_bgd->m_t_tbl[index]; + shdw->mCallbackFun(shdw, (cBgD_Vtx_t*)pm_vtx_tbl, tri->vtx0, tri->vtx1, tri->vtx2, &pm_tri[index].m_plane); + } + if (rwg->next == 0xFFFF) + break; + index = rwg->next; + JUT_ASSERT(0xbc6, 0 <= index && index < pm_bgd->m_t_num); + } } /* 80249698-80249840 .text ShdwDrawRp__4cBgWFP13cBgS_ShdwDrawi */ -void cBgW::ShdwDrawRp(cBgS_ShdwDraw*, int) { - /* Nonmatching */ +void cBgW::ShdwDrawRp(cBgS_ShdwDraw* shdw, int i) { + if (!pm_node_tree[i].Cross(shdw->GetBndP())) + return; + + cBgD_Tree_t* tree = &pm_bgd->m_tree_tbl[i]; + if (tree->mFlag & 1) { + if (pm_blk[tree->mBlock].wall != 0xFFFF) + RwgShdwDraw(pm_blk[tree->mBlock].wall, shdw); + if (pm_blk[tree->mBlock].roof != 0xFFFF) + RwgShdwDraw(pm_blk[tree->mBlock].roof, shdw); + if (pm_blk[tree->mBlock].ground != 0xFFFF) + RwgShdwDraw(pm_blk[tree->mBlock].ground, shdw); + } else { + if (tree->mChild[0] != 0xFFFF) + ShdwDrawRp(shdw, tree->mChild[0]); + if (tree->mChild[1] != 0xFFFF) + ShdwDrawRp(shdw, tree->mChild[1]); + if (tree->mChild[2] != 0xFFFF) + ShdwDrawRp(shdw, tree->mChild[2]); + if (tree->mChild[3] != 0xFFFF) + ShdwDrawRp(shdw, tree->mChild[3]); + if (tree->mChild[4] != 0xFFFF) + ShdwDrawRp(shdw, tree->mChild[4]); + if (tree->mChild[5] != 0xFFFF) + ShdwDrawRp(shdw, tree->mChild[5]); + if (tree->mChild[6] != 0xFFFF) + ShdwDrawRp(shdw, tree->mChild[6]); + if (tree->mChild[7] != 0xFFFF) + ShdwDrawRp(shdw, tree->mChild[7]); + } } /* 80249840-80249904 .text ShdwDrawGrpRp__4cBgWFP13cBgS_ShdwDrawi */ -void cBgW::ShdwDrawGrpRp(cBgS_ShdwDraw*, int) { +void cBgW::ShdwDrawGrpRp(cBgS_ShdwDraw* shdw, int grp_idx) { /* Nonmatching */ + if (!pm_grp[grp_idx].aab.Cross(shdw->GetBndP())) + return; + + u32 tree_idx = pm_bgd->m_g_tbl[grp_idx].m_tree_idx; + if (tree_idx != 0xFFFF) { + ShdwDrawRp(shdw, tree_idx); + } + + u32 child_idx = pm_bgd->m_g_tbl[grp_idx].m_first_child; + while (true) { + if (child_idx == 0xFFFF) + break; + ShdwDrawGrpRp(shdw, child_idx); + child_idx = pm_bgd->m_g_tbl[child_idx].m_next_sibling; + } + } /* 80249904-8024990C .text ChkPolyThrough__4cBgWFiP16cBgS_PolyPassChk */ @@ -272,8 +563,7 @@ void cBgW::GetTriPnt(int i_no, cXyz* p0, cXyz* p1, cXyz* p2) const { } /* 80249B64-80249BA0 .text GetTopUnder__4cBgWCFPfPf */ -void cBgW::GetTopUnder(f32* min, f32* max) const { - /* Nonmatching */ - *min = pm_grp[m_rootGrpIdx].aab.mMin.y; - *max = pm_grp[m_rootGrpIdx].aab.mMax.y; +void cBgW::GetTopUnder(f32* max, f32* min) const { + *min = pm_grp[m_rootGrpIdx].aab.GetMinP()->y; + *max = pm_grp[m_rootGrpIdx].aab.GetMaxP()->y; } diff --git a/src/SSystem/SComponent/c_cc_d.cpp b/src/SSystem/SComponent/c_cc_d.cpp index 5d88b46d5..01dd30c97 100644 --- a/src/SSystem/SComponent/c_cc_d.cpp +++ b/src/SSystem/SComponent/c_cc_d.cpp @@ -358,17 +358,17 @@ bool cCcD_CpsAttr::GetNVec(const cXyz& vec, cXyz* dst) const { return false; cXyz p0_v; - VECSubtract(&vec, &GetStartP(), &p0_v); + VECSubtract(&vec, GetStartP(), &p0_v); f32 dot = p0_v.getDotProduct(lin) / len; cXyz pt; if (dot < 0.0f) { - pt.set(GetStartP()); + pt.set(*GetStartP()); } else if (dot > 1.0f) { - pt.set(GetEndP()); + pt.set(*GetEndP()); } else { VECScale(&lin, &lin, dot); - VECAdd(&lin, &GetStartP(), &pt); + VECAdd(&lin, GetStartP(), &pt); } VECSubtract(&vec, &pt, dst); diff --git a/src/SSystem/SComponent/c_m3d.cpp b/src/SSystem/SComponent/c_m3d.cpp index 2d3897e9d..973c1f628 100644 --- a/src/SSystem/SComponent/c_m3d.cpp +++ b/src/SSystem/SComponent/c_m3d.cpp @@ -179,7 +179,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 @@ -217,22 +217,22 @@ int cM3d_Check_LinLin(const cM3dGLin* lin_a, const cM3dGLin* lin_b, f32* dst_a, /* 8024ACA8-8024AE3C .text cM3d_Cross_LinPla__FPC8cM3dGLinPC8cM3dGPlaP3Vecbb */ 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->GetEndP(); + *dst = *lin->GetEndP(); 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->GetEndP(); + *dst = *lin->GetEndP(); return false; } } @@ -540,22 +540,22 @@ int cM3d_2PlaneCrossLine(const cM3dGPla& pPlaneA, const cM3dGPla& pPlaneB, cM3dG 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()); VECScale(&tmp, &tmp, scale); - VECAdd(&pLinOut->GetStartP(), &tmp, &pLinOut->GetEndP()); + VECAdd(pLinOut->GetStartP(), &tmp, pLinOut->GetEndP()); return 1; } } @@ -585,13 +585,13 @@ f32 cM3d_lineVsPosSuisenCross(const cM3dGLin* g_lin, const Vec* pt, Vec* dst) { } Vec p0_v; - VECSubtract(pt, &g_lin->GetStartP(), &p0_v); + VECSubtract(pt, g_lin->GetStartP(), &p0_v); f32 dot = VECDotProduct(&p0_v, &lin); f32 v = dot / len; Vec ret; VECScale(&lin, &ret, v); - VECAdd(&ret, &g_lin->GetStartP(), dst); + VECAdd(&ret, g_lin->GetStartP(), dst); return v; } diff --git a/src/d/actor/d_a_arrow.cpp b/src/d/actor/d_a_arrow.cpp index 9c49cb6ed..6dab73289 100644 --- a/src/d/actor/d_a_arrow.cpp +++ b/src/d/actor/d_a_arrow.cpp @@ -754,7 +754,7 @@ BOOL daArrow_c::procMove() { setStopActorMatrix(); } } else if (dComIfG_Bgsp()->LineCross(&mLinChk)) { - cXyz* linEnd = &mLinChk.GetLinP()->GetEndP(); + cXyz* linEnd = mLinChk.GetLinP()->GetEndP(); field_0x6a8 = *linEnd; current.pos = *linEnd - (speed * 0.25f); diff --git a/src/d/actor/d_a_player_main.cpp b/src/d/actor/d_a_player_main.cpp index 7c06be9d3..23fb0c866 100644 --- a/src/d/actor/d_a_player_main.cpp +++ b/src/d/actor/d_a_player_main.cpp @@ -3669,7 +3669,7 @@ BOOL daPy_lk_c::playerDelete() { mDoAud_seDeleteObject(&mSwordTopPos); mDoAud_seDeleteObject(&mRopePos); mDoAud_seDeleteObject(&m338C.field_0x08); - mDoAud_seDeleteObject(&mFanWindCps.GetEndP()); + mDoAud_seDeleteObject(mFanWindCps.GetEndP()); for (i = 0; i < (int)ARRAY_SIZE(m_anm_heap_under); i++) { mDoExt_destroySolidHeap(m_anm_heap_under[i].mpAnimeHeap); diff --git a/src/d/d_drawlist.cpp b/src/d/d_drawlist.cpp index 3a94f6540..abd8e662c 100644 --- a/src/d/d_drawlist.cpp +++ b/src/d/d_drawlist.cpp @@ -1556,10 +1556,10 @@ void dDlst_alphaVolPacket::draw() { GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GXClearVtxDesc(); GXSetVtxDesc(GX_VA_POS, GX_INDEX8); - GXSetArray(GX_VA_POS, (void*)l_simpleShadowPos, ARRAY_SIZE(l_simpleShadowPos)); + GXSetArray(GX_VA_POS, (void*)l_simpleShadowPos, 0x0C); GXLoadPosMtxImm(mtx, GX_PNMTX0); GXSetCurrentMtx(GX_PNMTX0); - GXCallDisplayList(l_frontMat, 0x40); + GXCallDisplayList(l_frontMat, 0x40) GXCallDisplayList(l_shadowVolumeDL, 0x40); GXCallDisplayList(l_backSubMat, 0x20); GXCallDisplayList(l_shadowVolumeDL, 0x40); @@ -1576,7 +1576,7 @@ void dDlst_alphaInvVolPacket::draw() { GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GXClearVtxDesc(); GXSetVtxDesc(GX_VA_POS, GX_INDEX8); - GXSetArray(GX_VA_POS, (void*)l_simpleShadowPos, ARRAY_SIZE(l_simpleShadowPos)); + GXSetArray(GX_VA_POS, (void*)l_simpleShadowPos, 0x0C); GXLoadPosMtxImm(mtx, GX_PNMTX0); GXSetCurrentMtx(GX_PNMTX0); GXSetTevColor(GX_TEVREG0, g_whiteColor);