Replace ARRAYSIZE macro with another ugly macro. At least this will throw an error for a non-array and won't conflict with Windows macro names.

This commit is contained in:
Jordan Woyak 2013-09-11 19:19:36 -05:00
parent ce49964dfe
commit fde3815d34
7 changed files with 45 additions and 33 deletions

View File

@ -12,6 +12,18 @@
#define SLEEP(x) usleep(x*1000) #define SLEEP(x) usleep(x*1000)
#endif #endif
#include <cstddef>
// TODO: make into function when type_traits and constexpr are available
template <typename T, std::size_t N = 0>
struct ArraySizeImpl {};
template <typename T, std::size_t N>
struct ArraySizeImpl<T[N], 0> { static const std::size_t size = N; };
// Will fail to compile on a non-array:
#define ArraySize(x) ArraySizeImpl<decltype(x)>::size
template <bool> struct CompileTimeAssert; template <bool> struct CompileTimeAssert;
template<> struct CompileTimeAssert<true> {}; template<> struct CompileTimeAssert<true> {};
@ -52,7 +64,7 @@ _mm_shuffle_epi8(__m128i a, __m128i mask)
#else #else
#define Crash() {asm ("int $3");} #define Crash() {asm ("int $3");}
#endif #endif
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
// GCC 4.8 defines all the rotate functions now // GCC 4.8 defines all the rotate functions now
// Small issue with GCC's lrotl/lrotr intrinsics is they are still 32bit while we require 64bit // Small issue with GCC's lrotl/lrotr intrinsics is they are still 32bit while we require 64bit
#ifndef _rotl #ifndef _rotl

View File

@ -116,7 +116,7 @@ void GeckoSockServer::ClientThread()
char data[128]; char data[128];
std::size_t got = 0; std::size_t got = 0;
if (client.Receive(&data[0], ARRAYSIZE(data), got) == sf::Socket::Disconnected) if (client.Receive(&data[0], ArraySize(data), got) == sf::Socket::Disconnected)
client_running = false; client_running = false;
if (got != 0) if (got != 0)

View File

