From 0c926552502759ece98bdf14e76b7d01b6d7aaf7 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Tue, 12 Jun 2018 11:51:54 +0400 Subject: [PATCH] Avoid code duplication in character manager --- apps/openmw/mwmechanics/character.cpp | 44 ++++++++++++--------------- apps/openmw/mwmechanics/character.hpp | 2 ++ 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 332cd225c..6eaaa3def 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -562,12 +562,8 @@ void CharacterController::refreshIdleAnims(const WeaponInfo* weap, CharacterStat void CharacterController::refreshCurrentAnims(CharacterState idle, CharacterState movement, JumpingState jump, bool force) { // If the current animation is persistent, do not touch it - if (!mAnimQueue.empty()) - { - AnimationQueueEntry& first = mAnimQueue.front(); - if (first.mPersist && isAnimPlaying(first.mGroup)) - return; - } + if (isPersistentAnimPlaying()) + return; if (mPtr.getClass().isActor()) refreshHitRecoilAnims(); @@ -754,12 +750,8 @@ void CharacterController::playRandomDeath(float startpoint) } // Do not interrupt scripted animation by death - if (!mAnimQueue.empty()) - { - AnimationQueueEntry& first = mAnimQueue.front(); - if (first.mPersist && isAnimPlaying(first.mGroup)) - return; - } + if (isPersistentAnimPlaying()) + return; playDeath(startpoint, mDeathState); } @@ -2154,12 +2146,8 @@ bool CharacterController::playGroup(const std::string &groupname, int mode, int return false; // We should not interrupt persistent animations by non-persistent ones - if (!mAnimQueue.empty()) - { - AnimationQueueEntry& first = mAnimQueue.front(); - if (first.mPersist && !persist) - return false; - } + if (isPersistentAnimPlaying() && !persist) + return false; // If this animation is a looped animation (has a "loop start" key) that is already playing // and has not yet reached the end of the loop, allow it to continue animating with its existing loop count @@ -2215,6 +2203,17 @@ void CharacterController::skipAnim() mSkipAnim = true; } +bool CharacterController::isPersistentAnimPlaying() +{ + if (!mAnimQueue.empty()) + { + AnimationQueueEntry& first = mAnimQueue.front(); + return first.mPersist && isAnimPlaying(first.mGroup); + } + + return false; +} + bool CharacterController::isAnimPlaying(const std::string &groupName) { if(mAnimation == NULL) @@ -2222,16 +2221,11 @@ bool CharacterController::isAnimPlaying(const std::string &groupName) return mAnimation->isPlaying(groupName); } - void CharacterController::clearAnimQueue() { // Do not interrupt scripted animations - if (!mAnimQueue.empty()) - { - AnimationQueueEntry& first = mAnimQueue.front(); - if (!first.mPersist) - mAnimation->disable(mAnimQueue.front().mGroup); - } + if (!isPersistentAnimPlaying() && !mAnimQueue.empty()) + mAnimation->disable(mAnimQueue.front().mGroup); for (AnimationQueue::iterator it = mAnimQueue.begin(); it != mAnimQueue.end();) { diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index a172620b9..74910b3c3 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -221,6 +221,8 @@ class CharacterController : public MWRender::Animation::TextKeyListener bool updateCreatureState(); void updateIdleStormState(bool inwater); + bool isPersistentAnimPlaying(); + void updateAnimQueue(); void updateHeadTracking(float duration);