From d9540c31ce45dfa72127df61eb51303d2d7ecbae Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 14 May 2020 21:58:10 -0400 Subject: [PATCH 01/16] CElitePirate: Simplify IsArmClawCollider() We can collapse this down into a std::any_of call. --- Runtime/MP1/World/CElitePirate.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Runtime/MP1/World/CElitePirate.cpp b/Runtime/MP1/World/CElitePirate.cpp index 8d3602796..077c530ac 100644 --- a/Runtime/MP1/World/CElitePirate.cpp +++ b/Runtime/MP1/World/CElitePirate.cpp @@ -1,5 +1,8 @@ #include "Runtime/MP1/World/CElitePirate.hpp" +#include +#include + #include "Runtime/Camera/CFirstPersonCamera.hpp" #include "Runtime/Collision/CCollisionActor.hpp" #include "Runtime/Collision/CCollisionActorManager.hpp" @@ -884,12 +887,7 @@ bool CElitePirate::IsArmClawCollider(std::string_view name, std::string_view loc if (name == locator) { return true; } - for (size_t i = 0; i < infoCount; ++i) { - if (name == info[i].from) { - return true; - } - } - return false; + return std::any_of(info, info + infoCount, [&name](const auto& entry) { return entry.from == name; }); } void CElitePirate::CreateGrenadeLauncher(CStateManager& mgr, TUniqueId uid) { From 7d3b43712ddb33d7db2213730e8a3d7c71bc1f41 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 14 May 2020 22:09:56 -0400 Subject: [PATCH 02/16] CElitePirate: Make IsArmClawCollider internally linked We can fully collapse this into a helper function and simplify the parameters on it. --- Runtime/MP1/World/CElitePirate.cpp | 35 +++++++++++++++--------------- Runtime/MP1/World/CElitePirate.hpp | 3 --- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Runtime/MP1/World/CElitePirate.cpp b/Runtime/MP1/World/CElitePirate.cpp index 077c530ac..e8e6f911b 100644 --- a/Runtime/MP1/World/CElitePirate.cpp +++ b/Runtime/MP1/World/CElitePirate.cpp @@ -42,7 +42,22 @@ constexpr std::array skSphereJointList{{ {"L_Ball", 0.8f}, {"R_Ball", 0.8f}, }}; -} // namespace + +// The following used to be member functions, but are made internal as +// they alter no internal state. + +// Used to be a member function with a pointer and size in GM8Ev0 +bool IsArmClawCollider(std::string_view name, std::string_view locator, const std::array& info) { + if (name == locator) { + return true; + } + return std::any_of(info.cbegin(), info.cend(), [&name](const auto& entry) { return entry.from == name; }); +} + +bool IsArmClawCollider(TUniqueId uid, const rstl::reserved_vector& vec) { + return std::find(vec.cbegin(), vec.cend(), uid) != vec.cend(); +} +} // Anonymous namespace CElitePirateData::CElitePirateData(CInputStream& in, u32 propCount) : x0_tauntInterval(in.readFloatBig()) @@ -787,10 +802,6 @@ void CElitePirate::SetShotAt(bool val, CStateManager& mgr) { } } -bool CElitePirate::IsArmClawCollider(TUniqueId uid, const rstl::reserved_vector& vec) const { - return std::find(vec.begin(), vec.end(), uid) != vec.end(); -} - void CElitePirate::AddCollisionList(const SJointInfo* joints, size_t count, std::vector& outJoints) const { const CAnimData* animData = GetModelData()->GetAnimationData(); @@ -858,11 +869,9 @@ void CElitePirate::SetupCollisionActorInfo(CStateManager& mgr) { if (TCastToPtr act = mgr.ObjectById(uid)) { if (colDesc.GetName() == "Head_1"sv) { x770_collisionHeadId = uid; - } else if (IsArmClawCollider(colDesc.GetName(), "R_Palm_LCTR"sv, skRightArmJointList.data(), - skRightArmJointList.size())) { + } else if (IsArmClawCollider(colDesc.GetName(), "R_Palm_LCTR"sv, skRightArmJointList)) { x774_collisionRJointIds.push_back(uid); - } else if (IsArmClawCollider(colDesc.GetName(), "L_Palm_LCTR"sv, skLeftArmJointList.data(), - skLeftArmJointList.size())) { + } else if (IsArmClawCollider(colDesc.GetName(), "L_Palm_LCTR"sv, skLeftArmJointList)) { x788_collisionLJointIds.push_back(uid); } if (uid != x770_collisionHeadId) { @@ -882,14 +891,6 @@ void CElitePirate::SetupCollisionActorInfo(CStateManager& mgr) { x5d4_collisionActorMgr->AddMaterial(mgr, {EMaterialTypes::AIJoint, EMaterialTypes::CameraPassthrough}); } -bool CElitePirate::IsArmClawCollider(std::string_view name, std::string_view locator, const SJointInfo* info, - size_t infoCount) const { - if (name == locator) { - return true; - } - return std::any_of(info, info + infoCount, [&name](const auto& entry) { return entry.from == name; }); -} - void CElitePirate::CreateGrenadeLauncher(CStateManager& mgr, TUniqueId uid) { const CAnimationParameters& params = x5d8_data.GetLauncherAnimParams(); if (!params.GetACSFile().IsValid()) { diff --git a/Runtime/MP1/World/CElitePirate.hpp b/Runtime/MP1/World/CElitePirate.hpp index c3d3b506a..7d954e828 100644 --- a/Runtime/MP1/World/CElitePirate.hpp +++ b/Runtime/MP1/World/CElitePirate.hpp @@ -220,15 +220,12 @@ protected: const CCollisionActorManager& GetCollisionActorManager() const { return *x5d4_collisionActorMgr; } private: - bool IsArmClawCollider(TUniqueId uid, const rstl::reserved_vector& vec) const; void AddSphereCollisionList(const SSphereJointInfo* joints, size_t count, std::vector& outJoints) const; void AddCollisionList(const SJointInfo* joints, size_t count, std::vector& outJoints) const; void SetupCollisionManager(CStateManager& mgr); void SetupCollisionActorInfo(CStateManager& mgr); - bool IsArmClawCollider(std::string_view name, std::string_view locator, const SJointInfo* info, - size_t infoCount) const; void ApplyDamageToHead(CStateManager& mgr, TUniqueId uid); void CreateEnergyAbsorb(CStateManager& mgr, const zeus::CTransform& xf); bool CanKnockBack(const CDamageInfo& info) const; From 871d3dc6eca2500ad2cfb5ce079302d51619ca3a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 15 May 2020 16:51:17 -0400 Subject: [PATCH 03/16] CPatterned: Make skDamageColor fully constexpr --- Runtime/World/CPatterned.cpp | 1 - Runtime/World/CPatterned.hpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Runtime/World/CPatterned.cpp b/Runtime/World/CPatterned.cpp index a22d01e94..3964fec4c 100644 --- a/Runtime/World/CPatterned.cpp +++ b/Runtime/World/CPatterned.cpp @@ -25,7 +25,6 @@ namespace urde { -constexpr zeus::CColor CPatterned::skDamageColor(0.5f, 0.f, 0.f); constexpr CMaterialList skPatternedGroundMaterialList(EMaterialTypes::Character, EMaterialTypes::Solid, EMaterialTypes::Orbit, EMaterialTypes::GroundCollider, EMaterialTypes::Target); diff --git a/Runtime/World/CPatterned.hpp b/Runtime/World/CPatterned.hpp index 4c3dbbdcb..8a2f629a7 100644 --- a/Runtime/World/CPatterned.hpp +++ b/Runtime/World/CPatterned.hpp @@ -31,7 +31,7 @@ using CPatternedTryFunc = void (CPatterned::*)(CStateManager&, int); class CPatterned : public CAi { public: - static const zeus::CColor skDamageColor; + static constexpr zeus::CColor skDamageColor{0.5f, 0.f, 0.f}; enum class ECharacter { AtomicAlpha = 0, AtomicBeta = 1, From 463e9e9f60fe9f53dc5c103746f0d847a2c2284e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 19 May 2020 22:14:18 -0400 Subject: [PATCH 04/16] CStaticInterference: Eliminate sign conversion warnings in constructor We can just accept a size_t to prevent warnings from occurring. --- Runtime/CStaticInterference.cpp | 2 +- Runtime/CStaticInterference.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/CStaticInterference.cpp b/Runtime/CStaticInterference.cpp index 432a6664a..7015e85e4 100644 --- a/Runtime/CStaticInterference.cpp +++ b/Runtime/CStaticInterference.cpp @@ -4,7 +4,7 @@ namespace urde { -CStaticInterference::CStaticInterference(int sourceCount) { m_sources.reserve(sourceCount); } +CStaticInterference::CStaticInterference(size_t sourceCount) { m_sources.reserve(sourceCount); } void CStaticInterference::RemoveSource(TUniqueId id) { auto iter = std::find_if(m_sources.begin(), m_sources.end(), diff --git a/Runtime/CStaticInterference.hpp b/Runtime/CStaticInterference.hpp index 2018165f9..97e3eff55 100644 --- a/Runtime/CStaticInterference.hpp +++ b/Runtime/CStaticInterference.hpp @@ -16,7 +16,7 @@ class CStaticInterference { std::vector m_sources; public: - explicit CStaticInterference(int sourceCount); + explicit CStaticInterference(size_t sourceCount); void RemoveSource(TUniqueId id); void Update(CStateManager&, float dt); float GetTotalInterference() const; From 9ce7c72a1c73f9e8b0d0340cc2efea73d8299b0c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 19 May 2020 22:17:20 -0400 Subject: [PATCH 05/16] CStaticInterference: Shorten some find_if calls While we're at it, we can also const qualify a reference --- Runtime/CStaticInterference.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Runtime/CStaticInterference.cpp b/Runtime/CStaticInterference.cpp index 7015e85e4..1cd337ac5 100644 --- a/Runtime/CStaticInterference.cpp +++ b/Runtime/CStaticInterference.cpp @@ -7,10 +7,13 @@ namespace urde { CStaticInterference::CStaticInterference(size_t sourceCount) { m_sources.reserve(sourceCount); } void CStaticInterference::RemoveSource(TUniqueId id) { - auto iter = std::find_if(m_sources.begin(), m_sources.end(), - [id](const CStaticInterferenceSource& src) -> bool { return src.id == id; }); - if (iter != m_sources.end()) - m_sources.erase(iter); + const auto iter = std::find_if(m_sources.cbegin(), m_sources.cend(), [id](const auto& src) { return src.id == id; }); + + if (iter == m_sources.cend()) { + return; + } + + m_sources.erase(iter); } void CStaticInterference::Update(CStateManager&, float dt) { @@ -44,15 +47,17 @@ float CStaticInterference::GetTotalInterference() const { void CStaticInterference::AddSource(TUniqueId id, float magnitude, float duration) { magnitude = zeus::clamp(0.f, magnitude, 1.f); - auto search = std::find_if(m_sources.begin(), m_sources.end(), - [id](CStaticInterferenceSource& source) { return source.id == id; }); - if (search != m_sources.end()) { + const auto search = std::find_if(m_sources.begin(), m_sources.end(), + [id](const CStaticInterferenceSource& source) { return source.id == id; }); + if (search != m_sources.cend()) { search->magnitude = magnitude; search->timeLeft = duration; return; } - if (m_sources.size() < m_sources.capacity()) + + if (m_sources.size() < m_sources.capacity()) { m_sources.push_back({id, magnitude, duration}); + } } } // namespace urde From e73e704d20c014435c7efcbcf9fea62fcfabc346 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 19 May 2020 22:25:22 -0400 Subject: [PATCH 06/16] CPlayerState: Make GetPickupTotal() a const member function This doesn't modify internal member state. --- Runtime/CPlayerState.hpp | 2 +- Runtime/MP1/MP1.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Runtime/CPlayerState.hpp b/Runtime/CPlayerState.hpp index 8b3798063..54e877827 100644 --- a/Runtime/CPlayerState.hpp +++ b/Runtime/CPlayerState.hpp @@ -119,7 +119,7 @@ public: CHealthInfo& GetHealthInfo(); const CHealthInfo& GetHealthInfo() const; - u32 GetPickupTotal() { return 99; } + u32 GetPickupTotal() const { return 99; } void SetIsFusionEnabled(bool val) { x0_26_fusion = val; } bool IsFusionEnabled() const { return x0_26_fusion; } EPlayerSuit GetCurrentSuit() const; diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 826f42b74..3c21543e4 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -692,8 +692,8 @@ void CMain::UpdateDiscordPresence(CAssetId worldSTRG) { } if (g_GameState != nullptr) { - if (CPlayerState* pState = g_GameState->GetPlayerState().get()) { - u32 itemPercent = pState->CalculateItemCollectionRate() * 100 / pState->GetPickupTotal(); + if (const CPlayerState* pState = g_GameState->GetPlayerState().get()) { + const u32 itemPercent = pState->CalculateItemCollectionRate() * 100 / pState->GetPickupTotal(); if (DiscordItemPercent != itemPercent) { DiscordItemPercent = itemPercent; DiscordState = fmt::format(FMT_STRING("{}%"), itemPercent); From e1ddabaff8a3b5ff5ffb367a11b16772397f340e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 19 May 2020 23:40:53 -0400 Subject: [PATCH 07/16] CTeamAiMgr: Make use of std::any_of in ShouldUpdateRoles() Same behavior, less code. --- Runtime/World/CTeamAiMgr.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Runtime/World/CTeamAiMgr.cpp b/Runtime/World/CTeamAiMgr.cpp index 4e152be26..6651f457f 100644 --- a/Runtime/World/CTeamAiMgr.cpp +++ b/Runtime/World/CTeamAiMgr.cpp @@ -65,20 +65,19 @@ void CTeamAiMgr::UpdateTeamCaptain() { } bool CTeamAiMgr::ShouldUpdateRoles(float dt) { - if (x58_roles.empty()) + if (x58_roles.empty()) { return false; - - x88_timeDirty += dt; - if (x88_timeDirty >= 1.5f) - return true; - - for (const auto& role : x58_roles) { - if (role.GetTeamAiRole() <= CTeamAiRole::ETeamAiRole::Initial || - role.GetTeamAiRole() > CTeamAiRole::ETeamAiRole::Unassigned) - return true; } - return false; + x88_timeDirty += dt; + if (x88_timeDirty >= 1.5f) { + return true; + } + + return std::any_of(x58_roles.cbegin(), x58_roles.cend(), [](const auto& role) { + return role.GetTeamAiRole() <= CTeamAiRole::ETeamAiRole::Initial || + role.GetTeamAiRole() > CTeamAiRole::ETeamAiRole::Unassigned; + }); } void CTeamAiMgr::ResetRoles(CStateManager& mgr) { From 96129264a3044032ea18f0a201ac03e1d6e1894a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 19 May 2020 23:47:02 -0400 Subject: [PATCH 08/16] CTeamAiMgr: Make use of TCastToConstPtr where applicable Makes mutability explicit. --- Runtime/World/CTeamAiMgr.cpp | 49 +++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/Runtime/World/CTeamAiMgr.cpp b/Runtime/World/CTeamAiMgr.cpp index 6651f457f..372e66582 100644 --- a/Runtime/World/CTeamAiMgr.cpp +++ b/Runtime/World/CTeamAiMgr.cpp @@ -90,27 +90,29 @@ void CTeamAiMgr::ResetRoles(CStateManager& mgr) { } void CTeamAiMgr::SpacingSort(CStateManager& mgr, const zeus::CVector3f& pos) { - TeamAiRoleSorter sorter(pos, 2); + const TeamAiRoleSorter sorter(pos, 2); std::sort(x58_roles.begin(), x58_roles.end(), sorter); float tierStagger = 4.5f; for (const auto& role : x58_roles) { - if (TCastToPtr ai = mgr.ObjectById(role.GetOwnerId())) { - float length = (ai->GetBaseBoundingBox().max.y() - ai->GetBaseBoundingBox().min.y()) * 1.5f; - if (length > tierStagger) + if (const TCastToConstPtr ai = mgr.ObjectById(role.GetOwnerId())) { + const float length = (ai->GetBaseBoundingBox().max.y() - ai->GetBaseBoundingBox().min.y()) * 1.5f; + if (length > tierStagger) { tierStagger = length; + } } } float curTierDist = tierStagger; int tierTeamSize = 0; int maxTierTeamSize = 3; for (auto& role : x58_roles) { - if (TCastToPtr ai = mgr.ObjectById(role.GetOwnerId())) { + if (const TCastToConstPtr ai = mgr.ObjectById(role.GetOwnerId())) { zeus::CVector3f delta = ai->GetTranslation() - pos; zeus::CVector3f newPos; - if (delta.canBeNormalized()) + if (delta.canBeNormalized()) { newPos = pos + delta.normalized() * curTierDist; - else + } else { newPos = pos + ai->GetTransform().basis[1] * curTierDist; + } role.x1c_position = newPos; role.x1c_position.z() = ai->GetTranslation().z(); tierTeamSize += 1; @@ -121,7 +123,7 @@ void CTeamAiMgr::SpacingSort(CStateManager& mgr, const zeus::CVector3f& pos) { } } } - TeamAiRoleSorter sorter2(pos, 0); + const TeamAiRoleSorter sorter2(pos, 0); std::sort(x58_roles.begin(), x58_roles.end(), sorter2); } @@ -132,24 +134,29 @@ void CTeamAiMgr::PositionTeam(CStateManager& mgr) { SpacingSort(mgr, aimPos); break; default: - for (auto& role : x58_roles) - if (TCastToPtr ai = mgr.ObjectById(role.GetOwnerId())) + for (auto& role : x58_roles) { + if (const TCastToConstPtr ai = mgr.ObjectById(role.GetOwnerId())) { role.x1c_position = ai->GetOrigin(mgr, role, aimPos); + } + } break; } } void CTeamAiMgr::AssignRoles(CTeamAiRole::ETeamAiRole assRole, s32 count) { - if (count == 0) + if (count == 0) { return; + } + s32 lastIdx = 0; for (auto& role : x58_roles) { if (role.GetTeamAiRole() == CTeamAiRole::ETeamAiRole::Initial) { if (role.x4_roleA == assRole || role.x8_roleB == assRole || role.xc_roleC == assRole) { role.x10_curRole = assRole; role.x14_roleIndex = lastIdx++; - if (lastIdx == count) + if (lastIdx == count) { return; + } } } } @@ -157,26 +164,34 @@ void CTeamAiMgr::AssignRoles(CTeamAiRole::ETeamAiRole assRole, s32 count) { void CTeamAiMgr::UpdateRoles(CStateManager& mgr) { ResetRoles(mgr); - zeus::CVector3f aimPos = mgr.GetPlayer().GetAimPosition(mgr, 0.f); - TeamAiRoleSorter sorter(aimPos, 1); + + const zeus::CVector3f aimPos = mgr.GetPlayer().GetAimPosition(mgr, 0.f); + const TeamAiRoleSorter sorter(aimPos, 1); std::sort(x58_roles.begin(), x58_roles.end(), sorter); + AssignRoles(CTeamAiRole::ETeamAiRole::Melee, x34_data.x4_meleeCount); AssignRoles(CTeamAiRole::ETeamAiRole::Ranged, x34_data.x8_rangedCount); AssignRoles(CTeamAiRole::ETeamAiRole::Unknown, x34_data.xc_unknownCount); + for (auto& role : x58_roles) { if (role.GetTeamAiRole() <= CTeamAiRole::ETeamAiRole::Initial || - role.GetTeamAiRole() > CTeamAiRole::ETeamAiRole::Unassigned) + role.GetTeamAiRole() > CTeamAiRole::ETeamAiRole::Unassigned) { role.SetTeamAiRole(CTeamAiRole::ETeamAiRole::Unassigned); + } } - TeamAiRoleSorter sorter2(aimPos, 0); + + const TeamAiRoleSorter sorter2(aimPos, 0); std::sort(x58_roles.begin(), x58_roles.end(), sorter2); x88_timeDirty = 0.f; } void CTeamAiMgr::Think(float dt, CStateManager& mgr) { CEntity::Think(dt, mgr); - if (ShouldUpdateRoles(dt)) + + if (ShouldUpdateRoles(dt)) { UpdateRoles(mgr); + } + PositionTeam(mgr); x90_timeSinceMelee += dt; x94_timeSinceRanged += dt; From 38213bae99bf42bd3217ea5574dbbfa1e9edee9f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 19 May 2020 23:49:59 -0400 Subject: [PATCH 09/16] CTeamAiMgr: Convert type into an enum class Makes the sorting type explicit at the call site, rather than using magic values. --- Runtime/World/CTeamAiMgr.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Runtime/World/CTeamAiMgr.cpp b/Runtime/World/CTeamAiMgr.cpp index 372e66582..a084ca3be 100644 --- a/Runtime/World/CTeamAiMgr.cpp +++ b/Runtime/World/CTeamAiMgr.cpp @@ -10,15 +10,22 @@ namespace urde { struct TeamAiRoleSorter { + enum class Type { + OwnerID, + Distance, + TeamAIRole, + }; + zeus::CVector3f x0_pos; - s32 xc_type; + Type xc_type; + bool operator()(const CTeamAiRole& a, const CTeamAiRole& b) const { - float aDist = (x0_pos - a.GetTeamPosition()).magSquared(); - float bDist = (x0_pos - b.GetTeamPosition()).magSquared(); + const float aDist = (x0_pos - a.GetTeamPosition()).magSquared(); + const float bDist = (x0_pos - b.GetTeamPosition()).magSquared(); switch (xc_type) { - case 0: + case Type::OwnerID: return a.GetOwnerId() < b.GetOwnerId(); - case 1: + case Type::Distance: return aDist < bDist; default: if (a.GetTeamAiRole() == b.GetTeamAiRole()) @@ -27,7 +34,7 @@ struct TeamAiRoleSorter { return a.GetTeamAiRole() < b.GetTeamAiRole(); } } - TeamAiRoleSorter(const zeus::CVector3f& pos, s32 type) : x0_pos(pos), xc_type(type) {} + TeamAiRoleSorter(const zeus::CVector3f& pos, Type type) : x0_pos(pos), xc_type(type) {} }; CTeamAiData::CTeamAiData(CInputStream& in, s32 propCount) @@ -90,7 +97,7 @@ void CTeamAiMgr::ResetRoles(CStateManager& mgr) { } void CTeamAiMgr::SpacingSort(CStateManager& mgr, const zeus::CVector3f& pos) { - const TeamAiRoleSorter sorter(pos, 2); + const TeamAiRoleSorter sorter(pos, TeamAiRoleSorter::Type::TeamAIRole); std::sort(x58_roles.begin(), x58_roles.end(), sorter); float tierStagger = 4.5f; for (const auto& role : x58_roles) { @@ -123,7 +130,7 @@ void CTeamAiMgr::SpacingSort(CStateManager& mgr, const zeus::CVector3f& pos) { } } } - const TeamAiRoleSorter sorter2(pos, 0); + const TeamAiRoleSorter sorter2(pos, TeamAiRoleSorter::Type::OwnerID); std::sort(x58_roles.begin(), x58_roles.end(), sorter2); } @@ -166,7 +173,7 @@ void CTeamAiMgr::UpdateRoles(CStateManager& mgr) { ResetRoles(mgr); const zeus::CVector3f aimPos = mgr.GetPlayer().GetAimPosition(mgr, 0.f); - const TeamAiRoleSorter sorter(aimPos, 1); + const TeamAiRoleSorter sorter(aimPos, TeamAiRoleSorter::Type::Distance); std::sort(x58_roles.begin(), x58_roles.end(), sorter); AssignRoles(CTeamAiRole::ETeamAiRole::Melee, x34_data.x4_meleeCount); @@ -180,7 +187,7 @@ void CTeamAiMgr::UpdateRoles(CStateManager& mgr) { } } - const TeamAiRoleSorter sorter2(aimPos, 0); + const TeamAiRoleSorter sorter2(aimPos, TeamAiRoleSorter::Type::OwnerID); std::sort(x58_roles.begin(), x58_roles.end(), sorter2); x88_timeDirty = 0.f; } From 677ed1ce9af1e6a2708e2443850cc7985130837f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 20 May 2020 12:19:00 -0400 Subject: [PATCH 10/16] CScriptSpawnPoint: Resolve sign conversion warnings operator[] takes a size_t, not an int. --- Runtime/World/CScriptSpawnPoint.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Runtime/World/CScriptSpawnPoint.cpp b/Runtime/World/CScriptSpawnPoint.cpp index 7b22469a9..645081504 100644 --- a/Runtime/World/CScriptSpawnPoint.cpp +++ b/Runtime/World/CScriptSpawnPoint.cpp @@ -15,18 +15,18 @@ CScriptSpawnPoint::CScriptSpawnPoint(TUniqueId uid, std::string_view name, const bool defaultSpawn, bool active, bool morphed) : CEntity(uid, info, active, name), x34_xf(xf), x64_itemCounts(itemCounts) { #ifndef NDEBUG - x64_itemCounts[int(CPlayerState::EItemType::MorphBall)] = 1; - x64_itemCounts[int(CPlayerState::EItemType::MorphBallBombs)] = 1; - x64_itemCounts[int(CPlayerState::EItemType::PhazonSuit)] = 1; - x64_itemCounts[int(CPlayerState::EItemType::ThermalVisor)] = 1; - x64_itemCounts[int(CPlayerState::EItemType::XRayVisor)] = 1; - x64_itemCounts[int(CPlayerState::EItemType::GrappleBeam)] = 1; - x64_itemCounts[int(CPlayerState::EItemType::BoostBall)] = 1; - x64_itemCounts[int(CPlayerState::EItemType::ChargeBeam)] = 1; - x64_itemCounts[int(CPlayerState::EItemType::PowerBombs)] = 8; - x64_itemCounts[int(CPlayerState::EItemType::SpaceJumpBoots)] = 1; - x64_itemCounts[int(CPlayerState::EItemType::Missiles)] = - std::max(x64_itemCounts[int(CPlayerState::EItemType::Missiles)], u32(5)); + x64_itemCounts[size_t(CPlayerState::EItemType::MorphBall)] = 1; + x64_itemCounts[size_t(CPlayerState::EItemType::MorphBallBombs)] = 1; + x64_itemCounts[size_t(CPlayerState::EItemType::PhazonSuit)] = 1; + x64_itemCounts[size_t(CPlayerState::EItemType::ThermalVisor)] = 1; + x64_itemCounts[size_t(CPlayerState::EItemType::XRayVisor)] = 1; + x64_itemCounts[size_t(CPlayerState::EItemType::GrappleBeam)] = 1; + x64_itemCounts[size_t(CPlayerState::EItemType::BoostBall)] = 1; + x64_itemCounts[size_t(CPlayerState::EItemType::ChargeBeam)] = 1; + x64_itemCounts[size_t(CPlayerState::EItemType::PowerBombs)] = 8; + x64_itemCounts[size_t(CPlayerState::EItemType::SpaceJumpBoots)] = 1; + x64_itemCounts[size_t(CPlayerState::EItemType::Missiles)] = + std::max(x64_itemCounts[size_t(CPlayerState::EItemType::Missiles)], u32(5)); #endif x10c_24_firstSpawn = defaultSpawn; x10c_25_morphed = morphed; @@ -77,8 +77,8 @@ void CScriptSpawnPoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objI } u32 CScriptSpawnPoint::GetPowerup(CPlayerState::EItemType item) const { - const auto idx = static_cast(item); - if (item >= CPlayerState::EItemType::Max || idx < 0) { + const auto idx = static_cast(item); + if (item >= CPlayerState::EItemType::Max) { return x64_itemCounts.front(); } return x64_itemCounts[idx]; From 1049a1a590f723d3150adcbf2d7d98c9eb7dfc90 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 20 May 2020 13:49:59 -0400 Subject: [PATCH 11/16] CScriptActorRotate: Make use of insert_or_assign in UpdateActors() Same behavior, minus potentially avoidable default constructions that immediately get overwritten. --- Runtime/World/CScriptActorRotate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/World/CScriptActorRotate.cpp b/Runtime/World/CScriptActorRotate.cpp index fa013b431..1f1333cfe 100644 --- a/Runtime/World/CScriptActorRotate.cpp +++ b/Runtime/World/CScriptActorRotate.cpp @@ -112,7 +112,7 @@ void CScriptActorRotate::UpdateActors(bool next, CStateManager& mgr) { auto search = mgr.GetIdListForScript(conn.x8_objId); for (auto it = search.first; it != search.second; ++it) { if (const TCastToConstPtr act = mgr.ObjectById(it->second)) { - x48_actors[it->second] = act->GetTransform().getRotation(); + x48_actors.insert_or_assign(it->second, act->GetTransform().getRotation()); } } } From 47cfaf17bdb6eb5f6f4fef8472d004fc10c13b1a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 20 May 2020 13:59:18 -0400 Subject: [PATCH 12/16] CScriptActor: Remove unused printf code Given it's not actively used or tied into the logging system, we can get rid of this to prevent it from ever bitrotting. --- Runtime/World/CScriptActor.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Runtime/World/CScriptActor.cpp b/Runtime/World/CScriptActor.cpp index 7fab393c8..5fa39aaa4 100644 --- a/Runtime/World/CScriptActor.cpp +++ b/Runtime/World/CScriptActor.cpp @@ -110,9 +110,6 @@ void CScriptActor::Think(float dt, CStateManager& mgr) { MoveToOR(deltas.x0_posDelta, dt); } - //if (TCastToPtr(this)) - //printf("DEL %f\n", zeus::radToDeg(zeus::CEulerAngles(deltas.xc_rotDelta).z())); - //printf("DEL %f %f %f %f\n", float(deltas.xc_rotDelta[0]), float(deltas.xc_rotDelta[1]), float(deltas.xc_rotDelta[2]), float(deltas.xc_rotDelta[3])); RotateToOR(deltas.xc_rotDelta, dt); } From 55364174749d609c19584be9e25993236542717f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 20 May 2020 14:02:50 -0400 Subject: [PATCH 13/16] CScannableObjectInfo: Resolve unused parameter warning This is unused, so we can just not specify it. --- Runtime/CScannableObjectInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/CScannableObjectInfo.cpp b/Runtime/CScannableObjectInfo.cpp index c4e8a8c58..a4787d253 100644 --- a/Runtime/CScannableObjectInfo.cpp +++ b/Runtime/CScannableObjectInfo.cpp @@ -66,7 +66,7 @@ CScannableObjectInfo::SBucket::SBucket(CInputStream& in, u32 version) { } CFactoryFnReturn FScannableObjectInfoFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer&, - CObjectReference* selfRef) { + CObjectReference*) { return TToken::GetIObjObjectFor(std::make_unique(in, tag.id)); } } // namespace urde From 32a4087f69b39f5bb3d99622d1e0d2ca6514f590 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 20 May 2020 14:32:20 -0400 Subject: [PATCH 14/16] CScriptAiJumpPoint: Mark reference as const in AcceptScriptMsg None of the data members of the referenced connections are modified. --- Runtime/World/CScriptAiJumpPoint.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/World/CScriptAiJumpPoint.cpp b/Runtime/World/CScriptAiJumpPoint.cpp index 8d4ab9967..b54961f39 100644 --- a/Runtime/World/CScriptAiJumpPoint.cpp +++ b/Runtime/World/CScriptAiJumpPoint.cpp @@ -31,7 +31,7 @@ void CScriptAiJumpPoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId oth return; } - for (SConnection& conn : x20_conns) { + for (const SConnection& conn : x20_conns) { if (conn.x0_state != EScriptObjectState::Arrived || conn.x4_msg != EScriptObjectMessage::Next) { continue; } From 6063ec2540981e3e7b64ba5a7075aa9666a352aa Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 21 May 2020 01:33:31 -0400 Subject: [PATCH 15/16] CFontRenderState: Eliminate sign conversion in SetColor() Same behavior, minus a sign conversion warning. --- Runtime/GuiSys/CFontRenderState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/GuiSys/CFontRenderState.cpp b/Runtime/GuiSys/CFontRenderState.cpp index 20b3b45fe..ef91455e0 100644 --- a/Runtime/GuiSys/CFontRenderState.cpp +++ b/Runtime/GuiSys/CFontRenderState.cpp @@ -26,7 +26,7 @@ void CFontRenderState::SetColor(EColorType tp, const CTextColor& col) { case EColorType::Main: case EColorType::Outline: case EColorType::Geometry: - x54_colors[int(tp)] = col; + x54_colors[size_t(tp)] = col; break; case EColorType::Foreground: x54_colors[0] = col; From 1158a171e78be480bd0e7fbc29ed1f859550e7e8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 21 May 2020 01:40:28 -0400 Subject: [PATCH 16/16] CFontImageDef: Collapse IsLoaded() into a std::all_of call Same behavior, less code. C++20 ranges will allow shortening this in the future. --- Runtime/GuiSys/CFontImageDef.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Runtime/GuiSys/CFontImageDef.cpp b/Runtime/GuiSys/CFontImageDef.cpp index e20b52403..7a0db90b1 100644 --- a/Runtime/GuiSys/CFontImageDef.cpp +++ b/Runtime/GuiSys/CFontImageDef.cpp @@ -1,5 +1,7 @@ #include "Runtime/GuiSys/CFontImageDef.hpp" +#include + #include "Runtime/Graphics/CTexture.hpp" namespace urde { @@ -19,10 +21,7 @@ CFontImageDef::CFontImageDef(const TToken& tex, const zeus::CVector2f& } bool CFontImageDef::IsLoaded() const { - for (const TToken& tok : x4_texs) - if (!tok.IsLoaded()) - return false; - return true; + return std::all_of(x4_texs.cbegin(), x4_texs.cend(), [](const auto& token) { return token.IsLoaded(); }); } s32 CFontImageDef::CalculateBaseline() const {