From 2dbe518f161296d0489dcc97d819b08487d0fd4c Mon Sep 17 00:00:00 2001 From: Yanis42 <35189056+Yanis42@users.noreply.github.com> Date: Tue, 25 Jan 2022 00:51:14 +0100 Subject: [PATCH] Document Obj_Switch subtypes (#1082) * * Named subtypes enums * Updated the comment for unk_17F * Removed unk_17F comment * * Merged SubTypes enums * Fixed JntSphElement items count * Used ARRAY_COUNT where it's needed * Used subtype enum names for SetOn and SetOff Changed "SUBTYPE_DEFAULT" to "SUBTYPE_ONCE" Updated some comments * Updated reset subtyped names Documented a bug with the inverted reset subtype * Comments * forgot one comment * Formatting * Review * Review 2 * Missed one comment --- .../actors/ovl_Obj_Switch/z_obj_switch.c | 60 ++++++++++--------- .../actors/ovl_Obj_Switch/z_obj_switch.h | 28 +++------ 2 files changed, 40 insertions(+), 48 deletions(-) diff --git a/src/overlays/actors/ovl_Obj_Switch/z_obj_switch.c b/src/overlays/actors/ovl_Obj_Switch/z_obj_switch.c index 0f2221c10d..c0e1c0abec 100644 --- a/src/overlays/actors/ovl_Obj_Switch/z_obj_switch.c +++ b/src/overlays/actors/ovl_Obj_Switch/z_obj_switch.c @@ -97,7 +97,7 @@ static ColliderTrisInit sRustyFloorTrisInit = { OC2_NONE, COLSHAPE_TRIS, }, - 2, + ARRAY_COUNT(D_80B9EC34), D_80B9EC34, }; @@ -135,7 +135,7 @@ static ColliderTrisInit trisColliderEye = { OC2_NONE, COLSHAPE_TRIS, }, - 2, + ARRAY_COUNT(D_80B9ECBC), D_80B9ECBC, }; @@ -162,7 +162,7 @@ static ColliderJntSphInit sCyrstalJntSphereInit = { OC2_TYPE_2, COLSHAPE_JNTSPH, }, - 1, + ARRAY_COUNT(D_80B9ED44), D_80B9ED44, }; @@ -248,7 +248,7 @@ void ObjSwitch_SetOn(ObjSwitch* this, GlobalContext* globalCtx) { subType = (this->dyna.actor.params >> 4 & 7); Flags_SetSwitch(globalCtx, (this->dyna.actor.params >> 8 & 0x3F)); - if (subType == 0 || subType == 4) { + if (subType == OBJSWITCH_SUBTYPE_ONCE || subType == OBJSWITCH_SUBTYPE_SYNC) { OnePointCutscene_AttentionSetSfx(globalCtx, &this->dyna.actor, NA_SE_SY_CORRECT_CHIME); } else { OnePointCutscene_AttentionSetSfx(globalCtx, &this->dyna.actor, NA_SE_SY_TRE_BOX_APPEAR); @@ -264,7 +264,7 @@ void ObjSwitch_SetOff(ObjSwitch* this, GlobalContext* globalCtx) { if (Flags_GetSwitch(globalCtx, (this->dyna.actor.params >> 8 & 0x3F))) { Flags_UnsetSwitch(globalCtx, (this->dyna.actor.params >> 8 & 0x3F)); - if ((this->dyna.actor.params >> 4 & 7) == 1) { + if ((this->dyna.actor.params >> 4 & 7) == OBJSWITCH_SUBTYPE_TOGGLE) { OnePointCutscene_AttentionSetSfx(globalCtx, &this->dyna.actor, NA_SE_SY_TRE_BOX_APPEAR); this->cooldownOn = true; } @@ -323,6 +323,8 @@ void ObjSwitch_Init(Actor* thisx, GlobalContext* globalCtx) { if (this->dyna.actor.params >> 7 & 1) { ObjSwitch_EyeFrozenInit(this); } else if (type == OBJSWITCH_TYPE_FLOOR || type == OBJSWITCH_TYPE_FLOOR_RUSTY) { + //! @bug This condition does not account for OBJSWITCH_SUBTYPE_HOLD_INVERTED which expects + //! the relationship between the switch position and the switch flag to be inverted if (switchFlagSet) { ObjSwitch_FloorDownInit(this); } else { @@ -383,25 +385,25 @@ void ObjSwitch_FloorUp(ObjSwitch* this, GlobalContext* globalCtx) { } } else { switch ((this->dyna.actor.params >> 4 & 7)) { - case OBJSWITCH_SUBTYPE_FLOOR_0: + case OBJSWITCH_SUBTYPE_ONCE: if (func_8004356C(&this->dyna)) { ObjSwitch_FloorPressInit(this); ObjSwitch_SetOn(this, globalCtx); } break; - case OBJSWITCH_SUBTYPE_FLOOR_1: + case OBJSWITCH_SUBTYPE_TOGGLE: if ((this->dyna.unk_160 & 2) && !(this->unk_17F & 2)) { ObjSwitch_FloorPressInit(this); ObjSwitch_SetOn(this, globalCtx); } break; - case OBJSWITCH_SUBTYPE_FLOOR_2: + case OBJSWITCH_SUBTYPE_HOLD: if (func_800435B4(&this->dyna)) { ObjSwitch_FloorPressInit(this); ObjSwitch_SetOn(this, globalCtx); } break; - case OBJSWITCH_SUBTYPE_FLOOR_3: + case OBJSWITCH_SUBTYPE_HOLD_INVERTED: if (func_800435B4(&this->dyna)) { ObjSwitch_FloorPressInit(this); ObjSwitch_SetOff(this, globalCtx); @@ -417,7 +419,7 @@ void ObjSwitch_FloorPressInit(ObjSwitch* this) { } void ObjSwitch_FloorPress(ObjSwitch* this, GlobalContext* globalCtx) { - if ((this->dyna.actor.params >> 4 & 7) == OBJSWITCH_SUBTYPE_FLOOR_3 || !this->cooldownOn || + if ((this->dyna.actor.params >> 4 & 7) == OBJSWITCH_SUBTYPE_HOLD_INVERTED || !this->cooldownOn || func_8005B198() == this->dyna.actor.category || this->cooldownTimer <= 0) { this->dyna.actor.scale.y -= 99.0f / 2000.0f; if (this->dyna.actor.scale.y <= 33.0f / 2000.0f) { @@ -436,23 +438,23 @@ void ObjSwitch_FloorDownInit(ObjSwitch* this) { void ObjSwitch_FloorDown(ObjSwitch* this, GlobalContext* globalCtx) { switch ((this->dyna.actor.params >> 4 & 7)) { - case OBJSWITCH_SUBTYPE_FLOOR_0: + case OBJSWITCH_SUBTYPE_ONCE: if (!Flags_GetSwitch(globalCtx, (this->dyna.actor.params >> 8 & 0x3F))) { ObjSwitch_FloorReleaseInit(this); } break; - case OBJSWITCH_SUBTYPE_FLOOR_1: + case OBJSWITCH_SUBTYPE_TOGGLE: if ((this->dyna.unk_160 & 2) && !(this->unk_17F & 2)) { ObjSwitch_FloorReleaseInit(this); ObjSwitch_SetOff(this, globalCtx); } break; - case OBJSWITCH_SUBTYPE_FLOOR_2: - case OBJSWITCH_SUBTYPE_FLOOR_3: + case OBJSWITCH_SUBTYPE_HOLD: + case OBJSWITCH_SUBTYPE_HOLD_INVERTED: if (!func_800435B4(&this->dyna) && !Player_InCsMode(globalCtx)) { if (this->releaseTimer <= 0) { ObjSwitch_FloorReleaseInit(this); - if ((this->dyna.actor.params >> 4 & 7) == OBJSWITCH_SUBTYPE_FLOOR_2) { + if ((this->dyna.actor.params >> 4 & 7) == OBJSWITCH_SUBTYPE_HOLD) { ObjSwitch_SetOff(this, globalCtx); } else { ObjSwitch_SetOn(this, globalCtx); @@ -473,13 +475,13 @@ void ObjSwitch_FloorReleaseInit(ObjSwitch* this) { void ObjSwitch_FloorRelease(ObjSwitch* this, GlobalContext* globalCtx) { s16 subType = (this->dyna.actor.params >> 4 & 7); - if (((subType != OBJSWITCH_SUBTYPE_FLOOR_1) && (subType != OBJSWITCH_SUBTYPE_FLOOR_3)) || !this->cooldownOn || + if (((subType != OBJSWITCH_SUBTYPE_TOGGLE) && (subType != OBJSWITCH_SUBTYPE_HOLD_INVERTED)) || !this->cooldownOn || func_8005B198() == this->dyna.actor.category || this->cooldownTimer <= 0) { this->dyna.actor.scale.y += 99.0f / 2000.0f; if (this->dyna.actor.scale.y >= 33.0f / 200.0f) { ObjSwitch_FloorUpInit(this); Audio_PlayActorSound2(&this->dyna.actor, NA_SE_EV_FOOT_SWITCH); - if (subType == OBJSWITCH_SUBTYPE_FLOOR_1) { + if (subType == OBJSWITCH_SUBTYPE_TOGGLE) { func_800AA000(this->dyna.actor.xyzDistToPlayerSq, 120, 20, 10); } } @@ -549,13 +551,13 @@ void ObjSwitch_EyeClosedInit(ObjSwitch* this) { void ObjSwitch_EyeClosed(ObjSwitch* this, GlobalContext* globalCtx) { switch ((this->dyna.actor.params >> 4 & 7)) { - case OBJSWITCH_SUBTYPE_EYE_0: + case OBJSWITCH_SUBTYPE_ONCE: if (!Flags_GetSwitch(globalCtx, (this->dyna.actor.params >> 8 & 0x3F))) { ObjSwitch_EyeOpeningInit(this); this->dyna.actor.params &= ~0x80; } break; - case OBJSWITCH_SUBTYPE_EYE_1: + case OBJSWITCH_SUBTYPE_TOGGLE: if (ObjSwitch_EyeIsHit(this) || (this->dyna.actor.params >> 7 & 1)) { ObjSwitch_EyeOpeningInit(this); ObjSwitch_SetOff(this, globalCtx); @@ -571,7 +573,7 @@ void ObjSwitch_EyeOpeningInit(ObjSwitch* this) { } void ObjSwitch_EyeOpening(ObjSwitch* this, GlobalContext* globalCtx) { - if ((this->dyna.actor.params >> 4 & 7) != OBJSWITCH_SUBTYPE_EYE_1 || !this->cooldownOn || + if ((this->dyna.actor.params >> 4 & 7) != OBJSWITCH_SUBTYPE_TOGGLE || !this->cooldownOn || func_8005B198() == this->dyna.actor.category || this->cooldownTimer <= 0) { this->eyeTexIndex--; if (this->eyeTexIndex <= 0) { @@ -591,14 +593,14 @@ void ObjSwitch_CrystalOffInit(ObjSwitch* this) { void ObjSwitch_CrystalOff(ObjSwitch* this, GlobalContext* globalCtx) { switch ((this->dyna.actor.params >> 4 & 7)) { - case OBJSWITCH_SUBTYPE_CRYSTAL_0: + case OBJSWITCH_SUBTYPE_ONCE: if ((this->jntSph.col.base.acFlags & AC_HIT) && this->disableAcTimer <= 0) { this->disableAcTimer = 10; ObjSwitch_SetOn(this, globalCtx); ObjSwitch_CrystalTurnOnInit(this); } break; - case OBJSWITCH_SUBTYPE_CRYSTAL_4: + case OBJSWITCH_SUBTYPE_SYNC: if (((this->jntSph.col.base.acFlags & AC_HIT) && this->disableAcTimer <= 0) || Flags_GetSwitch(globalCtx, (this->dyna.actor.params >> 8 & 0x3F))) { this->disableAcTimer = 10; @@ -606,7 +608,7 @@ void ObjSwitch_CrystalOff(ObjSwitch* this, GlobalContext* globalCtx) { ObjSwitch_CrystalTurnOnInit(this); } break; - case OBJSWITCH_SUBTYPE_CRYSTAL_1: + case OBJSWITCH_SUBTYPE_TOGGLE: if ((this->jntSph.col.base.acFlags & AC_HIT) && !(this->unk_17F & 2) && this->disableAcTimer <= 0) { this->disableAcTimer = 10; ObjSwitch_SetOn(this, globalCtx); @@ -625,7 +627,7 @@ void ObjSwitch_CrystalTurnOnInit(ObjSwitch* this) { void ObjSwitch_CrystalTurnOn(ObjSwitch* this, GlobalContext* globalCtx) { if (!this->cooldownOn || func_8005B198() == this->dyna.actor.category || this->cooldownTimer <= 0) { ObjSwitch_CrystalOnInit(this); - if ((this->dyna.actor.params >> 4 & 7) == OBJSWITCH_SUBTYPE_CRYSTAL_1) { + if ((this->dyna.actor.params >> 4 & 7) == OBJSWITCH_SUBTYPE_TOGGLE) { ObjSwitch_UpdateTwoTexScrollXY(this); } Audio_PlayActorSound2(&this->dyna.actor, NA_SE_EV_DIAMOND_SWITCH); @@ -642,13 +644,13 @@ void ObjSwitch_CrystalOnInit(ObjSwitch* this) { void ObjSwitch_CrystalOn(ObjSwitch* this, GlobalContext* globalCtx) { switch ((this->dyna.actor.params >> 4 & 7)) { - case OBJSWITCH_SUBTYPE_CRYSTAL_0: - case OBJSWITCH_SUBTYPE_CRYSTAL_4: + case OBJSWITCH_SUBTYPE_ONCE: + case OBJSWITCH_SUBTYPE_SYNC: if (!Flags_GetSwitch(globalCtx, (this->dyna.actor.params >> 8 & 0x3F))) { ObjSwitch_CrystalTurnOffInit(this); } break; - case OBJSWITCH_SUBTYPE_CRYSTAL_1: + case OBJSWITCH_SUBTYPE_TOGGLE: if ((this->jntSph.col.base.acFlags & AC_HIT) && !(this->unk_17F & 2) && this->disableAcTimer <= 0) { this->disableAcTimer = 10; globalCtx = globalCtx; @@ -666,7 +668,7 @@ void ObjSwitch_CrystalTurnOffInit(ObjSwitch* this) { } void ObjSwitch_CrystalTurnOff(ObjSwitch* this, GlobalContext* globalCtx) { - if ((this->dyna.actor.params >> 4 & 7) != OBJSWITCH_SUBTYPE_CRYSTAL_1 || !this->cooldownOn || + if ((this->dyna.actor.params >> 4 & 7) != OBJSWITCH_SUBTYPE_TOGGLE || !this->cooldownOn || func_8005B198() == this->dyna.actor.category || this->cooldownTimer <= 0) { ObjSwitch_CrystalOffInit(this); ObjSwitch_UpdateTwoTexScrollXY(this); @@ -770,7 +772,7 @@ void ObjSwitch_DrawCrystal(ObjSwitch* this, GlobalContext* globalCtx) { gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_obj_switch.c", 1511), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - if (subType == OBJSWITCH_SUBTYPE_CRYSTAL_1) { + if (subType == OBJSWITCH_SUBTYPE_TOGGLE) { gSPSegment(POLY_OPA_DISP++, 0x09, SEGMENTED_TO_VIRTUAL(this->crystalSubtype1texture)); } diff --git a/src/overlays/actors/ovl_Obj_Switch/z_obj_switch.h b/src/overlays/actors/ovl_Obj_Switch/z_obj_switch.h index 3a44c8af26..323d09ebb2 100644 --- a/src/overlays/actors/ovl_Obj_Switch/z_obj_switch.h +++ b/src/overlays/actors/ovl_Obj_Switch/z_obj_switch.h @@ -17,26 +17,16 @@ typedef enum { } ObjSwitchType; typedef enum { - /* 0 */ OBJSWITCH_SUBTYPE_FLOOR_0, - /* 1 */ OBJSWITCH_SUBTYPE_FLOOR_1, - /* 2 */ OBJSWITCH_SUBTYPE_FLOOR_2, - /* 3 */ OBJSWITCH_SUBTYPE_FLOOR_3 -} ObjSwitchSubTypeFloor; - -typedef enum { - /* 0 */ OBJSWITCH_SUBTYPE_EYE_0, - /* 1 */ OBJSWITCH_SUBTYPE_EYE_1 -} ObjSwitchSubTypeEye; - -typedef enum { - /* 0 */ OBJSWITCH_SUBTYPE_CRYSTAL_0, - /* 1 */ OBJSWITCH_SUBTYPE_CRYSTAL_1, - /* 4 */ OBJSWITCH_SUBTYPE_CRYSTAL_4 = 4 -} ObjSwitchSubTypeCrystal; + /* 0 */ OBJSWITCH_SUBTYPE_ONCE, // Switches that can only be turned on (On -> Flag Set) + /* 1 */ OBJSWITCH_SUBTYPE_TOGGLE, // Switches that can be turned on and off (On -> Flag Set, Off -> Flag Cleared) + /* 2 */ OBJSWITCH_SUBTYPE_HOLD, // Floor Types only, released when not stood on (Down -> Flag Set, Up -> Flag Cleared) + /* 3 */ OBJSWITCH_SUBTYPE_HOLD_INVERTED, // Floor Types only, unused, inverted Switch Flag behavior (Down -> Flag Cleared, Up -> Flag Set) + /* 4 */ OBJSWITCH_SUBTYPE_SYNC // Crystal Types only, syncs with the Switch Flag (On -> Flag Set, Off -> Flag Cleared) +} ObjSwitchSubType; typedef struct { /* 0x00 */ ColliderJntSph col; - /* 0x20 */ ColliderJntSphElement items[2]; + /* 0x20 */ ColliderJntSphElement items[1]; } ObjSwitchJntSph; typedef struct { @@ -47,7 +37,7 @@ typedef struct { typedef struct ObjSwitch { /* 0x0000 */ DynaPolyActor dyna; /* 0x0164 */ ObjSwitchActionFunc actionFunc; - /* 0x0168 */ s16 releaseTimer; // used for SUBTYPE_FLOOR_2 and SUBTYPE_FLOOR_3 + /* 0x0168 */ s16 releaseTimer; // used for SUBTYPE_HOLD and SUBTYPE_HOLD_INVERTED /* 0x016A */ s16 disableAcTimer; /* 0x016C */ s16 cooldownTimer; /* 0x016E */ u8 cooldownOn; @@ -58,7 +48,7 @@ typedef struct ObjSwitch { /* 0x017A */ u8 x2TexScroll; /* 0x017B */ u8 y2TexScroll; /* 0x017C */ Color_RGB8 crystalColor; - /* 0x017F */ u8 unk_17F; // used for different purposes between floor and eye switch + /* 0x017F */ u8 unk_17F; union { /* 0x0180 */ ObjSwitchJntSph jntSph; /* 0x0180 */ ObjSwitchTris tris;