diff --git a/include/Game/DynParticle.h b/include/Game/DynParticle.h index 7e5fbf153..3ae3bf366 100644 --- a/include/Game/DynParticle.h +++ b/include/Game/DynParticle.h @@ -13,10 +13,10 @@ namespace Game { struct DynParticle { DynParticle() { - mRadius = 1.0f; - mIsTouching = false; - mNext = nullptr; - _20 = Vector3f(0.0f); + mRadius = 1.0f; + mIsTouching = false; + mNext = nullptr; + mCollisionNormal = Vector3f(0.0f); } DynParticle* getAt(int); @@ -26,12 +26,12 @@ struct DynParticle { void updateGlobal(Matrixf&); // _30 = VTBL - Vector3f mRotation; // _00 - Vector3f mPosition; // _0C - f32 mRadius; // _18 - DynParticle* mNext; // _1C - Vector3f _20; // _20 - u8 mIsTouching; // _2C + Vector3f mRotation; // _00 + Vector3f mPosition; // _0C + f32 mRadius; // _18 + DynParticle* mNext; // _1C + Vector3f mCollisionNormal; // _20 + u8 mIsTouching; // _2C // NB: vtable has to go after the member declarations virtual void constructor() { } // _08 (weak) diff --git a/include/Game/EnemyAnimatorBase.h b/include/Game/EnemyAnimatorBase.h index e2fffa91a..425f576b2 100644 --- a/include/Game/EnemyAnimatorBase.h +++ b/include/Game/EnemyAnimatorBase.h @@ -4,10 +4,6 @@ #include "SysShape/Animator.h" #include "BitFlag.h" -#define EANIM_FLAG_STOPPED (1 << 0) // 1 -#define EANIM_FLAG_FINISHED (1 << 1) // 2 -#define EANIM_FLAG_PLAYING (1 << 2) // 4 - namespace Game { struct EnemyAnimatorBase { EnemyAnimatorBase(); diff --git a/include/Game/EnemyBase.h b/include/Game/EnemyBase.h index 0401fe9f1..b5f05aa8d 100644 --- a/include/Game/EnemyBase.h +++ b/include/Game/EnemyBase.h @@ -105,8 +105,7 @@ enum DropGroup { }; // Interface for specific overrides (e.g. PelplantInitialParams) -struct EnemyInitialParamBase { -}; +struct EnemyInitialParamBase { }; struct EnemyKillArg : public CreatureKillArg { inline EnemyKillArg(int flag) @@ -280,7 +279,7 @@ struct EnemyBase : public Creature, public SysShape::MotionListener, virtual pub SysShape::MotionListener* listener = this; EnemyAnimatorBase* animator = mAnimator; - animator->mFlags.unset(EANIM_FLAG_STOPPED | EANIM_FLAG_FINISHED); + animator->mFlags.unset(SysShape::Animator::Stopped | SysShape::Animator::Finished); animator->mNormalizedTime = 1.0f; animator->getAnimator(0).startAnim(0, listener); diff --git a/include/SysShape/Animator.h b/include/SysShape/Animator.h index adef2c2f1..432cb260f 100644 --- a/include/SysShape/Animator.h +++ b/include/SysShape/Animator.h @@ -18,6 +18,12 @@ struct BaseAnimator { * @size{0x1C} */ struct Animator : public BaseAnimator { + enum Flags { + Stopped = 1, + Finished = 2, + Playing = 4, + }; + Animator() { mFlags = 0; @@ -40,6 +46,10 @@ struct Animator : public BaseAnimator { void setFrameByKeyType(u32); void setLastFrame(); + inline void setFlag(u8 flag) { mFlags |= flag; } + inline void resetFlag(u8 flag) { mFlags &= ~flag; } + inline bool isFlag(u8 flag) const { return mFlags & flag; } + inline int getAnimIndex() { if (mAnimInfo) { diff --git a/src/plugProjectKandoU/aiBore.cpp b/src/plugProjectKandoU/aiBore.cpp index 24b2f4c96..b79873970 100644 --- a/src/plugProjectKandoU/aiBore.cpp +++ b/src/plugProjectKandoU/aiBore.cpp @@ -217,7 +217,7 @@ int ActRest::exec() return ACTEXEC_Success; } - if (mParent->mAnimator.mSelfAnimator.mFlags & 1) { + if (mParent->mAnimator.mSelfAnimator.isFlag(SysShape::Animator::Stopped)) { resetFlag(RESTFLAG_IsIdle); if (mState == REST_Sleep) { mState = REST_Sit; diff --git a/src/plugProjectKandoU/aiFormation.cpp b/src/plugProjectKandoU/aiFormation.cpp index 007080ec9..ad8911623 100644 --- a/src/plugProjectKandoU/aiFormation.cpp +++ b/src/plugProjectKandoU/aiFormation.cpp @@ -217,8 +217,8 @@ void ActFormation::onKeyEvent(SysShape::KeyEvent const& keyEvent) if (mIsAnimating) { mAnimationTimer--; if (mAnimationTimer <= 0) { - mParent->mAnimator.mSelfAnimator.mFlags |= EANIM_FLAG_FINISHED; - mParent->mAnimator.mBoundAnimator.mFlags |= EANIM_FLAG_FINISHED; + mParent->mAnimator.mSelfAnimator.setFlag(SysShape::Animator::Finished); + mParent->mAnimator.mBoundAnimator.setFlag(SysShape::Animator::Finished); } } break; diff --git a/src/plugProjectKandoU/dynCreature.cpp b/src/plugProjectKandoU/dynCreature.cpp index f32f31abd..a0e515788 100644 --- a/src/plugProjectKandoU/dynCreature.cpp +++ b/src/plugProjectKandoU/dynCreature.cpp @@ -147,20 +147,20 @@ void DynCreature::computeForces(f32 friction) Vector3f sep = particle->mPosition - mTransformedPosition; Vector3f crossVec = mRigid.mConfigs[0].mRotatedMomentum.cross(sep) + mRigid.mConfigs[0].mVelocity; - f32 dotProd = crossVec.dot(particle->_20); // f13 - f32 dotProd2 = mRigid.mConfigs[0].mForce.dot(particle->_20); + f32 dotProd = crossVec.dot(particle->mCollisionNormal); // f13 + f32 dotProd2 = mRigid.mConfigs[0].mForce.dot(particle->mCollisionNormal); - Vector3f sep2 = crossVec - particle->_20 * dotProd; + Vector3f sep2 = crossVec - particle->mCollisionNormal * dotProd; sep2.normalise(); - mRigid.mConfigs[0].mForce += particle->_20 * dotProd2; + mRigid.mConfigs[0].mForce += particle->mCollisionNormal * dotProd2; // f32 dotProd3 = sep2.dot(crossVec); if (absF(sep2.dot(crossVec)) < DynamicsParms::mInstance->mStatic()) { sep2.normalise(); mRigid.mConfigs[0].mForce -= sep2 * DynamicsParms::mInstance->mStaParm(); } else { - Vector3f sep3 = crossVec - particle->_20 * crossVec.dot(particle->_20); + Vector3f sep3 = crossVec - particle->mCollisionNormal * crossVec.dot(particle->mCollisionNormal); sep3.normalise(); mRigid.mConfigs[0].mForce += sep3 * -DynamicsParms::mInstance->mFixedFrictionValue(); } @@ -198,7 +198,7 @@ void DynCreature::computeForces(f32 friction) } Vector3f sep = particle->mPosition - mTransformedPosition; Vector3f crossVec = mRigid.mConfigs[0].mRotatedMomentum.cross(sep) + mRigid.mConfigs[0].mVelocity; - Vector3f vec = particle->_20 * crossVec.dot(particle->_20); + Vector3f vec = particle->mCollisionNormal * crossVec.dot(particle->mCollisionNormal); vec = crossVec - vec; if (DynamicsParms::mInstance->mFrictionTangentVelocity()) { vec.normalise(); @@ -589,18 +589,18 @@ lbl_801A87D0: * @note Address: 0x801A87D8 * @note Size: 0xB4 */ -void DynCreature::tracemoveCallback(Vector3f& vec1, Vector3f& vec2) +void DynCreature::tracemoveCallback(Vector3f& point, Vector3f& normal) { - bool collCheck = mRigid.resolveCollision(0, vec1, vec2, DynamicsParms::mInstance->mElasticity()); + bool collCheck = mRigid.resolveCollision(0, point, normal, DynamicsParms::mInstance->mElasticity()); if (mCurrentChildPtcl && collCheck) { if (!mCanBounce) { bounceCallback(nullptr); } - mHasCollided = 1; - mCurrentChildPtcl->mIsTouching = 1; - mCurrentChildPtcl->_20 = vec2; + mHasCollided = 1; + mCurrentChildPtcl->mIsTouching = 1; + mCurrentChildPtcl->mCollisionNormal = normal; } } diff --git a/src/plugProjectKandoU/fakePiki.cpp b/src/plugProjectKandoU/fakePiki.cpp index ded39b587..e2660c9f0 100644 --- a/src/plugProjectKandoU/fakePiki.cpp +++ b/src/plugProjectKandoU/fakePiki.cpp @@ -171,8 +171,8 @@ void FakePiki::startMotion(int selfAnimIdx, int boundAnimIdx, SysShape::MotionLi */ void FakePiki::finishMotion() { - mAnimator.mSelfAnimator.mFlags |= 0x2; - mAnimator.mBoundAnimator.mFlags |= 0x2; + mAnimator.mSelfAnimator.setFlag(SysShape::Animator::Finished); + mAnimator.mBoundAnimator.setFlag(SysShape::Animator::Finished); } /** diff --git a/src/plugProjectKandoU/naviState.cpp b/src/plugProjectKandoU/naviState.cpp index 941f514b7..5dd3b87de 100644 --- a/src/plugProjectKandoU/naviState.cpp +++ b/src/plugProjectKandoU/naviState.cpp @@ -6905,7 +6905,7 @@ void NaviPelletState::onKeyEvent(Navi* navi, SysShape::KeyEvent const& key) { if (mDoForceWakeup) { if (key.mType == 1) { - if (navi->mAnimator.mSelfAnimator.mFlags & 2) { + if (navi->mAnimator.mSelfAnimator.isFlag(SysShape::Animator::Finished)) { if (playData->mStoryFlags & STORY_DebtPaid) { navi->mSoundObj->startSound(PSSE_PL_WAKEUP_SHACHO, 0); } else { diff --git a/src/plugProjectKandoU/pikiState.cpp b/src/plugProjectKandoU/pikiState.cpp index b294de9c7..9e39b03f8 100644 --- a/src/plugProjectKandoU/pikiState.cpp +++ b/src/plugProjectKandoU/pikiState.cpp @@ -4696,8 +4696,8 @@ void PikiKokeState::onKeyEvent(Piki* piki, SysShape::KeyEvent const& event) case KEYEVENT_1: mTimer--; if (mTimer <= 0) { - piki->mAnimator.mSelfAnimator.mFlags |= EANIM_FLAG_FINISHED; - piki->mAnimator.mBoundAnimator.mFlags |= EANIM_FLAG_FINISHED; + piki->mAnimator.mSelfAnimator.mFlags |= SysShape::Animator::Finished; + piki->mAnimator.mBoundAnimator.mFlags |= SysShape::Animator::Finished; } break; @@ -6411,8 +6411,8 @@ void PikiEscapeState::onKeyEvent(Piki* piki, SysShape::KeyEvent const& event) if (mSubState == 1 || mSubState == 2) { mDoFinishAnim--; if (mDoFinishAnim <= 0) { - piki->mAnimator.mSelfAnimator.mFlags |= EANIM_FLAG_FINISHED; - piki->mAnimator.mBoundAnimator.mFlags |= EANIM_FLAG_FINISHED; + piki->mAnimator.mSelfAnimator.mFlags |= SysShape::Animator::Finished; + piki->mAnimator.mBoundAnimator.mFlags |= SysShape::Animator::Finished; } } break; diff --git a/src/plugProjectYamashitaU/enemyAnimatorBase.cpp b/src/plugProjectYamashitaU/enemyAnimatorBase.cpp index 39bb0eaf7..b348394a8 100644 --- a/src/plugProjectYamashitaU/enemyAnimatorBase.cpp +++ b/src/plugProjectYamashitaU/enemyAnimatorBase.cpp @@ -20,21 +20,21 @@ EnemyAnimatorBase::EnemyAnimatorBase() */ void EnemyAnimatorBase::animate(f32 speed) { - if (!(mFlags.isSet(EANIM_FLAG_STOPPED))) { - if (mFlags.isSet(EANIM_FLAG_FINISHED)) { + if (!(mFlags.isSet(SysShape::Animator::Stopped))) { + if (mFlags.isSet(SysShape::Animator::Finished)) { mNormalizedTime *= 0.9f; if (mNormalizedTime < 0.1f) { mNormalizedTime = 0.0f; - mFlags.unset(EANIM_FLAG_PLAYING); - mFlags.set(EANIM_FLAG_STOPPED); + mFlags.unset(SysShape::Animator::Playing); + mFlags.set(SysShape::Animator::Stopped); } - } else if (mFlags.isSet(EANIM_FLAG_PLAYING)) { + } else if (mFlags.isSet(SysShape::Animator::Playing)) { mNormalizedTime *= 1.1f; if (mNormalizedTime > 1.0f) { mNormalizedTime = 1.0f; - mFlags.unset(EANIM_FLAG_FINISHED | EANIM_FLAG_STOPPED); + mFlags.unset(SysShape::Animator::Finished | SysShape::Animator::Stopped); mNormalizedTime = 1.0f; } } @@ -51,21 +51,21 @@ void EnemyAnimatorBase::animate(f32 speed) */ void EnemyAnimatorBase::animate(int animatorNum, f32 speed) { - if (!(mFlags.isSet(EANIM_FLAG_STOPPED))) { - if (mFlags.isSet(EANIM_FLAG_FINISHED)) { + if (!(mFlags.isSet(SysShape::Animator::Stopped))) { + if (mFlags.isSet(SysShape::Animator::Finished)) { mNormalizedTime *= 0.9f; if (mNormalizedTime < 0.1f) { mNormalizedTime = 0.0f; - mFlags.unset(EANIM_FLAG_PLAYING); - mFlags.set(EANIM_FLAG_STOPPED); + mFlags.unset(SysShape::Animator::Playing); + mFlags.set(SysShape::Animator::Stopped); } - } else if (mFlags.isSet(EANIM_FLAG_PLAYING)) { + } else if (mFlags.isSet(SysShape::Animator::Playing)) { mNormalizedTime *= 1.1f; if (mNormalizedTime > 1.0f) { mNormalizedTime = 1.0f; - mFlags.unset(EANIM_FLAG_FINISHED | EANIM_FLAG_STOPPED); + mFlags.unset(SysShape::Animator::Finished | SysShape::Animator::Stopped); mNormalizedTime = 1.0f; } } diff --git a/src/plugProjectYamashitaU/enemyBase.cpp b/src/plugProjectYamashitaU/enemyBase.cpp index 8ce38acbc..cfc716e9f 100644 --- a/src/plugProjectYamashitaU/enemyBase.cpp +++ b/src/plugProjectYamashitaU/enemyBase.cpp @@ -2291,7 +2291,7 @@ void EnemyBase::startMotion(int id, SysShape::MotionListener* inputListener) } EnemyAnimatorBase* animator = mAnimator; - animator->mFlags.unset(EANIM_FLAG_STOPPED | EANIM_FLAG_FINISHED); + animator->mFlags.unset(SysShape::Animator::Stopped | SysShape::Animator::Finished); animator->mNormalizedTime = 1.0f; animator->getAnimator(0).startAnim(id, inputListener); @@ -2352,7 +2352,7 @@ f32 EnemyBase::getMotionFrame() { return mAnimator->getAnimator().mTimer; } * @note Address: 0x801052A0 * @note Size: 0x40 */ -void EnemyBase::finishMotion() { SET_FLAG(mAnimator->getAnimator(0).mFlags, EANIM_FLAG_FINISHED); } +void EnemyBase::finishMotion() { SET_FLAG(mAnimator->getAnimator(0).mFlags, SysShape::Animator::Finished); } /** * @note Address: 0x801052E0 @@ -3113,7 +3113,7 @@ PSM::EnemyBase* EnemyBase::createPSEnemyBase() void EnemyBase::startMotion() { EnemyAnimatorBase* animator = mAnimator; - RESET_FLAG(animator->mFlags.typeView, EANIM_FLAG_STOPPED | EANIM_FLAG_FINISHED); + RESET_FLAG(animator->mFlags.typeView, SysShape::Animator::Stopped | SysShape::Animator::Finished); animator->mNormalizedTime = 1.0f; } @@ -3144,8 +3144,8 @@ f32 EnemyBase::getFirstKeyFrame() void EnemyBase::stopMotion() { EnemyAnimatorBase* animator = mAnimator; - RESET_FLAG(animator->mFlags.typeView, EANIM_FLAG_PLAYING); - SET_FLAG(animator->mFlags.typeView, EANIM_FLAG_STOPPED); + RESET_FLAG(animator->mFlags.typeView, SysShape::Animator::Playing); + SET_FLAG(animator->mFlags.typeView, SysShape::Animator::Stopped); } /** @@ -3158,7 +3158,7 @@ bool EnemyBase::isFinishMotion() { return mAnimator->getAnimator().mFlags >> 1 & * @note Address: 0x80107338 * @note Size: 0x10 */ -bool EnemyBase::isStopMotion() { return mAnimator->mFlags.isSet(EANIM_FLAG_STOPPED); } +bool EnemyBase::isStopMotion() { return mAnimator->mFlags.isSet(SysShape::Animator::Stopped); } /** * @note Address: 0x80107348