1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-04 16:55:56 +00:00
oot/src/code/z_fcurve_data_skelanime.c

179 lines
6.7 KiB
C
Raw Normal View History

#include "global.h"
2020-03-17 04:31:30 +00:00
void SkelCurve_Clear(SkelAnimeCurve* skelCurve) {
skelCurve->limbCount = 0;
skelCurve->limbList = NULL;
skelCurve->transUpdIdx = NULL;
skelCurve->animCurFrame = 0.0f;
skelCurve->animSpeed = 0.0f;
skelCurve->animFinalFrame = 0.0f;
skelCurve->transforms = NULL;
skelCurve->unk_0C = 0.0f;
}
2020-03-17 04:31:30 +00:00
s32 SkelCurve_Init(GlobalContext* globalCtx, SkelAnimeCurve* skelCurve, SkelCurveLimbList* limbListSeg,
ovl_demo_effect 100% OK (#466) * Fully decompiles demo_effect actor. * Formats z_demo_effect.c * GET_ACTOR_TYPE is renamed to GET_EFFECT_TYPE * Implements OPEN_DISPS macros for all draw functions. * Fixes ugly float values * Removes unnecessary union structs in the DemoEffect actor struct * Renames DemoEffect SkelAnimeCurve member to skelCurve * Names initObjectBankIndex DemoEffect struct member * Renames jewel display list holders * Renames initialization function pointers to initUpdateFunc and initDrawFunc * Renames primitive and environment color DemoEffect struct members. * Fixes a couple missed floats. * Renames most draw and update functions. * Finishes naming all update functions. * Adds additional SFX defines. * Renames the rest of the functions * Renames all external object display lists and vertex references * Renames DemoEffect global data variables * Renames DemoEffect Medal function to GetItem because it's used by LightArrows too * Fixes DemoEffect Timewarp_Timeblock documentation. * DemoEffect_TimewarpTimeblock updates shrink functions to use decimal * Converts DemoEffect hex to decimal where appopriate * Names the rest of DemoEffect struct members. * Names DemoEffect triforceSpot crystalLightOpacity * Adds DemoEffect enums for light effect color and god lgt types. * Renames DemoEffect_UpdateBlueOrb to DemoEffect_UpdateBlueOrbGrow * Fixes compiler warning in DemoEffect_JewelSparkle * Renames DemoEffect_MedalSparkle argument * Reformatting DemoEffect struct offset comments. * Formats z_demo_effect * Updates DemoEffect oGfxCtx to use the new macros. * Adds comments detailing what each function in the DemoEffect system does. * Removes z_demo_effect.data.s * Renames DemoEffect global variables and sets them to static * Removes pointer from DemoEffect function references * Removes unncecessary default: break; statements in DemoEffect * Converts rotation values to hex in DemoEffect * DemoEffect effectFlags now uses ~1 rather than 65534 * DemoEffect_DrawGodLgt now uses a cleaner conditional statement * eventChkInf in DemoEffect now uses 1 << 9 and 1 << 11 * DemoEffect now uses VT macros. * Converts DemoEffect colors to hex. * Changes M_PI / 32768.0f to M_PI / 0x8000 * Updates demo_effect enums to be all caps * ovl_demo_effect reloc info is now included via build process rather than included from original asm * Adds param packing macro * DemoEffect struct unions are now typedef'd outside of the main struct * Reformats DemoEffect sJewelSparkleColors * Removes an if(globalCtx){} in DemoEffect_Init * Removes ActorFunc cast in DemoEffect_Wait * Removes unncessary comment in DemoEffect_MedalSparkle * Timer check in DemoEffect_UpdateLightRingShrinking now uses <= 255 rather than < 256 * Removes unnecessary comment in DemoEffect_SetJewelColor * Removes unncessary comment in DemoEffect_MoveJewelActivateDoorOfTime * Converts an angle to hex in DemoEffect_MoveJewelActivateDoorOfTime * Converts a while to for loop in DemoEffect_JewelSparkle * Moves stack variables in DemoEffect_UpdateDust to a new line for each one * Removes globalCtx2 assignment to the beginning of the function in DemoEffect_DrawJewel * Removes unnecessary comment in DemoEffect_DrawCrystalLight * No longer wrapping rotation reset in if(1){} in DemoEffect_DrawGodLgt * Converts DemoEffect if statements to use != 0 and == 0 when non-boolean ints are checked. * DemoEffect initDrawFunc now uses type ActorFunc rather than DemoEffectFunc * review 2 Co-authored-by: fig <fig02srl@gmail.com>
2020-12-07 17:48:29 +00:00
TransformUpdateIndex* transUpdIdx) {
SkelCurveLimb** limbs;
SkelCurveLimbList* limbList = SEGMENTED_TO_VIRTUAL(limbListSeg);
2020-03-17 04:31:30 +00:00
skelCurve->limbCount = limbList->limbCount;
skelCurve->limbList = SEGMENTED_TO_VIRTUAL(limbList->limbs);
2020-03-17 04:31:30 +00:00
skelCurve->transforms = ZeldaArena_MallocDebug(sizeof(*skelCurve->transforms) * skelCurve->limbCount,
"../z_fcurve_data_skelanime.c", 125);
ASSERT(skelCurve->transforms != NULL, "this->now_joint != NULL", "../z_fcurve_data_skelanime.c", 127);
skelCurve->animCurFrame = 0.0f;
return 1;
}
2020-03-17 04:31:30 +00:00
void SkelCurve_Destroy(GlobalContext* globalCtx, SkelAnimeCurve* skelCurve) {
if (skelCurve->transforms != NULL) {
ZeldaArena_FreeDebug(skelCurve->transforms, "../z_fcurve_data_skelanime.c", 146);
}
}
2020-03-17 04:31:30 +00:00
void SkelCurve_SetAnim(SkelAnimeCurve* skelCurve, TransformUpdateIndex* transUpdIdx, f32 arg2, f32 animFinalFrame,
f32 animCurFrame, f32 animSpeed) {
skelCurve->unk_0C = arg2 - skelCurve->animSpeed;
skelCurve->animFinalFrame = animFinalFrame;
skelCurve->animCurFrame = animCurFrame;
skelCurve->animSpeed = animSpeed;
skelCurve->transUpdIdx = transUpdIdx;
}
2020-03-17 04:31:30 +00:00
s32 SkelCurve_Update(GlobalContext* globalCtx, SkelAnimeCurve* skelCurve) {
s16* transforms;
u8* transformRefIdx;
TransformUpdateIndex* transformIndex;
u16* transformCopyValues;
s32 i;
s32 ret = 0;
s32 k;
TransformData* transData;
f32 transformValue;
s32 j;
transformIndex = SEGMENTED_TO_VIRTUAL(skelCurve->transUpdIdx);
transformRefIdx = SEGMENTED_TO_VIRTUAL(transformIndex->refIndex);
transData = SEGMENTED_TO_VIRTUAL(transformIndex->transformData);
transformCopyValues = SEGMENTED_TO_VIRTUAL(transformIndex->copyValues);
transforms = (s16*)skelCurve->transforms;
skelCurve->animCurFrame += skelCurve->animSpeed * R_UPDATE_RATE * 0.5f;
if ((skelCurve->animSpeed >= 0.0f && skelCurve->animCurFrame > skelCurve->animFinalFrame) ||
(skelCurve->animSpeed < 0.0f && skelCurve->animCurFrame < skelCurve->animFinalFrame)) {
skelCurve->animCurFrame = skelCurve->animFinalFrame;
ret = 1;
}
for (i = 0; i < skelCurve->limbCount; i++) {
for (j = 0; j < 3; j++) {
for (k = 0; k < 3; k++, transformRefIdx++, transforms++) {
if (*transformRefIdx == 0) {
transformValue = *transformCopyValues;
*transforms = transformValue;
transformCopyValues++;
} else {
transformValue = func_8006C5A8(skelCurve->animCurFrame, transData, *transformRefIdx);
transData += *transformRefIdx;
if (j == 0) {
*transforms = transformValue * 1024.0f;
} else if (j == 1) {
*transforms = transformValue * (32768.0f / 180.0f);
} else {
*transforms = transformValue * 100.0f;
}
}
}
}
}
return ret;
}
void SkelCurve_DrawLimb(GlobalContext* globalCtx, s32 limbIndex, SkelAnimeCurve* skelCurve,
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);
Matrix_Push();
if (overrideLimbDraw == NULL ||
(overrideLimbDraw != NULL && overrideLimbDraw(globalCtx, skelCurve, limbIndex, data))) {
Vec3f scale;
Vec3s rot;
Vec3f pos;
Gfx* dList;
Vec3s* transform = (Vec3s*)&skelCurve->transforms[limbIndex];
scale.x = transform->x / 1024.0f;
scale.y = transform->y / 1024.0f;
scale.z = transform->z / 1024.0f;
transform++;
rot.x = transform->x;
rot.y = transform->y;
rot.z = transform->z;
transform++;
pos.x = transform->x;
pos.y = transform->y;
pos.z = transform->z;
Matrix_JointPosition(&pos, &rot);
Matrix_Scale(scale.x, scale.y, scale.z, MTXMODE_APPLY);
if (lod == 0) {
s32 pad1;
dList = limb->dList[0];
if (dList != NULL) {
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_fcurve_data_skelanime.c", 321),
G_MTX_LOAD | G_MTX_NOPUSH | G_MTX_MODELVIEW);
gSPDisplayList(POLY_OPA_DISP++, dList);
}
} else if (lod == 1) {
s32 pad2;
dList = limb->dList[0];
if (dList != NULL) {
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_fcurve_data_skelanime.c", 332),
G_MTX_LOAD | G_MTX_NOPUSH | G_MTX_MODELVIEW);
gSPDisplayList(POLY_OPA_DISP++, dList);
}
dList = limb->dList[1];
if (dList != NULL) {
gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_fcurve_data_skelanime.c", 338),
G_MTX_LOAD | G_MTX_NOPUSH | G_MTX_MODELVIEW);
gSPDisplayList(POLY_XLU_DISP++, dList);
}
} else {
// "FcSkeletonInfo_draw_child (): Not supported"
osSyncPrintf("FcSkeletonInfo_draw_child():未対応\n");
}
}
if (postLimbDraw != NULL) {
postLimbDraw(globalCtx, skelCurve, limbIndex, data);
}
if (limb->firstChildIdx != LIMB_DONE) {
SkelCurve_DrawLimb(globalCtx, limb->firstChildIdx, skelCurve, overrideLimbDraw, postLimbDraw, lod, data);
}
Matrix_Pop();
if (limb->nextLimbIdx != LIMB_DONE) {
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, void* data) {
if (skelCurve->transforms != NULL) {
SkelCurve_DrawLimb(globalCtx, 0, skelCurve, overrideLimbDraw, postLimbDraw, lod, data);
}
}