Run animations from the character controller

This commit is contained in:
Chris Robinson 2013-01-16 16:31:09 -08:00
parent 46728ab27f
commit 46fc61a4c1
5 changed files with 16 additions and 8 deletions

View file

@ -263,6 +263,7 @@ namespace MWMechanics
std::vector<std::pair<std::string, Ogre::Vector3> > movement;
for(PtrControllerMap::iterator iter(mActors.begin());iter != mActors.end();++iter)
{
iter->second.update(duration);
Ogre::Vector3 vector = MWWorld::Class::get(iter->first).getMovementVector(iter->first);
if(vector!=Ogre::Vector3::ZERO)
movement.push_back(std::make_pair(iter->first.getRefData().getHandle(), vector));

View file

@ -32,7 +32,9 @@ 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 && mAnimation->getAnimationCount() == 0)
mAnimation = NULL;
if(!mAnimation)
return;
mAnimation->setController(this);
@ -50,7 +52,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 || mAnimation->getAnimationCount() == 0)
if(!mAnimation)
return;
/* We've been copied. Update the animation with the new controller. */
mAnimation->setController(this);
@ -67,11 +69,18 @@ void CharacterController::markerEvent(const std::string &evt)
}
void CharacterController::update(float duration)
{
if(mAnimation)
mAnimation->runAnimation(duration);
}
void CharacterController::setState(CharacterState state)
{
mState = state;
if(!mAnimation || mAnimation->getAnimationCount() == 0)
if(!mAnimation)
return;
switch(mState)
{

View file

@ -33,6 +33,8 @@ public:
CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state);
CharacterController(const CharacterController &rhs);
void update(float duration);
void setState(CharacterState state);
CharacterState getState() const
{ return mState; }

View file

@ -149,8 +149,7 @@ void Actors::skipAnimation (const MWWorld::Ptr& ptr)
}
void Actors::update (float duration)
{
for(PtrAnimationMap::const_iterator iter = mAllActors.begin();iter != mAllActors.end();iter++)
iter->second->runAnimation(duration);
// Nothing to do
}
Animation* Actors::getAnimation(const MWWorld::Ptr &ptr)

View file

@ -129,9 +129,6 @@ namespace MWRender
MWBase::Environment::get().getWindowManager ()->showCrosshair
(!MWBase::Environment::get().getWindowManager ()->isGuiMode () && (mFirstPersonView && !mVanity.enabled && !mPreviewMode));
if (mAnimation) {
mAnimation->runAnimation(duration);
}
mPlayerNode->setVisible(
mVanity.enabled || mPreviewMode || !mFirstPersonView,
false