diff --git a/lib/spl/include/spl.h b/lib/spl/include/spl.h index b8edfd5d00..497aacfa78 100644 --- a/lib/spl/include/spl.h +++ b/lib/spl/include/spl.h @@ -438,17 +438,16 @@ typedef struct SPLList { } SPLList; typedef struct FieldFunc { - void(*func)(SPLParticle *, UnkSPLStruct4 *, int); + void (*func)(SPLParticle *, UnkSPLStruct4 *, int); BOOL loop; } FieldFunc; typedef struct FieldFunc8 { - void(*func)(SPLParticle *, UnkSPLStruct4 *, u8); + void (*func)(SPLParticle *, UnkSPLStruct4 *, u8); BOOL loop; } FieldFunc8; -typedef struct SPLArcHdr -{ +typedef struct SPLArcHdr { u32 id; u32 ver; u16 res_num; @@ -460,6 +459,8 @@ typedef struct SPLArcHdr u32 reserved1; } SPLArcHdr; +typedef void (*UnkSPLFuncPtr0)(SPLEmitter *, void *); + void SPL_0209C400(SPLManager * param0); void SPL_0209C444(SPLManager * param0, SPLEmitter * param1); SPLEmitter * SPL_0209C4D8(SPLManager * param0, int param1, void (* param2)(struct SPLEmitter_t *)); @@ -496,7 +497,6 @@ void sub_020A1608(VecFx32 *ptclPos, VecFx32 *pos, SPLEmitter *emtr); void sub_020A2354(VecFx32 *vec); void sub_020A23B0(VecFx32 *vec); - void sub_0209D998(SPLEmitter *emtr, UnkSPLStruct4 *res, const VecFx32 *param2); void sub_0209CF00(SPLManager *mgr); void sub_0209D150(SPLManager *mgr, SPLEmitter *emtr); @@ -533,6 +533,8 @@ void sub_020A0398(fx32 sin, fx32 cos, MtxFx43 *mat); void sub_020A0444(fx16 s, fx16 t, fx16 offsetX, fx16 offsetZ); void sub_020A0500(fx16 s, fx16 t, fx16 offsetX, fx16 offsetY); +void spl_generate(SPLEmitter *emtr, SPLList *list); + static inline void SPL_UnkInline1 (SPLEmitter * param0, const VecFx32 * param1) { param0->unk_98.x = param1->x + param0->p_res->unk_00->unk_04.x; @@ -568,6 +570,11 @@ static inline u32 rng_next(u32 shift) return Unk_021C3A38 >> shift; } +static inline s32 rng_next_s32(u32 shift) +{ + return (s32)rng_next(shift); +} + #ifdef __cplusplus } #endif diff --git a/lib/spl/meson.build b/lib/spl/meson.build index 0236a47949..936ac17f0f 100644 --- a/lib/spl/meson.build +++ b/lib/spl/meson.build @@ -1,7 +1,22 @@ + +libspl_c_args = [ + '-nothumb', + '-wrap:ver', '1.2/base_b73' +] + +libspl_link_args = [ + '-library', + '-nothumb', + '-main', '""', + '-nostdlib', +] + +libspl_public_includes = include_directories('include') + libspl_srcs = files( 'src/unk_0209C400.c', 'src/unk_0209CF00.c', - 'asm/unk_0209DD54.s', + 'src/unk_0209DD54.c', 'src/unk_020A05BC.c', 'src/unk_020A19F0.c', 'src/unk_020A1E30.c', @@ -9,11 +24,11 @@ libspl_srcs = files( 'src/unk_020A2354.c' ) -libspl_public_includes = include_directories('include') - libspl = static_library('spl', sources: libspl_srcs, nasm_args: asm_args, + c_args: libspl_c_args, + link_args: libspl_link_args, include_directories: [public_includes, libspl_public_includes], dependencies: [ nitrosdk_dep, nitrosystem_dep ], pic: false diff --git a/lib/spl/src/unk_0209C400.c b/lib/spl/src/unk_0209C400.c index 3ee3b9f413..56a3677455 100644 --- a/lib/spl/src/unk_0209C400.c +++ b/lib/spl/src/unk_0209C400.c @@ -6,200 +6,68 @@ #define DECODE_WH(X) ((u16)(1 << ((X) + 3))) -void SPL_0209C400(SPLManager *p0) +u32 sub_0209CEC8(u32 size, BOOL is4x4) { - SPLEmitter *next; - SPLEmitter *emtr = p0->unk_04.unk_00; - - while (emtr != NULL) { - next = emtr->unk_00; - SPL_0209C444(p0, emtr); - emtr = next; - } + return (NNS_GfdAllocTexVram(size, is4x4, 0) & 0xFFFF) * 8; } -void SPL_0209C444(SPLManager *p0, SPLEmitter *p1) +u32 sub_0209CE90(u32 size, BOOL is4Pltt) { - SPLEmitter *v0 = (SPLEmitter *)sub_020A22B8((SPLList *)&p1->unk_08); - if (v0 != NULL) { - do { - sub_020A2304((SPLList *)&p0->unk_1C, (SPLNode *)v0); - v0 = (SPLEmitter *)sub_020A22B8((SPLList *)&p1->unk_08); - } while (v0 != NULL); - } - v0 = (SPLEmitter *)sub_020A22B8((SPLList *)&p1->unk_4C); - if (v0 != NULL) { - do { - sub_020A2304((SPLList *)&p0->unk_1C, (SPLNode *)v0); - v0 = (SPLEmitter *)sub_020A22B8((SPLList *)&p1->unk_4C); - } while (v0 != NULL); - } - sub_020A2238((SPLList *)&p0->unk_04, (SPLNode *)p1); - sub_020A2304((SPLList *)&p0->unk_10, (SPLNode *)p1); + return (NNS_GfdAllocPlttVram(size, is4Pltt, 0) & 0xFFFF) * 8; } -SPLEmitter * SPL_0209C4D8(SPLManager *mgr, int resno, void(*fpcb)(SPLEmitter*)) +SPLManager *SPL_0209CD00(void *(*alloc)(u32), u16 max_emtr, u16 max_ptcl, u16 fixPolyID, u16 minPolyID, u16 maxPolyID) { + SPLManager *mgr; SPLEmitter *emtr; - - emtr = NULL; - if (mgr->unk_10.unk_00 != NULL) { - VecFx32 v0 = { 0, 0, 0 }; - emtr = (SPLEmitter*)sub_020A22B8((SPLList *)&mgr->unk_10); - sub_0209D998(emtr, mgr->unk_28 + resno, &v0); - if (fpcb != NULL) { - fpcb(emtr); - } - sub_020A2304((SPLList *)&mgr->unk_04, (SPLNode *)emtr); - if (emtr->p_res->unk_00->unk_00.unk_05_6) { - emtr = NULL; - } - } - - return emtr; -} - -SPLEmitter *SPL_0209C56C(SPLManager *mgr, int resno, const VecFx32 *pos) -{ - SPLEmitter *emtr = NULL; - - if (mgr->unk_10.unk_00 != NULL) { - emtr = (SPLEmitter *)sub_020A22B8((SPLList *)&mgr->unk_10); - sub_0209D998(emtr, mgr->unk_28 + resno, pos); - sub_020A2304((SPLList *)&mgr->unk_04, (SPLNode *)emtr); - if (emtr->p_res->unk_00->unk_00.unk_05_6) { - emtr = NULL; - } - } - - return emtr; -} - -void SPL_0209C5E0(SPLManager *mgr, const MtxFx43 *cmr) -{ - SPLEmitter *emtr; - - reg_G3X_DISP3DCNT = (reg_G3X_DISP3DCNT & ~(REG_G3X_DISP3DCNT_GO_MASK | REG_G3X_DISP3DCNT_RO_MASK)) | REG_G3X_DISP3DCNT_ABE_MASK; - mgr->unk_40.unk_04 = cmr; - if (!mgr->unk_38.unk_03_0) { - emtr = mgr->unk_04.unk_00; - - while (emtr != NULL) { - mgr->unk_40.unk_00 = emtr; - if (!emtr->unk_94.stop_draw) { - sub_0209CF00(mgr); - } - emtr = emtr->unk_00; - } - - return; - } - - emtr = mgr->unk_04.unk_08; - while (emtr != NULL) { - mgr->unk_40.unk_00 = emtr; - if (!emtr->unk_94.stop_draw) { - sub_0209CF00(mgr); - } - emtr = emtr->unk_04; - } -} - -void SPL_0209C6A8(SPLManager *mgr) -{ - SPLEmitter *emtr; - SPLEmitter *next; - - emtr = mgr->unk_04.unk_00; - while (emtr != NULL) { - UnkSPLStruct9 *base = emtr->p_res->unk_00; - next = emtr->unk_00; - - if (!emtr->unk_94.started && emtr->unk_BC >= base->unk_32) { - emtr->unk_94.started = TRUE; - emtr->unk_BC = 0; - } - - if (!emtr->unk_94.stop_calc) { - if (emtr->unk_F0.unk_02_0 == 0 || mgr->unk_48 == emtr->unk_F0.unk_02_0 - 1) { - sub_0209D150(mgr, emtr); - } - } - - if (((base->unk_00.unk_05_6 && base->unk_3C != 0 && emtr->unk_94.started && emtr->unk_BC > base->unk_3C) - || emtr->unk_94.terminate) && emtr->unk_08.unk_04 == 0 && emtr->unk_4C.unk_04 == 0) { - SPLEmitter *e0 = (SPLEmitter *)sub_020A2238((SPLList *)&mgr->unk_04, (SPLNode *)emtr); - sub_020A2304((SPLList *)&mgr->unk_10, (SPLNode *)e0); - } - - emtr = next; - } - - mgr->unk_48 += 1; - if (mgr->unk_48 > 1) { - mgr->unk_48 = 0; - } -} - -int SPL_0209C7E0(SPLManager *mgr) -{ - return SPL_0209C808(mgr, sub_0209CE90); -} - -int SPL_0209C7F4(SPLManager *mgr) -{ - return SPL_0209C8BC(mgr, sub_0209CEC8); -} - -BOOL SPL_0209C808(SPLManager *mgr, u32 (*func)(u32, BOOL)) -{ - s32 i; - UnkSPLStruct5 *tex; - UnkSPLStruct15 *hdr; - u32 ofs; - - GX_BeginLoadTexPltt(); - - for (i = 0; i < mgr->unk_32; i++) { - ofs = 0; - tex = &mgr->unk_2C[i]; - hdr = (UnkSPLStruct15 *)tex->unk_00; - - if (hdr->unk_10 != 0) { - ofs = func(hdr->unk_10, hdr->unk_04.val2_00_0 == 2); - GX_LoadTexPltt((u8 *)tex->unk_00 + hdr->unk_0C, ofs, hdr->unk_10); - } - - tex->unk_08 = ofs; - } - - GX_EndLoadTexPltt(); - return TRUE; -} - -BOOL SPL_0209C8BC(SPLManager *mgr, u32 (*func)(u32, BOOL)) -{ + SPLParticle *ptcl; int i; - u32 addr; - GX_BeginLoadTex(); - - for (i = 0; i < mgr->unk_32; i++) { - UnkSPLStruct5 *textures = mgr->unk_2C; - UnkSPLStruct5 *tex = &textures[i]; - UnkSPLStruct15 *hdr = (UnkSPLStruct15 *)tex->unk_00; - - if (hdr->unk_04.val2_02_1) { - tex->unk_04 = textures[hdr->unk_04.val2_02_2].unk_04; - } else { - addr = func(hdr->unk_08, hdr->unk_04.val2_00_0 == 5); - GX_LoadTex(((UnkSPLStruct15 *)tex->unk_00) + 1, addr, hdr->unk_08); - tex->unk_04 = addr; - } + mgr = alloc(sizeof(SPLManager)); + MI_CpuFill8(mgr, 0, sizeof(SPLManager)); + + mgr->unk_34 = max_emtr; + mgr->unk_36 = max_ptcl; + + mgr->unk_38.unk_00_0 = minPolyID; + mgr->unk_38.unk_00_6 = maxPolyID; + mgr->unk_38.unk_01_4 = mgr->unk_38.unk_00_0; + mgr->unk_38.unk_02_2 = fixPolyID; + mgr->unk_38.unk_03_0 = FALSE; + mgr->unk_38.unk_03_7 = 0; + + mgr->unk_00 = alloc; + + mgr->unk_04.unk_04 = 0; + mgr->unk_10.unk_04 = 0; + mgr->unk_1C.unk_04 = 0; + + mgr->unk_04.unk_00 = NULL; + mgr->unk_10.unk_00 = NULL; + mgr->unk_1C.unk_00 = NULL; + + mgr->unk_3C = 0; + mgr->unk_48 = 0; + + emtr = alloc(max_emtr * sizeof(SPLEmitter)); + MI_CpuFill8(emtr, 0, max_emtr * sizeof(SPLEmitter)); + + for (i = 0; i < max_emtr; ++i) { + sub_020A2304((SPLList *)&mgr->unk_10, (SPLNode *)&emtr[i]); } - GX_EndLoadTex(); - return TRUE; + ptcl = alloc(max_ptcl * sizeof(SPLParticle)); + MI_CpuFill8(ptcl, 0, max_ptcl * sizeof(SPLParticle)); + + for (i = 0; i < max_ptcl; ++i) { + sub_020A2304((SPLList *)&mgr->unk_1C, (SPLNode *)&ptcl[i]); + } + + mgr->unk_28 = NULL; + mgr->unk_2C = NULL; + mgr->unk_30 = mgr->unk_32 = 0; + + return mgr; } void SPL_0209C988(SPLManager *mgr, const void *p_spa) @@ -226,10 +94,10 @@ void SPL_0209C988(SPLManager *mgr, const void *p_spa) for (i = 0; i < mgr->unk_30; ++i) { p_res = mgr->unk_28 + i; p_res->unk_00 = (UnkSPLStruct9 *)((u8 *)spa + offset); - + offset += sizeof(UnkSPLStruct9); flag = p_res->unk_00->unk_00; - + if (flag.unk_05_0) { // Has scaleAnim p_res->unk_04 = (UnkSPLStruct10 *)((u8 *)spa + offset); offset += sizeof(UnkSPLStruct10); @@ -266,7 +134,7 @@ void SPL_0209C988(SPLManager *mgr, const void *p_spa) } // Sum up all fields - p_res->unk_1C = flag.unk_07_0 + flag.unk_07_1 + flag.unk_07_2 + p_res->unk_1C = flag.unk_07_0 + flag.unk_07_1 + flag.unk_07_2 + flag.unk_07_3 + flag.unk_07_4 + flag.unk_07_5; if (p_res->unk_1C != 0) { @@ -333,66 +201,233 @@ void SPL_0209C988(SPLManager *mgr, const void *p_spa) } } -SPLManager *SPL_0209CD00(void *(*alloc)(u32), u16 max_emtr, u16 max_ptcl, u16 fixPolyID, u16 minPolyID, u16 maxPolyID) +BOOL SPL_0209C8BC(SPLManager *mgr, u32 (*func)(u32, BOOL)) { - SPLManager *mgr; - SPLEmitter *emtr; - SPLParticle *ptcl; int i; + u32 addr; - mgr = alloc(sizeof(SPLManager)); - MI_CpuFill8(mgr, 0, sizeof(SPLManager)); + GX_BeginLoadTex(); - mgr->unk_34 = max_emtr; - mgr->unk_36 = max_ptcl; + for (i = 0; i < mgr->unk_32; i++) { + UnkSPLStruct5 *textures = mgr->unk_2C; + UnkSPLStruct5 *tex = &textures[i]; + UnkSPLStruct15 *hdr = (UnkSPLStruct15 *)tex->unk_00; - mgr->unk_38.unk_00_0 = minPolyID; - mgr->unk_38.unk_00_6 = maxPolyID; - mgr->unk_38.unk_01_4 = mgr->unk_38.unk_00_0; - mgr->unk_38.unk_02_2 = fixPolyID; - mgr->unk_38.unk_03_0 = FALSE; - mgr->unk_38.unk_03_7 = 0; - - mgr->unk_00 = alloc; - - mgr->unk_04.unk_04 = 0; - mgr->unk_10.unk_04 = 0; - mgr->unk_1C.unk_04 = 0; - - mgr->unk_04.unk_00 = NULL; - mgr->unk_10.unk_00 = NULL; - mgr->unk_1C.unk_00 = NULL; - - mgr->unk_3C = 0; - mgr->unk_48 = 0; - - emtr = alloc(max_emtr * sizeof(SPLEmitter)); - MI_CpuFill8(emtr, 0, max_emtr * sizeof(SPLEmitter)); - - for (i = 0; i < max_emtr; ++i) { - sub_020A2304((SPLList *)&mgr->unk_10, (SPLNode *)&emtr[i]); + if (hdr->unk_04.val2_02_1) { + tex->unk_04 = textures[hdr->unk_04.val2_02_2].unk_04; + } else { + addr = func(hdr->unk_08, hdr->unk_04.val2_00_0 == 5); + GX_LoadTex(((UnkSPLStruct15 *)tex->unk_00) + 1, addr, hdr->unk_08); + tex->unk_04 = addr; + } } - ptcl = alloc(max_ptcl * sizeof(SPLParticle)); - MI_CpuFill8(ptcl, 0, max_ptcl * sizeof(SPLParticle)); + GX_EndLoadTex(); + return TRUE; +} - for (i = 0; i < max_ptcl; ++i) { - sub_020A2304((SPLList *)&mgr->unk_1C, (SPLNode *)&ptcl[i]); +BOOL SPL_0209C808(SPLManager *mgr, u32 (*func)(u32, BOOL)) +{ + s32 i; + UnkSPLStruct5 *tex; + UnkSPLStruct15 *hdr; + u32 ofs; + + GX_BeginLoadTexPltt(); + + for (i = 0; i < mgr->unk_32; i++) { + ofs = 0; + tex = &mgr->unk_2C[i]; + hdr = (UnkSPLStruct15 *)tex->unk_00; + + if (hdr->unk_10 != 0) { + ofs = func(hdr->unk_10, hdr->unk_04.val2_00_0 == 2); + GX_LoadTexPltt((u8 *)tex->unk_00 + hdr->unk_0C, ofs, hdr->unk_10); + } + + tex->unk_08 = ofs; } - mgr->unk_28 = NULL; - mgr->unk_2C = NULL; - mgr->unk_30 = mgr->unk_32 = 0; - - return mgr; + GX_EndLoadTexPltt(); + return TRUE; } -u32 sub_0209CE90(u32 size, BOOL is4Pltt) +int SPL_0209C7F4(SPLManager *mgr) { - return (NNS_GfdAllocPlttVram(size, is4Pltt, 0) & 0xFFFF) * 8; + return SPL_0209C8BC(mgr, sub_0209CEC8); } -u32 sub_0209CEC8(u32 size, BOOL is4x4) +int SPL_0209C7E0(SPLManager *mgr) { - return (NNS_GfdAllocTexVram(size, is4x4, 0) & 0xFFFF) * 8; + return SPL_0209C808(mgr, sub_0209CE90); +} + +void SPL_0209C6A8(SPLManager *mgr) +{ + SPLEmitter *emtr; + SPLEmitter *next; + + emtr = mgr->unk_04.unk_00; + while (emtr != NULL) { + UnkSPLStruct9 *base = emtr->p_res->unk_00; + next = emtr->unk_00; + + if (!emtr->unk_94.started && emtr->unk_BC >= base->unk_32) { + emtr->unk_94.started = TRUE; + emtr->unk_BC = 0; + } + + if (!emtr->unk_94.stop_calc) { + if (emtr->unk_F0.unk_02_0 == 0 || mgr->unk_48 == emtr->unk_F0.unk_02_0 - 1) { + sub_0209D150(mgr, emtr); + } + } + + if (((base->unk_00.unk_05_6 && base->unk_3C != 0 && emtr->unk_94.started && emtr->unk_BC > base->unk_3C) + || emtr->unk_94.terminate) + && emtr->unk_08.unk_04 == 0 && emtr->unk_4C.unk_04 == 0) { + SPLEmitter *e0 = (SPLEmitter *)sub_020A2238((SPLList *)&mgr->unk_04, (SPLNode *)emtr); + sub_020A2304((SPLList *)&mgr->unk_10, (SPLNode *)e0); + } + + emtr = next; + } + + mgr->unk_48 += 1; + if (mgr->unk_48 > 1) { + mgr->unk_48 = 0; + } +} + +void SPL_0209C5E0(SPLManager *mgr, const MtxFx43 *cmr) +{ + SPLEmitter *emtr; + + reg_G3X_DISP3DCNT = (reg_G3X_DISP3DCNT & ~(REG_G3X_DISP3DCNT_GO_MASK | REG_G3X_DISP3DCNT_RO_MASK)) | REG_G3X_DISP3DCNT_ABE_MASK; + mgr->unk_40.unk_04 = cmr; + if (!mgr->unk_38.unk_03_0) { + emtr = mgr->unk_04.unk_00; + + while (emtr != NULL) { + mgr->unk_40.unk_00 = emtr; + if (!emtr->unk_94.stop_draw) { + sub_0209CF00(mgr); + } + emtr = emtr->unk_00; + } + + return; + } + + emtr = mgr->unk_04.unk_08; + while (emtr != NULL) { + mgr->unk_40.unk_00 = emtr; + if (!emtr->unk_94.stop_draw) { + sub_0209CF00(mgr); + } + emtr = emtr->unk_04; + } +} + +SPLEmitter *SPL_0209C56C(SPLManager *mgr, int resno, const VecFx32 *pos) +{ + SPLEmitter *emtr = NULL; + + if (mgr->unk_10.unk_00 != NULL) { + emtr = (SPLEmitter *)sub_020A22B8((SPLList *)&mgr->unk_10); + sub_0209D998(emtr, mgr->unk_28 + resno, pos); + sub_020A2304((SPLList *)&mgr->unk_04, (SPLNode *)emtr); + if (emtr->p_res->unk_00->unk_00.unk_05_6) { + emtr = NULL; + } + } + + return emtr; +} + +SPLEmitter *SPL_0209C4D8(SPLManager *mgr, int resno, void (*fpcb)(SPLEmitter *)) +{ + SPLEmitter *emtr; + + emtr = NULL; + if (mgr->unk_10.unk_00 != NULL) { + VecFx32 v0 = { 0, 0, 0 }; + emtr = (SPLEmitter *)sub_020A22B8((SPLList *)&mgr->unk_10); + sub_0209D998(emtr, mgr->unk_28 + resno, &v0); + if (fpcb != NULL) { + fpcb(emtr); + } + sub_020A2304((SPLList *)&mgr->unk_04, (SPLNode *)emtr); + if (emtr->p_res->unk_00->unk_00.unk_05_6) { + emtr = NULL; + } + } + + return emtr; +} + +SPLEmitter *SPL_CreateWithInitializeEx(SPLManager *mgr, int resNo, VecFx32 *pos, void *pvoid, UnkSPLFuncPtr0 cb) +{ + SPLEmitter *emtr; + + emtr = NULL; + if (mgr->unk_10.unk_00 != NULL) { + emtr = (SPLEmitter *)sub_020A22B8((SPLList *)&mgr->unk_10); + sub_0209D998(emtr, mgr->unk_28 + resNo, pos); + if (cb != NULL) { + cb(emtr, pvoid); + } + + sub_020A2304((SPLList *)&mgr->unk_04, (SPLNode *)emtr); + if (emtr->p_res->unk_00->unk_00.unk_05_6) { + emtr = NULL; + } + } + + return emtr; +} + +void SPL_0209C444(SPLManager *p0, SPLEmitter *p1) +{ + SPLEmitter *v0 = (SPLEmitter *)sub_020A22B8((SPLList *)&p1->unk_08); + if (v0 != NULL) { + do { + sub_020A2304((SPLList *)&p0->unk_1C, (SPLNode *)v0); + v0 = (SPLEmitter *)sub_020A22B8((SPLList *)&p1->unk_08); + } while (v0 != NULL); + } + v0 = (SPLEmitter *)sub_020A22B8((SPLList *)&p1->unk_4C); + if (v0 != NULL) { + do { + sub_020A2304((SPLList *)&p0->unk_1C, (SPLNode *)v0); + v0 = (SPLEmitter *)sub_020A22B8((SPLList *)&p1->unk_4C); + } while (v0 != NULL); + } + sub_020A2238((SPLList *)&p0->unk_04, (SPLNode *)p1); + sub_020A2304((SPLList *)&p0->unk_10, (SPLNode *)p1); +} + +void SPL_0209C400(SPLManager *p0) +{ + SPLEmitter *next; + SPLEmitter *emtr = p0->unk_04.unk_00; + + while (emtr != NULL) { + next = emtr->unk_00; + SPL_0209C444(p0, emtr); + emtr = next; + } +} + +void SPL_Emit(SPLManager *mgr, SPLEmitter *emtr) +{ + spl_generate(emtr, (SPLList *)&mgr->unk_1C); +} + +void SPL_EmitAt(SPLManager *mgr, SPLEmitter *emtr, VecFx32 *pos) +{ + emtr->unk_98.x = pos->x + emtr->p_res->unk_00->unk_04.x; + emtr->unk_98.y = pos->y + emtr->p_res->unk_00->unk_04.y; + emtr->unk_98.z = pos->z + emtr->p_res->unk_00->unk_04.z; + spl_generate(emtr, (SPLList *)&mgr->unk_1C); } diff --git a/lib/spl/src/unk_0209CF00.c b/lib/spl/src/unk_0209CF00.c index 5513064336..2598e162fa 100644 --- a/lib/spl/src/unk_0209CF00.c +++ b/lib/spl/src/unk_0209CF00.c @@ -1,92 +1,98 @@ -#include "spl.h" - #include #include #include #include -void sub_0209CF00(SPLManager *mgr) +#include "spl.h" + +void sub_0209DC68(UnkSPLStruct5 *tex) { - UnkSPLStruct9 *resBase; + UnkSPLUnion5 param = tex->unk_0C; - resBase = mgr->unk_40.unk_00->p_res->unk_00; - if (resBase->unk_00.unk_06_5) { - sub_0209CF7C(mgr); + G3_TexImageParam( + param.val2_00_0, + GX_TEXGEN_TEXCOORD, + param.val2_00_4, + param.val2_01_0, + param.val2_01_4, + param.val2_01_6, + param.val2_02_0, + tex->unk_04); - if (!resBase->unk_00.unk_06_6) { - sub_0209D064(mgr); - } - } else { - if (!resBase->unk_00.unk_06_6) { - sub_0209D064(mgr); - } - - sub_0209CF7C(mgr); - } + G3_TexPlttBase(tex->unk_08, param.val2_00_0); + G3_MtxMode(GX_MTXMODE_TEXTURE); + G3_Identity(); + G3_Scale(tex->unk_10 * FX32_ONE, tex->unk_12 * FX32_ONE, 0); + G3_MtxMode(GX_MTXMODE_POSITION); } -void sub_0209CF7C(SPLManager *mgr) +void sub_0209DC64(UnkSPLStruct5 *tex) { - SPLEmitter *emtr; - UnkSPLStruct4 *res; - DrawFunc drawFunc; - SPLParticle *ptcl; - - emtr = mgr->unk_40.unk_00; - drawFunc = NULL; - res = emtr->p_res; - - if (!res->unk_00->unk_00.unk_06_0) { - return; - } - - sub_0209DC68(mgr->unk_2C + res->unk_14->unk_0C.unk_03_0); - - switch (res->unk_14->unk_00.unk_02_7) { - case 0: drawFunc = sub_0209FAB8; break; - case 1: drawFunc = sub_0209ECF0; break; - case 2: drawFunc = sub_0209E650; break; - case 3: drawFunc = sub_0209DD54; break; - case 4: drawFunc = sub_0209DD54; break; - } - - ptcl = emtr->unk_4C.unk_00; - while (ptcl != NULL) { - drawFunc(mgr, ptcl); - ptcl = ptcl->unk_00; - } } -void sub_0209D064(SPLManager *mgr) +void sub_0209D998(SPLEmitter *emtr, UnkSPLStruct4 *res, const VecFx32 *pos) { - SPLEmitter *emtr; - UnkSPLStruct9 *resBase; - SPLParticle *ptcl; - DrawFunc drawFunc; - SetTexFunc setTexFunc; + emtr->p_res = res; + emtr->unk_94.all = 0; - emtr = mgr->unk_40.unk_00; - resBase = emtr->p_res->unk_00; - drawFunc = NULL; + emtr->unk_98.x = pos->x + emtr->p_res->unk_00->unk_04.x; + emtr->unk_98.y = pos->y + emtr->p_res->unk_00->unk_04.y; + emtr->unk_98.z = pos->z + emtr->p_res->unk_00->unk_04.z; - sub_0209DC68(mgr->unk_2C + resBase->unk_48.unk_03_0); + emtr->unk_B0.x = 0; + emtr->unk_B0.y = 0; + emtr->unk_B0.z = 0; + emtr->unk_A4.x = emtr->unk_A4.y = emtr->unk_A4.z = 0; - switch (resBase->unk_00.unk_04_4) { - case 0: drawFunc = sub_0209FF0C; break; - case 1: drawFunc = sub_0209F3D0; break; - case 2: drawFunc = sub_0209E9A0; break; - case 3: drawFunc = sub_0209E1D4; break; - case 4: drawFunc = sub_0209E1D4; break; + emtr->unk_BC = 0; + emtr->unk_BE = 0; + + emtr->unk_C0 = emtr->p_res->unk_00->unk_1C; + emtr->unk_C6 = emtr->p_res->unk_00->unk_38; + emtr->unk_C8 = emtr->p_res->unk_00->unk_10; + emtr->unk_CC = emtr->p_res->unk_00->unk_14; + emtr->unk_D0 = emtr->p_res->unk_00->unk_18; + emtr->unk_D4 = emtr->p_res->unk_00->unk_24; + emtr->unk_D8 = emtr->p_res->unk_00->unk_28; + emtr->unk_DC = emtr->p_res->unk_00->unk_2C; + emtr->unk_E0 = emtr->p_res->unk_00->unk_40; + + emtr->unk_E2 = GX_RGB(31, 31, 31); + emtr->unk_F0.unk_00_0 = emtr->p_res->unk_00->unk_48.unk_00_0; + emtr->unk_F0.unk_01_0 = emtr->p_res->unk_00->unk_48.unk_01_0; + emtr->unk_F0.unk_02_0 = 0; + emtr->unk_F0.unk_02_3 = 0; + emtr->unk_E4 = FX32_MIN; + emtr->unk_E8 = FX32_ONE << emtr->p_res->unk_00->unk_48.unk_07_0; + emtr->unk_EA = FX32_ONE << emtr->p_res->unk_00->unk_48.unk_07_2; + + if (emtr->p_res->unk_00->unk_48.unk_08_0) { + emtr->unk_E8 *= -1; } - setTexFunc = resBase->unk_00.unk_05_3 ? sub_0209DC68 : sub_0209DC64; - ptcl = emtr->unk_08.unk_00; - - while (ptcl != NULL) { - setTexFunc(mgr->unk_2C + ptcl->unk_2C.unk_00); - drawFunc(mgr, ptcl); - ptcl = ptcl->unk_00; + if (emtr->p_res->unk_00->unk_48.unk_08_1) { + emtr->unk_EA *= -1; } + + if (emtr->p_res->unk_00->unk_00.unk_06_0) { + emtr->unk_EC = FX32_ONE << emtr->p_res->unk_14->unk_0C.unk_04_0; + emtr->unk_EE = FX32_ONE << emtr->p_res->unk_14->unk_0C.unk_04_2; + + if (emtr->p_res->unk_14->unk_0C.unk_04_4) { + emtr->unk_EC *= -1; + } + + if (emtr->p_res->unk_14->unk_0C.unk_04_5) { + emtr->unk_EE *= -1; + } + } + + emtr->unk_00 = emtr->unk_04 = NULL; + emtr->unk_08.unk_00 = emtr->unk_4C.unk_00 = NULL; + emtr->unk_08.unk_04 = emtr->unk_4C.unk_04 = 0; + emtr->unk_100 = NULL; + emtr->unk_104 = NULL; + emtr->unk_108.unk_108_val1 = 0; } void sub_0209D150(SPLManager *mgr, SPLEmitter *emtr) @@ -145,7 +151,6 @@ void sub_0209D150(SPLManager *mgr, SPLEmitter *emtr) fieldFuncs[fieldIndex++].loop = res->unk_10->unk_08.unk_02_1; } - for (ptcl = emtr->unk_08.unk_00; ptcl != NULL; ptcl = next) { next = ptcl->unk_00; lifeRates[0] = ptcl->unk_2A * ptcl->unk_26 >> 8; @@ -253,24 +258,24 @@ void sub_0209D150(SPLManager *mgr, SPLEmitter *emtr) ptcl->unk_14.x += vec.x; ptcl->unk_14.y += vec.y; ptcl->unk_14.z += vec.z; - + ptcl->unk_08.x += ptcl->unk_14.x + emtr->unk_A4.x; ptcl->unk_08.y += ptcl->unk_14.y + emtr->unk_A4.y; ptcl->unk_08.z += ptcl->unk_14.z + emtr->unk_A4.z; - + if (emtr->p_res->unk_00->unk_00.unk_07_7) { ptcl->unk_2E.unk_01_2 = mgr->unk_38.unk_02_2; } else { ptcl->unk_2E.unk_01_2 = mgr->unk_38.unk_01_4; mgr->unk_38.unk_01_4 += 1; - + if (mgr->unk_38.unk_01_4 > mgr->unk_38.unk_00_6) { mgr->unk_38.unk_01_4 = mgr->unk_38.unk_00_0; } } - + ptcl->unk_26 += 1; - + if (ptcl->unk_26 > ptcl->unk_24) { sub_020A2304((SPLList *)&mgr->unk_1C, sub_020A2238((SPLList *)(&emtr->unk_4C), (SPLNode *)ptcl)); } @@ -284,91 +289,132 @@ void sub_0209D150(SPLManager *mgr, SPLEmitter *emtr) } } -void sub_0209D998(SPLEmitter *emtr, UnkSPLStruct4 *res, const VecFx32 *pos) +void sub_0209D064(SPLManager *mgr) { - emtr->p_res = res; - emtr->unk_94.all = 0; - - emtr->unk_98.x = pos->x + emtr->p_res->unk_00->unk_04.x; - emtr->unk_98.y = pos->y + emtr->p_res->unk_00->unk_04.y; - emtr->unk_98.z = pos->z + emtr->p_res->unk_00->unk_04.z; + SPLEmitter *emtr; + UnkSPLStruct9 *resBase; + SPLParticle *ptcl; + DrawFunc drawFunc; + SetTexFunc setTexFunc; - emtr->unk_B0.x = 0; - emtr->unk_B0.y = 0; - emtr->unk_B0.z = 0; - emtr->unk_A4.x = emtr->unk_A4.y = emtr->unk_A4.z = 0; + emtr = mgr->unk_40.unk_00; + resBase = emtr->p_res->unk_00; + drawFunc = NULL; - emtr->unk_BC = 0; - emtr->unk_BE = 0; + sub_0209DC68(mgr->unk_2C + resBase->unk_48.unk_03_0); - emtr->unk_C0 = emtr->p_res->unk_00->unk_1C; - emtr->unk_C6 = emtr->p_res->unk_00->unk_38; - emtr->unk_C8 = emtr->p_res->unk_00->unk_10; - emtr->unk_CC = emtr->p_res->unk_00->unk_14; - emtr->unk_D0 = emtr->p_res->unk_00->unk_18; - emtr->unk_D4 = emtr->p_res->unk_00->unk_24; - emtr->unk_D8 = emtr->p_res->unk_00->unk_28; - emtr->unk_DC = emtr->p_res->unk_00->unk_2C; - emtr->unk_E0 = emtr->p_res->unk_00->unk_40; - - emtr->unk_E2 = GX_RGB(31, 31, 31); - emtr->unk_F0.unk_00_0 = emtr->p_res->unk_00->unk_48.unk_00_0; - emtr->unk_F0.unk_01_0 = emtr->p_res->unk_00->unk_48.unk_01_0; - emtr->unk_F0.unk_02_0 = 0; - emtr->unk_F0.unk_02_3 = 0; - emtr->unk_E4 = FX32_MIN; - emtr->unk_E8 = FX32_ONE << emtr->p_res->unk_00->unk_48.unk_07_0; - emtr->unk_EA = FX32_ONE << emtr->p_res->unk_00->unk_48.unk_07_2; - - if (emtr->p_res->unk_00->unk_48.unk_08_0) { - emtr->unk_E8 *= -1; + switch (resBase->unk_00.unk_04_4) { + case 0: + drawFunc = sub_0209FF0C; + break; + case 1: + drawFunc = sub_0209F3D0; + break; + case 2: + drawFunc = sub_0209E9A0; + break; + case 3: + drawFunc = sub_0209E1D4; + break; + case 4: + drawFunc = sub_0209E1D4; + break; } - if (emtr->p_res->unk_00->unk_48.unk_08_1) { - emtr->unk_EA *= -1; + setTexFunc = resBase->unk_00.unk_05_3 ? sub_0209DC68 : sub_0209DC64; + ptcl = emtr->unk_08.unk_00; + + while (ptcl != NULL) { + setTexFunc(mgr->unk_2C + ptcl->unk_2C.unk_00); + drawFunc(mgr, ptcl); + ptcl = ptcl->unk_00; } - - if (emtr->p_res->unk_00->unk_00.unk_06_0) { - emtr->unk_EC = FX32_ONE << emtr->p_res->unk_14->unk_0C.unk_04_0; - emtr->unk_EE = FX32_ONE << emtr->p_res->unk_14->unk_0C.unk_04_2; - - if (emtr->p_res->unk_14->unk_0C.unk_04_4) { - emtr->unk_EC *= -1; - } - - if (emtr->p_res->unk_14->unk_0C.unk_04_5) { - emtr->unk_EE *= -1; - } - } - - emtr->unk_00 = emtr->unk_04 = NULL; - emtr->unk_08.unk_00 = emtr->unk_4C.unk_00 = NULL; - emtr->unk_08.unk_04 = emtr->unk_4C.unk_04 = 0; - emtr->unk_100 = NULL; - emtr->unk_104 = NULL; - emtr->unk_108.unk_108_val1 = 0; } -void sub_0209DC64(UnkSPLStruct5 *tex) { } - -void sub_0209DC68(UnkSPLStruct5 *tex) +void sub_0209CF7C(SPLManager *mgr) { - UnkSPLUnion5 param = tex->unk_0C; + SPLEmitter *emtr; + UnkSPLStruct4 *res; + DrawFunc drawFunc; + SPLParticle *ptcl; - G3_TexImageParam( - param.val2_00_0, - GX_TEXGEN_TEXCOORD, - param.val2_00_4, - param.val2_01_0, - param.val2_01_4, - param.val2_01_6, - param.val2_02_0, - tex->unk_04 - ); + emtr = mgr->unk_40.unk_00; + drawFunc = NULL; + res = emtr->p_res; - G3_TexPlttBase(tex->unk_08, param.val2_00_0); - G3_MtxMode(GX_MTXMODE_TEXTURE); - G3_Identity(); - G3_Scale(tex->unk_10 * FX32_ONE, tex->unk_12 * FX32_ONE, 0); - G3_MtxMode(GX_MTXMODE_POSITION); + if (!res->unk_00->unk_00.unk_06_0) { + return; + } + + sub_0209DC68(mgr->unk_2C + res->unk_14->unk_0C.unk_03_0); + + switch (res->unk_14->unk_00.unk_02_7) { + case 0: + drawFunc = sub_0209FAB8; + break; + case 1: + drawFunc = sub_0209ECF0; + break; + case 2: + drawFunc = sub_0209E650; + break; + case 3: + drawFunc = sub_0209DD54; + break; + case 4: + drawFunc = sub_0209DD54; + break; + } + + ptcl = emtr->unk_4C.unk_00; + while (ptcl != NULL) { + drawFunc(mgr, ptcl); + ptcl = ptcl->unk_00; + } +} + +void sub_0209CF00(SPLManager *mgr) +{ + UnkSPLStruct9 *resBase; + + resBase = mgr->unk_40.unk_00->p_res->unk_00; + if (resBase->unk_00.unk_06_5) { + sub_0209CF7C(mgr); + + if (!resBase->unk_00.unk_06_6) { + sub_0209D064(mgr); + } + } else { + if (!resBase->unk_00.unk_06_6) { + sub_0209D064(mgr); + } + + sub_0209CF7C(mgr); + } +} + +void spl_generate(SPLEmitter *emtr, SPLList *list) +{ + sub_020A08DC(emtr, list); +} + +void SPL_Util_SetCylinderEmiterDirection(SPLEmitter *emtr, VecFx32 *p1, VecFx32 *p2) +{ + VecFx32 vex; + + if (emtr->p_res->unk_00->unk_00.unk_04_0 == 6 || emtr->p_res->unk_00->unk_00.unk_04_0 == 7) { + emtr->unk_98.x = (p2->x + p1->x) / 2; + emtr->unk_98.y = (p2->y + p1->y) / 2; + emtr->unk_98.z = (p2->z + p1->z) / 2; + emtr->unk_D0 = VEC_Distance(p1, p2) / 2; + + vex.x = p2->x - p1->x; + vex.y = p2->y - p1->y; + vex.z = p2->z - p1->z; + VEC_Normalize(&vex, &vex); + + emtr->unk_C0.x = (fx16)vex.x; + emtr->unk_C0.y = (fx16)vex.y; + emtr->unk_C0.z = (fx16)vex.z; + } } diff --git a/lib/spl/src/unk_0209DD54.c b/lib/spl/src/unk_0209DD54.c index d23ba44bf8..00858c637c 100644 --- a/lib/spl/src/unk_0209DD54.c +++ b/lib/spl/src/unk_0209DD54.c @@ -1,49 +1,237 @@ -#include "spl.h" - #include #include -#include #include +#include #include #include +#include "spl.h" + typedef void (*RotFunc)(fx32 sin, fx32 cos, MtxFx43 *rot); typedef void (*DrawPlaneFunc)(fx16 s, fx16 t, fx16 offsetX, fx16 offsetY); -DrawPlaneFunc Unk_02100DA0[2] = { +static DrawPlaneFunc Unk_02100DA0[2] = { sub_020A0500, sub_020A0444, }; -RotFunc Unk_02100DA8[2] = { + +static RotFunc Unk_02100DA8[2] = { sub_020A0358, sub_020A0398, }; - -void sub_0209DD54(SPLManager *mgr, SPLParticle *ptcl) +void sub_020A0500(fx16 s, fx16 t, fx16 offsetX, fx16 offsetY) { - MtxFx43 transform; - MtxFx43 rotMtx; - MtxFx43 sclMat; - VecFx32 vec1, vec2, vec3, vec4, axis; - MtxFx43 mat; - fx32 dot, scaleX, scaleY, scaleZ, alpha, tmp; - u32 polygonID, cullMode; - UnkSPLStruct9 *resBase; - - alpha = ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1) >> 5; - polygonID = ptcl->unk_2E.unk_01_2 << REG_G3_POLYGON_ATTR_ID_SHIFT; - cullMode = GX_CULL_NONE << REG_G3_POLYGON_ATTR_BK_SHIFT; + G3_Begin(GX_BEGIN_QUADS); - reg_G3_POLYGON_ATTR = (u32)( - (0 << REG_G3_POLYGON_ATTR_LE_SHIFT) + G3_TexCoord(0, 0); + G3_Vtx10(offsetX - FX32_ONE, offsetY + FX32_ONE, 0); + + G3_TexCoord(s, 0); + G3_Vtx10(offsetX + FX32_ONE, offsetY + FX32_ONE, 0); + + G3_TexCoord(s, t); + G3_Vtx10(offsetX + FX32_ONE, offsetY - FX32_ONE, 0); + + G3_TexCoord(0, t); + G3_Vtx10(offsetX - FX32_ONE, offsetY - FX32_ONE, 0); + + G3_End(); +} + +void sub_020A0444(fx16 s, fx16 t, fx16 offsetX, fx16 offsetZ) +{ + G3_Begin(GX_BEGIN_QUADS); + + G3_TexCoord(0, 0); + G3_Vtx10(offsetX - FX32_ONE, 0, offsetZ + FX32_ONE); + + G3_TexCoord(s, 0); + G3_Vtx10(offsetX + FX32_ONE, 0, offsetZ + FX32_ONE); + + G3_TexCoord(s, t); + G3_Vtx10(offsetX + FX32_ONE, 0, offsetZ - FX32_ONE); + + G3_TexCoord(0, t); + G3_Vtx10(offsetX - FX32_ONE, 0, offsetZ - FX32_ONE); + + G3_End(); +} + +void sub_020A0398(fx32 sin, fx32 cos, MtxFx43 *mat) +{ + fx32 C, Sm, Sp; + + C = FX_MUL(FX32_ONE - cos, FX32_CONST(1 / 3.0)); + Sm = C + FX_MUL(sin, FX32_SQRT1_3); + Sp = C - FX_MUL(sin, FX32_SQRT1_3); + C += cos; + + mat->_00 = C; + mat->_10 = Sm; + mat->_20 = Sp; + mat->_30 = 0; + mat->_01 = Sp; + mat->_11 = C; + mat->_21 = Sm; + mat->_31 = 0; + mat->_02 = Sm; + mat->_12 = Sp; + mat->_22 = C; + mat->_32 = 0; +} + +void sub_020A0358(fx32 sin, fx32 cos, MtxFx43 *mat) +{ + mat->_00 = cos; + mat->_10 = 0; + mat->_20 = sin; + mat->_30 = 0; + mat->_01 = 0; + mat->_11 = FX32_ONE; + mat->_21 = 0; + mat->_31 = 0; + mat->_02 = -sin; + mat->_12 = 0; + mat->_22 = cos; + mat->_32 = 0; +} + +void sub_0209FF0C(SPLManager *mgr, SPLParticle *ptcl) +{ + fx32 aspect; + const MtxFx43 *cmr; + VecFx32 trs; + fx32 sclX, sclY; + MtxFx43 load; + fx32 sin; + fx16 animScale; + GXRgb ptclCol, emtrCol; + u8 scaleAnimDirect; + + SPLEmitter *emtr = mgr->unk_40.unk_00; + UnkSPLStruct9 *resBase = emtr->p_res->unk_00; + + cmr = mgr->unk_40.unk_04; + aspect = mgr->unk_40.unk_00->p_res->unk_00->unk_30; + animScale = ptcl->unk_34; + + ptclCol = ptcl->unk_36; + emtrCol = emtr->unk_E2; + + scaleAnimDirect = resBase->unk_48.unk_07_4; + + fx32 alpha = ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1) >> 5; + + G3_PolygonAttr( + GX_LIGHTMASK_NONE, + GX_POLYGONMODE_MODULATE, + GX_CULL_NONE, + ptcl->unk_2E.unk_01_2, + alpha, + mgr->unk_3C); + + reg_G3_POLYGON_ATTR; + + if (alpha == 0) { + return; + } + + sclY = ptcl->unk_30; + sclX = FX_MUL(sclY, aspect); + + if (scaleAnimDirect == 0) { + sclX = FX_MUL(sclX, animScale); + sclY = FX_MUL(sclY, animScale); + } else if (scaleAnimDirect == 1) { + sclX = FX_MUL(sclX, animScale); + } else { + sclY = FX_MUL(sclY, animScale); + } + + if (!mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_7) { + trs.x = ptcl->unk_08.x + ptcl->unk_38.x; + trs.y = ptcl->unk_08.y + ptcl->unk_38.y; + trs.z = ptcl->unk_08.z + ptcl->unk_38.z; + MTX_MultVec43(&trs, cmr, &trs); + + sin = FX_SinIdx(ptcl->unk_20); + fx32 cos = FX_CosIdx(ptcl->unk_20); + load._00 = FX_MUL(cos, sclX); + load._01 = FX_MUL(sin, sclX); + load._02 = 0; + load._10 = FX_MUL(-sin, sclY); + load._11 = FX_MUL(cos, sclY); + load._12 = 0; + load._20 = 0; + load._21 = 0; + load._22 = FX32_ONE; + load._30 = trs.x; + load._31 = trs.y; + load._32 = trs.z; + + G3_Identity(); + G3_MultMtx43(&load); + } else { + trs.x = ptcl->unk_08.x + ptcl->unk_38.x - mgr->unk_40.unk_00->p_res->unk_00->unk_04.x; + trs.y = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; + trs.z = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; + MTX_MultVec43(&trs, cmr, &trs); + + sin = FX_SinIdx(ptcl->unk_20); + fx32 cos = FX_CosIdx(ptcl->unk_20); + load._00 = FX_MUL(cos, sclX); + load._01 = FX_MUL(sin, sclX); + load._02 = 0; + load._10 = FX_MUL(-sin, sclY); + load._11 = FX_MUL(cos, sclY); + load._12 = 0; + load._20 = 0; + load._21 = 0; + load._22 = FX32_ONE; + load._30 = trs.x; + load._31 = trs.y; + load._32 = trs.z; + + G3_Identity(); + + UnkSPLStruct9 *resBase = mgr->unk_40.unk_00->p_res->unk_00; + G3_Translate(resBase->unk_04.x, resBase->unk_04.y, resBase->unk_04.z); + G3_MultMtx43(&load); + } + + G3_Color(GX_RGB( + GX_RGB_R_(ptclCol) * GX_RGB_R_(emtrCol) >> 5, + GX_RGB_G_(ptclCol) * GX_RGB_G_(emtrCol) >> 15, + GX_RGB_B_(ptclCol) * GX_RGB_B_(emtrCol) >> 25)); + + emtr = mgr->unk_40.unk_00; + sub_020A0500(emtr->unk_E8, emtr->unk_EA, emtr->p_res->unk_00->unk_54, emtr->p_res->unk_00->unk_56); +} + +void sub_0209FAB8(SPLManager *mgr, SPLParticle *ptcl) +{ + fx32 aspect; + const MtxFx43 *cmr; + VecFx32 trs; + fx32 sclX, sclY; + MtxFx43 load; + fx32 sin; + + cmr = mgr->unk_40.unk_04; + aspect = mgr->unk_40.unk_00->p_res->unk_00->unk_30; + + u32 polygonID = ptcl->unk_2E.unk_01_2 << REG_G3_POLYGON_ATTR_ID_SHIFT; + u32 cullMode = GX_CULL_NONE << REG_G3_POLYGON_ATTR_BK_SHIFT; + fx32 alpha = (fx32)(ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1)) >> 5; + + reg_G3_POLYGON_ATTR = (u32)((0 << REG_G3_POLYGON_ATTR_LE_SHIFT) | (GX_POLYGONMODE_MODULATE << REG_G3_POLYGON_ATTR_PM_SHIFT) | (cullMode) | (mgr->unk_3C) | (polygonID) - | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT) - ); + | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT)); u32 polygonAttr = reg_G3_POLYGON_ATTR; @@ -51,81 +239,480 @@ void sub_0209DD54(SPLManager *mgr, SPLParticle *ptcl) return; } - int rotation = ptcl->unk_20; - RotFunc rot = Unk_02100DA8[mgr->unk_40.unk_00->p_res->unk_14->unk_00.unk_03_1]; - rot(FX_SinIdx(rotation), FX_CosIdx(rotation), &rotMtx); + sclY = ptcl->unk_30; + sclX = FX_MUL(sclY, aspect); - MTX_Identity43(&mat); - - if (!mgr->unk_40.unk_00->p_res->unk_14->unk_0C.unk_04_6) { - VEC_Normalize(&ptcl->unk_14, &vec1); - } else { - VEC_Normalize(&ptcl->unk_08, &vec1); - vec1.x = -vec1.x; - vec1.y = -vec1.y; - vec1.z = -vec1.z; - } - - axis.x = 0; - axis.y = FX32_ONE; - axis.z = 0; - - dot = VEC_DotProduct(&vec1, &axis); - if (dot > FX32_CONST(0.800049) || dot < FX32_CONST(-0.800049)) { - axis.x = FX32_ONE; - axis.y = 0; - axis.z = 0; - } - - VEC_CrossProduct(&vec1, &axis, &vec2); - VEC_CrossProduct(&vec1, &vec2, &vec3); - - mat._00 = vec2.x; - mat._01 = vec2.y; - mat._02 = vec2.z; - scaleY = vec1.x; - mat._10 = scaleY; - mat._11 = vec1.y; - mat._12 = vec1.z; - mat._20 = vec3.x; - tmp = vec3.z; - mat._21 = vec3.y; - mat._22 = tmp; - MTX_Concat43(&rotMtx, &mat, &rotMtx); - - resBase = mgr->unk_40.unk_00->p_res->unk_00; - scaleY = ptcl->unk_30; - scaleX = FX_MUL(scaleY, resBase->unk_30); - - switch (resBase->unk_48.unk_07_4) { + switch (mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_07_4) { case 0: - scaleX = FX_MUL(scaleX, ptcl->unk_34); - scaleY = FX_MUL(scaleY, ptcl->unk_34); + sclX = FX_MUL(sclX, ptcl->unk_34); + sclY = FX_MUL(sclY, ptcl->unk_34); break; case 1: - scaleX = FX_MUL(scaleX, ptcl->unk_34); + sclX = FX_MUL(sclX, ptcl->unk_34); break; case 2: - scaleY = FX_MUL(scaleY, ptcl->unk_34); + sclY = FX_MUL(sclY, ptcl->unk_34); break; } - MTX_Scale43(&sclMat, scaleX, scaleY, scaleY); - MTX_Concat43(&rotMtx, &sclMat, &transform); + if (!mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_7) { + trs.x = ptcl->unk_08.x + ptcl->unk_38.x; + trs.y = ptcl->unk_08.y + ptcl->unk_38.y; + trs.z = ptcl->unk_08.z + ptcl->unk_38.z; + MTX_MultVec43(&trs, cmr, &trs); - resBase = mgr->unk_40.unk_00->p_res->unk_00; - if (!resBase->unk_00.unk_06_7) { - transform._30 = ptcl->unk_08.x + ptcl->unk_38.x; - transform._31 = ptcl->unk_08.y + ptcl->unk_38.y; - transform._32 = ptcl->unk_08.z + ptcl->unk_38.z; - G3_LoadMtx43(mgr->unk_40.unk_04); - G3_MultMtx43(&transform); + sin = FX_SinIdx(ptcl->unk_20); + fx32 cos = FX_CosIdx(ptcl->unk_20); + load._00 = FX_MUL(cos, sclX); + load._01 = FX_MUL(sin, sclX); + load._02 = 0; + load._10 = FX_MUL(-sin, sclY); + load._11 = FX_MUL(cos, sclY); + load._12 = 0; + load._20 = 0; + load._21 = 0; + load._22 = FX32_ONE; + load._30 = trs.x; + load._31 = trs.y; + load._32 = trs.z; + + reg_G3_MTX_IDENTITY = 0; + + G3_MultMtx43(&load); } else { - transform._30 = ptcl->unk_08.x + ptcl->unk_38.x - resBase->unk_04.x; - transform._31 = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; - transform._32 = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; + trs.x = ptcl->unk_08.x + ptcl->unk_38.x - mgr->unk_40.unk_00->p_res->unk_00->unk_04.x; + trs.y = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; + trs.z = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; + MTX_MultVec43(&trs, cmr, &trs); + + sin = FX_SinIdx(ptcl->unk_20); + fx32 cos = FX_CosIdx(ptcl->unk_20); + load._00 = FX_MUL(cos, sclX); + load._01 = FX_MUL(sin, sclX); + load._02 = 0; + load._10 = FX_MUL(-sin, sclY); + load._11 = FX_MUL(cos, sclY); + load._12 = 0; + load._20 = 0; + load._21 = 0; + load._22 = FX32_ONE; + load._30 = trs.x; + load._31 = trs.y; + load._32 = trs.z; + + reg_G3_MTX_IDENTITY = 0; + + UnkSPLStruct9 *resBase = mgr->unk_40.unk_00->p_res->unk_00; + fx32 px = resBase->unk_04.x, pz = resBase->unk_04.z, py = resBase->unk_04.y; + reg_G3_MTX_TRANS = px; + reg_G3_MTX_TRANS = py; + reg_G3_MTX_TRANS = pz; + + G3_MultMtx43(&load); + } + + GXRgb colA = ptcl->unk_36; + GXRgb colB = mgr->unk_40.unk_00->unk_E2; + reg_G3_COLOR = GX_RGB( + GX_RGB_R_(colA) * GX_RGB_R_(colB) >> 5, + GX_RGB_G_(colA) * GX_RGB_G_(colB) >> 15, + GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25); + + SPLEmitter *emtr = mgr->unk_40.unk_00; + sub_020A0500(emtr->unk_EC, emtr->unk_EE, 0, 0); +} + +void sub_0209F3D0(SPLManager *mgr, SPLParticle *ptcl) +{ + fx32 aspect; + const MtxFx43 *cmr; + VecFx32 vel_dir; + fx32 dot; + VecFx32 trs; + fx32 sclX, sclY; + VecFx32 dir, look; + MtxFx33 mtx; + MtxFx43 load; + + cmr = mgr->unk_40.unk_04; + aspect = mgr->unk_40.unk_00->p_res->unk_00->unk_30; + + u32 polygonID = ptcl->unk_2E.unk_01_2 << REG_G3_POLYGON_ATTR_ID_SHIFT; + u32 cullMode = GX_CULL_NONE << REG_G3_POLYGON_ATTR_BK_SHIFT; + fx32 alpha = (fx32)(ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1)) >> 5; + + reg_G3_POLYGON_ATTR = (u32)((0 << REG_G3_POLYGON_ATTR_LE_SHIFT) + | (GX_POLYGONMODE_MODULATE << REG_G3_POLYGON_ATTR_PM_SHIFT) + | (cullMode) + | (mgr->unk_3C) + | (polygonID) + | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT)); + + u32 polygonAttr = reg_G3_POLYGON_ATTR; + + if (alpha == 0) { + return; + } + + sclY = ptcl->unk_30; + sclX = FX_MUL(sclY, aspect); + + switch (mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_07_4) { + case 0: + sclX = FX_MUL(sclX, ptcl->unk_34); + sclY = FX_MUL(sclY, ptcl->unk_34); + break; + + case 1: + sclX = FX_MUL(sclX, ptcl->unk_34); + break; + + case 2: + sclY = FX_MUL(sclY, ptcl->unk_34); + break; + } + + if (!mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_7) { + trs.x = ptcl->unk_08.x + ptcl->unk_38.x; + trs.y = ptcl->unk_08.y + ptcl->unk_38.y; + trs.z = ptcl->unk_08.z + ptcl->unk_38.z; + + dir = ptcl->unk_14; + + look.x = cmr->_02; + look.y = cmr->_12; + look.z = cmr->_22; + + VEC_CrossProduct(&dir, &look, &dir); + if (dir.x == 0 && dir.y == 0 && dir.z == 0) { + return; + } + + VEC_Normalize(&dir, &dir); + MI_Copy36B(cmr, &mtx); + MTX_MultVec33(&dir, &mtx, &dir); + MTX_MultVec43(&trs, cmr, &trs); + + vel_dir = ptcl->unk_14; + VEC_Normalize(&vel_dir, &vel_dir); + + dot = FX_MUL(vel_dir.x, -cmr->_02) + FX_MUL(vel_dir.y, -cmr->_12) + FX_MUL(vel_dir.z, -cmr->_22); + if (dot < 0) { + dot = -dot; + } + + // dot = FX_MUL(FX32_ONE - dot, mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_05_0) + FX32_ONE + dot = FX_MUL(sclY, FX_MUL(FX32_ONE - dot, (fx32)mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_05_0) + FX32_ONE); + // fx32 x = FX_MUL(dir.x, sclX); + /* 54 */ load._00 = FX_MUL(dir.x, sclX); + /* 48 */ load._10 = FX_MUL(-dir.y, dot); + /* 30 */ load._30 = trs.x; + /* 2C */ load._31 = trs.y; + /* 50 */ load._01 = FX_MUL(dir.y, sclX); + /* 44 */ load._11 = FX_MUL(dir.x, dot); + /* 3C */ load._20 = 0; + /* 38 */ load._21 = 0; + /* 4C */ load._02 = 0; + /* 40 */ load._12 = 0; + /* 34 */ load._22 = FX32_ONE; + /* 28 */ load._32 = trs.z; + + reg_G3_MTX_IDENTITY = 0; + + G3_MultMtx43(&load); + } else { + trs.x = ptcl->unk_08.x + ptcl->unk_38.x - mgr->unk_40.unk_00->p_res->unk_00->unk_04.x; + trs.y = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; + trs.z = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; + + dir = ptcl->unk_14; + + look.x = cmr->_02; + look.y = cmr->_12; + look.z = cmr->_22; + + VEC_CrossProduct(&dir, &look, &dir); + if (dir.x == 0 && dir.y == 0 && dir.z == 0) { + return; + } + + VEC_Normalize(&dir, &dir); + MI_Copy36B(cmr, &mtx); + MTX_MultVec33(&dir, &mtx, &dir); + MTX_MultVec43(&trs, cmr, &trs); + + vel_dir = ptcl->unk_14; + VEC_Normalize(&vel_dir, &vel_dir); + + dot = FX_MUL(vel_dir.x, -cmr->_02) + FX_MUL(vel_dir.y, -cmr->_12) + FX_MUL(vel_dir.z, -cmr->_22); + if (dot < 0) { + dot = -dot; + } + + dot = FX_MUL(sclY, FX_MUL(FX32_ONE - dot, (fx32)mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_05_0) + FX32_ONE); + /* 54 */ load._00 = FX_MUL(dir.x, sclX); + /* 48 */ load._10 = FX_MUL(-dir.y, dot); + /* 40 */ load._20 = 0; + /* 30 */ load._30 = trs.x; + /* 50 */ load._01 = FX_MUL(dir.y, sclX); + /* 3C */ load._11 = FX_MUL(dir.x, dot); + /* 38 */ load._21 = 0; + /* 2C */ load._31 = trs.y; + /* 4C */ load._02 = 0; + /* 44 */ load._12 = 0; + /* 34 */ load._22 = FX32_ONE; + /* 28 */ load._32 = trs.z; + + reg_G3_MTX_IDENTITY = 0; + + UnkSPLStruct9 *resBase = mgr->unk_40.unk_00->p_res->unk_00; + fx32 px = resBase->unk_04.x, pz = resBase->unk_04.z, py = resBase->unk_04.y; + reg_G3_MTX_TRANS = px; + reg_G3_MTX_TRANS = py; + reg_G3_MTX_TRANS = pz; + + G3_MultMtx43(&load); + } + + GXRgb colA = ptcl->unk_36; + GXRgb colB = mgr->unk_40.unk_00->unk_E2; + reg_G3_COLOR = GX_RGB( + GX_RGB_R_(colA) * GX_RGB_R_(colB) >> 5, + GX_RGB_G_(colA) * GX_RGB_G_(colB) >> 15, + GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25); + + SPLEmitter *emtr = mgr->unk_40.unk_00; + sub_020A0500(emtr->unk_E8, emtr->unk_EA, emtr->p_res->unk_00->unk_54, emtr->p_res->unk_00->unk_56); +} + +void sub_0209ECF0(SPLManager *mgr, SPLParticle *ptcl) +{ + fx32 aspect; + const MtxFx43 *cmr; + VecFx32 vel_dir; + fx32 dot; + VecFx32 trs; + fx32 sclX, sclY; + VecFx32 dir, look; + MtxFx33 mtx; + MtxFx43 load; + + cmr = mgr->unk_40.unk_04; + aspect = mgr->unk_40.unk_00->p_res->unk_00->unk_30; + + u32 polygonID = ptcl->unk_2E.unk_01_2 << REG_G3_POLYGON_ATTR_ID_SHIFT; + u32 cullMode = GX_CULL_NONE << REG_G3_POLYGON_ATTR_BK_SHIFT; + fx32 alpha = (fx32)(ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1)) >> 5; + + reg_G3_POLYGON_ATTR = (u32)((0 << REG_G3_POLYGON_ATTR_LE_SHIFT) + | (GX_POLYGONMODE_MODULATE << REG_G3_POLYGON_ATTR_PM_SHIFT) + | (cullMode) + | (mgr->unk_3C) + | (polygonID) + | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT)); + + u32 polygonAttr = reg_G3_POLYGON_ATTR; + + if (alpha == 0) { + return; + } + + sclY = ptcl->unk_30; + sclX = FX_MUL(sclY, aspect); + + switch (mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_07_4) { + case 0: + sclX = FX_MUL(sclX, ptcl->unk_34); + sclY = FX_MUL(sclY, ptcl->unk_34); + break; + + case 1: + sclX = FX_MUL(sclX, ptcl->unk_34); + break; + + case 2: + sclY = FX_MUL(sclY, ptcl->unk_34); + break; + } + + if (!mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_7) { + trs.x = ptcl->unk_08.x + ptcl->unk_38.x; + trs.y = ptcl->unk_08.y + ptcl->unk_38.y; + trs.z = ptcl->unk_08.z + ptcl->unk_38.z; + + dir = ptcl->unk_14; + + look.x = cmr->_02; + look.y = cmr->_12; + look.z = cmr->_22; + + VEC_CrossProduct(&dir, &look, &dir); + if (dir.x == 0 && dir.y == 0 && dir.z == 0) { + return; + } + + VEC_Normalize(&dir, &dir); + MI_Copy36B(cmr, &mtx); + MTX_MultVec33(&dir, &mtx, &dir); + MTX_MultVec43(&trs, cmr, &trs); + + vel_dir = ptcl->unk_14; + VEC_Normalize(&vel_dir, &vel_dir); + + dot = FX_MUL(vel_dir.x, -cmr->_02) + FX_MUL(vel_dir.y, -cmr->_12) + FX_MUL(vel_dir.z, -cmr->_22); + if (dot < 0) { + dot = -dot; + } + + dot = FX_MUL(sclY, FX_MUL(FX32_ONE - dot, (fx32)mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_05_0) + FX32_ONE); + load._00 = FX_MUL(dir.x, sclX); + load._10 = FX_MUL(-dir.y, dot); + load._30 = trs.x; + load._31 = trs.y; + load._01 = FX_MUL(dir.y, sclX); + load._11 = FX_MUL(dir.x, dot); + load._20 = 0; + load._21 = 0; + load._02 = 0; + load._12 = 0; + load._22 = FX32_ONE; + load._32 = trs.z; + + reg_G3_MTX_IDENTITY = 0; + + G3_MultMtx43(&load); + } else { + trs.x = ptcl->unk_08.x + ptcl->unk_38.x - mgr->unk_40.unk_00->p_res->unk_00->unk_04.x; + trs.y = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; + trs.z = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; + + dir = ptcl->unk_14; + + look.x = cmr->_02; + look.y = cmr->_12; + look.z = cmr->_22; + + VEC_CrossProduct(&dir, &look, &dir); + if (dir.x == 0 && dir.y == 0 && dir.z == 0) { + return; + } + + VEC_Normalize(&dir, &dir); + MI_Copy36B(cmr, &mtx); + MTX_MultVec33(&dir, &mtx, &dir); + MTX_MultVec43(&trs, cmr, &trs); + + vel_dir = ptcl->unk_14; + VEC_Normalize(&vel_dir, &vel_dir); + + dot = FX_MUL(vel_dir.x, -cmr->_02) + FX_MUL(vel_dir.y, -cmr->_12) + FX_MUL(vel_dir.z, -cmr->_22); + if (dot < 0) { + dot = -dot; + } + + dot = FX_MUL(sclY, FX_MUL(FX32_ONE - dot, (fx32)mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_05_0) + FX32_ONE); + /* 54 */ load._00 = FX_MUL(dir.x, sclX); + /* 48 */ load._10 = FX_MUL(-dir.y, dot); + /* 40 */ load._20 = 0; + /* 30 */ load._30 = trs.x; + /* 50 */ load._01 = FX_MUL(dir.y, sclX); + /* 3C */ load._11 = FX_MUL(dir.x, dot); + /* 38 */ load._21 = 0; + /* 2C */ load._31 = trs.y; + /* 4C */ load._02 = 0; + /* 44 */ load._12 = 0; + /* 34 */ load._22 = FX32_ONE; + /* 28 */ load._32 = trs.z; + + reg_G3_MTX_IDENTITY = 0; + + UnkSPLStruct9 *resBase = mgr->unk_40.unk_00->p_res->unk_00; + fx32 px = resBase->unk_04.x, pz = resBase->unk_04.z, py = resBase->unk_04.y; + reg_G3_MTX_TRANS = px; + reg_G3_MTX_TRANS = py; + reg_G3_MTX_TRANS = pz; + + G3_MultMtx43(&load); + } + + GXRgb colA = ptcl->unk_36; + GXRgb colB = mgr->unk_40.unk_00->unk_E2; + reg_G3_COLOR = GX_RGB( + GX_RGB_R_(colA) * GX_RGB_R_(colB) >> 5, + GX_RGB_G_(colA) * GX_RGB_G_(colB) >> 15, + GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25); + + SPLEmitter *emtr = mgr->unk_40.unk_00; + sub_020A0500(emtr->unk_EC, emtr->unk_EE, 0, 0); +} + +void sub_0209E9A0(SPLManager *mgr, SPLParticle *ptcl) +{ + fx32 sclX, sclY; + MtxFx43 load; + MtxFx43 rotMtx; + MtxFx43 sclMtx; + u32 polygonID, cullMode; + fx32 alpha; + UnkSPLStruct9 *resBase; + + alpha = ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1) >> 5; + polygonID = ptcl->unk_2E.unk_01_2 << REG_G3_POLYGON_ATTR_ID_SHIFT; + cullMode = GX_CULL_NONE << REG_G3_POLYGON_ATTR_BK_SHIFT; + + reg_G3_POLYGON_ATTR = (u32)((0 << REG_G3_POLYGON_ATTR_LE_SHIFT) + | (GX_POLYGONMODE_MODULATE << REG_G3_POLYGON_ATTR_PM_SHIFT) + | (cullMode) + | (mgr->unk_3C) + | (polygonID) + | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT)); + + u32 polygonAttr = reg_G3_POLYGON_ATTR; + + if (alpha == 0) { + return; + } + + Unk_02100DA8[mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_1]( + FX_SinIdx(ptcl->unk_20), + FX_CosIdx(ptcl->unk_20), + &rotMtx); + + sclY = ptcl->unk_30; + resBase = mgr->unk_40.unk_00->p_res->unk_00; + sclX = FX_MUL(sclY, resBase->unk_30); + + switch (resBase->unk_48.unk_07_4) { + case 0: + sclX = FX_MUL(sclX, ptcl->unk_34); + sclY = FX_MUL(sclY, ptcl->unk_34); + break; + + case 1: + sclX = FX_MUL(sclX, ptcl->unk_34); + break; + + case 2: + sclY = FX_MUL(sclY, ptcl->unk_34); + break; + } + + MTX_Scale43(&sclMtx, sclX, sclY, sclY); + MTX_Concat43(&sclMtx, &rotMtx, &load); + + // resBase = mgr->unk_40.unk_00->p_res->unk_00; + if (!mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_7) { + load._30 = ptcl->unk_08.x + ptcl->unk_38.x; + load._31 = ptcl->unk_08.y + ptcl->unk_38.y; + load._32 = ptcl->unk_08.z + ptcl->unk_38.z; + G3_LoadMtx43(mgr->unk_40.unk_04); + G3_MultMtx43(&load); + } else { + load._30 = ptcl->unk_08.x + ptcl->unk_38.x - mgr->unk_40.unk_00->p_res->unk_00->unk_04.x; + load._31 = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; + load._32 = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; reg_G3_MTX_IDENTITY = 0; @@ -136,7 +723,7 @@ void sub_0209DD54(SPLManager *mgr, SPLParticle *ptcl) reg_G3_MTX_TRANS = z; G3_MultMtx43(mgr->unk_40.unk_04); - G3_MultMtx43(&transform); + G3_MultMtx43(&load); } GXRgb colA = ptcl->unk_36; @@ -144,12 +731,100 @@ void sub_0209DD54(SPLManager *mgr, SPLParticle *ptcl) reg_G3_COLOR = GX_RGB( GX_RGB_R_(colA) * GX_RGB_R_(colB) >> 5, GX_RGB_G_(colA) * GX_RGB_G_(colB) >> 15, - GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25 - ); + GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25); SPLEmitter *emtr = mgr->unk_40.unk_00; - DrawPlaneFunc drawPlane = Unk_02100DA0[emtr->p_res->unk_14->unk_00.unk_03_3]; - drawPlane(emtr->unk_EC, emtr->unk_EE, 0, 0); + resBase = emtr->p_res->unk_00; + Unk_02100DA0[resBase->unk_00.unk_06_3](emtr->unk_E8, emtr->unk_EA, resBase->unk_54, resBase->unk_56); +} + +void sub_0209E650(SPLManager *mgr, SPLParticle *ptcl) +{ + fx32 sclX, sclY; + MtxFx43 load; + MtxFx43 rotMtx; + MtxFx43 sclMtx; + u32 polygonID, cullMode; + fx32 alpha; + UnkSPLStruct9 *resBase; + + alpha = ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1) >> 5; + polygonID = ptcl->unk_2E.unk_01_2 << REG_G3_POLYGON_ATTR_ID_SHIFT; + cullMode = GX_CULL_NONE << REG_G3_POLYGON_ATTR_BK_SHIFT; + + reg_G3_POLYGON_ATTR = (u32)((0 << REG_G3_POLYGON_ATTR_LE_SHIFT) + | (GX_POLYGONMODE_MODULATE << REG_G3_POLYGON_ATTR_PM_SHIFT) + | (cullMode) + | (mgr->unk_3C) + | (polygonID) + | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT)); + + u32 polygonAttr = reg_G3_POLYGON_ATTR; + + if (alpha == 0) { + return; + } + + Unk_02100DA8[mgr->unk_40.unk_00->p_res->unk_14->unk_00.unk_03_1]( + FX_SinIdx(ptcl->unk_20), + FX_CosIdx(ptcl->unk_20), + &rotMtx); + + sclY = ptcl->unk_30; + resBase = mgr->unk_40.unk_00->p_res->unk_00; + sclX = FX_MUL(sclY, resBase->unk_30); + + switch (resBase->unk_48.unk_07_4) { + case 0: + sclX = FX_MUL(sclX, ptcl->unk_34); + sclY = FX_MUL(sclY, ptcl->unk_34); + break; + + case 1: + sclX = FX_MUL(sclX, ptcl->unk_34); + break; + + case 2: + sclY = FX_MUL(sclY, ptcl->unk_34); + break; + } + + MTX_Scale43(&sclMtx, sclX, sclY, sclY); + MTX_Concat43(&rotMtx, &sclMtx, &load); + + // resBase = mgr->unk_40.unk_00->p_res->unk_00; + if (!mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_7) { + load._30 = ptcl->unk_08.x + ptcl->unk_38.x; + load._31 = ptcl->unk_08.y + ptcl->unk_38.y; + load._32 = ptcl->unk_08.z + ptcl->unk_38.z; + G3_LoadMtx43(mgr->unk_40.unk_04); + G3_MultMtx43(&load); + } else { + load._30 = ptcl->unk_08.x + ptcl->unk_38.x - mgr->unk_40.unk_00->p_res->unk_00->unk_04.x; + load._31 = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; + load._32 = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; + + reg_G3_MTX_IDENTITY = 0; + + resBase = mgr->unk_40.unk_00->p_res->unk_00; + fx32 x = resBase->unk_04.x, z = resBase->unk_04.z, y = resBase->unk_04.y; + reg_G3_MTX_TRANS = x; + reg_G3_MTX_TRANS = y; + reg_G3_MTX_TRANS = z; + + G3_MultMtx43(mgr->unk_40.unk_04); + G3_MultMtx43(&load); + } + + GXRgb colA = ptcl->unk_36; + GXRgb colB = mgr->unk_40.unk_00->unk_E2; + reg_G3_COLOR = GX_RGB( + GX_RGB_R_(colA) * GX_RGB_R_(colB) >> 5, + GX_RGB_G_(colA) * GX_RGB_G_(colB) >> 15, + GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25); + + SPLEmitter *emtr = mgr->unk_40.unk_00; + Unk_02100DA0[emtr->p_res->unk_14->unk_00.unk_03_3](emtr->unk_EC, emtr->unk_EE, 0, 0); } void sub_0209E1D4(SPLManager *mgr, SPLParticle *ptcl) @@ -167,19 +842,17 @@ void sub_0209E1D4(SPLManager *mgr, SPLParticle *ptcl) RotFunc rot; DrawPlaneFunc drawPlane; GXRgb colA, colB; - + alpha = ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1) >> 5; polygonID = ptcl->unk_2E.unk_01_2 << REG_G3_POLYGON_ATTR_ID_SHIFT; cullMode = GX_CULL_NONE << REG_G3_POLYGON_ATTR_BK_SHIFT; - reg_G3_POLYGON_ATTR = (u32)( - (0 << REG_G3_POLYGON_ATTR_LE_SHIFT) + reg_G3_POLYGON_ATTR = (u32)((0 << REG_G3_POLYGON_ATTR_LE_SHIFT) | (GX_POLYGONMODE_MODULATE << REG_G3_POLYGON_ATTR_PM_SHIFT) | (cullMode) | (mgr->unk_3C) | (polygonID) - | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT) - ); + | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT)); u32 polygonAttr = reg_G3_POLYGON_ATTR; @@ -282,8 +955,7 @@ void sub_0209E1D4(SPLManager *mgr, SPLParticle *ptcl) reg_G3_COLOR = GX_RGB( GX_RGB_R_(colA) * GX_RGB_R_(colB) >> 5, GX_RGB_G_(colA) * GX_RGB_G_(colB) >> 15, - GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25 - ); + GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25); emtr = mgr->unk_40.unk_00; resBase = emtr->p_res->unk_00; @@ -291,28 +963,27 @@ void sub_0209E1D4(SPLManager *mgr, SPLParticle *ptcl) drawPlane(emtr->unk_E8, emtr->unk_EA, resBase->unk_54, resBase->unk_56); } -void sub_0209E650(SPLManager *mgr, SPLParticle *ptcl) +void sub_0209DD54(SPLManager *mgr, SPLParticle *ptcl) { - fx32 sclX, sclY; - MtxFx43 load; + MtxFx43 transform; MtxFx43 rotMtx; - MtxFx43 sclMtx; + MtxFx43 sclMat; + VecFx32 vec1, vec2, vec3, vec4, axis; + MtxFx43 mat; + fx32 dot, scaleX, scaleY, scaleZ, alpha, tmp; u32 polygonID, cullMode; - fx32 alpha; UnkSPLStruct9 *resBase; alpha = ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1) >> 5; polygonID = ptcl->unk_2E.unk_01_2 << REG_G3_POLYGON_ATTR_ID_SHIFT; cullMode = GX_CULL_NONE << REG_G3_POLYGON_ATTR_BK_SHIFT; - reg_G3_POLYGON_ATTR = (u32)( - (0 << REG_G3_POLYGON_ATTR_LE_SHIFT) + reg_G3_POLYGON_ATTR = (u32)((0 << REG_G3_POLYGON_ATTR_LE_SHIFT) | (GX_POLYGONMODE_MODULATE << REG_G3_POLYGON_ATTR_PM_SHIFT) | (cullMode) | (mgr->unk_3C) | (polygonID) - | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT) - ); + | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT)); u32 polygonAttr = reg_G3_POLYGON_ATTR; @@ -320,45 +991,81 @@ void sub_0209E650(SPLManager *mgr, SPLParticle *ptcl) return; } - Unk_02100DA8[mgr->unk_40.unk_00->p_res->unk_14->unk_00.unk_03_1]( - FX_SinIdx(ptcl->unk_20), - FX_CosIdx(ptcl->unk_20), - &rotMtx - ); + int rotation = ptcl->unk_20; + RotFunc rot = Unk_02100DA8[mgr->unk_40.unk_00->p_res->unk_14->unk_00.unk_03_1]; + rot(FX_SinIdx(rotation), FX_CosIdx(rotation), &rotMtx); + + MTX_Identity43(&mat); + + if (!mgr->unk_40.unk_00->p_res->unk_14->unk_0C.unk_04_6) { + VEC_Normalize(&ptcl->unk_14, &vec1); + } else { + VEC_Normalize(&ptcl->unk_08, &vec1); + vec1.x = -vec1.x; + vec1.y = -vec1.y; + vec1.z = -vec1.z; + } + + axis.x = 0; + axis.y = FX32_ONE; + axis.z = 0; + + dot = VEC_DotProduct(&vec1, &axis); + if (dot > FX32_CONST(0.800049) || dot < FX32_CONST(-0.800049)) { + axis.x = FX32_ONE; + axis.y = 0; + axis.z = 0; + } + + VEC_CrossProduct(&vec1, &axis, &vec2); + VEC_CrossProduct(&vec1, &vec2, &vec3); + + mat._00 = vec2.x; + mat._01 = vec2.y; + mat._02 = vec2.z; + scaleY = vec1.x; + mat._10 = scaleY; + mat._11 = vec1.y; + mat._12 = vec1.z; + mat._20 = vec3.x; + tmp = vec3.z; + mat._21 = vec3.y; + mat._22 = tmp; + MTX_Concat43(&rotMtx, &mat, &rotMtx); - sclY = ptcl->unk_30; resBase = mgr->unk_40.unk_00->p_res->unk_00; - sclX = FX_MUL(sclY, resBase->unk_30); - + scaleY = ptcl->unk_30; + scaleX = FX_MUL(scaleY, resBase->unk_30); + switch (resBase->unk_48.unk_07_4) { case 0: - sclX = FX_MUL(sclX, ptcl->unk_34); - sclY = FX_MUL(sclY, ptcl->unk_34); + scaleX = FX_MUL(scaleX, ptcl->unk_34); + scaleY = FX_MUL(scaleY, ptcl->unk_34); break; case 1: - sclX = FX_MUL(sclX, ptcl->unk_34); + scaleX = FX_MUL(scaleX, ptcl->unk_34); break; case 2: - sclY = FX_MUL(sclY, ptcl->unk_34); + scaleY = FX_MUL(scaleY, ptcl->unk_34); break; } - MTX_Scale43(&sclMtx, sclX, sclY, sclY); - MTX_Concat43(&rotMtx, &sclMtx, &load); + MTX_Scale43(&sclMat, scaleX, scaleY, scaleY); + MTX_Concat43(&rotMtx, &sclMat, &transform); - // resBase = mgr->unk_40.unk_00->p_res->unk_00; - if (!mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_7) { - load._30 = ptcl->unk_08.x + ptcl->unk_38.x; - load._31 = ptcl->unk_08.y + ptcl->unk_38.y; - load._32 = ptcl->unk_08.z + ptcl->unk_38.z; + resBase = mgr->unk_40.unk_00->p_res->unk_00; + if (!resBase->unk_00.unk_06_7) { + transform._30 = ptcl->unk_08.x + ptcl->unk_38.x; + transform._31 = ptcl->unk_08.y + ptcl->unk_38.y; + transform._32 = ptcl->unk_08.z + ptcl->unk_38.z; G3_LoadMtx43(mgr->unk_40.unk_04); - G3_MultMtx43(&load); + G3_MultMtx43(&transform); } else { - load._30 = ptcl->unk_08.x + ptcl->unk_38.x - mgr->unk_40.unk_00->p_res->unk_00->unk_04.x; - load._31 = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; - load._32 = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; + transform._30 = ptcl->unk_08.x + ptcl->unk_38.x - resBase->unk_04.x; + transform._31 = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; + transform._32 = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; reg_G3_MTX_IDENTITY = 0; @@ -369,7 +1076,7 @@ void sub_0209E650(SPLManager *mgr, SPLParticle *ptcl) reg_G3_MTX_TRANS = z; G3_MultMtx43(mgr->unk_40.unk_04); - G3_MultMtx43(&load); + G3_MultMtx43(&transform); } GXRgb colA = ptcl->unk_36; @@ -377,742 +1084,9 @@ void sub_0209E650(SPLManager *mgr, SPLParticle *ptcl) reg_G3_COLOR = GX_RGB( GX_RGB_R_(colA) * GX_RGB_R_(colB) >> 5, GX_RGB_G_(colA) * GX_RGB_G_(colB) >> 15, - GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25 - ); + GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25); SPLEmitter *emtr = mgr->unk_40.unk_00; - Unk_02100DA0[emtr->p_res->unk_14->unk_00.unk_03_3](emtr->unk_EC, emtr->unk_EE, 0, 0); -} - -void sub_0209E9A0(SPLManager *mgr, SPLParticle *ptcl) -{ - fx32 sclX, sclY; - MtxFx43 load; - MtxFx43 rotMtx; - MtxFx43 sclMtx; - u32 polygonID, cullMode; - fx32 alpha; - UnkSPLStruct9 *resBase; - - alpha = ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1) >> 5; - polygonID = ptcl->unk_2E.unk_01_2 << REG_G3_POLYGON_ATTR_ID_SHIFT; - cullMode = GX_CULL_NONE << REG_G3_POLYGON_ATTR_BK_SHIFT; - - reg_G3_POLYGON_ATTR = (u32)( - (0 << REG_G3_POLYGON_ATTR_LE_SHIFT) - | (GX_POLYGONMODE_MODULATE << REG_G3_POLYGON_ATTR_PM_SHIFT) - | (cullMode) - | (mgr->unk_3C) - | (polygonID) - | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT) - ); - - u32 polygonAttr = reg_G3_POLYGON_ATTR; - - if (alpha == 0) { - return; - } - - Unk_02100DA8[mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_1]( - FX_SinIdx(ptcl->unk_20), - FX_CosIdx(ptcl->unk_20), - &rotMtx - ); - - sclY = ptcl->unk_30; - resBase = mgr->unk_40.unk_00->p_res->unk_00; - sclX = FX_MUL(sclY, resBase->unk_30); - - switch (resBase->unk_48.unk_07_4) { - case 0: - sclX = FX_MUL(sclX, ptcl->unk_34); - sclY = FX_MUL(sclY, ptcl->unk_34); - break; - - case 1: - sclX = FX_MUL(sclX, ptcl->unk_34); - break; - - case 2: - sclY = FX_MUL(sclY, ptcl->unk_34); - break; - } - - MTX_Scale43(&sclMtx, sclX, sclY, sclY); - MTX_Concat43(&sclMtx, &rotMtx, &load); - - // resBase = mgr->unk_40.unk_00->p_res->unk_00; - if (!mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_7) { - load._30 = ptcl->unk_08.x + ptcl->unk_38.x; - load._31 = ptcl->unk_08.y + ptcl->unk_38.y; - load._32 = ptcl->unk_08.z + ptcl->unk_38.z; - G3_LoadMtx43(mgr->unk_40.unk_04); - G3_MultMtx43(&load); - } else { - load._30 = ptcl->unk_08.x + ptcl->unk_38.x - mgr->unk_40.unk_00->p_res->unk_00->unk_04.x; - load._31 = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; - load._32 = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; - - reg_G3_MTX_IDENTITY = 0; - - resBase = mgr->unk_40.unk_00->p_res->unk_00; - fx32 x = resBase->unk_04.x, z = resBase->unk_04.z, y = resBase->unk_04.y; - reg_G3_MTX_TRANS = x; - reg_G3_MTX_TRANS = y; - reg_G3_MTX_TRANS = z; - - G3_MultMtx43(mgr->unk_40.unk_04); - G3_MultMtx43(&load); - } - - GXRgb colA = ptcl->unk_36; - GXRgb colB = mgr->unk_40.unk_00->unk_E2; - reg_G3_COLOR = GX_RGB( - GX_RGB_R_(colA) * GX_RGB_R_(colB) >> 5, - GX_RGB_G_(colA) * GX_RGB_G_(colB) >> 15, - GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25 - ); - - SPLEmitter *emtr = mgr->unk_40.unk_00; - resBase = emtr->p_res->unk_00; - Unk_02100DA0[resBase->unk_00.unk_06_3](emtr->unk_E8, emtr->unk_EA, resBase->unk_54, resBase->unk_56); -} - -void sub_0209ECF0(SPLManager *mgr, SPLParticle *ptcl) -{ - fx32 aspect; - const MtxFx43 *cmr; - VecFx32 vel_dir; - fx32 dot; - VecFx32 trs; - fx32 sclX, sclY; - VecFx32 dir, look; - MtxFx33 mtx; - MtxFx43 load; - - - cmr = mgr->unk_40.unk_04; - aspect = mgr->unk_40.unk_00->p_res->unk_00->unk_30; - - u32 polygonID = ptcl->unk_2E.unk_01_2 << REG_G3_POLYGON_ATTR_ID_SHIFT; - u32 cullMode = GX_CULL_NONE << REG_G3_POLYGON_ATTR_BK_SHIFT; - fx32 alpha = (fx32)(ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1)) >> 5; - - reg_G3_POLYGON_ATTR = (u32)( - (0 << REG_G3_POLYGON_ATTR_LE_SHIFT) - | (GX_POLYGONMODE_MODULATE << REG_G3_POLYGON_ATTR_PM_SHIFT) - | (cullMode) - | (mgr->unk_3C) - | (polygonID) - | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT) - ); - - u32 polygonAttr = reg_G3_POLYGON_ATTR; - - if (alpha == 0) { - return; - } - - sclY = ptcl->unk_30; - sclX = FX_MUL(sclY, aspect); - - switch (mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_07_4) { - case 0: - sclX = FX_MUL(sclX, ptcl->unk_34); - sclY = FX_MUL(sclY, ptcl->unk_34); - break; - - case 1: - sclX = FX_MUL(sclX, ptcl->unk_34); - break; - - case 2: - sclY = FX_MUL(sclY, ptcl->unk_34); - break; - } - - if (!mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_7) { - trs.x = ptcl->unk_08.x + ptcl->unk_38.x; - trs.y = ptcl->unk_08.y + ptcl->unk_38.y; - trs.z = ptcl->unk_08.z + ptcl->unk_38.z; - - dir = ptcl->unk_14; - - look.x = cmr->_02; - look.y = cmr->_12; - look.z = cmr->_22; - - VEC_CrossProduct(&dir, &look, &dir); - if (dir.x == 0 && dir.y == 0 && dir.z == 0) { - return; - } - - VEC_Normalize(&dir, &dir); - MI_Copy36B(cmr, &mtx); - MTX_MultVec33(&dir, &mtx, &dir); - MTX_MultVec43(&trs, cmr, &trs); - - vel_dir = ptcl->unk_14; - VEC_Normalize(&vel_dir, &vel_dir); - - dot = FX_MUL(vel_dir.x, -cmr->_02) + FX_MUL(vel_dir.y, -cmr->_12) + FX_MUL(vel_dir.z, -cmr->_22); - if (dot < 0) { - dot = -dot; - } - - dot = FX_MUL(sclY, FX_MUL(FX32_ONE - dot, (fx32)mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_05_0) + FX32_ONE); - load._00 = FX_MUL(dir.x, sclX); - load._10 = FX_MUL(-dir.y, dot); - load._30 = trs.x; - load._31 = trs.y; - load._01 = FX_MUL(dir.y, sclX); - load._11 = FX_MUL(dir.x, dot); - load._20 = 0; - load._21 = 0; - load._02 = 0; - load._12 = 0; - load._22 = FX32_ONE; - load._32 = trs.z; - - reg_G3_MTX_IDENTITY = 0; - - G3_MultMtx43(&load); - } else { - trs.x = ptcl->unk_08.x + ptcl->unk_38.x - mgr->unk_40.unk_00->p_res->unk_00->unk_04.x; - trs.y = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; - trs.z = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; - - dir = ptcl->unk_14; - - look.x = cmr->_02; - look.y = cmr->_12; - look.z = cmr->_22; - - VEC_CrossProduct(&dir, &look, &dir); - if (dir.x == 0 && dir.y == 0 && dir.z == 0) { - return; - } - - VEC_Normalize(&dir, &dir); - MI_Copy36B(cmr, &mtx); - MTX_MultVec33(&dir, &mtx, &dir); - MTX_MultVec43(&trs, cmr, &trs); - - vel_dir = ptcl->unk_14; - VEC_Normalize(&vel_dir, &vel_dir); - - dot = FX_MUL(vel_dir.x, -cmr->_02) + FX_MUL(vel_dir.y, -cmr->_12) + FX_MUL(vel_dir.z, -cmr->_22); - if (dot < 0) { - dot = -dot; - } - - dot = FX_MUL(sclY, FX_MUL(FX32_ONE - dot, (fx32)mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_05_0) + FX32_ONE); - /* 54 */ load._00 = FX_MUL(dir.x, sclX); - /* 48 */ load._10 = FX_MUL(-dir.y, dot); - /* 40 */ load._20 = 0; - /* 30 */ load._30 = trs.x; - /* 50 */ load._01 = FX_MUL(dir.y, sclX); - /* 3C */ load._11 = FX_MUL(dir.x, dot); - /* 38 */ load._21 = 0; - /* 2C */ load._31 = trs.y; - /* 4C */ load._02 = 0; - /* 44 */ load._12 = 0; - /* 34 */ load._22 = FX32_ONE; - /* 28 */ load._32 = trs.z; - - reg_G3_MTX_IDENTITY = 0; - - UnkSPLStruct9 *resBase = mgr->unk_40.unk_00->p_res->unk_00; - fx32 px = resBase->unk_04.x, pz = resBase->unk_04.z, py = resBase->unk_04.y; - reg_G3_MTX_TRANS = px; - reg_G3_MTX_TRANS = py; - reg_G3_MTX_TRANS = pz; - - G3_MultMtx43(&load); - } - - GXRgb colA = ptcl->unk_36; - GXRgb colB = mgr->unk_40.unk_00->unk_E2; - reg_G3_COLOR = GX_RGB( - GX_RGB_R_(colA) * GX_RGB_R_(colB) >> 5, - GX_RGB_G_(colA) * GX_RGB_G_(colB) >> 15, - GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25 - ); - - SPLEmitter *emtr = mgr->unk_40.unk_00; - sub_020A0500(emtr->unk_EC, emtr->unk_EE, 0, 0); -} - -void sub_0209F3D0(SPLManager *mgr, SPLParticle *ptcl) -{ - fx32 aspect; - const MtxFx43 *cmr; - VecFx32 vel_dir; - fx32 dot; - VecFx32 trs; - fx32 sclX, sclY; - VecFx32 dir, look; - MtxFx33 mtx; - MtxFx43 load; - - cmr = mgr->unk_40.unk_04; - aspect = mgr->unk_40.unk_00->p_res->unk_00->unk_30; - - u32 polygonID = ptcl->unk_2E.unk_01_2 << REG_G3_POLYGON_ATTR_ID_SHIFT; - u32 cullMode = GX_CULL_NONE << REG_G3_POLYGON_ATTR_BK_SHIFT; - fx32 alpha = (fx32)(ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1)) >> 5; - - reg_G3_POLYGON_ATTR = (u32)( - (0 << REG_G3_POLYGON_ATTR_LE_SHIFT) - | (GX_POLYGONMODE_MODULATE << REG_G3_POLYGON_ATTR_PM_SHIFT) - | (cullMode) - | (mgr->unk_3C) - | (polygonID) - | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT) - ); - - u32 polygonAttr = reg_G3_POLYGON_ATTR; - - if (alpha == 0) { - return; - } - - sclY = ptcl->unk_30; - sclX = FX_MUL(sclY, aspect); - - switch (mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_07_4) { - case 0: - sclX = FX_MUL(sclX, ptcl->unk_34); - sclY = FX_MUL(sclY, ptcl->unk_34); - break; - - case 1: - sclX = FX_MUL(sclX, ptcl->unk_34); - break; - - case 2: - sclY = FX_MUL(sclY, ptcl->unk_34); - break; - } - - if (!mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_7) { - trs.x = ptcl->unk_08.x + ptcl->unk_38.x; - trs.y = ptcl->unk_08.y + ptcl->unk_38.y; - trs.z = ptcl->unk_08.z + ptcl->unk_38.z; - - dir = ptcl->unk_14; - - look.x = cmr->_02; - look.y = cmr->_12; - look.z = cmr->_22; - - VEC_CrossProduct(&dir, &look, &dir); - if (dir.x == 0 && dir.y == 0 && dir.z == 0) { - return; - } - - VEC_Normalize(&dir, &dir); - MI_Copy36B(cmr, &mtx); - MTX_MultVec33(&dir, &mtx, &dir); - MTX_MultVec43(&trs, cmr, &trs); - - vel_dir = ptcl->unk_14; - VEC_Normalize(&vel_dir, &vel_dir); - - dot = FX_MUL(vel_dir.x, -cmr->_02) + FX_MUL(vel_dir.y, -cmr->_12) + FX_MUL(vel_dir.z, -cmr->_22); - if (dot < 0) { - dot = -dot; - } - - // dot = FX_MUL(FX32_ONE - dot, mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_05_0) + FX32_ONE - dot = FX_MUL(sclY, FX_MUL(FX32_ONE - dot, (fx32)mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_05_0) + FX32_ONE); - // fx32 x = FX_MUL(dir.x, sclX); - /* 54 */ load._00 = FX_MUL(dir.x, sclX); - /* 48 */ load._10 = FX_MUL(-dir.y, dot); - /* 30 */ load._30 = trs.x; - /* 2C */ load._31 = trs.y; - /* 50 */ load._01 = FX_MUL(dir.y, sclX); - /* 44 */ load._11 = FX_MUL(dir.x, dot); - /* 3C */ load._20 = 0; - /* 38 */ load._21 = 0; - /* 4C */ load._02 = 0; - /* 40 */ load._12 = 0; - /* 34 */ load._22 = FX32_ONE; - /* 28 */ load._32 = trs.z; - - reg_G3_MTX_IDENTITY = 0; - - G3_MultMtx43(&load); - } else { - trs.x = ptcl->unk_08.x + ptcl->unk_38.x - mgr->unk_40.unk_00->p_res->unk_00->unk_04.x; - trs.y = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; - trs.z = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; - - dir = ptcl->unk_14; - - look.x = cmr->_02; - look.y = cmr->_12; - look.z = cmr->_22; - - VEC_CrossProduct(&dir, &look, &dir); - if (dir.x == 0 && dir.y == 0 && dir.z == 0) { - return; - } - - VEC_Normalize(&dir, &dir); - MI_Copy36B(cmr, &mtx); - MTX_MultVec33(&dir, &mtx, &dir); - MTX_MultVec43(&trs, cmr, &trs); - - vel_dir = ptcl->unk_14; - VEC_Normalize(&vel_dir, &vel_dir); - - dot = FX_MUL(vel_dir.x, -cmr->_02) + FX_MUL(vel_dir.y, -cmr->_12) + FX_MUL(vel_dir.z, -cmr->_22); - if (dot < 0) { - dot = -dot; - } - - dot = FX_MUL(sclY, FX_MUL(FX32_ONE - dot, (fx32)mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_05_0) + FX32_ONE); - /* 54 */ load._00 = FX_MUL(dir.x, sclX); - /* 48 */ load._10 = FX_MUL(-dir.y, dot); - /* 40 */ load._20 = 0; - /* 30 */ load._30 = trs.x; - /* 50 */ load._01 = FX_MUL(dir.y, sclX); - /* 3C */ load._11 = FX_MUL(dir.x, dot); - /* 38 */ load._21 = 0; - /* 2C */ load._31 = trs.y; - /* 4C */ load._02 = 0; - /* 44 */ load._12 = 0; - /* 34 */ load._22 = FX32_ONE; - /* 28 */ load._32 = trs.z; - - reg_G3_MTX_IDENTITY = 0; - - UnkSPLStruct9 *resBase = mgr->unk_40.unk_00->p_res->unk_00; - fx32 px = resBase->unk_04.x, pz = resBase->unk_04.z, py = resBase->unk_04.y; - reg_G3_MTX_TRANS = px; - reg_G3_MTX_TRANS = py; - reg_G3_MTX_TRANS = pz; - - G3_MultMtx43(&load); - } - - GXRgb colA = ptcl->unk_36; - GXRgb colB = mgr->unk_40.unk_00->unk_E2; - reg_G3_COLOR = GX_RGB( - GX_RGB_R_(colA) * GX_RGB_R_(colB) >> 5, - GX_RGB_G_(colA) * GX_RGB_G_(colB) >> 15, - GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25 - ); - - SPLEmitter *emtr = mgr->unk_40.unk_00; - sub_020A0500(emtr->unk_E8, emtr->unk_EA, emtr->p_res->unk_00->unk_54, emtr->p_res->unk_00->unk_56); -} - -void sub_0209FAB8(SPLManager *mgr, SPLParticle *ptcl) -{ - fx32 aspect; - const MtxFx43 *cmr; - VecFx32 trs; - fx32 sclX, sclY; - MtxFx43 load; - fx32 sin; - - cmr = mgr->unk_40.unk_04; - aspect = mgr->unk_40.unk_00->p_res->unk_00->unk_30; - - u32 polygonID = ptcl->unk_2E.unk_01_2 << REG_G3_POLYGON_ATTR_ID_SHIFT; - u32 cullMode = GX_CULL_NONE << REG_G3_POLYGON_ATTR_BK_SHIFT; - fx32 alpha = (fx32)(ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1)) >> 5; - - reg_G3_POLYGON_ATTR = (u32)( - (0 << REG_G3_POLYGON_ATTR_LE_SHIFT) - | (GX_POLYGONMODE_MODULATE << REG_G3_POLYGON_ATTR_PM_SHIFT) - | (cullMode) - | (mgr->unk_3C) - | (polygonID) - | (alpha << REG_G3_POLYGON_ATTR_ALPHA_SHIFT) - ); - - u32 polygonAttr = reg_G3_POLYGON_ATTR; - - if (alpha == 0) { - return; - } - - sclY = ptcl->unk_30; - sclX = FX_MUL(sclY, aspect); - - switch (mgr->unk_40.unk_00->p_res->unk_00->unk_48.unk_07_4) { - case 0: - sclX = FX_MUL(sclX, ptcl->unk_34); - sclY = FX_MUL(sclY, ptcl->unk_34); - break; - - case 1: - sclX = FX_MUL(sclX, ptcl->unk_34); - break; - - case 2: - sclY = FX_MUL(sclY, ptcl->unk_34); - break; - } - - if (!mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_7) { - trs.x = ptcl->unk_08.x + ptcl->unk_38.x; - trs.y = ptcl->unk_08.y + ptcl->unk_38.y; - trs.z = ptcl->unk_08.z + ptcl->unk_38.z; - MTX_MultVec43(&trs, cmr, &trs); - - sin = FX_SinIdx(ptcl->unk_20); - fx32 cos = FX_CosIdx(ptcl->unk_20); - load._00 = FX_MUL(cos, sclX); - load._01 = FX_MUL(sin, sclX); - load._02 = 0; - load._10 = FX_MUL(-sin, sclY); - load._11 = FX_MUL(cos, sclY); - load._12 = 0; - load._20 = 0; - load._21 = 0; - load._22 = FX32_ONE; - load._30 = trs.x; - load._31 = trs.y; - load._32 = trs.z; - - reg_G3_MTX_IDENTITY = 0; - - G3_MultMtx43(&load); - } else { - trs.x = ptcl->unk_08.x + ptcl->unk_38.x - mgr->unk_40.unk_00->p_res->unk_00->unk_04.x; - trs.y = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; - trs.z = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; - MTX_MultVec43(&trs, cmr, &trs); - - sin = FX_SinIdx(ptcl->unk_20); - fx32 cos = FX_CosIdx(ptcl->unk_20); - load._00 = FX_MUL(cos, sclX); - load._01 = FX_MUL(sin, sclX); - load._02 = 0; - load._10 = FX_MUL(-sin, sclY); - load._11 = FX_MUL(cos, sclY); - load._12 = 0; - load._20 = 0; - load._21 = 0; - load._22 = FX32_ONE; - load._30 = trs.x; - load._31 = trs.y; - load._32 = trs.z; - - reg_G3_MTX_IDENTITY = 0; - - UnkSPLStruct9 *resBase = mgr->unk_40.unk_00->p_res->unk_00; - fx32 px = resBase->unk_04.x, pz = resBase->unk_04.z, py = resBase->unk_04.y; - reg_G3_MTX_TRANS = px; - reg_G3_MTX_TRANS = py; - reg_G3_MTX_TRANS = pz; - - G3_MultMtx43(&load); - } - - GXRgb colA = ptcl->unk_36; - GXRgb colB = mgr->unk_40.unk_00->unk_E2; - reg_G3_COLOR = GX_RGB( - GX_RGB_R_(colA) * GX_RGB_R_(colB) >> 5, - GX_RGB_G_(colA) * GX_RGB_G_(colB) >> 15, - GX_RGB_B_(colA) * GX_RGB_B_(colB) >> 25 - ); - - SPLEmitter *emtr = mgr->unk_40.unk_00; - sub_020A0500(emtr->unk_EC, emtr->unk_EE, 0, 0); -} - -void sub_0209FF0C(SPLManager *mgr, SPLParticle *ptcl) -{ - fx32 aspect; - const MtxFx43 *cmr; - VecFx32 trs; - fx32 sclX, sclY; - MtxFx43 load; - fx32 sin; - fx16 animScale; - GXRgb ptclCol, emtrCol; - u8 scaleAnimDirect; - - SPLEmitter *emtr = mgr->unk_40.unk_00; - UnkSPLStruct9 *resBase = emtr->p_res->unk_00; - - cmr = mgr->unk_40.unk_04; - aspect = mgr->unk_40.unk_00->p_res->unk_00->unk_30; - animScale = ptcl->unk_34; - - ptclCol = ptcl->unk_36; - emtrCol = emtr->unk_E2; - - scaleAnimDirect = resBase->unk_48.unk_07_4; - - fx32 alpha = ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1) >> 5; - - G3_PolygonAttr( - GX_LIGHTMASK_NONE, - GX_POLYGONMODE_MODULATE, - GX_CULL_NONE, - ptcl->unk_2E.unk_01_2, - alpha, - mgr->unk_3C - ); - - reg_G3_POLYGON_ATTR; - - if (alpha == 0) { - return; - } - - sclY = ptcl->unk_30; - sclX = FX_MUL(sclY, aspect); - - if (scaleAnimDirect == 0) { - sclX = FX_MUL(sclX, animScale); - sclY = FX_MUL(sclY, animScale); - } else if (scaleAnimDirect == 1) { - sclX = FX_MUL(sclX, animScale); - } else { - sclY = FX_MUL(sclY, animScale); - } - - if (!mgr->unk_40.unk_00->p_res->unk_00->unk_00.unk_06_7) { - trs.x = ptcl->unk_08.x + ptcl->unk_38.x; - trs.y = ptcl->unk_08.y + ptcl->unk_38.y; - trs.z = ptcl->unk_08.z + ptcl->unk_38.z; - MTX_MultVec43(&trs, cmr, &trs); - - sin = FX_SinIdx(ptcl->unk_20); - fx32 cos = FX_CosIdx(ptcl->unk_20); - load._00 = FX_MUL(cos, sclX); - load._01 = FX_MUL(sin, sclX); - load._02 = 0; - load._10 = FX_MUL(-sin, sclY); - load._11 = FX_MUL(cos, sclY); - load._12 = 0; - load._20 = 0; - load._21 = 0; - load._22 = FX32_ONE; - load._30 = trs.x; - load._31 = trs.y; - load._32 = trs.z; - - G3_Identity(); - G3_MultMtx43(&load); - } else { - trs.x = ptcl->unk_08.x + ptcl->unk_38.x - mgr->unk_40.unk_00->p_res->unk_00->unk_04.x; - trs.y = ptcl->unk_08.y + ptcl->unk_38.y - mgr->unk_40.unk_00->p_res->unk_00->unk_04.y; - trs.z = ptcl->unk_08.z + ptcl->unk_38.z - mgr->unk_40.unk_00->p_res->unk_00->unk_04.z; - MTX_MultVec43(&trs, cmr, &trs); - - sin = FX_SinIdx(ptcl->unk_20); - fx32 cos = FX_CosIdx(ptcl->unk_20); - load._00 = FX_MUL(cos, sclX); - load._01 = FX_MUL(sin, sclX); - load._02 = 0; - load._10 = FX_MUL(-sin, sclY); - load._11 = FX_MUL(cos, sclY); - load._12 = 0; - load._20 = 0; - load._21 = 0; - load._22 = FX32_ONE; - load._30 = trs.x; - load._31 = trs.y; - load._32 = trs.z; - - G3_Identity(); - - UnkSPLStruct9 *resBase = mgr->unk_40.unk_00->p_res->unk_00; - G3_Translate(resBase->unk_04.x, resBase->unk_04.y, resBase->unk_04.z); - G3_MultMtx43(&load); - } - - G3_Color(GX_RGB( - GX_RGB_R_(ptclCol) * GX_RGB_R_(emtrCol) >> 5, - GX_RGB_G_(ptclCol) * GX_RGB_G_(emtrCol) >> 15, - GX_RGB_B_(ptclCol) * GX_RGB_B_(emtrCol) >> 25 - )); - - emtr = mgr->unk_40.unk_00; - sub_020A0500(emtr->unk_E8, emtr->unk_EA, emtr->p_res->unk_00->unk_54, emtr->p_res->unk_00->unk_56); -} - -void sub_020A0358(fx32 sin, fx32 cos, MtxFx43 *mat) -{ - mat->_00 = cos; - mat->_10 = 0; - mat->_20 = sin; - mat->_30 = 0; - mat->_01 = 0; - mat->_11 = FX32_ONE; - mat->_21 = 0; - mat->_31 = 0; - mat->_02 = -sin; - mat->_12 = 0; - mat->_22 = cos; - mat->_32 = 0; -} - -void sub_020A0398(fx32 sin, fx32 cos, MtxFx43 *mat) -{ - fx32 C, Sm, Sp; - - C = FX_MUL(FX32_ONE - cos, FX32_CONST(1 / 3.0)); - Sm = C + FX_MUL(sin, FX32_SQRT1_3); - Sp = C - FX_MUL(sin, FX32_SQRT1_3); - C += cos; - - mat->_00 = C; - mat->_10 = Sm; - mat->_20 = Sp; - mat->_30 = 0; - mat->_01 = Sp; - mat->_11 = C; - mat->_21 = Sm; - mat->_31 = 0; - mat->_02 = Sm; - mat->_12 = Sp; - mat->_22 = C; - mat->_32 = 0; -} - -void sub_020A0444(fx16 s, fx16 t, fx16 offsetX, fx16 offsetZ) -{ - G3_Begin(GX_BEGIN_QUADS); - - G3_TexCoord(0, 0); - G3_Vtx10(offsetX - FX32_ONE, 0, offsetZ + FX32_ONE); - - G3_TexCoord(s, 0); - G3_Vtx10(offsetX + FX32_ONE, 0, offsetZ + FX32_ONE); - - G3_TexCoord(s, t); - G3_Vtx10(offsetX + FX32_ONE, 0, offsetZ - FX32_ONE); - - G3_TexCoord(0, t); - G3_Vtx10(offsetX - FX32_ONE, 0, offsetZ - FX32_ONE); - - G3_End(); -} - -void sub_020A0500(fx16 s, fx16 t, fx16 offsetX, fx16 offsetY) -{ - G3_Begin(GX_BEGIN_QUADS); - - G3_TexCoord(0, 0); - G3_Vtx10(offsetX - FX32_ONE, offsetY + FX32_ONE, 0); - - G3_TexCoord(s, 0); - G3_Vtx10(offsetX + FX32_ONE, offsetY + FX32_ONE, 0); - - G3_TexCoord(s, t); - G3_Vtx10(offsetX + FX32_ONE, offsetY - FX32_ONE, 0); - - G3_TexCoord(0, t); - G3_Vtx10(offsetX - FX32_ONE, offsetY - FX32_ONE, 0); - - G3_End(); + DrawPlaneFunc drawPlane = Unk_02100DA0[emtr->p_res->unk_14->unk_00.unk_03_3]; + drawPlane(emtr->unk_EC, emtr->unk_EE, 0, 0); } diff --git a/lib/spl/src/unk_020A05BC.c b/lib/spl/src/unk_020A05BC.c index 24c768a5f4..cf2763e1b9 100644 --- a/lib/spl/src/unk_020A05BC.c +++ b/lib/spl/src/unk_020A05BC.c @@ -4,324 +4,6 @@ #include "spl.h" -void sub_020A05BC(SPLParticle *ptcl, SPLEmitter *emtr, SPLList *list) -{ - SPLParticle *chld; - fx32 velBase, velRand; - u32 rng; - int i; - UnkSPLStruct14 *chldRes = emtr->p_res->unk_14; - fx32 vel = FX_MUL((fx32)(chldRes->unk_08.unk_00_0 << FX32_SHIFT), FX32_CONST(1 / 256.0f)); - - for (i = 0; i < chldRes->unk_0C.unk_00_0; i++) { - chld = (SPLParticle *)sub_020A22B8(list); - if (chld == NULL) { - return; - } - sub_020A2304((SPLList *)&emtr->unk_4C, (SPLNode *)chld); - - chld->unk_08 = ptcl->unk_08; - - velBase = FX_MUL(ptcl->unk_14.x, vel); - velRand = (fx32)(chldRes->unk_02 * rng_next(0x17) - chldRes->unk_02 * 256) >> 8; - chld->unk_14.x = velBase + velRand; - - velBase = FX_MUL(ptcl->unk_14.y, vel); - velRand = (fx32)(chldRes->unk_02 * rng_next(0x17) - chldRes->unk_02 * 256) >> 8; - chld->unk_14.y = velBase + velRand; - - velBase = FX_MUL(ptcl->unk_14.z, vel); - velRand = (fx32)(chldRes->unk_02 * rng_next(0x17) - chldRes->unk_02 * 256) >> 8; - chld->unk_14.z = velBase + velRand; - - chld->unk_38 = ptcl->unk_38; - - // `unk_08.unk_00_0` and `unk_08.unk_01_0` in `UnkSPLStruct14` - // could just be `u8 unk_08;` and `u8 unk_09;` - // instead of an inner struct - int idk = ptcl->unk_30 * ptcl->unk_34 >> FX32_SHIFT; - chld->unk_30 = idk * (chldRes->unk_08.unk_01_0 + 1) >> 6; - - chld->unk_34 = FX32_ONE; - - if (chldRes->unk_00.unk_02_6) { - chld->unk_36 = chldRes->unk_0A; - } else { - chld->unk_36 = ptcl->unk_36; - } - - chld->unk_2E.unk_00_0 = (ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1)) >> 5; - chld->unk_2E.unk_00_5 = 31; - - switch (chldRes->unk_00.unk_02_3) { - case 0: - chld->unk_20 = 0; - chld->unk_22 = 0; - break; - case 1: - chld->unk_20 = ptcl->unk_20; - chld->unk_22 = 0; - break; - case 2: - chld->unk_20 = ptcl->unk_20; - chld->unk_22 = ptcl->unk_22; - break; - } - - chld->unk_24 = chldRes->unk_06; - chld->unk_26 = 0; - chld->unk_2C.unk_00 = chldRes->unk_0C.unk_03_0; - - chld->unk_28 = 0xFFFF / (ptcl->unk_24 / 2); - chld->unk_2A = 0xFFFF / ptcl->unk_24; - chld->unk_2C.unk_01 = 0; - - } -} - -void sub_020A08DC(SPLEmitter *emtr, SPLList *list) -{ - UnkSPLStruct4 *res; - UnkSPLStruct9 *resBase; - //fx32 genNum; - int i, curGenNum; - SPLParticle *ptcl; - - fx32 magPos; - fx32 magAxis; - res = emtr->p_res; - resBase = res->unk_00; - - int temp = emtr->unk_C8 + FX32_CAST(emtr->unk_BE); - curGenNum = temp >> FX32_SHIFT; - emtr->unk_BE = (temp & FX32_DEC_MASK); - - u32 initType = resBase->unk_00.unk_04_0; - if (initType == 2 || initType == 3 || (initType - 5 <= 4)) { - sub_020A1768(emtr); - } - - i = 0; - if (i < curGenNum) { - fx32 genNum = 0; - do { - ptcl = (SPLParticle *)sub_020A22B8(list); - - if (ptcl == NULL) { - return; - } - - sub_020A2304((SPLList *)&emtr->unk_08, (SPLNode *)ptcl); - - switch (resBase->unk_00.unk_04_0) { - case 0: - ptcl->unk_08.x = ptcl->unk_08.y = ptcl->unk_08.z = 0; - break; - - case 1: - sub_020A23B0(&ptcl->unk_08); - ptcl->unk_08.x = FX_MUL(ptcl->unk_08.x, emtr->unk_CC); - ptcl->unk_08.y = FX_MUL(ptcl->unk_08.y, emtr->unk_CC); - ptcl->unk_08.z = FX_MUL(ptcl->unk_08.z, emtr->unk_CC); - break; - - case 2: - { - VecFx32 pos; - sub_020A2354(&pos); - pos.x = FX_MUL(pos.x, emtr->unk_CC); - pos.y = FX_MUL(pos.y, emtr->unk_CC); - pos.z = 0; - sub_020A1608(&ptcl->unk_08, &pos, emtr); - } - break; - - case 3: - { - VecFx32 pos; - int idx = genNum / curGenNum; - genNum += 0x10000; - fx32 sin = FX_SinIdx(idx); - fx32 cos = FX_CosIdx(idx); - pos.x = FX_MUL(sin, emtr->unk_CC); - pos.y = FX_MUL(cos, emtr->unk_CC); - pos.z = 0; - sub_020A1608(&ptcl->unk_08, &pos, emtr); - } - break; - - case 4: - sub_020A23B0(&ptcl->unk_08); - ptcl->unk_08.x = FX_MUL(FX_MUL(ptcl->unk_08.x, emtr->unk_CC), rng_next(0x17) * FX32_ONE - 0x100000 >> 8); - ptcl->unk_08.y = FX_MUL(FX_MUL(ptcl->unk_08.y, emtr->unk_CC), rng_next(0x17) * FX32_ONE - 0x100000 >> 8); - ptcl->unk_08.z = FX_MUL(FX_MUL(ptcl->unk_08.z, emtr->unk_CC), rng_next(0x17) * FX32_ONE - 0x100000 >> 8); - break; - - case 5: - { - VecFx32 pos; - sub_020A2354(&pos); - pos.x = FX_MUL(FX_MUL(pos.x, emtr->unk_CC), (fx32)rng_next(0x17) * FX32_ONE - 0x100000 >> 8); - pos.y = FX_MUL(FX_MUL(pos.y, emtr->unk_CC), (fx32)rng_next(0x17) * FX32_ONE - 0x100000 >> 8); - sub_020A1608(&ptcl->unk_08, &pos, emtr); - } - break; - - case 8: - { - VecFx32 pos; - VecFx16 tmpUnitVec; - sub_020A23B0(&ptcl->unk_08); - VEC_Fx16CrossProduct(&emtr->unk_F4, &emtr->unk_FA, &tmpUnitVec); - pos.x = tmpUnitVec.x; - pos.y = tmpUnitVec.y; - pos.z = tmpUnitVec.z; - if (VEC_DotProduct(&pos, &ptcl->unk_08) <= 0) { - ptcl->unk_08.x = -ptcl->unk_08.x; - ptcl->unk_08.y = -ptcl->unk_08.y; - ptcl->unk_08.z = -ptcl->unk_08.z; - } - - ptcl->unk_08.x = FX_MUL(ptcl->unk_08.x, emtr->unk_CC); - ptcl->unk_08.y = FX_MUL(ptcl->unk_08.y, emtr->unk_CC); - ptcl->unk_08.z = FX_MUL(ptcl->unk_08.z, emtr->unk_CC); - } - break; - - case 9: - { - VecFx32 pos; - VecFx16 tmpUnitVec; - sub_020A23B0(&ptcl->unk_08); - VEC_Fx16CrossProduct(&emtr->unk_F4, &emtr->unk_FA, &tmpUnitVec); - pos.x = tmpUnitVec.x; - pos.y = tmpUnitVec.y; - pos.z = tmpUnitVec.z; - if (VEC_DotProduct(&pos, &ptcl->unk_08) < 0) { - ptcl->unk_08.x = -ptcl->unk_08.x; - ptcl->unk_08.y = -ptcl->unk_08.y; - ptcl->unk_08.z = -ptcl->unk_08.z; - } - - ptcl->unk_08.x = FX_MUL(FX_MUL(ptcl->unk_08.x, emtr->unk_CC), ((fx32)rng_next(0x17) * FX32_ONE - 0x100000 >> 9) + 0x800); - ptcl->unk_08.y = FX_MUL(FX_MUL(ptcl->unk_08.y, emtr->unk_CC), ((fx32)rng_next(0x17) * FX32_ONE - 0x100000 >> 9) + 0x800); - ptcl->unk_08.z = FX_MUL(FX_MUL(ptcl->unk_08.z, emtr->unk_CC), ((fx32)rng_next(0x17) * FX32_ONE - 0x100000 >> 9) + 0x800); - } - break; - - case 6: - { - VecFx32 pos; - sub_020A2354(&ptcl->unk_14); - pos.x = FX_MUL(ptcl->unk_14.x, emtr->unk_CC); - pos.y = FX_MUL(ptcl->unk_14.y, emtr->unk_CC); - pos.z = (emtr->unk_D0 * rng_next(0x17) - emtr->unk_D0 * 256) >> 8; - sub_020A1608(&ptcl->unk_08, &pos, emtr); - } - break; - - case 7: - { - VecFx32 pos; - sub_020A2354(&ptcl->unk_14); - pos.x = FX_MUL(FX_MUL(ptcl->unk_14.x, emtr->unk_CC), (fx32)rng_next(0x17) * FX32_ONE - 0x100000 >> 8); - pos.y = FX_MUL(FX_MUL(ptcl->unk_14.y, emtr->unk_CC), (fx32)rng_next(0x17) * FX32_ONE - 0x100000 >> 8); - pos.z = (emtr->unk_D0 * (fx32)rng_next(0x17) - emtr->unk_D0 * 256) >> 8; - sub_020A1608(&ptcl->unk_08, &pos, emtr); - } - break; - } - - magPos = emtr->unk_D4 * ((resBase->unk_44.unk_02_0 + 0xFF) - ((fx32)(resBase->unk_44.unk_02_0 * rng_next(0x18)) >> 7)) >> 8; - magAxis = emtr->unk_D8 * ((resBase->unk_44.unk_02_0 + 0xFF) - ((fx32)(resBase->unk_44.unk_02_0 * rng_next(0x18)) >> 7)) >> 8; - - VecFx32 posNorm; - if (resBase->unk_00.unk_04_0 == 6) { - VecFx32 tmp; - tmp.x = FX_MUL(ptcl->unk_14.x, emtr->unk_F4.x) + FX_MUL(ptcl->unk_14.y, emtr->unk_FA.x); - tmp.y = FX_MUL(ptcl->unk_14.x, emtr->unk_F4.y) + FX_MUL(ptcl->unk_14.y, emtr->unk_FA.y); - tmp.z = FX_MUL(ptcl->unk_14.x, emtr->unk_F4.z) + FX_MUL(ptcl->unk_14.y, emtr->unk_FA.z); - - VEC_Normalize(&tmp, &posNorm); - } else if (ptcl->unk_08.x == 0 && ptcl->unk_08.y == 0 && ptcl->unk_08.z == 0) { - sub_020A23B0(&posNorm); - } else { - VEC_Normalize(&ptcl->unk_08, &posNorm); - } - - ptcl->unk_14.x = FX_MUL(posNorm.x, magPos) + FX_MUL(emtr->unk_C0.x, magAxis) + emtr->unk_B0.x; - ptcl->unk_14.y = FX_MUL(posNorm.y, magPos) + FX_MUL(emtr->unk_C0.y, magAxis) + emtr->unk_B0.y; - ptcl->unk_14.z = FX_MUL(posNorm.z, magPos) + FX_MUL(emtr->unk_C0.z, magAxis) + emtr->unk_B0.z; - - ptcl->unk_38 = emtr->unk_98; - - ptcl->unk_30 = emtr->unk_DC * ((resBase->unk_44.unk_00_0 + 0xFF) - ((resBase->unk_44.unk_00_0 * (fx32)rng_next(0x18)) >> 7)) >> 8; - ptcl->unk_34 = FX32_ONE; - - if (resBase->unk_00.unk_05_1 && res->unk_08->unk_08.unk_00_0) { - u16 clr[3]; - u32 indxx = rng_next(0x14); - clr[0] = res->unk_08->unk_00; - clr[1] = resBase->unk_22; - clr[2] = res->unk_08->unk_02; - ptcl->unk_36 = clr[indxx % 3]; - } else { - ptcl->unk_36 = resBase->unk_22; - } - - ptcl->unk_2E.unk_00_0 = emtr->unk_F0.unk_01_0; - ptcl->unk_2E.unk_00_5 = 31; - - if (resBase->unk_00.unk_05_5) { - ptcl->unk_20 = rng_next(0); - } else { - ptcl->unk_20 = emtr->unk_C6; - } - - if (resBase->unk_00.unk_05_4) { - ptcl->unk_22 = ((resBase->unk_36 - resBase->unk_34) * (u32)rng_next(0x14) + (fx32)resBase->unk_34 * FX32_ONE) >> FX32_SHIFT; - } else { - ptcl->unk_22 = 0; - } - - ptcl->unk_24 = (emtr->unk_E0 * (0xFF - ((resBase->unk_44.unk_01_0 * rng_next(0x18) >> 8))) >> 8) + 1; - ptcl->unk_26 = 0; - - if (resBase->unk_00.unk_05_3 && res->unk_10->unk_08.unk_02_0) { - ptcl->unk_2C.unk_00 = res->unk_10->unk_00[rng_next(0x14) % res->unk_10->unk_08.unk_00_0]; - } else if (resBase->unk_00.unk_05_3 && !res->unk_10->unk_08.unk_02_0) { - ptcl->unk_2C.unk_00 = res->unk_10->unk_00[0]; - } else { - ptcl->unk_2C.unk_00 = resBase->unk_48.unk_03_0; - } - - ptcl->unk_28 = 0xFFFF / res->unk_00->unk_48.unk_04_0; - ptcl->unk_2A = 0xFFFF / ptcl->unk_24; - - ptcl->unk_2C.unk_01 = 0; - - if (resBase->unk_00.unk_06_4) { - ptcl->unk_2C.unk_01 = (u8)rng_next(0x18); - } - i++; - } while (i < curGenNum); - } - for (i = 0; i < curGenNum; i++) { - - } -} - -void sub_020A1608(VecFx32 *ptclPos, VecFx32 *pos, SPLEmitter *emtr) -{ - VecFx16 vec; - VEC_Fx16CrossProduct(&emtr->unk_F4, &emtr->unk_FA, &vec); - VEC_Fx16Normalize(&vec, &vec); - - ptclPos->x = FX_MUL(pos->x, emtr->unk_F4.x) + FX_MUL(pos->y, emtr->unk_FA.x) + FX_MUL(pos->z, vec.x); - ptclPos->y = FX_MUL(pos->x, emtr->unk_F4.y) + FX_MUL(pos->y, emtr->unk_FA.y) + FX_MUL(pos->z, vec.y); - ptclPos->z = FX_MUL(pos->x, emtr->unk_F4.z) + FX_MUL(pos->y, emtr->unk_FA.z) + FX_MUL(pos->z, vec.z); -} - VecFx16 Unk_02100DB0 = { 0, 0, FX16_ONE }; void sub_020A1768(SPLEmitter *emtr) @@ -329,7 +11,7 @@ void sub_020A1768(SPLEmitter *emtr) VecFx16 vec, axis; vec = Unk_02100DB0; - + switch (emtr->p_res->unk_00->unk_00.unk_04_6) { case 2: axis.x = FX32_ONE; @@ -369,3 +51,303 @@ void sub_020A1768(SPLEmitter *emtr) VEC_Fx16Normalize(&emtr->unk_F4, &emtr->unk_F4); VEC_Fx16Normalize(&emtr->unk_FA, &emtr->unk_FA); } + +void sub_020A1608(VecFx32 *ptclPos, VecFx32 *pos, SPLEmitter *emtr) +{ + VecFx16 vec; + VEC_Fx16CrossProduct(&emtr->unk_F4, &emtr->unk_FA, &vec); + VEC_Fx16Normalize(&vec, &vec); + + ptclPos->x = FX_MUL(pos->x, emtr->unk_F4.x) + FX_MUL(pos->y, emtr->unk_FA.x) + FX_MUL(pos->z, vec.x); + ptclPos->y = FX_MUL(pos->x, emtr->unk_F4.y) + FX_MUL(pos->y, emtr->unk_FA.y) + FX_MUL(pos->z, vec.y); + ptclPos->z = FX_MUL(pos->x, emtr->unk_F4.z) + FX_MUL(pos->y, emtr->unk_FA.z) + FX_MUL(pos->z, vec.z); +} + +void sub_020A08DC(SPLEmitter *emtr, SPLList *list) +{ + UnkSPLStruct4 *res; + UnkSPLStruct9 *resBase; + // fx32 genNum; + int i, curGenNum; + SPLParticle *ptcl; + + fx32 magPos; + fx32 magAxis; + res = emtr->p_res; + resBase = res->unk_00; + + int temp = emtr->unk_C8 + FX32_CAST(emtr->unk_BE); + curGenNum = temp >> FX32_SHIFT; + emtr->unk_BE = (temp & FX32_DEC_MASK); + + u32 initType = resBase->unk_00.unk_04_0; + if (initType == 2 || initType == 3 || (initType - 5 <= 4)) { + sub_020A1768(emtr); + } + + i = 0; + if (i < curGenNum) { + fx32 genNum = 0; + do { + ptcl = (SPLParticle *)sub_020A22B8(list); + + if (ptcl == NULL) { + return; + } + + sub_020A2304((SPLList *)&emtr->unk_08, (SPLNode *)ptcl); + + switch (resBase->unk_00.unk_04_0) { + case 0: + ptcl->unk_08.x = ptcl->unk_08.y = ptcl->unk_08.z = 0; + break; + + case 1: + sub_020A23B0(&ptcl->unk_08); + ptcl->unk_08.x = FX_MUL(ptcl->unk_08.x, emtr->unk_CC); + ptcl->unk_08.y = FX_MUL(ptcl->unk_08.y, emtr->unk_CC); + ptcl->unk_08.z = FX_MUL(ptcl->unk_08.z, emtr->unk_CC); + break; + + case 2: { + VecFx32 pos; + sub_020A2354(&pos); + pos.x = FX_MUL(pos.x, emtr->unk_CC); + pos.y = FX_MUL(pos.y, emtr->unk_CC); + pos.z = 0; + sub_020A1608(&ptcl->unk_08, &pos, emtr); + } break; + + case 3: { + VecFx32 pos; + int idx = genNum / curGenNum; + genNum += 0x10000; + fx32 sin = FX_SinIdx(idx); + fx32 cos = FX_CosIdx(idx); + pos.x = FX_MUL(sin, emtr->unk_CC); + pos.y = FX_MUL(cos, emtr->unk_CC); + pos.z = 0; + sub_020A1608(&ptcl->unk_08, &pos, emtr); + } break; + + case 4: + sub_020A23B0(&ptcl->unk_08); + ptcl->unk_08.x = FX_MUL(FX_MUL(ptcl->unk_08.x, emtr->unk_CC), (rng_next_s32(0x17) * FX32_ONE - 0x100000) >> 8); + ptcl->unk_08.y = FX_MUL(FX_MUL(ptcl->unk_08.y, emtr->unk_CC), (rng_next_s32(0x17) * FX32_ONE - 0x100000) >> 8); + ptcl->unk_08.z = FX_MUL(FX_MUL(ptcl->unk_08.z, emtr->unk_CC), (rng_next_s32(0x17) * FX32_ONE - 0x100000) >> 8); + break; + + case 5: { + VecFx32 pos; + sub_020A2354(&pos); + pos.x = FX_MUL(FX_MUL(pos.x, emtr->unk_CC), ((fx32)rng_next_s32(0x17) * FX32_ONE - 0x100000) >> 8); + pos.y = FX_MUL(FX_MUL(pos.y, emtr->unk_CC), ((fx32)rng_next_s32(0x17) * FX32_ONE - 0x100000) >> 8); + sub_020A1608(&ptcl->unk_08, &pos, emtr); + } break; + + case 8: { + VecFx32 pos; + VecFx16 tmpUnitVec; + sub_020A23B0(&ptcl->unk_08); + VEC_Fx16CrossProduct(&emtr->unk_F4, &emtr->unk_FA, &tmpUnitVec); + pos.x = tmpUnitVec.x; + pos.y = tmpUnitVec.y; + pos.z = tmpUnitVec.z; + if (VEC_DotProduct(&pos, &ptcl->unk_08) <= 0) { + ptcl->unk_08.x = -ptcl->unk_08.x; + ptcl->unk_08.y = -ptcl->unk_08.y; + ptcl->unk_08.z = -ptcl->unk_08.z; + } + + ptcl->unk_08.x = FX_MUL(ptcl->unk_08.x, emtr->unk_CC); + ptcl->unk_08.y = FX_MUL(ptcl->unk_08.y, emtr->unk_CC); + ptcl->unk_08.z = FX_MUL(ptcl->unk_08.z, emtr->unk_CC); + } break; + + case 9: { + VecFx32 pos; + VecFx16 tmpUnitVec; + sub_020A23B0(&ptcl->unk_08); + VEC_Fx16CrossProduct(&emtr->unk_F4, &emtr->unk_FA, &tmpUnitVec); + pos.x = tmpUnitVec.x; + pos.y = tmpUnitVec.y; + pos.z = tmpUnitVec.z; + if (VEC_DotProduct(&pos, &ptcl->unk_08) < 0) { + ptcl->unk_08.x = -ptcl->unk_08.x; + ptcl->unk_08.y = -ptcl->unk_08.y; + ptcl->unk_08.z = -ptcl->unk_08.z; + } + + ptcl->unk_08.x = FX_MUL(FX_MUL(ptcl->unk_08.x, emtr->unk_CC), (((fx32)rng_next_s32(0x17) * FX32_ONE - 0x100000) >> 9) + 0x800); + ptcl->unk_08.y = FX_MUL(FX_MUL(ptcl->unk_08.y, emtr->unk_CC), (((fx32)rng_next_s32(0x17) * FX32_ONE - 0x100000) >> 9) + 0x800); + ptcl->unk_08.z = FX_MUL(FX_MUL(ptcl->unk_08.z, emtr->unk_CC), (((fx32)rng_next_s32(0x17) * FX32_ONE - 0x100000) >> 9) + 0x800); + } break; + + case 6: { + VecFx32 pos; + sub_020A2354(&ptcl->unk_14); + pos.x = FX_MUL(ptcl->unk_14.x, emtr->unk_CC); + pos.y = FX_MUL(ptcl->unk_14.y, emtr->unk_CC); + pos.z = (emtr->unk_D0 * rng_next_s32(0x17) - emtr->unk_D0 * 256) >> 8; + sub_020A1608(&ptcl->unk_08, &pos, emtr); + } break; + + case 7: { + VecFx32 pos; + sub_020A2354(&ptcl->unk_14); + pos.x = FX_MUL(FX_MUL(ptcl->unk_14.x, emtr->unk_CC), ((fx32)rng_next_s32(0x17) * FX32_ONE - 0x100000) >> 8); + pos.y = FX_MUL(FX_MUL(ptcl->unk_14.y, emtr->unk_CC), ((fx32)rng_next_s32(0x17) * FX32_ONE - 0x100000) >> 8); + pos.z = (emtr->unk_D0 * (fx32)rng_next_s32(0x17) - emtr->unk_D0 * 256) >> 8; + sub_020A1608(&ptcl->unk_08, &pos, emtr); + } break; + } + + magPos = emtr->unk_D4 * ((resBase->unk_44.unk_02_0 + 0xFF) - ((fx32)(resBase->unk_44.unk_02_0 * rng_next_s32(0x18)) >> 7)) >> 8; + magAxis = emtr->unk_D8 * ((resBase->unk_44.unk_02_0 + 0xFF) - ((fx32)(resBase->unk_44.unk_02_0 * rng_next_s32(0x18)) >> 7)) >> 8; + + VecFx32 posNorm; + if (resBase->unk_00.unk_04_0 == 6) { + VecFx32 tmp; + tmp.x = FX_MUL(ptcl->unk_14.x, emtr->unk_F4.x) + FX_MUL(ptcl->unk_14.y, emtr->unk_FA.x); + tmp.y = FX_MUL(ptcl->unk_14.x, emtr->unk_F4.y) + FX_MUL(ptcl->unk_14.y, emtr->unk_FA.y); + tmp.z = FX_MUL(ptcl->unk_14.x, emtr->unk_F4.z) + FX_MUL(ptcl->unk_14.y, emtr->unk_FA.z); + + VEC_Normalize(&tmp, &posNorm); + } else if (ptcl->unk_08.x == 0 && ptcl->unk_08.y == 0 && ptcl->unk_08.z == 0) { + sub_020A23B0(&posNorm); + } else { + VEC_Normalize(&ptcl->unk_08, &posNorm); + } + + ptcl->unk_14.x = FX_MUL(posNorm.x, magPos) + FX_MUL(emtr->unk_C0.x, magAxis) + emtr->unk_B0.x; + ptcl->unk_14.y = FX_MUL(posNorm.y, magPos) + FX_MUL(emtr->unk_C0.y, magAxis) + emtr->unk_B0.y; + ptcl->unk_14.z = FX_MUL(posNorm.z, magPos) + FX_MUL(emtr->unk_C0.z, magAxis) + emtr->unk_B0.z; + + ptcl->unk_38 = emtr->unk_98; + + ptcl->unk_30 = emtr->unk_DC * ((resBase->unk_44.unk_00_0 + 0xFF) - ((resBase->unk_44.unk_00_0 * (fx32)rng_next_s32(0x18)) >> 7)) >> 8; + ptcl->unk_34 = FX32_ONE; + + if (resBase->unk_00.unk_05_1 && res->unk_08->unk_08.unk_00_0) { + u16 clr[3]; + u32 indxx = rng_next_s32(0x14); + clr[0] = res->unk_08->unk_00; + clr[1] = resBase->unk_22; + clr[2] = res->unk_08->unk_02; + ptcl->unk_36 = clr[indxx % 3]; + } else { + ptcl->unk_36 = resBase->unk_22; + } + + ptcl->unk_2E.unk_00_0 = emtr->unk_F0.unk_01_0; + ptcl->unk_2E.unk_00_5 = 31; + + if (resBase->unk_00.unk_05_5) { + ptcl->unk_20 = rng_next_s32(0); + } else { + ptcl->unk_20 = emtr->unk_C6; + } + + if (resBase->unk_00.unk_05_4) { + ptcl->unk_22 = ((resBase->unk_36 - resBase->unk_34) * (u32)rng_next_s32(0x14) + (fx32)resBase->unk_34 * FX32_ONE) >> FX32_SHIFT; + } else { + ptcl->unk_22 = 0; + } + + ptcl->unk_24 = (emtr->unk_E0 * (0xFF - (resBase->unk_44.unk_01_0 * rng_next_s32(0x18) >> 8)) >> 8) + 1; + ptcl->unk_26 = 0; + + if (resBase->unk_00.unk_05_3 && res->unk_10->unk_08.unk_02_0) { + ptcl->unk_2C.unk_00 = res->unk_10->unk_00[rng_next_s32(0x14) % res->unk_10->unk_08.unk_00_0]; + } else if (resBase->unk_00.unk_05_3 && !res->unk_10->unk_08.unk_02_0) { + ptcl->unk_2C.unk_00 = res->unk_10->unk_00[0]; + } else { + ptcl->unk_2C.unk_00 = resBase->unk_48.unk_03_0; + } + + ptcl->unk_28 = 0xFFFF / res->unk_00->unk_48.unk_04_0; + ptcl->unk_2A = 0xFFFF / ptcl->unk_24; + + ptcl->unk_2C.unk_01 = 0; + + if (resBase->unk_00.unk_06_4) { + ptcl->unk_2C.unk_01 = (u8)rng_next_s32(0x18); + } + i++; + } while (i < curGenNum); + } +} + +void sub_020A05BC(SPLParticle *ptcl, SPLEmitter *emtr, SPLList *list) +{ + SPLParticle *chld; + fx32 velBase, velRand; + u32 rng; + int i; + UnkSPLStruct14 *chldRes = emtr->p_res->unk_14; + fx32 vel = FX_MUL((fx32)(chldRes->unk_08.unk_00_0 << FX32_SHIFT), FX32_CONST(1 / 256.0f)); + + for (i = 0; i < chldRes->unk_0C.unk_00_0; i++) { + chld = (SPLParticle *)sub_020A22B8(list); + if (chld == NULL) { + return; + } + sub_020A2304((SPLList *)&emtr->unk_4C, (SPLNode *)chld); + + chld->unk_08 = ptcl->unk_08; + + velBase = FX_MUL(ptcl->unk_14.x, vel); + velRand = (fx32)(chldRes->unk_02 * rng_next_s32(0x17) - chldRes->unk_02 * 256) >> 8; + chld->unk_14.x = velBase + velRand; + + velBase = FX_MUL(ptcl->unk_14.y, vel); + velRand = (fx32)(chldRes->unk_02 * rng_next_s32(0x17) - chldRes->unk_02 * 256) >> 8; + chld->unk_14.y = velBase + velRand; + + velBase = FX_MUL(ptcl->unk_14.z, vel); + velRand = (fx32)(chldRes->unk_02 * rng_next_s32(0x17) - chldRes->unk_02 * 256) >> 8; + chld->unk_14.z = velBase + velRand; + + chld->unk_38 = ptcl->unk_38; + + // `unk_08.unk_00_0` and `unk_08.unk_01_0` in `UnkSPLStruct14` + // could just be `u8 unk_08;` and `u8 unk_09;` + // instead of an inner struct + int idk = ptcl->unk_30 * ptcl->unk_34 >> FX32_SHIFT; + chld->unk_30 = idk * (chldRes->unk_08.unk_01_0 + 1) >> 6; + + chld->unk_34 = FX32_ONE; + + if (chldRes->unk_00.unk_02_6) { + chld->unk_36 = chldRes->unk_0A; + } else { + chld->unk_36 = ptcl->unk_36; + } + + chld->unk_2E.unk_00_0 = (ptcl->unk_2E.unk_00_0 * (ptcl->unk_2E.unk_00_5 + 1)) >> 5; + chld->unk_2E.unk_00_5 = 31; + + switch (chldRes->unk_00.unk_02_3) { + case 0: + chld->unk_20 = 0; + chld->unk_22 = 0; + break; + case 1: + chld->unk_20 = ptcl->unk_20; + chld->unk_22 = 0; + break; + case 2: + chld->unk_20 = ptcl->unk_20; + chld->unk_22 = ptcl->unk_22; + break; + } + + chld->unk_24 = chldRes->unk_06; + chld->unk_26 = 0; + chld->unk_2C.unk_00 = chldRes->unk_0C.unk_03_0; + + chld->unk_28 = 0xFFFF / (ptcl->unk_24 / 2); + chld->unk_2A = 0xFFFF / ptcl->unk_24; + chld->unk_2C.unk_01 = 0; + } +} diff --git a/lib/spl/src/unk_020A19F0.c b/lib/spl/src/unk_020A19F0.c index 2203538b27..f48dac4a59 100644 --- a/lib/spl/src/unk_020A19F0.c +++ b/lib/spl/src/unk_020A19F0.c @@ -3,45 +3,27 @@ #include "spl.h" -void sub_020A19F0(SPLParticle *ptcl, UnkSPLStruct4 *res, int lifeRate) +void sub_020A1DA0(SPLParticle *ptcl, UnkSPLStruct4 *res, int lifeRate) { - ptcl->unk_2E.unk_00_5 = ((255 - lifeRate) * 31) / 255; -} + UnkSPLStruct10 *scaleAnim; + int in, out; + fx16 start, n, end; -void sub_020A1A48(SPLParticle *ptcl, UnkSPLStruct4 *res, int lifeRate) -{ - ptcl->unk_34 = res->unk_14->unk_04 + ((res->unk_14->unk_04 - FX16_ONE) * (lifeRate - 255)) / 255; -} + scaleAnim = res->unk_04; + in = scaleAnim->unk_06.val2_00; + out = scaleAnim->unk_06.val2_01; -void sub_020A1A94(SPLParticle *ptcl, UnkSPLStruct4 *res, int lifeRate) -{ - UnkSPLStruct13 *texAnim = res->unk_10; - for (int i = 0; i < texAnim->unk_08.unk_00_0; i++) { - if (lifeRate < texAnim->unk_08.unk_01_0 * (i + 1)) { - ptcl->unk_2C.unk_00 = texAnim->unk_00[i]; - return; - } - } -} - -void sub_020A1AF8(SPLParticle *ptcl, UnkSPLStruct4 *res, int lifeRate) -{ - u32 x; - UnkSPLStruct12 *alphaAnim = res->unk_0C; - int maxA = alphaAnim->unk_04.val2_00; - int maxB = alphaAnim->unk_04.val2_01; - - if (lifeRate < maxA) { - x = ((lifeRate * (alphaAnim->unk_00.val2_00_5 - alphaAnim->unk_00.val2_00_0)) / alphaAnim->unk_04.val2_00); - x += alphaAnim->unk_00.val2_00_0; - } else if (lifeRate < maxB) { - x = alphaAnim->unk_00.val2_00_5; + if (lifeRate < in) { + start = scaleAnim->unk_00; + n = scaleAnim->unk_02; + ptcl->unk_34 = start + ((lifeRate * (n - start)) / in); + } else if (lifeRate >= out) { + end = scaleAnim->unk_04; + n = scaleAnim->unk_02; + ptcl->unk_34 = end + (((lifeRate - 255) * (end - n)) / (255 - out)); } else { - x = ((lifeRate - 255) * (alphaAnim->unk_00.val2_01_2 - alphaAnim->unk_00.val2_00_5)) / (255 - alphaAnim->unk_04.val2_01); - x += alphaAnim->unk_00.val2_01_2; + ptcl->unk_34 = scaleAnim->unk_02; } - - ptcl->unk_2E.unk_00_5 = x * (255 - ((int)(alphaAnim->unk_02.unk_00_0 * rng_next(0x18)) >> 8)) >> 8; } void sub_020A1BD4(SPLParticle *ptcl, UnkSPLStruct4 *res, int lifeRate) @@ -107,25 +89,43 @@ void sub_020A1BD4(SPLParticle *ptcl, UnkSPLStruct4 *res, int lifeRate) } } -void sub_020A1DA0(SPLParticle *ptcl, UnkSPLStruct4 *res, int lifeRate) +void sub_020A1AF8(SPLParticle *ptcl, UnkSPLStruct4 *res, int lifeRate) { - UnkSPLStruct10 *scaleAnim; - int in, out; - fx16 start, n, end; + u32 x; + UnkSPLStruct12 *alphaAnim = res->unk_0C; + int maxA = alphaAnim->unk_04.val2_00; + int maxB = alphaAnim->unk_04.val2_01; - scaleAnim = res->unk_04; - in = scaleAnim->unk_06.val2_00; - out = scaleAnim->unk_06.val2_01; - - if (lifeRate < in) { - start = scaleAnim->unk_00; - n = scaleAnim->unk_02; - ptcl->unk_34 = start + ((lifeRate * (n - start)) / in); - } else if (lifeRate >= out) { - end = scaleAnim->unk_04; - n = scaleAnim->unk_02; - ptcl->unk_34 = end + (((lifeRate - 255) * (end - n)) / (255 - out)); + if (lifeRate < maxA) { + x = ((lifeRate * (alphaAnim->unk_00.val2_00_5 - alphaAnim->unk_00.val2_00_0)) / alphaAnim->unk_04.val2_00); + x += alphaAnim->unk_00.val2_00_0; + } else if (lifeRate < maxB) { + x = alphaAnim->unk_00.val2_00_5; } else { - ptcl->unk_34 = scaleAnim->unk_02; + x = ((lifeRate - 255) * (alphaAnim->unk_00.val2_01_2 - alphaAnim->unk_00.val2_00_5)) / (255 - alphaAnim->unk_04.val2_01); + x += alphaAnim->unk_00.val2_01_2; + } + + ptcl->unk_2E.unk_00_5 = x * (255 - ((int)(alphaAnim->unk_02.unk_00_0 * rng_next(0x18)) >> 8)) >> 8; +} + +void sub_020A1A94(SPLParticle *ptcl, UnkSPLStruct4 *res, int lifeRate) +{ + UnkSPLStruct13 *texAnim = res->unk_10; + for (int i = 0; i < texAnim->unk_08.unk_00_0; i++) { + if (lifeRate < texAnim->unk_08.unk_01_0 * (i + 1)) { + ptcl->unk_2C.unk_00 = texAnim->unk_00[i]; + return; + } } } + +void sub_020A1A48(SPLParticle *ptcl, UnkSPLStruct4 *res, int lifeRate) +{ + ptcl->unk_34 = res->unk_14->unk_04 + ((res->unk_14->unk_04 - FX16_ONE) * (lifeRate - 255)) / 255; +} + +void sub_020A19F0(SPLParticle *ptcl, UnkSPLStruct4 *res, int lifeRate) +{ + ptcl->unk_2E.unk_00_5 = ((255 - lifeRate) * 31) / 255; +} diff --git a/lib/spl/src/unk_020A1E30.c b/lib/spl/src/unk_020A1E30.c index 217fc01d9b..056e4a9489 100644 --- a/lib/spl/src/unk_020A1E30.c +++ b/lib/spl/src/unk_020A1E30.c @@ -1,15 +1,52 @@ +#include +#include +#include + #include "spl.h" -#include -#include -#include - -void SPL_020A1E30(const void *obj, SPLParticle *ptcl, VecFx32 *pos, SPLEmitter *emtr) +void SPL_020A2204(const void *obj, SPLParticle *ptcl, VecFx32 *pos, SPLEmitter *emtr) { - SPLConvergence *conv = (SPLConvergence *)obj; - ptcl->unk_08.x += FX32_CAST(FX_MUL(conv->ratio, (conv->pos.x - ptcl->unk_08.x))); - ptcl->unk_08.y += FX32_CAST(FX_MUL(conv->ratio, (conv->pos.y - ptcl->unk_08.y))); - ptcl->unk_08.z += FX32_CAST(FX_MUL(conv->ratio, (conv->pos.z - ptcl->unk_08.z))); + SPLGravity *gravity = (SPLGravity *)obj; + pos->x += gravity->mag.x; + pos->y += gravity->mag.y; + pos->z += gravity->mag.z; +} + +void SPL_020A213C(const void *obj, SPLParticle *ptcl, VecFx32 *acc, SPLEmitter *emtr) +{ + SPLRandom *rng = (SPLRandom *)obj; + if ((ptcl->unk_26 % rng->intvl) == 0) { + acc->x += (((fx32)(rng->mag.x * rng_next(0x17))) - rng->mag.x * 256) >> 8; + acc->y += (((fx32)(rng->mag.y * rng_next(0x17))) - rng->mag.y * 256) >> 8; + acc->z += (((fx32)(rng->mag.z * rng_next(0x17))) - rng->mag.z * 256) >> 8; + } +} + +void SPL_020A20B8(const void *obj, SPLParticle *ptcl, VecFx32 *pos, SPLEmitter *emtr) +{ + SPLMagnet *magnet = (SPLMagnet *)obj; + pos->x += (magnet->mag * ((magnet->pos.x - ptcl->unk_08.x) - ptcl->unk_14.x)) >> FX32_SHIFT; + pos->y += (magnet->mag * ((magnet->pos.y - ptcl->unk_08.y) - ptcl->unk_14.y)) >> FX32_SHIFT; + pos->z += (magnet->mag * ((magnet->pos.z - ptcl->unk_08.z) - ptcl->unk_14.z)) >> FX32_SHIFT; +} + +void SPL_020A1FE0(const void *obj, SPLParticle *ptcl, VecFx32 *pos, SPLEmitter *emtr) +{ + SPLSpin *spin = (SPLSpin *)obj; + MtxFx33 rot; + switch (spin->axis_type) { + case 0: + MTX_RotX33(&rot, FX_SinIdx(spin->radian), FX_CosIdx(spin->radian)); + break; + case 1: + MTX_RotY33(&rot, FX_SinIdx(spin->radian), FX_CosIdx(spin->radian)); + break; + case 2: + MTX_RotZ33(&rot, FX_SinIdx(spin->radian), FX_CosIdx(spin->radian)); + break; + } + + MTX_MultVec33(&ptcl->unk_08, &rot, &ptcl->unk_08); } void SPL_020A1EC4(const void *obj,SPLParticle *ptcl,VecFx32 *pos,SPLEmitter *emtr) @@ -53,41 +90,10 @@ void SPL_020A1EC4(const void *obj,SPLParticle *ptcl,VecFx32 *pos,SPLEmitter *emt } } -void SPL_020A1FE0(const void *obj, SPLParticle *ptcl, VecFx32 *pos, SPLEmitter *emtr) +void SPL_020A1E30(const void *obj, SPLParticle *ptcl, VecFx32 *pos, SPLEmitter *emtr) { - SPLSpin *spin = (SPLSpin *)obj; - MtxFx33 rot; - switch (spin->axis_type) { - case 0: MTX_RotX33(&rot, FX_SinIdx(spin->radian), FX_CosIdx(spin->radian)); break; - case 1: MTX_RotY33(&rot, FX_SinIdx(spin->radian), FX_CosIdx(spin->radian)); break; - case 2: MTX_RotZ33(&rot, FX_SinIdx(spin->radian), FX_CosIdx(spin->radian)); break; - } - - MTX_MultVec33(&ptcl->unk_08, &rot, &ptcl->unk_08); -} - -void SPL_020A20B8(const void *obj, SPLParticle *ptcl, VecFx32 *pos, SPLEmitter *emtr) -{ - SPLMagnet *magnet = (SPLMagnet *)obj; - pos->x += (magnet->mag * ((magnet->pos.x - ptcl->unk_08.x) - ptcl->unk_14.x)) >> FX32_SHIFT; - pos->y += (magnet->mag * ((magnet->pos.y - ptcl->unk_08.y) - ptcl->unk_14.y)) >> FX32_SHIFT; - pos->z += (magnet->mag * ((magnet->pos.z - ptcl->unk_08.z) - ptcl->unk_14.z)) >> FX32_SHIFT; -} - -void SPL_020A213C(const void *obj, SPLParticle *ptcl, VecFx32 *acc, SPLEmitter *emtr) -{ - SPLRandom *rng = (SPLRandom *)obj; - if ((ptcl->unk_26 % rng->intvl) == 0) { - acc->x += (((fx32)(rng->mag.x * rng_next(0x17))) - rng->mag.x * 256) >> 8; - acc->y += (((fx32)(rng->mag.y * rng_next(0x17))) - rng->mag.y * 256) >> 8; - acc->z += (((fx32)(rng->mag.z * rng_next(0x17))) - rng->mag.z * 256) >> 8; - } -} - -void SPL_020A2204(const void *obj,SPLParticle *ptcl,VecFx32 *pos, SPLEmitter *emtr) -{ - SPLGravity *gravity = (SPLGravity *)obj; - pos->x += gravity->mag.x; - pos->y += gravity->mag.y; - pos->z += gravity->mag.z; + SPLConvergence *conv = (SPLConvergence *)obj; + ptcl->unk_08.x += FX32_CAST(FX_MUL(conv->ratio, (conv->pos.x - ptcl->unk_08.x))); + ptcl->unk_08.y += FX32_CAST(FX_MUL(conv->ratio, (conv->pos.y - ptcl->unk_08.y))); + ptcl->unk_08.z += FX32_CAST(FX_MUL(conv->ratio, (conv->pos.z - ptcl->unk_08.z))); } diff --git a/lib/spl/src/unk_020A2238.c b/lib/spl/src/unk_020A2238.c index db35d31270..9bc7853c42 100644 --- a/lib/spl/src/unk_020A2238.c +++ b/lib/spl/src/unk_020A2238.c @@ -2,27 +2,26 @@ #include -SPLNode *sub_020A2238(SPLList *list, SPLNode *node) +void sub_020A2304(SPLList *list, SPLNode *node) { - SPLNode *next = node->p_next; - if (next == NULL) { - if (list->p_begin == node) { - list->p_begin = NULL; - list->p_end = NULL; - } else { - node->p_prev->p_next = NULL; - list->p_end = list->p_end->p_prev; - } - } else if (list->p_begin == node) { - list->p_begin = next; - list->p_begin->p_prev = NULL; + if (list->p_begin == NULL) { + list->p_begin = node; + list->p_end = node; + node->p_next = NULL; + node->p_prev = node->p_next; } else { - next->p_prev = node->p_prev; - node->p_prev->p_next = node->p_next; + node->p_next = list->p_begin; + node->p_prev = NULL; + list->p_begin->p_prev = node; + list->p_begin = node; } - list->node_num -= 1; - return node; + list->node_num += 1; +} + +void spl_push_back(SPLList *list, SPLNode *node) +{ + return; } SPLNode *sub_020A22B8(SPLList *list) @@ -49,19 +48,30 @@ SPLNode *sub_020A22B8(SPLList *list) return node; } -void sub_020A2304(SPLList *list, SPLNode *node) +SPLNode *spl_pop_back(SPLList *list) { - if (list->p_begin == NULL) { - list->p_begin = node; - list->p_end = node; - node->p_next = NULL; - node->p_prev = node->p_next; + return NULL; +} + +SPLNode *sub_020A2238(SPLList *list, SPLNode *node) +{ + SPLNode *next = node->p_next; + if (next == NULL) { + if (list->p_begin == node) { + list->p_begin = NULL; + list->p_end = NULL; + } else { + node->p_prev->p_next = NULL; + list->p_end = list->p_end->p_prev; + } + } else if (list->p_begin == node) { + list->p_begin = next; + list->p_begin->p_prev = NULL; } else { - node->p_next = list->p_begin; - node->p_prev = NULL; - list->p_begin->p_prev = node; - list->p_begin = node; + next->p_prev = node->p_prev; + node->p_prev->p_next = node->p_next; } - list->node_num += 1; + list->node_num -= 1; + return node; } diff --git a/lib/spl/src/unk_020A2354.c b/lib/spl/src/unk_020A2354.c index d66f8f3bb3..09704919a8 100644 --- a/lib/spl/src/unk_020A2354.c +++ b/lib/spl/src/unk_020A2354.c @@ -4,14 +4,6 @@ u32 Unk_021C3A38; -void sub_020A2354(VecFx32 *vec) -{ - vec->x = rng_next(8); - vec->y = rng_next(8); - vec->z = 0; - VEC_Normalize(vec, vec); -} - void sub_020A23B0(VecFx32 *vec) { vec->x = rng_next(8); @@ -19,3 +11,11 @@ void sub_020A23B0(VecFx32 *vec) vec->z = rng_next(8); VEC_Normalize(vec, vec); } + +void sub_020A2354(VecFx32 *vec) +{ + vec->x = rng_next(8); + vec->y = rng_next(8); + vec->z = 0; + VEC_Normalize(vec, vec); +} diff --git a/tools/cw/1.2/base_b73/lmgr8c.dll b/tools/cw/1.2/base_b73/lmgr8c.dll new file mode 100644 index 0000000000..35bc6be4a8 Binary files /dev/null and b/tools/cw/1.2/base_b73/lmgr8c.dll differ diff --git a/tools/cw/1.2/base_b73/mwasmarm.exe b/tools/cw/1.2/base_b73/mwasmarm.exe new file mode 100644 index 0000000000..fa30085511 Binary files /dev/null and b/tools/cw/1.2/base_b73/mwasmarm.exe differ diff --git a/tools/cw/1.2/base_b73/mwccarm.exe b/tools/cw/1.2/base_b73/mwccarm.exe new file mode 100644 index 0000000000..04f776494a Binary files /dev/null and b/tools/cw/1.2/base_b73/mwccarm.exe differ diff --git a/tools/cw/1.2/base_b73/mwldarm.exe b/tools/cw/1.2/base_b73/mwldarm.exe new file mode 100644 index 0000000000..6be8190da5 Binary files /dev/null and b/tools/cw/1.2/base_b73/mwldarm.exe differ diff --git a/tools/cw/mwrap.c b/tools/cw/mwrap.c index e8c6d0af86..aa2e754956 100644 --- a/tools/cw/mwrap.c +++ b/tools/cw/mwrap.c @@ -465,6 +465,25 @@ char *replace_str(char *str, char *orig, char *rep, int start) return str; } +void remove_ipa_arguments(int *argc, _TCHAR **argv) +{ + int new_argc = 0; + for (int i = 0; i < *argc; i++) { + if (argv[i] && _tcscmp(argv[i], _T("-ipa")) == 0 && (i + 1) < *argc) { + // Skip the current "-ipa" argument and the following argument. + i++; // Increment to skip the next argument. + } else { + // Keep this argument, by moving it down if necessary. + argv[new_argc] = argv[i]; + new_argc++; + } + } + + // Update the original argc to the new count of arguments. + *argc = new_argc; + argv[*argc] = NULL; +} + int _tmain(int argc, _TCHAR *argv[]) { if (argc < 2) { @@ -490,6 +509,10 @@ int _tmain(int argc, _TCHAR *argv[]) if (args.wrap_ver) tool_ver = args.wrap_ver; + if (_tcscmp(tool_ver, _T("1.2/base_b73")) == 0) { + remove_ipa_arguments(&new_argc, new_argv); + } + // Make a path of the chosen tool size_t tool_size = _tcslen(tool_dir) + 1 + _tcslen(tool_ver) + 1 + _tcslen(tool_bin) + 5;