Broke my promise and cleaned

This commit is contained in:
intns 2024-05-20 19:31:38 +01:00
parent d005c004cd
commit a868cf6a32
9 changed files with 67 additions and 42 deletions

View File

@ -51,6 +51,20 @@ struct CNode {
setName(name);
}
inline CNode* getParent() const { return mParent; }
inline CNode* getChild() const { return mChild; }
inline CNode* getNext() const { return mNext; }
inline CNode* getPrev() const { return mPrev; }
inline const char* getName() const { return mName; }
inline bool isChild() const { return mParent != nullptr; }
inline bool isRoot() const { return mParent == nullptr; }
inline void setParent(CNode* parent) { mParent = parent; }
inline void setChild(CNode* child) { mChild = child; }
inline void setNext(CNode* next) { mNext = next; }
inline void setPrev(CNode* prev) { mPrev = prev; }
// _00 vtbl
CNode* mNext; // _04
CNode* mPrev; // _08

View File

@ -41,7 +41,7 @@ enum J3DAnmAttr { J3DAA_UNKNOWN_0 = 0, J3DAA_UNKNOWN_1 = 1, J3DAA_UNKNOWN_2 = 2,
struct J3DAnmBase {
inline J3DAnmBase()
: mAttribute(0)
, _05(0)
, mUnused(0)
, mTotalFrameCount(0)
, mCurrentFrame(0.0f)
{
@ -51,13 +51,13 @@ struct J3DAnmBase {
virtual J3DAnmKind getKind() const = 0; // _0C
u8 getAttribute() const { return mAttribute; }
s16 getFrameMax() const { return mTotalFrameCount; }
s16 getTotalFrameCount() const { return mTotalFrameCount; }
f32 getFrame() const { return mCurrentFrame; }
void setFrame(f32 frame) { mCurrentFrame = frame; }
// _00 = VTBL
u8 mAttribute; // _04
u8 _05; // _05
u8 mUnused; // _05
s16 mTotalFrameCount; // _06
f32 mCurrentFrame; // _08
};

View File

@ -17,7 +17,7 @@ struct J3DMtxCalc {
virtual J3DAnmTransform* getAnmTransform() { return nullptr; } // _10
virtual void setAnmTransform(u8, J3DAnmTransform*) { } // _14
virtual J3DAnmTransform* getAnmTransform(u8) { return nullptr; } // _18
virtual void setWeight(u8, f32) { } // _1C
virtual void setWeight(u8 index, f32 weight) { } // _1C
virtual f32 getWeight(u8) const { return 0.0f; } // _20
virtual void init(const Vec&, const Mtx&) = 0; // _24
virtual void calc() = 0; // _28

View File

@ -10,6 +10,13 @@ namespace Sys {
* @size{0xC}
*/
struct MatBaseAnimator {
enum State {
Playing = 0,
AtStart = 1,
AtEnd = 2,
NoAnimation = 0x8000,
};
MatBaseAnimator();
virtual void start(MatBaseAnimation* animation); // _08
@ -29,16 +36,16 @@ struct MatBaseAnimator {
{
int state;
if (!mAnimation) {
state = 0x8000;
state = NoAnimation;
} else {
state = 0;
state = Playing;
mCurrFrame -= rate;
if (mCurrFrame < 0.0f) {
mCurrFrame = 0.0f;
state = 1;
state = AtStart;
} else if (mCurrFrame >= mAnimation->getFrameMax()) {
mCurrFrame = mAnimation->getFrameMax();
state = 2;
state = AtEnd;
}
mAnimation->getAnmBase()->setFrame(mCurrFrame);
}
@ -66,7 +73,7 @@ struct MatRepeatAnimator : public MatBaseAnimator {
virtual void onStart(); // _0C
virtual void do_animate(f32); // _10
u8 _0C; // _0C
u8 mStarted; // _0C
};
} // namespace Sys

View File

@ -39,7 +39,7 @@ struct Animator : public BaseAnimator {
{
return (mAnimInfo != nullptr) ? mAnimInfo->mCalc : nullptr;
}
virtual void animate(f32); // _0C
virtual void animate(f32 speed); // _0C
void startAnim(int animID, MotionListener* listener);
void startExAnim(AnimInfo* info);

View File

@ -36,6 +36,10 @@ struct KeyEvent : public CNode {
virtual ~KeyEvent() { } // _08 (weak)
inline int getFrame() const { return mFrame; }
inline int getType() const { return mType; }
inline s16 getAnimIdx() const { return mAnimIdx; }
inline bool isEnd() const { return mType == KEYEVENT_END; }
int mFrame; // _18
u32 mType; // _1C

View File

@ -55,7 +55,7 @@ J3DUMtxAnmCacheTableBase::~J3DUMtxAnmCacheTableBase()
J3DUMtxAnmCacheTable::J3DUMtxAnmCacheTable(J3DModel* model, J3DAnmTransform* transform)
{
int jointCount = model->mModelData->getJointNum();
int frameCount = transform->getFrameMax();
int frameCount = transform->getTotalFrameCount();
mAnimationFrame = 0;
mJointCount = jointCount;

View File

@ -35,7 +35,7 @@ void MatBaseAnimation::attachResource(void* resource, J3DModelData* modelData)
f32 MatBaseAnimation::getFrameMax()
{
P2ASSERTLINE(57, getAnmBase());
return getAnmBase()->getFrameMax();
return getAnmBase()->getTotalFrameCount();
}
/**
@ -151,16 +151,16 @@ int MatBaseAnimator::forward(f32 rate)
{
int state;
if (!mAnimation) {
state = 0x8000;
state = NoAnimation;
} else {
state = 0;
state = Playing;
mCurrFrame += rate;
if (mCurrFrame < 0.0f) {
mCurrFrame = 0.0f;
state = 1;
state = AtStart;
} else if (mCurrFrame >= mAnimation->getFrameMax()) {
mCurrFrame = mAnimation->getFrameMax();
state = 2;
state = AtEnd;
}
mAnimation->getAnmBase()->setFrame(mCurrFrame);
}
@ -210,7 +210,7 @@ void MatLoopAnimator::do_animate(f32 rate)
{
u32 state = forward(rate);
if (state == 2) {
if (state == MatBaseAnimator::AtEnd) {
mCurrFrame = 0.0f;
}
}
@ -219,7 +219,7 @@ void MatLoopAnimator::do_animate(f32 rate)
* @note Address: 0x80434778
* @note Size: 0xC
*/
void MatRepeatAnimator::onStart() { _0C = 1; }
void MatRepeatAnimator::onStart() { mStarted = true; }
/**
* @note Address: 0x80434784
@ -227,17 +227,15 @@ void MatRepeatAnimator::onStart() { _0C = 1; }
*/
void MatRepeatAnimator::do_animate(f32 rate)
{
if (_0C) {
if (mStarted) {
u32 state = forward(rate);
if (state == 2) {
_0C = false;
if (state == MatBaseAnimator::AtEnd) {
mStarted = false;
}
} else {
u32 state = backward(rate);
if (state == 1) {
_0C = true;
if (state == MatBaseAnimator::AtStart) {
mStarted = true;
}
}
}

View File

@ -49,6 +49,7 @@ void Animator::startAnim(int animID, MotionListener* listener)
mAnimMgr->dump();
JUT_PANICLINE(220, "go to hell !\n");
}
mTimer = 0.0f;
mCurAnimKey = mAnimInfo->getLowestAnimKey(0.0f);
if (listener != nullptr) {
@ -98,17 +99,18 @@ void Animator::setCurrFrame(f32 timer)
*/
void Animator::setFrameByKeyType(u32 id)
{
JUT_ASSERTLINE(300, !(mFlags & Unk80), "ExMotionErr::setFrameByKeyType(%d)\n", id);
JUT_ASSERTLINE(300, !isFlag(Unk80), "ExMotionErr::setFrameByKeyType(%d)\n", id);
if (id == KEYEVENT_END) {
setCurrFrame(mAnimInfo->mAnm->mTotalFrameCount - 1.0f);
} else {
setCurrFrame(mAnimInfo->mAnm->getTotalFrameCount() - 1.0f);
return;
}
KeyEvent* evt = mAnimInfo->getAnimKeyByType(id);
if (evt) {
setCurrFrame(evt->mFrame);
}
}
}
/**
* @note Address: 0x80428F00
@ -117,7 +119,7 @@ void Animator::setFrameByKeyType(u32 id)
void Animator::setLastFrame()
{
if (mAnimInfo) {
setCurrFrame(mAnimInfo->mAnm->mTotalFrameCount - 1.0f);
setCurrFrame(mAnimInfo->mAnm->getTotalFrameCount() - 1.0f);
}
}
@ -125,16 +127,16 @@ void Animator::setLastFrame()
* @note Address: 0x80428F78
* @note Size: 0x2AC
*/
void Animator::animate(f32 deltaTime)
void Animator::animate(f32 speed)
{
if (!mAnimInfo) {
return;
}
mTimer += deltaTime;
mTimer += speed;
bool found = false;
while (!found && mCurAnimKey && mCurAnimKey->mFrame < (int)mTimer) {
bool loopEndFound = false;
while (!loopEndFound && mCurAnimKey && mCurAnimKey->getFrame() < (int)mTimer) {
onKeyEventTrigger(mCurAnimKey);
SysShape::KeyEvent* currentEv = mCurAnimKey;
@ -147,13 +149,13 @@ void Animator::animate(f32 deltaTime)
if (!isFlag(AnimFinishMotion)) {
KeyEvent* start = mAnimInfo->getLastLoopStart(currentEv);
if (start) {
mTimer = start->mFrame;
mTimer = start->getFrame();
} else {
mTimer = 0.0f;
JUT_PANICLINE(369, "mismatch LOOP_START - LOOP_END\n");
}
found = true;
loopEndFound = true;
break;
}
}
@ -161,17 +163,17 @@ void Animator::animate(f32 deltaTime)
mCurAnimKey = (KeyEvent*)mCurAnimKey->mNext;
}
if (found) {
if (loopEndFound) {
mCurAnimKey = mAnimInfo->getLowestAnimKey(mTimer);
}
int time = mAnimInfo->mAnm->getFrameMax();
s32 time = mAnimInfo->mAnm->getTotalFrameCount();
if (mTimer >= time) {
mTimer = time - 1.0f;
if (mListener && !isFlag(AnimCompleted)) {
KeyEvent event;
event.mFrame = (f32)mAnimInfo->mAnm->getFrameMax();
event.mFrame = (f32)mAnimInfo->mAnm->getTotalFrameCount();
event.mType = KEYEVENT_END;
event.mAnimIdx = mAnimInfo->mId;
setFlag(AnimCompleted);