mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Common/CommonFuncs: Remove now-unneccessary ArraySize function
Since C++17, non-member std::size() is present in the standard library which also operates on regular C arrays. Given that, we can just replace usages of ArraySize with that where applicable. In many cases, we can just change the actual C array ArraySize() was called on into a std::array and just use its .size() member function instead. In some other cases, we can collapse the loops they were used in, into a ranged-for loop, eliminating the need for en explicit bounds query.
This commit is contained in:
@ -2,12 +2,12 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include "VideoCommon/PixelShaderManager.h"
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "Common/ChunkFile.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "VideoCommon/PixelShaderManager.h"
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
@ -114,7 +114,7 @@ void PixelShaderManager::SetConstants()
|
||||
constants.fogf[3] =
|
||||
static_cast<float>(g_renderer->EFBToScaledX(static_cast<int>(2.0f * xfmem.viewport.wd)));
|
||||
|
||||
for (size_t i = 0, vec_index = 0; i < ArraySize(bpmem.fogRange.K); i++)
|
||||
for (size_t i = 0, vec_index = 0; i < std::size(bpmem.fogRange.K); i++)
|
||||
{
|
||||
constexpr float scale = 4.0f;
|
||||
constants.fogrange[vec_index / 4][vec_index % 4] = bpmem.fogRange.K[i].GetValue(0) * scale;
|
||||
|
@ -2,7 +2,10 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "VideoCommon/VertexLoaderManager.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
@ -11,7 +14,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Core/HW/Memmap.h"
|
||||
|
||||
@ -23,7 +25,6 @@
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
#include "VideoCommon/Statistics.h"
|
||||
#include "VideoCommon/VertexLoaderBase.h"
|
||||
#include "VideoCommon/VertexLoaderManager.h"
|
||||
#include "VideoCommon/VertexManagerBase.h"
|
||||
#include "VideoCommon/VertexShaderManager.h"
|
||||
|
||||
@ -168,21 +169,21 @@ NativeVertexFormat* GetUberVertexFormat(const PortableVertexDeclaration& decl)
|
||||
CopyAttribute(new_decl.position, decl.position);
|
||||
else
|
||||
MakeDummyAttribute(new_decl.position, VAR_FLOAT, 1, false);
|
||||
for (size_t i = 0; i < ArraySize(new_decl.normals); i++)
|
||||
for (size_t i = 0; i < std::size(new_decl.normals); i++)
|
||||
{
|
||||
if (decl.normals[i].enable)
|
||||
CopyAttribute(new_decl.normals[i], decl.normals[i]);
|
||||
else
|
||||
MakeDummyAttribute(new_decl.normals[i], VAR_FLOAT, 1, false);
|
||||
}
|
||||
for (size_t i = 0; i < ArraySize(new_decl.colors); i++)
|
||||
for (size_t i = 0; i < std::size(new_decl.colors); i++)
|
||||
{
|
||||
if (decl.colors[i].enable)
|
||||
CopyAttribute(new_decl.colors[i], decl.colors[i]);
|
||||
else
|
||||
MakeDummyAttribute(new_decl.colors[i], VAR_UNSIGNED_BYTE, 4, false);
|
||||
}
|
||||
for (size_t i = 0; i < ArraySize(new_decl.texcoords); i++)
|
||||
for (size_t i = 0; i < std::size(new_decl.texcoords); i++)
|
||||
{
|
||||
if (decl.texcoords[i].enable)
|
||||
CopyAttribute(new_decl.texcoords[i], decl.texcoords[i]);
|
||||
|
@ -2,15 +2,15 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <cfloat>
|
||||
#include "VideoCommon/VertexShaderManager.h"
|
||||
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
|
||||
#include "Common/BitSet.h"
|
||||
#include "Common/ChunkFile.h"
|
||||
#include "Common/CommonFuncs.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/Matrix.h"
|
||||
@ -22,7 +22,6 @@
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
#include "VideoCommon/Statistics.h"
|
||||
#include "VideoCommon/VertexManagerBase.h"
|
||||
#include "VideoCommon/VertexShaderManager.h"
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
#include "VideoCommon/XFMemory.h"
|
||||
@ -251,13 +250,14 @@ void VertexShaderManager::SetConstants()
|
||||
if (bTexMatricesChanged[0])
|
||||
{
|
||||
bTexMatricesChanged[0] = false;
|
||||
const float* pos_matrix_ptrs[] = {
|
||||
const std::array<const float*, 4> pos_matrix_ptrs{
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex0MtxIdx * 4],
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex1MtxIdx * 4],
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex2MtxIdx * 4],
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex3MtxIdx * 4]};
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_a.Tex3MtxIdx * 4],
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < ArraySize(pos_matrix_ptrs); ++i)
|
||||
for (size_t i = 0; i < pos_matrix_ptrs.size(); ++i)
|
||||
{
|
||||
memcpy(constants.texmatrices[3 * i].data(), pos_matrix_ptrs[i], 3 * sizeof(float4));
|
||||
}
|
||||
@ -267,13 +267,14 @@ void VertexShaderManager::SetConstants()
|
||||
if (bTexMatricesChanged[1])
|
||||
{
|
||||
bTexMatricesChanged[1] = false;
|
||||
const float* pos_matrix_ptrs[] = {
|
||||
const std::array<const float*, 4> pos_matrix_ptrs{
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex4MtxIdx * 4],
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex5MtxIdx * 4],
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex6MtxIdx * 4],
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex7MtxIdx * 4]};
|
||||
&xfmem.posMatrices[g_main_cp_state.matrix_index_b.Tex7MtxIdx * 4],
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < ArraySize(pos_matrix_ptrs); ++i)
|
||||
for (size_t i = 0; i < pos_matrix_ptrs.size(); ++i)
|
||||
{
|
||||
memcpy(constants.texmatrices[3 * i + 12].data(), pos_matrix_ptrs[i], 3 * sizeof(float4));
|
||||
}
|
||||
@ -461,9 +462,9 @@ void VertexShaderManager::SetConstants()
|
||||
{
|
||||
bTexMtxInfoChanged = false;
|
||||
constants.xfmem_dualTexInfo = xfmem.dualTexTrans.enabled;
|
||||
for (size_t i = 0; i < ArraySize(xfmem.texMtxInfo); i++)
|
||||
for (size_t i = 0; i < std::size(xfmem.texMtxInfo); i++)
|
||||
constants.xfmem_pack1[i][0] = xfmem.texMtxInfo[i].hex;
|
||||
for (size_t i = 0; i < ArraySize(xfmem.postMtxInfo); i++)
|
||||
for (size_t i = 0; i < std::size(xfmem.postMtxInfo); i++)
|
||||
constants.xfmem_pack1[i][1] = xfmem.postMtxInfo[i].hex;
|
||||
|
||||
dirty = true;
|
||||
|
Reference in New Issue
Block a user