From 7fcbf3f4b280e26284a8f62dbcb5b72d0e24dcc4 Mon Sep 17 00:00:00 2001 From: fig02 Date: Sat, 27 Jul 2024 23:47:58 -0400 Subject: [PATCH] Document `ANIM_FLAG_PLAYER_2` as `ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT` (#2001) * name ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT * reword * typo --- include/z64animation.h | 13 ++- src/code/z_player_lib.c | 5 +- .../actors/ovl_player_actor/z_player.c | 84 +++++++++++-------- 3 files changed, 60 insertions(+), 42 deletions(-) diff --git a/include/z64animation.h b/include/z64animation.h index 782380ad20..ff4df48a22 100644 --- a/include/z64animation.h +++ b/include/z64animation.h @@ -106,8 +106,15 @@ typedef enum { // An option is to implement and use `ANIM_FLAG_OVERRIDE_MOVEMENT`. #define ANIM_FLAG_UPDATE_Y (1 << 1) -// (player-only) Related to scaling an animation from/to child/adult -#define ANIM_FLAG_PLAYER_2 (1 << 2) +// When this flag is set, Player's root limb position adjustment as child is disabled. +// Many of Player's animations are originally created for Adult Link. When playing those +// animations as Child Link without any adjustment, he will appear to be floating in the air. +// To fix this, Child Link's root position is scaled down by default to fit his smaller size. +// However, if an animation is created specifically for Child Link, it is desirable to disable +// this scaling of the root position by using this flag. +// Note that this flag will be ignored if `ANIM_FLAG_UPDATE_XZ` or `ANIM_FLAG_UPDATE_Y` are also +// set. The adjustment will be applied in this case regardless of this flag being enabled. +#define ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT (1 << 2) // (player-only) Call AnimTaskQueue_AddActorMove #define ANIM_FLAG_PLAYER_SETMOVE (1 << 3) @@ -123,7 +130,7 @@ typedef enum { // Some animations have translation data that does not begin at the "origin". This is common when a // longer sequence of animation is broken up into different parts as seperate animations. // In this case, when one animation starts its translation at the same position where a different animation -// left off, resetting `prevTransl` is not desireable. This will cause the actor's position to noticeably change +// left off, resetting `prevTransl` is not desirable. This will cause the actor's position to noticeably change // when the translation data from the first frame of the new animation is applied. // // When this flag is used during a transition between two animations, the first frame of movement is not applied. diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index 1c05d26f90..7b90a1e35f 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -1125,13 +1125,14 @@ s32 Player_OverrideLimbDrawGameplayCommon(PlayState* play, s32 limbIndex, Gfx** sCurBodyPartPos = &this->bodyPartsPos[0] - 1; if (!LINK_IS_ADULT) { - if (!(this->skelAnime.moveFlags & ANIM_FLAG_PLAYER_2) || + if (!(this->skelAnime.moveFlags & ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT) || (this->skelAnime.moveFlags & ANIM_FLAG_UPDATE_XZ)) { pos->x *= 0.64f; pos->z *= 0.64f; } - if (!(this->skelAnime.moveFlags & ANIM_FLAG_PLAYER_2) || (this->skelAnime.moveFlags & ANIM_FLAG_UPDATE_Y)) { + if (!(this->skelAnime.moveFlags & ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT) || + (this->skelAnime.moveFlags & ANIM_FLAG_UPDATE_Y)) { pos->y *= 0.64f; } } diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 9ac957cc02..0073b5d76e 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -2008,7 +2008,8 @@ void Player_AnimReplacePlayOnceAdjusted(PlayState* play, Player* this, LinkAnima void Player_AnimReplaceNormalPlayOnceAdjusted(PlayState* play, Player* this, LinkAnimationHeader* anim) { Player_AnimReplacePlayOnceAdjusted(play, this, anim, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS); + ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | ANIM_FLAG_PLAYER_SETMOVE | + ANIM_FLAG_ADJUST_STARTING_POS); } void Player_AnimReplacePlayLoopSetSpeed(PlayState* play, Player* this, LinkAnimationHeader* anim, s32 flags, @@ -2027,7 +2028,8 @@ void Player_AnimReplacePlayLoopAdjusted(PlayState* play, Player* this, LinkAnima void Player_AnimReplaceNormalPlayLoopAdjusted(PlayState* play, Player* this, LinkAnimationHeader* anim) { Player_AnimReplacePlayLoopAdjusted(play, this, anim, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS); + ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | ANIM_FLAG_PLAYER_SETMOVE | + ANIM_FLAG_ADJUST_STARTING_POS); } void Player_ProcessControlStick(PlayState* play, Player* this) { @@ -5056,7 +5058,7 @@ s32 Player_ActionChange_1(Player* this, PlayState* play) { func_80832224(this); Player_AnimReplaceApplyFlags(play, this, ANIM_REPLACE_APPLY_FLAG_9 | ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | + ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); // If this door is the second half of a double door (spawned as child) @@ -5367,9 +5369,9 @@ s32 func_8083A6AC(Player* this, PlayState* play) { this->stateFlags1 |= PLAYER_STATE1_21; Player_AnimReplaceApplyFlags(play, this, - ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | ANIM_FLAG_PLAYER_2 | - ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | - ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | + ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | ANIM_FLAG_PLAYER_SETMOVE | + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); this->av2.actionVar2 = -1; this->av1.actionVar1 = sp50; @@ -6062,7 +6064,7 @@ s32 Player_ActionChange_11(Player* this, PlayState* play) { LinkAnimation_Change(play, &this->skelAnime, anim, 1.0f, frame, frame, ANIMMODE_ONCE, 0.0f); if (Player_IsChildWithHylianShield(this)) { - Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_PLAYER_2); + Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT); } Player_PlaySfx(this, NA_SE_IT_SHIELD_POSTURE); @@ -6892,8 +6894,8 @@ s32 Player_ActionChange_2(Player* this, PlayState* play) { Player_AnimPlayOnceAdjusted(play, this, this->ageProperties->unk_98); Player_AnimReplaceApplyFlags(play, this, ANIM_REPLACE_APPLY_FLAG_9 | ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | + ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); chest->unk_1F4 = 1; Camera_RequestSetting(Play_GetCamera(play, CAM_ID_MAIN), CAM_SET_SLOW_CHEST_CS); } else { @@ -7069,10 +7071,10 @@ s32 func_8083EC18(Player* this, PlayState* play, u32 wallFlags) { func_80832224(this); Math_Vec3f_Copy(&this->actor.prevPos, &this->actor.world.pos); Player_AnimPlayOnce(play, this, anim); - Player_AnimReplaceApplyFlags(play, this, - ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | ANIM_FLAG_PLAYER_2 | - ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | - ANIM_FLAG_OVERRIDE_MOVEMENT); + Player_AnimReplaceApplyFlags( + play, this, + ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | + ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); return true; } @@ -7152,8 +7154,9 @@ s32 Player_TryEnteringCrawlspace(Player* this, PlayState* play, u32 interactWall this->actor.prevPos = this->actor.world.pos; Player_AnimPlayOnce(play, this, &gPlayerAnim_link_child_tunnel_start); Player_AnimReplaceApplyFlags(play, this, - ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | + ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | + ANIM_FLAG_OVERRIDE_MOVEMENT); return true; } @@ -7242,8 +7245,9 @@ s32 Player_TryLeavingCrawlspace(Player* this, PlayState* play) { this->actor.shape.rot.y = this->actor.wallYaw + 0x8000; Player_AnimPlayOnce(play, this, &gPlayerAnim_link_child_tunnel_end); Player_AnimReplaceApplyFlags(play, this, - ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | + ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | + ANIM_FLAG_OVERRIDE_MOVEMENT); OnePointCutscene_Init(play, 9601, 999, NULL, CAM_ID_MAIN); } else { // Leaving a crawlspace backwards @@ -7252,8 +7256,9 @@ s32 Player_TryLeavingCrawlspace(Player* this, PlayState* play) { Animation_GetLastFrame(&gPlayerAnim_link_child_tunnel_start), 0.0f, ANIMMODE_ONCE, 0.0f); Player_AnimReplaceApplyFlags(play, this, - ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | + ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | + ANIM_FLAG_OVERRIDE_MOVEMENT); OnePointCutscene_Init(play, 9602, 999, NULL, CAM_ID_MAIN); } @@ -8661,7 +8666,7 @@ void Player_Action_80843188(Player* this, PlayState* play) { LinkAnimation_Change(play, &this->skelAnime, &gPlayerAnim_clink_normal_defense_ALL, 1.0f, Animation_GetLastFrame(&gPlayerAnim_clink_normal_defense_ALL), 0.0f, ANIMMODE_ONCE, 0.0f); - Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_PLAYER_2); + Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT); } else { if (this->itemAction < 0) { func_8008EC70(this); @@ -9972,7 +9977,8 @@ void func_808467D4(PlayState* play, Player* this) { 0.0f); Player_AnimReplaceApplyFlags(play, this, ANIM_REPLACE_APPLY_FLAG_9 | ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | ANIM_FLAG_PLAYER_SETMOVE | + ANIM_FLAG_OVERRIDE_MOVEMENT); if (LINK_IS_ADULT) { func_80846720(play, this, 0); } @@ -11350,8 +11356,9 @@ void Player_UpdateCommon(Player* this, PlayState* play, Input* input) { if (this->skelAnime.moveFlags & ANIM_FLAG_PLAYER_SETMOVE) { AnimTaskQueue_AddActorMove(play, &this->actor, &this->skelAnime, - (this->skelAnime.moveFlags & ANIM_FLAG_PLAYER_2) ? 1.0f - : this->ageProperties->unk_08); + (this->skelAnime.moveFlags & ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT) + ? 1.0f + : this->ageProperties->unk_08); } Player_UpdateShapeYaw(this, play); @@ -14549,8 +14556,8 @@ void func_808510D4(PlayState* play, Player* this, void* anim) { void func_808510F4(PlayState* play, Player* this, void* anim) { Player_AnimReplacePlayOnce(play, this, anim, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | - ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | ANIM_FLAG_PLAYER_SETMOVE | + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); } void func_80851114(PlayState* play, Player* this, void* anim) { @@ -14559,8 +14566,8 @@ void func_80851114(PlayState* play, Player* this, void* anim) { void func_80851134(PlayState* play, Player* this, void* anim) { Player_AnimReplacePlayLoop(play, this, anim, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | - ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | ANIM_FLAG_PLAYER_SETMOVE | + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); } void func_80851154(PlayState* play, Player* this, void* anim) { @@ -14807,7 +14814,8 @@ void func_808519EC(PlayState* play, Player* this, CsCmdActorCue* cue) { Player_AnimPlayOnceAdjusted(play, this, this->ageProperties->unk_9C); Player_AnimReplaceApplyFlags(play, this, ANIM_REPLACE_APPLY_FLAG_9 | ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | ANIM_FLAG_PLAYER_SETMOVE | + ANIM_FLAG_OVERRIDE_MOVEMENT); } static struct_808551A4 D_808551A4[] = { @@ -14924,16 +14932,16 @@ void func_80851E64(PlayState* play, Player* this, CsCmdActorCue* cue) { void func_80851E90(PlayState* play, Player* this, CsCmdActorCue* cue) { Player_AnimReplacePlayOnce(play, this, &gPlayerAnim_clink_op3_negaeri, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | - ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | ANIM_FLAG_PLAYER_SETMOVE | + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); func_80832698(this, NA_SE_VO_LI_GROAN); } void func_80851ECC(PlayState* play, Player* this, CsCmdActorCue* cue) { if (LinkAnimation_Update(play, &this->skelAnime)) { Player_AnimReplacePlayLoop(play, this, &gPlayerAnim_clink_op3_wait2, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | - ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | ANIM_FLAG_PLAYER_SETMOVE | + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); } } @@ -14960,8 +14968,8 @@ static AnimSfxEntry D_808551BC[] = { void func_80851FB0(PlayState* play, Player* this, CsCmdActorCue* cue) { if (LinkAnimation_Update(play, &this->skelAnime)) { Player_AnimReplacePlayLoop(play, this, &gPlayerAnim_clink_op3_wait3, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | - ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | ANIM_FLAG_PLAYER_SETMOVE | + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); this->av2.actionVar2 = 1; } else if (this->av2.actionVar2 == 0) { Player_ProcessAnimSfxList(this, D_808551BC); @@ -14985,8 +14993,9 @@ void func_80852048(PlayState* play, Player* this, CsCmdActorCue* cue) { void func_80852080(PlayState* play, Player* this, CsCmdActorCue* cue) { Player_AnimReplacePlayOnceAdjusted(play, this, &gPlayerAnim_clink_demo_futtobi, - ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT | + ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | + ANIM_FLAG_OVERRIDE_MOVEMENT); func_80832698(this, NA_SE_VO_LI_FALL_L); } @@ -15273,7 +15282,8 @@ void func_80852B4C(PlayState* play, Player* this, CsCmdActorCue* cue, struct_808 arg3->func(play, this, cue); } - if ((D_80858AA0 & ANIM_FLAG_PLAYER_2) && !(this->skelAnime.moveFlags & ANIM_FLAG_PLAYER_2)) { + if ((D_80858AA0 & ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT) && + !(this->skelAnime.moveFlags & ANIM_FLAG_DISABLE_CHILD_ROOT_ADJUSTMENT)) { this->skelAnime.morphTable[0].y /= this->ageProperties->unk_08; D_80858AA0 = 0; }