Skip to content

Commit

Permalink
Cleanup: Renamed the LONG/SHORT macros
Browse files Browse the repository at this point in the history
The LONG macro conflicted with the LONG typedef in <windows.h>.
  • Loading branch information
skyjake committed Feb 22, 2015
1 parent ca840c0 commit 7f9c1de
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 189 deletions.
16 changes: 8 additions & 8 deletions doomsday/apps/api/dd_share.h
Expand Up @@ -91,9 +91,9 @@ int32_t LongSwap(int32_t);
float FloatSwap(float);

#ifdef __BIG_ENDIAN__
#define SHORT(x) ShortSwap(x)
#define LONG(x) LongSwap(x)
#define FLOAT(x) FloatSwap(x)
#define DD_SHORT(x) ShortSwap(x)
#define DD_LONG(x) LongSwap(x)
#define DD_FLOAT(x) FloatSwap(x)

#define BIGSHORT(x) (x)
#define BIGLONG(x) (x)
Expand All @@ -106,9 +106,9 @@ float FloatSwap(float);
(( ((int32_t)(x)) & 0xff0000) >> 8) | (( ((int32_t)(x)) & 0xff000000) >> 24) ))
#else
/// Byte order conversion from native to little-endian. @{
#define SHORT(x) (x)
#define LONG(x) (x)
#define FLOAT(x) (x)
#define DD_SHORT(x) (x)
#define DD_LONG(x) (x)
#define DD_FLOAT(x) (x)
///@}

/// Byte order conversion from native to big-endian. @{
Expand All @@ -122,8 +122,8 @@ float FloatSwap(float);
#endif

/// Byte order conversion from native to little-endian. @{
#define USHORT(x) ((uint16_t) SHORT(x))
#define ULONG(x) ((uint32_t) LONG(x))
#define DD_USHORT(x) ((uint16_t) DD_SHORT(x))
#define DD_ULONG(x) ((uint32_t) DD_LONG(x))
///@}

/// Integer values for Set/Get
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/de_platform.h
Expand Up @@ -47,6 +47,8 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <io.h>
#undef min
#undef max

#define INTEGER64 __int64

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/audio/m_mus2midi.cpp
Expand Up @@ -293,7 +293,7 @@ dd_bool M_Mus2Midi(void* data, size_t length, const char* outFile)
fwrite(buffer, 7, 1, file);

