From 6b493d3f9d79dd2546e833998f3b9ba8a747223a Mon Sep 17 00:00:00 2001 From: mzxrules Date: Tue, 23 Nov 2021 11:29:18 -0500 Subject: [PATCH] z_bgcheck.c (#357) * first few functions * two more almost matching functions * Rebase to NBS, get it to compile * BgCheck_RaycastFloorStaticList OK, fix-up some functions * BgCheck_SphVsStaticWall OK! and a few others * more z_bgcheck NON_MATCHINGS * OK more functions, reorganize external reference #defines * More functions OK, more struct fixes * More OKs * Decomp all the way to the end of bgcheck * All functions attempted * Rename functions * formatting, data migration * Give names to unk structs, rename some structs, fix some non-equivalent functions * WaterBox_GetSurfaceImpl OK * BgCheck_ResetPolyCheckTbl OK, improve WaterBox_GetSurface2 codegen, eliminate warnings and clean up source. * BcCheck3_BgActorInit ->BgCheck3_BgActorInit, fix warnings * pr change requests * fix crc maybe * implement more changes * implement alf's changes --- include/functions.h | 394 +- include/variables.h | 35 +- include/z64.h | 66 - include/z64bgcheck.h | 247 +- spec | 2 - src/code/sys_math3d.c | 50 +- src/code/z_bg_collect.c | 48 +- src/code/z_bg_item.c | 20 +- src/code/z_bgcheck.c | 5071 +++++++++++++++-- src/code/z_collision_check.c | 6 +- src/code/z_fireobj.c | 6 +- src/code/z_quake.c | 5 +- src/code/z_scene.c | 2 +- src/code/z_scene_proc.c | 4 +- src/code/z_snap.c | 7 +- .../actors/ovl_Arms_Hook/z_arms_hook.c | 27 +- .../ovl_Bg_Ctower_Gear/z_bg_ctower_gear.c | 2 +- .../ovl_Bg_Ctower_Rot/z_bg_ctower_rot.c | 2 +- .../actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.c | 16 +- .../actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.h | 2 +- .../ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c | 2 +- .../actors/ovl_Bg_Haka_Tomb/z_bg_haka_tomb.c | 2 +- .../ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c | 4 +- .../actors/ovl_Bg_Icicle/z_bg_icicle.c | 2 +- .../ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c | 2 +- .../ovl_Bg_Iknin_Susceil/z_bg_iknin_susceil.c | 2 +- .../actors/ovl_Bg_Iknv_Obj/z_bg_iknv_obj.c | 10 +- .../ovl_Bg_Kin2_Fence/z_bg_kin2_fence.c | 2 +- .../actors/ovl_Bg_Ladder/z_bg_ladder.c | 2 +- .../actors/ovl_Bg_Lbfshot/z_bg_lbfshot.c | 2 +- src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c | 12 +- .../ovl_Bg_Mbar_Chair/z_bg_mbar_chair.c | 2 +- .../actors/ovl_Bg_Tobira01/z_bg_tobira01.c | 5 +- src/overlays/actors/ovl_Boss_02/z_boss_02.c | 9 +- .../actors/ovl_Dm_Char07/z_dm_char07.c | 2 +- .../actors/ovl_En_Clear_Tag/z_en_clear_tag.c | 6 +- src/overlays/actors/ovl_En_Dg/z_en_dg.c | 20 +- src/overlays/actors/ovl_En_Dnb/z_en_dnb.c | 2 +- src/overlays/actors/ovl_En_Dns/z_en_dns.c | 2 +- .../actors/ovl_En_Dodongo/z_en_dodongo.c | 2 +- .../actors/ovl_En_Encount2/z_en_encount2.c | 6 +- src/overlays/actors/ovl_En_Fish2/z_en_fish2.c | 25 +- src/overlays/actors/ovl_En_Fu/z_en_fu.c | 2 +- .../actors/ovl_En_Goroiwa/z_en_goroiwa.c | 21 +- .../actors/ovl_En_Invadepoh/z_en_invadepoh.c | 14 +- src/overlays/actors/ovl_En_Mm/z_en_mm.c | 2 +- .../actors/ovl_En_Mushi2/z_en_mushi2.c | 102 +- .../actors/ovl_En_Mushi2/z_en_mushi2.h | 4 +- src/overlays/actors/ovl_En_Niw/z_en_niw.c | 2 +- .../actors/ovl_En_Nutsball/z_en_nutsball.c | 6 +- src/overlays/actors/ovl_En_Ot/z_en_ot.c | 15 +- .../actors/ovl_En_Pametfrog/z_en_pametfrog.c | 14 +- .../ovl_En_Po_Sisters/z_en_po_sisters.c | 13 +- .../actors/ovl_En_Suttari/z_en_suttari.c | 12 +- src/overlays/actors/ovl_En_Sw/z_en_sw.c | 15 +- src/overlays/actors/ovl_En_Tite/z_en_tite.c | 6 +- src/overlays/actors/ovl_En_Tk/z_en_tk.c | 15 +- src/overlays/actors/ovl_Obj_Aqua/z_obj_aqua.c | 4 +- src/overlays/actors/ovl_Obj_Bell/z_obj_bell.c | 2 +- .../actors/ovl_Obj_Etcetera/z_obj_etcetera.c | 10 +- .../actors/ovl_Obj_Ghaka/z_obj_ghaka.c | 6 +- .../actors/ovl_Obj_Hgdoor/z_obj_hgdoor.c | 8 +- .../actors/ovl_Obj_HsStump/z_obj_hsstump.c | 2 +- .../ovl_Obj_Kepn_Koya/z_obj_kepn_koya.c | 4 +- .../actors/ovl_Obj_Kibako/z_obj_kibako.c | 7 +- .../actors/ovl_Obj_Kibako2/z_obj_kibako2.c | 6 +- .../ovl_Obj_Lightblock/z_obj_lightblock.c | 2 +- .../ovl_Obj_Makeoshihiki/z_obj_makeoshihiki.c | 2 +- .../actors/ovl_Obj_Raillift/z_obj_raillift.c | 2 +- .../actors/ovl_Obj_Syokudai/z_obj_syokudai.c | 4 +- .../ovl_Obj_Tokei_Step/z_obj_tokei_step.c | 2 +- .../ovl_Obj_Visiblock/z_obj_visiblock.c | 2 +- tools/disasm/functions.txt | 364 +- tools/disasm/variables.txt | 39 +- 74 files changed, 5551 insertions(+), 1293 deletions(-) diff --git a/include/functions.h b/include/functions.h index 231056fc89..806c7e65bf 100644 --- a/include/functions.h +++ b/include/functions.h @@ -912,199 +912,159 @@ void ActorOverlayTable_FaultPrint(void* arg0, void* arg1); // ActorOverlayTable_ void* ActorOverlayTable_FaultAddrConv(void* arg0, void* arg1); // ActorOverlayTable_FaultAddrConv void ActorOverlayTable_Init(void); // ActorOverlayTable_Init void ActorOverlayTable_Cleanup(void); // ActorOverlayTable_Cleanup -void BgCheck_PolygonLinkedListNodeInit(SSNode* node, s16* polyIndex, u16 next); -void BgCheck_PolygonLinkedListResetHead(u16* head); -void BgCheck_ScenePolygonListsNodeInsert(SSNodeList* list, u16* head, s16* polyIndex); -void BgCheck_PolygonLinkedListNodeInsert(DynaSSNodeList* list, u16* head, s16* polyIndex); -void BgCheck_PolygonLinkedListInit(GlobalContext* globalCtx, DynaSSNodeList* list); -void BgCheck_PolygonLinkedListAlloc(GlobalContext* globalCtx, DynaSSNodeList* list, u32 numNodes); -void BgCheck_PolygonLinkedListReset(DynaSSNodeList* list); -u16 BgCheck_AllocPolygonLinkedListNode(DynaSSNodeList* list); -void BgCheck_CreateVec3fFromVertex(Vec3s* vertex, Vec3f* vector); -void BgCheck_CreateVertexFromVec3f(Vec3s* vertex, Vec3f* vector); -float func_800BFD84(CollisionPoly* polygon, f32 param_2, f32 param_3); -s32 func_800BFDEC(CollisionPoly* param_1, CollisionPoly* param_2, u32* param_3, u32* param_4); -s32 BgCheck_PolygonGetMinY(CollisionPoly* polygons, Vec3s* vertices); -void BgCheck_PolygonGetNormal(CollisionPoly* polygon, f32* normalX, f32* normalY, f32* normalZ); -void func_800C0094(struct CollisionPoly* param_1, f32 xOffset, f32 yOffset, f32 zOffset, MtxF* matrix); -f32 func_800C01B8(CollisionPoly* param_1, Vec3f* param_2); -void BgCheck_CreateColTriParamsFromPolygon(CollisionPoly* polygon, Vec3s* vertices, TriNorm* tri); -void func_800C02C0(CollisionPoly* poly, s32 index, CollisionContext* colCtx, TriNorm* tri); -// void func_800C0340(CollisionPoly* param_1, Vec3s* param_2, UNK_TYPE4 param_3, UNK_TYPE4 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// UNK_TYPE4 func_800C0474(CollisionPoly* param_1, Vec3s* param_2, UNK_TYPE4 param_3, UNK_TYPE4 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// void func_800C0668(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -// void func_800C06A8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -// void func_800C074C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -// void func_800C07F0(void); -void BgCheck_PolygonCollidesWithSphere(CollisionPoly* polygon, Vec3s* verticies, Vec3f* pos, f32 readius); -void BgCheck_ScenePolygonListsInsertSorted(CollisionContext* colCtx, u16* head, CollisionPoly* polygons, Vec3s* vertices, s16 index); -void BgCheck_ScenePolygonListsInsert(StaticLookup* subdivision, CollisionContext* colCtx, CollisionPoly* polygons, Vec3s* vertices, s16 index); -// void func_800C0E74(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); -// void func_800C10FC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9); -// void func_800C1238(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE1 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); -// void func_800C12A4(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9); -// void func_800C1B68(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); -// void func_800C1D7C(void); -// void func_800C2008(void); -// void func_800C20F4(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_800C2310(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE2 param_7, UNK_TYPE4 param_8); -// void func_800C2460(void); -// void func_800C2514(void); -// void func_800C25E0(void); -void BgCheck_GetPolyMinSubdivisions(CollisionContext* colCtx, Vec3f* min, s32* xSubdivision, s32* ySubdivision, s32* zSubdivision); -void BgCheck_GetPolyMaxSubdivisions(CollisionContext* colCtx, Vec3f* max, s32* xSubdivision, s32* ySubdivision, s32* zSubdivision); -void BgCheck_GetPolyMinMaxSubdivisions(CollisionContext* colCtx, Vec3s* vertices, CollisionPoly* polygons, s32* minX, s32* minY, s32* minZ, s32* maxX, s32* maxY, s32* maxZ, s16 index); -// UNK_TYPE4 func_800C2BE0(Vec3f* param_1, Vec3f* param_2, CollisionPoly* polygons, Vec3s* vertices, s16 index); -u32 BgCheck_SplitScenePolygonsIntoSubdivisions(CollisionContext* colCtx, GlobalContext* globalCtx, StaticLookup* subdivisions); -s32 BgCheck_GetIsDefaultSpecialScene(GlobalContext* globalCtx); -s32 BgCheck_GetSpecialSceneMaxMemory(s32 sceneId, u32* maxMemory); -void BgCheck_CalcSubdivisionSize(f32 min, s32 subdivisions, f32* max, f32* subdivisionSize, f32* inverseSubdivisionSize); -s32 BgCheck_GetSpecialSceneMaxObjects(GlobalContext* globalCtx, u32* maxNodes, u32* maxPolygons, u32* maxVertices); -void BgCheck_Init(CollisionContext* colCtx, GlobalContext* globalCtx, CollisionHeader* mesh); -void func_800C3C00(CollisionContext* colCtx, u32 param_2); -void func_800C3C14(CollisionContext* colCtx, u32 param_2); -CollisionHeader* BgCheck_GetActorMeshHeader(CollisionContext* colCtx, s32 index); -// void func_800C3C94(void); -f32 func_800C3D50(s32 arg0, CollisionContext* colCtx, s32 arg2, CollisionPoly** arg3, s32* arg4, Vec3f* pos, Actor* actor, s32 arg7, f32 arg8, s32 arg9); -// void func_800C3F40(void); -f32 func_800C3FA0(CollisionContext* colCtx, CollisionPoly** arg1, Vec3f* arg2); -f32 func_800C4000(GlobalContext* globalCtx, CollisionContext* colCtx, s32* arg2, Vec3f* arg3); -// void func_800C4058(void); -f32 func_800C40B4(CollisionContext* colCtx, CollisionPoly** poly, s32* arg2, Vec3f* arg3); -f32 func_800C411C(CollisionContext* colCtx, CollisionPoly** arg1, s32* arg2, Actor* actor, Vec3f* pos); -f32 func_800C4188(GlobalContext* globalCtx, CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Actor* actor, Vec3f* pos); -// void func_800C41E4(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// void func_800C4240(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// void func_800C42A8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -// void func_800C4314(void); -// void func_800C43CC(void); -// void func_800C4488(void); -// void func_800C44F0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -// void func_800C455C(void); -s32 func_800C45C4(CollisionContext* colCtx, u32 arg1, Vec3f* arg2, Vec3f* arg3, Vec3f* arg4, f32 arg5, s32* arg6, s32* arg7, DynaPolyActor* arg8, f32 arg9, u8 arg10); -// void func_800C4C74(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_800C4CD8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); -// void func_800C4D3C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9); -// void func_800C4DA4(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9); -// void func_800C4E10(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); -// void func_800C4F38(void); -// void func_800C4F84(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_800C4FD4(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); -// void func_800C5464(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -// void func_800C54AC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); -// void func_800C5538(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); -s32 func_800C55C4(CollisionContext* colCtx, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, CollisionPoly** arg4, u32 arg5, u32 arg6, u32 arg7, u32 arg8, u32* arg9); -// void func_800C5650(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); -s32 func_800C56E0(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, s32 chkWall, s32 chkFloor, s32 chkCeil, s32 chkOneFace, s32* bgId, Actor* actor, f32 chkDist); -s32 func_800C576C(CollisionContext* colCtx, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, CollisionPoly** arg4, u32 arg5, u32 arg6, u32 arg7, u32 arg8, u32* arg9); -// void func_800C57F8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// void func_800C583C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9); -// void func_800C58C8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); -// void func_800C5954(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE2 param_8); -s32 func_800C5A20(CollisionContext* colCtx, Vec3f* arg1, f32 arg2); -s32 func_800C5A64(CollisionContext* colCtx, Vec3f* arg1, f32 arg2); -void BgCheck_ScenePolygonListsInit(SSNodeList* arg0); -void BgCheck_ScenePolygonListsAlloc(GlobalContext* globalCtx, SSNodeList* lists, s32 numNodes, u32 numPolygons); -s32 func_800C5B80(u16* arg0); -u16 BgCheck_ScenePolygonListsReserveNode(SSNodeList* lists); -void BgCheck_ActorMeshParamsInit(ScaleRotPos* params); -void BgCheck_SetActorMeshParams(ScaleRotPos* params, Vec3f* scale, Vec3s* rotation, Vec3f* position); -s32 BgCheck_AreActorMeshParamsEqual(ScaleRotPos* arg0, ScaleRotPos* arg1); -void BgCheck_ActorMeshPolyListsHeadsInit(DynaLookup* lists); -void BgCheck_ActorMeshPolyListsInit(DynaLookup* lists); -void BgCheck_ActorMeshVerticesIndexInit(s16* index); -void BgCheck_ActorMeshWaterboxesIndexInit(s16* index); -void BgCheck_ActorMeshInit(GlobalContext* globalCtx, BgActor* mesh); -void BgCheck_ActorMeshInitFromActor(BgActor* actorMesh, DynaPolyActor* actor, CollisionHeader* header); -s32 BgCheck_HasActorMeshChanged(BgActor* mesh); -void BgCheck_PolygonsInit(CollisionPoly** polygons); -void BgCheck_PolygonsAlloc(GlobalContext* globalCtx, CollisionPoly* polygons, u32 numPolygons); -void BgCheck_VerticesInit(Vec3s** vertices); -void BgCheck_VerticesListAlloc(GlobalContext* globalCtx, Vec3s** vertices, u32 numVertices); -void BgCheck_WaterboxListInit(DynaSSWaterboxList* waterboxList); -void BgCheck_WaterboxListAlloc(GlobalContext* globalCtx, DynaSSWaterboxList* waterboxList, u32 numWaterboxes); -void BgCheck_ActorMeshUpdateParams(GlobalContext* globalCtx, BgActor* mesh); -s32 BgCheck_IsActorMeshIndexValid(s32 index); -void BgCheck_DynaInit(GlobalContext* globalCtx, DynaCollisionContext* param_2); -void BgCheck_DynaAlloc(GlobalContext* globalCtx, DynaCollisionContext* dyna); -s32 BgCheck_AddActorMesh(GlobalContext* globalCtx, DynaCollisionContext* dyna, DynaPolyActor* actor, CollisionHeader* header); -DynaPolyActor* BgCheck_GetActorOfMesh(CollisionContext* colCtx, s32 index); -void func_800C62BC(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 index); -void func_800C6314(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 index); -void func_800C636C(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 index); -void func_800C63C4(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 index); -void func_800C641C(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 index); -void func_800C6474(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 index); -void BgCheck_RemoveActorMesh(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 index); -// void func_800C6554(void); +void SSNode_SetValue(SSNode* node, s16* polyIndex, u16 next); +void SSList_SetNull(SSList* head); +void SSNodeList_SetSSListHead(SSNodeList* list, SSList* ssList, s16* polyIndex); +void DynaSSNodeList_SetSSListHead(DynaSSNodeList* list, SSList* ssList, s16* polyIndex); +void DynaSSNodeList_Init(GlobalContext* globalCtx, DynaSSNodeList* list); +void DynaSSNodeList_Alloc(GlobalContext* globalCtx, DynaSSNodeList* list, u32 numNodes); +void DynaSSNodeList_ResetCount(DynaSSNodeList* list); +u16 DynaSSNodeList_GetNextNodeIdx(DynaSSNodeList* list); +void BgCheck_Vec3sToVec3f(Vec3s* vertex, Vec3f* vector); +void BgCheck_Vec3fToVec3s(Vec3s* vertex, Vec3f* vector); +f32 func_800BFD84(CollisionPoly *poly, f32 arg1, f32 arg2); +s32 func_800BFDEC(CollisionPoly* polyA, CollisionPoly* polyB, u32* outVtxId0, u32* outVtxId1); +s16 CollisionPoly_GetMinY(CollisionPoly* poly, Vec3s* vertices); +void CollisionPoly_GetNormalF(CollisionPoly* poly, f32* nx, f32* ny, f32* nz); +void func_800C0094(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); +s32 CollisionPoly_SphVsPoly(CollisionPoly* poly, Vec3s* vtxList, Vec3f* center, f32 radius); +void StaticLookup_AddPolyToSSList(CollisionContext* colCtx, SSList* ssList, CollisionPoly* polyList, Vec3s* vtxList, s16 polyId); +void StaticLookup_AddPoly(StaticLookup* lookup, CollisionContext* colCtx, CollisionPoly* polyList, Vec3s* vtxList, s16 index); +void BgCheck_GetSubdivisionMinBounds(CollisionContext* colCtx, Vec3f* pos, s32* sx, s32* sy, s32* sz); +void BgCheck_GetSubdivisionMaxBounds(CollisionContext* colCtx, Vec3f* pos, s32* sx, s32* sy, s32* sz); +void BgCheck_GetPolySubdivisionBounds(CollisionContext* colCtx, Vec3s* vtxList, CollisionPoly* polyList, s32* subdivMinX, s32* subdivMinY, s32* subdivMinZ, s32* subdivMaxX, s32* subdivMaxY, s32* subdivMaxZ, s16 polyId); +s32 BgCheck_PolyIntersectsSubdivision(Vec3f* min, Vec3f* max, CollisionPoly* polyList, Vec3s* vtxList, s16 polyId); +u32 BgCheck_InitStaticLookup(CollisionContext* colCtx, GlobalContext* globalCtx, StaticLookup* lookupTbl); +s32 BgCheck_IsSmallMemScene(GlobalContext* globalCtx); +s32 BgCheck_TryGetCustomMemsize(s32 sceneId, u32* memSize); +void BgCheck_SetSubdivisionDimension(f32 min, s32 subdivAmount, f32* max, f32* subdivLength, f32* subdivLengthInv); +s32 BgCheck_GetSpecialSceneMaxObjects(GlobalContext* globalCtx, s32* maxNodes, s32* maxPolygons, s32* maxVertices); +void BgCheck_Allocate(CollisionContext* colCtx, GlobalContext* globalCtx, CollisionHeader* colHeader); +void BgCheck_SetContextFlags(CollisionContext* colCtx, u32 flags); +void BgCheck_UnsetContextFlags(CollisionContext* colCtx, u32 flags); +CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId); +f32 BgCheck_RaycastFloorImpl(GlobalContext* globalCtx, CollisionContext* colCtx, u16 xpFlags, CollisionPoly** outPoly, s32* outBgId, Vec3f* pos, Actor* actor, u32 arg7, f32 chkDist, s32 arg9); +f32 BgCheck_CameraRaycastFloor1(CollisionContext* colCtx, CollisionPoly** outPoly, Vec3f* pos); +f32 BgCheck_EntityRaycastFloor1(CollisionContext* colCtx, CollisionPoly** outPoly, Vec3f* pos); +f32 BgCheck_EntityRaycastFloor2(GlobalContext* globalCtx, CollisionContext* colCtx, CollisionPoly** outPoly, Vec3f* pos); +f32 BgCheck_EntityRaycastFloor2_1(GlobalContext* globalCtx, CollisionContext* colCtx, CollisionPoly** outPoly, Vec3f* pos); +f32 BgCheck_EntityRaycastFloor3(CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Vec3f* pos); +f32 BgCheck_EntityRaycastFloor5(CollisionContext* colCtx, CollisionPoly** outPoly, s32* outBgId, Actor* actor, Vec3f* pos); +f32 BgCheck_EntityRaycastFloor5_2(GlobalContext* globalCtx, CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Actor* actor, Vec3f* pos); +f32 BgCheck_EntityRaycastFloor5_3(GlobalContext* globalCtx, CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Actor* actor, Vec3f* pos); +f32 BgCheck_EntityRaycastFloor6(CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Actor* actor, Vec3f* pos, f32 chkDist); +f32 BgCheck_EntityRaycastFloor7(CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Actor* actor, Vec3f* pos); +f32 BgCheck_AnyRaycastFloor1(CollisionContext* colCtx, CollisionPoly* outPoly, Vec3f* pos); +f32 BgCheck_AnyRaycastFloor2(CollisionContext* colCtx, CollisionPoly* outPoly, s32* bgId, Vec3f* pos); +f32 BgCheck_CameraRaycastFloor2(CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Vec3f* pos); +f32 BgCheck_EntityRaycastFloor8(CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Actor* actor, Vec3f* pos); +f32 BgCheck_EntityRaycastFloor9(CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Vec3f* pos); +s32 BgCheck_CheckWallImpl(CollisionContext* colCtx, u16 xpFlags, Vec3f* posResult, Vec3f* posNext, Vec3f* posPrev, f32 radius, CollisionPoly** outPoly, s32* outBgId, Actor* actor, f32 checkHeight, u8 argA); +s32 BgCheck_EntitySphVsWall1(CollisionContext* colCtx, Vec3f* posResult, Vec3f* posNext, Vec3f* posPrev, f32 radius, CollisionPoly** outPoly, f32 checkHeight); +s32 BgCheck_EntitySphVsWall2(CollisionContext* colCtx, Vec3f* posResult, Vec3f* posNext, Vec3f* posPrev, f32 radius, CollisionPoly** outPoly, s32* outBgId, f32 checkHeight); +s32 BgCheck_EntitySphVsWall3(CollisionContext* colCtx, Vec3f* posResult, Vec3f* posNext, Vec3f* posPrev, f32 radius, CollisionPoly** outPoly, s32* outBgId, Actor* actor, f32 checkHeight); +s32 BgCheck_EntitySphVsWall4(CollisionContext* colCtx, Vec3f* posResult, Vec3f* posNext, Vec3f* posPrev, f32 radius, CollisionPoly** outPoly, s32* outBgId, Actor* actor, f32 checkHeight); +s32 BgCheck_CheckCeilingImpl(CollisionContext* colCtx, u16 xpFlags, f32* outY, Vec3f* pos, f32 checkHeight, CollisionPoly** outPoly, s32* outBgId, Actor* actor); +s32 BgCheck_AnyCheckCeiling(CollisionContext* colCtx, f32* outY, Vec3f* pos, f32 checkHeight); +s32 BgCheck_EntityCheckCeiling(CollisionContext* colCtx, f32* outY, Vec3f* pos, f32 checkHeight, CollisionPoly** outPoly, s32* outBgId, Actor* actor); +s32 BgCheck_CameraLineTest1(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, s32 chkWall, s32 chkFloor, s32 chkCeil, s32 chkOneFace, s32* bgId); +s32 BgCheck_CameraLineTest2(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, s32 chkWall, s32 chkFloor, s32 chkCeil, s32 chkOneFace, s32* bgId); +s32 BgCheck_EntityLineTest1(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, s32 chkWall, s32 chkFloor, s32 chkCeil, s32 chkOneFace, s32* bgId); +s32 BgCheck_EntityLineTest2(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, s32 chkWall, s32 chkFloor, s32 chkCeil, s32 chkOneFace, s32* bgId, Actor* actor); +s32 BgCheck_EntityLineTest3(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, s32 chkWall, s32 chkFloor, s32 chkCeil, s32 chkOneFace, s32* bgId, Actor* actor, f32 chkDist); +s32 BgCheck_ProjectileLineTest(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, s32 chkWall, s32 chkFloor, s32 chkCeil, s32 chkOneFace, s32* bgId); +s32 BgCheck_AnyLineTest1(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, s32 chkOneFace); +s32 BgCheck_AnyLineTest2(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, s32 chkWall, s32 chkFloor, s32 chkCeil, s32 chkOneFace); +s32 BgCheck_AnyLineTest3(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, s32 chkWall, s32 chkFloor, s32 chkCeil, s32 chkOneFace, s32* bgId); +s32 BgCheck_SphVsFirstPolyImpl(CollisionContext* colCtx, u16 xpFlags, CollisionPoly** outPoly, s32* outBgId, Vec3f* center, f32 radius, Actor* actor, u16 bciFlags); +s32 BgCheck_SphVsFirstPoly(CollisionContext* colCtx, Vec3f* center, f32 radius); +s32 BgCheck_SphVsFirstWall(CollisionContext* colCtx, Vec3f* center, f32 radius); +void SSNodeList_Init(SSNodeList* this); +void SSNodeList_Alloc(GlobalContext* globalCtx, SSNodeList* this, s32 tblMax, s32 numPolys); +SSNode* SSNodeList_GetNextNode(SSNodeList* this); +u16 SSNodeList_GetNextNodeIdx(SSNodeList* this); +void ScaleRotPos_Init(ScaleRotPos* srp); +void ScaleRotPos_SetValue(ScaleRotPos* srp, Vec3f* scale, Vec3s* rot, Vec3f* pos); +s32 ScaleRotPos_IsEqual(ScaleRotPos* a, ScaleRotPos* b); +void DynaLookup_ResetLists(DynaLookup* dynaLookup); +void DynaLookup_Reset(DynaLookup* dynaLookup); +void DynaLookup_ResetVtxStartIndex(u16* vtxStartIndex); +void DynaLookup_ResetWaterBoxStartIndex(u16* waterBoxStartIndex); +void BgActor_Init(GlobalContext* globalCtx, BgActor* bgActor); +void BgActor_SetActor(BgActor* bgActor, Actor* actor, CollisionHeader* colHeader); +s32 BgActor_IsTransformUnchanged(BgActor* bgActor); +void DynaPoly_NullPolyList(CollisionPoly** polyList); +void DynaPoly_AllocPolyList(GlobalContext* globalCtx, CollisionPoly** polyList, s32 numPolys); +void DynaPoly_NullVtxList(Vec3s** vtxList); +void DynaPoly_AllocVtxList(GlobalContext* globalCtx, Vec3s** vtxList, s32 numVtx); +void DynaPoly_InitWaterBoxList(DynaWaterBoxList* waterBoxList); +void DynaPoly_AllocWaterBoxList(GlobalContext* globalCtx, DynaWaterBoxList* waterBoxList, s32 numWaterBoxes); +void DynaPoly_SetBgActorPrevTransform(GlobalContext* globalCtx, BgActor* bgActor); +s32 DynaPoly_IsBgIdBgActor(s32 bgId); +void DynaPoly_Init(GlobalContext* globalCtx, DynaCollisionContext* dyna); +void DynaPoly_Alloc(GlobalContext* globalCtx, DynaCollisionContext* dyna); +s32 DynaPoly_SetBgActor(GlobalContext* globalCtx, DynaCollisionContext* dyna, Actor* actor, CollisionHeader* colHeader); +DynaPolyActor* DynaPoly_GetActor(CollisionContext* colCtx, s32 bgId); +void func_800C62BC(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId); +void func_800C6314(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId); +void func_800C636C(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId); +void func_800C63C4(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId); +void func_800C641C(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId); +void func_800C6474(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId); +void DynaPoly_DeleteBgActor(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId); void BgCheck_CalcWaterboxDimensions(Vec3f* minPos, Vec3f* maxXPos, Vec3f* maxZPos, Vec3s* minPosOut, s16* xLength, s16* zLength); -void BgCheck_AddActorMeshToLists(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 index, s32* currVertices, s32* currPolygons, s32* currWaterboxes); +void DynaPoly_ExpandSRT(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId, s32* vtxStartIndex, s32* polyStartIndex, s32* waterBoxStartIndex); void BgCheck_ResetFlagsIfLoadedActor(GlobalContext* globalCtx, DynaCollisionContext* dyna, Actor* actor); -void BgCheck_Update(GlobalContext* globalCtx, DynaCollisionContext* dyna); -void func_800C756C(s32 param_1, s32* param_2, s32* param_3, s32* param_4); -void BgCheck_UpdateAllActorMeshes(GlobalContext* globalCtx, DynaCollisionContext* dyna); -// void func_800C76EC(void); -// void func_800C7974(void); -// void func_800C7E40(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11, UNK_TYPE4 param_12); -// void func_800C8580(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9); -// void func_800C87D0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9); -// void func_800C8A60(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); -// void func_800C8BD0(void); -// void func_800C8DC0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); -// void func_800C8EEC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); -// void func_800C90AC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_800C921C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE2 param_7, UNK_TYPE4 param_8); -// void func_800C9380(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE2 param_8); -void BgCheck_RelocateMeshHeaderPointers(CollisionHeader* header); -void BgCheck_RelocateMeshHeader(CollisionHeader* meshSegPtr, CollisionHeader** param_2); -void BgCheck_RelocateAllMeshHeaders(CollisionContext* colCtx, GlobalContext* globalCtx); -// void func_800C9640(void); -u32 BgCheck_GetPolygonAttributes(CollisionContext* colCtx, CollisionPoly* polygon, s32 index, s32 attributeIndex); -u32 func_800C9704(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -// void func_800C9728(void); -// UNK_TYPE4 func_800C9770(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -// void func_800C97F8(void); -// UNK_TYPE4 func_800C9844(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -// void func_800C98CC(void); -// UNK_TYPE4 func_800C9924(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C99AC(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C99D4(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C99FC(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9A24(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9A4C(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9A7C(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9AB0(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9AE4(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9B18(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9B40(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9B68(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9B90(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -s32 func_800C9BB8(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9BDC(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -// u32 func_800C9C24(CollisionContext* colCtx, CollisionPoly* polygon, s32 index, UNK_TYPE4 param_4); -u32 func_800C9C74(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9C9C(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9CC4(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9CEC(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -// void func_800C9D14(void); -// void func_800C9D50(void); -u32 func_800C9D8C(CollisionContext* param_1, CollisionPoly* param_2, s32 param_3); -// void func_800C9DDC(void); -u32 func_800C9E18(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9E40(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -u32 func_800C9E88(CollisionContext* colCtx, CollisionPoly* polygon, s32 index); -s32 func_800C9EBC(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, WaterBox** outWaterBox, s32* bgId); -s32 func_800CA1AC(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, WaterBox** outWaterBox); -s32 func_800CA1E8(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, WaterBox** outWaterBox); -// void func_800CA22C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// void func_800CA568(void); -// void func_800CA634(void); -// void func_800CA648(void); -// void func_800CA6B8(void); -// void func_800CA6D8(void); -// void func_800CA6F0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_800CA9D0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// void func_800CAA14(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); +void DynaPoly_Setup(GlobalContext* globalCtx, DynaCollisionContext* dyna); +void func_800C756C(DynaCollisionContext* dyna, s32* numPolygons, s32* numVertices, s32* numWaterBoxes); +void DynaPoly_UpdateBgActorTransforms(GlobalContext* globalCtx, DynaCollisionContext* dyna); +void CollisionHeader_SegmentedToVirtual(CollisionHeader* header); +void CollisionHeader_GetVirtual(CollisionHeader* meshSegPtr, CollisionHeader** param_2); +void BgCheck_InitCollisionHeaders(CollisionContext* colCtx, GlobalContext* globalCtx); +u32 SurfaceType_GetData(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId, s32 dataIdx); +u32 SurfaceType_GetCamDataIndex(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u16 SurfaceType_GetCameraSType(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u16 SurfaceType_GetNumCameras(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +Vec3s* SurfaceType_GetCamPosData(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 SurfaceType_GetSceneExitIndex(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 func_800C99D4(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 func_800C99FC(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 func_800C9A24(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +s32 func_800C9A4C(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +s32 func_800C9A7C(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +s32 func_800C9AB0(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +s32 func_800C9AE4(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 func_800C9B18(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 func_800C9B40(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 func_800C9B68(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 SurfaceType_IsHorseBlocked(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 func_800C9BB8(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u16 SurfaceType_GetSfx(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +s32 func_800C9C24(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId, s32 arg3); +u32 SurfaceType_GetSlope(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 SurfaceType_GetLightSettingIndex(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 SurfaceType_GetEcho(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 SurfaceType_IsHookshotSurface(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +s32 SurfaceType_IsIgnoredByEntities(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +s32 SurfaceType_IsIgnoredByProjectiles(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +s32 SurfaceType_IsConveyor(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +s32 func_800C9DDC(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 SurfaceType_GetConveyorSpeed(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 SurfaceType_GetConveyorDirection(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +u32 SurfaceType_IsWallDamage(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +s32 WaterBox_GetSurfaceImpl(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, WaterBox** outWaterBox, s32* bgId); +s32 WaterBox_GetSurface1(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, WaterBox** outWaterBox); +s32 WaterBox_GetSurface1_2(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, WaterBox** outWaterBox); +s32 WaterBox_GetSurface2(GlobalContext* globalCtx, CollisionContext* colCtx, Vec3f* pos, f32 surfaceChkDist, WaterBox** outWaterBox, s32* bgId); +f32 func_800CA568(CollisionContext* colCtx, s32 waterBoxId, s32 bgId); +u16 WaterBox_GetCameraSType(CollisionContext* colCtx, WaterBox* waterBox, s32 bgId); +void func_800CA6B8(CollisionContext* colCtx, WaterBox* waterBox); +u32 WaterBox_GetLightSettingIndex(CollisionContext* colCtx, WaterBox* waterBox); +s32 func_800CA6F0(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, WaterBox** outWaterBox, s32* bgId); +s32 func_800CA9D0(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, WaterBox** outWaterBox); +s32 func_800CAA14(CollisionPoly* polyA, CollisionPoly* polyB, Vec3f* pointA, Vec3f* pointB, Vec3f* closestPoint); void BgCheck2_UpdateActorPosition(CollisionContext* colCtx, s32 index, Actor* actor); void BgCheck2_UpdateActorYRotation(CollisionContext* colCtx, s32 index, Actor* actor); void BgCheck2_AttachToMesh(CollisionContext* colCtx, Actor* actor, s32 index); @@ -3269,7 +3229,7 @@ f32 cos_rad(f32 rad); f32 Rand_ZeroFloat(f32 scale); f32 randPlusMinusPoint5Scaled(f32 scale); f32 Math3D_Normalize(Vec3f* vec); -// UNK_TYPE4 func_80179678(f32 fParm1, f32 fParm2, f32 fParm5, f32 param_4, f32 param_5, f32 param_6, f32 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); +s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* closestPoint); // UNK_TYPE4 func_80179798(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3, Vec3f* param_4, Vec3f* param_5, Vec3f* param_6); // void func_80179A44(void); void func_80179B34(float fParm1, f32 fParm2, f32 fParm5, f32 fParm6, f32 param_5, f32 param_6, f32 param_7, float* param_8, float* param_9); @@ -3283,7 +3243,7 @@ void func_80179F64(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); s32 Math3D_XZBoundCheck(f32 xMin, f32 xMax, f32 zMin, f32 zMax, f32 x, f32 z); // void func_8017A09C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); // void func_8017A1D0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// void func_8017A304(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +s32 func_8017A304(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 chkDist); // UNK_TYPE4 func_8017A438(Vec3f* pfParm1, Vec3f* pfParm2, Vec3f* pfParm3, Vec3f* pfParm4, f32 param_5); f32 Math3D_XZLengthSquared(f32 x, f32 z); f32 Math3D_XZLength(f32 x, f32 z); @@ -3291,46 +3251,46 @@ f32 Math3D_XZDistanceSquared(f32 x1, f32 x2, f32 z1, f32 z2); f32 Math3D_XZDistance(f32 x1, f32 x2, f32 z1, f32 z2); f32 Math3D_LengthSquared(Vec3f* vec); f32 Math3D_Vec3fMagnitude(Vec3f* vec); -f32 Math3D_DistanceSquared(Vec3f* a, Vec3f* b); +f32 Math3D_Vec3fDistSq(Vec3f* a, Vec3f* b); f32 Math3D_Distance(Vec3f* a, Vec3f* b); f32 Math3D_DistanceS(Vec3s* s, Vec3f* f); f32 func_8017A7B8(f32* param_1, f32* param_2, f32 param_3, f32 param_4); f32 func_8017A7F8(f32* param_1, f32* param_2, f32 param_3, f32 param_4); f32 func_8017A838(f32* param_1, f32* param_2, f32 param_3, f32 param_4); void Math3D_CrossProduct(Vec3f* a, Vec3f* b, Vec3f* res); -void Math3D_NormalVector(Vec3f* a, Vec3f* b, Vec3f* c, Vec3f* res); -u32 func_8017A954(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); -u32 func_8017AA0C(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); -u32 func_8017ABBC(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); -// void func_8017AD38(void); +void Math3D_SurfaceNorm(Vec3f* a, Vec3f* b, Vec3f* c, Vec3f* res); +u32 Math3D_PointRelativeToCubeFaces(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); +u32 Math3D_PointRelativeToCubeEdges(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); +u32 Math3D_PointRelativeToCubeVertices(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); +s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b); // void func_8017B68C(void); void func_8017B7F8(Vec3f* arg0, s16 arg1, f32* arg2, f32* arg3, f32* arg4); void Math3D_UnitNormalVector(Vec3f* a, Vec3f* b, Vec3f* c, f32* normX, f32* normY, f32* normZ, f32* param_7); f32 Math3D_SignedDistanceFromPlane(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); // void func_8017B9D8(void); -f32 Math3D_NormalizedDistanceFromPlane(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); -f32 Math3D_NormalizedSignedDistanceFromPlane(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); -// void func_8017BAD0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); +f32 Math3D_UDistPlaneToPos(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); +f32 Math3D_DistPlaneToPos(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); +s32 Math3D_TriChkPointParaYDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 unk, f32 chkDist, f32 ny); // void func_8017BD98(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); // void func_8017BDE0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -// void func_8017BE30(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); -// void func_8017BEE0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); +s32 Math3D_TriChkPointParaYIntersectDist(Vec3f* a, Vec3f* b, Vec3f* c, f32 nx, f32 ny, f32 nz, f32 dist, f32 z, f32 x, f32* yIntersect, f32 chkDist); +s32 Math3D_TriChkPointParaYIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); // void func_8017BF8C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// void func_8017C008(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11, UNK_TYPE4 param_12); +s32 Math3D_TriChkLineSegParaYIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 y0, f32 y1); // void func_8017C17C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); // void func_8017C1F0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); -// void func_8017C494(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); -// void func_8017C540(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); +s32 Math3D_TriChkPointParaYIntersectInsideTri2(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); +s32 Math3D_TriChkPointParaXDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 unk, f32 chkDist, f32 nx); // void func_8017C808(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_8017C850(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); +s32 Math3D_TriChkPointParaXIntersect(Vec3f* a, Vec3f* b, Vec3f* c, f32 nx, f32 ny, f32 nz, f32 dist, f32 y, f32 z, f32* xIntersect); // void func_8017C904(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// void func_8017C980(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11, UNK_TYPE4 param_12); +s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, f32 z, f32* xIntersect, f32 x0, f32 x1); // void func_8017CB08(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_8017CB7C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); +s32 Math3D_TriChkLineSegParaZDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 unk, f32 chkDist, f32 nz); // void func_8017CEA8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_8017CEF0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); +s32 Math3D_TriChkPointParaZIntersect(Vec3f* a, Vec3f* b, Vec3f* c, f32 nx, f32 ny, f32 nz, f32 dist, f32 x, f32 y, f32* zIntersect); // void func_8017CFA4(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// void func_8017D020(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11, UNK_TYPE4 param_12); +s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, f32* zIntersect, f32 z0, f32 z1); // void func_8017D1AC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); // void func_8017D220(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); // void func_8017D2FC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); @@ -3342,14 +3302,14 @@ u32 Math3D_IsPointInSphere(Sphere16* sphere, Vec3f* point); // void func_8017D814(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); // void func_8017D91C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); // void func_8017DA24(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -s32 Math3D_ColSphereLineSeg(Sphere16* sphere, LineSegment* line); +s32 Math3D_LineVsSph(Sphere16* sphere, LineSegment* line); void func_8017DD34(Sphere16* sphere, TriNorm* tri, Vec3f* pfParm3); s32 Math3D_ColSphereTri(Sphere16* sphere, TriNorm* tri, Vec3f* uParm3); // void func_8017E294(void); UNK_TYPE func_8017E350(UNK_PTR, Vec3f*, Vec3f*, Vec3f*, Vec3f*); s32 Math3D_ColCylinderTri(Cylinder16* cylinder, TriNorm* tri, Vec3f* pzParm3); // void func_8017F1A0(void); -s32 Math3D_ColSphereSphere(Sphere16* sphere1, Sphere16* sphere2); +s32 Math3D_SphVsSph(Sphere16* sphere1, Sphere16* sphere2); s32 Math3D_ColSphereSphereIntersect(Sphere16* sphere1, Sphere16* sphere2, f32* intersectAmount); s32 Math3D_ColSphereSphereIntersectAndDistance(Sphere16* sphere1, Sphere16* sphere2, f32* intersectAmount, f32* dist); s32 Math3D_ColSphereCylinderDistance(Sphere16* sphere, Cylinder16* cylinder, f32* dist); @@ -3357,9 +3317,9 @@ s32 Math3D_ColSphereCylinderDistanceAndAmount(Sphere16* sphere, Cylinder16* cyli s32 Math3D_ColCylinderCylinderAmount(Cylinder16* cylinder1, Cylinder16* cylinder2, f32* intersectAmount); s32 Math3D_ColCylinderCylinderAmountAndDistance(Cylinder16* cylinder1, Cylinder16* cylinder2, f32* intersectAmount, f32* dist); s32 Math3d_ColTriTri(TriNorm* tri1, TriNorm* tri2, Vec3f* uParm3); -// void func_8017F9C0(void); -// void func_8017FA34(void); -// void func_8017FAA8(void); +s32 Math3D_XZInSphere(Sphere16* sphere, f32 x, f32 z); +s32 Math3D_XYInSphere(Sphere16* sphere, f32 x, f32 y); +s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z); // void func_8017FB1C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); // void func_8017FD44(void); u16 Math_GetAtan2Tbl(f32 opposite, f32 adjacent); diff --git a/include/variables.h b/include/variables.h index a4bf58d264..29ab452863 100644 --- a/include/variables.h +++ b/include/variables.h @@ -442,14 +442,8 @@ extern Gfx D_801AEFA0[]; // extern UNK_TYPE1 D_801AEFC0; extern ActorOverlay gActorOverlayTable[ACTOR_ID_MAX]; extern s32 gMaxActorId; -extern u32 D_801B4620[32]; -extern u16 D_801B46A0[16]; -extern u8 D_801B46C0[16]; -extern s16 bgSpecialSceneParamsDefault[1]; -// extern UNK_TYPE1 D_801B46D2; -extern BgSpecialSceneMaxMemory bgSpecialSceneMaxMemory[1]; -extern BgSpecialSceneMeshSubdivision bgSpecialSceneMeshSubdivisions[3]; -extern BgSpecialSceneMaxObjects bgSpecialSceneMaxObjects[1]; +extern BgCheckSceneSubdivisionEntry sSceneSubdivisionList[]; +extern BgSpecialSceneMaxObjects sCustomDynapolyMem[]; // extern UNK_TYPE1 D_801B4708; // extern UNK_TYPE1 D_801B4710; // extern UNK_TYPE1 D_801B4738; @@ -3139,28 +3133,15 @@ extern FaultClient D_801ED930; extern FaultAddrConvClient D_801ED940; extern char D_801ED950[80]; extern char D_801ED9A0[80]; -extern Vec3f D_801ED9F0; -extern Vec3f D_801ED9FC; -extern Vec3f D_801EDA08; -extern Vec3f D_801EDA18; -extern Vec3f D_801EDA24; -extern Vec3f D_801EDA30; +extern Vec3f D_801ED9F0[3]; +extern Vec3f D_801EDA18[3]; extern MtxF D_801EDA40; -extern Vec3f D_801EDA80; -extern Vec3f D_801EDA8C; -extern Vec3f D_801EDA98; +extern Vec3f D_801EDA80[3]; extern char D_801EDAA8[80]; extern char D_801EDAF8[80]; -extern Vec3f D_801EDB48; -extern Vec3f D_01EDB54; -extern Vec3f D_01EDB60; -extern Vec3f D_01EDB70; -extern Vec3f D_801EDB7C; -extern Vec3f D_801EDB88; -extern f32 D_801EDB98; -extern f32 D_801EDB9C; -extern f32 D_801EDBA0; -// extern UNK_TYPE1 D_801EDBA4; +extern Vec3f D_801EDB48[3]; +extern Vec3f D_801EDB70[3]; +extern Plane D_801EDB98; extern Sphere16 D_801EDBA8; extern TriNorm D_801EDBB0; // extern UNK_TYPE1 D_801EDBD4; diff --git a/include/z64.h b/include/z64.h index 4081936105..e8c138e0b8 100644 --- a/include/z64.h +++ b/include/z64.h @@ -76,13 +76,6 @@ typedef struct { /* 0xF */ u8 letterboxSize; } ActorCutscene; // size = 0x10 -typedef struct { - /* 0x0 */ s16 polyStartIndex; - /* 0x2 */ s16 ceilingNodeHead; - /* 0x4 */ s16 wallNodeHead; - /* 0x6 */ s16 floorNodeHead; -} ActorMeshPolyLists; // size = 0x8 - typedef struct { /* 0x0 */ s8 segment; /* 0x2 */ s16 type; @@ -103,49 +96,6 @@ typedef struct { /* 0x08 */ void* end; } PolygonType2; // size = 0xC -typedef struct { - /* 0x0 */ u16 floorHead; - /* 0x2 */ u16 wallHead; - /* 0x4 */ u16 ceilingHead; -} BgMeshSubdivision; // size = 0x6 - -typedef struct { - /* 0x0 */ u32 attributes[2]; -} BgPolygonAttributes; // size = 0x8 - -typedef struct { - /* 0x0 */ s16 polyIndex; - /* 0x2 */ u16 next; -} BgPolygonLinkedListNode; // size = 0x4 - -typedef struct { - /* 0x0 */ u16 maxNodes; - /* 0x2 */ u16 reservedNodes; - /* 0x4 */ BgPolygonLinkedListNode* nodes; - /* 0x8 */ u8* unk8; -} BgScenePolygonLists; // size = 0xC - -typedef struct { - /* 0x0 */ s16 sceneNumber; - /* 0x2 */ UNK_TYPE1 pad2[0x2]; - /* 0x4 */ u32 maxMemory; -} BgSpecialSceneMaxMemory; // size = 0x8 - -typedef struct { - /* 0x0 */ s16 sceneId; - /* 0x2 */ s16 maxNodes; - /* 0x4 */ s16 maxPolygons; - /* 0x6 */ s16 maxVertices; -} BgSpecialSceneMaxObjects; // size = 0x8 - -typedef struct { - /* 0x0 */ s16 sceneNumber; - /* 0x2 */ s16 xSubdivisions; - /* 0x4 */ s16 ySubdivisions; - /* 0x6 */ s16 zSubdivisions; - /* 0x8 */ s32 unk8; -} BgSpecialSceneMeshSubdivision; // size = 0xC - typedef struct { /* 0x0 */ s16 func; /* 0x2 */ UNK_TYPE1 pad2[0x6]; @@ -459,18 +409,6 @@ typedef struct { /* 0x1A */ s16 unk1A; } s80874650; // size = 0x1C -typedef struct { - /* 0x00 */ Vec3f scale; - /* 0x0C */ Vec3s rotation; - /* 0x14 */ Vec3f pos; -} ActorMeshParams; // size = 0x20 - -typedef struct { - /* 0x0 */ BgPolygonLinkedListNode* nodes; - /* 0x4 */ u32 nextFreeNode; - /* 0x8 */ s32 maxNodes; -} BgPolygonLinkedList; // size = 0xC - typedef struct { /* 0x00 */ f32 x[4]; /* 0x10 */ f32 y[4]; @@ -478,10 +416,6 @@ typedef struct { /* 0x30 */ f32 w[4]; } z_Matrix; // size = 0x40 -typedef struct { - /* 0x0 */ Vec3s pos; -} BgVertex; // size = 0x6 - typedef union { F3DVertexColor color; F3DVertexNormal normal; diff --git a/include/z64bgcheck.h b/include/z64bgcheck.h index 7dc380bf2f..6ca0b66d54 100644 --- a/include/z64bgcheck.h +++ b/include/z64bgcheck.h @@ -1,10 +1,12 @@ -#ifndef _Z_BGCHECK_ -#define _Z_BGCHECK_ +#ifndef Z64_BGCHECK_H +#define Z64_BGCHECK_H struct GlobalContext; struct Actor; struct DynaPolyActor; +#define SS_NULL 0xFFFF + #define COLPOLY_NORMAL_FRAC (1.0f / SHT_MAX) #define COLPOLY_SNORMAL(x) ((s16)((x) * SHT_MAX)) #define COLPOLY_GET_NORMAL(n) ((n)*COLPOLY_NORMAL_FRAC) @@ -15,24 +17,54 @@ struct DynaPolyActor; #define BGACTOR_NEG_ONE -1 #define BG_ACTOR_MAX 50 +#define DYNA_WATERBOX_MAX 30 #define BGCHECK_SCENE BG_ACTOR_MAX +#define BGCHECK_Y_MAX 32000.0f #define BGCHECK_Y_MIN -32000.0f #define BGCHECK_XYZ_ABSMAX 32760.0f #define BGCHECK_SUBDIV_OVERLAP 50 #define BGCHECK_SUBDIV_MIN 150.0f -#define FUNC_80041EA4_RESPAWN 5 -#define FUNC_80041EA4_MOUNT_WALL 6 -#define FUNC_80041EA4_STOP 8 -#define FUNC_80041EA4_VOID_OUT 12 +#define WATERBOX_ROOM(p) ((((s32)p) >> 13) & 0x3F) -#define WATERBOX_ROOM(p) ((p >> 13) & 0x3F) +// bccFlags (bgcheck check flags) +#define BGCHECK_CHECK_WALL (1 << 0) +#define BGCHECK_CHECK_FLOOR (1 << 1) +#define BGCHECK_CHECK_CEILING (1 << 2) +#define BGCHECK_CHECK_ONE_FACE (1 << 3) +#define BGCHECK_CHECK_DYNA (1 << 4) +#define BGCHECK_CHECK_ALL \ + (BGCHECK_CHECK_WALL | BGCHECK_CHECK_FLOOR | BGCHECK_CHECK_CEILING | BGCHECK_CHECK_ONE_FACE | BGCHECK_CHECK_DYNA) + +// bciFlags (bgcheck ignore flags) +#define BGCHECK_IGNORE_NONE 0 +#define BGCHECK_IGNORE_CEILING (1 << 0) +#define BGCHECK_IGNORE_WALL (1 << 1) +#define BGCHECK_IGNORE_FLOOR (1 << 2) + +// xpFlags (poly exclusion flags) +#define COLPOLY_IGNORE_NONE 0 +#define COLPOLY_IGNORE_CAMERA (1 << 0) +#define COLPOLY_IGNORE_ENTITY (1 << 1) +#define COLPOLY_IGNORE_PROJECTILES (1 << 2) + +// Surface Types +#define COLPOLY_SURFACE_GROUND 0 +#define COLPOLY_SURFACE_SAND 1 +#define COLPOLY_SURFACE_SNOW 14 + +// CollisionContext flags +#define BGCHECK_FLAG_REVERSE_CONVEYOR_FLOW 1 typedef struct { - Vec3f scale; - Vec3s rot; - Vec3f pos; -} ScaleRotPos; + /* 0x0 */ Vec3s pos; +} BgVertex; // size = 0x6 + +typedef struct { + /* 0x00 */ Vec3f scale; + /* 0x0C */ Vec3s rot; + /* 0x14 */ Vec3f pos; +} ScaleRotPos; // size = 0x20 typedef struct CollisionPoly { /* 0x00 */ u16 type; @@ -53,30 +85,44 @@ typedef struct CollisionPoly { typedef struct { /* 0x00 */ u16 cameraSType; - /* 0x02 */ s16 numCameras; + /* 0x02 */ s16 unk_02; /* 0x04 */ Vec3s* camPosData; } CamData; typedef struct { - /* 0x00 */ s16 xMin; - /* 0x02 */ s16 ySurface; - /* 0x04 */ s16 zMin; - /* 0x06 */ s16 xLength; - /* 0x08 */ s16 zLength; - /* 0x0C */ u32 properties; - + /* 0x0 */ Vec3s minPos; + /* 0x6 */ s16 xLength; + /* 0x8 */ s16 zLength; + /* 0xC */ u32 properties; // 0x0008_0000 = ? - // 0x0007_E000 = Room Index, 0x3F = all rooms - // 0x0000_1F00 = Lighting Settings Index + // 0x0007_E000 = room index, 0x3F = all rooms + // 0x0000_1F00 = lighting setting index // 0x0000_00FF = CamData index } WaterBox; // size = 0x10 typedef struct { - u32 data[2]; + /* 0x0 */ u32 data[2]; - // Type 1 + // Word 0 + // 0x8000_0000 = horse blocked + // 0x4000_0000 = floor surface recessed by 1 unit + // 0x3C00_0000 = ? (floor property?) + // 0x03E0_0000 = ? (wall property?) + // 0x001C_0000 = ? + // 0x0003_E000 = ? + // 0x0000_1F00 = scene exit index + // 0x0000_00FF = CamData index + // Word 1 // 0x0800_0000 = wall damage -} SurfaceType; + // 0x07E0_0000 = conveyor direction + // 0x001C_0000 = conveyor speed + // 0x0002_0000 = is hookable surface + // 0x0001_F800 = echo/reverb + // 0x0000_07C0 = lighting setting index + // 0x0000_0030 = surface slope + // 0x0000_000F = type + +} SurfaceType; // size = 0x8 typedef struct { /* 0x00 */ Vec3s minBounds; // minimum coordinates of poly bounding box @@ -89,49 +135,54 @@ typedef struct { /* 0x20 */ CamData* cameraDataList; /* 0x24 */ u16 numWaterBoxes; /* 0x28 */ WaterBox* waterBoxes; -} CollisionHeader; // original name: BGDataInfo +} CollisionHeader; // size = 0x2C typedef struct { - s16 polyId; - u16 next; // next SSNode index -} SSNode; + /* 0x0 */ s16 polyId; + /* 0x2 */ u16 next; // index of the next SSNode in the list, or SS_NULL if last element +} SSNode; // size = 0x4 typedef struct { - u16 head; // first SSNode index -} SSList; + u16 head; // index of the first SSNode in the list, or SS_NULL if the list is empty +} SSList; // represents a linked list of type SSNode typedef struct { - /* 0x00 */ u16 max; // original name: short_slist_node_size - /* 0x02 */ u16 count; // original name: short_slist_node_last_index - /* 0x04 */ SSNode* tbl; // original name: short_slist_node_tbl - /* 0x08 */ u8* polyCheckTbl; // points to an array of bytes, one per static poly. Zero initialized when starting a - // bg check, and set to 1 if that poly has already been tested. -} SSNodeList; + /* 0x0 */ u16 max; + /* 0x2 */ u16 count; + /* 0x4 */ SSNode* tbl; + /* 0x8 */ u8* polyCheckTbl; +} SSNodeList; // size = 0xC typedef struct { - SSNode* tbl; - s32 count; - s32 max; -} DynaSSNodeList; + /* 0x0 */ SSNode* tbl; + /* 0x4 */ u32 count; + /* 0x8 */ s32 maxNodes; +} DynaSSNodeList; // size = 0xC typedef struct { - SSList floor; - SSList wall; - SSList ceiling; -} StaticLookup; + /* 0x0 */ s32 unk0; + /* 0x4 */ WaterBox* boxes; +} DynaWaterBoxList; // size = 0x8 typedef struct { - u16 polyStartIndex; - SSList ceiling; - SSList wall; - SSList floor; -} DynaLookup; + /* 0x0 */ SSList floor; + /* 0x2 */ SSList wall; + /* 0x4 */ SSList ceiling; +} StaticLookup; // size = 0x6 typedef struct { - /* 0x00 */ struct Actor* actor; + /* 0x0 */ s16 polyStartIndex; + /* 0x2 */ SSList ceiling; + /* 0x4 */ SSList wall; + /* 0x6 */ SSList floor; +} DynaLookup; // size = 0x8 + +typedef struct { + /* 0x00 */ Actor* actor; /* 0x04 */ CollisionHeader* colHeader; /* 0x08 */ DynaLookup dynaLookup; /* 0x10 */ u16 vtxStartIndex; + /* 0x12 */ u16 waterboxesStartIndex; /* 0x14 */ ScaleRotPos prevTransform; /* 0x34 */ ScaleRotPos curTransform; /* 0x54 */ Sphere16 boundingSphere; @@ -139,25 +190,20 @@ typedef struct { /* 0x60 */ f32 maxY; } BgActor; // size = 0x64 -typedef struct { - /* 0x0 */ UNK_TYPE1 pad0[0x4]; - /* 0x4 */ WaterBox* boxes; -} DynaSSWaterboxList; // size = 0x8 - typedef struct { /* 0x0000 */ u8 bitFlag; /* 0x0004 */ BgActor bgActors[BG_ACTOR_MAX]; - /* 0x138C */ u16 bgActorFlags[BG_ACTOR_MAX]; // & 0x0008 = no dyna ceiling + /* 0x138C */ u16 bgActorFlags[BG_ACTOR_MAX]; // bit 0 - Is mesh active /* 0x13F0 */ CollisionPoly* polyList; /* 0x13F4 */ Vec3s* vtxList; - /* 0x13F8 */ DynaSSWaterboxList waterboxes; + /* 0x13F8 */ DynaWaterBoxList waterBoxList; /* 0x1400 */ DynaSSNodeList polyNodes; /* 0x140C */ s32 polyNodesMax; /* 0x1410 */ s32 polyListMax; /* 0x1414 */ s32 vtxListMax; } DynaCollisionContext; // size = 0x1418 -typedef struct CollisionContext { +typedef struct { /* 0x00 */ CollisionHeader* colHeader; // scene's static collision /* 0x04 */ Vec3f minBounds; // minimum coordinates of collision bounding box /* 0x10 */ Vec3f maxBounds; // maximum coordinates of collision bounding box @@ -166,28 +212,46 @@ typedef struct CollisionContext { /* 0x34 */ Vec3f subdivLengthInv; // inverse of subdivision length /* 0x40 */ StaticLookup* lookupTbl; // 3d array of length subdivAmount /* 0x44 */ SSNodeList polyNodes; - /* 0x50 */ DynaCollisionContext dyna; - /* 0x1460 */ u32 memSize; // Size of all allocated memory plus CollisionContext - /* 0x146C */ u32 unk146C; + /* 0x0050 */ DynaCollisionContext dyna; + /* 0x1468 */ u32 memSize; // Size of all allocated memory plus CollisionContext + /* 0x146C */ u32 flags; // bit 0 reverses conveyor direction (i.e. water flow in Great Bay Temple) } CollisionContext; // size = 0x1470 typedef struct { /* 0x00 */ struct GlobalContext* globalCtx; - /* 0x04 */ struct CollisionContext* colCtx; + /* 0x04 */ CollisionContext* colCtx; /* 0x08 */ u16 xpFlags; /* 0x0C */ CollisionPoly** resultPoly; /* 0x10 */ f32 yIntersect; /* 0x14 */ Vec3f* pos; /* 0x18 */ s32* bgId; - /* 0x1C */ struct Actor* actor; - /* 0x20 */ u32 unk_20; - /* 0x24 */ f32 chkDist; - /* 0x28 */ DynaCollisionContext* dyna; - /* 0x2C */ SSList* ssList; -} DynaRaycast; + /* 0x1C */ s32 unk1C; + /* 0x20 */ struct Actor* actor; + /* 0x24 */ u32 unk_24; + /* 0x28 */ f32 checkDist; + /* 0x2C */ DynaCollisionContext* dyna; + /* 0x30 */ SSList* ssList; +} DynaRaycast; // size = 0x34 + +typedef struct +{ + /* 0x00 */ StaticLookup* lookup; + /* 0x04 */ SSList* ssList; + /* 0x08 */ CollisionContext* colCtx; + /* 0x0C */ u16 xpFlags1; + /* 0x0E */ u16 xpFlags2; + /* 0x10 */ Vec3f* posA; + /* 0x14 */ Vec3f* posB; + /* 0x18 */ Vec3f* outPos; + /* 0x1C */ CollisionPoly** outPoly; + /* 0x20 */ f32 outDistSq; + /* 0x24 */ f32 checkDist; + /* 0x28 */ s32 bccFlags; + /* 0x2C */ Actor* actor; +} StaticLineTest; // size = 0x30 typedef struct { - /* 0x00 */ struct CollisionContext* colCtx; + /* 0x00 */ CollisionContext* colCtx; /* 0x04 */ u16 xpFlags; /* 0x08 */ DynaCollisionContext* dyna; /* 0x0C */ SSList* ssList; @@ -195,9 +259,46 @@ typedef struct { /* 0x14 */ Vec3f* posB; /* 0x18 */ Vec3f* posResult; /* 0x1C */ CollisionPoly** resultPoly; - /* 0x20 */ s32 chkOneFace; // bccFlags & 0x8 - /* 0x24 */ f32* distSq; // distance from posA to poly squared - /* 0x28 */ f32 chkDist; // distance from poly -} DynaLineTest; + /* 0x20 */ s32 checkOneFace; // bccFlags & 0x8 + /* 0x24 */ f32* distSq; // distance from posA to poly squared + /* 0x28 */ f32 checkDist; // distance from poly + /* 0x2C */ Actor* actor; + /* 0x30 */ s32 bgId; +} DynaLineTest; // size = 0x34 +typedef struct { + /* 0x00 */ CollisionPoly* poly; + /* 0x04 */ Vec3s* vtxList; + /* 0x08 */ Vec3f* posA; + /* 0x0C */ Vec3f* posB; + /* 0x10 */ Vec3f* planeIntersect; + /* 0x14 */ s32 checkOneFace; + /* 0x18 */ f32 checkDist; +} BgLineVsPolyTest; // size = 0x1C + +typedef struct { + /* 0x0 */ s16 sceneId; + /* 0x4 */ u32 memSize; +} BgSpecialSceneMaxMemory; // size = 0x8 + +typedef struct { + /* 0x0 */ s16 sceneId; + /* 0x2 */ s16 maxNodes; + /* 0x4 */ s16 maxPolygons; + /* 0x6 */ s16 maxVertices; +} BgSpecialSceneMaxObjects; // size = 0x8 + +typedef struct { + /* 0x0 */ s16 sceneId; + /* 0x2 */ s16 xSubdivisions; + /* 0x4 */ s16 ySubdivisions; + /* 0x6 */ s16 zSubdivisions; + /* 0x8 */ s32 unk8; +} BgSpecialSceneMeshSubdivision; // size = 0xC + +typedef struct { + s16 sceneId; + Vec3s subdivAmount; + s32 nodeListMax; // if -1, dynamically compute max nodes +} BgCheckSceneSubdivisionEntry; #endif diff --git a/spec b/spec index ef82b65736..0e811e7e51 100644 --- a/spec +++ b/spec @@ -451,8 +451,6 @@ beginseg include "build/data/code/z_actor.bss.o" include "build/src/code/z_actor_dlftbls.o" include "build/src/code/z_bgcheck.o" - include "build/data/code/z_bgcheck.data.o" - include "build/data/code/z_bgcheck.bss.o" include "build/src/code/z_bg_collect.o" include "build/src/code/z_bg_item.o" include "build/src/code/z_camera.o" diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index f607295c19..50fd1211ec 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -2,7 +2,7 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_Normalize.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179678.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PlaneVsLineSegClosestPoint.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179798.s") @@ -46,7 +46,7 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_Vec3fMagnitude.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_DistanceSquared.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_Vec3fDistSq.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_Distance.s") @@ -60,15 +60,15 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CrossProduct.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_NormalVector.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_SurfaceNorm.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017A954.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeFaces.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017AA0C.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeEdges.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017ABBC.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeVertices.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017AD38.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsCube.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017B68C.s") @@ -80,51 +80,51 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017B9D8.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_NormalizedDistanceFromPlane.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_UDistPlaneToPos.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_NormalizedSignedDistanceFromPlane.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_DistPlaneToPos.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017BAD0.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYDist.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017BD98.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017BDE0.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017BE30.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYIntersectDist.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017BEE0.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYIntersectInsideTri.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017BF8C.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C008.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaYIntersect.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C17C.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C1F0.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C494.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYIntersectInsideTri2.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C540.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaXDist.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C808.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C850.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaXIntersect.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C904.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C980.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaXIntersect.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017CB08.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017CB7C.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaZDist.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017CEA8.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017CEF0.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaZIntersect.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017CFA4.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017D020.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaZIntersect.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017D1AC.s") @@ -148,7 +148,7 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017DA24.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColSphereLineSeg.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsSph.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017DD34.s") @@ -162,7 +162,7 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017F1A0.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColSphereSphere.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_SphVsSph.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColSphereSphereIntersect.s") @@ -178,11 +178,11 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3d_ColTriTri.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017F9C0.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_XZInSphere.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017FA34.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_XYInSphere.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017FAA8.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_YZInSphere.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017FB1C.s") diff --git a/src/code/z_bg_collect.c b/src/code/z_bg_collect.c index 706c4b80a4..0d4f4a21f6 100644 --- a/src/code/z_bg_collect.c +++ b/src/code/z_bg_collect.c @@ -1,33 +1,33 @@ #include "global.h" -void BgCheck2_UpdateActorPosition(CollisionContext* colCtx, s32 index, Actor* actor) { +void BgCheck2_UpdateActorPosition(CollisionContext* colCtx, s32 bgId, Actor* actor) { MtxF prevMatrix; MtxF prevMatrixInv; MtxF currMatrix; Vec3f newPos; Vec3f posWithInv; - if (BgCheck_IsActorMeshIndexValid(index) == 0) { + if (!DynaPoly_IsBgIdBgActor(bgId)) { return; } SkinMatrix_SetScaleRotateYRPTranslate( - &prevMatrix, colCtx->dyna.bgActors[index].prevTransform.scale.x, - colCtx->dyna.bgActors[index].prevTransform.scale.y, colCtx->dyna.bgActors[index].prevTransform.scale.z, - colCtx->dyna.bgActors[index].prevTransform.rot.x, colCtx->dyna.bgActors[index].prevTransform.rot.y, - colCtx->dyna.bgActors[index].prevTransform.rot.z, colCtx->dyna.bgActors[index].prevTransform.pos.x, - colCtx->dyna.bgActors[index].prevTransform.pos.y, colCtx->dyna.bgActors[index].prevTransform.pos.z); + &prevMatrix, colCtx->dyna.bgActors[bgId].prevTransform.scale.x, + colCtx->dyna.bgActors[bgId].prevTransform.scale.y, colCtx->dyna.bgActors[bgId].prevTransform.scale.z, + colCtx->dyna.bgActors[bgId].prevTransform.rot.x, colCtx->dyna.bgActors[bgId].prevTransform.rot.y, + colCtx->dyna.bgActors[bgId].prevTransform.rot.z, colCtx->dyna.bgActors[bgId].prevTransform.pos.x, + colCtx->dyna.bgActors[bgId].prevTransform.pos.y, colCtx->dyna.bgActors[bgId].prevTransform.pos.z); if (SkinMatrix_Invert(&prevMatrix, &prevMatrixInv) == 2) { return; } SkinMatrix_SetScaleRotateYRPTranslate( - &currMatrix, colCtx->dyna.bgActors[index].curTransform.scale.x, - colCtx->dyna.bgActors[index].curTransform.scale.y, colCtx->dyna.bgActors[index].curTransform.scale.z, - colCtx->dyna.bgActors[index].curTransform.rot.x, colCtx->dyna.bgActors[index].curTransform.rot.y, - colCtx->dyna.bgActors[index].curTransform.rot.z, colCtx->dyna.bgActors[index].curTransform.pos.x, - colCtx->dyna.bgActors[index].curTransform.pos.y, colCtx->dyna.bgActors[index].curTransform.pos.z); + &currMatrix, colCtx->dyna.bgActors[bgId].curTransform.scale.x, colCtx->dyna.bgActors[bgId].curTransform.scale.y, + colCtx->dyna.bgActors[bgId].curTransform.scale.z, colCtx->dyna.bgActors[bgId].curTransform.rot.x, + colCtx->dyna.bgActors[bgId].curTransform.rot.y, colCtx->dyna.bgActors[bgId].curTransform.rot.z, + colCtx->dyna.bgActors[bgId].curTransform.pos.x, colCtx->dyna.bgActors[bgId].curTransform.pos.y, + colCtx->dyna.bgActors[bgId].curTransform.pos.z); SkinMatrix_Vec3fMtxFMultXYZ(&prevMatrixInv, &actor->world.pos, &posWithInv); SkinMatrix_Vec3fMtxFMultXYZ(&currMatrix, &posWithInv, &newPos); @@ -35,14 +35,14 @@ void BgCheck2_UpdateActorPosition(CollisionContext* colCtx, s32 index, Actor* ac actor->world.pos = newPos; } -void BgCheck2_UpdateActorYRotation(CollisionContext* colCtx, s32 index, Actor* actor) { +void BgCheck2_UpdateActorYRotation(CollisionContext* colCtx, s32 bgId, Actor* actor) { s16 angleChange; - if (BgCheck_IsActorMeshIndexValid(index) == 0) { + if (!DynaPoly_IsBgIdBgActor(bgId)) { return; } - angleChange = colCtx->dyna.bgActors[index].curTransform.rot.y - colCtx->dyna.bgActors[index].prevTransform.rot.y; + angleChange = colCtx->dyna.bgActors[bgId].curTransform.rot.y - colCtx->dyna.bgActors[bgId].prevTransform.rot.y; if (actor->id == 0) { ((Player*)actor)->currentYaw += angleChange; @@ -52,14 +52,14 @@ void BgCheck2_UpdateActorYRotation(CollisionContext* colCtx, s32 index, Actor* a actor->world.rot.y += angleChange; } -void BgCheck2_AttachToMesh(CollisionContext* colCtx, Actor* actor, s32 index) { +void BgCheck2_AttachToMesh(CollisionContext* colCtx, Actor* actor, s32 bgId) { DynaPolyActor* meshActor; - if (BgCheck_IsActorMeshIndexValid(index) == 0) { + if (!DynaPoly_IsBgIdBgActor(bgId)) { return; } - meshActor = BgCheck_GetActorOfMesh(colCtx, index); + meshActor = DynaPoly_GetActor(colCtx, bgId); if (meshActor != NULL) { DynaPolyActor_SetRidingFallingState(meshActor); @@ -72,31 +72,31 @@ void BgCheck2_AttachToMesh(CollisionContext* colCtx, Actor* actor, s32 index) { } } -u32 BgCheck2_UpdateActorAttachedToMesh(CollisionContext* colCtx, s32 index, Actor* actor) { +u32 BgCheck2_UpdateActorAttachedToMesh(CollisionContext* colCtx, s32 bgId, Actor* actor) { u32 wasUpdated = 0; DynaPolyActor* meshActor; - if (BgCheck_IsActorMeshIndexValid(index) == 0) { + if (!DynaPoly_IsBgIdBgActor(bgId)) { return 0; } - if (colCtx->dyna.bgActorFlags[index] & 2 || !(colCtx->dyna.bgActorFlags[index] & 1)) { + if (colCtx->dyna.bgActorFlags[bgId] & 2 || !(colCtx->dyna.bgActorFlags[bgId] & 1)) { return 0; } - meshActor = BgCheck_GetActorOfMesh(colCtx, index); + meshActor = DynaPoly_GetActor(colCtx, bgId); if (meshActor == NULL) { return 0; } if (meshActor->flags & 1) { - BgCheck2_UpdateActorPosition(colCtx, index, actor); + BgCheck2_UpdateActorPosition(colCtx, bgId, actor); wasUpdated = 1; } if (meshActor->flags & 2) { - BgCheck2_UpdateActorYRotation(colCtx, index, actor); + BgCheck2_UpdateActorYRotation(colCtx, bgId, actor); wasUpdated = 1; } diff --git a/src/code/z_bg_item.c b/src/code/z_bg_item.c index 92a300e43d..74adbe6952 100644 --- a/src/code/z_bg_item.c +++ b/src/code/z_bg_item.c @@ -18,8 +18,8 @@ void DynaPolyActor_Init(DynaPolyActor* dynaActor, s32 flags) { void DynaPolyActor_LoadMesh(GlobalContext* globalCtx, DynaPolyActor* dynaActor, CollisionHeader* meshHeader) { CollisionHeader* header = NULL; - BgCheck_RelocateMeshHeader(meshHeader, &header); - dynaActor->bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, dynaActor, header); + CollisionHeader_GetVirtual(meshHeader, &header); + dynaActor->bgId = DynaPoly_SetBgActor(globalCtx, &globalCtx->colCtx.dyna, &dynaActor->actor, header); } void DynaPolyActor_ResetState(DynaPolyActor* dynaActor) { @@ -34,8 +34,8 @@ void DynaPolyActor_SetRidingMovingState(DynaPolyActor* dynaActor) { dynaActor->stateFlags |= DYNAPOLY_STATE_RIDING_MOVING; } -void DynaPolyActor_SetRidingMovingStateByIndex(CollisionContext* colCtx, s32 index) { - DynaPolyActor* dynaActor = BgCheck_GetActorOfMesh(colCtx, index); +void DynaPolyActor_SetRidingMovingStateByIndex(CollisionContext* colCtx, s32 bgId) { + DynaPolyActor* dynaActor = DynaPoly_GetActor(colCtx, bgId); if (dynaActor != NULL) { DynaPolyActor_SetRidingMovingState(dynaActor); @@ -46,8 +46,8 @@ void DynaPolyActor_SetRidingRotatingState(DynaPolyActor* dynaActor) { dynaActor->stateFlags |= DYNAPOLY_STATE_RIDING_ROTATING; } -void DynaPolyActor_SetRidingRotatingStateByIndex(CollisionContext* colCtx, s32 index) { - DynaPolyActor* dynaActor = BgCheck_GetActorOfMesh(colCtx, index); +void DynaPolyActor_SetRidingRotatingStateByIndex(CollisionContext* colCtx, s32 bgId) { + DynaPolyActor* dynaActor = DynaPoly_GetActor(colCtx, bgId); if (dynaActor != NULL) { DynaPolyActor_SetRidingRotatingState(dynaActor); @@ -125,16 +125,16 @@ s32 DynaPolyActor_ValidateMove(GlobalContext* globalCtx, DynaPolyActor* dynaActo endPos.y = startPos.y; endPos.z = sign * adjustedEndRadius * cos + startPos.z; - if (func_800C56E0(&globalCtx->colCtx, &startPos, &endPos, &intersectionPos, &poly, true, false, false, true, &bgId, - &dynaActor->actor, 0.0f)) { + if (BgCheck_EntityLineTest3(&globalCtx->colCtx, &startPos, &endPos, &intersectionPos, &poly, true, false, false, + true, &bgId, &dynaActor->actor, 0.0f)) { return false; } startPos.x = (dynaActor->actor.world.pos.x * 2.0f) - startPos.x; startPos.z = (dynaActor->actor.world.pos.z * 2.0f) - startPos.z; endPos.x = sign * adjustedEndRadius * sin + startPos.x; endPos.z = sign * adjustedEndRadius * cos + startPos.z; - if (func_800C56E0(&globalCtx->colCtx, &startPos, &endPos, &intersectionPos, &poly, true, false, false, true, &bgId, - &dynaActor->actor, 0.0f)) { + if (BgCheck_EntityLineTest3(&globalCtx->colCtx, &startPos, &endPos, &intersectionPos, &poly, true, false, false, + true, &bgId, &dynaActor->actor, 0.0f)) { return false; } return true; diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index e607b978a9..e5cb1ddb16 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -1,432 +1,4721 @@ #include "global.h" +#include "vt.h" -void BgCheck_PolygonLinkedListNodeInit(SSNode* node, s16* polyIndex, u16 next) { +#define DYNA_RAYCAST_FLOORS 1 +#define DYNA_RAYCAST_WALLS 2 +#define DYNA_RAYCAST_CEILINGS 4 + +static u32 sWallFlags[32] = { + 0, 1, 3, 5, 8, 16, 32, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + +static u16 sSurfaceTypeSfx[] = { + /* 0x00 */ NA_SE_PL_WALK_GROUND - SFX_FLAG, + /* 0x01 */ NA_SE_PL_WALK_SAND - SFX_FLAG, + /* 0x02 */ NA_SE_PL_WALK_CONCRETE - SFX_FLAG, + /* 0x03 */ NA_SE_PL_WALK_DIRT - SFX_FLAG, + /* 0x04 */ NA_SE_PL_WALK_WATER0 - SFX_FLAG, + /* 0x05 */ NA_SE_PL_WALK_WATER1 - SFX_FLAG, + /* 0x06 */ NA_SE_PL_WALK_WATER2 - SFX_FLAG, + /* 0x07 */ NA_SE_PL_WALK_MAGMA - SFX_FLAG, + /* 0x08 */ NA_SE_PL_WALK_GRASS - SFX_FLAG, + /* 0x09 */ NA_SE_PL_WALK_GLASS - SFX_FLAG, + /* 0x0A */ NA_SE_PL_WALK_LADDER - SFX_FLAG, + /* 0x0B */ NA_SE_PL_WALK_GROUND - SFX_FLAG, + /* 0x0C */ NA_SE_PL_WALK_ICE - SFX_FLAG, + /* 0x0D */ NA_SE_PL_WALK_IRON - SFX_FLAG, + /* 0x0E */ NA_SE_PL_WALK_SNOW - SFX_FLAG +}; + +static u8 D_801B46C0[] = { + /* 0x00 */ 1, + /* 0x01 */ 1, + /* 0x02 */ 0, + /* 0x03 */ 1, + /* 0x04 */ 0, + /* 0x05 */ 0, + /* 0x06 */ 0, + /* 0x07 */ 0, + /* 0x08 */ 0, + /* 0x09 */ 0, + /* 0x0A */ 0, + /* 0x0B */ 0, + /* 0x0C */ 0, + /* 0x0D */ 0, + /* 0x0E */ 1 +}; + +static s16 sSmallMemScenes[] = { + SCENE_F01, +}; + +typedef struct { + s16 sceneId; + u32 memSize; +} BgCheckSceneMemEntry; + +static BgCheckSceneMemEntry sSceneMemList[] = { + { SCENE_00KEIKOKU, 0xC800 }, +}; + +BgCheckSceneSubdivisionEntry sSceneSubdivisionList[] = { + { SCENE_00KEIKOKU, { 36, 1, 36 }, -1 }, + { SCENE_30GYOSON, { 40, 1, 40 }, -1 }, + { SCENE_31MISAKI, { 40, 1, 40 }, -1 }, +}; + +BgSpecialSceneMaxObjects sCustomDynapolyMem[] = { + { SCENE_21MITURINMAE, 1000, 600, 512 }, +}; + +char D_801ED950[80]; +char D_801ED9A0[80]; +Vec3f D_801ED9F0[3]; // polyVerts +Vec3f D_801EDA18[3]; // polyVerts //not ok, needs to be inlined to match +MtxF D_801EDA40; +Vec3f D_801EDA80[3]; // polyVerts +char D_801EDAA8[80]; +char D_801EDAF8[80]; +Vec3f D_801EDB48[3]; // polyVerts +Vec3f D_801EDB70[3]; +Plane D_801EDB98; +Sphere16 D_801EDBA8; +TriNorm D_801EDBB0; + +void BgCheck_GetStaticLookupIndicesFromPos(CollisionContext* colCtx, Vec3f* pos, Vec3i* sector); +f32 BgCheck_RaycastFloorDyna(DynaRaycast* dynaRaycast); +s32 BgCheck_SphVsDynaWall(CollisionContext* colCtx, u16 xpFlags, f32* outX, f32* outZ, Vec3f* pos, f32 radius, + CollisionPoly** outPoly, s32* outBgId, Actor* actor); +s32 BgCheck_CheckLineImpl(CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2, Vec3f* posA, Vec3f* posB, + Vec3f* posResult, CollisionPoly** outPoly, s32* outBgId, Actor* actor, f32 checkDist, + u32 bccFlags); +s32 BgCheck_CheckDynaCeiling(CollisionContext* colCtx, u16 xpFlags, f32* outY, Vec3f* pos, f32 checkDist, + CollisionPoly** outPoly, s32* outBgId, Actor* actor); +s32 BgCheck_CheckLineAgainstDyna(CollisionContext* colCtx, u16 xpFlags, Vec3f* posA, Vec3f* posB, Vec3f* posResult, + CollisionPoly** outPoly, f32* distSq, s32* outBgId, Actor* actor, f32 checkDist, + s32 bccFlags); +s32 BgCheck_SphVsFirstDynaPoly(CollisionContext* colCtx, u16 xpFlags, CollisionPoly** outPoly, s32* outBgId, + Vec3f* center, f32 radius, Actor* actor, u16 bciFlags); +void BgCheck_ResetPolyCheckTbl(SSNodeList* nodeList, s32 numPolys); +s32 BgCheck_PosInStaticBoundingBox(CollisionContext* colCtx, Vec3f* pos); + +void SSNode_SetValue(SSNode* node, s16* polyIndex, u16 next) { node->polyId = *polyIndex; node->next = next; } -void BgCheck_PolygonLinkedListResetHead(u16* head) { - *head = 0xFFFF; +void SSList_SetNull(SSList* ssList) { + ssList->head = SS_NULL; } -void BgCheck_ScenePolygonListsNodeInsert(SSNodeList* list, u16* head, s16* polyIndex) { +void SSNodeList_SetSSListHead(SSNodeList* list, SSList* ssList, s16* polyIndex) { u16 index; - index = BgCheck_ScenePolygonListsReserveNode(list); - BgCheck_PolygonLinkedListNodeInit(&list->tbl[index], polyIndex, *head); - *head = index; + index = SSNodeList_GetNextNodeIdx(list); + SSNode_SetValue(&list->tbl[index], polyIndex, ssList->head); + ssList->head = index; } -void BgCheck_PolygonLinkedListNodeInsert(DynaSSNodeList* list, u16* head, s16* polyIndex) { +void DynaSSNodeList_SetSSListHead(DynaSSNodeList* list, SSList* ssList, s16* polyIndex) { u16 index; - index = BgCheck_AllocPolygonLinkedListNode(list); - BgCheck_PolygonLinkedListNodeInit(&list->tbl[index], polyIndex, *head); - *head = index; + index = DynaSSNodeList_GetNextNodeIdx(list); + SSNode_SetValue(&list->tbl[index], polyIndex, ssList->head); + ssList->head = index; } -void BgCheck_PolygonLinkedListInit(GlobalContext* globalCtx, DynaSSNodeList* list) { +void DynaSSNodeList_Init(GlobalContext* globalCtx, DynaSSNodeList* list) { list->tbl = NULL; list->count = 0; } -void BgCheck_PolygonLinkedListAlloc(GlobalContext* globalCtx, DynaSSNodeList* list, u32 numNodes) { - list->tbl = (SSNode*)THA_AllocEndAlign(&globalCtx->state.heap, numNodes << 2, 0xfffffffe); - list->max = numNodes; +void DynaSSNodeList_Alloc(GlobalContext* globalCtx, DynaSSNodeList* list, u32 numNodes) { + list->tbl = (SSNode*)THA_AllocEndAlign(&globalCtx->state.heap, numNodes * sizeof(SSNode), -2); + list->maxNodes = numNodes; list->count = 0; } -void BgCheck_PolygonLinkedListReset(DynaSSNodeList* list) { +void DynaSSNodeList_ResetCount(DynaSSNodeList* list) { list->count = 0; } -u16 BgCheck_AllocPolygonLinkedListNode(DynaSSNodeList* list) { - u16 index; +u16 DynaSSNodeList_GetNextNodeIdx(DynaSSNodeList* list) { + u16 index = list->count++; - index = list->count++; - if (list->max <= index) { - return 0xffff; + if (list->maxNodes <= index) { + return SS_NULL; } return index; } -void BgCheck_CreateVec3fFromVertex(Vec3s* vertex, Vec3f* vector) { - vector->x = vertex->x; - vector->y = vertex->y; - vector->z = vertex->z; +void BgCheck_Vec3sToVec3f(Vec3s* src, Vec3f* dest) { + dest->x = src->x; + dest->y = src->y; + dest->z = src->z; } -void BgCheck_CreateVertexFromVec3f(Vec3s* vertex, Vec3f* vector) { - vertex->x = vector->x; - vertex->y = vector->y; - vertex->z = vector->z; +void BgCheck_Vec3fToVec3s(Vec3s* dest, Vec3f* src) { + dest->x = src->x; + dest->y = src->y; + dest->z = src->z; } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800BFD84.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800BFDEC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_PolygonGetMinY.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_PolygonGetNormal.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C0094.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C01B8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_CreateTriNormFromPolygon.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C02C0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C0340.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C0474.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C0668.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C06A8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C074C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C07F0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_PolygonCollidesWithSphere.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ScenePolygonListsInsertSorted.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ScenePolygonListsInsert.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C0E74.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C10FC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C1238.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C12A4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C1B68.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C1D7C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C2008.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C20F4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C2310.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C2460.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C2514.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C25E0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_GetPolyMinSubdivisions.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_GetPolyMaxSubdivisions.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_GetPolyMinMaxSubdivisions.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C2BE0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_SplitScenePolygonsIntoSubdivisions.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_GetIsDefaultSpecialScene.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_GetSpecialSceneMaxMemory.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_CalcSubdivisionSize.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_GetSpecialSceneMaxObjects.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_Init.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C3C00.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C3C14.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_GetActorMeshHeader.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C3C94.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C3D50.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C3F40.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C3FA0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4000.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4058.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C40B4.s") - -f32 func_800C411C(CollisionContext* colCtx, CollisionPoly** arg1, s32* arg2, Actor* actor, Vec3f* pos) { - return func_800C3D50(0, colCtx, 2, arg1, arg2, pos, actor, 28, 1.0f, 0); +f32 func_800BFD84(CollisionPoly* poly, f32 arg1, f32 arg2) { + return (COLPOLY_GET_NORMAL(poly->normal.x * arg1 + poly->normal.z * arg2) + poly->dist) / + COLPOLY_GET_NORMAL(-poly->normal.y); } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4188.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C41E4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4240.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C42A8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4314.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C43CC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4488.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C44F0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C455C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C45C4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4C74.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4CD8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4D3C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4DA4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4E10.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4F38.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4F84.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C4FD4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C5464.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C54AC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C5538.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C55C4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C5650.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C56E0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C576C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C57F8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C583C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C58C8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C5954.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C5A20.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C5A64.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ScenePolygonListsInit.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ScenePolygonListsAlloc.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C5B80.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ScenePolygonListsReserveNode.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ActorMeshParamsInit.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_SetActorMeshParams.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_AreActorMeshParamsEqual.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ActorMeshPolyListsHeadsInit.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ActorMeshPolyListsInit.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ActorMeshVerticesIndexInit.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ActorMeshWaterboxesIndexInit.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ActorMeshInit.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ActorMeshInitFromActor.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_HasActorMeshChanged.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_PolygonsInit.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_PolygonsAlloc.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_VerticesInit.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_VerticesListAlloc.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_WaterboxListInit.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_WaterboxListAlloc.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ActorMeshUpdateParams.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_IsActorMeshIndexValid.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_DynaInit.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_DynaAlloc.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_AddActorMesh.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_GetActorOfMesh.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C62BC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C6314.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C636C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C63C4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C641C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C6474.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_RemoveActorMesh.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C6554.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_CalcWaterboxDimensions.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_AddActorMeshToLists.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_ResetFlagsIfLoadedActor.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_Update.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C756C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_UpdateAllActorMeshes.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C76EC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C7974.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C7E40.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C8580.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C87D0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C8A60.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C8BD0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C8DC0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C8EEC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C90AC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C921C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9380.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_RelocateMeshHeaderPointers.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_RelocateMeshHeader.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_RelocateAllMeshHeaders.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9640.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_GetPolygonAttributes.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9704.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9728.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9770.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C97F8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9844.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C98CC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9924.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C99AC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C99D4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C99FC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9A24.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9A4C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9A7C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9AB0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9AE4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9B18.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9B40.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9B68.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9B90.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9BB8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9BDC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9C24.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9C74.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9C9C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9CC4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9CEC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9D14.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9D50.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9D8C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9DDC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9E18.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9E40.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9E88.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800C9EBC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800CA1AC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800CA1E8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800CA22C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800CA568.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800CA634.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800CA648.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800CA6B8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800CA6D8.s") - +/** + * Unused + */ +s32 func_800BFDEC(CollisionPoly* polyA, CollisionPoly* polyB, u32* outVtxId0, u32* outVtxId1) { + s32 vtxIdA[3]; + s32 vtxIdB[3]; + s32 i; + s32 j; + s32 count; + + *outVtxId0 = *outVtxId1 = 0; + for (i = 0; i < ARRAY_COUNT(vtxIdA); i++) { + vtxIdA[i] = COLPOLY_VTX_INDEX(polyA->vtxData[i]); + vtxIdB[i] = COLPOLY_VTX_INDEX(polyB->vtxData[i]); + } + + count = 0; + for (i = 0; i < 2; i++) { + for (j = i + 1; j < 3; j++) { + if (vtxIdA[i] == vtxIdB[j]) { + if (count == 0) { + *outVtxId0 = vtxIdA[i]; + } else if (count == 1) { + *outVtxId1 = vtxIdA[i]; + } + count++; + } + } + } + return count; +} + +s16 CollisionPoly_GetMinY(CollisionPoly* poly, Vec3s* vertices) { + s16 minY; + s32 a = COLPOLY_VTX_INDEX(poly->flags_vIA); + s32 b = COLPOLY_VTX_INDEX(poly->flags_vIB); + s32 c = poly->vIC; + + minY = vertices[a].y; + if (vertices[b].y < minY) { + minY = vertices[b].y; + } + if (minY < vertices[c].y) { + return minY; + } + return vertices[c].y; +} + +void CollisionPoly_GetNormalF(CollisionPoly* poly, f32* nx, f32* ny, f32* nz) { + *nx = COLPOLY_GET_NORMAL(poly->normal.x); + *ny = COLPOLY_GET_NORMAL(poly->normal.y); + *nz = COLPOLY_GET_NORMAL(poly->normal.z); +} + +/** + * Compute transform matrix mapping +y (up) to the collision poly's normal + */ +void func_800C0094(CollisionPoly* poly, f32 tx, f32 ty, f32 tz, MtxF* dest) { + f32 nx; + f32 ny; + f32 nz; + s32 pad; + f32 z_f14; + f32 phi_f14; + f32 phi_f12; + f32 inv_z_f14; + + if (poly == NULL) { + return; + } + CollisionPoly_GetNormalF(poly, &nx, &ny, &nz); + + z_f14 = sqrtf(SQ(ny) + SQ(nz)); + if (!IS_ZERO(z_f14)) { + inv_z_f14 = 1.0f / z_f14; + phi_f14 = ny * inv_z_f14; + phi_f12 = nz * inv_z_f14; + } else { + phi_f14 = 1.0f; + phi_f12 = 0.0f; + } + dest->xx = z_f14; + dest->xy = (-nx) * phi_f14; + dest->xz = (-nx) * phi_f12; + dest->yx = nx; + dest->yy = ny; + dest->yz = nz; + dest->zx = 0.0f; + dest->zy = -phi_f12; + dest->zz = phi_f14; + dest->wx = tx; + dest->wy = ty; + dest->wz = tz; + dest->xw = 0.0f; + dest->yw = 0.0f; + dest->zw = 0.0f; + dest->ww = 1.0f; +} + +f32 CollisionPoly_GetPointDistanceFromPlane(CollisionPoly* poly, Vec3f* point) { + return COLPOLY_GET_NORMAL(poly->normal.x * point->x + poly->normal.y * point->y + poly->normal.z * point->z) + + poly->dist; +} + +void CollisionPoly_GetVertices(CollisionPoly* poly, Vec3s* vtxList, Vec3f* dest) { + BgCheck_Vec3sToVec3f(&vtxList[COLPOLY_VTX_INDEX(poly->flags_vIA)], &dest[0]); + BgCheck_Vec3sToVec3f(&vtxList[COLPOLY_VTX_INDEX(poly->flags_vIB)], &dest[1]); + BgCheck_Vec3sToVec3f(&vtxList[poly->vIC], &dest[2]); +} + +void CollisionPoly_GetVerticesByBgId(CollisionPoly* poly, s32 bgId, CollisionContext* colCtx, Vec3f* dest) { + Vec3s* vtxList; + + 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; + } + } else { + if (bgId == BGCHECK_SCENE) { + vtxList = colCtx->colHeader->vtxList; + } else { + vtxList = colCtx->dyna.vtxList; + } + CollisionPoly_GetVertices(poly, vtxList, dest); + } +} + +s32 CollisionPoly_CheckYIntersectApprox1(CollisionPoly* poly, Vec3s* vtxList, f32 x, f32 z, f32* yIntersect, + f32 checkDist) { + f32 nx; + f32 ny; + f32 nz; + Vec3s* vA; + Vec3s* vB; + Vec3s* vC; + + vA = &vtxList[COLPOLY_VTX_INDEX(poly->flags_vIA)]; + Math_Vec3s_ToVec3f(&D_801ED9F0[0], vA); + vB = &vtxList[COLPOLY_VTX_INDEX(poly->flags_vIB)]; + Math_Vec3s_ToVec3f(&D_801ED9F0[1], vB); + vC = &vtxList[poly->vIC]; + Math_Vec3s_ToVec3f(&D_801ED9F0[2], vC); + + nx = COLPOLY_GET_NORMAL(poly->normal.x); + ny = COLPOLY_GET_NORMAL(poly->normal.y); + nz = COLPOLY_GET_NORMAL(poly->normal.z); + + return Math3D_TriChkPointParaYIntersectDist(&D_801ED9F0[0], &D_801ED9F0[1], &D_801ED9F0[2], nx, ny, nz, poly->dist, + z, x, yIntersect, checkDist); +} + +/** + * Checks if point (`x`,`z`) is within `checkDist` of `poly`, computing `yIntersect` if true + * Determinant max 0.0f (checks if on or within poly) + */ +#ifdef NON_MATCHING +s32 CollisionPoly_CheckYIntersect(CollisionPoly* poly, Vec3s* vtxList, f32 x, f32 z, f32* yIntersect, f32 checkDist) { + static Vec3f polyVerts[3]; // D_801EDA18 + Vec3s* sVerts; + f32 nx; + f32 ny; + f32 nz; + + sVerts = &vtxList[COLPOLY_VTX_INDEX(poly->flags_vIA)]; + polyVerts[0].x = sVerts->x; + polyVerts[0].y = sVerts->y; + polyVerts[0].z = sVerts->z; + sVerts = &vtxList[COLPOLY_VTX_INDEX(poly->flags_vIB)]; + polyVerts[1].x = sVerts->x; + polyVerts[1].y = sVerts->y; + polyVerts[1].z = sVerts->z; + sVerts = &vtxList[poly->vIC]; + polyVerts[2].x = sVerts->x; + polyVerts[2].y = sVerts->y; + polyVerts[2].z = sVerts->z; + + if (!func_8017A304(&polyVerts[0], &polyVerts[1], &polyVerts[2], z, x, checkDist)) { + return 0; + } + nx = COLPOLY_GET_NORMAL(poly->normal.x); + ny = COLPOLY_GET_NORMAL(poly->normal.y); + nz = COLPOLY_GET_NORMAL(poly->normal.z); + return Math3D_TriChkPointParaYIntersectInsideTri2(&polyVerts[0], &polyVerts[1], &polyVerts[2], nx, ny, nz, + poly->dist, z, x, yIntersect, checkDist); +} +#else +s32 CollisionPoly_CheckYIntersect(CollisionPoly* poly, Vec3s* vtxList, f32 x, f32 z, f32* yIntersect, f32 checkDist); +#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/CollisionPoly_CheckYIntersect.s") +#endif + +s32 CollisionPoly_CheckYIntersectApprox2(CollisionPoly* poly, Vec3s* vtxList, f32 x, f32 z, f32* yIntersect) { + return CollisionPoly_CheckYIntersectApprox1(poly, vtxList, x, z, yIntersect, 1.0f); +} + +s32 CollisionPoly_CheckXIntersectApprox(CollisionPoly* poly, Vec3s* vtxList, f32 y, f32 z, f32* xIntersect) { + f32 nx; + f32 ny; + f32 nz; + + CollisionPoly_GetVertices(poly, vtxList, D_801EDA80); + CollisionPoly_GetNormalF(poly, &nx, &ny, &nz); + return Math3D_TriChkPointParaXIntersect(&D_801EDA80[0], &D_801EDA80[1], &D_801EDA80[2], nx, ny, nz, poly->dist, y, + z, xIntersect); +} + +s32 CollisionPoly_CheckZIntersectApprox(CollisionPoly* poly, Vec3s* vtxList, f32 x, f32 y, f32* zIntersect) { + f32 nx; + f32 ny; + f32 nz; + + CollisionPoly_GetVertices(poly, vtxList, D_801EDB48); + CollisionPoly_GetNormalF(poly, &nx, &ny, &nz); + return Math3D_TriChkPointParaZIntersect(&D_801EDB48[0], &D_801EDB48[1], &D_801EDB48[2], nx, ny, nz, poly->dist, x, + y, zIntersect); +} + +#ifdef NON_MATCHING +s32 CollisionPoly_LineVsPoly(BgLineVsPolyTest* a0) { + static Vec3f polyVerts[3]; // D_801EDB70 + static Plane plane; // 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)) { + 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); + + 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))) { + return true; + } + return false; +} +#else +s32 CollisionPoly_LineVsPoly(BgLineVsPolyTest* a0); +#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/CollisionPoly_LineVsPoly.s") +#endif + +#ifdef NON_MATCHING +// OK but .bss order issues +s32 CollisionPoly_SphVsPoly(CollisionPoly* poly, Vec3s* vtxList, Vec3f* center, f32 radius) { + static Sphere16 sphere; // D_801EDBA8 + static TriNorm tri; // 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); +} +#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 + +#ifdef NON_MATCHING +/** + * Add poly to StaticLookup table + * Table is sorted by poly's smallest y vertex component + * `ssList` is the list to append a new poly to + * `polyList` is the CollisionPoly lookup list + * `vtxList` is the vertex lookup list + * `polyId` is the index of the poly in polyList to insert into the lookup table + */ +void StaticLookup_AddPolyToSSList(CollisionContext* colCtx, SSList* ssList, CollisionPoly* polyList, Vec3s* vtxList, + s16 polyId) { + SSNode* curNode; + SSNode* nextNode; + s32 polyYMin; + u16 newNodeId; + s16 curPolyId; + + // if list is null + if (ssList->head == SS_NULL) { + SSNodeList_SetSSListHead(&colCtx->polyNodes, ssList, &polyId); + return; + } + + polyYMin = CollisionPoly_GetMinY(&polyList[polyId], vtxList); + + curNode = &colCtx->polyNodes.tbl[ssList->head]; + 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) { + SSNodeList_SetSSListHead(&colCtx->polyNodes, ssList, &polyId); + return; + } + while (true) { + // if at the end of the list + if (curNode->next == SS_NULL) { + newNodeId = SSNodeList_GetNextNodeIdx(&colCtx->polyNodes); + SSNode_SetValue(&colCtx->polyNodes.tbl[newNodeId], &polyId, SS_NULL); + curNode->next = newNodeId; + break; + } + + nextNode = &colCtx->polyNodes.tbl[curNode->next]; + 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) { + newNodeId = SSNodeList_GetNextNodeIdx(&colCtx->polyNodes); + SSNode_SetValue(&colCtx->polyNodes.tbl[newNodeId], &polyId, curNode->next); + curNode->next = newNodeId; + break; + } + curNode = nextNode; + } +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/StaticLookup_AddPolyToSSList.s") +#endif + +/** + * Add CollisionPoly to StaticLookup list + */ +void StaticLookup_AddPoly(StaticLookup* lookup, CollisionContext* colCtx, CollisionPoly* polyList, Vec3s* vtxList, + s16 index) { + if (polyList[index].normal.y > COLPOLY_SNORMAL(0.5f)) { + StaticLookup_AddPolyToSSList(colCtx, &lookup->floor, polyList, vtxList, index); + } else if (polyList[index].normal.y < COLPOLY_SNORMAL(-0.8f)) { + StaticLookup_AddPolyToSSList(colCtx, &lookup->ceiling, polyList, vtxList, index); + } else { + StaticLookup_AddPolyToSSList(colCtx, &lookup->wall, polyList, vtxList, index); + } +} + +/** + * Locates the closest static poly directly underneath `pos`, starting at list `ssList` + * returns yIntersect of the closest poly, or `yIntersectMin` + * stores the pointer of the closest poly to `outPoly` + * if (flags & 1), ignore polys with a normal.y < 0 (from vertical walls to ceilings) + */ +f32 BgCheck_RaycastFloorStaticList(CollisionContext* colCtx, u16 xpFlags, SSList* ssList, CollisionPoly** outPoly, + Vec3f* pos, f32 yIntersectMin, f32 checkDist, s32 flags, Actor* actor, s32 arg9) { + SSNode* curNode; + s32 polyId; + f32 result; + f32 yIntersect; + CollisionPoly* colPoly; + s32 pad; + + result = yIntersectMin; + if (ssList->head == SS_NULL) { + return result; + } + + curNode = &colCtx->polyNodes.tbl[ssList->head]; + + while (true) { + polyId = curNode->polyId; + colPoly = &colCtx->colHeader->polyList[polyId]; + + 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)))) { + if (curNode->next == SS_NULL) { + break; + } + curNode = &colCtx->polyNodes.tbl[curNode->next]; + 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) { + 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) { + result = yIntersect; + *outPoly = colPoly; + } + } + + if (curNode->next == SS_NULL) { + break; + } + curNode = &colCtx->polyNodes.tbl[curNode->next]; + } + return result; +} + +/** + * Locates the closest static poly directly underneath `pos` within `lookup`. + * returns yIntersect of the closest poly, or `yIntersectMin` + * stores the pointer of the closest poly to `outPoly` + */ +f32 BgCheck_RaycastFloorStatic(StaticLookup* lookup, CollisionContext* colCtx, u16 xpFlags, CollisionPoly** poly, + Vec3f* pos, u32 arg5, f32 checkDist, f32 yIntersectMin, Actor* actor) { + s32 flag; // skip polys with normal.y < 0 + f32 yIntersect = yIntersectMin; + + if (arg5 & 4) { + yIntersect = BgCheck_RaycastFloorStaticList(colCtx, xpFlags, &lookup->floor, poly, pos, yIntersect, checkDist, + 0, actor, arg5); + } + + if ((arg5 & 2) || (arg5 & 8)) { + flag = 0; + if (arg5 & 0x10) { + flag = 1; + } + yIntersect = BgCheck_RaycastFloorStaticList(colCtx, xpFlags, &lookup->wall, poly, pos, yIntersect, checkDist, + flag, actor, arg5); + } + + if (arg5 & 1) { + flag = 0; + if (arg5 & 0x10) { + flag = 1; + } + yIntersect = BgCheck_RaycastFloorStaticList(colCtx, xpFlags, &lookup->ceiling, poly, pos, yIntersect, checkDist, + flag, actor, arg5); + } + + return yIntersect; +} + +/** + * Compute wall displacement on `posX` and `posZ` + * sets `wallPolyPtr` to `poly` if `wallPolyPtr` is NULL + * returns true if `wallPolyPtr` was changed + * `invXZlength` is 1 / sqrt( sq(poly.normal.x) + sq(poly.normal.z) ) + */ +s32 BgCheck_ComputeWallDisplacement(CollisionContext* colCtx, CollisionPoly* poly, f32* posX, f32* posZ, f32 nx, f32 ny, + f32 nz, f32 invXZlength, f32 planeDist, f32 radius, CollisionPoly** wallPolyPtr) { + f32 displacement = (radius - planeDist) * invXZlength; + + *posX += displacement * nx; + *posZ += displacement * nz; + + if (*wallPolyPtr == NULL) { + *wallPolyPtr = poly; + return true; + } else { + return false; + } +} + +/** + * Performs collision detection on static poly walls within `lookup` on sphere `pos`, `radius` + * returns true if a collision was detected + * `outX` `outZ` return the displaced x,z coordinates, + * `outPoly` returns the pointer to the nearest poly collided with, or NULL + */ +s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16 xpFlags, f32* outX, f32* outZ, + Vec3f* pos, f32 radius, CollisionPoly** outPoly, Actor* actor) { + Vec3f resultPos; + f32 zTemp; + f32 xTemp; + f32 planeDist; + f32 intersect; + s32 result; + CollisionPoly* curPoly; + CollisionPoly* polyList; + SSNode* curNode; + f32 invNormalXZ; + Vec3s* vtxA; + Vec3s* vtxB; + Vec3s* vtxC; + s32 polyId; + f32 normalXZ; + f32 nx; + f32 ny; + f32 nz; + Vec3s* vtxList; + u16 pad; + f32 temp_f16; + f32 zMin; + f32 zMax; + f32 xMin; + f32 xMax; + + result = false; + if (lookup->wall.head == SS_NULL) { + return result; + } + resultPos = *pos; + + polyList = colCtx->colHeader->polyList; + vtxList = colCtx->colHeader->vtxList; + curNode = &colCtx->polyNodes.tbl[lookup->wall.head]; + + while (true) { + polyId = curNode->polyId; + curPoly = &polyList[polyId]; + vtxA = &vtxList[COLPOLY_VTX_INDEX(curPoly->flags_vIA)]; + 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) { + break; + } + + nx = COLPOLY_GET_NORMAL(curPoly->normal.x); + ny = COLPOLY_GET_NORMAL(curPoly->normal.y); + nz = COLPOLY_GET_NORMAL(curPoly->normal.z); + 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)))) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &colCtx->polyNodes.tbl[curNode->next]; + continue; + } + } + + invNormalXZ = 1.0f / normalXZ; + temp_f16 = fabsf(nz) * invNormalXZ; + if (temp_f16 < 0.4f) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &colCtx->polyNodes.tbl[curNode->next]; + continue; + } + } + + // compute curPoly zMin/zMax + zTemp = vtxA->z; + zMax = zMin = zTemp; + zTemp = vtxB->z; + + if (zTemp < zMin) { + zMin = zTemp; + } else if (zMax < zTemp) { + zMax = zTemp; + } + zTemp = vtxC->z; + if (zTemp < zMin) { + zMin = zTemp; + } else if (zTemp > zMax) { + zMax = zTemp; + } + + zMin -= radius; + zMax += radius; + + if (resultPos.z < zMin || resultPos.z > zMax) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &colCtx->polyNodes.tbl[curNode->next]; + continue; + } + } + if (CollisionPoly_CheckZIntersectApprox(curPoly, vtxList, resultPos.x, pos->y, &intersect)) { + f32 test = intersect - resultPos.z; + + if (fabsf(test) <= radius / temp_f16) { + if (test * nz <= 4.0f) { + if (BgCheck_ComputeWallDisplacement(colCtx, curPoly, &resultPos.x, &resultPos.z, nx, ny, nz, + invNormalXZ, planeDist, radius, outPoly)) { + result = true; + } + } + } + } + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &colCtx->polyNodes.tbl[curNode->next]; + } + } + + curNode = &colCtx->polyNodes.tbl[lookup->wall.head]; + + while (true) { + polyId = curNode->polyId; + curPoly = &polyList[polyId]; + vtxA = &vtxList[COLPOLY_VTX_INDEX(curPoly->flags_vIA)]; + 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) { + break; + } + + nx = COLPOLY_GET_NORMAL(curPoly->normal.x); + ny = COLPOLY_GET_NORMAL(curPoly->normal.y); + nz = COLPOLY_GET_NORMAL(curPoly->normal.z); + 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)))) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &colCtx->polyNodes.tbl[curNode->next]; + continue; + } + } + + invNormalXZ = 1.0f / normalXZ; + temp_f16 = fabsf(nx) * invNormalXZ; + if (temp_f16 < 0.4f) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &colCtx->polyNodes.tbl[curNode->next]; + continue; + } + } + + // compute curPoly xMin/xMax + xTemp = vtxA->x; + xMax = xMin = xTemp; + xTemp = vtxB->x; + + if (xTemp < xMin) { + xMin = xTemp; + } else if (xMax < xTemp) { + xMax = xTemp; + } + xTemp = vtxC->x; + if (xTemp < xMin) { + xMin = xTemp; + } else if (xMax < xTemp) { + xMax = xTemp; + } + + xMin -= radius; + xMax += radius; + + if (resultPos.x < xMin || xMax < resultPos.x) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &colCtx->polyNodes.tbl[curNode->next]; + continue; + } + } + if (CollisionPoly_CheckXIntersectApprox(curPoly, vtxList, pos->y, resultPos.z, &intersect)) { + f32 test = intersect - resultPos.x; + + if (fabsf(test) <= radius / temp_f16) { + if (test * nx <= 4.0f) { + if (BgCheck_ComputeWallDisplacement(colCtx, curPoly, &resultPos.x, &resultPos.z, nx, ny, nz, + invNormalXZ, planeDist, radius, outPoly)) { + result = true; + } + } + } + } + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &colCtx->polyNodes.tbl[curNode->next]; + continue; + } + } + + *outX = resultPos.x; + *outZ = resultPos.z; + return result; +} + +/** + * Tests for collision with a static poly ceiling + * returns true if a collision occurs, else false + * `outPoly` returns the poly collided with + * `outY` returns the y coordinate needed to not collide with `outPoly` + */ +#ifdef NON_MATCHING +s32 BgCheck_CheckStaticCeiling(StaticLookup* lookup, u16 xpFlags, CollisionContext* colCtx, f32* outY, Vec3f* pos, + f32 checkHeight, CollisionPoly** outPoly, Actor* actor) { + s32 result = false; + // u16 nextId; + CollisionPoly* curPoly; + CollisionPoly* polyList; + f32 ceilingY; + Vec3s* vtxList; + SSNode* curNode; + s32 curPolyId; + + if (lookup->ceiling.head == SS_NULL) { + return result; + } + curNode = &colCtx->polyNodes.tbl[lookup->ceiling.head]; + polyList = colCtx->colHeader->polyList; + vtxList = colCtx->colHeader->vtxList; + + *outY = pos->y; + + while (true) { + curPolyId = curNode->polyId; + 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)))) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &colCtx->polyNodes.tbl[curNode->next]; + continue; + } + } + + if (CollisionPoly_CheckYIntersectApprox2(curPoly, vtxList, pos->x, pos->z, &ceilingY)) { + f32 intersectDist = ceilingY - *outY; + f32 ny = COLPOLY_GET_NORMAL(curPoly->normal.y); + + if (intersectDist > 0 && intersectDist < checkHeight && intersectDist * ny <= 0) { + *outY = ceilingY - checkHeight; + *outPoly = curPoly; + result = true; + } + } + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &colCtx->polyNodes.tbl[curNode->next]; + continue; + } + } + return result; +} +#else +s32 BgCheck_CheckStaticCeiling(StaticLookup* lookup, u16 xpFlags, CollisionContext* colCtx, f32* outY, Vec3f* pos, + f32 checkHeight, CollisionPoly** outPoly, Actor* actor); +#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_CheckStaticCeiling.s") +#endif + +/** + * Tests if line `posA` to `posB` intersects with a static poly in list `ssList`. Uses polyCheckTbl + * returns true if such a poly exists, else false + * `outPoly` returns the pointer of the poly intersected + * `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; + s32 result; + Vec3f polyIntersect; // sp7C + SSNode* curNode; + u8* checkedPoly; + f32 minY; + 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; + test.posA = arg0->posA; + test.posB = arg0->posB; + test.planeIntersect = &polyIntersect; // reorder maybe + test.checkOneFace = (arg0->bccFlags & BGCHECK_CHECK_ONE_FACE) != 0; + test.checkDist = arg0->checkDist; + + while (true) { + polyId = curNode->polyId; + 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)) || + 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)))) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &colCtx->polyNodes.tbl[curNode->next]; + continue; + } + } + *checkedPoly = true; + minY = CollisionPoly_GetMinY(test.poly, test.vtxList); + if (test.posA->y < minY && test.posB->y < minY) { + break; + } + if (CollisionPoly_LineVsPoly(&test)) { + distSq = Math3D_Vec3fDistSq(test.posA, test.planeIntersect); + if (distSq < arg0->outDistSq) { + arg0->outDistSq = distSq; + *arg0->outPos = *test.planeIntersect; + *arg0->posB = *test.planeIntersect; + *arg0->outPoly = test.poly; + result = true; + } + } + if (curNode->next == SS_NULL) { + break; + } + curNode = &arg0->colCtx->polyNodes.tbl[curNode->next]; + } + 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 + * returns true if such a poly exists, else false + * `outPoly` returns the pointer of the poly intersected + * `posB` and `outPos` returns the point of intersection with `outPoly` + * `outDistSq` returns the squared distance from `posA` to the point of intersect + */ +s32 BgCheck_CheckLineInSubdivision(StaticLineTest* arg0) { + s32 result = false; + + 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) { + arg0->ssList = &arg0->lookup->wall; + if (BgCheck_CheckLineAgainstSSList(arg0)) { + result = true; + } + } + + if ((arg0->bccFlags & BGCHECK_CHECK_CEILING) && arg0->lookup->ceiling.head != SS_NULL) { + arg0->ssList = &arg0->lookup->ceiling; + if (BgCheck_CheckLineAgainstSSList(arg0)) { + result = true; + } + } + return result; +} + +/** + * Get first static poly intersecting sphere `center` `radius` from list `node` + * returns true if any poly intersects the sphere, else returns false + * `outPoly` returns the pointer of the first poly found that intersects + */ +#ifdef NON_MATCHING +s32 BgCheck_SphVsFirstStaticPolyList(SSNode* node, u16 xpFlags, CollisionContext* colCtx, Vec3f* center, f32 radius, + CollisionPoly** outPoly, Actor* actor) { + Vec3s* vtxList; + CollisionPoly* polyList; + CollisionPoly* curPoly; + u16 nextId; + s16 curPolyId; + s32 pad; + + polyList = colCtx->colHeader->polyList; + vtxList = colCtx->colHeader->vtxList; + + while (true) { + curPolyId = node->polyId; + 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)))) { + if (node->next != SS_NULL) { + node = &colCtx->polyNodes.tbl[node->next]; + continue; + } + 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) { + break; + } + + if (CollisionPoly_SphVsPoly(curPoly, vtxList, center, radius)) { + *outPoly = curPoly; + return true; + } + if (node->next != SS_NULL) { + node = &colCtx->polyNodes.tbl[node->next]; + continue; + } + break; + } + return false; +} +#else +s32 BgCheck_SphVsFirstStaticPolyList(SSNode* node, u16 xpFlags, CollisionContext* colCtx, Vec3f* center, f32 radius, + CollisionPoly** outPoly, Actor* actor); +#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_SphVsFirstStaticPolyList.s") +#endif + +/** + * Get first static poly intersecting sphere `center` `radius` within `lookup` + * returns true if any poly intersects the sphere, else false + * `outPoly` returns the first poly found that intersects + */ +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) && + 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) && + 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) && + BgCheck_SphVsFirstStaticPolyList(&colCtx->polyNodes.tbl[lookup->ceiling.head], xpFlags, colCtx, center, radius, + outPoly, actor)) { + return true; + } + + return false; +} + +/** + * Get StaticLookup from `pos` + * Does not return NULL + */ +StaticLookup* BgCheck_GetNearestStaticLookup(CollisionContext* colCtx, StaticLookup* lookupTbl, Vec3f* pos) { + Vec3i sector; + s32 subdivAmountX; + + BgCheck_GetStaticLookupIndicesFromPos(colCtx, pos, §or); + subdivAmountX = colCtx->subdivAmount.x; + return (sector.z * subdivAmountX) * colCtx->subdivAmount.y + lookupTbl + sector.x + sector.y * subdivAmountX; +} + +/** + * Get StaticLookup from `pos` + * Returns NULL if just outside the mesh bounding box + */ +StaticLookup* BgCheck_GetStaticLookup(CollisionContext* colCtx, StaticLookup* lookupTbl, Vec3f* pos) { + Vec3i sector; + s32 subdivAmountX; + + if (!BgCheck_PosInStaticBoundingBox(colCtx, pos)) { + return NULL; + } + BgCheck_GetStaticLookupIndicesFromPos(colCtx, pos, §or); + subdivAmountX = colCtx->subdivAmount.x; + return (sector.z * subdivAmountX) * colCtx->subdivAmount.y + lookupTbl + sector.x + sector.y * subdivAmountX; +} + +/** + * Get StaticLookup subdivision indices from `pos` + * `sector` returns the subdivision x,y,z indices containing or is nearest to `pos` + */ +void BgCheck_GetStaticLookupIndicesFromPos(CollisionContext* colCtx, Vec3f* pos, Vec3i* sector) { + sector->x = (pos->x - colCtx->minBounds.x) * colCtx->subdivLengthInv.x; + sector->y = (pos->y - colCtx->minBounds.y) * colCtx->subdivLengthInv.y; + sector->z = (pos->z - colCtx->minBounds.z) * colCtx->subdivLengthInv.z; + + if (sector->x < 0) { + sector->x = 0; + } else if (sector->x >= colCtx->subdivAmount.x) { + sector->x = colCtx->subdivAmount.x - 1; + } + + if (sector->y < 0) { + sector->y = 0; + } else if (sector->y >= colCtx->subdivAmount.y) { + sector->y = colCtx->subdivAmount.y - 1; + } + + if (sector->z < 0) { + sector->z = 0; + } else if (sector->z >= colCtx->subdivAmount.z) { + sector->z = colCtx->subdivAmount.z - 1; + } +} + +/** + * Get negative bias subdivision indices + * decrements indices if `pos` is within BGCHECK_SUBDIV_OVERLAP units of the negative subdivision boundary + * `sx`, `sy`, `sz` returns the subdivision x, y, z indices + */ +void BgCheck_GetSubdivisionMinBounds(CollisionContext* colCtx, Vec3f* pos, s32* sx, s32* sy, s32* sz) { + f32 dx = pos->x - colCtx->minBounds.x; + f32 dy = pos->y - colCtx->minBounds.y; + f32 dz = pos->z - colCtx->minBounds.z; + + *sx = dx * colCtx->subdivLengthInv.x; + *sy = dy * colCtx->subdivLengthInv.y; + *sz = dz * colCtx->subdivLengthInv.z; + + if (((s32)dx % (s32)colCtx->subdivLength.x < BGCHECK_SUBDIV_OVERLAP) && (*sx > 0)) { + *sx -= 1; + } + + if (((s32)dy % (s32)colCtx->subdivLength.y < BGCHECK_SUBDIV_OVERLAP) && (*sy > 0)) { + *sy -= 1; + } + + if (((s32)dz % (s32)colCtx->subdivLength.z < BGCHECK_SUBDIV_OVERLAP) && (*sz > 0)) { + *sz -= 1; + } +} + +/** + * Get positive bias subdivision indices + * increments indicies if `pos` is within BGCHECK_SUBDIV_OVERLAP units of the postive subdivision boundary + * `sx`, `sy`, `sz` returns the subdivision x, y, z indices + */ +void BgCheck_GetSubdivisionMaxBounds(CollisionContext* colCtx, Vec3f* pos, s32* sx, s32* sy, s32* sz) { + f32 dx = pos->x - colCtx->minBounds.x; + f32 dy = pos->y - colCtx->minBounds.y; + f32 dz = pos->z - colCtx->minBounds.z; + + *sx = dx * colCtx->subdivLengthInv.x; + *sy = dy * colCtx->subdivLengthInv.y; + *sz = dz * colCtx->subdivLengthInv.z; + + if (((s32)colCtx->subdivLength.x - BGCHECK_SUBDIV_OVERLAP < (s32)dx % (s32)colCtx->subdivLength.x) && + (*sx < colCtx->subdivAmount.x - 1)) { + *sx += 1; + } + + if (((s32)colCtx->subdivLength.y - BGCHECK_SUBDIV_OVERLAP < (s32)dy % (s32)colCtx->subdivLength.y) && + (*sy < colCtx->subdivAmount.y - 1)) { + *sy += 1; + } + + if (((s32)colCtx->subdivLength.z - BGCHECK_SUBDIV_OVERLAP < (s32)dz % (s32)colCtx->subdivLength.z) && + (*sz < colCtx->subdivAmount.z - 1)) { + *sz += 1; + } +} + +/** + * Calculate the subdivision index bounding box for CollisionPoly `polyId` + * `subdivMinX`, `subdivMinY`, `subdivMinZ` returns the minimum subdivision x, y, z indices + * `subdivMaxX`, `subdivMaxY`, `subdivMaxZ` returns the maximum subdivision x, y, z indices + */ +void BgCheck_GetPolySubdivisionBounds(CollisionContext* colCtx, Vec3s* vtxList, CollisionPoly* polyList, + s32* subdivMinX, s32* subdivMinY, s32* subdivMinZ, s32* subdivMaxX, + s32* subdivMaxY, s32* subdivMaxZ, s16 polyId) { + u16* vtxDataTemp; + Vec3f minVtx; + Vec3f maxVtx; + + f32 x; + f32 y; + f32 z; + + Vec3s* vtx; + s16 vtxId = COLPOLY_VTX_INDEX(polyList[polyId].vtxData[0]); + + Math_Vec3s_ToVec3f(&maxVtx, &vtxList[vtxId]); + Math_Vec3f_Copy(&minVtx, &maxVtx); + + for (vtxDataTemp = polyList[polyId].vtxData + 1; vtxDataTemp < polyList[polyId].vtxData + 3; vtxDataTemp++) { + vtxId = COLPOLY_VTX_INDEX(*vtxDataTemp); + vtx = &vtxList[vtxId]; + x = vtx->x; + y = vtx->y; + z = vtx->z; + + if (minVtx.x > x) { + minVtx.x = x; + } else if (maxVtx.x < x) { + maxVtx.x = x; + } + + if (minVtx.y > y) { + minVtx.y = y; + } else if (maxVtx.y < y) { + maxVtx.y = y; + } + + if (minVtx.z > z) { + minVtx.z = z; + } else if (maxVtx.z < z) { + maxVtx.z = z; + } + } + BgCheck_GetSubdivisionMinBounds(colCtx, &minVtx, subdivMinX, subdivMinY, subdivMinZ); + BgCheck_GetSubdivisionMaxBounds(colCtx, &maxVtx, subdivMaxX, subdivMaxY, subdivMaxZ); +} + +/** + * Test if poly `polyList`[`polyId`] intersects cube `min` `max` + * returns true if the poly intersects the cube, else false + */ +s32 BgCheck_PolyIntersectsSubdivision(Vec3f* min, Vec3f* max, CollisionPoly* polyList, Vec3s* vtxList, s16 polyId) { + f32 intersect; + Vec3f va2; + Vec3f vb2; + Vec3f vc2; + CollisionPoly* poly; + f32 nx; + f32 ny; + f32 nz; + f32 dist; + Vec3f va; + Vec3f vb; + Vec3f vc; + s32 flags[3]; + + flags[0] = flags[1] = 0; + poly = &polyList[polyId]; + + BgCheck_Vec3sToVec3f(&vtxList[COLPOLY_VTX_INDEX(poly->flags_vIA)], &va); + flags[0] = Math3D_PointRelativeToCubeFaces(&va, min, max); + if (flags[0] == 0) { + return true; + } + + BgCheck_Vec3sToVec3f(&vtxList[COLPOLY_VTX_INDEX(poly->flags_vIB)], &vb); + flags[1] = Math3D_PointRelativeToCubeFaces(&vb, min, max); + if (flags[1] == 0) { + return true; + } + + BgCheck_Vec3sToVec3f(&vtxList[poly->vIC], &vc); + flags[2] = Math3D_PointRelativeToCubeFaces(&vc, min, max); + if (flags[2] == 0) { + return true; + } + + if (flags[0] & flags[1] & flags[2]) { + return false; + } + + flags[0] |= Math3D_PointRelativeToCubeEdges(&va, min, max) << 8; + flags[1] |= Math3D_PointRelativeToCubeEdges(&vb, min, max) << 8; + flags[2] |= Math3D_PointRelativeToCubeEdges(&vc, min, max) << 8; + if (flags[0] & flags[1] & flags[2]) { + return false; + } + + flags[0] |= Math3D_PointRelativeToCubeVertices(&va, min, max) << 0x18; + flags[1] |= Math3D_PointRelativeToCubeVertices(&vb, min, max) << 0x18; + flags[2] |= Math3D_PointRelativeToCubeVertices(&vc, min, max) << 0x18; + if (flags[0] & flags[1] & flags[2]) { + return false; + } + + CollisionPoly_GetNormalF(poly, &nx, &ny, &nz); + dist = poly->dist; + + if (Math3D_TriChkLineSegParaYIntersect(&va, &vb, &vc, nx, ny, nz, dist, min->z, min->x, &intersect, min->y, + max->y) || + Math3D_TriChkLineSegParaYIntersect(&va, &vb, &vc, nx, ny, nz, dist, max->z, min->x, &intersect, min->y, + max->y) || + Math3D_TriChkLineSegParaYIntersect(&va, &vb, &vc, nx, ny, nz, dist, min->z, max->x, &intersect, min->y, + max->y) || + Math3D_TriChkLineSegParaYIntersect(&va, &vb, &vc, nx, ny, nz, dist, max->z, max->x, &intersect, min->y, + max->y)) { + return true; + } + if (Math3D_TriChkLineSegParaZIntersect(&va, &vb, &vc, nx, ny, nz, dist, min->x, min->y, &intersect, min->z, + max->z) || + Math3D_TriChkLineSegParaZIntersect(&va, &vb, &vc, nx, ny, nz, dist, min->x, max->y, &intersect, min->z, + max->z) || + Math3D_TriChkLineSegParaZIntersect(&va, &vb, &vc, nx, ny, nz, dist, max->x, min->y, &intersect, min->z, + max->z) || + Math3D_TriChkLineSegParaZIntersect(&va, &vb, &vc, nx, ny, nz, dist, max->x, max->y, &intersect, min->z, + max->z)) { + return true; + } + if (Math3D_TriChkLineSegParaXIntersect(&va, &vb, &vc, nx, ny, nz, dist, min->y, min->z, &intersect, min->x, + max->x) || + Math3D_TriChkLineSegParaXIntersect(&va, &vb, &vc, nx, ny, nz, dist, min->y, max->z, &intersect, min->x, + max->x) || + Math3D_TriChkLineSegParaXIntersect(&va, &vb, &vc, nx, ny, nz, dist, max->y, min->z, &intersect, min->x, + max->x) || + Math3D_TriChkLineSegParaXIntersect(&va, &vb, &vc, nx, ny, nz, dist, max->y, max->z, &intersect, min->x, + max->x)) { + return true; + } + + BgCheck_Vec3sToVec3f(&vtxList[COLPOLY_VTX_INDEX(poly->flags_vIA)], &va2); + BgCheck_Vec3sToVec3f(&vtxList[COLPOLY_VTX_INDEX(poly->flags_vIB)], &vb2); + BgCheck_Vec3sToVec3f(&vtxList[poly->vIC], &vc2); + if (Math3D_LineVsCube(min, max, &va2, &vb2) || Math3D_LineVsCube(min, max, &vb2, &vc2) || + Math3D_LineVsCube(min, max, &vc2, &va2)) { + return true; + } + return false; +} + +/** + * Initialize StaticLookup Table + * returns size of table, in bytes + */ +u32 BgCheck_InitStaticLookup(CollisionContext* colCtx, GlobalContext* globalCtx, StaticLookup* lookupTbl) { + Vec3s* vtxList; + CollisionPoly* polyList; + s32 polyMax; + s32 polyIdx; + s32 sx; + s32 sy; + s32 sz; + // subdivMin indices + s32 sxMin; + s32 syMin; + s32 szMin; + // subdivMax indices + s32 sxMax; + s32 syMax; + s32 szMax; + // subdiv min/max bounds for adding a poly + Vec3f curSubdivMin; + Vec3f curSubdivMax; + CollisionHeader* colHeader = colCtx->colHeader; + s32 pad[2]; + StaticLookup* iLookup; + StaticLookup* jLookup; + StaticLookup* lookup; + s32 sp98; + f32 subdivLengthX; + f32 subdivLengthY; + f32 subdivLengthZ; + + for (iLookup = lookupTbl; + iLookup < (colCtx->subdivAmount.x * colCtx->subdivAmount.y * colCtx->subdivAmount.z + lookupTbl); iLookup++) { + iLookup->floor.head = SS_NULL; + iLookup->wall.head = SS_NULL; + iLookup->ceiling.head = SS_NULL; + } + + polyMax = colHeader->numPolygons; + vtxList = colHeader->vtxList; + polyList = colHeader->polyList; + sp98 = colCtx->subdivAmount.x * colCtx->subdivAmount.y; + subdivLengthX = colCtx->subdivLength.x + (2 * BGCHECK_SUBDIV_OVERLAP); + subdivLengthY = colCtx->subdivLength.y + (2 * BGCHECK_SUBDIV_OVERLAP); + subdivLengthZ = colCtx->subdivLength.z + (2 * BGCHECK_SUBDIV_OVERLAP); + + for (polyIdx = 0; polyIdx < polyMax; polyIdx++) { + BgCheck_GetPolySubdivisionBounds(colCtx, vtxList, polyList, &sxMin, &syMin, &szMin, &sxMax, &syMax, &szMax, + polyIdx); + iLookup = szMin * sp98 + lookupTbl; + curSubdivMin.z = (colCtx->subdivLength.z * szMin + colCtx->minBounds.z) - BGCHECK_SUBDIV_OVERLAP; + curSubdivMax.z = curSubdivMin.z + subdivLengthZ; + + for (sz = szMin; sz < szMax + 1; sz++) { + jLookup = (colCtx->subdivAmount.x * syMin) + iLookup; + curSubdivMin.y = (colCtx->subdivLength.y * syMin + colCtx->minBounds.y) - BGCHECK_SUBDIV_OVERLAP; + curSubdivMax.y = curSubdivMin.y + subdivLengthY; + + for (sy = syMin; sy < syMax + 1; sy++) { + lookup = sxMin + jLookup; + curSubdivMin.x = (colCtx->subdivLength.x * sxMin + colCtx->minBounds.x) - BGCHECK_SUBDIV_OVERLAP; + curSubdivMax.x = curSubdivMin.x + subdivLengthX; + + for (sx = sxMin; sx < sxMax + 1; sx++) { + if (BgCheck_PolyIntersectsSubdivision(&curSubdivMin, &curSubdivMax, polyList, vtxList, polyIdx)) { + StaticLookup_AddPoly(lookup, colCtx, polyList, vtxList, polyIdx); + } + curSubdivMin.x += colCtx->subdivLength.x; + curSubdivMax.x += colCtx->subdivLength.x; + lookup++; + } + curSubdivMin.y += colCtx->subdivLength.y; + curSubdivMax.y += colCtx->subdivLength.y; + jLookup += colCtx->subdivAmount.x; + } + curSubdivMin.z += colCtx->subdivLength.z; + curSubdivMax.z += colCtx->subdivLength.z; + iLookup += sp98; + } + } + return colCtx->polyNodes.count * sizeof(SSNode); +} + +/** + * Returns whether the current scene should reserve less memory for it's collision lookup + */ +s32 BgCheck_IsSmallMemScene(GlobalContext* globalCtx) { + s16* i; + + for (i = sSmallMemScenes; i < sSmallMemScenes + ARRAY_COUNT(sSmallMemScenes); i++) { + if (globalCtx->sceneNum == *i) { + return true; + } + } + return false; +} + +/** + * Get custom scene memSize + */ +s32 BgCheck_TryGetCustomMemsize(s32 sceneId, u32* memSize) { + s32 i; + + for (i = 0; i < ARRAY_COUNT(sSceneMemList); i++) { + if (sceneId == sSceneMemList[i].sceneId) { + *memSize = sSceneMemList[i].memSize; + return true; + } + } + return false; +} + +/** + * Compute subdivLength for scene mesh lookup, for a single dimension + */ +void BgCheck_SetSubdivisionDimension(f32 min, s32 subdivAmount, f32* max, f32* subdivLength, f32* subdivLengthInv) { + f32 length = (*max - min); + + *subdivLength = (s32)(length / subdivAmount) + 1; + *subdivLength = CLAMP_MIN(*subdivLength, BGCHECK_SUBDIV_MIN); + *subdivLengthInv = 1.0f / *subdivLength; + + *max = *subdivLength * subdivAmount + min; +} + +s32 BgCheck_GetSpecialSceneMaxObjects(GlobalContext* globalCtx, s32* maxNodes, s32* maxPolygons, s32* maxVertices) { + s32 i; + + for (i = 0; i < ARRAY_COUNT(sCustomDynapolyMem); i++) { + if (globalCtx->sceneNum == sCustomDynapolyMem[i].sceneId) { + *maxNodes = sCustomDynapolyMem[i].maxNodes; + *maxPolygons = sCustomDynapolyMem[i].maxPolygons; + *maxVertices = sCustomDynapolyMem[i].maxVertices; + return true; + } + } + return false; +} + +/** + * Allocate CollisionContext + */ +#ifdef NON_MATCHING +void BgCheck_Allocate(CollisionContext* colCtx, GlobalContext* globalCtx, CollisionHeader* colHeader) { + u32 tblMax; + u32 memSize; + u32 lookupTblMemSize; + SSNodeList* nodeList; + s32 useCustomSubdivisions; + u32 customMemSize; + s32 customNodeListMax; + s32 i; + + customNodeListMax = -1; + colCtx->colHeader = colHeader; + colCtx->flags = 0; + + if (BgCheck_IsSmallMemScene(globalCtx)) { + colCtx->memSize = 0xF000; + colCtx->dyna.polyNodesMax = 1000; + colCtx->dyna.polyListMax = 512; + colCtx->dyna.vtxListMax = 512; + colCtx->subdivAmount.x = 16; + colCtx->subdivAmount.y = 4; + colCtx->subdivAmount.z = 16; + } else { + if (BgCheck_TryGetCustomMemsize(globalCtx->sceneNum, &customMemSize)) { + colCtx->memSize = customMemSize; + } else { + colCtx->memSize = 0x23000; + } + colCtx->dyna.polyNodesMax = 1000; + colCtx->dyna.polyListMax = 544; + colCtx->dyna.vtxListMax = 512; + BgCheck_GetSpecialSceneMaxObjects(globalCtx, &colCtx->dyna.polyNodesMax, &colCtx->dyna.polyListMax, + &colCtx->dyna.vtxListMax); + useCustomSubdivisions = false; + + for (i = 0; i < ARRAY_COUNT(sSceneSubdivisionList); i++) { + if (globalCtx->sceneNum == sSceneSubdivisionList[i].sceneId) { + colCtx->subdivAmount.x = sSceneSubdivisionList[i].subdivAmount.x; + colCtx->subdivAmount.y = sSceneSubdivisionList[i].subdivAmount.y; + colCtx->subdivAmount.z = sSceneSubdivisionList[i].subdivAmount.z; + useCustomSubdivisions = true; + customNodeListMax = sSceneSubdivisionList[i].nodeListMax; + } + } + if (useCustomSubdivisions == false) { + colCtx->subdivAmount.x = 16; + colCtx->subdivAmount.y = 4; + colCtx->subdivAmount.z = 16; + } + } + colCtx->lookupTbl = THA_AllocEndAlign( + &globalCtx->state.heap, + colCtx->subdivAmount.x * sizeof(StaticLookup) * colCtx->subdivAmount.y * colCtx->subdivAmount.z, ~1); + if (colCtx->lookupTbl == NULL) { + Fault_AddHungupAndCrash("../z_bgcheck.c", 3955); + } + colCtx->minBounds.x = colCtx->colHeader->minBounds.x; + colCtx->minBounds.y = colCtx->colHeader->minBounds.y; + colCtx->minBounds.z = colCtx->colHeader->minBounds.z; + colCtx->maxBounds.x = colCtx->colHeader->maxBounds.x; + colCtx->maxBounds.y = colCtx->colHeader->maxBounds.y; + colCtx->maxBounds.z = colCtx->colHeader->maxBounds.z; + BgCheck_SetSubdivisionDimension(colCtx->minBounds.x, colCtx->subdivAmount.x, &colCtx->maxBounds.x, + &colCtx->subdivLength.x, &colCtx->subdivLengthInv.x); + BgCheck_SetSubdivisionDimension(colCtx->minBounds.y, colCtx->subdivAmount.y, &colCtx->maxBounds.y, + &colCtx->subdivLength.y, &colCtx->subdivLengthInv.y); + BgCheck_SetSubdivisionDimension(colCtx->minBounds.z, colCtx->subdivAmount.z, &colCtx->maxBounds.z, + &colCtx->subdivLength.z, &colCtx->subdivLengthInv.z); + memSize = colCtx->subdivAmount.x * sizeof(StaticLookup) * colCtx->subdivAmount.y * colCtx->subdivAmount.z + + colCtx->colHeader->numPolygons * sizeof(u8) + colCtx->dyna.polyNodesMax * sizeof(SSNode) + + colCtx->dyna.polyListMax * sizeof(CollisionPoly) + colCtx->dyna.vtxListMax * sizeof(Vec3s) + + sizeof(CollisionContext); + if (customNodeListMax > 0) { + // tblMax is set without checking if customNodeListMax will result in a memory overflow + // this is a non-issue as long as sSceneSubdivisionList.nodeListMax is -1 + tblMax = customNodeListMax; + } else { + if (colCtx->memSize < memSize) { + Fault_AddHungupAndCrash("../z_bgcheck.c", 4011); + } + tblMax = (colCtx->memSize - memSize) / sizeof(SSNode); + } + + SSNodeList_Init(&colCtx->polyNodes); + SSNodeList_Alloc(globalCtx, &colCtx->polyNodes, tblMax, colCtx->colHeader->numPolygons); + + lookupTblMemSize = BgCheck_InitStaticLookup(colCtx, globalCtx, colCtx->lookupTbl); + + DynaPoly_Init(globalCtx, &colCtx->dyna); + DynaPoly_Alloc(globalCtx, &colCtx->dyna); +} +#else +void BgCheck_Allocate(CollisionContext* colCtx, GlobalContext* globalCtx, CollisionHeader* colHeader); +#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_Allocate.s") +#endif + +/** + * Enables CollisionContext wide flags + * Only used to reverse water flow in Great Bay Temple + */ +void BgCheck_SetContextFlags(CollisionContext* colCtx, u32 flags) { + colCtx->flags |= flags; +} + +/** + * Disables CollisionContext wide flags + * Only used to revert the reverse water flow in Great Bay Temple + */ +void BgCheck_UnsetContextFlags(CollisionContext* colCtx, u32 flags) { + colCtx->flags &= ~flags; +} + +/** + * original name: T_BGCheck_getBGDataInfo + */ +CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId) { + if (bgId == BGCHECK_SCENE) { + return colCtx->colHeader; + } + if (bgId < 0 || bgId > BG_ACTOR_MAX) { + return NULL; + } + if (!(colCtx->dyna.bgActorFlags[bgId] & 1)) { + return NULL; + } + return colCtx->dyna.bgActors[bgId].colHeader; +} + +/** + * 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) { + return false; + } + return true; +} + +/** + * Raycast Toward Floor + * returns the yIntersect of the nearest poly found directly below `pos`, or BGCHECK_Y_MIN if no floor detected + * returns the poly found in `outPoly`, and the bgId of the entity in `outBgId` + */ +f32 BgCheck_RaycastFloorImpl(GlobalContext* globalCtx, CollisionContext* colCtx, u16 xpFlags, CollisionPoly** outPoly, + s32* outBgId, Vec3f* pos, Actor* actor, u32 arg7, f32 checkDist, s32 arg9) { + f32 yIntersectDyna; + f32 yIntersect; + StaticLookup* lookupTbl; + Vec3f checkPos; + StaticLookup* lookup; + DynaRaycast dynaRaycast; + + *outBgId = BGCHECK_SCENE; + *outPoly = NULL; + lookupTbl = colCtx->lookupTbl; + yIntersect = BGCHECK_Y_MIN; + checkPos = *pos; + + while (true) { + if (checkPos.y < colCtx->minBounds.y) { + break; + } + lookup = BgCheck_GetStaticLookup(colCtx, lookupTbl, &checkPos); + if (lookup == NULL) { + checkPos.y -= colCtx->subdivLength.y; + continue; + } + yIntersect = + BgCheck_RaycastFloorStatic(lookup, colCtx, xpFlags, outPoly, pos, arg7, checkDist, BGCHECK_Y_MIN, actor); + if (yIntersect > BGCHECK_Y_MIN) { + break; + } + checkPos.y -= colCtx->subdivLength.y; + } + if (!(arg9 & 1)) { + dynaRaycast.globalCtx = globalCtx; + dynaRaycast.colCtx = colCtx; + dynaRaycast.xpFlags = xpFlags; + dynaRaycast.resultPoly = outPoly; + dynaRaycast.yIntersect = yIntersect; + dynaRaycast.pos = pos; + dynaRaycast.bgId = outBgId; + dynaRaycast.unk1C = 50; + dynaRaycast.actor = actor; + dynaRaycast.unk_24 = arg7; + dynaRaycast.checkDist = checkDist; + + yIntersectDyna = BgCheck_RaycastFloorDyna(&dynaRaycast); + if (yIntersect < yIntersectDyna) { + yIntersect = yIntersectDyna; + } + } + + if (yIntersect != BGCHECK_Y_MIN && func_800C9B68(colCtx, *outPoly, *outBgId)) { + yIntersect -= 1.0f; + } + return yIntersect; +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_CameraRaycastFloor1(CollisionContext* colCtx, CollisionPoly** outPoly, Vec3f* pos) { + s32 bgId; + + return BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_CAMERA, outPoly, &bgId, pos, NULL, 0x1C, 1.0f, 0); +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_EntityRaycastFloor1(CollisionContext* colCtx, CollisionPoly** outPoly, Vec3f* pos) { + s32 bgId; + + return BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_ENTITY, outPoly, &bgId, pos, NULL, 0x1C, 1.0f, 0); +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_EntityRaycastFloor2(GlobalContext* globalCtx, CollisionContext* colCtx, CollisionPoly** outPoly, + Vec3f* pos) { + s32 bgId; + + return BgCheck_RaycastFloorImpl(globalCtx, colCtx, COLPOLY_IGNORE_ENTITY, outPoly, &bgId, pos, NULL, 0x1C, 1.0f, 0); +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_EntityRaycastFloor2_1(GlobalContext* globalCtx, CollisionContext* colCtx, CollisionPoly** outPoly, + Vec3f* pos) { + s32 bgId; + + return BgCheck_RaycastFloorImpl(globalCtx, colCtx, COLPOLY_IGNORE_ENTITY, outPoly, &bgId, pos, NULL, 0x1C, 1.0f, 1); +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_EntityRaycastFloor3(CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Vec3f* pos) { + return BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_ENTITY, outPoly, bgId, pos, NULL, 0x1C, 1.0f, 0); +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_EntityRaycastFloor5(CollisionContext* colCtx, CollisionPoly** outPoly, s32* outBgId, Actor* actor, + Vec3f* pos) { + return BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_ENTITY, outPoly, outBgId, pos, actor, 0x1C, 1.0f, 0); +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_EntityRaycastFloor5_2(GlobalContext* globalCtx, CollisionContext* colCtx, CollisionPoly** outPoly, + s32* bgId, Actor* actor, Vec3f* pos) { + return BgCheck_RaycastFloorImpl(globalCtx, colCtx, COLPOLY_IGNORE_ENTITY, outPoly, bgId, pos, actor, 0x1C, 1.0f, 0); +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_EntityRaycastFloor5_3(GlobalContext* globalCtx, CollisionContext* colCtx, CollisionPoly** outPoly, + s32* bgId, Actor* actor, Vec3f* pos) { + return BgCheck_RaycastFloorImpl(globalCtx, colCtx, COLPOLY_IGNORE_ENTITY, outPoly, bgId, pos, actor, 0x3C, 1.0f, 0); +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_EntityRaycastFloor6(CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Actor* actor, Vec3f* pos, + f32 checkDist) { + return BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_ENTITY, outPoly, bgId, pos, actor, 0x1C, checkDist, 0); +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_EntityRaycastFloor7(CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Actor* actor, + Vec3f* pos) { + return BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_ENTITY, outPoly, bgId, pos, actor, 0x06, 1.0f, 0); +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_AnyRaycastFloor1(CollisionContext* colCtx, CollisionPoly* outPoly, Vec3f* pos) { + CollisionPoly* tempPoly; + f32 result; + s32 bgId; + + result = BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_NONE, &tempPoly, &bgId, pos, NULL, 0x1C, 1.0f, 0); + + if (tempPoly != NULL) { + *outPoly = *tempPoly; + } + return result; +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_AnyRaycastFloor2(CollisionContext* colCtx, CollisionPoly* outPoly, s32* bgId, Vec3f* pos) { + CollisionPoly* tempPoly; + f32 result = BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_NONE, &tempPoly, bgId, pos, NULL, 0x1C, 1.0f, 0); + + if (tempPoly != NULL) { + *outPoly = *tempPoly; + } + return result; +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_CameraRaycastFloor2(CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Vec3f* pos) { + return BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_CAMERA, outPoly, bgId, pos, NULL, 0x06, 1.0f, 0); +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_EntityRaycastFloor8(CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Actor* actor, + Vec3f* pos) { + return BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_ENTITY, outPoly, bgId, pos, actor, 0x02, 1.0f, 0); +} + +/** + * Public raycast toward floor + * returns yIntersect of the poly found, or BGCHECK_Y_MIN if no poly detected + */ +f32 BgCheck_EntityRaycastFloor9(CollisionContext* colCtx, CollisionPoly** outPoly, s32* bgId, Vec3f* pos) { + return BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_ENTITY, outPoly, bgId, pos, NULL, 0x06, 1.0f, 0); +} + +#ifdef NON_MATCHING +/** + * Tests if moving from `posPrev` to `posNext` will collide with a "wall" + * `radius` is used to form a sphere for collision detection purposes + * `checkHeight` is the positive height above posNext to perform certain checks + * returns true if a collision is detected, else false + * `outPoly` returns the closest poly detected, while `outBgId` returns the poly owner + */ +s32 BgCheck_CheckWallImpl(CollisionContext* colCtx, u16 xpFlags, Vec3f* posResult, Vec3f* posNext, Vec3f* posPrev, + f32 radius, CollisionPoly** outPoly, s32* outBgId, Actor* actor, f32 checkHeight, u8 argA) { + StaticLookup* lookupTbl; + f32 temp_f0; + s32 result; + CollisionPoly* poly; + // change between posPrev to posNext + f32 dx; + f32 dy; + f32 dz; + Vec3f sphCenter; + s32 dynaPolyCollision; + Vec3f posIntersect; + s32 bgId; + f32 temp_f0_2; + f32 f32temp; + f32 nx2, nz2; + Vec3f checkLineNext; + Vec3f checkLinePrev; + f32 n2XZDist; + f32 n3XZDist; + f32 nx3, nz3; + s32 bccFlags; + Vec3f posIntersect2; + s32 bgId2; + // unit normal of polygon + f32 nx; + f32 ny; + f32 nz; + + result = false; + *outBgId = BGCHECK_SCENE; + *outPoly = NULL; + lookupTbl = colCtx->lookupTbl; + *posResult = *posNext; + dx = posNext->x - posPrev->x; + dy = posNext->y - posPrev->y; + 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 ((checkHeight + dy) < 5.0f) { + //! @bug checkHeight is not applied to posPrev/posNext + result = BgCheck_CheckLineImpl(colCtx, xpFlags, COLPOLY_IGNORE_NONE, posPrev, posNext, &posIntersect, &poly, + &bgId, actor, 1.0f, BGCHECK_CHECK_ALL & ~BGCHECK_CHECK_CEILING); + if (result) { + ny = COLPOLY_GET_NORMAL(poly->normal.y); + // if poly is floor, push result underneath the floor + if (ny > 0.5f) { + posResult->x = posIntersect.x; + if (checkHeight > 1.0f) { + posResult->y = posIntersect.y - 1.0f; + } else { + posResult->y = posIntersect.y - checkHeight; + } + posResult->z = posIntersect.z; + if (actor != NULL) { + actor->bgCheckFlags |= 0x1000; + } + } + // poly is wall + else { + nx = COLPOLY_GET_NORMAL(poly->normal.x); + nz = COLPOLY_GET_NORMAL(poly->normal.z); + posResult->x = radius * nx + posIntersect.x; + posResult->y = radius * ny + posIntersect.y; + posResult->z = radius * nz + posIntersect.z; + } + *outPoly = poly; + *outBgId = bgId; + } + } else { + // if the radius is less than the distance travelled on the xz plane, also test for floor collisions + bccFlags = SQ(radius) < (SQ(dx) + SQ(dz)) + ? (BGCHECK_CHECK_ALL & ~BGCHECK_CHECK_CEILING) + : (BGCHECK_CHECK_ALL & ~BGCHECK_CHECK_FLOOR & ~BGCHECK_CHECK_CEILING); + + // perform a straight line test to see if a line at posNext.y + checkHeight from posPrev.xz to posNext.xz + // passes through any wall and possibly floor polys + checkLineNext = *posNext; + checkLineNext.y += checkHeight; + checkLinePrev = *posPrev; + checkLinePrev.y = checkLineNext.y; + result = BgCheck_CheckLineImpl(colCtx, xpFlags, COLPOLY_IGNORE_NONE, &checkLinePrev, &checkLineNext, + &posIntersect, &poly, &bgId, actor, 1.0f, bccFlags); + + if (result) { + nx2 = COLPOLY_GET_NORMAL(poly->normal.x); + nz2 = COLPOLY_GET_NORMAL(poly->normal.z); + n2XZDist = sqrtf(SQ(nx2) + SQ(nz2)); + + // if poly is not a "flat" floor or "flat" ceiling + if (!IS_ZERO(n2XZDist)) { + // normalize nx,nz and multiply each by the radius to go back to the other side of the wall + f32temp = 1.0f / n2XZDist; + temp_f0 = radius * f32temp; + posResult->x = temp_f0 * nx2 + posIntersect.x; + posResult->z = temp_f0 * nz2 + posIntersect.z; + *outPoly = poly; + *outBgId = bgId; + result = true; + if (COLPOLY_GET_NORMAL(poly->normal.y) > 0.5f) { + if (actor != NULL) { + actor->bgCheckFlags |= 0x1000; + } + } + } else { + result = false; + } + } + } + } + + sphCenter = *posResult; + dynaPolyCollision = false; + sphCenter.y += checkHeight; + // test if sphere (sphCenter, radius) collides with a dynamic wall, displacing the x/z coordinates + if (BgCheck_SphVsDynaWall(colCtx, xpFlags, &posResult->x, &posResult->z, &sphCenter, radius, outPoly, outBgId, + actor)) { + result = true; + dynaPolyCollision = true; + sphCenter = *posResult; + sphCenter.y += checkHeight; + } + // test if sphere (sphCenter, radius) collides with a static wall, displacing the x/z coordinates + if (BgCheck_PosInStaticBoundingBox(colCtx, posNext) && + // possible bug? if the sphere's radius is smaller than the distance to a subdivision boundary, some static + // polys will be missed + BgCheck_SphVsStaticWall(BgCheck_GetNearestStaticLookup(colCtx, lookupTbl, posResult), colCtx, xpFlags, + &posResult->x, &posResult->z, &sphCenter, radius, outPoly, actor)) { + *outBgId = BGCHECK_SCENE; + result = true; + } + // if a collision with a dyna poly was detected + 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); + nz3 = COLPOLY_GET_NORMAL(poly->normal.z); + n3XZDist = sqrtf(SQ(nx3) + SQ(nz3)); + + // if poly is not a "flat" floor or "flat" ceiling + if (!IS_ZERO(n3XZDist)) { + // normalize nx,nz and multiply each by the radius to go back to the other side of the wall + f32temp = 1.0f / n3XZDist; + temp_f0_2 = radius * f32temp; + posResult->x = temp_f0_2 * nx3 + posIntersect2.x; + posResult->z = temp_f0_2 * nz3 + posIntersect2.z; + *outPoly = poly; + *outBgId = bgId2; + result = true; + } + } + } + return result; +} +#else +s32 BgCheck_CheckWallImpl(CollisionContext* colCtx, u16 xpFlags, Vec3f* posResult, Vec3f* posNext, Vec3f* posPrev, + f32 radius, CollisionPoly** outPoly, s32* outBgId, Actor* actor, f32 checkHeight, u8 argA); +#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_CheckWallImpl.s") +#endif + +/** + * Public. Tests if moving from `posPrev` to `posNext` will collide with a "wall" + * `radius` is used to form a sphere for collision detection purposes + * `checkHeight` is the positive height above posNext to perform certain checks + * returns true if a collision is detected, else false + * `outPoly` returns the closest poly detected + */ +s32 BgCheck_EntitySphVsWall1(CollisionContext* colCtx, Vec3f* posResult, Vec3f* posNext, Vec3f* posPrev, f32 radius, + CollisionPoly** outPoly, f32 checkHeight) { + s32 bgId; + + return BgCheck_CheckWallImpl(colCtx, COLPOLY_IGNORE_ENTITY, posResult, posNext, posPrev, radius, outPoly, &bgId, + NULL, checkHeight, 0); +} + +/** + * Public. Tests if moving from `posPrev` to `posNext` will collide with a "wall" + * `radius` is used to form a sphere for collision detection purposes + * `checkHeight` is the positive height above posNext to perform certain checks + * returns true if a collision is detected, else false + * `outPoly` returns the closest poly detected, while `outBgId` returns the poly owner + */ +s32 BgCheck_EntitySphVsWall2(CollisionContext* colCtx, Vec3f* posResult, Vec3f* posNext, Vec3f* posPrev, f32 radius, + CollisionPoly** outPoly, s32* outBgId, f32 checkHeight) { + return BgCheck_CheckWallImpl(colCtx, COLPOLY_IGNORE_ENTITY, posResult, posNext, posPrev, radius, outPoly, outBgId, + NULL, checkHeight, 0); +} + +/** + * Public. Tests if *moving from `posPrev` to `posNext` will collide with a "wall" + * `radius` is used to form a sphere for collision detection purposes + * `checkHeight` is the positive height above posNext to perform certain checks + * `actor` is the actor performing the check, allowing it to be skipped + * returns true if a collision is detected, else false + * `outPoly` returns the closest poly detected, while `outBgId` returns the poly owner + */ +s32 BgCheck_EntitySphVsWall3(CollisionContext* colCtx, Vec3f* posResult, Vec3f* posNext, Vec3f* posPrev, f32 radius, + CollisionPoly** outPoly, s32* outBgId, Actor* actor, f32 checkHeight) { + return BgCheck_CheckWallImpl(colCtx, COLPOLY_IGNORE_ENTITY, posResult, posNext, posPrev, radius, outPoly, outBgId, + actor, checkHeight, 0); +} + +/** + * Public. Tests if moving from `posPrev` to `posNext` will collide with a "wall" + * Skips a check that occurs only when moving on the xz plane + * `radius` is used to form a sphere for collision detection purposes + * `checkHeight` is the positive height above posNext to perform certain checks + * `actor` is the actor performing the check, allowing it to be skipped + * returns true if a collision is detected, else false + * `outPoly` returns the closest poly detected, while `outBgId` returns the poly owner + */ +s32 BgCheck_EntitySphVsWall4(CollisionContext* colCtx, Vec3f* posResult, Vec3f* posNext, Vec3f* posPrev, f32 radius, + CollisionPoly** outPoly, s32* outBgId, Actor* actor, f32 checkHeight) { + return BgCheck_CheckWallImpl(colCtx, COLPOLY_IGNORE_ENTITY, posResult, posNext, posPrev, radius, outPoly, outBgId, + actor, checkHeight, 1); +} + +/** + * Tests for collision with a ceiling poly + * `checkHeight` should be a positive value + * returns true if a collision occurs, else false + * `outPoly` returns the poly collided with, while `outBgId` returns the owner of the poly + * `outY` returns the y coordinate of pos needed to not collide with `outPoly` + */ +s32 BgCheck_CheckCeilingImpl(CollisionContext* colCtx, u16 xpFlags, f32* outY, Vec3f* pos, f32 checkHeight, + CollisionPoly** outPoly, s32* outBgId, Actor* actor) { + StaticLookup* lookupTbl; + StaticLookup* lookup; + s32 result; + Vec3f posTemp; + f32 tempY; + + *outBgId = BGCHECK_SCENE; + *outY = pos->y; + lookupTbl = colCtx->lookupTbl; + if (!BgCheck_PosInStaticBoundingBox(colCtx, pos)) { + return false; + } + + lookup = BgCheck_GetNearestStaticLookup(colCtx, lookupTbl, pos); + result = BgCheck_CheckStaticCeiling(lookup, xpFlags, colCtx, outY, pos, checkHeight, outPoly, actor); + + posTemp = *pos; + posTemp.y = *outY; + tempY = *outY; + + if (BgCheck_CheckDynaCeiling(colCtx, xpFlags, &tempY, &posTemp, checkHeight, outPoly, outBgId, actor)) { + *outY = tempY; + result = true; + } + return result; +} + +/** + * Tests for collision with any ceiling poly + * `checkHeight` must be a positive value + * returns true if a collision occurs, else false + * `outY` returns the displaced y coordinate needed to not collide with the poly + */ +s32 BgCheck_AnyCheckCeiling(CollisionContext* colCtx, f32* outY, Vec3f* pos, f32 checkHeight) { + CollisionPoly* poly; + s32 bgId; + + return BgCheck_CheckCeilingImpl(colCtx, COLPOLY_IGNORE_NONE, outY, pos, checkHeight, &poly, &bgId, NULL); +} + +/** + * Tests for collision with any entity solid ceiling poly + * `checkHeight` must be a positive value + * returns true if a collision occurs, else false + * `outY` returns the displaced y coordinate needed to not collide with the poly + */ +s32 BgCheck_EntityCheckCeiling(CollisionContext* colCtx, f32* outY, Vec3f* pos, f32 checkHeight, + CollisionPoly** outPoly, s32* outBgId, Actor* actor) { + return BgCheck_CheckCeilingImpl(colCtx, COLPOLY_IGNORE_ENTITY, outY, pos, checkHeight, outPoly, outBgId, actor); +} + +#ifdef NON_MATCHING +/** + * Tests if a line from `posA` to `posB` intersects with a poly + * returns true if it does, else false + * `posB`? `posResult` returns the point of intersection + * `outPoly` returns the pointer to the intersected poly, while `outBgId` returns the entity the poly belongs to + */ +s32 BgCheck_CheckLineImpl(CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2, Vec3f* posA, Vec3f* posB, + Vec3f* posResult, CollisionPoly** outPoly, s32* outBgId, Actor* actor, f32 checkDist, + u32 bccFlags) { + StaticLookup* lookupTbl; + StaticLookup* iLookup; + s32 subdivMin[3]; + s32 subdivMax[3]; + s32 i; + s32 result; + Vec3f posBTemp; + StaticLineTest checkLine; + Vec3f sectorMin; + Vec3f sectorMax; + s32 k; + StaticLookup* lookup; + s32 j; + StaticLookup* jLookup; + s32 temp_lo; + s32 pad[2]; + + lookupTbl = colCtx->lookupTbl; + posBTemp = *posB; + + *outBgId = BGCHECK_SCENE; + + BgCheck_ResetPolyCheckTbl(&colCtx->polyNodes, colCtx->colHeader->numPolygons); + BgCheck_GetStaticLookupIndicesFromPos(colCtx, posA, (Vec3i*)&subdivMin); + BgCheck_GetStaticLookupIndicesFromPos(colCtx, &posBTemp, (Vec3i*)&subdivMax); + *posResult = *posB; + checkLine.outDistSq = 1.0e38f; + *outPoly = NULL; + + checkLine.colCtx = colCtx; + checkLine.xpFlags2 = xpFlags2; + checkLine.posA = posA; + checkLine.posB = &posBTemp; + checkLine.outPoly = outPoly; + checkLine.xpFlags1 = xpFlags1; + checkLine.outPos = posResult; + checkLine.checkDist = checkDist; + checkLine.bccFlags = bccFlags; + checkLine.actor = actor; + result = false; + + 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]; + subdivMax[i] = subdivMin[i]; + subdivMin[i] = j; + } + } + temp_lo = colCtx->subdivAmount.x * colCtx->subdivAmount.y; + iLookup = lookupTbl + subdivMin[2] * temp_lo; + sectorMin.z = subdivMin[2] * colCtx->subdivLength.z + colCtx->minBounds.z; + sectorMax.z = colCtx->subdivLength.z + sectorMin.z; + + for (i = subdivMin[2]; i < subdivMax[2] + 1; i++) { + jLookup = iLookup + subdivMin[1] * colCtx->subdivAmount.x; + sectorMin.y = subdivMin[1] * colCtx->subdivLength.y + colCtx->minBounds.y; + sectorMax.y = colCtx->subdivLength.y + sectorMin.y; + + for (j = subdivMin[1]; j < subdivMax[1] + 1; j++) { + lookup = jLookup + subdivMin[0]; + sectorMin.x = subdivMin[0] * colCtx->subdivLength.x + colCtx->minBounds.x; + sectorMax.x = colCtx->subdivLength.x + sectorMin.x; + + for (k = subdivMin[0]; k < subdivMax[0] + 1; k++) { + if (Math3D_LineVsCube(§orMin, §orMax, posA, &posBTemp)) { + checkLine.lookup = lookup; + + if (BgCheck_CheckLineInSubdivision(&checkLine)) { + result = true; + } + } + lookup++; + sectorMin.x += colCtx->subdivLength.x; + sectorMax.x += colCtx->subdivLength.x; + } + jLookup += colCtx->subdivAmount.x; + sectorMin.y += colCtx->subdivLength.y; + sectorMax.y += colCtx->subdivLength.y; + } + iLookup += temp_lo; + sectorMin.z += colCtx->subdivLength.z; + sectorMax.z += colCtx->subdivLength.z; + } + } else if (BgCheck_PosInStaticBoundingBox(colCtx, posA) == false) { + return false; + } else { + checkLine.lookup = BgCheck_GetNearestStaticLookup(colCtx, lookupTbl, posA); + result = BgCheck_CheckLineInSubdivision(&checkLine); + if (result) { + checkLine.outDistSq = Math3D_Vec3fDistSq(posResult, posA); + } + } + if ((bccFlags & BGCHECK_CHECK_DYNA) && + BgCheck_CheckLineAgainstDyna(colCtx, xpFlags1, posA, &posBTemp, posResult, outPoly, &checkLine.outDistSq, + outBgId, actor, checkDist, bccFlags)) { + result = true; + } + return result; +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_CheckLineImpl.s") +#endif + +/** + * Get bccFlags + */ +u32 BgCheck_GetBccFlags(s32 checkWall, s32 checkFloor, s32 checkCeil, s32 checkOneFace, s32 checkDyna) { + u32 result = 0; + + if (checkWall) { + result = BGCHECK_CHECK_WALL; + } + if (checkFloor) { + result |= BGCHECK_CHECK_FLOOR; + } + if (checkCeil) { + result |= BGCHECK_CHECK_CEILING; + } + if (checkOneFace) { + result |= BGCHECK_CHECK_ONE_FACE; + } + if (checkDyna) { + result |= BGCHECK_CHECK_DYNA; + } + return result; +} + +/** + * Public. Tests if a line from `posA` to `posB` intersects with a poly + * returns true if it does, else false + */ +s32 BgCheck_CameraLineTest1(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, + CollisionPoly** outPoly, s32 checkWall, s32 checkFloor, s32 checkCeil, s32 checkOneFace, + s32* bgId) { + return BgCheck_CheckLineImpl(colCtx, COLPOLY_IGNORE_CAMERA, COLPOLY_IGNORE_NONE, posA, posB, posResult, outPoly, + bgId, NULL, 1.0f, + BgCheck_GetBccFlags(checkWall, checkFloor, checkCeil, checkOneFace, true)); +} + +/** + * Public. Tests if a line from `posA` to `posB` intersects with a poly + * returns true if it does, else false + */ +s32 BgCheck_CameraLineTest2(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, + CollisionPoly** outPoly, s32 checkWall, s32 checkFloor, s32 checkCeil, s32 checkOneFace, + s32* bgId) { + return BgCheck_CheckLineImpl(colCtx, COLPOLY_IGNORE_NONE, COLPOLY_IGNORE_CAMERA, posA, posB, posResult, outPoly, + bgId, NULL, 1.0f, + BgCheck_GetBccFlags(checkWall, checkFloor, checkCeil, checkOneFace, true)); +} + +/** + * Public. Tests if a line from `posA` to `posB` intersects with a poly + * returns true if it does, else false + */ +s32 BgCheck_EntityLineTest1(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, + CollisionPoly** outPoly, s32 checkWall, s32 checkFloor, s32 checkCeil, s32 checkOneFace, + s32* bgId) { + return BgCheck_CheckLineImpl(colCtx, COLPOLY_IGNORE_ENTITY, COLPOLY_IGNORE_NONE, posA, posB, posResult, outPoly, + bgId, NULL, 1.0f, + BgCheck_GetBccFlags(checkWall, checkFloor, checkCeil, checkOneFace, true)); +} + +/** + * Public. Tests if a line from `posA` to `posB` intersects with a poly + * returns true if it does, else false + */ +s32 BgCheck_EntityLineTest2(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, + CollisionPoly** outPoly, s32 checkWall, s32 checkFloor, s32 checkCeil, s32 checkOneFace, + s32* bgId, Actor* actor) { + return BgCheck_CheckLineImpl(colCtx, COLPOLY_IGNORE_ENTITY, COLPOLY_IGNORE_NONE, posA, posB, posResult, outPoly, + bgId, actor, 1.0f, + BgCheck_GetBccFlags(checkWall, checkFloor, checkCeil, checkOneFace, true)); +} + +/** + * Public. Tests if a line from `posA` to `posB` intersects with a poly + * returns true if it does, else false + */ +s32 BgCheck_EntityLineTest3(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, + CollisionPoly** outPoly, s32 checkWall, s32 checkFloor, s32 checkCeil, s32 checkOneFace, + s32* bgId, Actor* actor, f32 checkDist) { + return BgCheck_CheckLineImpl(colCtx, COLPOLY_IGNORE_ENTITY, COLPOLY_IGNORE_NONE, posA, posB, posResult, outPoly, + bgId, actor, checkDist, + BgCheck_GetBccFlags(checkWall, checkFloor, checkCeil, checkOneFace, true)); +} + +/** + * Public. Tests if a line from `posA` to `posB` intersects with a poly + * returns true if it does, else false + */ +s32 BgCheck_ProjectileLineTest(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, + CollisionPoly** outPoly, s32 checkWall, s32 checkFloor, s32 checkCeil, s32 checkOneFace, + s32* bgId) { + return BgCheck_CheckLineImpl(colCtx, COLPOLY_IGNORE_PROJECTILES, COLPOLY_IGNORE_NONE, posA, posB, posResult, + outPoly, bgId, NULL, 1.0f, + BgCheck_GetBccFlags(checkWall, checkFloor, checkCeil, checkOneFace, true)); +} + +/** + * Public. Tests if a line from `posA` to `posB` intersects with a poly + * returns true if it does, else false + */ +s32 BgCheck_AnyLineTest1(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, + s32 checkOneFace) { + return BgCheck_AnyLineTest2(colCtx, posA, posB, posResult, outPoly, true, true, true, checkOneFace); +} + +/** + * Public. Tests if a line from `posA` to `posB` intersects with a poly + * returns true if it does, else false + */ +s32 BgCheck_AnyLineTest2(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, + s32 checkWall, s32 checkFloor, s32 checkCeil, s32 checkOneFace) { + s32 bgId; + + return BgCheck_CheckLineImpl(colCtx, COLPOLY_IGNORE_NONE, COLPOLY_IGNORE_NONE, posA, posB, posResult, outPoly, + &bgId, NULL, 1.0f, + BgCheck_GetBccFlags(checkWall, checkFloor, checkCeil, checkOneFace, true)); +} + +/** + * Public. Tests if a line from `posA` to `posB` intersects with a poly + * returns true if it does, else false + */ +s32 BgCheck_AnyLineTest3(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, + s32 checkWall, s32 checkFloor, s32 checkCeil, s32 checkOneFace, s32* bgId) { + return BgCheck_CheckLineImpl(colCtx, COLPOLY_IGNORE_NONE, COLPOLY_IGNORE_NONE, posA, posB, posResult, outPoly, bgId, + NULL, 1.0f, BgCheck_GetBccFlags(checkWall, checkFloor, checkCeil, checkOneFace, true)); +} + +/** + * Get first poly intersecting sphere `center` `radius` + * ignores `actor` dyna poly + * returns true if any poly intersects the sphere, else false + * `outPoly` returns the pointer of the first poly found that intersects + * `outBgId` returns the bgId of the entity that owns `outPoly` + */ +s32 BgCheck_SphVsFirstPolyImpl(CollisionContext* colCtx, u16 xpFlags, CollisionPoly** outPoly, s32* outBgId, + Vec3f* center, f32 radius, Actor* actor, u16 bciFlags) { + StaticLookup* lookup; + + *outBgId = BGCHECK_SCENE; + lookup = BgCheck_GetStaticLookup(colCtx, colCtx->lookupTbl, center); + if (lookup == NULL) { + return false; + } else if (BgCheck_SphVsFirstStaticPoly(lookup, xpFlags, colCtx, center, radius, outPoly, bciFlags, actor) || + BgCheck_SphVsFirstDynaPoly(colCtx, xpFlags, outPoly, outBgId, center, radius, actor, bciFlags)) { + return true; + } + return false; +} + +/** + * Public get first poly intersecting sphere `center` `radius` + */ +s32 BgCheck_SphVsFirstPoly(CollisionContext* colCtx, Vec3f* center, f32 radius) { + CollisionPoly* poly; + s32 bgId; + + return BgCheck_SphVsFirstPolyImpl(colCtx, COLPOLY_IGNORE_NONE, &poly, &bgId, center, radius, NULL, + BGCHECK_IGNORE_NONE); +} + +/** + * Public get first wall poly intersecting sphere `center` `radius` + */ +s32 BgCheck_SphVsFirstWall(CollisionContext* colCtx, Vec3f* center, f32 radius) { + CollisionPoly* poly; + s32 bgId; + + return BgCheck_SphVsFirstPolyImpl(colCtx, COLPOLY_IGNORE_NONE, &poly, &bgId, center, radius, NULL, + BGCHECK_IGNORE_FLOOR | BGCHECK_IGNORE_CEILING); +} + +/** + * Init SSNodeList + */ +void SSNodeList_Init(SSNodeList* this) { + this->max = 0; + this->count = 0; + this->tbl = NULL; + this->polyCheckTbl = NULL; +} + +/** + * Allocate SSNodeList + * tblMax is the number of SSNode records to allocate + * numPolys is the number of polygons defined within the CollisionHeader + */ +void SSNodeList_Alloc(GlobalContext* globalCtx, SSNodeList* this, s32 tblMax, s32 numPolys) { + this->max = tblMax; + this->count = 0; + this->tbl = THA_AllocEndAlign(&globalCtx->state.heap, tblMax * sizeof(SSNode), -2); + this->polyCheckTbl = THA_AllocEndAlign16(&globalCtx->state.heap, numPolys * sizeof(u8)); + + if (this->polyCheckTbl == NULL) { + sprintf(D_801ED950, "this->polygon_check == NULL(game_alloc() MemoryAllocationError.)\n"); + sprintf(D_801ED9A0, "short_slist_node_size = %d/polygon_num = %d\n", tblMax, numPolys); + Fault_AddHungupAndCrashImpl(D_801ED950, D_801ED9A0); + } +} + +/** + * Get next SSNodeList SSNode + */ +SSNode* SSNodeList_GetNextNode(SSNodeList* this) { + SSNode* result = &this->tbl[this->count]; + + this->count++; + if (!(this->count < this->max)) { + return NULL; + } + return result; +} + +/** + * Get next SSNodeList SSNode index + */ +u16 SSNodeList_GetNextNodeIdx(SSNodeList* this) { + u16 new_index = this->count++; + + return new_index; +} + +/** + * Initialize ScaleRotPos + */ +void ScaleRotPos_Init(ScaleRotPos* srp) { + srp->scale.x = srp->scale.y = srp->scale.z = 1; + srp->rot.x = 0; + srp->rot.y = 0; + srp->rot.z = 0; + srp->pos.x = srp->pos.y = srp->pos.z = 0; +} + +/** + * Set ScaleRotPos + */ +void ScaleRotPos_SetValue(ScaleRotPos* srp, Vec3f* scale, Vec3s* rot, Vec3f* pos) { + srp->scale = *scale; + srp->rot = *rot; + srp->pos = *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) { + return false; + } + return true; +} + +/** + * Reset DynaLookup lists + */ +void DynaLookup_ResetLists(DynaLookup* dynaLookup) { + SSList_SetNull(&dynaLookup->ceiling); + SSList_SetNull(&dynaLookup->wall); + SSList_SetNull(&dynaLookup->floor); +} + +/** + * Reset DynaLookup + */ +void DynaLookup_Reset(DynaLookup* dynaLookup) { + dynaLookup->polyStartIndex = 0; + DynaLookup_ResetLists(dynaLookup); +} + +/** + * Reset vtxStartIndex + */ +void DynaLookup_ResetVtxStartIndex(u16* vtxStartIndex) { + *vtxStartIndex = 0; +} + +/** + * Reset waterBoxStartIndex + */ +void DynaLookup_ResetWaterBoxStartIndex(u16* waterBoxStartIndex) { + *waterBoxStartIndex = 0; +} + +/** + * Initialize BgActor + */ +void BgActor_Init(GlobalContext* globalCtx, BgActor* bgActor) { + bgActor->actor = NULL; + bgActor->colHeader = NULL; + ScaleRotPos_Init(&bgActor->prevTransform); + ScaleRotPos_Init(&bgActor->curTransform); + DynaLookup_Reset(&bgActor->dynaLookup); + DynaLookup_ResetVtxStartIndex(&bgActor->vtxStartIndex); + DynaLookup_ResetWaterBoxStartIndex(&bgActor->waterboxesStartIndex); + bgActor->boundingSphere.center.x = bgActor->boundingSphere.center.y = bgActor->boundingSphere.center.z = 0; + bgActor->boundingSphere.radius = 0; +} + +/** + * setActor internal + */ +void BgActor_SetActor(BgActor* bgActor, Actor* actor, CollisionHeader* colHeader) { + bgActor->actor = actor; + bgActor->colHeader = colHeader; + bgActor->prevTransform.scale = actor->scale; + bgActor->prevTransform.rot = actor->shape.rot; + bgActor->prevTransform.rot.x--; + bgActor->prevTransform.pos = actor->world.pos; + bgActor->curTransform.scale = actor->scale; + bgActor->curTransform.rot = actor->shape.rot; + bgActor->curTransform.pos = actor->world.pos; +} + +/** + * Test if the BgActor transform is the same + */ +s32 BgActor_IsTransformUnchanged(BgActor* bgActor) { + return ScaleRotPos_IsEqual(&bgActor->prevTransform, &bgActor->curTransform); +} + +/** + * NULL polyList + */ +void DynaPoly_NullPolyList(CollisionPoly** polyList) { + *polyList = NULL; +} + +/** + * Allocate dyna.polyList + */ +void DynaPoly_AllocPolyList(GlobalContext* globalCtx, CollisionPoly** polyList, s32 numPolys) { + *polyList = THA_AllocEndAlign(&globalCtx->state.heap, numPolys * sizeof(CollisionPoly), -2); +} + +/** + * NULL vtxList + */ +void DynaPoly_NullVtxList(Vec3s** vtxList) { + *vtxList = NULL; +} + +/** + * Allocate dyna.vtxList + */ +void DynaPoly_AllocVtxList(GlobalContext* globalCtx, Vec3s** vtxList, s32 numVtx) { + *vtxList = THA_AllocEndAlign(&globalCtx->state.heap, numVtx * sizeof(Vec3s), -2); +} + +/** + * Init dyna.waterBoxList + */ +void DynaPoly_InitWaterBoxList(DynaWaterBoxList* waterBoxList) { + waterBoxList->unk0 = 0; + waterBoxList->boxes = NULL; +} + +/** + * Allocate dyna.waterBoxList + */ +void DynaPoly_AllocWaterBoxList(GlobalContext* globalCtx, DynaWaterBoxList* waterBoxList, s32 numWaterBoxes) { + waterBoxList->boxes = THA_AllocEndAlign(&globalCtx->state.heap, numWaterBoxes * sizeof(WaterBox), -2); +} + +/** + * Update BgActor's prevTransform + */ +void DynaPoly_SetBgActorPrevTransform(GlobalContext* globalCtx, BgActor* bgActor) { + bgActor->prevTransform = bgActor->curTransform; +} + +/** + * Is BgActor Id + */ +s32 DynaPoly_IsBgIdBgActor(s32 bgId) { + if (bgId < 0 || bgId >= BG_ACTOR_MAX) { + return false; + } + return true; +} + +/** + * Init DynaCollisionContext + */ +void DynaPoly_Init(GlobalContext* globalCtx, DynaCollisionContext* dyna) { + dyna->bitFlag = DYNAPOLY_INVALIDATE_LOOKUP; + DynaPoly_NullPolyList(&dyna->polyList); + DynaPoly_NullVtxList(&dyna->vtxList); + DynaPoly_InitWaterBoxList(&dyna->waterBoxList); + DynaSSNodeList_Init(globalCtx, &dyna->polyNodes); +} + +/** + * Set DynaCollisionContext + */ +void DynaPoly_Alloc(GlobalContext* globalCtx, DynaCollisionContext* dyna) { + s32 i; + + for (i = 0; i < BG_ACTOR_MAX; i++) { + BgActor_Init(globalCtx, &dyna->bgActors[i]); + dyna->bgActorFlags[i] = 0; + } + DynaPoly_NullPolyList(&dyna->polyList); + DynaPoly_AllocPolyList(globalCtx, &dyna->polyList, dyna->polyListMax); + + DynaPoly_NullVtxList(&dyna->vtxList); + DynaPoly_AllocVtxList(globalCtx, &dyna->vtxList, dyna->vtxListMax); + + DynaPoly_InitWaterBoxList(&dyna->waterBoxList); + DynaPoly_AllocWaterBoxList(globalCtx, &dyna->waterBoxList, DYNA_WATERBOX_MAX); + + DynaSSNodeList_Init(globalCtx, &dyna->polyNodes); + DynaSSNodeList_Alloc(globalCtx, &dyna->polyNodes, dyna->polyNodesMax); +} + +/** + * Set BgActor + * original name: DynaPolyInfo_setActor + */ +s32 DynaPoly_SetBgActor(GlobalContext* globalCtx, DynaCollisionContext* dyna, Actor* actor, + CollisionHeader* colHeader) { + s32 bgId; + s32 foundSlot = false; + + for (bgId = 0; bgId < BG_ACTOR_MAX; bgId++) { + if (!(dyna->bgActorFlags[bgId] & 1)) { + dyna->bgActorFlags[bgId] |= 1; + foundSlot = true; + break; + } + } + + if (foundSlot == false) { + return BG_ACTOR_MAX; + } + + BgActor_SetActor(&dyna->bgActors[bgId], actor, colHeader); + dyna->bitFlag |= DYNAPOLY_INVALIDATE_LOOKUP; + + dyna->bgActorFlags[bgId] &= ~2; + return bgId; +} + +/** + * Gets the actor assigned to `bgId` + */ +DynaPolyActor* DynaPoly_GetActor(CollisionContext* colCtx, s32 bgId) { + if (!DynaPoly_IsBgIdBgActor(bgId) || !(colCtx->dyna.bgActorFlags[bgId] & 1) || + colCtx->dyna.bgActorFlags[bgId] & 2) { + return NULL; + } + return (DynaPolyActor*)colCtx->dyna.bgActors[bgId].actor; +} + +void func_800C62BC(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId) { + if (DynaPoly_IsBgIdBgActor(bgId)) { + dyna->bgActorFlags[bgId] |= 4; + dyna->bitFlag |= DYNAPOLY_INVALIDATE_LOOKUP; + } +} + +void func_800C6314(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId) { + if (DynaPoly_IsBgIdBgActor(bgId)) { + dyna->bgActorFlags[bgId] &= ~4; + dyna->bitFlag |= DYNAPOLY_INVALIDATE_LOOKUP; + } +} + +void func_800C636C(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId) { + if (DynaPoly_IsBgIdBgActor(bgId)) { + dyna->bgActorFlags[bgId] |= 8; + dyna->bitFlag |= DYNAPOLY_INVALIDATE_LOOKUP; + } +} + +void func_800C63C4(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId) { + if (DynaPoly_IsBgIdBgActor(bgId)) { + dyna->bgActorFlags[bgId] &= ~8; + dyna->bitFlag |= DYNAPOLY_INVALIDATE_LOOKUP; + } +} + +void func_800C641C(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId) { + if (DynaPoly_IsBgIdBgActor(bgId)) { + dyna->bgActorFlags[bgId] |= 0x20; + dyna->bitFlag |= DYNAPOLY_INVALIDATE_LOOKUP; + } +} + +void func_800C6474(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId) { + if (DynaPoly_IsBgIdBgActor(bgId)) { + dyna->bgActorFlags[bgId] &= ~0x20; + dyna->bitFlag |= DYNAPOLY_INVALIDATE_LOOKUP; + } +} + +/** + * original name: DynaPolyInfo_delReserve + */ +void DynaPoly_DeleteBgActor(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId) { + DynaPolyActor* actor; + + if (DynaPoly_IsBgIdBgActor(bgId) == false) { + return; + } + actor = DynaPoly_GetActor(&globalCtx->colCtx, bgId); + if (actor != NULL) { + + actor->bgId = BGACTOR_NEG_ONE; + dyna->bgActors[bgId].actor = NULL; + dyna->bgActorFlags[bgId] |= 2; + } +} + +void func_800C6554(GlobalContext* globalCtx, DynaCollisionContext* dyna) { + dyna->bitFlag |= DYNAPOLY_INVALIDATE_LOOKUP; +} + +void BgCheck_CalcWaterboxDimensions(Vec3f* minPos, Vec3f* maxXPos, Vec3f* maxZPos, Vec3s* minPosOut, s16* xLength, + s16* zLength) { + f32 temp; + + minPosOut->x = minPos->x; + minPosOut->y = minPos->y; + minPosOut->z = minPos->z; + + if (maxXPos->x < minPosOut->x) { + minPosOut->x = maxXPos->x; + } + if (maxXPos->y < minPosOut->y) { + minPosOut->y = maxXPos->y; + } + if (maxXPos->z < minPosOut->z) { + minPosOut->z = maxXPos->z; + } + + if (maxZPos->x < minPosOut->x) { + minPosOut->x = maxZPos->x; + } + if (maxZPos->y < minPosOut->y) { + minPosOut->y = maxZPos->y; + } + if (maxZPos->z < minPosOut->z) { + minPosOut->z = maxZPos->z; + } + + *xLength = minPos->x - minPosOut->x; + temp = maxXPos->x - minPosOut->x; + + if (*xLength < temp) { + *xLength = temp; + } + temp = maxZPos->x - minPosOut->x; + if (*xLength < temp) { + *xLength = temp; + } + *zLength = minPos->z - minPosOut->z; + + temp = maxXPos->z - minPosOut->z; + if (*zLength < temp) { + *zLength = temp; + } + temp = maxZPos->z - minPosOut->z; + if (*zLength < temp) { + *zLength = temp; + } +} + +#ifdef NON_MATCHING +/** + * original name: DynaPolyInfo_expandSRT + */ +void DynaPoly_ExpandSRT(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId, s32* vtxStartIndex, + s32* polyStartIndex, s32* waterBoxStartIndex) { + Actor* actor; + s32 pad; + s32 pad2; + f32 numVtxInverse; + s32 i; + Vec3f pos; // sp170 + Sphere16* sphere; + Vec3s* dVtxList; + Vec3s* point; + Vec3f newCenterPoint; // sp158 + + f32 newRadiusSq; + CollisionHeader* pbgdata; + Vec3f newVtx; // sp144 + Vec3f vtxA; // sp138 + Vec3f vtxB; // sp12C + Vec3f vtxC; // sp120 + Vec3f newNormal; + s32 wi; + Vec3f spB8; // waterbox ? + Vec3f spAC; + Vec3f spA0; // waterbox ? + Vec3f sp94; + Vec3f sp88; // waterbox ? + Vec3f sp7C; + WaterBox* waterBox; + + pbgdata = dyna->bgActors[bgId].colHeader; + sphere = &dyna->bgActors[bgId].boundingSphere; + actor = dyna->bgActors[bgId].actor; + dyna->bgActors[bgId].dynaLookup.polyStartIndex = *polyStartIndex; + dyna->bgActors[bgId].vtxStartIndex = *vtxStartIndex; + dyna->bgActors[bgId].waterboxesStartIndex = *waterBoxStartIndex; + pos = actor->world.pos; + pos.y += actor->shape.yOffset * actor->scale.y; + + ScaleRotPos_SetValue(&dyna->bgActors[bgId].curTransform, &actor->scale, &actor->shape.rot, &pos); + + if (dyna->bgActorFlags[bgId] & 4) { + return; + } + + if (!(DYNA_WATERBOX_MAX >= *waterBoxStartIndex + pbgdata->numWaterBoxes)) { + 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)) { + 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)) { + 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); + } + + if (!(dyna->bitFlag & DYNAPOLY_INVALIDATE_LOOKUP) && BgActor_IsTransformUnchanged(&dyna->bgActors[bgId])) { + s32 pi; + + for (pi = *polyStartIndex; pi < *polyStartIndex + pbgdata->numPolygons; pi++) { + CollisionPoly* poly = &dyna->polyList[pi]; + s16 normalY = poly->normal.y; + + if (normalY > COLPOLY_SNORMAL(0.5f)) { + if (!(dyna->bgActorFlags[bgId] & 0x20)) { + s16 polyIndex = pi; + + DynaSSNodeList_SetSSListHead(&dyna->polyNodes, &dyna->bgActors[bgId].dynaLookup.floor, &polyIndex); + } + } else if (normalY < COLPOLY_SNORMAL(-0.8f)) { + if (!(dyna->bgActorFlags[bgId] & 8)) { + s16 polyIndex = pi; + + DynaSSNodeList_SetSSListHead(&dyna->polyNodes, &dyna->bgActors[bgId].dynaLookup.ceiling, + &polyIndex); + } + } else { + s16 polyIndex = pi; + + DynaSSNodeList_SetSSListHead(&dyna->polyNodes, &dyna->bgActors[bgId].dynaLookup.wall, &polyIndex); + } + } + + *polyStartIndex += pbgdata->numPolygons; + *vtxStartIndex += pbgdata->numVertices; + *waterBoxStartIndex += pbgdata->numWaterBoxes; + } else { + SkinMatrix_SetScaleRotateYRPTranslate( + &D_801EDA40, dyna->bgActors[bgId].curTransform.scale.x, dyna->bgActors[bgId].curTransform.scale.y, + dyna->bgActors[bgId].curTransform.scale.z, dyna->bgActors[bgId].curTransform.rot.x, + dyna->bgActors[bgId].curTransform.rot.y, dyna->bgActors[bgId].curTransform.rot.z, + 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) { + numVtxInverse = 1.0f / pbgdata->numVertices; + newCenterPoint.x = newCenterPoint.y = newCenterPoint.z = 0.0f; + for (i = 0; i < pbgdata->numVertices; i++) { + Vec3f vtx; // spF4 + Vec3f vtxT; // spE8 Vtx after mtx transform + + Math_Vec3s_ToVec3f(&vtx, &pbgdata->vtxList[i]); + SkinMatrix_Vec3fMtxFMultXYZ(&D_801EDA40, &vtx, &vtxT); + BgCheck_Vec3fToVec3s(&dyna->vtxList[*vtxStartIndex + i], &vtxT); + + if (i == 0) { + dyna->bgActors[bgId].minY = dyna->bgActors[bgId].maxY = vtxT.y; + } else if (vtxT.y < dyna->bgActors[bgId].minY) { + dyna->bgActors[bgId].minY = vtxT.y; + } else if (dyna->bgActors[bgId].maxY < vtxT.y) { + dyna->bgActors[bgId].maxY = vtxT.y; + } + newCenterPoint.x += vtxT.x; + newCenterPoint.y += vtxT.y; + newCenterPoint.z += vtxT.z; + } + + newCenterPoint.x *= numVtxInverse; + newCenterPoint.y *= numVtxInverse; + newCenterPoint.z *= numVtxInverse; + sphere->center.x = newCenterPoint.x; + sphere->center.y = newCenterPoint.y; + sphere->center.z = newCenterPoint.z; + newRadiusSq = -100.0f; + + for (i = 0; i < pbgdata->numVertices; i++) { + f32 radiusSq; + s32 idx = *vtxStartIndex + i; + + newVtx.x = dyna->vtxList[idx].x; + newVtx.y = dyna->vtxList[idx].y; + newVtx.z = dyna->vtxList[idx].z; + radiusSq = Math3D_Vec3fDistSq(&newVtx, &newCenterPoint); + if (newRadiusSq < radiusSq) { + newRadiusSq = radiusSq; + } + } + + sphere->radius = sqrtf(newRadiusSq) * 1.1f; + + for (i = 0; i < pbgdata->numPolygons; i++) { + CollisionPoly* newPoly = &dyna->polyList[*polyStartIndex + i]; + f32 newNormMagnitude; + u32 vIA; + u32 vIB; + u32 vIC; + + *newPoly = pbgdata->polyList[i]; + + vIA = (COLPOLY_VTX_INDEX(newPoly->flags_vIA) + *vtxStartIndex); + vIB = (COLPOLY_VTX_INDEX(newPoly->flags_vIB) + *vtxStartIndex); + vIC = newPoly->vIC + *vtxStartIndex; + + newPoly->flags_vIA = vIA | ((*newPoly).flags_vIA & 0xE000); + newPoly->flags_vIB = vIB | ((*newPoly).flags_vIB & 0xE000); + newPoly->vIC = vIC; + dVtxList = dyna->vtxList; + vtxA.x = dVtxList[vIA].x; + vtxA.y = dVtxList[vIA].y; + vtxA.z = dVtxList[vIA].z; + vtxB.x = dVtxList[vIB].x; + vtxB.y = dVtxList[vIB].y; + vtxB.z = dVtxList[vIB].z; + vtxC.x = dVtxList[vIC].x; + vtxC.y = dVtxList[vIC].y; + vtxC.z = dVtxList[vIC].z; + Math3D_SurfaceNorm(&vtxA, &vtxB, &vtxC, &newNormal); + newNormMagnitude = Math3D_Vec3fMagnitude(&newNormal); + + if (!IS_ZERO(newNormMagnitude)) { + newNormal.x *= (1.0f / newNormMagnitude); + newNormal.y *= (1.0f / newNormMagnitude); + newNormal.z *= (1.0f / newNormMagnitude); + newPoly->normal.x = COLPOLY_SNORMAL(newNormal.x); + newPoly->normal.y = COLPOLY_SNORMAL(newNormal.y); + newPoly->normal.z = COLPOLY_SNORMAL(newNormal.z); + } + + newPoly->dist = -DOTXYZ(newNormal, dVtxList[vIA]); + if (newNormal.y > 0.5f) { + s16 polyId = *polyStartIndex + i; + + DynaSSNodeList_SetSSListHead(&dyna->polyNodes, &dyna->bgActors[bgId].dynaLookup.floor, &polyId); + } else if (newNormal.y < -0.8f) { + s16 polyId = *polyStartIndex + i; + + DynaSSNodeList_SetSSListHead(&dyna->polyNodes, &dyna->bgActors[bgId].dynaLookup.ceiling, &polyId); + } else { + s16 polyId = *polyStartIndex + i; + + DynaSSNodeList_SetSSListHead(&dyna->polyNodes, &dyna->bgActors[bgId].dynaLookup.wall, &polyId); + } + } + } + + 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; + } +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/DynaPoly_ExpandSRT.s") +#endif + +void BgCheck_ResetFlagsIfLoadedActor(GlobalContext* globalCtx, DynaCollisionContext* dyna, Actor* actor) { + DynaPolyActor* dynaActor; + s32 i; + + for (i = 0; i < BG_ACTOR_MAX; i++) { + if ((dyna->bgActorFlags[i] & 1)) { + dynaActor = DynaPoly_GetActor(&globalCtx->colCtx, i); + if (dynaActor != NULL && &dynaActor->actor == actor) { + DynaPolyActor_ResetState((DynaPolyActor*)actor); + return; + } + } + } +} + +/** + * original name: DynaPolyInfo_setup + */ +void DynaPoly_Setup(GlobalContext* globalCtx, DynaCollisionContext* dyna) { + DynaPolyActor* actor; + s32 vtxStartIndex; + s32 polyStartIndex; + s32 waterBoxStartIndex; + s32 i; + + DynaSSNodeList_ResetCount(&dyna->polyNodes); + + for (i = 0; i < BG_ACTOR_MAX; i++) { + DynaLookup_ResetLists(&dyna->bgActors[i].dynaLookup); + } + + for (i = 0; i < BG_ACTOR_MAX; i++) { + if (dyna->bgActorFlags[i] & 2) { + // Initialize BgActor + dyna->bgActorFlags[i] = 0; + BgActor_Init(globalCtx, &dyna->bgActors[i]); + dyna->bitFlag |= DYNAPOLY_INVALIDATE_LOOKUP; + } + if (dyna->bgActors[i].actor != NULL && dyna->bgActors[i].actor->update == NULL) { + // Delete BgActor + actor = DynaPoly_GetActor(&globalCtx->colCtx, i); + if (actor == NULL) { + return; + } + actor->bgId = BGACTOR_NEG_ONE; + dyna->bgActorFlags[i] = 0; + + BgActor_Init(globalCtx, &dyna->bgActors[i]); + dyna->bitFlag |= DYNAPOLY_INVALIDATE_LOOKUP; + } + } + vtxStartIndex = 0; + polyStartIndex = 0; + waterBoxStartIndex = 0; + for (i = 0; i < BG_ACTOR_MAX; i++) { + if ((dyna->bgActorFlags[i] & 1) && !(dyna->bgActorFlags[i] & 2)) { + DynaPoly_ExpandSRT(globalCtx, dyna, i, &vtxStartIndex, &polyStartIndex, &waterBoxStartIndex); + } + } + dyna->bitFlag &= ~DYNAPOLY_INVALIDATE_LOOKUP; +} + +/** + * Compute the number of dynamic resources in use? + */ +void func_800C756C(DynaCollisionContext* dyna, s32* numPolygons, s32* numVertices, s32* numWaterBoxes) { + s32 i; + CollisionHeader* colHeader; + + *numPolygons = 0; + *numVertices = 0; + *numWaterBoxes = 0; + + for (i = 0; i < BG_ACTOR_MAX; i++) { + if ((dyna->bgActorFlags[i] & 1) && !(dyna->bgActorFlags[i] & 2) && !(dyna->bgActorFlags[i] & 4)) { + colHeader = dyna->bgActors[i].colHeader; + *numPolygons += colHeader->numPolygons; + *numVertices += colHeader->numVertices; + *numWaterBoxes += colHeader->numWaterBoxes; + } + } +} + +/** + * Update all BgActor's previous ScaleRotPos + */ +void DynaPoly_UpdateBgActorTransforms(GlobalContext* globalCtx, DynaCollisionContext* dyna) { + s32 i; + + for (i = 0; i < BG_ACTOR_MAX; i++) { + if (dyna->bgActorFlags[i] & 1) { + DynaPoly_SetBgActorPrevTransform(globalCtx, &dyna->bgActors[i]); + } + } +} + +/** + * Perform dyna poly raycast toward floor on a list of floor, wall, or ceiling polys + * `listType` specifies the poly list type (e.g. DYNA_RAYCAST_FLOORS) + */ +f32 BgCheck_RaycastFloorDynaList(DynaRaycast* dynaRaycast, u32 listType) { + CollisionPoly* polyList; + SSNode* curNode; + f32 result; + f32 yIntersect; + s16 id; + + result = dynaRaycast->yIntersect; + if (dynaRaycast->ssList->head == SS_NULL) { + return result; + } + polyList = dynaRaycast->dyna->polyList; + curNode = &dynaRaycast->dyna->polyNodes.tbl[dynaRaycast->ssList->head]; + + while (true) { + 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->unk_24 & 0x20) && func_800C9B68(dynaRaycast->colCtx, &polyList[id], dynaRaycast->unk1C))) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dynaRaycast->dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + if ((listType & (DYNA_RAYCAST_WALLS | DYNA_RAYCAST_CEILINGS)) && (dynaRaycast->unk_24 & 0x10) && + COLPOLY_GET_NORMAL(polyList[id].normal.y) < 0.0f) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dynaRaycast->dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + if (CollisionPoly_CheckYIntersectApprox1(&polyList[id], dynaRaycast->dyna->vtxList, dynaRaycast->pos->x, + dynaRaycast->pos->z, &yIntersect, dynaRaycast->checkDist) && + yIntersect < dynaRaycast->pos->y && result < yIntersect) { + result = yIntersect; + *dynaRaycast->resultPoly = &dynaRaycast->dyna->polyList[id]; + } + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dynaRaycast->dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + return result; +} + +#ifdef NON_MATCHING +/** + * Perform dyna poly raycast toward floor + * returns the yIntersect of the poly found, or BGCHECK_Y_MIN if no poly is found + */ +f32 BgCheck_RaycastFloorDyna(DynaRaycast* dynaRaycast) { + s32 i; + f32 result; + f32 intersect2; + s32 i2; + s32 pauseState; + DynaPolyActor* dynaActor; + s32 pad; + Vec3f polyVtx[3]; + Vec3f polyNorm; + u32 polyIndex; + CollisionPoly* polyMin; + MtxF srpMtx; + f32 magnitude; + Vec3s* vtxList; + f32 polyDist; + Vec3f vtx; + f32 intersect; + ScaleRotPos* curTransform; + CollisionPoly* poly; + + result = BGCHECK_Y_MIN; + *dynaRaycast->bgId = BGCHECK_SCENE; + + for (i = 0; i < BG_ACTOR_MAX; i++) { + if (!(dynaRaycast->colCtx->dyna.bgActorFlags[i] & 1) || (dynaRaycast->colCtx->dyna.bgActorFlags[i] & 2)) { + continue; + } + + 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; + } + + dynaRaycast->unk1C = i; + dynaRaycast->dyna = &dynaRaycast->colCtx->dyna; + if (dynaRaycast->unk_24 & BGCHECK_IGNORE_FLOOR) { + dynaRaycast->ssList = &dynaRaycast->colCtx->dyna.bgActors[i].dynaLookup.floor; + intersect2 = BgCheck_RaycastFloorDynaList(dynaRaycast, DYNA_RAYCAST_FLOORS); + + if (dynaRaycast->yIntersect < intersect2) { + dynaRaycast->yIntersect = intersect2; + *dynaRaycast->bgId = i; + result = intersect2; + } + } + if ((dynaRaycast->unk_24 & BGCHECK_IGNORE_WALL) || + (*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) { + + dynaRaycast->yIntersect = intersect2; + *dynaRaycast->bgId = i; + result = intersect2; + } + } + + if (dynaRaycast->unk_24 & BGCHECK_IGNORE_CEILING) { + dynaRaycast->ssList = &dynaRaycast->colCtx->dyna.bgActors[i].dynaLookup.ceiling; + intersect2 = BgCheck_RaycastFloorDynaList(dynaRaycast, DYNA_RAYCAST_CEILINGS); + if (dynaRaycast->yIntersect < intersect2) { + + dynaRaycast->yIntersect = intersect2; + *dynaRaycast->bgId = i; + result = intersect2; + } + } + } + + dynaActor = DynaPoly_GetActor(dynaRaycast->colCtx, *dynaRaycast->bgId); + if ((result != BGCHECK_Y_MIN) && (dynaActor != NULL) && (dynaRaycast->globalCtx != NULL)) { + pauseState = dynaRaycast->globalCtx->pauseCtx.state != 0; + if (!pauseState) { + pauseState = dynaRaycast->globalCtx->pauseCtx.debugState != 0; + } + if (!pauseState && (dynaRaycast->colCtx->dyna.bgActorFlags[*dynaRaycast->bgId] & 2)) { + curTransform = &dynaRaycast->dyna->bgActors[*dynaRaycast->bgId].curTransform; + polyMin = &dynaRaycast->dyna + ->polyList[(u16)dynaRaycast->dyna->bgActors[*dynaRaycast->bgId].dynaLookup.polyStartIndex]; + polyIndex = *dynaRaycast->resultPoly - polyMin; + poly = &dynaRaycast->dyna->bgActors[*dynaRaycast->bgId].colHeader->polyList[polyIndex]; + + SkinMatrix_SetScaleRotateYRPTranslate(&srpMtx, curTransform->scale.x, curTransform->scale.y, + curTransform->scale.z, curTransform->rot.x, curTransform->rot.y, + curTransform->rot.z, curTransform->pos.x, curTransform->pos.y, + curTransform->pos.z); + + vtxList = dynaRaycast->dyna->bgActors[*dynaRaycast->bgId].colHeader->vtxList; + + for (i2 = 0; i2 < 3; i2++) { + Math_Vec3s_ToVec3f(&vtx, &vtxList[COLPOLY_VTX_INDEX(poly->vtxData[i2])]); + SkinMatrix_Vec3fMtxFMultXYZ(&srpMtx, &vtx, &polyVtx[i2]); + } + Math3D_SurfaceNorm(&polyVtx[0], &polyVtx[1], &polyVtx[2], &polyNorm); + magnitude = Math3D_Vec3fMagnitude(&polyNorm); + + if (!IS_ZERO(magnitude)) { + polyNorm.x *= 1.0f / magnitude; + polyNorm.y *= 1.0f / magnitude; + polyNorm.z *= 1.0f / magnitude; + polyDist = -DOTXYZ(polyNorm, polyVtx[0]); + if (Math3D_TriChkPointParaYIntersectInsideTri( + &polyVtx[0], &polyVtx[1], &polyVtx[2], polyNorm.x, polyNorm.y, polyNorm.z, polyDist, + dynaRaycast->pos->z, dynaRaycast->pos->x, &intersect, dynaRaycast->checkDist)) { + if (fabsf(intersect - result) < 1.0f) { + + result = intersect; + } + } + } + } + } + return result; +} +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_RaycastFloorDyna.s") +#endif + +#ifdef NON_MATCHING +// regalloc, minor instruction ordering +/** + * Performs collision detection on a BgActor's wall polys on sphere `pos`, `radius` + * returns true if a collision was detected + * `outX` `outZ` return the displaced x,z coordinates + * `outPoly` returns the pointer to the nearest poly collided with, or NULL + * `outBgId` returns `bgId` if the poly SurfaceType's wall damage flag is not set, else ? + */ +s32 BgCheck_SphVsDynaWallInBgActor(CollisionContext* colCtx, u16 xpFlags, DynaCollisionContext* dyna, SSList* ssList, + f32* outX, f32* outZ, CollisionPoly** outPoly, s32* outBgId, Vec3f* pos, f32 radius, + s32 bgId, Actor* actor) { + f32 temp; + f32 intersect; + s32 result = false; + CollisionPoly* poly; + SSNode* curNode; + f32 nx; + f32 ny; + f32 nz; + Vec3f resultPos; + s16 polyId; + f32 zTemp; + f32 xTemp; + f32 normalXZ; + f32 invNormalXZ; + f32 planeDist; + f32 temp_f18; + f32 zIntersectDist; + f32 xIntersectDist; + f32 zMin; + f32 zMax; + f32 xMin; + f32 xMax; + + if (ssList->head == SS_NULL) { + return result; + } + + resultPos = *pos; + curNode = &dyna->polyNodes.tbl[ssList->head]; + + while (true) { + polyId = curNode->polyId; + poly = &dyna->polyList[polyId]; + CollisionPoly_GetNormalF(poly, &nx, &ny, &nz); + normalXZ = sqrtf(SQ(nx) + SQ(nz)); + + 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)))) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + invNormalXZ = 1.0f / normalXZ; + temp_f18 = fabsf(nz) * invNormalXZ; + if (temp_f18 < 0.4f) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + + // compute poly zMin/zMax + zTemp = dyna->vtxList[COLPOLY_VTX_INDEX(poly->flags_vIA)].z; + zMax = zMin = zTemp; + + zTemp = dyna->vtxList[COLPOLY_VTX_INDEX(poly->flags_vIB)].z; + if (zTemp < zMin) { + zMin = zTemp; + } else if (zTemp > zMax) { + zMax = zTemp; + } + + zTemp = dyna->vtxList[poly->vIC].z; + if (zTemp < zMin) { + zMin = zTemp; + } else if (zMax < zTemp) { + zMax = zTemp; + } + + zMin -= radius; + zMax += radius; + if (resultPos.z < zMin || zMax < resultPos.z) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + if (CollisionPoly_CheckZIntersectApprox(poly, dyna->vtxList, resultPos.x, pos->y, &intersect)) { + if (fabsf(intersect - resultPos.z) <= radius / temp_f18) { + if ((intersect - resultPos.z) * nz <= 4.0f) { + if (BgCheck_ComputeWallDisplacement(colCtx, poly, &resultPos.x, &resultPos.z, nx, ny, nz, + invNormalXZ, planeDist, radius, outPoly)) { + *outBgId = bgId; + } + result = true; + } + } + } + if (curNode->next == SS_NULL) { + break; + } + curNode = &dyna->polyNodes.tbl[curNode->next]; + } + + curNode = &dyna->polyNodes.tbl[ssList->head]; + while (true) { + polyId = curNode->polyId; + poly = &dyna->polyList[polyId]; + CollisionPoly_GetNormalF(poly, &nx, &ny, &nz); + normalXZ = sqrtf(SQ(nx) + SQ(nz)); + + 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)))) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + + invNormalXZ = 1.0f / normalXZ; + temp_f18 = fabsf(nx) * invNormalXZ; + if (temp_f18 < 0.4f) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + + // compute poly xMin/xMax + xTemp = dyna->vtxList[COLPOLY_VTX_INDEX(poly->flags_vIA)].x; + xMax = xMin = xTemp; + xTemp = dyna->vtxList[COLPOLY_VTX_INDEX(poly->flags_vIB)].x; + + if (xTemp < xMin) { + xMin = xTemp; + } else if (xMax < xTemp) { + xMax = xTemp; + } + xTemp = dyna->vtxList[poly->vIC].x; + if (xTemp < xMin) { + xMin = xTemp; + } else if (xMax < xTemp) { + xMax = xTemp; + } + + xMin -= radius; + xMax += radius; + if (resultPos.x < xMin || xMax < resultPos.x) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + + if (CollisionPoly_CheckXIntersectApprox(poly, dyna->vtxList, pos->y, resultPos.z, &intersect)) { + xIntersectDist = intersect - resultPos.x; + if (fabsf(xIntersectDist) <= radius / temp_f18) { + if (xIntersectDist * nx <= 4.0f) { + if (BgCheck_ComputeWallDisplacement(colCtx, poly, &resultPos.x, &resultPos.z, nx, ny, nz, + invNormalXZ, planeDist, radius, outPoly)) { + *outBgId = bgId; + } + result = true; + } + } + } + if (curNode->next == SS_NULL) { + break; + } + curNode = &dyna->polyNodes.tbl[curNode->next]; + } + *outX = resultPos.x; + *outZ = resultPos.z; + return result; +} +#else +s32 BgCheck_SphVsDynaWallInBgActor(CollisionContext* colCtx, u16 xpFlags, DynaCollisionContext* dyna, SSList* ssList, + f32* outX, f32* outZ, CollisionPoly** outPoly, s32* outBgId, Vec3f* pos, f32 radius, + s32 bgId, Actor* actor); +#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/BgCheck_SphVsDynaWallInBgActor.s") +#endif + +/** + * Performs collision detection on all dyna poly walls using sphere `pos`, `radius` + * returns true if a collision was detected + * `outX` `outZ` return the displaced x,z coordinates + * `outPoly` returns the pointer to the nearest poly collided with, or NULL + * `outBgId` returns the index of the BgActor that owns `outPoly` + * If `actor` is not NULL, an BgActor bound to that actor will be ignored + */ +s32 BgCheck_SphVsDynaWall(CollisionContext* colCtx, u16 xpFlags, f32* outX, f32* outZ, Vec3f* pos, f32 radius, + CollisionPoly** outPoly, s32* outBgId, Actor* actor) { + Vec3f resultPos; + s32 result; + f32 r; + f32 dz; + f32 dx; + BgActor* bgActor; + s32 i; + + result = false; + resultPos = *pos; + + for (i = 0; i < BG_ACTOR_MAX; i++) { + if (!(colCtx->dyna.bgActorFlags[i] & 1) || (colCtx->dyna.bgActorFlags[i] & 2)) { + continue; + } + if ((colCtx->dyna.bgActors + i)->actor == actor) { + continue; + } + bgActor = &colCtx->dyna.bgActors[i]; + + if (bgActor->minY > resultPos.y || bgActor->maxY < resultPos.y) { + continue; + } + + bgActor->boundingSphere.radius += (s16)radius; + + 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) && + !Math3D_YZInSphere(&bgActor->boundingSphere, resultPos.y, resultPos.z))) { + bgActor->boundingSphere.radius -= (s16)radius; + continue; + } + bgActor->boundingSphere.radius -= (s16)radius; + if (BgCheck_SphVsDynaWallInBgActor(colCtx, xpFlags, &colCtx->dyna, + &(colCtx->dyna.bgActors + i)->dynaLookup.wall, outX, outZ, outPoly, outBgId, + &resultPos, radius, i, actor)) { + resultPos.x = *outX; + resultPos.z = *outZ; + result = true; + } + } + return result; +} + +/** + * Tests for collision with a dyna poly ceiling, starting at `ssList` + * returns true if a collision occurs, else false + * `outPoly` returns the poly collided with + * `outY` returns the y coordinate needed to not collide with `outPoly` + */ +s32 BgCheck_CheckDynaCeilingList(CollisionContext* colCtx, u16 xpFlags, DynaCollisionContext* dyna, SSList* ssList, + f32* outY, Vec3f* pos, f32 checkHeight, CollisionPoly** outPoly, Actor* actor, + s32 bgId) { + s16 polyId; + SSNode* curNode; + CollisionPoly* poly; + Vec3f testPos; + f32 ceilingY; + f32 sign; + f32 nx; + f32 ny; + f32 nz; + s32 result = false; + f32 intersectDist; + u16 padding; + + if (ssList->head == SS_NULL) { + return false; + } + curNode = &dyna->polyNodes.tbl[ssList->head]; + testPos = *pos; + + while (true) { + 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)))) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + CollisionPoly_GetNormalF(poly, &nx, &ny, &nz); + if (checkHeight < Math3D_UDistPlaneToPos(nx, ny, nz, poly->dist, &testPos)) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + 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) { + sign = (0.0f <= ny) ? 1.0f : -1.0f; + testPos.y = (sign * checkHeight) + ceilingY; + result = true; + *outPoly = poly; + } + } + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + *outY = testPos.y; + return result; +} + +/** + * Tests collision with a dyna poly ceiling + * returns true if a collision occurs, else false + * `outPoly` returns the poly collided with, while `outBgId` returns the id of the BgActor that owns the poly + * `outY` returns the y coordinate needed to not collide with `outPoly`, or `pos`.y + `checkDist` if no collision occurs + */ +s32 BgCheck_CheckDynaCeiling(CollisionContext* colCtx, u16 xpFlags, f32* outY, Vec3f* pos, f32 checkDist, + CollisionPoly** outPoly, s32* outBgId, Actor* actor) { + s32 i; + s32 result = false; + f32 resultY; + f32 tempY = checkDist + pos->y; + BgActor* bgActor; + CollisionPoly* poly; + + resultY = tempY; + + for (i = 0; i < BG_ACTOR_MAX; i++) { + if (!(colCtx->dyna.bgActorFlags[i] & 1) || (colCtx->dyna.bgActorFlags[i] & 2)) { + continue; + } + if (actor == colCtx->dyna.bgActors[i].actor) { + continue; + } + if (!Math3D_XZInSphere(&colCtx->dyna.bgActors[i].boundingSphere, pos->x, pos->z)) { + continue; + } + if (BgCheck_CheckDynaCeilingList(colCtx, xpFlags, &colCtx->dyna, &colCtx->dyna.bgActors[i].dynaLookup.ceiling, + &tempY, pos, checkDist, &poly, actor, i) && + tempY < resultY) { + + resultY = tempY; + *outPoly = poly; + *outBgId = i; + result = true; + } + } + *outY = resultY; + return result; +} + +/** + * Tests if DynaLineTest intersects with a poly + * returns true if a poly was intersected, else false + */ +s32 BgCheck_CheckLineAgainstBgActorSSList(DynaLineTest* dynaLineTest) { + f32 distSq; + s32 result; + SSNode* curNode; + Vec3f polyIntersect; + s16 polyId; + BgLineVsPolyTest test; + + result = false; + if (dynaLineTest->ssList->head == SS_NULL) { + return result; + } + curNode = &dynaLineTest->dyna->polyNodes.tbl[dynaLineTest->ssList->head]; + + test.vtxList = dynaLineTest->dyna->vtxList; + test.posA = dynaLineTest->posA; + test.posB = dynaLineTest->posB; + test.planeIntersect = &polyIntersect; + test.checkOneFace = dynaLineTest->checkOneFace; + test.checkDist = dynaLineTest->checkDist; + + while (true) { + polyId = curNode->polyId; + 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)))) { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dynaLineTest->dyna->polyNodes.tbl[curNode->next]; + } + } else { + if (CollisionPoly_LineVsPoly(&test)) { + distSq = Math3D_Vec3fDistSq(dynaLineTest->posA, test.planeIntersect); + if (distSq < *dynaLineTest->distSq) { + *dynaLineTest->distSq = distSq; + *dynaLineTest->posResult = *test.planeIntersect; + *dynaLineTest->posB = *test.planeIntersect; + *dynaLineTest->resultPoly = test.poly; + result = true; + } + } + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dynaLineTest->dyna->polyNodes.tbl[curNode->next]; + } + } + } + return result; +} + +/** + * Tests if line `posA` `posB` intersects with a dyna poly within BgActor `bgId` + * `distSq` is the maximum squared distance to check for a collision + * returns true if an intersection occurred, else false + * `posB`? and `posResult` return the point of intersection + * `outPoly` returns the poly intersected + * `distSq` returns the squared distance of the intersection + */ +s32 BgCheck_CheckLineAgainstBgActor(CollisionContext* colCtx, u16 xpFlags, Vec3f* posA, Vec3f* posB, Vec3f* posResult, + CollisionPoly** outPoly, f32* distSq, s32 bgId, f32 checkDist, s32 bccFlags, + Actor* actor) { + s32 result = false; + DynaLineTest dynaLineTest; + + dynaLineTest.colCtx = colCtx; + dynaLineTest.xpFlags = xpFlags; + dynaLineTest.dyna = &colCtx->dyna; + dynaLineTest.posA = posA; + dynaLineTest.posB = posB; + dynaLineTest.posResult = posResult; + dynaLineTest.resultPoly = outPoly; + dynaLineTest.checkOneFace = (bccFlags & BGCHECK_CHECK_ONE_FACE) != 0; + dynaLineTest.distSq = distSq; + dynaLineTest.checkDist = checkDist; + dynaLineTest.actor = actor; + dynaLineTest.bgId = bgId; + + dynaLineTest.ssList = &colCtx->dyna.bgActors[bgId].dynaLookup.wall; + if (bccFlags & BGCHECK_CHECK_WALL) { + if (BgCheck_CheckLineAgainstBgActorSSList(&dynaLineTest)) { + result = true; + } + } + dynaLineTest.ssList = &colCtx->dyna.bgActors[bgId].dynaLookup.floor; + if (bccFlags & BGCHECK_CHECK_FLOOR) { + if (BgCheck_CheckLineAgainstBgActorSSList(&dynaLineTest)) { + result = true; + } + } + dynaLineTest.ssList = &colCtx->dyna.bgActors[bgId].dynaLookup.ceiling; + if (bccFlags & BGCHECK_CHECK_CEILING) { + if (BgCheck_CheckLineAgainstBgActorSSList(&dynaLineTest)) { + result = true; + } + } + return result; +} + +/** + * Tests if line from `posA` to `posB` passes through a dyna poly. + * returns true if so, otherwise false + * `outPoly` returns the pointer of the poly intersected. + * `outBgId` returns the BgActor index of the poly + */ +s32 BgCheck_CheckLineAgainstDyna(CollisionContext* colCtx, u16 xpFlags, Vec3f* posA, Vec3f* posB, Vec3f* posResult, + CollisionPoly** outPoly, f32* distSq, s32* outBgId, Actor* actor, f32 checkDist, + s32 bccFlags) { + s32 pad; + s32 i; + s32 result = false; + LineSegment line; + f32 ay; + f32 by; + + for (i = 0; i < BG_ACTOR_MAX; i++) { + if ((colCtx->dyna.bgActorFlags[i] & 1) && !(colCtx->dyna.bgActorFlags[i] & 2)) { + 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; + } + } + } + } + } + } + } + return result; +} + +/** + * Get first dyna poly intersecting sphere `center` `radius` from list `ssList` + * returns true if any poly intersects the sphere, else returns false + * `outPoly` returns the pointer of the first poly found that intersects + */ +s32 BgCheck_SphVsFirstDynaPolyList(CollisionContext* colCtx, u16 xpFlags, CollisionPoly** outPoly, Vec3f* center, + f32 radius, SSList* ssList, Actor* actor, s32 bgId) { + CollisionPoly* curPoly; + DynaCollisionContext* dyna; + SSNode* curNode; + s32 curPolyId; + + if (ssList->head == SS_NULL) { + return false; + } + dyna = &colCtx->dyna; + curNode = &dyna->polyNodes.tbl[ssList->head]; + while (true) { + 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)))) + + { + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + if (CollisionPoly_SphVsPoly(curPoly, dyna->vtxList, center, radius)) { + *outPoly = curPoly; + return true; + } + if (curNode->next == SS_NULL) { + break; + } else { + curNode = &dyna->polyNodes.tbl[curNode->next]; + continue; + } + } + return false; +} + +/** + * Get first dyna poly intersecting sphere `center` `radius` from BgActor `bgId` + * returns true if any poly intersects the sphere, else false + * `outPoly` returns the pointer of the first poly found that intersects + */ +s32 BgCheck_SphVsFirstDynaPolyInBgActor(CollisionContext* colCtx, u16 xpFlags, CollisionPoly** outPoly, Vec3f* center, + f32 radius, s32 bgId, u16 bciFlags, Actor* actor) { + if (!(bciFlags & BGCHECK_IGNORE_CEILING)) { + if (BgCheck_SphVsFirstDynaPolyList(colCtx, xpFlags, outPoly, center, radius, + &colCtx->dyna.bgActors[bgId].dynaLookup.ceiling, actor, bgId)) { + return true; + } + } + if (!(bciFlags & BGCHECK_IGNORE_WALL)) { + if (BgCheck_SphVsFirstDynaPolyList(colCtx, xpFlags, outPoly, center, radius, + &colCtx->dyna.bgActors[bgId].dynaLookup.wall, actor, bgId)) { + return true; + } + } + if (!(bciFlags & BGCHECK_IGNORE_FLOOR)) { + if (BgCheck_SphVsFirstDynaPolyList(colCtx, xpFlags, outPoly, center, radius, + &colCtx->dyna.bgActors[bgId].dynaLookup.floor, actor, bgId)) { + return true; + } + } + return false; +} + +/** + * Gets first dyna poly intersecting sphere `center` `radius` + * returns true if poly detected, else false + * `outPoly` returns the first intersecting poly, while `outBgId` returns the BgActor index of that poly + */ +s32 BgCheck_SphVsFirstDynaPoly(CollisionContext* colCtx, u16 xpFlags, CollisionPoly** outPoly, s32* outBgId, + Vec3f* center, f32 radius, Actor* actor, u16 bciFlags) { + s32 i = 0; + Sphere16 testSphere; + + for (i = 0; i < BG_ACTOR_MAX; i++) { + if (!(colCtx->dyna.bgActorFlags[i] & 1) || (colCtx->dyna.bgActorFlags[i] & 2)) { + continue; + } + if (colCtx->dyna.bgActors[i].actor == actor) { + continue; + } + testSphere.center.x = center->x; + testSphere.center.y = center->y; + testSphere.center.z = center->z; + testSphere.radius = radius; + if (!Math3D_SphVsSph(&testSphere, &colCtx->dyna.bgActors[i].boundingSphere)) { + continue; + } + if (BgCheck_SphVsFirstDynaPolyInBgActor(colCtx, xpFlags, outPoly, center, radius, i, bciFlags, actor)) { + return true; + } + } + return false; +} + +/** + * SEGMENTED_TO_VIRTUAL CollisionHeader members + */ +void CollisionHeader_SegmentedToVirtual(CollisionHeader* colHeader) { + colHeader->vtxList = Lib_SegmentedToVirtual(colHeader->vtxList); + colHeader->polyList = Lib_SegmentedToVirtual(colHeader->polyList); + if (colHeader->surfaceTypeList) { + colHeader->surfaceTypeList = Lib_SegmentedToVirtual(colHeader->surfaceTypeList); + } + if (colHeader->cameraDataList) { + colHeader->cameraDataList = Lib_SegmentedToVirtual(colHeader->cameraDataList); + } + if (colHeader->waterBoxes) { + colHeader->waterBoxes = Lib_SegmentedToVirtual(colHeader->waterBoxes); + } +} + +/** + * Convert CollisionHeader Segmented to Virtual addressing + */ +void CollisionHeader_GetVirtual(CollisionHeader* colHeader, CollisionHeader** dest) { + *dest = Lib_SegmentedToVirtual(colHeader); + CollisionHeader_SegmentedToVirtual(*dest); +} + +/** + * SEGMENT_TO_VIRTUAL all active BgActor CollisionHeaders + */ +void BgCheck_InitCollisionHeaders(CollisionContext* colCtx, GlobalContext* globalCtx) { + DynaCollisionContext* dyna = &colCtx->dyna; + s32 i; + u16 flag; + + for (i = 0; i < BG_ACTOR_MAX; i++) { + flag = dyna->bgActorFlags[i]; + if ((flag & 1) && !(flag & 2)) { + Actor_SetObjectSegment(globalCtx, dyna->bgActors[i].actor); + CollisionHeader_SegmentedToVirtual(dyna->bgActors[i].colHeader); + } + } +} + +/** + * Reset SSNodeList polyCheckTbl + */ +void BgCheck_ResetPolyCheckTbl(SSNodeList* nodeList, s32 numPolys) { + u8* end = nodeList->polyCheckTbl + numPolys; + u8* t; + + for (t = nodeList->polyCheckTbl; t < end; t++) { + *t = 0; + } +} + +/** + * Get SurfaceType property set + */ +u32 SurfaceType_GetData(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId, s32 dataIdx) { + CollisionHeader* colHeader; + SurfaceType* surfaceTypes; + + colHeader = BgCheck_GetCollisionHeader(colCtx, bgId); + if (colHeader == NULL || poly == NULL) { + return 0; + } + surfaceTypes = colHeader->surfaceTypeList; + if (surfaceTypes == NULL) { + return 0; + } + return surfaceTypes[poly->type].data[dataIdx]; +} + +/** + * SurfaceType return CamData Index + */ +u32 SurfaceType_GetCamDataIndex(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 0) & 0xFF; +} + +/** + * CamData return camera setting + */ +u16 func_800C9728(CollisionContext* colCtx, u32 camId, s32 bgId) { + u16 result; + CollisionHeader* colHeader; + CamData* camData; + + colHeader = BgCheck_GetCollisionHeader(colCtx, bgId); + if (colHeader == NULL) { + return 0; + } + camData = colHeader->cameraDataList; + result = camData[camId].cameraSType; + return result; +} + +/** + * SurfaceType return camera setting + */ +u16 SurfaceType_GetCameraSetting(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + CollisionHeader* colHeader = BgCheck_GetCollisionHeader(colCtx, bgId); + CamData* camData; + SurfaceType* surfaceTypes; + + if (colHeader == NULL) { + return 0; + } + camData = colHeader->cameraDataList; + if (camData == NULL) { + return 0; + } + surfaceTypes = colHeader->surfaceTypeList; + if (surfaceTypes == NULL) { + return 0; + } + return func_800C9728(colCtx, SurfaceType_GetCamDataIndex(colCtx, poly, bgId), bgId); +} + +/** + * CamData get number of camera data blocks + */ +u16 func_800C97F8(CollisionContext* colCtx, u32 camId, s32 bgId) { + CollisionHeader* colHeader = BgCheck_GetCollisionHeader(colCtx, bgId); + CamData* camData; + + if (colHeader == NULL) { + return 0; + } + + camData = colHeader->cameraDataList; + if (camData == NULL) { + return 0; + } + return camData[camId].unk_02; +} + +/** + * SurfaceType get number of camera data blocks + */ +u16 func_800C9844(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + CollisionHeader* colHeader = BgCheck_GetCollisionHeader(colCtx, bgId); + CamData* camData; + SurfaceType* surfaceTypes; + + if (colHeader == NULL) { + return 0; + } + camData = colHeader->cameraDataList; + if (camData == NULL) { + return 0; + } + surfaceTypes = colHeader->surfaceTypeList; + if (surfaceTypes == NULL) { + return 0; + } + return func_800C97F8(colCtx, SurfaceType_GetCamDataIndex(colCtx, poly, bgId), bgId); +} + +/** + * CamData get camPosData + */ +Vec3s* func_800C98CC(CollisionContext* colCtx, s32 camId, s32 bgId) { + CollisionHeader* colHeader = BgCheck_GetCollisionHeader(colCtx, bgId); + CamData* cameraDataList; + + if (colHeader == NULL) { + return NULL; + } + cameraDataList = colHeader->cameraDataList; + if (cameraDataList == NULL) { + return NULL; + } + return Lib_SegmentedToVirtual(cameraDataList[camId].camPosData); +} + +/** + * SurfaceType Get camPosData + */ +Vec3s* SurfaceType_GetCamPosData(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + CollisionHeader* colHeader = BgCheck_GetCollisionHeader(colCtx, bgId); + CamData* camData; + SurfaceType* surfaceTypes; + + if (colHeader == NULL) { + return NULL; + } + camData = colHeader->cameraDataList; + if (camData == NULL) { + return NULL; + } + surfaceTypes = colHeader->surfaceTypeList; + if (surfaceTypes == NULL) { + return NULL; + } + return func_800C98CC(colCtx, SurfaceType_GetCamDataIndex(colCtx, poly, bgId), bgId); +} + +/** + * SurfaceType Get Scene Exit Index + */ +u32 SurfaceType_GetSceneExitIndex(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 0) >> 8 & 0x1F; +} + +/** + * SurfaceType Get ? Property (& 0x0003_E000) + */ +u32 func_800C99D4(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 0) >> 13 & 0x1F; +} + +/** + * SurfaceType Get ? Property (& 0x001C_0000) + */ +u32 func_800C99FC(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 0) >> 18 & 7; +} + +/** + * SurfaceType Get Wall Property (Internal) + */ +u32 func_800C9A24(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 0) >> 21 & 0x1F; +} + +/** + * SurfaceType Get Wall Flags + */ +s32 func_800C9A4C(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return sWallFlags[func_800C9A24(colCtx, poly, bgId)]; +} + +/** + * SurfaceType Is Wall Flag (1 << 0) Set + */ +s32 func_800C9A7C(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return (func_800C9A4C(colCtx, poly, bgId) & 1) ? true : false; +} + +/** + * SurfaceType Is Wall Flag (1 << 1) Set + */ +s32 func_800C9AB0(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return (func_800C9A4C(colCtx, poly, bgId) & 2) ? true : false; +} + +/** + * SurfaceType Is Wall Flag (1 << 2) Set + */ +s32 func_800C9AE4(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return (func_800C9A4C(colCtx, poly, bgId) & 4) ? true : false; +} + +/** + * unused + */ +u32 func_800C9B18(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 0) >> 26 & 0xF; +} + +/** + * SurfaceType Get Floor Property + */ +u32 func_800C9B40(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 0) >> 26 & 0xF; +} + +/** + * SurfaceType Is Floor Minus 1 + */ +u32 func_800C9B68(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 0) >> 30 & 1; +} + +/** + * SurfaceType Is Horse Blocked + */ +u32 SurfaceType_IsHorseBlocked(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 0) >> 31 & 1; +} + +u32 func_800C9BB8(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 1) & 0xF; +} + +/** + * SurfaceType Get Poly Sfx + */ +u16 SurfaceType_GetSfx(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + s32 id = func_800C9BB8(colCtx, poly, bgId); + + if (id < 0 || id > 14) { + return NA_SE_PL_WALK_GROUND - SFX_FLAG; + } + return sSurfaceTypeSfx[id]; +} + +/** + * SurfaceType Get ? (same indexer as Get Poly Sfx) + */ +s32 func_800C9C24(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId, s32 arg3) { + s32 id = func_800C9BB8(colCtx, poly, bgId); + + if (id < 0 || id > 14) { + return 0; + } + return D_801B46C0[id] & arg3; +} + +/** + * SurfaceType get terrain slope surface + */ +u32 SurfaceType_GetSlope(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 1) >> 4 & 3; +} + +/** + * SurfaceType get surface lighting setting + */ +u32 SurfaceType_GetLightSettingIndex(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 1) >> 6 & 0x1F; +} + +/** + * SurfaceType get echo + */ +u32 SurfaceType_GetEcho(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 1) >> 11 & 0x3F; +} + +/** + * SurfaceType Is Hookshot Surface + */ +u32 SurfaceType_IsHookshotSurface(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 1) >> 17 & 1; +} + +/** + * CollisionPoly is ignored by entities + * Returns true if poly is ignored by entities, else false + */ +s32 SurfaceType_IsIgnoredByEntities(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + u32 flags; + + if (BgCheck_GetCollisionHeader(colCtx, bgId) == NULL) { + return true; + } + flags = poly->flags_vIA & 0x4000; + return !!flags; +} + +/** + * CollisionPoly is ignored by projectiles + * Returns true if poly is ignored by projectiles, else false + */ +s32 SurfaceType_IsIgnoredByProjectiles(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + u32 flags; + + if (BgCheck_GetCollisionHeader(colCtx, bgId) == NULL) { + return true; + } + flags = poly->flags_vIA & 0x8000; + return !!flags; +} + +/** + * CollisionPoly is conveyor enabled + * Returns true if `poly` is a conveyor surface, else false + */ +s32 SurfaceType_IsConveyor(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + u32 flags; + + if (BgCheck_GetCollisionHeader(colCtx, bgId) == NULL) { + return true; + } + if (poly == NULL) { + return false; + } + flags = poly->flags_vIB & 0x2000; + return !!flags; +} + +s32 func_800C9DDC(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + u32 flags; + + if (BgCheck_GetCollisionHeader(colCtx, bgId) == NULL) { + return true; + } + flags = poly->flags_vIB & 0x4000; + return !!flags; +} + +/** + * SurfaceType Get Conveyor Surface Speed + */ +u32 SurfaceType_GetConveyorSpeed(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return SurfaceType_GetData(colCtx, poly, bgId, 1) >> 18 & 7; +} + +/** + * SurfaceType Get Conveyor Direction + * returns a value between 0-63, representing 360 / 64 degrees of rotation + */ +u32 SurfaceType_GetConveyorDirection(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + u32 data; + + data = SurfaceType_GetData(colCtx, poly, bgId, 1) >> 21; + if (colCtx->flags & 1) { + data += 0x20; + } + return data & 0x3F; +} + +/** + * SurfaceType is Wall Damage + */ +u32 SurfaceType_IsWallDamage(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { + return (SurfaceType_GetData(colCtx, poly, bgId, 1) & 0x8000000) ? true : false; +} + +/** + * Internal. Get the water surface at point (`x`, `ySurface`, `z`). `ySurface` doubles as position y input + * returns true if point is within the xz boundaries of an active water box, else false + * `ySurface` returns the water box's surface, while `outWaterBox` returns a pointer to the WaterBox + */ +s32 WaterBox_GetSurfaceImpl(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, + WaterBox** outWaterBox, s32* bgId) { + CollisionHeader* colHeader; + u32 room; + WaterBox* curWaterBox; + s32 i; + + *bgId = BGCHECK_SCENE; + colHeader = colCtx->colHeader; + + 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)globalCtx->roomCtx.currRoom.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) { + *outWaterBox = curWaterBox; + *ySurface = curWaterBox->minPos.y; + return true; + } + } + } + } + } + + 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; + } + } + } + } + } + } + return false; +} + +s32 WaterBox_GetSurface1(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, + WaterBox** outWaterBox) { + WaterBox_GetSurface1_2(globalCtx, colCtx, x, z, ySurface, outWaterBox); +} + +s32 WaterBox_GetSurface1_2(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, + WaterBox** outWaterBox) { + s32 bgId; + return WaterBox_GetSurfaceImpl(globalCtx, 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 + * returns the index of the waterbox found, or -1 if no waterbox is found + * `outWaterBox` returns the pointer to the waterbox found, or NULL if none is found + */ +s32 WaterBox_GetSurface2(GlobalContext* globalCtx, CollisionContext* colCtx, Vec3f* pos, f32 surfaceCheckDist, + WaterBox** outWaterBox, s32* bgId) { + CollisionHeader* colHeader; + s32 room; + s32 i; + WaterBox* waterBox; + + *bgId = BGCHECK_SCENE; + colHeader = colCtx->colHeader; + + //! @bug: check skips testing BgActor waterboxes + if (colHeader->numWaterBoxes == 0 || colHeader->waterBoxes == NULL) { + *outWaterBox = NULL; + return -1; + } + + for (i = 0; i < colHeader->numWaterBoxes; i++) { + waterBox = &colHeader->waterBoxes[i]; + + room = WATERBOX_ROOM(waterBox->properties); + if (!(room == globalCtx->roomCtx.currRoom.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) { + *outWaterBox = waterBox; + return i; + } + } + } + } + + 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 < + colCtx->dyna.waterBoxList.boxes + bgActor->waterboxesStartIndex + bgActor->colHeader->numWaterBoxes; + iterator++) { + if (iterator->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) { + *bgId = i; + *outWaterBox = iterator; + return i; + } + } + } + } + } + + *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; + + colHeader = BgCheck_GetCollisionHeader(colCtx, bgId); + if ((colHeader == NULL) || (waterBoxId < 0) || (waterBoxId >= (s32)colHeader->numWaterBoxes)) { + return 0.0f; + } + if (bgId == BGCHECK_SCENE) { + return colCtx->colHeader->waterBoxes[waterBoxId].minPos.y; + } + return (&colCtx->dyna.waterBoxList.boxes[colCtx->dyna.bgActors[bgId].waterboxesStartIndex])[waterBoxId].minPos.y; +} + +/** + * WaterBox get CamData index + */ +u32 WaterBox_GetCamDataIndex(CollisionContext* colCtx, WaterBox* waterBox) { + u32 prop = waterBox->properties >> 0; + + return prop & 0xFF; +} + +/** + * WaterBox get CamData camera setting + */ +u16 WaterBox_GetCameraSetting(CollisionContext* colCtx, WaterBox* waterBox, s32 bgId) { + s32 pad[2]; + u16 result = 0; + CollisionHeader* colHeader; + CamData* camData; + s32 camId; + + colHeader = BgCheck_GetCollisionHeader(colCtx, bgId); + if (colHeader == NULL) { + return result; + } + camId = WaterBox_GetCamDataIndex(colCtx, waterBox); + camData = colHeader->cameraDataList; + + if (camData == NULL) { + return result; + } + + result = camData[camId].cameraSType; + return result; +} + +void func_800CA6B8(CollisionContext* colCtx, WaterBox* waterBox) { + WaterBox_GetCameraSetting(colCtx, waterBox, BGCHECK_SCENE); +} + +/** + * WaterBox get lighting settings + */ +u32 WaterBox_GetLightSettingIndex(CollisionContext* colCtx, WaterBox* waterBox) { + u32 prop = waterBox->properties >> 8; + + 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 + * returns true if point is within the xz boundaries of an active water box, else false + * `ySurface` returns the water box's surface, while `outWaterBox` returns a pointer to the WaterBox + */ +s32 func_800CA6F0(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, + WaterBox** outWaterBox, s32* bgId) { + CollisionHeader* colHeader; + u32 room; + WaterBox* curWaterBox; + s32 i; + BgActor* bgActor; + + colHeader = colCtx->colHeader; + *outWaterBox = NULL; + *bgId = BGCHECK_SCENE; + + 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)globalCtx->roomCtx.currRoom.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; + } + } + } + } + } + + 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; + } + } + } + } + } + } + } + return false; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800CA6F0.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800CA9D0.s") +s32 func_800CA9D0(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, + WaterBox** outWaterBox) { + s32 bgId; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800CAA14.s") + return func_800CA6F0(globalCtx, colCtx, x, z, ySurface, outWaterBox, &bgId); +} + +/** + * Get the `closestPoint` to line (`pointA`, `pointB`) formed from the intersection of planes `polyA` and `polyB` + * returns true if the `closestPoint` exists, else returns false + */ +s32 func_800CAA14(CollisionPoly* polyA, CollisionPoly* polyB, Vec3f* pointA, Vec3f* pointB, Vec3f* closestPoint) { + f32 n1X; + f32 n1Y; + f32 n1Z; + f32 n2X; + f32 n2Y; + f32 n2Z; + s32 result; + + CollisionPoly_GetNormalF(polyA, &n1X, &n1Y, &n1Z); + CollisionPoly_GetNormalF(polyB, &n2X, &n2Y, &n2Z); + result = Math3D_PlaneVsLineSegClosestPoint(n1X, n1Y, n1Z, polyA->dist, n2X, n2Y, n2Z, polyB->dist, pointA, pointB, + closestPoint); + return result; +} diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index 059fbce09c..e11e6cbd74 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -941,7 +941,7 @@ s32 Collider_QuadSetNearestAC(GlobalContext* globalCtx, ColliderQuad* quad, Vec3 return 1; } Math_Vec3s_ToVec3f(&dcMid, &quad->dim.dcMid); - acDist = Math3D_DistanceSquared(&dcMid, hitPos); + acDist = Math3D_Vec3fDistSq(&dcMid, hitPos); if (acDist < quad->dim.acDist) { quad->dim.acDist = acDist; @@ -3510,7 +3510,7 @@ s32 CollisionCheck_LineOC_JntSph(GlobalContext* globalCtx, CollisionCheckContext D_801EDEB0.a = *a; D_801EDEB0.b = *b; - if (Math3D_ColSphereLineSeg(&element->dim.worldSphere, &D_801EDEB0) != 0) { + if (Math3D_LineVsSph(&element->dim.worldSphere, &D_801EDEB0) != 0) { return 1; } } @@ -3548,7 +3548,7 @@ s32 CollisionCheck_LineOC_Sphere(GlobalContext* globalCtx, CollisionCheckContext D_801EDFC8.a = *a; D_801EDFC8.b = *b; - if (Math3D_ColSphereLineSeg(&sphere->dim.worldSphere, &D_801EDFC8) != 0) { + if (Math3D_LineVsSph(&sphere->dim.worldSphere, &D_801EDFC8) != 0) { return 1; } diff --git a/src/code/z_fireobj.c b/src/code/z_fireobj.c index 816fec2be0..6e543d115a 100644 --- a/src/code/z_fireobj.c +++ b/src/code/z_fireobj.c @@ -94,7 +94,7 @@ void FireObj_StepSize(FireObj* fire) { void FireObj_UpdateStateTransitions(GlobalContext* globalCtx, FireObj* fire) { Player* player = GET_PLAYER(globalCtx); WaterBox* waterBox; - f32 sp44; + f32 waterY; s32 sp40 = 0; u8 nextState; Vec3f dist; @@ -113,8 +113,8 @@ void FireObj_UpdateStateTransitions(GlobalContext* globalCtx, FireObj* fire) { FireObj_SetState(fire, fire->dynamicSizeStep, nextState); } if ((fire->flags & 1) && (fire->state != FIRE_STATE_3) && - (func_800CA1E8(globalCtx, &globalCtx->colCtx, fire->position.x, fire->position.z, &sp44, &waterBox) != 0) && - ((fire->yScale * ((void)0, 6500.0f)) < (sp44 - fire->position.y))) { // Fake but IDK what else + WaterBox_GetSurface1_2(globalCtx, &globalCtx->colCtx, fire->position.x, fire->position.z, &waterY, &waterBox) && + ((fire->yScale * ((void)0, 6500.0f)) < (waterY - fire->position.y))) { // Fake but IDK what else FireObj_SetState(fire, fire->dynamicSizeStep, FIRE_STATE_3); } if ((fire->flags & 2) && (player->itemActionParam == PLAYER_AP_STICK)) { diff --git a/src/code/z_quake.c b/src/code/z_quake.c index d08ff59931..9c5288139d 100644 --- a/src/code/z_quake.c +++ b/src/code/z_quake.c @@ -416,8 +416,9 @@ void Quake2_ClearType(s32 type) { } s32 Quake2_GetFloorQuake(Player* player) { - if (func_800C9D8C(&sQuake2Context.globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId) == 0) { - return func_800C9E18(&sQuake2Context.globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId); + if (!SurfaceType_IsConveyor(&sQuake2Context.globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId)) { + return SurfaceType_GetConveyorSpeed(&sQuake2Context.globalCtx->colCtx, player->actor.floorPoly, + player->actor.floorBgId); } return 0; } diff --git a/src/code/z_scene.c b/src/code/z_scene.c index 293a9762d9..6bebcf9386 100644 --- a/src/code/z_scene.c +++ b/src/code/z_scene.c @@ -204,7 +204,7 @@ void Scene_HeaderCmdColHeader(GlobalContext* globalCtx, SceneCmd* cmd) { colHeader->waterBoxes = (WaterBox*)Lib_SegmentedToVirtual(colHeader->waterBoxes); } - BgCheck_Init(&globalCtx->colCtx, globalCtx, colHeader); + BgCheck_Allocate(&globalCtx->colCtx, globalCtx, colHeader); } // SceneTableEntry Header Command 0x04: Room List diff --git a/src/code/z_scene_proc.c b/src/code/z_scene_proc.c index bdd3ea1adf..57e2930a26 100644 --- a/src/code/z_scene_proc.c +++ b/src/code/z_scene_proc.c @@ -722,9 +722,9 @@ void Scene_DrawConfigGreatBayTemple(GlobalContext* globalCtx) { if (Flags_GetSwitch(globalCtx, 0x33) && Flags_GetSwitch(globalCtx, 0x34) && Flags_GetSwitch(globalCtx, 0x35) && Flags_GetSwitch(globalCtx, 0x36)) { - func_800C3C00(&globalCtx->colCtx, 1); + BgCheck_SetContextFlags(&globalCtx->colCtx, BGCHECK_FLAG_REVERSE_CONVEYOR_FLOW); } else { - func_800C3C14(&globalCtx->colCtx, 1); + BgCheck_UnsetContextFlags(&globalCtx->colCtx, BGCHECK_FLAG_REVERSE_CONVEYOR_FLOW); } dList = (Gfx*)GRAPH_ALLOC(globalCtx->state.gfxCtx, sizeof(Gfx) * 18); diff --git a/src/code/z_snap.c b/src/code/z_snap.c index 120861ff5f..1c0ab3a27d 100644 --- a/src/code/z_snap.c +++ b/src/code/z_snap.c @@ -113,11 +113,11 @@ s32 func_8013A530(GlobalContext* globalCtx, Actor* actor, s32 flag, Vec3f* pos, s16 x; s16 y; f32 distance; - CollisionPoly* unk1; + CollisionPoly* poly; Camera* camera; Actor* actors[2]; s32 ret = 0; - u32 unk2; + s32 bgId; camera = GET_ACTIVE_CAM(globalCtx); @@ -142,7 +142,8 @@ s32 func_8013A530(GlobalContext* globalCtx, Actor* actor, s32 flag, Vec3f* pos, ret |= 0x3d; } - if (func_800C576C(&globalCtx->colCtx, pos, &camera->eye, &screenSpace, &unk1, 1, 1, 1, 1, &unk2) != 0) { + if (BgCheck_ProjectileLineTest(&globalCtx->colCtx, pos, &camera->eye, &screenSpace, &poly, true, true, true, true, + &bgId)) { func_8013A41C(0x3c); ret |= 0x3c; } diff --git a/src/overlays/actors/ovl_Arms_Hook/z_arms_hook.c b/src/overlays/actors/ovl_Arms_Hook/z_arms_hook.c index a66535d79f..42834bb57e 100644 --- a/src/overlays/actors/ovl_Arms_Hook/z_arms_hook.c +++ b/src/overlays/actors/ovl_Arms_Hook/z_arms_hook.c @@ -232,8 +232,8 @@ void ArmsHook_Shoot(ArmsHook* this, GlobalContext* globalCtx) { } } else { CollisionPoly* poly; - u32 bgId; - Vec3f sp78; + s32 bgId; + Vec3f posResult; Vec3f prevFrameDiff; Vec3f sp60; @@ -244,20 +244,23 @@ void ArmsHook_Shoot(ArmsHook* this, GlobalContext* globalCtx) { sp60.x = this->unk1EC.x - (this->unk1E0.x - this->unk1EC.x); sp60.y = this->unk1EC.y - (this->unk1E0.y - this->unk1EC.y); sp60.z = this->unk1EC.z - (this->unk1E0.z - this->unk1EC.z); - if (func_800C55C4(&globalCtx->colCtx, &sp60, &this->unk1E0, &sp78, &poly, 1, 1, 1, 1, &bgId) != 0 && - (func_800B90AC(globalCtx, &this->actor, poly, bgId, &sp78) == 0 || - func_800C576C(&globalCtx->colCtx, &sp60, &this->unk1E0, &sp78, &poly, 1, 1, 1, 1, &bgId) != 0)) { - f32 sp5C = poly->normal.x * (1 / SHT_MAX); - f32 sp58 = poly->normal.z * (1 / SHT_MAX); + if (BgCheck_EntityLineTest1(&globalCtx->colCtx, &sp60, &this->unk1E0, &posResult, &poly, true, true, true, true, + &bgId) && + (func_800B90AC(globalCtx, &this->actor, poly, bgId, &posResult) == 0 || + BgCheck_ProjectileLineTest(&globalCtx->colCtx, &sp60, &this->unk1E0, &posResult, &poly, true, true, true, + true, &bgId))) { + f32 nx = COLPOLY_GET_NORMAL(poly->normal.x); + f32 nz = COLPOLY_GET_NORMAL(poly->normal.z); - Math_Vec3f_Copy(&this->actor.world.pos, &sp78); - this->actor.world.pos.x += 10.0f * sp5C; - this->actor.world.pos.z += 10.0f * sp58; + Math_Vec3f_Copy(&this->actor.world.pos, &posResult); + this->actor.world.pos.x += 10.0f * nx; + this->actor.world.pos.z += 10.0f * nz; this->timer = 1; - if (func_800C9CEC(&globalCtx->colCtx, poly, bgId)) { + if (SurfaceType_IsHookshotSurface(&globalCtx->colCtx, poly, bgId)) { { DynaPolyActor* dynaPolyActor; - if (bgId != 0x32 && (dynaPolyActor = BgCheck_GetActorOfMesh(&globalCtx->colCtx, bgId)) != NULL) { + if (bgId != BGCHECK_SCENE && + (dynaPolyActor = DynaPoly_GetActor(&globalCtx->colCtx, bgId)) != NULL) { ArmsHook_AttachHookToActor(this, &dynaPolyActor->actor); } } diff --git a/src/overlays/actors/ovl_Bg_Ctower_Gear/z_bg_ctower_gear.c b/src/overlays/actors/ovl_Bg_Ctower_Gear/z_bg_ctower_gear.c index e41b4ef732..ff11631ef1 100644 --- a/src/overlays/actors/ovl_Bg_Ctower_Gear/z_bg_ctower_gear.c +++ b/src/overlays/actors/ovl_Bg_Ctower_Gear/z_bg_ctower_gear.c @@ -158,7 +158,7 @@ void BgCtowerGear_Destroy(Actor* thisx, GlobalContext* globalCtx) { type = BGCTOWERGEAR_GET_TYPE(this); if ((type == WATER_WHEEL) || (type == ORGAN)) { - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } } diff --git a/src/overlays/actors/ovl_Bg_Ctower_Rot/z_bg_ctower_rot.c b/src/overlays/actors/ovl_Bg_Ctower_Rot/z_bg_ctower_rot.c index df56b42a0c..94868e0cd6 100644 --- a/src/overlays/actors/ovl_Bg_Ctower_Rot/z_bg_ctower_rot.c +++ b/src/overlays/actors/ovl_Bg_Ctower_Rot/z_bg_ctower_rot.c @@ -81,7 +81,7 @@ void BgCtowerRot_Init(Actor* thisx, GlobalContext* globalCtx) { void BgCtowerRot_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgCtowerRot* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void BgCtowerRot_CorridorRotate(BgCtowerRot* this, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.c b/src/overlays/actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.c index f757f54ab8..0d215f5c2e 100644 --- a/src/overlays/actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.c +++ b/src/overlays/actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.c @@ -36,9 +36,9 @@ void BgFuKaiten_Init(Actor* thisx, GlobalContext* globalCtx) { CollisionHeader* header = 0; Actor_SetScale(thisx, 1.0); - DynaPolyActor_Init(&THIS->bg, 3); - BgCheck_RelocateMeshHeader(&D_06002D30, &header); - THIS->bg.bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, &THIS->bg, header); + DynaPolyActor_Init(&THIS->dyna, 3); + CollisionHeader_GetVirtual(&D_06002D30, &header); + THIS->dyna.bgId = DynaPoly_SetBgActor(globalCtx, &globalCtx->colCtx.dyna, &THIS->dyna.actor, header); THIS->bouceHeight = 0.0; THIS->rotationSpeed = 0; @@ -47,23 +47,23 @@ void BgFuKaiten_Init(Actor* thisx, GlobalContext* globalCtx) { } void BgFuKaiten_Destroy(Actor* thisx, GlobalContext* globalCtx) { - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, THIS->bg.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, THIS->dyna.bgId); } void BgFuKaiten_UpdateRotation(BgFuKaiten* this) { f32 f0; - this->bg.actor.shape.rot.y += this->rotationSpeed; + this->dyna.actor.shape.rot.y += this->rotationSpeed; if (this->rotationSpeed > 0) { f0 = this->rotationSpeed * .002f; - func_8019FAD8(&this->bg.actor.projectedPos, 8310, f0); + func_8019FAD8(&this->dyna.actor.projectedPos, 8310, f0); } } void BgFuKaiten_UpdateHeight(BgFuKaiten* this) { this->bounce += this->bounceSpeed; - this->bg.actor.world.pos.y = this->bg.actor.home.pos.y + this->elevation + this->bouceHeight; + this->dyna.actor.world.pos.y = this->dyna.actor.home.pos.y + this->elevation + this->bouceHeight; - this->bg.actor.world.pos.y -= this->bouceHeight * Math_CosS(this->bounce); + this->dyna.actor.world.pos.y -= this->bouceHeight * Math_CosS(this->bounce); } void BgFuKaiten_Update(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.h b/src/overlays/actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.h index 94b582bb30..a7a589717b 100644 --- a/src/overlays/actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.h +++ b/src/overlays/actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.h @@ -6,7 +6,7 @@ struct BgFuKaiten; typedef struct BgFuKaiten { - /* 0x000 */ DynaPolyActor bg; + /* 0x000 */ DynaPolyActor dyna; /* 0x15C */ UNK_TYPE1 pad15C[0x4]; /* 0x160 */ f32 elevation; /* 0x164 */ f32 bouceHeight; diff --git a/src/overlays/actors/ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c b/src/overlays/actors/ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c index dfe04cbba5..fceb27755e 100644 --- a/src/overlays/actors/ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c +++ b/src/overlays/actors/ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c @@ -63,7 +63,7 @@ void BgHakaCurtain_Init(Actor* thisx, GlobalContext* globalCtx) { void BgHakaCurtain_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgHakaCurtain* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void func_80B6DC98(BgHakaCurtain* this) { diff --git a/src/overlays/actors/ovl_Bg_Haka_Tomb/z_bg_haka_tomb.c b/src/overlays/actors/ovl_Bg_Haka_Tomb/z_bg_haka_tomb.c index e05c842823..58ccf1cd91 100644 --- a/src/overlays/actors/ovl_Bg_Haka_Tomb/z_bg_haka_tomb.c +++ b/src/overlays/actors/ovl_Bg_Haka_Tomb/z_bg_haka_tomb.c @@ -56,7 +56,7 @@ void BgHakaTomb_Init(Actor* thisx, GlobalContext* globalCtx) { void BgHakaTomb_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgHakaTomb* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void func_80BD6624(BgHakaTomb* this) { diff --git a/src/overlays/actors/ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c b/src/overlays/actors/ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c index 13facec770..77a0cb2eea 100644 --- a/src/overlays/actors/ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c +++ b/src/overlays/actors/ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c @@ -523,7 +523,7 @@ void func_80A9C058(BgHakuginPost* this, GlobalContext* globalCtx, BgHakuginPostU sp44.x = this->dyna.actor.home.pos.x + unkStruct1->unk_14.x; sp44.y = this->unk_16C + unkStruct1->unk_14.y; sp44.z = this->dyna.actor.home.pos.z + unkStruct1->unk_14.z; - func_8013ECE0(Math3D_DistanceSquared(&sp44, &GET_PLAYER(globalCtx)->actor.world.pos), 255, 20, 150); + func_8013ECE0(Math3D_Vec3fDistSq(&sp44, &GET_PLAYER(globalCtx)->actor.world.pos), 255, 20, 150); quake = Quake_Add(GET_ACTIVE_CAM(globalCtx), 3); Quake_SetSpeed(quake, 20000); Quake_SetQuakeValues(quake, 7, 0, 0, 0); @@ -718,7 +718,7 @@ void BgHakuginPost_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgHakuginPost* this = THIS; if (BGHAKUGINPOST_GET_7(&this->dyna.actor) == 7) { - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); func_80A9AE3C(this, globalCtx); } } diff --git a/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.c b/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.c index 965a999bcd..653e125044 100644 --- a/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.c +++ b/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.c @@ -94,7 +94,7 @@ void BgIcicle_Init(Actor* thisx, GlobalContext* globalCtx) { void BgIcicle_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgIcicle* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); Collider_DestroyCylinder(globalCtx, &this->collider); } diff --git a/src/overlays/actors/ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c b/src/overlays/actors/ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c index 6643aeab7c..503c09048a 100644 --- a/src/overlays/actors/ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c +++ b/src/overlays/actors/ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c @@ -87,7 +87,7 @@ void BgIkanaShutter_Init(Actor* thisx, GlobalContext* globalCtx) { void BgIkanaShutter_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgIkanaShutter* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void func_80BD5828(BgIkanaShutter* this) { diff --git a/src/overlays/actors/ovl_Bg_Iknin_Susceil/z_bg_iknin_susceil.c b/src/overlays/actors/ovl_Bg_Iknin_Susceil/z_bg_iknin_susceil.c index 9ffd1e549d..10454f2cb1 100644 --- a/src/overlays/actors/ovl_Bg_Iknin_Susceil/z_bg_iknin_susceil.c +++ b/src/overlays/actors/ovl_Bg_Iknin_Susceil/z_bg_iknin_susceil.c @@ -124,7 +124,7 @@ void BgIkninSusceil_Init(Actor* thisx, GlobalContext* globalCtx) { void BgIkninSusceil_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgIkninSusceil* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void func_80C0AB14(BgIkninSusceil* this) { diff --git a/src/overlays/actors/ovl_Bg_Iknv_Obj/z_bg_iknv_obj.c b/src/overlays/actors/ovl_Bg_Iknv_Obj/z_bg_iknv_obj.c index 90984244c4..3bf7bf9889 100644 --- a/src/overlays/actors/ovl_Bg_Iknv_Obj/z_bg_iknv_obj.c +++ b/src/overlays/actors/ovl_Bg_Iknv_Obj/z_bg_iknv_obj.c @@ -75,8 +75,8 @@ void BgIknvObj_Init(Actor* thisx, GlobalContext* globalCtx) { case IKNV_OBJ_RAISED_DOOR: this->displayListPtr = D_06011880; DynaPolyActor_Init(&this->dyna, 0); - BgCheck_RelocateMeshHeader(&D_060119D4, &colHeader); - this->dyna.bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, &this->dyna, colHeader); + CollisionHeader_GetVirtual(&D_060119D4, &colHeader); + this->dyna.bgId = DynaPoly_SetBgActor(globalCtx, &globalCtx->colCtx.dyna, &this->dyna.actor, colHeader); this->actionFunc = BgIknvObj_UpdateRaisedDoor; this->dyna.actor.world.pos.y = this->dyna.actor.home.pos.y + 120.0f; break; @@ -84,8 +84,8 @@ void BgIknvObj_Init(Actor* thisx, GlobalContext* globalCtx) { this->displayListPtr = D_060129C8; this->actionFunc = BgIknvObj_UpdateSakonDoor; DynaPolyActor_Init(&this->dyna, 0); - BgCheck_RelocateMeshHeader(&D_06012CA4, &colHeader); - this->dyna.bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, &this->dyna, colHeader); + CollisionHeader_GetVirtual(&D_06012CA4, &colHeader); + this->dyna.bgId = DynaPoly_SetBgActor(globalCtx, &globalCtx->colCtx.dyna, &this->dyna.actor, colHeader); Collider_InitAndSetCylinder(globalCtx, &this->collider, &this->dyna.actor, &sCylinderInit); Collider_UpdateCylinder(&this->dyna.actor, &this->collider); this->dyna.actor.colChkInfo.mass = MASS_IMMOVABLE; @@ -108,7 +108,7 @@ void BgIknvObj_Destroy(Actor* thisx, GlobalContext* globalCtx) { return; } } - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } s32 func_80BD7CEC(BgIknvObj* this) { diff --git a/src/overlays/actors/ovl_Bg_Kin2_Fence/z_bg_kin2_fence.c b/src/overlays/actors/ovl_Bg_Kin2_Fence/z_bg_kin2_fence.c index 4b98ed4e05..cc92791fcc 100644 --- a/src/overlays/actors/ovl_Bg_Kin2_Fence/z_bg_kin2_fence.c +++ b/src/overlays/actors/ovl_Bg_Kin2_Fence/z_bg_kin2_fence.c @@ -180,7 +180,7 @@ void BgKin2Fence_Init(Actor* thisx, GlobalContext* globalCtx) { void BgKin2Fence_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgKin2Fence* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); Collider_DestroyJntSph(globalCtx, &this->collider); } diff --git a/src/overlays/actors/ovl_Bg_Ladder/z_bg_ladder.c b/src/overlays/actors/ovl_Bg_Ladder/z_bg_ladder.c index 81c1f6a97c..0acccbc56a 100644 --- a/src/overlays/actors/ovl_Bg_Ladder/z_bg_ladder.c +++ b/src/overlays/actors/ovl_Bg_Ladder/z_bg_ladder.c @@ -94,7 +94,7 @@ void BgLadder_Init(Actor* thisx, GlobalContext* globalCtx) { void BgLadder_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgLadder* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void BgLadder_ActionWait(BgLadder* this, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Bg_Lbfshot/z_bg_lbfshot.c b/src/overlays/actors/ovl_Bg_Lbfshot/z_bg_lbfshot.c index 19a6e36680..c07f419f9e 100644 --- a/src/overlays/actors/ovl_Bg_Lbfshot/z_bg_lbfshot.c +++ b/src/overlays/actors/ovl_Bg_Lbfshot/z_bg_lbfshot.c @@ -44,7 +44,7 @@ void BgLbfshot_Init(Actor* thisx, GlobalContext* globalCtx) { void BgLbfshot_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgLbfshot* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void BgLbfshot_Draw(Actor* thisx, GlobalContext* globalCtx) { func_800BDFC0(globalCtx, D_06000228); diff --git a/src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c b/src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c index d8141abc39..7499e35cde 100644 --- a/src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c +++ b/src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c @@ -41,13 +41,13 @@ extern Gfx D_06000040[]; // Lilypad model void BgLotus_Init(Actor* thisx, GlobalContext* globalCtx) { BgLotus* this = THIS; s32 pad; - s32 sp2C; + s32 bgId; Actor_ProcessInitChain(&this->dyna.actor, sInitChain); DynaPolyActor_Init(&this->dyna, 1); DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000A20); - this->dyna.actor.floorHeight = - func_800C411C(&globalCtx->colCtx, &thisx->floorPoly, &sp2C, &this->dyna.actor, &this->dyna.actor.world.pos); + this->dyna.actor.floorHeight = BgCheck_EntityRaycastFloor5(&globalCtx->colCtx, &thisx->floorPoly, &bgId, + &this->dyna.actor, &this->dyna.actor.world.pos); this->timer2 = 96; this->dyna.actor.world.rot.y = Rand_Next() >> 0x10; this->actionFunc = BgLotus_Wait; @@ -56,7 +56,7 @@ void BgLotus_Init(Actor* thisx, GlobalContext* globalCtx) { void BgLotus_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgLotus* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void BgLotus_SetScaleXZ(BgLotus* this) { @@ -167,8 +167,8 @@ void BgLotus_Update(Actor* thisx, GlobalContext* globalCtx) { s32 pad; WaterBox* waterBox; - func_800CA1E8(globalCtx, &globalCtx->colCtx, this->dyna.actor.world.pos.x, this->dyna.actor.world.pos.z, - &this->height, &waterBox); + WaterBox_GetSurface1_2(globalCtx, &globalCtx->colCtx, this->dyna.actor.world.pos.x, this->dyna.actor.world.pos.z, + &this->height, &waterBox); this->actionFunc(this, globalCtx); } diff --git a/src/overlays/actors/ovl_Bg_Mbar_Chair/z_bg_mbar_chair.c b/src/overlays/actors/ovl_Bg_Mbar_Chair/z_bg_mbar_chair.c index 112eabfbcb..c805de05c9 100644 --- a/src/overlays/actors/ovl_Bg_Mbar_Chair/z_bg_mbar_chair.c +++ b/src/overlays/actors/ovl_Bg_Mbar_Chair/z_bg_mbar_chair.c @@ -48,7 +48,7 @@ void BgMbarChair_Init(Actor* thisx, GlobalContext* globalCtx) { void BgMbarChair_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgMbarChair* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void BgMbarChair_Update(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Bg_Tobira01/z_bg_tobira01.c b/src/overlays/actors/ovl_Bg_Tobira01/z_bg_tobira01.c index e759edfb3a..69ba3e6529 100644 --- a/src/overlays/actors/ovl_Bg_Tobira01/z_bg_tobira01.c +++ b/src/overlays/actors/ovl_Bg_Tobira01/z_bg_tobira01.c @@ -47,7 +47,8 @@ void BgTobira01_Open(BgTobira01* this, GlobalContext* globalCtx) { } } else if (!(gSaveContext.weekEventReg[88] & 0x40) && (this->timer == 0) && (globalCtx->actorCtx.unk1F5 != 0) && (globalCtx->actorCtx.unk1F4 == 0) && - (func_800C99AC(&globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId) == 6)) { + (SurfaceType_GetSceneExitIndex(&globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId) == + 6)) { this->playCutscene = true; this->unk_16C = 0; // this variable is not used anywhere else } @@ -91,7 +92,7 @@ void BgTobira01_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgTobira01* this = THIS; s32 pad; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void BgTobira01_Update(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Boss_02/z_boss_02.c b/src/overlays/actors/ovl_Boss_02/z_boss_02.c index 4984550114..32d75abba3 100644 --- a/src/overlays/actors/ovl_Boss_02/z_boss_02.c +++ b/src/overlays/actors/ovl_Boss_02/z_boss_02.c @@ -752,7 +752,7 @@ void func_809DAB78(Boss02* this, GlobalContext* globalCtx) { spD0.y = 2000.0f; } - temp_f0 = func_800C3FA0(&globalCtx->colCtx, &spDC, &spD0); + temp_f0 = BgCheck_EntityRaycastFloor1(&globalCtx->colCtx, &spDC, &spD0); if (((this->unk_017C.y < temp_f0) && (temp_f0 <= this->unk_0188.y)) || ((temp_f0 < this->unk_017C.y) && (this->unk_0188.y <= temp_f0))) { this->unk_0170 = this->unk_017C; @@ -1057,8 +1057,8 @@ void func_809DAB78(Boss02* this, GlobalContext* globalCtx) { spD0.x = this->unk_0170.x + sp90.x; spD0.y = this->unk_0170.y + (1000.0f * D_809DF5B0); spD0.z = this->unk_0170.z + sp90.z; - if (func_800C40B4(&globalCtx->colCtx, &sp8C, &sp88, &spD0) != BGCHECK_Y_MIN) { - spA0 = func_800C3FA0(&globalCtx->colCtx, &sp8C, &spD0); + if (BgCheck_EntityRaycastFloor3(&globalCtx->colCtx, &sp8C, &sp88, &spD0) != BGCHECK_Y_MIN) { + spA0 = BgCheck_EntityRaycastFloor1(&globalCtx->colCtx, &sp8C, &spD0); Matrix_GetStateTranslationAndScaledZ(5.0f * D_809DF5B0, &sp70); sp70.y = 2.0f * D_809DF5B0; sp64.y = 0.3f * D_809DF5B0; @@ -1183,7 +1183,8 @@ void func_809DC218(Actor* thisx, GlobalContext* globalCtx) { sp24.y = 2000.0f; } - if ((this->actor.focus.pos.y < func_800C3FA0(&globalCtx->colCtx, &sp20, &sp24)) || (D_809E0422 != 0)) { + if ((this->actor.focus.pos.y < BgCheck_EntityRaycastFloor1(&globalCtx->colCtx, &sp20, &sp24)) || + (D_809E0422 != 0)) { this->actor.flags &= ~1; } else { this->actor.flags |= 1; diff --git a/src/overlays/actors/ovl_Dm_Char07/z_dm_char07.c b/src/overlays/actors/ovl_Dm_Char07/z_dm_char07.c index c5ff12452d..efb716667e 100644 --- a/src/overlays/actors/ovl_Dm_Char07/z_dm_char07.c +++ b/src/overlays/actors/ovl_Dm_Char07/z_dm_char07.c @@ -73,7 +73,7 @@ void DmChar07_Destroy(Actor* thisx, GlobalContext* globalCtx) { DmChar07* this = THIS; if (this->isStage) { - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } } diff --git a/src/overlays/actors/ovl_En_Clear_Tag/z_en_clear_tag.c b/src/overlays/actors/ovl_En_Clear_Tag/z_en_clear_tag.c index b7ad8e6f3e..6ee8f0055f 100644 --- a/src/overlays/actors/ovl_En_Clear_Tag/z_en_clear_tag.c +++ b/src/overlays/actors/ovl_En_Clear_Tag/z_en_clear_tag.c @@ -642,7 +642,7 @@ void EnClearTag_UpdateEffects(EnClearTag* this, GlobalContext* globalCtx) { sphereCenter.y += 5.0f; // Check if the debris has hit the ground. - if (func_800C5A20(&globalCtx->colCtx, &sphereCenter, 11.0f)) { + if (BgCheck_SphVsFirstPoly(&globalCtx->colCtx, &sphereCenter, 11.0f)) { effect->position.y = originalYPosition; // Bounce the debris effect. @@ -976,8 +976,8 @@ void EnClearTag_DrawEffects(Actor* thisx, GlobalContext* globalCtx) { * `ySurface` returns the water box's surface, while `outWaterBox` returns a pointer to the WaterBox */ ySurface = effect->position.y; - if (func_800CA1AC(globalCtx, &globalCtx->colCtx, effect->position.x + vec.x, effect->position.z + vec.z, - &ySurface, &waterBox)) { + if (WaterBox_GetSurface1(globalCtx, &globalCtx->colCtx, effect->position.x + vec.x, + effect->position.z + vec.z, &ySurface, &waterBox)) { if ((effect->position.y - ySurface) < 200.0f) { // Draw the splash effect. Matrix_InsertTranslation(effect->position.x + vec.x, ySurface, effect->position.z + vec.z, diff --git a/src/overlays/actors/ovl_En_Dg/z_en_dg.c b/src/overlays/actors/ovl_En_Dg/z_en_dg.c index 801a60012c..2c5a330ab7 100644 --- a/src/overlays/actors/ovl_En_Dg/z_en_dg.c +++ b/src/overlays/actors/ovl_En_Dg/z_en_dg.c @@ -946,19 +946,19 @@ void func_8098B464(EnDg* this, GlobalContext* globalCtx) { void func_8098B560(EnDg* this, GlobalContext* globalCtx) { Vec3f sp54; - Vec3f sp48; + Vec3f pos; s16 sp46 = 0; - WaterBox* sp40; - f32 sp3C; - s32 sp38; + WaterBox* waterBox; + f32 waterSurface; + CollisionPoly* poly; f32 sp34; sp54.x = this->actor.world.pos.x; sp54.y = this->actor.world.pos.y + this->actor.depthInWater; sp54.z = this->actor.world.pos.z + 20.0f; - sp48.x = (Math_SinS(this->actor.world.rot.y) * 50.0f) + this->actor.world.pos.x; - sp48.y = this->actor.home.pos.y + 100.0f; - sp48.z = (Math_CosS(this->actor.world.rot.y) * 50.0f) + this->actor.world.pos.z; + pos.x = (Math_SinS(this->actor.world.rot.y) * 50.0f) + this->actor.world.pos.x; + pos.y = this->actor.home.pos.y + 100.0f; + pos.z = (Math_CosS(this->actor.world.rot.y) * 50.0f) + this->actor.world.pos.z; if (DECR(this->unk_284) == 0) { if (!(this->unk_280 & 4)) { @@ -975,9 +975,9 @@ void func_8098B560(EnDg* this, GlobalContext* globalCtx) { this->actor.velocity.y = -0.5f; } - sp34 = func_800C4000(globalCtx, &globalCtx->colCtx, &sp38, &sp48); + sp34 = BgCheck_EntityRaycastFloor2(globalCtx, &globalCtx->colCtx, &poly, &pos); if (this->actor.bgCheckFlags & 8) { - if (!func_800CA1AC(globalCtx, &globalCtx->colCtx, sp48.x, sp48.z, &sp3C, &sp40)) { + if (!WaterBox_GetSurface1(globalCtx, &globalCtx->colCtx, pos.x, pos.z, &waterSurface, &waterBox)) { if (sp34 > -100.0f) { this->unk_280 &= ~4; this->actionFunc = func_8098B88C; @@ -985,7 +985,7 @@ void func_8098B560(EnDg* this, GlobalContext* globalCtx) { sp46 = this->actor.wallYaw; } } else if (sp34 > -100.0f) { - if (sp3C < sp34) { + if (waterSurface < sp34) { this->unk_280 &= ~4; this->actionFunc = func_8098B88C; } else { diff --git a/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c b/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c index 945e9365d8..a2804c0a89 100644 --- a/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c +++ b/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c @@ -122,7 +122,7 @@ void EnDnb_Init(Actor* thisx, GlobalContext* globalCtx) { void EnDnb_Destroy(Actor* thisx, GlobalContext* globalCtx) { EnDnb* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void EnDnb_Update(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_En_Dns/z_en_dns.c b/src/overlays/actors/ovl_En_Dns/z_en_dns.c index 373e69880c..e75f1aa461 100644 --- a/src/overlays/actors/ovl_En_Dns/z_en_dns.c +++ b/src/overlays/actors/ovl_En_Dns/z_en_dns.c @@ -267,7 +267,7 @@ s32 func_8092CC68(GlobalContext* globalCtx) { if (!func_801690CC(globalCtx) && (player->actor.bgCheckFlags & 1) && (player->transformation != PLAYER_FORM_DEKU)) { bgId = player->actor.floorBgId; - if (func_800C99AC(&globalCtx->colCtx, player->actor.floorPoly, bgId) != 4) { + if (SurfaceType_GetSceneExitIndex(&globalCtx->colCtx, player->actor.floorPoly, bgId) != 4) { ret = true; } } diff --git a/src/overlays/actors/ovl_En_Dodongo/z_en_dodongo.c b/src/overlays/actors/ovl_En_Dodongo/z_en_dodongo.c index 72e7ed6069..693ea4ec4f 100644 --- a/src/overlays/actors/ovl_En_Dodongo/z_en_dodongo.c +++ b/src/overlays/actors/ovl_En_Dodongo/z_en_dodongo.c @@ -366,7 +366,7 @@ void func_80876930(EnDodongo* this, GlobalContext* globalCtx, Vec3f* arg2) { s16 temp2; f32 temp3; - if (func_800C9BB8(&globalCtx->colCtx, this->actor.floorPoly, this->actor.floorBgId) == 14) { + if (func_800C9BB8(&globalCtx->colCtx, this->actor.floorPoly, this->actor.floorBgId) == COLPOLY_SURFACE_SNOW) { sp80 = &D_8087932C; sp7C = &D_80879330; } else { diff --git a/src/overlays/actors/ovl_En_Encount2/z_en_encount2.c b/src/overlays/actors/ovl_En_Encount2/z_en_encount2.c index 20bd44fe71..a5f6b1d7af 100644 --- a/src/overlays/actors/ovl_En_Encount2/z_en_encount2.c +++ b/src/overlays/actors/ovl_En_Encount2/z_en_encount2.c @@ -107,8 +107,8 @@ void EnEncount2_Init(Actor* thisx, GlobalContext* globalCtx) { CollisionHeader* colHeader = NULL; DynaPolyActor_Init(&this->dyna, 0); - BgCheck_RelocateMeshHeader(&D_06002420, &colHeader); - this->dyna.bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, &this->dyna, colHeader); + CollisionHeader_GetVirtual(&D_06002420, &colHeader); + this->dyna.bgId = DynaPoly_SetBgActor(globalCtx, &globalCtx->colCtx.dyna, &this->dyna.actor, colHeader); ActorShape_Init(&this->dyna.actor.shape, 0.0f, func_800B3FC0, 25.0f); this->dyna.actor.colChkInfo.mass = MASS_IMMOVABLE; Collider_InitAndSetJntSph(globalCtx, &this->collider, &this->dyna.actor, &sJntSphInit, &this->colElement); @@ -139,7 +139,7 @@ void EnEncount2_Init(Actor* thisx, GlobalContext* globalCtx) { void EnEncount2_Destroy(Actor* thisx, GlobalContext* globalCtx) { EnEncount2* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); Collider_DestroyJntSph(globalCtx, &this->collider); } diff --git a/src/overlays/actors/ovl_En_Fish2/z_en_fish2.c b/src/overlays/actors/ovl_En_Fish2/z_en_fish2.c index 825f60cbe9..7b52e0a30b 100644 --- a/src/overlays/actors/ovl_En_Fish2/z_en_fish2.c +++ b/src/overlays/actors/ovl_En_Fish2/z_en_fish2.c @@ -268,7 +268,7 @@ s32 func_80B288E8(EnFish2* this, Vec3f vec, s32 arg2) { } s32 func_80B2899C(EnFish2* this, GlobalContext* globalCtx) { - if (func_800C5A64(&globalCtx->colCtx, &this->unk_2F4, this->unk_33C)) { + if (BgCheck_SphVsFirstWall(&globalCtx->colCtx, &this->unk_2F4, this->unk_33C)) { return true; } @@ -294,8 +294,8 @@ void func_80B289DC(EnFish2* this, GlobalContext* globalCtx) { this->actor.velocity.y = 0.0f; this->actor.gravity = 0.0f; } - } else if (func_800CA1AC(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, - &this->unk_334, &sp2C)) { + } else if (WaterBox_GetSurface1(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, + &this->unk_334, &sp2C)) { if ((this->unk_334 != BGCHECK_Y_MIN) && (this->actor.world.pos.y < (this->unk_334 - this->unk_2D8))) { this->actor.velocity.y = this->actor.world.rot.x * 0.001f * -0.1f; if (this->actionFunc == func_80B297FC) { @@ -373,8 +373,9 @@ void func_80B28C14(EnFish2* this, GlobalContext* globalCtx) { } } - if ((this->unk_334 == BGCHECK_Y_MIN) && !func_800CA1AC(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, - this->actor.world.pos.z, &this->unk_334, &waterbox)) { + if ((this->unk_334 == BGCHECK_Y_MIN) && + !WaterBox_GetSurface1(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, + &this->unk_334, &waterbox)) { this->unk_334 = this->actor.world.pos.y; } @@ -906,8 +907,8 @@ void func_80B2A498(EnFish2* this, GlobalContext* globalCtx) { (Animation_OnFrame(&this->skelAnime, 13.0f) || Animation_OnFrame(&this->skelAnime, 31.0f))) { WaterBox* sp78; - if (func_800CA1AC(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, - &this->unk_334, &sp78)) { + if (WaterBox_GetSurface1(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, + &this->unk_334, &sp78)) { Vec3f sp6C; s32 i; @@ -999,8 +1000,8 @@ void EnFish2_Update(Actor* thisx, GlobalContext* globalCtx2) { this->actor.world.pos.y = this->unk_2D4 + 0.1f; } - if (func_800CA1AC(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, - &this->unk_334, &sp6C)) { + if (WaterBox_GetSurface1(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, + &this->unk_334, &sp6C)) { if ((this->unk_334 != BGCHECK_Y_MIN) && (this->unk_334 - this->unk_2D8 < this->actor.world.pos.y)) { this->actor.world.pos.y = this->unk_334 - this->unk_2D8; } @@ -1012,8 +1013,8 @@ void EnFish2_Update(Actor* thisx, GlobalContext* globalCtx2) { f32 phi_f20 = 0; WaterBox* sp4C; - if (func_800CA1AC(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, - &this->unk_334, &sp4C)) { + if (WaterBox_GetSurface1(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, + this->actor.world.pos.z, &this->unk_334, &sp4C)) { phi_f20 = D_80B2B3A8[temp_s0_2] + (this->unk_334 - this->unk_2D8); phi_f2 = D_80B2B3A8[temp_s0_2 + 1] + this->unk_2D4; } @@ -1136,7 +1137,7 @@ void func_80B2AF80(EnFish2* this, GlobalContext* globalCtx) { ptr->unk_04.y += 1.0f + ((Rand_ZeroOne() - 0.3f) * 1.2f); ptr->unk_04.z += (0.3f + (Rand_ZeroOne() * 0.5f)) - 0.55f; sp8C = ptr->unk_04.y; - if (!func_800CA1AC(globalCtx, &globalCtx->colCtx, ptr->unk_04.x, ptr->unk_04.z, &sp8C, &sp90)) { + if (!WaterBox_GetSurface1(globalCtx, &globalCtx->colCtx, ptr->unk_04.x, ptr->unk_04.z, &sp8C, &sp90)) { ptr->unk_00 = 0; } else if (sp8C < ptr->unk_04.y) { Vec3f sp7C; diff --git a/src/overlays/actors/ovl_En_Fu/z_en_fu.c b/src/overlays/actors/ovl_En_Fu/z_en_fu.c index a898ea7cc2..558e1cf990 100644 --- a/src/overlays/actors/ovl_En_Fu/z_en_fu.c +++ b/src/overlays/actors/ovl_En_Fu/z_en_fu.c @@ -264,7 +264,7 @@ void func_80961D7C(GlobalContext* globalCtx) { EnBom* bomb = (EnBom*)explosive; if (bomb->actor.floorBgId != BGCHECK_SCENE) { - DynaPolyActor* fuKago = BgCheck_GetActorOfMesh(&globalCtx->colCtx, bomb->actor.floorBgId); + DynaPolyActor* fuKago = DynaPoly_GetActor(&globalCtx->colCtx, bomb->actor.floorBgId); if ((fuKago != NULL) && (fuKago->actor.id == ACTOR_EN_FU_KAGO)) { Math_SmoothStepToF(&bomb->actor.world.pos.x, fuKago->actor.world.pos.x, 0.1f, 1.0f, 0.5f); diff --git a/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c b/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c index e06c886893..22ea6a953e 100644 --- a/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c +++ b/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c @@ -472,17 +472,18 @@ s32 func_8093F6F8(EnGoroiwa* this, GlobalContext* globalCtx) { this->unk_1C4 = 0.0f; if (!(this->unk_1E5 & 0x20)) { - CollisionPoly* sp6C; + CollisionPoly* poly; Vec3f sp60; s32 pad[2]; - s32 sp54; + s32 bgId; Vec3f sp48; sp60.x = this->actor.world.pos.x; sp60.y = this->actor.world.pos.y + 50.0f; sp60.z = this->actor.world.pos.z; - temp_f14 = func_800C4188(globalCtx, &globalCtx->colCtx, &sp6C, &sp54, &this->actor, &sp60); + temp_f14 = + BgCheck_EntityRaycastFloor5_2(globalCtx, &globalCtx->colCtx, &poly, &bgId, &this->actor, &sp60); temp_f2 = temp_f14 - this->actor.world.pos.y; if (fabsf(temp_f2) < (fabsf(this->actor.velocity.y) + 0.01f)) { @@ -513,8 +514,8 @@ s32 func_8093F6F8(EnGoroiwa* this, GlobalContext* globalCtx) { WaterBox* sp44; f32 sp40; - if (func_800CA1E8(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &sp40, - &sp44)) { + if (WaterBox_GetSurface1_2(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, + &sp40, &sp44)) { if ((this->actor.world.pos.y + this->unk_1DC) <= sp40) { this->unk_1E5 |= 0x20; if (sp40 < (this->unk_1DC + sp78)) { @@ -1367,7 +1368,7 @@ void func_8094220C(EnGoroiwa* this, GlobalContext* globalCtx) { spC4.y = ptr->unk_00.y + 25.0f; spC4.z = ptr->unk_00.z; - ptr->unk_18 = func_800C411C(&globalCtx->colCtx, &ptr->unk_28, &spD0, &this->actor, &spC4); + ptr->unk_18 = BgCheck_EntityRaycastFloor5(&globalCtx->colCtx, &ptr->unk_28, &spD0, &this->actor, &spC4); if (ptr->unk_10 <= 0.0f) { Matrix_InsertRotation(ptr->unk_1C, ptr->unk_1E, ptr->unk_20, 0); @@ -1449,7 +1450,7 @@ void EnGoroiwa_Update(Actor* thisx, GlobalContext* globalCtx) { s32 pad; EnGoroiwa* this = THIS; Player* player = GET_PLAYER(globalCtx); - s32 sp60; + s32 bgId; s32 sp5C = false; Vec3f sp50; f32 sp4C; @@ -1511,10 +1512,10 @@ void EnGoroiwa_Update(Actor* thisx, GlobalContext* globalCtx) { sp50.x = this->actor.world.pos.x; sp50.y = this->actor.world.pos.y + 50.0f; sp50.z = this->actor.world.pos.z; - this->actor.floorHeight = - func_800C411C(&globalCtx->colCtx, &this->actor.floorPoly, &sp60, &this->actor, &sp50); + this->actor.floorHeight = BgCheck_EntityRaycastFloor5(&globalCtx->colCtx, &this->actor.floorPoly, + &bgId, &this->actor, &sp50); if (this->actor.floorHeight > BGCHECK_Y_MIN) { - this->actor.floorBgId = sp60; + this->actor.floorBgId = bgId; if (this->actor.world.pos.y <= (this->actor.floorHeight + 2.0f)) { this->actor.bgCheckFlags |= 1; } else { diff --git a/src/overlays/actors/ovl_En_Invadepoh/z_en_invadepoh.c b/src/overlays/actors/ovl_En_Invadepoh/z_en_invadepoh.c index 09b5cb9ae0..8a1feaf13a 100644 --- a/src/overlays/actors/ovl_En_Invadepoh/z_en_invadepoh.c +++ b/src/overlays/actors/ovl_En_Invadepoh/z_en_invadepoh.c @@ -3,7 +3,7 @@ * Overlay: ovl_En_Invadepoh * Description: Ranch nighttime actors */ - +#include "prevent_bss_reordering.h" #include "z_en_invadepoh.h" #include "overlays/actors/ovl_En_Door/z_en_door.h" @@ -906,7 +906,7 @@ s32 func_80B44234(EnInvadepoh* this, Vec3f* vec) { for (i = 0, arr = this->pathPoints; i < temp_s3; i++, arr++) { Math_Vec3s_ToVec3f(&sp48, arr); - distance = Math3D_DistanceSquared(&sp48, vec); + distance = Math3D_Vec3fDistSq(&sp48, vec); if (distance < min) { min = distance; ret = i; @@ -1384,7 +1384,7 @@ s32 func_80B45550(EnInvadepoh* this, GlobalContext* globalCtx, f32 range, s32 ar while (actorIterator != NULL) { if ((actorIterator->id == ACTOR_EN_DOOR) && (actorIterator->update != NULL) && (actorIterator->room == this->actor.room) && - Math3D_DistanceSquared(&actorIterator->world.pos, &this->actor.world.pos) < range) { + Math3D_Vec3fDistSq(&actorIterator->world.pos, &this->actor.world.pos) < range) { ((EnDoor*)actorIterator)->unk_1A7 = arg3; retVal = true; break; @@ -1435,7 +1435,7 @@ void func_80B457A0(EnInvadepoh* this) { for (i = 0; i < this->unk379; i++) { if ((D_80B50320[i] != NULL) && D_80B50320[i]->drawAlien) { - distanceSquared = Math3D_DistanceSquared(&D_80B50320[i]->actor.world.pos, &this->actor.world.pos); + distanceSquared = Math3D_Vec3fDistSq(&D_80B50320[i]->actor.world.pos, &this->actor.world.pos); if (distanceSquared < phi_f20) { phi_f20 = distanceSquared; phi_s5 = i; @@ -2880,7 +2880,7 @@ void func_80B49454(EnInvadepoh* this, GlobalContext* globalCtx) { } Math_Vec3f_Sum(&D_80B4EDD0[this->unk3AC], &this->actor.home.pos, &sp30); - if (Math3D_DistanceSquared(&this->actor.world.pos, &sp30) < SQ(400.0f)) { + if (Math3D_Vec3fDistSq(&this->actor.world.pos, &sp30) < SQ(400.0f)) { this->actor.speedXZ *= 0.8f; } else { Math_StepToF(&this->actor.speedXZ, 170.0f, 21.0f); @@ -3614,7 +3614,7 @@ void func_80B4B564(EnInvadepoh* this, GlobalContext* globalCtx) { if (this->unk3BC >= 0) { Math_Vec3s_ToVec3f(&sp28, &this->pathPoints[this->unk3BC]); - temp_f0 = Math3D_DistanceSquared(&this->actor.world.pos, &sp28); + temp_f0 = Math3D_Vec3fDistSq(&this->actor.world.pos, &sp28); if (temp_f0 < SQ(80.0f)) { this->actor.speedXZ *= 0.85f; } else if (temp_f0 < SQ(150.0f)) { @@ -3808,7 +3808,7 @@ void func_80B4BC4C(EnInvadepoh* this, GlobalContext* globalCtx) { func_800B4AEC(globalCtx, &this->actor, 50.0f); func_80B4516C(this); Math_StepToS(&this->behaviorInfo.unk4C, 0xBB8, 0x1F5); - if (Math3D_DistanceSquared(&this->actor.prevPos, &this->actor.world.pos) > SQ(0.01f)) { + if (Math3D_Vec3fDistSq(&this->actor.prevPos, &this->actor.world.pos) > SQ(0.01f)) { Math_SmoothStepToS(&this->actor.shape.rot.y, Math_Vec3f_Yaw(&this->actor.prevPos, &this->actor.world.pos), 3, this->behaviorInfo.unk4C, 0x1F4); } diff --git a/src/overlays/actors/ovl_En_Mm/z_en_mm.c b/src/overlays/actors/ovl_En_Mm/z_en_mm.c index ed4c155443..00bf38f8ab 100644 --- a/src/overlays/actors/ovl_En_Mm/z_en_mm.c +++ b/src/overlays/actors/ovl_En_Mm/z_en_mm.c @@ -148,7 +148,7 @@ void func_80965DB4(EnMm* this, GlobalContext* globalCtx) { temp_f2 = sqrtf(SQ(temp_f14) + SQ(temp_f12)); if ((temp_f2 < this->actor.speedXZ) || - (func_800C9C74(&globalCtx->colCtx, this->actor.floorPoly, this->actor.floorBgId) == 1)) { + (SurfaceType_GetSlope(&globalCtx->colCtx, this->actor.floorPoly, this->actor.floorBgId) == 1)) { this->actor.speedXZ = CLAMP_MAX(temp_f2, 16.0f); this->actor.world.rot.y = Math_FAtan2F(temp_f12, temp_f14); } diff --git a/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c b/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c index b7be4211bc..0969c123ab 100644 --- a/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c +++ b/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c @@ -125,7 +125,7 @@ s32 func_80A68860(EnMushi2* this, GlobalContext* globalCtx) { s32 pad; s32 sp40; CollisionPoly* sp3C; - f32 temp_f0 = func_800C411C(&globalCtx->colCtx, &sp3C, &sp40, &this->actor, &this->actor.world.pos); + f32 temp_f0 = BgCheck_EntityRaycastFloor5(&globalCtx->colCtx, &sp3C, &sp40, &this->actor, &this->actor.world.pos); WaterBox* sp34; f32 sp30; @@ -133,7 +133,8 @@ s32 func_80A68860(EnMushi2* this, GlobalContext* globalCtx) { return true; } - return func_800CA1E8(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &sp30, &sp34); + return WaterBox_GetSurface1_2(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, + &sp30, &sp34); } s32 func_80A68910(EnMushi2* this, GlobalContext* globalCtx) { @@ -446,7 +447,7 @@ void func_80A69424(EnMushi2* this, GlobalContext* globalCtx) { s32 func_80A69468(EnMushi2* this, GlobalContext* globalCtx) { s32 pad; Vec3f sp68; - Vec3f sp5C; + Vec3f posB; Vec3f sp50; f32 x; f32 y; @@ -462,12 +463,12 @@ s32 func_80A69468(EnMushi2* this, GlobalContext* globalCtx) { y = (this->unk_328.y * 4.0f); z = (this->unk_328.z * 4.0f); - sp5C.x = (x + sp50.x) + this->actor.world.pos.x; - sp5C.y = (y + sp50.y) + this->actor.world.pos.y; - sp5C.z = (z + sp50.z) + this->actor.world.pos.z; + posB.x = (x + sp50.x) + this->actor.world.pos.x; + posB.y = (y + sp50.y) + this->actor.world.pos.y; + posB.z = (z + sp50.z) + this->actor.world.pos.z; - if (func_800C55C4(&globalCtx->colCtx, &this->actor.prevPos, &sp5C, &this->unk_33C, &this->unk_334, 1, 1, 1, 1, - &this->unk_338)) { + if (BgCheck_EntityLineTest1(&globalCtx->colCtx, &this->actor.prevPos, &posB, &this->unk_33C, &this->poly, true, + true, true, true, &this->polyBgId)) { this->unk_30C |= 6; return true; } @@ -476,18 +477,19 @@ s32 func_80A69468(EnMushi2* this, GlobalContext* globalCtx) { s32 func_80A6958C(EnMushi2* this, GlobalContext* globalCtx) { s32 pad; - Vec3f sp48; - Vec3f sp3C; + Vec3f posA; + Vec3f posB; - sp48.x = (2.0f * this->unk_31C.x) + this->actor.world.pos.x; - sp48.y = (2.0f * this->unk_31C.y) + this->actor.world.pos.y; - sp48.z = (2.0f * this->unk_31C.z) + this->actor.world.pos.z; + posA.x = (2.0f * this->unk_31C.x) + this->actor.world.pos.x; + posA.y = (2.0f * this->unk_31C.y) + this->actor.world.pos.y; + posA.z = (2.0f * this->unk_31C.z) + this->actor.world.pos.z; - sp3C.x = (this->unk_31C.x * -4.0f) + this->actor.world.pos.x; - sp3C.y = (this->unk_31C.y * -4.0f) + this->actor.world.pos.y; - sp3C.z = (this->unk_31C.z * -4.0f) + this->actor.world.pos.z; + posB.x = (this->unk_31C.x * -4.0f) + this->actor.world.pos.x; + posB.y = (this->unk_31C.y * -4.0f) + this->actor.world.pos.y; + posB.z = (this->unk_31C.z * -4.0f) + this->actor.world.pos.z; - if (func_800C55C4(&globalCtx->colCtx, &sp48, &sp3C, &this->unk_33C, &this->unk_334, 1, 1, 1, 1, &this->unk_338)) { + if (BgCheck_EntityLineTest1(&globalCtx->colCtx, &posA, &posB, &this->unk_33C, &this->poly, true, true, true, true, + &this->polyBgId)) { this->unk_30C |= 0xA; return true; } @@ -496,21 +498,22 @@ s32 func_80A6958C(EnMushi2* this, GlobalContext* globalCtx) { s32 func_80A6969C(EnMushi2* this, GlobalContext* globalCtx) { s32 pad; - Vec3f sp50; - Vec3f sp44; + Vec3f posA; + Vec3f posB; Vec3f sp38; sp38.x = this->unk_31C.x * -4.0f; sp38.y = this->unk_31C.y * -4.0f; sp38.z = this->unk_31C.z * -4.0f; - Math_Vec3f_Sum(&sp38, &this->actor.world.pos, &sp50); + Math_Vec3f_Sum(&sp38, &this->actor.world.pos, &posA); - sp44.x = this->actor.prevPos.x + sp38.x + (this->unk_328.x * -4.0f); - sp44.y = this->actor.prevPos.y + sp38.y + (this->unk_328.y * -4.0f); - sp44.z = this->actor.prevPos.z + sp38.z + (this->unk_328.z * -4.0f); + posB.x = this->actor.prevPos.x + sp38.x + (this->unk_328.x * -4.0f); + posB.y = this->actor.prevPos.y + sp38.y + (this->unk_328.y * -4.0f); + posB.z = this->actor.prevPos.z + sp38.z + (this->unk_328.z * -4.0f); - if (func_800C55C4(&globalCtx->colCtx, &sp50, &sp44, &this->unk_33C, &this->unk_334, 1, 1, 1, 1, &this->unk_338)) { + if (BgCheck_EntityLineTest1(&globalCtx->colCtx, &posA, &posB, &this->unk_33C, &this->poly, true, true, true, true, + &this->polyBgId)) { this->unk_30C |= (0x10 | 0x2); return true; } @@ -519,8 +522,8 @@ s32 func_80A6969C(EnMushi2* this, GlobalContext* globalCtx) { void func_80A697C4(EnMushi2* this, GlobalContext* globalCtx) { s32 pad; - s32 sp38 = this->unk_334; - s32 sp34 = this->unk_338; + CollisionPoly* poly = this->poly; + s32 bgId = this->polyBgId; if (!(this->unk_30C & (0x10 | 0x4))) { WaterBox* sp30; @@ -531,8 +534,8 @@ void func_80A697C4(EnMushi2* this, GlobalContext* globalCtx) { func_80A6969C(this, globalCtx); } - if (func_800CA1E8(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &sp2C, - &sp30)) { + if (WaterBox_GetSurface1_2(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, + &sp2C, &sp30)) { this->actor.depthInWater = sp2C - this->actor.world.pos.y; if (this->actor.depthInWater >= 1.0f) { this->unk_30C |= 0x20; @@ -547,11 +550,11 @@ void func_80A697C4(EnMushi2* this, GlobalContext* globalCtx) { if (this->unk_30C & 4) { Math_Vec3f_Copy(&this->actor.world.pos, &this->unk_33C); - if (func_80A691EC(this, this->unk_334, 0.4f) == 1) { + if (func_80A691EC(this, this->poly, 0.4f) == 1) { this->unk_30C &= ~0x4; } } else if (this->unk_30C & 0x10) { - if (func_80A691EC(this, this->unk_334, 0.4f) == 1) { + if (func_80A691EC(this, this->poly, 0.4f) == 1) { this->unk_30C &= ~0x10; Math_Vec3f_Copy(&this->actor.world.pos, &this->unk_33C); } else { @@ -560,13 +563,13 @@ void func_80A697C4(EnMushi2* this, GlobalContext* globalCtx) { } else if (this->unk_30C & 8) { if (!(this->unk_30C & 0x20)) { Math_Vec3f_Copy(&this->actor.world.pos, &this->unk_33C); - func_80A691EC(this, this->unk_334, -1.0f); + func_80A691EC(this, this->poly, -1.0f); } } else if (!(this->unk_30C & 2)) { Math_Vec3f_Copy(&this->actor.world.pos, &this->actor.prevPos); Math_Vec3f_Copy(&this->unk_33C, &this->actor.prevPos); - this->unk_334 = sp38; - this->unk_338 = sp34; + this->poly = poly; + this->polyBgId = bgId; } } @@ -580,7 +583,7 @@ s32 func_80A699E4(EnMushi2* this, GlobalContext* globalCtx) { f32 y = (2.0f * this->unk_328.y) + this->actor.world.pos.y; f32 z = (2.0f * this->unk_328.z) + this->actor.world.pos.z; - if (func_800CA1E8(globalCtx, &globalCtx->colCtx, x, z, &sp3C, &sp40) && (y <= sp3C)) { + if (WaterBox_GetSurface1_2(globalCtx, &globalCtx->colCtx, x, z, &sp3C, &sp40) && (y <= sp3C)) { return true; } } @@ -676,13 +679,13 @@ void func_80A69D3C(EnMushi2* this) { s32 func_80A69EE4(EnMushi2* this, GlobalContext* globalCtx) { s32 pad; - WaterBox* sp30; - f32 sp2C; - s32 sp28; + WaterBox* waterBox; + f32 waterSurface; + s32 bgId; - if (func_800C9EBC(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &sp2C, &sp30, - &sp28) && - (this->actor.world.pos.y < sp2C)) { + if (WaterBox_GetSurfaceImpl(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, + &waterSurface, &waterBox, &bgId) && + (this->actor.world.pos.y < waterSurface)) { return true; } return false; @@ -1083,8 +1086,8 @@ void func_80A6B0D8(EnMushi2* this, GlobalContext* globalCtx) { Vec3f sp48; s32 sp44 = 0; - if (this->unk_334 != 0) { - u32 temp_v0 = func_800C99D4(&globalCtx->colCtx, this->unk_334, this->unk_338); + if (this->poly != NULL) { + u32 temp_v0 = func_800C99D4(&globalCtx->colCtx, this->poly, this->polyBgId); if ((temp_v0 == 5) || (temp_v0 == 14) || (temp_v0 == 15)) { sp44 = 1; } @@ -1151,8 +1154,8 @@ void EnMushi2_Update(Actor* thisx, GlobalContext* globalCtx) { this->unk_358 = 1.0f; } - temp = this->unk_338; - if ((temp != 50) && + temp = this->polyBgId; + if ((temp != BGCHECK_SCENE) && ((this->actionFunc == func_80A6A5C0) || (this->actionFunc == func_80A6A824) || (this->actionFunc == func_80A6A9E4) || (this->actionFunc == func_80A6B0D8)) && BgCheck2_UpdateActorAttachedToMesh(&globalCtx->colCtx, temp, &this->actor)) { @@ -1176,13 +1179,12 @@ void EnMushi2_Update(Actor* thisx, GlobalContext* globalCtx) { if (this->unk_34C != 0) { sp4C = 0.0f; - this->unk_354 = Math3D_DistanceSquared(&this->actor.world.pos, &this->unk_34C->actor.world.pos); + this->unk_354 = Math3D_Vec3fDistSq(&this->actor.world.pos, &this->unk_34C->actor.world.pos); if (this->unk_354 < this->unk_350) { - f32 dist = Math3D_NormalizedSignedDistanceFromPlane( - COLPOLY_GET_NORMAL(this->unk_34C->actor.floorPoly->normal.x), - COLPOLY_GET_NORMAL(this->unk_34C->actor.floorPoly->normal.y), - COLPOLY_GET_NORMAL(this->unk_34C->actor.floorPoly->normal.z), this->unk_34C->actor.floorPoly->dist, - &this->actor.world.pos); + f32 dist = Math3D_DistPlaneToPos(COLPOLY_GET_NORMAL(this->unk_34C->actor.floorPoly->normal.x), + COLPOLY_GET_NORMAL(this->unk_34C->actor.floorPoly->normal.y), + COLPOLY_GET_NORMAL(this->unk_34C->actor.floorPoly->normal.z), + this->unk_34C->actor.floorPoly->dist, &this->actor.world.pos); if (fabsf(dist) < 3.0f) { sp4C = 1.9f; diff --git a/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.h b/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.h index 5a95ee49ae..f773cd7460 100644 --- a/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.h +++ b/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.h @@ -26,8 +26,8 @@ typedef struct EnMushi2 { /* 0x0310 */ Vec3f unk_310; /* 0x031C */ Vec3f unk_31C; /* 0x0328 */ Vec3f unk_328; - /* 0x0334 */ CollisionPoly* unk_334; - /* 0x0338 */ u32 unk_338; + /* 0x0334 */ CollisionPoly* poly; + /* 0x0338 */ s32 polyBgId; /* 0x033C */ Vec3f unk_33C; /* 0x0348 */ f32 unk_348; /* 0x034C */ struct ObjBean* unk_34C; diff --git a/src/overlays/actors/ovl_En_Niw/z_en_niw.c b/src/overlays/actors/ovl_En_Niw/z_en_niw.c index f72add584b..3eadcc15ec 100644 --- a/src/overlays/actors/ovl_En_Niw/z_en_niw.c +++ b/src/overlays/actors/ovl_En_Niw/z_en_niw.c @@ -810,7 +810,7 @@ void EnNiw_Update(Actor* thisx, GlobalContext* globalCtx) { Actor_UpdateBgCheckInfo(globalCtx, &this->actor, 20.0f, 20.0f, 60.0f, 0x1F); - if ((this->actor.floorHeight <= BGCHECK_Y_MIN) || (this->actor.floorHeight >= 32000.0f)) { + if (this->actor.floorHeight <= BGCHECK_Y_MIN || this->actor.floorHeight >= BGCHECK_Y_MAX) { // if cucco is off the map? Vec3f camera; camera.x = globalCtx->view.at.x - globalCtx->view.eye.x; diff --git a/src/overlays/actors/ovl_En_Nutsball/z_en_nutsball.c b/src/overlays/actors/ovl_En_Nutsball/z_en_nutsball.c index 9d90c4ec61..d2140a16e3 100644 --- a/src/overlays/actors/ovl_En_Nutsball/z_en_nutsball.c +++ b/src/overlays/actors/ovl_En_Nutsball/z_en_nutsball.c @@ -94,7 +94,7 @@ void EnNutsball_Update(Actor* thisx, GlobalContext* globalCtx) { Vec3s worldRot; Vec3f spawnBurstPos; f32 spdXZ; - u32 bgId; + s32 bgId; CollisionPoly* poly; if (!(player->stateFlags1 & 0x300000C0)) { @@ -140,8 +140,8 @@ void EnNutsball_Update(Actor* thisx, GlobalContext* globalCtx) { if (this->actor.bgCheckFlags & 8) { if (func_800C9A4C(&globalCtx2->colCtx, this->actor.wallPoly, this->actor.wallBgId) & 0x30) { this->actor.bgCheckFlags &= ~8; - if (func_800C55C4(&globalCtx2->colCtx, &this->actor.prevPos, &worldPos, &this->actor.world.pos, &poly, - 1, 0, 0, 1, &bgId)) { + if (BgCheck_EntityLineTest1(&globalCtx2->colCtx, &this->actor.prevPos, &worldPos, + &this->actor.world.pos, &poly, true, false, false, true, &bgId)) { if (func_800C9A4C(&globalCtx2->colCtx, poly, bgId) & 0x30) { this->actor.world.pos.x += this->actor.velocity.x * 0.01f; this->actor.world.pos.z += this->actor.velocity.z * 0.01f; diff --git a/src/overlays/actors/ovl_En_Ot/z_en_ot.c b/src/overlays/actors/ovl_En_Ot/z_en_ot.c index 5018a6bc2d..d6c95bad6e 100644 --- a/src/overlays/actors/ovl_En_Ot/z_en_ot.c +++ b/src/overlays/actors/ovl_En_Ot/z_en_ot.c @@ -138,7 +138,7 @@ void func_80B5B2E0(GlobalContext* globalCtx, Vec3f* pos, s16 params, Vec3f* vec, void EnOt_Init(Actor* thisx, GlobalContext* globalCtx) { s32 pad; EnOt* this = THIS; - s32 sp74; + s32 bgId; s32 pad2; Vec3f sp64; Vec3f sp58; @@ -183,9 +183,9 @@ void EnOt_Init(Actor* thisx, GlobalContext* globalCtx) { switch (this->unk_344) { case 0: - this->actor.world.pos.y = - func_800C40B4(&globalCtx->colCtx, &this->actor.floorPoly, &sp74, &this->actor.world.pos) + - 50.0f; + this->actor.world.pos.y = BgCheck_EntityRaycastFloor3(&globalCtx->colCtx, &this->actor.floorPoly, + &bgId, &this->actor.world.pos) + + 50.0f; if (gSaveContext.weekEventReg[84] & 0x10) { Matrix_RotateY(this->actor.shape.rot.y, MTXMODE_NEW); Matrix_GetStateTranslationAndScaledZ(52.519997f, &sp64); @@ -242,7 +242,8 @@ void EnOt_Init(Actor* thisx, GlobalContext* globalCtx) { } else { Player* player = GET_PLAYER(globalCtx); - if (func_800C9B90(&globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId)) { + if (SurfaceType_IsHorseBlocked(&globalCtx->colCtx, player->actor.floorPoly, + player->actor.floorBgId)) { Actor_SetScale(&this->actor, 0.0f); func_80B5C910(this, globalCtx); } else { @@ -1007,7 +1008,7 @@ void func_80B5DB6C(Actor* thisx, GlobalContext* globalCtx) { s32 sp4C = false; if (gSaveContext.weekEventReg[13] & 1) { - if (!func_800C9B90(&globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId)) { + if (!SurfaceType_IsHorseBlocked(&globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId)) { sp4C = true; } } @@ -1021,7 +1022,7 @@ void func_80B5DB6C(Actor* thisx, GlobalContext* globalCtx) { temp->actor.cutscene = this->actor.cutscene; this->unk_32C |= 8; } - } else if (func_800C9B90(&globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId)) { + } else if (SurfaceType_IsHorseBlocked(&globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId)) { player->unk_B2B = 29; } } diff --git a/src/overlays/actors/ovl_En_Pametfrog/z_en_pametfrog.c b/src/overlays/actors/ovl_En_Pametfrog/z_en_pametfrog.c index b4f84e9021..8993cb14a4 100644 --- a/src/overlays/actors/ovl_En_Pametfrog/z_en_pametfrog.c +++ b/src/overlays/actors/ovl_En_Pametfrog/z_en_pametfrog.c @@ -370,7 +370,7 @@ void EnPametfrog_StopCutscene(EnPametfrog* this, GlobalContext* globalCtx) { void EnPametfrog_PlaceSnapper(EnPametfrog* this, GlobalContext* globalCtx) { CollisionPoly* poly; - u32 bgId; + s32 bgId; Vec3f vec1; Vec3f vec2; Vec3f vec3; @@ -386,7 +386,7 @@ void EnPametfrog_PlaceSnapper(EnPametfrog* this, GlobalContext* globalCtx) { vec3.x = this->actor.child->world.pos.x; vec3.y = this->actor.child->world.pos.y - 150.0f; vec3.z = this->actor.child->world.pos.z; - if (func_800C55C4(&globalCtx->colCtx, &vec2, &vec3, &vec1, &poly, 0, 1, 0, 1, &bgId) != 0) { + if (BgCheck_EntityLineTest1(&globalCtx->colCtx, &vec2, &vec3, &vec1, &poly, false, true, false, true, &bgId)) { this->actor.child->floorHeight = vec1.y; } else { this->actor.child->floorHeight = this->actor.home.pos.y; @@ -615,8 +615,8 @@ void EnPametfrog_WallCrawl(EnPametfrog* this, GlobalContext* globalCtx) { Vec3f worldPos1; Vec3f worldPos2; f32 doubleSpeedXZ; - u32 bgId1; - u32 bgId2; + s32 bgId1; + s32 bgId2; s32 isSuccess = false; if (this->freezeTimer > 0) { @@ -632,11 +632,13 @@ void EnPametfrog_WallCrawl(EnPametfrog* this, GlobalContext* globalCtx) { vec2.x = this->actor.world.pos.x - this->unk_2DC.x * 25.0f; vec2.y = this->actor.world.pos.y - this->unk_2DC.y * 25.0f; vec2.z = this->actor.world.pos.z - this->unk_2DC.z * 25.0f; - if (func_800C55C4(&globalCtx->colCtx, &vec1, &vec2, &worldPos2, &poly2, 1, 1, 1, 1, &bgId2) != 0) { + if (BgCheck_EntityLineTest1(&globalCtx->colCtx, &vec1, &vec2, &worldPos2, &poly2, true, true, true, true, + &bgId2)) { vec2.x = this->unk_2D0.x * doubleSpeedXZ + vec1.x; vec2.y = this->unk_2D0.y * doubleSpeedXZ + vec1.y; vec2.z = this->unk_2D0.z * doubleSpeedXZ + vec1.z; - if (func_800C55C4(&globalCtx->colCtx, &vec1, &vec2, &worldPos1, &poly1, 1, 1, 1, 1, &bgId1) != 0) { + if (BgCheck_EntityLineTest1(&globalCtx->colCtx, &vec1, &vec2, &worldPos1, &poly1, true, true, true, true, + &bgId1)) { isSuccess = func_8086A2CC(this, poly1); Math_Vec3f_Copy(&this->actor.world.pos, &worldPos1); this->actor.floorBgId = bgId1; diff --git a/src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c b/src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c index 57fca7fd7b..1bb44aa022 100644 --- a/src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c +++ b/src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c @@ -901,8 +901,8 @@ void EnPoSisters_Update(Actor* thisx, GlobalContext* globalCtx) { s32 pad; EnPoSisters* this = THIS; f32 temp_f2; - Vec3f sp40; - s32 sp3C; + Vec3f checkPos; + s32 bgId; if (this->collider.base.atFlags & AT_HIT) { this->collider.base.atFlags &= ~AT_HIT; @@ -925,10 +925,11 @@ void EnPoSisters_Update(Actor* thisx, GlobalContext* globalCtx) { if (this->unk_191 & 0x10) { Actor_UpdateBgCheckInfo(globalCtx, &this->actor, 20.0f, 20.0f, 0.0f, 5); } else { - sp40.x = this->actor.world.pos.x; - sp40.y = this->actor.world.pos.y + 10.0f; - sp40.z = this->actor.world.pos.z; - this->actor.floorHeight = func_800C411C(&globalCtx->colCtx, &this->actor.floorPoly, &sp3C, &this->actor, &sp40); + checkPos.x = this->actor.world.pos.x; + checkPos.y = this->actor.world.pos.y + 10.0f; + checkPos.z = this->actor.world.pos.z; + this->actor.floorHeight = + BgCheck_EntityRaycastFloor5(&globalCtx->colCtx, &this->actor.floorPoly, &bgId, &this->actor, &checkPos); } this->actor.shape.shadowAlpha = this->unk_229; diff --git a/src/overlays/actors/ovl_En_Suttari/z_en_suttari.c b/src/overlays/actors/ovl_En_Suttari/z_en_suttari.c index 10994fe102..0e6b20f3dd 100644 --- a/src/overlays/actors/ovl_En_Suttari/z_en_suttari.c +++ b/src/overlays/actors/ovl_En_Suttari/z_en_suttari.c @@ -201,14 +201,14 @@ void EnSuttari_UpdateTime(void) { } s32 func_80BAA904(EnSuttari* this, GlobalContext* globalCtx) { - Vec3f sp2C; + Vec3f pos; s32 pad; - s32 sp24; + CollisionPoly* poly; - sp2C.x = (Math_SinS(this->actor.world.rot.y) * 50.0f) + this->actor.world.pos.x; - sp2C.y = this->actor.world.pos.y + 100.0f; - sp2C.z = (Math_CosS(this->actor.world.rot.y) * 50.0f) + this->actor.world.pos.z; - if (func_800C4000(globalCtx, &globalCtx->colCtx, &sp24, &sp2C) > -500.0f) { + pos.x = (Math_SinS(this->actor.world.rot.y) * 50.0f) + this->actor.world.pos.x; + pos.y = this->actor.world.pos.y + 100.0f; + pos.z = (Math_CosS(this->actor.world.rot.y) * 50.0f) + this->actor.world.pos.z; + if (BgCheck_EntityRaycastFloor2(globalCtx, &globalCtx->colCtx, &poly, &pos) > -500.0f) { return false; } return true; diff --git a/src/overlays/actors/ovl_En_Sw/z_en_sw.c b/src/overlays/actors/ovl_En_Sw/z_en_sw.c index 31f4d19226..221de85014 100644 --- a/src/overlays/actors/ovl_En_Sw/z_en_sw.c +++ b/src/overlays/actors/ovl_En_Sw/z_en_sw.c @@ -360,11 +360,12 @@ void func_808D93BC(EnSw* this) { this->actor.world.rot.x = -this->actor.world.rot.x; } -s32 func_808D9440(GlobalContext* globalCtx, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, CollisionPoly** arg4, u32* arg5) { +s32 func_808D9440(GlobalContext* globalCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, + s32* bgId) { s32 ret = false; - if (func_800C55C4(&globalCtx->colCtx, arg1, arg2, arg3, arg4, 1, 1, 1, 1, arg5) && - !(func_800C9A4C(&globalCtx->colCtx, *arg4, *arg5) & 0x30)) { + if (BgCheck_EntityLineTest1(&globalCtx->colCtx, posA, posB, posResult, outPoly, true, true, true, true, bgId) && + !(func_800C9A4C(&globalCtx->colCtx, *outPoly, *bgId) & 0x30)) { ret = true; } return ret; @@ -379,16 +380,16 @@ void func_808D94D0(EnSw* this, GlobalContext* globalCtx, s32 arg2, s32 arg3, s16 Vec3f sp84; Vec3f sp78; Vec3f sp6C; - u32 sp68; - u32 sp64; + s32 sp68; + s32 sp64; Actor* thisx = &this->actor; f32 temp_f20; s32 i; spA4 = NULL; spA0 = NULL; - sp68 = 50; - sp64 = 50; + sp68 = BGCHECK_SCENE; + sp64 = BGCHECK_SCENE; func_808D90F0(this, arg3, arg4); this->actor.speedXZ = this->unk_44C; temp_f20 = thisx->speedXZ * 2.0f; diff --git a/src/overlays/actors/ovl_En_Tite/z_en_tite.c b/src/overlays/actors/ovl_En_Tite/z_en_tite.c index 58e41b530b..61a12cfb0a 100644 --- a/src/overlays/actors/ovl_En_Tite/z_en_tite.c +++ b/src/overlays/actors/ovl_En_Tite/z_en_tite.c @@ -251,13 +251,13 @@ void func_80893BCC(EnTite* this, GlobalContext* globalCtx) { s32 j; if (this->actor.bgCheckFlags & 2) { - u32 temp_v0 = func_800C9BB8(&globalCtx->colCtx, this->actor.floorPoly, this->actor.floorBgId); + u32 surface = func_800C9BB8(&globalCtx->colCtx, this->actor.floorPoly, this->actor.floorBgId); - if ((temp_v0 == 0) || (temp_v0 == 1)) { + if ((surface == COLPOLY_SURFACE_GROUND) || (surface == COLPOLY_SURFACE_SAND)) { for (i = 5; i < ARRAY_COUNT(this->unk_2D0); i++) { func_800BBFB0(globalCtx, &this->unk_2D0[i], 1.0f, 2, 80, 15, 1); } - } else if (temp_v0 == 14) { + } else if (surface == COLPOLY_SURFACE_SNOW) { Vec3f* ptr; for (i = 5; i < ARRAY_COUNT(this->unk_2D0); i++) { diff --git a/src/overlays/actors/ovl_En_Tk/z_en_tk.c b/src/overlays/actors/ovl_En_Tk/z_en_tk.c index 0fd752c431..07bf625d21 100644 --- a/src/overlays/actors/ovl_En_Tk/z_en_tk.c +++ b/src/overlays/actors/ovl_En_Tk/z_en_tk.c @@ -1046,8 +1046,8 @@ s32 func_80AEE86C(EnTk* this, GlobalContext* globalCtx) { Vec3f sp28; Lib_Vec3f_TranslateAndRotateY(&this->actor.world.pos, this->actor.shape.rot.y, &D_80AEFA78, &sp28); - if ((func_800C40B4(&globalCtx->colCtx, &sp38, &sp34, &sp28) != BGCHECK_Y_MIN) && - (func_800C9BB8(&globalCtx->colCtx, sp38, sp34) == 1) && (this->unk_2D0 == 1) && + if ((BgCheck_EntityRaycastFloor3(&globalCtx->colCtx, &sp38, &sp34, &sp28) != BGCHECK_Y_MIN) && + (func_800C9BB8(&globalCtx->colCtx, sp38, sp34) == 1) && (this->unk_2D0 == (u32)1) && (this->actor.xyzDistToPlayerSq <= SQ(115.0f)) && func_80AEE7E0(&this->actor.world.pos, 100.0f, this->unk_324, this->unk_36C) && (((this->unk_2CA & 2) && (Math_Vec3f_DistXZ(&this->unk_300, &sp28) >= 100.0f)) || !(this->unk_2CA & 2)) && @@ -1131,7 +1131,8 @@ void func_80AEEB88(EnTk* this, GlobalContext* globalCtx) { sp68.y = this->actor.world.pos.y + 50.0f; sp68.z += this->actor.world.pos.z; - temp = func_800C40B4(&globalCtx->colCtx, &this->actor.floorPoly, &sp74, &sp68) - this->actor.world.pos.y; + temp = BgCheck_EntityRaycastFloor3(&globalCtx->colCtx, &this->actor.floorPoly, &sp74, &sp68) - + this->actor.world.pos.y; if (temp <= -80.0f) { break; } @@ -1160,7 +1161,7 @@ void func_80AEED38(EnTk* this, GlobalContext* globalCtx) { sp58.y += 30.0f; sp58.z += Math_CosS(sp56) * 20.0f; - if (func_800C5A64(&globalCtx->colCtx, &sp58, 20.0f)) { + if (BgCheck_SphVsFirstWall(&globalCtx->colCtx, &sp58, 20.0f)) { Math_Vec3f_Copy(&sp48, &this->actor.world.pos); sp56 = BINANG_ADD(this->actor.shape.rot.y, 0x4000); sp48.x += (Math_SinS(sp56) * 20.0f); @@ -1173,8 +1174,8 @@ void func_80AEED38(EnTk* this, GlobalContext* globalCtx) { sp3C.y += 30.0f; sp3C.z += Math_CosS(sp56) * 20.0f; - if (func_800C5A64(&globalCtx->colCtx, &sp48, 20.0f)) { - if (func_800C5A64(&globalCtx->colCtx, &sp3C, 20.0f)) { + if (BgCheck_SphVsFirstWall(&globalCtx->colCtx, &sp48, 20.0f)) { + if (BgCheck_SphVsFirstWall(&globalCtx->colCtx, &sp3C, 20.0f)) { this->unk_2CC = this->actor.shape.rot.y - 0x4000; } else { this->unk_2CC = this->actor.shape.rot.y - 0x4000; @@ -1297,7 +1298,7 @@ void EnTk_Update(Actor* thisx, GlobalContext* globalCtx) { this->unk_2CA &= ~1; if (this->actor.floorBgId != BGCHECK_SCENE) { - BgDanpeiMovebg* platform = (BgDanpeiMovebg*)BgCheck_GetActorOfMesh(&globalCtx->colCtx, this->actor.floorBgId); + BgDanpeiMovebg* platform = (BgDanpeiMovebg*)DynaPoly_GetActor(&globalCtx->colCtx, this->actor.floorBgId); if (platform != NULL) { if (platform->dyna.actor.id == ACTOR_BG_DANPEI_MOVEBG) { diff --git a/src/overlays/actors/ovl_Obj_Aqua/z_obj_aqua.c b/src/overlays/actors/ovl_Obj_Aqua/z_obj_aqua.c index 2b4b762f7b..2b3a3189fc 100644 --- a/src/overlays/actors/ovl_Obj_Aqua/z_obj_aqua.c +++ b/src/overlays/actors/ovl_Obj_Aqua/z_obj_aqua.c @@ -133,8 +133,8 @@ s32 func_80ACBA60(ObjAqua* this, GlobalContext* globalCtx) { f32 ySurface; s32 bgId; - if (func_800C9EBC(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &ySurface, - &waterBox, &bgId) && + if (WaterBox_GetSurfaceImpl(globalCtx, &globalCtx->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, + &ySurface, &waterBox, &bgId) && (this->actor.world.pos.y < ySurface)) { return true; } diff --git a/src/overlays/actors/ovl_Obj_Bell/z_obj_bell.c b/src/overlays/actors/ovl_Obj_Bell/z_obj_bell.c index 4a70dc0ec1..55b8f301f5 100644 --- a/src/overlays/actors/ovl_Obj_Bell/z_obj_bell.c +++ b/src/overlays/actors/ovl_Obj_Bell/z_obj_bell.c @@ -275,7 +275,7 @@ void ObjBell_Init(Actor* thisx, GlobalContext* globalCtx) { void ObjBell_Destroy(Actor* thisx, GlobalContext* globalCtx) { ObjBell* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); Collider_DestroySphere(globalCtx, &this->collider1); Collider_DestroySphere(globalCtx, &this->collider2); } diff --git a/src/overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.c b/src/overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.c index b08f690d48..a4eb9ad9ac 100644 --- a/src/overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.c +++ b/src/overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.c @@ -88,7 +88,7 @@ void ObjEtcetera_Init(Actor* thisx, GlobalContext* globalCtx) { pos.x = this->dyna.actor.world.pos.x; pos.y = this->dyna.actor.world.pos.y + 10.0f; pos.z = this->dyna.actor.world.pos.z; - func_800C411C(&globalCtx->colCtx, &this->dyna.actor.floorPoly, &floorBgId, &this->dyna.actor, &pos); + BgCheck_EntityRaycastFloor5(&globalCtx->colCtx, &this->dyna.actor.floorPoly, &floorBgId, &this->dyna.actor, &pos); this->dyna.actor.floorBgId = floorBgId; Collider_InitAndSetCylinder(globalCtx, &this->collider, &this->dyna.actor, &sCylinderInit); Collider_UpdateCylinder(&this->dyna.actor, &this->collider); @@ -101,7 +101,7 @@ void ObjEtcetera_Init(Actor* thisx, GlobalContext* globalCtx) { void ObjEtcetera_Destroy(Actor* thisx, GlobalContext* globalCtx) { ObjEtcetera* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); Collider_DestroyCylinder(globalCtx, &this->collider); } @@ -236,9 +236,9 @@ void ObjEtcetera_Setup(ObjEtcetera* this, GlobalContext* globalCtx) { DynaPolyActor_Init(&this->dyna, 1); thisCollisionHeader = collisionHeaders[type]; if (thisCollisionHeader != 0) { - BgCheck_RelocateMeshHeader(thisCollisionHeader, &colHeader); + CollisionHeader_GetVirtual(thisCollisionHeader, &colHeader); } - this->dyna.bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, &this->dyna, colHeader); + this->dyna.bgId = DynaPoly_SetBgActor(globalCtx, &globalCtx->colCtx.dyna, &this->dyna.actor, colHeader); type = DEKU_FLOWER_TYPE(&this->dyna.actor); switch (type) { @@ -292,7 +292,7 @@ void ObjEtcetera_Update(Actor* thisx, GlobalContext* globalCtx) { if (floorBgId == BGCHECK_SCENE) { floorPoly = this->dyna.actor.floorPoly; if (floorPoly != NULL && this->burrowFlag & 1) { - func_800FAAB4(globalCtx, func_800C9C9C(&globalCtx->colCtx, floorPoly, floorBgId)); + func_800FAAB4(globalCtx, SurfaceType_GetLightSettingIndex(&globalCtx->colCtx, floorPoly, floorBgId)); } } this->actionFunc(this, globalCtx); diff --git a/src/overlays/actors/ovl_Obj_Ghaka/z_obj_ghaka.c b/src/overlays/actors/ovl_Obj_Ghaka/z_obj_ghaka.c index 6a7bf18e47..3d5ee7848e 100644 --- a/src/overlays/actors/ovl_Obj_Ghaka/z_obj_ghaka.c +++ b/src/overlays/actors/ovl_Obj_Ghaka/z_obj_ghaka.c @@ -154,8 +154,8 @@ void ObjGhaka_Init(Actor* thisx, GlobalContext* globalCtx) { Actor_ProcessInitChain(&this->dyna.actor, D_80B3C96C); Actor_SetScale(&this->dyna.actor, 0.1f); DynaPolyActor_Init(&this->dyna, 1); - BgCheck_RelocateMeshHeader(&D_06003CD0, &colHeader); - this->dyna.bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, &this->dyna, colHeader); + CollisionHeader_GetVirtual(&D_06003CD0, &colHeader); + this->dyna.bgId = DynaPoly_SetBgActor(globalCtx, &globalCtx->colCtx.dyna, &this->dyna.actor, colHeader); Actor_UpdateBgCheckInfo(globalCtx, &this->dyna.actor, 0.0f, 0.0f, 0.0f, 0x4); if (this->dyna.actor.floorPoly == 0) { Actor_MarkForDeath(&this->dyna.actor); @@ -169,7 +169,7 @@ void ObjGhaka_Init(Actor* thisx, GlobalContext* globalCtx) { void ObjGhaka_Destroy(Actor* thisx, GlobalContext* globalCtx) { ObjGhaka* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void ObjGhaka_Update(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Obj_Hgdoor/z_obj_hgdoor.c b/src/overlays/actors/ovl_Obj_Hgdoor/z_obj_hgdoor.c index 31184fc30a..0b32504fa1 100644 --- a/src/overlays/actors/ovl_Obj_Hgdoor/z_obj_hgdoor.c +++ b/src/overlays/actors/ovl_Obj_Hgdoor/z_obj_hgdoor.c @@ -80,11 +80,11 @@ void ObjHgdoor_Init(Actor* thisx, GlobalContext* globalCtx) { Actor_SetScale(&this->dyna.actor, 0.1f); DynaPolyActor_Init(&this->dyna, 1); if (OBJHGDOOR_IS_RIGHT_DOOR(&this->dyna.actor)) { - BgCheck_RelocateMeshHeader(&D_06001D10, &header); + CollisionHeader_GetVirtual(&D_06001D10, &header); } else { - BgCheck_RelocateMeshHeader(&D_060018C0, &header); + CollisionHeader_GetVirtual(&D_060018C0, &header); } - this->dyna.bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, &this->dyna, header); + this->dyna.bgId = DynaPoly_SetBgActor(globalCtx, &globalCtx->colCtx.dyna, &this->dyna.actor, header); this->rotation = 0; this->timer = 0; this->cutscene = this->dyna.actor.cutscene; @@ -94,7 +94,7 @@ void ObjHgdoor_Init(Actor* thisx, GlobalContext* globalCtx) { void ObjHgdoor_Destroy(Actor* thisx, GlobalContext* globalCtx) { ObjHgdoor* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void ObjHgdoor_SetupCheckShouldOpen(ObjHgdoor* this) { diff --git a/src/overlays/actors/ovl_Obj_HsStump/z_obj_hsstump.c b/src/overlays/actors/ovl_Obj_HsStump/z_obj_hsstump.c index e3813efb52..cca1b99224 100644 --- a/src/overlays/actors/ovl_Obj_HsStump/z_obj_hsstump.c +++ b/src/overlays/actors/ovl_Obj_HsStump/z_obj_hsstump.c @@ -136,7 +136,7 @@ void ObjHsStump_Appear(ObjHsStump* this, GlobalContext* globalCtx) { void ObjHsStump_Destroy(Actor* thisx, GlobalContext* globalCtx) { ObjHsStump* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void ObjHsStump_Update(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Obj_Kepn_Koya/z_obj_kepn_koya.c b/src/overlays/actors/ovl_Obj_Kepn_Koya/z_obj_kepn_koya.c index f7901f708d..65a39be35b 100644 --- a/src/overlays/actors/ovl_Obj_Kepn_Koya/z_obj_kepn_koya.c +++ b/src/overlays/actors/ovl_Obj_Kepn_Koya/z_obj_kepn_koya.c @@ -42,7 +42,7 @@ void ObjKepnKoya_Init(Actor* thisx, GlobalContext* globalCtx) { Actor_SetScale(&this->dyna.actor, 0.1f); DynaPolyActor_Init(&this->dyna, 0); DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_0600805C); - if (this->dyna.bgId == 0x32) { + if (this->dyna.bgId == BG_ACTOR_MAX) { Actor_MarkForDeath(&this->dyna.actor); } } @@ -50,7 +50,7 @@ void ObjKepnKoya_Init(Actor* thisx, GlobalContext* globalCtx) { void ObjKepnKoya_Destroy(Actor* thisx, GlobalContext* globalCtx) { ObjKepnKoya* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void ObjKepnKoya_Update(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Obj_Kibako/z_obj_kibako.c b/src/overlays/actors/ovl_Obj_Kibako/z_obj_kibako.c index 2d3ea6d4eb..204b506630 100644 --- a/src/overlays/actors/ovl_Obj_Kibako/z_obj_kibako.c +++ b/src/overlays/actors/ovl_Obj_Kibako/z_obj_kibako.c @@ -298,7 +298,7 @@ void ObjKibako_Idle(ObjKibako* this, GlobalContext* globalCtx) { } if ((this->actor.colChkInfo.mass != MASS_IMMOVABLE) && - (Math3D_DistanceSquared(&this->actor.world.pos, &this->actor.prevPos) < 0.01f)) { + (Math3D_Vec3fDistSq(&this->actor.world.pos, &this->actor.prevPos) < 0.01f)) { this->actor.colChkInfo.mass = MASS_IMMOVABLE; } @@ -333,7 +333,7 @@ void ObjKibako_SetupHeld(ObjKibako* this) { void ObjKibako_Held(ObjKibako* this, GlobalContext* globalCtx) { s32 pad; Vec3f pos; - s32 sp2C; + s32 bgId; func_80926394(this, globalCtx); if (Actor_HasNoParent(&this->actor, globalCtx)) { @@ -352,7 +352,8 @@ void ObjKibako_Held(ObjKibako* this, GlobalContext* globalCtx) { pos.x = this->actor.world.pos.x; pos.y = this->actor.world.pos.y + 20.0f; pos.z = this->actor.world.pos.z; - this->actor.floorHeight = func_800C411C(&globalCtx->colCtx, &this->actor.floorPoly, &sp2C, &this->actor, &pos); + this->actor.floorHeight = + BgCheck_EntityRaycastFloor5(&globalCtx->colCtx, &this->actor.floorPoly, &bgId, &this->actor, &pos); } } diff --git a/src/overlays/actors/ovl_Obj_Kibako2/z_obj_kibako2.c b/src/overlays/actors/ovl_Obj_Kibako2/z_obj_kibako2.c index abd04dc65e..69bfaad18c 100644 --- a/src/overlays/actors/ovl_Obj_Kibako2/z_obj_kibako2.c +++ b/src/overlays/actors/ovl_Obj_Kibako2/z_obj_kibako2.c @@ -177,7 +177,7 @@ void ObjKibako2_Destroy(Actor* thisx, GlobalContext* globalCtx) { ObjKibako2* this = THIS; Collider_DestroyCylinder(globalCtx, &this->collider); - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } s32 ObjKibako2_ShouldBreak(ObjKibako2* this) { @@ -190,12 +190,12 @@ s32 ObjKibako2_ShouldBreak(ObjKibako2* this) { if (ac != NULL) { if (this->collider.info.acHitInfo->toucher.dmgFlags & (1 << 31)) { // Powder Keg - if (Math3D_DistanceSquared(&this->dyna.actor.world.pos, &ac->world.pos) < SQ(160.0f)) { + if (Math3D_Vec3fDistSq(&this->dyna.actor.world.pos, &ac->world.pos) < SQ(160.0f)) { shouldBreak = true; } } else if (this->collider.info.acHitInfo->toucher.dmgFlags & (1 << 3)) { // Explosives - if (Math3D_DistanceSquared(&this->dyna.actor.world.pos, &ac->world.pos) < SQ(100.0f)) { + if (Math3D_Vec3fDistSq(&this->dyna.actor.world.pos, &ac->world.pos) < SQ(100.0f)) { shouldBreak = true; } } else if (this->collider.info.acHitInfo->toucher.dmgFlags & (1 << 8 | 1 << 10)) { diff --git a/src/overlays/actors/ovl_Obj_Lightblock/z_obj_lightblock.c b/src/overlays/actors/ovl_Obj_Lightblock/z_obj_lightblock.c index 6a123c6ca0..9f4b8c2b0d 100644 --- a/src/overlays/actors/ovl_Obj_Lightblock/z_obj_lightblock.c +++ b/src/overlays/actors/ovl_Obj_Lightblock/z_obj_lightblock.c @@ -110,7 +110,7 @@ void ObjLightblock_Init(Actor* thisx, GlobalContext* globalCtx) { void ObjLightblock_Destroy(Actor* thisx, GlobalContext* globalCtx) { ObjLightblock* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); Collider_DestroyCylinder(globalCtx, &this->collider); } diff --git a/src/overlays/actors/ovl_Obj_Makeoshihiki/z_obj_makeoshihiki.c b/src/overlays/actors/ovl_Obj_Makeoshihiki/z_obj_makeoshihiki.c index a704f2773c..e864e86b42 100644 --- a/src/overlays/actors/ovl_Obj_Makeoshihiki/z_obj_makeoshihiki.c +++ b/src/overlays/actors/ovl_Obj_Makeoshihiki/z_obj_makeoshihiki.c @@ -85,7 +85,7 @@ void ObjMakeoshihiki_Update(Actor* thisx, GlobalContext* globalCtx) { } else { for (loopPathIndex = 0; loopPathIndex < this->pathCount; loopPathIndex++) { Math_Vec3s_ToVec3f(&pathPointF, &this->pathPoints[loopPathIndex]); - if (Math3D_DistanceSquared(&this->actor.child->world.pos, &pathPointF) < SQ(0.5f)) { + if (Math3D_Vec3fDistSq(&this->actor.child->world.pos, &pathPointF) < SQ(0.5f)) { ObjMakeoshihiki_SetSwitchFlags(this, globalCtx, loopPathIndex); return; } diff --git a/src/overlays/actors/ovl_Obj_Raillift/z_obj_raillift.c b/src/overlays/actors/ovl_Obj_Raillift/z_obj_raillift.c index 969326cf4f..041e869826 100644 --- a/src/overlays/actors/ovl_Obj_Raillift/z_obj_raillift.c +++ b/src/overlays/actors/ovl_Obj_Raillift/z_obj_raillift.c @@ -107,7 +107,7 @@ void ObjRaillift_Init(Actor* thisx, GlobalContext* globalCtx) { void ObjRaillift_Destroy(Actor* thisx, GlobalContext* globalCtx) { ObjRaillift* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void ObjRaillift_DoNothing(ObjRaillift* this, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.c b/src/overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.c index 03e96013a3..3eb50153be 100644 --- a/src/overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.c +++ b/src/overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.c @@ -155,8 +155,8 @@ void ObjSyokudai_Update(Actor* thisx, GlobalContext* globalCtx2) { this->pendingAction = OBJ_SYOKUDAI_PENDING_ACTION_NONE; } } else { - if (func_800CA1E8(globalCtx, &globalCtx->colCtx, thisx->world.pos.x, thisx->world.pos.z, &waterSurface, - &waterBox) && + if (WaterBox_GetSurface1_2(globalCtx, &globalCtx->colCtx, thisx->world.pos.x, thisx->world.pos.z, &waterSurface, + &waterBox) && ((waterSurface - thisx->world.pos.y) > OBJ_SYOKUDAI_FLAME_HEIGHT)) { this->snuffTimer = OBJ_SYOKUDAI_SNUFF_OUT; diff --git a/src/overlays/actors/ovl_Obj_Tokei_Step/z_obj_tokei_step.c b/src/overlays/actors/ovl_Obj_Tokei_Step/z_obj_tokei_step.c index c5e00241c4..837c05ae9f 100644 --- a/src/overlays/actors/ovl_Obj_Tokei_Step/z_obj_tokei_step.c +++ b/src/overlays/actors/ovl_Obj_Tokei_Step/z_obj_tokei_step.c @@ -214,7 +214,7 @@ void ObjTokeiStep_Init(Actor* thisx, GlobalContext* globalCtx) { void ObjTokeiStep_Destroy(Actor* thisx, GlobalContext* globalCtx) { ObjTokeiStep* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void ObjTokeiStep_SetupBeginOpen(ObjTokeiStep* this) { diff --git a/src/overlays/actors/ovl_Obj_Visiblock/z_obj_visiblock.c b/src/overlays/actors/ovl_Obj_Visiblock/z_obj_visiblock.c index 5f5b25cb3e..427400f99a 100644 --- a/src/overlays/actors/ovl_Obj_Visiblock/z_obj_visiblock.c +++ b/src/overlays/actors/ovl_Obj_Visiblock/z_obj_visiblock.c @@ -47,7 +47,7 @@ void ObjVisiblock_Init(Actor* thisx, GlobalContext* globalCtx) { void ObjVisiblock_Destroy(Actor* thisx, GlobalContext* globalCtx) { ObjVisiblock* this = THIS; - BgCheck_RemoveActorMesh(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); + DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } void ObjVisiblock_Draw(Actor* thisx, GlobalContext* globalCtx) { diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index dda5c667f6..8f3aa72489 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -899,162 +899,162 @@ 0x800BFA78:("ActorOverlayTable_FaultAddrConv",), 0x800BFAE8:("ActorOverlayTable_Init",), 0x800BFB40:("ActorOverlayTable_Cleanup",), - 0x800BFB80:("BgCheck_PolygonLinkedListNodeInit",), - 0x800BFB9C:("BgCheck_PolygonLinkedListResetHead",), - 0x800BFBAC:("BgCheck_ScenePolygonListsNodeInsert",), - 0x800BFC04:("BgCheck_PolygonLinkedListNodeInsert",), - 0x800BFC5C:("BgCheck_PolygonLinkedListInit",), - 0x800BFC70:("BgCheck_PolygonLinkedListAlloc",), - 0x800BFCC0:("BgCheck_PolygonLinkedListReset",), - 0x800BFCCC:("BgCheck_AllocPolygonLinkedListNode",), - 0x800BFCFC:("BgCheck_CreateVec3fFromVertex",), - 0x800BFD40:("BgCheck_CreateVertexFromVec3f",), + 0x800BFB80:("SSNode_SetValue",), + 0x800BFB9C:("SSList_SetNull",), + 0x800BFBAC:("SSNodeList_SetSSListHead",), + 0x800BFC04:("DynaSSNodeList_SetSSListHead",), + 0x800BFC5C:("DynaSSNodeList_Init",), + 0x800BFC70:("DynaSSNodeList_Alloc",), + 0x800BFCC0:("DynaSSNodeList_ResetCount",), + 0x800BFCCC:("DynaSSNodeList_GetNextNodeIdx",), + 0x800BFCFC:("BgCheck_Vec3sToVec3f",), + 0x800BFD40:("BgCheck_Vec3fToVec3s",), 0x800BFD84:("func_800BFD84",), 0x800BFDEC:("func_800BFDEC",), - 0x800BFFC4:("BgCheck_PolygonGetMinY",), - 0x800C003C:("BgCheck_PolygonGetNormal",), + 0x800BFFC4:("CollisionPoly_GetMinY",), + 0x800C003C:("CollisionPoly_GetNormalF",), 0x800C0094:("func_800C0094",), - 0x800C01B8:("func_800C01B8",), - 0x800C0220:("BgCheck_CreateTriNormFromPolygon",), - 0x800C02C0:("func_800C02C0",), - 0x800C0340:("func_800C0340",), - 0x800C0474:("func_800C0474",), - 0x800C0668:("func_800C0668",), - 0x800C06A8:("func_800C06A8",), - 0x800C074C:("func_800C074C",), - 0x800C07F0:("func_800C07F0",), - 0x800C0AF0:("BgCheck_PolygonCollidesWithSphere",), - 0x800C0BC0:("BgCheck_ScenePolygonListsInsertSorted",), - 0x800C0DE0:("BgCheck_ScenePolygonListsInsert",), - 0x800C0E74:("func_800C0E74",), - 0x800C10FC:("func_800C10FC",), - 0x800C1238:("func_800C1238",), - 0x800C12A4:("func_800C12A4",), - 0x800C1B68:("func_800C1B68",), - 0x800C1D7C:("func_800C1D7C",), - 0x800C2008:("func_800C2008",), - 0x800C20F4:("func_800C20F4",), - 0x800C2310:("func_800C2310",), - 0x800C2460:("func_800C2460",), - 0x800C2514:("func_800C2514",), - 0x800C25E0:("func_800C25E0",), - 0x800C26C0:("BgCheck_GetPolyMinSubdivisions",), - 0x800C2864:("BgCheck_GetPolyMaxSubdivisions",), - 0x800C2A30:("BgCheck_GetPolyMinMaxSubdivisions",), - 0x800C2BE0:("func_800C2BE0",), - 0x800C3334:("BgCheck_SplitScenePolygonsIntoSubdivisions",), - 0x800C3734:("BgCheck_GetIsDefaultSpecialScene",), - 0x800C3778:("BgCheck_GetSpecialSceneMaxMemory",), - 0x800C37BC:("BgCheck_CalcSubdivisionSize",), + 0x800C01B8:("CollisionPoly_GetPointDistanceFromPlane",), + 0x800C0220:("CollisionPoly_GetVertices",), + 0x800C02C0:("CollisionPoly_GetVerticesByBgId",), + 0x800C0340:("CollisionPoly_CheckYIntersectApprox1",), + 0x800C0474:("CollisionPoly_CheckYIntersect",), + 0x800C0668:("CollisionPoly_CheckYIntersectApprox2",), + 0x800C06A8:("CollisionPoly_CheckXIntersectApprox",), + 0x800C074C:("CollisionPoly_CheckZIntersectApprox",), + 0x800C07F0:("CollisionPoly_LineVsPoly",), + 0x800C0AF0:("CollisionPoly_SphVsPoly",), + 0x800C0BC0:("StaticLookup_AddPolyToSSList",), + 0x800C0DE0:("StaticLookup_AddPoly",), + 0x800C0E74:("BgCheck_RaycastFloorStaticList",), + 0x800C10FC:("BgCheck_RaycastFloorStatic",), + 0x800C1238:("BgCheck_ComputeWallDisplacement",), + 0x800C12A4:("BgCheck_SphVsStaticWall",), + 0x800C1B68:("BgCheck_CheckStaticCeiling",), + 0x800C1D7C:("BgCheck_CheckLineAgainstSSList",), + 0x800C2008:("BgCheck_CheckLineInSubdivision",), + 0x800C20F4:("BgCheck_SphVsFirstStaticPolyList",), + 0x800C2310:("BgCheck_SphVsFirstStaticPoly",), + 0x800C2460:("BgCheck_GetNearestStaticLookup",), + 0x800C2514:("BgCheck_GetStaticLookup",), + 0x800C25E0:("BgCheck_GetStaticLookupIndicesFromPos",), + 0x800C26C0:("BgCheck_GetSubdivisionMinBounds",), + 0x800C2864:("BgCheck_GetSubdivisionMaxBounds",), + 0x800C2A30:("BgCheck_GetPolySubdivisionBounds",), + 0x800C2BE0:("BgCheck_PolyIntersectsSubdivision",), + 0x800C3334:("BgCheck_InitStaticLookup",), + 0x800C3734:("BgCheck_IsSmallMemScene",), + 0x800C3778:("BgCheck_TryGetCustomMemsize",), + 0x800C37BC:("BgCheck_SetSubdivisionDimension",), 0x800C3844:("BgCheck_GetSpecialSceneMaxObjects",), - 0x800C389C:("BgCheck_Init",), - 0x800C3C00:("func_800C3C00",), - 0x800C3C14:("func_800C3C14",), - 0x800C3C2C:("BgCheck_GetActorMeshHeader",), - 0x800C3C94:("func_800C3C94",), - 0x800C3D50:("func_800C3D50",), - 0x800C3F40:("func_800C3F40",), - 0x800C3FA0:("func_800C3FA0",), - 0x800C4000:("func_800C4000",), - 0x800C4058:("func_800C4058",), - 0x800C40B4:("func_800C40B4",), - 0x800C411C:("func_800C411C",), - 0x800C4188:("func_800C4188",), - 0x800C41E4:("func_800C41E4",), - 0x800C4240:("func_800C4240",), - 0x800C42A8:("func_800C42A8",), - 0x800C4314:("func_800C4314",), - 0x800C43CC:("func_800C43CC",), - 0x800C4488:("func_800C4488",), - 0x800C44F0:("func_800C44F0",), - 0x800C455C:("func_800C455C",), - 0x800C45C4:("func_800C45C4",), - 0x800C4C74:("func_800C4C74",), - 0x800C4CD8:("func_800C4CD8",), - 0x800C4D3C:("func_800C4D3C",), - 0x800C4DA4:("func_800C4DA4",), - 0x800C4E10:("func_800C4E10",), - 0x800C4F38:("func_800C4F38",), - 0x800C4F84:("func_800C4F84",), - 0x800C4FD4:("func_800C4FD4",), - 0x800C5464:("func_800C5464",), - 0x800C54AC:("func_800C54AC",), - 0x800C5538:("func_800C5538",), - 0x800C55C4:("func_800C55C4",), - 0x800C5650:("func_800C5650",), - 0x800C56E0:("func_800C56E0",), - 0x800C576C:("func_800C576C",), - 0x800C57F8:("func_800C57F8",), - 0x800C583C:("func_800C583C",), - 0x800C58C8:("func_800C58C8",), - 0x800C5954:("func_800C5954",), - 0x800C5A20:("func_800C5A20",), - 0x800C5A64:("func_800C5A64",), - 0x800C5AAC:("BgCheck_ScenePolygonListsInit",), - 0x800C5AC4:("BgCheck_ScenePolygonListsAlloc",), - 0x800C5B80:("func_800C5B80",), - 0x800C5BBC:("BgCheck_ScenePolygonListsReserveNode",), - 0x800C5BD0:("BgCheck_ActorMeshParamsInit",), - 0x800C5C0C:("BgCheck_SetActorMeshParams",), - 0x800C5C5C:("BgCheck_AreActorMeshParamsEqual",), - 0x800C5D30:("BgCheck_ActorMeshPolyListsHeadsInit",), - 0x800C5D70:("BgCheck_ActorMeshPolyListsInit",), - 0x800C5D90:("BgCheck_ActorMeshVerticesIndexInit",), - 0x800C5D9C:("BgCheck_ActorMeshWaterboxesIndexInit",), - 0x800C5DA8:("BgCheck_ActorMeshInit",), - 0x800C5E10:("BgCheck_ActorMeshInitFromActor",), - 0x800C5EC8:("BgCheck_HasActorMeshChanged",), - 0x800C5EF0:("BgCheck_PolygonsInit",), - 0x800C5EFC:("BgCheck_PolygonsAlloc",), - 0x800C5F38:("BgCheck_VerticesInit",), - 0x800C5F44:("BgCheck_VerticesListAlloc",), - 0x800C5F8C:("BgCheck_WaterboxListInit",), - 0x800C5F9C:("BgCheck_WaterboxListAlloc",), - 0x800C5FD8:("BgCheck_ActorMeshUpdateParams",), - 0x800C6024:("BgCheck_IsActorMeshIndexValid",), - 0x800C6044:("BgCheck_DynaInit",), - 0x800C6098:("BgCheck_DynaAlloc",), - 0x800C6188:("BgCheck_AddActorMesh",), - 0x800C6248:("BgCheck_GetActorOfMesh",), + 0x800C389C:("BgCheck_Allocate",), + 0x800C3C00:("BgCheck_SetContextFlags",), + 0x800C3C14:("BgCheck_UnsetContextFlags",), + 0x800C3C2C:("BgCheck_GetCollisionHeader",), + 0x800C3C94:("BgCheck_PosInStaticBoundingBox",), + 0x800C3D50:("BgCheck_RaycastFloorImpl",), + 0x800C3F40:("BgCheck_CameraRaycastFloor1",), + 0x800C3FA0:("BgCheck_EntityRaycastFloor1",), + 0x800C4000:("BgCheck_EntityRaycastFloor2",), + 0x800C4058:("BgCheck_EntityRaycastFloor2_1",), + 0x800C40B4:("BgCheck_EntityRaycastFloor3",), + 0x800C411C:("BgCheck_EntityRaycastFloor5",), + 0x800C4188:("BgCheck_EntityRaycastFloor5_2",), + 0x800C41E4:("BgCheck_EntityRaycastFloor5_3",), + 0x800C4240:("BgCheck_EntityRaycastFloor6",), + 0x800C42A8:("BgCheck_EntityRaycastFloor7",), + 0x800C4314:("BgCheck_AnyRaycastFloor1",), + 0x800C43CC:("BgCheck_AnyRaycastFloor2",), + 0x800C4488:("BgCheck_CameraRaycastFloor2",), + 0x800C44F0:("BgCheck_EntityRaycastFloor8",), + 0x800C455C:("BgCheck_EntityRaycastFloor9",), + 0x800C45C4:("BgCheck_CheckWallImpl",), + 0x800C4C74:("BgCheck_EntitySphVsWall1",), + 0x800C4CD8:("BgCheck_EntitySphVsWall2",), + 0x800C4D3C:("BgCheck_EntitySphVsWall3",), + 0x800C4DA4:("BgCheck_EntitySphVsWall4",), + 0x800C4E10:("BgCheck_CheckCeilingImpl",), + 0x800C4F38:("BgCheck_AnyCheckCeiling",), + 0x800C4F84:("BgCheck_EntityCheckCeiling",), + 0x800C4FD4:("BgCheck_CheckLineImpl",), + 0x800C5464:("BgCheck_GetBccFlags",), + 0x800C54AC:("BgCheck_CameraLineTest1",), + 0x800C5538:("BgCheck_CameraLineTest2",), + 0x800C55C4:("BgCheck_EntityLineTest1",), + 0x800C5650:("BgCheck_EntityLineTest2",), + 0x800C56E0:("BgCheck_EntityLineTest3",), + 0x800C576C:("BgCheck_ProjectileLineTest",), + 0x800C57F8:("BgCheck_AnyLineTest1",), + 0x800C583C:("BgCheck_AnyLineTest2",), + 0x800C58C8:("BgCheck_AnyLineTest3",), + 0x800C5954:("BgCheck_SphVsFirstPolyImpl",), + 0x800C5A20:("BgCheck_SphVsFirstPoly",), + 0x800C5A64:("BgCheck_SphVsFirstWall",), + 0x800C5AAC:("SSNodeList_Init",), + 0x800C5AC4:("SSNodeList_Alloc",), + 0x800C5B80:("SSNodeList_GetNextNode",), + 0x800C5BBC:("SSNodeList_GetNextNodeIdx",), + 0x800C5BD0:("ScaleRotPos_Init",), + 0x800C5C0C:("ScaleRotPos_SetValue",), + 0x800C5C5C:("ScaleRotPos_Equals",), + 0x800C5D30:("DynaLookup_ResetLists",), + 0x800C5D70:("DynaLookup_Reset",), + 0x800C5D90:("DynaLookup_ResetVtxStartIndex",), + 0x800C5D9C:("DynaLookup_ResetWaterBoxStartIndex",), + 0x800C5DA8:("BgActor_Init",), + 0x800C5E10:("BgActor_SetActor",), + 0x800C5EC8:("BgActor_IsTransformUnchanged",), + 0x800C5EF0:("DynaPoly_NullPolyList",), + 0x800C5EFC:("DynaPoly_AllocPolyList",), + 0x800C5F38:("DynaPoly_NullVtxList",), + 0x800C5F44:("DynaPoly_AllocVtxList",), + 0x800C5F8C:("DynaPoly_InitWaterBoxList",), + 0x800C5F9C:("DynaPoly_AllocWaterBoxList",), + 0x800C5FD8:("DynaPoly_SetBgActorPrevTransform",), + 0x800C6024:("DynaPoly_IsBgIdBgActor",), + 0x800C6044:("DynaPoly_Init",), + 0x800C6098:("DynaPoly_Alloc",), + 0x800C6188:("DynaPoly_SetBgActor",), + 0x800C6248:("DynaPoly_GetActor",), 0x800C62BC:("func_800C62BC",), 0x800C6314:("func_800C6314",), 0x800C636C:("func_800C636C",), 0x800C63C4:("func_800C63C4",), 0x800C641C:("func_800C641C",), 0x800C6474:("func_800C6474",), - 0x800C64CC:("BgCheck_RemoveActorMesh",), + 0x800C64CC:("DynaPoly_DeleteBgActor",), 0x800C6554:("func_800C6554",), 0x800C656C:("BgCheck_CalcWaterboxDimensions",), - 0x800C6838:("BgCheck_AddActorMeshToLists",), + 0x800C6838:("DynaPoly_ExpandSRT",), 0x800C734C:("BgCheck_ResetFlagsIfLoadedActor",), - 0x800C73E4:("BgCheck_Update",), + 0x800C73E4:("DynaPoly_Setup",), 0x800C756C:("func_800C756C",), - 0x800C765C:("BgCheck_UpdateAllActorMeshes",), - 0x800C76EC:("func_800C76EC",), - 0x800C7974:("func_800C7974",), - 0x800C7E40:("func_800C7E40",), - 0x800C8580:("func_800C8580",), - 0x800C87D0:("func_800C87D0",), - 0x800C8A60:("func_800C8A60",), - 0x800C8BD0:("func_800C8BD0",), - 0x800C8DC0:("func_800C8DC0",), - 0x800C8EEC:("func_800C8EEC",), - 0x800C90AC:("func_800C90AC",), - 0x800C921C:("func_800C921C",), - 0x800C9380:("func_800C9380",), - 0x800C94E0:("BgCheck_RelocateMeshHeaderPointers",), - 0x800C9564:("BgCheck_RelocateMeshHeader",), - 0x800C9598:("BgCheck_RelocateAllMeshHeaders",), - 0x800C9640:("func_800C9640",), - 0x800C9694:("BgCheck_GetPolygonAttributes",), - 0x800C9704:("func_800C9704",), + 0x800C765C:("DynaPoly_UpdateBgActorTransforms",), + 0x800C76EC:("BgCheck_RaycastFloorDynaList",), + 0x800C7974:("BgCheck_RaycastFloorDyna",), + 0x800C7E40:("BgCheck_SphVsDynaWallInBgActor",), + 0x800C8580:("BgCheck_SphVsDynaWall",), + 0x800C87D0:("BgCheck_CheckDynaCeilingList",), + 0x800C8A60:("BgCheck_CheckDynaCeiling",), + 0x800C8BD0:("BgCheck_CheckLineAgainstBgActorSSList",), + 0x800C8DC0:("BgCheck_CheckLineAgainstBgActor",), + 0x800C8EEC:("BgCheck_CheckLineAgainstDyna",), + 0x800C90AC:("BgCheck_SphVsFirstDynaPolyList",), + 0x800C921C:("BgCheck_SphVsFirstDynaPolyInBgActor",), + 0x800C9380:("BgCheck_SphVsFirstDynaPoly",), + 0x800C94E0:("CollisionHeader_SegmentedToVirtual",), + 0x800C9564:("CollisionHeader_GetVirtual",), + 0x800C9598:("BgCheck_InitCollisionHeaders",), + 0x800C9640:("BgCheck_ResetPolyCheckTbl",), + 0x800C9694:("SurfaceType_GetData",), + 0x800C9704:("SurfaceType_GetCamDataIndex",), 0x800C9728:("func_800C9728",), - 0x800C9770:("func_800C9770",), + 0x800C9770:("SurfaceType_GetCameraSetting",), 0x800C97F8:("func_800C97F8",), 0x800C9844:("func_800C9844",), 0x800C98CC:("func_800C98CC",), - 0x800C9924:("func_800C9924",), - 0x800C99AC:("func_800C99AC",), + 0x800C9924:("SurfaceType_GetCamPosData",), + 0x800C99AC:("SurfaceType_GetSceneExitIndex",), 0x800C99D4:("func_800C99D4",), 0x800C99FC:("func_800C99FC",), 0x800C9A24:("func_800C9A24",), @@ -1065,30 +1065,30 @@ 0x800C9B18:("func_800C9B18",), 0x800C9B40:("func_800C9B40",), 0x800C9B68:("func_800C9B68",), - 0x800C9B90:("func_800C9B90",), + 0x800C9B90:("SurfaceType_IsHorseBlocked",), 0x800C9BB8:("func_800C9BB8",), - 0x800C9BDC:("func_800C9BDC",), + 0x800C9BDC:("SurfaceType_GetSfx",), 0x800C9C24:("func_800C9C24",), - 0x800C9C74:("func_800C9C74",), - 0x800C9C9C:("func_800C9C9C",), - 0x800C9CC4:("func_800C9CC4",), - 0x800C9CEC:("func_800C9CEC",), - 0x800C9D14:("func_800C9D14",), - 0x800C9D50:("func_800C9D50",), - 0x800C9D8C:("func_800C9D8C",), + 0x800C9C74:("SurfaceType_GetSlope",), + 0x800C9C9C:("SurfaceType_GetLightSettingIndex",), + 0x800C9CC4:("SurfaceType_GetEcho",), + 0x800C9CEC:("SurfaceType_IsHookshotSurface",), + 0x800C9D14:("SurfaceType_IsIgnoredByEntities",), + 0x800C9D50:("SurfaceType_IsIgnoredByProjectiles",), + 0x800C9D8C:("SurfaceType_IsConveyor",), 0x800C9DDC:("func_800C9DDC",), - 0x800C9E18:("func_800C9E18",), - 0x800C9E40:("func_800C9E40",), - 0x800C9E88:("func_800C9E88",), - 0x800C9EBC:("func_800C9EBC",), - 0x800CA1AC:("func_800CA1AC",), - 0x800CA1E8:("func_800CA1E8",), - 0x800CA22C:("func_800CA22C",), + 0x800C9E18:("SurfaceType_GetConveyorSpeed",), + 0x800C9E40:("SurfaceType_GetConveyorDirection",), + 0x800C9E88:("SurfaceType_IsWallDamage",), + 0x800C9EBC:("WaterBox_GetSurfaceImpl",), + 0x800CA1AC:("WaterBox_GetSurface1",), + 0x800CA1E8:("WaterBox_GetSurface1_2",), + 0x800CA22C:("WaterBox_GetSurface2",), 0x800CA568:("func_800CA568",), - 0x800CA634:("func_800CA634",), - 0x800CA648:("func_800CA648",), + 0x800CA634:("WaterBox_GetCamDataIndex",), + 0x800CA648:("WaterBox_GetCameraSetting",), 0x800CA6B8:("func_800CA6B8",), - 0x800CA6D8:("func_800CA6D8",), + 0x800CA6D8:("WaterBox_GetLightSettingIndex",), 0x800CA6F0:("func_800CA6F0",), 0x800CA9D0:("func_800CA9D0",), 0x800CAA14:("func_800CAA14",), @@ -3256,7 +3256,7 @@ 0x80179594:("Rand_ZeroFloat",), 0x801795C0:("randPlusMinusPoint5Scaled",), 0x801795F0:("Math3D_Normalize",), - 0x80179678:("func_80179678",), + 0x80179678:("Math3D_PlaneVsLineSegClosestPoint",), 0x80179798:("func_80179798",), 0x80179A44:("func_80179A44",), 0x80179B34:("func_80179B34",), @@ -3278,46 +3278,46 @@ 0x8017A678:("Math3D_XZDistance",), 0x8017A6A8:("Math3D_LengthSquared",), 0x8017A6D4:("Math3D_Vec3fMagnitude",), - 0x8017A6F8:("Math3D_DistanceSquared",), + 0x8017A6F8:("Math3D_Vec3fDistSq",), 0x8017A720:("Math3D_Distance",), 0x8017A740:("Math3D_DistanceS",), 0x8017A7B8:("func_8017A7B8",), 0x8017A7F8:("func_8017A7F8",), 0x8017A838:("func_8017A838",), 0x8017A878:("Math3D_CrossProduct",), - 0x8017A8EC:("Math3D_NormalVector",), - 0x8017A954:("func_8017A954",), - 0x8017AA0C:("func_8017AA0C",), - 0x8017ABBC:("func_8017ABBC",), - 0x8017AD38:("func_8017AD38",), + 0x8017A8EC:("Math3D_SurfaceNorm",), + 0x8017A954:("Math3D_PointRelativeToCubeFaces",), + 0x8017AA0C:("Math3D_PointRelativeToCubeEdges",), + 0x8017ABBC:("Math3D_PointRelativeToCubeVertices",), + 0x8017AD38:("Math3D_LineVsCube",), 0x8017B68C:("func_8017B68C",), 0x8017B7F8:("func_8017B7F8",), 0x8017B884:("Math3D_UnitNormalVector",), 0x8017B998:("Math3D_SignedDistanceFromPlane",), 0x8017B9D8:("func_8017B9D8",), - 0x8017BA14:("Math3D_NormalizedDistanceFromPlane",), - 0x8017BA4C:("Math3D_NormalizedSignedDistanceFromPlane",), - 0x8017BAD0:("func_8017BAD0",), + 0x8017BA14:("Math3D_UDistPlaneToPos",), + 0x8017BA4C:("Math3D_DistPlaneToPos",), + 0x8017BAD0:("Math3D_TriChkPointParaYDist",), 0x8017BD98:("func_8017BD98",), 0x8017BDE0:("func_8017BDE0",), - 0x8017BE30:("func_8017BE30",), - 0x8017BEE0:("func_8017BEE0",), + 0x8017BE30:("Math3D_TriChkPointParaYIntersectDist",), + 0x8017BEE0:("Math3D_TriChkPointParaYIntersectInsideTri",), 0x8017BF8C:("func_8017BF8C",), - 0x8017C008:("func_8017C008",), + 0x8017C008:("Math3D_TriChkLineSegParaYIntersect",), 0x8017C17C:("func_8017C17C",), 0x8017C1F0:("func_8017C1F0",), - 0x8017C494:("func_8017C494",), - 0x8017C540:("func_8017C540",), + 0x8017C494:("Math3D_TriChkPointParaYIntersectInsideTri2",), + 0x8017C540:("Math3D_TriChkPointParaXDist",), 0x8017C808:("func_8017C808",), - 0x8017C850:("func_8017C850",), + 0x8017C850:("Math3D_TriChkPointParaXIntersect",), 0x8017C904:("func_8017C904",), - 0x8017C980:("func_8017C980",), + 0x8017C980:("Math3D_TriChkLineSegParaXIntersect",), 0x8017CB08:("func_8017CB08",), - 0x8017CB7C:("func_8017CB7C",), + 0x8017CB7C:("Math3D_TriChkLineSegParaZDist",), 0x8017CEA8:("func_8017CEA8",), - 0x8017CEF0:("func_8017CEF0",), + 0x8017CEF0:("Math3D_TriChkPointParaZIntersect",), 0x8017CFA4:("func_8017CFA4",), - 0x8017D020:("func_8017D020",), + 0x8017D020:("Math3D_TriChkLineSegParaZIntersect",), 0x8017D1AC:("func_8017D1AC",), 0x8017D220:("func_8017D220",), 0x8017D2FC:("func_8017D2FC",), @@ -3329,14 +3329,14 @@ 0x8017D814:("func_8017D814",), 0x8017D91C:("func_8017D91C",), 0x8017DA24:("func_8017DA24",), - 0x8017DB2C:("Math3D_ColSphereLineSeg",), + 0x8017DB2C:("Math3D_LineVsSph",), 0x8017DD34:("func_8017DD34",), 0x8017DE74:("Math3D_ColSphereTri",), 0x8017E294:("func_8017E294",), 0x8017E350:("func_8017E350",), 0x8017ED20:("Math3D_ColCylinderTri",), 0x8017F1A0:("func_8017F1A0",), - 0x8017F1C0:("Math3D_ColSphereSphere",), + 0x8017F1C0:("Math3D_SphVsSph",), 0x8017F1E0:("Math3D_ColSphereSphereIntersect",), 0x8017F200:("Math3D_ColSphereSphereIntersectAndDistance",), 0x8017F2CC:("Math3D_ColSphereCylinderDistance",), @@ -3344,9 +3344,9 @@ 0x8017F45C:("Math3D_ColCylinderCylinderAmount",), 0x8017F47C:("Math3D_ColCylinderCylinderAmountAndDistance",), 0x8017F64C:("Math3d_ColTriTri",), - 0x8017F9C0:("func_8017F9C0",), - 0x8017FA34:("func_8017FA34",), - 0x8017FAA8:("func_8017FAA8",), + 0x8017F9C0:("Math3D_XZInSphere",), + 0x8017FA34:("Math3D_XYInSphere",), + 0x8017FAA8:("Math3D_YZInSphere",), 0x8017FB1C:("func_8017FB1C",), 0x8017FD44:("func_8017FD44",), 0x8017FEB0:("Math_GetAtan2Tbl",), diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index 35716f88b2..66e7166c98 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -453,14 +453,8 @@ 0x801AEFC0:("D_801AEFC0","UNK_TYPE1","",0x1), 0x801AEFD0:("gActorOverlayTable","ActorOverlay","[ACTOR_ID_MAX]",0x5640), 0x801B4610:("gMaxActorId","s32","",0x4), - 0x801B4620:("D_801B4620","u32","[32]",0x80), - 0x801B46A0:("D_801B46A0","u16","[16]",0x20), - 0x801B46C0:("D_801B46C0","u8","[16]",0x10), - 0x801B46D0:("bgSpecialSceneParamsDefault","s16","[1]",0x2), - 0x801B46D2:("D_801B46D2","UNK_TYPE1","",0x1), - 0x801B46D4:("bgSpecialSceneMaxMemory","BgSpecialSceneMaxMemory","[1]",0x8), - 0x801B46DC:("bgSpecialSceneMeshSubdivisions","BgSpecialSceneMeshSubdivision","[3]",0x24), - 0x801B4700:("bgSpecialSceneMaxObjects","BgSpecialSceneMaxObjects","[1]",0x8), + 0x801B46DC:("sSceneSubdivisionList","BgCheckSceneSubdivisionEntry","[3]",0x24), + 0x801B4700:("sCustomDynapolyMem","BgSpecialSceneMaxObjects","[1]",0x8), 0x801B4708:("D_801B4708","UNK_TYPE1","",0x1), 0x801B4710:("D_801B4710","UNK_TYPE1","",0x1), 0x801B4738:("D_801B4738","UNK_TYPE1","",0x1), @@ -3924,34 +3918,17 @@ 0x801ED940:("D_801ED940","FaultAddrConvClient","",0xc), 0x801ED950:("D_801ED950","char","[80]",0x50), 0x801ED9A0:("D_801ED9A0","char","[80]",0x50), - 0x801ED9F0:("D_801ED9F0","Vec3f","",0xc), - 0x801ED9FC:("D_801ED9FC","Vec3f","",0xc), - 0x801EDA08:("D_801EDA08","Vec3f","",0xc), - 0x801EDA18:("D_801EDA18","Vec3f","",0xc), - 0x801EDA24:("D_801EDA24","Vec3f","",0xc), - 0x801EDA30:("D_801EDA30","Vec3f","",0xc), + 0x801ED9F0:("D_801ED9F0","Vec3f","[3]",0x24), + 0x801EDA18:("D_801EDA18","Vec3f","[3]",0x24), 0x801EDA40:("D_801EDA40","MtxF","",0x40), - 0x801EDA80:("D_801EDA80","Vec3f","",0xc), - 0x801EDA8C:("D_801EDA8C","Vec3f","",0xc), - 0x801EDA98:("D_801EDA98","Vec3f","",0xc), + 0x801EDA80:("D_801EDA80","Vec3f","[3]",0x24), 0x801EDAA8:("D_801EDAA8","char","[80]",0x50), 0x801EDAF8:("D_801EDAF8","char","[80]",0x50), - 0x801EDB48:("D_801EDB48","Vec3f","",0xc), - 0x801EDB54:("D_801EDB54","Vec3f","",0xc), - 0x801EDB60:("D_801EDB60","Vec3f","",0xc), - 0x801EDB70:("D_801EDB70","Vec3f","",0xc), - 0x801EDB7C:("D_801EDB7C","Vec3f","",0xc), - 0x801EDB88:("D_801EDB88","Vec3f","",0xc), - 0x801EDB98:("D_801EDB98","f32","",0x4), - 0x801EDB9C:("D_801EDB9C","f32","",0x4), - 0x801EDBA0:("D_801EDBA0","f32","",0x4), - 0x801EDBA4:("D_801EDBA4","UNK_TYPE1","",0x1), + 0x801EDB48:("D_801EDB48","Vec3f","[3]",0x24), + 0x801EDB70:("D_801EDB70","Vec3f","[3]",0x24), + 0x801EDB98:("D_801EDB98","Plane","",0x10), 0x801EDBA8:("D_801EDBA8","Sphere16","",0x8), 0x801EDBB0:("D_801EDBB0","TriNorm","",0x34), - 0x801EDBD4:("D_801EDBD4","UNK_TYPE1","",0x1), - 0x801EDBD8:("D_801EDBD8","UNK_TYPE1","",0x1), - 0x801EDBDC:("D_801EDBDC","UNK_TYPE1","",0x1), - 0x801EDBE0:("D_801EDBE0","UNK_TYPE1","",0x1), 0x801EDBF0:("D_801EDBF0","s16","",0x2), 0x801EDBF4:("D_801EDBF4","UNK_TYPE1","",0x1), 0x801EDBF8:("D_801EDBF8","UNK_TYPE1","",0x1),