mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 19:45:33 +00:00
Consolidate refreshMovementAnims()
This commit is contained in:
parent
7a390a359f
commit
9e6b7fed1a
1 changed files with 121 additions and 132 deletions
|
@ -491,23 +491,36 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup
|
||||||
if (movement == mMovementState && idle == mIdleState && !force)
|
if (movement == mMovementState && idle == mIdleState && !force)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Reset idle if we actually play movement animations excepts of these cases:
|
|
||||||
// 1. When we play turning animations
|
|
||||||
// 2. When we use a fallback animation for lower body since movement animation for given weapon is missing (e.g. for crossbows and spellcasting)
|
|
||||||
bool resetIdle = (movement != CharState_None && !isTurning());
|
|
||||||
|
|
||||||
std::string movementAnimName = movementStateToAnimGroup(movement);
|
std::string movementAnimName = movementStateToAnimGroup(movement);
|
||||||
|
|
||||||
|
if (movementAnimName.empty())
|
||||||
|
{
|
||||||
|
if (!mCurrentMovement.empty())
|
||||||
|
{
|
||||||
|
mAnimation->disable(mCurrentMovement);
|
||||||
|
mCurrentMovement.clear();
|
||||||
|
}
|
||||||
|
mMovementState = CharState_None;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string::size_type swimpos = movementAnimName.find("swim");
|
||||||
|
if (!mAnimation->hasAnimation(movementAnimName))
|
||||||
|
{
|
||||||
|
if (swimpos != std::string::npos)
|
||||||
|
{
|
||||||
|
movementAnimName.erase(swimpos, 4);
|
||||||
|
swimpos = std::string::npos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MWRender::Animation::BlendMask movemask = MWRender::Animation::BlendMask_All;
|
MWRender::Animation::BlendMask movemask = MWRender::Animation::BlendMask_All;
|
||||||
|
|
||||||
if (!movementAnimName.empty())
|
if (swimpos == std::string::npos && !weapShortGroup.empty())
|
||||||
{
|
|
||||||
if(!weapShortGroup.empty())
|
|
||||||
{
|
|
||||||
std::string::size_type swimpos = movementAnimName.find("swim");
|
|
||||||
if (swimpos == std::string::npos)
|
|
||||||
{
|
{
|
||||||
std::string weapMovementAnimName;
|
std::string weapMovementAnimName;
|
||||||
if (mWeaponType == ESM::Weapon::Spell && (movement == CharState_TurnLeft || movement == CharState_TurnRight)) // Spellcasting stance turning is a special case
|
// Spellcasting stance turning is a special case
|
||||||
|
if (mWeaponType == ESM::Weapon::Spell && (movement == CharState_TurnLeft || movement == CharState_TurnRight))
|
||||||
weapMovementAnimName = weapShortGroup + movementAnimName;
|
weapMovementAnimName = weapShortGroup + movementAnimName;
|
||||||
else
|
else
|
||||||
weapMovementAnimName = movementAnimName + weapShortGroup;
|
weapMovementAnimName = movementAnimName + weapShortGroup;
|
||||||
|
@ -519,56 +532,34 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup
|
||||||
// For upper body there will be idle animation.
|
// For upper body there will be idle animation.
|
||||||
if (movemask == MWRender::Animation::BlendMask_LowerBody && idle == CharState_None)
|
if (movemask == MWRender::Animation::BlendMask_LowerBody && idle == CharState_None)
|
||||||
idle = CharState_Idle;
|
idle = CharState_Idle;
|
||||||
|
|
||||||
if (movemask == MWRender::Animation::BlendMask_LowerBody)
|
|
||||||
resetIdle = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
movementAnimName = weapMovementAnimName;
|
movementAnimName = weapMovementAnimName;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(force || movement != mMovementState)
|
if (!force && movement == mMovementState)
|
||||||
{
|
return;
|
||||||
mMovementState = movement;
|
|
||||||
if (!movementAnimName.empty())
|
|
||||||
{
|
|
||||||
if(!mAnimation->hasAnimation(movementAnimName))
|
|
||||||
{
|
|
||||||
std::string::size_type swimpos = movementAnimName.find("swim");
|
|
||||||
if (swimpos != std::string::npos)
|
|
||||||
{
|
|
||||||
movementAnimName.erase(swimpos, 4);
|
|
||||||
if (!weapShortGroup.empty())
|
|
||||||
{
|
|
||||||
std::string weapMovementAnimName = movementAnimName + weapShortGroup;
|
|
||||||
if(mAnimation->hasAnimation(weapMovementAnimName))
|
|
||||||
movementAnimName = weapMovementAnimName;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
movementAnimName = fallbackShortWeaponGroup(movementAnimName, &movemask);
|
|
||||||
if (movemask == MWRender::Animation::BlendMask_LowerBody)
|
|
||||||
resetIdle = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (swimpos == std::string::npos || !mAnimation->hasAnimation(movementAnimName))
|
if (!mAnimation->hasAnimation(movementAnimName))
|
||||||
{
|
{
|
||||||
std::string::size_type runpos = movementAnimName.find("run");
|
std::string::size_type runpos = movementAnimName.find("run");
|
||||||
if (runpos != std::string::npos)
|
if (runpos != std::string::npos)
|
||||||
{
|
|
||||||
movementAnimName.replace(runpos, 3, "walk");
|
movementAnimName.replace(runpos, 3, "walk");
|
||||||
|
|
||||||
if (!mAnimation->hasAnimation(movementAnimName))
|
if (!mAnimation->hasAnimation(movementAnimName))
|
||||||
movementAnimName.clear();
|
{
|
||||||
}
|
if (!mCurrentMovement.empty())
|
||||||
else
|
{
|
||||||
movementAnimName.clear();
|
mAnimation->disable(mCurrentMovement);
|
||||||
|
mCurrentMovement.clear();
|
||||||
}
|
}
|
||||||
|
mMovementState = CharState_None;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mMovementState = movement;
|
||||||
|
|
||||||
// If we're playing the same animation, start it from the point it ended
|
// If we're playing the same animation, start it from the point it ended
|
||||||
float startpoint = 0.f;
|
float startpoint = 0.f;
|
||||||
if (!mCurrentMovement.empty() && movementAnimName == mCurrentMovement)
|
if (!mCurrentMovement.empty() && movementAnimName == mCurrentMovement)
|
||||||
|
@ -576,17 +567,21 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup
|
||||||
|
|
||||||
mMovementAnimationControlled = true;
|
mMovementAnimationControlled = true;
|
||||||
|
|
||||||
|
if (!mCurrentMovement.empty())
|
||||||
mAnimation->disable(mCurrentMovement);
|
mAnimation->disable(mCurrentMovement);
|
||||||
|
|
||||||
if (!mAnimation->hasAnimation(movementAnimName))
|
|
||||||
movementAnimName.clear();
|
|
||||||
|
|
||||||
mCurrentMovement = movementAnimName;
|
mCurrentMovement = movementAnimName;
|
||||||
if(!mCurrentMovement.empty())
|
|
||||||
|
// Reset idle if we actually play movement animations excepts of these cases:
|
||||||
|
// 1. When we play turning animations
|
||||||
|
// 2. When we use a fallback animation for lower body since movement animation for given weapon is missing (e.g. for crossbows and spellcasting)
|
||||||
|
if (!isTurning() && movemask == MWRender::Animation::BlendMask_All)
|
||||||
{
|
{
|
||||||
if (resetIdle)
|
if (!mCurrentIdle.empty())
|
||||||
{
|
{
|
||||||
mAnimation->disable(mCurrentIdle);
|
mAnimation->disable(mCurrentIdle);
|
||||||
|
mCurrentIdle.clear();
|
||||||
|
}
|
||||||
mIdleState = CharState_None;
|
mIdleState = CharState_None;
|
||||||
idle = CharState_None;
|
idle = CharState_None;
|
||||||
}
|
}
|
||||||
|
@ -594,8 +589,7 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup
|
||||||
// For non-flying creatures, MW uses the Walk animation to calculate the animation velocity
|
// For non-flying creatures, MW uses the Walk animation to calculate the animation velocity
|
||||||
// even if we are running. This must be replicated, otherwise the observed speed would differ drastically.
|
// even if we are running. This must be replicated, otherwise the observed speed would differ drastically.
|
||||||
mAdjustMovementAnimSpeed = true;
|
mAdjustMovementAnimSpeed = true;
|
||||||
if (mPtr.getClass().getType() == ESM::Creature::sRecordId
|
if (mPtr.getClass().getType() == ESM::Creature::sRecordId && !(mPtr.get<ESM::Creature>()->mBase->mFlags & ESM::Creature::Flies))
|
||||||
&& !(mPtr.get<ESM::Creature>()->mBase->mFlags & ESM::Creature::Flies))
|
|
||||||
{
|
{
|
||||||
CharacterState walkState = runStateToWalkState(mMovementState);
|
CharacterState walkState = runStateToWalkState(mMovementState);
|
||||||
std::string anim = movementStateToAnimGroup(walkState);
|
std::string anim = movementStateToAnimGroup(walkState);
|
||||||
|
@ -628,12 +622,7 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mAnimation->play(mCurrentMovement, Priority_Movement, movemask, false,
|
mAnimation->play(mCurrentMovement, Priority_Movement, movemask, false, 1.f, "start", "stop", startpoint, ~0ul, true);
|
||||||
1.f, "start", "stop", startpoint, ~0ul, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
mMovementState = CharState_None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterController::refreshIdleAnims(const std::string& weapShortGroup, CharacterState idle, bool force)
|
void CharacterController::refreshIdleAnims(const std::string& weapShortGroup, CharacterState idle, bool force)
|
||||||
|
|
Loading…
Reference in a new issue