From ee791d6a37b8436475189bc1ec6bea1575d9b82d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Oct 2019 00:30:03 -0400 Subject: [PATCH 1/6] CAtomicAlpha: Organize cpp includes --- Runtime/MP1/World/CAtomicAlpha.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Runtime/MP1/World/CAtomicAlpha.cpp b/Runtime/MP1/World/CAtomicAlpha.cpp index b3c18e3ff..ce7430285 100644 --- a/Runtime/MP1/World/CAtomicAlpha.cpp +++ b/Runtime/MP1/World/CAtomicAlpha.cpp @@ -1,11 +1,12 @@ -#include "CAtomicAlpha.hpp" -#include "World/CWorld.hpp" -#include "World/CGameArea.hpp" -#include "World/CPlayer.hpp" -#include "World/CPatternedInfo.hpp" -#include "Weapon/CPlayerGun.hpp" +#include "Runtime/MP1/World/CAtomicAlpha.hpp" + +#include "Runtime/CStateManager.hpp" +#include "Runtime/Weapon/CPlayerGun.hpp" +#include "Runtime/World/CGameArea.hpp" +#include "Runtime/World/CPatternedInfo.hpp" +#include "Runtime/World/CPlayer.hpp" +#include "Runtime/World/CWorld.hpp" -#include "CStateManager.hpp" namespace urde::MP1 { const std::string_view CAtomicAlpha::skBombLocators[4] = {"bomb1_LCTR"sv, "bomb2_LCTR"sv, "bomb3_LCTR"sv, "bomb4_LCTR"sv}; From c882003d378c1bdd0271d9613f29f0bb5e0b151c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Oct 2019 00:32:17 -0400 Subject: [PATCH 2/6] CAtomicAlpha: Make skBombLocators an internal array This is only used within the cpp file, so we can relocate its definition there to make it fully internally-linked. --- Runtime/MP1/World/CAtomicAlpha.cpp | 10 ++++++++-- Runtime/MP1/World/CAtomicAlpha.hpp | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Runtime/MP1/World/CAtomicAlpha.cpp b/Runtime/MP1/World/CAtomicAlpha.cpp index ce7430285..6332e60eb 100644 --- a/Runtime/MP1/World/CAtomicAlpha.cpp +++ b/Runtime/MP1/World/CAtomicAlpha.cpp @@ -1,5 +1,7 @@ #include "Runtime/MP1/World/CAtomicAlpha.hpp" +#include + #include "Runtime/CStateManager.hpp" #include "Runtime/Weapon/CPlayerGun.hpp" #include "Runtime/World/CGameArea.hpp" @@ -8,8 +10,12 @@ #include "Runtime/World/CWorld.hpp" namespace urde::MP1 { -const std::string_view CAtomicAlpha::skBombLocators[4] = {"bomb1_LCTR"sv, "bomb2_LCTR"sv, "bomb3_LCTR"sv, - "bomb4_LCTR"sv}; +constexpr std::array skBombLocators{ + "bomb1_LCTR"sv, + "bomb2_LCTR"sv, + "bomb3_LCTR"sv, + "bomb4_LCTR"sv, +}; CAtomicAlpha::CAtomicAlpha(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& actParms, const CPatternedInfo& pInfo, diff --git a/Runtime/MP1/World/CAtomicAlpha.hpp b/Runtime/MP1/World/CAtomicAlpha.hpp index 75c9554d7..951f52ccd 100644 --- a/Runtime/MP1/World/CAtomicAlpha.hpp +++ b/Runtime/MP1/World/CAtomicAlpha.hpp @@ -9,7 +9,6 @@ namespace urde::MP1 { class CAtomicAlpha : public CPatterned { - static const std::string_view skBombLocators[4]; static constexpr u32 skBombCount = 4; struct SBomb { std::string x0_locatorName; From 18eb2b73b18e743439b5fb55642855c2c04a42e1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Oct 2019 00:36:29 -0400 Subject: [PATCH 3/6] CAtomicAlpha: Use emplace_back where applicable Simplifies the construction of the SBomb instances, while also constructing in place. --- Runtime/MP1/World/CAtomicAlpha.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Runtime/MP1/World/CAtomicAlpha.cpp b/Runtime/MP1/World/CAtomicAlpha.cpp index 6332e60eb..d3af41292 100644 --- a/Runtime/MP1/World/CAtomicAlpha.cpp +++ b/Runtime/MP1/World/CAtomicAlpha.cpp @@ -34,8 +34,7 @@ CAtomicAlpha::CAtomicAlpha(TUniqueId uid, std::string_view name, const CEntityIn , x690_bombModel(CStaticRes(cmdl, GetModelData()->GetScale())) { x668_bombProjectile.Token().Lock(); for (u32 i = 0; i < skBombCount; ++i) { - x6dc_bombLocators.push_back( - SBomb(skBombLocators[i], pas::ELocomotionType(u32(pas::ELocomotionType::Internal10) + i))); + x6dc_bombLocators.emplace_back(skBombLocators[i], pas::ELocomotionType(u32(pas::ELocomotionType::Internal10) + i)); } } From e0e38b569e1f0a08a822589804822941e91b6a89 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Oct 2019 00:41:23 -0400 Subject: [PATCH 4/6] CAtomicAlpha: Remove .data() call in SBomb constructor We can just use the std::string_view constructor for std::string, which eliminates an unnecessary strlen call. --- Runtime/MP1/World/CAtomicAlpha.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/MP1/World/CAtomicAlpha.hpp b/Runtime/MP1/World/CAtomicAlpha.hpp index 951f52ccd..5f1a9e335 100644 --- a/Runtime/MP1/World/CAtomicAlpha.hpp +++ b/Runtime/MP1/World/CAtomicAlpha.hpp @@ -15,7 +15,7 @@ class CAtomicAlpha : public CPatterned { pas::ELocomotionType x10_locomotionType; float x14_scaleTime = FLT_MAX; SBomb(const std::string_view locator, pas::ELocomotionType locomotionType) - : x0_locatorName(locator.data()), x10_locomotionType(locomotionType) {} + : x0_locatorName(locator), x10_locomotionType(locomotionType) {} }; bool x568_24_inRange : 1; bool x568_25_invisible : 1; From abe8b9510b888c80e97fc96a1da990424582068c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Oct 2019 01:30:04 -0400 Subject: [PATCH 5/6] CAtomicBeta: Organize cpp includes --- Runtime/MP1/World/CAtomicBeta.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Runtime/MP1/World/CAtomicBeta.cpp b/Runtime/MP1/World/CAtomicBeta.cpp index 44da43010..2225ff6c0 100644 --- a/Runtime/MP1/World/CAtomicBeta.cpp +++ b/Runtime/MP1/World/CAtomicBeta.cpp @@ -1,11 +1,12 @@ -#include "CAtomicBeta.hpp" -#include "Particle/CWeaponDescription.hpp" -#include "Weapon/CPlayerGun.hpp" -#include "Weapon/CElectricBeamProjectile.hpp" -#include "World/CPlayer.hpp" -#include "GameGlobalObjects.hpp" -#include "CStateManager.hpp" -#include "CSimplePool.hpp" +#include "Runtime/MP1/World/CAtomicBeta.hpp" + +#include "Runtime/CSimplePool.hpp" +#include "Runtime/CStateManager.hpp" +#include "Runtime/GameGlobalObjects.hpp" +#include "Runtime/Particle/CWeaponDescription.hpp" +#include "Runtime/Weapon/CElectricBeamProjectile.hpp" +#include "Runtime/Weapon/CPlayerGun.hpp" +#include "Runtime/World/CPlayer.hpp" namespace urde::MP1 { const std::string_view CAtomicBeta::skBombLocators[3] = {"bomb2_LCTR"sv, "bomb3_LCTR"sv, "bomb4_LCTR"sv}; From 67cd0d44c6a39ed7c4d313194e140b41f1d8fb38 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Oct 2019 01:32:30 -0400 Subject: [PATCH 6/6] CAtomicBeta: Make skBombLocators an internal array Like with CAtomicAlpha, we can also fully hide this array from external view by making it internally linked. --- Runtime/MP1/World/CAtomicBeta.cpp | 32 ++++++++++++++++++++----------- Runtime/MP1/World/CAtomicBeta.hpp | 1 - 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Runtime/MP1/World/CAtomicBeta.cpp b/Runtime/MP1/World/CAtomicBeta.cpp index 2225ff6c0..55d6c4537 100644 --- a/Runtime/MP1/World/CAtomicBeta.cpp +++ b/Runtime/MP1/World/CAtomicBeta.cpp @@ -1,5 +1,7 @@ #include "Runtime/MP1/World/CAtomicBeta.hpp" +#include + #include "Runtime/CSimplePool.hpp" #include "Runtime/CStateManager.hpp" #include "Runtime/GameGlobalObjects.hpp" @@ -9,7 +11,11 @@ #include "Runtime/World/CPlayer.hpp" namespace urde::MP1 { -const std::string_view CAtomicBeta::skBombLocators[3] = {"bomb2_LCTR"sv, "bomb3_LCTR"sv, "bomb4_LCTR"sv}; +constexpr std::array skBombLocators{ + "bomb2_LCTR"sv, + "bomb3_LCTR"sv, + "bomb4_LCTR"sv, +}; CAtomicBeta::CAtomicBeta(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData, const CActorParameters& actParms, const CPatternedInfo& pInfo, @@ -43,7 +49,7 @@ CAtomicBeta::CAtomicBeta(TUniqueId uid, std::string_view name, const CEntityInfo void CAtomicBeta::CreateBeams(CStateManager& mgr) { const SElectricBeamInfo beamInfo{x600_electricWeapon, 50.f, x634_beamRadius, 10.f, x62c_beamParticle, x630_, x638_}; - for (u32 i = 0; i < kBombCount; ++i) { + for (size_t i = 0; i < kBombCount; ++i) { x568_projectileIds.push_back(mgr.AllocateUniqueId()); mgr.AddObject(new CElectricBeamProjectile(x608_, EWeaponType::AI, beamInfo, {}, EMaterialTypes::Character, x610_projectileDamage, x568_projectileIds[i], GetAreaIdAlways(), @@ -52,17 +58,19 @@ void CAtomicBeta::CreateBeams(CStateManager& mgr) { } void CAtomicBeta::UpdateBeams(CStateManager& mgr, bool fireBeam) { - if (x574_beamFired == fireBeam) + if (x574_beamFired == fireBeam) { return; + } - for (u32 i = 0; i < kBombCount; ++i) { + for (size_t i = 0; i < kBombCount; ++i) { //zeus::CTransform xf = GetTransform() * GetScaledLocatorTransform(skBombLocators[i]); //zeus::CTransform newXf = zeus::lookAt(xf.origin, xf.origin + xf.basis[1], zeus::skUp); - if (CElectricBeamProjectile* proj = static_cast(mgr.ObjectById(x568_projectileIds[i]))) { - if (fireBeam) + if (auto* const proj = static_cast(mgr.ObjectById(x568_projectileIds[i]))) { + if (fireBeam) { proj->Fire(GetTransform() * GetScaledLocatorTransform(skBombLocators[i]), mgr, false); - else + } else { proj->ResetBeam(mgr, false); + } } } x574_beamFired = fireBeam; @@ -127,11 +135,13 @@ void CAtomicBeta::Think(float dt, CStateManager& mgr) { UpdateOrCreateEmitter(x64c_, x644_, GetTranslation(), 96 / 127.f); } - for (u32 i = 0; i < kBombCount; ++i) { - if (CElectricBeamProjectile* proj = static_cast(mgr.ObjectById(x568_projectileIds[i]))) { - if (!proj->GetActive()) + for (size_t i = 0; i < kBombCount; ++i) { + if (auto* const proj = static_cast(mgr.ObjectById(x568_projectileIds[i]))) { + if (!proj->GetActive()) { continue; - zeus::CTransform xf = GetTransform() * GetScaledLocatorTransform(skBombLocators[i]); + } + + const zeus::CTransform xf = GetTransform() * GetScaledLocatorTransform(skBombLocators[i]); proj->UpdateFx(zeus::lookAt(xf.origin, xf.origin + xf.basis[1], zeus::skUp), dt, mgr); } } diff --git a/Runtime/MP1/World/CAtomicBeta.hpp b/Runtime/MP1/World/CAtomicBeta.hpp index 46197653f..978ea54ce 100644 --- a/Runtime/MP1/World/CAtomicBeta.hpp +++ b/Runtime/MP1/World/CAtomicBeta.hpp @@ -13,7 +13,6 @@ class CWeaponDescription; namespace urde::MP1 { class CAtomicBeta final : public CPatterned { - static const std::string_view skBombLocators[3]; static constexpr u32 kBombCount = 3; rstl::reserved_vector x568_projectileIds; bool x574_beamFired = false;