♻️Fully apply clang-tidy rules to a few files

This commit is contained in:
Anders Jenbo 2021-04-20 01:16:10 +02:00
commit f8e3672469
12 changed files with 470 additions and 571 deletions

View file

@ -25,21 +25,21 @@ namespace devilution {
*/
static bool CaptureHdr(short width, short height, std::ofstream *out)
{
PCXHeader Buffer;
PCXHeader buffer;
memset(&Buffer, 0, sizeof(Buffer));
Buffer.Manufacturer = 10;
Buffer.Version = 5;
Buffer.Encoding = 1;
Buffer.BitsPerPixel = 8;
Buffer.Xmax = SDL_SwapLE16(width - 1);
Buffer.Ymax = SDL_SwapLE16(height - 1);
Buffer.HDpi = SDL_SwapLE16(width);
Buffer.VDpi = SDL_SwapLE16(height);
Buffer.NPlanes = 1;
Buffer.BytesPerLine = SDL_SwapLE16(width);
memset(&buffer, 0, sizeof(buffer));
buffer.Manufacturer = 10;
buffer.Version = 5;
buffer.Encoding = 1;
buffer.BitsPerPixel = 8;
buffer.Xmax = SDL_SwapLE16(width - 1);
buffer.Ymax = SDL_SwapLE16(height - 1);
buffer.HDpi = SDL_SwapLE16(width);
buffer.VDpi = SDL_SwapLE16(height);
buffer.NPlanes = 1;
buffer.BytesPerLine = SDL_SwapLE16(width);
out->write(reinterpret_cast<const char *>(&Buffer), sizeof(Buffer));
out->write(reinterpret_cast<const char *>(&buffer), sizeof(buffer));
return !out->fail();
}
@ -51,17 +51,17 @@ static bool CaptureHdr(short width, short height, std::ofstream *out)
*/
static bool CapturePal(SDL_Color *palette, std::ofstream *out)
{
BYTE pcx_palette[1 + 256 * 3];
BYTE pcxPalette[1 + 256 * 3];
int i;
pcx_palette[0] = 12;
pcxPalette[0] = 12;
for (i = 0; i < 256; i++) {
pcx_palette[1 + 3 * i + 0] = palette[i].r;
pcx_palette[1 + 3 * i + 1] = palette[i].g;
pcx_palette[1 + 3 * i + 2] = palette[i].b;
pcxPalette[1 + 3 * i + 0] = palette[i].r;
pcxPalette[1 + 3 * i + 1] = palette[i].g;
pcxPalette[1 + 3 * i + 2] = palette[i].b;
}
out->write(reinterpret_cast<const char *>(pcx_palette), sizeof(pcx_palette));
out->write(reinterpret_cast<const char *>(pcxPalette), sizeof(pcxPalette));
return !out->fail();
}
@ -87,7 +87,7 @@ static BYTE *CaptureEnc(BYTE *src, BYTE *dst, int width)
while (rlePixel == *src) {
if (rleLength >= 63)
break;
if (!width)
if (width == 0)
break;
rleLength++;
@ -102,7 +102,7 @@ static BYTE *CaptureEnc(BYTE *src, BYTE *dst, int width)
*dst = rlePixel;
dst++;
} while (width);
} while (width > 0);
return dst;
}
@ -115,10 +115,9 @@ static BYTE *CaptureEnc(BYTE *src, BYTE *dst, int width)
static bool CapturePix(CelOutputBuffer buf, std::ofstream *out)
{
int width = buf.w();
int height = buf.h();
BYTE *pBuffer = (BYTE *)DiabloAllocPtr(2 * width);
BYTE *pixels = buf.begin();
while (height--) {
for (int height = buf.h(); height > 0; height--) {
const BYTE *pBufferEnd = CaptureEnc(pixels, pBuffer, width);
pixels += buf.pitch();
out->write(reinterpret_cast<const char *>(pBuffer), pBufferEnd - pBuffer);
@ -132,14 +131,14 @@ static bool CapturePix(CelOutputBuffer buf, std::ofstream *out)
/**
* Returns a pointer because in GCC < 5 ofstream itself is not moveable due to a bug.
*/
static std::ofstream *CaptureFile(std::string *dst_path)
static std::ofstream *CaptureFile(std::string *dstPath)
{
char filename[sizeof("screen00.PCX") / sizeof(char)];
for (int i = 0; i <= 99; ++i) {
snprintf(filename, sizeof(filename) / sizeof(char), "screen%02d.PCX", i);
*dst_path = GetPrefPath() + filename;
if (!FileExists(dst_path->c_str())) {
return new std::ofstream(*dst_path, std::ios::binary | std::ios::trunc);
*dstPath = GetPrefPath() + filename;
if (!FileExists(dstPath->c_str())) {
return new std::ofstream(*dstPath, std::ios::binary | std::ios::trunc);
}
}
return nullptr;
@ -155,13 +154,13 @@ static void RedPalette()
system_palette[i].b = 0;
}
palette_update();
SDL_Rect SrcRect = {
SDL_Rect srcRect = {
BUFFER_BORDER_LEFT,
BUFFER_BORDER_TOP,
gnScreenWidth,
gnScreenHeight,
};
BltFast(&SrcRect, nullptr);
BltFast(&srcRect, nullptr);
RenderPresent();
}
@ -172,11 +171,11 @@ static void RedPalette()
void CaptureScreen()
{
SDL_Color palette[256];
std::string FileName;
std::string fileName;
bool success;
std::ofstream *out_stream = CaptureFile(&FileName);
if (out_stream == nullptr)
std::ofstream *outStream = CaptureFile(&fileName);
if (outStream == nullptr)
return;
DrawAndBlit();
PaletteGetEntries(256, palette);
@ -184,21 +183,21 @@ void CaptureScreen()
lock_buf(2);
CelOutputBuffer buf = GlobalBackBuffer();
success = CaptureHdr(buf.w(), buf.h(), out_stream);
success = CaptureHdr(buf.w(), buf.h(), outStream);
if (success) {
success = CapturePix(buf, out_stream);
success = CapturePix(buf, outStream);
}
if (success) {
success = CapturePal(palette, out_stream);
success = CapturePal(palette, outStream);
}
unlock_buf(2);
out_stream->close();
outStream->close();
if (!success) {
SDL_Log("Failed to save screenshot at %s", FileName.c_str());
RemoveFile(FileName.c_str());
SDL_Log("Failed to save screenshot at %s", fileName.c_str());
RemoveFile(fileName.c_str());
} else {
SDL_Log("Screenshot saved at %s", FileName.c_str());
SDL_Log("Screenshot saved at %s", fileName.c_str());
}
SDL_Delay(300);
for (int i = 0; i < 256; i++) {
@ -206,7 +205,7 @@ void CaptureScreen()
}
palette_update();
force_redraw = 255;
delete out_stream;
delete outStream;
}
} // namespace devilution