From e26afe887f97614696da6e1b5ceeabc1198dd00d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 13 Apr 2020 16:44:39 -0400 Subject: [PATCH] CCompoundTargetReticle: Make use of std::array where applicable Same behavior, stronger typing. While we're at it, we can eliminate a case of variable shadowing. --- Runtime/GuiSys/CCompoundTargetReticle.cpp | 29 ++++++++++++----------- Runtime/GuiSys/CCompoundTargetReticle.hpp | 5 ++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Runtime/GuiSys/CCompoundTargetReticle.cpp b/Runtime/GuiSys/CCompoundTargetReticle.cpp index af9e138d1..9430ac06c 100644 --- a/Runtime/GuiSys/CCompoundTargetReticle.cpp +++ b/Runtime/GuiSys/CCompoundTargetReticle.cpp @@ -71,10 +71,11 @@ CCompoundTargetReticle::CCompoundTargetReticle(const CStateManager& mgr) CCompoundTargetReticle::SScanReticuleRenderer::SScanReticuleRenderer() { CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - for (int i = 0; i < 2; ++i) { + for (size_t i = 0; i < m_lineRenderers.size(); ++i) { m_lineRenderers[i].emplace(ctx, CLineRenderer::EPrimitiveMode::Lines, 8, nullptr, true, true); - for (int j = 0; j < 4; ++j) - m_stripRenderers[i][j].emplace(ctx, CLineRenderer::EPrimitiveMode::LineStrip, 4, nullptr, true, true); + for (auto& stripRenderer : m_stripRenderers[i]) { + stripRenderer.emplace(ctx, CLineRenderer::EPrimitiveMode::LineStrip, 4, nullptr, true, true); + } } return true; } BooTrace); @@ -822,8 +823,8 @@ void CCompoundTargetReticle::DrawNextLockOnGroup(const zeus::CMatrix3f& rot, con float alpha = 0.5f * factor; zeus::CColor color = g_tweakGuiColors->GetScanReticuleColor(); color.a() *= alpha; - for (int i = 0; i < 2; ++i) { - float lineWidth = i ? 2.5f : 1.f; + for (size_t i = 0; i < m_scanRetRenderer.m_lineRenderers.size(); ++i) { + float lineWidth = i != 0 ? 2.5f : 1.f; auto& rend = *m_scanRetRenderer.m_lineRenderers[i]; rend.Reset(); rend.AddVertex({-0.5f, 0.f, 0.f}, color, lineWidth); @@ -836,17 +837,17 @@ void CCompoundTargetReticle::DrawNextLockOnGroup(const zeus::CMatrix3f& rot, con rend.AddVertex({0.f, 0.f, 20.5f}, color, lineWidth); rend.Render(); - for (int j = 0; j < 4; ++j) { + for (size_t j = 0; j < m_scanRetRenderer.m_stripRenderers[i].size(); ++j) { float xSign = j < 2 ? -1.f : 1.f; - float zSign = (j & 0x1) ? -1.f : 1.f; + float zSign = (j & 0x1) != 0 ? -1.f : 1.f; // begin line strip - auto& rend = *m_scanRetRenderer.m_stripRenderers[i][j]; - rend.Reset(); - rend.AddVertex({0.5f * xSign, 0.f, 0.1f * zSign}, color, lineWidth); - rend.AddVertex({0.5f * xSign, 0.f, 0.35f * zSign}, color, lineWidth); - rend.AddVertex({0.35f * xSign, 0.f, 0.5f * zSign}, color, lineWidth); - rend.AddVertex({0.1f * xSign, 0.f, 0.5f * zSign}, color, lineWidth); - rend.Render(); + auto& stripRend = *m_scanRetRenderer.m_stripRenderers[i][j]; + stripRend.Reset(); + stripRend.AddVertex({0.5f * xSign, 0.f, 0.1f * zSign}, color, lineWidth); + stripRend.AddVertex({0.5f * xSign, 0.f, 0.35f * zSign}, color, lineWidth); + stripRend.AddVertex({0.35f * xSign, 0.f, 0.5f * zSign}, color, lineWidth); + stripRend.AddVertex({0.1f * xSign, 0.f, 0.5f * zSign}, color, lineWidth); + stripRend.Render(); } } } diff --git a/Runtime/GuiSys/CCompoundTargetReticle.hpp b/Runtime/GuiSys/CCompoundTargetReticle.hpp index dec5f904d..5049a1c45 100644 --- a/Runtime/GuiSys/CCompoundTargetReticle.hpp +++ b/Runtime/GuiSys/CCompoundTargetReticle.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include "Runtime/CPlayerState.hpp" @@ -125,8 +126,8 @@ private: u32 x228_ = 0; struct SScanReticuleRenderer { - std::optional m_lineRenderers[2]; - std::optional m_stripRenderers[2][4]; + std::array, 2> m_lineRenderers; + std::array, 4>, 2> m_stripRenderers; SScanReticuleRenderer(); }; SScanReticuleRenderer m_scanRetRenderer;