From 15e4d4aa0182ac9bb3fd07fb5eddc42751437d1f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 17 Mar 2020 21:18:52 -0400 Subject: [PATCH] CAuiImagePane: Make use of std::array where applicable Same behavior, stronger typing. --- Runtime/GuiSys/CAuiImagePane.cpp | 42 +++++++++++++++++--------------- Runtime/GuiSys/CAuiImagePane.hpp | 10 +++++--- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Runtime/GuiSys/CAuiImagePane.cpp b/Runtime/GuiSys/CAuiImagePane.cpp index 027b15306..2bcfefce4 100644 --- a/Runtime/GuiSys/CAuiImagePane.cpp +++ b/Runtime/GuiSys/CAuiImagePane.cpp @@ -54,9 +54,9 @@ void CAuiImagePane::Update(float dt) { CAuiImagePane::Filters::Filters(TLockedToken& tex) : m_texId(tex.GetObjectTag()->id) , m_darkenerQuad(EFilterType::Blend, tex) -, m_flashQuad{{EFilterType::Add, tex}, {EFilterType::Add, tex}} -, m_alphaQuad{{EFilterType::Blend, tex}, {EFilterType::Blend, tex}} -, m_addQuad{{EFilterType::Add, tex}, {EFilterType::Add, tex}} {} +, m_flashQuad{{{EFilterType::Add, tex}, {EFilterType::Add, tex}}} +, m_alphaQuad{{{EFilterType::Blend, tex}, {EFilterType::Blend, tex}}} +, m_addQuad{{{EFilterType::Add, tex}, {EFilterType::Add, tex}}} {} void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& tex, int frame, float alpha, bool noBlur, CTexturedQuadFilterAlpha& quad) const { @@ -66,13 +66,13 @@ void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& t rstl::reserved_vector vec; const rstl::reserved_vector* useUVs; if (x138_tileSize != zeus::skZero2f) { - zeus::CVector2f res(xb8_tex0Tok->GetWidth(), xb8_tex0Tok->GetHeight()); - zeus::CVector2f tmp = res / x138_tileSize; - zeus::CVector2f tmpRecip = x138_tileSize / res; - float x0 = tmpRecip.x() * (frame % int(tmp.x())); - float x1 = x0 + tmpRecip.x(); - float y0 = tmpRecip.y() * (frame % int(tmp.y())); - float y1 = y0 + tmpRecip.y(); + const zeus::CVector2f res(xb8_tex0Tok->GetWidth(), xb8_tex0Tok->GetHeight()); + const zeus::CVector2f tmp = res / x138_tileSize; + const zeus::CVector2f tmpRecip = x138_tileSize / res; + const float x0 = tmpRecip.x() * (frame % int(tmp.x())); + const float x1 = x0 + tmpRecip.x(); + const float y0 = tmpRecip.y() * (frame % int(tmp.y())); + const float y1 = y0 + tmpRecip.y(); vec.push_back(zeus::CVector2f(x0, y0)); vec.push_back(zeus::CVector2f(x0, y1)); vec.push_back(zeus::CVector2f(x1, y0)); @@ -82,20 +82,22 @@ void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& t useUVs = &x114_uvs; } - CTexturedQuadFilter::Vert verts[] = {{xe0_coords[0], (*useUVs)[0] + xd0_uvBias0}, - {xe0_coords[1], (*useUVs)[1] + xd0_uvBias0}, - {xe0_coords[3], (*useUVs)[3] + xd0_uvBias0}, - {xe0_coords[2], (*useUVs)[2] + xd0_uvBias0}}; + const std::array verts{{ + {xe0_coords[0], (*useUVs)[0] + xd0_uvBias0}, + {xe0_coords[1], (*useUVs)[1] + xd0_uvBias0}, + {xe0_coords[3], (*useUVs)[3] + xd0_uvBias0}, + {xe0_coords[2], (*useUVs)[2] + xd0_uvBias0}, + }}; if (noBlur) { - quad.drawVerts(useColor, verts); + quad.drawVerts(useColor, verts.data()); } else if ((x14c_deResFactor == 0.f && alpha == 1.f) || tex.GetNumMips() == 1) { - quad.drawVerts(useColor, verts, 0.f); + quad.drawVerts(useColor, verts.data(), 0.f); } else { - float tmp = (1.f - x14c_deResFactor) * alpha; - float tmp3 = 1.f - tmp * tmp * tmp; - float mip = tmp3 * (tex.GetNumMips() - 1); - quad.drawVerts(useColor, verts, mip); + const float tmp = (1.f - x14c_deResFactor) * alpha; + const float tmp3 = 1.f - tmp * tmp * tmp; + const float mip = tmp3 * (tex.GetNumMips() - 1); + quad.drawVerts(useColor, verts.data(), mip); } } diff --git a/Runtime/GuiSys/CAuiImagePane.hpp b/Runtime/GuiSys/CAuiImagePane.hpp index 528a83417..5b7b20f57 100644 --- a/Runtime/GuiSys/CAuiImagePane.hpp +++ b/Runtime/GuiSys/CAuiImagePane.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "Runtime/CToken.hpp" #include "Runtime/rstl.hpp" #include "Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp" @@ -33,10 +35,10 @@ class CAuiImagePane : public CGuiWidget { struct Filters { CAssetId m_texId; CTexturedQuadFilterAlpha m_darkenerQuad; - CTexturedQuadFilterAlpha m_flashQuad[2]; - CTexturedQuadFilterAlpha m_alphaQuad[2]; - CTexturedQuadFilterAlpha m_addQuad[2]; - Filters(TLockedToken& tex); + std::array m_flashQuad; + std::array m_alphaQuad; + std::array m_addQuad; + explicit Filters(TLockedToken& tex); }; std::optional m_filters; void DoDrawImagePane(const zeus::CColor& color, const CTexture& tex, int frame, float blurAmt, bool noBlur,