From da2e8a8f2c07b40a7bb4eaeeddaf7a6249933bbe Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Wed, 30 Nov 2022 18:46:12 +0100 Subject: [PATCH] Skelanime/Animation header cleanup (#1434) * Skelanime/Animation header cleanup * touch up names of the two existing moveFlags macros * formatter is a dum dum D: --- include/functions.h | 86 --------- include/macros.h | 4 +- include/z64.h | 31 +--- include/z64animation.h | 327 +++++++++++++++++++++++++--------- include/z64animation_legacy.h | 40 +++++ src/code/z_skelanime.c | 16 +- 6 files changed, 293 insertions(+), 211 deletions(-) create mode 100644 include/z64animation_legacy.h diff --git a/include/functions.h b/include/functions.h index d017977d4f..2cc26a9d3e 100644 --- a/include/functions.h +++ b/include/functions.h @@ -494,7 +494,6 @@ void func_80034BA0(PlayState* play, SkelAnime* skelAnime, OverrideLimbDraw overr void func_80034CC4(PlayState* play, SkelAnime* skelAnime, OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, Actor* actor, s16 alpha); s16 func_80034DD4(Actor* actor, PlayState* play, s16 arg2, f32 arg3); -void Animation_ChangeByInfo(SkelAnime* skelAnime, AnimationInfo* animationInfo, s32 index); void func_80034F54(PlayState* play, s16* arg1, s16* arg2, s32 arg3); void Actor_Noop(Actor* actor, PlayState* play); void Gfx_DrawDListOpa(PlayState* play, Gfx* dlist); @@ -1117,91 +1116,6 @@ s32 Scene_ExecuteCommands(PlayState* play, SceneCmd* sceneCmd); void TransitionActor_InitContext(GameState* state, TransitionActorContext* transiActorCtx); void Scene_SetTransitionForNextEntrance(PlayState* play); void Scene_Draw(PlayState* play); -void SkelAnime_DrawLod(PlayState* play, void** skeleton, Vec3s* jointTable, - OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg, s32 lod); -void SkelAnime_DrawFlexLod(PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount, - OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg, s32 lod); -void SkelAnime_DrawOpa(PlayState* play, void** skeleton, Vec3s* jointTable, - OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg); -void SkelAnime_DrawFlexOpa(PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount, - OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg); -s16 Animation_GetLength(void* animation); -s16 Animation_GetLastFrame(void* animation); -s32 SkelAnime_GetFrameDataLegacy(LegacyAnimationHeader* animation, s32 frame, Vec3s* frameTable); -s16 Animation_GetLimbCountLegacy(LegacyAnimationHeader* animation); -s16 Animation_GetLengthLegacy(LegacyAnimationHeader* animation); -s16 Animation_GetLastFrameLegacy(LegacyAnimationHeader* animation); -Gfx* SkelAnime_Draw(PlayState* play, void** skeleton, Vec3s* jointTable, OverrideLimbDraw overrideLimbDraw, - PostLimbDraw postLimbDraw, void* arg, Gfx* gfx); -Gfx* SkelAnime_DrawFlex(PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount, - OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, void* arg, Gfx* gfx); -void SkelAnime_InterpFrameTable(s32 limbCount, Vec3s* dst, Vec3s* start, Vec3s* target, f32 weight); -void AnimationContext_Reset(AnimationContext* animationCtx); -void AnimationContext_SetNextQueue(PlayState* play); -void AnimationContext_DisableQueue(PlayState* play); -void AnimationContext_SetLoadFrame(PlayState* play, LinkAnimationHeader* animation, s32 frame, s32 limbCount, - Vec3s* frameTable); -void AnimationContext_SetCopyAll(PlayState* play, s32 vecCount, Vec3s* dst, Vec3s* src); -void AnimationContext_SetInterp(PlayState* play, s32 vecCount, Vec3s* base, Vec3s* mod, f32 weight); -void AnimationContext_SetCopyTrue(PlayState* play, s32 vecCount, Vec3s* dst, Vec3s* src, u8* copyFlag); -void AnimationContext_SetCopyFalse(PlayState* play, s32 vecCount, Vec3s* dst, Vec3s* src, u8* copyFlag); -void AnimationContext_SetMoveActor(PlayState* play, Actor* actor, SkelAnime* skelAnime, f32 arg3); -void AnimationContext_Update(PlayState* play, AnimationContext* animationCtx); -void SkelAnime_InitLink(PlayState* play, SkelAnime* skelAnime, FlexSkeletonHeader* skeletonHeaderSeg, - LinkAnimationHeader* animation, s32 flags, Vec3s* jointTable, Vec3s* morphTable, - s32 limbBufCount); -void LinkAnimation_SetUpdateFunction(SkelAnime* skelAnime); -s32 LinkAnimation_Update(PlayState* play, SkelAnime* skelAnime); -void LinkAnimation_AnimateFrame(PlayState* play, SkelAnime* skelAnime); -void Animation_SetMorph(PlayState* play, SkelAnime* skelAnime, f32 morphFrames); -void LinkAnimation_Change(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, f32 playSpeed, - f32 startFrame, f32 endFrame, u8 mode, f32 morphFrames); -void LinkAnimation_PlayOnce(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation); -void LinkAnimation_PlayOnceSetSpeed(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, - f32 playSpeed); -void LinkAnimation_PlayLoop(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation); -void LinkAnimation_PlayLoopSetSpeed(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, - f32 playSpeed); -void LinkAnimation_CopyJointToMorph(PlayState* play, SkelAnime* skelAnime); -void LinkAnimation_CopyMorphToJoint(PlayState* play, SkelAnime* skelAnime); -void LinkAnimation_LoadToMorph(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, - f32 frame); -void LinkAnimation_LoadToJoint(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, - f32 frame); -void LinkAnimation_InterpJointMorph(PlayState* play, SkelAnime* skelAnime, f32 weight); -void LinkAnimation_BlendToJoint(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation1, - f32 frame1, LinkAnimationHeader* animation2, f32 frame2, f32 blendWeight, - Vec3s* blendTable); -void LinkAnimation_BlendToMorph(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation1, - f32 frame1, LinkAnimationHeader* animation2, f32 frame2, f32 blendWeight, - Vec3s* blendTable); -void LinkAnimation_EndLoop(SkelAnime* skelAnime); -s32 LinkAnimation_OnFrame(SkelAnime* skelAnime, f32 frame); -BAD_RETURN(s32) SkelAnime_Init(PlayState* play, SkelAnime* skelAnime, SkeletonHeader* skeletonHeaderSeg, - AnimationHeader* animation, Vec3s* jointTable, Vec3s* morphTable, s32 limbCount); -BAD_RETURN(s32) SkelAnime_InitFlex(PlayState* play, SkelAnime* skelAnime, FlexSkeletonHeader* skeletonHeaderSeg, - AnimationHeader* animation, Vec3s* jointTable, Vec3s* morphTable, s32 limbCount); -BAD_RETURN(s32) SkelAnime_InitSkin(PlayState* play, SkelAnime* skelAnime, SkeletonHeader* skeletonHeaderSeg, - AnimationHeader* animation); -s32 SkelAnime_Update(SkelAnime* skelAnime); -void Animation_ChangeImpl(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed, f32 startFrame, f32 endFrame, - u8 mode, f32 morphFrames, s8 taper); -void Animation_Change(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed, f32 startFrame, f32 endFrame, - u8 mode, f32 morphFrames); -void Animation_PlayOnce(SkelAnime* skelAnime, AnimationHeader* animation); -void Animation_MorphToPlayOnce(SkelAnime* skelAnime, AnimationHeader* animation, f32 morphFrames); -void Animation_PlayOnceSetSpeed(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed); -void Animation_PlayLoop(SkelAnime* skelAnime, AnimationHeader* animation); -void Animation_MorphToLoop(SkelAnime* skelAnime, AnimationHeader* animation, f32 morphFrames); -void Animation_PlayLoopSetSpeed(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed); -void Animation_EndLoop(SkelAnime* skelAnime); -void Animation_Reverse(SkelAnime* skelAnime); -void SkelAnime_CopyFrameTableTrue(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src, u8* copyFlag); -void SkelAnime_CopyFrameTableFalse(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src, u8* copyFlag); -void SkelAnime_UpdateTranslation(SkelAnime* skelAnime, Vec3f* diff, s16 angle); -s32 Animation_OnFrame(SkelAnime* skelAnime, f32 frame); -void SkelAnime_Free(SkelAnime* skelAnime, PlayState* play); -void SkelAnime_CopyFrameTable(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src); void Skin_UpdateVertices(MtxF* mtx, SkinVertex* skinVertices, SkinLimbModif* modifEntry, Vtx* vtxBuf, Vec3f* pos); void Skin_DrawAnimatedLimb(GraphicsContext* gfxCtx, Skin* skin, s32 limbIndex, s32 arg3, s32 drawFlags); diff --git a/include/macros.h b/include/macros.h index 6aa5745e5e..fc0615266a 100644 --- a/include/macros.h +++ b/include/macros.h @@ -139,7 +139,9 @@ } \ (void)0 -extern GraphicsContext* __gfxCtx; +struct GraphicsContext; + +extern struct GraphicsContext* __gfxCtx; #define WORK_DISP __gfxCtx->work.p #define POLY_OPA_DISP __gfxCtx->polyOpa.p diff --git a/include/z64.h b/include/z64.h index 2a02d483a5..5599d6c4de 100644 --- a/include/z64.h +++ b/include/z64.h @@ -20,6 +20,7 @@ #include "z64effect.h" #include "z64item.h" #include "z64animation.h" +#include "z64animation_legacy.h" #include "z64dma.h" #include "z64math.h" #include "z64map_mark.h" @@ -1258,36 +1259,6 @@ typedef struct { /* 0x1CAD6 */ s16 unk_1CAD6[5]; } FileSelectState; // size = 0x1CAE0 -typedef struct { - /* 0x00 */ AnimationHeader* animation; - /* 0x04 */ f32 playSpeed; - /* 0x08 */ f32 startFrame; - /* 0x0C */ f32 frameCount; - /* 0x10 */ u8 mode; - /* 0x14 */ f32 morphFrames; -} AnimationInfo; // size = 0x18 - -typedef struct { - /* 0x00 */ AnimationHeader* animation; - /* 0x04 */ f32 frameCount; - /* 0x08 */ u8 mode; - /* 0x0C */ f32 morphFrames; -} AnimationFrameCountInfo; // size = 0x10 - -typedef struct { - /* 0x00 */ AnimationHeader* animation; - /* 0x04 */ f32 playSpeed; - /* 0x08 */ u8 mode; - /* 0x0C */ f32 morphFrames; -} AnimationSpeedInfo; // size = 0x10 - -typedef struct { - /* 0x00 */ AnimationHeader* animation; - /* 0x04 */ u8 mode; - /* 0x08 */ f32 morphFrames; -} AnimationMinimalInfo; // size = 0xC - - // Macros for `EntranceInfo.field` #define ENTRANCE_INFO_CONTINUE_BGM_FLAG (1 << 15) #define ENTRANCE_INFO_DISPLAY_TITLE_CARD_FLAG (1 << 14) diff --git a/include/z64animation.h b/include/z64animation.h index 830befae79..c7108a6681 100755 --- a/include/z64animation.h +++ b/include/z64animation.h @@ -4,32 +4,17 @@ #include "ultra64.h" #include "z64dma.h" #include "z64math.h" +#include "macros.h" struct PlayState; struct Actor; struct SkelAnime; -#define LINK_ANIMATION_OFFSET(addr, offset) \ - (((uintptr_t)_link_animetionSegmentRomStart) + ((uintptr_t)(addr)) - ((uintptr_t)_link_animetionSegmentStart) + (offset)) +/* + * Skeletons and limbs + */ + #define LIMB_DONE 0xFF -#define ANIMATION_ENTRY_MAX 50 -#define ANIM_FLAG_UPDATEY (1 << 1) -#define ANIM_FLAG_NOMOVE (1 << 4) - -typedef enum { - /* 0 */ ANIMMODE_LOOP, - /* 1 */ ANIMMODE_LOOP_INTERP, - /* 2 */ ANIMMODE_ONCE, - /* 3 */ ANIMMODE_ONCE_INTERP, - /* 4 */ ANIMMODE_LOOP_PARTIAL, - /* 5 */ ANIMMODE_LOOP_PARTIAL_INTERP -} AnimationMode; - -typedef enum { - /* -1 */ ANIMTAPER_DECEL = -1, - /* 0 */ ANIMTAPER_NONE, - /* 1 */ ANIMTAPER_ACCEL -} AnimationTapers; typedef struct { /* 0x00 */ Vec3s jointPos; // Root is position in model space, children are relative to parent @@ -45,14 +30,6 @@ typedef struct { /* 0x08 */ Gfx* dLists[2]; // Near and far } LodLimb; // size = 0x10 -typedef struct LegacyLimb { - /* 0x000 */ Gfx* dList; - /* 0x004 */ Vec3f trans; - /* 0x010 */ Vec3s rot; - /* 0x018 */ struct LegacyLimb* sibling; - /* 0x01C */ struct LegacyLimb* child; -} LegacyLimb; // size = 0x20 - // Model has limbs with only rigid meshes typedef struct { /* 0x00 */ void** segment; @@ -65,6 +42,10 @@ typedef struct { /* 0x08 */ u8 dListCount; } FlexSkeletonHeader; // size = 0xC +/* + * Animations + */ + // Index into the frame data table. typedef struct { /* 0x00 */ u16 x; @@ -88,41 +69,182 @@ typedef struct { /* 0x0C */ u16 staticIndexMax; } AnimationHeader; // size = 0x10 -// Unused -typedef struct { - /* 0x00 */ s16 xMax; - /* 0x02 */ s16 x; - /* 0x04 */ s16 yMax; - /* 0x06 */ s16 y; - /* 0x08 */ s16 zMax; - /* 0x0A */ s16 z; -} JointKey; // size = 0x0C - -// Unused -typedef struct { - /* 0x00 */ s16 frameCount; - /* 0x02 */ s16 limbCount; - /* 0x04 */ s16* frameData; - /* 0x08 */ JointKey* jointKey; -} LegacyAnimationHeader; // size = 0xC - -typedef s32 (*OverrideLimbDrawOpa)(struct PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, - void*); - -typedef void (*PostLimbDrawOpa)(struct PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot, void*); - -typedef s32 (*OverrideLimbDraw)(struct PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, - void*, Gfx** gfx); - -typedef void (*PostLimbDraw)(struct PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot, void*, Gfx** gfx); +/* + * SkelAnime + */ typedef enum { - ANIMENTRY_LOADFRAME, - ANIMENTRY_COPYALL, - ANIMENTRY_INTERP, - ANIMENTRY_COPYTRUE, - ANIMENTRY_COPYFALSE, - ANIMENTRY_MOVEACTOR + /* 0 */ ANIMMODE_LOOP, + /* 1 */ ANIMMODE_LOOP_INTERP, + /* 2 */ ANIMMODE_ONCE, + /* 3 */ ANIMMODE_ONCE_INTERP, + /* 4 */ ANIMMODE_LOOP_PARTIAL, + /* 5 */ ANIMMODE_LOOP_PARTIAL_INTERP +} AnimationMode; + +typedef enum { + /* -1 */ ANIMTAPER_DECEL = -1, + /* 0 */ ANIMTAPER_NONE, + /* 1 */ ANIMTAPER_ACCEL +} AnimationTapers; + +#define ANIM_FLAG_UPDATE_Y (1 << 1) +#define ANIM_FLAG_NO_MOVE (1 << 4) + +typedef struct SkelAnime { + /* 0x00 */ u8 limbCount; // Number of limbs in the skeleton + /* 0x01 */ u8 mode; // See `AnimationMode` + /* 0x02 */ u8 dListCount; // Number of display lists in a flexible skeleton + /* 0x03 */ s8 taper; // Tapering to use when morphing between animations. Only used by Door_Warp1. + /* 0x04 */ void** skeleton; // An array of pointers to limbs. Can be StandardLimb, LodLimb, or SkinLimb. + /* 0x08 */ void* animation; // Can be an AnimationHeader or LinkAnimationHeader. + /* 0x0C */ f32 startFrame; // In mode ANIMMODE_LOOP_PARTIAL*, start of partial loop. + /* 0x10 */ f32 endFrame; // In mode ANIMMODE_ONCE*, Update returns true when curFrame is equal to this. In mode ANIMMODE_LOOP_PARTIAL*, end of partial loop. + /* 0x14 */ f32 animLength; // Total number of frames in the current animation. + /* 0x18 */ f32 curFrame; // Current frame in the animation + /* 0x1C */ f32 playSpeed; // Multiplied by R_UPDATE_RATE / 3 to get the animation's frame rate. + /* 0x20 */ Vec3s* jointTable; // Current translation of model and rotations of all limbs + /* 0x24 */ Vec3s* morphTable; // Table of values used to morph between animations + /* 0x28 */ f32 morphWeight; // Weight of the current animation morph as a fraction in [0,1] + /* 0x2C */ f32 morphRate; // Reciprocal of the number of frames in the morph + /* 0x30 */ union { + s32 (*normal)(struct SkelAnime*); // Can be Loop, Partial loop, Play once, Morph, or Tapered morph + s32 (*link)(struct PlayState*, struct SkelAnime*); // Can be Loop, Play once, or Morph + } update; + /* 0x34 */ s8 initFlags; // Flags used when initializing Link's skeleton + /* 0x35 */ u8 moveFlags; // Flags used for animations that move the actor in worldspace. + /* 0x36 */ s16 prevRot; // Previous rotation in worldspace. + /* 0x38 */ Vec3s prevTransl; // Previous modelspace translation. + /* 0x3E */ Vec3s baseTransl; // Base modelspace translation. +} SkelAnime; // size = 0x44 + +// Init + +BAD_RETURN(s32) SkelAnime_Init(struct PlayState* play, SkelAnime* skelAnime, SkeletonHeader* skeletonHeaderSeg, + AnimationHeader* animation, Vec3s* jointTable, Vec3s* morphTable, s32 limbCount); +BAD_RETURN(s32) SkelAnime_InitFlex(struct PlayState* play, SkelAnime* skelAnime, FlexSkeletonHeader* skeletonHeaderSeg, + AnimationHeader* animation, Vec3s* jointTable, Vec3s* morphTable, s32 limbCount); +BAD_RETURN(s32) SkelAnime_InitSkin(struct PlayState* play, SkelAnime* skelAnime, SkeletonHeader* skeletonHeaderSeg, + AnimationHeader* animation); + +void SkelAnime_InitLink(struct PlayState* play, SkelAnime* skelAnime, FlexSkeletonHeader* skeletonHeaderSeg, + LinkAnimationHeader* animation, s32 flags, Vec3s* jointTable, Vec3s* morphTable, + s32 limbBufCount); + +// Free + +void SkelAnime_Free(SkelAnime* skelAnime, struct PlayState* play); + +// Update + +s32 SkelAnime_Update(SkelAnime* skelAnime); + +// Draw + +typedef s32 (*OverrideLimbDraw)(struct PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void*, + Gfx** gfx); +typedef void (*PostLimbDraw)(struct PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot, void*, Gfx** gfx); + +typedef s32 (*OverrideLimbDrawOpa)(struct PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void*); +typedef void (*PostLimbDrawOpa)(struct PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot, void*); + +Gfx* SkelAnime_Draw(struct PlayState* play, void** skeleton, Vec3s* jointTable, OverrideLimbDraw overrideLimbDraw, + PostLimbDraw postLimbDraw, void* arg, Gfx* gfx); +void SkelAnime_DrawOpa(struct PlayState* play, void** skeleton, Vec3s* jointTable, OverrideLimbDrawOpa overrideLimbDraw, + PostLimbDrawOpa postLimbDraw, void* arg); + +Gfx* SkelAnime_DrawFlex(struct PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount, + OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, void* arg, Gfx* gfx); +void SkelAnime_DrawFlexOpa(struct PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount, + OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg); + +void SkelAnime_DrawLod(struct PlayState* play, void** skeleton, Vec3s* jointTable, OverrideLimbDrawOpa overrideLimbDraw, + PostLimbDrawOpa postLimbDraw, void* arg, s32 lod); + +void SkelAnime_DrawFlexLod(struct PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount, + OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg, s32 lod); + +// Misc. operations + +void SkelAnime_CopyFrameTable(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src); +void SkelAnime_CopyFrameTableTrue(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src, u8* copyFlag); +void SkelAnime_CopyFrameTableFalse(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src, u8* copyFlag); + +void SkelAnime_InterpFrameTable(s32 limbCount, Vec3s* dst, Vec3s* start, Vec3s* target, f32 weight); + +void SkelAnime_UpdateTranslation(SkelAnime* skelAnime, Vec3f* diff, s16 angle); + +/* + * Play animations + */ + +void Animation_Change(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed, f32 startFrame, f32 endFrame, + u8 mode, f32 morphFrames); +void Animation_ChangeImpl(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed, f32 startFrame, f32 endFrame, + u8 mode, f32 morphFrames, s8 taper); + +void Animation_PlayOnce(SkelAnime* skelAnime, AnimationHeader* animation); +void Animation_PlayOnceSetSpeed(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed); +void Animation_MorphToPlayOnce(SkelAnime* skelAnime, AnimationHeader* animation, f32 morphFrames); + +void Animation_PlayLoop(SkelAnime* skelAnime, AnimationHeader* animation); +void Animation_PlayLoopSetSpeed(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed); +void Animation_MorphToLoop(SkelAnime* skelAnime, AnimationHeader* animation, f32 morphFrames); + +void Animation_EndLoop(SkelAnime* skelAnime); +void Animation_Reverse(SkelAnime* skelAnime); +void Animation_SetMorph(struct PlayState* play, SkelAnime* skelAnime, f32 morphFrames); + +typedef struct { + /* 0x00 */ AnimationHeader* animation; + /* 0x04 */ f32 playSpeed; + /* 0x08 */ f32 startFrame; + /* 0x0C */ f32 frameCount; + /* 0x10 */ u8 mode; + /* 0x14 */ f32 morphFrames; +} AnimationInfo; // size = 0x18 + +void Animation_ChangeByInfo(SkelAnime* skelAnime, AnimationInfo* animationInfo, s32 index); + +typedef struct { + /* 0x00 */ AnimationHeader* animation; + /* 0x04 */ f32 frameCount; + /* 0x08 */ u8 mode; + /* 0x0C */ f32 morphFrames; +} AnimationFrameCountInfo; // size = 0x10 + +typedef struct { + /* 0x00 */ AnimationHeader* animation; + /* 0x04 */ f32 playSpeed; + /* 0x08 */ u8 mode; + /* 0x0C */ f32 morphFrames; +} AnimationSpeedInfo; // size = 0x10 + +typedef struct { + /* 0x00 */ AnimationHeader* animation; + /* 0x04 */ u8 mode; + /* 0x08 */ f32 morphFrames; +} AnimationMinimalInfo; // size = 0xC + +/* + * Animation helpers + */ + +s32 Animation_OnFrame(SkelAnime* skelAnime, f32 frame); +s16 Animation_GetLength(void* animation); +s16 Animation_GetLastFrame(void* animation); + +/* + * Animation requests + */ + +typedef enum { + /* 0 */ ANIMENTRY_LOADFRAME, + /* 1 */ ANIMENTRY_COPYALL, + /* 2 */ ANIMENTRY_INTERP, + /* 3 */ ANIMENTRY_COPYTRUE, + /* 4 */ ANIMENTRY_COPYFALSE, + /* 5 */ ANIMENTRY_MOVEACTOR } AnimationType; typedef struct { @@ -182,40 +304,67 @@ typedef struct { /* 0x04 */ AnimationEntryData data; } AnimationEntry; // size = 0x40 +#define ANIMATION_ENTRY_MAX 50 + typedef struct AnimationContext { s16 animationCount; AnimationEntry entries[ANIMATION_ENTRY_MAX]; } AnimationContext; // size = 0xC84 -typedef void (*AnimationEntryCallback)(struct PlayState* play, AnimationEntryData* data); +void AnimationContext_SetLoadFrame(struct PlayState* play, LinkAnimationHeader* animation, s32 frame, s32 limbCount, + Vec3s* frameTable); +void AnimationContext_SetCopyAll(struct PlayState* play, s32 vecCount, Vec3s* dst, Vec3s* src); +void AnimationContext_SetCopyTrue(struct PlayState* play, s32 vecCount, Vec3s* dst, Vec3s* src, u8* copyFlag); +void AnimationContext_SetCopyFalse(struct PlayState* play, s32 vecCount, Vec3s* dst, Vec3s* src, u8* copyFlag); +void AnimationContext_SetInterp(struct PlayState* play, s32 vecCount, Vec3s* base, Vec3s* mod, f32 weight); +void AnimationContext_SetMoveActor(struct PlayState* play, struct Actor* actor, SkelAnime* skelAnime, f32 arg3); -typedef s32 (*AnimUpdateFunc)(); +void AnimationContext_SetNextQueue(struct PlayState* play); +void AnimationContext_DisableQueue(struct PlayState* play); -typedef struct SkelAnime { - /* 0x00 */ u8 limbCount; // Number of limbs in the skeleton - /* 0x01 */ u8 mode; // See `AnimationMode` - /* 0x02 */ u8 dListCount; // Number of display lists in a flexible skeleton - /* 0x03 */ s8 taper; // Tapering to use when morphing between animations. Only used by Door_Warp1. - /* 0x04 */ void** skeleton; // An array of pointers to limbs. Can be StandardLimb, LodLimb, or SkinLimb. - /* 0x08 */ void* animation; // Can be an AnimationHeader or LinkAnimationHeader. - /* 0x0C */ f32 startFrame; // In mode ANIMMODE_LOOP_PARTIAL*, start of partial loop. - /* 0x10 */ f32 endFrame; // In mode ANIMMODE_ONCE*, Update returns true when curFrame is equal to this. In mode ANIMMODE_LOOP_PARTIAL*, end of partial loop. - /* 0x14 */ f32 animLength; // Total number of frames in the current animation. - /* 0x18 */ f32 curFrame; // Current frame in the animation - /* 0x1C */ f32 playSpeed; // Multiplied by R_UPDATE_RATE / 3 to get the animation's frame rate. - /* 0x20 */ Vec3s* jointTable; // Current translation of model and rotations of all limbs - /* 0x24 */ Vec3s* morphTable; // Table of values used to morph between animations - /* 0x28 */ f32 morphWeight; // Weight of the current animation morph as a fraction in [0,1] - /* 0x2C */ f32 morphRate; // Reciprocal of the number of frames in the morph - /* 0x30 */ union { - s32 (*normal)(struct SkelAnime*); // Can be Loop, Partial loop, Play once, Morph, or Tapered morph - s32 (*link)(struct PlayState*, struct SkelAnime*); // Can be Loop, Play once, or Morph - } update; - /* 0x34 */ s8 initFlags; // Flags used when initializing Link's skeleton - /* 0x35 */ u8 moveFlags; // Flags used for animations that move the actor in worldspace. - /* 0x36 */ s16 prevRot; // Previous rotation in worldspace. - /* 0x38 */ Vec3s prevTransl; // Previous modelspace translation. - /* 0x3E */ Vec3s baseTransl; // Base modelspace translation. -} SkelAnime; // size = 0x44 +void AnimationContext_Reset(AnimationContext* animationCtx); +void AnimationContext_Update(struct PlayState* play, AnimationContext* animationCtx); + +/* + * Link animations + */ + +// Update + +s32 LinkAnimation_Update(struct PlayState* play, SkelAnime* skelAnime); + +void LinkAnimation_SetUpdateFunction(SkelAnime* skelAnime); +void LinkAnimation_AnimateFrame(struct PlayState* play, SkelAnime* skelAnime); + +// Play animations + +void LinkAnimation_Change(struct PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, f32 playSpeed, + f32 startFrame, f32 endFrame, u8 mode, f32 morphFrames); + +void LinkAnimation_PlayOnce(struct PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation); +void LinkAnimation_PlayOnceSetSpeed(struct PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, + f32 playSpeed); + +void LinkAnimation_PlayLoop(struct PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation); +void LinkAnimation_PlayLoopSetSpeed(struct PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, + f32 playSpeed); + +void LinkAnimation_EndLoop(SkelAnime* skelAnime); + +// Misc. operations + +void LinkAnimation_CopyJointToMorph(struct PlayState* play, SkelAnime* skelAnime); +void LinkAnimation_CopyMorphToJoint(struct PlayState* play, SkelAnime* skelAnime); +void LinkAnimation_LoadToMorph(struct PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, f32 frame); +void LinkAnimation_LoadToJoint(struct PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, f32 frame); +void LinkAnimation_InterpJointMorph(struct PlayState* play, SkelAnime* skelAnime, f32 weight); +void LinkAnimation_BlendToJoint(struct PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation1, + f32 frame1, LinkAnimationHeader* animation2, f32 frame2, f32 blendWeight, + Vec3s* blendTable); +void LinkAnimation_BlendToMorph(struct PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation1, + f32 frame1, LinkAnimationHeader* animation2, f32 frame2, f32 blendWeight, + Vec3s* blendTable); + +s32 LinkAnimation_OnFrame(SkelAnime* skelAnime, f32 frame); #endif diff --git a/include/z64animation_legacy.h b/include/z64animation_legacy.h new file mode 100644 index 0000000000..f5f68bfc8c --- /dev/null +++ b/include/z64animation_legacy.h @@ -0,0 +1,40 @@ +#ifndef Z64_ANIMATION_LEGACY_H +#define Z64_ANIMATION_LEGACY_H + +#include "ultra64.h" +#include "z64math.h" + +typedef struct LegacyLimb { + /* 0x000 */ Gfx* dList; + /* 0x004 */ Vec3f trans; + /* 0x010 */ Vec3s rot; + /* 0x018 */ struct LegacyLimb* sibling; + /* 0x01C */ struct LegacyLimb* child; +} LegacyLimb; // size = 0x20 + +typedef struct { + /* 0x00 */ s16 xMax; + /* 0x02 */ s16 x; + /* 0x04 */ s16 yMax; + /* 0x06 */ s16 y; + /* 0x08 */ s16 zMax; + /* 0x0A */ s16 z; +} LegacyJointKey; // size = 0x0C + +// ZAPD compatibility typedefs +// TODO: Remove when ZAPD adds support for them +typedef LegacyJointKey JointKey; + +typedef struct { + /* 0x00 */ s16 frameCount; + /* 0x02 */ s16 limbCount; + /* 0x04 */ s16* frameData; + /* 0x08 */ LegacyJointKey* jointKey; +} LegacyAnimationHeader; // size = 0xC + +s32 SkelAnime_GetFrameDataLegacy(LegacyAnimationHeader* animation, s32 frame, Vec3s* frameTable); +s16 Animation_GetLimbCountLegacy(LegacyAnimationHeader* animation); +s16 Animation_GetLengthLegacy(LegacyAnimationHeader* animation); +s16 Animation_GetLastFrameLegacy(LegacyAnimationHeader* animation); + +#endif diff --git a/src/code/z_skelanime.c b/src/code/z_skelanime.c index 43e7e02d80..6be89bafeb 100644 --- a/src/code/z_skelanime.c +++ b/src/code/z_skelanime.c @@ -716,7 +716,7 @@ Gfx* SkelAnime_DrawFlex(PlayState* play, void** skeleton, Vec3s* jointTable, s32 s32 SkelAnime_GetFrameDataLegacy(LegacyAnimationHeader* animation, s32 frame, Vec3s* frameTable) { LegacyAnimationHeader* animHeader = SEGMENTED_TO_VIRTUAL(animation); s32 limbCount = animHeader->limbCount; - JointKey* key = SEGMENTED_TO_VIRTUAL(animHeader->jointKey); + LegacyJointKey* key = SEGMENTED_TO_VIRTUAL(animHeader->jointKey); s16* frameData = SEGMENTED_TO_VIRTUAL(animHeader->frameData); s16* staticData = &frameData[0]; s16* dynamicData = &frameData[frame]; @@ -829,6 +829,10 @@ AnimationEntry* AnimationContext_AddEntry(AnimationContext* animationCtx, Animat return entry; } +#define LINK_ANIMATION_OFFSET(addr, offset) \ + (((uintptr_t)_link_animetionSegmentRomStart) + ((uintptr_t)(addr)) - ((uintptr_t)_link_animetionSegmentStart) + \ + (offset)) + /** * Requests loading frame data from the Link animation into frameTable */ @@ -1011,6 +1015,8 @@ void AnimationContext_MoveActor(PlayState* play, AnimationEntryData* data) { actor->world.pos.z += diff.z * actor->scale.z; } +typedef void (*AnimationEntryCallback)(struct PlayState* play, AnimationEntryData* data); + /** * Performs all requests in the animation queue, then resets the queue flags. */ @@ -1784,7 +1790,7 @@ void SkelAnime_UpdateTranslation(SkelAnime* skelAnime, Vec3f* diff, s16 angle) { f32 sin; f32 cos; - if (skelAnime->moveFlags & ANIM_FLAG_NOMOVE) { + if (skelAnime->moveFlags & ANIM_FLAG_NO_MOVE) { diff->x = diff->z = 0.0f; } else { x = skelAnime->jointTable[0].x; @@ -1806,8 +1812,8 @@ void SkelAnime_UpdateTranslation(SkelAnime* skelAnime, Vec3f* diff, s16 angle) { skelAnime->jointTable[0].x = skelAnime->baseTransl.x; skelAnime->prevTransl.z = skelAnime->jointTable[0].z; skelAnime->jointTable[0].z = skelAnime->baseTransl.z; - if (skelAnime->moveFlags & ANIM_FLAG_UPDATEY) { - if (skelAnime->moveFlags & ANIM_FLAG_NOMOVE) { + if (skelAnime->moveFlags & ANIM_FLAG_UPDATE_Y) { + if (skelAnime->moveFlags & ANIM_FLAG_NO_MOVE) { diff->y = 0.0f; } else { diff->y = skelAnime->jointTable[0].y - skelAnime->prevTransl.y; @@ -1818,7 +1824,7 @@ void SkelAnime_UpdateTranslation(SkelAnime* skelAnime, Vec3f* diff, s16 angle) { diff->y = 0.0f; skelAnime->prevTransl.y = skelAnime->jointTable[0].y; } - skelAnime->moveFlags &= ~ANIM_FLAG_NOMOVE; + skelAnime->moveFlags &= ~ANIM_FLAG_NO_MOVE; } /**