Browse Source

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

pull/1609/head
Anders Jenbo 5 years ago
parent
commit
f8e3672469
  1. 14
      Source/.clang-tidy
  2. 14
      Source/appfat.cpp
  3. 2
      Source/appfat.h
  4. 58
      Source/automap.cpp
  5. 83
      Source/capture.cpp
  6. 826
      Source/control.cpp
  7. 34
      Source/control.h
  8. 2
      Source/diablo.cpp
  9. 2
      Source/msg.cpp
  10. 2
      Source/msg.h
  11. 2
      Source/multi.cpp
  12. 2
      Source/multi.h

14
Source/.clang-tidy

@ -45,23 +45,23 @@ Checks: >
-modernize-avoid-c-arrays,
-modernize-use-trailing-return-type,
HeaderFilterRegex: "^Source[SXT].*\\.h$"
HeaderFilterRegex: "^(Source|test)\\.h$"
CheckOptions:
# Identifier names per the Google Style Guide:
# https://google.github.io/styleguide/cppguide.html#General_Naming_Rules
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
- { key: readability-identifier-naming.FunctionCase, value: aNy_CasE }
- { key: readability-identifier-naming.VariableCase, value: lower_case }
- { key: readability-identifier-naming.FunctionCase, value: CamelCase }
- { key: readability-identifier-naming.ParameterCase, value: camelBack }
- { key: readability-identifier-naming.VariableCase, value: camelBack }
- { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
- { key: readability-identifier-naming.GlobalVariableCase, value: aNy_CasE }
- { key: readability-identifier-naming.GlobalFunctionCase, value: aNy_CasE }
- { key: readability-identifier-naming.ClassMemberSuffix, value: _ }
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
- { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ }
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
- { key: readability-identifier-naming.EnumConstantPrefix, value: k }
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprVariablePrefix, value: k }
- { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase }
@ -72,7 +72,7 @@ CheckOptions:
- { key: readability-identifier-naming.StaticConstantPrefix, value: k }
# Allow short if-statements without braces
- { key: readability-braces-around-statements.ShortStatementLines, value: 2 }
- { key: readability-braces-around-statements.ShortStatementLines, value: 3 }
# Use <cstdint> fixed-width integer types instead of short, long and long long
- { key: google-runtime-int.UnsignedTypePrefix, value: "std::uint" }

14
Source/appfat.cpp

