From b8018024a690da86c4a5cead5d316f576246e632 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Mon, 13 Jun 2022 16:21:48 +0300 Subject: [PATCH] Avoid passing weapon short group to refreshXAnims --- apps/openmw/mwmechanics/character.cpp | 31 ++++++++++++++++----------- apps/openmw/mwmechanics/character.hpp | 7 +++--- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 2a975fa649..2e3777e5b0 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -425,7 +425,7 @@ void CharacterController::refreshHitRecoilAnims(CharacterState& idle) idle = CharState_None; } -void CharacterController::refreshJumpAnims(const std::string& weapShortGroup, JumpingState jump, CharacterState& idle, bool force) +void CharacterController::refreshJumpAnims(JumpingState jump, CharacterState& idle, bool force) { if (!force && jump == mJumpState && idle == CharState_None) return; @@ -436,6 +436,7 @@ void CharacterController::refreshJumpAnims(const std::string& weapShortGroup, Ju return; } + std::string weapShortGroup = getWeaponShortGroup(mWeaponType); std::string jumpAnimName = "jump" + weapShortGroup; MWRender::Animation::BlendMask jumpmask = MWRender::Animation::BlendMask_All; if (!weapShortGroup.empty() && !mAnimation->hasAnimation(jumpAnimName)) @@ -525,6 +526,13 @@ std::string CharacterController::getWeaponAnimation(int weaponType) const return weaponGroup; } +std::string CharacterController::getWeaponShortGroup(int weaponType) const +{ + if (weaponType == ESM::Weapon::HandToHand && !mPtr.getClass().isBipedal(mPtr)) + return {}; + return getWeaponType(weaponType)->mShortGroup; +} + std::string CharacterController::fallbackShortWeaponGroup(const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask) const { bool isRealWeapon = mWeaponType != ESM::Weapon::HandToHand && mWeaponType != ESM::Weapon::Spell && mWeaponType != ESM::Weapon::None; @@ -536,8 +544,8 @@ std::string CharacterController::fallbackShortWeaponGroup(const std::string& bas return baseGroupName; } - static const std::string oneHandFallback = getWeaponType(ESM::Weapon::LongBladeOneHand)->mShortGroup; - static const std::string twoHandFallback = getWeaponType(ESM::Weapon::LongBladeTwoHand)->mShortGroup; + static const std::string oneHandFallback = getWeaponShortGroup(ESM::Weapon::LongBladeOneHand); + static const std::string twoHandFallback = getWeaponShortGroup(ESM::Weapon::LongBladeTwoHand); std::string groupName = baseGroupName; const ESM::WeaponType* weapInfo = getWeaponType(mWeaponType); @@ -562,7 +570,7 @@ std::string CharacterController::fallbackShortWeaponGroup(const std::string& bas return groupName; } -void CharacterController::refreshMovementAnims(const std::string& weapShortGroup, CharacterState movement, CharacterState& idle, bool force) +void CharacterController::refreshMovementAnims(CharacterState movement, CharacterState& idle, bool force) { if (movement == mMovementState && idle == mIdleState && !force) return; @@ -587,6 +595,7 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup MWRender::Animation::BlendMask movemask = MWRender::Animation::BlendMask_All; + std::string weapShortGroup = getWeaponShortGroup(mWeaponType); if (swimpos == std::string::npos && !weapShortGroup.empty()) { std::string weapMovementAnimName; @@ -684,7 +693,7 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup 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) +void CharacterController::refreshIdleAnims(CharacterState idle, bool force) { // FIXME: if one of the below states is close to their last animation frame (i.e. will be disabled in the coming update), // the idle animation should be displayed @@ -714,6 +723,7 @@ void CharacterController::refreshIdleAnims(const std::string& weapShortGroup, Ch return; } + std::string weapShortGroup = getWeaponShortGroup(mWeaponType); if (mIdleState != CharState_IdleSwim && mIdleState != CharState_IdleSneak && mIdleState != CharState_None && !weapShortGroup.empty()) { std::string weapIdleGroup = idleGroup + weapShortGroup; @@ -751,16 +761,11 @@ void CharacterController::refreshCurrentAnims(CharacterState idle, CharacterStat return; refreshHitRecoilAnims(idle); - - std::string weap; - if (mWeaponType != ESM::Weapon::HandToHand || mPtr.getClass().isBipedal(mPtr)) - weap = getWeaponType(mWeaponType)->mShortGroup; - - refreshJumpAnims(weap, jump, idle, force); - refreshMovementAnims(weap, movement, idle, force); + refreshJumpAnims(jump, idle, force); + refreshMovementAnims(movement, idle, force); // idle handled last as it can depend on the other states - refreshIdleAnims(weap, idle, force); + refreshIdleAnims(idle, force); } void CharacterController::playDeath(float startpoint, CharacterState death) diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 1f1effed28..bd9fa70711 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -207,9 +207,9 @@ class CharacterController : public MWRender::Animation::TextKeyListener void refreshCurrentAnims(CharacterState idle, CharacterState movement, JumpingState jump, bool force=false); void refreshHitRecoilAnims(CharacterState& idle); - void refreshJumpAnims(const std::string& weapShortGroup, JumpingState jump, CharacterState& idle, bool force=false); - void refreshMovementAnims(const std::string& weapShortGroup, CharacterState movement, CharacterState& idle, bool force=false); - void refreshIdleAnims(const std::string& weapShortGroup, CharacterState idle, bool force=false); + void refreshJumpAnims(JumpingState jump, CharacterState& idle, bool force=false); + void refreshMovementAnims(CharacterState movement, CharacterState& idle, bool force=false); + void refreshIdleAnims(CharacterState idle, bool force=false); void clearAnimQueue(bool clearPersistAnims = false); @@ -240,6 +240,7 @@ class CharacterController : public MWRender::Animation::TextKeyListener std::string fallbackShortWeaponGroup(const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask = nullptr) const; std::string getWeaponAnimation(int weaponType) const; + std::string getWeaponShortGroup(int weaponType) const; bool getAttackingOrSpell() const; void setAttackingOrSpell(bool attackingOrSpell) const;