From a868cf6a32deba8f18a4e4cfb44f8d5419f2e04f Mon Sep 17 00:00:00 2001 From: intns <84647527+intns@users.noreply.github.com> Date: Mon, 20 May 2024 19:31:38 +0100 Subject: [PATCH] Broke my promise and cleaned --- include/CNode.h | 14 ++++++++++++ include/JSystem/J3D/J3DAnmBase.h | 6 +++--- include/JSystem/J3D/J3DMtxCalc.h | 2 +- include/Sys/MatBaseAnimator.h | 17 ++++++++++----- include/SysShape/Animator.h | 2 +- include/SysShape/KeyEvent.h | 4 ++++ src/JSystem/J3DU/J3DUMtxCache.cpp | 2 +- src/sysGCU/sysMaterialAnim.cpp | 26 +++++++++++----------- src/sysGCU/sysShape.cpp | 36 ++++++++++++++++--------------- 9 files changed, 67 insertions(+), 42 deletions(-) diff --git a/include/CNode.h b/include/CNode.h index 66f13e3d3..d1fd7ce9d 100644 --- a/include/CNode.h +++ b/include/CNode.h @@ -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 diff --git a/include/JSystem/J3D/J3DAnmBase.h b/include/JSystem/J3D/J3DAnmBase.h index f354ead3f..0981b491e 100644 --- a/include/JSystem/J3D/J3DAnmBase.h +++ b/include/JSystem/J3D/J3DAnmBase.h @@ -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 }; diff --git a/include/JSystem/J3D/J3DMtxCalc.h b/include/JSystem/J3D/J3DMtxCalc.h index 114dbe14a..bbd7691bc 100644 --- a/include/JSystem/J3D/J3DMtxCalc.h +++ b/include/JSystem/J3D/J3DMtxCalc.h @@ -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 diff --git a/include/Sys/MatBaseAnimator.h b/include/Sys/MatBaseAnimator.h index 0c61f7ffe..b2a2c68cb 100644 --- a/include/Sys/MatBaseAnimator.h +++ b/include/Sys/MatBaseAnimator.h @@ -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 diff --git a/include/SysShape/Animator.h b/include/SysShape/Animator.h index 4108011b0..89afb2f63 100644 --- a/include/SysShape/Animator.h +++ b/include/SysShape/Animator.h @@ -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); diff --git a/include/SysShape/KeyEvent.h b/include/SysShape/KeyEvent.h index 8010646d3..feb8353bf 100644 --- a/include/SysShape/KeyEvent.h +++ b/include/SysShape/KeyEvent.h @@ -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 diff --git a/src/JSystem/J3DU/J3DUMtxCache.cpp b/src/JSystem/J3DU/J3DUMtxCache.cpp index 7c1d1635a..ccea8147b 100644 --- a/src/JSystem/J3DU/J3DUMtxCache.cpp +++ b/src/JSystem/J3DU/J3DUMtxCache.cpp @@ -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; diff --git a/src/sysGCU/sysMaterialAnim.cpp b/src/sysGCU/sysMaterialAnim.cpp index 2ac8443f5..49f1ca36e 100644 --- a/src/sysGCU/sysMaterialAnim.cpp +++ b/src/sysGCU/sysMaterialAnim.cpp @@ -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; } } } diff --git a/src/sysGCU/sysShape.cpp b/src/sysGCU/sysShape.cpp index fe34b9aaf..34deebad0 100644 --- a/src/sysGCU/sysShape.cpp +++ b/src/sysGCU/sysShape.cpp @@ -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,15 +99,16 @@ 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 { - KeyEvent* evt = mAnimInfo->getAnimKeyByType(id); - if (evt) { - setCurrFrame(evt->mFrame); - } + setCurrFrame(mAnimInfo->mAnm->getTotalFrameCount() - 1.0f); + return; + } + + KeyEvent* evt = mAnimInfo->getAnimKeyByType(id); + if (evt) { + setCurrFrame(evt->mFrame); } } @@ -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);