Browse Source

Clang-tidy: basic naming

pull/2283/head
Anders Jenbo 5 years ago
parent
commit
d9e0658643
  1. 4
      Source/DiabloUI/selhero.cpp
  2. 12
      Source/control.cpp
  3. 4
      Source/controls/plrctrls.cpp
  4. 58
      Source/diablo.cpp
  5. 12
      Source/items.cpp
  6. 84
      Source/loadsave.cpp
  7. 2
      Source/main.cpp
  8. 24
      Source/monster.cpp
  9. 4
      Source/objects.cpp
  10. 6
      Source/player.cpp
  11. 6
      Source/stores.cpp
  12. 8
      Source/towners.cpp

4
Source/DiabloUI/selhero.cpp

@ -394,7 +394,7 @@ void SelheroLoadSelect(int value)
const char *SelheroGenerateName(HeroClass heroClass)
{
static const char *const names[6][10] = {
static const char *const Names[6][10] = {
{
// Warrior
"Aidan",
@ -477,7 +477,7 @@ const char *SelheroGenerateName(HeroClass heroClass)
int iRand = rand() % 10;
return names[static_cast<std::size_t>(heroClass) % 6][iRand];
return Names[static_cast<std::size_t>(heroClass) % 6][iRand];
}
} // namespace

12
Source/control.cpp

@ -1676,7 +1676,7 @@ void DrawGoldSplit(const CelOutputBuffer &out, int amount)
CelDrawTo(out, { dialogX, 178 }, *pGBoxBuff, 1);
constexpr auto bufferSize = sizeof(tempstr) / sizeof(*tempstr);
constexpr auto BufferSize = sizeof(tempstr) / sizeof(*tempstr);
// strncpy copies up to the maximum number of characters specified, it does not ensure that a null character is
// written to the end of the c-string. To be safe we specify a limit one character shorter than the buffer size and
@ -1689,10 +1689,10 @@ void DrawGoldSplit(const CelOutputBuffer &out, int amount)
initialDropGoldValue),
initialDropGoldValue)
.c_str(),
bufferSize - 1);
BufferSize - 1);
// Ensure the prompt shown to the player is terminated properly (in case the formatted/translated string ends up
// being longer than 255 characters)
tempstr[bufferSize - 1] = '\0';
tempstr[BufferSize - 1] = '\0';
// Pre-wrap the string at spaces, otherwise DrawString would hard wrap in the middle of words
WordWrapGameString(tempstr, 200);
@ -1705,7 +1705,7 @@ void DrawGoldSplit(const CelOutputBuffer &out, int amount)
tempstr[0] = '\0';
if (amount > 0) {
// snprintf ensures that the destination buffer ends in a null character.
snprintf(tempstr, bufferSize, "%u", amount);
snprintf(tempstr, BufferSize, "%u", amount);
}
// Even a ten digit amount of gold only takes up about half a line. There's no need to wrap or clip text here so we
// use the Point form of DrawString.
@ -1748,7 +1748,7 @@ void control_drop_gold(char vkey)
}
}
static void control_set_gold_curs(PlayerStruct &player)
static void ControlSetGoldCurs(PlayerStruct &player)
{
SetPlrHandGoldCurs(&player.HoldItem);
NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM);
@ -1768,7 +1768,7 @@ void control_remove_gold(int pnum, int goldIndex)
GetGoldSeed(pnum, &player.HoldItem);
player.HoldItem._ivalue = dropGoldValue;
player.HoldItem._iStatFlag = true;
control_set_gold_curs(player);
ControlSetGoldCurs(player);
player._pGold = CalculateGold(player);
dropGoldValue = 0;
}

4
Source/controls/plrctrls.cpp

