Skip to content

Commit

Permalink
Merge pull request #73 from lioncash/ArraySize-Cleanup
Browse files Browse the repository at this point in the history
Kill off some usages of the ArraySize macro.
  • Loading branch information
delroth committed Feb 15, 2014
2 parents 48798d8 + 655d225 commit cf736cd
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 45 deletions.
17 changes: 6 additions & 11 deletions Source/Core/Core/ActionReplay.cpp
Expand Up @@ -111,7 +111,7 @@ bool CompareValues(const u32 val1, const u32 val2, const int type);

// ----------------------
// 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.
if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bEnableCheats
Expand All @@ -132,22 +132,17 @@ void LoadCodes(IniFile &globalIni, IniFile &localIni, bool forceLoad)
}
}

IniFile* inis[] = {&globalIni, &localIni};
for (size_t i = 0; i < ArraySize(inis); ++i)
const IniFile* inis[2] = {&globalIni, &localIni};
for (const IniFile* ini : inis)
{
std::vector<std::string> lines;
std::vector<std::string> encryptedLines;
ARCode currentCode;

inis[i]->GetLines("ActionReplay", lines);
ini->GetLines("ActionReplay", lines);

std::vector<std::string>::const_iterator
it = lines.begin(),
lines_end = lines.end();
for (; it != lines_end; ++it)
for (std::string line : lines)
{
const std::string line = *it;

if (line.empty())
continue;

Expand All @@ -171,7 +166,7 @@ void LoadCodes(IniFile &globalIni, IniFile &localIni, bool forceLoad)

currentCode.name = line.substr(1, line.size() - 1);
currentCode.active = enabledNames.find(currentCode.name) != enabledNames.end();
currentCode.user_defined = (i == 1);
currentCode.user_defined = (ini == &localIni);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/ActionReplay.h
Expand Up @@ -27,7 +27,7 @@ struct ARCode

void RunAllActive();
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);
size_t GetCodeListSize();
ARCode GetARCode(size_t index);
Expand Down
15 changes: 8 additions & 7 deletions Source/Core/Core/GeckoCodeConfig.cpp
Expand Up @@ -15,11 +15,12 @@ namespace Gecko

void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<GeckoCode>& gcodes)
{
const IniFile* inis[] = {&globalIni, &localIni};
for (size_t i = 0; i < ArraySize(inis); ++i)
const IniFile* inis[2] = { &globalIni, &localIni };

for (const IniFile* ini : inis)
{
std::vector<std::string> lines;
inis[i]->GetLines("Gecko", lines, false);
ini->GetLines("Gecko", lines, false);

GeckoCode gcode;

Expand All @@ -40,11 +41,11 @@ void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<Ge
if (gcode.name.size())
gcodes.push_back(gcode);
gcode = GeckoCode();
gcode.enabled = (1 == ss.tellg()); // silly
gcode.user_defined = i == 1;
gcode.enabled = (1 == ss.tellg()); // silly
gcode.user_defined = (ini == &localIni);
ss.seekg(1, std::ios_base::cur);
// 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)
gcode.name = StripSpaces(gcode.name);
// read the code creator name
std::getline(ss, gcode.creator, ']');
Expand Down Expand Up @@ -73,7 +74,7 @@ void LoadCodes(const IniFile& globalIni, const IniFile& localIni, std::vector<Ge
if (gcode.name.size())
gcodes.push_back(gcode);

inis[i]->GetLines("Gecko_Enabled", lines, false);
ini->GetLines("Gecko_Enabled", lines, false);

for (auto line : lines)
{
Expand Down
12 changes: 6 additions & 6 deletions Source/Core/Core/PatchEngine.cpp
Expand Up @@ -46,8 +46,8 @@ std::vector<Patch> onFrame;
std::map<u32, int> speedHacks;
std::vector<std::string> discList;

void LoadPatchSection(const char *section, std::vector<Patch> &patches,
IniFile &globalIni, IniFile &localIni)
void LoadPatchSection(const char *section, std::vector<Patch>& patches,
IniFile& globalIni, IniFile& localIni)
{
// Load the name of all enabled patches
std::string enabledSectionName = std::string(section) + "_Enabled";
Expand All @@ -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;
Patch currentPatch;
inis[i]->GetLines(section, lines);
ini->GetLines(section, lines);

for (std::string& line : lines)
{
Expand All @@ -86,7 +86,7 @@ void LoadPatchSection(const char *section, std::vector<Patch> &patches,
// Set active and name
currentPatch.name = line.substr(1, line.size() - 1);
currentPatch.active = enabledNames.find(currentPatch.name) != enabledNames.end();
currentPatch.user_defined = (i == 1);
currentPatch.user_defined = (ini == &localIni);
}
else
{
Expand Down
21 changes: 11 additions & 10 deletions Source/Core/VideoBackends/D3D/PerfQuery.cpp
Expand Up @@ -9,20 +9,21 @@ PerfQuery::PerfQuery()
: m_query_read_pos()
, 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);
D3D::device->CreateQuery(&qdesc, &m_query_buffer[i].query);
D3D::device->CreateQuery(&qdesc, &entry.query);
}

ResetQuery();
}

PerfQuery::~PerfQuery()
{
for (int i = 0; i != ArraySize(m_query_buffer); ++i)
for (ActiveQuery& entry : m_query_buffer)
{
// TODO: EndQuery?
m_query_buffer[i].query->Release();
entry.query->Release();
}
}

Expand All @@ -32,10 +33,10 @@ void PerfQuery::EnableQuery(PerfQueryGroup type)
return;

// Is this sane?
if (m_query_count > ArraySize(m_query_buffer) / 2)
if (m_query_count > m_query_buffer.size() / 2)
WeakFlush();

if (ArraySize(m_query_buffer) == m_query_count)
if (m_query_buffer.size() == m_query_count)
{
// TODO
FlushOne();
Expand All @@ -45,7 +46,7 @@ void PerfQuery::EnableQuery(PerfQueryGroup type)
// start query
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);
entry.query_type = type;
Expand All @@ -62,7 +63,7 @@ void PerfQuery::DisableQuery(PerfQueryGroup type)
// stop query
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);
}
}
Expand Down Expand Up @@ -118,7 +119,7 @@ void PerfQuery::FlushOne()
// 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_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;
}

