From 0d3bab4c1482c544c626c0b4adcd272460c4f126 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 29 Mar 2020 21:44:07 -0400 Subject: [PATCH] CScanDisplay: Remove use of const_cast The draw function is essentially not fully const in behavior, so we can remove the const qualifiers where necessary. --- Runtime/GuiSys/CHudDecoInterface.cpp | 7 ++++--- Runtime/GuiSys/CHudDecoInterface.hpp | 4 ++-- Runtime/GuiSys/CScanDisplay.cpp | 29 ++++++++++++++++------------ Runtime/GuiSys/CScanDisplay.hpp | 4 ++-- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Runtime/GuiSys/CHudDecoInterface.cpp b/Runtime/GuiSys/CHudDecoInterface.cpp index 5a7156584..d85df6618 100644 --- a/Runtime/GuiSys/CHudDecoInterface.cpp +++ b/Runtime/GuiSys/CHudDecoInterface.cpp @@ -17,7 +17,7 @@ namespace urde { void IHudDecoInterface::SetReticuleTransform(const zeus::CMatrix3f& xf) {} void IHudDecoInterface::SetDecoRotation(float angle) {} void IHudDecoInterface::SetFrameColorValue(float v) {} -void IHudDecoInterface::Draw() const {} +void IHudDecoInterface::Draw() {} void IHudDecoInterface::ProcessInput(const CFinalInput& input) {} float IHudDecoInterface::GetHudTextAlpha() const { return 1.f; } @@ -325,10 +325,11 @@ void CHudDecoInterfaceScan::Update(float dt, const CStateManager& stateMgr) { UpdateScanDisplay(stateMgr, dt); } -void CHudDecoInterfaceScan::Draw() const { +void CHudDecoInterfaceScan::Draw() { x18_scanDisplay.Draw(); - if (x10_loadedScanHudFlat) + if (x10_loadedScanHudFlat) { x10_loadedScanHudFlat->Draw(CGuiWidgetDrawParms::Default); + } } void CHudDecoInterfaceScan::ProcessInput(const CFinalInput& input) { x18_scanDisplay.ProcessInput(input); } diff --git a/Runtime/GuiSys/CHudDecoInterface.hpp b/Runtime/GuiSys/CHudDecoInterface.hpp index 8b489e854..e6e8f301e 100644 --- a/Runtime/GuiSys/CHudDecoInterface.hpp +++ b/Runtime/GuiSys/CHudDecoInterface.hpp @@ -28,7 +28,7 @@ public: virtual void SetDamageTransform(const zeus::CMatrix3f& rotation, const zeus::CVector3f& position) = 0; virtual void SetFrameColorValue(float v); virtual void Update(float dt, const CStateManager& stateMgr) = 0; - virtual void Draw() const; + virtual void Draw(); virtual void ProcessInput(const CFinalInput& input); virtual void UpdateCameraDebugSettings(float fov, float y, float z) = 0; virtual void UpdateHudAlpha() = 0; @@ -116,7 +116,7 @@ public: const CScannableObjectInfo* GetCurrScanInfo(const CStateManager& stateMgr) const; void UpdateScanDisplay(const CStateManager& stateMgr, float dt); void Update(float dt, const CStateManager& stateMgr) override; - void Draw() const override; + void Draw() override; void ProcessInput(const CFinalInput& input) override; void UpdateCameraDebugSettings(float fov, float y, float z) override; void UpdateHudAlpha() override; diff --git a/Runtime/GuiSys/CScanDisplay.cpp b/Runtime/GuiSys/CScanDisplay.cpp index 12dba9f4c..471f6ee18 100644 --- a/Runtime/GuiSys/CScanDisplay.cpp +++ b/Runtime/GuiSys/CScanDisplay.cpp @@ -35,20 +35,23 @@ void CScanDisplay::CDataDot::Update(float dt) { } } -void CScanDisplay::CDataDot::Draw(const zeus::CColor& col, float radius) const { - if (x24_alpha == 0.f) +void CScanDisplay::CDataDot::Draw(const zeus::CColor& col, float radius) { + if (x24_alpha == 0.f) { return; + } if (x0_dotState != EDotState::Hidden) { - zeus::CTransform xf = zeus::CTransform::Translate(xc_curPos.x(), 0.f, xc_curPos.y()); + const zeus::CTransform xf = zeus::CTransform::Translate(xc_curPos.x(), 0.f, xc_curPos.y()); CGraphics::SetModelMatrix(xf); zeus::CColor useColor = col; useColor.a() *= x24_alpha; - CTexturedQuadFilter::Vert verts[4] = {{{-radius, 0.f, radius}, {0.f, 1.f}}, - {{-radius, 0.f, -radius}, {0.f, 0.f}}, - {{radius, 0.f, radius}, {1.f, 1.f}}, - {{radius, 0.f, -radius}, {1.f, 0.f}}}; - const_cast(m_quad).drawVerts(useColor, verts); + const CTexturedQuadFilter::Vert verts[4] = { + {{-radius, 0.f, radius}, {0.f, 1.f}}, + {{-radius, 0.f, -radius}, {0.f, 0.f}}, + {{radius, 0.f, radius}, {1.f, 1.f}}, + {{radius, 0.f, -radius}, {1.f, 0.f}}, + }; + m_quad.drawVerts(useColor, verts); } } @@ -418,16 +421,18 @@ void CScanDisplay::Update(float dt, float scanningTime) { } } -void CScanDisplay::Draw() const { - if (!x0_dataDot.IsLoaded()) +void CScanDisplay::Draw() { + if (!x0_dataDot.IsLoaded()) { return; + } // No Z-test or write g_Renderer->SetViewportOrtho(true, -4096.f, 4096.f); // Additive alpha - float vpRatio = g_Viewport.xc_height / 480.f; - for (const CDataDot& dot : xbc_dataDots) + const float vpRatio = g_Viewport.xc_height / 480.f; + for (CDataDot& dot : xbc_dataDots) { dot.Draw(g_tweakGuiColors->GetScanDataDotColor(), g_tweakGui->GetScanDataDotRadius() * vpRatio); + } } } // namespace urde diff --git a/Runtime/GuiSys/CScanDisplay.hpp b/Runtime/GuiSys/CScanDisplay.hpp index 15ea47f0d..7b9c60d83 100644 --- a/Runtime/GuiSys/CScanDisplay.hpp +++ b/Runtime/GuiSys/CScanDisplay.hpp @@ -45,7 +45,7 @@ public: public: explicit CDataDot(const TLockedToken& dataDotTex) : m_quad(EFilterType::Add, dataDotTex) {} void Update(float dt); - void Draw(const zeus::CColor& color, float radius) const; + void Draw(const zeus::CColor& color, float radius); float GetTransitionFactor() const { return x1c_transDur > 0.f ? x20_remTime / x1c_transDur : 0.f; } void StartTransitionTo(const zeus::CVector2f&, float); void SetDestPosition(const zeus::CVector2f&); @@ -90,7 +90,7 @@ public: CGuiWidget* textGroup, CGuiModel* xmark, CGuiModel* abutton, CGuiModel* dash, float scanTime); void StopScan(); void Update(float dt, float scanningTime); - void Draw() const; + void Draw(); EScanState GetScanState() const { return xc_state; } TUniqueId ScanTarget() const { return x10_objId; } };