Merge pull request #244 from lioncash/pane

CAui*: Make use of std::array where applicable
This commit is contained in:
Luke Street 2020-03-18 01:03:50 -04:00 committed by GitHub
commit 7c8de88fd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 31 deletions

View File

@ -54,15 +54,16 @@ void CAuiEnergyBarT01::Update(float dt) {
} }
void CAuiEnergyBarT01::Draw(const CGuiWidgetDrawParms& drawParms) const { void CAuiEnergyBarT01::Draw(const CGuiWidgetDrawParms& drawParms) const {
if (!xbc_tex || !xbc_tex.IsLoaded() || !xd8_coordFunc) if (!xbc_tex || !xbc_tex.IsLoaded() || !xd8_coordFunc) {
return; return;
}
SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(fmt("CAuiEnergyBarT01::Draw {}"), m_name).c_str(), zeus::skCyan); SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(fmt("CAuiEnergyBarT01::Draw {}"), m_name).c_str(), zeus::skCyan);
CGraphics::SetModelMatrix(x34_worldXF); CGraphics::SetModelMatrix(x34_worldXF);
const_cast<CEnergyBarShader&>(m_energyBarShader).updateModelMatrix(); const_cast<CEnergyBarShader&>(m_energyBarShader).updateModelMatrix();
float filledT = xe0_maxEnergy > 0.f ? xf8_filledEnergy / xe0_maxEnergy : 0.f; const float filledT = xe0_maxEnergy > 0.f ? xf8_filledEnergy / xe0_maxEnergy : 0.f;
float shadowT = xe0_maxEnergy > 0.f ? xfc_shadowEnergy / xe0_maxEnergy : 0.f; const float shadowT = xe0_maxEnergy > 0.f ? xfc_shadowEnergy / xe0_maxEnergy : 0.f;
zeus::CColor filledColor = xd0_filledColor; zeus::CColor filledColor = xd0_filledColor;
filledColor.a() *= drawParms.x0_alphaMod; filledColor.a() *= drawParms.x0_alphaMod;
@ -76,7 +77,7 @@ void CAuiEnergyBarT01::Draw(const CGuiWidgetDrawParms& drawParms) const {
emptyColor.a() *= drawParms.x0_alphaMod; emptyColor.a() *= drawParms.x0_alphaMod;
emptyColor *= xa8_color2; emptyColor *= xa8_color2;
for (int i = 0; i < 3; ++i) { for (size_t i = 0; i < m_verts.size(); ++i) {
std::vector<CEnergyBarShader::Vertex>& verts = const_cast<CAuiEnergyBarT01&>(*this).m_verts[i]; std::vector<CEnergyBarShader::Vertex>& verts = const_cast<CAuiEnergyBarT01&>(*this).m_verts[i];
verts.clear(); verts.clear();
@ -98,8 +99,9 @@ void CAuiEnergyBarT01::Draw(const CGuiWidgetDrawParms& drawParms) const {
break; break;
} }
if (start == end) if (start == end) {
continue; continue;
}
std::pair<zeus::CVector3f, zeus::CVector3f> coords = xd8_coordFunc(start); std::pair<zeus::CVector3f, zeus::CVector3f> coords = xd8_coordFunc(start);
while (start < end) { while (start < end) {

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <array>
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -16,7 +17,7 @@ class CSimplePool;
class CAuiEnergyBarT01 : public CGuiWidget { class CAuiEnergyBarT01 : public CGuiWidget {
public: public:
typedef std::pair<zeus::CVector3f, zeus::CVector3f> (*FCoordFunc)(float t); using FCoordFunc = std::pair<zeus::CVector3f, zeus::CVector3f> (*)(float t);
enum class ESetMode { Normal, Wrapped, Insta }; enum class ESetMode { Normal, Wrapped, Insta };
private: private:
@ -38,7 +39,7 @@ private:
float xfc_shadowEnergy = 0.f; float xfc_shadowEnergy = 0.f;
float x100_shadowDrainDelayTimer = 0.f; float x100_shadowDrainDelayTimer = 0.f;
CEnergyBarShader m_energyBarShader; CEnergyBarShader m_energyBarShader;
std::vector<CEnergyBarShader::Vertex> m_verts[3]; std::array<std::vector<CEnergyBarShader::Vertex>, 3> m_verts;
public: public:
CAuiEnergyBarT01(const CGuiWidgetParms& parms, CSimplePool* sp, CAssetId txtrId); CAuiEnergyBarT01(const CGuiWidgetParms& parms, CSimplePool* sp, CAssetId txtrId);

View File

@ -54,9 +54,9 @@ void CAuiImagePane::Update(float dt) {
CAuiImagePane::Filters::Filters(TLockedToken<CTexture>& tex) CAuiImagePane::Filters::Filters(TLockedToken<CTexture>& tex)
: m_texId(tex.GetObjectTag()->id) : m_texId(tex.GetObjectTag()->id)
, m_darkenerQuad(EFilterType::Blend, tex) , m_darkenerQuad(EFilterType::Blend, tex)
, m_flashQuad{{EFilterType::Add, tex}, {EFilterType::Add, tex}} , m_flashQuad{{{EFilterType::Add, tex}, {EFilterType::Add, tex}}}
, m_alphaQuad{{EFilterType::Blend, tex}, {EFilterType::Blend, tex}} , m_alphaQuad{{{EFilterType::Blend, tex}, {EFilterType::Blend, tex}}}
, m_addQuad{{EFilterType::Add, tex}, {EFilterType::Add, 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, void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& tex, int frame, float alpha, bool noBlur,
CTexturedQuadFilterAlpha& quad) const { CTexturedQuadFilterAlpha& quad) const {
@ -66,13 +66,13 @@ void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& t
rstl::reserved_vector<zeus::CVector2f, 4> vec; rstl::reserved_vector<zeus::CVector2f, 4> vec;
const rstl::reserved_vector<zeus::CVector2f, 4>* useUVs; const rstl::reserved_vector<zeus::CVector2f, 4>* useUVs;
if (x138_tileSize != zeus::skZero2f) { if (x138_tileSize != zeus::skZero2f) {
zeus::CVector2f res(xb8_tex0Tok->GetWidth(), xb8_tex0Tok->GetHeight()); const zeus::CVector2f res(xb8_tex0Tok->GetWidth(), xb8_tex0Tok->GetHeight());
zeus::CVector2f tmp = res / x138_tileSize; const zeus::CVector2f tmp = res / x138_tileSize;
zeus::CVector2f tmpRecip = x138_tileSize / res; const zeus::CVector2f tmpRecip = x138_tileSize / res;
float x0 = tmpRecip.x() * (frame % int(tmp.x())); const float x0 = tmpRecip.x() * (frame % int(tmp.x()));
float x1 = x0 + tmpRecip.x(); const float x1 = x0 + tmpRecip.x();
float y0 = tmpRecip.y() * (frame % int(tmp.y())); const float y0 = tmpRecip.y() * (frame % int(tmp.y()));
float y1 = y0 + tmpRecip.y(); const float y1 = y0 + tmpRecip.y();
vec.push_back(zeus::CVector2f(x0, y0)); vec.push_back(zeus::CVector2f(x0, y0));
vec.push_back(zeus::CVector2f(x0, y1)); vec.push_back(zeus::CVector2f(x0, y1));
vec.push_back(zeus::CVector2f(x1, y0)); vec.push_back(zeus::CVector2f(x1, y0));
@ -82,20 +82,22 @@ void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, const CTexture& t
useUVs = &x114_uvs; useUVs = &x114_uvs;
} }
CTexturedQuadFilter::Vert verts[] = {{xe0_coords[0], (*useUVs)[0] + xd0_uvBias0}, const std::array<CTexturedQuadFilter::Vert, 4> verts{{
{xe0_coords[0], (*useUVs)[0] + xd0_uvBias0},
{xe0_coords[1], (*useUVs)[1] + xd0_uvBias0}, {xe0_coords[1], (*useUVs)[1] + xd0_uvBias0},
{xe0_coords[3], (*useUVs)[3] + xd0_uvBias0}, {xe0_coords[3], (*useUVs)[3] + xd0_uvBias0},
{xe0_coords[2], (*useUVs)[2] + xd0_uvBias0}}; {xe0_coords[2], (*useUVs)[2] + xd0_uvBias0},
}};
if (noBlur) { if (noBlur) {
quad.drawVerts(useColor, verts); quad.drawVerts(useColor, verts.data());
} else if ((x14c_deResFactor == 0.f && alpha == 1.f) || tex.GetNumMips() == 1) { } 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 { } else {
float tmp = (1.f - x14c_deResFactor) * alpha; const float tmp = (1.f - x14c_deResFactor) * alpha;
float tmp3 = 1.f - tmp * tmp * tmp; const float tmp3 = 1.f - tmp * tmp * tmp;
float mip = tmp3 * (tex.GetNumMips() - 1); const float mip = tmp3 * (tex.GetNumMips() - 1);
quad.drawVerts(useColor, verts, mip); quad.drawVerts(useColor, verts.data(), mip);
} }
} }

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <array>
#include "Runtime/CToken.hpp" #include "Runtime/CToken.hpp"
#include "Runtime/rstl.hpp" #include "Runtime/rstl.hpp"
#include "Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp" #include "Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp"
@ -33,10 +35,10 @@ class CAuiImagePane : public CGuiWidget {
struct Filters { struct Filters {
CAssetId m_texId; CAssetId m_texId;
CTexturedQuadFilterAlpha m_darkenerQuad; CTexturedQuadFilterAlpha m_darkenerQuad;
CTexturedQuadFilterAlpha m_flashQuad[2]; std::array<CTexturedQuadFilterAlpha, 2> m_flashQuad;
CTexturedQuadFilterAlpha m_alphaQuad[2]; std::array<CTexturedQuadFilterAlpha, 2> m_alphaQuad;
CTexturedQuadFilterAlpha m_addQuad[2]; std::array<CTexturedQuadFilterAlpha, 2> m_addQuad;
Filters(TLockedToken<CTexture>& tex); explicit Filters(TLockedToken<CTexture>& tex);
}; };
std::optional<Filters> m_filters; std::optional<Filters> m_filters;
void DoDrawImagePane(const zeus::CColor& color, const CTexture& tex, int frame, float blurAmt, bool noBlur, void DoDrawImagePane(const zeus::CColor& color, const CTexture& tex, int frame, float blurAmt, bool noBlur,