1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-13 12:59:59 +00:00
oot/src/code/z_effect_soft_sprite.c

140 lines
3.8 KiB
C
Raw Normal View History

2020-03-17 04:31:30 +00:00
#include <ultra64.h>
#include <global.h>
extern ParticleOverlay sParticleOverlayTable[37];
void Effect_SS_Delete(LoadedParticleEntry* particle);
#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite/func_800272B0.s")
2020-03-22 21:19:43 +00:00
void Effect_SS_Clear(GlobalContext* globalCtx) {
2020-03-17 04:31:30 +00:00
u32 i;
LoadedParticleEntry* iter;
ParticleOverlay* iter2;
void* addr;
EffectSS2Info.data_table = NULL;
EffectSS2Info.searchIndex = 0;
EffectSS2Info.size = 0;
2020-03-22 21:19:43 +00:00
for (iter = EffectSS2Info.data_table; iter < EffectSS2Info.data_table + EffectSS2Info.size; iter++) {
2020-03-17 04:31:30 +00:00
Effect_SS_Delete(iter);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
// Free memory from loaded particle overlays
iter2 = &sParticleOverlayTable[0];
2020-03-22 21:19:43 +00:00
for (i = 0; i < ARRAY_COUNT(sParticleOverlayTable); i++) {
2020-03-17 04:31:30 +00:00
addr = iter2->loadedRamAddr;
2020-03-22 21:19:43 +00:00
if (addr != NULL) {
2020-03-17 04:31:30 +00:00
ZeldaArena_FreeDebug(addr, D_801357DC, 337);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
(iter2++)->loadedRamAddr = NULL;
}
}
2020-03-22 21:19:43 +00:00
void Effect_SS_Delete(LoadedParticleEntry* particle) {
if (particle->flags & 2) {
func_800F89E8(&particle->position);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
if (particle->flags & 4) {
2020-03-17 04:31:30 +00:00
func_800F89E8(&particle->unk_2C);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
Effect_SS_ResetEntry(particle);
}
2020-03-22 21:19:43 +00:00
void Effect_SS_ResetEntry(LoadedParticleEntry* particle) {
2020-03-17 04:31:30 +00:00
u32 i;
particle->type = 0x25;
particle->acceleration.z = 0;
particle->acceleration.y = 0;
particle->acceleration.x = 0;
particle->velocity.z = 0;
particle->velocity.y = 0;
particle->velocity.x = 0;
particle->unk_34 = 0;
particle->unk_30 = 0;
particle->unk_2C = 0;
particle->position.z = 0;
particle->position.y = 0;
particle->position.x = 0;
particle->life = -1;
particle->flags = 0;
particle->priority = 128;
particle->draw = NULL;
particle->update = NULL;
particle->unk_38 = 0;
particle->unk_3C = 0;
2020-03-22 21:19:43 +00:00
for (i = 0; i != 13; i++) {
2020-03-17 04:31:30 +00:00
particle->unk_40[i] = 0;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite/func_800275D0.s")
#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite/func_80027704.s")
#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite/func_80027798.s")
2020-03-22 21:19:43 +00:00
void Effect_SS_UpdateParticle(GlobalContext* globalCtx, s32 index) {
2020-03-17 04:31:30 +00:00
LoadedParticleEntry* particle = &EffectSS2Info.data_table[index];
2020-03-22 21:19:43 +00:00
if (particle->update != NULL) {
2020-03-17 04:31:30 +00:00
particle->velocity.x += particle->acceleration.x;
particle->velocity.y += particle->acceleration.y;
particle->velocity.z += particle->acceleration.z;
particle->position.x += particle->velocity.x;
particle->position.y += particle->velocity.y;
particle->position.z += particle->velocity.z;
particle->update(globalCtx, index, particle);
}
}
2020-03-22 21:19:43 +00:00
void Effect_SS_UpdateAllParticles(GlobalContext* globalCtx) {
2020-03-17 04:31:30 +00:00
s32 i;
2020-03-22 21:19:43 +00:00
for (i = 0; i < EffectSS2Info.size; i++) {
if (EffectSS2Info.data_table[i].life > -1) {
2020-03-17 04:31:30 +00:00
EffectSS2Info.data_table[i].life--;
2020-03-22 21:19:43 +00:00
if (EffectSS2Info.data_table[i].life < 0) {
2020-03-17 04:31:30 +00:00
Effect_SS_Delete(&EffectSS2Info.data_table[i]);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
2020-03-22 21:19:43 +00:00
if (EffectSS2Info.data_table[i].life > -1) {
2020-03-17 04:31:30 +00:00
Effect_SS_UpdateParticle(globalCtx, i);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
}
2020-03-22 21:19:43 +00:00
void Effect_SS_DrawParticle(GlobalContext* globalCtx, s32 index) {
2020-03-17 04:31:30 +00:00
LoadedParticleEntry* particle = &EffectSS2Info.data_table[index];
2020-03-22 21:19:43 +00:00
if (particle->draw != NULL) {
2020-03-17 04:31:30 +00:00
particle->draw(globalCtx, index, particle);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect_soft_sprite/func_80027BDC.s")
2020-03-22 21:19:43 +00:00
s16 func_80027DD4(s16 arg0, s16 arg1, s32 arg2) {
s16 ret = !arg2 ? arg1 : (arg0 + (s32)((f32)(arg1 - arg0) / arg2));
2020-03-17 04:31:30 +00:00
return ret;
}
2020-03-22 21:19:43 +00:00
s16 func_80027E34(s16 a0, s16 a1, f32 a2) {
2020-03-17 04:31:30 +00:00
return (a1 - a0) * a2 + a0;
}
2020-03-22 21:19:43 +00:00
u8 func_80027E84(u8 a0, u8 a1, f32 a2) {
2020-03-17 04:31:30 +00:00
return a2 * ((f32)a1 - (f32)a0) + a0;
}