header = (struct mus_header *) data;
readPos = (byte*)data + USHORT(header->scoreStart);
readPos = (byte*)data + DD_USHORT(header->scoreStart);
readTime = 0;
// Init channel volumes.
for(i = 0; i < 16; ++i)
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/client/src/audio/s_cache.cpp
Expand Up @@ -624,9 +624,9 @@ static sfxsample_t *cacheSample(int id, sfxinfo_t const *info)
{
uint8_t hdr[8];
lump.read(hdr, 0, 8);
int head = SHORT(*(short const *) (hdr));
rate = SHORT(*(short const *) (hdr + 2));
numSamples = de::max(0, LONG(*(int const *) (hdr + 4)));
int head = DD_SHORT(*(short const *) (hdr));
rate = DD_SHORT(*(short const *) (hdr + 2));
numSamples = de::max(0, DD_LONG(*(int const *) (hdr + 4)));

bytesPer = 1; // 8-bit.

Expand Down
18 changes: 9 additions & 9 deletions doomsday/apps/client/src/audio/sys_audiod_sdlmixer.cpp
Expand Up @@ -328,12 +328,12 @@ void DS_SDLMixer_SFX_Load(sfxbuffer_t* buf, struct sfxsample_s* sample)

// Transfer the sample to SDL_mixer by converting it to WAVE format.
strcpy(conv, "RIFF");
*(Uint32 *) (conv + 4) = ULONG(4 + 8 + 16 + 8 + sample->size);
*(Uint32 *) (conv + 4) = DD_ULONG(4 + 8 + 16 + 8 + sample->size);
strcpy(conv + 8, "WAVE");

// Format chunk.
strcpy(conv + 12, "fmt ");
*(Uint32 *) (conv + 16) = ULONG(16);
*(Uint32 *) (conv + 16) = DD_ULONG(16);
/**
* WORD wFormatTag; // Format category
* WORD wChannels; // Number of channels
Expand All @@ -342,16 +342,16 @@ void DS_SDLMixer_SFX_Load(sfxbuffer_t* buf, struct sfxsample_s* sample)
* WORD wBlockAlign; // Data block size
* WORD wBitsPerSample; // Sample size
*/
*(Uint16 *) (conv + 20) = USHORT(1);
*(Uint16 *) (conv + 22) = USHORT(1);
*(Uint32 *) (conv + 24) = ULONG(sample->rate);
*(Uint32 *) (conv + 28) = ULONG(sample->rate * sample->bytesPer);
*(Uint16 *) (conv + 32) = USHORT(sample->bytesPer);
*(Uint16 *) (conv + 34) = USHORT(sample->bytesPer * 8);
*(Uint16 *) (conv + 20) = DD_USHORT(1);
*(Uint16 *) (conv + 22) = DD_USHORT(1);
*(Uint32 *) (conv + 24) = DD_ULONG(sample->rate);
*(Uint32 *) (conv + 28) = DD_ULONG(sample->rate * sample->bytesPer);
*(Uint16 *) (conv + 32) = DD_USHORT(sample->bytesPer);
*(Uint16 *) (conv + 34) = DD_USHORT(sample->bytesPer * 8);

// Data chunk.
strcpy(conv + 36, "data");
*(Uint32 *) (conv + 40) = ULONG(sample->size);
*(Uint32 *) (conv + 40) = DD_ULONG(sample->size);
memcpy(conv + 44, sample->data, sample->size);

buf->ptr = Mix_LoadWAV_RW(SDL_RWFromMem(conv, 44 + sample->size), 1);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/client/cl_main.cpp
Expand Up @@ -66,7 +66,7 @@ void Cl_InitID()
{
if(fread(&clientID, sizeof(clientID), 1, file))
{
clientID = ULONG(clientID);
clientID = DD_ULONG(clientID);
fclose(file);
return;
}
Expand All @@ -75,7 +75,7 @@ void Cl_InitID()

// Ah-ha, we need to generate a new ID.
clientID = (ident_t)
ULONG(Timer_RealMilliseconds() * rand() + (rand() & 0xfff) +
DD_ULONG(Timer_RealMilliseconds() * rand() + (rand() & 0xfff) +
((rand() & 0xfff) << 12) + ((rand() & 0xff) << 24));

// Write it to the file.
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/client/src/resource/bitmapfont.cpp
Expand Up @@ -42,7 +42,7 @@ static ushort inShort(FileHandle *file)
{
ushort s;
file->read((uint8_t *)&s, sizeof(s));
return USHORT(s);
return DD_USHORT(s);
}

struct Glyph
Expand Down Expand Up @@ -221,7 +221,7 @@ DENG2_PIMPL(BitmapFont)
byte blue = inByte(file);
byte alpha = inByte(file);

*ptr++ = ULONG(red | (green << 8) | (blue << 16) | (alpha << 24));
*ptr++ = DD_ULONG(red | (green << 8) | (blue << 16) | (alpha << 24));
}
}
else if(bitmapFormat == 1)
Expand All @@ -231,7 +231,7 @@ DENG2_PIMPL(BitmapFont)
{
byte luminance = inByte(file);
byte alpha = inByte(file);
*ptr++ = ULONG(luminance | (luminance << 8) | (luminance << 16) | (alpha << 24));
*ptr++ = DD_ULONG(luminance | (luminance << 8) | (luminance << 16) | (alpha << 24));
}
}

