From b55d1e4c7798b80d5385872978daf5ff796f2c4a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 17 Apr 2020 01:03:10 -0400 Subject: [PATCH] CKnockBackController: Make use of const references where applicable In many cases the CPatterned& parameter is only used for read-only querying. We can make this explicit in the interface. --- Runtime/World/CKnockBackController.cpp | 21 ++++++++++++--------- Runtime/World/CKnockBackController.hpp | 6 +++--- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Runtime/World/CKnockBackController.cpp b/Runtime/World/CKnockBackController.cpp index 8de40cd51..3792ad3f2 100644 --- a/Runtime/World/CKnockBackController.cpp +++ b/Runtime/World/CKnockBackController.cpp @@ -407,7 +407,7 @@ EKnockBackCharacterState CKnockBackController::GetKnockBackCharacterState(const return parent.IsAlive() ? EKnockBackCharacterState::Alive : EKnockBackCharacterState::Dead; } -void CKnockBackController::ValidateState(CPatterned& parent) { +void CKnockBackController::ValidateState(const CPatterned& parent) { if (x4_activeParms.x0_animState < x18_minAnimState) x4_activeParms.x0_animState = x18_minAnimState; else if (x4_activeParms.x0_animState > x1c_maxAnimState) @@ -518,7 +518,8 @@ void CKnockBackController::DoKnockBackAnimation(const zeus::CVector3f& backVec, } } -void CKnockBackController::ResetKnockBackImpulse(CPatterned& parent, const zeus::CVector3f& backVec, float magnitude) { +void CKnockBackController::ResetKnockBackImpulse(const CPatterned& parent, const zeus::CVector3f& backVec, + float magnitude) { if (x81_24_autoResetImpulse && x4_activeParms.x0_animState == EKnockBackAnimationState::KnockBack && x4_activeParms.x4_animFollowup != EKnockBackAnimationFollowUp::Freeze) { x50_impulseDir = backVec.canBeNormalized() ? backVec.normalized() : -parent.GetTransform().basis[1]; @@ -609,16 +610,18 @@ EKnockBackWeaponType CKnockBackController::GetKnockBackWeaponType(const CDamageI } } -void CKnockBackController::SelectDamageState(CPatterned& parent, const CDamageInfo& info, EWeaponType wType, +void CKnockBackController::SelectDamageState(const CPatterned& parent, const CDamageInfo& info, EWeaponType wType, EKnockBackType type) { - x4_activeParms = KnockBackParms(); - EKnockBackWeaponType weaponType = GetKnockBackWeaponType(info, wType, type); - if (weaponType != EKnockBackWeaponType::Invalid) { - x4_activeParms = - KnockBackParmsTable[size_t(x0_variant)][size_t(weaponType)][size_t(GetKnockBackCharacterState(parent))]; - ValidateState(parent); + + const EKnockBackWeaponType weaponType = GetKnockBackWeaponType(info, wType, type); + if (weaponType == EKnockBackWeaponType::Invalid) { + return; } + + x4_activeParms = + KnockBackParmsTable[size_t(x0_variant)][size_t(weaponType)][size_t(GetKnockBackCharacterState(parent))]; + ValidateState(parent); } void CKnockBackController::KnockBack(const zeus::CVector3f& backVec, CStateManager& mgr, CPatterned& parent, diff --git a/Runtime/World/CKnockBackController.hpp b/Runtime/World/CKnockBackController.hpp index 54c8b30c2..07fc160cc 100644 --- a/Runtime/World/CKnockBackController.hpp +++ b/Runtime/World/CKnockBackController.hpp @@ -100,13 +100,13 @@ private: void ApplyImpulse(float dt, CPatterned& parent); bool TickDeferredTimer(float dt); EKnockBackCharacterState GetKnockBackCharacterState(const CPatterned& parent) const; - void ValidateState(CPatterned& parent); + void ValidateState(const CPatterned& parent); float CalculateExtraHurlVelocity(CStateManager& mgr, float magnitude, float kbResistance); void DoKnockBackAnimation(const zeus::CVector3f& backVec, CStateManager& mgr, CPatterned& parent, float magnitude); - void ResetKnockBackImpulse(CPatterned& parent, const zeus::CVector3f& backVec, float magnitude); + void ResetKnockBackImpulse(const CPatterned& parent, const zeus::CVector3f& backVec, float magnitude); void DoDeferredKnockBack(CStateManager& mgr, CPatterned& parent); EKnockBackWeaponType GetKnockBackWeaponType(const CDamageInfo& info, EWeaponType wType, EKnockBackType type); - void SelectDamageState(CPatterned& parent, const CDamageInfo& info, EWeaponType wType, EKnockBackType type); + void SelectDamageState(const CPatterned& parent, const CDamageInfo& info, EWeaponType wType, EKnockBackType type); public: explicit CKnockBackController(EKnockBackVariant variant);