Browse Source

🎨 Apply clang-tidy

pull/2328/head
Anders Jenbo 5 years ago
parent
commit
bc51e1616d
  1. 14
      Source/capture.cpp
  2. 4
      Source/codec.cpp
  3. 30
      Source/control.cpp
  4. 2
      Source/debug.cpp
  5. 118
      Source/diablo.cpp
  6. 632
      Source/drlg_l1.cpp

14
Source/capture.cpp

@ -25,7 +25,7 @@ namespace {
* @param out File stream to write to
* @return True on success
*/
static bool CaptureHdr(int16_t width, int16_t height, std::ofstream *out)
bool CaptureHdr(int16_t width, int16_t height, std::ofstream *out)
{
PCXHeader buffer;
@ -51,7 +51,7 @@ static bool CaptureHdr(int16_t width, int16_t height, std::ofstream *out)
* @param out File stream for the PCX file.
* @return True if successful, else false
*/
static bool CapturePal(SDL_Color *palette, std::ofstream *out)
bool CapturePal(SDL_Color *palette, std::ofstream *out)
{
BYTE pcxPalette[1 + 256 * 3];
@ -74,7 +74,7 @@ static bool CapturePal(SDL_Color *palette, std::ofstream *out)
* @return Output buffer
*/
static BYTE *CaptureEnc(BYTE *src, BYTE *dst, int width)
BYTE *CaptureEnc(BYTE *src, BYTE *dst, int width)
{
int rleLength;
@ -113,7 +113,7 @@ static BYTE *CaptureEnc(BYTE *src, BYTE *dst, int width)
* @param buf Buffer
* @return True if successful, else false
*/
static bool CapturePix(const Surface &buf, std::ofstream *out)
bool CapturePix(const Surface &buf, std::ofstream *out)
{
int width = buf.w();
std::unique_ptr<BYTE[]> pBuffer { new BYTE[2 * width] };
@ -131,7 +131,7 @@ static bool CapturePix(const Surface &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 *dstPath)
std::ofstream *CaptureFile(std::string *dstPath)
{
char filename[sizeof("screen00.PCX") / sizeof(char)];
for (int i = 0; i <= 99; ++i) {
@ -147,7 +147,7 @@ static std::ofstream *CaptureFile(std::string *dstPath)
/**
* @brief Make a red version of the given palette and apply it to the screen.
*/
static void RedPalette()
void RedPalette()
{
for (int i = 0; i < 255; i++) {
system_palette[i].g = 0;
@ -157,7 +157,7 @@ static void RedPalette()
BltFast(nullptr, nullptr);
RenderPresent();
}
}
} // namespace
/**
* @brief Save the current screen to a screen??.PCX (00-99) in file if available, then make the screen red for 200ms.

4
Source/codec.cpp

@ -23,7 +23,7 @@ struct CodecSignature {
#define BlockSize 64
static void CodecInitKey(const char *pszPassword)
void CodecInitKey(const char *pszPassword)
{
char key[136]; // last 64 bytes are the SHA1
uint32_t randState = 0x7058;
@ -54,7 +54,7 @@ static void CodecInitKey(const char *pszPassword)
}
memset(key, 0, sizeof(key));
}
}
} // namespace
std::size_t codec_decode(byte *pbSrcDst, std::size_t size, const char *pszPassword)
{

30
Source/control.cpp

@ -241,7 +241,7 @@ spell_id SpellPages[6][7] = {
* @param cel The CEL sprite
* @param nCel Index of the cel frame to draw. 0 based.
*/
static void DrawSpellCel(const Surface &out, Point position, const CelSprite &cel, int nCel)
void DrawSpellCel(const Surface &out, Point position, const CelSprite &cel, int nCel)
{
CelDrawLightTo(out, position, cel, nCel, SplTransTbl);
}
@ -303,7 +303,7 @@ void SetSpellTrans(spell_type t)
}
}
static void PrintSBookHotkey(const Surface &out, Point position, const std::string &text)
void PrintSBookHotkey(const Surface &out, Point position, const std::string &text)
{
// Align the hot key text with the top-right corner of the spell icon
position += Displacement { SPLICONLENGTH - (GetLineWidth(text.c_str()) + 5), 17 - SPLICONLENGTH };
@ -324,7 +324,7 @@ static void PrintSBookHotkey(const Surface &out, Point position, const std::stri
* @param y0 Top of the flask cel section to draw.
* @param y1 Bottom of the flask cel section to draw.
*/
static void DrawFlaskTop(const Surface &out, Point position, const Surface &celBuf, int y0, int y1)
void DrawFlaskTop(const Surface &out, Point position, const Surface &celBuf, int y0, int y1)
{
out.BlitFrom(celBuf, SDL_Rect { 0, static_cast<decltype(SDL_Rect {}.y)>(y0), celBuf.w(), y1 - y0 }, position);
}
@ -339,7 +339,7 @@ static void DrawFlaskTop(const Surface &out, Point position, const Surface &celB
* @param targetPosition Target buffer coordinate.
* @param h How many lines of the source buffer that will be copied.
*/
static void DrawFlask(const Surface &out, const Surface &celBuf, Point sourcePosition, Point targetPosition, int h)
void DrawFlask(const Surface &out, const Surface &celBuf, Point sourcePosition, Point targetPosition, int h)
{
constexpr int FlaskWidth = 59;
out.BlitFromSkipColorIndexZero(celBuf, MakeSdlRect(sourcePosition.x, sourcePosition.y, FlaskWidth, h), targetPosition);
@ -386,14 +386,14 @@ void DrawFlaskLower(const Surface &out, const Surface &sourceBuffer, int offset,
DrawPanelBox(out, { offset, 85 - filled, 88, filled }, { PANEL_X + offset, PANEL_Y + 69 - filled });
}
void control_set_button_down(int btnId)
void SetButtonStateDown(int btnId)
{
panbtns[btnId] = true;
drawbtnflag = true;
panbtndown = true;
}
static void PrintInfo(const Surface &out)
void PrintInfo(const Surface &out)
{
if (talkflag)
return;
@ -421,7 +421,7 @@ int CapStatPointsToAdd(int remainingStatPoints, const PlayerStruct &player, Char
return std::min(remainingStatPoints, pointsToReachCap);
}
static int DrawDurIcon4Item(const Surface &out, ItemStruct *pItem, int x, int c)
int DrawDurIcon4Item(const Surface &out, ItemStruct *pItem, int x, int c)
{
if (pItem->isEmpty())
return x;
@ -455,7 +455,7 @@ static int DrawDurIcon4Item(const Surface &out, ItemStruct *pItem, int x, int c)
return x - 32 - 8;
}
static void PrintSBookStr(const Surface &out, Point position, const char *text)
void PrintSBookStr(const Surface &out, Point position, const char *text)
{
DrawString(out, text, { { RIGHT_PANEL_X + SPLICONLENGTH + position.x, position.y }, { 222, 0 } }, UIS_SILVER);
}
@ -487,13 +487,13 @@ spell_type GetSBookTrans(spell_id ii, bool townok)
return st;
}
static void ControlSetGoldCurs(PlayerStruct &player)
void ControlSetGoldCurs(PlayerStruct &player)
{
SetPlrHandGoldCurs(&player.HoldItem);
NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM);
}
void control_reset_talk_msg()
void ResetTalkMsg()
{
uint32_t pmask = 0;
@ -504,10 +504,10 @@ void control_reset_talk_msg()
NetSendCmdString(pmask, sgszTalkMsg);
}
static void ControlPressEnter()
void ControlPressEnter()
{
if (sgszTalkMsg[0] != 0) {
control_reset_talk_msg();
ResetTalkMsg();
int i = 0;
for (; i < 8; i++) {
if (strcmp(sgszTalkSave[i], sgszTalkMsg) == 0)
@ -531,7 +531,7 @@ static void ControlPressEnter()
control_reset_talk();
}
static void ControlUpDown(int v)
void ControlUpDown(int v)
{
for (int i = 0; i < 8; i++) {
sgbTalkSavePos = (v + sgbTalkSavePos) & 7;
@ -1017,7 +1017,7 @@ void control_check_btn_press()
&& MousePosition.x <= x
&& MousePosition.y >= PanBtnPos[3].y + PANEL_TOP
&& MousePosition.y <= y) {
control_set_button_down(3);
SetButtonStateDown(3);
}
x = PanBtnPos[6].x + PANEL_LEFT + PanBtnPos[6].w;
y = PanBtnPos[6].y + PANEL_TOP + PanBtnPos[6].h;
@ -1025,7 +1025,7 @@ void control_check_btn_press()
&& MousePosition.x <= x
&& MousePosition.y >= PanBtnPos[6].y + PANEL_TOP
&& MousePosition.y <= y) {
control_set_button_down(6);
SetButtonStateDown(6);
}
}

2
Source/debug.cpp

@ -59,7 +59,7 @@ void PrintDebugMonster(int m)
NetSendCmdString(1 << MyPlayerId, dstr);
}
}
} // namespace
void LoadDebugGFX()
{

118
Source/diablo.cpp

@ -160,7 +160,7 @@ bool was_window_init = false;
bool was_ui_init = false;
bool was_snd_init = false;
static void StartGame(interface_mode uMsg)
void StartGame(interface_mode uMsg)
{
zoomflag = true;
CalcViewportGeometry();
@ -180,7 +180,7 @@ static void StartGame(interface_mode uMsg)
track_repeat_walk(false);
}
static void FreeGame()
void FreeGame()
{
FreeQol();
FreeControlPan();
@ -199,7 +199,7 @@ static void FreeGame()
FreeGameMem();
}
static bool ProcessInput()
bool ProcessInput()
{
if (PauseMode == 2) {
return false;
@ -224,7 +224,7 @@ static bool ProcessInput()
return true;
}
static void RunGameLoop(interface_mode uMsg)
void RunGameLoop(interface_mode uMsg)
{
WNDPROC saveProc;
tagMSG msg;
@ -296,7 +296,7 @@ static void RunGameLoop(interface_mode uMsg)
}
}
[[noreturn]] static void PrintHelpAndExit()
[[noreturn]] void PrintHelpAndExit()
{
printInConsole("%s", _(/* TRANSLATORS: Commandline Option */ "Options:\n"));
printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "-h, --help", _("Print this message and exit"));
@ -332,7 +332,7 @@ static void RunGameLoop(interface_mode uMsg)
diablo_quit(0);
}
static void DiabloParseFlags(int argc, char **argv)
void DiabloParseFlags(int argc, char **argv)
{
for (int i = 1; i < argc; i++) {
if (strcasecmp("-h", argv[i]) == 0 || strcasecmp("--help", argv[i]) == 0) {
@ -406,7 +406,7 @@ static void DiabloParseFlags(int argc, char **argv)
}
}
static void DiabloInitScreen()
void DiabloInitScreen()
{
MousePosition = { gnScreenWidth / 2, gnScreenHeight / 2 };
if (!sgbControllerActive)
@ -418,13 +418,13 @@ static void DiabloInitScreen()
ClrDiabloMsg();
}
static void SetApplicationVersions()
void SetApplicationVersions()
{
snprintf(gszProductName, sizeof(gszProductName) / sizeof(char), "%s v%s", PROJECT_NAME, PROJECT_VERSION);
strncpy(gszVersionNumber, fmt::format(_("version {:s}"), PROJECT_VERSION).c_str(), sizeof(gszVersionNumber) / sizeof(char));
}
static void DiabloInit()
void DiabloInit()
{
if (sgOptions.Graphics.bShowFPS)
EnableFrameCount();
@ -475,7 +475,7 @@ static void DiabloInit()
InitItemGFX();
}
static void DiabloSplash()
void DiabloSplash()
{
if (!gbShowIntro)
return;
@ -494,7 +494,7 @@ static void DiabloSplash()
UiTitleDialog();
}
static void DiabloDeinit()
void DiabloDeinit()
{
FreeItemGFX();
@ -518,7 +518,7 @@ static void DiabloDeinit()
SDL_Quit();
}
static bool LeftMouseCmd(bool bShift)
bool LeftMouseCmd(bool bShift)
{
bool bNear;
@ -574,7 +574,7 @@ static bool LeftMouseCmd(bool bShift)
return false;
}
static bool LeftMouseDown(int wParam)
bool LeftMouseDown(int wParam)
{
if (gmenu_left_mouse(true))
return false;
@ -647,7 +647,7 @@ static bool LeftMouseDown(int wParam)
return false;
}
static void LeftMouseUp(int wParam)
void LeftMouseUp(int wParam)
{
gmenu_left_mouse(false);
control_release_talk_btn();
@ -662,7 +662,7 @@ static void LeftMouseUp(int wParam)
ReleaseStoreBtn();
}
static void RightMouseDown()
void RightMouseDown()
{
if (gmenu_is_active() || sgnTimeoutCurs != CURSOR_NONE || PauseMode == 2 || Players[MyPlayerId]._pInvincible) {
return;
@ -691,7 +691,7 @@ static void RightMouseDown()
}
}
static void DiabloHotkeyMsg(DWORD dwMsg)
void DiabloHotkeyMsg(DWORD dwMsg)
{
if (!gbIsMultiplayer) {
return;
@ -702,7 +702,7 @@ static void DiabloHotkeyMsg(DWORD dwMsg)
NetSendCmdString(0xFFFFFF, sgOptions.Chat.szHotKeyMsgs[dwMsg]);
}
static bool PressSysKey(int wParam)
bool PressSysKey(int wParam)
{
if (gmenu_is_active() || wParam != DVL_VK_F10)
return false;
@ -710,7 +710,7 @@ static bool PressSysKey(int wParam)
return true;
}
static void ReleaseKey(int vkey)
void ReleaseKey(int vkey)
{
if (vkey == DVL_VK_SNAPSHOT)
CaptureScreen();
@ -720,7 +720,7 @@ static void ReleaseKey(int vkey)
ToggleItemLabelHighlight();
}
static void ClosePanels()
void ClosePanels()
{
if (CanPanelsCoverView()) {
if (!chrflag && !QuestLogIsOpen && (invflag || sbookflag) && MousePosition.x < 480 && MousePosition.y < PANEL_TOP) {
@ -735,7 +735,7 @@ static void ClosePanels()
QuestLogIsOpen = false;
}
static void PressKey(int vkey)
void PressKey(int vkey)
{
if (gmenu_presskeys(vkey) || control_presskeys(vkey)) {
return;
@ -848,7 +848,7 @@ static void PressKey(int vkey)
/**
* @internal `return` must be used instead of `break` to be bin exact as C++
*/
static void PressChar(int32_t vkey)
void PressChar(int32_t vkey)
{
if (gmenu_is_active() || control_talk_last_key(vkey) || sgnTimeoutCurs != CURSOR_NONE || MyPlayerIsDead) {
return;
@ -971,7 +971,7 @@ static void PressChar(int32_t vkey)
}
}
static void GetMousePos(int32_t lParam)
void GetMousePos(int32_t lParam)
{
MousePosition = { (std::int16_t)(lParam & 0xffff), (std::int16_t)((lParam >> 16) & 0xffff) };
}
@ -1094,7 +1094,7 @@ void CreateLevel(lvl_entry lvldir)
}
}
static void UpdateMonsterLights()
void UpdateMonsterLights()
{
for (int i = 0; i < ActiveMonsterCount; i++) {
MonsterStruct *mon = &Monsters[ActiveMonsters[i]];
@ -1112,7 +1112,7 @@ static void UpdateMonsterLights()
}
}
static void GameLogic()
void GameLogic()
{
if (!ProcessInput()) {
return;
@ -1158,7 +1158,7 @@ static void GameLogic()
plrctrls_after_game_logic();
}
static void TimeoutCursor(bool bTimeout)
void TimeoutCursor(bool bTimeout)
{
if (bTimeout) {
if (sgnTimeoutCurs == CURSOR_NONE && sgbMouseDown == CLICK_NONE) {
@ -1179,7 +1179,7 @@ static void TimeoutCursor(bool bTimeout)
}
}
void helpKeyPressed()
void HelpKeyPressed()
{
if (HelpFlag) {
HelpFlag = false;
@ -1207,7 +1207,7 @@ void helpKeyPressed()
}
#ifdef _DEBUG
void itemInfoKeyPressed()
void ItemInfoKeyPressed()
{
if (pcursitem != -1) {
sprintf(
@ -1223,7 +1223,7 @@ void itemInfoKeyPressed()
}
#endif
void inventoryKeyPressed()
void InventoryKeyPressed()
{
if (stextflag != STORE_NONE)
return;
@ -1242,7 +1242,7 @@ void inventoryKeyPressed()
sbookflag = false;
}
void characterSheetKeyPressed()
void CharacterSheetKeyPressed()
{
if (stextflag != STORE_NONE)
return;
@ -1261,7 +1261,7 @@ void characterSheetKeyPressed()
QuestLogIsOpen = false;
}
void questLogKeyPressed()
void QuestLogKeyPressed()
{
if (stextflag != STORE_NONE)
return;
@ -1284,7 +1284,7 @@ void questLogKeyPressed()
chrflag = false;
}
void displaySpellsKeyPressed()
void DisplaySpellsKeyPressed()
{
if (stextflag != STORE_NONE)
return;
@ -1300,7 +1300,7 @@ void displaySpellsKeyPressed()
track_repeat_walk(false);
}
void spellBookKeyPressed()
void SpellBookKeyPressed()
{
if (stextflag != STORE_NONE)
return;
@ -1319,31 +1319,31 @@ void spellBookKeyPressed()
invflag = false;
}
bool isPlayerDead()
bool IsPlayerDead()
{
return Players[MyPlayerId]._pmode == PM_DEATH || MyPlayerIsDead;
}
void initKeymapActions()
void InitKeymapActions()
{
keymapper.AddAction({
"Help",
DVL_VK_F1,
helpKeyPressed,
[&]() { return !isPlayerDead(); },
HelpKeyPressed,
[&]() { return !IsPlayerDead(); },
});
#ifdef _DEBUG
keymapper.AddAction({
"ItemInfo",
DVL_VK_INVALID,
itemInfoKeyPressed,
[&]() { return !isPlayerDead(); },
ItemInfoKeyPressed,
[&]() { return !IsPlayerDead(); },
});
keymapper.AddAction({
"QuestDebug",
DVL_VK_INVALID,
PrintDebugQuest,
[&]() { return !isPlayerDead(); },
[&]() { return !IsPlayerDead(); },
});
#endif
for (int i = 0; i < 4; ++i) {
@ -1357,7 +1357,7 @@ void initKeymapActions()
}
ToggleSpell(i);
},
[&]() { return !isPlayerDead(); },
[&]() { return !IsPlayerDead(); },
});
}
for (int i = 0; i < 4; ++i) {
@ -1371,31 +1371,31 @@ void initKeymapActions()
"DecreaseGamma",
'G',
DecreaseGamma,
[&]() { return !isPlayerDead(); },
[&]() { return !IsPlayerDead(); },
});
keymapper.AddAction({
"IncreaseGamma",
'F',
IncreaseGamma,
[&]() { return !isPlayerDead(); },
[&]() { return !IsPlayerDead(); },
});
keymapper.AddAction({
"Inventory",
'I',
inventoryKeyPressed,
[&]() { return !isPlayerDead(); },
InventoryKeyPressed,
[&]() { return !IsPlayerDead(); },
});
keymapper.AddAction({
"Character",
'C',
characterSheetKeyPressed,
[&]() { return !isPlayerDead(); },
CharacterSheetKeyPressed,
[&]() { return !IsPlayerDead(); },
});
keymapper.AddAction({
"QuestLog",
'Q',
questLogKeyPressed,
[&]() { return !isPlayerDead(); },
QuestLogKeyPressed,
[&]() { return !IsPlayerDead(); },
});
keymapper.AddAction({
"Zoom",
@ -1404,19 +1404,19 @@ void initKeymapActions()
zoomflag = !zoomflag;
CalcViewportGeometry();
},
[&]() { return !isPlayerDead(); },
[&]() { return !IsPlayerDead(); },
});
keymapper.AddAction({
"DisplaySpells",
'S',
displaySpellsKeyPressed,
[&]() { return !isPlayerDead(); },
DisplaySpellsKeyPressed,
[&]() { return !IsPlayerDead(); },
});
keymapper.AddAction({
"SpellBook",
'B',
spellBookKeyPressed,
[&]() { return !isPlayerDead(); },
SpellBookKeyPressed,
[&]() { return !IsPlayerDead(); },
});
keymapper.AddAction({
"GameInfo",
@ -1434,7 +1434,7 @@ void initKeymapActions()
.c_str());
NetSendCmdString(1 << MyPlayerId, pszStr);
},
[&]() { return !isPlayerDead(); },
[&]() { return !IsPlayerDead(); },
});
for (int i = 0; i < 8; ++i) {
keymapper.AddAction({
@ -1446,14 +1446,14 @@ void initKeymapActions()
UseInvItem(MyPlayerId, INVITEM_BELT_FIRST + i);
}
},
[&]() { return !isPlayerDead(); },
[&]() { return !IsPlayerDead(); },
});
}
keymapper.AddAction({
"QuickSave",
DVL_VK_F2,
[] { gamemenu_save_game(false); },
[&]() { return !gbIsMultiplayer && !isPlayerDead(); },
[&]() { return !gbIsMultiplayer && !IsPlayerDead(); },
});
keymapper.AddAction({
"QuickLoad",
@ -1476,14 +1476,14 @@ void initKeymapActions()
return;
}
},
[&]() { return !isPlayerDead(); },
[&]() { return !IsPlayerDead(); },
});
#endif
keymapper.AddAction({
"StopHero",
DVL_VK_INVALID,
[] { Players[MyPlayerId].Stop(); },
[&]() { return !isPlayerDead(); },
[&]() { return !IsPlayerDead(); },
});
}
@ -1559,7 +1559,7 @@ int DiabloMain(int argc, char **argv)
#endif
DiabloParseFlags(argc, argv);
initKeymapActions();
InitKeymapActions();
LoadOptions();
DiabloInit();
DiabloSplash();

632
Source/drlg_l1.cpp

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save