From c60290819e71407d1caf17aef0addcfaa160b40b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 11 May 2020 18:39:21 -0400 Subject: [PATCH] CMorphBall: Collapse common code within ApplyGravity() All that differs between the conditionals is the gravity value used, so we can collapse all of this down to simply conditionally retrieve that. --- Runtime/World/CMorphBall.cpp | 13 +++++++------ Runtime/World/CMorphBall.hpp | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Runtime/World/CMorphBall.cpp b/Runtime/World/CMorphBall.cpp index d2f010a0d..0ccde6073 100644 --- a/Runtime/World/CMorphBall.cpp +++ b/Runtime/World/CMorphBall.cpp @@ -2168,12 +2168,13 @@ float CMorphBall::CalculateSurfaceFriction() const { return friction; } -void CMorphBall::ApplyGravity(CStateManager& mgr) { - if (x0_player.CheckSubmerged() && !mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit)) { - x0_player.SetMomentumWR(zeus::CVector3f(0.f, 0.f, g_tweakBall->GetBallWaterGravity() * x0_player.GetMass())); - } else { - x0_player.SetMomentumWR(zeus::CVector3f(0.f, 0.f, g_tweakBall->GetBallGravity() * x0_player.GetMass())); - } +void CMorphBall::ApplyGravity(const CStateManager& mgr) { + const float mass = x0_player.GetMass(); + const bool hasGravitySuit = mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit); + const bool useWaterGravity = x0_player.CheckSubmerged() && !hasGravitySuit; + const float gravity = useWaterGravity ? g_tweakBall->GetBallWaterGravity() : g_tweakBall->GetBallGravity(); + + x0_player.SetMomentumWR(zeus::CVector3f(0.f, 0.f, gravity * mass)); } void CMorphBall::SpinToSpeed(float holdMag, const zeus::CVector3f& torque, float mag) { diff --git a/Runtime/World/CMorphBall.hpp b/Runtime/World/CMorphBall.hpp index fe6153089..2d66e143c 100644 --- a/Runtime/World/CMorphBall.hpp +++ b/Runtime/World/CMorphBall.hpp @@ -249,7 +249,7 @@ public: void ComputeLiftForces(const zeus::CVector3f& controlForce, const zeus::CVector3f& velocity, const CStateManager& mgr); float CalculateSurfaceFriction() const; - void ApplyGravity(CStateManager& mgr); + void ApplyGravity(const CStateManager& mgr); void SpinToSpeed(float holdMag, const zeus::CVector3f& torque, float mag); float ComputeMaxSpeed() const; void Touch(CActor& actor, CStateManager& mgr);