mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-27 03:35:27 +00:00
Consolidate refreshMovementAnims()
This commit is contained in:
parent
7a390a359f
commit
9e6b7fed1a
@ -491,23 +491,36 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup
|
||||
if (movement == mMovementState && idle == mIdleState && !force)
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
if (!movementAnimName.empty())
|
||||
{
|
||||
if(!weapShortGroup.empty())
|
||||
{
|
||||
std::string::size_type swimpos = movementAnimName.find("swim");
|
||||
if (swimpos == std::string::npos)
|
||||
if (swimpos == std::string::npos && !weapShortGroup.empty())
|
||||
{
|
||||
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;
|
||||
else
|
||||
weapMovementAnimName = movementAnimName + weapShortGroup;
|
||||
@ -519,56 +532,34 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup
|
||||
// For upper body there will be idle animation.
|
||||
if (movemask == MWRender::Animation::BlendMask_LowerBody && idle == CharState_None)
|
||||
idle = CharState_Idle;
|
||||
|
||||
if (movemask == MWRender::Animation::BlendMask_LowerBody)
|
||||
resetIdle = false;
|
||||
}
|
||||
|
||||
movementAnimName = weapMovementAnimName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(force || movement != mMovementState)
|
||||
{
|
||||
mMovementState = movement;
|
||||
if (!movementAnimName.empty())
|
||||
{
|
||||
if (!force && movement == mMovementState)
|
||||
return;
|
||||
|
||||
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))
|
||||
{
|
||||
std::string::size_type runpos = movementAnimName.find("run");
|
||||
if (runpos != std::string::npos)
|
||||
{
|
||||
movementAnimName.replace(runpos, 3, "walk");
|
||||
|
||||
if (!mAnimation->hasAnimation(movementAnimName))
|
||||
movementAnimName.clear();
|
||||
}
|
||||
else
|
||||
movementAnimName.clear();
|
||||
{
|
||||
if (!mCurrentMovement.empty())
|
||||
{
|
||||
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
|
||||
float startpoint = 0.f;
|
||||
if (!mCurrentMovement.empty() && movementAnimName == mCurrentMovement)
|
||||
@ -576,17 +567,21 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup
|
||||
|
||||
mMovementAnimationControlled = true;
|
||||
|
||||
if (!mCurrentMovement.empty())
|
||||
mAnimation->disable(mCurrentMovement);
|
||||
|
||||
if (!mAnimation->hasAnimation(movementAnimName))
|
||||
movementAnimName.clear();
|
||||
|
||||
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);
|
||||
mCurrentIdle.clear();
|
||||
}
|
||||
mIdleState = 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
|
||||
// even if we are running. This must be replicated, otherwise the observed speed would differ drastically.
|
||||
mAdjustMovementAnimSpeed = true;
|
||||
if (mPtr.getClass().getType() == ESM::Creature::sRecordId
|
||||
&& !(mPtr.get<ESM::Creature>()->mBase->mFlags & ESM::Creature::Flies))
|
||||
if (mPtr.getClass().getType() == ESM::Creature::sRecordId && !(mPtr.get<ESM::Creature>()->mBase->mFlags & ESM::Creature::Flies))
|
||||
{
|
||||
CharacterState walkState = runStateToWalkState(mMovementState);
|
||||
std::string anim = movementStateToAnimGroup(walkState);
|
||||
@ -628,12 +622,7 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup
|
||||
}
|
||||
}
|
||||
|
||||
mAnimation->play(mCurrentMovement, Priority_Movement, movemask, false,
|
||||
1.f, "start", "stop", startpoint, ~0ul, true);
|
||||
}
|
||||
else
|
||||
mMovementState = CharState_None;
|
||||
}
|
||||
mAnimation->play(mCurrentMovement, Priority_Movement, movemask, false, 1.f, "start", "stop", startpoint, ~0ul, true);
|
||||
}
|
||||
|
||||
void CharacterController::refreshIdleAnims(const std::string& weapShortGroup, CharacterState idle, bool force)
|
||||
|
Loading…
x
Reference in New Issue
Block a user