z_eff_footmark cleanup (#1180)

* z64eff_footmark.h

* arraycount and other clenaups

* flag

* extract data

* gEffFootprints

* singular

* minor cleanup

* review

* pos

* mf

* format
This commit is contained in:
Anghelo Carvajal 2023-02-27 19:56:04 -03:00 committed by GitHub
parent 2080f9906f
commit 1e03e13b37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 96 additions and 73 deletions

View File

@ -4,7 +4,7 @@
<Vtx/>
</Array>
<DList Name="sDebugDisplay1DL" Offset="0x114CD0"/>
<Array Name="sDebugDisplay2Vtx" Count="8" Offset="0x114D30">
<Vtx/>
</Array>

View File

@ -0,0 +1,9 @@
<Root>
<File Name="code" BaseAddress="0x800A5AC0" RangeStart="0x116750" RangeEnd="0x1167E0" OutName="eff_footmark">
<Array Name="gEffFootprintVtx" Count="3" Offset="0x116750">
<Vtx/>
</Array>
<DList Name="gEffFootprintMaterialDL" Offset="0x116780"/>
<DList Name="gEffFootprintModelDL" Offset="0x1167C8"/>
</File>
</Root>

View File

@ -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);

View File

@ -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;

View File

@ -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;

33
include/z64eff_footmark.h Normal file
View File

@ -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

1
spec
View File

@ -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"

View File

@ -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);
}
}
}

View File

@ -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),