summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorpetrie911 <69443847+petrie911@users.noreply.github.com>2022-10-20 20:34:21 -0500
committerGitHub <noreply@github.com>2022-10-21 02:34:21 +0100
commitdca019f9fa648db1fa1dc827899002a9dffa1bb6 (patch)
treed4b1e6755258067075f7fdb8f3422cd36783c990 /src/code
parent75d7cf668c64967fb7f8c5b9c6182bb70e7fbba9 (diff)
Match 4 functions in BGcheck, remove nonequivalency in DynaPoly_ExpandSRT and BgHakaBombwall (#1128)
* match 1 * more matches * one thing * cleaned up conditionals * move bss * format * I swear that's all of the () Co-authored-by: petrie911 <petrie911@users.noreply.github.com>
Diffstat (limited to 'src/code')
-rw-r--r--src/code/z_bgcheck.c538
1 files changed, 277 insertions, 261 deletions
diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c
index 7f4247b0d..2052449f7 100644
--- a/src/code/z_bgcheck.c
+++ b/src/code/z_bgcheck.c
@@ -72,17 +72,25 @@ BgSpecialSceneMaxObjects sCustomDynapolyMem[] = {
// TODO: All these bss variables are localized to one function and can
// likely be made into in-function static bss variables in the future
-char D_801ED950[80];
-char D_801ED9A0[80];
+
Vec3f D_801ED9F0[3]; // polyVerts
Vec3f D_801EDA18[3]; // polyVerts
-MtxF D_801EDA40;
Vec3f D_801EDA80[3]; // polyVerts
+Vec3f D_801EDB48[3]; // polyVerts
+
+#ifndef NON_MATCHING
+Vec3f D_801EDB70[3]; // polyVerts;
+Plane D_801EDB98; // plane;
+Sphere16 D_801EDBA8; // sphere;
+TriNorm D_801EDBB0; // tri;
+#endif
+
+char D_801ED950[80];
+char D_801ED9A0[80];
+
char D_801EDAA8[80];
char D_801EDAF8[80];
-Vec3f D_801EDB48[3]; // polyVerts
-Vec3f D_801EDB70[3];
-Plane D_801EDB98;
+MtxF D_801EDA40;
void BgCheck_GetStaticLookupIndicesFromPos(CollisionContext* colCtx, Vec3f* pos, Vec3i* sector);
f32 BgCheck_RaycastFloorDyna(DynaRaycast* dynaRaycast);
@@ -281,7 +289,7 @@ void CollisionPoly_GetVertices(CollisionPoly* poly, Vec3s* vtxList, Vec3f* dest)
void CollisionPoly_GetVerticesByBgId(CollisionPoly* poly, s32 bgId, CollisionContext* colCtx, Vec3f* dest) {
Vec3s* vtxList;
- if (poly == NULL || bgId > BG_ACTOR_MAX || dest == NULL) {
+ if ((poly == NULL) || (bgId > BG_ACTOR_MAX) || (dest == NULL)) {
if (dest != NULL) {
// @bug: dest[2] x and y are not set to 0
dest[0].x = dest[0].y = dest[0].z = dest[1].x = dest[1].y = dest[1].z = dest[2].z = 0.0f;
@@ -380,40 +388,52 @@ s32 CollisionPoly_CheckZIntersectApprox(CollisionPoly* poly, Vec3s* vtxList, f32
}
#ifdef NON_MATCHING
+// Matches, but needs in-function static bss
s32 CollisionPoly_LineVsPoly(BgLineVsPolyTest* a0) {
- static Vec3f polyVerts[3]; // D_801EDB70
- static Plane plane; // D_801EDB98
+ static Vec3f sPolyVerts[3]; // D_801EDB70
+ static Plane sPlane; // D_801EDB98
f32 planeDistA;
f32 planeDistB;
- f32 planeDistDelta;
-
- plane.originDist = a0->poly->dist;
- planeDistA = COLPOLY_GET_NORMAL(a0->poly->normal.x * a0->posA->x + a0->poly->normal.y * a0->posA->y +
- a0->poly->normal.z * a0->posA->z) +
- plane.originDist;
- planeDistB = COLPOLY_GET_NORMAL(a0->poly->normal.x * a0->posB->x + a0->poly->normal.y * a0->posB->y +
- a0->poly->normal.z * a0->posB->z) +
- plane.originDist;
-
- planeDistDelta = planeDistA - planeDistB;
- if ((planeDistA >= 0.0f && planeDistB >= 0.0f) || (planeDistA < 0.0f && planeDistB < 0.0f) ||
- ((a0->checkOneFace != 0) && (planeDistA < 0.0f && planeDistB > 0.0f)) || IS_ZERO(planeDistDelta)) {
+ f32 dpA;
+ f32 dpB;
+ f32 originDist;
+
+ sPlane.originDist = a0->poly->dist;
+ originDist = sPlane.originDist;
+ planeDistA = originDist;
+ planeDistB = originDist;
+
+ dpA = a0->poly->normal.x * a0->posA->x;
+ dpB = a0->poly->normal.x * a0->posB->x;
+ dpA += a0->poly->normal.y * a0->posA->y;
+ dpB += a0->poly->normal.y * a0->posB->y;
+ dpA += a0->poly->normal.z * a0->posA->z;
+ dpB += a0->poly->normal.z * a0->posB->z;
+
+ dpA *= COLPOLY_NORMAL_FRAC;
+ dpB *= COLPOLY_NORMAL_FRAC;
+
+ planeDistA += dpA;
+ planeDistB += dpB;
+
+ if (((planeDistA >= 0.0f) && (planeDistB >= 0.0f)) || ((planeDistA < 0.0f) && (planeDistB < 0.0f)) ||
+ ((a0->checkOneFace != 0) && (planeDistA < 0.0f) && (0.0f < planeDistB)) || IS_ZERO(planeDistA - planeDistB)) {
return false;
}
- CollisionPoly_GetNormalF(a0->poly, &plane.normal.x, &plane.normal.y, &plane.normal.z);
- CollisionPoly_GetVertices(a0->poly, a0->vtxList, polyVerts);
- Math3D_Lerp(a0->posA, a0->posB, planeDistA / planeDistDelta, a0->planeIntersect);
+ CollisionPoly_GetNormalF(a0->poly, &sPlane.normal.x, &sPlane.normal.y, &sPlane.normal.z);
+ CollisionPoly_GetVertices(a0->poly, a0->vtxList, sPolyVerts);
+ Math3D_Lerp(a0->posA, a0->posB, planeDistA / (planeDistA - planeDistB), a0->planeIntersect);
- if ((fabsf(plane.normal.x) > 0.5f &&
- Math3D_TriChkPointParaXDist(&polyVerts[0], &polyVerts[1], &polyVerts[2], a0->planeIntersect->y,
- a0->planeIntersect->z, 0.0f, a0->checkDist, plane.normal.x)) ||
- (fabsf(plane.normal.y) > 0.5f &&
- Math3D_TriChkPointParaYDist(&polyVerts[0], &polyVerts[1], &polyVerts[2], a0->planeIntersect->z,
- a0->planeIntersect->x, 0.0f, a0->checkDist, plane.normal.y)) ||
- (fabsf(plane.normal.z) > 0.5f &&
- Math3D_TriChkLineSegParaZDist(&polyVerts[0], &polyVerts[1], &polyVerts[2], a0->planeIntersect->x,
- a0->planeIntersect->y, 0.0f, a0->checkDist, plane.normal.z))) {
+ if (((fabsf(sPlane.normal.x) > 0.5f) &&
+ Math3D_TriChkPointParaXDist(&sPolyVerts[0], &sPolyVerts[1], &sPolyVerts[2], a0->planeIntersect->y,
+ a0->planeIntersect->z, 0.0f, a0->checkDist, sPlane.normal.x)) ||
+ ((fabsf(sPlane.normal.y) > 0.5f) &&
+ Math3D_TriChkPointParaYDist(&sPolyVerts[0], &sPolyVerts[1], &sPolyVerts[2], a0->planeIntersect->z,
+ a0->planeIntersect->x, 0.0f, a0->checkDist, sPlane.normal.y)) ||
+ ((fabsf(sPlane.normal.z) > 0.5f) &&
+ Math3D_TriChkLineSegParaZDist(&sPolyVerts[0], &sPolyVerts[1], &sPolyVerts[2], a0->planeIntersect->x,
+ a0->planeIntersect->y, 0.0f, a0->checkDist, sPlane.normal.z))) {
return true;
}
return false;
@@ -423,20 +443,26 @@ s32 CollisionPoly_LineVsPoly(BgLineVsPolyTest* a0);
#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/CollisionPoly_LineVsPoly.s")
#endif
+#ifdef NON_MATCHING
+// Matches, but needs in-function static bss
s32 CollisionPoly_SphVsPoly(CollisionPoly* poly, Vec3s* vtxList, Vec3f* center, f32 radius) {
- static Sphere16 sphere; // D_801EDBA8
- static TriNorm tri; // D_801EDBB0
+ static Sphere16 sSphere; // D_801EDBA8
+ static TriNorm sTri; // D_801EDBB0
Vec3f intersect;
- CollisionPoly_GetVertices(poly, vtxList, tri.vtx);
- CollisionPoly_GetNormalF(poly, &tri.plane.normal.x, &tri.plane.normal.y, &tri.plane.normal.z);
- tri.plane.originDist = poly->dist;
- sphere.center.x = center->x;
- sphere.center.y = center->y;
- sphere.center.z = center->z;
- sphere.radius = radius;
- return Math3D_ColSphereTri(&sphere, &tri, &intersect);
+ CollisionPoly_GetVertices(poly, vtxList, sTri.vtx);
+ CollisionPoly_GetNormalF(poly, &sTri.plane.normal.x, &sTri.plane.normal.y, &sTri.plane.normal.z);
+ sTri.plane.originDist = poly->dist;
+ sSphere.center.x = center->x;
+ sSphere.center.y = center->y;
+ sSphere.center.z = center->z;
+ sSphere.radius = radius;
+ return Math3D_ColSphereTri(&sSphere, &sTri, &intersect);
}
+#else
+s32 CollisionPoly_SphVsPoly(CollisionPoly* poly, Vec3s* vtxList, Vec3f* center, f32 radius);
+#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/CollisionPoly_SphVsPoly.s")
+#endif
/**
* Add poly to StaticLookup table
@@ -466,9 +492,9 @@ void StaticLookup_AddPolyToSSList(CollisionContext* colCtx, SSList* ssList, Coll
curPolyId = curNode->polyId;
// if the poly being inserted has a lower y than the first poly
- if (polyYMin < vtxList[COLPOLY_VTX_INDEX(polyList[curPolyId].flags_vIA)].y &&
- polyYMin < vtxList[COLPOLY_VTX_INDEX(polyList[curPolyId].flags_vIB)].y &&
- polyYMin < vtxList[polyList[curPolyId].vIC].y) {
+ if ((polyYMin < vtxList[COLPOLY_VTX_INDEX(polyList[curPolyId].flags_vIA)].y) &&
+ (polyYMin < vtxList[COLPOLY_VTX_INDEX(polyList[curPolyId].flags_vIB)].y) &&
+ (polyYMin < vtxList[polyList[curPolyId].vIC].y)) {
SSNodeList_SetSSListHead(&colCtx->polyNodes, ssList, &polyId);
return;
}
@@ -487,9 +513,9 @@ void StaticLookup_AddPolyToSSList(CollisionContext* colCtx, SSList* ssList, Coll
curPolyId = nextNode->polyId;
// if the poly being inserted is lower than the next poly
- if (polyYMin < vtxList[COLPOLY_VTX_INDEX(polyList[curPolyId].flags_vIA)].y &&
- polyYMin < vtxList[COLPOLY_VTX_INDEX(polyList[curPolyId].flags_vIB)].y &&
- polyYMin < vtxList[polyList[curPolyId].vIC].y) {
+ if ((polyYMin < vtxList[COLPOLY_VTX_INDEX(polyList[curPolyId].flags_vIA)].y) &&
+ (polyYMin < vtxList[COLPOLY_VTX_INDEX(polyList[curPolyId].flags_vIB)].y) &&
+ (polyYMin < vtxList[polyList[curPolyId].vIC].y)) {
newNodeId = SSNodeList_GetNextNodeIdx(&colCtx->polyNodes);
SSNode_SetValue(&colCtx->polyNodes.tbl[newNodeId], &polyId, curNode->next);
curNode->next = newNodeId;
@@ -542,8 +568,9 @@ f32 BgCheck_RaycastFloorStaticList(CollisionContext* colCtx, u16 xpFlags, SSList
if (((flags & 1) && (colPoly->normal.y < 0)) ||
((arg9 & 0x20) && ((colCtx->colHeader->surfaceTypeList[colPoly->type].data[0] >> 0x1E) & 1)) ||
COLPOLY_VIA_FLAG_TEST(colPoly->flags_vIA, xpFlags) ||
- (COLPOLY_VIA_FLAG_TEST(colPoly->flags_vIB, 4) && ((actor != NULL && actor->category != ACTORCAT_PLAYER) ||
- (actor == NULL && xpFlags != COLPOLY_IGNORE_CAMERA)))) {
+ (COLPOLY_VIA_FLAG_TEST(colPoly->flags_vIB, 4) &&
+ (((actor != NULL) && (actor->category != ACTORCAT_PLAYER)) ||
+ ((actor == NULL) && (xpFlags != COLPOLY_IGNORE_CAMERA))))) {
if (curNode->next == SS_NULL) {
break;
}
@@ -551,16 +578,16 @@ f32 BgCheck_RaycastFloorStaticList(CollisionContext* colCtx, u16 xpFlags, SSList
continue;
}
- if (pos->y < colCtx->colHeader->vtxList[COLPOLY_VTX_INDEX(colPoly->flags_vIA)].y &&
- pos->y < colCtx->colHeader->vtxList[COLPOLY_VTX_INDEX(colPoly->flags_vIB)].y &&
- pos->y < colCtx->colHeader->vtxList[colPoly->vIC].y) {
+ if ((pos->y < colCtx->colHeader->vtxList[COLPOLY_VTX_INDEX(colPoly->flags_vIA)].y) &&
+ (pos->y < colCtx->colHeader->vtxList[COLPOLY_VTX_INDEX(colPoly->flags_vIB)].y) &&
+ (pos->y < colCtx->colHeader->vtxList[colPoly->vIC].y)) {
break;
}
if (CollisionPoly_CheckYIntersect(colPoly, colCtx->colHeader->vtxList, pos->x, pos->z, &yIntersect,
checkDist)) {
// if poly is closer to pos without going over
- if (yIntersect < pos->y && result < yIntersect) {
+ if ((yIntersect < pos->y) && (result < yIntersect)) {
result = yIntersect;
*outPoly = colPoly;
}
@@ -682,7 +709,7 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
vtxB = &vtxList[COLPOLY_VTX_INDEX(curPoly->flags_vIB)];
vtxC = &vtxList[curPoly->vIC];
- if (pos->y < vtxA->y && pos->y < vtxB->y && pos->y < vtxC->y) {
+ if ((pos->y < vtxA->y) && (pos->y < vtxB->y) && (pos->y < vtxC->y)) {
break;
}
@@ -692,8 +719,9 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
normalXZ = sqrtf(SQ(nx) + SQ(nz));
planeDist = Math3D_DistPlaneToPos(nx, ny, nz, curPoly->dist, &resultPos);
if (radius < fabsf(planeDist) || COLPOLY_VIA_FLAG_TEST(curPoly->flags_vIA, xpFlags) ||
- (COLPOLY_VIA_FLAG_TEST(curPoly->flags_vIB, 4) && ((actor != NULL && actor->category != ACTORCAT_PLAYER) ||
- (actor == NULL && xpFlags != COLPOLY_IGNORE_CAMERA)))) {
+ (COLPOLY_VIA_FLAG_TEST(curPoly->flags_vIB, 4) &&
+ (((actor != NULL) && (actor->category != ACTORCAT_PLAYER)) ||
+ ((actor == NULL) && (xpFlags != COLPOLY_IGNORE_CAMERA))))) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -733,7 +761,7 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
zMin -= radius;
zMax += radius;
- if (resultPos.z < zMin || resultPos.z > zMax) {
+ if ((resultPos.z < zMin) || (resultPos.z > zMax)) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -769,7 +797,7 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
vtxB = &vtxList[COLPOLY_VTX_INDEX(curPoly->flags_vIB)];
vtxC = &vtxList[curPoly->vIC];
- if (pos->y < vtxA->y && pos->y < vtxB->y && pos->y < vtxC->y) {
+ if ((pos->y < vtxA->y) && (pos->y < vtxB->y) && (pos->y < vtxC->y)) {
break;
}
@@ -779,8 +807,9 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
normalXZ = sqrtf(SQ(nx) + SQ(nz));
planeDist = Math3D_DistPlaneToPos(nx, ny, nz, curPoly->dist, &resultPos);
if (radius < fabsf(planeDist) || COLPOLY_VIA_FLAG_TEST(curPoly->flags_vIA, xpFlags) ||
- (COLPOLY_VIA_FLAG_TEST(curPoly->flags_vIB, 4) && ((actor != NULL && actor->category != ACTORCAT_PLAYER) ||
- (actor == NULL && xpFlags != COLPOLY_IGNORE_CAMERA)))) {
+ (COLPOLY_VIA_FLAG_TEST(curPoly->flags_vIB, 4) &&
+ (((actor != NULL) && (actor->category != ACTORCAT_PLAYER)) ||
+ ((actor == NULL) && (xpFlags != COLPOLY_IGNORE_CAMERA))))) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -820,7 +849,7 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
xMin -= radius;
xMax += radius;
- if (resultPos.x < xMin || xMax < resultPos.x) {
+ if ((resultPos.x < xMin) || (xMax < resultPos.x)) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -886,8 +915,8 @@ s32 BgCheck_CheckStaticCeiling(StaticLookup* lookup, u16 xpFlags, CollisionConte
curPoly = &polyList[curPolyId];
if (COLPOLY_VIA_FLAG_TEST(colCtx->colHeader->polyList[curPolyId].flags_vIA, xpFlags) ||
(COLPOLY_VIA_FLAG_TEST(colCtx->colHeader->polyList[curPolyId].flags_vIB, 4) &&
- ((actor != NULL && actor->category != ACTORCAT_PLAYER) ||
- (actor == NULL && xpFlags != COLPOLY_IGNORE_CAMERA)))) {
+ (((actor != NULL) && (actor->category != ACTORCAT_PLAYER)) ||
+ ((actor == NULL) && (xpFlags != COLPOLY_IGNORE_CAMERA))))) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -900,7 +929,7 @@ s32 BgCheck_CheckStaticCeiling(StaticLookup* lookup, u16 xpFlags, CollisionConte
intersectDist = ceilingY - *outY;
ny = COLPOLY_GET_NORMAL(curPoly->normal.y);
- if (intersectDist > 0 && intersectDist < checkHeight && intersectDist * ny <= 0) {
+ if ((intersectDist > 0) && (intersectDist < checkHeight) && (intersectDist * ny <= 0)) {
*outY = ceilingY - checkHeight;
*outPoly = curPoly;
result = true;
@@ -923,9 +952,8 @@ s32 BgCheck_CheckStaticCeiling(StaticLookup* lookup, u16 xpFlags, CollisionConte
* `posB` and `outPos` returns the point of intersection with `outPoly`
* `outDistSq` returns the squared distance from `posA` to the point of intersect
*/
-#ifdef NON_MATCHING
s32 BgCheck_CheckLineAgainstSSList(StaticLineTest* arg0) {
- CollisionContext* colCtx;
+ CollisionPoly* polyList;
s32 result;
Vec3f polyIntersect; // sp7C
SSNode* curNode;
@@ -934,16 +962,14 @@ s32 BgCheck_CheckLineAgainstSSList(StaticLineTest* arg0) {
f32 distSq;
BgLineVsPolyTest test; // sp50
s16 polyId;
- CollisionPoly* polyList;
result = false;
if (arg0->ssList->head == SS_NULL) {
return result;
}
- colCtx = arg0->colCtx;
- curNode = &colCtx->polyNodes.tbl[arg0->ssList->head];
- polyList = colCtx->colHeader->polyList;
- test.vtxList = colCtx->colHeader->vtxList;
+ curNode = &arg0->colCtx->polyNodes.tbl[arg0->ssList->head];
+ polyList = arg0->colCtx->colHeader->polyList;
+ test.vtxList = arg0->colCtx->colHeader->vtxList;
test.posA = arg0->posA;
test.posB = arg0->posB;
test.planeIntersect = &polyIntersect; // reorder maybe
@@ -955,22 +981,22 @@ s32 BgCheck_CheckLineAgainstSSList(StaticLineTest* arg0) {
test.poly = &polyList[polyId];
checkedPoly = &arg0->colCtx->polyNodes.polyCheckTbl[polyId];
- if (*checkedPoly == true ||
- (arg0->xpFlags2 != 0 && !COLPOLY_VIA_FLAG_TEST(test.poly->flags_vIA, arg0->xpFlags2)) ||
+ if ((*checkedPoly == true) ||
+ ((arg0->xpFlags2 != 0) && !COLPOLY_VIA_FLAG_TEST(test.poly->flags_vIA, arg0->xpFlags2)) ||
COLPOLY_VIA_FLAG_TEST(test.poly->flags_vIA, arg0->xpFlags1) ||
(COLPOLY_VIA_FLAG_TEST(test.poly->flags_vIB, 4) &&
- ((arg0->actor != NULL && arg0->actor->category != ACTORCAT_PLAYER) ||
- (arg0->actor == NULL && arg0->xpFlags1 != COLPOLY_IGNORE_CAMERA)))) {
+ (((arg0->actor != NULL) && (arg0->actor->category != ACTORCAT_PLAYER)) ||
+ ((arg0->actor == NULL) && (arg0->xpFlags1 != COLPOLY_IGNORE_CAMERA))))) {
if (curNode->next == SS_NULL) {
break;
} else {
- curNode = &colCtx->polyNodes.tbl[curNode->next];
+ curNode = &arg0->colCtx->polyNodes.tbl[curNode->next];
continue;
}
}
*checkedPoly = true;
minY = CollisionPoly_GetMinY(test.poly, test.vtxList);
- if (test.posA->y < minY && test.posB->y < minY) {
+ if (((test.posA->y < minY)) && (test.posB->y < minY)) {
break;
}
if (CollisionPoly_LineVsPoly(&test)) {
@@ -990,10 +1016,6 @@ s32 BgCheck_CheckLineAgainstSSList(StaticLineTest* arg0) {
}
return result;
}
-#else
-s32 BgCheck_CheckLineAgainstSSList(StaticLineTest* arg0);
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_CheckLineAgainstSSList.s")
-#endif
/**
* Tests if line `posA` to `posB` intersects with a static poly in `lookup`. Uses polyCheckTbl
@@ -1005,21 +1027,21 @@ s32 BgCheck_CheckLineAgainstSSList(StaticLineTest* arg0);
s32 BgCheck_CheckLineInSubdivision(StaticLineTest* arg0) {
s32 result = false;
- if ((arg0->bccFlags & BGCHECK_CHECK_FLOOR) && arg0->lookup->floor.head != SS_NULL) {
+ if ((arg0->bccFlags & BGCHECK_CHECK_FLOOR) && (arg0->lookup->floor.head != SS_NULL)) {
arg0->ssList = &arg0->lookup->floor;
if (BgCheck_CheckLineAgainstSSList(arg0)) {
result = true;
}
}
- if ((arg0->bccFlags & BGCHECK_CHECK_WALL) && arg0->lookup->wall.head != SS_NULL) {
+ if ((arg0->bccFlags & BGCHECK_CHECK_WALL) && (arg0->lookup->wall.head != SS_NULL)) {
arg0->ssList = &arg0->lookup->wall;
if (BgCheck_CheckLineAgainstSSList(arg0)) {
result = true;
}
}
- if ((arg0->bccFlags & BGCHECK_CHECK_CEILING) && arg0->lookup->ceiling.head != SS_NULL) {
+ if ((arg0->bccFlags & BGCHECK_CHECK_CEILING) && (arg0->lookup->ceiling.head != SS_NULL)) {
arg0->ssList = &arg0->lookup->ceiling;
if (BgCheck_CheckLineAgainstSSList(arg0)) {
result = true;
@@ -1049,8 +1071,8 @@ s32 BgCheck_SphVsFirstStaticPolyList(SSNode* node, u16 xpFlags, CollisionContext
curPoly = &polyList[curPolyId];
if (COLPOLY_VIA_FLAG_TEST(colCtx->colHeader->polyList[curPolyId].flags_vIA, xpFlags) ||
(COLPOLY_VIA_FLAG_TEST(colCtx->colHeader->polyList[curPolyId].flags_vIB, 4) &&
- ((actor != NULL && actor->category != ACTORCAT_PLAYER) ||
- (actor == NULL && xpFlags != COLPOLY_IGNORE_CAMERA)))) {
+ (((actor != NULL) && (actor->category != ACTORCAT_PLAYER)) ||
+ ((actor == NULL) && (xpFlags != COLPOLY_IGNORE_CAMERA))))) {
if (node->next != SS_NULL) {
node = &colCtx->polyNodes.tbl[node->next];
continue;
@@ -1058,9 +1080,9 @@ s32 BgCheck_SphVsFirstStaticPolyList(SSNode* node, u16 xpFlags, CollisionContext
break;
}
- if (center->y + radius < vtxList[COLPOLY_VTX_INDEX(curPoly->flags_vIA)].y &&
- center->y + radius < vtxList[COLPOLY_VTX_INDEX(curPoly->flags_vIB)].y &&
- center->y + radius < vtxList[curPoly->vIC].y) {
+ if ((center->y + radius < vtxList[COLPOLY_VTX_INDEX(curPoly->flags_vIA)].y) &&
+ (center->y + radius < vtxList[COLPOLY_VTX_INDEX(curPoly->flags_vIB)].y) &&
+ (center->y + radius < vtxList[curPoly->vIC].y)) {
break;
}
@@ -1086,19 +1108,19 @@ s32 BgCheck_SphVsFirstStaticPolyList(SSNode* node, u16 xpFlags, CollisionContext
*/
s32 BgCheck_SphVsFirstStaticPoly(StaticLookup* lookup, u16 xpFlags, CollisionContext* colCtx, Vec3f* center, f32 radius,
CollisionPoly** outPoly, u16 bciFlags, Actor* actor) {
- if (lookup->floor.head != SS_NULL && !(bciFlags & BGCHECK_IGNORE_FLOOR) &&
+ if ((lookup->floor.head != SS_NULL) && !(bciFlags & BGCHECK_IGNORE_FLOOR) &&
BgCheck_SphVsFirstStaticPolyList(&colCtx->polyNodes.tbl[lookup->floor.head], xpFlags, colCtx, center, radius,
outPoly, actor)) {
return true;
}
- if (lookup->wall.head != SS_NULL && !(bciFlags & BGCHECK_IGNORE_WALL) &&
+ if ((lookup->wall.head != SS_NULL) && !(bciFlags & BGCHECK_IGNORE_WALL) &&
BgCheck_SphVsFirstStaticPolyList(&colCtx->polyNodes.tbl[lookup->wall.head], xpFlags, colCtx, center, radius,
outPoly, actor)) {
return true;
}
- if (lookup->ceiling.head != SS_NULL && !(bciFlags & BGCHECK_IGNORE_CEILING) &&
+ if ((lookup->ceiling.head != SS_NULL) && !(bciFlags & BGCHECK_IGNORE_CEILING) &&
BgCheck_SphVsFirstStaticPolyList(&colCtx->polyNodes.tbl[lookup->ceiling.head], xpFlags, colCtx, center, radius,
outPoly, actor)) {
return true;
@@ -1634,7 +1656,7 @@ CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId)
if (bgId == BGCHECK_SCENE) {
return colCtx->colHeader;
}
- if (bgId < 0 || bgId > BG_ACTOR_MAX) {
+ if ((bgId < 0) || (bgId > BG_ACTOR_MAX)) {
return NULL;
}
if (!(colCtx->dyna.bgActorFlags[bgId] & 1)) {
@@ -1647,12 +1669,12 @@ CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId)
* Test if pos is near collision boundaries
*/
s32 BgCheck_PosInStaticBoundingBox(CollisionContext* colCtx, Vec3f* pos) {
- if (pos->x < (colCtx->minBounds.x - BGCHECK_SUBDIV_OVERLAP) ||
- (colCtx->maxBounds.x + BGCHECK_SUBDIV_OVERLAP) < pos->x ||
- pos->y < (colCtx->minBounds.y - BGCHECK_SUBDIV_OVERLAP) ||
- (colCtx->maxBounds.y + BGCHECK_SUBDIV_OVERLAP) < pos->y ||
- pos->z < (colCtx->minBounds.z - BGCHECK_SUBDIV_OVERLAP) ||
- (colCtx->maxBounds.z + BGCHECK_SUBDIV_OVERLAP) < pos->z) {
+ if ((pos->x < (colCtx->minBounds.x - BGCHECK_SUBDIV_OVERLAP)) ||
+ ((colCtx->maxBounds.x + BGCHECK_SUBDIV_OVERLAP) < pos->x) ||
+ (pos->y < (colCtx->minBounds.y - BGCHECK_SUBDIV_OVERLAP)) ||
+ ((colCtx->maxBounds.y + BGCHECK_SUBDIV_OVERLAP) < pos->y) ||
+ (pos->z < (colCtx->minBounds.z - BGCHECK_SUBDIV_OVERLAP)) ||
+ ((colCtx->maxBounds.z + BGCHECK_SUBDIV_OVERLAP) < pos->z)) {
return false;
}
return true;
@@ -1713,7 +1735,7 @@ f32 BgCheck_RaycastFloorImpl(PlayState* play, CollisionContext* colCtx, u16 xpFl
}
}
- if (yIntersect != BGCHECK_Y_MIN && func_800C9B68(colCtx, *outPoly, *outBgId)) {
+ if ((yIntersect != BGCHECK_Y_MIN) && func_800C9B68(colCtx, *outPoly, *outBgId)) {
yIntersect -= 1.0f;
}
return yIntersect;
@@ -1916,7 +1938,7 @@ s32 BgCheck_CheckWallImpl(CollisionContext* colCtx, u16 xpFlags, Vec3f* posResul
dz = posNext->z - posPrev->z;
// if there's movement on the xz plane, and argA flag is 0,
- if ((dx != 0.0f || dz != 0.0f) && (argA & 1) == 0) {
+ if (((dx != 0.0f) || (dz != 0.0f)) && !(argA & 1)) {
if ((checkHeight + dy) < 5.0f) {
//! @bug checkHeight is not applied to posPrev/posNext
result = BgCheck_CheckLineImpl(colCtx, xpFlags, COLPOLY_IGNORE_NONE, posPrev, posNext, &posIntersect, &poly,
@@ -1977,7 +1999,7 @@ s32 BgCheck_CheckWallImpl(CollisionContext* colCtx, u16 xpFlags, Vec3f* posResul
*outPoly = poly;
*outBgId = bgId;
result = true;
- if (COLPOLY_GET_NORMAL(poly->normal.y) > 0.5f) {
+ if (poly->normal.y * COLPOLY_NORMAL_FRAC > 0.5f) {
if (actor != NULL) {
actor->bgCheckFlags |= 0x1000;
}
@@ -2010,7 +2032,7 @@ s32 BgCheck_CheckWallImpl(CollisionContext* colCtx, u16 xpFlags, Vec3f* posResul
result = true;
}
// if a collision with a dyna poly was detected
- if (dynaPolyCollision || *outBgId != BGCHECK_SCENE) {
+ if (dynaPolyCollision || (*outBgId != BGCHECK_SCENE)) {
if (BgCheck_CheckLineImpl(colCtx, xpFlags, COLPOLY_IGNORE_NONE, posPrev, posResult, &posIntersect2, &poly,
&bgId2, actor, 1.0f, BGCHECK_CHECK_ONE_FACE | BGCHECK_CHECK_WALL)) {
nx3 = COLPOLY_GET_NORMAL(poly->normal.x);
@@ -2202,7 +2224,7 @@ s32 BgCheck_CheckLineImpl(CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2,
checkLine.actor = actor;
result = false;
- if (subdivMin[0] != subdivMax[0] || subdivMin[1] != subdivMax[1] || subdivMin[2] != subdivMax[2]) {
+ if ((subdivMin[0] != subdivMax[0]) || (subdivMin[1] != subdivMax[1]) || (subdivMin[2] != subdivMax[2])) {
for (i = 0; i < 3; i++) {
if (subdivMax[i] < subdivMin[i]) {
j = subdivMax[i];
@@ -2512,9 +2534,9 @@ void ScaleRotPos_SetValue(ScaleRotPos* srp, Vec3f* scale, Vec3s* rot, Vec3f* pos
* ScaleRotPos equality test
*/
s32 ScaleRotPos_IsEqual(ScaleRotPos* a, ScaleRotPos* b) {
- if (a->scale.x != b->scale.x || a->scale.y != b->scale.y || a->scale.z != b->scale.z || a->rot.x != b->rot.x ||
- a->rot.y != b->rot.y || a->rot.z != b->rot.z || a->pos.x != b->pos.x || a->pos.y != b->pos.y ||
- a->pos.z != b->pos.z) {
+ if ((a->scale.x != b->scale.x) || (a->scale.y != b->scale.y) || (a->scale.z != b->scale.z) ||
+ (a->rot.x != b->rot.x) || (a->rot.y != b->rot.y) || (a->rot.z != b->rot.z) || (a->pos.x != b->pos.x) ||
+ (a->pos.y != b->pos.y) || (a->pos.z != b->pos.z)) {
return false;
}
return true;
@@ -2642,7 +2664,7 @@ void DynaPoly_SetBgActorPrevTransform(PlayState* play, BgActor* bgActor) {
* Is BgActor Id
*/
s32 DynaPoly_IsBgIdBgActor(s32 bgId) {
- if (bgId < 0 || bgId >= BG_ACTOR_MAX) {
+ if ((bgId < 0) || (bgId >= BG_ACTOR_MAX)) {
return false;
}
return true;
@@ -2714,7 +2736,7 @@ s32 DynaPoly_SetBgActor(PlayState* play, DynaCollisionContext* dyna, Actor* acto
*/
DynaPolyActor* DynaPoly_GetActor(CollisionContext* colCtx, s32 bgId) {
if (!DynaPoly_IsBgIdBgActor(bgId) || !(colCtx->dyna.bgActorFlags[bgId] & 1) ||
- colCtx->dyna.bgActorFlags[bgId] & 2) {
+ (colCtx->dyna.bgActorFlags[bgId] & 2)) {
return NULL;
}
return (DynaPolyActor*)colCtx->dyna.bgActors[bgId].actor;
@@ -2881,20 +2903,20 @@ void DynaPoly_ExpandSRT(PlayState* play, DynaCollisionContext* dyna, s32 bgId, s
if (dyna->bgActorFlags[bgId] & 4) {
return;
}
-
- if (!(DYNA_WATERBOX_MAX >= *waterBoxStartIndex + pbgdata->numWaterBoxes)) {
+ // if(&pos){} // fake but considerably improves match. commented out to stop warnings
+ if (*waterBoxStartIndex + pbgdata->numWaterBoxes > DYNA_WATERBOX_MAX) {
sprintf(D_801EDAA8, "water_poly Error:[MoveBG OSUGI!!!]");
sprintf(D_801EDAF8, "num = %d > %d\n", *waterBoxStartIndex + pbgdata->numWaterBoxes, DYNA_WATERBOX_MAX);
Fault_AddHungupAndCrashImpl(D_801EDAA8, D_801EDAF8);
}
- if (!(dyna->polyListMax >= *polyStartIndex + pbgdata->numPolygons)) {
+ if (*polyStartIndex + pbgdata->numPolygons > dyna->polyListMax) {
sprintf(D_801EDAA8, "bg_poly Error:[MoveBG OSUGI!!!]");
sprintf(D_801EDAF8, "num = %d > %d\n", *polyStartIndex + pbgdata->numPolygons, dyna->polyListMax);
Fault_AddHungupAndCrashImpl(D_801EDAA8, D_801EDAF8);
}
- if (!(dyna->vtxListMax >= *vtxStartIndex + pbgdata->numVertices)) {
+ if (*vtxStartIndex + pbgdata->numVertices > dyna->vtxListMax) {
sprintf(D_801EDAA8, "bg_vert Error:[MoveBG OSUGI!!!]");
sprintf(D_801EDAF8, "num = %d > %d\n", *vtxStartIndex + pbgdata->numVertices, dyna->vtxListMax);
Fault_AddHungupAndCrashImpl(D_801EDAA8, D_801EDAF8);
@@ -2938,7 +2960,8 @@ void DynaPoly_ExpandSRT(PlayState* play, DynaCollisionContext* dyna, s32 bgId, s
dyna->bgActors[bgId].curTransform.pos.x, dyna->bgActors[bgId].curTransform.pos.y,
dyna->bgActors[bgId].curTransform.pos.z);
- if (pbgdata->numVertices != 0 && pbgdata->numPolygons != 0) {
+ if ((pbgdata->numVertices != 0) && (pbgdata->numPolygons != 0)) {
+ s32 j;
numVtxInverse = 1.0f / pbgdata->numVertices;
newCenterPoint.x = newCenterPoint.y = newCenterPoint.z = 0.0f;
for (i = 0; i < pbgdata->numVertices; i++) {
@@ -2969,13 +2992,12 @@ void DynaPoly_ExpandSRT(PlayState* play, DynaCollisionContext* dyna, s32 bgId, s
sphere->center.z = newCenterPoint.z;
newRadiusSq = -100.0f;
- for (i = 0; i < pbgdata->numVertices; i++) {
+ for (i = 0, j = *vtxStartIndex; i < pbgdata->numVertices; i++, j++) {
f32 radiusSq;
- s32 idx = *vtxStartIndex + i;
- newVtx.x = dyna->vtxList[idx].x;
- newVtx.y = dyna->vtxList[idx].y;
- newVtx.z = dyna->vtxList[idx].z;
+ newVtx.x = dyna->vtxList[j].x;
+ newVtx.y = dyna->vtxList[j].y;
+ newVtx.z = dyna->vtxList[j].z;
radiusSq = Math3D_Vec3fDistSq(&newVtx, &newCenterPoint);
if (newRadiusSq < radiusSq) {
newRadiusSq = radiusSq;
@@ -3022,7 +3044,7 @@ void DynaPoly_ExpandSRT(PlayState* play, DynaCollisionContext* dyna, s32 bgId, s
newPoly->normal.z = COLPOLY_SNORMAL(newNormal.z);
}
- newPoly->dist = -DOTXYZ(newNormal, dVtxList[vIA]);
+ newPoly->dist = func_80086D24(-DOTXYZ(newNormal, vtxA));
if (newNormal.y > 0.5f) {
s16 polyId = *polyStartIndex + i;
@@ -3039,21 +3061,22 @@ void DynaPoly_ExpandSRT(PlayState* play, DynaCollisionContext* dyna, s32 bgId, s
}
}
- for (wi = 0; wi < pbgdata->numWaterBoxes; wi++) {
- Math_Vec3s_ToVec3f(&spB8, &pbgdata->waterBoxes[wi].minPos);
- Math_Vec3f_Copy(&spA0, &spB8);
- spA0.x += pbgdata->waterBoxes[wi].xLength;
- Math_Vec3f_Copy(&sp88, &spB8);
- sp88.z += pbgdata->waterBoxes[wi].zLength;
- SkinMatrix_Vec3fMtxFMultXYZ(&D_801EDA40, &spB8, &spAC);
- SkinMatrix_Vec3fMtxFMultXYZ(&D_801EDA40, &spA0, &sp94);
- SkinMatrix_Vec3fMtxFMultXYZ(&D_801EDA40, &sp88, &sp7C);
- waterBox = &dyna->waterBoxList.boxes[*waterBoxStartIndex + wi];
- BgCheck_CalcWaterboxDimensions(&spAC, &sp94, &sp7C, &waterBox->minPos, &waterBox->xLength,
- &waterBox->zLength);
- waterBox->properties = pbgdata->waterBoxes[wi].properties;
+ if (pbgdata->numWaterBoxes > 0) {
+ for (wi = 0; wi < pbgdata->numWaterBoxes; wi++) {
+ Math_Vec3s_ToVec3f(&spB8, &pbgdata->waterBoxes[wi].minPos);
+ Math_Vec3f_Copy(&spA0, &spB8);
+ spA0.x += pbgdata->waterBoxes[wi].xLength;
+ Math_Vec3f_Copy(&sp88, &spB8);
+ sp88.z += pbgdata->waterBoxes[wi].zLength;
+ SkinMatrix_Vec3fMtxFMultXYZ(&D_801EDA40, &spB8, &spAC);
+ SkinMatrix_Vec3fMtxFMultXYZ(&D_801EDA40, &spA0, &sp94);
+ SkinMatrix_Vec3fMtxFMultXYZ(&D_801EDA40, &sp88, &sp7C);
+ waterBox = &dyna->waterBoxList.boxes[*waterBoxStartIndex + wi];
+ BgCheck_CalcWaterboxDimensions(&spAC, &sp94, &sp7C, &waterBox->minPos, &waterBox->xLength,
+ &waterBox->zLength);
+ waterBox->properties = pbgdata->waterBoxes[wi].properties;
+ }
}
-
*polyStartIndex += pbgdata->numPolygons;
*vtxStartIndex += pbgdata->numVertices;
*waterBoxStartIndex += pbgdata->numWaterBoxes;
@@ -3070,7 +3093,7 @@ void BgCheck_ResetFlagsIfLoadedActor(PlayState* play, DynaCollisionContext* dyna
for (i = 0; i < BG_ACTOR_MAX; i++) {
if ((dyna->bgActorFlags[i] & 1)) {
dynaActor = DynaPoly_GetActor(&play->colCtx, i);
- if (dynaActor != NULL && &dynaActor->actor == actor) {
+ if ((dynaActor != NULL) && (&dynaActor->actor == actor)) {
DynaPolyActor_ResetState((DynaPolyActor*)actor);
return;
}
@@ -3101,7 +3124,7 @@ void DynaPoly_Setup(PlayState* play, DynaCollisionContext* dyna) {
BgActor_Init(play, &dyna->bgActors[i]);
dyna->bitFlag |= DYNAPOLY_INVALIDATE_LOOKUP;
}
- if (dyna->bgActors[i].actor != NULL && dyna->bgActors[i].actor->update == NULL) {
+ if ((dyna->bgActors[i].actor != NULL) && (dyna->bgActors[i].actor->update == NULL)) {
// Delete BgActor
actor = DynaPoly_GetActor(&play->colCtx, i);
if (actor == NULL) {
@@ -3181,8 +3204,8 @@ f32 BgCheck_RaycastFloorDynaList(DynaRaycast* dynaRaycast, u32 listType) {
id = curNode->polyId;
if (COLPOLY_VIA_FLAG_TEST(polyList[id].flags_vIA, dynaRaycast->xpFlags) ||
(COLPOLY_VIA_FLAG_TEST(polyList[id].flags_vIB, 4) &&
- ((dynaRaycast->actor != NULL && dynaRaycast->actor->category != ACTORCAT_PLAYER) ||
- (dynaRaycast->actor == NULL && dynaRaycast->xpFlags != COLPOLY_IGNORE_CAMERA))) ||
+ (((dynaRaycast->actor != NULL) && (dynaRaycast->actor->category != ACTORCAT_PLAYER)) ||
+ ((dynaRaycast->actor == NULL) && (dynaRaycast->xpFlags != COLPOLY_IGNORE_CAMERA)))) ||
((dynaRaycast->unk_24 & 0x20) && func_800C9B68(dynaRaycast->colCtx, &polyList[id], dynaRaycast->unk1C))) {
if (curNode->next == SS_NULL) {
break;
@@ -3192,7 +3215,7 @@ f32 BgCheck_RaycastFloorDynaList(DynaRaycast* dynaRaycast, u32 listType) {
}
}
if ((listType & (DYNA_RAYCAST_WALLS | DYNA_RAYCAST_CEILINGS)) && (dynaRaycast->unk_24 & 0x10) &&
- COLPOLY_GET_NORMAL(polyList[id].normal.y) < 0.0f) {
+ (COLPOLY_GET_NORMAL(polyList[id].normal.y) < 0.0f)) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -3202,7 +3225,7 @@ f32 BgCheck_RaycastFloorDynaList(DynaRaycast* dynaRaycast, u32 listType) {
}
if (CollisionPoly_CheckYIntersectApprox1(&polyList[id], dynaRaycast->dyna->vtxList, dynaRaycast->pos->x,
dynaRaycast->pos->z, &yIntersect, dynaRaycast->checkDist) &&
- yIntersect < dynaRaycast->pos->y && result < yIntersect) {
+ (yIntersect < dynaRaycast->pos->y) && (result < yIntersect)) {
result = yIntersect;
*dynaRaycast->resultPoly = &dynaRaycast->dyna->polyList[id];
}
@@ -3250,8 +3273,8 @@ f32 BgCheck_RaycastFloorDyna(DynaRaycast* dynaRaycast) {
continue;
}
- if (dynaRaycast->actor == dynaRaycast->colCtx->dyna.bgActors[i].actor ||
- dynaRaycast->pos->y < dynaRaycast->colCtx->dyna.bgActors[i].minY ||
+ if ((dynaRaycast->actor == dynaRaycast->colCtx->dyna.bgActors[i].actor) ||
+ (dynaRaycast->pos->y < dynaRaycast->colCtx->dyna.bgActors[i].minY) ||
!Math3D_XZInSphere(&dynaRaycast->colCtx->dyna.bgActors[i].boundingSphere, dynaRaycast->pos->x,
dynaRaycast->pos->z)) {
continue;
@@ -3270,7 +3293,7 @@ f32 BgCheck_RaycastFloorDyna(DynaRaycast* dynaRaycast) {
}
}
if ((dynaRaycast->unk_24 & BGCHECK_IGNORE_WALL) ||
- (*dynaRaycast->resultPoly == NULL && (dynaRaycast->unk_24 & 8))) {
+ ((*dynaRaycast->resultPoly == NULL) && (dynaRaycast->unk_24 & 8))) {
dynaRaycast->ssList = &dynaRaycast->colCtx->dyna.bgActors[i].dynaLookup.wall;
intersect2 = BgCheck_RaycastFloorDynaList(dynaRaycast, DYNA_RAYCAST_WALLS);
if (dynaRaycast->yIntersect < intersect2) {
@@ -3388,8 +3411,8 @@ s32 BgCheck_SphVsDynaWallInBgActor(CollisionContext* colCtx, u16 xpFlags, DynaCo
planeDist = Math3D_DistPlaneToPos(nx, ny, nz, poly->dist, &resultPos);
if (radius < fabsf(planeDist) || COLPOLY_VIA_FLAG_TEST(poly->flags_vIA, xpFlags) ||
- ((COLPOLY_VIA_FLAG_TEST(poly->flags_vIB, 4)) && ((actor != NULL && actor->category != ACTORCAT_PLAYER) ||
- (actor == NULL && xpFlags != COLPOLY_IGNORE_CAMERA)))) {
+ (COLPOLY_VIA_FLAG_TEST(poly->flags_vIB, 4) && (((actor != NULL) && (actor->category != ACTORCAT_PLAYER)) ||
+ ((actor == NULL) && (xpFlags != COLPOLY_IGNORE_CAMERA))))) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -3428,7 +3451,7 @@ s32 BgCheck_SphVsDynaWallInBgActor(CollisionContext* colCtx, u16 xpFlags, DynaCo
zMin -= radius;
zMax += radius;
- if (resultPos.z < zMin || zMax < resultPos.z) {
+ if ((resultPos.z < zMin) || (zMax < resultPos.z)) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -3464,8 +3487,8 @@ s32 BgCheck_SphVsDynaWallInBgActor(CollisionContext* colCtx, u16 xpFlags, DynaCo
planeDist = Math3D_DistPlaneToPos(nx, ny, nz, poly->dist, &resultPos);
if (radius < fabsf(planeDist) || COLPOLY_VIA_FLAG_TEST(poly->flags_vIA, xpFlags) ||
- (COLPOLY_VIA_FLAG_TEST(poly->flags_vIB, 4) && ((actor != NULL && actor->category != ACTORCAT_PLAYER) ||
- (actor == NULL && xpFlags != COLPOLY_IGNORE_CAMERA)))) {
+ (COLPOLY_VIA_FLAG_TEST(poly->flags_vIB, 4) && (((actor != NULL) && (actor->category != ACTORCAT_PLAYER)) ||
+ ((actor == NULL) && (xpFlags != COLPOLY_IGNORE_CAMERA))))) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -3504,7 +3527,7 @@ s32 BgCheck_SphVsDynaWallInBgActor(CollisionContext* colCtx, u16 xpFlags, DynaCo
xMin -= radius;
xMax += radius;
- if (resultPos.x < xMin || xMax < resultPos.x) {
+ if ((resultPos.x < xMin) || (xMax < resultPos.x)) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -3566,7 +3589,7 @@ s32 BgCheck_SphVsDynaWall(CollisionContext* colCtx, u16 xpFlags, f32* outX, f32*
}
bgActor = &colCtx->dyna.bgActors[i];
- if (bgActor->minY > resultPos.y || bgActor->maxY < resultPos.y) {
+ if ((bgActor->minY > resultPos.y) || (bgActor->maxY < resultPos.y)) {
continue;
}
@@ -3575,7 +3598,7 @@ s32 BgCheck_SphVsDynaWall(CollisionContext* colCtx, u16 xpFlags, f32* outX, f32*
r = bgActor->boundingSphere.radius;
dx = bgActor->boundingSphere.center.x - resultPos.x;
dz = bgActor->boundingSphere.center.z - resultPos.z;
- if (SQ(r) < (SQ(dx) + SQ(dz)) || (!Math3D_XYInSphere(&bgActor->boundingSphere, resultPos.x, resultPos.y) &&
+ if ((SQ(r) < SQ(dx) + SQ(dz)) || (!Math3D_XYInSphere(&bgActor->boundingSphere, resultPos.x, resultPos.y) &&
!Math3D_YZInSphere(&bgActor->boundingSphere, resultPos.y, resultPos.z))) {
bgActor->boundingSphere.radius -= (s16)radius;
continue;
@@ -3624,8 +3647,8 @@ s32 BgCheck_CheckDynaCeilingList(CollisionContext* colCtx, u16 xpFlags, DynaColl
polyId = curNode->polyId;
poly = &dyna->polyList[polyId];
if (COLPOLY_VIA_FLAG_TEST(poly->flags_vIA, xpFlags) ||
- (COLPOLY_VIA_FLAG_TEST(poly->flags_vIB, 4) && ((actor != NULL && actor->category != ACTORCAT_PLAYER) ||
- (actor == NULL && xpFlags != COLPOLY_IGNORE_CAMERA)))) {
+ (COLPOLY_VIA_FLAG_TEST(poly->flags_vIB, 4) && (((actor != NULL) && (actor->category != ACTORCAT_PLAYER)) ||
+ ((actor == NULL) && (xpFlags != COLPOLY_IGNORE_CAMERA))))) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -3644,7 +3667,7 @@ s32 BgCheck_CheckDynaCeilingList(CollisionContext* colCtx, u16 xpFlags, DynaColl
}
if (CollisionPoly_CheckYIntersectApprox2(poly, dyna->vtxList, testPos.x, testPos.z, &ceilingY)) {
intersectDist = ceilingY - testPos.y;
- if (testPos.y < ceilingY && intersectDist < checkHeight && intersectDist * ny <= 0.0f) {
+ if ((testPos.y < ceilingY) && (intersectDist < checkHeight) && (intersectDist * ny <= 0.0f)) {
sign = (0.0f <= ny) ? 1.0f : -1.0f;
testPos.y = (sign * checkHeight) + ceilingY;
result = true;
@@ -3733,8 +3756,8 @@ s32 BgCheck_CheckLineAgainstBgActorSSList(DynaLineTest* dynaLineTest) {
test.poly = &dynaLineTest->dyna->polyList[polyId];
if (COLPOLY_VIA_FLAG_TEST(test.poly->flags_vIA, dynaLineTest->xpFlags) ||
(COLPOLY_VIA_FLAG_TEST(test.poly->flags_vIB, 4) &&
- ((dynaLineTest->actor != NULL && dynaLineTest->actor->category != ACTORCAT_PLAYER) ||
- (dynaLineTest->actor == NULL && dynaLineTest->xpFlags != COLPOLY_IGNORE_CAMERA)))) {
+ (((dynaLineTest->actor != NULL) && (dynaLineTest->actor->category != ACTORCAT_PLAYER)) ||
+ ((dynaLineTest->actor == NULL) && (dynaLineTest->xpFlags != COLPOLY_IGNORE_CAMERA))))) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -3830,17 +3853,19 @@ s32 BgCheck_CheckLineAgainstDyna(CollisionContext* colCtx, u16 xpFlags, Vec3f* p
if (actor != colCtx->dyna.bgActors[i].actor) {
ay = posA->y;
by = posB->y;
- if (!(ay < colCtx->dyna.bgActors[i].minY) || !(by < colCtx->dyna.bgActors[i].minY)) {
- if (!(colCtx->dyna.bgActors[i].maxY < ay) || !(colCtx->dyna.bgActors[i].maxY < by)) {
- line.a = *posA;
- line.b = *posB;
- if (Math3D_LineVsSph(&colCtx->dyna.bgActors[i].boundingSphere, &line) != 0) {
- if (BgCheck_CheckLineAgainstBgActor(colCtx, xpFlags, posA, posB, posResult, outPoly, distSq,
- i, checkDist, bccFlags, actor)) {
- *outBgId = i;
- result = true;
- }
- }
+ if ((ay < colCtx->dyna.bgActors[i].minY) && (by < colCtx->dyna.bgActors[i].minY)) {
+ continue;
+ }
+ if ((ay > colCtx->dyna.bgActors[i].maxY) && (by > colCtx->dyna.bgActors[i].maxY)) {
+ continue;
+ }
+ line.a = *posA;
+ line.b = *posB;
+ if (Math3D_LineVsSph(&colCtx->dyna.bgActors[i].boundingSphere, &line) != 0) {
+ if (BgCheck_CheckLineAgainstBgActor(colCtx, xpFlags, posA, posB, posResult, outPoly, distSq, i,
+ checkDist, bccFlags, actor)) {
+ *outBgId = i;
+ result = true;
}
}
}
@@ -3870,10 +3895,9 @@ s32 BgCheck_SphVsFirstDynaPolyList(CollisionContext* colCtx, u16 xpFlags, Collis
curPolyId = curNode->polyId;
curPoly = &dyna->polyList[curPolyId];
if (COLPOLY_VIA_FLAG_TEST(curPoly->flags_vIA, xpFlags) ||
- (COLPOLY_VIA_FLAG_TEST(curPoly->flags_vIB, 4) && ((actor != NULL && actor->category != ACTORCAT_PLAYER) ||
- (actor == NULL && xpFlags != COLPOLY_IGNORE_CAMERA))))
-
- {
+ (COLPOLY_VIA_FLAG_TEST(curPoly->flags_vIB, 4) &&
+ (((actor != NULL) && (actor->category != ACTORCAT_PLAYER)) ||
+ ((actor == NULL) && (xpFlags != COLPOLY_IGNORE_CAMERA))))) {
if (curNode->next == SS_NULL) {
break;
} else {
@@ -4016,7 +4040,7 @@ u32 SurfaceType_GetData(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId,
SurfaceType* surfaceTypes;
colHeader = BgCheck_GetCollisionHeader(colCtx, bgId);
- if (colHeader == NULL || poly == NULL) {
+ if ((colHeader == NULL) || (poly == NULL)) {
return 0;
}
surfaceTypes = colHeader->surfaceTypeList;
@@ -4256,7 +4280,7 @@ u32 func_800C9BB8(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) {
u16 SurfaceType_GetSfx(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) {
s32 id = func_800C9BB8(colCtx, poly, bgId);
- if (id < 0 || id > 14) {
+ if ((id < 0) || (id > 14)) {
return NA_SE_PL_WALK_GROUND - SFX_FLAG;
}
return sSurfaceTypeSfx[id];
@@ -4268,7 +4292,7 @@ u16 SurfaceType_GetSfx(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId)
s32 func_800C9C24(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId, s32 arg3) {
s32 id = func_800C9BB8(colCtx, poly, bgId);
- if (id < 0 || id > 14) {
+ if ((id < 0) || (id > 14)) {
return 0;
}
return D_801B46C0[id] & arg3;
@@ -4398,23 +4422,24 @@ u32 SurfaceType_IsWallDamage(CollisionContext* colCtx, CollisionPoly* poly, s32
s32 WaterBox_GetSurfaceImpl(PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface,
WaterBox** outWaterBox, s32* bgId) {
CollisionHeader* colHeader;
- u32 room;
- WaterBox* curWaterBox;
+ s32 room;
s32 i;
+ WaterBox* curWaterBox;
+ BgActor* bgActor;
*bgId = BGCHECK_SCENE;
colHeader = colCtx->colHeader;
- if (colHeader->numWaterBoxes != 0 && colHeader->waterBoxes != NULL) {
+ if ((colHeader->numWaterBoxes != 0) && (colHeader->waterBoxes != NULL)) {
for (curWaterBox = colHeader->waterBoxes; curWaterBox < colHeader->waterBoxes + colHeader->numWaterBoxes;
curWaterBox++) {
room = 0x3F & (curWaterBox->properties >> 13);
- if (room == (u32)play->roomCtx.curRoom.num || room == 0x3F) {
+ if ((room == play->roomCtx.curRoom.num) || (room == 0x3F)) {
if (curWaterBox->properties & 0x80000) {
continue;
}
- if (curWaterBox->minPos.x < x && x < curWaterBox->minPos.x + curWaterBox->xLength) {
- if (curWaterBox->minPos.z < z && z < curWaterBox->minPos.z + curWaterBox->zLength) {
+ if ((curWaterBox->minPos.x < x) && (x < curWaterBox->minPos.x + curWaterBox->xLength)) {
+ if ((curWaterBox->minPos.z < z) && (z < curWaterBox->minPos.z + curWaterBox->zLength)) {
*outWaterBox = curWaterBox;
*ySurface = curWaterBox->minPos.y;
return true;
@@ -4425,27 +4450,24 @@ s32 WaterBox_GetSurfaceImpl(PlayState* play, CollisionContext* colCtx, f32 x, f3
}
for (i = 0; i < BG_ACTOR_MAX; i++) {
- if (colCtx->dyna.bgActorFlags[i] & 1) {
- BgActor* bgActor;
- if (colCtx->dyna.bgActorFlags[i] & 4) {
- continue;
- }
- bgActor = &colCtx->dyna.bgActors[i];
- if (bgActor->colHeader->numWaterBoxes != 0 && bgActor->colHeader->waterBoxes != NULL) {
- for (curWaterBox = colCtx->dyna.waterBoxList.boxes + bgActor->waterboxesStartIndex;
- curWaterBox < colCtx->dyna.waterBoxList.boxes + bgActor->waterboxesStartIndex +
- bgActor->colHeader->numWaterBoxes;
- curWaterBox++) {
- if (curWaterBox->properties & 0x80000) {
- continue;
- }
- if (curWaterBox->minPos.x < x && x < curWaterBox->minPos.x + curWaterBox->xLength) {
- if (curWaterBox->minPos.z < z && z < curWaterBox->minPos.z + curWaterBox->zLength) {
- *outWaterBox = curWaterBox;
- *ySurface = curWaterBox->minPos.y;
- *bgId = i;
- return true;
- }
+ if (!(colCtx->dyna.bgActorFlags[i] & 1) || (colCtx->dyna.bgActorFlags[i] & 4)) {
+ continue;
+ }
+ bgActor = &colCtx->dyna.bgActors[i];
+ if ((bgActor->colHeader->numWaterBoxes != 0) && (bgActor->colHeader->waterBoxes != NULL)) {
+ for (curWaterBox = colCtx->dyna.waterBoxList.boxes + bgActor->waterboxesStartIndex;
+ curWaterBox <
+ colCtx->dyna.waterBoxList.boxes + bgActor->waterboxesStartIndex + bgActor->colHeader->numWaterBoxes;
+ curWaterBox++) {
+ if (curWaterBox->properties & 0x80000) {
+ continue;
+ }
+ if ((curWaterBox->minPos.x < x) && (x < curWaterBox->minPos.x + curWaterBox->xLength)) {
+ if ((curWaterBox->minPos.z < z) && (z < curWaterBox->minPos.z + curWaterBox->zLength)) {
+ *outWaterBox = curWaterBox;
+ *ySurface = curWaterBox->minPos.y;
+ *bgId = i;
+ return true;
}
}
}
@@ -4467,7 +4489,6 @@ s32 WaterBox_GetSurface1_2(PlayState* play, CollisionContext* colCtx, f32 x, f32
return WaterBox_GetSurfaceImpl(play, colCtx, x, z, ySurface, outWaterBox, &bgId);
}
-#ifdef NON_MATCHING
/**
* Gets the first active WaterBox at `pos` where WaterBox.properties & 0x80000 == 0
* `surfaceCheckDist` is the absolute y distance from the water surface to check
@@ -4480,12 +4501,13 @@ s32 WaterBox_GetSurface2(PlayState* play, CollisionContext* colCtx, Vec3f* pos,
s32 room;
s32 i;
WaterBox* waterBox;
+ BgActor* bgActor;
*bgId = BGCHECK_SCENE;
colHeader = colCtx->colHeader;
//! @bug: check skips testing BgActor waterboxes
- if (colHeader->numWaterBoxes == 0 || colHeader->waterBoxes == NULL) {
+ if ((colHeader->numWaterBoxes == 0) || (colHeader->waterBoxes == NULL)) {
*outWaterBox = NULL;
return -1;
}
@@ -4494,15 +4516,16 @@ s32 WaterBox_GetSurface2(PlayState* play, CollisionContext* colCtx, Vec3f* pos,
waterBox = &colHeader->waterBoxes[i];
room = WATERBOX_ROOM(waterBox->properties);
- if (!(room == play->roomCtx.curRoom.num || room == 0x3F)) {
+ if ((room != play->roomCtx.curRoom.num) && (room != 0x3F)) {
continue;
}
if ((waterBox->properties & 0x80000)) {
continue;
}
- if ((waterBox->minPos.x < pos->x && pos->x < waterBox->minPos.x + waterBox->xLength)) {
- if ((waterBox->minPos.z < pos->z && pos->z < waterBox->minPos.z + waterBox->zLength)) {
- if (pos->y - surfaceCheckDist < waterBox->minPos.y && waterBox->minPos.y < pos->y + surfaceCheckDist) {
+ if (((waterBox->minPos.x < pos->x) && (pos->x < waterBox->minPos.x + waterBox->xLength))) {
+ if ((waterBox->minPos.z < pos->z) && (pos->z < waterBox->minPos.z + waterBox->zLength)) {
+ if ((pos->y - surfaceCheckDist < waterBox->minPos.y) &&
+ (waterBox->minPos.y < pos->y + surfaceCheckDist)) {
*outWaterBox = waterBox;
return i;
}
@@ -4511,27 +4534,25 @@ s32 WaterBox_GetSurface2(PlayState* play, CollisionContext* colCtx, Vec3f* pos,
}
for (i = 0; i < BG_ACTOR_MAX; i++) {
- WaterBox* iterator;
- WaterBox* start;
- BgActor* bgActor;
+
if (!(colCtx->dyna.bgActorFlags[i] & 1) || (colCtx->dyna.bgActorFlags[i] & 4) ||
(colCtx->dyna.bgActorFlags[i] & 2)) {
continue;
}
bgActor = &colCtx->dyna.bgActors[i];
- for (iterator = colCtx->dyna.waterBoxList.boxes + bgActor->waterboxesStartIndex;
- iterator <
+ for (waterBox = colCtx->dyna.waterBoxList.boxes + bgActor->waterboxesStartIndex;
+ waterBox <
colCtx->dyna.waterBoxList.boxes + bgActor->waterboxesStartIndex + bgActor->colHeader->numWaterBoxes;
- iterator++) {
- if (iterator->properties & 0x80000) {
+ waterBox++) {
+ if (waterBox->properties & 0x80000) {
continue;
}
- if ((iterator->minPos.x < pos->x) && pos->x < iterator->minPos.x + iterator->xLength) {
- if ((iterator->minPos.z < pos->z) && pos->z < iterator->minPos.z + iterator->zLength) {
- if (pos->y - surfaceCheckDist < iterator->minPos.y &&
- iterator->minPos.y < pos->y + surfaceCheckDist) {
+ if ((waterBox->minPos.x < pos->x) && (pos->x < waterBox->minPos.x + waterBox->xLength)) {
+ if ((waterBox->minPos.z < pos->z) && (pos->z < waterBox->minPos.z + waterBox->zLength)) {
+ if ((pos->y - surfaceCheckDist < waterBox->minPos.y) &&
+ (waterBox->minPos.y < pos->y + surfaceCheckDist)) {
*bgId = i;
- *outWaterBox = iterator;
+ *outWaterBox = waterBox;
return i;
}
}
@@ -4542,9 +4563,6 @@ s32 WaterBox_GetSurface2(PlayState* play, CollisionContext* colCtx, Vec3f* pos,
*outWaterBox = NULL;
return -1;
}
-#else
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/WaterBox_GetSurface2.s")
-#endif
f32 func_800CA568(CollisionContext* colCtx, s32 waterBoxId, s32 bgId) {
CollisionHeader* colHeader;
@@ -4611,7 +4629,6 @@ u32 WaterBox_GetLightSettingIndex(CollisionContext* colCtx, WaterBox* waterBox)
return prop & 0x1F;
}
-#ifdef NON_MATCHING
/**
* Get the water surface at point (`x`, `ySurface`, `z`). `ySurface` doubles as position y input
* same as WaterBox_GetSurfaceImpl, but tests if WaterBox properties & 0x80000 != 0
@@ -4621,62 +4638,61 @@ u32 WaterBox_GetLightSettingIndex(CollisionContext* colCtx, WaterBox* waterBox)
s32 func_800CA6F0(PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, WaterBox** outWaterBox,
s32* bgId) {
CollisionHeader* colHeader;
- u32 room;
- WaterBox* curWaterBox;
s32 i;
+ WaterBox* curWaterBox;
BgActor* bgActor;
+ s32 room;
- colHeader = colCtx->colHeader;
*outWaterBox = NULL;
*bgId = BGCHECK_SCENE;
+ colHeader = colCtx->colHeader;
- if (colHeader->numWaterBoxes == 0 || colHeader->waterBoxes == NULL) {
+ if ((colHeader->numWaterBoxes == 0) || (colHeader->waterBoxes == NULL)) {
return false;
}
for (curWaterBox = colHeader->waterBoxes; curWaterBox < colHeader->waterBoxes + colHeader->numWaterBoxes;
curWaterBox++) {
room = WATERBOX_ROOM(curWaterBox->properties);
- if (room == (u32)play->roomCtx.curRoom.num || room == 0x3F) {
- if ((curWaterBox->properties & 0x80000) != 0) {
- if (curWaterBox->minPos.x < x && x < curWaterBox->minPos.x + curWaterBox->xLength) {
- if (curWaterBox->minPos.z < z && z < curWaterBox->minPos.z + curWaterBox->zLength) {
- *outWaterBox = curWaterBox;
- *ySurface = curWaterBox->minPos.y;
- return true;
- }
- }
+
+ if ((room != play->roomCtx.curRoom.num) && (room != 0x3F)) {
+ continue;
+ }
+ if (!(curWaterBox->properties & 0x80000)) {
+ continue;
+ }
+ if ((curWaterBox->minPos.x < x) && (x < curWaterBox->minPos.x + curWaterBox->xLength)) {
+ if ((curWaterBox->minPos.z < z) && (z < curWaterBox->minPos.z + curWaterBox->zLength)) {
+ *outWaterBox = curWaterBox;
+ *ySurface = curWaterBox->minPos.y;
+ return true;
}
}
}
-
for (i = 0; i < BG_ACTOR_MAX; i++) {
- if ((colCtx->dyna.bgActorFlags[i] & 1) && !(colCtx->dyna.bgActorFlags[i] & 2)) {
- WaterBox* boxes;
- boxes = colCtx->dyna.waterBoxList.boxes;
- bgActor = &colCtx->dyna.bgActors[i];
- if (bgActor->colHeader->numWaterBoxes != 0 && bgActor->colHeader->waterBoxes != NULL) {
- for (curWaterBox = boxes + bgActor->waterboxesStartIndex;
- curWaterBox < boxes + bgActor->waterboxesStartIndex + bgActor->colHeader->numWaterBoxes;
- curWaterBox++) {
- if ((curWaterBox->properties & 0x80000) != 0) {
- if (curWaterBox->minPos.x < x && x < curWaterBox->minPos.x + curWaterBox->xLength) {
- if (curWaterBox->minPos.z < z && z < curWaterBox->minPos.z + curWaterBox->zLength) {
- *outWaterBox = curWaterBox;
- *ySurface = curWaterBox->minPos.y;
- *bgId = i;
- return true;
- }
- }
- }
+ if (!(colCtx->dyna.bgActorFlags[i] & 1) || (colCtx->dyna.bgActorFlags[i] & 2)) {
+ continue;
+ }
+ bgActor = &colCtx->dyna.bgActors[i];
+
+ for (curWaterBox = colCtx->dyna.waterBoxList.boxes + bgActor->waterboxesStartIndex;
+ curWaterBox <
+ colCtx->dyna.waterBoxList.boxes + bgActor->waterboxesStartIndex + bgActor->colHeader->numWaterBoxes;
+ curWaterBox++) {
+ if (!(curWaterBox->properties & 0x80000)) {
+ continue;
+ }
+ if ((curWaterBox->minPos.x < x) && (x < curWaterBox->minPos.x + curWaterBox->xLength)) {
+ if ((curWaterBox->minPos.z < z) && (z < curWaterBox->minPos.z + curWaterBox->zLength)) {
+ *outWaterBox = curWaterBox;
+ *ySurface = curWaterBox->minPos.y;
+ *bgId = i;
+ return true;
}
}
}
}
return false;
}
-#else
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800CA6F0.s")
-#endif
s32 func_800CA9D0(PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, WaterBox** outWaterBox) {
s32 bgId;