effect_soft_sprite matching! (#177)

This commit is contained in:
engineer124 2021-06-11 08:05:40 +10:00 committed by GitHub
parent d7fc053441
commit 059c9075ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 114 additions and 135 deletions

View File

@ -585,14 +585,14 @@ void EffectSS_Clear(GlobalContext* globalCtx);
EffectSs* EffectSS_GetTable(void);
void EffectSS_Delete(EffectSs* param_1);
void EffectSS_ResetEntry(EffectSs* particle);
s32 EffectSS_FindFreeSpace(u32 priority, u32* tableEntry);
s32 EffectSS_FindFreeSpace(s32 priority, s32* tableEntry);
void EffectSS_Copy(GlobalContext* globalCtx, EffectSs* particle);
void EffectSs_Spawn(GlobalContext* globalCtx, s32 type, s32 priority, void* initParams);
void EffectSS_UpdateParticle(GlobalContext* globalCtx, s32 index);
void EffectSS_UpdateAllParticles(GlobalContext* globalCtx);
void EffectSS_DrawParticle(GlobalContext* globalCtx, s32 index);
void EffectSS_DrawAllParticles(GlobalContext* globalCtx);
s32 func_800B096C(s16 param_1, s16 param_2, s32 param_3);
s16 func_800B096C(s16 param_1, s16 param_2, s32 param_3);
s16 func_800B09D0(s16 a0, s16 a1, f32 a2);
u8 func_800B0A24(u8 a0, u8 a1, f32 a2);
void EffectSs_DrawGEffect(GlobalContext* globalCtx, EffectSs* this, void* texture);
@ -3058,7 +3058,7 @@ void func_80169E6C(GlobalContext* globalCtx, s32 param_1, s32 param_2);
// void func_80169F78(void);
// void func_80169FDC(void);
// void func_80169FFC(void);
u32 func_8016A01C(GlobalContext* globalCtx);
s32 FrameAdvance_IsEnabled(GlobalContext* globalCtx);
// UNK_TYPE4 func_8016A02C(s32 param_1, s32 param_2, s16* param_3);
// void func_8016A0AC(void);
// void func_8016A168(void);

View File

@ -236,8 +236,8 @@ typedef struct {
/* 0x34 */ u8 type; // type0: start small, get big, fade away type1: start big, fade away
} EffectDustInit; // size = 0x35
typedef u32 (*EffectSsInitFunc)(struct GlobalContext* globalCtx, u32 index, struct EffectSs* effectSs, void* initParams);
typedef void(*EffectSsUpdateFunc)(struct GlobalContext* globalCtx, u32 index, struct EffectSs* particle);
typedef void(*EffectSsDrawFunc)(struct GlobalContext* globalCtx, u32 index, struct EffectSs* particle);
typedef struct EffectSs {
@ -264,7 +264,7 @@ typedef struct {
typedef struct {
/* 0x0 */ UNK_TYPE4 unk0;
/* 0x4 */ EffectSsDrawFunc init;
/* 0x4 */ EffectSsInitFunc init;
} ParticleOverlayInfo; // size = 0x8
typedef struct {

View File

@ -1108,7 +1108,7 @@ ColChkResetFunc sATResetFuncs[] = {
s32 CollisionCheck_SetAT(GlobalContext* globalCtx, CollisionCheckContext* colCtxt, Collider* collider) {
s32 index;
if (func_8016A01C(globalCtx)) {
if (FrameAdvance_IsEnabled(globalCtx)) {
return -1;
}
sATResetFuncs[collider->shape](globalCtx, collider);
@ -1134,7 +1134,7 @@ s32 CollisionCheck_SetAT(GlobalContext* globalCtx, CollisionCheckContext* colCtx
* will be inserted into the next slot.
*/
s32 CollisionCheck_SetAT_SAC(GlobalContext* globalCtx, CollisionCheckContext* colCtxt, Collider* collider, s32 index) {
if (func_8016A01C(globalCtx)) {
if (FrameAdvance_IsEnabled(globalCtx)) {
return -1;
}
sATResetFuncs[collider->shape](globalCtx, collider);
@ -1168,7 +1168,7 @@ ColChkResetFunc sACResetFuncs[] = {
s32 CollisionCheck_SetAC(GlobalContext* globalCtx, CollisionCheckContext* colCtxt, Collider* collider) {
s32 index;
if (func_8016A01C(globalCtx)) {
if (FrameAdvance_IsEnabled(globalCtx)) {
return -1;
}
sACResetFuncs[collider->shape](globalCtx, collider);
@ -1194,7 +1194,7 @@ s32 CollisionCheck_SetAC(GlobalContext* globalCtx, CollisionCheckContext* colCtx
* will be inserted into the next slot
*/
s32 CollisionCheck_SetAC_SAC(GlobalContext* globalCtx, CollisionCheckContext* colCtxt, Collider* collider, s32 index) {
if (func_8016A01C(globalCtx)) {
if (FrameAdvance_IsEnabled(globalCtx)) {
return -1;
}
sACResetFuncs[collider->shape](globalCtx, collider);
@ -1228,7 +1228,7 @@ ColChkResetFunc sOCResetFuncs[] = {
s32 CollisionCheck_SetOC(GlobalContext* globalCtx, CollisionCheckContext* colCtxt, Collider* collider) {
s32 index;
if (func_8016A01C(globalCtx)) {
if (FrameAdvance_IsEnabled(globalCtx)) {
return -1;
}
sOCResetFuncs[collider->shape](globalCtx, collider);
@ -1254,7 +1254,7 @@ s32 CollisionCheck_SetOC(GlobalContext* globalCtx, CollisionCheckContext* colCtx
* will be inserted into the next slot.
*/
s32 CollisionCheck_SetOC_SAC(GlobalContext* globalCtx, CollisionCheckContext* colCtxt, Collider* collider, s32 index) {
if (func_8016A01C(globalCtx)) {
if (FrameAdvance_IsEnabled(globalCtx)) {
return -1;
}
sOCResetFuncs[collider->shape](globalCtx, collider);
@ -1286,7 +1286,7 @@ s32 CollisionCheck_SetOC_SAC(GlobalContext* globalCtx, CollisionCheckContext* co
s32 CollisionCheck_SetOCLine(GlobalContext* globalCtx, CollisionCheckContext* colCtxt, OcLine* line) {
s32 index;
if (func_8016A01C(globalCtx)) {
if (FrameAdvance_IsEnabled(globalCtx)) {
return -1;
}

View File

@ -125,7 +125,7 @@ void Effect_Add(GlobalContext* globalCtx, s32* index, s32 type, u8 param_4, u8 p
*index = TOTAL_EFFECT_COUNT;
common = NULL;
if (func_8016A01C(globalCtx) != 1) {
if (FrameAdvance_IsEnabled(globalCtx) != true) {
slotFound = 0;
switch (type) {
case 0:

View File

@ -3,26 +3,28 @@
void EffectSS_Init(GlobalContext* globalCtx, s32 numEntries) {
u32 i;
EffectSs* iter;
ParticleOverlay* iter2;
EffectSs* effectsSs;
ParticleOverlay* overlay;
EffectSS2Info.data_table = (EffectSs*)THA_AllocEndAlign16(&globalCtx->state.heap, numEntries * sizeof(EffectSs));
EffectSS2Info.searchIndex = 0;
EffectSS2Info.size = numEntries;
for (iter = EffectSS2Info.data_table; iter < EffectSS2Info.data_table + EffectSS2Info.size; iter++) {
EffectSS_ResetEntry(iter);
for (effectsSs = &EffectSS2Info.data_table[0]; effectsSs < &EffectSS2Info.data_table[EffectSS2Info.size]; effectsSs++) {
EffectSS_ResetEntry(effectsSs);
}
for (i = 0, iter2 = particleOverlayTable; i != EFFECT_SS2_TYPE_LAST_LABEL; i++) {
(iter2++)->loadedRamAddr = 0;
overlay = &particleOverlayTable[0];
for (i = 0; i < EFFECT_SS2_TYPE_LAST_LABEL; i++) {
overlay->loadedRamAddr = NULL;
overlay++;
}
}
void EffectSS_Clear(GlobalContext* globalCtx) {
u32 i;
EffectSs* iter;
ParticleOverlay* iter2;
EffectSs* effectsSs;
ParticleOverlay* overlay;
void* addr;
EffectSS2Info.data_table = NULL;
@ -30,17 +32,20 @@ void EffectSS_Clear(GlobalContext* globalCtx) {
EffectSS2Info.size = 0;
// This code is completely useless, as data_table was just set to NULL and size to 0
for (iter = EffectSS2Info.data_table; iter < EffectSS2Info.data_table + EffectSS2Info.size; iter++) {
EffectSS_Delete(iter);
for (effectsSs = EffectSS2Info.data_table; effectsSs < EffectSS2Info.data_table + EffectSS2Info.size; effectsSs++) {
EffectSS_Delete(effectsSs);
}
// Free memory from loaded particle overlays
for (i = 0, iter2 = particleOverlayTable; i != EFFECT_SS2_TYPE_LAST_LABEL; i++) {
addr = (void*)iter2->loadedRamAddr;
overlay = &particleOverlayTable[0];
for (i = 0; i < EFFECT_SS2_TYPE_LAST_LABEL; i++) {
addr = overlay->loadedRamAddr;
if (addr != NULL) {
zelda_free(addr);
}
(iter2++)->loadedRamAddr = 0;
overlay->loadedRamAddr = 0;
overlay++;
}
}
@ -48,34 +53,26 @@ EffectSs* EffectSS_GetTable() {
return EffectSS2Info.data_table;
}
void EffectSS_Delete(EffectSs* a0) {
if (a0->flags & 0x2) {
func_801A72CC((UNK_PTR)&a0->pos);
void EffectSS_Delete(EffectSs* effectSs) {
if (effectSs->flags & 2) {
func_801A72CC(&effectSs->pos);
}
if (a0->flags & 0x4) {
func_801A72CC((UNK_PTR)&a0->vec);
if (effectSs->flags & 4) {
func_801A72CC(&effectSs->vec);
}
EffectSS_ResetEntry(a0);
EffectSS_ResetEntry(effectSs);
}
void EffectSS_ResetEntry(EffectSs* particle) {
u32 i;
particle->type = EFFECT_SS2_TYPE_LAST_LABEL;
particle->accel.z = 0;
particle->accel.y = 0;
particle->accel.x = 0;
particle->velocity.z = 0;
particle->velocity.y = 0;
particle->velocity.x = 0;
particle->vec.z = 0;
particle->vec.y = 0;
particle->vec.x = 0;
particle->pos.z = 0;
particle->pos.y = 0;
particle->pos.x = 0;
particle->accel.x = particle->accel.y = particle->accel.z = 0;
particle->velocity.x = particle->velocity.y = particle->velocity.z = 0;
particle->vec.x = particle->vec.y = particle->vec.z = 0;
particle->pos.x = particle->pos.y = particle->pos.z = 0;
particle->life = -1;
particle->flags = 0;
particle->priority = 128;
@ -84,134 +81,128 @@ void EffectSS_ResetEntry(EffectSs* particle) {
particle->gfx = NULL;
particle->actor = NULL;
for (i = 0; i != ARRAY_COUNT(particle->regs); i++) {
for (i = 0; i < ARRAY_COUNT(particle->regs); i++) {
particle->regs[i] = 0;
}
}
// XXX Some regalloc differences and instruction ordering
#ifdef NON_MATCHING
s32 EffectSS_FindFreeSpace(u32 priority, u32* tableEntry) {
s32 ret = 0;
s32 EffectSS_FindFreeSpace(s32 priority, s32* tableEntry) {
s32 foundFree;
s32 i;
if (EffectSS2Info.size <= EffectSS2Info.searchIndex) {
if (EffectSS2Info.searchIndex >= EffectSS2Info.size) {
EffectSS2Info.searchIndex = 0;
}
// Search for a unused entry
for (i = EffectSS2Info.searchIndex;;) {
i = EffectSS2Info.searchIndex;
foundFree = false;
while(true) {
if (EffectSS2Info.data_table[i].life == -1) {
ret = 1;
foundFree = true;
break;
}
i += 1;
i++;
if (EffectSS2Info.size <= i) {
i = 0;
if (i >= EffectSS2Info.size) {
i = 0; // Loop around the whole table
}
// After a full loop, break out
if (i == EffectSS2Info.searchIndex) {
break;
}
}
if (ret == 1) {
ret = 0;
} else {
// If the entire table is full, look for a lower priority entry instead
for (;;) {
if (priority <= EffectSS2Info.data_table[i].priority &&
(priority != EffectSS2Info.data_table[i].priority || (EffectSS2Info.data_table[i].flags & 0x1) == 0)) {
ret = 0;
if (foundFree == true) {
*tableEntry = i;
return false;
}
// If all slots are in use, search for a slot with a lower priority
// Note that a lower priority is representend by a higher value
i = EffectSS2Info.searchIndex;
while(true) {
// Equal priority should only be considered "lower" if flag 0 is set
if ((priority <= EffectSS2Info.data_table[i].priority) &&
!((priority == EffectSS2Info.data_table[i].priority) && (EffectSS2Info.data_table[i].flags & 1))) {
break;
}
i += 1;
i++;
if (EffectSS2Info.size <= i) {
i = 0;
if (i >= EffectSS2Info.size) {
i = 0; // Loop around the whole table
}
// After a full loop, return 1 to indicate that we failed to find a suitable slot
if (i == EffectSS2Info.searchIndex) {
ret = 1;
return ret;
}
return true;
}
}
*tableEntry = i;
return ret;
return false;
}
#else
#pragma GLOBAL_ASM("./asm/non_matchings/code/z_effect_soft_sprite/EffectSS_FindFreeSpace.asm")
#endif
void EffectSS_Copy(GlobalContext* globalCtx, EffectSs* a1) {
u32 index;
if (func_8016A01C(globalCtx) != 1) {
if (EffectSS_FindFreeSpace(a1->priority, &index) == 0) {
void EffectSS_Copy(GlobalContext* globalCtx, EffectSs* effectsSs) {
s32 index;
if (FrameAdvance_IsEnabled(globalCtx) != true) {
if (EffectSS_FindFreeSpace(effectsSs->priority, &index) == 0) {
EffectSS2Info.searchIndex = index + 1;
EffectSS2Info.data_table[index] = *a1;
EffectSS2Info.data_table[index] = *effectsSs;
}
}
}
#ifdef NON_MATCHING
void EffectSs_Spawn(GlobalContext* globalCtx, s32 type, s32 priority, void* initData) {
u32 index;
u32 initRet;
s32 index;
u32 overlaySize;
ParticleOverlayInfo* overlayInfo;
ParticleOverlay* entry = &particleOverlayTable[type];
ParticleOverlayInfo* overlayInfo;
if (EffectSS_FindFreeSpace(priority, &index) != 0) {
// Abort because we couldn't find a suitable slot to add this effect in
return;
}
EffectSS2Info.searchIndex = index + 1;
if (entry->vramStart == 0) {
overlaySize = (u32)entry->vramEnd - (u32)entry->vramStart;
if (entry->vramStart == NULL) {
overlayInfo = entry->overlayInfo;
} else {
// XXX this subtraction is done earlier
overlaySize = entry->vramEnd - entry->vramStart;
if (entry->loadedRamAddr == 0) {
entry->loadedRamAddr = (u32)zelda_mallocR(overlaySize);
if (entry->loadedRamAddr == NULL) {
entry->loadedRamAddr = zelda_mallocR(overlaySize);
if (entry->loadedRamAddr == 0) {
if (entry->loadedRamAddr == NULL) {
return;
}
load_and_relocate_overlay(entry->vromStart, entry->vromEnd, entry->vramStart, entry->vramEnd,
Load2_LoadOverlay(entry->vromStart, entry->vromEnd, entry->vramStart, entry->vramEnd,
entry->loadedRamAddr);
}
// XXX this should use a0, but it doesn't
if (entry->overlayInfo != NULL) {
overlayInfo = (ParticleOverlayInfo*)(-(entry->vramStart - entry->loadedRamAddr) + (u32)entry->overlayInfo);
} else {
overlayInfo = NULL;
}
overlayInfo = (void*)(u32)(entry->overlayInfo != NULL
? (ParticleOverlayInfo*)(-((u32)entry->vramStart - (u32)entry->loadedRamAddr) +
(u32)entry->overlayInfo)
: NULL);
}
if (overlayInfo->init != 0) {
if (overlayInfo->init != NULL) {
// Delete the previous effect in the slot, in case the slot wasn't free
EffectSS_Delete(&EffectSS2Info.data_table[index]);
EffectSS2Info.data_table[index].type = type;
EffectSS2Info.data_table[index].priority = priority;
initRet = (*overlayInfo->init)(globalCtx, index, &EffectSS2Info.data_table[index], initData);
if (initRet == 0) {
if (overlayInfo->init(globalCtx, index, &EffectSS2Info.data_table[index], initData) == 0) {
EffectSS_ResetEntry(&EffectSS2Info.data_table[index]);
}
}
}
#else
#pragma GLOBAL_ASM("./asm/non_matchings/code/z_effect_soft_sprite/EffectSs_Spawn.asm")
#endif
void EffectSS_UpdateParticle(GlobalContext* globalCtx, s32 index) {
EffectSs* particle = &EffectSS2Info.data_table[index];
@ -249,24 +240,24 @@ void EffectSS_UpdateAllParticles(GlobalContext* globalCtx) {
void EffectSS_DrawParticle(GlobalContext* globalCtx, s32 index) {
EffectSs* entry = &EffectSS2Info.data_table[index];
if (entry->draw != 0) {
if (entry->draw != NULL) {
entry->draw(globalCtx, index, entry);
}
}
void EffectSS_DrawAllParticles(GlobalContext* globalCtx) {
Lights* s0;
Lights* lights = LightContext_NewLights(&globalCtx->lightCtx, globalCtx->state.gfxCtx);
s32 i;
s0 = LightContext_NewLights(&globalCtx->lightCtx, globalCtx->state.gfxCtx);
Lights_BindAll(s0, globalCtx->lightCtx.listHead, 0, globalCtx);
Lights_Draw(s0, globalCtx->state.gfxCtx);
Lights_BindAll(lights, globalCtx->lightCtx.listHead, NULL, globalCtx);
Lights_Draw(lights, globalCtx->state.gfxCtx);
for (i = 0; i < EffectSS2Info.size; i++) {
if (EffectSS2Info.data_table[i].life > -1) {
if (EffectSS2Info.data_table[i].pos.x > 32000 || EffectSS2Info.data_table[i].pos.x < -32000 ||
EffectSS2Info.data_table[i].pos.y > 32000 || EffectSS2Info.data_table[i].pos.y < -32000 ||
EffectSS2Info.data_table[i].pos.z > 32000 || EffectSS2Info.data_table[i].pos.z < -32000) {
if ((EffectSS2Info.data_table[i].pos.x > 32000.0f) || (EffectSS2Info.data_table[i].pos.x < -32000.0f) ||
(EffectSS2Info.data_table[i].pos.y > 32000.0f) || (EffectSS2Info.data_table[i].pos.y < -32000.0f) ||
(EffectSS2Info.data_table[i].pos.z > 32000.0f) || (EffectSS2Info.data_table[i].pos.z < -32000.0f)) {
EffectSS_Delete(&EffectSS2Info.data_table[i]);
} else {
EffectSS_DrawParticle(globalCtx, i);
@ -275,27 +266,15 @@ void EffectSS_DrawAllParticles(GlobalContext* globalCtx) {
}
}
#ifdef NON_MATCHING
s16 func_800B096C(s16 a0, s16 a1, s32 a2) {
s16 ret;
if (a2 == 0) {
ret = a1;
} else {
// XXX result of the division is put in t0 instead of t8
ret = a0 + (s16)((a1 - a0) / (f32)a2);
}
s16 func_800B096C(s16 arg0, s16 arg1, s32 arg2) {
s16 ret = (arg2 == 0) ? arg1 : arg0 + (s32)((arg1 - arg0) / (f32)arg2);
return ret;
}
#else
#pragma GLOBAL_ASM("./asm/non_matchings/code/z_effect_soft_sprite/func_800B096C.asm")
#endif
s16 func_800B09D0(s16 a0, s16 a1, f32 a2) {
return a2 * (a1 - a0) + a0;
s16 func_800B09D0(s16 arg0, s16 arg1, f32 arg2) {
return arg2 * (arg1 - arg0) + arg0;
}
u8 func_800B0A24(u8 a0, u8 a1, f32 a2) {
return a2 * ((f32)a1 - (f32)a0) + a0;
u8 func_800B0A24(u8 arg0, u8 arg1, f32 arg2) {
return arg2 * ((f32)arg1 - (f32)arg0) + arg0;
}

View File

@ -52,7 +52,7 @@ void func_8096B104(EnOkarinaEffect* this, GlobalContext* globalCtx) {
void func_8096B174(EnOkarinaEffect* this, GlobalContext* globalCtx) {
DECR(this->unk144);
if (!globalCtx->unk16D30.unk1EC && !globalCtx->unk17000 && !globalCtx->msgCtx.unk11F10 &&
!func_8016A01C(globalCtx) && this->unk144 == 0) {
!FrameAdvance_IsEnabled(globalCtx) && this->unk144 == 0) {
EnOkarinaEffect_SetupAction(this, func_8096B1FC);
}
}

View File

@ -3042,7 +3042,7 @@
0x80169F78:("func_80169F78",),
0x80169FDC:("func_80169FDC",),
0x80169FFC:("func_80169FFC",),
0x8016A01C:("func_8016A01C",),
0x8016A01C:("FrameAdvance_IsEnabled",),
0x8016A02C:("func_8016A02C",),
0x8016A0AC:("func_8016A0AC",),
0x8016A168:("func_8016A168",),