Fix two small things in Bg_F40_Switch (#717)

This commit is contained in:
Tom Overton 2022-03-25 17:53:19 -07:00 committed by GitHub
parent ce7aa87454
commit fa8c723da8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 29 deletions

View File

@ -52,10 +52,10 @@ void BgF40Switch_CheckAll(BgF40Switch* this, GlobalContext* globalCtx) {
u32 inCsMode = Player_InCsMode(&globalCtx->state); u32 inCsMode = Player_InCsMode(&globalCtx->state);
for (actor = globalCtx->actorCtx.actorLists[ACTORCAT_SWITCH].first; actor != NULL; actor = actor->next) { for (actor = globalCtx->actorCtx.actorLists[ACTORCAT_SWITCH].first; actor != NULL; actor = actor->next) {
if (actor->id == ACTOR_BG_F40_SWITCH && actor->room == this->actor.actor.room && actor->update != NULL) { if (actor->id == ACTOR_BG_F40_SWITCH && actor->room == this->dyna.actor.room && actor->update != NULL) {
actorAsSwitch = (BgF40Switch*)actor; actorAsSwitch = (BgF40Switch*)actor;
actorAsSwitch->wasPressed = actorAsSwitch->isPressed; actorAsSwitch->wasPressed = actorAsSwitch->isPressed;
isPressed = DynaPolyActor_IsInSwitchPressedState(&actorAsSwitch->actor); isPressed = DynaPolyActor_IsInSwitchPressedState(&actorAsSwitch->dyna);
if (actorAsSwitch->isPressed && actorAsSwitch->actionFunc == BgF40Switch_IdlePressed) { if (actorAsSwitch->isPressed && actorAsSwitch->actionFunc == BgF40Switch_IdlePressed) {
// Switch is fully pressed - if there's nothing keeping it pressed, wait a short time before // Switch is fully pressed - if there's nothing keeping it pressed, wait a short time before
// reverting to unpressed state. // reverting to unpressed state.
@ -73,7 +73,7 @@ void BgF40Switch_CheckAll(BgF40Switch* this, GlobalContext* globalCtx) {
actorAsSwitch->isPressed = isPressed; actorAsSwitch->isPressed = isPressed;
} }
if (actorAsSwitch->isPressed) { if (actorAsSwitch->isPressed) {
switchFlag = BGF40SWITCH_GET_SWITCHFLAG(actorAsSwitch); switchFlag = BGF40SWITCH_GET_SWITCHFLAG(&actorAsSwitch->dyna.actor);
if (switchFlag >= 0 && switchFlag < 0x80) { if (switchFlag >= 0 && switchFlag < 0x80) {
pressedSwitchFlags[(switchFlag & ~0x1F) >> 5] |= 1 << (switchFlag & 0x1F); pressedSwitchFlags[(switchFlag & ~0x1F) >> 5] |= 1 << (switchFlag & 0x1F);
if (!actorAsSwitch->wasPressed && actorAsSwitch->actionFunc == BgF40Switch_IdleUnpressed && if (!actorAsSwitch->wasPressed && actorAsSwitch->actionFunc == BgF40Switch_IdleUnpressed &&
@ -85,8 +85,8 @@ void BgF40Switch_CheckAll(BgF40Switch* this, GlobalContext* globalCtx) {
} }
} }
for (actor = globalCtx->actorCtx.actorLists[ACTORCAT_SWITCH].first; actor != NULL; actor = actor->next) { for (actor = globalCtx->actorCtx.actorLists[ACTORCAT_SWITCH].first; actor != NULL; actor = actor->next) {
if (actor->id == ACTOR_BG_F40_SWITCH && actor->room == this->actor.actor.room && actor->update != 0) { if (actor->id == ACTOR_BG_F40_SWITCH && actor->room == this->dyna.actor.room && actor->update != 0) {
switchFlag = BGF40SWITCH_GET_SWITCHFLAG((BgF40Switch*)actor); switchFlag = BGF40SWITCH_GET_SWITCHFLAG(actor);
if (switchFlag >= 0 && switchFlag < 0x80 && Flags_GetSwitch(globalCtx, switchFlag) && if (switchFlag >= 0 && switchFlag < 0x80 && Flags_GetSwitch(globalCtx, switchFlag) &&
!(pressedSwitchFlags[(switchFlag & ~0x1F) >> 5] & (1 << (switchFlag & 0x1F)))) { !(pressedSwitchFlags[(switchFlag & ~0x1F) >> 5] & (1 << (switchFlag & 0x1F)))) {
Flags_UnsetSwitch(globalCtx, switchFlag); Flags_UnsetSwitch(globalCtx, switchFlag);
@ -107,12 +107,12 @@ static InitChainEntry sInitChain[] = {
void BgF40Switch_Init(Actor* thisx, GlobalContext* globalCtx) { void BgF40Switch_Init(Actor* thisx, GlobalContext* globalCtx) {
BgF40Switch* this = THIS; BgF40Switch* this = THIS;
Actor_ProcessInitChain(&this->actor.actor, sInitChain); Actor_ProcessInitChain(&this->dyna.actor, sInitChain);
this->actor.actor.scale.y = 0.165f; this->dyna.actor.scale.y = 0.165f;
this->actionFunc = BgF40Switch_IdleUnpressed; this->actionFunc = BgF40Switch_IdleUnpressed;
this->actor.actor.world.pos.y = this->actor.actor.home.pos.y + 1.0f; this->dyna.actor.world.pos.y = this->dyna.actor.home.pos.y + 1.0f;
DynaPolyActor_Init(&this->actor, 1); DynaPolyActor_Init(&this->dyna, 1);
DynaPolyActor_LoadMesh(globalCtx, &this->actor, &object_f40_switch_Colheader_000118); DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &object_f40_switch_Colheader_000118);
if (!sBgF40SwitchGlobalsInitialized) { if (!sBgF40SwitchGlobalsInitialized) {
sBgF40SwitchLastUpdateFrame = globalCtx->gameplayFrames; sBgF40SwitchLastUpdateFrame = globalCtx->gameplayFrames;
sBgF40SwitchGlobalsInitialized = true; sBgF40SwitchGlobalsInitialized = true;
@ -122,15 +122,15 @@ void BgF40Switch_Init(Actor* thisx, GlobalContext* globalCtx) {
void BgF40Switch_Destroy(Actor* thisx, GlobalContext* globalCtx) { void BgF40Switch_Destroy(Actor* thisx, GlobalContext* globalCtx) {
BgF40Switch* this = THIS; BgF40Switch* this = THIS;
DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->actor.bgId); DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId);
} }
void BgF40Switch_Unpress(BgF40Switch* this, GlobalContext* globalCtx) { void BgF40Switch_Unpress(BgF40Switch* this, GlobalContext* globalCtx) {
this->actor.actor.scale.y += 0.0495f; this->dyna.actor.scale.y += 0.0495f;
if (this->actor.actor.scale.y >= 0.165f) { if (this->dyna.actor.scale.y >= 0.165f) {
Actor_PlaySfxAtPos(&this->actor.actor, NA_SE_EV_IKANA_BLOCK_SWITCH); Actor_PlaySfxAtPos(&this->dyna.actor, NA_SE_EV_IKANA_BLOCK_SWITCH);
this->actionFunc = BgF40Switch_IdleUnpressed; this->actionFunc = BgF40Switch_IdleUnpressed;
this->actor.actor.scale.y = 0.165f; this->dyna.actor.scale.y = 0.165f;
} }
} }
@ -141,34 +141,34 @@ void BgF40Switch_IdlePressed(BgF40Switch* this, GlobalContext* globalCtx) {
} }
void BgF40Switch_Press(BgF40Switch* this, GlobalContext* globalCtx) { void BgF40Switch_Press(BgF40Switch* this, GlobalContext* globalCtx) {
this->actor.actor.scale.y -= 0.0495f; this->dyna.actor.scale.y -= 0.0495f;
if (this->actor.actor.scale.y <= 0.0165f) { if (this->dyna.actor.scale.y <= 0.0165f) {
Actor_PlaySfxAtPos(&this->actor.actor, NA_SE_EV_IKANA_BLOCK_SWITCH); Actor_PlaySfxAtPos(&this->dyna.actor, NA_SE_EV_IKANA_BLOCK_SWITCH);
func_8013ECE0(this->actor.actor.xyzDistToPlayerSq, 120, 20, 10); func_8013ECE0(this->dyna.actor.xyzDistToPlayerSq, 120, 20, 10);
if (this->isInitiator) { if (this->isInitiator) {
ActorCutscene_Stop(this->actor.actor.cutscene); ActorCutscene_Stop(this->dyna.actor.cutscene);
this->isInitiator = false; this->isInitiator = false;
} }
this->actionFunc = BgF40Switch_IdlePressed; this->actionFunc = BgF40Switch_IdlePressed;
this->actor.actor.scale.y = 0.0165f; this->dyna.actor.scale.y = 0.0165f;
this->switchReleaseDelay = 6; this->switchReleaseDelay = 6;
} }
} }
void BgF40Switch_WaitToPress(BgF40Switch* this, GlobalContext* globalCtx) { void BgF40Switch_WaitToPress(BgF40Switch* this, GlobalContext* globalCtx) {
if (!this->isInitiator || this->actor.actor.cutscene == -1) { if (!this->isInitiator || this->dyna.actor.cutscene == -1) {
this->actionFunc = BgF40Switch_Press; this->actionFunc = BgF40Switch_Press;
if (this->isInitiator) { if (this->isInitiator) {
Flags_SetSwitch(globalCtx, BGF40SWITCH_GET_SWITCHFLAG(this)); Flags_SetSwitch(globalCtx, BGF40SWITCH_GET_SWITCHFLAG(&this->dyna.actor));
} }
} else if (ActorCutscene_GetCanPlayNext(this->actor.actor.cutscene)) { } else if (ActorCutscene_GetCanPlayNext(this->dyna.actor.cutscene)) {
ActorCutscene_StartAndSetUnkLinkFields(this->actor.actor.cutscene, &this->actor.actor); ActorCutscene_StartAndSetUnkLinkFields(this->dyna.actor.cutscene, &this->dyna.actor);
this->actionFunc = BgF40Switch_Press; this->actionFunc = BgF40Switch_Press;
if (this->isInitiator) { if (this->isInitiator) {
Flags_SetSwitch(globalCtx, BGF40SWITCH_GET_SWITCHFLAG(this)); Flags_SetSwitch(globalCtx, BGF40SWITCH_GET_SWITCHFLAG(&this->dyna.actor));
} }
} else { } else {
ActorCutscene_SetIntentToPlay(this->actor.actor.cutscene); ActorCutscene_SetIntentToPlay(this->dyna.actor.cutscene);
} }
} }

View File

@ -5,12 +5,12 @@
struct BgF40Switch; struct BgF40Switch;
#define BGF40SWITCH_GET_SWITCHFLAG(this) (((this)->actor.actor.params & 0xFE00) >> 9) #define BGF40SWITCH_GET_SWITCHFLAG(thisx) (((thisx)->params & 0xFE00) >> 9)
typedef void (*BgF40SwitchActionFunc)(struct BgF40Switch*, GlobalContext*); typedef void (*BgF40SwitchActionFunc)(struct BgF40Switch*, GlobalContext*);
typedef struct BgF40Switch { typedef struct BgF40Switch {
/* 0x0000 */ DynaPolyActor actor; /* 0x0000 */ DynaPolyActor dyna;
/* 0x015C */ s16 switchReleaseDelay; // frames until a pressed switch becomes released if nothing is still pressing it /* 0x015C */ s16 switchReleaseDelay; // frames until a pressed switch becomes released if nothing is still pressing it
/* 0x015E */ s8 isPressed; // Logical state of the switch (pressed or unpressed). Animation state may lag behind this slightly. /* 0x015E */ s8 isPressed; // Logical state of the switch (pressed or unpressed). Animation state may lag behind this slightly.
/* 0x015F */ s8 wasPressed; // used as temporary during update function /* 0x015F */ s8 wasPressed; // used as temporary during update function