Expand Down Expand Up @@ -149,7 +150,7 @@ void PerfQuery::WeakFlush()
// 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_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;
}
else
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/VideoBackends/D3D/PerfQuery.h
@@ -1,5 +1,6 @@
#pragma once

#include <array>
#include "PerfQueryBase.h"

namespace DX11 {
Expand Down Expand Up @@ -32,7 +33,7 @@ class PerfQuery : public PerfQueryBase
// when testing in SMS: 64 was too small, 128 was ok
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;

// TODO: sloppy
Expand Down
16 changes: 8 additions & 8 deletions Source/Core/VideoBackends/OGL/PerfQuery.cpp
Expand Up @@ -14,16 +14,16 @@ PerfQuery::PerfQuery()
: m_query_read_pos()
, m_query_count()
{
for (u32 i = 0; i != ArraySize(m_query_buffer); ++i)
glGenQueries(1, &m_query_buffer[i].query_id);
for (ActiveQuery& query : m_query_buffer)
glGenQueries(1, &query.query_id);

ResetQuery();
}

PerfQuery::~PerfQuery()
{
for (u32 i = 0; i != ArraySize(m_query_buffer); ++i)
glDeleteQueries(1, &m_query_buffer[i].query_id);
for (ActiveQuery& query : m_query_buffer)
glDeleteQueries(1, &query.query_id);
}

void PerfQuery::EnableQuery(PerfQueryGroup type)
Expand All @@ -32,10 +32,10 @@ void PerfQuery::EnableQuery(PerfQueryGroup type)
return;

// Is this sane?
if (m_query_count > ArraySize(m_query_buffer) / 2)
if (m_query_count > m_query_buffer.size() / 2)
WeakFlush();

if (ArraySize(m_query_buffer) == m_query_count)
if (m_query_buffer.size() == m_query_count)
{
FlushOne();
//ERROR_LOG(VIDEO, "Flushed query buffer early!");
Expand All @@ -44,7 +44,7 @@ void PerfQuery::EnableQuery(PerfQueryGroup type)
// start query
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);
entry.query_type = type;
Expand Down Expand Up @@ -86,7 +86,7 @@ void PerfQuery::FlushOne()
// 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_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;
}

Expand Down
3 changes: 2 additions & 1 deletion Source/Core/VideoBackends/OGL/PerfQuery.h
@@ -1,5 +1,6 @@
#pragma once

#include <array>
#include "PerfQueryBase.h"

namespace OGL {
Expand Down Expand Up @@ -32,7 +33,7 @@ class PerfQuery : public PerfQueryBase
void FlushOne();

// 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;

// TODO: sloppy
Expand Down

0 comments on commit cf736cd

Please sign in to comment.