@ -696,7 +696,7 @@ void ReadHeader()
bongos = tmpHeader.bongos; bongos = tmpHeader.bongos;
bSyncGPU = tmpHeader.bSyncGPU; bSyncGPU = tmpHeader.bSyncGPU;
bNetPlay = tmpHeader.bNetPlay; bNetPlay = tmpHeader.bNetPlay;
memcpy(revision, tmpHeader.revision, ARRAYSIZE(revision)); memcpy(revision, tmpHeader.revision, ArraySize(revision));
} }
else else
{ {
@ -1110,7 +1110,7 @@ void SaveRecording(const char *filename)
header.bProgressive = bProgressive; header.bProgressive = bProgressive;
header.bDSPHLE = bDSPHLE; header.bDSPHLE = bDSPHLE;
header.bFastDiscSpeed = bFastDiscSpeed; header.bFastDiscSpeed = bFastDiscSpeed;
strncpy((char *)header.videoBackend, videoBackend.c_str(),ARRAYSIZE(header.videoBackend)); strncpy((char *)header.videoBackend, videoBackend.c_str(),ArraySize(header.videoBackend));
header.CPUCore = iCPUCore; header.CPUCore = iCPUCore;
header.bEFBAccessEnable = g_ActiveConfig.bEFBAccessEnable; header.bEFBAccessEnable = g_ActiveConfig.bEFBAccessEnable;
header.bEFBCopyEnable = g_ActiveConfig.bEFBCopyEnable; header.bEFBCopyEnable = g_ActiveConfig.bEFBCopyEnable;
@ -1123,11 +1123,11 @@ void SaveRecording(const char *filename)
header.bClearSave = g_bClearSave; header.bClearSave = g_bClearSave;
header.bSyncGPU = bSyncGPU; header.bSyncGPU = bSyncGPU;
header.bNetPlay = bNetPlay; header.bNetPlay = bNetPlay;
strncpy((char *)header.discChange, g_discChange.c_str(),ARRAYSIZE(header.discChange)); strncpy((char *)header.discChange, g_discChange.c_str(),ArraySize(header.discChange));
strncpy((char *)header.author, author.c_str(),ARRAYSIZE(header.author)); strncpy((char *)header.author, author.c_str(),ArraySize(header.author));
memcpy(header.md5,MD5,16); memcpy(header.md5,MD5,16);
header.bongos = bongos; header.bongos = bongos;
memcpy(header.revision, revision, ARRAYSIZE(header.revision)); memcpy(header.revision, revision, ArraySize(header.revision));
// TODO // TODO
header.uniqueID = 0; header.uniqueID = 0;

View File

@ -9,7 +9,7 @@ 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 (int i = 0; i != ArraySize(m_query_buffer); ++i)
{ {
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, &m_query_buffer[i].query);
@ -19,7 +19,7 @@ PerfQuery::PerfQuery()
PerfQuery::~PerfQuery() PerfQuery::~PerfQuery()
{ {
for (int i = 0; i != ARRAYSIZE(m_query_buffer); ++i) for (int i = 0; i != ArraySize(m_query_buffer); ++i)
{ {
// TODO: EndQuery? // TODO: EndQuery?
m_query_buffer[i].query->Release(); m_query_buffer[i].query->Release();
@ -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 > ArraySize(m_query_buffer) / 2)
WeakFlush(); WeakFlush();
if (ARRAYSIZE(m_query_buffer) == m_query_count) if (ArraySize(m_query_buffer) == m_query_count)
{ {
// TODO // TODO
FlushOne(); FlushOne();
@ -45,7 +45,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) % ArraySize(m_query_buffer)];
D3D::context->Begin(entry.query); D3D::context->Begin(entry.query);
entry.query_type = type; entry.query_type = type;
@ -62,7 +62,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 + ArraySize(m_query_buffer)-1) % ArraySize(m_query_buffer)];
D3D::context->End(entry.query); D3D::context->End(entry.query);
} }
} }
@ -70,7 +70,7 @@ void PerfQuery::DisableQuery(PerfQueryGroup type)
void PerfQuery::ResetQuery() void PerfQuery::ResetQuery()
{ {
m_query_count = 0; m_query_count = 0;
std::fill_n(m_results, ARRAYSIZE(m_results), 0); std::fill_n(m_results, ArraySize(m_results), 0);
} }
u32 PerfQuery::GetQueryResult(PerfQueryType type) u32 PerfQuery::GetQueryResult(PerfQueryType type)
@ -118,7 +118,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) % ArraySize(m_query_buffer);
--m_query_count; --m_query_count;
} }
@ -149,7 +149,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] += (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) % ArraySize(m_query_buffer);
--m_query_count; --m_query_count;
} }
else else

View File

@ -19,7 +19,7 @@ PerfQuery::~PerfQuery()
void PerfQuery::CreateDeviceObjects() void PerfQuery::CreateDeviceObjects()
{ {
for (int i = 0; i != ARRAYSIZE(m_query_buffer); ++i) for (int i = 0; i != ArraySize(m_query_buffer); ++i)
{ {
D3D::dev->CreateQuery(D3DQUERYTYPE_OCCLUSION, &m_query_buffer[i].query); D3D::dev->CreateQuery(D3DQUERYTYPE_OCCLUSION, &m_query_buffer[i].query);
} }
@ -27,7 +27,7 @@ void PerfQuery::CreateDeviceObjects()
} }
void PerfQuery::DestroyDeviceObjects() void PerfQuery::DestroyDeviceObjects()
{ {
for (int i = 0; i != ARRAYSIZE(m_query_buffer); ++i) for (int i = 0; i != ArraySize(m_query_buffer); ++i)
{ {
m_query_buffer[i].query->Release(); m_query_buffer[i].query->Release();
} }
@ -38,10 +38,10 @@ void PerfQuery::EnableQuery(PerfQueryGroup type)
if (!ShouldEmulate()) if (!ShouldEmulate())
return; return;
// Is this sane? // Is this sane?
if (m_query_count > ARRAYSIZE(m_query_buffer) / 2) if (m_query_count > ArraySize(m_query_buffer) / 2)
WeakFlush(); WeakFlush();
if (ARRAYSIZE(m_query_buffer) == m_query_count) if (ArraySize(m_query_buffer) == m_query_count)
{ {
// TODO // TODO
FlushOne(); FlushOne();
@ -51,7 +51,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) % ArraySize(m_query_buffer)];
entry.query->Issue(D3DISSUE_BEGIN); entry.query->Issue(D3DISSUE_BEGIN);
entry.query_type = type; entry.query_type = type;
++m_query_count; ++m_query_count;
@ -65,7 +65,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 + ArraySize(m_query_buffer)-1) % ArraySize(m_query_buffer)];
entry.query->Issue(D3DISSUE_END); entry.query->Issue(D3DISSUE_END);
} }
} }
@ -73,7 +73,7 @@ void PerfQuery::DisableQuery(PerfQueryGroup type)
void PerfQuery::ResetQuery() void PerfQuery::ResetQuery()
{ {
m_query_count = 0; m_query_count = 0;
std::fill_n(m_results, ARRAYSIZE(m_results), 0); std::fill_n(m_results, ArraySize(m_results), 0);
} }
u32 PerfQuery::GetQueryResult(PerfQueryType type) u32 PerfQuery::GetQueryResult(PerfQueryType type)
@ -119,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)((u64)result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight()); m_results[entry.query_type] += (u32)((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) % ArraySize(m_query_buffer);
--m_query_count; --m_query_count;
} }
@ -148,7 +148,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)((u64)result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight()); m_results[entry.query_type] += (u32)((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) % ArraySize(m_query_buffer);
--m_query_count; --m_query_count;
} }
else else

