1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-02 03:15:35 +00:00

Avoid trying to animate things that don't have animations

This commit is contained in:
Chris Robinson 2013-01-16 15:00:06 -08:00
parent 94b93227d3
commit 3c32385e17
3 changed files with 24 additions and 2 deletions

View file

@ -29,7 +29,7 @@ namespace MWMechanics
CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state)
: mPtr(ptr), mAnimation(anim), mState(state)
{
if(!mAnimation)
if(!mAnimation || mAnimation->getAnimationCount() == 0)
return;
mAnimation->setController(this);
@ -47,7 +47,7 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim
CharacterController::CharacterController(const CharacterController &rhs)
: mPtr(rhs.mPtr), mAnimation(rhs.mAnimation), mState(rhs.mState)
{
if(!mAnimation)
if(!mAnimation || mAnimation->getAnimationCount() == 0)
return;
/* We've been copied. Update the animation with the new controller. */
mAnimation->setController(this);
@ -68,6 +68,9 @@ void CharacterController::markerEvent(const std::string &evt)
void CharacterController::setState(CharacterState state)
{
mState = state;
if(!mAnimation || mAnimation->getAnimationCount() == 0)
return;
switch(mState)
{
case CharState_Idle:

View file

@ -98,6 +98,23 @@ void Animation::createEntityList(Ogre::SceneNode *node, const std::string &model
}
int Animation::getAnimationCount()
{
int num = 0;
if(mEntityList.mSkelBase)
{
Ogre::AnimationStateSet *as = mEntityList.mSkelBase->getAllAnimationStates();
Ogre::AnimationStateIterator ai = as->getAnimationStateIterator();
while(ai.hasMoreElements())
{
num++;
ai.moveNext();
}
}
return num;
}
void Animation::setController(MWMechanics::CharacterController *controller)
{
mController = controller;

View file

@ -66,6 +66,8 @@ public:
virtual ~Animation();
void setController(MWMechanics::CharacterController *controller);
int getAnimationCount();
void playGroup(std::string groupname, int mode, int loops);
void skipAnim();
virtual void runAnimation(float timepassed);