Finish documenting SPLEmitter

This commit is contained in:
Fexty12573 2024-08-01 12:44:44 +02:00
parent 0b9f3ec2ca
commit 98ca0c745a
9 changed files with 71 additions and 87 deletions

View File

@ -28,7 +28,7 @@ static inline void SPL_UnkInline4 (SPLEmitter * param0, fx32 param1)
static inline void SPL_UnkInline5 (SPLEmitter * param0, const VecFx16 * param1)
{
param0->unk_C0 = *param1;
param0->axis = *param1;
}
#endif // POKEPLATINUM_SPL_H

View File

@ -42,11 +42,11 @@ typedef struct SPLEmitter {
VecFx32 unk_B0;
u16 age;
fx16 unk_BE;
VecFx16 unk_C0;
VecFx16 axis;
u16 unk_C6;
fx32 unk_C8;
fx32 unk_CC;
fx32 unk_D0;
fx32 length;
fx32 unk_D4;
fx32 unk_D8;
fx32 unk_DC;

View File

@ -40,9 +40,9 @@ void sub_020A08DC(SPLEmitter *emtr, SPLList *list);
void sub_020A05BC(SPLParticle *ptcl, SPLEmitter *emtr, SPLList *list);
void SPLEmitter_Update(SPLManager *mgr, SPLEmitter *emtr);
void sub_0209CF00(SPLManager *mgr);
void SPLManager_DoDraw(SPLManager *mgr);
void SPLEmitter_Init(SPLEmitter *emtr, SPLResource *res, const VecFx32 *pos);
void spl_generate(SPLEmitter *emtr, SPLList *list);
void SPLEmitter_Emit(SPLEmitter *emtr, SPLList *list);
static inline void SPLParticleList_PushFront(SPLParticleList *list, SPLParticle *ptcl)
{

View File

@ -18,11 +18,11 @@ typedef struct SPLArcHdr {
u32 reserved1;
} SPLFileHeader;
typedef union {
typedef union SPLResourceFlags {
u32 all;
struct {
u32 unk_04_0 : 4;
u32 unk_04_4 : 2;
u32 drawType : 2;
u32 unk_04_6 : 2;
u32 hasScaleAnim : 1;
u32 hasColorAnim : 1;
@ -39,8 +39,8 @@ typedef union {
u32 unk_06_1 : 2;
u32 unk_06_3 : 1;
u32 unk_06_4 : 1;
u32 unk_06_5 : 1;
u32 unk_06_6 : 1;
u32 drawChildrenFirst : 1; // If set, child particles will be rendered before parent particles
u32 hideParent : 1; // If set, only child particles will be rendered
u32 unk_06_7 : 1;
u32 hasGravityBehavior : 1;
u32 hasRandomBehavior : 1;
@ -51,9 +51,9 @@ typedef union {
u32 hasFixedPolygonID : 1;
u32 childHasFixedPolygonID : 1;
};
} SPLResourceFlags; // size=0x4
} SPLResourceFlags;
typedef union {
typedef union SPLChildResourceFlags {
u16 all;
struct {
u16 usesBehaviors : 1;
@ -62,12 +62,12 @@ typedef union {
u16 unk_02_3 : 2;
u16 followEmitter : 1;
u16 unk_02_6 : 1;
u16 unk_02_7 : 2;
u16 drawType : 2;
u16 unk_03_1 : 2;
u16 unk_03_3 : 1;
u16 reserved_03_4 : 4;
};
} SPLChildResourceFlags; // size=0x2
} SPLChildResourceFlags;
typedef union {
u16 val1;
@ -117,7 +117,7 @@ typedef struct SPLResourceHeader {
u32 unk_00_0 : 8;
u32 unk_01_0 : 8;
u32 airResistance : 8;
u32 unk_03_0 : 8;
u32 textureIndex : 8;
u32 unk_04_0 : 8;
u32 unk_05_0 : 16;
u32 unk_07_0 : 2;
@ -206,7 +206,7 @@ typedef struct SPLChildResource {
u32 unk_00_0 : 8;
u32 emissionDelay : 8; // Delay, as a fraction of the particle's lifetime, before the particle starts emitting
u32 emissionInterval : 8;
u32 unk_03_0 : 8;
u32 textureIndex : 8;
u32 unk_04_0 : 2;
u32 unk_04_2 : 2;
u32 unk_04_4 : 1;

View File

@ -16,7 +16,7 @@ libspl_public_includes = include_directories('include')
libspl_srcs = files(
'src/spl_manager.c',
'src/unk_0209CF00.c',
'src/spl_emitter.c',
'src/unk_0209DD54.c',
'src/unk_020A05BC.c',
'src/unk_020A19F0.c',

View File

@ -4,17 +4,17 @@
#include <nitro/gx/g3imm.h>
#include "spl_emitter.h"
#include "spl_texture.h"
#include "spl_manager.h"
#include "spl_particle.h"
#include "spl_internal.h"
#include "spl_list.h"
#include "spl_manager.h"
#include "spl_particle.h"
#include "spl_texture.h"
#define ANIM_FUNC_NO_LOOP 0
#define ANIM_FUNC_LOOP 1
#define ANIM_FUNC_NO_LOOP 0
#define ANIM_FUNC_LOOP 1
typedef void(*DrawFunc)(SPLManager *mgr, SPLParticle *ptcl);
typedef void(*SetTexFunc)(SPLTexture *tex);
typedef void (*DrawFunc)(SPLManager *mgr, SPLParticle *ptcl);
typedef void (*SetTexFunc)(SPLTexture *tex);
typedef struct FieldFunc {
void (*func)(SPLParticle *, SPLResource *, int);
@ -28,10 +28,10 @@ typedef struct FieldFunc8 {
static void SPLUtil_SetTexture(SPLTexture *tex); // spl_set_tex
static void SPLUtil_SetTexture_Stub(SPLTexture *tex); // spl_set_tex_dummy
static void sub_0209D064(SPLManager *mgr);
static void sub_0209CF7C(SPLManager *mgr);
static void SPLManager_DrawParticles(SPLManager *mgr);
static void SPLManager_DrawChildParticles(SPLManager *mgr);
void SPLEmitter_Init(SPLEmitter *emtr, SPLResource *res, const VecFx32 *param2);
void sub_0209CF00(SPLManager *mgr);
void SPLManager_DoDraw(SPLManager *mgr);
void SPLEmitter_Update(SPLManager *mgr, SPLEmitter *emtr);
static void SPLUtil_SetTexture(SPLTexture *tex)
@ -76,11 +76,11 @@ void SPLEmitter_Init(SPLEmitter *emtr, SPLResource *res, const VecFx32 *pos)
emtr->age = 0;
emtr->unk_BE = 0;
emtr->unk_C0 = emtr->resource->header->unk_1C;
emtr->axis = emtr->resource->header->unk_1C;
emtr->unk_C6 = emtr->resource->header->unk_38;
emtr->unk_C8 = emtr->resource->header->unk_10;
emtr->unk_CC = emtr->resource->header->unk_14;
emtr->unk_D0 = emtr->resource->header->unk_18;
emtr->length = emtr->resource->header->unk_18;
emtr->unk_D4 = emtr->resource->header->unk_24;
emtr->unk_D8 = emtr->resource->header->unk_28;
emtr->unk_DC = emtr->resource->header->unk_2C;
@ -326,21 +326,15 @@ void SPLEmitter_Update(SPLManager *mgr, SPLEmitter *emtr)
}
}
static void sub_0209D064(SPLManager *mgr)
static void SPLManager_DrawParticles(SPLManager *mgr)
{
SPLEmitter *emtr;
SPLResourceHeader *resBase;
SPLParticle *ptcl;
DrawFunc drawFunc;
SetTexFunc setTexFunc;
SPLEmitter *emtr = mgr->renderState.emitter;
SPLResourceHeader *header = emtr->resource->header;
DrawFunc drawFunc = NULL;
emtr = mgr->renderState.emitter;
resBase = emtr->resource->header;
drawFunc = NULL;
SPLUtil_SetTexture(mgr->textures + header->misc.textureIndex);
SPLUtil_SetTexture(mgr->textures + resBase->misc.unk_03_0);
switch (resBase->flags.unk_04_4) {
switch (header->flags.drawType) {
case 0:
drawFunc = sub_0209FF0C;
break;
@ -358,34 +352,27 @@ static void sub_0209D064(SPLManager *mgr)
break;
}
setTexFunc = resBase->flags.hasTexAnim ? SPLUtil_SetTexture : SPLUtil_SetTexture_Stub;
ptcl = emtr->particles.first;
SetTexFunc setTexFunc = header->flags.hasTexAnim ? SPLUtil_SetTexture : SPLUtil_SetTexture_Stub;
while (ptcl != NULL) {
for (SPLParticle *ptcl = emtr->particles.first; ptcl != NULL; ptcl = ptcl->next) {
setTexFunc(mgr->textures + ptcl->misc.unk_00);
drawFunc(mgr, ptcl);
ptcl = ptcl->next;
}
}
static void sub_0209CF7C(SPLManager *mgr)
static void SPLManager_DrawChildParticles(SPLManager *mgr)
{
SPLEmitter *emtr;
SPLResource *res;
DrawFunc drawFunc;
SPLParticle *ptcl;
emtr = mgr->renderState.emitter;
drawFunc = NULL;
res = emtr->resource;
SPLEmitter *emtr = mgr->renderState.emitter;
SPLResource *res = emtr->resource;
DrawFunc drawFunc = NULL;
if (!res->header->flags.hasChildResource) {
return;
}
SPLUtil_SetTexture(mgr->textures + res->childResource->misc.unk_03_0);
SPLUtil_SetTexture(mgr->textures + res->childResource->misc.textureIndex);
switch (res->childResource->flags.unk_02_7) {
switch (res->childResource->flags.drawType) {
case 0:
drawFunc = sub_0209FAB8;
break;
@ -403,39 +390,36 @@ static void sub_0209CF7C(SPLManager *mgr)
break;
}
ptcl = emtr->childParticles.first;
while (ptcl != NULL) {
for (SPLParticle *ptcl = emtr->childParticles.first; ptcl != NULL; ptcl = ptcl->next) {
drawFunc(mgr, ptcl);
ptcl = ptcl->next;
}
}
void sub_0209CF00(SPLManager *mgr)
void SPLManager_DoDraw(SPLManager *mgr)
{
SPLResourceHeader *resBase;
SPLResourceHeader *header = mgr->renderState.emitter->resource->header;
resBase = mgr->renderState.emitter->resource->header;
if (resBase->flags.unk_06_5) {
sub_0209CF7C(mgr);
if (header->flags.drawChildrenFirst) {
SPLManager_DrawChildParticles(mgr);
if (!resBase->flags.unk_06_6) {
sub_0209D064(mgr);
if (!header->flags.hideParent) {
SPLManager_DrawParticles(mgr);
}
} else {
if (!resBase->flags.unk_06_6) {
sub_0209D064(mgr);
if (!header->flags.hideParent) {
SPLManager_DrawParticles(mgr);
}
sub_0209CF7C(mgr);
SPLManager_DrawChildParticles(mgr);
}
}
void spl_generate(SPLEmitter *emtr, SPLList *list)
void SPLEmitter_Emit(SPLEmitter *emtr, SPLList *list)
{
sub_020A08DC(emtr, list);
}
void SPL_Util_SetCylinderEmiterDirection(SPLEmitter *emtr, VecFx32 *p1, VecFx32 *p2)
void SPLUtil_SetCylinderEmitterDir(SPLEmitter *emtr, VecFx32 *p1, VecFx32 *p2)
{
VecFx32 vex;
@ -443,15 +427,15 @@ void SPL_Util_SetCylinderEmiterDirection(SPLEmitter *emtr, VecFx32 *p1, VecFx32
emtr->position.x = (p2->x + p1->x) / 2;
emtr->position.y = (p2->y + p1->y) / 2;
emtr->position.z = (p2->z + p1->z) / 2;
emtr->unk_D0 = VEC_Distance(p1, p2) / 2;
emtr->length = 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;
emtr->axis.x = (fx16)vex.x;
emtr->axis.y = (fx16)vex.y;
emtr->axis.z = (fx16)vex.z;
}
}

View File

@ -317,7 +317,7 @@ void SPLManager_Draw(SPLManager *mgr, const MtxFx43 *viewMatrix)
while (emtr != NULL) {
mgr->renderState.emitter = emtr;
if (!emtr->state.renderingDisabled) {
sub_0209CF00(mgr);
SPLManager_DoDraw(mgr);
}
emtr = emtr->next;
@ -328,7 +328,7 @@ void SPLManager_Draw(SPLManager *mgr, const MtxFx43 *viewMatrix)
while (emtr != NULL) {
mgr->renderState.emitter = emtr;
if (!emtr->state.renderingDisabled) {
sub_0209CF00(mgr);
SPLManager_DoDraw(mgr);
}
emtr = emtr->prev;
@ -426,7 +426,7 @@ void SPLManager_DeleteAllEmitters(SPLManager *mgr)
void SPL_Emit(SPLManager *mgr, SPLEmitter *emtr)
{
spl_generate(emtr, (SPLList *)&mgr->inactiveParticles);
SPLEmitter_Emit(emtr, (SPLList *)&mgr->inactiveParticles);
}
void SPL_EmitAt(SPLManager *mgr, SPLEmitter *emtr, VecFx32 *pos)
@ -434,5 +434,5 @@ void SPL_EmitAt(SPLManager *mgr, SPLEmitter *emtr, VecFx32 *pos)
emtr->position.x = pos->x + emtr->resource->header->emitterBasePos.x;
emtr->position.y = pos->y + emtr->resource->header->emitterBasePos.y;
emtr->position.z = pos->z + emtr->resource->header->emitterBasePos.z;
spl_generate(emtr, (SPLList *)&mgr->inactiveParticles);
SPLEmitter_Emit(emtr, (SPLList *)&mgr->inactiveParticles);
}

View File

@ -39,7 +39,7 @@ static void sub_020A1768(SPLEmitter *emtr)
axis.z = FX32_ONE;
break;
default:
VEC_Fx16Normalize(&emtr->unk_C0, &axis);
VEC_Fx16Normalize(&emtr->axis, &axis);
break;
}
@ -197,7 +197,7 @@ void sub_020A08DC(SPLEmitter *emtr, SPLList *list)
SPLRandom_VecFx32_XY(&ptcl->velocity);
pos.x = FX_MUL(ptcl->velocity.x, emtr->unk_CC);
pos.y = FX_MUL(ptcl->velocity.y, emtr->unk_CC);
pos.z = SPLRandom_RangeFX32(emtr->unk_D0);
pos.z = SPLRandom_RangeFX32(emtr->length);
sub_020A1608(&ptcl->position, &pos, emtr);
} break;
@ -206,7 +206,7 @@ void sub_020A08DC(SPLEmitter *emtr, SPLList *list)
SPLRandom_VecFx32_XY(&ptcl->velocity);
pos.x = FX_MUL(FX_MUL(ptcl->velocity.x, emtr->unk_CC), SPLRandom_RangeFX32(FX32_ONE));
pos.y = FX_MUL(FX_MUL(ptcl->velocity.y, emtr->unk_CC), SPLRandom_RangeFX32(FX32_ONE));
pos.z = SPLRandom_RangeFX32(emtr->unk_D0);
pos.z = SPLRandom_RangeFX32(emtr->length);
sub_020A1608(&ptcl->position, &pos, emtr);
} break;
}
@ -228,9 +228,9 @@ void sub_020A08DC(SPLEmitter *emtr, SPLList *list)
VEC_Normalize(&ptcl->position, &posNorm);
}
ptcl->velocity.x = FX_MUL(posNorm.x, magPos) + FX_MUL(emtr->unk_C0.x, magAxis) + emtr->unk_B0.x;
ptcl->velocity.y = FX_MUL(posNorm.y, magPos) + FX_MUL(emtr->unk_C0.y, magAxis) + emtr->unk_B0.y;
ptcl->velocity.z = FX_MUL(posNorm.z, magPos) + FX_MUL(emtr->unk_C0.z, magAxis) + emtr->unk_B0.z;
ptcl->velocity.x = FX_MUL(posNorm.x, magPos) + FX_MUL(emtr->axis.x, magAxis) + emtr->unk_B0.x;
ptcl->velocity.y = FX_MUL(posNorm.y, magPos) + FX_MUL(emtr->axis.y, magAxis) + emtr->unk_B0.y;
ptcl->velocity.z = FX_MUL(posNorm.z, magPos) + FX_MUL(emtr->axis.z, magAxis) + emtr->unk_B0.z;
ptcl->emitterPos = emtr->position;
@ -271,7 +271,7 @@ void sub_020A08DC(SPLEmitter *emtr, SPLList *list)
} else if (resBase->flags.hasTexAnim && !res->texAnim->unk_08.unk_02_0) {
ptcl->misc.unk_00 = res->texAnim->unk_00[0];
} else {
ptcl->misc.unk_00 = resBase->misc.unk_03_0;
ptcl->misc.unk_00 = resBase->misc.textureIndex;
}
ptcl->loopTimeFactor = 0xFFFF / res->header->misc.unk_04_0;
@ -353,7 +353,7 @@ void sub_020A05BC(SPLParticle *ptcl, SPLEmitter *emtr, SPLList *list)
chld->lifeTime = chldRes->unk_06;
chld->age = 0;
chld->misc.unk_00 = chldRes->misc.unk_03_0;
chld->misc.unk_00 = chldRes->misc.textureIndex;
chld->loopTimeFactor = 0xFFFF / (ptcl->lifeTime / 2);
chld->lifeTimeFactor = 0xFFFF / ptcl->lifeTime;

View File

@ -647,7 +647,7 @@ u8 sub_02014790(UnkStruct_02014014 *param0)
void sub_02014798(SPLEmitter *param0, VecFx16 *param1)
{
*param1 = param0->unk_C0;
*param1 = param0->axis;
}
void sub_020147B0(SPLEmitter *param0, fx32 param1)