From 3717480eebe9021eae5741dbef17bec1881a1d63 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 5 Mar 2020 23:18:27 -0500 Subject: [PATCH] CThardus: Make use of std::array where applicable Dehardcodes some sizes and gets rid of two instances of implicit sign conversions. --- Runtime/MP1/World/CThardus.cpp | 39 +++++++++++++++++++--------------- Runtime/MP1/World/CThardus.hpp | 4 ++-- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/Runtime/MP1/World/CThardus.cpp b/Runtime/MP1/World/CThardus.cpp index b01b35d17..9a78f1018 100644 --- a/Runtime/MP1/World/CThardus.cpp +++ b/Runtime/MP1/World/CThardus.cpp @@ -1,5 +1,7 @@ #include "Runtime/MP1/World/CThardus.hpp" +#include + #include "Runtime/Camera/CCameraManager.hpp" #include "Runtime/Camera/CFirstPersonCamera.hpp" #include "Runtime/Collision/CCollisionActor.hpp" @@ -21,9 +23,8 @@ #include namespace urde::MP1 { - namespace { -constexpr SSphereJointInfo skDamageableSphereJointInfoList1[7] = { +constexpr std::array skDamageableSphereJointInfoList1{{ {"R_Knee", 1.f}, {"R_Elbow_Collision_LCTR", 1.5f}, {"L_Elbow_Collision_LCTR", 1.5f}, @@ -31,19 +32,22 @@ constexpr SSphereJointInfo skDamageableSphereJointInfoList1[7] = { {"R_Back_Rock_Collision_LCTR", 2.5f}, {"L_Back_Rock_Collision_LCTR", 1.5f}, {"Head_Collision_LCTR", 1.5f}, -}; +}}; -constexpr SSphereJointInfo skDamageableSphereJointInfoList2[5] = { - {"R_Shoulder_Collision_LCTR", 0.75f}, {"L_Shoulder_Collision_LCTR", 0.75f}, {"Spine_Collision_LCTR", 0.75f}, - {"R_Hand_Collision_LCTR", 2.25f}, {"L_Hand_Collision_LCTR", 2.f}, -}; +constexpr std::array skDamageableSphereJointInfoList2{{ + {"R_Shoulder_Collision_LCTR", 0.75f}, + {"L_Shoulder_Collision_LCTR", 0.75f}, + {"Spine_Collision_LCTR", 0.75f}, + {"R_Hand_Collision_LCTR", 2.25f}, + {"L_Hand_Collision_LCTR", 2.f}, +}}; -constexpr SAABoxJointInfo skFootCollision[2] = { +constexpr std::array skFootCollision{{ {"R_Foot_Collision_LCTR", zeus::CVector3f(3.f, 3.f, 1.f)}, {"L_Foot_Collision_LCTR", zeus::CVector3f(3.f, 2.f, 3.f)}, -}; +}}; -constexpr std::array skSearchJointNames = { +constexpr std::array skSearchJointNames{ "R_Knee"sv, "R_Elbow_Collision_LCTR"sv, "L_Elbow_Collision_LCTR"sv, @@ -53,10 +57,11 @@ constexpr std::array skSearchJointNames = { "Head_Collision_LCTR"sv, }; -constexpr std::array skRockJoints = { +constexpr std::array skRockJoints{ "R_knee"sv, "R_forearm"sv, "L_elbow"sv, "L_hip"sv, "R_collar_BigRock_SDK"sv, "collar_rock4_SDK"sv, "Neck_1"sv, }; -} // namespace +} // Anonymous namespace + CThardus::CThardus(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& actParms, const CPatternedInfo& pInfo, const std::vector& mData1, const std::vector& mData2, CAssetId particle1, @@ -797,7 +802,7 @@ void CThardus::GatherWaypoints(urde::CScriptWaypoint* wp, urde::CStateManager& m } } -void CThardus::_BuildSphereJointList(const SSphereJointInfo* arr, int count, +void CThardus::_BuildSphereJointList(const SSphereJointInfo* arr, size_t count, std::vector& list) { for (size_t i = 0; i < count; ++i) { const auto& jInfo = arr[i]; @@ -806,7 +811,7 @@ void CThardus::_BuildSphereJointList(const SSphereJointInfo* arr, int count, } } -void CThardus::_BuildAABoxJointList(const SAABoxJointInfo* arr, int count, +void CThardus::_BuildAABoxJointList(const SAABoxJointInfo* arr, size_t count, std::vector& list) { for (size_t i = 0; i < count; ++i) { const auto& jInfo = arr[i]; @@ -835,15 +840,15 @@ void CThardus::_SetupCollisionActorMaterials(const std::unique_ptr list; - _BuildSphereJointList(skDamageableSphereJointInfoList1, 7, list); + _BuildSphereJointList(skDamageableSphereJointInfoList1.data(), skDamageableSphereJointInfoList1.size(), list); x5f0_rockColliders = std::make_unique(mgr, GetUniqueId(), GetAreaIdAlways(), list, true); _SetupCollisionActorMaterials(x5f0_rockColliders, mgr); list.clear(); - _BuildSphereJointList(skDamageableSphereJointInfoList2, 5, list); + _BuildSphereJointList(skDamageableSphereJointInfoList2.data(), skDamageableSphereJointInfoList2.size(), list); x5f4_ = std::make_unique(mgr, GetUniqueId(), GetAreaIdAlways(), list, true); _SetupCollisionActorMaterials(x5f4_, mgr); list.clear(); - _BuildAABoxJointList(skFootCollision, 2, list); + _BuildAABoxJointList(skFootCollision.data(), skFootCollision.size(), list); x5f8_ = std::make_unique(mgr, GetUniqueId(), GetAreaIdAlways(), list, true); _SetupCollisionActorMaterials(x5f8_, mgr); list.clear(); diff --git a/Runtime/MP1/World/CThardus.hpp b/Runtime/MP1/World/CThardus.hpp index c6d026d4c..07bf97191 100644 --- a/Runtime/MP1/World/CThardus.hpp +++ b/Runtime/MP1/World/CThardus.hpp @@ -157,8 +157,8 @@ class CThardus : public CPatterned { EMaterialTypes mat, CStateManager& mgr); void _SetupCollisionActorMaterials(const std::unique_ptr& colMgr, CStateManager& mgr); void _SetupCollisionManagers(CStateManager& mgr); - void _BuildSphereJointList(const SSphereJointInfo* arr, int count, std::vector& list); - void _BuildAABoxJointList(const SAABoxJointInfo* arr, int count, std::vector& list); + void _BuildSphereJointList(const SSphereJointInfo* arr, size_t count, std::vector& list); + void _BuildAABoxJointList(const SAABoxJointInfo* arr, size_t count, std::vector& list); void RenderFlare(const CStateManager& mgr, float t) const; zeus::CVector3f sub801de550(const CStateManager& mgr) const; zeus::CVector3f sub801de434(const CStateManager& mgr) const { return {}; }