summaryrefslogtreecommitdiff
path: root/src/d/d_bg_w.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/d/d_bg_w.cpp')
-rw-r--r--src/d/d_bg_w.cpp1315
1 files changed, 825 insertions, 490 deletions
diff --git a/src/d/d_bg_w.cpp b/src/d/d_bg_w.cpp
index d0f5a718eb..1407b38b15 100644
--- a/src/d/d_bg_w.cpp
+++ b/src/d/d_bg_w.cpp
@@ -9,11 +9,43 @@
#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"
+#if DEBUG
+#include "d/d_debug_viewer.h"
+#endif
+
+#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 +59,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 +95,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*)new Vec[pm_bgd->m_v_num];
if (pm_vtx_tbl == NULL) {
+ OS_REPORT_ERROR("c_bg_w.cpp[%d] メモリ確保できません。\n", 272);
return true;
}
@@ -103,22 +164,36 @@ 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++) {
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
+ }
}
}
}
bool cBgW::SetTri() {
+ #if DEBUG
+ ASSERT_SOLDHEAP();
+ #endif
+
pm_tri = new cBgW_TriElm[pm_bgd->m_t_num];
if (pm_tri == NULL) {
+ OS_REPORT_ERROR("c_bg_w.cpp[%d] メモリ確保できません\n", 353);
return true;
}
@@ -130,17 +205,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() {
@@ -173,7 +248,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 {
@@ -184,117 +259,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) {
Vec* 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;
}
}
@@ -333,6 +401,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;
@@ -340,7 +412,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;
@@ -352,38 +424,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 = new 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 = new 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 = new 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 = new cBgW_GrpElm[pm_bgd->m_g_num];
if (pm_grp == NULL) {
+ OS_REPORT_ERROR("c_bg_w.cpp[%d] メモリ確保できません\n", 958);
FreeArea();
return true;
}
@@ -398,62 +475,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;
}
@@ -462,7 +550,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;
}
}
@@ -470,30 +558,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;
@@ -502,19 +591,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;
}
}
@@ -523,55 +616,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;
}
@@ -579,12 +678,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;
}
@@ -596,33 +695,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;
}
@@ -632,38 +734,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;
}
@@ -682,63 +784,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) {
@@ -753,16 +872,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;
}
@@ -774,79 +895,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) {
@@ -891,31 +1024,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);
}
@@ -929,26 +1066,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;
}
@@ -964,6 +1105,111 @@ bool cBgW::ChkMoveBg() const {
return mFlags & MOVE_BG_e;
}
+#if DEBUG
+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, (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);
+}
+#endif
+
dBgW::dBgW() {
m_crr_func = NULL;
m_ride_callback = NULL;
@@ -976,41 +1222,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()) {
@@ -1119,10 +1368,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;
@@ -1130,9 +1379,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 =
@@ -1143,12 +1392,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,
@@ -1156,21 +1405,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,
@@ -1178,15 +1426,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();
}
@@ -1204,27 +1452,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;
}
@@ -1232,7 +1487,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;
}
}
@@ -1240,28 +1495,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;
@@ -1270,8 +1528,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 {
@@ -1286,24 +1544,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);
@@ -1312,52 +1570,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;
}
}
}
@@ -1367,52 +1640,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;
}
@@ -1546,8 +1831,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;
@@ -1555,9 +1840,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 =
@@ -1568,12 +1853,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,
@@ -1581,21 +1866,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,
@@ -1603,15 +1887,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();
}
@@ -1630,46 +1913,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;
}
@@ -1678,7 +1973,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;
}
}
@@ -1686,31 +1981,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;
@@ -1719,50 +2017,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;
}
@@ -1771,7 +2081,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;
}
}
@@ -1779,31 +2089,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;
@@ -1812,38 +2125,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;
}
@@ -1852,90 +2168,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;
}
@@ -1947,34 +2263,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;
@@ -1983,35 +2301,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) {
@@ -2066,7 +2388,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;
}
}
@@ -2083,26 +2406,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;
}
@@ -2123,7 +2455,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 {
@@ -2134,10 +2466,13 @@ dBgW* dBgW_NewSet(cBgD_t* pbgd, u32 flags, Mtx* pbase_mtx) {
dBgW* nw = 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;
}