From aeea0f8052ba6ceb2f6b226949a89a001e88b5e0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 11 Jun 2020 17:44:26 -0400 Subject: [PATCH] CMaterialPass: Make use of std::array --- src/Core/Resource/CMaterialPass.cpp | 61 ++++++++++++----------------- src/Core/Resource/CMaterialPass.h | 11 +++--- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/src/Core/Resource/CMaterialPass.cpp b/src/Core/Resource/CMaterialPass.cpp index 4527d501..83f972bf 100644 --- a/src/Core/Resource/CMaterialPass.cpp +++ b/src/Core/Resource/CMaterialPass.cpp @@ -10,18 +10,14 @@ CMaterialPass::CMaterialPass(CMaterial *pParent) CMaterialPass::~CMaterialPass() = default; -std::unique_ptr CMaterialPass::Clone(CMaterial* pParent) +std::unique_ptr CMaterialPass::Clone(CMaterial* pParent) const { - std::unique_ptr pOut = std::make_unique(pParent); + auto pOut = std::make_unique(pParent); + pOut->mPassType = mPassType; pOut->mSettings = mSettings; - - for (uint32 iIn = 0; iIn < 4; iIn++) - { - pOut->mColorInputs[iIn] = mColorInputs[iIn]; - pOut->mAlphaInputs[iIn] = mAlphaInputs[iIn]; - } - + pOut->mColorInputs = mColorInputs; + pOut->mAlphaInputs = mAlphaInputs; pOut->mColorOutput = mColorOutput; pOut->mAlphaOutput = mAlphaOutput; pOut->mKColorSel = mKColorSel; @@ -32,13 +28,8 @@ std::unique_ptr CMaterialPass::Clone(CMaterial* pParent) pOut->mTexCoordSource = mTexCoordSource; pOut->mpTexture = mpTexture; pOut->mAnimMode = mAnimMode; - - for (uint32 iParam = 0; iParam < 8; iParam++) - pOut->mAnimParams[iParam] = mAnimParams[iParam]; - - for (uint32 iComp = 0; iComp < 4; iComp++) - pOut->mTexSwapComps[iComp] = mTexSwapComps[iComp]; - + pOut->mAnimParams = mAnimParams; + pOut->mTexSwapComps = mTexSwapComps; pOut->mEnabled = mEnabled; return pOut; @@ -46,25 +37,25 @@ std::unique_ptr CMaterialPass::Clone(CMaterial* pParent) void CMaterialPass::HashParameters(CFNV1A& rHash) { - if (mEnabled) - { - rHash.HashLong(mPassType.ToLong()); - rHash.HashLong(mSettings); - rHash.HashData(&mColorInputs[0], sizeof(ETevColorInput) * 4); - rHash.HashData(&mAlphaInputs[0], sizeof(ETevAlphaInput) * 4); - rHash.HashLong(mColorOutput); - rHash.HashLong(mAlphaOutput); - rHash.HashLong(mKColorSel); - rHash.HashLong(mKAlphaSel); - rHash.HashLong(mRasSel); - rHash.HashFloat(mTevColorScale); - rHash.HashFloat(mTevAlphaScale); - rHash.HashLong(mTexCoordSource); - rHash.HashLong((uint) mAnimMode); - rHash.HashData(mAnimParams, sizeof(float) * 8); - rHash.HashData(mTexSwapComps, sizeof(char) * 4); - rHash.HashByte(mEnabled); - } + if (!mEnabled) + return; + + rHash.HashLong(mPassType.ToLong()); + rHash.HashLong(mSettings); + rHash.HashData(mColorInputs.data(), sizeof(mColorInputs)); + rHash.HashData(mAlphaInputs.data(), sizeof(mAlphaInputs)); + rHash.HashLong(mColorOutput); + rHash.HashLong(mAlphaOutput); + rHash.HashLong(mKColorSel); + rHash.HashLong(mKAlphaSel); + rHash.HashLong(mRasSel); + rHash.HashFloat(mTevColorScale); + rHash.HashFloat(mTevAlphaScale); + rHash.HashLong(mTexCoordSource); + rHash.HashLong(static_cast(mAnimMode)); + rHash.HashData(mAnimParams.data(), sizeof(mAnimParams)); + rHash.HashData(mTexSwapComps.data(), sizeof(mTexSwapComps)); + rHash.HashByte(mEnabled); } void CMaterialPass::LoadTexture(uint32 PassIndex) diff --git a/src/Core/Resource/CMaterialPass.h b/src/Core/Resource/CMaterialPass.h index 0698c0ce..87e35b21 100644 --- a/src/Core/Resource/CMaterialPass.h +++ b/src/Core/Resource/CMaterialPass.h @@ -7,6 +7,7 @@ #include "Core/Render/FRenderOptions.h" #include #include +#include class CMaterial; @@ -28,8 +29,8 @@ class CMaterialPass CFourCC mPassType{"CUST"}; FPassSettings mSettings{EPassSettings::None}; - ETevColorInput mColorInputs[4] = {kZeroRGB, kZeroRGB, kZeroRGB, kZeroRGB}; - ETevAlphaInput mAlphaInputs[4] = {kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha}; + std::array mColorInputs{kZeroRGB, kZeroRGB, kZeroRGB, kZeroRGB}; + std::array mAlphaInputs{kZeroAlpha, kZeroAlpha, kZeroAlpha, kZeroAlpha}; ETevOutput mColorOutput{kPrevReg}; ETevOutput mAlphaOutput{kPrevReg}; ETevKSel mKColorSel{kKonstOne}; @@ -41,14 +42,14 @@ class CMaterialPass TResPtr mpTexture{nullptr}; EUVAnimMode mAnimMode{EUVAnimMode::NoUVAnim}; EUVConvolutedModeBType mAnimConvolutedModeBType{}; - float mAnimParams[8] = {}; - char mTexSwapComps[4] = {'r', 'g', 'b', 'a'}; + std::array mAnimParams{}; + std::array mTexSwapComps{'r', 'g', 'b', 'a'}; bool mEnabled = true; public: explicit CMaterialPass(CMaterial *pParent); ~CMaterialPass(); - std::unique_ptr Clone(CMaterial *pParent); + std::unique_ptr Clone(CMaterial *pParent) const; void HashParameters(CFNV1A& rHash); void LoadTexture(uint32 PassIndex); void SetAnimCurrent(FRenderOptions Options, uint32 PassIndex);