1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 10:53:54 +00:00

Handle animation skipping in the character controller

This commit is contained in:
Chris Robinson 2013-01-16 21:25:50 -08:00
parent 852aa214cc
commit 7ee389f3b2
4 changed files with 6 additions and 18 deletions

View file

@ -30,7 +30,7 @@ namespace MWMechanics
{ {
CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state) CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state)
: mPtr(ptr), mAnimation(anim), mState(state) : mPtr(ptr), mAnimation(anim), mState(state), mSkipAnim(false)
{ {
if(mAnimation) if(mAnimation)
mAnimNames = mAnimation->getAnimationNames(); mAnimNames = mAnimation->getAnimationNames();
@ -56,7 +56,7 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim
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)
, mState(rhs.mState) , mState(rhs.mState), mSkipAnim(rhs.mSkipAnim)
{ {
if(mAnimNames.size() == 0) if(mAnimNames.size() == 0)
return; return;
@ -77,8 +77,9 @@ void CharacterController::markerEvent(const std::string &evt)
Ogre::Vector3 CharacterController::update(float duration) Ogre::Vector3 CharacterController::update(float duration)
{ {
if(mAnimation) if(mAnimation && !mSkipAnim)
mAnimation->runAnimation(duration); mAnimation->runAnimation(duration);
mSkipAnim = false;
return MWWorld::Class::get(mPtr).getMovementVector(mPtr); return MWWorld::Class::get(mPtr).getMovementVector(mPtr);
} }
@ -92,8 +93,7 @@ void CharacterController::playGroup(const std::string &groupname, int mode, int
void CharacterController::skipAnim() void CharacterController::skipAnim()
{ {
if(mAnimation) mSkipAnim = true;
mAnimation->skipAnim();
} }

View file

@ -25,6 +25,7 @@ class CharacterController
std::string mCurrentGroup; std::string mCurrentGroup;
CharacterState mState; CharacterState mState;
bool mSkipAnim;
protected: protected:
/* Called by the animation whenever a new text key is reached. */ /* Called by the animation whenever a new text key is reached. */

View file

@ -24,7 +24,6 @@ Animation::Animation(const MWWorld::Ptr &ptr)
, mStartPosition(0.0f) , mStartPosition(0.0f)
, mLastPosition(0.0f) , mLastPosition(0.0f)
, mTime(0.0f) , mTime(0.0f)
, mSkipFrame(false)
{ {
} }
@ -246,17 +245,8 @@ void Animation::playGroup(std::string groupname, int mode, int loops)
} }
} }
void Animation::skipAnim()
{
mSkipFrame = true;
}
void Animation::runAnimation(float timepassed) void Animation::runAnimation(float timepassed)
{ {
if(mSkipFrame)
timepassed = 0.0f;
mSkipFrame = false;
while(mCurGroup.mAnimState && timepassed > 0.0f) while(mCurGroup.mAnimState && timepassed > 0.0f)
{ {
float targetTime = mTime + timepassed; float targetTime = mTime + timepassed;

View file

@ -48,8 +48,6 @@ protected:
GroupTimes mCurGroup; GroupTimes mCurGroup;
GroupTimes mNextGroup; GroupTimes mNextGroup;
bool mSkipFrame;
/* Updates the animation to the specified time, and moves the mPtr object /* Updates the animation to the specified time, and moves the mPtr object
* based on the change since the last update or reset. */ * based on the change since the last update or reset. */
void updatePosition(float time); void updatePosition(float time);
@ -69,7 +67,6 @@ public:
std::vector<std::string> getAnimationNames(); std::vector<std::string> getAnimationNames();
void playGroup(std::string groupname, int mode, int loops); void playGroup(std::string groupname, int mode, int loops);
void skipAnim();
virtual void runAnimation(float timepassed); virtual void runAnimation(float timepassed);
}; };