From 126a3dcaffcefcc4d405308bc31a48bd7e84c62e Mon Sep 17 00:00:00 2001 From: ser-pounce Date: Sat, 16 Dec 2023 17:53:28 +0100 Subject: [PATCH] Dedupe FindFirstUnkPrim (#852) Follows discussion on https://github.com/Xeeynamo/sotn-decomp/pull/848, not too sure about interim function name. --- src/st/cen/1B274.c | 11 +---------- src/st/dre/1E1C8.c | 11 +---------- src/st/find_first_unk_prim.h | 10 ++++++++++ src/st/mad/15520.c | 11 +---------- src/st/no3/377D4.c | 6 ++++-- src/st/no3/564B0.c | 11 +---------- src/st/no3/no3.h | 2 +- src/st/np3/3246C.c | 5 +++-- src/st/np3/4E69C.c | 11 +---------- src/st/nz0/49930.c | 11 +---------- src/st/rwrp/14590.c | 11 +---------- src/st/st0/36358.c | 9 +-------- src/st/wrp/F420.c | 9 +-------- 13 files changed, 27 insertions(+), 91 deletions(-) create mode 100644 src/st/find_first_unk_prim.h diff --git a/src/st/cen/1B274.c b/src/st/cen/1B274.c index f2d085e05..2cbfa63ea 100644 --- a/src/st/cen/1B274.c +++ b/src/st/cen/1B274.c @@ -252,16 +252,7 @@ void BottomCornerText(u8* str, u8 lower_left) { INCLUDE_ASM("asm/us/st/cen/nonmatchings/1B274", func_8019C2BC); -POLY_GT4* func_8019C40C(POLY_GT4* poly) { - while (poly != NULL) { - if (poly->p3 != 0) { - poly = (POLY_GT4*)poly->tag; - } else { - return poly; - } - } - return NULL; -} +#include "../find_first_unk_prim.h" POLY_GT4* func_8019C43C(POLY_GT4* poly, u8 index) { if (poly) { diff --git a/src/st/dre/1E1C8.c b/src/st/dre/1E1C8.c index 29ea6efa7..6b5490d30 100644 --- a/src/st/dre/1E1C8.c +++ b/src/st/dre/1E1C8.c @@ -752,16 +752,7 @@ void BottomCornerText(u8* str, u8 lower_left) { INCLUDE_ASM("asm/us/st/dre/nonmatchings/1E1C8", func_801A2400); -POLY_GT4* func_801A2550(POLY_GT4* poly) { - while (poly != NULL) { - if (poly->p3 != 0) { - poly = (POLY_GT4*)poly->tag; - } else { - return poly; - } - } - return NULL; -} +#include "../find_first_unk_prim.h" INCLUDE_ASM("asm/us/st/dre/nonmatchings/1E1C8", func_801A2580); diff --git a/src/st/find_first_unk_prim.h b/src/st/find_first_unk_prim.h new file mode 100644 index 000000000..43870cdb9 --- /dev/null +++ b/src/st/find_first_unk_prim.h @@ -0,0 +1,10 @@ +Primitive* FindFirstUnkPrim(Primitive* poly) { + while (poly != NULL) { + if (poly->p3 != 0) { + poly = poly->next; + } else { + return poly; + } + } + return NULL; +} \ No newline at end of file diff --git a/src/st/mad/15520.c b/src/st/mad/15520.c index 4610be34e..0b67b3f17 100644 --- a/src/st/mad/15520.c +++ b/src/st/mad/15520.c @@ -567,16 +567,7 @@ INCLUDE_ASM("asm/us/st/mad/nonmatchings/15520", func_80198BC8); INCLUDE_ASM("asm/us/st/mad/nonmatchings/15520", func_80199388); -POLY_GT4* func_801994D8(POLY_GT4* poly) { - while (poly != NULL) { - if (poly->p3 != 0) { - poly = (POLY_GT4*)poly->tag; - } else { - return poly; - } - } - return NULL; -} +#include "../find_first_unk_prim.h" INCLUDE_ASM("asm/us/st/mad/nonmatchings/15520", func_80199508); diff --git a/src/st/no3/377D4.c b/src/st/no3/377D4.c index 4ed77e421..ad2329a41 100644 --- a/src/st/no3/377D4.c +++ b/src/st/no3/377D4.c @@ -726,7 +726,8 @@ void EntityCavernDoor(Entity* self) { } if (!(g_Timer & 1)) { - poly = func_801D6DB8((POLY_GT4*)(*(s32*)&self->ext.generic.unk7C)); + poly = + FindFirstUnkPrim((Primitive*)(*(s32*)&self->ext.generic.unk7C)); if (poly != NULL) { poly->p3 = 1; } @@ -1699,7 +1700,8 @@ void EntityHeartRoomGoldDoor(Entity* self) { } if (!(g_Timer & 1)) { - poly = func_801D6DB8((POLY_GT4*)(*(s32*)&self->ext.generic.unk7C)); + poly = + FindFirstUnkPrim((POLY_GT4*)(*(s32*)&self->ext.generic.unk7C)); if (poly != NULL) { poly->p3 = 1; } diff --git a/src/st/no3/564B0.c b/src/st/no3/564B0.c index 9b3b59f68..4297cf63c 100644 --- a/src/st/no3/564B0.c +++ b/src/st/no3/564B0.c @@ -127,16 +127,7 @@ void EntityZombieSpawner(Entity* self) { INCLUDE_ASM("asm/us/st/no3/nonmatchings/564B0", func_801D6C68); -POLY_GT4* func_801D6DB8(POLY_GT4* poly) { - while (poly != NULL) { - if (poly->p3 != 0) { - poly = (POLY_GT4*)poly->tag; - } else { - return poly; - } - } - return NULL; -} +#include "../find_first_unk_prim.h" POLY_GT4* func_8019C43C(POLY_GT4* poly, u8 index) { if (poly) { diff --git a/src/st/no3/no3.h b/src/st/no3/no3.h index 4bda7655b..cb45655db 100644 --- a/src/st/no3/no3.h +++ b/src/st/no3/no3.h @@ -81,7 +81,7 @@ typedef enum EntityIDs { extern void CreateEntityFromCurrentEntity(u16, Entity*); extern void ReplaceBreakableWithItemDrop(Entity*); extern s32 func_801C5D18(Entity* entity, s32 arg1, s32 arg2, s32 arg3); -extern POLY_GT4* func_801D6DB8(POLY_GT4* poly); +extern Primitive* FindFirstUnkPrim(Primitive* poly); extern LayoutEntity* D_80180850[]; extern u16 g_InitializeData0[]; diff --git a/src/st/np3/3246C.c b/src/st/np3/3246C.c index fda8f5167..14448d430 100644 --- a/src/st/np3/3246C.c +++ b/src/st/np3/3246C.c @@ -667,7 +667,8 @@ void func_801B40F8(Entity* self) { } if (!(g_Timer & 1)) { - poly = func_801D2470((POLY_GT4*)(*(s32*)&self->ext.generic.unk7C)); + poly = + FindFirstUnkPrim((Primitive*)(*(s32*)&self->ext.generic.unk7C)); if (poly != NULL) { poly->p3 = 1; } @@ -1577,7 +1578,7 @@ void EntityHeartRoomGoldDoor(Entity* self) { } if (!(g_Timer & 1)) { - prim = func_801D2470(self->ext.heartRoomGoldDoor.prim); + prim = FindFirstUnkPrim(self->ext.heartRoomGoldDoor.prim); if (prim != NULL) { prim->p3 = 1; } diff --git a/src/st/np3/4E69C.c b/src/st/np3/4E69C.c index 043de07d5..360b0b8d3 100644 --- a/src/st/np3/4E69C.c +++ b/src/st/np3/4E69C.c @@ -465,16 +465,7 @@ void EntityBladeSword(Entity* self) { INCLUDE_ASM("asm/us/st/np3/nonmatchings/4E69C", func_801D2320); -Primitive* func_801D2470(Primitive* prim) { - while (prim != NULL) { - if (prim->p3 != 0) { - prim = prim->next; - } else { - return prim; - } - } - return NULL; -} +#include "../find_first_unk_prim.h" Primitive* func_801D24A0(Primitive* prim, u8 index) { if (prim) { diff --git a/src/st/nz0/49930.c b/src/st/nz0/49930.c index 9266dcaa8..6fe33a65a 100644 --- a/src/st/nz0/49930.c +++ b/src/st/nz0/49930.c @@ -4,16 +4,7 @@ INCLUDE_ASM("asm/us/st/nz0/nonmatchings/49930", func_801C9D18); -Primitive* func_801C9E68(Primitive* poly) { - while (poly != NULL) { - if (poly->p3 != 0) { - poly = poly->next; - } else { - return poly; - } - } - return NULL; -} +#include "../find_first_unk_prim.h" Primitive* func_801C9E98(Primitive* prim, u8 index) { if (prim) { diff --git a/src/st/rwrp/14590.c b/src/st/rwrp/14590.c index 7f7a2228b..bf1678dbf 100644 --- a/src/st/rwrp/14590.c +++ b/src/st/rwrp/14590.c @@ -116,16 +116,7 @@ INCLUDE_ASM("asm/us/st/rwrp/nonmatchings/14590", BottomCornerText); INCLUDE_ASM("asm/us/st/rwrp/nonmatchings/14590", func_801955D8); -POLY_GT4* func_80195728(POLY_GT4* poly) { - while (poly != NULL) { - if (poly->p3 != 0) { - poly = (POLY_GT4*)poly->tag; - } else { - return poly; - } - } - return NULL; -} +#include "../find_first_unk_prim.h" INCLUDE_ASM("asm/us/st/rwrp/nonmatchings/14590", func_80195758); diff --git a/src/st/st0/36358.c b/src/st/st0/36358.c index c5da59d1b..c3124b2b6 100644 --- a/src/st/st0/36358.c +++ b/src/st/st0/36358.c @@ -1058,14 +1058,7 @@ INCLUDE_ASM("asm/us/st/st0/nonmatchings/36358", func_801BC5C0); INCLUDE_ASM("asm/us/st/st0/nonmatchings/36358", func_801BD4A8); -POLY_GT4* func_801BD5F8(POLY_GT4* poly) { - while (poly) { - if (poly->p3 == 0) - return poly; - poly = (POLY_GT4*)poly->tag; - } - return NULL; -} +#include "../find_first_unk_prim.h" POLY_GT4* func_801BD628(POLY_GT4* poly, u8 index) { if (poly) { diff --git a/src/st/wrp/F420.c b/src/st/wrp/F420.c index 930853ebc..8f9422f61 100644 --- a/src/st/wrp/F420.c +++ b/src/st/wrp/F420.c @@ -1039,14 +1039,7 @@ void BottomCornerText(u8* str, u8 lower_left) { INCLUDE_ASM("asm/us/st/wrp/nonmatchings/F420", func_80193658); -POLY_GT4* func_801937A8(POLY_GT4* poly) { - while (poly) { - if (poly->p3 == 0) - return poly; - poly = (POLY_GT4*)poly->tag; - } - return NULL; -} +#include "../find_first_unk_prim.h" POLY_GT4* func_801937D8(POLY_GT4* poly, u8 index) { if (poly) {