From 6bdf619a624109061fe7508879ccff29367a18c3 Mon Sep 17 00:00:00 2001 From: mzxrules Date: Tue, 3 Jun 2025 20:49:22 -0400 Subject: [PATCH] Collision tweaks --- include/z64bgcheck.h | 2 +- include/z64collision_check.h | 1 + src/code/sys_math3d.c | 6 +++--- src/code/z_actor.c | 5 +++-- src/code/z_bgcheck.c | 7 +++++-- src/code/z_camera.c | 8 ++++---- src/overlays/actors/ovl_En_Dekubaba/z_en_dekubaba.c | 3 ++- src/overlays/actors/ovl_En_Karebaba/z_en_karebaba.c | 3 ++- src/overlays/actors/ovl_En_Nwc/z_en_nwc.c | 2 +- src/overlays/actors/ovl_En_Wallmas/z_en_wallmas.c | 4 ++-- .../effects/ovl_Effect_Ss_Dead_Ds/z_eff_ss_dead_ds.c | 4 ++-- 11 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/z64bgcheck.h b/include/z64bgcheck.h index eb7e9155d0..7bb5ca4ad4 100644 --- a/include/z64bgcheck.h +++ b/include/z64bgcheck.h @@ -361,7 +361,7 @@ typedef struct DynaLineTest { /* 0x28 */ f32 chkDist; // distance from poly } DynaLineTest; -void func_80038A28(CollisionPoly* poly, f32 tx, f32 ty, f32 tz, MtxF* dest); +void CollisionPoly_GetGroundMtxF(CollisionPoly* poly, f32 tx, f32 ty, f32 tz, MtxF* dest); f32 CollisionPoly_GetPointDistanceFromPlane(CollisionPoly* poly, Vec3f* point); void CollisionPoly_GetVerticesByBgId(CollisionPoly* poly, s32 bgId, CollisionContext* colCtx, Vec3f* dest); void BgCheck_Allocate(CollisionContext* colCtx, struct PlayState* play, CollisionHeader* colHeader); diff --git a/include/z64collision_check.h b/include/z64collision_check.h index 2c27563766..1976710c58 100644 --- a/include/z64collision_check.h +++ b/include/z64collision_check.h @@ -534,6 +534,7 @@ s32 CollisionCheck_SetOC(struct PlayState* play, CollisionCheckContext* colChkCt s32 CollisionCheck_SetOC_SAC(struct PlayState* play, CollisionCheckContext* colChkCtx, Collider* collider, s32 index); s32 CollisionCheck_SetOCLine(struct PlayState* play, CollisionCheckContext* colChkCtx, OcLine* collider); void CollisionCheck_BlueBlood(struct PlayState* play, Collider* collider, Vec3f* v); +void CollisionCheck_GreenBlood(struct PlayState* play, Collider* collider, Vec3f* v); void CollisionCheck_AT(struct PlayState* play, CollisionCheckContext* colChkCtx); void CollisionCheck_OC(struct PlayState* play, CollisionCheckContext* colChkCtx); void CollisionCheck_InitInfo(CollisionCheckInfo* info); diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 1ce651e9c9..e83dcbc6f5 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -30,7 +30,7 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 static InfiniteLine planeIntersectLine; static Linef planeIntersectSeg; - Vec3f sp34; // unused + Vec3f _point; // discarded if (!Math3D_PlaneVsPlaneNewLine(planeAA, planeAB, planeAC, planeADist, planeBA, planeBB, planeBC, planeBDist, &planeIntersectLine)) { @@ -44,9 +44,9 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeIntersectSeg.b.y = (planeIntersectLine.dir.y * 100.0f) + planeIntersectLine.point.y; planeIntersectSeg.b.z = (planeIntersectLine.dir.z * 100.0f) + planeIntersectLine.point.z; - // closestPoint is a point on planeIntersect, sp34 is a point on linePointA, linePointB + // closestPoint is a point on planeIntersect, _point is a point on linePointA, linePointB if (!Math3D_LineVsLineClosestTwoPoints(&planeIntersectSeg.a, &planeIntersectSeg.b, linePointA, linePointB, - closestPoint, &sp34)) { + closestPoint, &_point)) { return false; } return true; diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 83105d23ec..c03c10e993 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -97,7 +97,8 @@ void ActorShadow_Draw(Actor* actor, Lights* lights, PlayState* play, Gfx* dlist, gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 0, 0, 0, (u32)(actor->shape.shadowAlpha * temp2) & 0xFF); } - func_80038A28(actor->floorPoly, actor->world.pos.x, actor->floorHeight, actor->world.pos.z, &sp60); + CollisionPoly_GetGroundMtxF(actor->floorPoly, actor->world.pos.x, actor->floorHeight, actor->world.pos.z, + &sp60); Matrix_Put(&sp60); if (dlist != gCircleShadowDL) { @@ -4053,7 +4054,7 @@ void func_80033C30(Vec3f* arg0, Vec3f* arg1, u8 alpha, PlayState* play) { yIntersect = BgCheck_EntityRaycastDown2(play, &play->colCtx, &groundPoly, &checkPos); if (groundPoly != NULL) { - func_80038A28(groundPoly, arg0->x, yIntersect, arg0->z, &sp60); + CollisionPoly_GetGroundMtxF(groundPoly, arg0->x, yIntersect, arg0->z, &sp60); Matrix_Put(&sp60); } else { Matrix_Translate(arg0->x, arg0->y, arg0->z, MTXMODE_NEW); diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index 945051552a..d11aca16f8 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -243,7 +243,7 @@ void CollisionPoly_GetNormalF(CollisionPoly* poly, f32* nx, f32* ny, f32* nz) { /** * Compute transform matrix mapping +y (up) to the collision poly's normal */ -void func_80038A28(CollisionPoly* poly, f32 tx, f32 ty, f32 tz, MtxF* dest) { +void CollisionPoly_GetGroundMtxF(CollisionPoly* poly, f32 tx, f32 ty, f32 tz, MtxF* dest) { f32 nx; f32 ny; f32 nz; @@ -3919,7 +3919,10 @@ void CollisionHeader_GetVirtual(void* colHeader, CollisionHeader** dest) { } /** - * SEGMENT_TO_VIRTUAL all active BgActor CollisionHeaders + * SEGMENTED_TO_VIRTUAL all active BgActor CollisionHeaders + * + * When the game is paused, object data is clobbered to make space for the pause menu assets. + * Once the object data is restored, pointers in the CollisionHeader must be linked again before the game can resume. */ void func_800418D0(CollisionContext* colCtx, PlayState* play) { DynaCollisionContext* dyna = &colCtx->dyna; diff --git a/src/code/z_camera.c b/src/code/z_camera.c index cf18c3634a..f07954e36d 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -1012,7 +1012,7 @@ s32 func_80045508(Camera* camera, VecGeo* diffGeo, CamColChk* eyeChk, CamColChk* eyeChk->geoNorm = OLib_Vec3fToVecGeo(&eyeChk->norm); - if (eyeChk->geoNorm.pitch >= 0x2EE1) { + if (eyeChk->geoNorm.pitch > 0x2EE0) { eyeChk->geoNorm.yaw = diffGeo->yaw; } @@ -1042,7 +1042,7 @@ s32 func_80045508(Camera* camera, VecGeo* diffGeo, CamColChk* eyeChk, CamColChk* atChk->geoNorm = OLib_Vec3fToVecGeo(&atChk->norm); - if (atChk->geoNorm.pitch >= 0x2EE1) { + if (atChk->geoNorm.pitch > 0x2EE0) { atChk->geoNorm.yaw = diffGeo->yaw - 0x7FFF; } @@ -1961,7 +1961,7 @@ s32 Camera_Normal2(Camera* camera) { camera->dist = adjGeo.r = Camera_ClampDist(camera, sp90.r, roData->unk_04, roData->unk_08, 0); if (!(rwData->unk_28 & 1)) { - if (adjGeo.pitch >= 0xE39) { + if (adjGeo.pitch > 0xE38) { adjGeo.pitch += ((s16)(0xE38 - adjGeo.pitch) >> 2); } @@ -5684,7 +5684,7 @@ s32 Camera_Unique9(Camera* camera) { scratchGeo.yaw += CAM_DEG_TO_BINANG(rwData->curKeyFrame->eyeTargetInit.y); // 3A98 ~ 82.40 degrees - if (scratchGeo.pitch >= 0x3A99) { + if (scratchGeo.pitch > 0x3A98) { scratchGeo.pitch = 0x3A98; } diff --git a/src/overlays/actors/ovl_En_Dekubaba/z_en_dekubaba.c b/src/overlays/actors/ovl_En_Dekubaba/z_en_dekubaba.c index df9b566f87..850433a838 100644 --- a/src/overlays/actors/ovl_En_Dekubaba/z_en_dekubaba.c +++ b/src/overlays/actors/ovl_En_Dekubaba/z_en_dekubaba.c @@ -1266,7 +1266,8 @@ void EnDekubaba_DrawBaseShadow(EnDekubaba* this, PlayState* play) { gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 0, 0, 0, 255); - func_80038A28(this->boundFloor, this->actor.home.pos.x, this->actor.home.pos.y, this->actor.home.pos.z, &mtx); + CollisionPoly_GetGroundMtxF(this->boundFloor, this->actor.home.pos.x, this->actor.home.pos.y, + this->actor.home.pos.z, &mtx); Matrix_Mult(&mtx, MTXMODE_NEW); horizontalScale = this->size * 0.15f; diff --git a/src/overlays/actors/ovl_En_Karebaba/z_en_karebaba.c b/src/overlays/actors/ovl_En_Karebaba/z_en_karebaba.c index be3b0eacb5..a9c576d778 100644 --- a/src/overlays/actors/ovl_En_Karebaba/z_en_karebaba.c +++ b/src/overlays/actors/ovl_En_Karebaba/z_en_karebaba.c @@ -459,7 +459,8 @@ void EnKarebaba_DrawBaseShadow(EnKarebaba* this, PlayState* play) { Gfx_SetupDL_44Xlu(play->state.gfxCtx); gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 0, 0, 0, 255); - func_80038A28(this->boundFloor, this->actor.home.pos.x, this->actor.home.pos.y, this->actor.home.pos.z, &mf); + CollisionPoly_GetGroundMtxF(this->boundFloor, this->actor.home.pos.x, this->actor.home.pos.y, + this->actor.home.pos.z, &mf); Matrix_Mult(&mf, MTXMODE_NEW); Matrix_Scale(0.15f, 1.0f, 0.15f, MTXMODE_APPLY); MATRIX_FINALIZE_AND_LOAD(POLY_XLU_DISP++, play->state.gfxCtx, "../z_en_karebaba.c", 1029); diff --git a/src/overlays/actors/ovl_En_Nwc/z_en_nwc.c b/src/overlays/actors/ovl_En_Nwc/z_en_nwc.c index a5f322def6..f688e0f48d 100644 --- a/src/overlays/actors/ovl_En_Nwc/z_en_nwc.c +++ b/src/overlays/actors/ovl_En_Nwc/z_en_nwc.c @@ -197,7 +197,7 @@ void EnNwc_DrawChicks(EnNwc* this, PlayState* play) { for (i = 0; i < this->count; i++, chick++) { if ((chick->type != CHICK_NONE) && (chick->floorPoly != NULL)) { - func_80038A28(chick->floorPoly, chick->pos.x, chick->floorY, chick->pos.z, &floorMat); + CollisionPoly_GetGroundMtxF(chick->floorPoly, chick->pos.x, chick->floorY, chick->pos.z, &floorMat); Matrix_Put(&floorMat); Matrix_RotateY(BINANG_TO_RAD(chick->rot.y), MTXMODE_APPLY); Matrix_Scale(1.0f, 1.0f, 1.0f, MTXMODE_APPLY); diff --git a/src/overlays/actors/ovl_En_Wallmas/z_en_wallmas.c b/src/overlays/actors/ovl_En_Wallmas/z_en_wallmas.c index abb91c80b9..56585bbe01 100644 --- a/src/overlays/actors/ovl_En_Wallmas/z_en_wallmas.c +++ b/src/overlays/actors/ovl_En_Wallmas/z_en_wallmas.c @@ -608,8 +608,8 @@ void EnWallmas_DrawXlu(EnWallmas* this, PlayState* play) { Gfx_SetupDL_44Xlu(play->state.gfxCtx); gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 0, 0, 0, 255); - func_80038A28(this->actor.floorPoly, this->actor.world.pos.x, this->actor.floorHeight, this->actor.world.pos.z, - &mf); + CollisionPoly_GetGroundMtxF(this->actor.floorPoly, this->actor.world.pos.x, this->actor.floorHeight, + this->actor.world.pos.z, &mf); Matrix_Mult(&mf, MTXMODE_NEW); if ((this->actionFunc != EnWallmas_WaitToDrop) && (this->actionFunc != EnWallmas_ReturnToCeiling) && diff --git a/src/overlays/effects/ovl_Effect_Ss_Dead_Ds/z_eff_ss_dead_ds.c b/src/overlays/effects/ovl_Effect_Ss_Dead_Ds/z_eff_ss_dead_ds.c index 4d649d4be4..804f3430ea 100644 --- a/src/overlays/effects/ovl_Effect_Ss_Dead_Ds/z_eff_ss_dead_ds.c +++ b/src/overlays/effects/ovl_Effect_Ss_Dead_Ds/z_eff_ss_dead_ds.c @@ -79,14 +79,14 @@ void EffectSsDeadDs_Draw(PlayState* play, u32 index, EffectSs* this) { prevPos.z = pos.z - this->velocity.z; if (BgCheck_EntitySphVsWall1(&play->colCtx, &this->pos, &pos, &prevPos, 1.5f, &groundPoly, 1.0f)) { - func_80038A28(groundPoly, this->pos.x, this->pos.y, this->pos.z, &mf); + CollisionPoly_GetGroundMtxF(groundPoly, this->pos.x, this->pos.y, this->pos.z, &mf); Matrix_Put(&mf); } else { pos.y++; yIntersect = BgCheck_EntityRaycastDown1(&play->colCtx, &groundPoly, &pos); if (groundPoly != NULL) { - func_80038A28(groundPoly, this->pos.x, yIntersect + 1.5f, this->pos.z, &mf); + CollisionPoly_GetGroundMtxF(groundPoly, this->pos.x, yIntersect + 1.5f, this->pos.z, &mf); Matrix_Put(&mf); } else { Matrix_Translate(this->pos.x, this->pos.y, this->pos.z, MTXMODE_NEW);