Start cleaning up animator

This commit is contained in:
intns 2024-05-11 11:19:58 +01:00
parent 7ddac08c4b
commit 28dcff438e
12 changed files with 61 additions and 56 deletions

View File

@ -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)

View File

@ -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();

View File

@ -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);

View File

@ -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) {

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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);
}
/**

View File

@ -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 {

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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