CSeedling: Use std::array with skNeedleLocators

Makes the array strongly-typed and impervious to implicit array to
pointer decay.
This commit is contained in:
Lioncash 2019-09-28 20:12:22 -04:00
parent 2a34b6be68
commit 3f743d5c9f
1 changed files with 12 additions and 7 deletions

View File

@ -1,5 +1,7 @@
#include "Runtime/MP1/World/CSeedling.hpp" #include "Runtime/MP1/World/CSeedling.hpp"
#include <array>
#include "Runtime/CStateManager.hpp" #include "Runtime/CStateManager.hpp"
#include "Runtime/World/CGameArea.hpp" #include "Runtime/World/CGameArea.hpp"
#include "Runtime/World/CPatternedInfo.hpp" #include "Runtime/World/CPatternedInfo.hpp"
@ -10,7 +12,7 @@
namespace urde::MP1 { namespace urde::MP1 {
namespace { namespace {
const std::string skNeedleLocators[2][6] = { const std::array<std::array<std::string, 6>, 2> skNeedleLocators{{
{ {
"A_spike1_LCTR_SDK", "A_spike1_LCTR_SDK",
"A_spike2_LCTR_SDK", "A_spike2_LCTR_SDK",
@ -27,7 +29,7 @@ const std::string skNeedleLocators[2][6] = {
"B_spike5_LCTR_SDK", "B_spike5_LCTR_SDK",
"B_spike6_LCTR_SDK", "B_spike6_LCTR_SDK",
}, },
}; }};
} // Anonymous namespace } // Anonymous namespace
CSeedling::CSeedling(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CSeedling::CSeedling(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
@ -107,14 +109,15 @@ void CSeedling::Think(float dt, CStateManager& mgr) {
void CSeedling::Render(const CStateManager& mgr) const { void CSeedling::Render(const CStateManager& mgr) const {
if (x400_25_alive && x6bc_spikeData) { if (x400_25_alive && x6bc_spikeData) {
u32 index = x722_24_renderOnlyClusterA ? 0 : u32(x722_25_curNeedleCluster); const size_t index = x722_24_renderOnlyClusterA ? 0 : size_t(x722_25_curNeedleCluster);
CModelFlags flags; CModelFlags flags;
flags.x2_flags = 3; flags.x2_flags = 3;
flags.x4_color = zeus::skWhite; flags.x4_color = zeus::skWhite;
for (const std::string& sv : skNeedleLocators[index]) for (const std::string& sv : skNeedleLocators[index]) {
x6bc_spikeData->Render(mgr, GetLctrTransform(sv), x90_actorLights.get(), flags); x6bc_spikeData->Render(mgr, GetLctrTransform(sv), x90_actorLights.get(), flags);
} }
}
CWallWalker::Render(mgr); CWallWalker::Render(mgr);
} }
@ -206,9 +209,11 @@ bool CSeedling::ShouldAttack(CStateManager& mgr, float) {
} }
void CSeedling::LaunchNeedles(CStateManager& mgr) { void CSeedling::LaunchNeedles(CStateManager& mgr) {
for (const std::string& needle : skNeedleLocators[u32(x722_25_curNeedleCluster)]) const auto& needleLocators = skNeedleLocators[size_t(x722_25_curNeedleCluster)];
LaunchProjectile(GetLctrTransform(needle), mgr, 6, EProjectileAttrib::None, true, {}, 0xFFFF, false, for (const std::string& needle : needleLocators) {
GetModelData()->GetScale()); LaunchProjectile(GetLctrTransform(needle), mgr, int(needleLocators.size()), EProjectileAttrib::None, true, {},
0xFFFF, false, GetModelData()->GetScale());
}
x722_25_curNeedleCluster = !x722_25_curNeedleCluster; x722_25_curNeedleCluster = !x722_25_curNeedleCluster;
x722_24_renderOnlyClusterA = false; x722_24_renderOnlyClusterA = false;