Store the available animation names in the character controller

This commit is contained in:
Chris Robinson 2013-01-16 21:16:22 -08:00
parent afbc9f3e41
commit 852aa214cc
4 changed files with 17 additions and 14 deletions

View file

@ -32,10 +32,13 @@ namespace MWMechanics
CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state)
: mPtr(ptr), mAnimation(anim), mState(state)
{
if(mAnimation && mAnimation->getAnimationCount() == 0)
if(mAnimation)
mAnimNames = mAnimation->getAnimationNames();
if(mAnimNames.size() == 0)
{
mAnimation = NULL;
if(!mAnimation)
return;
}
mAnimation->setController(this);
switch(mState)
@ -52,9 +55,10 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim
}
CharacterController::CharacterController(const CharacterController &rhs)
: mPtr(rhs.mPtr), mAnimation(rhs.mAnimation), mState(rhs.mState)
: mPtr(rhs.mPtr), mAnimation(rhs.mAnimation), mAnimNames(rhs.mAnimNames)
, mState(rhs.mState)
{
if(!mAnimation)
if(mAnimNames.size() == 0)
return;
/* We've been copied. Update the animation with the new controller. */
mAnimation->setController(this);
@ -82,7 +86,7 @@ Ogre::Vector3 CharacterController::update(float duration)
void CharacterController::playGroup(const std::string &groupname, int mode, int count)
{
// set mState = CharState_Idle?
if(mAnimation)
if(std::find(mAnimNames.begin(), mAnimNames.end(), groupname) != mAnimNames.end())
mAnimation->playGroup(groupname, mode, count);
}
@ -97,7 +101,7 @@ void CharacterController::setState(CharacterState state)
{
mState = state;
if(!mAnimation)
if(mAnimNames.size() == 0)
return;
switch(mState)
{

View file

@ -21,6 +21,8 @@ class CharacterController
MWWorld::Ptr mPtr;
MWRender::Animation *mAnimation;
std::vector<std::string> mAnimNames;
std::string mCurrentGroup;
CharacterState mState;

View file

@ -98,20 +98,17 @@ void Animation::createEntityList(Ogre::SceneNode *node, const std::string &model
}
int Animation::getAnimationCount()
std::vector<std::string> Animation::getAnimationNames()
{
int num = 0;
std::vector<std::string> anims;
if(mEntityList.mSkelBase)
{
Ogre::AnimationStateSet *as = mEntityList.mSkelBase->getAllAnimationStates();
Ogre::AnimationStateIterator ai = as->getAnimationStateIterator();
while(ai.hasMoreElements())
{
num++;
ai.moveNext();
}
anims.push_back(ai.getNext()->getAnimationName());
}
return num;
return anims;
}

View file

@ -66,7 +66,7 @@ public:
virtual ~Animation();
void setController(MWMechanics::CharacterController *controller);
int getAnimationCount();
std::vector<std::string> getAnimationNames();
void playGroup(std::string groupname, int mode, int loops);
void skipAnim();