View File

@ -9,7 +9,7 @@ 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 (u32 i = 0; i != ArraySize(m_query_buffer); ++i)
glGenQueries(1, &m_query_buffer[i].query_id); glGenQueries(1, &m_query_buffer[i].query_id);
ResetQuery(); ResetQuery();
@ -17,7 +17,7 @@ PerfQuery::PerfQuery()
PerfQuery::~PerfQuery() PerfQuery::~PerfQuery()
{ {
for (u32 i = 0; i != ARRAYSIZE(m_query_buffer); ++i) for (u32 i = 0; i != ArraySize(m_query_buffer); ++i)
glDeleteQueries(1, &m_query_buffer[i].query_id); glDeleteQueries(1, &m_query_buffer[i].query_id);
} }
@ -27,10 +27,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 > ArraySize(m_query_buffer) / 2)
WeakFlush(); WeakFlush();
if (ARRAYSIZE(m_query_buffer) == m_query_count) if (ArraySize(m_query_buffer) == m_query_count)
{ {
FlushOne(); FlushOne();
//ERROR_LOG(VIDEO, "Flushed query buffer early!"); //ERROR_LOG(VIDEO, "Flushed query buffer early!");
@ -39,7 +39,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) % ArraySize(m_query_buffer)];
glBeginQuery(GL_SAMPLES_PASSED, entry.query_id); glBeginQuery(GL_SAMPLES_PASSED, entry.query_id);
entry.query_type = type; entry.query_type = type;
@ -81,7 +81,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) % ArraySize(m_query_buffer);
--m_query_count; --m_query_count;
} }
@ -121,7 +121,7 @@ void PerfQuery::WeakFlush()
void PerfQuery::ResetQuery() void PerfQuery::ResetQuery()
{ {
m_query_count = 0; m_query_count = 0;
std::fill_n(m_results, ARRAYSIZE(m_results), 0); std::fill_n(m_results, ArraySize(m_results), 0);
} }
u32 PerfQuery::GetQueryResult(PerfQueryType type) u32 PerfQuery::GetQueryResult(PerfQueryType type)

View File

@ -89,7 +89,7 @@ void SamplerCache::SetParameters(GLuint sampler_id, const Params& params)
auto& tm0 = params.tm0; auto& tm0 = params.tm0;
auto& tm1 = params.tm1; auto& tm1 = params.tm1;
glSamplerParameteri(sampler_id, GL_TEXTURE_MIN_FILTER, min_filters[tm0.min_filter % ARRAYSIZE(min_filters)]); glSamplerParameteri(sampler_id, GL_TEXTURE_MIN_FILTER, min_filters[tm0.min_filter % ArraySize(min_filters)]);
glSamplerParameteri(sampler_id, GL_TEXTURE_MAG_FILTER, tm0.mag_filter ? GL_LINEAR : GL_NEAREST); glSamplerParameteri(sampler_id, GL_TEXTURE_MAG_FILTER, tm0.mag_filter ? GL_LINEAR : GL_NEAREST);
glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_S, wrap_settings[tm0.wrap_s]); glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_S, wrap_settings[tm0.wrap_s]);