Merge pull request #73 from lioncash/ArraySize-Cleanup

Kill off some usages of the ArraySize macro.
This commit is contained in:
Pierre Bourdon 2014-02-15 18:22:28 +01:00
commit cf736cd5df
8 changed files with 44 additions and 45 deletions

View File

@ -111,7 +111,7 @@ bool CompareValues(const u32 val1, const u32 val2, const int type);
// ---------------------- // ----------------------
// AR Remote Functions // AR Remote Functions
void LoadCodes(IniFile &globalIni, IniFile &localIni, bool forceLoad) void LoadCodes(const IniFile& globalIni, const IniFile& localIni, bool forceLoad)
{ {
// Parses the Action Replay section of a game ini file. // Parses the Action Replay section of a game ini file.
if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bEnableCheats if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bEnableCheats
@ -132,22 +132,17 @@ void LoadCodes(IniFile &globalIni, IniFile &localIni, bool forceLoad)
} }
} }
IniFile* inis[] = {&globalIni, &localIni}; const IniFile* inis[2] = {&globalIni, &localIni};
for (size_t i = 0; i < ArraySize(inis); ++i) for (const IniFile* ini : inis)
{ {
std::vector<std::string> lines; std::vector<std::string> lines;
std::vector<std::string> encryptedLines; std::vector<std::string> encryptedLines;
ARCode currentCode; ARCode currentCode;
inis[i]->GetLines("ActionReplay", lines); ini->GetLines("ActionReplay", lines);
std::vector<std::string>::const_iterator for (std::string line : lines)
it = lines.begin(),
lines_end = lines.end();
for (; it != lines_end; ++it)
{ {
const std::string line = *it;
if (line.empty()) if (line.empty())
continue; continue;
@ -171,7 +166,7 @@ void LoadCodes(IniFile &globalIni, IniFile &localIni, bool forceLoad)
currentCode.name = line.substr(1, line.size() - 1); currentCode.name = line.substr(1, line.size() - 1);
currentCode.active = enabledNames.find(currentCode.name) != enabledNames.end(); currentCode.active = enabledNames.find(currentCode.name) != enabledNames.end();
currentCode.user_defined = (i == 1); currentCode.user_defined = (ini == &localIni);
} }
else else
{ {

View File

@ -27,7 +27,7 @@ struct ARCode
void RunAllActive(); void RunAllActive();
bool RunCode(const ARCode &arcode); bool RunCode(const ARCode &arcode);
void LoadCodes(IniFile &globalini, IniFile &localIni, bool forceLoad); void LoadCodes(const IniFile &globalini, const IniFile &localIni, bool forceLoad);
void LoadCodes(std::vector<ARCode> &_arCodes, IniFile &globalini, IniFile &localIni); void LoadCodes(std::vector<ARCode> &_arCodes, IniFile &globalini, IniFile &localIni);
size_t GetCodeListSize(); size_t GetCodeListSize();
ARCode GetARCode(size_t index); ARCode GetARCode(size_t index);

View File

@ -15,11 +15,12 @@ namespace Gecko
void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<GeckoCode>& gcodes) void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<GeckoCode>& gcodes)
{ {
const IniFile* inis[] = {&globalIni, &localIni}; const IniFile* inis[2] = { &globalIni, &localIni };
for (size_t i = 0; i < ArraySize(inis); ++i)
for (const IniFile* ini : inis)
{ {
std::vector<std::string> lines; std::vector<std::string> lines;
inis[i]->GetLines("Gecko", lines, false); ini->GetLines("Gecko", lines, false);
GeckoCode gcode; GeckoCode gcode;
@ -41,7 +42,7 @@ void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<Ge
gcodes.push_back(gcode); gcodes.push_back(gcode);
gcode = GeckoCode(); gcode = GeckoCode();
gcode.enabled = (1 == ss.tellg()); // silly gcode.enabled = (1 == ss.tellg()); // silly
gcode.user_defined = i == 1; gcode.user_defined = (ini == &localIni);
ss.seekg(1, std::ios_base::cur); ss.seekg(1, std::ios_base::cur);
// read the code name // read the code name
std::getline(ss, gcode.name, '['); // stop at [ character (beginning of contributor name) std::getline(ss, gcode.name, '['); // stop at [ character (beginning of contributor name)
@ -73,7 +74,7 @@ void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<Ge
if (gcode.name.size()) if (gcode.name.size())
gcodes.push_back(gcode); gcodes.push_back(gcode);
inis[i]->GetLines("Gecko_Enabled", lines, false); ini->GetLines("Gecko_Enabled", lines, false);
for (auto line : lines) for (auto line : lines)
{ {

View File

@ -63,13 +63,13 @@ void LoadPatchSection(const char *section, std::vector<Patch> &patches,
} }
} }
IniFile* inis[] = {&globalIni, &localIni}; const IniFile* inis[2] = {&globalIni, &localIni};
for (size_t i = 0; i < ArraySize(inis); ++i) for (const IniFile* ini : inis)
{ {
std::vector<std::string> lines; std::vector<std::string> lines;
Patch currentPatch; Patch currentPatch;
inis[i]->GetLines(section, lines); ini->GetLines(section, lines);
for (std::string& line : lines) for (std::string& line : lines)
{ {
@ -86,7 +86,7 @@ void LoadPatchSection(const char *section, std::vector<Patch> &patches,
// Set active and name // Set active and name
currentPatch.name = line.substr(1, line.size() - 1); currentPatch.name = line.substr(1, line.size() - 1);
currentPatch.active = enabledNames.find(currentPatch.name) != enabledNames.end(); currentPatch.active = enabledNames.find(currentPatch.name) != enabledNames.end();
currentPatch.user_defined = (i == 1); currentPatch.user_defined = (ini == &localIni);
} }
else else
{ {

View File

@ -9,20 +9,21 @@ PerfQuery::PerfQuery()
: m_query_read_pos() : m_query_read_pos()
, m_query_count() , m_query_count()
{ {
for (int i = 0; i != ArraySize(m_query_buffer); ++i) for (ActiveQuery& entry : m_query_buffer)
{ {
D3D11_QUERY_DESC qdesc = CD3D11_QUERY_DESC(D3D11_QUERY_OCCLUSION, 0); D3D11_QUERY_DESC qdesc = CD3D11_QUERY_DESC(D3D11_QUERY_OCCLUSION, 0);
D3D::device->CreateQuery(&qdesc, &m_query_buffer[i].query); D3D::device->CreateQuery(&qdesc, &entry.query);
} }
ResetQuery(); ResetQuery();
} }
PerfQuery::~PerfQuery() PerfQuery::~PerfQuery()
{ {
for (int i = 0; i != ArraySize(m_query_buffer); ++i) for (ActiveQuery& entry : m_query_buffer)
{ {
// TODO: EndQuery? // TODO: EndQuery?
m_query_buffer[i].query->Release(); entry.query->Release();
} }
} }
@ -32,10 +33,10 @@ void PerfQuery::EnableQuery(PerfQueryGroup type)
return; return;
// Is this sane? // Is this sane?
if (m_query_count > ArraySize(m_query_buffer) / 2) if (m_query_count > m_query_buffer.size() / 2)
WeakFlush(); WeakFlush();
if (ArraySize(m_query_buffer) == m_query_count) if (m_query_buffer.size() == m_query_count)
{ {
// TODO // TODO
FlushOne(); FlushOne();
@ -45,7 +46,7 @@ void PerfQuery::EnableQuery(PerfQueryGroup type)
// start query // start query
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP) if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
{ {
auto& entry = m_query_buffer[(m_query_read_pos + m_query_count) % ArraySize(m_query_buffer)]; auto& entry = m_query_buffer[(m_query_read_pos + m_query_count) % m_query_buffer.size()];
D3D::context->Begin(entry.query); D3D::context->Begin(entry.query);
entry.query_type = type; entry.query_type = type;
@ -62,7 +63,7 @@ void PerfQuery::DisableQuery(PerfQueryGroup type)
// stop query // stop query
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP) if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
{ {
auto& entry = m_query_buffer[(m_query_read_pos + m_query_count + ArraySize(m_query_buffer)-1) % ArraySize(m_query_buffer)]; auto& entry = m_query_buffer[(m_query_read_pos + m_query_count + m_query_buffer.size()-1) % m_query_buffer.size()];
D3D::context->End(entry.query); D3D::context->End(entry.query);
} }
} }
@ -118,7 +119,7 @@ void PerfQuery::FlushOne()
// NOTE: Reported pixel metrics should be referenced to native resolution // NOTE: Reported pixel metrics should be referenced to native resolution
m_results[entry.query_type] += (u32)(result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight()); m_results[entry.query_type] += (u32)(result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight());
m_query_read_pos = (m_query_read_pos + 1) % ArraySize(m_query_buffer); m_query_read_pos = (m_query_read_pos + 1) % m_query_buffer.size();
--m_query_count; --m_query_count;
} }
@ -149,7 +150,7 @@ void PerfQuery::WeakFlush()
// NOTE: Reported pixel metrics should be referenced to native resolution // NOTE: Reported pixel metrics should be referenced to native resolution
m_results[entry.query_type] += (u32)(result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight()); m_results[entry.query_type] += (u32)(result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight());
m_query_read_pos = (m_query_read_pos + 1) % ArraySize(m_query_buffer); m_query_read_pos = (m_query_read_pos + 1) % m_query_buffer.size();
--m_query_count; --m_query_count;
} }
else else

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <array>
#include "PerfQueryBase.h" #include "PerfQueryBase.h"
namespace DX11 { namespace DX11 {
@ -32,7 +33,7 @@ private:
// when testing in SMS: 64 was too small, 128 was ok // when testing in SMS: 64 was too small, 128 was ok
static const int PERF_QUERY_BUFFER_SIZE = 512; static const int PERF_QUERY_BUFFER_SIZE = 512;
ActiveQuery m_query_buffer[PERF_QUERY_BUFFER_SIZE]; std::array<ActiveQuery, PERF_QUERY_BUFFER_SIZE> m_query_buffer;
int m_query_read_pos; int m_query_read_pos;
// TODO: sloppy // TODO: sloppy

View File

@ -14,16 +14,16 @@ PerfQuery::PerfQuery()
: m_query_read_pos() : m_query_read_pos()
, m_query_count() , m_query_count()
{ {
for (u32 i = 0; i != ArraySize(m_query_buffer); ++i) for (ActiveQuery& query : m_query_buffer)
glGenQueries(1, &m_query_buffer[i].query_id); glGenQueries(1, &query.query_id);
ResetQuery(); ResetQuery();
} }
PerfQuery::~PerfQuery() PerfQuery::~PerfQuery()
{ {
for (u32 i = 0; i != ArraySize(m_query_buffer); ++i) for (ActiveQuery& query : m_query_buffer)
glDeleteQueries(1, &m_query_buffer[i].query_id); glDeleteQueries(1, &query.query_id);
} }
void PerfQuery::EnableQuery(PerfQueryGroup type) void PerfQuery::EnableQuery(PerfQueryGroup type)
@ -32,10 +32,10 @@ void PerfQuery::EnableQuery(PerfQueryGroup type)
return; return;
// Is this sane? // Is this sane?
if (m_query_count > ArraySize(m_query_buffer) / 2) if (m_query_count > m_query_buffer.size() / 2)
WeakFlush(); WeakFlush();
if (ArraySize(m_query_buffer) == m_query_count) if (m_query_buffer.size() == m_query_count)
{ {
FlushOne(); FlushOne();
//ERROR_LOG(VIDEO, "Flushed query buffer early!"); //ERROR_LOG(VIDEO, "Flushed query buffer early!");
@ -44,7 +44,7 @@ void PerfQuery::EnableQuery(PerfQueryGroup type)
// start query // start query
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP) if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
{ {
auto& entry = m_query_buffer[(m_query_read_pos + m_query_count) % ArraySize(m_query_buffer)]; auto& entry = m_query_buffer[(m_query_read_pos + m_query_count) % m_query_buffer.size()];
glBeginQuery(GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL ? GL_SAMPLES_PASSED : GL_ANY_SAMPLES_PASSED, entry.query_id); glBeginQuery(GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL ? GL_SAMPLES_PASSED : GL_ANY_SAMPLES_PASSED, entry.query_id);
entry.query_type = type; entry.query_type = type;
@ -86,7 +86,7 @@ void PerfQuery::FlushOne()
// NOTE: Reported pixel metrics should be referenced to native resolution // NOTE: Reported pixel metrics should be referenced to native resolution
m_results[entry.query_type] += (u64)result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight(); m_results[entry.query_type] += (u64)result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight();
m_query_read_pos = (m_query_read_pos + 1) % ArraySize(m_query_buffer); m_query_read_pos = (m_query_read_pos + 1) % m_query_buffer.size();
--m_query_count; --m_query_count;
} }

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <array>
#include "PerfQueryBase.h" #include "PerfQueryBase.h"
namespace OGL { namespace OGL {
@ -32,7 +33,7 @@ private:
void FlushOne(); void FlushOne();
// This contains gl query objects with unretrieved results. // This contains gl query objects with unretrieved results.
ActiveQuery m_query_buffer[PERF_QUERY_BUFFER_SIZE]; std::array<ActiveQuery, PERF_QUERY_BUFFER_SIZE> m_query_buffer;
u32 m_query_read_pos; u32 m_query_read_pos;
// TODO: sloppy // TODO: sloppy