CMaterialPass: Make use of std::array

This commit is contained in:
Lioncash 2020-06-11 17:44:26 -04:00
parent 7b81aa5268
commit aeea0f8052
2 changed files with 32 additions and 40 deletions

View File

@ -10,18 +10,14 @@ CMaterialPass::CMaterialPass(CMaterial *pParent)
CMaterialPass::~CMaterialPass() = default; CMaterialPass::~CMaterialPass() = default;
std::unique_ptr<CMaterialPass> CMaterialPass::Clone(CMaterial* pParent) std::unique_ptr<CMaterialPass> CMaterialPass::Clone(CMaterial* pParent) const
{ {
std::unique_ptr<CMaterialPass> pOut = std::make_unique<CMaterialPass>(pParent); auto pOut = std::make_unique<CMaterialPass>(pParent);
pOut->mPassType = mPassType; pOut->mPassType = mPassType;
pOut->mSettings = mSettings; pOut->mSettings = mSettings;
pOut->mColorInputs = mColorInputs;
for (uint32 iIn = 0; iIn < 4; iIn++) pOut->mAlphaInputs = mAlphaInputs;
{
pOut->mColorInputs[iIn] = mColorInputs[iIn];
pOut->mAlphaInputs[iIn] = mAlphaInputs[iIn];
}
pOut->mColorOutput = mColorOutput; pOut->mColorOutput = mColorOutput;
pOut->mAlphaOutput = mAlphaOutput; pOut->mAlphaOutput = mAlphaOutput;
pOut->mKColorSel = mKColorSel; pOut->mKColorSel = mKColorSel;
@ -32,13 +28,8 @@ std::unique_ptr<CMaterialPass> CMaterialPass::Clone(CMaterial* pParent)
pOut->mTexCoordSource = mTexCoordSource; pOut->mTexCoordSource = mTexCoordSource;
pOut->mpTexture = mpTexture; pOut->mpTexture = mpTexture;
pOut->mAnimMode = mAnimMode; pOut->mAnimMode = mAnimMode;
pOut->mAnimParams = mAnimParams;
for (uint32 iParam = 0; iParam < 8; iParam++) pOut->mTexSwapComps = mTexSwapComps;
pOut->mAnimParams[iParam] = mAnimParams[iParam];
for (uint32 iComp = 0; iComp < 4; iComp++)
pOut->mTexSwapComps[iComp] = mTexSwapComps[iComp];
pOut->mEnabled = mEnabled; pOut->mEnabled = mEnabled;
return pOut; return pOut;
@ -46,25 +37,25 @@ std::unique_ptr<CMaterialPass> CMaterialPass::Clone(CMaterial* pParent)
void CMaterialPass::HashParameters(CFNV1A& rHash) void CMaterialPass::HashParameters(CFNV1A& rHash)
{ {
if (mEnabled) if (!mEnabled)
{ return;
rHash.HashLong(mPassType.ToLong());
rHash.HashLong(mSettings); rHash.HashLong(mPassType.ToLong());
rHash.HashData(&mColorInputs[0], sizeof(ETevColorInput) * 4); rHash.HashLong(mSettings);
rHash.HashData(&mAlphaInputs[0], sizeof(ETevAlphaInput) * 4); rHash.HashData(mColorInputs.data(), sizeof(mColorInputs));
rHash.HashLong(mColorOutput); rHash.HashData(mAlphaInputs.data(), sizeof(mAlphaInputs));
rHash.HashLong(mAlphaOutput); rHash.HashLong(mColorOutput);
rHash.HashLong(mKColorSel); rHash.HashLong(mAlphaOutput);
rHash.HashLong(mKAlphaSel); rHash.HashLong(mKColorSel);
rHash.HashLong(mRasSel); rHash.HashLong(mKAlphaSel);
rHash.HashFloat(mTevColorScale); rHash.HashLong(mRasSel);
rHash.HashFloat(mTevAlphaScale); rHash.HashFloat(mTevColorScale);
rHash.HashLong(mTexCoordSource); rHash.HashFloat(mTevAlphaScale);
rHash.HashLong((uint) mAnimMode); rHash.HashLong(mTexCoordSource);
rHash.HashData(mAnimParams, sizeof(float) * 8); rHash.HashLong(static_cast<uint>(mAnimMode));
rHash.HashData(mTexSwapComps, sizeof(char) * 4); rHash.HashData(mAnimParams.data(), sizeof(mAnimParams));
rHash.HashByte(mEnabled); rHash.HashData(mTexSwapComps.data(), sizeof(mTexSwapComps));
} rHash.HashByte(mEnabled);
} }
void CMaterialPass::LoadTexture(uint32 PassIndex) void CMaterialPass::LoadTexture(uint32 PassIndex)

View File

@ -7,6 +7,7 @@
#include "Core/Render/FRenderOptions.h" #include "Core/Render/FRenderOptions.h"
#include <Common/CFourCC.h> #include <Common/CFourCC.h>
#include <Common/Hash/CFNV1A.h> #include <Common/Hash/CFNV1A.h>
#include <array>
class CMaterial; class CMaterial;
@ -28,8 +29,8 @@ class CMaterialPass
CFourCC mPassType{"CUST"}; CFourCC mPassType{"CUST"};
FPassSettings mSettings{EPassSettings::None}; FPassSettings mSettings{EPassSettings::None};
ETevColorInput mColorInputs[4] = {kZeroRGB, kZeroRGB, kZeroRGB, kZeroRGB}; std::array<ETevColorInput, 4> mColorInputs{kZeroRGB, kZeroRGB, kZeroRGB, kZeroRGB};
ETevAlphaInput mAlphaInputs[4] = {kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha}; std::array<ETevAlphaInput, 4> mAlphaInputs{kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha};
ETevOutput mColorOutput{kPrevReg}; ETevOutput mColorOutput{kPrevReg};
ETevOutput mAlphaOutput{kPrevReg}; ETevOutput mAlphaOutput{kPrevReg};
ETevKSel mKColorSel{kKonstOne}; ETevKSel mKColorSel{kKonstOne};
@ -41,14 +42,14 @@ class CMaterialPass
TResPtr<CTexture> mpTexture{nullptr}; TResPtr<CTexture> mpTexture{nullptr};
EUVAnimMode mAnimMode{EUVAnimMode::NoUVAnim}; EUVAnimMode mAnimMode{EUVAnimMode::NoUVAnim};
EUVConvolutedModeBType mAnimConvolutedModeBType{}; EUVConvolutedModeBType mAnimConvolutedModeBType{};
float mAnimParams[8] = {}; std::array<float, 8> mAnimParams{};
char mTexSwapComps[4] = {'r', 'g', 'b', 'a'}; std::array<char, 4> mTexSwapComps{'r', 'g', 'b', 'a'};
bool mEnabled = true; bool mEnabled = true;
public: public:
explicit CMaterialPass(CMaterial *pParent); explicit CMaterialPass(CMaterial *pParent);
~CMaterialPass(); ~CMaterialPass();
std::unique_ptr<CMaterialPass> Clone(CMaterial *pParent); std::unique_ptr<CMaterialPass> Clone(CMaterial *pParent) const;
void HashParameters(CFNV1A& rHash); void HashParameters(CFNV1A& rHash);
void LoadTexture(uint32 PassIndex); void LoadTexture(uint32 PassIndex);
void SetAnimCurrent(FRenderOptions Options, uint32 PassIndex); void SetAnimCurrent(FRenderOptions Options, uint32 PassIndex);