diff --git a/linker_scripts/code_script.txt b/linker_scripts/code_script.txt index 5a16650154..8664b78bbf 100644 --- a/linker_scripts/code_script.txt +++ b/linker_scripts/code_script.txt @@ -1043,14 +1043,8 @@ SECTIONS { build/src/overlays/actors/ovl_En_Niw/z_en_niw.o(.text) build/src/overlays/actors/ovl_En_Niw/z_en_niw.o(.data) -#ifdef NON_EQUIVALENT - build/src/overlays/actors/ovl_En_Niw_rodata_overlay.o(.ovl) -#elseif NON_MATCHING - build/src/overlays/actors/ovl_En_Niw_rodata_overlay.o(.ovl) -#else build/src/overlays/actors/ovl_En_Niw/z_en_niw.o(.rodata) - build/asm/overlays/ovl_En_Niw_rodata.o(.rodata) -#endif + build/src/overlays/actors/ovl_En_Niw/z_en_niw_overlay.o(.ovl) } SegmentEnd = .; SegmentSize = SegmentEnd - SegmentStart; diff --git a/linker_scripts/object_script.txt b/linker_scripts/object_script.txt index 5b8ba7db0a..0500d1cae3 100644 --- a/linker_scripts/object_script.txt +++ b/linker_scripts/object_script.txt @@ -494,8 +494,10 @@ D_06005BA0 = 0x06005BA0; D_0600B538 = 0x0600B538; /* en_niw */ -D_06002530 = 0x06002530; D_060000E8 = 0x060000E8; +D_060023B0 = 0x060023B0; +D_06002428 = 0x06002428; +D_06002530 = 0x06002530; /* z_en_nnh */ D_06001510 = 0x06001510; diff --git a/src/overlays/actors/ovl_En_Niw/z_en_niw.c b/src/overlays/actors/ovl_En_Niw/z_en_niw.c index bbc1dc1ef8..8281676e1c 100644 --- a/src/overlays/actors/ovl_En_Niw/z_en_niw.c +++ b/src/overlays/actors/ovl_En_Niw/z_en_niw.c @@ -13,10 +13,10 @@ void EnNiw_Destroy(Actor* thisx, GlobalContext* globalCtx); void EnNiw_Update(Actor* thisx, GlobalContext* globalCtx); void EnNiw_Draw(Actor* thisx, GlobalContext* globalCtx); void EnNiw_SetupIdle(EnNiw* this); -void func_808919E8(EnNiw* this, GlobalContext* globalCtx); +void EnNiw_Idle(EnNiw* this, GlobalContext* globalCtx); void EnNiw_Thrown(EnNiw* this, GlobalContext* globalCtx); -void EnNiw_SetupRunning(EnNiw* this); -void func_808924B0(EnNiw* this, GlobalContext* globalCtx); +void EnNiw_SetupRunAway(EnNiw* this); +void EnNiw_RunAway(EnNiw* this, GlobalContext* globalCtx); void EnNiw_Swimming(EnNiw* this, GlobalContext* globalCtx); void EnNiw_Trigger(EnNiw* this, GlobalContext* globalCtx); void EnNiw_Upset(EnNiw* this, GlobalContext* globalCtx); @@ -25,12 +25,17 @@ void EnNiw_CuccoStorm(EnNiw* this, GlobalContext* globalCtx); void EnNiw_SpawnAttackNiw(EnNiw* this, GlobalContext* globalCtx); void EnNiw_Held(EnNiw* this, GlobalContext* globalCtx); void EnNiw_UpdateFeather(EnNiw* this, GlobalContext* globalCtx); -void func_808932B0(EnNiw* this, GlobalContext* globalCtx); // draw feather +void EnNiw_DrawFeathers(EnNiw* this, GlobalContext* globalCtx); void EnNiw_CheckRage(EnNiw* this, GlobalContext* globalCtx); void func_80891320(EnNiw* this, GlobalContext* globalCtx, s16 arg2); s32 EnNiw_LimbDraw(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, struct Actor* actor); void EnNiw_SpawnFeather(EnNiw* this, Vec3f* pos, Vec3f* vel, Vec3f* accel, f32 scale); +extern FlexSkeletonHeader D_06002530; +extern AnimationHeader D_060000E8; +extern Gfx D_060023B0[]; // gNiwFeatherMaterialDL +extern Gfx D_06002428[]; // gNiwFeatherDL + // turned on during cucco storm, but not read by anything? // maybe read by En_Attack_Niw s16 D_80893460 = false; @@ -324,18 +329,16 @@ void EnNiw_SetupIdle(EnNiw* this) { SkelAnime_ChangeAnim(&this->skelanime, &D_060000E8, 1.0f, 0.0f, SkelAnime_GetFrameCount(&D_060000E8.common), 0, -10.0f); this->unknownState28E = 0; - this->actionFunc = func_808919E8; + this->actionFunc = EnNiw_Idle; } -#ifdef NON_MATCHING -// non-matching: stack offset and regalloc -// EnNiw_Idle -void func_808919E8(EnNiw* this, GlobalContext* globalCtx) { +void EnNiw_Idle(EnNiw* this, GlobalContext* globalCtx) { + f32 posX2; + f32 posZ2; + f32 posX1 = randPlusMinusPoint5Scaled(100.0f); + f32 posZ1 = randPlusMinusPoint5Scaled(100.0f); s16 s16tmp; - Vec3f newPos; - newPos.y = randPlusMinusPoint5Scaled(100.0f); - newPos.z = randPlusMinusPoint5Scaled(100.0f); if (this->niwType == ENNIW_TYPE_REGULAR) { if (Actor_HasParent(&this->actor, globalCtx)) { // picked up @@ -369,24 +372,20 @@ void func_808919E8(EnNiw* this, GlobalContext* globalCtx) { if (this->unk298 > 7) { this->unkTimer252 = Rand_ZeroFloat(30.0f); this->unk298 = Rand_ZeroFloat(3.99f); - // (3.99..) is loaded into f12 for rand_zero, but f12 never released - // b18: jal Rand_ZeroFloat b18: jal Rand_ZeroFloat - // b1c: lwc1 $f12,%lo(D_80893554)(at) i b1c: lwc1 $f12,%lo(.rodata+0x54)(at) - // b20: lwc1 $f12,0x34(sp) r b20: lwc1 $f2,0x2c(sp) - if (newPos.y < 0.0f) { - newPos.y -= 100.0f; + if (posX1 < 0.0f) { + posX1 -= 100.0f; } else { - newPos.y += 100.0f; + posX1 += 100.0f; } - if (newPos.z < 0.0f) { - newPos.z -= 100.0f; + if (posZ1 < 0.0f) { + posZ1 -= 100.0f; } else { - newPos.z += 100.0f; + posZ1 += 100.0f; } - this->unk2B0.x = this->unk2A4.x + newPos.y; - this->unk2B0.z = this->unk2A4.z + newPos.z; + this->unk2B0.x = this->unk2A4.x + posX1; + this->unk2B0.z = this->unk2A4.z + posZ1; } else { this->unkTimer250 = 4; @@ -404,35 +403,31 @@ void func_808919E8(EnNiw* this, GlobalContext* globalCtx) { Math_ApproachF(&this->actor.world.pos.z, this->unk2B0.z, 1.0f, this->unk300); Math_ApproachF(&this->unk300, 3.0f, 1.0f, 0.3f); - newPos.x = this->unk2B0.x - this->actor.world.pos.x; - newPos.z = this->unk2B0.z - this->actor.world.pos.z; + posX2 = this->unk2B0.x - this->actor.world.pos.x; + posZ2 = this->unk2B0.z - this->actor.world.pos.z; - if (fabsf(newPos.x) < 10.0f) { - newPos.x = 0.0; + if (fabsf(posX2) < 10.0f) { + posX2 = 0; } - if (fabsf(newPos.z) < 10.0f) { - newPos.z = 0.0; + if (fabsf(posZ2) < 10.0f) { + posZ2 = 0; } - if ((newPos.x == 0.0f) && (newPos.z == 0.0f)) { + if ((posX2 == 0.0f) && (posZ2 == 0.0f)) { this->unkTimer250 = 0; this->unk298 = 7; } - Math_SmoothStepToS(&this->actor.world.rot.y, Math_Atan2S(newPos.x, newPos.z), 3, this->unk304, 0); + Math_SmoothStepToS(&this->actor.world.rot.y, Math_Atan2S(posX2, posZ2), 3, this->unk304, 0); Math_ApproachF(&this->unk304, 10000.0f, 1.0f, 1000.0f); } func_80891320(this, globalCtx, s16tmp); } -#else -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Niw_0x80891060/func_808919E8.asm") -#endif void EnNiw_Held(EnNiw* this, GlobalContext* globalCtx) { - Vec3f vec3fcopy; + Vec3f vec3fcopy = D_808934DC; s16 rotZ; - vec3fcopy = D_808934DC; if (this->unkTimer250 == 0) { this->unk29E = 2; this->unkTimer250 = (s32)(Rand_ZeroFloat(1.0f) * 10.0f) + 10; @@ -491,7 +486,7 @@ void EnNiw_Thrown(EnNiw* this, GlobalContext* globalCtx) { this->unkTimer254 = 100; this->unkTimer250 = 0; this->unk2EC = 0; - EnNiw_SetupRunning(this); + EnNiw_SetupRunAway(this); return; } } @@ -559,7 +554,7 @@ void EnNiw_Swimming(EnNiw* this, GlobalContext* globalCtx) { this->unkTimer250 = 0; this->actor.velocity.y = 0.0f; if (!this->isStormActive) { - EnNiw_SetupRunning(this); + EnNiw_SetupRunAway(this); } else { this->unknownState28E = 3; this->actionFunc = EnNiw_CuccoStorm; @@ -633,50 +628,38 @@ void EnNiw_CuccoStorm(EnNiw* this, GlobalContext* globalCtx) { } } -void EnNiw_SetupRunning(EnNiw* this) { +void EnNiw_SetupRunAway(EnNiw* this) { SkelAnime_ChangeAnim(&this->skelanime, &D_060000E8, 1.0f, 0.0f, SkelAnime_GetFrameCount(&D_060000E8.common), 0, -10.0f); this->unk29A = Rand_ZeroFloat(1.99f); this->unknownState28E = 7; - this->actionFunc = func_808924B0; // running away + this->actionFunc = EnNiw_RunAway; this->actor.speedXZ = 4.0f; } -#ifdef NON_MATCHING -// bad regalloc, center of first if block -// actionfunc: running away from link -void func_808924B0(EnNiw* this, GlobalContext* globalCtx) { +void EnNiw_RunAway(EnNiw* this, GlobalContext* globalCtx) { Player* player = PLAYER; - Vec3f tempVec3f; + Vec3f tempVec3f = D_808934E8; s16 temp298; f32 dX; f32 dZ; - // it actually wants to copy to stack... not modify, then pass to veccopy - // and it does it BEFORE the if block, this is just unoptimized. - tempVec3f = D_808934E8; if (this->unkTimer254 == 0) { - // the assignements in this block never want to align properly - // its not lineswap, as 800k permuter with only lineswap didn't find a solution - this->unk298 = 0; + this->unk2A4.x = this->unk2B0.x = this->actor.world.pos.x; + this->unk2A4.y = this->unk2B0.y = this->actor.world.pos.y; + this->unk2A4.z = this->unk2B0.z = this->actor.world.pos.z; - this->unk2A4.x = this->actor.world.pos.x; - this->unk2A4.y = this->actor.world.pos.y; - this->unk2A4.z = this->actor.world.pos.z; - this->unk2B0.x = this->actor.world.pos.x; - this->unk2B0.y = this->actor.world.pos.y; - this->unk2B0.z = this->actor.world.pos.z; + this->unkTimer252 = this->unkTimer250 = this->unk298 = 0; + this->unk300 = this->unk304 = 0; + + this->actor.speedXZ = 0; - this->unkTimer252 = this->unkTimer250 = this->unk298; this->unk264[8] = 0; this->unk264[6] = 0; this->unk264[5] = 0; this->unk264[7] = 0; - this->unk304 = 0; - this->unk300 = 0; - this->actor.speedXZ = 0; Math_Vec3f_Copy(&this->unk2BC, &tempVec3f); - EnNiw_SetupIdle(&this->actor); + EnNiw_SetupIdle(this); } else { if (this->unk2BC.x != 90000.0f) { dX = this->actor.world.pos.x - this->unk2BC.x; @@ -690,11 +673,7 @@ void func_808924B0(EnNiw* this, GlobalContext* globalCtx) { func_80891320(this, globalCtx, 2); } } -#else -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Niw_0x80891060/func_808924B0.asm") -#endif -// check if on the ground after running, once on the ground, start idling void EnNiw_LandBeforeIdle(EnNiw* this, GlobalContext* globalCtx) { if (this->actor.bgCheckFlags & 1) { EnNiw_SetupIdle(this); @@ -702,7 +681,7 @@ void EnNiw_LandBeforeIdle(EnNiw* this, GlobalContext* globalCtx) { } void EnNiw_CheckRage(EnNiw* this, GlobalContext* globalCtx) { - if ((!this->isStormActive) && (this->unkTimer260 == 0) && (this->niwType == ENNIW_TYPE_REGULAR)) { + if (!this->isStormActive && (this->unkTimer260 == 0) && (this->niwType == ENNIW_TYPE_REGULAR)) { if ((this->unknownState28E != 7) && (this->unk2BC.x != 90000.0f)) { this->unkTimer260 = 10; this->sfxTimer1 = 30; @@ -710,7 +689,7 @@ void EnNiw_CheckRage(EnNiw* this, GlobalContext* globalCtx) { Audio_PlayActorSound2(&this->actor, NA_SE_EV_CHICKEN_CRY_M); // crow this->unkTimer254 = 100; this->unk2EC = 0; - EnNiw_SetupRunning(this); + EnNiw_SetupRunAway(this); } if (this->collider.base.acFlags & AC_HIT) { @@ -747,7 +726,7 @@ void EnNiw_CheckRage(EnNiw* this, GlobalContext* globalCtx) { Audio_PlayActorSound2(&this->actor, NA_SE_EV_CHICKEN_CRY_M); // crow this->unkTimer254 = 100; this->unk2EC = 0; - EnNiw_SetupRunning(this); + EnNiw_SetupRunAway(this); } } } @@ -878,7 +857,7 @@ void EnNiw_Update(Actor* thisx, GlobalContext* globalCtx) { this->unknownState28E = 8; this->isStormActive = false; this->actionFunc = EnNiw_LandBeforeIdle; - return; // still required even with the else/else + return; } else if ((this->actor.bgCheckFlags & 0x20) && (this->actor.yDistToWater > 15.0f) && (this->unknownState28E != 6)) { @@ -956,7 +935,7 @@ void EnNiw_Draw(Actor* thisx, GlobalContext* globalCtx) { func_8012C28C(globalCtx->state.gfxCtx); SkelAnime_DrawSV(globalCtx, this->skelanime.skeleton, this->skelanime.limbDrawTbl, this->skelanime.dListCount, EnNiw_LimbDraw, NULL, &this->actor); - func_808932B0(this, globalCtx); + EnNiw_DrawFeathers(this, globalCtx); } void EnNiw_SpawnFeather(EnNiw* this, Vec3f* pos, Vec3f* vel, Vec3f* accel, f32 scale) { @@ -1010,51 +989,37 @@ void EnNiw_UpdateFeather(EnNiw* this, GlobalContext* globalCtx) { } } -#ifdef NON_EQUIVALENT -// non-equiv: not even close // feather draw function -void func_808932B0(EnNiw* this, GlobalContext* globalCtx) { - // vanilla wants to load this early (and other values) - // but it needs to be stored in a s register not v/a - // EnNiwFeather* feathers = &this->feathers; - u8 flag = 0; - - // permuter thinks this might be int which makes sense... - // but the end of the loop converts type, int reemoves it - // s16 i; - s32 i; - - if (globalCtx->state.gfxCtx) {} - if (this->feathers) {} - - OPEN_DISPS(globalCtx->state.gfxCtx); +void EnNiw_DrawFeathers(EnNiw* this, GlobalContext* globalCtx) { + GraphicsContext* gfxCtx = globalCtx->state.gfxCtx; + u8 isMaterialApplied = false; + EnNiwFeather* feather = &this->feathers[0]; + s16 i; + OPEN_DISPS(gfxCtx); func_8012C2DC(globalCtx->state.gfxCtx); - for (i = 0; i < ARRAY_COUNT(this->feathers); i++) { - if (this->feathers[i].isEnabled == true) { - if (flag == 0) { + for (i = 0; i < ARRAY_COUNT(this->feathers); i++, feather++) { + if (feather->isEnabled == true) { + // Apply the feather material if it has not already been applied. + if (!isMaterialApplied) { gSPDisplayList(POLY_XLU_DISP++, D_060023B0); - - flag++; + isMaterialApplied++; } - SysMatrix_InsertTranslation(this->feathers[i].pos.x, this->feathers[i].pos.y, this->feathers[i].pos.z, + SysMatrix_InsertTranslation(feather->pos.x, feather->pos.y, feather->pos.z, MTXMODE_NEW); SysMatrix_NormalizeXYZ(&globalCtx->mf_187FC); - Matrix_Scale(this->feathers[i].scale, this->feathers[i].scale, 1.0f, MTXMODE_APPLY); - SysMatrix_InsertZRotation_f(this->feathers[i].zRot, MTXMODE_APPLY); + Matrix_Scale(feather->scale, feather->scale, 1.0f, MTXMODE_APPLY); + SysMatrix_InsertZRotation_f(feather->zRot, MTXMODE_APPLY); SysMatrix_InsertTranslation(0.0f, -1000.0f, 0.0f, MTXMODE_APPLY); - gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx), + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_XLU_DISP++, D_06002428); } } - CLOSE_DISPS(globalCtx->state.gfxCtx); + CLOSE_DISPS(gfxCtx); } -#else -#pragma GLOBAL_ASM("./asm/non_matchings/overlays/ovl_En_Niw_0x80891060/func_808932B0.asm") -#endif diff --git a/src/overlays/actors/ovl_En_Niw/z_en_niw.h b/src/overlays/actors/ovl_En_Niw/z_en_niw.h index 4c09866743..6da6c97e7f 100644 --- a/src/overlays/actors/ovl_En_Niw/z_en_niw.h +++ b/src/overlays/actors/ovl_En_Niw/z_en_niw.h @@ -87,11 +87,4 @@ typedef struct EnNiw { // the attacking cuccos are not here, they are a different actor: // ovl_En_Attack_Niw -extern FlexSkeletonHeader D_06002530; -extern AnimationHeader D_060000E8; - -// feather display list? -extern Gfx D_060023B0[]; -extern Gfx D_06002428[]; - #endif // Z_EN_NIW_H diff --git a/tables/functions.txt b/tables/functions.txt index af1101bd43..b7cd058a78 100644 --- a/tables/functions.txt +++ b/tables/functions.txt @@ -5441,7 +5441,7 @@ 0x808916B0:("EnNiw_SpawnAttackNiw",), 0x808917F8:("func_808917F8",), 0x80891974:("EnNiw_SetupIdle",), - 0x808919E8:("func_808919E8",), + 0x808919E8:("EnNiw_Idle",), 0x80891D78:("EnNiw_Held",), 0x80891F60:("EnNiw_Thrown",), 0x808920A0:("EnNiw_Swimming",), @@ -5449,8 +5449,8 @@ 0x80892274:("EnNiw_Upset",), 0x808922D0:("EnNiw_SetupCuccoStorm",), 0x80892390:("EnNiw_CuccoStorm",), - 0x80892414:("EnNiw_SetupRunning",), - 0x808924B0:("func_808924B0",), + 0x80892414:("EnNiw_SetupRunAway",), + 0x808924B0:("EnNiw_RunAway",), 0x808925F8:("EnNiw_LandBeforeIdle",), 0x8089262C:("EnNiw_CheckRage",), 0x808927CC:("EnNiw_Update",), @@ -5458,7 +5458,7 @@ 0x80892FA0:("EnNiw_Draw",), 0x80893008:("EnNiw_SpawnFeather",), 0x808930FC:("EnNiw_UpdateFeather",), - 0x808932B0:("func_808932B0",), + 0x808932B0:("EnNiw_DrawFeathers",), 0x808937F0:("EnTite_Init",), 0x808939EC:("EnTite_Destroy",), 0x80893A18:("func_80893A18",),