mirror of
https://github.com/zeldaret/tww.git
synced 2026-08-20 13:45:14 -04:00
d_bg_w progress
This commit is contained in:
+241
-31
@@ -7,8 +7,10 @@
|
||||
#include "d/d_bg_s.h"
|
||||
#include "d/d_bg_s_acch.h"
|
||||
#include "d/d_bg_s_sph_chk.h"
|
||||
#include "SSystem/SComponent/c_m2d.h"
|
||||
#include "SSystem/SComponent/c_math.h"
|
||||
|
||||
#define CHECK_FLOAT_CLASS(line, x) JUT_ASSERT(line, !(((sizeof(x) == sizeof(float)) ? __fpclassifyf((float)(x)) : __fpclassifyd((double)(x)) ) == 1));
|
||||
#define CHECK_FLOAT_CLASS(line, x) JUT_ASSERT(line, !(fpclassify(x) == 1));
|
||||
|
||||
/* 800A5C3C-800A5CA8 .text __ct__4dBgWFv */
|
||||
dBgW::dBgW() {
|
||||
@@ -39,8 +41,218 @@ void dBgW::positionWallCorrect(dBgS_Acch* acch, f32 dist, cM3dGPla& plane, cXyz*
|
||||
}
|
||||
|
||||
/* 800A5E64-800A6DF8 .text RwgWallCorrect__4dBgWFP9dBgS_AcchUs */
|
||||
bool dBgW::RwgWallCorrect(dBgS_Acch*, u16) {
|
||||
/* Nonmatching */
|
||||
bool dBgW::RwgWallCorrect(dBgS_Acch* pwi, u16 i_poly_idx) {
|
||||
bool correct = false;
|
||||
|
||||
while (true) {
|
||||
cBgW_RwgElm* rwg_elm = &pm_rwg[i_poly_idx];
|
||||
|
||||
if (!ChkPolyThrough(i_poly_idx, pwi->GetPolyPassChk())) {
|
||||
cBgW_TriElm* tri = &pm_tri[i_poly_idx];
|
||||
|
||||
f32 sp68 = std::sqrtf(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->next != 0xFFFF) {
|
||||
i_poly_idx = rwg_elm->next;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
f32 sp6C = 1.0f / sp68;
|
||||
cBgD_Tri_t* tri_data = &pm_bgd->m_t_tbl[i_poly_idx];
|
||||
int cir_index = 0;
|
||||
|
||||
while (cir_index < pwi->GetTblSize()) {
|
||||
f32 sp78 = sp6C * pwi->GetWallR(cir_index);
|
||||
Vec sp50;
|
||||
sp50.x = sp78 * tri->m_plane.GetNP()->x;
|
||||
sp50.y = 0.0f;
|
||||
sp50.z = sp78 * tri->m_plane.GetNP()->z;
|
||||
|
||||
f32 sp7C;
|
||||
if (!pwi->ChkWallHDirect(cir_index)) {
|
||||
sp7C =
|
||||
(pwi->GetWallAddY(sp50, cir_index) + (pwi->GetPos()->y + pwi->GetWallH(cir_index))) -
|
||||
pwi->GetSpeedY();
|
||||
} else {
|
||||
sp7C = pwi->GetWallHDirect(cir_index);
|
||||
}
|
||||
|
||||
f32 sp5C[3];
|
||||
sp5C[0] = pm_vtx_tbl[tri_data->vtx0].y - sp7C;
|
||||
sp5C[1] = pm_vtx_tbl[tri_data->vtx1].y - sp7C;
|
||||
sp5C[2] = pm_vtx_tbl[tri_data->vtx2].y - sp7C;
|
||||
|
||||
if ((!(sp5C[0] > 0.0f) || !(sp5C[1] > 0.0f) || !(sp5C[2] > 0.0f)) &&
|
||||
(!(sp5C[0] < 0.0f) || !(sp5C[1] < 0.0f) || !(sp5C[2] < 0.0f)))
|
||||
{
|
||||
int sp8C = 0;
|
||||
if (cM3d_IsZero(sp5C[0])) {
|
||||
sp8C++;
|
||||
}
|
||||
if (cM3d_IsZero(sp5C[1])) {
|
||||
sp8C++;
|
||||
}
|
||||
if (cM3d_IsZero(sp5C[2])) {
|
||||
sp8C++;
|
||||
}
|
||||
|
||||
int sp80, sp84, sp88;
|
||||
if (sp8C != 1) {
|
||||
if ((sp5C[0] > 0.0f && (sp5C[1] <= 0.0f) && (sp5C[2] <= 0.0f)) ||
|
||||
(sp5C[0] < 0.0f && (sp5C[1] >= 0.0f) && (sp5C[2] >= 0.0f)))
|
||||
{
|
||||
sp80 = 0;
|
||||
sp84 = 1;
|
||||
sp88 = 2;
|
||||
} else if ((sp5C[1] > 0.0f && (sp5C[0] <= 0.0f) && (sp5C[2] <= 0.0f)) ||
|
||||
(sp5C[1] < 0.0f && (sp5C[0] >= 0.0f) && (sp5C[2] >= 0.0f)))
|
||||
{
|
||||
sp80 = 1;
|
||||
sp84 = 0;
|
||||
sp88 = 2;
|
||||
} else {
|
||||
sp80 = 2;
|
||||
sp84 = 0;
|
||||
sp88 = 1;
|
||||
}
|
||||
|
||||
f32 sp90 = sp5C[sp80] - sp5C[sp84];
|
||||
f32 sp94 = sp5C[sp80] - sp5C[sp88];
|
||||
if (!cM3d_IsZero(sp90) && !cM3d_IsZero(sp94)) {
|
||||
f32 sp98 = -sp5C[sp84] / sp90;
|
||||
f32 sp9C = -sp5C[sp88] / sp94;
|
||||
|
||||
f32 vtx0_x = pm_vtx_tbl[tri_data->vtx0].x;
|
||||
f32 vtx0_z = pm_vtx_tbl[tri_data->vtx0].z;
|
||||
f32 vtx1_x = pm_vtx_tbl[tri_data->vtx1].x;
|
||||
f32 vtx1_z = pm_vtx_tbl[tri_data->vtx1].z;
|
||||
f32 vtx2_x = pm_vtx_tbl[tri_data->vtx2].x;
|
||||
f32 vtx2_z = pm_vtx_tbl[tri_data->vtx2].z;
|
||||
|
||||
f32 cx0, cy0, cx1, cy1;
|
||||
if (sp80 == 0) {
|
||||
cx0 = vtx1_x + sp98 * (vtx0_x - vtx1_x);
|
||||
cy0 = vtx1_z + sp98 * (vtx0_z - vtx1_z);
|
||||
cx1 = vtx2_x + sp9C * (vtx0_x - vtx2_x);
|
||||
cy1 = vtx2_z + sp9C * (vtx0_z - vtx2_z);
|
||||
} else if (sp80 == 1) {
|
||||
cx0 = vtx0_x + sp98 * (vtx1_x - vtx0_x);
|
||||
cy0 = vtx0_z + sp98 * (vtx1_z - vtx0_z);
|
||||
cx1 = vtx2_x + sp9C * (vtx1_x - vtx2_x);
|
||||
cy1 = vtx2_z + sp9C * (vtx1_z - vtx2_z);
|
||||
} else {
|
||||
cx0 = vtx0_x + sp98 * (vtx2_x - vtx0_x);
|
||||
cy0 = vtx0_z + sp98 * (vtx2_z - vtx0_z);
|
||||
cx1 = vtx1_x + sp9C * (vtx2_x - vtx1_x);
|
||||
cy1 = vtx1_z + sp9C * (vtx2_z - vtx1_z);
|
||||
}
|
||||
|
||||
cx0 += sp50.x;
|
||||
cy0 += sp50.z;
|
||||
cx1 += sp50.x;
|
||||
cy1 += sp50.z;
|
||||
|
||||
f32 spC8, spCC, spD0;
|
||||
bool sp107 = cM3d_Len2dSqPntAndSegLine(
|
||||
pwi->GetCx(), pwi->GetCz(),
|
||||
cx0, cy0,
|
||||
cx1, cy1,
|
||||
&spCC, &spD0,
|
||||
&spC8
|
||||
);
|
||||
|
||||
f32 spD4 = spCC - pwi->GetCx();
|
||||
f32 spD8 = spD0 - pwi->GetCz();
|
||||
f32 spDC = pwi->GetWallRR(cir_index);
|
||||
|
||||
if (!(spC8 > spDC) && !(spD4 * sp50.x + spD8 * sp50.z < 0.0f)) {
|
||||
if (sp107 == 1) {
|
||||
positionWallCorrect(pwi, sp6C, tri->m_plane, pwi->GetPos(),
|
||||
std::sqrtf(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)
|
||||
);
|
||||
correct = true;
|
||||
} else {
|
||||
cx0 -= sp50.x;
|
||||
cy0 -= sp50.z;
|
||||
cx1 -= sp50.x;
|
||||
cy1 -= sp50.z;
|
||||
|
||||
f32 spE0 = cM3d_Len2dSq(cx0, cy0, pwi->GetPos()->x, pwi->GetPos()->z);
|
||||
f32 spE4 = cM3d_Len2dSq(cx1, cy1, pwi->GetPos()->x, pwi->GetPos()->z);
|
||||
|
||||
f32 onx = -tri->m_plane.GetNP()->x;
|
||||
f32 ony = -tri->m_plane.GetNP()->z;
|
||||
|
||||
JUT_ASSERT(463, !(cM3d_IsZero(onx) && cM3d_IsZero(ony)));
|
||||
|
||||
if (spE0 < spE4) {
|
||||
if (!(spE0 > spDC) && !(std::fabsf(spE0 - spDC) < 0.008f)) {
|
||||
f32 spF0, spF4;
|
||||
cM2d_CrossCirLin(*pwi->GetWallCirP(cir_index), cx0, cy0,
|
||||
onx, ony, &spF0, &spF4);
|
||||
pwi->GetPos()->x += cx0 - spF0;
|
||||
pwi->GetPos()->z += cy0 - spF4;
|
||||
|
||||
CHECK_FLOAT_CLASS(484, pwi->GetPos()->x);
|
||||
CHECK_FLOAT_CLASS(485, 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)
|
||||
);
|
||||
correct = true;
|
||||
pwi->SetWallHit();
|
||||
}
|
||||
} else if (!(spE4 > spDC) && !(std::fabsf(spE4 - spDC) < 0.008f)) {
|
||||
f32 spF8, spFC;
|
||||
cM2d_CrossCirLin(*pwi->GetWallCirP(cir_index), cx1, cy1,
|
||||
onx, ony, &spF8, &spFC);
|
||||
pwi->GetPos()->x += cx1 - spF8;
|
||||
pwi->GetPos()->z += cy1 - spFC;
|
||||
|
||||
CHECK_FLOAT_CLASS(524, pwi->GetPos()->x);
|
||||
CHECK_FLOAT_CLASS(525, 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)
|
||||
);
|
||||
correct = true;
|
||||
pwi->SetWallHit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cir_index++;
|
||||
}
|
||||
}
|
||||
|
||||
if (rwg_elm->next == 0xFFFF) {
|
||||
break;
|
||||
}
|
||||
|
||||
i_poly_idx = rwg_elm->next;
|
||||
}
|
||||
|
||||
return correct;
|
||||
}
|
||||
|
||||
/* 800A6DF8-800A7004 .text WallCorrectRp__4dBgWFP9dBgS_Acchi */
|
||||
@@ -80,7 +292,6 @@ bool dBgW::WallCorrectRp(dBgS_Acch* acch, int i) {
|
||||
|
||||
/* 800A7004-800A7120 .text WallCorrectGrpRp__4dBgWFP9dBgS_Acchii */
|
||||
bool dBgW::WallCorrectGrpRp(dBgS_Acch* acch, int grp_id, int depth) {
|
||||
/* Nonmatching */
|
||||
if (ChkGrpThrough(grp_id, acch->GetGrpPassChk(), depth))
|
||||
return false;
|
||||
|
||||
@@ -108,8 +319,6 @@ bool dBgW::WallCorrectGrpRp(dBgS_Acch* acch, int grp_id, int depth) {
|
||||
|
||||
/* 800A7120-800A72E0 .text RwgRoofChk__4dBgWFUsP12dBgS_RoofChk */
|
||||
bool dBgW::RwgRoofChk(u16 poly_index, dBgS_RoofChk* chk) {
|
||||
/* Nonmatching */
|
||||
|
||||
bool ret = false;
|
||||
while (true) {
|
||||
f32 y;
|
||||
@@ -134,7 +343,6 @@ bool dBgW::RwgRoofChk(u16 poly_index, dBgS_RoofChk* chk) {
|
||||
|
||||
/* 800A72E0-800A7514 .text RoofChkRp__4dBgWFP12dBgS_RoofChki */
|
||||
bool dBgW::RoofChkRp(dBgS_RoofChk* chk, int i) {
|
||||
/* Nonmatching */
|
||||
cBgW_NodeTree* node = &m_nt_tbl[i];
|
||||
// if (!node->CrossY(chk->GetPosP()) || !node->UnderPlaneYUnder(chk->GetNowY()) || node->TopPlaneYUnder(chk->GetPosP()->y))
|
||||
if (!node->CrossY(chk->GetPosP()) || !(node->GetMinY() < chk->GetNowY()) || node->TopPlaneYUnder(chk->GetPosP()->y))
|
||||
@@ -198,8 +406,6 @@ bool dBgW::RoofChkGrpRp(dBgS_RoofChk* chk, int grp_id, int depth) {
|
||||
|
||||
/* 800A767C-800A783C .text RwgSplGrpChk__4dBgWFUsP14dBgS_SplGrpChk */
|
||||
bool dBgW::RwgSplGrpChk(u16 poly_index, dBgS_SplGrpChk* chk) {
|
||||
/* Nonmatching */
|
||||
|
||||
bool ret = false;
|
||||
while (true) {
|
||||
f32 y;
|
||||
@@ -286,36 +492,35 @@ bool dBgW::SplGrpChkGrpRp(dBgS_SplGrpChk* chk, int grp_id, int depth) {
|
||||
}
|
||||
|
||||
/* 800A7BDC-800A7DCC .text RwgSphChk__4dBgWFUsP11dBgS_SphChkPv */
|
||||
bool dBgW::RwgSphChk(u16 poly_index, dBgS_SphChk* chk, void* user) {
|
||||
/* Nonmatching */
|
||||
cM3dGTri gtri;
|
||||
bool dBgW::RwgSphChk(u16 i_poly_idx, dBgS_SphChk* i_sphchk, void* i_data) {
|
||||
cM3dGTri tri;
|
||||
cBgW_RwgElm* rwg;
|
||||
cBgD_Tri_t* tri_t;
|
||||
|
||||
bool ret = false;
|
||||
bool chk = false;
|
||||
while (true) {
|
||||
if (!ChkPolyThrough(poly_index, chk->GetPolyPassChk())) {
|
||||
cBgW_TriElm* tri_elm;
|
||||
cBgD_Tri_t* tri;
|
||||
rwg = &pm_rwg[i_poly_idx];
|
||||
if (!ChkPolyThrough(i_poly_idx, i_sphchk->GetPolyPassChk())) {
|
||||
tri_t = &pm_bgd->m_t_tbl[i_poly_idx];
|
||||
tri.setBg(&pm_vtx_tbl[tri_t->vtx0], &pm_vtx_tbl[tri_t->vtx1],
|
||||
&pm_vtx_tbl[tri_t->vtx2], &pm_tri[i_poly_idx].m_plane);
|
||||
|
||||
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);
|
||||
if (cM3d_Cross_SphTri(chk, >ri)) {
|
||||
if (chk->mpCallback != NULL) {
|
||||
chk->mpCallback(chk, (cBgD_Vtx_t*)pm_vtx_tbl, tri->vtx0, tri->vtx1, tri->vtx2, &pm_tri[poly_index].m_plane, user);
|
||||
if (i_sphchk->cross(&tri)) {
|
||||
if (i_sphchk->mpCallback != NULL) {
|
||||
i_sphchk->mpCallback(i_sphchk, pm_vtx_tbl, tri_t->vtx0, tri_t->vtx1,
|
||||
tri_t->vtx2, &pm_tri[i_poly_idx].m_plane, i_data);
|
||||
}
|
||||
chk->SetPolyIndex(poly_index);
|
||||
ret = true;
|
||||
i_sphchk->SetPolyIndex(i_poly_idx);
|
||||
chk = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (pm_rwg[poly_index].next == 0xFFFF)
|
||||
if (rwg->next == 0xFFFF)
|
||||
break;
|
||||
|
||||
poly_index = pm_rwg[poly_index].next;
|
||||
i_poly_idx = rwg->next;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return chk;
|
||||
}
|
||||
|
||||
/* 800A7DCC-800A8038 .text SphChkRp__4dBgWFP11dBgS_SphChkPvi */
|
||||
@@ -396,6 +601,13 @@ bool dBgW::RwgWallCrrPos(u16, dBgS_CrrPos*) {
|
||||
/* Nonmatching */
|
||||
}
|
||||
|
||||
void dBgW::dummyfunc() {
|
||||
// TODO: find where this assert actually comes from
|
||||
// cBgW::RwgShdwDraw ?
|
||||
int index;
|
||||
JUT_ASSERT(0, 0 <= index && index < pm_bgd->m_t_num);
|
||||
}
|
||||
|
||||
/* 800A8964-800A8B70 .text WallCrrPosRp__4dBgWFP11dBgS_CrrPosi */
|
||||
bool dBgW::WallCrrPosRp(dBgS_CrrPos* crr, int i) {
|
||||
cBgW_NodeTree* node = &m_nt_tbl[i];
|
||||
@@ -477,7 +689,6 @@ void dBgW::TransPos(cBgS_PolyInfo& poly, void* user, bool accept, cXyz* pos, csX
|
||||
|
||||
/* 800A8D2C-800A9474 .text ChkPolyThrough__4dBgWFiP16cBgS_PolyPassChk */
|
||||
bool dBgW::ChkPolyThrough(int poly_index, cBgS_PolyPassChk* chk) {
|
||||
/* Nonmatching */
|
||||
if (chk == NULL)
|
||||
return false;
|
||||
if (chk->mbObjThrough && GetPolyInf3(GetPolyInfId(poly_index)) & 0x02)
|
||||
@@ -499,7 +710,6 @@ bool dBgW::ChkPolyThrough(int poly_index, cBgS_PolyPassChk* chk) {
|
||||
|
||||
/* 800A9474-800A9684 .text ChkShdwDrawThrough__4dBgWFiP16cBgS_PolyPassChk */
|
||||
bool dBgW::ChkShdwDrawThrough(int poly_index, cBgS_PolyPassChk* chk) {
|
||||
/* Nonmatching */
|
||||
if ((GetPolyInf0(GetPolyInfId(poly_index)) >> 27) & 1)
|
||||
return true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user