@ -15,9 +15,9 @@ namespace devilution {
namespace {
/** Set to true when a fatal error is encountered and the application should shut down. */
bool terminating = false;
bool Terminating = false;
/** Thread id of the last callee to FreeDlg(). */
SDL_threadID cleanup_thread_id;
SDL_threadID CleanupThreadId;
/**
* @brief Displays an error message box based on the given format string and variable argument list.
@ -38,11 +38,11 @@ void MsgBox(const char *pszFmt, va_list va)
*/
void FreeDlg()
{
if (terminating && cleanup_thread_id != SDL_GetThreadID(nullptr))
if (Terminating && CleanupThreadId != SDL_GetThreadID(nullptr))
SDL_Delay(20000);
terminating = true;
cleanup_thread_id = SDL_GetThreadID(nullptr);
Terminating = true;
CleanupThreadId = SDL_GetThreadID(nullptr);
if (gbIsMultiplayer) {
if (SNetLeaveGame(3))
@ -107,13 +107,13 @@ void assert_fail(int nLineNo, const char *pszFile, const char *pszFail)
/**
* @brief Terminates the game and displays an error dialog box based on the given dialog_id.
*/
void ErrDlg(const char *title, const char *error, const char *log_file_path, int log_line_nr)
void ErrDlg(const char *title, const char *error, const char *logFilePath, int logLineNr)
{
char text[1024];
FreeDlg();
snprintf(text, 1024, "%s\n\nThe error occurred at: %s line %d", error, log_file_path, log_line_nr);
snprintf(text, 1024, "%s\n\nThe error occurred at: %s line %d", error, logFilePath, logLineNr);
UiErrorOkDialog(title, text);
app_fatal(nullptr);

2
Source/appfat.h

@ -34,7 +34,7 @@ void DrawDlg(const char *pszFmt, ...) DVL_PRINTF_ATTRIBUTE(1, 2);
#ifdef _DEBUG
[[noreturn]] void assert_fail(int nLineNo, const char *pszFile, const char *pszFail);
#endif
[[noreturn]] void ErrDlg(const char *title, const char *error, const char *log_file_path, int log_line_nr);
[[noreturn]] void ErrDlg(const char *title, const char *error, const char *logFilePath, int logLineNr);
[[noreturn]] void FileErrDlg(const char *error);
[[noreturn]] void InsertCDDlg();
[[noreturn]] void DirErrorDlg(const char *error);

58
Source/automap.cpp

@ -21,10 +21,10 @@ namespace {
* Maps from tile_id to automap type.
* BUGFIX: only the first 256 elements are ever read
*/
uint16_t automaptype[512];
uint16_t AutomapTypes[512];
static Sint32 AutoMapX;
static Sint32 AutoMapY;
int AutoMapX;
int AutoMapY;
/** color used to draw the player's arrow */
#define COLOR_PLAYER (PAL8_ORANGE + 1)
@ -49,9 +49,9 @@ static Sint32 AutoMapY;
/**
* @brief Renders the given automap shape at the specified screen coordinates.
*/
void DrawAutomapTile(const CelOutputBuffer &out, int sx, int sy, uint16_t automap_type)
void DrawAutomapTile(const CelOutputBuffer &out, int sx, int sy, uint16_t automapType)
{
uint8_t flags = automap_type >> 8;
uint8_t flags = automapType >> 8;
if ((flags & MAPFLAG_DIRT) != 0) {
SetPixel(out, sx, sy, COLOR_DIM);
@ -79,11 +79,11 @@ void DrawAutomapTile(const CelOutputBuffer &out, int sx, int sy, uint16_t automa
DrawLineTo(out, sx - AmLine32, sy, sx, sy + AmLine16, COLOR_BRIGHT);
}
bool do_vert = false;
bool do_horz = false;
bool do_cave_horz = false;
bool do_cave_vert = false;
switch (automap_type & MAPFLAG_TYPE) {
bool doVert = false;
bool doHorz = false;
bool doCaveHorz = false;
bool doCaveVert = false;
switch (automapType & MAPFLAG_TYPE) {
case 1: { // stand-alone column or other unpassable object
int x1 = sx - AmLine16;
int y1 = sy - AmLine16;
@ -97,37 +97,37 @@ void DrawAutomapTile(const CelOutputBuffer &out, int sx, int sy, uint16_t automa
} break;
case 2:
case 5:
do_vert = true;
doVert = true;
break;
case 3:
case 6:
do_horz = true;
doHorz = true;
break;
case 4:
do_vert = true;
do_horz = true;
doVert = true;
doHorz = true;
break;
case 8:
do_vert = true;
do_cave_horz = true;
doVert = true;
doCaveHorz = true;
break;
case 9:
do_horz = true;
do_cave_vert = true;
doHorz = true;
doCaveVert = true;
break;
case 10:
do_cave_horz = true;
doCaveHorz = true;
break;
case 11:
do_cave_vert = true;
doCaveVert = true;
break;
case 12:
do_cave_horz = true;
do_cave_vert = true;
doCaveHorz = true;
doCaveVert = true;
break;
}
if (do_vert) { // right-facing obstacle
if (doVert) { // right-facing obstacle
if ((flags & MAPFLAG_VERTDOOR) != 0) { // two wall segments with a door in the middle
int x1 = sx - AmLine32;
int x2 = sx - AmLine16;
@ -160,7 +160,7 @@ void DrawAutomapTile(const CelOutputBuffer &out, int sx, int sy, uint16_t automa
DrawLineTo(out, sx, sy - AmLine16, sx - AmLine32, sy, COLOR_DIM);
}
if (do_horz) { // left-facing obstacle
if (doHorz) { // left-facing obstacle
if ((flags & MAPFLAG_HORZDOOR) != 0) {
int x1 = sx + AmLine16;
int x2 = sx + AmLine32;
@ -194,7 +194,7 @@ void DrawAutomapTile(const CelOutputBuffer &out, int sx, int sy, uint16_t automa
}
// for caves the horz/vert flags are switched
if (do_cave_horz) {
if (doCaveHorz) {
if ((flags & MAPFLAG_VERTDOOR) != 0) {
int x1 = sx - AmLine32;
int x2 = sx - AmLine16;
@ -211,7 +211,7 @@ void DrawAutomapTile(const CelOutputBuffer &out, int sx, int sy, uint16_t automa
DrawLineTo(out, sx, sy + AmLine16, sx - AmLine32, sy, COLOR_DIM);
}
if (do_cave_vert) {
if (doCaveVert) {
if ((flags & MAPFLAG_HORZDOOR) != 0) {
int x1 = sx + AmLine16;
int x2 = sx + AmLine32;
@ -410,7 +410,7 @@ uint16_t GetAutomapType(int x, int y, bool view)
return 0;
}
uint16_t rv = automaptype[(BYTE)dungeon[x][y]];
uint16_t rv = AutomapTypes[(BYTE)dungeon[x][y]];
if (rv == 7) {
if (((GetAutomapType(x - 1, y, false) >> 8) & MAPFLAG_HORZARCH) != 0) {
if (((GetAutomapType(x, y - 1, false) >> 8) & MAPFLAG_VERTARCH) != 0) {
@ -485,7 +485,7 @@ void InitAutomap()
DWORD dwTiles;
BYTE *pAFile;
memset(automaptype, 0, sizeof(automaptype));
memset(AutomapTypes, 0, sizeof(AutomapTypes));
switch (leveltype) {
case DTYPE_CATHEDRAL:
@ -516,7 +516,7 @@ void InitAutomap()
for (unsigned i = 1; i <= dwTiles; i++) {
uint8_t b1 = *pTmp++;
uint8_t b2 = *pTmp++;
automaptype[i] = b1 + (b2 << 8);
AutomapTypes[i] = b1 + (b2 << 8);
}
mem_free_dbg(pAFile);

83
Source/capture.cpp

@ -25,21 +25,21 @@ namespace devilution {
*/
static bool CaptureHdr(short width, short height, std::ofstream *out)
{
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);
out->write(reinterpret_cast<const char *>(&Buffer), sizeof(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);
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

826
Source/control.cpp

File diff suppressed because it is too large Load Diff

34
Source/control.h

@ -67,7 +67,7 @@ extern int initialDropGoldValue;
extern bool panbtndown;
extern bool spselflag;
void DrawSpellList(CelOutputBuffer out);
void DrawSpellList(const CelOutputBuffer &out);
void SetSpell();
void SetSpeedSpell(int slot);
void ToggleSpell(int slot);
@ -80,7 +80,7 @@ void ToggleSpell(int slot);
* @param nCel Number of letter in Windows-1252
* @param col text_color color value
*/
void PrintChar(CelOutputBuffer out, int sx, int sy, int nCel, text_color col);
void PrintChar(const CelOutputBuffer &out, int sx, int sy, int nCel, text_color col);
void AddPanelString(const char *str, bool just);
void ClearPanel();
@ -90,32 +90,32 @@ void DrawPanelBox(CelOutputBuffer out, int x, int y, int w, int h, int sx, int s
* Draws the top dome of the life flask (that part that protrudes out of the control panel).
* First it draws the empty flask cel and then draws the filled part on top if needed.
*/
void DrawLifeFlask(CelOutputBuffer out);
void DrawLifeFlask(const CelOutputBuffer &out);
/**
* Controls the drawing of the area of the life flask within the control panel.
* First sets the fill amount then draws the empty flask cel portion then the filled
* flask portion.
*/
void UpdateLifeFlask(CelOutputBuffer out);
void UpdateLifeFlask(const CelOutputBuffer &out);
void DrawManaFlask(CelOutputBuffer out);
void DrawManaFlask(const CelOutputBuffer &out);
void control_update_life_mana();
/**
* Controls the drawing of the area of the life flask within the control panel.
* Also for some reason draws the current right mouse button spell.
*/
void UpdateManaFlask(CelOutputBuffer out);
void UpdateManaFlask(const CelOutputBuffer &out);
void InitControlPan();
void DrawCtrlPan(CelOutputBuffer out);
void DrawCtrlPan(const CelOutputBuffer &out);
/**
* Draws the control panel buttons in their current state. If the button is in the default
* state draw it from the panel cel(extract its sub-rect). Else draw it from the buttons cel.
*/
void DrawCtrlBtns(CelOutputBuffer out);
void DrawCtrlBtns(const CelOutputBuffer &out);
void DoSpeedBook();
void DoPanBtn();
@ -129,25 +129,25 @@ bool control_WriteStringToBuffer(BYTE *str);
/**
* Sets a string to be drawn in the info box and then draws it.
*/
void DrawInfoBox(CelOutputBuffer out);
void DrawInfoBox(const CelOutputBuffer &out);
void PrintGameStr(CelOutputBuffer out, int x, int y, const char *str, text_color color);
void DrawChr(CelOutputBuffer out);
void PrintGameStr(const CelOutputBuffer &out, int x, int y, const char *str, text_color color);
void DrawChr(const CelOutputBuffer &out);
void CheckLvlBtn();
void ReleaseLvlBtn();
void DrawLevelUpIcon(CelOutputBuffer out);
void DrawLevelUpIcon(const CelOutputBuffer &out);
void CheckChrBtns();
void ReleaseChrBtns(bool addAllStatPoints);
void DrawDurIcon(CelOutputBuffer out);
void DrawDurIcon(const CelOutputBuffer &out);
void RedBack(CelOutputBuffer out);
void DrawSpellBook(CelOutputBuffer out);
void DrawSpellBook(const CelOutputBuffer &out);
void CheckSBook();
const char *get_pieces_str(int nGold);
void DrawGoldSplit(CelOutputBuffer out, int amount);
void DrawGoldSplit(const CelOutputBuffer &out, int amount);
void control_drop_gold(char vkey);
void control_remove_gold(int pnum, int gold_index);
void control_remove_gold(int pnum, int goldIndex);
void control_set_gold_curs(int pnum);
void DrawTalkPan(CelOutputBuffer out);
void DrawTalkPan(const CelOutputBuffer &out);
bool control_check_talk_btn();
void control_release_talk_btn();
void control_type_message();

2
Source/diablo.cpp

@ -960,7 +960,7 @@ static void diablo_hotkey_msg(DWORD dwMsg)
assert(dwMsg < sizeof(spszMsgTbl) / sizeof(spszMsgTbl[0]));
NetSendCmdString(-1, sgOptions.Chat.szHotKeyMsgs[dwMsg]);
NetSendCmdString(0xFFFFFF, sgOptions.Chat.szHotKeyMsgs[dwMsg]);
}
static bool PressSysKey(int wParam)

2
Source/msg.cpp

@ -1250,7 +1250,7 @@ void NetSendCmdMonDmg(bool bHiPri, WORD wMon, DWORD dwDam)
NetSendLoPri(myplr, (BYTE *)&cmd, sizeof(cmd));
}
void NetSendCmdString(int pmask, const char *pszStr)
void NetSendCmdString(uint32_t pmask, const char *pszStr)
{
int dwStrLen;
TCmdString cmd;

2
Source/msg.h

@ -449,7 +449,7 @@ void NetSendCmdDelItem(bool bHiPri, BYTE bLoc);
void NetSendCmdDItem(bool bHiPri, int ii);
void NetSendCmdDamage(bool bHiPri, BYTE bPlr, DWORD dwDam);
void NetSendCmdMonDmg(bool bHiPri, WORD bMon, DWORD dwDam);
void NetSendCmdString(int pmask, const char *pszStr);
void NetSendCmdString(uint32_t pmask, const char *pszStr);
void delta_close_portal(int pnum);
DWORD ParseCmd(int pnum, TCmd *pCmd);

2
Source/multi.cpp

@ -177,7 +177,7 @@ void NetSendHiPri(int playerId, BYTE *pbMsg, BYTE bLen)
}
}
void multi_send_msg_packet(int pmask, BYTE *src, BYTE len)
void multi_send_msg_packet(uint32_t pmask, BYTE *src, BYTE len)
{
DWORD v, p, t;
TPkt pkt;

2
Source/multi.h

@ -50,7 +50,7 @@ extern int player_state[MAX_PLRS];
void multi_msg_add(BYTE *pbMsg, BYTE bLen);
void NetSendLoPri(int playerId, BYTE *pbMsg, BYTE bLen);
void NetSendHiPri(int playerId, BYTE *pbMsg, BYTE bLen);
void multi_send_msg_packet(int pmask, BYTE *src, BYTE len);
void multi_send_msg_packet(uint32_t pmask, BYTE *src, BYTE len);
void multi_msg_countdown();
void multi_player_left(int pnum, int reason);
void multi_net_ping();

Loading…
Cancel
Save