diff options
| author | petrie911 <69443847+petrie911@users.noreply.github.com> | 2020-12-01 21:19:56 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-01 22:19:56 -0500 |
| commit | 4876610c75b228cf1abe4b4d0eafe9a3cc1b21fd (patch) | |
| tree | 2e20db86ce23690a30fee117aeed3f8a26d522be /src/code | |
| parent | 629d1c89682bcbd9280afdaf50afa61ea0c92fed (diff) | |
SkelAnime "Skeleton" Documentation Pass (#497)
* Darkmeiro decompilation
Bg_Gnd_Darkmeiro decompiled, matched, and documented.
* give this a shot
* fix conflict
* one more try
* could be useful
* whoops
* ZAP2 stuff
* ZAP why
* ZAP again
* spooky scary skeletons
* there's a skeleton inside of you
* formatting
* types
* a matched function even
* undo change
* lol anime
* ok how did I forget the .s
* array fix
* would you like to ride the bone train?
* stuff
* more renames
* renames and cleanup
* names suck
* idea
* using void** for now
* stuff
* look more type fixes
Co-authored-by: fig <fig02srl@gmail.com>
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/z_actor.c | 16 | ||||
| -rw-r--r-- | src/code/z_bgcheck.c | 2 | ||||
| -rw-r--r-- | src/code/z_fcurve_data_skelanime.c | 14 | ||||
| -rw-r--r-- | src/code/z_player_lib.c | 54 | ||||
| -rw-r--r-- | src/code/z_skelanime.c | 1019 |
5 files changed, 530 insertions, 575 deletions
diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 42ad328bd..17aa8a714 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -3794,8 +3794,8 @@ Gfx* func_80034B54(GraphicsContext* gfxCtx) { return displayList; } -void func_80034BA0(GlobalContext* globalCtx, SkelAnime* skelAnime, OverrideLimbDraw2 overrideLimbDraw, - PostLimbDraw2 postLimbDraw, Actor* actor, s16 alpha) { +void func_80034BA0(GlobalContext* globalCtx, SkelAnime* skelAnime, OverrideLimbDraw overrideLimbDraw, + PostLimbDraw postLimbDraw, Actor* actor, s16 alpha) { OPEN_DISPS(globalCtx->state.gfxCtx, "../z_actor.c", 8831); func_80093D18(globalCtx->state.gfxCtx); @@ -3805,14 +3805,14 @@ void func_80034BA0(GlobalContext* globalCtx, SkelAnime* skelAnime, OverrideLimbD gDPPipeSync(POLY_OPA_DISP++); gSPSegment(POLY_OPA_DISP++, 0x0C, func_80034B28(globalCtx->state.gfxCtx)); - POLY_OPA_DISP = SkelAnime_DrawSV2(globalCtx, skelAnime->skeleton, skelAnime->limbDrawTbl, skelAnime->dListCount, - overrideLimbDraw, postLimbDraw, actor, POLY_OPA_DISP); + POLY_OPA_DISP = SkelAnime_DrawFlex(globalCtx, skelAnime->skeleton, skelAnime->limbDrawTbl, skelAnime->dListCount, + overrideLimbDraw, postLimbDraw, actor, POLY_OPA_DISP); CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_actor.c", 8860); } -void func_80034CC4(GlobalContext* globalCtx, SkelAnime* skelAnime, OverrideLimbDraw2 overrideLimbDraw, - PostLimbDraw2 postLimbDraw, Actor* actor, s16 alpha) { +void func_80034CC4(GlobalContext* globalCtx, SkelAnime* skelAnime, OverrideLimbDraw overrideLimbDraw, + PostLimbDraw postLimbDraw, Actor* actor, s16 alpha) { OPEN_DISPS(globalCtx->state.gfxCtx, "../z_actor.c", 8876); func_80093D84(globalCtx->state.gfxCtx); @@ -3821,8 +3821,8 @@ void func_80034CC4(GlobalContext* globalCtx, SkelAnime* skelAnime, OverrideLimbD gDPSetEnvColor(POLY_XLU_DISP++, 0, 0, 0, alpha); gSPSegment(POLY_XLU_DISP++, 0x0C, func_80034B54(globalCtx->state.gfxCtx)); - POLY_XLU_DISP = SkelAnime_DrawSV2(globalCtx, skelAnime->skeleton, skelAnime->limbDrawTbl, skelAnime->dListCount, - overrideLimbDraw, postLimbDraw, actor, POLY_XLU_DISP); + POLY_XLU_DISP = SkelAnime_DrawFlex(globalCtx, skelAnime->skeleton, skelAnime->limbDrawTbl, skelAnime->dListCount, + overrideLimbDraw, postLimbDraw, actor, POLY_XLU_DISP); CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_actor.c", 8904); } diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index 75d078ab3..8dc88a5ac 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -417,7 +417,7 @@ u32 func_80041F10(u32 a0, u32 a1, u32 a2) { #pragma GLOBAL_ASM("asm/non_matchings/code/z_bgcheck/func_800420E4.s") -u32 func_80042108(u32 a0, u32 a1, u32 a2) { +s32 func_80042108(CollisionContext* a0, CollisionPoly* a1, u32 a2) { u32 result; s32 var1; diff --git a/src/code/z_fcurve_data_skelanime.c b/src/code/z_fcurve_data_skelanime.c index 3cb3905f2..92073b01c 100644 --- a/src/code/z_fcurve_data_skelanime.c +++ b/src/code/z_fcurve_data_skelanime.c @@ -99,7 +99,7 @@ s32 SkelCurve_Update(GlobalContext* globalCtx, SkelAnimeCurve* skelCurve) { } void SkelCurve_DrawLimb(GlobalContext* globalCtx, s32 limbIndex, SkelAnimeCurve* skelCurve, - OverrideCurveLimbDraw overrideLimbDraw, PostCurveLimbDraw postLimbDraw, s32 lod, Actor* actor) { + OverrideCurveLimbDraw overrideLimbDraw, PostCurveLimbDraw postLimbDraw, s32 lod, void* data) { SkelCurveLimb* limb = SEGMENTED_TO_VIRTUAL(skelCurve->limbList[limbIndex]); OPEN_DISPS(globalCtx->state.gfxCtx, "../z_fcurve_data_skelanime.c", 279); @@ -107,7 +107,7 @@ void SkelCurve_DrawLimb(GlobalContext* globalCtx, s32 limbIndex, SkelAnimeCurve* Matrix_Push(); if (overrideLimbDraw == NULL || - (overrideLimbDraw != NULL && overrideLimbDraw(globalCtx, skelCurve, limbIndex, actor))) { + (overrideLimbDraw != NULL && overrideLimbDraw(globalCtx, skelCurve, limbIndex, data))) { Vec3f scale; Vec3s rot; Vec3f pos; @@ -161,25 +161,25 @@ void SkelCurve_DrawLimb(GlobalContext* globalCtx, s32 limbIndex, SkelAnimeCurve* } if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, skelCurve, limbIndex, actor); + postLimbDraw(globalCtx, skelCurve, limbIndex, data); } if (limb->firstChildIdx != LIMB_DONE) { - SkelCurve_DrawLimb(globalCtx, limb->firstChildIdx, skelCurve, overrideLimbDraw, postLimbDraw, lod, actor); + SkelCurve_DrawLimb(globalCtx, limb->firstChildIdx, skelCurve, overrideLimbDraw, postLimbDraw, lod, data); } Matrix_Pull(); if (limb->nextLimbIdx != LIMB_DONE) { - SkelCurve_DrawLimb(globalCtx, limb->nextLimbIdx, skelCurve, overrideLimbDraw, postLimbDraw, lod, actor); + SkelCurve_DrawLimb(globalCtx, limb->nextLimbIdx, skelCurve, overrideLimbDraw, postLimbDraw, lod, data); } CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_fcurve_data_skelanime.c", 371); } void SkelCurve_Draw(Actor* actor, GlobalContext* globalCtx, SkelAnimeCurve* skelCurve, - OverrideCurveLimbDraw overrideLimbDraw, PostCurveLimbDraw postLimbDraw, s32 lod, Actor* actor2) { + OverrideCurveLimbDraw overrideLimbDraw, PostCurveLimbDraw postLimbDraw, s32 lod, void* data) { if (skelCurve->transforms != NULL) { - SkelCurve_DrawLimb(globalCtx, 0, skelCurve, overrideLimbDraw, postLimbDraw, lod, actor2); + SkelCurve_DrawLimb(globalCtx, 0, skelCurve, overrideLimbDraw, postLimbDraw, lod, data); } } diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index 901815963..f8ee4e7a0 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -10,7 +10,7 @@ typedef struct { /* 0x04 */ Vec3f pos; } BowStringData; // size = 0x10 -SkeletonHeader* gPlayerSkelHeaders[] = { 0x060377F4, 0x0602CF6C }; +FlexSkeletonHeader* gPlayerSkelHeaders[] = { 0x060377F4, 0x0602CF6C }; s16 sBootData[PLAYER_BOOTS_MAX][17] = { { 200, 1000, 300, 700, 550, 270, 600, 350, 800, 600, -100, 600, 590, 750, 125, 200, 130 }, @@ -625,9 +625,9 @@ Gfx* sBootDListGroups[][2] = { { 0x06025BA8, 0x06025DB0 }, }; -void func_8008F470(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDrawTable, s32 dListCount, s32 lod, - s32 tunic, s32 boots, s32 face, OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, - void* arg) { +void func_8008F470(GlobalContext* globalCtx, void** skeleton, Vec3s* limbDrawTable, s32 dListCount, s32 lod, s32 tunic, + s32 boots, s32 face, OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, + void* data) { Color_RGB8* color; s32 eyeIndex = (limbDrawTable[22].x & 0xF) - 1; s32 mouthIndex = (limbDrawTable[22].x >> 4) - 1; @@ -651,7 +651,7 @@ void func_8008F470(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDraw sDListsLodOffset = lod * 2; - SkelAnime_LodDrawSV(globalCtx, skeleton, limbDrawTable, dListCount, overrideLimbDraw, postLimbDraw, arg, lod); + SkelAnime_DrawFlexLod(globalCtx, skeleton, limbDrawTable, dListCount, overrideLimbDraw, postLimbDraw, data, lod); if ((overrideLimbDraw != func_800902F0) && (overrideLimbDraw != func_80090440) && (gSaveContext.gameMode != 3)) { if (LINK_IS_ADULT) { @@ -792,8 +792,8 @@ void func_8008F87C(GlobalContext* globalCtx, Player* this, SkelAnime* skelAnime, } } -s32 func_8008FCC8(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, Actor* actor) { - Player* this = (Player*)actor; +s32 func_8008FCC8(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* thisx) { + Player* this = (Player*)thisx; if (limbIndex == PLAYER_LIMB_ROOT) { D_80160014 = this->leftHandType; @@ -858,10 +858,10 @@ s32 func_8008FCC8(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* p return 0; } -s32 func_80090014(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, Actor* actor) { - Player* this = (Player*)actor; +s32 func_80090014(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* thisx) { + Player* this = (Player*)thisx; - if (func_8008FCC8(globalCtx, limbIndex, dList, pos, rot, actor) == 0) { + if (!func_8008FCC8(globalCtx, limbIndex, dList, pos, rot, thisx)) { if (limbIndex == PLAYER_LIMB_L_HAND) { Gfx** dLists = this->leftHandDLists; @@ -910,10 +910,10 @@ s32 func_80090014(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* p return 0; } -s32 func_800902F0(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, Actor* actor) { - Player* this = (Player*)actor; +s32 func_800902F0(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* thisx) { + Player* this = (Player*)thisx; - if (func_8008FCC8(globalCtx, limbIndex, dList, pos, rot, actor) == 0) { + if (!func_8008FCC8(globalCtx, limbIndex, dList, pos, rot, thisx)) { if (this->unk_6AD != 2) { *dList = NULL; } else if (limbIndex == PLAYER_LIMB_L_FOREARM) { @@ -934,8 +934,8 @@ s32 func_800902F0(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* p return 0; } -s32 func_80090440(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, Actor* actor) { - if (func_8008FCC8(globalCtx, limbIndex, dList, pos, rot, actor) == 0) { +s32 func_80090440(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* thisx) { + if (!func_8008FCC8(globalCtx, limbIndex, dList, pos, rot, thisx)) { *dList = NULL; } @@ -1069,7 +1069,7 @@ void func_80090A28(Player* this, Vec3f* vecs) { void func_80090AFC(GlobalContext* globalCtx, Player* this, f32 arg2) { static Vec3f D_801260C8 = { -500.0f, -100.0f, 0.0f }; - f32 sp9C; + CollisionPoly* sp9C; f32 sp98; Vec3f sp8C; Vec3f sp80; @@ -1085,7 +1085,7 @@ void func_80090AFC(GlobalContext* globalCtx, Player* this, f32 arg2) { if (1) {} - if (func_8003E188(&globalCtx->colCtx, &sp8C, &sp80, &sp74, &sp9C, 1, 1, 1, 1, &sp98) != 0) { + if (func_8003E188(&globalCtx->colCtx, &sp8C, &sp80, &sp74, &sp9C, 1, 1, 1, 1, &sp98)) { OPEN_DISPS(globalCtx->state.gfxCtx, "../z_player_lib.c", 2572); OVERLAY_DISP = Gfx_CallSetupDL(OVERLAY_DISP, 0x07); @@ -1152,8 +1152,8 @@ Vec3f D_801261E0[] = { { 200.0f, 200.0f, 0.0f }, }; -void func_80090D20(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3s* rot, Actor* actor) { - Player* this = (Player*)actor; +void func_80090D20(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3s* rot, void* thisx) { + Player* this = (Player*)thisx; if (*dList != NULL) { Matrix_MultVec3f(&D_8012602C, D_80160000); @@ -1367,7 +1367,7 @@ u32 func_80091738(GlobalContext* globalCtx, u8* segment, SkelAnime* skelAnime) { gSegments[4] = VIRTUAL_TO_PHYSICAL(segment + 0x3800); gSegments[6] = VIRTUAL_TO_PHYSICAL(segment + 0x8800); - SkelAnime_InitLinkAnimetion(globalCtx, skelAnime, gPlayerSkelHeaders[(void)0, gSaveContext.linkAge], &D_04003238, 9, + SkelAnime_InitLinkAnimation(globalCtx, skelAnime, gPlayerSkelHeaders[(void)0, gSaveContext.linkAge], &D_04003238, 9, ptr, ptr, PLAYER_LIMB_MAX); return size + 0x8890; @@ -1415,9 +1415,9 @@ s32 func_80091880(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3s* p return 0; } -void func_80091A24(GlobalContext* globalCtx, void* seg04, void* seg06, struct_80091A24_arg3* arg3, Vec3f* pos, - Vec3s* rot, f32 scale, s32 sword, s32 tunic, s32 shield, s32 boots, s32 width, s32 height, - Vec3f* eye, Vec3f* at, f32 fovy, void* img1, void* img2) { +void func_80091A24(GlobalContext* globalCtx, void* seg04, void* seg06, SkelAnime* arg3, Vec3f* pos, Vec3s* rot, + f32 scale, s32 sword, s32 tunic, s32 shield, s32 boots, s32 width, s32 height, Vec3f* eye, Vec3f* at, + f32 fovy, void* img1, void* img2) { static Vp viewport = { 128, 224, 511, 0, 128, 224, 511, 0 }; static Lights1 lights1 = gdSPDefLights1(80, 80, 80, 255, 255, 255, 84, 84, 172); static Vec3f lightDir = { 89.8f, 0.0f, 89.8f }; @@ -1509,7 +1509,7 @@ void func_80091A24(GlobalContext* globalCtx, void* seg04, void* seg06, struct_80 gSPSegment(POLY_OPA_DISP++, 0x0C, gCullBackDList); - func_8008F470(globalCtx, arg3->skeleton, arg3->limbDrawTable, arg3->dListCount, 0, tunic, boots, 0, func_80091880, + func_8008F470(globalCtx, arg3->skeleton, arg3->limbDrawTbl, arg3->dListCount, 0, tunic, boots, 0, func_80091880, NULL, &sp12C); gSPEndDisplayList(POLY_OPA_DISP++); @@ -1521,8 +1521,8 @@ void func_80091A24(GlobalContext* globalCtx, void* seg04, void* seg06, struct_80 CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_player_lib.c", 3288); } -void func_8009214C(GlobalContext* globalCtx, u8* segment, struct_80091A24_arg3* arg2, Vec3f* pos, Vec3s* rot, f32 scale, - s32 sword, s32 tunic, s32 shield, s32 boots) { +void func_8009214C(GlobalContext* globalCtx, u8* segment, SkelAnime* arg2, Vec3f* pos, Vec3s* rot, f32 scale, s32 sword, + s32 tunic, s32 shield, s32 boots) { static Vec3f eye = { 0.0f, 0.0f, -400.0f }; static Vec3f at = { 0.0f, 0.0f, 0.0f }; Vec3s* destTable; @@ -1549,7 +1549,7 @@ void func_8009214C(GlobalContext* globalCtx, u8* segment, struct_80091A24_arg3* } srcTable = SEGMENTED_TO_VIRTUAL(srcTable); - destTable = arg2->limbDrawTable; + destTable = arg2->limbDrawTbl; for (i = 0; i < arg2->limbCount; i++) { *destTable++ = *srcTable++; } diff --git a/src/code/z_skelanime.c b/src/code/z_skelanime.c index 19aac4ae8..cf63e6798 100644 --- a/src/code/z_skelanime.c +++ b/src/code/z_skelanime.c @@ -1,35 +1,24 @@ #include "global.h" #include "vt.h" -s32 func_800A3D70(GlobalContext*, SkelAnime*); -s32 func_800A3E0C(GlobalContext*, SkelAnime*); +s32 func_800A3D70(GlobalContext* globalCtx, SkelAnime* skelAnime); +s32 func_800A3E0C(GlobalContext* globalCtx, SkelAnime* skelAnime); s32 func_800A4D9C(SkelAnime* skelAnime); s32 func_800A4EE0(SkelAnime* skelAnime); s32 func_800A4E38(SkelAnime* skelAnime); + void SkelAnime_CopyVec3s(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src); -void SkelAnime_LinkAnimetionLoaded(GlobalContext* globalCtx, AnimationEntryType0* entry); -void SkelAnime_AnimationType1Loaded(GlobalContext* globalCtx, AnimationEntryType1* entry); -void SkelAnime_AnimationType2Loaded(GlobalContext* globalCtx, AnimationEntryType2* entry); -void SkelAnime_AnimationType3Loaded(GlobalContext* globalCtx, AnimationEntryType3* entry); -void SkelAnime_AnimationType4Loaded(GlobalContext* globalCtx, AnimationEntryType4* entry); -void SkelAnime_AnimationType5Loaded(GlobalContext* globalCtx, AnimationEntryType5* entry); - -// .data -u32 D_8012A480 = 0; -static AnimationEntryCallback sAnimationLoadDone[] = { - &SkelAnime_LinkAnimetionLoaded, &SkelAnime_AnimationType1Loaded, &SkelAnime_AnimationType2Loaded, - &SkelAnime_AnimationType3Loaded, &SkelAnime_AnimationType4Loaded, &SkelAnime_AnimationType5Loaded, -}; - -// .bss -u32 D_801600B0; + +static u32 D_8012A480 = 0; +static u32 D_801600B0; /* - * Draws the limb at `limbIndex` with a level of detail display lists index by `dListIndex` + * Draw a limb of type `LodLimb` + * Near or far display list is specified via `lod` */ -void SkelAnime_LodDrawLimb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skeleton, Vec3s* limbDrawTable, - OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, Actor* actor, s32 dListIndex) { - SkelLimbEntry* limbEntry; +void SkelAnime_DrawLimbLod(GlobalContext* globalCtx, s32 limbIndex, void** skeleton, Vec3s* limbDrawTable, + OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg, s32 lod) { + LodLimb* limb; Gfx* dList; Vec3f pos; Vec3s rot; @@ -37,20 +26,20 @@ void SkelAnime_LodDrawLimb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* sk OPEN_DISPS(globalCtx->state.gfxCtx, "../z_skelanime.c", 773); Matrix_Push(); - limbEntry = SEGMENTED_TO_VIRTUAL(skeleton->limbs[limbIndex]); + limb = (LodLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; - pos.x = limbEntry->translation.x; - pos.y = limbEntry->translation.y; - pos.z = limbEntry->translation.z; + pos.x = limb->jointPos.x; + pos.y = limb->jointPos.y; + pos.z = limb->jointPos.z; + + dList = limb->dLists[lod]; - dList = limbEntry->displayLists[dListIndex]; - if ((overrideLimbDraw == NULL) || (overrideLimbDraw(globalCtx, limbIndex, &dList, &pos, &rot, actor) == 0)) { + if ((overrideLimbDraw == NULL) || !overrideLimbDraw(globalCtx, limbIndex, &dList, &pos, &rot, arg)) { Matrix_JointPosition(&pos, &rot); if (dList != NULL) { gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_skelanime.c", 805), G_MTX_LOAD); - gSPDisplayList(POLY_OPA_DISP++, dList); } } @@ -58,31 +47,32 @@ void SkelAnime_LodDrawLimb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* sk if (1) {} if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, limbIndex, &dList, &rot, actor); + postLimbDraw(globalCtx, limbIndex, &dList, &rot, arg); } - if (limbEntry->firstChildIndex != LIMB_DONE) { - SkelAnime_LodDrawLimb(globalCtx, limbEntry->firstChildIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, dListIndex); + if (limb->child != LIMB_DONE) { + SkelAnime_DrawLimbLod(globalCtx, limb->child, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, arg, + lod); } Matrix_Pull(); - if (limbEntry->nextLimbIndex != LIMB_DONE) { - SkelAnime_LodDrawLimb(globalCtx, limbEntry->nextLimbIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, dListIndex); + if (limb->sibling != LIMB_DONE) { + SkelAnime_DrawLimbLod(globalCtx, limb->sibling, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, arg, + lod); } CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_skelanime.c", 821); } /* - * Draws the Skeleton described by `skeleton` with a level of detail display list indexed by `dListIndex` + * Draw all limbs of type `LodLimb` in a given skeleton + * Near or far display list is specified via `lod` */ -void SkelAnime_LodDraw(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDrawTable, - OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, Actor* actor, s32 dListIndex) { - SkelLimbEntry* limbEntry; - char pad[4]; +void SkelAnime_DrawLod(GlobalContext* globalCtx, void** skeleton, Vec3s* limbDrawTable, + OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg, s32 lod) { + LodLimb* rootLimb; + s32 pad; Gfx* dList; Vec3f pos; Vec3s rot; @@ -98,29 +88,28 @@ void SkelAnime_LodDraw(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limb Matrix_Push(); - limbEntry = SEGMENTED_TO_VIRTUAL(skeleton->limbs[0]); + rootLimb = (LodLimb*)SEGMENTED_TO_VIRTUAL(skeleton[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; pos.z = limbDrawTable[0].z; rot = limbDrawTable[1]; - dList = limbEntry->displayLists[dListIndex]; + dList = rootLimb->dLists[lod]; - if ((overrideLimbDraw == NULL) || (overrideLimbDraw(globalCtx, 1, &dList, &pos, &rot, actor) == 0)) { + if ((overrideLimbDraw == NULL) || !overrideLimbDraw(globalCtx, 1, &dList, &pos, &rot, arg)) { Matrix_JointPosition(&pos, &rot); if (dList != NULL) { gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_skelanime.c", 881), G_MTX_LOAD); - gSPDisplayList(POLY_OPA_DISP++, dList); } } if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, 1, &dList, &rot, actor); + postLimbDraw(globalCtx, 1, &dList, &rot, arg); } - if (limbEntry->firstChildIndex != 0xFF) { - SkelAnime_LodDrawLimb(globalCtx, limbEntry->firstChildIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, dListIndex); + if (rootLimb->child != LIMB_DONE) { + SkelAnime_DrawLimbLod(globalCtx, rootLimb->child, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, arg, + lod); } Matrix_Pull(); @@ -129,71 +118,74 @@ void SkelAnime_LodDraw(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limb } /* - * Draws the limb at `limbIndex` with a level of detail display lists index by `dListIndex`, Limb matrices come - * from a dynamic allocation from the graph arena. + * Draw a limb of type `LodLimb` contained within a flexible skeleton + * Near or far display list is specified via `lod` */ -void SkelAnime_LodDrawLimbSV(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skeleton, Vec3s* limbDrawTable, - OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, Actor* actor, s32 dListIndex, - Mtx** mtx) { - SkelLimbEntry* limbEntry; - Gfx* dList[2]; +void SkelAnime_DrawFlexLimbLod(GlobalContext* globalCtx, s32 limbIndex, void** skeleton, Vec3s* limbDrawTable, + OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg, s32 lod, + Mtx** mtx) { + LodLimb* limb; + Gfx* newDList; + Gfx* limbDList; Vec3f pos; Vec3s rot; Matrix_Push(); - limbEntry = SEGMENTED_TO_VIRTUAL(skeleton->limbs[limbIndex]); + limb = (LodLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; - pos.x = limbEntry->translation.x; - pos.y = limbEntry->translation.y; - pos.z = limbEntry->translation.z; - // Double assignment here would not work. - dList[0] = limbEntry->displayLists[dListIndex]; - dList[1] = dList[0]; + pos.x = limb->jointPos.x; + pos.y = limb->jointPos.y; + pos.z = limb->jointPos.z; + + newDList = limbDList = limb->dLists[lod]; - if ((overrideLimbDraw == NULL) || (overrideLimbDraw(globalCtx, limbIndex, &dList[1], &pos, &rot, actor) == 0)) { + if ((overrideLimbDraw == NULL) || !overrideLimbDraw(globalCtx, limbIndex, &newDList, &pos, &rot, arg)) { Matrix_JointPosition(&pos, &rot); - if (dList[1] != NULL) { + if (newDList != NULL) { Matrix_ToMtx(*mtx, "../z_skelanime.c", 945); - OPEN_DISPS(globalCtx->state.gfxCtx, "../z_skelanime.c", 946); - gSPMatrix(POLY_OPA_DISP++, *mtx, G_MTX_LOAD); - gSPDisplayList(POLY_OPA_DISP++, dList[1]); - CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_skelanime.c", 949); + { + OPEN_DISPS(globalCtx->state.gfxCtx, "../z_skelanime.c", 946); + gSPMatrix(POLY_OPA_DISP++, *mtx, G_MTX_LOAD); + gSPDisplayList(POLY_OPA_DISP++, newDList); + CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_skelanime.c", 949); + } (*mtx)++; - } else if (dList[0] != NULL) { + } else if (limbDList != NULL) { Matrix_ToMtx(*mtx, "../z_skelanime.c", 954); (*mtx)++; } } if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, limbIndex, &dList[0], &rot, actor); + postLimbDraw(globalCtx, limbIndex, &limbDList, &rot, arg); } - if (limbEntry->firstChildIndex != LIMB_DONE) { - SkelAnime_LodDrawLimbSV(globalCtx, limbEntry->firstChildIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, dListIndex, mtx); + if (limb->child != LIMB_DONE) { + SkelAnime_DrawFlexLimbLod(globalCtx, limb->child, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, arg, + lod, mtx); } Matrix_Pull(); - if (limbEntry->nextLimbIndex != LIMB_DONE) { - SkelAnime_LodDrawLimbSV(globalCtx, limbEntry->nextLimbIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, dListIndex, mtx); + if (limb->sibling != LIMB_DONE) { + SkelAnime_DrawFlexLimbLod(globalCtx, limb->sibling, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, + arg, lod, mtx); } } /* - * Draws the Skeleton described by `skeleton` with a level of detail display list indexed by `dListIndex` - * Matricies for the limbs are dynamically allocted from the graph arena. The dynamic allocation occurs - * because the Skeleton is too large to be supported by the normal matrix stack. + * Draws all limbs of type `LodLimb` in a given flexible skeleton + * Limbs in a flexible skeleton have meshes that can stretch to line up with other limbs. + * An array of matrices is dynamically allocated so each limb can access any transform to ensure its meshes line up. */ -void SkelAnime_LodDrawSV(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDrawTable, s32 dListCount, - OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, Actor* actor, s32 dListIndex) { - SkelLimbEntry* limbEntry; - char pad[4]; - Gfx* dList[2]; +void SkelAnime_DrawFlexLod(GlobalContext* globalCtx, void** skeleton, Vec3s* limbDrawTable, s32 dListCount, + OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg, s32 lod) { + LodLimb* rootLimb; + s32 pad; + Gfx* newDList; + Gfx* limbDList; Vec3f pos; Vec3s rot; Mtx* mtx; @@ -212,35 +204,34 @@ void SkelAnime_LodDrawSV(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* li gSPSegment(POLY_OPA_DISP++, 0xD, mtx); Matrix_Push(); - limbEntry = SEGMENTED_TO_VIRTUAL(skeleton->limbs[0]); + rootLimb = (LodLimb*)SEGMENTED_TO_VIRTUAL(skeleton[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; pos.z = limbDrawTable[0].z; rot = limbDrawTable[1]; - dList[0] = limbEntry->displayLists[dListIndex]; - dList[1] = dList[0]; + newDList = limbDList = rootLimb->dLists[lod]; - if ((overrideLimbDraw == 0) || (overrideLimbDraw(globalCtx, 1, &dList[1], &pos, &rot, actor) == 0)) { + if ((overrideLimbDraw == 0) || !overrideLimbDraw(globalCtx, 1, &newDList, &pos, &rot, arg)) { Matrix_JointPosition(&pos, &rot); - if (dList[1] != NULL) { + if (newDList != NULL) { Matrix_ToMtx(mtx, "../z_skelanime.c", 1033); gSPMatrix(POLY_OPA_DISP++, mtx, G_MTX_LOAD); - gSPDisplayList(POLY_OPA_DISP++, dList[1]); + gSPDisplayList(POLY_OPA_DISP++, newDList); mtx++; - } else if (dList[0] != NULL) { + } else if (limbDList != NULL) { Matrix_ToMtx(mtx, "../z_skelanime.c", 1040); mtx++; } } if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, 1, &dList[0], &rot, actor); + postLimbDraw(globalCtx, 1, &limbDList, &rot, arg); } - if (limbEntry->firstChildIndex != LIMB_DONE) { - SkelAnime_LodDrawLimbSV(globalCtx, limbEntry->firstChildIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, dListIndex, &mtx); + if (rootLimb->child != LIMB_DONE) { + SkelAnime_DrawFlexLimbLod(globalCtx, rootLimb->child, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, + arg, lod, &mtx); } Matrix_Pull(); @@ -249,28 +240,27 @@ void SkelAnime_LodDrawSV(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* li } /* - * Draws the limb of the Skeleton `skeleton` at `limbIndex` + * Draw a limb of type `StandardLimb` to the polyOpa buffer */ -void SkelAnime_DrawLimb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skeleton, Vec3s* limbDrawTable, - OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, Actor* actor) { - SkelLimbEntry* limbEntry; +void SkelAnime_DrawLimbOpa(GlobalContext* globalCtx, s32 limbIndex, void** skeleton, Vec3s* limbDrawTable, + OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg) { + StandardLimb* limb; Gfx* dList; Vec3f pos; Vec3s rot; OPEN_DISPS(globalCtx->state.gfxCtx, "../z_skelanime.c", 1076); - Matrix_Push(); - limbEntry = SEGMENTED_TO_VIRTUAL(skeleton->limbs[limbIndex]); + limb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; - pos.x = limbEntry->translation.x; - pos.y = limbEntry->translation.y; - pos.z = limbEntry->translation.z; - dList = limbEntry->displayLists[0]; + pos.x = limb->jointPos.x; + pos.y = limb->jointPos.y; + pos.z = limb->jointPos.z; + dList = limb->dList; - if ((overrideLimbDraw == NULL) || (overrideLimbDraw(globalCtx, limbIndex, &dList, &pos, &rot, actor) == 0)) { + if ((overrideLimbDraw == NULL) || !overrideLimbDraw(globalCtx, limbIndex, &dList, &pos, &rot, arg)) { Matrix_JointPosition(&pos, &rot); if (dList != NULL) { gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_skelanime.c", 1103), G_MTX_LOAD); @@ -281,28 +271,28 @@ void SkelAnime_DrawLimb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skele if (1) {} if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, limbIndex, &dList, &rot, actor); + postLimbDraw(globalCtx, limbIndex, &dList, &rot, arg); } - if (limbEntry->firstChildIndex != LIMB_DONE) { - SkelAnime_DrawLimb(globalCtx, limbEntry->firstChildIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor); + if (limb->child != LIMB_DONE) { + SkelAnime_DrawLimbOpa(globalCtx, limb->child, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, arg); } Matrix_Pull(); - if (limbEntry->nextLimbIndex != LIMB_DONE) { - SkelAnime_DrawLimb(globalCtx, limbEntry->nextLimbIndex, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, - actor); + if (limb->sibling != LIMB_DONE) { + SkelAnime_DrawLimbOpa(globalCtx, limb->sibling, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, arg); } - CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_skelanime.c", 1121); } -void SkelAnime_Draw(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDrawTable, - OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, Actor* actor) { - SkelLimbEntry* rootLimb; - char pad[4]; +/* + * Draw all limbs of type `StandardLimb` in a given skeleton to the polyOpa buffer + */ +void SkelAnime_DrawOpa(GlobalContext* globalCtx, void** skeleton, Vec3s* limbDrawTable, + OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg) { + StandardLimb* rootLimb; + s32 pad; Gfx* dList; Vec3f pos; Vec3s rot; @@ -317,16 +307,16 @@ void SkelAnime_Draw(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDra OPEN_DISPS(globalCtx->state.gfxCtx, "../z_skelanime.c", 1148); Matrix_Push(); - rootLimb = SEGMENTED_TO_VIRTUAL(skeleton->limbs[0]); + rootLimb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; pos.z = limbDrawTable[0].z; rot = limbDrawTable[1]; - dList = rootLimb->displayLists[0]; + dList = rootLimb->dList; - if ((overrideLimbDraw == NULL) || (overrideLimbDraw(globalCtx, 1, &dList, &pos, &rot, actor) == 0)) { + if ((overrideLimbDraw == NULL) || !overrideLimbDraw(globalCtx, 1, &dList, &pos, &rot, arg)) { Matrix_JointPosition(&pos, &rot); if (dList != NULL) { gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_skelanime.c", 1176), G_MTX_LOAD); @@ -335,12 +325,11 @@ void SkelAnime_Draw(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDra } if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, 1, &dList, &rot, actor); + postLimbDraw(globalCtx, 1, &dList, &rot, arg); } - if (rootLimb->firstChildIndex != LIMB_DONE) { - SkelAnime_DrawLimb(globalCtx, rootLimb->firstChildIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor); + if (rootLimb->child != LIMB_DONE) { + SkelAnime_DrawLimbOpa(globalCtx, rootLimb->child, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, arg); } Matrix_Pull(); @@ -348,11 +337,15 @@ void SkelAnime_Draw(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDra CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_skelanime.c", 1190); } -void SkelAnime_DrawLimbSV(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skeleton, Vec3s* limbDrawTable, - OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, Actor* actor, - Mtx** limbMatricies) { - SkelLimbEntry* limbEntry; - Gfx* dList[2]; +/* + * Draw a limb of type `StandardLimb` contained within a flexible skeleton to the polyOpa buffer + */ +void SkelAnime_DrawFlexLimbOpa(GlobalContext* globalCtx, s32 limbIndex, void** skeleton, Vec3s* limbDrawTable, + OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg, + Mtx** limbMatricies) { + StandardLimb* limb; + Gfx* newDList; + Gfx* limbDList; Vec3f pos; Vec3s rot; @@ -360,54 +353,58 @@ void SkelAnime_DrawLimbSV(GlobalContext* globalCtx, s32 limbIndex, Skeleton* ske Matrix_Push(); - limbEntry = SEGMENTED_TO_VIRTUAL(skeleton->limbs[limbIndex]); + limb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; - pos.x = limbEntry->translation.x; - pos.y = limbEntry->translation.y; - pos.z = limbEntry->translation.z; + pos.x = limb->jointPos.x; + pos.y = limb->jointPos.y; + pos.z = limb->jointPos.z; - dList[0] = limbEntry->displayLists[0]; - dList[1] = dList[0]; + newDList = limbDList = limb->dList; - if ((overrideLimbDraw == NULL) || (overrideLimbDraw(globalCtx, limbIndex, &dList[1], &pos, &rot, actor) == 0)) { + if ((overrideLimbDraw == NULL) || !overrideLimbDraw(globalCtx, limbIndex, &newDList, &pos, &rot, arg)) { Matrix_JointPosition(&pos, &rot); - if (dList[1] != NULL) { + if (newDList != NULL) { Matrix_ToMtx(*limbMatricies, "../z_skelanime.c", 1242); gSPMatrix(POLY_OPA_DISP++, *limbMatricies, G_MTX_LOAD); - gSPDisplayList(POLY_OPA_DISP++, dList[1]); + gSPDisplayList(POLY_OPA_DISP++, newDList); (*limbMatricies)++; - } else if (dList[0] != NULL) { + } else if (limbDList != NULL) { Matrix_ToMtx(*limbMatricies, "../z_skelanime.c", 1249); (*limbMatricies)++; } } if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, limbIndex, &dList[0], &rot, actor); + postLimbDraw(globalCtx, limbIndex, &limbDList, &rot, arg); } - if (limbEntry->firstChildIndex != LIMB_DONE) { - SkelAnime_DrawLimbSV(globalCtx, limbEntry->firstChildIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, limbMatricies); + if (limb->child != LIMB_DONE) { + SkelAnime_DrawFlexLimbOpa(globalCtx, limb->child, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, arg, + limbMatricies); } Matrix_Pull(); - if (limbEntry->nextLimbIndex != LIMB_DONE) { - SkelAnime_DrawLimbSV(globalCtx, limbEntry->nextLimbIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, limbMatricies); + if (limb->sibling != LIMB_DONE) { + SkelAnime_DrawFlexLimbOpa(globalCtx, limb->sibling, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, + arg, limbMatricies); } - CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_skelanime.c", 1265); } -void SkelAnime_DrawSV(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDrawTable, s32 dListCount, - OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, Actor* actor) { - SkelLimbEntry* limbEntry; - char pad[4]; - Gfx* dList[2]; +/* + * Draw all limbs of type `StandardLimb` in a given flexible skeleton to the polyOpa buffer + * Limbs in a flexible skeleton have meshes that can stretch to line up with other limbs. + * An array of matrices is dynamically allocated so each limb can access any transform to ensure its meshes line up. + */ +void SkelAnime_DrawFlexOpa(GlobalContext* globalCtx, void** skeleton, Vec3s* limbDrawTable, s32 dListCount, + OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg) { + StandardLimb* rootLimb; + s32 pad; + Gfx* newDList; + Gfx* limbDList; Vec3f pos; Vec3s rot; Mtx* mtx; @@ -427,7 +424,7 @@ void SkelAnime_DrawSV(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbD Matrix_Push(); - limbEntry = SEGMENTED_TO_VIRTUAL(skeleton->limbs[0]); + rootLimb = SEGMENTED_TO_VIRTUAL(skeleton[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; @@ -435,31 +432,28 @@ void SkelAnime_DrawSV(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbD rot = limbDrawTable[1]; - dList[0] = limbEntry->displayLists[0]; - dList[1] = dList[0]; + newDList = limbDList = rootLimb->dList; - if ((overrideLimbDraw == NULL) || (overrideLimbDraw(globalCtx, 1, &dList[1], &pos, &rot, actor) == 0)) { + if ((overrideLimbDraw == NULL) || !overrideLimbDraw(globalCtx, 1, &newDList, &pos, &rot, arg)) { Matrix_JointPosition(&pos, &rot); - if (dList[1] != NULL) { + if (newDList != NULL) { Matrix_ToMtx(mtx, "../z_skelanime.c", 1327); gSPMatrix(POLY_OPA_DISP++, mtx, G_MTX_LOAD); - gSPDisplayList(POLY_OPA_DISP++, dList[1]); + gSPDisplayList(POLY_OPA_DISP++, newDList); + mtx++; + } else if (limbDList != NULL) { + Matrix_ToMtx(mtx, "../z_skelanime.c", 1334); mtx++; - } else { - if (dList[0] != NULL) { - Matrix_ToMtx(mtx, "../z_skelanime.c", 1334); - mtx++; - } } } if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, 1, &dList[0], &rot, actor); + postLimbDraw(globalCtx, 1, &limbDList, &rot, arg); } - if (limbEntry->firstChildIndex != LIMB_DONE) { - SkelAnime_DrawLimbSV(globalCtx, limbEntry->firstChildIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, &mtx); + if (rootLimb->child != LIMB_DONE) { + SkelAnime_DrawFlexLimbOpa(globalCtx, rootLimb->child, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, + arg, &mtx); } Matrix_Pull(); @@ -472,19 +466,12 @@ void SkelAnime_DrawSV(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbD * rotation value list, otherwise it is copied from the initial rotation value list */ void SkelAnime_AnimateFrame(AnimationHeader* animationSeg, s32 currentFrame, s32 limbCount, Vec3s* dst) { - AnimationRotationIndex* index; - AnimationRotationValue* rotationValueTable; - AnimationRotationValue* frameRotationValueTable; - AnimationHeader* animationHeader; - + AnimationHeader* animHeader = SEGMENTED_TO_VIRTUAL(animationSeg); + AnimationRotationIndex* index = SEGMENTED_TO_VIRTUAL(animHeader->rotationIndexSeg); + AnimationRotationValue* rotationValueTable = SEGMENTED_TO_VIRTUAL(animHeader->rotationValueSeg); + AnimationRotationValue* frameRotationValueTable = &rotationValueTable[currentFrame]; + u16 limit = animHeader->limit; s32 i; - u16 limit; - - animationHeader = SEGMENTED_TO_VIRTUAL(animationSeg); - index = SEGMENTED_TO_VIRTUAL(animationHeader->rotationIndexSeg); - rotationValueTable = SEGMENTED_TO_VIRTUAL(animationHeader->rotationValueSeg); - frameRotationValueTable = &rotationValueTable[currentFrame]; - limit = animationHeader->limit; for (i = 0; i < limbCount; i++, dst++, index++) { if ((dst == NULL) || (index == NULL) || (frameRotationValueTable == NULL) || (rotationValueTable == NULL)) { @@ -494,48 +481,48 @@ void SkelAnime_AnimateFrame(AnimationHeader* animationSeg, s32 currentFrame, s32 LOG_ADDRESS("tbl", rotationValueTable, "../z_skelanime.c", 1395); } - dst->x = index->x >= limit ? frameRotationValueTable[index->x] : rotationValueTable[index->x]; - dst->y = index->y >= limit ? frameRotationValueTable[index->y] : rotationValueTable[index->y]; - dst->z = index->z >= limit ? frameRotationValueTable[index->z] : rotationValueTable[index->z]; + dst->x = (index->x >= limit) ? frameRotationValueTable[index->x] : rotationValueTable[index->x]; + dst->y = (index->y >= limit) ? frameRotationValueTable[index->y] : rotationValueTable[index->y]; + dst->z = (index->z >= limit) ? frameRotationValueTable[index->z] : rotationValueTable[index->z]; } } -s16 SkelAnime_GetTotalFrames(GenericAnimationHeader* animationSeg) { +s16 SkelAnime_GetTotalFrames(void* animationSeg) { GenericAnimationHeader* animation = SEGMENTED_TO_VIRTUAL(animationSeg); + return animation->frameCount; } -s16 SkelAnime_GetFrameCount(GenericAnimationHeader* animationSeg) { +s16 SkelAnime_GetFrameCount(void* animationSeg) { GenericAnimationHeader* animation = SEGMENTED_TO_VIRTUAL(animationSeg); // Loads an unsigned half for some reason. return (u16)animation->frameCount - 1; } /* - * Draws the Skeleton `skeleton`'s limb at index `limbIndex`. Appends all generated graphics commands to - * `gfx`. Returns a pointer to the next gfx to be appended to. + * Draw a limb of type `StandardLimb` to the specified display buffer */ -Gfx* SkelAnime_Draw2Limb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skeleton, Vec3s* limbDrawTable, - OverrideLimbDraw2 overrideLimbDraw, PostLimbDraw2 postLimbDraw, Actor* actor, Gfx* gfx) { - SkelLimbEntry* limbEntry; +Gfx* SkelAnime_DrawLimb(GlobalContext* globalCtx, s32 limbIndex, void** skeleton, Vec3s* limbDrawTable, + OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, void* arg, Gfx* gfx) { + StandardLimb* limb; Gfx* dList; Vec3f pos; Vec3s rot; Matrix_Push(); - limbEntry = SEGMENTED_TO_VIRTUAL(skeleton->limbs[limbIndex]); + limb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; - pos.x = limbEntry->translation.x; - pos.y = limbEntry->translation.y; - pos.z = limbEntry->translation.z; + pos.x = limb->jointPos.x; + pos.y = limb->jointPos.y; + pos.z = limb->jointPos.z; - dList = limbEntry->displayLists[0]; + dList = limb->dList; - if ((overrideLimbDraw == NULL) || (overrideLimbDraw(globalCtx, limbIndex, &dList, &pos, &rot, actor, &gfx) == 0)) { + if ((overrideLimbDraw == NULL) || !overrideLimbDraw(globalCtx, limbIndex, &dList, &pos, &rot, arg, &gfx)) { Matrix_JointPosition(&pos, &rot); if (dList != NULL) { gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_skelanime.c", 1489), G_MTX_LOAD); @@ -544,32 +531,31 @@ Gfx* SkelAnime_Draw2Limb(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skel } if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, limbIndex, &dList, &rot, actor, &gfx); + postLimbDraw(globalCtx, limbIndex, &dList, &rot, arg, &gfx); } - if (limbEntry->firstChildIndex != LIMB_DONE) { - gfx = SkelAnime_Draw2Limb(globalCtx, limbEntry->firstChildIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, gfx); + if (limb->child != LIMB_DONE) { + gfx = SkelAnime_DrawLimb(globalCtx, limb->child, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, arg, + gfx); } Matrix_Pull(); - if (limbEntry->nextLimbIndex != LIMB_DONE) { - gfx = SkelAnime_Draw2Limb(globalCtx, limbEntry->nextLimbIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, gfx); + if (limb->sibling != LIMB_DONE) { + gfx = SkelAnime_DrawLimb(globalCtx, limb->sibling, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, arg, + gfx); } return gfx; } /* - * Draws the Skeleton `skeleton` Appends all generated graphics to `gfx`, and returns a pointer to the - * next gfx to be appended to. + * Draw all limbs of type `StandardLimb` in a given skeleton to the specified display buffer */ -Gfx* SkelAnime_Draw2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDrawTable, - OverrideLimbDraw2 overrideLimbDraw, PostLimbDraw2 postLimbDraw, Actor* actor, Gfx* gfx) { - SkelLimbEntry* limbEntry; - char pad[4]; +Gfx* SkelAnime_Draw(GlobalContext* globalCtx, void** skeleton, Vec3s* limbDrawTable, OverrideLimbDraw overrideLimbDraw, + PostLimbDraw postLimbDraw, void* arg, Gfx* gfx) { + StandardLimb* rootLimb; + s32 pad; Gfx* dList; Vec3f pos; Vec3s rot; @@ -583,7 +569,7 @@ Gfx* SkelAnime_Draw2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDr Matrix_Push(); - limbEntry = SEGMENTED_TO_VIRTUAL(skeleton->limbs[0]); + rootLimb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; @@ -591,9 +577,9 @@ Gfx* SkelAnime_Draw2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDr rot = limbDrawTable[1]; - dList = limbEntry->displayLists[0]; + dList = rootLimb->dList; - if ((overrideLimbDraw == NULL) || (overrideLimbDraw(globalCtx, 1, &dList, &pos, &rot, actor, &gfx) == 0)) { + if ((overrideLimbDraw == NULL) || !overrideLimbDraw(globalCtx, 1, &dList, &pos, &rot, arg, &gfx)) { Matrix_JointPosition(&pos, &rot); if (dList != NULL) { gSPMatrix(gfx++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_skelanime.c", 1558), G_MTX_LOAD); @@ -602,12 +588,12 @@ Gfx* SkelAnime_Draw2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDr } if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, 1, &dList, &rot, actor, &gfx); + postLimbDraw(globalCtx, 1, &dList, &rot, arg, &gfx); } - if (limbEntry->firstChildIndex != LIMB_DONE) { - gfx = SkelAnime_Draw2Limb(globalCtx, limbEntry->firstChildIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, gfx); + if (rootLimb->child != LIMB_DONE) { + gfx = SkelAnime_DrawLimb(globalCtx, rootLimb->child, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, + arg, gfx); } Matrix_Pull(); @@ -615,69 +601,70 @@ Gfx* SkelAnime_Draw2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDr return gfx; } -Gfx* SkelAnime_DrawLimbSV2(GlobalContext* globalCtx, s32 limbIndex, Skeleton* skeleton, Vec3s* limbDrawTable, - OverrideLimbDraw2 overrideLimbDraw, PostLimbDraw2 postLimbDraw, Actor* actor, Mtx** mtx, - Gfx* gfx) { - SkelLimbEntry* limbEntry; - Gfx* dList1; - Gfx* dList2; +/* + * Draw a limb of type `StandardLimb` contained within a flexible skeleton to the specified display buffer + */ +Gfx* SkelAnime_DrawFlexLimb(GlobalContext* globalCtx, s32 limbIndex, void** skeleton, Vec3s* limbDrawTable, + OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, void* arg, Mtx** mtx, + Gfx* gfx) { + StandardLimb* limb; + Gfx* newDList; + Gfx* limbDList; Vec3f pos; Vec3s rot; - char pad[4]; Matrix_Push(); - limbEntry = SEGMENTED_TO_VIRTUAL(skeleton->limbs[limbIndex]); + limb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]); limbIndex++; rot = limbDrawTable[limbIndex]; - pos.x = limbEntry->translation.x; - pos.y = limbEntry->translation.y; - pos.z = limbEntry->translation.z; + pos.x = limb->jointPos.x; + pos.y = limb->jointPos.y; + pos.z = limb->jointPos.z; - dList1 = dList2 = limbEntry->displayLists[0]; - if ((overrideLimbDraw == NULL) || (overrideLimbDraw(globalCtx, limbIndex, &dList1, &pos, &rot, actor, &gfx) == 0)) { + newDList = limbDList = limb->dList; + if ((overrideLimbDraw == NULL) || !overrideLimbDraw(globalCtx, limbIndex, &newDList, &pos, &rot, arg, &gfx)) { Matrix_JointPosition(&pos, &rot); - if (dList1 != NULL) { + if (newDList != NULL) { Matrix_ToMtx(*mtx, "../z_skelanime.c", 1623); gSPMatrix(gfx++, *mtx, G_MTX_LOAD); - gSPDisplayList(gfx++, dList1); + gSPDisplayList(gfx++, newDList); + (*mtx)++; + } else if (limbDList != NULL) { + Matrix_ToMtx(*mtx, "../z_skelanime.c", 1630); (*mtx)++; - } else { - if (dList2 != NULL) { - Matrix_ToMtx(*mtx, "../z_skelanime.c", 1630); - (*mtx)++; - } } } if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, limbIndex, &dList2, &rot, actor, &gfx); + postLimbDraw(globalCtx, limbIndex, &limbDList, &rot, arg, &gfx); } - if (limbEntry->firstChildIndex != LIMB_DONE) { - gfx = SkelAnime_DrawLimbSV2(globalCtx, limbEntry->firstChildIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, mtx, gfx); + if (limb->child != LIMB_DONE) { + gfx = SkelAnime_DrawFlexLimb(globalCtx, limb->child, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, + arg, mtx, gfx); } Matrix_Pull(); - if (limbEntry->nextLimbIndex != LIMB_DONE) { - gfx = SkelAnime_DrawLimbSV2(globalCtx, limbEntry->nextLimbIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, mtx, gfx); + if (limb->sibling != LIMB_DONE) { + gfx = SkelAnime_DrawFlexLimb(globalCtx, limb->sibling, skeleton, limbDrawTable, overrideLimbDraw, postLimbDraw, + arg, mtx, gfx); } return gfx; } /* - * Draws the Skeleton `skeleton` Appends all generated graphics to `gfx`, and returns a pointer to the - * next gfx to be appended to. Allocates matricies for display lists on the graph heap. + * Draw all limbs of type `StandardLimb` in a given flexible skeleton to the specified display buffer + * Limbs in a flexible skeleton have meshes that can stretch to line up with other limbs. + * An array of matrices is dynamically allocated so each limb can access any transform to ensure its meshes line up. */ -Gfx* SkelAnime_DrawSV2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limbDrawTable, s32 dListCount, - OverrideLimbDraw2 overrideLimbDraw, PostLimbDraw2 postLimbDraw, Actor* actor, Gfx* gfx) { - SkelLimbEntry* limbEntry; - char pad[4]; - Gfx* dList1; - Gfx* dList2; +Gfx* SkelAnime_DrawFlex(GlobalContext* globalCtx, void** skeleton, Vec3s* limbDrawTable, s32 dListCount, + OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, void* arg, Gfx* gfx) { + StandardLimb* rootLimb; + s32 pad; + Gfx* newDList; + Gfx* limbDList; Vec3f pos; Vec3s rot; Mtx* mtx; @@ -693,7 +680,7 @@ Gfx* SkelAnime_DrawSV2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limb gSPSegment(gfx++, 0xD, mtx); Matrix_Push(); - limbEntry = SEGMENTED_TO_VIRTUAL(skeleton->limbs[0]); + rootLimb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[0]); pos.x = limbDrawTable[0].x; pos.y = limbDrawTable[0].y; @@ -701,28 +688,26 @@ Gfx* SkelAnime_DrawSV2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limb rot = limbDrawTable[1]; - dList1 = dList2 = limbEntry->displayLists[0]; + newDList = limbDList = rootLimb->dList; - if ((overrideLimbDraw == NULL) || (overrideLimbDraw(globalCtx, 1, &dList1, &pos, &rot, actor, &gfx) == 0)) { + if ((overrideLimbDraw == NULL) || !overrideLimbDraw(globalCtx, 1, &newDList, &pos, &rot, arg, &gfx)) { Matrix_JointPosition(&pos, &rot); - if (dList1 != NULL) { + if (newDList != NULL) { Matrix_ToMtx(mtx, "../z_skelanime.c", 1710); gSPMatrix(gfx++, mtx, G_MTX_LOAD); - gSPDisplayList(gfx++, dList1); + gSPDisplayList(gfx++, newDList); + mtx++; + } else if (limbDList != NULL) { + Matrix_ToMtx(mtx, "../z_skelanime.c", 1717); mtx++; - } else { - if (dList2 != NULL) { - Matrix_ToMtx(mtx, "../z_skelanime.c", 1717); - mtx++; - } } } if (postLimbDraw != NULL) { - postLimbDraw(globalCtx, 1, &dList2, &rot, actor, &gfx); + postLimbDraw(globalCtx, 1, &limbDList, &rot, arg, &gfx); } - if (limbEntry->firstChildIndex != LIMB_DONE) { - gfx = SkelAnime_DrawLimbSV2(globalCtx, limbEntry->firstChildIndex, skeleton, limbDrawTable, overrideLimbDraw, - postLimbDraw, actor, &mtx, gfx); + if (rootLimb->child != LIMB_DONE) { + gfx = SkelAnime_DrawFlexLimb(globalCtx, rootLimb->child, skeleton, limbDrawTable, overrideLimbDraw, + postLimbDraw, arg, &mtx, gfx); } Matrix_Pull(); @@ -730,17 +715,13 @@ Gfx* SkelAnime_DrawSV2(GlobalContext* globalCtx, Skeleton* skeleton, Vec3s* limb return gfx; } +// unused s32 func_800A29BC(s32 arg0, s32 arg1, Vec3s* arg2) { - s16* temp_t1; - s16* temp_a3; - AnimationHeader* temp_v0; + AnimationHeader* temp_v0 = SEGMENTED_TO_VIRTUAL(arg0); + s32 t = temp_v0->genericHeader.unk_02; + s16* temp_a3 = SEGMENTED_TO_VIRTUAL(temp_v0->rotationIndexSeg); + s16* temp_t1 = SEGMENTED_TO_VIRTUAL(temp_v0->rotationValueSeg); s32 phi_v0; - s32 t; - - temp_v0 = SEGMENTED_TO_VIRTUAL(arg0); - t = temp_v0->genericHeader.unk_02; - temp_a3 = SEGMENTED_TO_VIRTUAL(temp_v0->rotationIndexSeg); - temp_t1 = SEGMENTED_TO_VIRTUAL(temp_v0->rotationValueSeg); arg2->x = arg1 < temp_a3[0] ? ((s16*)((arg1 * 2) + (u32)temp_t1))[temp_a3[1]] : temp_t1[temp_a3[1]]; arg2->y = arg1 < temp_a3[2] ? ((s16*)((arg1 * 2) + (u32)temp_t1))[temp_a3[3]] : temp_t1[temp_a3[3]]; @@ -782,7 +763,8 @@ ret: return t; } -s16 func_800A2DBC(GenericAnimationHeader* animationSeg) { +// unused +s16 func_800A2DBC(void* animationSeg) { GenericAnimationHeader* animation = SEGMENTED_TO_VIRTUAL(animationSeg); return animation->unk_02; @@ -792,7 +774,7 @@ s16 func_800A2DBC(GenericAnimationHeader* animationSeg) { * Appears to be unused anywhere in the game. Appears to be a clone of * SkelAnime_GetTotalFrames */ -s16 SkelAnime_GetTotalFrames2(GenericAnimationHeader* animationSeg) { +s16 SkelAnime_GetTotalFrames2(void* animationSeg) { GenericAnimationHeader* animation = SEGMENTED_TO_VIRTUAL(animationSeg); return animation->frameCount; @@ -802,7 +784,7 @@ s16 SkelAnime_GetTotalFrames2(GenericAnimationHeader* animationSeg) { * Appears to be unused anywhere in the game. Appears to be a clone of * SkelAnime_GetFrameCount */ -s16 SkelAnime_GetFrameCount2(GenericAnimationHeader* animationSeg) { +s16 SkelAnime_GetFrameCount2(void* animationSeg) { GenericAnimationHeader* animation = SEGMENTED_TO_VIRTUAL(animationSeg); return animation->frameCount - 1; @@ -843,12 +825,10 @@ void func_800A32F4(GlobalContext* globalCtx) { } void func_800A3310(GlobalContext* globalCtx) { - u32* D_8012A480Ptr = &D_8012A480; - - *D_8012A480Ptr |= D_801600B0; + D_8012A480 |= D_801600B0; } -AnimationEntry* SkelAnime_NextEntry(AnimationContext* animationCtx, AnimationType type) { +AnimationEntry* SkelAnime_AddEntry(AnimationContext* animationCtx, AnimationType type) { AnimationEntry* entry; s16 index = animationCtx->animationCount; @@ -861,116 +841,121 @@ AnimationEntry* SkelAnime_NextEntry(AnimationContext* animationCtx, AnimationTyp return entry; } -/* - * The next 6 functions are coordinate with the AnimationType enum - */ - -void SkelAnime_LoadLinkAnimetion(GlobalContext* globalCtx, LinkAnimetionEntry* linkAnimetionSeg, s32 frame, - s32 limbCount, void* ram) { - AnimationEntry* entry; - LinkAnimetionEntry* linkAnimetionEntry; - char pad[4]; +// The next 6 functions are coordinate with the AnimationType enum - entry = SkelAnime_NextEntry(&globalCtx->animationCtx, ANIMATION_LINKANIMETION); +void SkelAnime_LoadLinkAnimation(GlobalContext* globalCtx, LinkAnimationHeader* segment, s32 frame, s32 limbCount, + Vec3s* drawTbl) { + AnimationEntry* entry = SkelAnime_AddEntry(&globalCtx->animationCtx, ANIMATION_LINK); if (entry != NULL) { - linkAnimetionEntry = SEGMENTED_TO_VIRTUAL(linkAnimetionSeg); - osCreateMesgQueue(&entry->types.type0.msgQueue, &entry->types.type0.msg, 1); - DmaMgr_SendRequest2( - &entry->types.type0.req, ram, - LINK_ANIMETION_OFFSET(linkAnimetionEntry->animationSegAddress, ((sizeof(Vec3s) * limbCount + 2) * frame)), - sizeof(Vec3s) * limbCount + 2, 0, &entry->types.type0.msgQueue, NULL, "../z_skelanime.c", 2004); + LinkAnimationHeader* linkAnimHeader = SEGMENTED_TO_VIRTUAL(segment); + u32 ram = drawTbl; + + osCreateMesgQueue(&entry->data.type0.msgQueue, &entry->data.type0.msg, 1); + DmaMgr_SendRequest2(&entry->data.type0.req, ram, + LINK_ANIMATION_OFFSET(linkAnimHeader->segment, ((sizeof(Vec3s) * limbCount + 2) * frame)), + sizeof(Vec3s) * limbCount + 2, 0, &entry->data.type0.msgQueue, NULL, "../z_skelanime.c", + 2004); } } void SkelAnime_LoadAnimationType1(GlobalContext* globalCtx, s32 vecCount, Vec3s* dst, Vec3s* src) { - AnimationEntry* entry = SkelAnime_NextEntry(&globalCtx->animationCtx, ANIMATION_TYPE1); + AnimationEntry* entry = SkelAnime_AddEntry(&globalCtx->animationCtx, ANIMATION_TYPE1); + if (entry != NULL) { - entry->types.type1.unk_00 = D_801600B0; - entry->types.type1.vecCount = vecCount; - entry->types.type1.dst = dst; - entry->types.type1.src = src; + entry->data.type1.unk_00 = D_801600B0; + entry->data.type1.vecCount = vecCount; + entry->data.type1.dst = dst; + entry->data.type1.src = src; } } void SkelAnime_LoadAnimationType2(GlobalContext* globalCtx, s32 limbCount, Vec3s* arg2, Vec3s* arg3, f32 arg4) { - AnimationEntry* entry = SkelAnime_NextEntry(&globalCtx->animationCtx, ANIMATION_TYPE2); + AnimationEntry* entry = SkelAnime_AddEntry(&globalCtx->animationCtx, ANIMATION_TYPE2); + if (entry != NULL) { - entry->types.type2.unk_00 = D_801600B0; - entry->types.type2.limbCount = limbCount; - entry->types.type2.unk_04 = arg2; - entry->types.type2.unk_08 = arg3; - entry->types.type2.unk_0C = arg4; + entry->data.type2.unk_00 = D_801600B0; + entry->data.type2.limbCount = limbCount; + entry->data.type2.unk_04 = arg2; + entry->data.type2.unk_08 = arg3; + entry->data.type2.unk_0C = arg4; } } void SkelAnime_LoadAnimationType3(GlobalContext* globalCtx, s32 vecCount, Vec3s* dst, Vec3s* src, u8* index) { - AnimationEntry* entry = SkelAnime_NextEntry(&globalCtx->animationCtx, ANIMATION_TYPE3); + AnimationEntry* entry = SkelAnime_AddEntry(&globalCtx->animationCtx, ANIMATION_TYPE3); + if (entry != NULL) { - entry->types.type3.unk_00 = D_801600B0; - entry->types.type3.vecCount = vecCount; - entry->types.type3.dst = dst; - entry->types.type3.src = src; - entry->types.type3.index = index; + entry->data.type3.unk_00 = D_801600B0; + entry->data.type3.vecCount = vecCount; + entry->data.type3.dst = dst; + entry->data.type3.src = src; + entry->data.type3.index = index; } } void SkelAnime_LoadAnimationType4(GlobalContext* globalCtx, s32 vecCount, Vec3s* dst, Vec3s* src, u8* index) { - AnimationEntry* entry = SkelAnime_NextEntry(&globalCtx->animationCtx, ANIMATION_TYPE4); + AnimationEntry* entry = SkelAnime_AddEntry(&globalCtx->animationCtx, ANIMATION_TYPE4); + if (entry != NULL) { - entry->types.type4.unk_00 = D_801600B0; - entry->types.type4.vecCount = vecCount; - entry->types.type4.dst = dst; - entry->types.type4.src = src; - entry->types.type4.index = index; + entry->data.type4.unk_00 = D_801600B0; + entry->data.type4.vecCount = vecCount; + entry->data.type4.dst = dst; + entry->data.type4.src = src; + entry->data.type4.index = index; } } void SkelAnime_LoadAnimationType5(GlobalContext* globalCtx, Actor* actor, SkelAnime* skelAnime, f32 arg3) { - AnimationEntry* entry = SkelAnime_NextEntry(&globalCtx->animationCtx, ANIMATION_TYPE5); + AnimationEntry* entry = SkelAnime_AddEntry(&globalCtx->animationCtx, ANIMATION_TYPE5); + if (entry != NULL) { - entry->types.type5.actor = actor; - entry->types.type5.skelAnime = skelAnime; - entry->types.type5.unk_08 = arg3; + entry->data.type5.actor = actor; + entry->data.type5.skelAnime = skelAnime; + entry->data.type5.unk_08 = arg3; } } -/* The next functions are callbacks to loading animations */ +// The next functions are callbacks to loading animations + +void SkelAnime_LinkAnimationLoaded(GlobalContext* globalCtx, AnimationEntryData* data) { + AnimationEntryType0* entry = &data->type0; -void SkelAnime_LinkAnimetionLoaded(GlobalContext* globalCtx, AnimationEntryType0* entry) { osRecvMesg(&entry->msgQueue, NULL, OS_MESG_BLOCK); } -void SkelAnime_AnimationType1Loaded(GlobalContext* globalCtx, AnimationEntryType1* entry) { - s32 i; - Vec3s* dst; - Vec3s* src; - AnimationEntryRaw* genericEntry = (AnimationEntryRaw*)entry; +void SkelAnime_AnimationType1Loaded(GlobalContext* globalCtx, AnimationEntryData* data) { + AnimationEntryType1* entry = &data->type1; - if ((genericEntry->raw[0] & D_8012A480) != 0) { - return; - } + if (!(entry->unk_00 & D_8012A480)) { + Vec3s* dst = entry->dst; + Vec3s* src = entry->src; + s32 i; - for (dst = entry->dst, src = entry->src, i = 0; i < genericEntry->raw[1]; i++) { - *dst++ = *src++; + for (i = 0; i < entry->vecCount; i++) { + *dst++ = *src++; + } } } -void SkelAnime_AnimationType2Loaded(GlobalContext* globalCtx, AnimationEntryType2* entry) { - if ((entry->unk_00 & D_8012A480) == 0) { +void SkelAnime_AnimationType2Loaded(GlobalContext* globalCtx, AnimationEntryData* data) { + AnimationEntryType2* entry = &data->type2; + + if (!(entry->unk_00 & D_8012A480)) { SkelAnime_InterpolateVec3s(entry->limbCount, entry->unk_04, entry->unk_04, entry->unk_08, entry->unk_0C); } } -void SkelAnime_AnimationType3Loaded(GlobalContext* globalCtx, AnimationEntryType3* entry) { - s32 i; - Vec3s* dst; - Vec3s* src; - u8* index; - AnimationEntryRaw* rawEntry = (AnimationEntryRaw*)entry; +void SkelAnime_AnimationType3Loaded(GlobalContext* globalCtx, AnimationEntryData* data) { + AnimationEntryType3* entry = &data->type3; - if ((rawEntry->raw[0] & D_8012A480) == 0) { - for (dst = entry->dst, src = entry->src, index = entry->index, i = 0; i < rawEntry->raw[1]; i++, dst++, src++) { + if (!(entry->unk_00 & D_8012A480)) { + Vec3s* dst = entry->dst; + Vec3s* src = entry->src; + u8* index = entry->index; + s32 i; + + for (i = 0; i < entry->vecCount; i++, dst++, src++) { if (*index++) { *dst = *src; } @@ -978,24 +963,25 @@ void SkelAnime_AnimationType3Loaded(GlobalContext* globalCtx, AnimationEntryType } } -void SkelAnime_AnimationType4Loaded(GlobalContext* globalCtx, AnimationEntryType4* entry) { - s32 i; - Vec3s* dst; - Vec3s* src; - u8* index; - AnimationEntryRaw* rawEntry = (AnimationEntryRaw*)entry; - - if ((rawEntry->raw[0] & D_8012A480) == 0) { - for (dst = entry->dst, src = entry->src, index = entry->index, i = 0; i < rawEntry->raw[1]; i++, dst++, src++) { - if (*index++ < 1U) { +void SkelAnime_AnimationType4Loaded(GlobalContext* globalCtx, AnimationEntryData* data) { + AnimationEntryType4* entry = &data->type4; + + if (!(entry->unk_00 & D_8012A480)) { + Vec3s* dst = entry->dst; + Vec3s* src = entry->src; + u8* index = entry->index; + s32 i; + + for (i = 0; i < entry->vecCount; i++, dst++, src++) { + if (!(*index++)) { *dst = *src; } } } } -void SkelAnime_AnimationType5Loaded(GlobalContext* globalCtx, AnimationEntryType5* entry) { - char pad[4]; +void SkelAnime_AnimationType5Loaded(GlobalContext* globalCtx, AnimationEntryData* data) { + AnimationEntryType5* entry = &data->type5; Actor* actor = entry->actor; Vec3f pos; @@ -1006,42 +992,43 @@ void SkelAnime_AnimationType5Loaded(GlobalContext* globalCtx, AnimationEntryType } void func_800A390C(GlobalContext* globalCtx, AnimationContext* animationCtx) { + static AnimationEntryCallback sAnimationLoadDone[] = { + SkelAnime_LinkAnimationLoaded, SkelAnime_AnimationType1Loaded, SkelAnime_AnimationType2Loaded, + SkelAnime_AnimationType3Loaded, SkelAnime_AnimationType4Loaded, SkelAnime_AnimationType5Loaded, + }; AnimationEntry* entry; for (entry = animationCtx->entries; animationCtx->animationCount != 0; entry++, animationCtx->animationCount--) { - sAnimationLoadDone[entry->type](globalCtx, &entry->types); + sAnimationLoadDone[entry->type](globalCtx, &entry->data); } D_801600B0 = 1; D_8012A480 = 0; } -void SkelAnime_InitLinkAnimetion(GlobalContext* globalCtx, SkelAnime* skelAnime, SkeletonHeader* skeletonHeaderSeg, - LinkAnimetionEntry* linkAnimetionEntrySeg, s32 flags, Vec3s* limbDrawTbl, - Vec3s* transitionDrawTbl, s32 limbBufCount) { - char pad[8]; - SkeletonHeader* skeletonHeader; - size_t allocSize; +void SkelAnime_InitLinkAnimation(GlobalContext* globalCtx, SkelAnime* skelAnime, FlexSkeletonHeader* skeletonHeaderSeg, + LinkAnimationHeader* segment, s32 flags, Vec3s* limbDrawTbl, Vec3s* transitionDrawTbl, + s32 limbBufCount) { + FlexSkeletonHeader* skeletonHeader = SEGMENTED_TO_VIRTUAL(skeletonHeaderSeg); + s32 headerJointCount = skeletonHeader->sh.limbCount; s32 limbCount; - s32 headerCount; + size_t allocSize; - skeletonHeader = SEGMENTED_TO_VIRTUAL(skeletonHeaderSeg); - headerCount = skeletonHeader->limbCount; skelAnime->initFlags = flags; - limbCount = (flags & 2) ? headerCount : 1; + limbCount = (flags & 2) ? headerJointCount : 1; if (flags & 1) { - limbCount += headerCount; + limbCount += headerJointCount; } if (flags & 4) { - limbCount += headerCount; + limbCount += headerJointCount; } skelAnime->limbCount = limbCount; skelAnime->dListCount = skeletonHeader->dListCount; allocSize = limbCount * sizeof(Vec3s); - skelAnime->skeleton = SEGMENTED_TO_VIRTUAL(skeletonHeader->skeletonSeg); + skelAnime->skeleton = SEGMENTED_TO_VIRTUAL(skeletonHeader->sh.segment); if (flags & 8) { allocSize += 2; @@ -1066,24 +1053,24 @@ void SkelAnime_InitLinkAnimetion(GlobalContext* globalCtx, SkelAnime* skelAnime, osSyncPrintf(VT_RST); } - SkelAnime_ChangeLinkAnim(globalCtx, skelAnime, linkAnimetionEntrySeg, 1.0f, 0.0f, 0.0f, 0, 0.0f); + SkelAnime_ChangeLinkAnim(globalCtx, skelAnime, segment, 1.0f, 0.0f, 0.0f, 0, 0.0f); } void func_800A3B8C(SkelAnime* skelAnime) { if (skelAnime->mode < 2) { - skelAnime->animUpdate = &func_800A3D70; + skelAnime->update = func_800A3D70; } else { - skelAnime->animUpdate = &func_800A3E0C; + skelAnime->update = func_800A3E0C; } skelAnime->transCurrentFrame = 0.0f; } s32 func_800A3BC0(GlobalContext* globalCtx, SkelAnime* skelAnime) { - return skelAnime->animUpdate(globalCtx, skelAnime); + return skelAnime->update(globalCtx, skelAnime); } s32 func_800A3BE4(GlobalContext* globalCtx, SkelAnime* skelAnime) { - f32 prevUnk28 = skelAnime->transCurrentFrame; + f32 transPrevFRame = skelAnime->transCurrentFrame; f32 updateRate = R_UPDATE_RATE * 0.5f; skelAnime->transCurrentFrame -= skelAnime->transitionStep * updateRate; @@ -1093,24 +1080,23 @@ s32 func_800A3BE4(GlobalContext* globalCtx, SkelAnime* skelAnime) { } SkelAnime_LoadAnimationType2(globalCtx, skelAnime->limbCount, skelAnime->limbDrawTbl, skelAnime->transitionDrawTbl, - 1.0f - (skelAnime->transCurrentFrame / prevUnk28)); + 1.0f - (skelAnime->transCurrentFrame / transPrevFRame)); return 0; } void func_800A3C9C(GlobalContext* globalCtx, SkelAnime* skelAnime) { - f32 updateRate; - - SkelAnime_LoadLinkAnimetion(globalCtx, skelAnime->linkAnimetionSeg, skelAnime->animCurrentFrame, - skelAnime->limbCount, skelAnime->limbDrawTbl); + SkelAnime_LoadLinkAnimation(globalCtx, skelAnime->animation, skelAnime->animCurrentFrame, skelAnime->limbCount, + skelAnime->limbDrawTbl); if (skelAnime->transCurrentFrame != 0) { - updateRate = R_UPDATE_RATE * 0.5f; + f32 updateRate = R_UPDATE_RATE * 0.5f; + skelAnime->transCurrentFrame -= skelAnime->transitionStep * updateRate; if (skelAnime->transCurrentFrame <= 0.0f) { skelAnime->transCurrentFrame = 0.0f; - return; + } else { + SkelAnime_LoadAnimationType2(globalCtx, skelAnime->limbCount, skelAnime->limbDrawTbl, + skelAnime->transitionDrawTbl, skelAnime->transCurrentFrame); } - SkelAnime_LoadAnimationType2(globalCtx, skelAnime->limbCount, skelAnime->limbDrawTbl, - skelAnime->transitionDrawTbl, skelAnime->transCurrentFrame); } } @@ -1135,14 +1121,12 @@ s32 func_800A3E0C(GlobalContext* globalCtx, SkelAnime* skelAnime) { return 1; } skelAnime->animCurrentFrame += skelAnime->animPlaybackSpeed * updateRate; - if (0.0f < ((skelAnime->animCurrentFrame - skelAnime->animFrameCount) * skelAnime->animPlaybackSpeed)) { + if ((skelAnime->animCurrentFrame - skelAnime->animFrameCount) * skelAnime->animPlaybackSpeed > 0.0f) { skelAnime->animCurrentFrame = skelAnime->animFrameCount; - } else { - if (skelAnime->animCurrentFrame < 0.0f) { - skelAnime->animCurrentFrame += skelAnime->totalFrames; - } else if (skelAnime->totalFrames <= skelAnime->animCurrentFrame) { - skelAnime->animCurrentFrame -= skelAnime->totalFrames; - } + } else if (skelAnime->animCurrentFrame < 0.0f) { + skelAnime->animCurrentFrame += skelAnime->totalFrames; + } else if (skelAnime->totalFrames <= skelAnime->animCurrentFrame) { + skelAnime->animCurrentFrame -= skelAnime->totalFrames; } func_800A3C9C(globalCtx, skelAnime); return 0; @@ -1153,81 +1137,72 @@ void SkelAnime_SetTransition(GlobalContext* globalCtx, SkelAnime* skelAnime, f32 skelAnime->transitionStep = 1.0f / transitionRate; } -void SkelAnime_ChangeLinkAnim(GlobalContext* globalCtx, SkelAnime* skelAnime, LinkAnimetionEntry* linkAnimetionEntrySeg, +void SkelAnime_ChangeLinkAnim(GlobalContext* globalCtx, SkelAnime* skelAnime, LinkAnimationHeader* segment, f32 playbackSpeed, f32 frame, f32 frameCount, u8 animationMode, f32 transitionRate) { - skelAnime->mode = animationMode; - if ((transitionRate != 0.0f) && - ((linkAnimetionEntrySeg != skelAnime->linkAnimetionSeg) || (frame != skelAnime->animCurrentFrame))) { + if ((transitionRate != 0.0f) && ((segment != skelAnime->animation) || (frame != skelAnime->animCurrentFrame))) { if (transitionRate < 0) { func_800A3B8C(skelAnime); SkelAnime_CopyVec3s(skelAnime, skelAnime->transitionDrawTbl, skelAnime->limbDrawTbl); transitionRate = -transitionRate; } else { - skelAnime->animUpdate = &func_800A3BE4; - SkelAnime_LoadLinkAnimetion(globalCtx, linkAnimetionEntrySeg, (s32)frame, skelAnime->limbCount, + skelAnime->update = func_800A3BE4; + SkelAnime_LoadLinkAnimation(globalCtx, segment, (s32)frame, skelAnime->limbCount, skelAnime->transitionDrawTbl); } skelAnime->transCurrentFrame = 1.0f; skelAnime->transitionStep = 1.0f / transitionRate; } else { func_800A3B8C(skelAnime); - SkelAnime_LoadLinkAnimetion(globalCtx, linkAnimetionEntrySeg, (s32)frame, skelAnime->limbCount, - skelAnime->limbDrawTbl); + SkelAnime_LoadLinkAnimation(globalCtx, segment, (s32)frame, skelAnime->limbCount, skelAnime->limbDrawTbl); skelAnime->transCurrentFrame = 0.0f; } - skelAnime->linkAnimetionSeg = linkAnimetionEntrySeg; + skelAnime->animation = segment; skelAnime->animCurrentFrame = 0.0f; skelAnime->initialFrame = frame; skelAnime->animCurrentFrame = frame; skelAnime->animFrameCount = frameCount; - skelAnime->totalFrames = SkelAnime_GetTotalFrames(linkAnimetionEntrySeg); + skelAnime->totalFrames = SkelAnime_GetTotalFrames(segment); skelAnime->animPlaybackSpeed = playbackSpeed; } -void SkelAnime_ChangeLinkAnimDefaultStop(GlobalContext* globalCtx, SkelAnime* skelAnime, - LinkAnimetionEntry* linkAnimetionEntrySeg) { - SkelAnime_ChangeLinkAnim(globalCtx, skelAnime, linkAnimetionEntrySeg, 1.0f, 0.0f, - SkelAnime_GetFrameCount(&linkAnimetionEntrySeg->genericHeader), 2, 0.0f); +void SkelAnime_ChangeLinkAnimDefaultStop(GlobalContext* globalCtx, SkelAnime* skelAnime, LinkAnimationHeader* segment) { + SkelAnime_ChangeLinkAnim(globalCtx, skelAnime, segment, 1.0f, 0.0f, SkelAnime_GetFrameCount(segment), 2, 0.0f); } -void SkelAnime_ChangeLinkAnimPlaybackStop(GlobalContext* globalCtx, SkelAnime* skelAnime, - LinkAnimetionEntry* linkAnimetionEntrySeg, f32 playbackSpeed) { - SkelAnime_ChangeLinkAnim(globalCtx, skelAnime, linkAnimetionEntrySeg, playbackSpeed, 0.0f, - SkelAnime_GetFrameCount(&linkAnimetionEntrySeg->genericHeader), 2, 0.0f); +void SkelAnime_ChangeLinkAnimPlaybackStop(GlobalContext* globalCtx, SkelAnime* skelAnime, LinkAnimationHeader* segment, + f32 playbackSpeed) { + SkelAnime_ChangeLinkAnim(globalCtx, skelAnime, segment, playbackSpeed, 0.0f, SkelAnime_GetFrameCount(segment), 2, + 0.0f); } void SkelAnime_ChangeLinkAnimDefaultRepeat(GlobalContext* globalCtx, SkelAnime* skelAnime, - LinkAnimetionEntry* linkAnimetionEntrySeg) { - SkelAnime_ChangeLinkAnim(globalCtx, skelAnime, linkAnimetionEntrySeg, 1.0f, 0.0f, - SkelAnime_GetFrameCount(&linkAnimetionEntrySeg->genericHeader), 0, 0.0f); + LinkAnimationHeader* segment) { + SkelAnime_ChangeLinkAnim(globalCtx, skelAnime, segment, 1.0f, 0.0f, SkelAnime_GetFrameCount(segment), 0, 0.0f); } void SkelAnime_ChangeLinkAnimPlaybackRepeat(GlobalContext* globalCtx, SkelAnime* skelAnime, - LinkAnimetionEntry* linkAnimetionEntrySeg, f32 playbackSpeed) { - SkelAnime_ChangeLinkAnim(globalCtx, skelAnime, linkAnimetionEntrySeg, playbackSpeed, 0.0f, - SkelAnime_GetFrameCount(&linkAnimetionEntrySeg->genericHeader), 0, 0.0f); + LinkAnimationHeader* segment, f32 playbackSpeed) { + SkelAnime_ChangeLinkAnim(globalCtx, skelAnime, segment, playbackSpeed, 0.0f, SkelAnime_GetFrameCount(segment), 0, + 0.0f); } void func_800A41FC(GlobalContext* globalCtx, SkelAnime* skelAnime) { SkelAnime_LoadAnimationType1(globalCtx, skelAnime->limbCount, skelAnime->transitionDrawTbl, skelAnime->limbDrawTbl); } +// Unused void func_800A422C(GlobalContext* globalCtx, SkelAnime* skelAnime) { SkelAnime_LoadAnimationType1(globalCtx, skelAnime->limbCount, skelAnime->limbDrawTbl, skelAnime->transitionDrawTbl); } -void func_800A425C(GlobalContext* globalCtx, SkelAnime* skelAnime, LinkAnimetionEntry* linkAnimetionEntrySeg, - f32 frame) { - SkelAnime_LoadLinkAnimetion(globalCtx, linkAnimetionEntrySeg, (s32)frame, skelAnime->limbCount, - skelAnime->transitionDrawTbl); +void func_800A425C(GlobalContext* globalCtx, SkelAnime* skelAnime, LinkAnimationHeader* segment, f32 frame) { + SkelAnime_LoadLinkAnimation(globalCtx, segment, (s32)frame, skelAnime->limbCount, skelAnime->transitionDrawTbl); } -void func_800A42A0(GlobalContext* globalCtx, SkelAnime* skelAnime, LinkAnimetionEntry* linkAnimetionEntrySeg, - f32 frame) { - SkelAnime_LoadLinkAnimetion(globalCtx, linkAnimetionEntrySeg, (s32)frame, skelAnime->limbCount, - skelAnime->limbDrawTbl); +void func_800A42A0(GlobalContext* globalCtx, SkelAnime* skelAnime, LinkAnimationHeader* segment, f32 frame) { + SkelAnime_LoadLinkAnimation(globalCtx, segment, (s32)frame, skelAnime->limbCount, skelAnime->limbDrawTbl); } void func_800A42E4(GlobalContext* globalCtx, SkelAnime* skelAnime, f32 frame) { @@ -1235,49 +1210,44 @@ void func_800A42E4(GlobalContext* globalCtx, SkelAnime* skelAnime, f32 frame) { frame); } -void func_800A431C(GlobalContext* globalCtx, SkelAnime* skelAnime, LinkAnimetionEntry* linkAnimetionEntrySeg, - f32 transitionFrame, LinkAnimetionEntry* linkAnimetionEntrySeg2, f32 frame, f32 transitionRate, - Vec3s* limbDrawTbl) { +void func_800A431C(GlobalContext* globalCtx, SkelAnime* skelAnime, LinkAnimationHeader* segment, f32 transitionFrame, + LinkAnimationHeader* linkAnimSeg2, f32 frame, f32 transitionRate, Vec3s* limbDrawTbl) { Vec3s* alignedLimbDrawTbl; - SkelAnime_LoadLinkAnimetion(globalCtx, linkAnimetionEntrySeg, (s32)transitionFrame, skelAnime->limbCount, - skelAnime->limbDrawTbl); + + SkelAnime_LoadLinkAnimation(globalCtx, segment, (s32)transitionFrame, skelAnime->limbCount, skelAnime->limbDrawTbl); alignedLimbDrawTbl = (Vec3s*)ALIGN16((u32)limbDrawTbl); - SkelAnime_LoadLinkAnimetion(globalCtx, linkAnimetionEntrySeg2, (s32)frame, skelAnime->limbCount, - alignedLimbDrawTbl); + SkelAnime_LoadLinkAnimation(globalCtx, linkAnimSeg2, (s32)frame, skelAnime->limbCount, alignedLimbDrawTbl); SkelAnime_LoadAnimationType2(globalCtx, skelAnime->limbCount, skelAnime->limbDrawTbl, alignedLimbDrawTbl, transitionRate); } -void func_800A43B8(GlobalContext* globalCtx, SkelAnime* skelAnime, LinkAnimetionEntry* linkAnimetionEntrySeg, - f32 transitionFrame, LinkAnimetionEntry* linkAnimetionEntrySeg2, f32 frame, f32 transitionRate, - Vec3s* limbDrawTbl) { +void func_800A43B8(GlobalContext* globalCtx, SkelAnime* skelAnime, LinkAnimationHeader* segment, f32 transitionFrame, + LinkAnimationHeader* linkAnimSeg2, f32 frame, f32 transitionRate, Vec3s* limbDrawTbl) { Vec3s* alignedLimbDrawTbl; - SkelAnime_LoadLinkAnimetion(globalCtx, linkAnimetionEntrySeg, (s32)transitionFrame, skelAnime->limbCount, + SkelAnime_LoadLinkAnimation(globalCtx, segment, (s32)transitionFrame, skelAnime->limbCount, skelAnime->transitionDrawTbl); alignedLimbDrawTbl = (Vec3s*)ALIGN16((u32)limbDrawTbl); - SkelAnime_LoadLinkAnimetion(globalCtx, linkAnimetionEntrySeg2, (s32)frame, skelAnime->limbCount, - alignedLimbDrawTbl); + SkelAnime_LoadLinkAnimation(globalCtx, linkAnimSeg2, (s32)frame, skelAnime->limbCount, alignedLimbDrawTbl); SkelAnime_LoadAnimationType2(globalCtx, skelAnime->limbCount, skelAnime->transitionDrawTbl, alignedLimbDrawTbl, transitionRate); } +// unused void SkelAnime_SetModeStop(SkelAnime* skelAnime) { skelAnime->mode = 2; func_800A3B8C(skelAnime); } s32 func_800A4478(SkelAnime* skelAnime, f32 arg1, f32 updateRate) { - f32 updateSpeed; + f32 updateSpeed = skelAnime->animPlaybackSpeed * updateRate; + f32 nextFrame = skelAnime->animCurrentFrame - updateSpeed; f32 temp_f12; - f32 nextFrame; - updateSpeed = skelAnime->animPlaybackSpeed * updateRate; - nextFrame = skelAnime->animCurrentFrame - updateSpeed; if (nextFrame < 0.0f) { nextFrame += skelAnime->totalFrames; } else if (skelAnime->totalFrames <= nextFrame) { @@ -1288,8 +1258,8 @@ s32 func_800A4478(SkelAnime* skelAnime, f32 arg1, f32 updateRate) { arg1 = skelAnime->totalFrames; } - temp_f12 = (nextFrame + updateSpeed) - arg1; - if ((0.0f <= (temp_f12 * updateSpeed)) && (((temp_f12 - updateSpeed) * updateSpeed) < 0.0f)) { + temp_f12 = nextFrame + updateSpeed - arg1; + if ((temp_f12 * updateSpeed >= 0.0f) && (((temp_f12 - updateSpeed) * updateSpeed) < 0.0f)) { return 1; } return 0; @@ -1303,11 +1273,10 @@ s32 func_800A4530(SkelAnime* skelAnime, f32 arg1) { void SkelAnime_Init(GlobalContext* globalCtx, SkelAnime* skelAnime, SkeletonHeader* skeletonHeaderSeg, AnimationHeader* animationSeg, Vec3s* limbDrawTbl, Vec3s* transitionDrawTable, s32 limbCount) { - SkeletonHeader* skeletonHeader; + SkeletonHeader* skeletonHeader = SEGMENTED_TO_VIRTUAL(skeletonHeaderSeg); - skeletonHeader = SEGMENTED_TO_VIRTUAL(skeletonHeaderSeg); skelAnime->limbCount = skeletonHeader->limbCount + 1; - skelAnime->skeleton = SEGMENTED_TO_VIRTUAL(skeletonHeader->skeletonSeg); + skelAnime->skeleton = SEGMENTED_TO_VIRTUAL(skeletonHeader->segment); if (limbDrawTbl == NULL) { skelAnime->limbDrawTbl = ZeldaArena_MallocDebug(skelAnime->limbCount * sizeof(*skelAnime->limbDrawTbl), "../z_skelanime.c", 2968); @@ -1331,14 +1300,13 @@ void SkelAnime_Init(GlobalContext* globalCtx, SkelAnime* skelAnime, SkeletonHead } } -void SkelAnime_InitSV(GlobalContext* globalCtx, SkelAnime* skelAnime, SkeletonHeader* skeletonHeaderSeg, - AnimationHeader* animationSeg, Vec3s* limbDrawTbl, Vec3s* transitionDrawTable, s32 limbCount) { - SkeletonHeader* skeletonHeader; +void SkelAnime_InitFlex(GlobalContext* globalCtx, SkelAnime* skelAnime, FlexSkeletonHeader* skeletonHeaderSeg, + AnimationHeader* animationSeg, Vec3s* limbDrawTbl, Vec3s* transitionDrawTable, s32 limbCount) { + FlexSkeletonHeader* skeletonHeader = SEGMENTED_TO_VIRTUAL(skeletonHeaderSeg); - skeletonHeader = SEGMENTED_TO_VIRTUAL(skeletonHeaderSeg); - skelAnime->limbCount = skeletonHeader->limbCount + 1; + skelAnime->limbCount = skeletonHeader->sh.limbCount + 1; skelAnime->dListCount = skeletonHeader->dListCount; - skelAnime->skeleton = SEGMENTED_TO_VIRTUAL(skeletonHeader->skeletonSeg); + skelAnime->skeleton = SEGMENTED_TO_VIRTUAL(skeletonHeader->sh.segment); if (limbDrawTbl == NULL) { skelAnime->limbDrawTbl = @@ -1367,11 +1335,10 @@ void SkelAnime_InitSV(GlobalContext* globalCtx, SkelAnime* skelAnime, SkeletonHe void SkelAnime_InitSkin(GlobalContext* globalCtx, SkelAnime* skelAnime, SkeletonHeader* skeletonHeaderSeg, AnimationHeader* animationSeg) { - SkeletonHeader* skeletonHeader; + SkeletonHeader* skeletonHeader = SEGMENTED_TO_VIRTUAL(skeletonHeaderSeg); - skeletonHeader = SEGMENTED_TO_VIRTUAL(skeletonHeaderSeg); skelAnime->limbCount = skeletonHeader->limbCount + 1; - skelAnime->skeleton = SEGMENTED_TO_VIRTUAL(skeletonHeader->skeletonSeg); + skelAnime->skeleton = SEGMENTED_TO_VIRTUAL(skeletonHeader->segment); skelAnime->limbDrawTbl = ZeldaArena_MallocDebug(skelAnime->limbCount * sizeof(*skelAnime->limbDrawTbl), "../z_skelanime.c", 3120); skelAnime->transitionDrawTbl = @@ -1390,49 +1357,45 @@ void SkelAnime_InitSkin(GlobalContext* globalCtx, SkelAnime* skelAnime, Skeleton void func_800A49B0(SkelAnime* skelAnime) { if (skelAnime->mode < 2) { - skelAnime->animUpdate = &func_800A4D9C; + skelAnime->update = func_800A4D9C; } else if (skelAnime->mode < 4) { - skelAnime->animUpdate = &func_800A4EE0; + skelAnime->update = func_800A4EE0; } else { - skelAnime->animUpdate = &func_800A4E38; + skelAnime->update = func_800A4E38; } } s32 SkelAnime_FrameUpdateMatrix(SkelAnime* skelAnime) { - return skelAnime->animUpdate(skelAnime); + return skelAnime->update(skelAnime); } s32 func_800A4A20(SkelAnime* skelAnime) { - f32 prevUnk28; - f32 updateRate; + f32 transPrevFrame = skelAnime->transCurrentFrame; + f32 updateRate = R_UPDATE_RATE * (1.0f / 3.0f); - prevUnk28 = skelAnime->transCurrentFrame; - updateRate = R_UPDATE_RATE * (1.0f / 3.0f); skelAnime->transCurrentFrame -= skelAnime->transitionStep * updateRate; if (skelAnime->transCurrentFrame <= 0.0f) { func_800A49B0(skelAnime); skelAnime->transCurrentFrame = 0.0f; } SkelAnime_InterpolateVec3s(skelAnime->limbCount, skelAnime->limbDrawTbl, skelAnime->limbDrawTbl, - skelAnime->transitionDrawTbl, 1.0f - (skelAnime->transCurrentFrame / prevUnk28)); + skelAnime->transitionDrawTbl, 1.0f - (skelAnime->transCurrentFrame / transPrevFrame)); return 0; } s32 func_800A4AD8(SkelAnime* skelAnime) { - s16 temp_a2; + s16 temp_a2 = skelAnime->transCurrentFrame * 0x4000; s16 temp_a1; f32 sp28; f32 phi_f2; - f32 updateRate; + f32 updateRate = R_UPDATE_RATE * (1.0f / 3.0f); - temp_a2 = (s16)(skelAnime->transCurrentFrame * 16384.0f); - updateRate = R_UPDATE_RATE * (1.0f / 3.0f); skelAnime->transCurrentFrame -= skelAnime->transitionStep * updateRate; if (skelAnime->transCurrentFrame <= 0.0f) { func_800A49B0(skelAnime); skelAnime->transCurrentFrame = 0.0f; } - temp_a1 = (s16)(skelAnime->transCurrentFrame * 16384.0f); + temp_a1 = skelAnime->transCurrentFrame * 0x4000; if (skelAnime->unk_03 < 0) { sp28 = 1.0f - Math_Coss(temp_a2); phi_f2 = 1.0f - Math_Coss(temp_a1); @@ -1451,40 +1414,36 @@ s32 func_800A4AD8(SkelAnime* skelAnime) { } void func_800A4C58(SkelAnime* skelAnime) { - s32 t; - f32 updateRate; - char pad[4]; - Vec3s sp38[98]; - f32 temp_f10; - f32 temp_f2; - - SkelAnime_AnimateFrame(skelAnime->animCurrentSeg, skelAnime->animCurrentFrame, skelAnime->limbCount, + Vec3s sp38[100]; + + SkelAnime_AnimateFrame(skelAnime->animation, skelAnime->animCurrentFrame, skelAnime->limbCount, skelAnime->limbDrawTbl); - if (skelAnime->mode & 0x1) { - t = (s32)skelAnime->animCurrentFrame; - temp_f10 = t; - temp_f2 = skelAnime->animCurrentFrame - temp_f10; - t++; - if (t >= (s32)skelAnime->totalFrames) { + if (skelAnime->mode & 1) { + s32 t = skelAnime->animCurrentFrame; + f32 sp30 = skelAnime->animCurrentFrame - t; + + if (++t >= (s32)skelAnime->totalFrames) { t = 0; } - SkelAnime_AnimateFrame(skelAnime->animCurrentSeg, t, skelAnime->limbCount, sp38); - SkelAnime_InterpolateVec3s(skelAnime->limbCount, skelAnime->limbDrawTbl, skelAnime->limbDrawTbl, sp38, temp_f2); + SkelAnime_AnimateFrame(skelAnime->animation, t, skelAnime->limbCount, sp38); + SkelAnime_InterpolateVec3s(skelAnime->limbCount, skelAnime->limbDrawTbl, skelAnime->limbDrawTbl, sp38, sp30); } if (skelAnime->transCurrentFrame != 0) { - updateRate = R_UPDATE_RATE * (1.0f / 3.0f); + f32 updateRate = R_UPDATE_RATE * (1.0f / 3.0f); + skelAnime->transCurrentFrame -= skelAnime->transitionStep * updateRate; if (skelAnime->transCurrentFrame <= 0.0f) { skelAnime->transCurrentFrame = 0.0f; - return; + } else { + SkelAnime_InterpolateVec3s(skelAnime->limbCount, skelAnime->limbDrawTbl, skelAnime->limbDrawTbl, + skelAnime->transitionDrawTbl, skelAnime->transCurrentFrame); } - SkelAnime_InterpolateVec3s(skelAnime->limbCount, skelAnime->limbDrawTbl, skelAnime->limbDrawTbl, - skelAnime->transitionDrawTbl, skelAnime->transCurrentFrame); } } s32 func_800A4D9C(SkelAnime* skelAnime) { f32 updateRate = R_UPDATE_RATE * (1.0f / 3.0f); + skelAnime->animCurrentFrame += skelAnime->animPlaybackSpeed * updateRate; if (skelAnime->animCurrentFrame < 0.0f) { skelAnime->animCurrentFrame += skelAnime->totalFrames; @@ -1497,6 +1456,7 @@ s32 func_800A4D9C(SkelAnime* skelAnime) { s32 func_800A4E38(SkelAnime* skelAnime) { f32 updateRate = R_UPDATE_RATE * (1.0f / 3.0f); + skelAnime->animCurrentFrame += skelAnime->animPlaybackSpeed * updateRate; if (skelAnime->animCurrentFrame < skelAnime->initialFrame) { skelAnime->animCurrentFrame = @@ -1511,27 +1471,23 @@ s32 func_800A4E38(SkelAnime* skelAnime) { } s32 func_800A4EE0(SkelAnime* skelAnime) { - f32 updateRate; + f32 updateRate = R_UPDATE_RATE * (1.0f / 3.0f); - updateRate = R_UPDATE_RATE * (1.0f / 3.0f); if (skelAnime->animCurrentFrame == skelAnime->animFrameCount) { - - SkelAnime_AnimateFrame(skelAnime->animCurrentSeg, (s32)skelAnime->animCurrentFrame, skelAnime->limbCount, + SkelAnime_AnimateFrame(skelAnime->animation, (s32)skelAnime->animCurrentFrame, skelAnime->limbCount, skelAnime->limbDrawTbl); func_800A4C58(skelAnime); return 1; } + skelAnime->animCurrentFrame += skelAnime->animPlaybackSpeed * updateRate; - if (0.0f < ((skelAnime->animCurrentFrame - skelAnime->animFrameCount) * skelAnime->animPlaybackSpeed)) { + + if ((skelAnime->animCurrentFrame - skelAnime->animFrameCount) * skelAnime->animPlaybackSpeed > 0.0f) { skelAnime->animCurrentFrame = skelAnime->animFrameCount; - } else { - if (skelAnime->animCurrentFrame < 0.0f) { - skelAnime->animCurrentFrame += skelAnime->totalFrames; - } else { - if (skelAnime->totalFrames <= skelAnime->animCurrentFrame) { - skelAnime->animCurrentFrame -= skelAnime->totalFrames; - } - } + } else if (skelAnime->animCurrentFrame < 0.0f) { + skelAnime->animCurrentFrame += skelAnime->totalFrames; + } else if (skelAnime->totalFrames <= skelAnime->animCurrentFrame) { + skelAnime->animCurrentFrame -= skelAnime->totalFrames; } func_800A4C58(skelAnime); return 0; @@ -1541,17 +1497,17 @@ void SkelAnime_ChangeAnimImpl(SkelAnime* skelAnime, AnimationHeader* animationSe f32 frameCount, u8 animationType, f32 transitionRate, s8 unk2) { skelAnime->mode = animationType; if ((transitionRate != 0.0f) && - ((animationSeg != skelAnime->animCurrentSeg) || (frame != skelAnime->animCurrentFrame))) { + ((animationSeg != skelAnime->animation) || (frame != skelAnime->animCurrentFrame))) { if (transitionRate < 0) { func_800A49B0(skelAnime); SkelAnime_CopyVec3s(skelAnime, skelAnime->transitionDrawTbl, skelAnime->limbDrawTbl); transitionRate = -transitionRate; } else { if (unk2 != 0) { - skelAnime->animUpdate = &func_800A4AD8; + skelAnime->update = func_800A4AD8; skelAnime->unk_03 = unk2; } else { - skelAnime->animUpdate = &func_800A4A20; + skelAnime->update = func_800A4A20; } SkelAnime_AnimateFrame(animationSeg, frame, skelAnime->limbCount, skelAnime->transitionDrawTbl); } @@ -1563,15 +1519,15 @@ void SkelAnime_ChangeAnimImpl(SkelAnime* skelAnime, AnimationHeader* animationSe skelAnime->transCurrentFrame = 0.0f; } - skelAnime->animCurrentSeg = animationSeg; + skelAnime->animation = animationSeg; skelAnime->initialFrame = frame; skelAnime->animFrameCount = frameCount; - skelAnime->totalFrames = SkelAnime_GetTotalFrames(&animationSeg->genericHeader); + skelAnime->totalFrames = SkelAnime_GetTotalFrames(animationSeg); if (skelAnime->mode >= 4) { skelAnime->animCurrentFrame = 0.0f; } else { skelAnime->animCurrentFrame = frame; - if (skelAnime->mode < 2) { + if (skelAnime->mode <= 1) { skelAnime->animFrameCount = skelAnime->totalFrames - 1.0f; } } @@ -1584,23 +1540,19 @@ void SkelAnime_ChangeAnim(SkelAnime* skelAnime, AnimationHeader* animationSeg, f } void SkelAnime_ChangeAnimDefaultStop(SkelAnime* skelAnime, AnimationHeader* animationSeg) { - SkelAnime_ChangeAnim(skelAnime, animationSeg, 1.0f, 0.0f, SkelAnime_GetFrameCount(&animationSeg->genericHeader), 2, - 0.0f); + SkelAnime_ChangeAnim(skelAnime, animationSeg, 1.0f, 0.0f, SkelAnime_GetFrameCount(animationSeg), 2, 0.0f); } void SkelAnime_ChangeAnimTransitionStop(SkelAnime* skelAnime, AnimationHeader* animationSeg, f32 transitionRate) { - SkelAnime_ChangeAnim(skelAnime, animationSeg, 1.0f, 0, SkelAnime_GetFrameCount(&animationSeg->genericHeader), 2, - transitionRate); + SkelAnime_ChangeAnim(skelAnime, animationSeg, 1.0f, 0, SkelAnime_GetFrameCount(animationSeg), 2, transitionRate); } void SkelAnime_ChangeAnimPlaybackStop(SkelAnime* skelAnime, AnimationHeader* animationSeg, f32 playbackSpeed) { - SkelAnime_ChangeAnim(skelAnime, animationSeg, playbackSpeed, 0.0f, - SkelAnime_GetFrameCount(&animationSeg->genericHeader), 2, 0.0f); + SkelAnime_ChangeAnim(skelAnime, animationSeg, playbackSpeed, 0.0f, SkelAnime_GetFrameCount(animationSeg), 2, 0.0f); } void SkelAnime_ChangeAnimDefaultRepeat(SkelAnime* skelAnime, AnimationHeader* animationSeg) { - SkelAnime_ChangeAnim(skelAnime, animationSeg, 1.0f, 0.0f, SkelAnime_GetFrameCount(&animationSeg->genericHeader), 0, - 0.0f); + SkelAnime_ChangeAnim(skelAnime, animationSeg, 1.0f, 0.0f, SkelAnime_GetFrameCount(animationSeg), 0, 0.0f); } void SkelAnime_ChangeAnimTransitionRepeat(SkelAnime* skelAnime, AnimationHeader* animationSeg, f32 transitionRate) { @@ -1608,10 +1560,10 @@ void SkelAnime_ChangeAnimTransitionRepeat(SkelAnime* skelAnime, AnimationHeader* } void SkelAnime_ChangeAnimPlaybackRepeat(SkelAnime* skelAnime, AnimationHeader* animationSeg, f32 playbackSpeed) { - SkelAnime_ChangeAnim(skelAnime, animationSeg, playbackSpeed, 0.0f, - SkelAnime_GetFrameCount(&animationSeg->genericHeader), 0, 0.0f); + SkelAnime_ChangeAnim(skelAnime, animationSeg, playbackSpeed, 0.0f, SkelAnime_GetFrameCount(animationSeg), 0, 0.0f); } +// unused void SkelAnime_AnimSetStop(SkelAnime* skelAnime) { skelAnime->mode = 2; skelAnime->animFrameCount = skelAnime->totalFrames; @@ -1628,6 +1580,7 @@ void SkelAnime_AnimReverse(SkelAnime* skelAnime) { void func_800A5428(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src, u8* index) { s32 i; + for (i = 0; i < skelAnime->limbCount; i++, dst++, src++) { if (*index++) { *dst = *src; @@ -1635,8 +1588,10 @@ void func_800A5428(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src, u8* index) { } } +// unused void func_800A5490(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src, u8* arg3) { s32 i; + for (i = 0; i < skelAnime->limbCount; i++, dst++, src++) { if (*arg3++ < 1U) { *dst = *src; @@ -1654,12 +1609,11 @@ void func_800A54FC(SkelAnime* skelAnime, Vec3f* pos, s16 angle) { f32 cos; if (skelAnime->flags & 0x10) { - pos->z = 0.0f; - pos->x = 0.0f; + pos->x = pos->z = 0.0f; } else { // `angle` rotation around y axis. - x = skelAnime->limbDrawTbl->x; - z = skelAnime->limbDrawTbl->z; + x = skelAnime->limbDrawTbl[0].x; + z = skelAnime->limbDrawTbl[0].z; sin = Math_Sins(angle); cos = Math_Coss(angle); pos->x = x * cos + z * sin; @@ -1674,21 +1628,21 @@ void func_800A54FC(SkelAnime* skelAnime, Vec3f* pos, s16 angle) { } skelAnime->prevFrameRot = angle; - skelAnime->prevFramePos.x = skelAnime->limbDrawTbl->x; - skelAnime->limbDrawTbl->x = skelAnime->unk_3E.x; - skelAnime->prevFramePos.z = skelAnime->limbDrawTbl->z; - skelAnime->limbDrawTbl->z = skelAnime->unk_3E.z; + skelAnime->prevFramePos.x = skelAnime->limbDrawTbl[0].x; + skelAnime->limbDrawTbl[0].x = skelAnime->unk_3E.x; + skelAnime->prevFramePos.z = skelAnime->limbDrawTbl[0].z; + skelAnime->limbDrawTbl[0].z = skelAnime->unk_3E.z; if (skelAnime->flags & ANIM_FLAG_UPDATEXZ) { if (skelAnime->flags & ANIM_FLAG_UPDATEY) { pos->y = 0.0f; } else { - pos->y = skelAnime->limbDrawTbl->y - skelAnime->prevFramePos.y; + pos->y = skelAnime->limbDrawTbl[0].y - skelAnime->prevFramePos.y; } - skelAnime->prevFramePos.y = skelAnime->limbDrawTbl->y; - skelAnime->limbDrawTbl->y = skelAnime->unk_3E.y; + skelAnime->prevFramePos.y = skelAnime->limbDrawTbl[0].y; + skelAnime->limbDrawTbl[0].y = skelAnime->unk_3E.y; } else { pos->y = 0.0f; - skelAnime->prevFramePos.y = skelAnime->limbDrawTbl->y; + skelAnime->prevFramePos.y = skelAnime->limbDrawTbl[0].y; } skelAnime->flags &= ~ANIM_FLAG_UPDATEY; } @@ -1713,6 +1667,7 @@ void SkelAnime_Free(SkelAnime* skelAnime, GlobalContext* globalCtx) { void SkelAnime_CopyVec3s(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src) { s32 i; + for (i = 0; i < skelAnime->limbCount; i++) { *dst++ = *src++; } |
