diff --git a/Source/.clang-tidy b/Source/.clang-tidy index dd0a07943..c85dc18e2 100644 --- a/Source/.clang-tidy +++ b/Source/.clang-tidy @@ -63,13 +63,9 @@ CheckOptions: - { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ } - { key: readability-identifier-naming.EnumConstantCase, value: CamelCase } - { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase } - - { key: readability-identifier-naming.ConstexprVariablePrefix, value: k } - { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase } - - { key: readability-identifier-naming.GlobalConstantPrefix, value: k } - { key: readability-identifier-naming.MemberConstantCase, value: CamelCase } - - { key: readability-identifier-naming.MemberConstantPrefix, value: k } - { key: readability-identifier-naming.StaticConstantCase, value: CamelCase } - - { key: readability-identifier-naming.StaticConstantPrefix, value: k } # Allow short if-statements without braces - { key: readability-braces-around-statements.ShortStatementLines, value: 3 } diff --git a/Source/DiabloUI/selhero.cpp b/Source/DiabloUI/selhero.cpp index 06de2e9df..8d933633c 100644 --- a/Source/DiabloUI/selhero.cpp +++ b/Source/DiabloUI/selhero.cpp @@ -32,7 +32,7 @@ namespace { std::size_t selhero_SaveCount = 0; _uiheroinfo selhero_heros[MAX_CHARACTERS]; _uiheroinfo selhero_heroInfo; -const size_t KMaxViewportItems = 6; +const size_t MaxViewportItems = 6; char textStats[5][4]; char title[32]; _selhero_selections selhero_result; @@ -112,13 +112,13 @@ UiArtTextButton *SELLIST_DIALOG_DELETE_BUTTON; void SelheroUpdateViewportItems() { - const std::size_t numViewportHeroes = std::min(selhero_SaveCount - listOffset, KMaxViewportItems); + const std::size_t numViewportHeroes = std::min(selhero_SaveCount - listOffset, MaxViewportItems); for (std::size_t i = 0; i < numViewportHeroes; i++) { const std::size_t index = i + listOffset; vecSelHeroDlgItems[i]->m_text = selhero_heros[index].name; vecSelHeroDlgItems[i]->m_value = static_cast(index); } - if (numViewportHeroes < KMaxViewportItems) { + if (numViewportHeroes < MaxViewportItems) { vecSelHeroDlgItems[numViewportHeroes]->m_text = "New Hero"; vecSelHeroDlgItems[numViewportHeroes]->m_value = static_cast(selhero_SaveCount); } @@ -127,8 +127,8 @@ void SelheroUpdateViewportItems() void SelheroScrollIntoView(std::size_t index) { std::size_t newOffset = listOffset; - if (index >= listOffset + KMaxViewportItems) - newOffset = index - (KMaxViewportItems - 1); + if (index >= listOffset + MaxViewportItems) + newOffset = index - (MaxViewportItems - 1); if (index < listOffset) newOffset = index; if (newOffset != listOffset) { @@ -399,7 +399,7 @@ void SelheroLoadSelect(int value) const char *SelheroGenerateName(HeroClass heroClass) { - static const char *const KNames[6][10] = { + static const char *const names[6][10] = { { // Warrior "Aidan", @@ -482,7 +482,7 @@ const char *SelheroGenerateName(HeroClass heroClass) int iRand = rand() % 10; - return KNames[static_cast(heroClass) % 6][iRand]; + return names[static_cast(heroClass) % 6][iRand]; } } // namespace @@ -544,7 +544,7 @@ void selhero_List_Init() vecSelDlgItems.push_back(new UiArtText("Select Hero", rect1, UIS_CENTER | UIS_BIG)); SelheroFreeListItems(); - const size_t numViewportHeroes = std::min(selhero_SaveCount + 1, KMaxViewportItems); + const size_t numViewportHeroes = std::min(selhero_SaveCount + 1, MaxViewportItems); for (std::size_t i = 0; i < numViewportHeroes; i++) { vecSelHeroDlgItems.push_back(new UiListItem("", -1)); } @@ -567,7 +567,7 @@ void selhero_List_Init() vecSelDlgItems.push_back(new UiArtTextButton("Cancel", &UiFocusNavigationEsc, rect5, UIS_CENTER | UIS_BIG | UIS_GOLD)); UiInitList(selhero_SaveCount + 1, SelheroListFocus, SelheroListSelect, SelheroListEsc, vecSelDlgItems, false, SelheroListDeleteYesNo); - UiInitScrollBar(scrollBar, KMaxViewportItems, &listOffset); + UiInitScrollBar(scrollBar, MaxViewportItems, &listOffset); if (selhero_isMultiPlayer) { strcpy(title, "Multi Player Characters"); } else { diff --git a/Source/control.cpp b/Source/control.cpp index e1c9cea9f..a9a7b26f0 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -82,7 +82,7 @@ bool panbtndown; bool spselflag; /** Map of hero class names */ -const char *const kClassStrTbl[] = { +const char *const ClassStrTbl[] = { "Warrior", "Rogue", "Sorcerer", @@ -120,7 +120,7 @@ const BYTE fontkern[68] = { /** * Line start position for info box text when displaying 1, 2, 3, 4 and 5 lines respectivly */ -const int kLineOffsets[5][5] = { +const int LineOffsets[5][5] = { { 82 }, { 70, 94 }, { 64, 82, 100 }, @@ -237,9 +237,9 @@ SDL_Rect PanBtnPos[8] = { // clang-format on }; /** Maps from panel_button_id to hotkey name. */ -const char *const kPanBtnHotKey[8] = { "'c'", "'q'", "Tab", "Esc", "'i'", "'b'", "Enter", nullptr }; +const char *const PanBtnHotKey[8] = { "'c'", "'q'", "Tab", "Esc", "'i'", "'b'", "Enter", nullptr }; /** Maps from panel_button_id to panel button description. */ -const char *const kPanBtnStr[8] = { +const char *const PanBtnStr[8] = { "Character Information", "Quests log", "Automap", @@ -998,15 +998,15 @@ void CheckPanelInfo() int yend = PanBtnPos[i].y + PANEL_TOP + PanBtnPos[i].h; if (MouseX >= PanBtnPos[i].x + PANEL_LEFT && MouseX <= xend && MouseY >= PanBtnPos[i].y + PANEL_TOP && MouseY <= yend) { if (i != 7) { - strcpy(infostr, kPanBtnStr[i]); + strcpy(infostr, PanBtnStr[i]); } else { if (gbFriendlyMode) strcpy(infostr, "Player friendly"); else strcpy(infostr, "Player attack"); } - if (kPanBtnHotKey[i] != nullptr) { - sprintf(tempstr, "Hotkey: %s", kPanBtnHotKey[i]); + if (PanBtnHotKey[i] != nullptr) { + sprintf(tempstr, "Hotkey: %s", PanBtnHotKey[i]); AddPanelString(tempstr, true); } infoclr = COL_WHITE; @@ -1201,7 +1201,7 @@ static void CPrintString(const CelOutputBuffer &out, int y, const char *str, boo { int lineOffset = 0; int sx = 177 + PANEL_X; - int sy = kLineOffsets[lines][y] + PANEL_Y; + int sy = LineOffsets[lines][y] + PANEL_Y; if (center) { int strWidth = 0; const char *tmp = str; @@ -1296,7 +1296,7 @@ void DrawInfoBox(const CelOutputBuffer &out) infoclr = COL_GOLD; strcpy(infostr, plr[pcursplr]._pName); ClearPanel(); - sprintf(tempstr, "%s, Level: %i", kClassStrTbl[static_cast(plr[pcursplr]._pClass)], plr[pcursplr]._pLevel); + sprintf(tempstr, "%s, Level: %i", ClassStrTbl[static_cast(plr[pcursplr]._pClass)], plr[pcursplr]._pLevel); AddPanelString(tempstr, true); sprintf(tempstr, "Hit Points %i of %i", plr[pcursplr]._pHitPoints >> 6, plr[pcursplr]._pMaxHP >> 6); AddPanelString(tempstr, true); @@ -1362,7 +1362,7 @@ void DrawChr(const CelOutputBuffer &out) CelDrawTo(out, 0, 351, pChrPanel, 1, SPANEL_WIDTH); ADD_PlrStringXY(out, 20, 32, 151, plr[myplr]._pName, COL_WHITE); - ADD_PlrStringXY(out, 168, 32, 299, kClassStrTbl[static_cast(plr[myplr]._pClass)], COL_WHITE); + ADD_PlrStringXY(out, 168, 32, 299, ClassStrTbl[static_cast(plr[myplr]._pClass)], COL_WHITE); sprintf(chrstr, "%i", plr[myplr]._pLevel); ADD_PlrStringXY(out, 66, 69, 109, chrstr, COL_WHITE); diff --git a/Source/controls/axis_direction.cpp b/Source/controls/axis_direction.cpp index 8faab07de..a2838ee09 100644 --- a/Source/controls/axis_direction.cpp +++ b/Source/controls/axis_direction.cpp @@ -4,14 +4,14 @@ namespace devilution { -AxisDirection AxisDirectionRepeater::Get(AxisDirection axis_direction) +AxisDirection AxisDirectionRepeater::Get(AxisDirection axisDirection) { const int now = SDL_GetTicks(); - switch (axis_direction.x) { + switch (axisDirection.x) { case AxisDirectionX_LEFT: last_right_ = 0; if (now - last_left_ < min_interval_ms_) { - axis_direction.x = AxisDirectionX_NONE; + axisDirection.x = AxisDirectionX_NONE; } else { last_left_ = now; } @@ -19,7 +19,7 @@ AxisDirection AxisDirectionRepeater::Get(AxisDirection axis_direction) case AxisDirectionX_RIGHT: last_left_ = 0; if (now - last_right_ < min_interval_ms_) { - axis_direction.x = AxisDirectionX_NONE; + axisDirection.x = AxisDirectionX_NONE; } else { last_right_ = now; } @@ -28,11 +28,11 @@ AxisDirection AxisDirectionRepeater::Get(AxisDirection axis_direction) last_left_ = last_right_ = 0; break; } - switch (axis_direction.y) { + switch (axisDirection.y) { case AxisDirectionY_UP: last_down_ = 0; if (now - last_up_ < min_interval_ms_) { - axis_direction.y = AxisDirectionY_NONE; + axisDirection.y = AxisDirectionY_NONE; } else { last_up_ = now; } @@ -40,7 +40,7 @@ AxisDirection AxisDirectionRepeater::Get(AxisDirection axis_direction) case AxisDirectionY_DOWN: last_up_ = 0; if (now - last_down_ < min_interval_ms_) { - axis_direction.y = AxisDirectionY_NONE; + axisDirection.y = AxisDirectionY_NONE; } else { last_down_ = now; } @@ -49,7 +49,7 @@ AxisDirection AxisDirectionRepeater::Get(AxisDirection axis_direction) last_up_ = last_down_ = 0; break; } - return axis_direction; + return axisDirection; } } // namespace devilution diff --git a/Source/controls/controller_motion.cpp b/Source/controls/controller_motion.cpp index f6eace89f..30508ec28 100644 --- a/Source/controls/controller_motion.cpp +++ b/Source/controls/controller_motion.cpp @@ -29,30 +29,30 @@ void ScaleJoystickAxes(float *x, float *y, float deadzone) } const float maximum = 32767.0f; - float analog_x = *x; - float analog_y = *y; - float dead_zone = deadzone * maximum; + float analogX = *x; + float analogY = *y; + float deadZone = deadzone * maximum; - float magnitude = std::sqrt(analog_x * analog_x + analog_y * analog_y); - if (magnitude >= dead_zone) { + float magnitude = std::sqrt(analogX * analogX + analogY * analogY); + if (magnitude >= deadZone) { // find scaled axis values with magnitudes between zero and maximum - float scalingFactor = 1.0 / magnitude * (magnitude - dead_zone) / (maximum - dead_zone); - analog_x = (analog_x * scalingFactor); - analog_y = (analog_y * scalingFactor); + float scalingFactor = 1.0 / magnitude * (magnitude - deadZone) / (maximum - deadZone); + analogX = (analogX * scalingFactor); + analogY = (analogY * scalingFactor); // clamp to ensure results will never exceed the max_axis value - float clamping_factor = 1.0f; - float abs_analog_x = std::fabs(analog_x); - float abs_analog_y = std::fabs(analog_y); - if (abs_analog_x > 1.0 || abs_analog_y > 1.0) { - if (abs_analog_x > abs_analog_y) { - clamping_factor = 1 / abs_analog_x; + float clampingFactor = 1.0f; + float absAnalogX = std::fabs(analogX); + float absAnalogY = std::fabs(analogY); + if (absAnalogX > 1.0 || absAnalogY > 1.0) { + if (absAnalogX > absAnalogY) { + clampingFactor = 1 / absAnalogX; } else { - clamping_factor = 1 / abs_analog_y; + clampingFactor = 1 / absAnalogY; } } - *x = (clamping_factor * analog_x); - *y = (clamping_factor * analog_y); + *x = (clampingFactor * analogX); + *y = (clampingFactor * analogY); } else { *x = 0; *y = 0; @@ -60,13 +60,13 @@ void ScaleJoystickAxes(float *x, float *y, float deadzone) } // SELECT + D-Pad to simulate right stick movement. -bool SimulateRightStickWithDpad(ControllerButtonEvent ctrl_event) +bool SimulateRightStickWithDpad(ControllerButtonEvent ctrlEvent) { if (sgOptions.Controller.bDpadHotkeys) return false; static bool simulating = false; - if (ctrl_event.button == ControllerButton_BUTTON_BACK) { - if (ctrl_event.up && simulating) { + if (ctrlEvent.button == ControllerButton_BUTTON_BACK) { + if (ctrlEvent.up && simulating) { rightStickX = rightStickY = 0; simulating = false; } @@ -74,18 +74,18 @@ bool SimulateRightStickWithDpad(ControllerButtonEvent ctrl_event) } if (!IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) return false; - switch (ctrl_event.button) { + switch (ctrlEvent.button) { case ControllerButton_BUTTON_DPAD_LEFT: - rightStickX = ctrl_event.up ? 0 : -1; + rightStickX = ctrlEvent.up ? 0 : -1; break; case ControllerButton_BUTTON_DPAD_RIGHT: - rightStickX = ctrl_event.up ? 0 : 1; + rightStickX = ctrlEvent.up ? 0 : 1; break; case ControllerButton_BUTTON_DPAD_UP: - rightStickY = ctrl_event.up ? 0 : 1; + rightStickY = ctrlEvent.up ? 0 : 1; break; case ControllerButton_BUTTON_DPAD_DOWN: - rightStickY = ctrl_event.up ? 0 : -1; + rightStickY = ctrlEvent.up ? 0 : -1; break; default: return false; @@ -126,7 +126,7 @@ void ScaleJoysticks() } // namespace // Updates motion state for mouse and joystick sticks. -bool ProcessControllerMotion(const SDL_Event &event, ControllerButtonEvent ctrl_event) +bool ProcessControllerMotion(const SDL_Event &event, ControllerButtonEvent ctrlEvent) { #ifndef USE_SDL1 GameController *const controller = GameController::Get(event); @@ -144,25 +144,25 @@ bool ProcessControllerMotion(const SDL_Event &event, ControllerButtonEvent ctrl_ if (ProcessKbCtrlAxisMotion(event)) return true; #endif - return SimulateRightStickWithDpad(ctrl_event); + return SimulateRightStickWithDpad(ctrlEvent); } -AxisDirection GetLeftStickOrDpadDirection(bool allow_dpad) +AxisDirection GetLeftStickOrDpadDirection(bool allowDpad) { const float stickX = leftStickX; const float stickY = leftStickY; AxisDirection result { AxisDirectionX_NONE, AxisDirectionY_NONE }; - if (stickY >= 0.5 || (allow_dpad && IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_UP))) { + if (stickY >= 0.5 || (allowDpad && IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_UP))) { result.y = AxisDirectionY_UP; - } else if (stickY <= -0.5 || (allow_dpad && IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_DOWN))) { + } else if (stickY <= -0.5 || (allowDpad && IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_DOWN))) { result.y = AxisDirectionY_DOWN; } - if (stickX <= -0.5 || (allow_dpad && IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_LEFT))) { + if (stickX <= -0.5 || (allowDpad && IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_LEFT))) { result.x = AxisDirectionX_LEFT; - } else if (stickX >= 0.5 || (allow_dpad && IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_RIGHT))) { + } else if (stickX >= 0.5 || (allowDpad && IsControllerButtonPressed(ControllerButton_BUTTON_DPAD_RIGHT))) { result.x = AxisDirectionX_RIGHT; } diff --git a/Source/controls/devices/game_controller.cpp b/Source/controls/devices/game_controller.cpp index dc728190d..d3a58047a 100644 --- a/Source/controls/devices/game_controller.cpp +++ b/Source/controls/devices/game_controller.cpp @@ -121,8 +121,8 @@ SDL_GameControllerButton GameController::ToSdlGameControllerButton(ControllerBut bool GameController::IsPressed(ControllerButton button) const { - const SDL_GameControllerButton gc_button = ToSdlGameControllerButton(button); - return gc_button != SDL_CONTROLLER_BUTTON_INVALID && SDL_GameControllerGetButton(sdl_game_controller_, gc_button); + const SDL_GameControllerButton gcButton = ToSdlGameControllerButton(button); + return gcButton != SDL_CONTROLLER_BUTTON_INVALID && SDL_GameControllerGetButton(sdl_game_controller_, gcButton); } bool GameController::ProcessAxisMotion(const SDL_Event &event) @@ -152,43 +152,43 @@ bool GameController::ProcessAxisMotion(const SDL_Event &event) return true; } -void GameController::Add(int joystick_index) +void GameController::Add(int joystickIndex) { - SDL_Log("Opening game controller for joystick at index %d", joystick_index); + SDL_Log("Opening game controller for joystick at index %d", joystickIndex); GameController result; - result.sdl_game_controller_ = SDL_GameControllerOpen(joystick_index); + result.sdl_game_controller_ = SDL_GameControllerOpen(joystickIndex); if (result.sdl_game_controller_ == nullptr) { SDL_Log("%s", SDL_GetError()); SDL_ClearError(); return; } - SDL_Joystick *const sdl_joystick = SDL_GameControllerGetJoystick(result.sdl_game_controller_); - result.instance_id_ = SDL_JoystickInstanceID(sdl_joystick); + SDL_Joystick *const sdlJoystick = SDL_GameControllerGetJoystick(result.sdl_game_controller_); + result.instance_id_ = SDL_JoystickInstanceID(sdlJoystick); controllers_->push_back(result); - const SDL_JoystickGUID guid = SDL_JoystickGetGUID(sdl_joystick); + const SDL_JoystickGUID guid = SDL_JoystickGetGUID(sdlJoystick); SDLUniquePtr mapping { SDL_GameControllerMappingForGUID(guid) }; SDL_Log("Opened game controller with mapping:\n%s", mapping.get()); } -void GameController::Remove(SDL_JoystickID instance_id) +void GameController::Remove(SDL_JoystickID instanceId) { - SDL_Log("Removing game controller with instance id %d", instance_id); + SDL_Log("Removing game controller with instance id %d", instanceId); for (std::size_t i = 0; i < controllers_->size(); ++i) { const GameController &controller = (*controllers_)[i]; - if (controller.instance_id_ != instance_id) + if (controller.instance_id_ != instanceId) continue; controllers_->erase(controllers_->begin() + i); sgbControllerActive = !controllers_->empty(); return; } - SDL_Log("Game controller not found with instance id: %d", instance_id); + SDL_Log("Game controller not found with instance id: %d", instanceId); } -GameController *GameController::Get(SDL_JoystickID instance_id) +GameController *GameController::Get(SDL_JoystickID instanceId) { for (auto &controller : *controllers_) { - if (controller.instance_id_ == instance_id) + if (controller.instance_id_ == instanceId) return &controller; } return nullptr; diff --git a/Source/controls/devices/joystick.cpp b/Source/controls/devices/joystick.cpp index e2014480a..aafd53ebc 100644 --- a/Source/controls/devices/joystick.cpp +++ b/Source/controls/devices/joystick.cpp @@ -207,8 +207,8 @@ bool Joystick::IsPressed(ControllerButton button) const return false; if (IsHatButtonPressed(button)) return true; - const int joy_button = ToSdlJoyButton(button); - return joy_button != -1 && SDL_JoystickGetButton(sdl_joystick_, joy_button); + const int joyButton = ToSdlJoyButton(button); + return joyButton != -1 && SDL_JoystickGetButton(sdl_joystick_, joyButton); } bool Joystick::ProcessAxisMotion(const SDL_Event &event) @@ -246,14 +246,14 @@ bool Joystick::ProcessAxisMotion(const SDL_Event &event) return true; } -void Joystick::Add(int device_index) +void Joystick::Add(int deviceIndex) { - if (SDL_NumJoysticks() <= device_index) + if (SDL_NumJoysticks() <= deviceIndex) return; Joystick result; - SDL_Log("Adding joystick %d: %s", device_index, - SDL_JoystickNameForIndex(device_index)); - result.sdl_joystick_ = SDL_JoystickOpen(device_index); + SDL_Log("Adding joystick %d: %s", deviceIndex, + SDL_JoystickNameForIndex(deviceIndex)); + result.sdl_joystick_ = SDL_JoystickOpen(deviceIndex); if (result.sdl_joystick_ == nullptr) { SDL_Log("%s", SDL_GetError()); SDL_ClearError(); @@ -266,19 +266,19 @@ void Joystick::Add(int device_index) sgbControllerActive = true; } -void Joystick::Remove(SDL_JoystickID instance_id) +void Joystick::Remove(SDL_JoystickID instanceId) { #ifndef USE_SDL1 - SDL_Log("Removing joystick (instance id: %d)", instance_id); + SDL_Log("Removing joystick (instance id: %d)", instanceId); for (std::size_t i = 0; i < joysticks_->size(); ++i) { const Joystick &joystick = (*joysticks_)[i]; - if (joystick.instance_id_ != instance_id) + if (joystick.instance_id_ != instanceId) continue; joysticks_->erase(joysticks_->begin() + i); sgbControllerActive = !joysticks_->empty(); return; } - SDL_Log("Joystick not found with instance id: %d", instance_id); + SDL_Log("Joystick not found with instance id: %d", instanceId); #endif } @@ -287,10 +287,10 @@ const std::vector &Joystick::All() return *joysticks_; } -Joystick *Joystick::Get(SDL_JoystickID instance_id) +Joystick *Joystick::Get(SDL_JoystickID instanceId) { for (auto &joystick : *joysticks_) { - if (joystick.instance_id_ == instance_id) + if (joystick.instance_id_ == instanceId) return &joystick; } return nullptr; diff --git a/Source/controls/game_controls.cpp b/Source/controls/game_controls.cpp index 8b1266149..8e34219b1 100644 --- a/Source/controls/game_controls.cpp +++ b/Source/controls/game_controls.cpp @@ -20,9 +20,9 @@ bool select_modifier_active = false; namespace { -DWORD translate_controller_button_to_key(ControllerButton controller_button) +DWORD TranslateControllerButtonToKey(ControllerButton controllerButton) { - switch (controller_button) { + switch (controllerButton) { case ControllerButton_BUTTON_A: // Bottom button return questlog ? DVL_VK_SPACE : DVL_VK_ESCAPE; case ControllerButton_BUTTON_B: // Right button @@ -47,43 +47,43 @@ DWORD translate_controller_button_to_key(ControllerButton controller_button) } } -bool HandleStartAndSelect(const ControllerButtonEvent &ctrl_event, GameAction *action) +bool HandleStartAndSelect(const ControllerButtonEvent &ctrlEvent, GameAction *action) { - const bool in_game_menu = InGameMenu(); + const bool inGameMenu = InGameMenu(); - const bool start_is_down = IsControllerButtonPressed(ControllerButton_BUTTON_START); - const bool select_is_down = IsControllerButtonPressed(ControllerButton_BUTTON_BACK); - start_modifier_active = !in_game_menu && start_is_down; - select_modifier_active = !in_game_menu && select_is_down && !start_modifier_active; + const bool startIsDown = IsControllerButtonPressed(ControllerButton_BUTTON_START); + const bool selectIsDown = IsControllerButtonPressed(ControllerButton_BUTTON_BACK); + start_modifier_active = !inGameMenu && startIsDown; + select_modifier_active = !inGameMenu && selectIsDown && !start_modifier_active; // Tracks whether we've received both START and SELECT down events. // // Using `IsControllerButtonPressed()` for this would be incorrect. // If both buttons are pressed simultaneously, SDL sends 2 events for which both buttons are in the pressed state. // This allows us to avoid triggering START+SELECT action twice in this case. - static bool start_down_received = false; - static bool select_down_received = false; - switch (ctrl_event.button) { + static bool startDownReceived = false; + static bool selectDownReceived = false; + switch (ctrlEvent.button) { case ControllerButton_BUTTON_BACK: - select_down_received = !ctrl_event.up; + selectDownReceived = !ctrlEvent.up; break; case ControllerButton_BUTTON_START: - start_down_received = !ctrl_event.up; + startDownReceived = !ctrlEvent.up; break; default: return false; } - if (start_down_received && select_down_received) { - *action = GameActionSendKey { DVL_VK_ESCAPE, ctrl_event.up }; + if (startDownReceived && selectDownReceived) { + *action = GameActionSendKey { DVL_VK_ESCAPE, ctrlEvent.up }; return true; } - if (in_game_menu && (start_is_down || select_is_down) && !ctrl_event.up) { + if (inGameMenu && (startIsDown || selectIsDown) && !ctrlEvent.up) { // If both are down, do nothing because `both_received` will trigger soon. - if (start_is_down && select_is_down) + if (startIsDown && selectIsDown) return true; - *action = GameActionSendKey { DVL_VK_ESCAPE, ctrl_event.up }; + *action = GameActionSendKey { DVL_VK_ESCAPE, ctrlEvent.up }; return true; } @@ -92,52 +92,52 @@ bool HandleStartAndSelect(const ControllerButtonEvent &ctrl_event, GameAction *a } // namespace -bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, GameAction *action) +bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, GameAction *action) { - const bool in_game_menu = InGameMenu(); + const bool inGameMenu = InGameMenu(); - if (HandleStartAndSelect(ctrl_event, action)) + if (HandleStartAndSelect(ctrlEvent, action)) return true; // Stick clicks simulate the mouse both in menus and in-game. - switch (ctrl_event.button) { + switch (ctrlEvent.button) { case ControllerButton_BUTTON_LEFTSTICK: if (select_modifier_active) { if (!IsAutomapActive()) - *action = GameActionSendMouseClick { GameActionSendMouseClick::LEFT, ctrl_event.up }; + *action = GameActionSendMouseClick { GameActionSendMouseClick::LEFT, ctrlEvent.up }; return true; } break; case ControllerButton_BUTTON_RIGHTSTICK: if (!IsAutomapActive()) { if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) - *action = GameActionSendMouseClick { GameActionSendMouseClick::RIGHT, ctrl_event.up }; + *action = GameActionSendMouseClick { GameActionSendMouseClick::RIGHT, ctrlEvent.up }; else - *action = GameActionSendMouseClick { GameActionSendMouseClick::LEFT, ctrl_event.up }; + *action = GameActionSendMouseClick { GameActionSendMouseClick::LEFT, ctrlEvent.up }; } return true; default: break; } - if (!in_game_menu) { - switch (ctrl_event.button) { + if (!inGameMenu) { + switch (ctrlEvent.button) { case ControllerButton_BUTTON_LEFTSHOULDER: if ((select_modifier_active && !sgOptions.Controller.bSwapShoulderButtonMode) || (sgOptions.Controller.bSwapShoulderButtonMode && !select_modifier_active)) { if (!IsAutomapActive()) - *action = GameActionSendMouseClick { GameActionSendMouseClick::LEFT, ctrl_event.up }; + *action = GameActionSendMouseClick { GameActionSendMouseClick::LEFT, ctrlEvent.up }; return true; } break; case ControllerButton_BUTTON_RIGHTSHOULDER: if ((select_modifier_active && !sgOptions.Controller.bSwapShoulderButtonMode) || (sgOptions.Controller.bSwapShoulderButtonMode && !select_modifier_active)) { if (!IsAutomapActive()) - *action = GameActionSendMouseClick { GameActionSendMouseClick::RIGHT, ctrl_event.up }; + *action = GameActionSendMouseClick { GameActionSendMouseClick::RIGHT, ctrlEvent.up }; return true; } break; case ControllerButton_AXIS_TRIGGERLEFT: // ZL (aka L2) - if (!ctrl_event.up) { + if (!ctrlEvent.up) { if (select_modifier_active) *action = GameAction(GameActionType_TOGGLE_QUEST_LOG); else @@ -145,7 +145,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam } return true; case ControllerButton_AXIS_TRIGGERRIGHT: // ZR (aka R2) - if (!ctrl_event.up) { + if (!ctrlEvent.up) { if (select_modifier_active) *action = GameAction(GameActionType_TOGGLE_SPELL_BOOK); else @@ -161,29 +161,29 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam break; } if (sgOptions.Controller.bDpadHotkeys) { - switch (ctrl_event.button) { + switch (ctrlEvent.button) { case ControllerButton_BUTTON_DPAD_UP: if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) - *action = GameActionSendKey { DVL_VK_F6, ctrl_event.up }; + *action = GameActionSendKey { DVL_VK_F6, ctrlEvent.up }; else - *action = GameActionSendKey { DVL_VK_ESCAPE, ctrl_event.up }; + *action = GameActionSendKey { DVL_VK_ESCAPE, ctrlEvent.up }; return true; case ControllerButton_BUTTON_DPAD_RIGHT: if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) - *action = GameActionSendKey { DVL_VK_F8, ctrl_event.up }; - else if (!ctrl_event.up) + *action = GameActionSendKey { DVL_VK_F8, ctrlEvent.up }; + else if (!ctrlEvent.up) *action = GameAction(GameActionType_TOGGLE_INVENTORY); return true; case ControllerButton_BUTTON_DPAD_DOWN: if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) - *action = GameActionSendKey { DVL_VK_F7, ctrl_event.up }; + *action = GameActionSendKey { DVL_VK_F7, ctrlEvent.up }; else - *action = GameActionSendKey { DVL_VK_TAB, ctrl_event.up }; + *action = GameActionSendKey { DVL_VK_TAB, ctrlEvent.up }; return true; case ControllerButton_BUTTON_DPAD_LEFT: if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) - *action = GameActionSendKey { DVL_VK_F5, ctrl_event.up }; - else if (!ctrl_event.up) + *action = GameActionSendKey { DVL_VK_F5, ctrlEvent.up }; + else if (!ctrlEvent.up) *action = GameAction(GameActionType_TOGGLE_CHARACTER_INFO); return true; default: @@ -191,19 +191,19 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam } } if (start_modifier_active) { - switch (ctrl_event.button) { + switch (ctrlEvent.button) { case ControllerButton_BUTTON_DPAD_UP: - *action = GameActionSendKey { DVL_VK_ESCAPE, ctrl_event.up }; + *action = GameActionSendKey { DVL_VK_ESCAPE, ctrlEvent.up }; return true; case ControllerButton_BUTTON_DPAD_RIGHT: - if (!ctrl_event.up) + if (!ctrlEvent.up) *action = GameAction(GameActionType_TOGGLE_INVENTORY); return true; case ControllerButton_BUTTON_DPAD_DOWN: - *action = GameActionSendKey { DVL_VK_TAB, ctrl_event.up }; + *action = GameActionSendKey { DVL_VK_TAB, ctrlEvent.up }; return true; case ControllerButton_BUTTON_DPAD_LEFT: - if (!ctrl_event.up) + if (!ctrlEvent.up) *action = GameAction(GameActionType_TOGGLE_CHARACTER_INFO); return true; case ControllerButton_BUTTON_Y: // Top button @@ -220,19 +220,19 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam // Not mapped. TODO: map to attack in place. return true; case ControllerButton_BUTTON_A: // Bottom button - if (!ctrl_event.up) + if (!ctrlEvent.up) *action = GameAction(GameActionType_TOGGLE_SPELL_BOOK); return true; case ControllerButton_BUTTON_X: // Left button - if (!ctrl_event.up) + if (!ctrlEvent.up) *action = GameAction(GameActionType_TOGGLE_QUEST_LOG); return true; case ControllerButton_BUTTON_LEFTSHOULDER: - if (!ctrl_event.up) + if (!ctrlEvent.up) *action = GameAction(GameActionType_TOGGLE_CHARACTER_INFO); return true; case ControllerButton_BUTTON_RIGHTSHOULDER: - if (!ctrl_event.up) + if (!ctrlEvent.up) *action = GameAction(GameActionType_TOGGLE_INVENTORY); return true; default: @@ -241,11 +241,11 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam } // Bottom button: Closes menus or opens quick spell book if nothing is open. - if (ctrl_event.button == ControllerButton_BUTTON_A) { // Bottom button - if (ctrl_event.up) + if (ctrlEvent.button == ControllerButton_BUTTON_A) { // Bottom button + if (ctrlEvent.up) return true; if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) - *action = GameActionSendKey { DVL_VK_F7, ctrl_event.up }; + *action = GameActionSendKey { DVL_VK_F7, ctrlEvent.up }; else if (invflag) *action = GameAction(GameActionType_TOGGLE_INVENTORY); else if (sbookflag) @@ -260,39 +260,39 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam } if (!questlog && !sbookflag) { - switch (ctrl_event.button) { + switch (ctrlEvent.button) { case ControllerButton_IGNORE: return true; case ControllerButton_BUTTON_B: // Right button - if (!ctrl_event.up) { + if (!ctrlEvent.up) { if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) - *action = GameActionSendKey { DVL_VK_F8, ctrl_event.up }; + *action = GameActionSendKey { DVL_VK_F8, ctrlEvent.up }; else *action = GameAction(GameActionType_PRIMARY_ACTION); } return true; case ControllerButton_BUTTON_Y: // Top button - if (!ctrl_event.up) { + if (!ctrlEvent.up) { if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) - *action = GameActionSendKey { DVL_VK_F6, ctrl_event.up }; + *action = GameActionSendKey { DVL_VK_F6, ctrlEvent.up }; else *action = GameAction(GameActionType_SECONDARY_ACTION); } return true; case ControllerButton_BUTTON_X: // Left button - if (!ctrl_event.up) { + if (!ctrlEvent.up) { if (IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) - *action = GameActionSendKey { DVL_VK_F5, ctrl_event.up }; + *action = GameActionSendKey { DVL_VK_F5, ctrlEvent.up }; else *action = GameAction(GameActionType_CAST_SPELL); } return true; case ControllerButton_BUTTON_LEFTSHOULDER: - if (!stextflag && !ctrl_event.up) + if (!stextflag && !ctrlEvent.up) *action = GameAction(GameActionType_USE_HEALTH_POTION); return true; case ControllerButton_BUTTON_RIGHTSHOULDER: - if (!stextflag && !ctrl_event.up) + if (!stextflag && !ctrlEvent.up) *action = GameAction(GameActionType_USE_MANA_POTION); return true; case ControllerButton_BUTTON_DPAD_UP: @@ -306,14 +306,14 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam } } - if (ctrl_event.button == ControllerButton_BUTTON_BACK) { + if (ctrlEvent.button == ControllerButton_BUTTON_BACK) { return true; // Ignore mod button } } // DPad navigation is handled separately for these. if (gmenu_is_active() || questlog || stextflag != STORE_NONE) { - switch (ctrl_event.button) { + switch (ctrlEvent.button) { case ControllerButton_BUTTON_DPAD_UP: case ControllerButton_BUTTON_DPAD_DOWN: case ControllerButton_BUTTON_DPAD_LEFT: @@ -325,9 +325,9 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrl_event, Gam } // By default, map to a keyboard key. - if (ctrl_event.button != ControllerButton_NONE) { - *action = GameActionSendKey { translate_controller_button_to_key(ctrl_event.button), - ctrl_event.up }; + if (ctrlEvent.button != ControllerButton_NONE) { + *action = GameActionSendKey { TranslateControllerButtonToKey(ctrlEvent.button), + ctrlEvent.up }; return true; } diff --git a/Source/controls/menu_controls.cpp b/Source/controls/menu_controls.cpp index ad39e6037..c48668000 100644 --- a/Source/controls/menu_controls.cpp +++ b/Source/controls/menu_controls.cpp @@ -25,18 +25,18 @@ MenuAction GetMenuHeldUpDownAction() MenuAction GetMenuAction(const SDL_Event &event) { - const ControllerButtonEvent ctrl_event = ToControllerButtonEvent(event); + const ControllerButtonEvent ctrlEvent = ToControllerButtonEvent(event); - if (ProcessControllerMotion(event, ctrl_event)) { + if (ProcessControllerMotion(event, ctrlEvent)) { sgbControllerActive = true; return GetMenuHeldUpDownAction(); } - if (ctrl_event.button != ControllerButton_NONE) + if (ctrlEvent.button != ControllerButton_NONE) sgbControllerActive = true; - if (!ctrl_event.up) { - switch (ctrl_event.button) { + if (!ctrlEvent.up) { + switch (ctrlEvent.button) { case ControllerButton_IGNORE: return MenuAction_NONE; case ControllerButton_BUTTON_B: // Right button diff --git a/Source/controls/modifier_hints.cpp b/Source/controls/modifier_hints.cpp index 8f9c2aa1f..0136ec61b 100644 --- a/Source/controls/modifier_hints.cpp +++ b/Source/controls/modifier_hints.cpp @@ -22,13 +22,13 @@ int CalculateTextWidth(const char *s) int SpaceWidth() { - static const int kSpaceWidth = CalculateTextWidth(" "); - return kSpaceWidth; + static const int spaceWidth = CalculateTextWidth(" "); + return spaceWidth; } struct CircleMenuHint { - CircleMenuHint(bool is_dpad, const char *top, const char *right, const char *bottom, const char *left) - : is_dpad(is_dpad) + CircleMenuHint(bool isDpad, const char *top, const char *right, const char *bottom, const char *left) + : is_dpad(isDpad) , top(top) , top_w(CalculateTextWidth(top)) , right(right) @@ -41,7 +41,7 @@ struct CircleMenuHint { { } - int width() const + int Width() const { return 2 * x_mid; } @@ -95,28 +95,28 @@ text_color CircleMenuHintTextColor(bool active) void DrawCircleMenuHint(const CelOutputBuffer &out, const CircleMenuHint &hint, int x, int y) { - const int kLineHeight = 25; + const int lineHeight = 25; PrintGameStr(out, x + hint.x_mid - hint.top_w / 2, y, hint.top, CircleMenuHintTextColor(IsTopActive(hint))); - y += kLineHeight; + y += lineHeight; PrintGameStr(out, x, y, hint.left, CircleMenuHintTextColor(IsLeftActive(hint))); PrintGameStr(out, x + hint.left_w + 5 * SpaceWidth(), y, hint.right, CircleMenuHintTextColor(IsRightActive(hint))); - y += kLineHeight; + y += lineHeight; PrintGameStr(out, x + hint.x_mid - hint.bottom_w / 2, y, hint.bottom, CircleMenuHintTextColor(IsBottomActive(hint))); } -const int kCircleMarginX = 16; -const int kCirclesTop = 76; +const int CircleMarginX = 16; +const int CirclesTop = 76; void DrawStartModifierMenu(const CelOutputBuffer &out) { if (!start_modifier_active) return; - static const CircleMenuHint kDpad(/*is_dpad=*/true, /*top=*/"Menu", /*right=*/"Inv", /*bottom=*/"Map", /*left=*/"Char"); - static const CircleMenuHint kButtons(/*is_dpad=*/false, /*top=*/"", /*right=*/"", /*bottom=*/"Spells", /*left=*/"Quests"); - DrawCircleMenuHint(out, kDpad, PANEL_LEFT + kCircleMarginX, PANEL_TOP - kCirclesTop); - DrawCircleMenuHint(out, kButtons, PANEL_LEFT + PANEL_WIDTH - kButtons.width() - kCircleMarginX, PANEL_TOP - kCirclesTop); + static const CircleMenuHint dPad(/*is_dpad=*/true, /*top=*/"Menu", /*right=*/"Inv", /*bottom=*/"Map", /*left=*/"Char"); + static const CircleMenuHint buttons(/*is_dpad=*/false, /*top=*/"", /*right=*/"", /*bottom=*/"Spells", /*left=*/"Quests"); + DrawCircleMenuHint(out, dPad, PANEL_LEFT + CircleMarginX, PANEL_TOP - CirclesTop); + DrawCircleMenuHint(out, buttons, PANEL_LEFT + PANEL_WIDTH - buttons.Width() - CircleMarginX, PANEL_TOP - CirclesTop); } void DrawSelectModifierMenu(const CelOutputBuffer &out) @@ -124,11 +124,11 @@ void DrawSelectModifierMenu(const CelOutputBuffer &out) if (!select_modifier_active) return; if (sgOptions.Controller.bDpadHotkeys) { - static const CircleMenuHint kDpad(/*is_dpad=*/true, /*top=*/"F6", /*right=*/"F8", /*bottom=*/"F7", /*left=*/"F5"); - DrawCircleMenuHint(out, kDpad, PANEL_LEFT + kCircleMarginX, PANEL_TOP - kCirclesTop); + static const CircleMenuHint dPad(/*is_dpad=*/true, /*top=*/"F6", /*right=*/"F8", /*bottom=*/"F7", /*left=*/"F5"); + DrawCircleMenuHint(out, dPad, PANEL_LEFT + CircleMarginX, PANEL_TOP - CirclesTop); } - static const CircleMenuHint kSpells(/*is_dpad=*/false, "F6", "F8", "F7", "F5"); - DrawCircleMenuHint(out, kSpells, PANEL_LEFT + PANEL_WIDTH - kSpells.width() - kCircleMarginX, PANEL_TOP - kCirclesTop); + static const CircleMenuHint spells(/*is_dpad=*/false, "F6", "F8", "F7", "F5"); + DrawCircleMenuHint(out, spells, PANEL_LEFT + PANEL_WIDTH - spells.Width() - CircleMarginX, PANEL_TOP - CirclesTop); } } // namespace diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index b924c2398..f15737641 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -250,10 +250,10 @@ void FindMeleeTarget() std::list queue; { - const int start_x = plr[myplr]._pfutx; - const int start_y = plr[myplr]._pfuty; - visited[start_x][start_y] = true; - queue.push_back({ start_x, start_y, 0 }); + const int startX = plr[myplr]._pfutx; + const int startY = plr[myplr]._pfuty; + visited[startX][startY] = true; + queue.push_back({ startX, startY, 0 }); } while (!queue.empty()) { @@ -748,13 +748,13 @@ void SpellBookMove(AxisDirection dir) } } -static const direction kFaceDir[3][3] = { +static const direction FaceDir[3][3] = { // NONE UP DOWN { DIR_OMNI, DIR_N, DIR_S }, // NONE { DIR_W, DIR_NW, DIR_SW }, // LEFT { DIR_E, DIR_NE, DIR_SE }, // RIGHT }; -static const int kOffsets[8][2] = { +static const int Offsets[8][2] = { { 1, 1 }, // DIR_S { 0, 1 }, // DIR_SW { -1, 1 }, // DIR_W @@ -800,10 +800,10 @@ bool IsPathBlocked(int x, int y, int dir) return false; } - d1x = x + kOffsets[d1][0]; - d1y = y + kOffsets[d1][1]; - d2x = x + kOffsets[d2][0]; - d2y = y + kOffsets[d2][1]; + d1x = x + Offsets[d1][0]; + d1y = y + Offsets[d1][1]; + d2x = x + Offsets[d2][0]; + d2y = y + Offsets[d2][1]; if (!nSolidTable[dPiece[d1x][d1y]] && !nSolidTable[dPiece[d2x][d2y]]) return false; @@ -822,9 +822,9 @@ void WalkInDir(int playerId, AxisDirection dir) return; } - const direction pdir = kFaceDir[static_cast(dir.x)][static_cast(dir.y)]; - const int dx = x + kOffsets[pdir][0]; - const int dy = y + kOffsets[pdir][1]; + const direction pdir = FaceDir[static_cast(dir.x)][static_cast(dir.y)]; + const int dx = x + Offsets[pdir][0]; + const int dy = y + Offsets[pdir][1]; plr[playerId]._pdir = pdir; if (PosOkPlayer(playerId, dx, dy) && IsPathBlocked(x, y, pdir)) @@ -833,23 +833,23 @@ void WalkInDir(int playerId, AxisDirection dir) NetSendCmdLoc(playerId, true, CMD_WALKXY, dx, dy); } -void QuestLogMove(AxisDirection move_dir) +void QuestLogMove(AxisDirection moveDir) { static AxisDirectionRepeater repeater; - move_dir = repeater.Get(move_dir); - if (move_dir.y == AxisDirectionY_UP) + moveDir = repeater.Get(moveDir); + if (moveDir.y == AxisDirectionY_UP) QuestlogUp(); - else if (move_dir.y == AxisDirectionY_DOWN) + else if (moveDir.y == AxisDirectionY_DOWN) QuestlogDown(); } -void StoreMove(AxisDirection move_dir) +void StoreMove(AxisDirection moveDir) { static AxisDirectionRepeater repeater; - move_dir = repeater.Get(move_dir); - if (move_dir.y == AxisDirectionY_UP) + moveDir = repeater.Get(moveDir); + if (moveDir.y == AxisDirectionY_UP) STextUp(); - else if (move_dir.y == AxisDirectionY_DOWN) + else if (moveDir.y == AxisDirectionY_DOWN) STextDown(); } @@ -888,13 +888,13 @@ void Movement(int playerId) || IsControllerButtonPressed(ControllerButton_BUTTON_BACK)) return; - AxisDirection move_dir = GetMoveDirection(); - if (move_dir.x != AxisDirectionX_NONE || move_dir.y != AxisDirectionY_NONE) { + AxisDirection moveDir = GetMoveDirection(); + if (moveDir.x != AxisDirectionX_NONE || moveDir.y != AxisDirectionY_NONE) { sgbControllerActive = true; } if (GetLeftStickOrDPadGameUIHandler() == nullptr) { - WalkInDir(playerId, move_dir); + WalkInDir(playerId, moveDir); } } @@ -907,7 +907,7 @@ struct RightStickAccumulator { hiresDY = 0; } - void pool(int *x, int *y, int slowdown) + void Pool(int *x, int *y, int slowdown) { const Uint32 tc = SDL_GetTicks(); const int dtc = tc - lastTc; @@ -923,7 +923,7 @@ struct RightStickAccumulator { hiresDY -= dy * slowdown; } - void clear() + void Clear() { lastTc = SDL_GetTicks(); } @@ -937,12 +937,12 @@ struct RightStickAccumulator { void StoreSpellCoords() { - const int START_X = PANEL_LEFT + 12 + SPLICONLENGTH / 2; - const int END_X = START_X + SPLICONLENGTH * 10; - const int END_Y = PANEL_TOP - 17 - SPLICONLENGTH / 2; + const int startX = PANEL_LEFT + 12 + SPLICONLENGTH / 2; + const int endX = startX + SPLICONLENGTH * 10; + const int endY = PANEL_TOP - 17 - SPLICONLENGTH / 2; speedspellcount = 0; - int xo = END_X; - int yo = END_Y; + int xo = endX; + int yo = endY; for (int i = RSPLTYPE_SKILL; i <= RSPLTYPE_CHARGES; i++) { std::uint64_t spells; switch (i) { @@ -965,17 +965,17 @@ void StoreSpellCoords() speedspellscoords[speedspellcount] = { xo, yo }; ++speedspellcount; xo -= SPLICONLENGTH; - if (xo < START_X) { - xo = END_X; + if (xo < startX) { + xo = endX; yo -= SPLICONLENGTH; } } spell <<= 1; } - if (spells && xo != END_X) + if (spells && xo != endX) xo -= SPLICONLENGTH; - if (xo < START_X) { - xo = END_X; + if (xo < startX) { + xo = endX; yo -= SPLICONLENGTH; } } @@ -996,13 +996,13 @@ void HandleRightStickMotion() static RightStickAccumulator acc; // deadzone is handled in ScaleJoystickAxes() already if (rightStickX == 0 && rightStickY == 0) { - acc.clear(); + acc.Clear(); return; } if (IsAutomapActive()) { // move map int dx = 0, dy = 0; - acc.pool(&dx, &dy, 32); + acc.Pool(&dx, &dy, 32); AutoMapXOfs += dy + dx; AutoMapYOfs += dy - dx; return; @@ -1012,7 +1012,7 @@ void HandleRightStickMotion() sgbControllerActive = false; int x = MouseX; int y = MouseY; - acc.pool(&x, &y, 2); + acc.Pool(&x, &y, 2); x = std::min(std::max(x, 0), gnScreenWidth - 1); y = std::min(std::max(y, 0), gnScreenHeight - 1); @@ -1150,8 +1150,8 @@ void UpdateSpellTarget() if (plr[myplr]._pRSpell == SPL_TELEPORT) range = 4; - cursmx = player._pfutx + kOffsets[player._pdir][0] * range; - cursmy = player._pfuty + kOffsets[player._pdir][1] * range; + cursmx = player._pfutx + Offsets[player._pdir][0] * range; + cursmy = player._pfuty + Offsets[player._pdir][1] * range; } /** @@ -1209,17 +1209,17 @@ void PerformSpellAction() void CtrlUseInvItem() { - ItemStruct *Item; + ItemStruct *item; if (pcursinvitem == -1) return; if (pcursinvitem <= INVITEM_INV_LAST) - Item = &plr[myplr].InvList[pcursinvitem - INVITEM_INV_FIRST]; + item = &plr[myplr].InvList[pcursinvitem - INVITEM_INV_FIRST]; else - Item = &plr[myplr].SpdList[pcursinvitem - INVITEM_BELT_FIRST]; + item = &plr[myplr].SpdList[pcursinvitem - INVITEM_BELT_FIRST]; - if ((Item->_iMiscId == IMISC_SCROLLT || Item->_iMiscId == IMISC_SCROLL) && spelldata[Item->_iSpell].sTargeted) { + if ((item->_iMiscId == IMISC_SCROLLT || item->_iMiscId == IMISC_SCROLL) && spelldata[item->_iSpell].sTargeted) { return; } diff --git a/Source/controls/touch.cpp b/Source/controls/touch.cpp index a51a45c3a..d947025cc 100644 --- a/Source/controls/touch.cpp +++ b/Source/controls/touch.cpp @@ -25,17 +25,17 @@ inline T clip(T v, T amin, T amax) #define TOUCH_PORT_MAX_NUM 1 #define NO_TOUCH (-1) // finger id setting if finger is not touching the screen -static void init_touch(); -static void preprocess_events(SDL_Event *event); -static void preprocess_finger_down(SDL_Event *event); -static void preprocess_finger_up(SDL_Event *event); +static void InitTouch(); +static void PreprocessEvents(SDL_Event *event); +static void PreprocessFingerDown(SDL_Event *event); +static void PreprocessFingerUp(SDL_Event *event); #ifdef __vita__ static void preprocess_back_finger_down(SDL_Event *event); static void preprocess_back_finger_up(SDL_Event *event); #endif -static void preprocess_finger_motion(SDL_Event *event); -static void set_mouse_button_event(SDL_Event *event, uint32_t type, uint8_t button, int32_t x, int32_t y); -static void set_mouse_motion_event(SDL_Event *event, int32_t x, int32_t y, int32_t xrel, int32_t yrel); +static void PreprocessFingerMotion(SDL_Event *event); +static void SetMouseButtonEvent(SDL_Event *event, uint32_t type, uint8_t button, int32_t x, int32_t y); +static void SetMouseMotionEvent(SDL_Event *event, int32_t x, int32_t y, int32_t xrel, int32_t yrel); static bool touch_initialized = false; static unsigned int simulated_click_start_time[TOUCH_PORT_MAX_NUM][2]; // initiation time of last simulated left or right click (zero if no click) @@ -45,10 +45,10 @@ static int mouse_y = 0; enum { // clang-format off - MAX_NUM_FINGERS = 3, // number of fingers to track per panel - MAX_TAP_TIME = 250, // taps longer than this will not result in mouse click events - MAX_TAP_MOTION_DISTANCE = 10, // max distance finger motion in Vita screen pixels to be considered a tap - SIMULATED_CLICK_DURATION = 50, // time in ms how long simulated mouse clicks should be + MaxNumFingers = 3, // number of fingers to track per panel + MaxTapTime = 250, // taps longer than this will not result in mouse click events + MaxTapMotionDistance = 10, // max distance finger motion in Vita screen pixels to be considered a tap + SimulatedClickDuration = 50, // time in ms how long simulated mouse clicks should be // clang-format on }; @@ -61,23 +61,23 @@ struct Touch { float last_down_y; // SDL touch coordinates when last pressed down }; -static Touch finger[TOUCH_PORT_MAX_NUM][MAX_NUM_FINGERS]; // keep track of finger status +static Touch finger[TOUCH_PORT_MAX_NUM][MaxNumFingers]; // keep track of finger status enum DraggingType { - DRAG_NONE, - DRAG_TWO_FINGER, - DRAG_THREE_FINGER, + DragNone, + DragTwoFinger, + DragThreeFinger, }; static DraggingType multi_finger_dragging[TOUCH_PORT_MAX_NUM]; // keep track whether we are currently drag-and-dropping -static void init_touch() +static void InitTouch() { for (int port = 0; port < TOUCH_PORT_MAX_NUM; port++) { - for (int i = 0; i < MAX_NUM_FINGERS; i++) { + for (int i = 0; i < MaxNumFingers; i++) { finger[port][i].id = NO_TOUCH; } - multi_finger_dragging[port] = DRAG_NONE; + multi_finger_dragging[port] = DragNone; } for (auto &port : simulated_click_start_time) { @@ -94,7 +94,7 @@ static void init_touch() y_borderwidth = (current.h - visible_height) / 2; } -static void preprocess_events(SDL_Event *event) +static void PreprocessEvents(SDL_Event *event) { // Supported touch gestures: // left mouse click: single finger short tap @@ -126,18 +126,18 @@ static void preprocess_events(SDL_Event *event) switch (event->type) { case SDL_FINGERDOWN: - preprocess_finger_down(event); + PreprocessFingerDown(event); break; case SDL_FINGERUP: - preprocess_finger_up(event); + PreprocessFingerUp(event); break; case SDL_FINGERMOTION: - preprocess_finger_motion(event); + PreprocessFingerMotion(event); break; } } -static void preprocess_finger_down(SDL_Event *event) +static void PreprocessFingerDown(SDL_Event *event) { // front (0) or back (1) panel SDL_TouchID port = event->tfinger.touchId; @@ -154,7 +154,7 @@ static void preprocess_finger_down(SDL_Event *event) } // make sure each finger is not reported down multiple times - for (int i = 0; i < MAX_NUM_FINGERS; i++) { + for (int i = 0; i < MaxNumFingers; i++) { if (finger[port][i].id != id) { continue; } @@ -164,7 +164,7 @@ static void preprocess_finger_down(SDL_Event *event) // we need the timestamps to decide later if the user performed a short tap (click) // or a long tap (drag) // we also need the last coordinates for each finger to keep track of dragging - for (int i = 0; i < MAX_NUM_FINGERS; i++) { + for (int i = 0; i < MaxNumFingers; i++) { if (finger[port][i].id != NO_TOUCH) { continue; } @@ -217,7 +217,7 @@ static void preprocess_back_finger_up(SDL_Event *event) } #endif -static void preprocess_finger_up(SDL_Event *event) +static void PreprocessFingerUp(SDL_Event *event) { // front (0) or back (1) panel SDL_TouchID port = event->tfinger.touchId; @@ -225,24 +225,24 @@ static void preprocess_finger_up(SDL_Event *event) SDL_FingerID id = event->tfinger.fingerId; // find out how many fingers were down before this event - int num_fingers_down = 0; - for (int i = 0; i < MAX_NUM_FINGERS; i++) { + int numFingersDown = 0; + for (int i = 0; i < MaxNumFingers; i++) { if (finger[port][i].id >= 0) { - num_fingers_down++; + numFingersDown++; } } int x = mouse_x; int y = mouse_y; - for (int i = 0; i < MAX_NUM_FINGERS; i++) { + for (int i = 0; i < MaxNumFingers; i++) { if (finger[port][i].id != id) { continue; } finger[port][i].id = NO_TOUCH; if (!multi_finger_dragging[port]) { - if ((event->tfinger.timestamp - finger[port][i].time_last_down) > MAX_TAP_TIME) { + if ((event->tfinger.timestamp - finger[port][i].time_last_down) > MaxTapTime) { continue; } @@ -250,22 +250,22 @@ static void preprocess_finger_up(SDL_Event *event) // but only if the finger hasn't moved since it was pressed down by more than MAX_TAP_MOTION_DISTANCE pixels float xrel = ((event->tfinger.x * devilution::GetOutputSurface()->w) - (finger[port][i].last_down_x * devilution::GetOutputSurface()->w)); float yrel = ((event->tfinger.y * devilution::GetOutputSurface()->h) - (finger[port][i].last_down_y * devilution::GetOutputSurface()->h)); - auto max_r_squared = static_cast(MAX_TAP_MOTION_DISTANCE * MAX_TAP_MOTION_DISTANCE); - if ((xrel * xrel + yrel * yrel) >= max_r_squared) { + auto maxRSquared = static_cast(MaxTapMotionDistance * MaxTapMotionDistance); + if ((xrel * xrel + yrel * yrel) >= maxRSquared) { continue; } - if (num_fingers_down != 2 && num_fingers_down != 1) { + if (numFingersDown != 2 && numFingersDown != 1) { continue; } - Uint8 simulated_button = 0; - if (num_fingers_down == 2) { - simulated_button = SDL_BUTTON_RIGHT; + Uint8 simulatedButton = 0; + if (numFingersDown == 2) { + simulatedButton = SDL_BUTTON_RIGHT; // need to raise the button later simulated_click_start_time[port][1] = event->tfinger.timestamp; - } else if (num_fingers_down == 1) { - simulated_button = SDL_BUTTON_LEFT; + } else if (numFingersDown == 1) { + simulatedButton = SDL_BUTTON_LEFT; // need to raise the button later simulated_click_start_time[port][0] = event->tfinger.timestamp; if (direct_touch) { @@ -274,22 +274,22 @@ static void preprocess_finger_up(SDL_Event *event) devilution::OutputToLogical(&x, &y); } } - set_mouse_button_event(event, SDL_MOUSEBUTTONDOWN, simulated_button, x, y); - } else if (num_fingers_down == 1) { + SetMouseButtonEvent(event, SDL_MOUSEBUTTONDOWN, simulatedButton, x, y); + } else if (numFingersDown == 1) { // when dragging, and the last finger is lifted, the drag is over - Uint8 simulated_button = 0; - if (multi_finger_dragging[port] == DRAG_THREE_FINGER) { - simulated_button = SDL_BUTTON_RIGHT; + Uint8 simulatedButton = 0; + if (multi_finger_dragging[port] == DragThreeFinger) { + simulatedButton = SDL_BUTTON_RIGHT; } else { - simulated_button = SDL_BUTTON_LEFT; + simulatedButton = SDL_BUTTON_LEFT; } - set_mouse_button_event(event, SDL_MOUSEBUTTONUP, simulated_button, x, y); - multi_finger_dragging[port] = DRAG_NONE; + SetMouseButtonEvent(event, SDL_MOUSEBUTTONUP, simulatedButton, x, y); + multi_finger_dragging[port] = DragNone; } } } -static void preprocess_finger_motion(SDL_Event *event) +static void PreprocessFingerMotion(SDL_Event *event) { // front (0) or back (1) panel SDL_TouchID port = event->tfinger.touchId; @@ -297,18 +297,18 @@ static void preprocess_finger_motion(SDL_Event *event) SDL_FingerID id = event->tfinger.fingerId; // find out how many fingers were down before this event - int num_fingers_down = 0; - for (int i = 0; i < MAX_NUM_FINGERS; i++) { + int numFingersDown = 0; + for (int i = 0; i < MaxNumFingers; i++) { if (finger[port][i].id >= 0) { - num_fingers_down++; + numFingersDown++; } } - if (num_fingers_down == 0) { + if (numFingersDown == 0) { return; } - if (num_fingers_down >= 1) { + if (numFingersDown >= 1) { int x = mouse_x; int y = mouse_y; int xrel = 0; @@ -334,7 +334,7 @@ static void preprocess_finger_motion(SDL_Event *event) yrel = y - mouse_y; // update the current finger's coordinates so we can track it later - for (int i = 0; i < MAX_NUM_FINGERS; i++) { + for (int i = 0; i < MaxNumFingers; i++) { if (finger[port][i].id != id) continue; finger[port][i].last_x = x; @@ -342,30 +342,30 @@ static void preprocess_finger_motion(SDL_Event *event) } // If we are starting a multi-finger drag, start holding down the mouse button - if (num_fingers_down >= 2 && !multi_finger_dragging[port]) { + if (numFingersDown >= 2 && !multi_finger_dragging[port]) { // only start a multi-finger drag if at least two fingers have been down long enough - int num_fingers_downlong = 0; - for (int i = 0; i < MAX_NUM_FINGERS; i++) { + int numFingersDownlong = 0; + for (int i = 0; i < MaxNumFingers; i++) { if (finger[port][i].id == NO_TOUCH) { continue; } - if (event->tfinger.timestamp - finger[port][i].time_last_down > MAX_TAP_TIME) { - num_fingers_downlong++; + if (event->tfinger.timestamp - finger[port][i].time_last_down > MaxTapTime) { + numFingersDownlong++; } } - if (num_fingers_downlong >= 2) { - int mouse_down_x = mouse_x; - int mouse_down_y = mouse_y; + if (numFingersDownlong >= 2) { + int mouseDownX = mouse_x; + int mouseDownY = mouse_y; if (direct_touch) { - for (int i = 0; i < MAX_NUM_FINGERS; i++) { + for (int i = 0; i < MaxNumFingers; i++) { if (finger[port][i].id == id) { - uint32_t earliest_time = finger[port][i].time_last_down; - for (int j = 0; j < MAX_NUM_FINGERS; j++) { + uint32_t earliestTime = finger[port][i].time_last_down; + for (int j = 0; j < MaxNumFingers; j++) { if (finger[port][j].id >= 0 && (i != j)) { - if (finger[port][j].time_last_down < earliest_time) { - mouse_down_x = finger[port][j].last_x; - mouse_down_y = finger[port][j].last_y; - earliest_time = finger[port][j].time_last_down; + if (finger[port][j].time_last_down < earliestTime) { + mouseDownX = finger[port][j].last_x; + mouseDownY = finger[port][j].last_y; + earliestTime = finger[port][j].time_last_down; } } } @@ -374,16 +374,16 @@ static void preprocess_finger_motion(SDL_Event *event) } } - Uint8 simulated_button = 0; - if (num_fingers_downlong == 2) { - simulated_button = SDL_BUTTON_LEFT; - multi_finger_dragging[port] = DRAG_TWO_FINGER; + Uint8 simulatedButton = 0; + if (numFingersDownlong == 2) { + simulatedButton = SDL_BUTTON_LEFT; + multi_finger_dragging[port] = DragTwoFinger; } else { - simulated_button = SDL_BUTTON_RIGHT; - multi_finger_dragging[port] = DRAG_THREE_FINGER; + simulatedButton = SDL_BUTTON_RIGHT; + multi_finger_dragging[port] = DragThreeFinger; } SDL_Event ev; - set_mouse_button_event(&ev, SDL_MOUSEBUTTONDOWN, simulated_button, mouse_down_x, mouse_down_y); + SetMouseButtonEvent(&ev, SDL_MOUSEBUTTONDOWN, simulatedButton, mouseDownX, mouseDownY); SDL_PushEvent(&ev); } } @@ -394,51 +394,51 @@ static void preprocess_finger_motion(SDL_Event *event) // check if this is the "oldest" finger down (or the only finger down) // otherwise it will not affect mouse motion - bool update_pointer = true; - if (num_fingers_down > 1) { - for (int i = 0; i < MAX_NUM_FINGERS; i++) { + bool updatePointer = true; + if (numFingersDown > 1) { + for (int i = 0; i < MaxNumFingers; i++) { if (finger[port][i].id != id) { continue; } - for (int j = 0; j < MAX_NUM_FINGERS; j++) { + for (int j = 0; j < MaxNumFingers; j++) { if (finger[port][j].id == NO_TOUCH || (j == i)) { continue; } if (finger[port][j].time_last_down < finger[port][i].time_last_down) { - update_pointer = false; + updatePointer = false; } } } } - if (!update_pointer) { + if (!updatePointer) { return; } - set_mouse_motion_event(event, x, y, xrel, yrel); + SetMouseMotionEvent(event, x, y, xrel, yrel); } } namespace devilution { -void handle_touch(SDL_Event *event, int current_mouse_x, int current_mouse_y) +void handle_touch(SDL_Event *event, int currentMouseX, int currentMouseY) { - mouse_x = current_mouse_x; - mouse_y = current_mouse_y; + mouse_x = currentMouseX; + mouse_y = currentMouseY; if (!touch_initialized) { - init_touch(); + InitTouch(); touch_initialized = true; } - preprocess_events(event); + PreprocessEvents(event); if (event->type == SDL_FINGERDOWN || event->type == SDL_FINGERUP || event->type == SDL_FINGERMOTION) { event->type = SDL_USEREVENT; event->user.code = -1; // ensure this event is ignored; } } -void finish_simulated_mouse_clicks(int current_mouse_x, int current_mouse_y) +void finish_simulated_mouse_clicks(int currentMouseX, int currentMouseY) { - mouse_x = current_mouse_x; - mouse_y = current_mouse_y; + mouse_x = currentMouseX; + mouse_y = currentMouseY; for (auto &port : simulated_click_start_time) { for (int i = 0; i < 2; i++) { @@ -446,19 +446,19 @@ void finish_simulated_mouse_clicks(int current_mouse_x, int current_mouse_y) continue; } - Uint32 current_time = SDL_GetTicks(); - if (current_time - port[i] < SIMULATED_CLICK_DURATION) { + Uint32 currentTime = SDL_GetTicks(); + if (currentTime - port[i] < SimulatedClickDuration) { continue; } - int simulated_button; + int simulatedButton; if (i == 0) { - simulated_button = SDL_BUTTON_LEFT; + simulatedButton = SDL_BUTTON_LEFT; } else { - simulated_button = SDL_BUTTON_RIGHT; + simulatedButton = SDL_BUTTON_RIGHT; } SDL_Event ev; - set_mouse_button_event(&ev, SDL_MOUSEBUTTONUP, simulated_button, mouse_x, mouse_y); + SetMouseButtonEvent(&ev, SDL_MOUSEBUTTONUP, simulatedButton, mouse_x, mouse_y); SDL_PushEvent(&ev); port[i] = 0; @@ -468,7 +468,7 @@ void finish_simulated_mouse_clicks(int current_mouse_x, int current_mouse_y) } // namespace devilution -static void set_mouse_button_event(SDL_Event *event, uint32_t type, uint8_t button, int32_t x, int32_t y) +static void SetMouseButtonEvent(SDL_Event *event, uint32_t type, uint8_t button, int32_t x, int32_t y) { event->type = type; event->button.button = button; @@ -481,7 +481,7 @@ static void set_mouse_button_event(SDL_Event *event, uint32_t type, uint8_t butt event->button.y = y; } -static void set_mouse_motion_event(SDL_Event *event, int32_t x, int32_t y, int32_t xrel, int32_t yrel) +static void SetMouseMotionEvent(SDL_Event *event, int32_t x, int32_t y, int32_t xrel, int32_t yrel) { event->type = SDL_MOUSEMOTION; event->motion.x = x; diff --git a/Source/dvlnet/base.cpp b/Source/dvlnet/base.cpp index e2324d06d..064c6907a 100644 --- a/Source/dvlnet/base.cpp +++ b/Source/dvlnet/base.cpp @@ -123,8 +123,8 @@ bool base::SNetSendMessage(int playerID, void *data, unsigned int size) if (playerID != SNPLAYER_ALL && playerID != SNPLAYER_OTHERS && (playerID < 0 || playerID >= MAX_PLRS)) abort(); - auto raw_message = reinterpret_cast(data); - buffer_t message(raw_message, raw_message + size); + auto rawMessage = reinterpret_cast(data); + buffer_t message(rawMessage, rawMessage + size); if (playerID == plr_self || playerID == SNPLAYER_ALL) message_queue.emplace_back(plr_self, message); plr_t dest; @@ -142,16 +142,16 @@ bool base::SNetSendMessage(int playerID, void *data, unsigned int size) bool base::SNetReceiveTurns(char **data, unsigned int *size, DWORD *status) { poll(); - bool all_turns_arrived = true; + bool allTurnsArrived = true; for (auto i = 0; i < MAX_PLRS; ++i) { status[i] = 0; if (connected_table[i]) { status[i] |= PS_CONNECTED; if (turn_queue[i].empty()) - all_turns_arrived = false; + allTurnsArrived = false; } } - if (all_turns_arrived) { + if (allTurnsArrived) { for (auto i = 0; i < MAX_PLRS; ++i) { if (connected_table[i]) { size[i] = sizeof(turn_t); diff --git a/Source/dvlnet/loopback.cpp b/Source/dvlnet/loopback.cpp index 7c4619b4e..c85446f32 100644 --- a/Source/dvlnet/loopback.cpp +++ b/Source/dvlnet/loopback.cpp @@ -28,8 +28,8 @@ bool loopback::SNetReceiveMessage(int *sender, char **data, int *size) bool loopback::SNetSendMessage(int dest, void *data, unsigned int size) { if (dest == plr_single || dest == SNPLAYER_ALL) { - auto *raw_message = reinterpret_cast(data); - buffer_t message(raw_message, raw_message + size); + auto *rawMessage = reinterpret_cast(data); + buffer_t message(rawMessage, rawMessage + size); message_queue.push(message); } return true; diff --git a/Source/dvlnet/packet.cpp b/Source/dvlnet/packet.cpp index aac6a9ebf..ba7393258 100644 --- a/Source/dvlnet/packet.cpp +++ b/Source/dvlnet/packet.cpp @@ -3,12 +3,12 @@ namespace devilution::net { #ifndef NONET -static constexpr bool disable_encryption = false; +static constexpr bool DisableEncryption = false; #endif -const char *packet_type_to_string(uint8_t packet_type) +const char *packet_type_to_string(uint8_t packetType) { - switch (packet_type) { + switch (packetType) { case PT_MESSAGE: return "PT_MESSAGE"; case PT_TURN: @@ -30,35 +30,35 @@ const char *packet_type_to_string(uint8_t packet_type) } } -wrong_packet_type_exception::wrong_packet_type_exception(std::initializer_list expected_types, std::uint8_t actual) +wrong_packet_type_exception::wrong_packet_type_exception(std::initializer_list expectedTypes, std::uint8_t actual) { message_ = "Expected packet of type "; - const auto append_packet_type = [this](std::uint8_t t) { - const char *type_str = packet_type_to_string(t); - if (type_str != nullptr) - message_.append(type_str); + const auto appendPacketType = [this](std::uint8_t t) { + const char *typeStr = packet_type_to_string(t); + if (typeStr != nullptr) + message_.append(typeStr); else message_.append(std::to_string(t)); }; - constexpr char kJoinTypes[] = " or "; - for (const packet_type t : expected_types) { - append_packet_type(t); - message_.append(kJoinTypes); + constexpr char KJoinTypes[] = " or "; + for (const packet_type t : expectedTypes) { + appendPacketType(t); + message_.append(KJoinTypes); } - message_.resize(message_.size() - (sizeof(kJoinTypes) - 1)); + message_.resize(message_.size() - (sizeof(KJoinTypes) - 1)); message_.append(", got"); - append_packet_type(actual); + appendPacketType(actual); } namespace { -void CheckPacketTypeOneOf(std::initializer_list expected_types, std::uint8_t actual_type) +void CheckPacketTypeOneOf(std::initializer_list expectedTypes, std::uint8_t actualType) { - for (std::uint8_t packet_type : expected_types) - if (actual_type == packet_type) + for (std::uint8_t packetType : expectedTypes) + if (actualType == packetType) return; - throw wrong_packet_type_exception(expected_types, actual_type); + throw wrong_packet_type_exception(expectedTypes, actualType); } } // namespace @@ -154,7 +154,7 @@ void packet_in::decrypt() if (have_decrypted) return; #ifndef NONET - if (!disable_encryption) { + if (!DisableEncryption) { if (encrypted_buffer.size() < crypto_secretbox_NONCEBYTES + crypto_secretbox_MACBYTES + sizeof(packet_type) + 2 * sizeof(plr_t)) @@ -194,8 +194,8 @@ void packet_out::encrypt() process_data(); #ifndef NONET - if (!disable_encryption) { - auto len_cleartext = encrypted_buffer.size(); + if (!DisableEncryption) { + auto lenCleartext = encrypted_buffer.size(); encrypted_buffer.insert(encrypted_buffer.begin(), crypto_secretbox_NONCEBYTES, 0); encrypted_buffer.insert(encrypted_buffer.end(), @@ -205,7 +205,7 @@ void packet_out::encrypt() + crypto_secretbox_NONCEBYTES, encrypted_buffer.data() + crypto_secretbox_NONCEBYTES, - len_cleartext, + lenCleartext, encrypted_buffer.data(), key.data())) ABORT(); diff --git a/Source/dvlnet/protocol_zt.cpp b/Source/dvlnet/protocol_zt.cpp index 8e848198c..5bbb682f5 100644 --- a/Source/dvlnet/protocol_zt.cpp +++ b/Source/dvlnet/protocol_zt.cpp @@ -295,11 +295,11 @@ uint64_t protocol_zt::current_ms() std::string protocol_zt::make_default_gamename() { std::string ret; - std::string allowed_chars = "abcdefghkopqrstuvwxyz"; + std::string allowedChars = "abcdefghkopqrstuvwxyz"; std::random_device rd; - std::uniform_int_distribution dist(0, allowed_chars.size() - 1); + std::uniform_int_distribution dist(0, allowedChars.size() - 1); for (int i = 0; i < 5; ++i) { - ret += allowed_chars.at(dist(rd)); + ret += allowedChars.at(dist(rd)); } return ret; } diff --git a/Source/dvlnet/tcp_client.cpp b/Source/dvlnet/tcp_client.cpp index c9c0473c4..e908d699e 100644 --- a/Source/dvlnet/tcp_client.cpp +++ b/Source/dvlnet/tcp_client.cpp @@ -28,8 +28,8 @@ int tcp_client::create(std::string addrstr, std::string passwd) int tcp_client::join(std::string addrstr, std::string passwd) { - constexpr int ms_sleep = 10; - constexpr int no_sleep = 250; + constexpr int MsSleep = 10; + constexpr int NoSleep = 250; setup_password(passwd); try { @@ -50,7 +50,7 @@ int tcp_client::join(std::string addrstr, std::string passwd) PLR_MASTER, cookie_self, game_init_info); send(*pkt); - for (auto i = 0; i < no_sleep; ++i) { + for (auto i = 0; i < NoSleep; ++i) { try { poll(); } catch (const std::runtime_error &e) { @@ -59,7 +59,7 @@ int tcp_client::join(std::string addrstr, std::string passwd) } if (plr_self != PLR_BROADCAST) break; // join successful - SDL_Delay(ms_sleep); + SDL_Delay(MsSleep); } } if (plr_self == PLR_BROADCAST) { @@ -75,7 +75,7 @@ void tcp_client::poll() ioc.poll(); } -void tcp_client::handle_recv(const asio::error_code &error, size_t bytes_read) +void tcp_client::handle_recv(const asio::error_code &error, size_t bytesRead) { if (error) { // error in recv from server @@ -83,10 +83,10 @@ void tcp_client::handle_recv(const asio::error_code &error, size_t bytes_read) // as if all connections to other clients were lost return; } - if (bytes_read == 0) { + if (bytesRead == 0) { throw std::runtime_error("error: read 0 bytes from server"); } - recv_buffer.resize(bytes_read); + recv_buffer.resize(bytesRead); recv_queue.write(std::move(recv_buffer)); recv_buffer.resize(frame_queue::max_frame_size); while (recv_queue.packet_ready()) { @@ -103,7 +103,7 @@ void tcp_client::start_recv() std::placeholders::_1, std::placeholders::_2)); } -void tcp_client::handle_send(const asio::error_code &error, size_t bytes_sent) +void tcp_client::handle_send(const asio::error_code &error, size_t bytesSent) { // empty for now } @@ -112,8 +112,8 @@ void tcp_client::send(packet &pkt) { const auto *frame = new buffer_t(frame_queue::make_frame(pkt.data())); auto buf = asio::buffer(*frame); - asio::async_write(sock, buf, [this, frame](const asio::error_code &error, size_t bytes_sent) { - handle_send(error, bytes_sent); + asio::async_write(sock, buf, [this, frame](const asio::error_code &error, size_t bytesSent) { + handle_send(error, bytesSent); delete frame; }); } diff --git a/Source/dvlnet/tcp_server.cpp b/Source/dvlnet/tcp_server.cpp index 2de7a9286..abdff48bb 100644 --- a/Source/dvlnet/tcp_server.cpp +++ b/Source/dvlnet/tcp_server.cpp @@ -65,13 +65,13 @@ void tcp_server::start_recv(const scc &con) } void tcp_server::handle_recv(const scc &con, const asio::error_code &ec, - size_t bytes_read) + size_t bytesRead) { - if (ec || bytes_read == 0) { + if (ec || bytesRead == 0) { drop_connection(con); return; } - con->recv_buffer.resize(bytes_read); + con->recv_buffer.resize(bytesRead); con->recv_queue.write(std::move(con->recv_buffer)); con->recv_buffer.resize(frame_queue::max_frame_size); while (con->recv_queue.packet_ready()) { @@ -140,14 +140,14 @@ void tcp_server::start_send(const scc &con, packet &pkt) const auto *frame = new buffer_t(frame_queue::make_frame(pkt.data())); auto buf = asio::buffer(*frame); asio::async_write(con->socket, buf, - [this, con, frame](const asio::error_code &ec, size_t bytes_sent) { - handle_send(con, ec, bytes_sent); + [this, con, frame](const asio::error_code &ec, size_t bytesSent) { + handle_send(con, ec, bytesSent); delete frame; }); } void tcp_server::handle_send(const scc &con, const asio::error_code &ec, - size_t bytes_sent) + size_t bytesSent) { // empty for now } diff --git a/Source/dvlnet/zerotier_native.cpp b/Source/dvlnet/zerotier_native.cpp index 588b1f60d..265785d55 100644 --- a/Source/dvlnet/zerotier_native.cpp +++ b/Source/dvlnet/zerotier_native.cpp @@ -19,21 +19,21 @@ namespace devilution::net { //static constexpr uint64_t zt_earth = 0x8056c2e21c000001; -static constexpr uint64_t zt_network = 0xaf78bf943649eb12; +static constexpr uint64_t ZtNetwork = 0xaf78bf943649eb12; static std::atomic_bool zt_network_ready(false); static std::atomic_bool zt_node_online(false); static std::atomic_bool zt_started(false); static std::atomic_bool zt_joined(false); -static void callback(struct zts_callback_msg *msg) +static void Callback(struct zts_callback_msg *msg) { //printf("callback %i\n", msg->eventCode); if (msg->eventCode == ZTS_EVENT_NODE_ONLINE) { SDL_Log("ZeroTier: ZTS_EVENT_NODE_ONLINE, nodeId=%llx\n", (unsigned long long)msg->node->address); zt_node_online = true; if (!zt_joined) { - zts_join(zt_network); + zts_join(ZtNetwork); zt_joined = true; } } else if (msg->eventCode == ZTS_EVENT_NODE_OFFLINE) { @@ -62,7 +62,7 @@ void zerotier_network_start() { if (zt_started) return; - zts_start(GetPrefPath().c_str(), (void (*)(void *))callback, 0); + zts_start(GetPrefPath().c_str(), (void (*)(void *))Callback, 0); std::atexit(zerotier_network_stop); } diff --git a/Source/miniwin/misc_msg.cpp b/Source/miniwin/misc_msg.cpp index 5543d1b9c..696c6ec7a 100644 --- a/Source/miniwin/misc_msg.cpp +++ b/Source/miniwin/misc_msg.cpp @@ -34,13 +34,13 @@ bool mouseWarping = false; int mouseWarpingX; int mouseWarpingY; -void SetCursorPos(int X, int Y) +void SetCursorPos(int x, int y) { - mouseWarpingX = X; - mouseWarpingY = Y; + mouseWarpingX = x; + mouseWarpingY = y; mouseWarping = true; - LogicalToOutput(&X, &Y); - SDL_WarpMouseInWindow(ghMainWnd, X, Y); + LogicalToOutput(&x, &y); + SDL_WarpMouseInWindow(ghMainWnd, x, y); } // Moves the mouse to the first attribute "+" button. @@ -79,7 +79,7 @@ void FocusOnCharInfo() SetCursorPos(rect.x + (rect.w / 2), rect.y + (rect.h / 2)); } -static int translate_sdl_key(SDL_Keysym key) +static int TranslateSdlKey(SDL_Keysym key) { // ref: https://wiki.libsdl.org/SDL_Keycode // ref: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes @@ -251,19 +251,19 @@ static int translate_sdl_key(SDL_Keysym key) namespace { -LPARAM position_for_mouse(short x, short y) +LPARAM PositionForMouse(short x, short y) { return (((uint16_t)(y & 0xFFFF)) << 16) | (uint16_t)(x & 0xFFFF); } -WPARAM keystate_for_mouse(WPARAM ret) +WPARAM KeystateForMouse(WPARAM ret) { ret |= (SDL_GetModState() & KMOD_SHIFT) ? DVL_MK_SHIFT : 0; // XXX: other DVL_MK_* codes not implemented return ret; } -bool false_avail(const char *name, int value) +bool FalseAvail(const char *name, int value) { SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Unhandled SDL event: %s %d", name, value); return true; @@ -339,12 +339,12 @@ bool FetchMessage(LPMSG lpMsg) if (HandleControllerAddedOrRemovedEvent(e)) return true; - const ControllerButtonEvent ctrl_event = ToControllerButtonEvent(e); - if (ProcessControllerMotion(e, ctrl_event)) + const ControllerButtonEvent ctrlEvent = ToControllerButtonEvent(e); + if (ProcessControllerMotion(e, ctrlEvent)) return true; GameAction action; - if (GetGameAction(e, ctrl_event, &action)) { + if (GetGameAction(e, ctrlEvent, &action)) { if (action.type != GameActionType_NONE) { sgbControllerActive = true; @@ -438,7 +438,7 @@ bool FetchMessage(LPMSG lpMsg) lpMsg->message = action.send_mouse_click.up ? DVL_WM_RBUTTONUP : DVL_WM_RBUTTONDOWN; break; } - lpMsg->lParam = position_for_mouse(MouseX, MouseY); + lpMsg->lParam = PositionForMouse(MouseX, MouseY); break; } return true; @@ -460,9 +460,9 @@ bool FetchMessage(LPMSG lpMsg) break; case SDL_KEYDOWN: case SDL_KEYUP: { - int key = translate_sdl_key(e.key.keysym); + int key = TranslateSdlKey(e.key.keysym); if (key == -1) - return false_avail(e.type == SDL_KEYDOWN ? "SDL_KEYDOWN" : "SDL_KEYUP", e.key.keysym.sym); + return FalseAvail(e.type == SDL_KEYDOWN ? "SDL_KEYDOWN" : "SDL_KEYUP", e.key.keysym.sym); lpMsg->message = e.type == SDL_KEYDOWN ? DVL_WM_KEYDOWN : DVL_WM_KEYUP; lpMsg->wParam = (DWORD)key; // HACK: Encode modifier in lParam for TranslateMessage later @@ -470,31 +470,31 @@ bool FetchMessage(LPMSG lpMsg) } break; case SDL_MOUSEMOTION: lpMsg->message = DVL_WM_MOUSEMOVE; - lpMsg->lParam = position_for_mouse(e.motion.x, e.motion.y); - lpMsg->wParam = keystate_for_mouse(0); + lpMsg->lParam = PositionForMouse(e.motion.x, e.motion.y); + lpMsg->wParam = KeystateForMouse(0); break; case SDL_MOUSEBUTTONDOWN: { int button = e.button.button; if (button == SDL_BUTTON_LEFT) { lpMsg->message = DVL_WM_LBUTTONDOWN; - lpMsg->lParam = position_for_mouse(e.button.x, e.button.y); - lpMsg->wParam = keystate_for_mouse(DVL_MK_LBUTTON); + lpMsg->lParam = PositionForMouse(e.button.x, e.button.y); + lpMsg->wParam = KeystateForMouse(DVL_MK_LBUTTON); } else if (button == SDL_BUTTON_RIGHT) { lpMsg->message = DVL_WM_RBUTTONDOWN; - lpMsg->lParam = position_for_mouse(e.button.x, e.button.y); - lpMsg->wParam = keystate_for_mouse(DVL_MK_RBUTTON); + lpMsg->lParam = PositionForMouse(e.button.x, e.button.y); + lpMsg->wParam = KeystateForMouse(DVL_MK_RBUTTON); } } break; case SDL_MOUSEBUTTONUP: { int button = e.button.button; if (button == SDL_BUTTON_LEFT) { lpMsg->message = DVL_WM_LBUTTONUP; - lpMsg->lParam = position_for_mouse(e.button.x, e.button.y); - lpMsg->wParam = keystate_for_mouse(0); + lpMsg->lParam = PositionForMouse(e.button.x, e.button.y); + lpMsg->wParam = KeystateForMouse(0); } else if (button == SDL_BUTTON_RIGHT) { lpMsg->message = DVL_WM_RBUTTONUP; - lpMsg->lParam = position_for_mouse(e.button.x, e.button.y); - lpMsg->wParam = keystate_for_mouse(0); + lpMsg->lParam = PositionForMouse(e.button.x, e.button.y); + lpMsg->wParam = KeystateForMouse(0); } } break; #ifndef USE_SDL1 @@ -512,16 +512,16 @@ bool FetchMessage(LPMSG lpMsg) break; #if SDL_VERSION_ATLEAST(2, 0, 4) case SDL_AUDIODEVICEADDED: - return false_avail("SDL_AUDIODEVICEADDED", e.adevice.which); + return FalseAvail("SDL_AUDIODEVICEADDED", e.adevice.which); case SDL_AUDIODEVICEREMOVED: - return false_avail("SDL_AUDIODEVICEREMOVED", e.adevice.which); + return FalseAvail("SDL_AUDIODEVICEREMOVED", e.adevice.which); case SDL_KEYMAPCHANGED: - return false_avail("SDL_KEYMAPCHANGED", 0); + return FalseAvail("SDL_KEYMAPCHANGED", 0); #endif case SDL_TEXTEDITING: - return false_avail("SDL_TEXTEDITING", e.edit.length); + return FalseAvail("SDL_TEXTEDITING", e.edit.length); case SDL_TEXTINPUT: - return false_avail("SDL_TEXTINPUT", e.text.windowID); + return FalseAvail("SDL_TEXTINPUT", e.text.windowID); case SDL_WINDOWEVENT: switch (e.window.event) { case SDL_WINDOWEVENT_SHOWN: @@ -563,13 +563,13 @@ bool FetchMessage(LPMSG lpMsg) lpMsg->message = DVL_WM_QUERYENDSESSION; break; default: - return false_avail("SDL_WINDOWEVENT", e.window.event); + return FalseAvail("SDL_WINDOWEVENT", e.window.event); } break; #endif default: - return false_avail("unknown", e.type); + return FalseAvail("unknown", e.type); } return true; } @@ -583,15 +583,15 @@ bool TranslateMessage(const MSG *lpMsg) bool shift = (mod & KMOD_SHIFT) != 0; bool upper = shift != (mod & KMOD_CAPS); - bool is_alpha = (key >= 'A' && key <= 'Z'); - bool is_numeric = (key >= '0' && key <= '9'); - bool is_control = key == DVL_VK_SPACE || key == DVL_VK_BACK || key == DVL_VK_ESCAPE || key == DVL_VK_TAB || key == DVL_VK_RETURN; - bool is_oem = (key >= DVL_VK_OEM_1 && key <= DVL_VK_OEM_7); + bool isAlpha = (key >= 'A' && key <= 'Z'); + bool isNumeric = (key >= '0' && key <= '9'); + bool isControl = key == DVL_VK_SPACE || key == DVL_VK_BACK || key == DVL_VK_ESCAPE || key == DVL_VK_TAB || key == DVL_VK_RETURN; + bool isOem = (key >= DVL_VK_OEM_1 && key <= DVL_VK_OEM_7); - if (is_control || is_alpha || is_numeric || is_oem) { - if (!upper && is_alpha) { + if (isControl || isAlpha || isNumeric || isOem) { + if (!upper && isAlpha) { key = tolower(key); - } else if (shift && is_numeric) { + } else if (shift && isNumeric) { switch (key) { case '1': key = '!'; @@ -624,7 +624,7 @@ bool TranslateMessage(const MSG *lpMsg) key = ')'; break; } - } else if (is_oem) { + } else if (isOem) { // XXX: This probably only supports US keyboard layout switch (key) { case DVL_VK_OEM_1: @@ -714,14 +714,14 @@ void PushMessage(const MSG *lpMsg) CurrentProc(lpMsg->message, lpMsg->wParam, lpMsg->lParam); } -bool PostMessage(UINT Msg, WPARAM wParam, LPARAM lParam) +bool PostMessage(UINT type, WPARAM wParam, LPARAM lParam) { - MSG msg; - msg.message = Msg; - msg.wParam = wParam; - msg.lParam = lParam; + MSG message; + message.message = type; + message.wParam = wParam; + message.lParam = lParam; - message_queue.push_back(msg); + message_queue.push_back(message); return true; } diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 64bd4f569..3a158dda8 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -172,10 +172,10 @@ private: std::unique_ptr s_; }; -constexpr std::size_t kBlockEntrySize = INDEX_ENTRIES * sizeof(_BLOCKENTRY); -constexpr std::size_t kHashEntrySize = INDEX_ENTRIES * sizeof(_HASHENTRY); -constexpr std::ios::off_type kMpqBlockEntryOffset = sizeof(_FILEHEADER); -constexpr std::ios::off_type kMpqHashEntryOffset = kMpqBlockEntryOffset + kBlockEntrySize; +constexpr std::size_t BlockEntrySize = INDEX_ENTRIES * sizeof(_BLOCKENTRY); +constexpr std::size_t HashEntrySize = INDEX_ENTRIES * sizeof(_HASHENTRY); +constexpr std::ios::off_type MpqBlockEntryOffset = sizeof(_FILEHEADER); +constexpr std::ios::off_type MpqHashEntryOffset = MpqBlockEntryOffset + BlockEntrySize; struct Archive { FStreamWrapper stream; @@ -269,8 +269,8 @@ private: fhdr.filesize = SDL_SwapLE32(static_cast(size)); fhdr.version = SDL_SwapLE16(0); fhdr.sectorsizeid = SDL_SwapLE16(3); - fhdr.hashoffset = SDL_SwapLE32(static_cast(kMpqHashEntryOffset)); - fhdr.blockoffset = SDL_SwapLE32(static_cast(kMpqBlockEntryOffset)); + fhdr.hashoffset = SDL_SwapLE32(static_cast(MpqHashEntryOffset)); + fhdr.blockoffset = SDL_SwapLE32(static_cast(MpqBlockEntryOffset)); fhdr.hashcount = SDL_SwapLE32(INDEX_ENTRIES); fhdr.blockcount = SDL_SwapLE32(INDEX_ENTRIES); @@ -281,17 +281,17 @@ private: bool WriteBlockTable() { - Encrypt((DWORD *)sgpBlockTbl, kBlockEntrySize, Hash("(block table)", 3)); - const bool success = stream.write(reinterpret_cast(sgpBlockTbl), kBlockEntrySize); - Decrypt((DWORD *)sgpBlockTbl, kBlockEntrySize, Hash("(block table)", 3)); + Encrypt((DWORD *)sgpBlockTbl, BlockEntrySize, Hash("(block table)", 3)); + const bool success = stream.write(reinterpret_cast(sgpBlockTbl), BlockEntrySize); + Decrypt((DWORD *)sgpBlockTbl, BlockEntrySize, Hash("(block table)", 3)); return success; } bool WriteHashTable() { - Encrypt((DWORD *)sgpHashTbl, kHashEntrySize, Hash("(hash table)", 3)); - const bool success = stream.write(reinterpret_cast(sgpHashTbl), kHashEntrySize); - Decrypt((DWORD *)sgpHashTbl, kHashEntrySize, Hash("(hash table)", 3)); + Encrypt((DWORD *)sgpHashTbl, HashEntrySize, Hash("(hash table)", 3)); + const bool success = stream.write(reinterpret_cast(sgpHashTbl), HashEntrySize); + Decrypt((DWORD *)sgpHashTbl, HashEntrySize, Hash("(hash table)", 3)); return success; } }; @@ -318,7 +318,7 @@ void InitDefaultMpqHeader(Archive *archive, _FILEHEADER *hdr) hdr->headersize = 32; hdr->sectorsizeid = 3; hdr->version = 0; - archive->size = kMpqHashEntryOffset + kHashEntrySize; + archive->size = MpqHashEntryOffset + HashEntrySize; archive->modified = true; } @@ -329,7 +329,7 @@ bool IsValidMPQHeader(const Archive &archive, _FILEHEADER *hdr) && hdr->version <= 0 && hdr->sectorsizeid == 3 && hdr->filesize == archive.size - && hdr->hashoffset == kMpqHashEntryOffset + && hdr->hashoffset == MpqHashEntryOffset && hdr->blockoffset == sizeof(_FILEHEADER) && hdr->hashcount == INDEX_ENTRIES && hdr->blockcount == INDEX_ENTRIES; @@ -540,8 +540,8 @@ static bool mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, pszName = tmp + 1; Hash(pszName, 3); - constexpr uint32_t kSectorSize = 4096; - const uint32_t num_sectors = (dwLen + (kSectorSize - 1)) / kSectorSize; + constexpr uint32_t sectorSize = 4096; + const uint32_t num_sectors = (dwLen + (sectorSize - 1)) / sectorSize; const uint32_t offset_table_bytesize = sizeof(uint32_t) * (num_sectors + 1); pBlk->offset = mpqapi_find_free_block(dwLen + offset_table_bytesize, &pBlk->sizealloc); pBlk->sizefile = dwLen; @@ -576,10 +576,10 @@ static bool mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, #endif uint32_t destsize = offset_table_bytesize; - BYTE mpq_buf[kSectorSize]; + BYTE mpq_buf[sectorSize]; std::size_t cur_sector = 0; while (true) { - uint32_t len = std::min(dwLen, kSectorSize); + uint32_t len = std::min(dwLen, sectorSize); memcpy(mpq_buf, pbData, len); pbData += len; len = PkwareCompress(mpq_buf, len); @@ -587,8 +587,8 @@ static bool mpqapi_write_file_contents(const char *pszName, const BYTE *pbData, return false; sectoroffsettable[cur_sector++] = SDL_SwapLE32(destsize); destsize += len; // compressed length - if (dwLen > kSectorSize) - dwLen -= kSectorSize; + if (dwLen > sectorSize) + dwLen -= sectorSize; else break; } @@ -663,21 +663,21 @@ bool OpenMPQ(const char *pszArchive) } else if (!ReadMPQHeader(&cur_archive, &fhdr)) { goto on_error; } - cur_archive.sgpBlockTbl = new _BLOCKENTRY[kBlockEntrySize / sizeof(_BLOCKENTRY)]; - std::memset(cur_archive.sgpBlockTbl, 0, kBlockEntrySize); + cur_archive.sgpBlockTbl = new _BLOCKENTRY[BlockEntrySize / sizeof(_BLOCKENTRY)]; + std::memset(cur_archive.sgpBlockTbl, 0, BlockEntrySize); if (fhdr.blockcount) { - if (!cur_archive.stream.read(reinterpret_cast(cur_archive.sgpBlockTbl), kBlockEntrySize)) + if (!cur_archive.stream.read(reinterpret_cast(cur_archive.sgpBlockTbl), BlockEntrySize)) goto on_error; key = Hash("(block table)", 3); - Decrypt((DWORD *)cur_archive.sgpBlockTbl, kBlockEntrySize, key); + Decrypt((DWORD *)cur_archive.sgpBlockTbl, BlockEntrySize, key); } - cur_archive.sgpHashTbl = new _HASHENTRY[kHashEntrySize / sizeof(_HASHENTRY)]; - std::memset(cur_archive.sgpHashTbl, 255, kHashEntrySize); + cur_archive.sgpHashTbl = new _HASHENTRY[HashEntrySize / sizeof(_HASHENTRY)]; + std::memset(cur_archive.sgpHashTbl, 255, HashEntrySize); if (fhdr.hashcount) { - if (!cur_archive.stream.read(reinterpret_cast(cur_archive.sgpHashTbl), kHashEntrySize)) + if (!cur_archive.stream.read(reinterpret_cast(cur_archive.sgpHashTbl), HashEntrySize)) goto on_error; key = Hash("(hash table)", 3); - Decrypt((DWORD *)cur_archive.sgpHashTbl, kHashEntrySize, key); + Decrypt((DWORD *)cur_archive.sgpHashTbl, HashEntrySize, key); } #ifndef CAN_SEEKP_BEYOND_EOF diff --git a/Source/render.cpp b/Source/render.cpp index dc1da80e1..76be0dc79 100644 --- a/Source/render.cpp +++ b/Source/render.cpp @@ -600,29 +600,29 @@ namespace { // The tile's bounding box is 64 by 31 px. // // Heights of the upper and lower triangles of the tile: -constexpr int kUpperHeight = TILE_HEIGHT / 2 - 1; -constexpr int kLowerHeight = TILE_HEIGHT / 2; -constexpr int kHeight = kLowerHeight + kLowerHeight; -constexpr int kXStep = 2; +constexpr int UpperHeight = TILE_HEIGHT / 2 - 1; +constexpr int LowerHeight = TILE_HEIGHT / 2; +constexpr int Height = LowerHeight + LowerHeight; +constexpr int XStep = 2; // Blit with left and vertical clipping. void BlitBlackTileClipLeftY(BYTE *dst, int dst_pitch, int sx, int skip_lower_bottom, int skip_lower_top, int skip_upper_bottom, int skip_upper_top) { // Lower triangle (drawn bottom to top): - for (int i = skip_lower_bottom + 1; i <= kLowerHeight - skip_lower_top; ++i, dst -= dst_pitch + kXStep) { - const int w = 2 * kXStep * i; - const int cur_x = sx + TILE_WIDTH / 2 - kXStep * i; + for (int i = skip_lower_bottom + 1; i <= LowerHeight - skip_lower_top; ++i, dst -= dst_pitch + XStep) { + const int w = 2 * XStep * i; + const int cur_x = sx + TILE_WIDTH / 2 - XStep * i; if (cur_x >= 0) { memset(dst, 0, w); } else if (-cur_x <= w) { memset(dst - cur_x, 0, w + cur_x); } } - dst += 2 * kXStep; + dst += 2 * XStep; // Upper triangle (drawn bottom to top): - for (int i = skip_upper_bottom, j = kUpperHeight - skip_upper_bottom; i < kUpperHeight - skip_upper_top; ++i, --j, dst -= dst_pitch - kXStep) { - const int w = 2 * kXStep * j; - const int cur_x = sx + TILE_WIDTH / 2 - kXStep * j; + for (int i = skip_upper_bottom, j = UpperHeight - skip_upper_bottom; i < UpperHeight - skip_upper_top; ++i, --j, dst -= dst_pitch - XStep) { + const int w = 2 * XStep * j; + const int cur_x = sx + TILE_WIDTH / 2 - XStep * j; if (cur_x >= 0) { memset(dst, 0, w); } else if (-cur_x <= w) { @@ -637,18 +637,18 @@ void BlitBlackTileClipLeftY(BYTE *dst, int dst_pitch, int sx, int skip_lower_bot void BlitBlackTileClipWidthY(BYTE *dst, int dst_pitch, int max_w, int skip_lower_bottom, int skip_lower_top, int skip_upper_bottom, int skip_upper_top) { // Lower triangle (drawn bottom to top): - for (int i = skip_lower_bottom + 1; i <= kLowerHeight - skip_lower_top; ++i, dst -= dst_pitch + kXStep) { + for (int i = skip_lower_bottom + 1; i <= LowerHeight - skip_lower_top; ++i, dst -= dst_pitch + XStep) { if (max_w > 0) - memset(dst, 0, std::min(2 * kXStep * i, max_w)); - max_w += 2 * kXStep * i; + memset(dst, 0, std::min(2 * XStep * i, max_w)); + max_w += 2 * XStep * i; } - dst += 2 * kXStep; + dst += 2 * XStep; // Upper triangle (drawn bottom to top): - for (int i = skip_upper_bottom, j = kUpperHeight - skip_upper_bottom; i < kUpperHeight - skip_upper_top; ++i, --j, dst -= dst_pitch - kXStep) { - max_w -= 2 * kXStep; + for (int i = skip_upper_bottom, j = UpperHeight - skip_upper_bottom; i < UpperHeight - skip_upper_top; ++i, --j, dst -= dst_pitch - XStep) { + max_w -= 2 * XStep; if (max_w <= 0) break; - memset(dst, 0, std::min(2 * kXStep * j, max_w)); + memset(dst, 0, std::min(2 * XStep * j, max_w)); } } @@ -656,13 +656,13 @@ void BlitBlackTileClipWidthY(BYTE *dst, int dst_pitch, int max_w, int skip_lower void BlitBlackTileClipY(BYTE *dst, int dst_pitch, int skip_lower_bottom, int skip_lower_top, int skip_upper_bottom, int skip_upper_top) { // Lower triangle (drawn bottom to top): - for (int i = skip_lower_bottom + 1; i <= kLowerHeight - skip_lower_top; ++i, dst -= dst_pitch + kXStep) { - memset(dst, 0, 2 * kXStep * i); + for (int i = skip_lower_bottom + 1; i <= LowerHeight - skip_lower_top; ++i, dst -= dst_pitch + XStep) { + memset(dst, 0, 2 * XStep * i); } - dst += 2 * kXStep; + dst += 2 * XStep; // Upper triangle (drawn bottom to top): - for (int i = skip_upper_bottom, j = kUpperHeight - skip_upper_bottom; i < kUpperHeight - skip_upper_top; ++i, --j, dst -= dst_pitch - kXStep) { - memset(dst, 0, 2 * kXStep * j); + for (int i = skip_upper_bottom, j = UpperHeight - skip_upper_bottom; i < UpperHeight - skip_upper_top; ++i, --j, dst -= dst_pitch - XStep) { + memset(dst, 0, 2 * XStep * j); } } @@ -671,13 +671,13 @@ void BlitBlackTileFull(BYTE *dst, int dst_pitch) { // Tile is fully in bounds, can use constant loop boundaries. // Lower triangle (drawn bottom to top): - for (int i = 1; i <= kLowerHeight; ++i, dst -= dst_pitch + kXStep) { - memset(dst, 0, 2 * kXStep * i); + for (int i = 1; i <= LowerHeight; ++i, dst -= dst_pitch + XStep) { + memset(dst, 0, 2 * XStep * i); } - dst += 2 * kXStep; + dst += 2 * XStep; // Upper triangle (drawn bottom to to top): - for (int i = 0, j = kUpperHeight; i < kUpperHeight; ++i, --j, dst -= dst_pitch - kXStep) { - memset(dst, 0, 2 * kXStep * j); + for (int i = 0, j = UpperHeight; i < UpperHeight; ++i, --j, dst -= dst_pitch - XStep) { + memset(dst, 0, 2 * XStep * j); } } @@ -685,11 +685,11 @@ void BlitBlackTileFull(BYTE *dst, int dst_pitch) void world_draw_black_tile(CelOutputBuffer out, int sx, int sy) { - if (sx <= -TILE_WIDTH || sx >= out.region.w || sy < 0 || sy + 1 > out.region.h + kHeight) + if (sx <= -TILE_WIDTH || sx >= out.region.w || sy < 0 || sy + 1 > out.region.h + Height) return; // Initial out position: the bottom corner of the lower triangle. - int out_x = sx + TILE_WIDTH / 2 - kXStep; + int out_x = sx + TILE_WIDTH / 2 - XStep; int out_y = sy; // How many lines to skip for the lower and upper triangles: @@ -700,21 +700,21 @@ void world_draw_black_tile(CelOutputBuffer out, int sx, int sy) if (sy >= out.region.h) { skip_lower_bottom = sy - out.region.h + 1; out_y -= skip_lower_bottom; - if (skip_lower_bottom > kLowerHeight) { - skip_upper_bottom = skip_lower_bottom - kLowerHeight; - skip_lower_bottom = kLowerHeight; + if (skip_lower_bottom > LowerHeight) { + skip_upper_bottom = skip_lower_bottom - LowerHeight; + skip_lower_bottom = LowerHeight; } - out_x += kXStep * (skip_upper_bottom - skip_lower_bottom); - } else if (sy + 1 < kHeight) { - skip_upper_top = kHeight - (sy + 1) - 1; - if (skip_upper_top > kUpperHeight) { - skip_lower_top = skip_upper_top - kUpperHeight; - skip_upper_top = kUpperHeight; + out_x += XStep * (skip_upper_bottom - skip_lower_bottom); + } else if (sy + 1 < Height) { + skip_upper_top = Height - (sy + 1) - 1; + if (skip_upper_top > UpperHeight) { + skip_lower_top = skip_upper_top - UpperHeight; + skip_upper_top = UpperHeight; } } BYTE *dst = out.at(out_x, out_y); - if (out_x < TILE_WIDTH / 2 - kXStep) { + if (out_x < TILE_WIDTH / 2 - XStep) { BlitBlackTileClipLeftY(dst, out.pitch(), sx, skip_lower_bottom, skip_lower_top, skip_upper_bottom, skip_upper_top); } else if (sx > out.region.w - TILE_WIDTH) { BlitBlackTileClipWidthY(dst, out.pitch(), out.region.w - out_x, skip_lower_bottom, skip_lower_top, skip_upper_bottom, skip_upper_top); diff --git a/Source/storm/storm.cpp b/Source/storm/storm.cpp index 37ad725b1..a70dadf8f 100644 --- a/Source/storm/storm.cpp +++ b/Source/storm/storm.cpp @@ -181,7 +181,7 @@ bool SBmpLoadImage(const char *pszFileName, SDL_Color *pPalette, BYTE *pBuffer, // // This is useful because in SDL the pitch size is often slightly larger // than image width for efficiency. - const int x_skip = dwBuffersize / height - width; + const int xSkip = dwBuffersize / height - width; if (pdwWidth) *pdwWidth = width; @@ -223,7 +223,7 @@ bool SBmpLoadImage(const char *pszFileName, SDL_Color *pPalette, BYTE *pBuffer, } } // Skip the pitch padding. - pBuffer += x_skip; + pBuffer += xSkip; } free(fileBuffer); diff --git a/Source/storm/storm_net.cpp b/Source/storm/storm_net.cpp index 98ff29407..31804b19c 100644 --- a/Source/storm/storm_net.cpp +++ b/Source/storm/storm_net.cpp @@ -149,20 +149,20 @@ int SNetInitializeProvider(Uint32 provider, struct GameData *gameData) /** * @brief Called by engine for single, called by ui for multi */ -bool SNetCreateGame(const char *pszGameName, const char *pszGamePassword, char *GameTemplateData, int GameTemplateSize, int *playerID) +bool SNetCreateGame(const char *pszGameName, const char *pszGamePassword, char *gameTemplateData, int gameTemplateSize, int *playerID) { #ifndef NONET std::lock_guard lg(storm_net_mutex); #endif - if (GameTemplateSize != sizeof(GameData)) + if (gameTemplateSize != sizeof(GameData)) ABORT(); - net::buffer_t game_init_info(GameTemplateData, GameTemplateData + GameTemplateSize); - dvlnet_inst->setup_gameinfo(std::move(game_init_info)); + net::buffer_t gameInitInfo(gameTemplateData, gameTemplateData + gameTemplateSize); + dvlnet_inst->setup_gameinfo(std::move(gameInitInfo)); - std::string default_name; + std::string defaultName; if (!pszGameName) { - default_name = dvlnet_inst->make_default_gamename(); - pszGameName = default_name.c_str(); + defaultName = dvlnet_inst->make_default_gamename(); + pszGameName = defaultName.c_str(); } strncpy(gpszGameName, pszGameName, sizeof(gpszGameName) - 1); diff --git a/Source/storm/storm_sdl_rw.cpp b/Source/storm/storm_sdl_rw.cpp index ec599cd85..6e56410de 100644 --- a/Source/storm/storm_sdl_rw.cpp +++ b/Source/storm/storm_sdl_rw.cpp @@ -8,25 +8,25 @@ namespace devilution { -static HANDLE SFileRw_GetHandle(struct SDL_RWops *context) +static HANDLE SFileRwGetHandle(struct SDL_RWops *context) { return (HANDLE)context->hidden.unknown.data1; } -static void SFileRw_SetHandle(struct SDL_RWops *context, HANDLE handle) +static void SFileRwSetHandle(struct SDL_RWops *context, HANDLE handle) { context->hidden.unknown.data1 = handle; } #ifndef USE_SDL1 -static Sint64 SFileRw_size(struct SDL_RWops *context) +static Sint64 SFileRwSize(struct SDL_RWops *context) { - return SFileGetFileSize(SFileRw_GetHandle(context), nullptr); + return SFileGetFileSize(SFileRwGetHandle(context), nullptr); } #endif #ifndef USE_SDL1 -static Sint64 SFileRw_seek(struct SDL_RWops *context, Sint64 offset, int whence) +static Sint64 SFileRwSeek(struct SDL_RWops *context, Sint64 offset, int whence) #else static int SFileRw_seek(struct SDL_RWops *context, int offset, int whence) #endif @@ -45,7 +45,7 @@ static int SFileRw_seek(struct SDL_RWops *context, int offset, int whence) default: return -1; } - const std::uint64_t pos = SFileSetFilePointer(SFileRw_GetHandle(context), offset, swhence); + const std::uint64_t pos = SFileSetFilePointer(SFileRwGetHandle(context), offset, swhence); if (pos == static_cast(-1)) { SDL_Log("SFileRw_seek error: %ud", (unsigned int)SErrGetLastError()); } @@ -53,22 +53,22 @@ static int SFileRw_seek(struct SDL_RWops *context, int offset, int whence) } #ifndef USE_SDL1 -static size_t SFileRw_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum) +static size_t SFileRwRead(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum) #else static int SFileRw_read(struct SDL_RWops *context, void *ptr, int size, int maxnum) #endif { - DWORD num_read = 0; - if (!SFileReadFile(SFileRw_GetHandle(context), ptr, maxnum * size, &num_read, nullptr)) { - const DWORD err_code = SErrGetLastError(); - if (err_code != STORM_ERROR_HANDLE_EOF) { - SDL_Log("SFileRw_read error: %u %u ERROR CODE %u", (unsigned int)size, (unsigned int)maxnum, (unsigned int)err_code); + DWORD numRead = 0; + if (!SFileReadFile(SFileRwGetHandle(context), ptr, maxnum * size, &numRead, nullptr)) { + const DWORD errCode = SErrGetLastError(); + if (errCode != STORM_ERROR_HANDLE_EOF) { + SDL_Log("SFileRw_read error: %u %u ERROR CODE %u", (unsigned int)size, (unsigned int)maxnum, (unsigned int)errCode); } } - return num_read / size; + return numRead / size; } -static int SFileRw_close(struct SDL_RWops *context) +static int SFileRwClose(struct SDL_RWops *context) { mem_free_dbg(context); return 0; @@ -80,17 +80,17 @@ SDL_RWops *SFileRw_FromStormHandle(HANDLE handle) std::memset(result, 0, sizeof(*result)); #ifndef USE_SDL1 - result->size = &SFileRw_size; + result->size = &SFileRwSize; result->type = SDL_RWOPS_UNKNOWN; #else result->type = 0; #endif - result->seek = &SFileRw_seek; - result->read = &SFileRw_read; + result->seek = &SFileRwSeek; + result->read = &SFileRwRead; result->write = nullptr; - result->close = &SFileRw_close; - SFileRw_SetHandle(result, handle); + result->close = &SFileRwClose; + SFileRwSetHandle(result, handle); return result; } diff --git a/Source/storm/storm_svid.cpp b/Source/storm/storm_svid.cpp index c5bf612cb..7f6108507 100644 --- a/Source/storm/storm_svid.cpp +++ b/Source/storm/storm_svid.cpp @@ -34,9 +34,9 @@ SDL_Palette *SVidPalette; SDL_Surface *SVidSurface; BYTE *SVidBuffer; -bool IsLandscapeFit(unsigned long src_w, unsigned long src_h, unsigned long dst_w, unsigned long dst_h) +bool IsLandscapeFit(unsigned long srcW, unsigned long srcH, unsigned long dstW, unsigned long dstH) { - return src_w * dst_h > dst_w * src_h; + return srcW * dstH > dstW * srcH; } #ifdef USE_SDL1 @@ -353,19 +353,19 @@ bool SVidPlayContinue() { if (smk_palette_updated(SVidSMK)) { SDL_Color colors[256]; - const unsigned char *palette_data = smk_get_palette(SVidSMK); + const unsigned char *paletteData = smk_get_palette(SVidSMK); for (int i = 0; i < 256; i++) { - colors[i].r = palette_data[i * 3 + 0]; - colors[i].g = palette_data[i * 3 + 1]; - colors[i].b = palette_data[i * 3 + 2]; + colors[i].r = paletteData[i * 3 + 0]; + colors[i].g = paletteData[i * 3 + 1]; + colors[i].b = paletteData[i * 3 + 2]; #ifndef USE_SDL1 colors[i].a = SDL_ALPHA_OPAQUE; #endif - orig_palette[i].r = palette_data[i * 3 + 0]; - orig_palette[i].g = palette_data[i * 3 + 1]; - orig_palette[i].b = palette_data[i * 3 + 2]; + orig_palette[i].r = paletteData[i * 3 + 0]; + orig_palette[i].g = paletteData[i * 3 + 1]; + orig_palette[i].b = paletteData[i * 3 + 2]; } memcpy(logical_palette, orig_palette, sizeof(logical_palette)); @@ -406,32 +406,32 @@ bool SVidPlayContinue() } else #endif { - SDL_Surface *output_surface = GetOutputSurface(); + SDL_Surface *outputSurface = GetOutputSurface(); #ifdef USE_SDL1 const bool is_indexed_output_format = SDLBackport_IsPixelFormatIndexed(output_surface->format); #else - const Uint32 wnd_format = SDL_GetWindowPixelFormat(ghMainWnd); - const bool is_indexed_output_format = SDL_ISPIXELFORMAT_INDEXED(wnd_format); + const Uint32 wndFormat = SDL_GetWindowPixelFormat(ghMainWnd); + const bool isIndexedOutputFormat = SDL_ISPIXELFORMAT_INDEXED(wndFormat); #endif - SDL_Rect output_rect; - if (is_indexed_output_format) { + SDL_Rect outputRect; + if (isIndexedOutputFormat) { // Cannot scale if the output format is indexed (8-bit palette). - output_rect.w = static_cast(SVidWidth); - output_rect.h = static_cast(SVidHeight); - } else if (IsLandscapeFit(SVidWidth, SVidHeight, output_surface->w, output_surface->h)) { - output_rect.w = output_surface->w; - output_rect.h = SVidHeight * output_surface->w / SVidWidth; + outputRect.w = static_cast(SVidWidth); + outputRect.h = static_cast(SVidHeight); + } else if (IsLandscapeFit(SVidWidth, SVidHeight, outputSurface->w, outputSurface->h)) { + outputRect.w = outputSurface->w; + outputRect.h = SVidHeight * outputSurface->w / SVidWidth; } else { - output_rect.w = SVidWidth * output_surface->h / SVidHeight; - output_rect.h = output_surface->h; + outputRect.w = SVidWidth * outputSurface->h / SVidHeight; + outputRect.h = outputSurface->h; } - output_rect.x = (output_surface->w - output_rect.w) / 2; - output_rect.y = (output_surface->h - output_rect.h) / 2; + outputRect.x = (outputSurface->w - outputRect.w) / 2; + outputRect.y = (outputSurface->h - outputRect.h) / 2; - if (is_indexed_output_format - || output_surface->w == static_cast(SVidWidth) - || output_surface->h == static_cast(SVidHeight)) { - if (SDL_BlitSurface(SVidSurface, nullptr, output_surface, &output_rect) <= -1) { + if (isIndexedOutputFormat + || outputSurface->w == static_cast(SVidWidth) + || outputSurface->h == static_cast(SVidHeight)) { + if (SDL_BlitSurface(SVidSurface, nullptr, outputSurface, &outputRect) <= -1) { ErrSdl(); } } else { @@ -440,9 +440,9 @@ bool SVidPlayContinue() #ifdef USE_SDL1 SDLSurfaceUniquePtr converted { SDL_ConvertSurface(SVidSurface, ghMainWnd->format, 0) }; #else - SDLSurfaceUniquePtr converted { SDL_ConvertSurfaceFormat(SVidSurface, wnd_format, 0) }; + SDLSurfaceUniquePtr converted { SDL_ConvertSurfaceFormat(SVidSurface, wndFormat, 0) }; #endif - if (SDL_BlitScaled(converted.get(), nullptr, output_surface, &output_rect) <= -1) { + if (SDL_BlitScaled(converted.get(), nullptr, outputSurface, &outputRect) <= -1) { SDL_Log("%s", SDL_GetError()); return false; } diff --git a/Source/utils/file_util.cpp b/Source/utils/file_util.cpp index 419b43d07..697ced622 100644 --- a/Source/utils/file_util.cpp +++ b/Source/utils/file_util.cpp @@ -56,10 +56,10 @@ bool GetFileSize(const char *path, std::uintmax_t *size) *size = (attr.nFileSizeHigh) << (sizeof(attr.nFileSizeHigh) * 8) | attr.nFileSizeLow; return true; #else - struct ::stat stat_result; - if (::stat(path, &stat_result) == -1) + struct ::stat statResult; + if (::stat(path, &statResult) == -1) return false; - *size = static_cast(stat_result.st_size); + *size = static_cast(statResult.st_size); return true; #endif } diff --git a/Source/utils/thread.cpp b/Source/utils/thread.cpp index e7c9ac540..e52ef125d 100644 --- a/Source/utils/thread.cpp +++ b/Source/utils/thread.cpp @@ -8,24 +8,24 @@ namespace devilution { -static int SDLCALL thread_translate(void *ptr) +static int SDLCALL ThreadTranslate(void *ptr) { auto handler = (unsigned int (*)(void *))ptr; return handler(nullptr); } -SDL_Thread *CreateThread(unsigned int (*handler)(void *), SDL_threadID *ThreadID) +SDL_Thread *CreateThread(unsigned int (*handler)(void *), SDL_threadID *threadId) { #ifdef USE_SDL1 SDL_Thread *ret = SDL_CreateThread(thread_translate, (void *)handler); #else - SDL_Thread *ret = SDL_CreateThread(thread_translate, nullptr, (void *)handler); + SDL_Thread *ret = SDL_CreateThread(ThreadTranslate, nullptr, (void *)handler); #endif if (ret == nullptr) { ErrSdl(); } - *ThreadID = SDL_GetThreadID(ret); + *threadId = SDL_GetThreadID(ret); return ret; }