From 782fdfd32eb77595192b5d39c9183f46feaf6e33 Mon Sep 17 00:00:00 2001 From: bismurphy Date: Fri, 14 Jun 2024 22:15:15 -0400 Subject: [PATCH] De-duplicate the first of the recursive prim functions (#1323) Fairly straightforward de-duplication. If anyone has better names for either the function or the array it uses, feel free to suggest them, but with this thing being so weird and its purpose being unknown, I had to keep the names pretty generic. --- config/symbols.stmad.txt | 1 + config/symbols.us.stcen.txt | 1 + config/symbols.us.stdre.txt | 1 + config/symbols.us.stno3.txt | 1 + config/symbols.us.stnp3.txt | 1 + config/symbols.us.stnz0.txt | 1 + config/symbols.us.strwrp.txt | 1 + config/symbols.us.stst0.txt | 1 + src/st/cen/18084.c | 2 +- src/st/dre/1E1C8.c | 2 +- src/st/mad/15520.c | 2 +- src/st/no3/48A84.c | 2 +- src/st/np3/402F4.c | 2 +- src/st/nz0/4070C.c | 2 +- src/st/rwrp/113A0.c | 2 +- src/st/st0/36358.c | 2 +- src/st/unk_recursive_primfunc_1.h | 108 +++++++++++++++++++++++++++++ src/st/wrp/e_misc.c | 109 +----------------------------- 18 files changed, 127 insertions(+), 114 deletions(-) create mode 100644 src/st/unk_recursive_primfunc_1.h diff --git a/config/symbols.stmad.txt b/config/symbols.stmad.txt index 07c24356a..6ca54ec96 100644 --- a/config/symbols.stmad.txt +++ b/config/symbols.stmad.txt @@ -24,6 +24,7 @@ unk15_yVel = 0x80180FCC; g_Rooms = 0x80181130; g_eRedDoorTiles = 0x80180594; g_olroxDroolCollOffsets = 0x80181008; +g_UnkRecursPrimVecOrder = 0x80181020; g_pStrObjLayout0 = 0x801811D4; g_pStrObjLayout1 = 0x801811E8; g_pStrObjLayout2 = 0x80181206; diff --git a/config/symbols.us.stcen.txt b/config/symbols.us.stcen.txt index 95475cede..2d28bb4cc 100644 --- a/config/symbols.us.stcen.txt +++ b/config/symbols.us.stcen.txt @@ -24,6 +24,7 @@ unk14_yVel = 0x80181148; unk14_startFrame = 0x80181160; unk14_lifetime = 0x80181164; g_olroxDroolCollOffsets = 0x8018116C; +g_UnkRecursPrimVecOrder = 0x80181184; g_ESoulStealOrbAngles = 0x801811C8; g_ESoulStealOrbSprt = 0x801811D8; g_ESoulStealOrbAnim = 0x80181238; diff --git a/config/symbols.us.stdre.txt b/config/symbols.us.stdre.txt index d24fd5e3c..05b8448f5 100644 --- a/config/symbols.us.stdre.txt +++ b/config/symbols.us.stdre.txt @@ -30,6 +30,7 @@ unk14_yVel = 0x8018130C; unk14_startFrame = 0x80181324; unk14_lifetime = 0x80181328; g_olroxDroolCollOffsets = 0x80181330; +g_UnkRecursPrimVecOrder = 0x80181348; g_ESoulStealOrbAngles = 0x8018138C; g_ESoulStealOrbSprt = 0x8018139C; g_ESoulStealOrbAnim = 0x801813FC; diff --git a/config/symbols.us.stno3.txt b/config/symbols.us.stno3.txt index 0810338ba..c6b5fd7c1 100644 --- a/config/symbols.us.stno3.txt +++ b/config/symbols.us.stno3.txt @@ -30,6 +30,7 @@ unk14_yVel = 0x80182650; unk14_startFrame = 0x80182668; unk14_lifetime = 0x8018266C; g_olroxDroolCollOffsets = 0x80182674; +g_UnkRecursPrimVecOrder = 0x8018268C; g_ESoulStealOrbAngles = 0x801826D0; g_ESoulStealOrbSprt = 0x801826E0; g_ESoulStealOrbAnim = 0x80182740; diff --git a/config/symbols.us.stnp3.txt b/config/symbols.us.stnp3.txt index 0f8d8bfcd..a1df9f85c 100644 --- a/config/symbols.us.stnp3.txt +++ b/config/symbols.us.stnp3.txt @@ -30,6 +30,7 @@ unk14_yVel = 0x80181FDC; unk14_startFrame = 0x80181FF4; unk14_lifetime = 0x80181FF8; g_olroxDroolCollOffsets = 0x80182000; +g_UnkRecursPrimVecOrder = 0x80182018; g_ESoulStealOrbAngles = 0x8018205C; g_ESoulStealOrbSprt = 0x8018206C; g_ESoulStealOrbAnim = 0x801820CC; diff --git a/config/symbols.us.stnz0.txt b/config/symbols.us.stnz0.txt index 699225473..e7f97121f 100644 --- a/config/symbols.us.stnz0.txt +++ b/config/symbols.us.stnz0.txt @@ -24,6 +24,7 @@ unk14_yVel = 0x80181F04; unk14_startFrame = 0x80181F1C; unk14_lifetime = 0x80181F20; g_olroxDroolCollOffsets = 0x80181F28; +g_UnkRecursPrimVecOrder = 0x80181F40; g_eBlueDoorUV = 0x801826B8; g_eBlueDoorTiles = 0x801826D0; g_Rooms = 0x8018272C; diff --git a/config/symbols.us.strwrp.txt b/config/symbols.us.strwrp.txt index b40a20456..fdb24d56a 100644 --- a/config/symbols.us.strwrp.txt +++ b/config/symbols.us.strwrp.txt @@ -23,6 +23,7 @@ unk14_yVel = 0x80181020; unk14_startFrame = 0x80181038; unk14_lifetime = 0x8018103C; g_olroxDroolCollOffsets = 0x80181044; +g_UnkRecursPrimVecOrder = 0x8018105C; g_ESoulStealOrbAngles = 0x801810A0; g_ESoulStealOrbSprt = 0x801810B0; g_ESoulStealOrbAnim = 0x80181110; diff --git a/config/symbols.us.stst0.txt b/config/symbols.us.stst0.txt index 6d738ab31..2f0004ce9 100644 --- a/config/symbols.us.stst0.txt +++ b/config/symbols.us.stst0.txt @@ -22,6 +22,7 @@ unk14_yVel = 0x80181ED8; unk14_startFrame = 0x80181EF0; unk14_lifetime = 0x80181EF4; g_olroxDroolCollOffsets = 0x80181EFC; +g_UnkRecursPrimVecOrder = 0x80181F14; g_ESoulStealOrbAngles = 0x80181F54; g_ESoulStealOrbSprt = 0x80181F64; g_ESoulStealOrbAnim = 0x80181FC4; diff --git a/src/st/cen/18084.c b/src/st/cen/18084.c index 52b686a94..6a6e23bf3 100644 --- a/src/st/cen/18084.c +++ b/src/st/cen/18084.c @@ -281,7 +281,7 @@ void func_801991C0(void) { #include "../entity_big_red_fireball.h" -INCLUDE_ASM("st/cen/nonmatchings/18084", func_80199450); +#include "../unk_recursive_primfunc_1.h" INCLUDE_ASM("st/cen/nonmatchings/18084", func_80199A30); diff --git a/src/st/dre/1E1C8.c b/src/st/dre/1E1C8.c index 122e6c8c6..2b5ec7d05 100644 --- a/src/st/dre/1E1C8.c +++ b/src/st/dre/1E1C8.c @@ -282,7 +282,7 @@ void func_8019F304(void) { #include "../entity_big_red_fireball.h" -INCLUDE_ASM("st/dre/nonmatchings/1E1C8", func_8019F594); +#include "../unk_recursive_primfunc_1.h" INCLUDE_ASM("st/dre/nonmatchings/1E1C8", func_8019FB74); diff --git a/src/st/mad/15520.c b/src/st/mad/15520.c index d850f3c03..5d93d098e 100644 --- a/src/st/mad/15520.c +++ b/src/st/mad/15520.c @@ -354,7 +354,7 @@ void func_80196934(void) { #include "../entity_big_red_fireball.h" -INCLUDE_ASM("asm/us/st/mad/nonmatchings/15520", func_80196BC4); +#include "../unk_recursive_primfunc_1.h" INCLUDE_ASM("asm/us/st/mad/nonmatchings/15520", func_801971A4); diff --git a/src/st/no3/48A84.c b/src/st/no3/48A84.c index 223e6a7cb..76d8554be 100644 --- a/src/st/no3/48A84.c +++ b/src/st/no3/48A84.c @@ -275,7 +275,7 @@ void func_801C9BC0(void) { #include "../entity_big_red_fireball.h" -INCLUDE_ASM("st/no3/nonmatchings/48A84", func_801C9E50); +#include "../unk_recursive_primfunc_1.h" INCLUDE_ASM("st/no3/nonmatchings/48A84", func_801CA430); diff --git a/src/st/np3/402F4.c b/src/st/np3/402F4.c index 9b1061246..55537aea2 100644 --- a/src/st/np3/402F4.c +++ b/src/st/np3/402F4.c @@ -279,7 +279,7 @@ void func_801C1848(void) { #include "../entity_big_red_fireball.h" -INCLUDE_ASM("st/np3/nonmatchings/402F4", func_801C16C0); +#include "../unk_recursive_primfunc_1.h" INCLUDE_ASM("st/np3/nonmatchings/402F4", func_801C1CA0); diff --git a/src/st/nz0/4070C.c b/src/st/nz0/4070C.c index 0e1d10e03..2177e96cf 100644 --- a/src/st/nz0/4070C.c +++ b/src/st/nz0/4070C.c @@ -313,7 +313,7 @@ void func_801C1848(void) { #include "../entity_big_red_fireball.h" -INCLUDE_ASM("st/nz0/nonmatchings/4070C", func_801C1AD8); +#include "../unk_recursive_primfunc_1.h" INCLUDE_ASM("st/nz0/nonmatchings/4070C", func_801C20B8); diff --git a/src/st/rwrp/113A0.c b/src/st/rwrp/113A0.c index 71b2d3df8..6443b8985 100644 --- a/src/st/rwrp/113A0.c +++ b/src/st/rwrp/113A0.c @@ -212,7 +212,7 @@ void func_801924DC(void) { } #include "../entity_big_red_fireball.h" -INCLUDE_ASM("st/rwrp/nonmatchings/113A0", func_8019276C); +#include "../unk_recursive_primfunc_1.h" INCLUDE_ASM("st/rwrp/nonmatchings/113A0", func_80192D4C); diff --git a/src/st/st0/36358.c b/src/st/st0/36358.c index 6a2526117..d6ec8b94c 100644 --- a/src/st/st0/36358.c +++ b/src/st/st0/36358.c @@ -704,7 +704,7 @@ void func_801B8C48(void) { #include "../entity_big_red_fireball.h" -INCLUDE_ASM("st/st0/nonmatchings/36358", func_801B8ED8); +#include "../unk_recursive_primfunc_1.h" INCLUDE_ASM("st/st0/nonmatchings/36358", func_801B94B8); diff --git a/src/st/unk_recursive_primfunc_1.h b/src/st/unk_recursive_primfunc_1.h new file mode 100644 index 000000000..58e76a83f --- /dev/null +++ b/src/st/unk_recursive_primfunc_1.h @@ -0,0 +1,108 @@ +extern u16 g_UnkRecursPrimVecOrder[]; + +// arg7 holds, in order: +// a Primitive, an array of 9 SVECTORs, an array of 10 uvPairs, and a pointer to +// another of arg7. +// arg7 is not actually u8* but windows doesn't like void* I guess? + +Primitive* UnkRecursivePrimFunc1( + SVECTOR* arg0, SVECTOR* arg1, SVECTOR* arg2, SVECTOR* arg3, Primitive* arg4, + s32 arg5, Primitive* arg6, u8* arg7) { + s32 unused1; + s32 unused2; + s32 i; + Primitive* prim1; + Primitive* prim2; + s32 vecIdx1; + s32 vecIdx2; + s32 vecIdx3; + s32 vecIdx4; + s16* vecIndices; + s32 rotTransResult; + SVECTOR* vectors; + uvPair* uv_values; + Primitive* nextArg6; + + if (arg6 == NULL) { + return NULL; + } + prim2 = arg7; + arg7 += 0x34; + vectors = arg7; + arg7 += 0x48; + + vectors[0] = *arg0; + vectors[2] = *arg1; + vectors[6] = *arg2; + vectors[8] = *arg3; + + uv_values = arg7; + arg7 += 0x14; // This is effectively arg7 = arg7->next, since this covers + // the full size of arg7. + + prim1 = prim2; + vectors[1].vx = (vectors[0].vx + vectors[2].vx + 1) >> 1; + vectors[1].vy = (vectors[0].vy + vectors[2].vy + 1) >> 1; + vectors[1].vz = (vectors[0].vz + vectors[2].vz + 1) >> 1; + vectors[7].vx = (vectors[6].vx + vectors[8].vx + 1) >> 1; + vectors[7].vy = (vectors[6].vy + vectors[8].vy + 1) >> 1; + vectors[7].vz = (vectors[6].vz + vectors[8].vz + 1) >> 1; + vectors[3].vx = (vectors[0].vx + vectors[6].vx + 1) >> 1; + vectors[3].vy = (vectors[0].vy + vectors[6].vy + 1) >> 1; + vectors[3].vz = (vectors[0].vz + vectors[6].vz + 1) >> 1; + vectors[5].vx = (vectors[2].vx + vectors[8].vx + 1) >> 1; + vectors[5].vy = (vectors[2].vy + vectors[8].vy + 1) >> 1; + vectors[5].vz = (vectors[2].vz + vectors[8].vz + 1) >> 1; + vectors[4].vx = (vectors[3].vx + vectors[5].vx + 1) >> 1; + vectors[4].vy = (vectors[3].vy + vectors[5].vy + 1) >> 1; + vectors[4].vz = (vectors[3].vz + vectors[5].vz + 1) >> 1; + + uv_values[0] = *(uvPair*)&arg4->u0; + uv_values[2] = *(uvPair*)&arg4->u1; + uv_values[6] = *(uvPair*)&arg4->u2; + uv_values[8] = *(uvPair*)&arg4->u3; + uv_values[1].u = (uv_values[0].u + uv_values[2].u + 1) >> 1; + uv_values[1].v = (uv_values[0].v + uv_values[2].v + 1) >> 1; + uv_values[7].u = (uv_values[6].u + uv_values[8].u + 1) >> 1; + uv_values[7].v = (uv_values[6].v + uv_values[8].v + 1) >> 1; + uv_values[3].u = (uv_values[0].u + uv_values[6].u + 1) >> 1; + uv_values[3].v = (uv_values[0].v + uv_values[6].v + 1) >> 1; + uv_values[5].u = (uv_values[2].u + uv_values[8].u + 1) >> 1; + uv_values[5].v = (uv_values[2].v + uv_values[8].v + 1) >> 1; + uv_values[4].u = (uv_values[3].u + uv_values[5].u + 1) >> 1; + uv_values[4].v = (uv_values[3].v + uv_values[5].v + 1) >> 1; + + *prim1 = *arg4; + vecIndices = &g_UnkRecursPrimVecOrder; + for (i = 0; i < 4; i++) { + vecIdx1 = *vecIndices++; + vecIdx2 = *vecIndices++; + vecIdx3 = *vecIndices++; + vecIdx4 = *vecIndices++; + rotTransResult = RotTransPers4( + &vectors[vecIdx1], &vectors[vecIdx2], &vectors[vecIdx3], + &vectors[vecIdx4], &prim2->x0, &prim2->x1, &prim2->x2, &prim2->x3, + &unused1, &unused2); + *(uvPair*)&prim2->u0 = uv_values[vecIdx1]; + *(uvPair*)&prim2->u1 = uv_values[vecIdx2]; + *(uvPair*)&prim2->u2 = uv_values[vecIdx3]; + *(uvPair*)&prim2->u3 = uv_values[vecIdx4]; + if (arg5 == 1) { + prim1 = arg6; + if (rotTransResult > 0) { + nextArg6 = arg6->next; + *prim1 = *prim2; + arg6->next = nextArg6; + arg6 = nextArg6; + if (arg6 == NULL) { + return NULL; + } + } + } else { + arg6 = UnkRecursivePrimFunc1( + &vectors[vecIdx1], &vectors[vecIdx2], &vectors[vecIdx3], + &vectors[vecIdx4], prim2, arg5 - 1, arg6, arg7); + } + } + return arg6; +} diff --git a/src/st/wrp/e_misc.c b/src/st/wrp/e_misc.c index 966326ce2..fda853fe6 100644 --- a/src/st/wrp/e_misc.c +++ b/src/st/wrp/e_misc.c @@ -407,114 +407,11 @@ void func_8019055C(void) { } extern u8 g_bigRedFireballAnim[]; -u16 D_8018105C[] = {0, 1, 3, 4, 1, 2, 4, 5, 3, 4, 6, 7, 4, 5, 7, 8}; +u16 g_UnkRecursPrimVecOrder[] = { + 0, 1, 3, 4, 1, 2, 4, 5, 3, 4, 6, 7, 4, 5, 7, 8}; #include "../entity_big_red_fireball.h" -// arg7 holds, in order: -// a Primitive, an array of 9 SVECTORs, an array of 10 uvPairs, and a pointer to -// another of arg7. -// arg7 is not actually u8* but windows doesn't like void* I guess? -Primitive* func_801907EC( - SVECTOR* arg0, SVECTOR* arg1, SVECTOR* arg2, SVECTOR* arg3, Primitive* arg4, - s32 arg5, Primitive* arg6, u8* arg7) { - s32 unused1; - s32 unused2; - s32 i; - Primitive* prim1; - Primitive* prim2; - s32 vecIdx1; - s32 vecIdx2; - s32 vecIdx3; - s32 vecIdx4; - s16* vecIndices; - s32 rotTransResult; - SVECTOR* vectors; - uvPair* uv_values; - Primitive* nextArg6; - - if (arg6 == NULL) { - return NULL; - } - prim2 = arg7; - arg7 += 0x34; - vectors = arg7; - arg7 += 0x48; - - vectors[0] = *arg0; - vectors[2] = *arg1; - vectors[6] = *arg2; - vectors[8] = *arg3; - - uv_values = arg7; - arg7 += 0x14; // This is effectively arg7 = arg7->next, since this covers - // the full size of arg7. - - prim1 = prim2; - vectors[1].vx = (vectors[0].vx + vectors[2].vx + 1) >> 1; - vectors[1].vy = (vectors[0].vy + vectors[2].vy + 1) >> 1; - vectors[1].vz = (vectors[0].vz + vectors[2].vz + 1) >> 1; - vectors[7].vx = (vectors[6].vx + vectors[8].vx + 1) >> 1; - vectors[7].vy = (vectors[6].vy + vectors[8].vy + 1) >> 1; - vectors[7].vz = (vectors[6].vz + vectors[8].vz + 1) >> 1; - vectors[3].vx = (vectors[0].vx + vectors[6].vx + 1) >> 1; - vectors[3].vy = (vectors[0].vy + vectors[6].vy + 1) >> 1; - vectors[3].vz = (vectors[0].vz + vectors[6].vz + 1) >> 1; - vectors[5].vx = (vectors[2].vx + vectors[8].vx + 1) >> 1; - vectors[5].vy = (vectors[2].vy + vectors[8].vy + 1) >> 1; - vectors[5].vz = (vectors[2].vz + vectors[8].vz + 1) >> 1; - vectors[4].vx = (vectors[3].vx + vectors[5].vx + 1) >> 1; - vectors[4].vy = (vectors[3].vy + vectors[5].vy + 1) >> 1; - vectors[4].vz = (vectors[3].vz + vectors[5].vz + 1) >> 1; - - uv_values[0] = *(uvPair*)&arg4->u0; - uv_values[2] = *(uvPair*)&arg4->u1; - uv_values[6] = *(uvPair*)&arg4->u2; - uv_values[8] = *(uvPair*)&arg4->u3; - uv_values[1].u = (uv_values[0].u + uv_values[2].u + 1) >> 1; - uv_values[1].v = (uv_values[0].v + uv_values[2].v + 1) >> 1; - uv_values[7].u = (uv_values[6].u + uv_values[8].u + 1) >> 1; - uv_values[7].v = (uv_values[6].v + uv_values[8].v + 1) >> 1; - uv_values[3].u = (uv_values[0].u + uv_values[6].u + 1) >> 1; - uv_values[3].v = (uv_values[0].v + uv_values[6].v + 1) >> 1; - uv_values[5].u = (uv_values[2].u + uv_values[8].u + 1) >> 1; - uv_values[5].v = (uv_values[2].v + uv_values[8].v + 1) >> 1; - uv_values[4].u = (uv_values[3].u + uv_values[5].u + 1) >> 1; - uv_values[4].v = (uv_values[3].v + uv_values[5].v + 1) >> 1; - - *prim1 = *arg4; - vecIndices = &D_8018105C; - for (i = 0; i < 4; i++) { - vecIdx1 = *vecIndices++; - vecIdx2 = *vecIndices++; - vecIdx3 = *vecIndices++; - vecIdx4 = *vecIndices++; - rotTransResult = RotTransPers4( - &vectors[vecIdx1], &vectors[vecIdx2], &vectors[vecIdx3], - &vectors[vecIdx4], &prim2->x0, &prim2->x1, &prim2->x2, &prim2->x3, - &unused1, &unused2); - *(uvPair*)&prim2->u0 = uv_values[vecIdx1]; - *(uvPair*)&prim2->u1 = uv_values[vecIdx2]; - *(uvPair*)&prim2->u2 = uv_values[vecIdx3]; - *(uvPair*)&prim2->u3 = uv_values[vecIdx4]; - if (arg5 == 1) { - prim1 = arg6; - if (rotTransResult > 0) { - nextArg6 = arg6->next; - *prim1 = *prim2; - arg6->next = nextArg6; - arg6 = nextArg6; - if (arg6 == NULL) { - return NULL; - } - } - } else { - arg6 = func_801907EC( - &vectors[vecIdx1], &vectors[vecIdx2], &vectors[vecIdx3], - &vectors[vecIdx4], prim2, arg5 - 1, arg6, arg7); - } - } - return arg6; -} +#include "../unk_recursive_primfunc_1.h" u16 D_8018107C[] = {0, 1, 3, 4, 1, 2, 4, 5, 3, 4, 6, 7, 4, 5, 7, 8, 0, 0}; INCLUDE_ASM("st/wrp/nonmatchings/e_misc", func_80190DCC);