1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-16 04:44:44 +00:00

ObjTimeblock OK (#421)

* ObjTimeblock: move data in source file

* ObjTimeblock: decomp Init()

* ObjTimeblock: decomp Destroy()

* ObjTimeblock: decomp func_80BA0058()/spawnDemoEffect()

* ObjTimeblock: decomp func_80B9FFA0()

* ObjTimeblock: decomp func_80BA040C()/mainActionFunc()

* ObjTimeblock: decomp func_80BA032C()

* ObjTimeblock: decomp func_80BA0480()

* ObjTimeblock: decomp func_80BA0514()

* ObjTimeblock: decomp func_80BA0524()

* ObjTimeblock: decomp func_80BA00CC()/toggleSceneSwitch()

* ObjTimeblock: decomp func_80BA04F8()

* ObjTimeblock: decomp func_80BA0508()/doNothing()

* ObjTimeblock: decomp func_80BA0758()

* ObjTimeblock: decomp func_80BA0768()

* ObjTimeblock: decomp func_80BA06AC()

* ObjTimeblock: decomp func_80BA083C()

* ObjTimeblock: decomp func_80BA084C()

* ObjTimeblock: decomp ObjTimeblock_Update()

* ObjTimeblock: decomp ObjTimeblock_Draw()

* ObjTimeblock: document the most obvious

* ObjTimeblock: use compiled reloc data

* ObjTimeblock: apply suggestions from mzxrules

* review

Co-authored-by: fig <fig02srl@gmail.com>
This commit is contained in:
Peppers1612 2020-12-03 16:52:26 -05:00 committed by GitHub
parent 579b87dceb
commit 80c803b9ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 330 additions and 921 deletions

View file

@ -5,13 +5,13 @@
#define THIS ((EnDh*)thisx)
typedef enum {
DH_WAIT,
DH_RETREAT,
DH_BURROW,
DH_WALK,
DH_ATTACK,
DH_DEATH,
DH_DAMAGE
/* 0 */ DH_WAIT,
/* 1 */ DH_RETREAT,
/* 2 */ DH_BURROW,
/* 3 */ DH_WALK,
/* 4 */ DH_ATTACK,
/* 5 */ DH_DEATH,
/* 6 */ DH_DAMAGE
} EnDhAction;
void EnDh_Init(Actor* this, GlobalContext* globalCtx);
@ -96,7 +96,7 @@ void EnDh_Init(Actor* thisx, GlobalContext* globalCtx) {
Actor_ProcessInitChain(&this->actor, sInitChain);
this->actor.colChkInfo.damageTable = &D_809EC620;
SkelAnime_InitFlex(globalCtx, &this->skelAnime, &D_06007E88, &D_06005880, this->limbDrawTable, this->limbRotTable,
16);
16);
ActorShape_Init(&this->actor.shape, 0.0f, &ActorShadow_DrawFunc_Circle, 64.0f);
this->actor.params = ENDH_WAIT_UNDERGROUND;
this->actor.colChkInfo.mass = 0xFE;
@ -502,13 +502,13 @@ void EnDh_Draw(Actor* thisx, GlobalContext* globalCtx) {
gSPSegment(POLY_OPA_DISP++, 0x08, &D_80116280[2]);
POLY_OPA_DISP =
SkelAnime_DrawFlex(globalCtx, this->skelAnime.skeleton, this->skelAnime.limbDrawTbl,
this->skelAnime.dListCount, NULL, EnDh_PostLimbDraw, &this->actor, POLY_OPA_DISP);
this->skelAnime.dListCount, NULL, EnDh_PostLimbDraw, &this->actor, POLY_OPA_DISP);
} else {
func_80093D84(globalCtx->state.gfxCtx);
gDPSetEnvColor(POLY_XLU_DISP++, 0, 0, 0, this->alpha);
gSPSegment(POLY_XLU_DISP++, 0x08, &D_80116280[0]);
POLY_XLU_DISP = SkelAnime_DrawFlex(globalCtx, this->skelAnime.skeleton, this->skelAnime.limbDrawTbl,
this->skelAnime.dListCount, NULL, NULL, &this->actor, POLY_XLU_DISP);
this->skelAnime.dListCount, NULL, NULL, &this->actor, POLY_XLU_DISP);
}
if (this->drawDirtWave) {
func_80093D84(globalCtx->state.gfxCtx);

View file

@ -255,7 +255,7 @@ void EnDha_Die(EnDha* this, GlobalContext* globalCtx) {
Vec3f vector;
Player* player = PLAYER;
if ((player->stateFlags2 & 0x80) && (&this->actor == player->actor.parent)) {
if ((player->stateFlags2 & 0x80) && (&this->actor == player->actor.parent)) {
player->stateFlags2 &= ~0x80;
player->actor.parent = NULL;
player->unk_850 = 200;
@ -305,7 +305,7 @@ void EnDha_UpdateHealth(EnDha* this, GlobalContext* globalCtx) {
}
}
}
if ((this->actor.parent != NULL) && (this->actor.parent->params == ENDH_DEATH)) {
if ((this->actor.parent != NULL) && (this->actor.parent->params == ENDH_DEATH)) {
EnDha_SetupDeath(this);
}
}

View file

@ -860,5 +860,5 @@ void EnSsh_Draw(Actor* thisx, GlobalContext* globalCtx) {
gSPSegment(POLY_OPA_DISP++, 0x08, SEGMENTED_TO_VIRTUAL(blinkTex[this->blinkState]));
CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_en_ssh.c", 2336);
SkelAnime_DrawOpa(globalCtx, this->skelAnime.skeleton, this->skelAnime.limbDrawTbl, EnSsh_OverrideLimbDraw,
EnSsh_PostLimbDraw, &this->actor);
EnSsh_PostLimbDraw, &this->actor);
}

View file

@ -15,7 +15,20 @@ void ObjTimeblock_Destroy(Actor* thisx, GlobalContext* globalCtx);
void ObjTimeblock_Update(Actor* thisx, GlobalContext* globalCtx);
void ObjTimeblock_Draw(Actor* thisx, GlobalContext* globalCtx);
/*
void ObjTimeblock_SetupNormal(ObjTimeblock* this);
void ObjTimeblock_SetupAltBehaviorVisible(ObjTimeblock* this);
void ObjTimeblock_SetupAltBehaviourNotVisible(ObjTimeblock* this);
s32 ObjTimeblock_WaitForOcarina(ObjTimeblock* this, GlobalContext* globalCtx);
s32 ObjTimeblock_WaitForSong(ObjTimeblock* this, GlobalContext* globalCtx);
void ObjTimeblock_DoNothing(ObjTimeblock* this, GlobalContext* globalCtx);
void ObjTimeblock_Normal(ObjTimeblock* this, GlobalContext* globalCtx);
void ObjTimeblock_AltBehaviorVisible(ObjTimeblock* this, GlobalContext* globalCtx);
void ObjTimeblock_AltBehaviourNotVisible(ObjTimeblock* this, GlobalContext* globalCtx);
extern Gfx D_06000980[];
extern CollisionHeader D_06000B30;
const ActorInit Obj_Timeblock_InitVars = {
ACTOR_OBJ_TIMEBLOCK,
ACTORTYPE_ITEMACTION,
@ -27,41 +40,307 @@ const ActorInit Obj_Timeblock_InitVars = {
(ActorFunc)ObjTimeblock_Update,
(ActorFunc)ObjTimeblock_Draw,
};
*/
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80B9FFA0.s")
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA0058.s")
typedef struct {
/* 0x00 */ f32 scale;
/* 0x04 */ f32 height;
/* 0x08 */ s16 demoEffectParams;
} ObjTimeblockSizeOptions; // size = 0x0C
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA00CC.s")
static ObjTimeblockSizeOptions sSizeOptions[] = {
{ 1.0, 60.0, 0x0018 },
{ 0.60, 40.0, 0x0019 },
};
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/ObjTimeblock_Init.s")
static f32 sRanges[] = { 60.0, 100.0, 140.0, 180.0, 220.0, 260.0, 300.0, 300.0 };
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/ObjTimeblock_Destroy.s")
static InitChainEntry sInitChain[] = {
ICHAIN_U8(unk_1F, 2, ICHAIN_CONTINUE),
ICHAIN_F32(uncullZoneForward, 1800, ICHAIN_CONTINUE),
ICHAIN_F32(uncullZoneScale, 300, ICHAIN_CONTINUE),
ICHAIN_F32(uncullZoneDownward, 1500, ICHAIN_STOP),
};
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA032C.s")
static Color_RGB8 sPrimColors[] = {
{ 100, 120, 140 }, { 80, 140, 200 }, { 100, 150, 200 }, { 100, 200, 240 },
{ 80, 110, 140 }, { 70, 160, 225 }, { 80, 100, 130 }, { 100, 110, 190 },
};
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA040C.s")
u32 ObjTimeblock_CalculateIsVisible(ObjTimeblock* this) {
if (!((this->dyna.actor.params >> 10) & 1)) {
if (this->unk_177 == 0) {
return this->unk_175;
} else {
u8 temp = ((this->dyna.actor.params >> 15) & 1) ? true : false;
if (this->unk_177 == 1) {
return this->unk_174 ^ temp;
} else {
u8 linkIsYoung = (LINK_AGE_IN_YEARS == YEARS_CHILD) ? true : false;
return this->unk_174 ^ temp ^ linkIsYoung;
}
}
} else {
return (((this->dyna.actor.params >> 15) & 1) ? true : false) ^ this->unk_174;
}
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA0480.s")
void ObjTimeblock_SpawnDemoEffect(ObjTimeblock* this, GlobalContext* globalCtx) {
Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_DEMO_EFFECT, this->dyna.actor.posRot.pos.x,
this->dyna.actor.posRot.pos.y, this->dyna.actor.posRot.pos.z, 0, 0, 0,
sSizeOptions[(this->dyna.actor.params >> 8) & 1].demoEffectParams);
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA04F8.s")
void ObjTimeblock_ToggleSwitchFlag(GlobalContext* globalCtx, s32 flag) {
if (Flags_GetSwitch(globalCtx, flag)) {
Flags_UnsetSwitch(globalCtx, flag);
} else {
Flags_SetSwitch(globalCtx, flag);
}
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA0508.s")
void ObjTimeblock_Init(Actor* thisx, GlobalContext* globalCtx) {
ObjTimeblock* this = THIS;
s32 pad;
UNK_PTR colHeader = NULL;
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA0514.s")
DynaPolyInfo_SetActorMove(&this->dyna, DPM_UNK);
this->dyna.actor.posRot.rot.z = this->dyna.actor.shape.rot.z = 0;
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA0524.s")
DynaPolyInfo_Alloc(&D_06000B30, &colHeader);
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA06AC.s")
this->dyna.dynaPolyId =
DynaPolyInfo_RegisterActor(globalCtx, &globalCtx->colCtx.dyna, &this->dyna.actor, colHeader);
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA0758.s")
Actor_ProcessInitChain(&this->dyna.actor, sInitChain);
Actor_SetScale(&this->dyna.actor, sSizeOptions[(this->dyna.actor.params >> 8) & 1].scale);
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA0768.s")
if ((this->dyna.actor.params >> 6) & 1) {
this->unk_177 = 0;
} else {
this->unk_177 = ((this->dyna.actor.params & 0x3F) < 0x38) ? 2 : 1;
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA083C.s")
this->songObserverFunc = ObjTimeblock_WaitForOcarina;
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/func_80BA084C.s")
Actor_SetHeight(&this->dyna.actor, sSizeOptions[(this->dyna.actor.params >> 8) & 1].height);
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/ObjTimeblock_Update.s")
this->unk_174 = (Flags_GetSwitch(globalCtx, this->dyna.actor.params & 0x3F)) ? true : false;
this->unk_175 = ((this->dyna.actor.params >> 15) & 1) ? true : false;
this->isVisible = ObjTimeblock_CalculateIsVisible(this);
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_Obj_Timeblock/ObjTimeblock_Draw.s")
if (!((this->dyna.actor.params >> 10) & 1)) {
ObjTimeblock_SetupNormal(this);
} else if (this->isVisible) {
ObjTimeblock_SetupAltBehaviorVisible(this);
} else {
ObjTimeblock_SetupAltBehaviourNotVisible(this);
}
// "Block of time"
osSyncPrintf("時のブロック (<arg> %04xH <type> save:%d color:%d range:%d move:%d)\n", (u16)this->dyna.actor.params,
this->unk_177, this->dyna.actor.initPosRot.rot.z & 7, (this->dyna.actor.params >> 11) & 7,
(this->dyna.actor.params >> 10) & 1);
}
void ObjTimeblock_Destroy(Actor* thisx, GlobalContext* globalCtx) {
DynaPolyInfo_Free(globalCtx, &globalCtx->colCtx.dyna, THIS->dyna.dynaPolyId);
}
u8 ObjTimeblock_PlayerIsInRange(ObjTimeblock* this, GlobalContext* globalCtx) {
if (this->isVisible && func_80043590(&this->dyna)) {
return false;
}
if (this->dyna.actor.xzDistFromLink <= sRanges[(this->dyna.actor.params >> 11) & 7]) {
Vec3f distance;
f32 blockSize;
func_8002DBD0(&this->dyna.actor, &distance, &PLAYER->actor.posRot.pos);
blockSize = this->dyna.actor.scale.x * 50.0f + 6.0f;
// Return true if player's xz position is not inside the block
if (blockSize < fabsf(distance.x) || blockSize < fabsf(distance.z)) {
return true;
}
}
return false;
}
s32 ObjTimeblock_WaitForOcarina(ObjTimeblock* this, GlobalContext* globalCtx) {
Player* player = PLAYER;
if (ObjTimeblock_PlayerIsInRange(this, globalCtx)) {
if (player->stateFlags2 & 0x1000000) {
func_8010BD58(globalCtx, 1);
this->songObserverFunc = ObjTimeblock_WaitForSong;
} else {
player->stateFlags2 |= 0x800000;
}
}
return false;
}
s32 ObjTimeblock_WaitForSong(ObjTimeblock* this, GlobalContext* globalCtx) {
if (globalCtx->msgCtx.unk_E3EE == 4) {
this->songObserverFunc = ObjTimeblock_WaitForOcarina;
}
if (globalCtx->msgCtx.unk_E3EC == 10) {
if (this->unk_172 == 254) {
this->songEndTimer = 110;
} else {
this->songEndTimer--;
if (this->songEndTimer == 0) {
return true;
}
}
}
return false;
}
void ObjTimeblock_SetupDoNothing(ObjTimeblock* this) {
this->actionFunc = ObjTimeblock_DoNothing;
}
void ObjTimeblock_DoNothing(ObjTimeblock* this, GlobalContext* globalCtx) {
}
void ObjTimeblock_SetupNormal(ObjTimeblock* this) {
this->actionFunc = ObjTimeblock_Normal;
}
void ObjTimeblock_Normal(ObjTimeblock* this, GlobalContext* globalCtx) {
u32 newIsVisible;
if (this->songObserverFunc(this, globalCtx) && this->demoEffectTimer <= 0) {
ObjTimeblock_SpawnDemoEffect(this, globalCtx);
this->demoEffectTimer = 160;
// Possibly points the camera to this actor
func_80080480(globalCtx, &this->dyna.actor);
// "◯◯◯◯ Time Block Attention Camera (frame counter %d)\n"
osSyncPrintf("◯◯◯◯ Time Block 注目カメラ (frame counter %d)\n", globalCtx->state.frames);
this->demoEffectFirstPartTimer = 12;
if (this->unk_177 == 0) {
this->dyna.actor.params ^= 0x8000;
} else {
ObjTimeblock_ToggleSwitchFlag(globalCtx, this->dyna.actor.params & 0x3F);
}
}
this->unk_172 = globalCtx->msgCtx.unk_E3EC;
if (this->demoEffectFirstPartTimer > 0) {
this->demoEffectFirstPartTimer--;
if (this->demoEffectFirstPartTimer == 0) {
if (this->unk_177 == 0) {
this->unk_175 = ((this->dyna.actor.params >> 15) & 1) ? true : false;
} else {
this->unk_174 = (Flags_GetSwitch(globalCtx, this->dyna.actor.params & 0x3F)) ? true : false;
}
}
}
newIsVisible = ObjTimeblock_CalculateIsVisible(this);
if (this->unk_177 == 1 && newIsVisible != this->isVisible) {
ObjTimeblock_SetupDoNothing(this);
}
this->isVisible = newIsVisible;
if (this->demoEffectTimer == 50) {
func_80078884(NA_SE_SY_TRE_BOX_APPEAR);
}
}
void func_80BA06AC(ObjTimeblock* this, GlobalContext* globalCtx) {
s32 switchFlag = this->dyna.actor.params & 0x3F;
this->unk_172 = globalCtx->msgCtx.unk_E3EC;
if (this->demoEffectFirstPartTimer > 0 && --this->demoEffectFirstPartTimer == 0) {
this->unk_174 = (Flags_GetSwitch(globalCtx, switchFlag)) ? true : false;
}
this->isVisible = ObjTimeblock_CalculateIsVisible(this);
this->unk_176 = (Flags_GetSwitch(globalCtx, switchFlag)) ? true : false;
}
void ObjTimeblock_SetupAltBehaviorVisible(ObjTimeblock* this) {
this->actionFunc = ObjTimeblock_AltBehaviorVisible;
}
void ObjTimeblock_AltBehaviorVisible(ObjTimeblock* this, GlobalContext* globalCtx) {
if (this->songObserverFunc(this, globalCtx) && this->demoEffectTimer <= 0) {
this->demoEffectFirstPartTimer = 12;
ObjTimeblock_SpawnDemoEffect(this, globalCtx);
this->demoEffectTimer = 160;
func_80080480(globalCtx, &this->dyna.actor);
// "Time Block Attention Camera (frame counter)"
osSyncPrintf("◯◯◯◯ Time Block 注目カメラ (frame counter %d)\n", globalCtx->state.frames);
ObjTimeblock_ToggleSwitchFlag(globalCtx, this->dyna.actor.params & 0x3F);
}
func_80BA06AC(this, globalCtx);
if (this->demoEffectTimer == 50) {
func_80078884(NA_SE_SY_TRE_BOX_APPEAR);
}
if (!this->isVisible && this->demoEffectTimer <= 0) {
ObjTimeblock_SetupAltBehaviourNotVisible(this);
}
}
void ObjTimeblock_SetupAltBehaviourNotVisible(ObjTimeblock* this) {
this->actionFunc = ObjTimeblock_AltBehaviourNotVisible;
}
void ObjTimeblock_AltBehaviourNotVisible(ObjTimeblock* this, GlobalContext* globalCtx) {
s32 switchFlag = this->dyna.actor.params & 0x3F;
s8 switchFlagIsSet = (Flags_GetSwitch(globalCtx, switchFlag)) ? true : false;
if (this->unk_176 ^ switchFlagIsSet && switchFlagIsSet ^ (((this->dyna.actor.params >> 15) & 1) ? true : false)) {
if (this->demoEffectTimer <= 0) {
ObjTimeblock_SpawnDemoEffect(this, globalCtx);
this->demoEffectTimer = 160;
}
this->demoEffectFirstPartTimer = 12;
}
func_80BA06AC(this, globalCtx);
if (this->isVisible && this->demoEffectTimer <= 0) {
ObjTimeblock_SetupAltBehaviorVisible(this);
}
}
void ObjTimeblock_Update(Actor* thisx, GlobalContext* globalCtx) {
ObjTimeblock* this = THIS;
this->actionFunc(this, globalCtx);
if (this->demoEffectTimer > 0) {
this->demoEffectTimer--;
}
if (this->isVisible) {
func_8003EC50(globalCtx, &globalCtx->colCtx.dyna, this->dyna.dynaPolyId);
} else {
func_8003EBF8(globalCtx, &globalCtx->colCtx.dyna, this->dyna.dynaPolyId);
}
}
void ObjTimeblock_Draw(Actor* thisx, GlobalContext* globalCtx) {
if (THIS->isVisible) {
Color_RGB8* primColor = &sPrimColors[THIS->dyna.actor.initPosRot.rot.z & 7];
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_obj_timeblock.c", 762);
func_80093D18(globalCtx->state.gfxCtx);
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_obj_timeblock.c", 766),
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, primColor->r, primColor->g, primColor->b, 255);
gSPDisplayList(POLY_OPA_DISP++, D_06000980);
CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_obj_timeblock.c", 772);
}
}

View file

@ -6,13 +6,22 @@
struct ObjTimeblock;
typedef s32 (*ObjTimeblockSongObserverFunc)(struct ObjTimeblock*, GlobalContext*);
typedef void (*ObjTimeblockActionFunc)(struct ObjTimeblock*, GlobalContext*);
typedef struct ObjTimeblock {
/* 0x0000 */ DynaPolyActor dyna;
/* 0x0164 */ char unk_164[0x4];
/* 0x0168 */ ObjTimeblockActionFunc actionFunc;
/* 0x016C */ char unk_16C[0x10];
/* 0x0164 */ ObjTimeblockActionFunc actionFunc;
/* 0x0168 */ ObjTimeblockSongObserverFunc songObserverFunc;
/* 0x016C */ s16 demoEffectTimer;
/* 0x016E */ s16 songEndTimer;
/* 0x0170 */ s16 demoEffectFirstPartTimer;
/* 0x0172 */ u16 unk_172;
/* 0x0174 */ u8 unk_174;
/* 0x0175 */ u8 unk_175;
/* 0x0176 */ u8 unk_176;
/* 0x0177 */ u8 unk_177;
/* 0x0178 */ u8 isVisible;
} ObjTimeblock; // size = 0x017C
extern const ActorInit Obj_Timeblock_InitVars;