From 71e3fb181789186fc01cb45d9c56c541212dfc1c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 5 Apr 2020 03:20:52 -0400 Subject: [PATCH] CBodyState: Eliminate usages of const_cast This is clearly modifying the command, so we should allow for modifying of command instances if necessary. --- Runtime/Character/CBodyState.cpp | 6 ++++-- Runtime/Character/CBodyStateCmdMgr.hpp | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Runtime/Character/CBodyState.cpp b/Runtime/Character/CBodyState.cpp index 040d1c079..fe7288e8b 100644 --- a/Runtime/Character/CBodyState.cpp +++ b/Runtime/Character/CBodyState.cpp @@ -1120,12 +1120,14 @@ pas::EAnimationState CBSHurled::GetBodyStateTransition(float dt, CBodyController if (bc.GetCommandMgr().GetCmd(EBodyStateCmd::NextState)) { return pas::EAnimationState::LieOnGround; } + if (x18_curTime > 0.25f) { - if (const auto* cmd = static_cast(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled))) { - const_cast(cmd)->SetSkipLaunchState(true); + if (auto* cmd = static_cast(bc.GetCommandMgr().GetCmd(EBodyStateCmd::Hurled))) { + cmd->SetSkipLaunchState(true); return pas::EAnimationState::Hurled; } } + return pas::EAnimationState::Invalid; } diff --git a/Runtime/Character/CBodyStateCmdMgr.hpp b/Runtime/Character/CBodyStateCmdMgr.hpp index a6ba84eef..17f4e5af5 100644 --- a/Runtime/Character/CBodyStateCmdMgr.hpp +++ b/Runtime/Character/CBodyStateCmdMgr.hpp @@ -452,11 +452,20 @@ public: void BlendSteeringCmds(); void Reset(); void ClearLocomotionCmds(); - const CBodyStateCmd* GetCmd(EBodyStateCmd cmd) const { - if (xb4_deliveredCmdMask & (1 << int(cmd))) - return x40_commandTable[int(cmd)]; + + CBodyStateCmd* GetCmd(EBodyStateCmd cmd) { + if ((xb4_deliveredCmdMask & (1U << u32(cmd))) != 0) { + return x40_commandTable[size_t(cmd)]; + } return nullptr; } + const CBodyStateCmd* GetCmd(EBodyStateCmd cmd) const { + if ((xb4_deliveredCmdMask & (1U << u32(cmd))) != 0) { + return x40_commandTable[size_t(cmd)]; + } + return nullptr; + } + const zeus::CVector3f& GetMoveVector() const { return x0_move; } const zeus::CVector3f& GetFaceVector() const { return xc_face; } const zeus::CVector3f& GetTargetVector() const { return x18_target; }