1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Add a looping property to handle if an animation should loop

This commit is contained in:
Chris Robinson 2013-01-19 14:22:15 -08:00
parent 0b68953f0d
commit de2d084e61
3 changed files with 17 additions and 13 deletions

View File

@ -169,9 +169,9 @@ namespace MWMechanics
/* Kind of a hack. Activators need a character controller to manage an idle state. */ /* Kind of a hack. Activators need a character controller to manage an idle state. */
if(ptr.getTypeName() == typeid(ESM::Activator).name() || if(ptr.getTypeName() == typeid(ESM::Activator).name() ||
!MWWorld::Class::get(ptr).getCreatureStats(ptr).isDead()) !MWWorld::Class::get(ptr).getCreatureStats(ptr).isDead())
mActors.insert(std::make_pair(ptr, CharacterController(ptr, anim, CharState_Idle))); mActors.insert(std::make_pair(ptr, CharacterController(ptr, anim, CharState_Idle, true)));
else else
mActors.insert(std::make_pair(ptr, CharacterController(ptr, anim, CharState_Dead))); mActors.insert(std::make_pair(ptr, CharacterController(ptr, anim, CharState_Dead, false)));
} }
void Actors::removeActor (const MWWorld::Ptr& ptr) void Actors::removeActor (const MWWorld::Ptr& ptr)
@ -213,7 +213,7 @@ namespace MWMechanics
if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead()) if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead())
{ {
if(iter->second.getState() == CharState_Dead) if(iter->second.getState() == CharState_Dead)
iter->second.setState(CharState_Idle); iter->second.setState(CharState_Idle, true);
updateActor(iter->first, totalDuration); updateActor(iter->first, totalDuration);
if(iter->first.getTypeName() == typeid(ESM::NPC).name()) if(iter->first.getTypeName() == typeid(ESM::NPC).name())
@ -250,7 +250,7 @@ namespace MWMechanics
continue; continue;
} }
iter->second.setState(CharState_Dead); iter->second.setState(CharState_Dead, false);
iter->second.setDirection(Ogre::Vector3::ZERO); iter->second.setDirection(Ogre::Vector3::ZERO);
++mDeathCount[MWWorld::Class::get(iter->first).getId(iter->first)]; ++mDeathCount[MWWorld::Class::get(iter->first).getId(iter->first)];
@ -280,7 +280,7 @@ namespace MWMechanics
} }
if(iter->second.getState() != newstate) if(iter->second.getState() != newstate)
iter->second.setState(newstate); iter->second.setState(newstate, true);
iter->second.setDirection(dir); iter->second.setDirection(dir);
} }

View File

@ -29,8 +29,8 @@
namespace MWMechanics namespace MWMechanics
{ {
CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state) CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state, bool loop)
: mPtr(ptr), mAnimation(anim), mDirection(Ogre::Vector3::ZERO), mState(state), mSkipAnim(false) : mPtr(ptr), mAnimation(anim), mDirection(Ogre::Vector3::ZERO), mState(state), mSkipAnim(false), mLoop(loop)
{ {
if(mAnimation) if(mAnimation)
mAnimNames = mAnimation->getAnimationNames(); mAnimNames = mAnimation->getAnimationNames();
@ -41,13 +41,14 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim
} }
mAnimation->setController(this); mAnimation->setController(this);
setState(mState); setState(mState, loop);
} }
CharacterController::CharacterController(const CharacterController &rhs) CharacterController::CharacterController(const CharacterController &rhs)
: mPtr(rhs.mPtr), mAnimation(rhs.mAnimation), mAnimNames(rhs.mAnimNames) : mPtr(rhs.mPtr), mAnimation(rhs.mAnimation), mAnimNames(rhs.mAnimNames)
, mAnimQueue(rhs.mAnimQueue), mCurrentGroup(rhs.mCurrentGroup) , mAnimQueue(rhs.mAnimQueue), mCurrentGroup(rhs.mCurrentGroup)
, mDirection(rhs.mDirection), mState(rhs.mState), mSkipAnim(rhs.mSkipAnim) , mDirection(rhs.mDirection), mState(rhs.mState), mSkipAnim(rhs.mSkipAnim)
, mLoop(rhs.mLoop)
{ {
if(mAnimNames.size() == 0) if(mAnimNames.size() == 0)
return; return;
@ -81,7 +82,7 @@ void CharacterController::markerEvent(float time, const std::string &evt)
{ {
if(mAnimQueue.size() == 0) if(mAnimQueue.size() == 0)
{ {
if(time > 0.0f && mState != CharState_Dead) if(time > 0.0f && mLoop)
mAnimation->play(mCurrentGroup, "loop start"); mAnimation->play(mCurrentGroup, "loop start");
} }
else if(mAnimQueue.size() >= 2 && mAnimQueue[0] == mAnimQueue[1]) else if(mAnimQueue.size() >= 2 && mAnimQueue[0] == mAnimQueue[1])
@ -96,7 +97,7 @@ void CharacterController::markerEvent(float time, const std::string &evt)
{ {
if(mAnimQueue.size() == 0) if(mAnimQueue.size() == 0)
{ {
if(time > 0.0f && mState != CharState_Dead) if(time > 0.0f && mLoop)
mAnimation->play(mCurrentGroup, "loop start"); mAnimation->play(mCurrentGroup, "loop start");
} }
else if(mAnimQueue.size() >= 2 && mAnimQueue[0] == mAnimQueue[1]) else if(mAnimQueue.size() >= 2 && mAnimQueue[0] == mAnimQueue[1])
@ -158,6 +159,7 @@ void CharacterController::playGroup(const std::string &groupname, int mode, int
mAnimQueue.push_back(groupname); mAnimQueue.push_back(groupname);
mCurrentGroup = groupname; mCurrentGroup = groupname;
mState = CharState_SpecialIdle; mState = CharState_SpecialIdle;
mLoop = false;
mAnimation->setAccumulation(Ogre::Vector3::ZERO); mAnimation->setAccumulation(Ogre::Vector3::ZERO);
mAnimation->play(mCurrentGroup, ((mode==2) ? "loop start" : "start")); mAnimation->play(mCurrentGroup, ((mode==2) ? "loop start" : "start"));
} }
@ -176,9 +178,10 @@ void CharacterController::skipAnim()
} }
void CharacterController::setState(CharacterState state) void CharacterController::setState(CharacterState state, bool loop)
{ {
mState = state; mState = state;
mLoop = loop;
if(mAnimNames.size() == 0) if(mAnimNames.size() == 0)
return; return;

View File

@ -38,6 +38,7 @@ class CharacterController
std::string mCurrentGroup; std::string mCurrentGroup;
CharacterState mState; CharacterState mState;
bool mSkipAnim; bool mSkipAnim;
bool mLoop;
protected: protected:
/* Called by the animation whenever a new text key is reached. */ /* Called by the animation whenever a new text key is reached. */
@ -46,7 +47,7 @@ protected:
friend class MWRender::Animation; friend class MWRender::Animation;
public: public:
CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state); CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state, bool loop);
CharacterController(const CharacterController &rhs); CharacterController(const CharacterController &rhs);
Ogre::Vector3 update(float duration); Ogre::Vector3 update(float duration);
@ -56,7 +57,7 @@ public:
void setDirection(const Ogre::Vector3 &dir); void setDirection(const Ogre::Vector3 &dir);
void setState(CharacterState state); void setState(CharacterState state, bool loop);
CharacterState getState() const CharacterState getState() const
{ return mState; } { return mState; }
}; };