diff --git a/include/struct_defs/struct_020147B8.h b/include/struct_defs/struct_020147B8.h index 047040d533..444b60fd22 100644 --- a/include/struct_defs/struct_020147B8.h +++ b/include/struct_defs/struct_020147B8.h @@ -7,7 +7,7 @@ struct SPLParticle; struct SPLEmitter; typedef struct SPLBehavior { - void (*apply)(const void *, struct SPLParticle *, VecFx32 *, struct SPLEmitter *); + void (*applyFunc)(const void *, struct SPLParticle *, VecFx32 *, struct SPLEmitter *); const void *object; } SPLBehavior; diff --git a/lib/spl/include/spl_behavior.h b/lib/spl/include/spl_behavior.h index 3b5f876fe1..3e9bdd27fb 100644 --- a/lib/spl/include/spl_behavior.h +++ b/lib/spl/include/spl_behavior.h @@ -41,11 +41,7 @@ typedef struct SPLSpinBehavior { typedef struct SPLCollisionPlaneBehavior { fx32 y; // The Y position of the collision plane fx16 elasticity; // The elasticity of the collision, 1.0 being perfectly elastic and 0.0 being perfectly inelastic - - struct { - u16 collisionType : 2; - u16 : 14; - } flags; + u16 collisionType : 2; } SPLCollisionPlaneBehavior; // Applies a convergence behavior to particles @@ -56,11 +52,11 @@ typedef struct SPLConvergenceBehavior { u16 padding; } SPLConvergenceBehavior; -void SPLBehavior_ApplyGravity(const void *param0, SPLParticle *param1, VecFx32 *param2, struct SPLEmitter *param3); -void SPLBehavior_ApplyRandom(const void *param0, SPLParticle *param1, VecFx32 *param2, struct SPLEmitter *param3); -void SPLBehavior_ApplyMagnet(const void *param0, SPLParticle *param1, VecFx32 *param2, struct SPLEmitter *param3); -void SPLBehavior_ApplySpin(const void *param0, SPLParticle *param1, VecFx32 *param2, struct SPLEmitter *param3); -void SPLBehavior_ApplyCollisionPlane(const void *param0, SPLParticle *param1, VecFx32 *param2, struct SPLEmitter *param3); -void SPLBehavior_ApplyConvergence(const void *param0, SPLParticle *param1, VecFx32 *param2, struct SPLEmitter *param3); +void SPLBehavior_ApplyGravity(const void *obj, SPLParticle *ptcl, VecFx32 *acc, struct SPLEmitter *emtr); +void SPLBehavior_ApplyRandom(const void *obj, SPLParticle *ptcl, VecFx32 *acc, struct SPLEmitter *emtr); +void SPLBehavior_ApplyMagnet(const void *obj, SPLParticle *ptcl, VecFx32 *acc, struct SPLEmitter *emtr); +void SPLBehavior_ApplySpin(const void *obj, SPLParticle *ptcl, VecFx32 *acc, struct SPLEmitter *emtr); +void SPLBehavior_ApplyCollisionPlane(const void *obj, SPLParticle *ptcl, VecFx32 *acc, struct SPLEmitter *emtr); +void SPLBehavior_ApplyConvergence(const void *obj, SPLParticle *ptcl, VecFx32 *acc, struct SPLEmitter *emtr); #endif // SPL_BEHAVIOR_H diff --git a/lib/spl/src/spl_behavior.c b/lib/spl/src/spl_behavior.c index b95bb3f8f6..49ef0e4d59 100644 --- a/lib/spl/src/spl_behavior.c +++ b/lib/spl/src/spl_behavior.c @@ -61,7 +61,7 @@ void SPLBehavior_ApplyCollisionPlane(const void *obj, SPLParticle *ptcl, VecFx32 y = emtr->collisionPlaneHeight; } - switch (plane->flags.collisionType) { + switch (plane->collisionType) { case SPL_COLLISION_BEHAVIOR_TYPE_KILL: ey = ptcl->emitterPos.y; if (ey < y && ey + ptcl->position.y > y) { diff --git a/lib/spl/src/spl_draw.c b/lib/spl/src/spl_draw.c index 2fa8d73b00..9568e53524 100644 --- a/lib/spl/src/spl_draw.c +++ b/lib/spl/src/spl_draw.c @@ -15,14 +15,6 @@ typedef void (*RotFunc)(fx32 sin, fx32 cos, MtxFx43 *rot); typedef void (*DrawPlaneFunc)(fx16 s, fx16 t, fx16 offsetX, fx16 offsetY); -void SPLDraw_Billboard(SPLManager *mgr, SPLParticle *ptcl); -void SPLDraw_Child_Billboard(SPLManager *mgr, SPLParticle *ptcl); -void SPLDraw_DirectionalBillboard(SPLManager *mgr, SPLParticle *ptcl); -void SPLDraw_Child_DirectionalBillboard(SPLManager *mgr, SPLParticle *ptcl); -void SPLDraw_Polygon(SPLManager *mgr, SPLParticle *ptcl); -void SPLDraw_Child_Polygon(SPLManager *mgr, SPLParticle *ptcl); -void SPLDraw_DirectionalPolygon(SPLManager *mgr, SPLParticle *ptcl); -void SPLDraw_Child_DirectionalPolygon(SPLManager *mgr, SPLParticle *ptcl); static void SPLUtil_DrawXYPlane(fx16 s, fx16 t, fx16 offsetX, fx16 offsetY); static void SPLUtil_DrawXZPlane(fx16 s, fx16 t, fx16 offsetX, fx16 offsetZ); static void SPLUtil_RotateXYZ(fx32 sin, fx32 cos, MtxFx43 *mat); diff --git a/lib/spl/src/spl_emit.c b/lib/spl/src/spl_emit.c index 0d867ebe0b..a4afbb16e9 100644 --- a/lib/spl/src/spl_emit.c +++ b/lib/spl/src/spl_emit.c @@ -78,14 +78,20 @@ void SPLEmitter_EmitParticles(SPLEmitter *emtr, SPLParticleList *list) SPLResource *res = emtr->resource; SPLResourceHeader *header = res->header; - int i = 0; + int i = 0; // Required for matching int emitCountDec = emtr->emissionCount + FX32_CAST(emtr->emissionCountFractional); int totalEmissions = emitCountDec >> FX32_SHIFT; int emission = 0; emtr->emissionCountFractional = emitCountDec & FX32_DEC_MASK; enum SPLEmissionType emitType = header->flags.emissionType; - if (emitType == SPL_EMISSION_TYPE_CIRCLE_BORDER || emitType == SPL_EMISSION_TYPE_CIRCLE_BORDER_UNIFORM || emitType == SPL_EMISSION_TYPE_CIRCLE || emitType == SPL_EMISSION_TYPE_CYLINDER_SURFACE || emitType == SPL_EMISSION_TYPE_CYLINDER || emitType == SPL_EMISSION_TYPE_HEMISPHERE_SURFACE || emitType == SPL_EMISSION_TYPE_HEMISPHERE) { + if (emitType == SPL_EMISSION_TYPE_CIRCLE_BORDER + || emitType == SPL_EMISSION_TYPE_CIRCLE_BORDER_UNIFORM + || emitType == SPL_EMISSION_TYPE_CIRCLE + || emitType == SPL_EMISSION_TYPE_CYLINDER_SURFACE + || emitType == SPL_EMISSION_TYPE_CYLINDER + || emitType == SPL_EMISSION_TYPE_HEMISPHERE_SURFACE + || emitType == SPL_EMISSION_TYPE_HEMISPHERE) { SPLEmitter_ComputeOrthogonalAxes(emtr); } diff --git a/lib/spl/src/spl_emitter.c b/lib/spl/src/spl_emitter.c index fa3648b5fb..705c3264c3 100644 --- a/lib/spl/src/spl_emitter.c +++ b/lib/spl/src/spl_emitter.c @@ -27,13 +27,10 @@ typedef struct FieldFunc8 { BOOL loop; } FieldFunc8; -static void SPLUtil_SetTexture(SPLTexture *tex); // spl_set_tex -static void SPLUtil_SetTexture_Stub(SPLTexture *tex); // spl_set_tex_dummy +static void SPLUtil_SetTexture(SPLTexture *tex); +static void SPLUtil_SetTexture_Stub(SPLTexture *tex); static void SPLManager_DrawParticles(SPLManager *mgr); static void SPLManager_DrawChildParticles(SPLManager *mgr); -void SPLEmitter_Init(SPLEmitter *emtr, SPLResource *res, const VecFx32 *param2); -void SPLManager_DoDraw(SPLManager *mgr); -void SPLEmitter_Update(SPLManager *mgr, SPLEmitter *emtr); static void SPLUtil_SetTexture(SPLTexture *tex) { @@ -201,7 +198,7 @@ void SPLEmitter_Update(SPLManager *mgr, SPLEmitter *emtr) } for (i = 0; i < behaviorCount; i++) { - res->behaviors[i].apply(res->behaviors[i].object, ptcl, &acc, emtr); + res->behaviors[i].applyFunc(res->behaviors[i].object, ptcl, &acc, emtr); } ptcl->rotation += ptcl->angularVelocity; @@ -224,10 +221,8 @@ void SPLEmitter_Update(SPLManager *mgr, SPLEmitter *emtr) // The >> 8 here is a division by 256 because emissionDelay is a fraction of the particle's lifetime represented as a u8 fx32 diff = ((fx32)ptcl->age * FX32_ONE) - (emissionDelay >> 8); - if (diff >= 0) { - if ((diff >> FX32_SHIFT) % child->misc.emissionInterval == 0) { - SPLEmitter_EmitChildren(ptcl, emtr, &mgr->inactiveParticles); - } + if (diff >= 0 && ((diff >> FX32_SHIFT) % child->misc.emissionInterval == 0)) { + SPLEmitter_EmitChildren(ptcl, emtr, &mgr->inactiveParticles); } } @@ -283,7 +278,7 @@ void SPLEmitter_Update(SPLManager *mgr, SPLEmitter *emtr) } for (i = 0; i < behaviorCount; i++) { - res->behaviors[i].apply(res->behaviors[i].object, ptcl, &acc, emtr); + res->behaviors[i].applyFunc(res->behaviors[i].object, ptcl, &acc, emtr); } ptcl->rotation += ptcl->angularVelocity; diff --git a/lib/spl/src/spl_manager.c b/lib/spl/src/spl_manager.c index 5e0f024ae0..c8ff6c3d6f 100644 --- a/lib/spl/src/spl_manager.c +++ b/lib/spl/src/spl_manager.c @@ -10,11 +10,10 @@ #include "spl_particle.h" #define DECODE_WH(X) ((u16)(1 << ((X) + 3))) -#define EMITTER_SHOULD_TERMINATE(emtr, header) \ - (( \ - (header->flags.selfMaintaining && header->emitterLifeTime != 0 && emtr->state.started && emtr->age > header->emitterLifeTime) \ - || emtr->state.terminate) \ - && emtr->particles.count == 0 && emtr->childParticles.count == 0) +#define EMITTER_SHOULD_TERMINATE(emtr, header) \ + (((header->flags.selfMaintaining && header->emitterLifeTime != 0 && emtr->state.started && emtr->age > header->emitterLifeTime) \ + || emtr->state.terminate) \ + && emtr->particles.count == 0 && emtr->childParticles.count == 0) static u32 SPLUtil_AllocTextureVRAM(u32 size, BOOL is4x4); static u32 SPLUtil_AllocPaletteVRAM(u32 size, BOOL is4Pltt); @@ -152,42 +151,42 @@ void SPLManager_LoadResources(SPLManager *mgr, const void *data) if (flags.hasGravityBehavior) { behavior->object = (const void *)((u8 *)spa + offset); - behavior->apply = SPLBehavior_ApplyGravity; + behavior->applyFunc = SPLBehavior_ApplyGravity; offset += sizeof(SPLGravityBehavior); behavior++; } if (flags.hasRandomBehavior) { behavior->object = (const void *)((u8 *)spa + offset); - behavior->apply = SPLBehavior_ApplyRandom; + behavior->applyFunc = SPLBehavior_ApplyRandom; offset += sizeof(SPLRandomBehavior); behavior++; } if (flags.hasMagnetBehavior) { behavior->object = (const void *)((u8 *)spa + offset); - behavior->apply = SPLBehavior_ApplyMagnet; + behavior->applyFunc = SPLBehavior_ApplyMagnet; offset += sizeof(SPLMagnetBehavior); behavior++; } if (flags.hasSpinBehavior) { behavior->object = (const void *)((u8 *)spa + offset); - behavior->apply = SPLBehavior_ApplySpin; + behavior->applyFunc = SPLBehavior_ApplySpin; offset += sizeof(SPLSpinBehavior); behavior++; } if (flags.hasCollisionPlaneBehavior) { behavior->object = (const void *)((u8 *)spa + offset); - behavior->apply = SPLBehavior_ApplyCollisionPlane; + behavior->applyFunc = SPLBehavior_ApplyCollisionPlane; offset += sizeof(SPLCollisionPlaneBehavior); behavior++; } if (flags.hasConvergenceBehavior) { behavior->object = (const void *)((u8 *)spa + offset); - behavior->apply = SPLBehavior_ApplyConvergence; + behavior->applyFunc = SPLBehavior_ApplyConvergence; offset += sizeof(SPLConvergenceBehavior); } } else { diff --git a/src/unk_02014000.c b/src/unk_02014000.c index e45d088e4e..5f8c54969d 100644 --- a/src/unk_02014000.c +++ b/src/unk_02014000.c @@ -685,32 +685,32 @@ static const void *sub_020147B8(SPLEmitter *param0, int param1) switch (param1) { case SPL_FLD_TYPE_GRAVITY: - if (v2->apply == SPLBehavior_ApplyGravity) { + if (v2->applyFunc == SPLBehavior_ApplyGravity) { return v2->object; } continue; case SPL_FLD_TYPE_RANDOM: - if (v2->apply == SPLBehavior_ApplyRandom) { + if (v2->applyFunc == SPLBehavior_ApplyRandom) { return v2->object; } continue; case SPL_FLD_TYPE_MAGNET: - if (v2->apply == SPLBehavior_ApplyMagnet) { + if (v2->applyFunc == SPLBehavior_ApplyMagnet) { return v2->object; } continue; case SPL_FLD_TYPE_SPIN: - if (v2->apply == SPLBehavior_ApplySpin) { + if (v2->applyFunc == SPLBehavior_ApplySpin) { return v2->object; } continue; case SPL_FLD_TYPE_SIMPLE_COLL: - if (v2->apply == SPLBehavior_ApplyCollisionPlane) { + if (v2->applyFunc == SPLBehavior_ApplyCollisionPlane) { return v2->object; } break; case SPL_FLD_TYPE_CONVERGENCE: - if (v2->apply == SPLBehavior_ApplyConvergence) { + if (v2->applyFunc == SPLBehavior_ApplyConvergence) { return v2->object; } continue;