mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
Add a looping property to handle if an animation should loop
This commit is contained in:
parent
0b68953f0d
commit
de2d084e61
@ -169,9 +169,9 @@ namespace MWMechanics
|
||||
/* Kind of a hack. Activators need a character controller to manage an idle state. */
|
||||
if(ptr.getTypeName() == typeid(ESM::Activator).name() ||
|
||||
!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
|
||||
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)
|
||||
@ -213,7 +213,7 @@ namespace MWMechanics
|
||||
if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead())
|
||||
{
|
||||
if(iter->second.getState() == CharState_Dead)
|
||||
iter->second.setState(CharState_Idle);
|
||||
iter->second.setState(CharState_Idle, true);
|
||||
|
||||
updateActor(iter->first, totalDuration);
|
||||
if(iter->first.getTypeName() == typeid(ESM::NPC).name())
|
||||
@ -250,7 +250,7 @@ namespace MWMechanics
|
||||
continue;
|
||||
}
|
||||
|
||||
iter->second.setState(CharState_Dead);
|
||||
iter->second.setState(CharState_Dead, false);
|
||||
iter->second.setDirection(Ogre::Vector3::ZERO);
|
||||
|
||||
++mDeathCount[MWWorld::Class::get(iter->first).getId(iter->first)];
|
||||
@ -280,7 +280,7 @@ namespace MWMechanics
|
||||
}
|
||||
|
||||
if(iter->second.getState() != newstate)
|
||||
iter->second.setState(newstate);
|
||||
iter->second.setState(newstate, true);
|
||||
iter->second.setDirection(dir);
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,8 @@
|
||||
namespace MWMechanics
|
||||
{
|
||||
|
||||
CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state)
|
||||
: mPtr(ptr), mAnimation(anim), mDirection(Ogre::Vector3::ZERO), mState(state), mSkipAnim(false)
|
||||
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), mLoop(loop)
|
||||
{
|
||||
if(mAnimation)
|
||||
mAnimNames = mAnimation->getAnimationNames();
|
||||
@ -41,13 +41,14 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim
|
||||
}
|
||||
|
||||
mAnimation->setController(this);
|
||||
setState(mState);
|
||||
setState(mState, loop);
|
||||
}
|
||||
|
||||
CharacterController::CharacterController(const CharacterController &rhs)
|
||||
: mPtr(rhs.mPtr), mAnimation(rhs.mAnimation), mAnimNames(rhs.mAnimNames)
|
||||
, mAnimQueue(rhs.mAnimQueue), mCurrentGroup(rhs.mCurrentGroup)
|
||||
, mDirection(rhs.mDirection), mState(rhs.mState), mSkipAnim(rhs.mSkipAnim)
|
||||
, mLoop(rhs.mLoop)
|
||||
{
|
||||
if(mAnimNames.size() == 0)
|
||||
return;
|
||||
@ -81,7 +82,7 @@ void CharacterController::markerEvent(float time, const std::string &evt)
|
||||
{
|
||||
if(mAnimQueue.size() == 0)
|
||||
{
|
||||
if(time > 0.0f && mState != CharState_Dead)
|
||||
if(time > 0.0f && mLoop)
|
||||
mAnimation->play(mCurrentGroup, "loop start");
|
||||
}
|
||||
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(time > 0.0f && mState != CharState_Dead)
|
||||
if(time > 0.0f && mLoop)
|
||||
mAnimation->play(mCurrentGroup, "loop start");
|
||||
}
|
||||
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);
|
||||
mCurrentGroup = groupname;
|
||||
mState = CharState_SpecialIdle;
|
||||
mLoop = false;
|
||||
mAnimation->setAccumulation(Ogre::Vector3::ZERO);
|
||||
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;
|
||||
mLoop = loop;
|
||||
|
||||
if(mAnimNames.size() == 0)
|
||||
return;
|
||||
|
@ -38,6 +38,7 @@ class CharacterController
|
||||
std::string mCurrentGroup;
|
||||
CharacterState mState;
|
||||
bool mSkipAnim;
|
||||
bool mLoop;
|
||||
|
||||
protected:
|
||||
/* Called by the animation whenever a new text key is reached. */
|
||||
@ -46,7 +47,7 @@ protected:
|
||||
friend class MWRender::Animation;
|
||||
|
||||
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);
|
||||
|
||||
Ogre::Vector3 update(float duration);
|
||||
@ -56,7 +57,7 @@ public:
|
||||
|
||||
void setDirection(const Ogre::Vector3 &dir);
|
||||
|
||||
void setState(CharacterState state);
|
||||
void setState(CharacterState state, bool loop);
|
||||
CharacterState getState() const
|
||||
{ return mState; }
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user