From 02a684cfdffa70a43cf149eb5396a0c6601a0134 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Apr 2020 11:14:00 -0400 Subject: [PATCH] CFlaahgra: Migrate static data into the cpp file Same behavior, but completely makes them internally linked. We can also make use of std::array and dehardcode some array sizes. --- Runtime/MP1/World/CFlaahgra.cpp | 66 +++++++++++++++++++++------------ Runtime/MP1/World/CFlaahgra.hpp | 11 +----- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/Runtime/MP1/World/CFlaahgra.cpp b/Runtime/MP1/World/CFlaahgra.cpp index 9d0ece782..8df1d39ac 100644 --- a/Runtime/MP1/World/CFlaahgra.cpp +++ b/Runtime/MP1/World/CFlaahgra.cpp @@ -22,14 +22,29 @@ #include "TCastTo.hpp" // Generated file, do not modify include path namespace urde::MP1 { +constexpr zeus::CColor skDamageColor{0.5f, 0.5f, 0.f, 1.f}; +constexpr zeus::CColor skUnkColor{0.5f, 0.f, 0.f, 1.f}; +constexpr zeus::CVector3f skUnkVec1{0.5f, 7.f, 0.f}; -const SJointInfo CFlaahgra::skLeftArmJointList[3]{ - {"L_elbow", "L_blade", 0.6f, 1.f}, {"L_blade", "L_claw", 0.6f, 1.f}, {"L_CLAW_LCTR", "L_CLAW_END_LCTR", 0.6f, 1.f}}; +constexpr std::array skLeftArmJointList{{ + {"L_elbow", "L_blade", 0.6f, 1.f}, + {"L_blade", "L_claw", 0.6f, 1.f}, + {"L_CLAW_LCTR", "L_CLAW_END_LCTR", 0.6f, 1.f}, +}}; -const SJointInfo CFlaahgra::skRightArmJointList[3]{ - {"R_elbow", "R_blade", 0.6f, 1.f}, {"R_blade", "R_claw", 0.6f, 1.f}, {"R_CLAW_LCTR", "R_CLAW_END_LCTR", 0.6f, 1.f}}; -const SSphereJointInfo CFlaahgra::skSphereJointList[5]{ - {"Head_1", 1.5f}, {"Spine_2", 1.5f}, {"Spine_4", 1.5f}, {"Spine_6", 1.5f}, {"Collar", 1.5f}}; +constexpr std::array skRightArmJointList{{ + {"R_elbow", "R_blade", 0.6f, 1.f}, + {"R_blade", "R_claw", 0.6f, 1.f}, + {"R_CLAW_LCTR", "R_CLAW_END_LCTR", 0.6f, 1.f}, +}}; + +constexpr std::array skSphereJointList{{ + {"Head_1", 1.5f}, + {"Spine_2", 1.5f}, + {"Spine_4", 1.5f}, + {"Spine_6", 1.5f}, + {"Collar", 1.5f}, +}}; CFlaahgraData::CFlaahgraData(CInputStream& in) : x0_(in.readFloatBig()) @@ -444,11 +459,11 @@ void CFlaahgra::GetMirrorWaypoints(CStateManager& mgr) { } } -void CFlaahgra::AddCollisionList(const SJointInfo* joints, int count, +void CFlaahgra::AddCollisionList(const SJointInfo* joints, size_t count, std::vector& outJoints) { const CAnimData* animData = GetModelData()->GetAnimationData(); - for (s32 i = 0; i < count; ++i) { + for (size_t i = 0; i < count; ++i) { const auto& joint = joints[i]; const CSegId from = animData->GetLocatorSegId(joint.from); const CSegId to = animData->GetLocatorSegId(joint.to); @@ -462,11 +477,11 @@ void CFlaahgra::AddCollisionList(const SJointInfo* joints, int count, } } -void CFlaahgra::AddSphereCollisionList(const SSphereJointInfo* joints, int count, +void CFlaahgra::AddSphereCollisionList(const SSphereJointInfo* joints, size_t count, std::vector& outJoints) { const CAnimData* animData = GetModelData()->GetAnimationData(); - for (s32 i = 0; i < count; ++i) { + for (size_t i = 0; i < count; ++i) { const auto& joint = joints[i]; const CSegId seg = animData->GetLocatorSegId(joint.name); @@ -499,20 +514,20 @@ void CFlaahgra::SetupHealthInfo(CStateManager& mgr) { void CFlaahgra::SetupCollisionManagers(CStateManager& mgr) { std::vector leftArmjointList; zeus::CVector3f oldScale = GetModelData()->GetScale(); - leftArmjointList.reserve(3); - AddCollisionList(skLeftArmJointList, 3, leftArmjointList); + leftArmjointList.reserve(skLeftArmJointList.size()); + AddCollisionList(skLeftArmJointList.data(), skLeftArmJointList.size(), leftArmjointList); x79c_leftArmCollision = std::make_unique(mgr, GetUniqueId(), GetAreaIdAlways(), leftArmjointList, true); SetMaterialProperties(x79c_leftArmCollision, mgr); std::vector rightArmJointList; - rightArmJointList.reserve(3); - AddCollisionList(skRightArmJointList, 3, rightArmJointList); + rightArmJointList.reserve(skRightArmJointList.size()); + AddCollisionList(skRightArmJointList.data(), skRightArmJointList.size(), rightArmJointList); x7a0_rightArmCollision = std::make_unique(mgr, GetUniqueId(), GetAreaIdAlways(), rightArmJointList, true); SetMaterialProperties(x7a0_rightArmCollision, mgr); std::vector sphereJointList; - sphereJointList.reserve(5); - AddSphereCollisionList(skSphereJointList, 5, sphereJointList); + sphereJointList.reserve(skSphereJointList.size()); + AddSphereCollisionList(skSphereJointList.data(), skSphereJointList.size(), sphereJointList); x7a4_sphereCollision = std::make_unique(mgr, GetUniqueId(), GetAreaIdAlways(), sphereJointList, true); SetMaterialProperties(x7a4_sphereCollision, mgr); @@ -872,7 +887,8 @@ void CFlaahgra::RattlePlayer(CStateManager& mgr, const zeus::CVector3f& vec) { } void CFlaahgra::Faint(CStateManager& mgr, EStateMsg msg, float arg) { - static const pas::ESeverity kSeverities[2]{pas::ESeverity::Zero, pas::ESeverity::One}; + static constexpr std::array kSeverities{pas::ESeverity::Zero, pas::ESeverity::One}; + if (msg == EStateMsg::Activate) { x568_ = 0; x7d4_ = 0.f; @@ -881,7 +897,7 @@ void CFlaahgra::Faint(CStateManager& mgr, EStateMsg msg, float arg) { SendScriptMsgs(EScriptObjectState::Entered, mgr, EScriptObjectMessage::None); SendScriptMsgs(EScriptObjectState::Retreat, mgr, EScriptObjectMessage::None); x450_bodyController->GetCommandMgr().DeliverCmd( - CBCKnockDownCmd(-GetTransform().frontVector(), kSeverities[u32(x7ac_)])); + CBCKnockDownCmd(-GetTransform().frontVector(), kSeverities[size_t(x7ac_)])); } else if (msg == EStateMsg::Update) { if (x568_ == 0) { if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::Fall) { @@ -890,7 +906,7 @@ void CFlaahgra::Faint(CStateManager& mgr, EStateMsg msg, float arg) { UpdateHeadDamageVulnerability(mgr, true); } else { x450_bodyController->GetCommandMgr().DeliverCmd( - CBCKnockDownCmd(-GetTransform().frontVector(), kSeverities[u32(x7ac_)])); + CBCKnockDownCmd(-GetTransform().frontVector(), kSeverities[size_t(x7ac_)])); } } else if (x568_ == 2) { if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::LieOnGround) { @@ -942,12 +958,14 @@ void CFlaahgra::Dead(CStateManager& mgr, EStateMsg msg, float) { } } -static const pas::ESeverity kStates1[5]{pas::ESeverity::Invalid, pas::ESeverity::Invalid, pas::ESeverity::Invalid, - pas::ESeverity::Two, pas::ESeverity::Invalid}; - void CFlaahgra::Attack(CStateManager& mgr, EStateMsg msg, float arg) { - static const pas::ESeverity kSeverity[5]{pas::ESeverity::Three, pas::ESeverity::Four, pas::ESeverity::One, - pas::ESeverity::Zero, pas::ESeverity::Invalid}; + static constexpr std::array kStates1{ + pas::ESeverity::Invalid, pas::ESeverity::Invalid, pas::ESeverity::Invalid, + pas::ESeverity::Two, pas::ESeverity::Invalid, + }; + static constexpr std::array kSeverity{ + pas::ESeverity::Three, pas::ESeverity::Four, pas::ESeverity::One, pas::ESeverity::Zero, pas::ESeverity::Invalid, + }; if (msg == EStateMsg::Activate) { x568_ = 0; diff --git a/Runtime/MP1/World/CFlaahgra.hpp b/Runtime/MP1/World/CFlaahgra.hpp index b8f0e32d0..24bbfcd20 100644 --- a/Runtime/MP1/World/CFlaahgra.hpp +++ b/Runtime/MP1/World/CFlaahgra.hpp @@ -86,13 +86,6 @@ public: }; class CFlaahgra : public CPatterned { - - static const SJointInfo skLeftArmJointList[3]; - static const SJointInfo skRightArmJointList[3]; - static const SSphereJointInfo skSphereJointList[5]; - static constexpr zeus::CColor skDamageColor = zeus::CColor(0.5f, 0.5f, 0.f, 1.f); - static constexpr zeus::CColor skUnkColor = zeus::CColor(0.5f, 0.f, 0.f, 1.f); - static constexpr zeus::CVector3f skUnkVec1 = zeus::CVector3f(0.5f, 7.f, 0.f); s32 x568_ = -1; CFlaahgraData x56c_; std::unique_ptr x6cc_boneTracking; // Used to be an rstl::pair @@ -163,8 +156,8 @@ class CFlaahgra : public CPatterned { void LoadTokens(CStateManager& mgr); void FinalizeLoad(CStateManager& mgr); void GetMirrorWaypoints(CStateManager& mgr); - void AddCollisionList(const SJointInfo*, int, std::vector&); - void AddSphereCollisionList(const SSphereJointInfo*, int, std::vector&); + void AddCollisionList(const SJointInfo*, size_t, std::vector&); + void AddSphereCollisionList(const SSphereJointInfo*, size_t, std::vector&); void SetupCollisionManagers(CStateManager&); void sub801ae980(CStateManager&); void UpdateCollisionManagers(float, CStateManager&);