Expand Down
26 changes: 13 additions & 13 deletions doomsday/apps/client/src/resource/hq2x.cpp
Expand Up @@ -298,42 +298,42 @@ uint8_t* GL_SmartFilterHQ2x(const uint8_t* src, int width, int height, int flags
{ int x;
for(x = 0; x < width; ++x)
{
w[5] = ULONG( *( (uint32_t*)(src + OFFSET(x, y)) ) );
w[5] = DD_ULONG( *( (uint32_t*)(src + OFFSET(x, y)) ) );

// Horizontal neighbors.
if(wrapH)
{
w[4] = ULONG( *( (uint32_t*)(src + OFFSET(x == 0? width-1 : x-1, y)) ) );
w[6] = ULONG( *( (uint32_t*)(src + OFFSET(x == width-1? 0 : x+1, y)) ) );
w[4] = DD_ULONG( *( (uint32_t*)(src + OFFSET(x == 0? width-1 : x-1, y)) ) );
w[6] = DD_ULONG( *( (uint32_t*)(src + OFFSET(x == width-1? 0 : x+1, y)) ) );
}
else
{
if(x != 0)
w[4] = ULONG( *( (uint32_t*)(src + OFFSET(x-1, y)) ) );
w[4] = DD_ULONG( *( (uint32_t*)(src + OFFSET(x-1, y)) ) );
else
w[4] = w[5];

if(x != width-1)
w[6] = ULONG( *( (uint32_t*)(src + OFFSET(x+1, y)) ) );
w[6] = DD_ULONG( *( (uint32_t*)(src + OFFSET(x+1, y)) ) );
else
w[6] = w[5];
}

// Vertical neighbors.
if(wrapV)
{
w[2] = ULONG( *( (uint32_t*)(src + OFFSET(x, y == 0? height-1 : y-1)) ) );
w[8] = ULONG( *( (uint32_t*)(src + OFFSET(x, y == height-1? 0 : y+1)) ) );
w[2] = DD_ULONG( *( (uint32_t*)(src + OFFSET(x, y == 0? height-1 : y-1)) ) );
w[8] = DD_ULONG( *( (uint32_t*)(src + OFFSET(x, y == height-1? 0 : y+1)) ) );
}
else
{
if(y != 0)
w[2] = ULONG( *( (uint32_t*)(src + OFFSET(x, y-1)) ) );
w[2] = DD_ULONG( *( (uint32_t*)(src + OFFSET(x, y-1)) ) );
else
w[2] = w[5];

if(y != height-1)
w[8] = ULONG( *( (uint32_t*)(src + OFFSET(x, y+1)) ) );
w[8] = DD_ULONG( *( (uint32_t*)(src + OFFSET(x, y+1)) ) );
else
w[8] = w[5];
}
Expand All @@ -344,10 +344,10 @@ uint8_t* GL_SmartFilterHQ2x(const uint8_t* src, int width, int height, int flags
yA = y == 0? ( wrapV? height-1 : 0) : y-1;
yB = y == height-1? (!wrapV? height-1 : 0) : y+1;

w[1] = ULONG( *( (uint32_t*)(src + OFFSET(xA, yA)) ) );
w[7] = ULONG( *( (uint32_t*)(src + OFFSET(xA, yB)) ) );
w[3] = ULONG( *( (uint32_t*)(src + OFFSET(xB, yA)) ) );
w[9] = ULONG( *( (uint32_t*)(src + OFFSET(xB, yB)) ) );
w[1] = DD_ULONG( *( (uint32_t*)(src + OFFSET(xA, yA)) ) );
w[7] = DD_ULONG( *( (uint32_t*)(src + OFFSET(xA, yB)) ) );
w[3] = DD_ULONG( *( (uint32_t*)(src + OFFSET(xB, yA)) ) );
w[9] = DD_ULONG( *( (uint32_t*)(src + OFFSET(xB, yB)) ) );

pattern = 0;
flag = 1;
Expand Down
60 changes: 30 additions & 30 deletions doomsday/apps/client/src/resource/model.cpp
Expand Up @@ -244,7 +244,7 @@ DENG2_PIMPL(Model)
uint8_t *commandData = (uint8_t *) allocAndLoad(file, hdr.offsetGlCommands, 4 * hdr.numGlCommands);
for(uint8_t const *pos = commandData; *pos;)
{
int count = LONG( *(int *) pos ); pos += 4;
int count = DD_LONG( *(int *) pos ); pos += 4;

lod0.primitives.append(Model::Primitive());
Model::Primitive &prim = lod0.primitives.last();
Expand All @@ -264,7 +264,7 @@ DENG2_PIMPL(Model)
prim.elements.append(Model::Primitive::Element());
Model::Primitive::Element &elem = prim.elements.last();
elem.texCoord = Vector2f(FLOAT(v->s), FLOAT(v->t));
elem.index = LONG(v->index);
elem.index = DD_LONG(v->index);
}
}
M_Free(commandData);
Expand Down Expand Up @@ -365,31 +365,31 @@ DENG2_PIMPL(Model)
file.read((uint8_t *)&chunk, sizeof(chunk));

dmd_info_t info; zap(info);
while(LONG(chunk.type) != DMC_END)
while(DD_LONG(chunk.type) != DMC_END)
{
switch(LONG(chunk.type))
switch(DD_LONG(chunk.type))
{
case DMC_INFO: // Standard DMD information chunk.
file.read((uint8_t *)&info, LONG(chunk.length));

info.skinWidth = LONG(info.skinWidth);
info.skinHeight = LONG(info.skinHeight);
info.frameSize = LONG(info.frameSize);
info.numSkins = LONG(info.numSkins);
info.numVertices = LONG(info.numVertices);
info.numTexCoords = LONG(info.numTexCoords);
info.numFrames = LONG(info.numFrames);
info.numLODs = LONG(info.numLODs);
info.offsetSkins = LONG(info.offsetSkins);
info.offsetTexCoords = LONG(info.offsetTexCoords);
info.offsetFrames = LONG(info.offsetFrames);
info.offsetLODs = LONG(info.offsetLODs);
info.offsetEnd = LONG(info.offsetEnd);
file.read((uint8_t *)&info, DD_LONG(chunk.length));

info.skinWidth = DD_LONG(info.skinWidth);
info.skinHeight = DD_LONG(info.skinHeight);
info.frameSize = DD_LONG(info.frameSize);
info.numSkins = DD_LONG(info.numSkins);
info.numVertices = DD_LONG(info.numVertices);
info.numTexCoords = DD_LONG(info.numTexCoords);
info.numFrames = DD_LONG(info.numFrames);
info.numLODs = DD_LONG(info.numLODs);
info.offsetSkins = DD_LONG(info.offsetSkins);
info.offsetTexCoords = DD_LONG(info.offsetTexCoords);
info.offsetFrames = DD_LONG(info.offsetFrames);
info.offsetLODs = DD_LONG(info.offsetLODs);
info.offsetEnd = DD_LONG(info.offsetEnd);
break;

default:
// Skip unknown chunks.
file.seek(LONG(chunk.length), SeekCur);
file.seek(DD_LONG(chunk.length), SeekCur);
break;
}
// Read the next chunk header.
Expand Down Expand Up @@ -430,7 +430,7 @@ DENG2_PIMPL(Model)
* scale + translation;
vtx.pos.y *= aspectScale; // Aspect undo.

vtx.norm = unpackVector(USHORT(pVtx->normal));
vtx.norm = unpackVector(DD_USHORT(pVtx->normal));

if(!k)
{
Expand All @@ -454,10 +454,10 @@ DENG2_PIMPL(Model)
{
file.read((uint8_t *)&lodInfo[i], sizeof(dmd_levelOfDetail_t));

lodInfo[i].numTriangles = LONG(lodInfo[i].numTriangles);
lodInfo[i].numGlCommands = LONG(lodInfo[i].numGlCommands);
lodInfo[i].offsetTriangles = LONG(lodInfo[i].offsetTriangles);
lodInfo[i].offsetGlCommands = LONG(lodInfo[i].offsetGlCommands);
lodInfo[i].numTriangles = DD_LONG(lodInfo[i].numTriangles);
lodInfo[i].numGlCommands = DD_LONG(lodInfo[i].numGlCommands);
lodInfo[i].offsetTriangles = DD_LONG(lodInfo[i].offsetTriangles);
lodInfo[i].offsetGlCommands = DD_LONG(lodInfo[i].offsetGlCommands);
}

dmd_triangle_t **triangles = new dmd_triangle_t*[info.numLODs];
Expand All @@ -474,7 +474,7 @@ DENG2_PIMPL(Model)
4 * lodInfo[i].numGlCommands);
for(uint8_t const *pos = commandData; *pos;)
{
int count = LONG( *(int *) pos ); pos += 4;
int count = DD_LONG( *(int *) pos ); pos += 4;

lod.primitives.append(Primitive());
Primitive &prim = lod.primitives.last();
Expand All @@ -495,7 +495,7 @@ DENG2_PIMPL(Model)
Primitive::Element &elem = prim.elements.last();

elem.texCoord = Vector2f(FLOAT(v->s), FLOAT(v->t));
elem.index = LONG(v->index);
elem.index = DD_LONG(v->index);
}
}
M_Free(commandData);
Expand All @@ -509,7 +509,7 @@ DENG2_PIMPL(Model)
for(int k = 0; k < lodInfo[i].numTriangles; ++k)
for(int m = 0; m < 3; ++m)
{
int vertexIndex = SHORT(triangles[i][k].vertexIndices[m]);
int vertexIndex = DD_SHORT(triangles[i][k].vertexIndices[m]);
mdl->d->lodVertexUsage.setBit(vertexIndex * info.numLODs + i);
}

Expand Down Expand Up @@ -609,7 +609,7 @@ static bool recogniseDmd(FileHandle &file)
size_t initPos = file.tell();
// Seek to the start of the header.
file.seek(0, SeekSet);
bool result = (readHeaderDmd(file, hdr) && LONG(hdr.magic) == DMD_MAGIC);
bool result = (readHeaderDmd(file, hdr) && DD_LONG(hdr.magic) == DMD_MAGIC);
// Return the stream to its original position.
file.seek(initPos, SeekSet);
return result;
Expand All @@ -621,7 +621,7 @@ static bool recogniseMd2(FileHandle &file)
size_t initPos = file.tell();
// Seek to the start of the header.
file.seek(0, SeekSet);
bool result = (readMd2Header(file, hdr) && LONG(hdr.magic) == MD2_MAGIC);
bool result = (readMd2Header(file, hdr) && DD_LONG(hdr.magic) == MD2_MAGIC);
// Return the stream to its original position.
file.seek(initPos, SeekSet);
return result;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/resource/pcx.cpp
Expand Up @@ -142,7 +142,7 @@ uint8_t *PCX_Load(FileHandle &file, de::Vector2ui &outSize, int &pixelSize)
return 0;
}

outSize = Vector2ui(SHORT(hdr.xmax) + 1, SHORT(hdr.ymax) + 1);
outSize = Vector2ui(DD_SHORT(hdr.xmax) + 1, DD_SHORT(hdr.ymax) + 1);
pixelSize = 3;

dstBufSize = 4 * outSize.x * outSize.y;
Expand Down
10 changes: 5 additions & 5 deletions doomsday/apps/client/src/resource/tga.cpp
Expand Up @@ -34,11 +34,11 @@ enum {
TGA_TARGA32 // rgba8888
};

#undef SHORT
#undef DD_SHORT
#ifdef __BIG_ENDIAN__
#define SHORT(x) shortSwap(x)
#define DD_SHORT(x) shortSwap(x)
# else // Little-endian.
#define SHORT(x) (x)
#define DD_SHORT(x) (x)
#endif

#pragma pack(1)
Expand Down Expand Up @@ -106,7 +106,7 @@ static void writeByte(FILE *f, uint8_t b)

static void writeShort(FILE *f, int16_t s)
{
int16_t v = SHORT(s);
int16_t v = DD_SHORT(s);
fwrite(&v, sizeof(v), 1, f);
}

Expand All @@ -121,7 +121,7 @@ static int16_t readShort(FileHandle &f)
{
int16_t v;
f.read((uint8_t *)&v, sizeof(v));
return SHORT(v);
return DD_SHORT(v);
}

/**
Expand Down

0 comments on commit 7f9c1de

Please sign in to comment.