2022-04-20 04:06:18 +00:00
|
|
|
#include "dynos.cpp.h"
|
|
|
|
extern "C" {
|
|
|
|
#include "object_fields.h"
|
|
|
|
#include "game/level_update.h"
|
|
|
|
#include "game/object_list_processor.h"
|
|
|
|
#include "pc/configfile.h"
|
2023-04-29 04:00:17 +00:00
|
|
|
#include "pc/lua/utils/smlua_anim_utils.h"
|
2022-04-20 04:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Update animations
|
|
|
|
//
|
|
|
|
|
|
|
|
// Retrieve the current Mario's animation index
|
|
|
|
static s32 RetrieveCurrentMarioAnimationIndex(u32 aPlayerIndex) {
|
2024-05-21 11:17:30 +00:00
|
|
|
static struct MarioAnimDmaRelatedThing *_MarioAnims = (struct MarioAnimDmaRelatedThing *) gMarioAnims;
|
|
|
|
for (s32 i = 0; i != (s32) _MarioAnims->count; ++i) {
|
|
|
|
void *_AnimAddr = gMarioAnims + _MarioAnims->anim[i].offset;
|
2022-04-20 04:06:18 +00:00
|
|
|
if (_AnimAddr == gMarioStates[aPlayerIndex].animation->currentAnimAddr) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the current animation index
|
|
|
|
// As we don't know the length of the table, let's hope that we'll always find the animation...
|
|
|
|
static s32 RetrieveCurrentAnimationIndex(struct Object *aObject) {
|
2023-04-29 04:00:17 +00:00
|
|
|
if (!aObject->oAnimations || !aObject->header.gfx.animInfo.curAnim || smlua_anim_util_get_current_animation_name(aObject)) {
|
2022-04-20 04:06:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2023-05-10 22:20:52 +00:00
|
|
|
struct AnimationTable* animations = aObject->oAnimations;
|
|
|
|
for (s32 i = 0; i < animations->count; ++i) {
|
|
|
|
if (animations->anims[i] == aObject->header.gfx.animInfo.curAnim) {
|
2022-04-20 04:06:18 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must be called twice, before and after geo_set_animation_globals
|
|
|
|
void DynOS_Anim_Swap(void *aPtr) {
|
2023-11-08 22:15:35 +00:00
|
|
|
if (!aPtr) { return; }
|
|
|
|
|
2022-04-20 04:06:18 +00:00
|
|
|
static Animation *pDefaultAnimation = NULL;
|
|
|
|
static Animation sGfxDataAnimation;
|
|
|
|
|
2023-10-27 23:42:27 +00:00
|
|
|
// Does the object have a model?
|
2022-04-20 04:06:18 +00:00
|
|
|
struct Object *_Object = (struct Object *) aPtr;
|
2024-05-09 11:36:32 +00:00
|
|
|
if (!_Object->header.gfx.sharedChild || !_Object->header.gfx.animInfo.curAnim) {
|
2022-04-20 04:06:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Swap the current animation with the one from the Gfx data
|
|
|
|
if (!pDefaultAnimation) {
|
|
|
|
pDefaultAnimation = _Object->header.gfx.animInfo.curAnim;
|
|
|
|
|
|
|
|
// ActorGfx data
|
2022-05-14 21:28:25 +00:00
|
|
|
ActorGfx* _ActorGfx = DynOS_Actor_GetActorGfx(_Object->header.gfx.sharedChild);
|
2022-04-20 04:06:18 +00:00
|
|
|
if (!_ActorGfx) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// GfxData
|
|
|
|
GfxData* _GfxData = _ActorGfx->mGfxData;
|
|
|
|
if (!_GfxData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Animation table
|
|
|
|
if (_GfxData->mAnimationTable.Empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Animation index
|
|
|
|
s32 _AnimIndex = -1;
|
|
|
|
for (u32 i = 0; i < MAX_PLAYERS; i++) {
|
|
|
|
if (gMarioStates[i].marioObj == NULL) { continue; }
|
|
|
|
if (_Object == gMarioStates[i].marioObj) {
|
|
|
|
_AnimIndex = RetrieveCurrentMarioAnimationIndex(i);
|
2024-05-09 11:36:32 +00:00
|
|
|
break;
|
2022-04-20 04:06:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_AnimIndex == -1) {
|
|
|
|
_AnimIndex = RetrieveCurrentAnimationIndex(_Object);
|
|
|
|
}
|
|
|
|
if (_AnimIndex == -1) {
|
|
|
|
return;
|
|
|
|
}
|
2023-05-15 22:55:16 +00:00
|
|
|
if (_AnimIndex >= _GfxData->mAnimationTable.Count()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-04-20 04:06:18 +00:00
|
|
|
|
|
|
|
// Animation data
|
|
|
|
const AnimData *_AnimData = (const AnimData *) _GfxData->mAnimationTable[_AnimIndex].second;
|
|
|
|
if (_AnimData) {
|
|
|
|
sGfxDataAnimation.flags = _AnimData->mFlags;
|
|
|
|
sGfxDataAnimation.animYTransDivisor = _AnimData->mUnk02;
|
|
|
|
sGfxDataAnimation.startFrame = _AnimData->mUnk04;
|
|
|
|
sGfxDataAnimation.loopStart = _AnimData->mUnk06;
|
|
|
|
sGfxDataAnimation.loopEnd = _AnimData->mUnk08;
|
|
|
|
sGfxDataAnimation.unusedBoneCount = _AnimData->mUnk0A.second;
|
2024-03-23 20:11:30 +00:00
|
|
|
sGfxDataAnimation.values = (u16*)_AnimData->mValues.second.begin();
|
|
|
|
sGfxDataAnimation.index = (u16*)_AnimData->mIndex.second.begin();
|
2023-05-18 19:42:18 +00:00
|
|
|
sGfxDataAnimation.valuesLength = _AnimData->mValues.second.Count();
|
|
|
|
sGfxDataAnimation.indexLength = _AnimData->mIndex.second.Count();
|
2022-04-20 04:06:18 +00:00
|
|
|
sGfxDataAnimation.length = _AnimData->mLength;
|
|
|
|
_Object->header.gfx.animInfo.curAnim = &sGfxDataAnimation;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore the default animation
|
|
|
|
} else {
|
|
|
|
_Object->header.gfx.animInfo.curAnim = pDefaultAnimation;
|
|
|
|
pDefaultAnimation = NULL;
|
|
|
|
}
|
|
|
|
}
|