@ -485,11 +485,11 @@ void AttrIncBtnSnap(AxisDirection dir)
SetCursorPos(x, y);
}
Point InvGetEquipSlotCoord(const inv_body_loc inv_slot)
Point InvGetEquipSlotCoord(const inv_body_loc invSlot)
{
Point result { RIGHT_PANEL, 0 };
result.x -= (icursW28 - 1) * (InventorySlotSizeInPixels.width / 2);
switch (inv_slot) {
switch (invSlot) {
case INVLOC_HEAD:
result.x += ((InvRect[SLOTXY_HEAD_FIRST].x + InvRect[SLOTXY_HEAD_LAST].x) / 2);
result.y += ((InvRect[SLOTXY_HEAD_FIRST].y + InvRect[SLOTXY_HEAD_LAST].y) / 2);

58
Source/diablo.cpp

@ -159,7 +159,7 @@ extern void plrctrls_after_game_logic();
void initKeymapActions();
[[noreturn]] static void print_help_and_exit()
[[noreturn]] static void PrintHelpAndExit()
{
printInConsole("%s", _(/* TRANSLATORS: Commandline Option */ "Options:\n"));
printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "-h, --help", _("Print this message and exit"));
@ -195,11 +195,11 @@ void initKeymapActions();
diablo_quit(0);
}
static void diablo_parse_flags(int argc, char **argv)
static void DiabloParseFlags(int argc, char **argv)
{
for (int i = 1; i < argc; i++) {
if (strcasecmp("-h", argv[i]) == 0 || strcasecmp("--help", argv[i]) == 0) {
print_help_and_exit();
PrintHelpAndExit();
} else if (strcasecmp("--version", argv[i]) == 0) {
printInConsole("%s v%s\n", PROJECT_NAME, PROJECT_VERSION);
diablo_quit(0);
@ -266,7 +266,7 @@ static void diablo_parse_flags(int argc, char **argv)
#endif
} else {
printInConsole("%s", fmt::format(_("unrecognized option '{:s}'\n"), argv[i]).c_str());
print_help_and_exit();
PrintHelpAndExit();
}
}
}
@ -287,7 +287,7 @@ void FreeGameMem()
FreeTownerGFX();
}
static void start_game(interface_mode uMsg)
static void StartGame(interface_mode uMsg)
{
zoomflag = true;
CalcViewportGeometry();
@ -307,7 +307,7 @@ static void start_game(interface_mode uMsg)
track_repeat_walk(false);
}
static void free_game()
static void FreeGame()
{
FreeQol();
FreeControlPan();
@ -328,7 +328,7 @@ static void free_game()
// Controller support: Actions to run after updating the cursor state.
// Defined in SourceX/controls/plctrls.cpp.
extern void finish_simulated_mouse_clicks(int current_mouse_x, int current_mouse_y);
extern void finish_simulated_mouse_clicks(int currentMouseX, int currentMouseY);
extern void plrctrls_after_check_curs_move();
static bool ProcessInput()
@ -356,13 +356,13 @@ static bool ProcessInput()
return true;
}
static void run_game_loop(interface_mode uMsg)
static void RunGameLoop(interface_mode uMsg)
{
WNDPROC saveProc;
tagMSG msg;
nthread_ignore_mutex(true);
start_game(uMsg);
StartGame(uMsg);
assert(ghMainWnd);
saveProc = SetWindowProc(GM_Game);
control_update_life_mana();
@ -421,7 +421,7 @@ static void run_game_loop(interface_mode uMsg)
scrollrt_draw_game_screen();
saveProc = SetWindowProc(saveProc);
assert(saveProc == GM_Game);
free_game();
FreeGame();
if (cineflag) {
cineflag = false;
@ -457,7 +457,7 @@ bool StartGame(bool bNewGame, bool bSinglePlayer)
if (gbValidSaveFile && gbLoadGame) {
uMsg = WM_DIABLOADGAME;
}
run_game_loop(uMsg);
RunGameLoop(uMsg);
NetClose();
// If the player left the game into the main menu,
@ -470,7 +470,7 @@ bool StartGame(bool bNewGame, bool bSinglePlayer)
return gbRunGameResult;
}
static void diablo_init_screen()
static void DiabloInitScreen()
{
MousePosition = { gnScreenWidth / 2, gnScreenHeight / 2 };
if (!sgbControllerActive)
@ -491,7 +491,7 @@ static void SetApplicationVersions()
strncpy(gszVersionNumber, fmt::format(_("version {:s}"), PROJECT_VERSION).c_str(), sizeof(gszVersionNumber) / sizeof(char));
}
static void diablo_init()
static void DiabloInit()
{
if (sgOptions.Graphics.bShowFPS)
EnableFrameCount();
@ -529,7 +529,7 @@ static void diablo_init()
InitHash();
diablo_init_screen();
DiabloInitScreen();
#ifndef NOSOUND
snd_init();
@ -542,7 +542,7 @@ static void diablo_init()
InitItemGFX();
}
static void diablo_splash()
static void DiabloSplash()
{
if (!gbShowIntro)
return;
@ -561,7 +561,7 @@ static void diablo_splash()
UiTitleDialog();
}
static void diablo_deinit()
static void DiabloDeinit()
{
FreeItemGFX();
@ -587,7 +587,7 @@ static void diablo_deinit()
void diablo_quit(int exitStatus)
{
diablo_deinit();
DiabloDeinit();
exit(exitStatus);
}
@ -597,13 +597,13 @@ int DiabloMain(int argc, char **argv)
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG);
#endif
diablo_parse_flags(argc, argv);
DiabloParseFlags(argc, argv);
initKeymapActions();
LoadOptions();
diablo_init();
diablo_splash();
DiabloInit();
DiabloSplash();
mainmenu_loop();
diablo_deinit();
DiabloDeinit();
return 0;
}
@ -864,7 +864,7 @@ void diablo_pause_game()
}
}
static void diablo_hotkey_msg(DWORD dwMsg)
static void DiabloHotkeyMsg(DWORD dwMsg)
{
if (!gbIsMultiplayer) {
return;
@ -879,7 +879,7 @@ static bool PressSysKey(int wParam)
{
if (gmenu_is_active() || wParam != DVL_VK_F10)
return false;
diablo_hotkey_msg(1);
DiabloHotkeyMsg(1);
return true;
}
@ -1708,7 +1708,7 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
PlaySFX(USFX_SKING1);
}
static void game_logic()
static void GameLogic()
{
if (!ProcessInput()) {
return;
@ -1754,7 +1754,7 @@ static void game_logic()
plrctrls_after_game_logic();
}
static void timeout_cursor(bool bTimeout)
static void TimeoutCursor(bool bTimeout)
{
if (bTimeout) {
if (sgnTimeoutCurs == CURSOR_NONE && sgbMouseDown == CLICK_NONE) {
@ -1784,11 +1784,11 @@ void game_loop(bool bStartup)
for (unsigned i = 0; i < wait; i++) {
if (!multi_handle_delta()) {
timeout_cursor(true);
TimeoutCursor(true);
break;
}
timeout_cursor(false);
game_logic();
TimeoutCursor(false);
GameLogic();
if (!gbRunGame || !gbIsMultiplayer || !nthread_has_500ms_passed())
break;
@ -1998,7 +1998,7 @@ void initKeymapActions()
keymapper.addAction({
QuickMessages[i].key,
DVL_VK_F9 + i,
[i]() { diablo_hotkey_msg(i); },
[i]() { DiabloHotkeyMsg(i); },
});
}
keymapper.addAction({

12
Source/items.cpp

@ -2636,7 +2636,7 @@ void CreateTypeItem(Point position, bool onlygood, int itype, int imisc, bool se
void RecreateItem(int ii, int idx, uint16_t icreateinfo, int iseed, int ivalue, bool isHellfire)
{
bool _gbIsHellfire = gbIsHellfire;
bool tmpIsHellfire = gbIsHellfire;
gbIsHellfire = isHellfire;
if (idx == IDI_GOLD) {
@ -2645,27 +2645,27 @@ void RecreateItem(int ii, int idx, uint16_t icreateinfo, int iseed, int ivalue,
items[ii]._iCreateInfo = icreateinfo;
items[ii]._ivalue = ivalue;
SetPlrHandGoldCurs(&items[ii]);
gbIsHellfire = _gbIsHellfire;
gbIsHellfire = tmpIsHellfire;
return;
}
if (icreateinfo == 0) {
SetPlrHandItem(&items[ii], idx);
SetPlrHandSeed(&items[ii], iseed);
gbIsHellfire = _gbIsHellfire;
gbIsHellfire = tmpIsHellfire;
return;
}
if ((icreateinfo & CF_UNIQUE) == 0) {
if ((icreateinfo & CF_TOWN) != 0) {
RecreateTownItem(ii, idx, icreateinfo, iseed);
gbIsHellfire = _gbIsHellfire;
gbIsHellfire = tmpIsHellfire;
return;
}
if ((icreateinfo & CF_USEFUL) == CF_USEFUL) {
SetupAllUseful(ii, iseed, icreateinfo & CF_LEVEL);
gbIsHellfire = _gbIsHellfire;
gbIsHellfire = tmpIsHellfire;
return;
}
}
@ -2683,7 +2683,7 @@ void RecreateItem(int ii, int idx, uint16_t icreateinfo, int iseed, int ivalue,
bool pregen = (icreateinfo & CF_PREGEN) != 0;
SetupAllItems(ii, idx, iseed, level, uper, onlygood, recreate, pregen);
gbIsHellfire = _gbIsHellfire;
gbIsHellfire = tmpIsHellfire;
}
void RecreateEar(int ii, uint16_t ic, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, int ibuff)

84
Source/loadsave.cpp

@ -67,9 +67,9 @@ T SwapBE(T in)
}
class LoadHelper {
std::unique_ptr<byte[]> m_buffer;
uint32_t m_cur = 0;
size_t m_size;
std::unique_ptr<byte[]> m_buffer_;
uint32_t m_cur_ = 0;
size_t m_size_;
template <class T>
T next()
@ -79,8 +79,8 @@ class LoadHelper {
return 0;
T value;
memcpy(&value, &m_buffer[m_cur], size);
m_cur += size;
memcpy(&value, &m_buffer_[m_cur_], size);
m_cur_ += size;
return value;
}
@ -88,18 +88,18 @@ class LoadHelper {
public:
LoadHelper(const char *szFileName)
{
m_buffer = pfile_read(szFileName, &m_size);
m_buffer_ = pfile_read(szFileName, &m_size_);
}
bool isValid(uint32_t size = 1)
{
return m_buffer != nullptr
&& m_size >= (m_cur + size);
return m_buffer_ != nullptr
&& m_size_ >= (m_cur_ + size);
}
void skip(uint32_t size)
{
m_cur += size;
m_cur_ += size;
}
void nextBytes(void *bytes, size_t size)
@ -107,8 +107,8 @@ public:
if (!isValid(size))
return;
memcpy(bytes, &m_buffer[m_cur], size);
m_cur += size;
memcpy(bytes, &m_buffer_[m_cur_], size);
m_cur_ += size;
}
template <class T>
@ -135,28 +135,28 @@ public:
};
class SaveHelper {
const char *m_szFileName;
std::unique_ptr<byte[]> m_buffer;
uint32_t m_cur = 0;
uint32_t m_capacity;
const char *m_szFileName_;
std::unique_ptr<byte[]> m_buffer_;
uint32_t m_cur_ = 0;
uint32_t m_capacity_;
public:
SaveHelper(const char *szFileName, size_t bufferLen)
: m_szFileName(szFileName)
, m_buffer(new byte[codec_get_encoded_len(bufferLen)])
, m_capacity(bufferLen)
: m_szFileName_(szFileName)
, m_buffer_(new byte[codec_get_encoded_len(bufferLen)])
, m_capacity_(bufferLen)
{
}
bool isValid(uint32_t len = 1)
{
return m_buffer != nullptr
&& m_capacity >= (m_cur + len);
return m_buffer_ != nullptr
&& m_capacity_ >= (m_cur_ + len);
}
void skip(uint32_t len)
{
m_cur += len;
m_cur_ += len;
}
void writeBytes(const void *bytes, size_t len)
@ -164,8 +164,8 @@ public:
if (!isValid(len))
return;
memcpy(&m_buffer[m_cur], bytes, len);
m_cur += len;
memcpy(&m_buffer_[m_cur_], bytes, len);
m_cur_ += len;
}
template <class T>
@ -184,10 +184,10 @@ public:
~SaveHelper()
{
const auto encoded_len = codec_get_encoded_len(m_cur);
const auto encoded_len = codec_get_encoded_len(m_cur_);
const char *const password = pfile_get_password();
codec_encode(m_buffer.get(), m_cur, encoded_len, password);
mpqapi_write_file(m_szFileName, m_buffer.get(), encoded_len);
codec_encode(m_buffer_.get(), m_cur_, encoded_len, password);
mpqapi_write_file(m_szFileName_, m_buffer_.get(), encoded_len);
}
};
@ -932,10 +932,10 @@ bool IsHeaderValid(uint32_t magicNumber)
static void ConvertLevels()
{
// Backup current level state
bool _setlevel = setlevel;
_setlevels _setlvlnum = setlvlnum;
int _currlevel = currlevel;
dungeon_type _leveltype = leveltype;
bool tmpSetlevel = setlevel;
_setlevels tmpSetlvlnum = setlvlnum;
int tmpCurrlevel = currlevel;
dungeon_type tmpLeveltype = leveltype;
gbSkipSync = true;
@ -973,10 +973,10 @@ static void ConvertLevels()
gbSkipSync = false;
// Restor current level state
setlevel = _setlevel;
setlvlnum = _setlvlnum;
currlevel = _currlevel;
leveltype = _leveltype;
setlevel = tmpSetlevel;
setlvlnum = tmpSetlvlnum;
currlevel = tmpCurrlevel;
leveltype = tmpLeveltype;
}
void LoadHotkeys()
@ -1103,10 +1103,10 @@ void LoadGame(bool firstflag)
int viewY = file.nextBE<int32_t>();
invflag = file.nextBool8();
chrflag = file.nextBool8();
int _nummonsters = file.nextBE<int32_t>();
int _numitems = file.nextBE<int32_t>();
int _nummissiles = file.nextBE<int32_t>();
int _nobjects = file.nextBE<int32_t>();
int tmpNummonsters = file.nextBE<int32_t>();
int tmpNumitems = file.nextBE<int32_t>();
int tmpNummissiles = file.nextBE<int32_t>();
int tmpNobjects = file.nextBE<int32_t>();
if (!gbIsHellfire && currlevel > 17)
app_fatal("%s", _("Player is on a Hellfire only level"));
@ -1138,10 +1138,10 @@ void LoadGame(bool firstflag)
ViewX = viewX;
ViewY = viewY;
nummonsters = _nummonsters;
numitems = _numitems;
nummissiles = _nummissiles;
nobjects = _nobjects;
nummonsters = tmpNummonsters;
numitems = tmpNumitems;
nummissiles = tmpNummissiles;
nobjects = tmpNobjects;
for (int &monstkill : monstkills)
monstkill = file.nextBE<int32_t>();

2
Source/main.cpp

@ -13,7 +13,7 @@
#include "diablo.h"
#if !defined(__APPLE__)
extern "C" const char *__asan_default_options() // NOLINT(bugprone-reserved-identifier)
extern "C" const char *__asan_default_options() // NOLINT(bugprone-reserved-identifier, readability-identifier-naming)
{
return "halt_on_error=0";
}

24
Source/monster.cpp

@ -3864,23 +3864,23 @@ void MAI_Golum(int i)
return;
}
int _menemy = monster[i]._menemy;
int menemy = monster[i]._menemy;
int _mex = monster[i].position.tile.x - monster[_menemy].position.future.x;
int _mey = monster[i].position.tile.y - monster[_menemy].position.future.y;
Direction md = GetDirection(monster[i].position.tile, monster[_menemy].position.tile);
int mex = monster[i].position.tile.x - monster[menemy].position.future.x;
int mey = monster[i].position.tile.y - monster[menemy].position.future.y;
Direction md = GetDirection(monster[i].position.tile, monster[menemy].position.tile);
monster[i]._mdir = md;
if (abs(_mex) < 2 && abs(_mey) < 2 && have_enemy) {
_menemy = monster[i]._menemy;
monster[i].enemyPosition = monster[_menemy].position.tile;
if (monster[_menemy]._msquelch == 0) {
monster[_menemy]._msquelch = UINT8_MAX;
if (abs(mex) < 2 && abs(mey) < 2 && have_enemy) {
menemy = monster[i]._menemy;
monster[i].enemyPosition = monster[menemy].position.tile;
if (monster[menemy]._msquelch == 0) {
monster[menemy]._msquelch = UINT8_MAX;
monster[monster[i]._menemy].position.last = monster[i].position.tile;
for (int j = 0; j < 5; j++) {
for (int k = 0; k < 5; k++) {
_menemy = dMonster[monster[i].position.tile.x + k - 2][monster[i].position.tile.y + j - 2];
if (_menemy > 0)
monster[_menemy - 1]._msquelch = UINT8_MAX; // BUGFIX: should be `monster[_menemy-1]`, not monster[_menemy]. (fixed)
menemy = dMonster[monster[i].position.tile.x + k - 2][monster[i].position.tile.y + j - 2];
if (menemy > 0)
monster[menemy - 1]._msquelch = UINT8_MAX; // BUGFIX: should be `monster[_menemy-1]`, not monster[_menemy]. (fixed)
}
}
}

4
Source/objects.cpp

@ -1197,7 +1197,7 @@ void SetMapObjects(const uint16_t *dunData, int startx, int starty)
InitObjFlag = false;
}
void DeleteObject_(int oi, int i)
void DeleteObject(int oi, int i)
{
int ox = object[oi].position.x;
int oy = object[oi].position.y;
@ -2145,7 +2145,7 @@ void ProcessObjects()
for (int i = 0; i < nobjects;) {
int oi = objectactive[i];
if (object[oi]._oDelFlag) {
DeleteObject_(oi, i);
DeleteObject(oi, i);
} else {
i++;
}

6
Source/player.cpp

@ -2287,9 +2287,9 @@ bool PlrHitMonst(int pnum, int m)
int tmac = monster[m].mArmorClass;
if (gbIsHellfire && player._pIEnAc > 0) {
int _pIEnAc = player._pIEnAc - 1;
if (_pIEnAc > 0)
tmac >>= _pIEnAc;
int pIEnAc = player._pIEnAc - 1;
if (pIEnAc > 0)
tmac >>= pIEnAc;
else
tmac -= tmac / 4;

6
Source/stores.cpp

@ -1460,13 +1460,13 @@ void PlaceStoreGold(int v)
{
auto &myPlayer = plr[myplr];
for (int gridNum = 0; gridNum < NUM_INV_GRID_ELEM; gridNum++) {
if (myPlayer.InvGrid[gridNum] == 0) {
for (auto &gridNum : myPlayer.InvGrid) {
if (gridNum == 0) {
int ii = myPlayer._pNumInv;
GetGoldSeed(myplr, &golditem);
myPlayer.InvList[ii] = golditem;
myPlayer._pNumInv++;
myPlayer.InvGrid[gridNum] = myPlayer._pNumInv;
gridNum = myPlayer._pNumInv;
myPlayer.InvList[ii]._ivalue = v;
SetPlrHandGoldCurs(&myPlayer.InvList[ii]);
return;

8
Source/towners.cpp

@ -589,8 +589,12 @@ void TalkToCow(PlayerStruct &player, TownerStruct &cow)
} else if (CowClicks >= 8 && !gbIsSpawn) {
CowClicks = 4;
static const HeroSpeech snSfx[3] = { HeroSpeech::YepThatsACowAlright, HeroSpeech::ImNotThirsty, HeroSpeech::ImNoMilkmaid };
player.SaySpecific(snSfx[CowMsg]);
static const HeroSpeech SnSfx[3] = {
HeroSpeech::YepThatsACowAlright,
HeroSpeech::ImNotThirsty,
HeroSpeech::ImNoMilkmaid,
};
player.SaySpecific(SnSfx[CowMsg]);
CowMsg++;
if (CowMsg >= 3)
CowMsg = 0;

Loading…
Cancel
Save