From 1e03e13b374f2bd26e761f24959c3260c82fa73d Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Mon, 27 Feb 2023 19:56:04 -0300 Subject: [PATCH] `z_eff_footmark` cleanup (#1180) * z64eff_footmark.h * arraycount and other clenaups * flag * extract data * gEffFootprints * singular * minor cleanup * review * pos * mf * format --- assets/xml/code/debug_display.xml | 2 +- assets/xml/code/eff_footmark.xml | 9 +++ include/functions.h | 4 -- include/variables.h | 3 - include/z64.h | 18 +----- include/z64eff_footmark.h | 33 +++++++++++ spec | 1 - src/code/z_eff_footmark.c | 93 ++++++++++++++++--------------- tools/disasm/variables.txt | 6 +- 9 files changed, 96 insertions(+), 73 deletions(-) create mode 100644 assets/xml/code/eff_footmark.xml create mode 100644 include/z64eff_footmark.h diff --git a/assets/xml/code/debug_display.xml b/assets/xml/code/debug_display.xml index c8ac659bcf..7a25bbd0c6 100644 --- a/assets/xml/code/debug_display.xml +++ b/assets/xml/code/debug_display.xml @@ -4,7 +4,7 @@ - + diff --git a/assets/xml/code/eff_footmark.xml b/assets/xml/code/eff_footmark.xml new file mode 100644 index 0000000000..2fae1fe16b --- /dev/null +++ b/assets/xml/code/eff_footmark.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/include/functions.h b/include/functions.h index 70114cb1f2..863cf50fa3 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1256,10 +1256,6 @@ u8 Cutscene_IsPlaying(PlayState* play); void GetItem_Draw(PlayState* play, s16 drawId); -void EffFootmark_Init(PlayState* play); -void EffFootmark_Add(PlayState* play, MtxF* displayMatrix, Actor* actor, u8 id, Vec3f* location, u16 size, u8 red, u8 green, u8 blue, u16 alpha, u16 alphaChange, u16 fadeoutDelay); -void EffFootmark_Update(PlayState* play); -void EffFootmark_Draw(PlayState* play); void SoundSource_InitAll(PlayState* play); void SoundSource_UpdateAll(PlayState* play); void SoundSource_PlaySfxAtFixedWorldPos(PlayState* play, Vec3f* worldPos, u32 duration, u16 sfxId); diff --git a/include/variables.h b/include/variables.h index 257fbfeb78..a5752eb7f7 100644 --- a/include/variables.h +++ b/include/variables.h @@ -479,9 +479,6 @@ extern EffectShieldParticleInit shieldParticleInitWood; extern u8 D_801BB12C; -// extern UNK_TYPE1 D_801BC210; -extern Gfx D_801BC240[9]; -extern Gfx D_801BC288[3]; // extern UNK_TYPE1 D_801BC41E; extern ActorCutscene actorCutscenesGlobalCutscenes[8]; extern s16 actorCutsceneCurrent; diff --git a/include/z64.h b/include/z64.h index e168bedbc8..9069dc819a 100644 --- a/include/z64.h +++ b/include/z64.h @@ -34,6 +34,7 @@ #include "z64curve.h" #include "z64cutscene.h" #include "z64dma.h" +#include "z64eff_footmark.h" #include "z64effect.h" #include "z64interface.h" #include "z64item.h" @@ -712,23 +713,6 @@ typedef struct { /* 0x130 */ OSThread thread; } AudioMgr; // size = 0x2E0 -typedef struct { - /* 0x00 */ MtxF displayMatrix; - /* 0x40 */ Actor* actor; - /* 0x44 */ Vec3f location; - /* 0x50 */ u8 flags; // bit 0 - footmark fades out - /* 0x51 */ u8 id; - /* 0x52 */ u8 red; - /* 0x53 */ u8 blue; - /* 0x54 */ u8 green; - /* 0x55 */ UNK_TYPE1 pad55[0x1]; - /* 0x56 */ u16 alpha; - /* 0x58 */ u16 alphaChange; - /* 0x5A */ u16 size; - /* 0x5C */ u16 fadeoutDelay; - /* 0x5E */ u16 age; -} EffFootmark; // size = 0x60 - typedef struct FireObj { /* 0x00 */ Vec3f position; /* 0x0C */ f32 size; diff --git a/include/z64eff_footmark.h b/include/z64eff_footmark.h new file mode 100644 index 0000000000..6d5fe3026a --- /dev/null +++ b/include/z64eff_footmark.h @@ -0,0 +1,33 @@ +#ifndef Z64EFF_FOOTMARK_H +#define Z64EFF_FOOTMARK_H + +#include "ultra64.h" +#include "z64math.h" + +struct PlayState; +struct Actor; + +typedef struct EffFootmark { + /* 0x00 */ MtxF mf; + /* 0x40 */ struct Actor* actor; + /* 0x44 */ Vec3f pos; + /* 0x50 */ u8 flags; // bit 0 - footmark fades out + /* 0x51 */ u8 id; + /* 0x52 */ u8 red; + /* 0x53 */ u8 blue; + /* 0x54 */ u8 green; + /* 0x56 */ u16 alpha; + /* 0x58 */ u16 alphaChange; + /* 0x5A */ u16 size; + /* 0x5C */ u16 fadeOutDelay; + /* 0x5E */ u16 age; +} EffFootmark; // size = 0x60 + +#define FOOTMARK_FLAG_1 (1 << 0) + +void EffFootmark_Init(struct PlayState* play); +void EffFootmark_Add(struct PlayState* play, MtxF* mf, struct Actor* actor, u8 id, Vec3f* pos, u16 size, u8 red, u8 green, u8 blue, u16 alpha, u16 alphaChange, u16 fadeOutDelay); +void EffFootmark_Update(struct PlayState* play); +void EffFootmark_Draw(struct PlayState* play); + +#endif diff --git a/spec b/spec index df74629c33..9a9deb9505 100644 --- a/spec +++ b/spec @@ -463,7 +463,6 @@ beginseg include "build/src/code/z_demo.o" include "build/src/code/z_draw.o" include "build/src/code/z_eff_footmark.o" - include "build/data/code/z_eff_footmark.data.o" include "build/src/code/z_sound_source.o" include "build/src/code/z_elf_message.o" include "build/src/code/z_en_hy_code.o" diff --git a/src/code/z_eff_footmark.c b/src/code/z_eff_footmark.c index 1dc3d72373..bcf6ff8241 100644 --- a/src/code/z_eff_footmark.c +++ b/src/code/z_eff_footmark.c @@ -1,14 +1,19 @@ -#include "global.h" +#include "z64eff_footmark.h" +#include "z64.h" +#include "macros.h" +#include "functions.h" + +#include "assets/code/eff_footmark/eff_footmark.c" void EffFootmark_Init(PlayState* play) { EffFootmark* footmark; s32 i; - for (footmark = play->footprintInfo, i = 0; i < 100; i++, footmark++) { + for (footmark = play->footprintInfo, i = 0; i < ARRAY_COUNT(play->footprintInfo); i++, footmark++) { footmark->actor = NULL; - footmark->location.x = 0; - footmark->location.y = 0; - footmark->location.z = 0; + footmark->pos.x = 0; + footmark->pos.y = 0; + footmark->pos.z = 0; footmark->flags = 0; footmark->id = 0; footmark->alpha = 0; @@ -16,47 +21,45 @@ void EffFootmark_Init(PlayState* play) { } } -void EffFootmark_Add(PlayState* play, MtxF* displayMatrix, Actor* actor, u8 id, Vec3f* location, u16 size, u8 red, - u8 green, u8 blue, u16 alpha, u16 alphaChange, u16 fadeoutDelay) { +void EffFootmark_Add(PlayState* play, MtxF* mf, Actor* actor, u8 id, Vec3f* pos, u16 size, u8 red, u8 green, u8 blue, + u16 alpha, u16 alphaChange, u16 fadeOutDelay) { s32 i; EffFootmark* footmark; EffFootmark* destination = NULL; EffFootmark* oldest = NULL; - s32 isNew = 1; + s32 isNew = true; - for (footmark = play->footprintInfo, i = 0; i < 100; i++, footmark++) { - if (((actor == footmark->actor) && (footmark->id == id)) && ((footmark->flags & 1) == 0)) { - if (fabsf((footmark->location).x - location->x) <= 1) { - if (fabsf((footmark->location).z - location->z) <= 1) { - isNew = 0; + for (footmark = play->footprintInfo, i = 0; i < ARRAY_COUNT(play->footprintInfo); i++, footmark++) { + if (((actor == footmark->actor) && (footmark->id == id)) && !(footmark->flags & FOOTMARK_FLAG_1)) { + if (fabsf(footmark->pos.x - pos->x) <= 1) { + if (fabsf(footmark->pos.z - pos->z) <= 1) { + isNew = false; break; } } - // This footmark is being re-added at a new location. Let's mark this one to start fading out. - footmark->flags = 1; + // This footmark is being re-added at a new pos. Let's mark this one to start fading out. + footmark->flags = FOOTMARK_FLAG_1; } if (footmark->actor == NULL) { destination = footmark; - } else { - if (destination == NULL) { - if ((oldest != NULL && footmark->age > oldest->age) || (oldest == NULL)) { - oldest = footmark; - } + } else if (destination == NULL) { + if (((oldest != NULL) && (footmark->age > oldest->age)) || (oldest == NULL)) { + oldest = footmark; } } } - if ((isNew) && ((destination != NULL || (oldest != NULL)))) { + if (isNew && ((destination != NULL) || (oldest != NULL))) { if (destination == NULL) { destination = oldest; } - Matrix_MtxFCopy(&destination->displayMatrix, displayMatrix); + Matrix_MtxFCopy(&destination->mf, mf); destination->actor = actor; - destination->location.x = location->x; - destination->location.y = location->y; - destination->location.z = location->z; + destination->pos.x = pos->x; + destination->pos.y = pos->y; + destination->pos.z = pos->z; destination->flags = 0; destination->id = id; destination->red = red; @@ -65,7 +68,7 @@ void EffFootmark_Add(PlayState* play, MtxF* displayMatrix, Actor* actor, u8 id, destination->alpha = alpha; destination->alphaChange = alphaChange; destination->size = size; - destination->fadeoutDelay = fadeoutDelay; + destination->fadeOutDelay = fadeOutDelay; destination->age = 0; } } @@ -74,22 +77,24 @@ void EffFootmark_Update(PlayState* play) { EffFootmark* footmark; s32 i; - for (footmark = play->footprintInfo, i = 0; i < 100; i++, footmark++) { - if (footmark->actor != NULL) { - if ((footmark->flags & 1) == 1) { - if ((u32)footmark->age < UINT16_MAX) { - footmark->age++; - } + for (footmark = play->footprintInfo, i = 0; i < ARRAY_COUNT(play->footprintInfo); i++, footmark++) { + if (footmark->actor == NULL) { + continue; + } - if (footmark->fadeoutDelay == 0) { - if (footmark->alpha >= footmark->alphaChange + 0x1000) { - footmark->alpha -= footmark->alphaChange; - } else { - footmark->actor = NULL; - } - } else if (footmark->fadeoutDelay > 0) { - footmark->fadeoutDelay--; + if (CHECK_FLAG_ALL(footmark->flags, FOOTMARK_FLAG_1)) { + if ((u32)footmark->age < UINT16_MAX) { + footmark->age++; + } + + if (footmark->fadeOutDelay == 0) { + if (footmark->alpha >= footmark->alphaChange + 0x1000) { + footmark->alpha -= footmark->alphaChange; + } else { + footmark->actor = NULL; } + } else if (footmark->fadeOutDelay > 0) { + footmark->fadeOutDelay--; } } } @@ -102,11 +107,11 @@ void EffFootmark_Draw(PlayState* play) { func_8012C448(play->state.gfxCtx); - gSPDisplayList(gfxCtx->polyXlu.p++, D_801BC240); + gSPDisplayList(gfxCtx->polyXlu.p++, gEffFootprintMaterialDL); - for (footmark = play->footprintInfo, i = 0; i < 100; i++, footmark++) { + for (footmark = play->footprintInfo, i = 0; i < ARRAY_COUNT(play->footprintInfo); i++, footmark++) { if (footmark->actor != NULL) { - Matrix_Put(&footmark->displayMatrix); + Matrix_Put(&footmark->mf); Matrix_Scale(footmark->size * (1.0f / 0x100) * 0.7f, 1, footmark->size * (1.0f / 0x100), MTXMODE_APPLY); gSPMatrix(gfxCtx->polyXlu.p++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD); @@ -114,7 +119,7 @@ void EffFootmark_Draw(PlayState* play) { gDPSetPrimColor(gfxCtx->polyXlu.p++, 0, 0, footmark->red, footmark->green, footmark->blue, footmark->alpha >> 8); - gSPDisplayList(gfxCtx->polyXlu.p++, D_801BC288); + gSPDisplayList(gfxCtx->polyXlu.p++, gEffFootprintModelDL); } } } diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index 4167de4b92..b07e060c0b 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -927,9 +927,9 @@ 0x801BB15C:("D_801BB15C","UNK_TYPE2","",0x2), 0x801BB160:("D_801BB160","UNK_TYPE4","",0x4), 0x801BB170:("sDrawItemTable","DrawItemTableEntry","[118]",0x1098), - 0x801BC210:("D_801BC210","UNK_TYPE1","",0x1), - 0x801BC240:("D_801BC240","Gfx","[9]",0x48), - 0x801BC288:("D_801BC288","Gfx","[3]",0x18), + 0x801BC210:("gEffFootprintVtx","UNK_TYPE1","",0x1), + 0x801BC240:("gEffFootprintMaterialDL","Gfx","[9]",0x48), + 0x801BC288:("gEffFootprintModelDL","Gfx","[3]",0x18), 0x801BC2A0:("D_801BC2A0","UNK_TYPE1","",0x1), 0x801BC3F0:("gEnHyBodyParts","UNK_TYPE1","",0x1), 0x801BC400:("gEnHyParentBodyParts","UNK_TYPE1","",0x1),