From 4cf0053eceeefbd9050b00b4d0462e767ea3d1f8 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Thu, 11 Aug 2022 00:20:09 +0100 Subject: [PATCH] Set underlying type for all the enums Reduces rg99 binary size by 3 KiB. --- Source/DiabloUI/settingsmenu.cpp | 4 ++-- Source/DiabloUI/ui_flags.hpp | 4 +++- Source/DiabloUI/ui_item.h | 2 +- Source/control.cpp | 2 +- Source/controls/touch/renderers.h | 4 ++-- Source/diablo.h | 4 ++-- Source/effects.h | 2 +- Source/engine/actor_position.cpp | 2 +- Source/engine/demomode.cpp | 2 +- Source/engine/render/automap_render.cpp | 4 ++-- Source/engine/render/dun_render.cpp | 6 +++--- Source/engine/render/text_render.hpp | 2 +- Source/hwcursor.cpp | 2 +- Source/hwcursor.hpp | 2 +- Source/itemdat.h | 4 ++-- Source/misdat.h | 4 ++-- Source/missiles.h | 4 ++-- Source/monstdat.h | 2 +- Source/monster.h | 2 +- Source/options.h | 14 +++++++------- Source/panels/ui_panels.hpp | 2 +- Source/pfile.h | 2 +- Source/platform/switch/docking.cpp | 2 +- Source/platform/vita/touch.cpp | 2 +- 24 files changed, 41 insertions(+), 39 deletions(-) diff --git a/Source/DiabloUI/settingsmenu.cpp b/Source/DiabloUI/settingsmenu.cpp index c47303b27..5fb7af90f 100644 --- a/Source/DiabloUI/settingsmenu.cpp +++ b/Source/DiabloUI/settingsmenu.cpp @@ -24,7 +24,7 @@ std::vector> vecDialog; std::vector vecOptions; OptionEntryBase *selectedOption = nullptr; -enum class ShownMenuType { +enum class ShownMenuType : uint8_t { Settings, ListOption, KeyInput, @@ -37,7 +37,7 @@ char optionDescription[512]; Rectangle rectList; Rectangle rectDescription; -enum class SpecialMenuEntry { +enum class SpecialMenuEntry : int8_t { None = -1, PreviousMenu = -2, UnbindKey = -3, diff --git a/Source/DiabloUI/ui_flags.hpp b/Source/DiabloUI/ui_flags.hpp index 69c49fb04..1d4530ec9 100644 --- a/Source/DiabloUI/ui_flags.hpp +++ b/Source/DiabloUI/ui_flags.hpp @@ -1,10 +1,12 @@ #pragma once +#include + #include "utils/enum_traits.h" namespace devilution { -enum class UiFlags { +enum class UiFlags : uint32_t { // clang-format off None = 0, diff --git a/Source/DiabloUI/ui_item.h b/Source/DiabloUI/ui_item.h index 771209161..e762a334b 100644 --- a/Source/DiabloUI/ui_item.h +++ b/Source/DiabloUI/ui_item.h @@ -13,7 +13,7 @@ namespace devilution { -enum class UiType { +enum class UiType : uint8_t { Text, ArtText, ArtTextButton, diff --git a/Source/control.cpp b/Source/control.cpp index adf48b57a..2a1527c08 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -151,7 +151,7 @@ int sgbPlrTalkTbl; bool WhisperList[MAX_PLRS]; char panelstr[4][64]; -enum panel_button_id { +enum panel_button_id : uint8_t { PanelButtonCharinfo, PanelButtonQlog, PanelButtonAutomap, diff --git a/Source/controls/touch/renderers.h b/Source/controls/touch/renderers.h index 2e6100563..68e664cbf 100644 --- a/Source/controls/touch/renderers.h +++ b/Source/controls/touch/renderers.h @@ -11,7 +11,7 @@ namespace devilution { -enum VirtualGamepadButtonType { +enum VirtualGamepadButtonType : uint8_t { GAMEPAD_ATTACK, GAMEPAD_ATTACKDOWN, GAMEPAD_TALK, @@ -40,7 +40,7 @@ enum VirtualGamepadButtonType { GAMEPAD_POTIONDOWN, }; -enum VirtualGamepadPotionType { +enum VirtualGamepadPotionType : uint8_t { GAMEPAD_HEALING, GAMEPAD_MANA, GAMEPAD_REJUVENATION, diff --git a/Source/diablo.h b/Source/diablo.h index bb163c5d2..517271ef9 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -34,7 +34,7 @@ enum clicktype : int8_t { /** * @brief Specifices what game logic step is currently executed */ -enum class GameLogicStep { +enum class GameLogicStep : uint8_t { None, ProcessPlayers, ProcessMonsters, @@ -46,7 +46,7 @@ enum class GameLogicStep { ProcessMissilesTown, }; -enum class MouseActionType : int { +enum class MouseActionType : uint8_t { None, Walk, Spell, diff --git a/Source/effects.h b/Source/effects.h index d3d25a411..c4ebd6d9e 100644 --- a/Source/effects.h +++ b/Source/effects.h @@ -13,7 +13,7 @@ namespace devilution { -enum class HeroSpeech { +enum class HeroSpeech : uint8_t { ChamberOfBoneLore, HorazonsSanctumLore, GolemSpellLore, diff --git a/Source/engine/actor_position.cpp b/Source/engine/actor_position.cpp index 59fb141db..78d7c0cdd 100644 --- a/Source/engine/actor_position.cpp +++ b/Source/engine/actor_position.cpp @@ -6,7 +6,7 @@ namespace devilution { namespace { -enum class VelocityToUse { +enum class VelocityToUse : uint8_t { None, Full, NegativeFull, diff --git a/Source/engine/demomode.cpp b/Source/engine/demomode.cpp index 3d3b9e503..30278db1f 100644 --- a/Source/engine/demomode.cpp +++ b/Source/engine/demomode.cpp @@ -19,7 +19,7 @@ namespace devilution { namespace { -enum class DemoMsgType { +enum class DemoMsgType : uint8_t { GameTick = 0, Rendering = 1, Message = 2, diff --git a/Source/engine/render/automap_render.cpp b/Source/engine/render/automap_render.cpp index 7942e65c1..4c959ec9f 100644 --- a/Source/engine/render/automap_render.cpp +++ b/Source/engine/render/automap_render.cpp @@ -8,12 +8,12 @@ namespace devilution { namespace { -enum class DirectionX { +enum class DirectionX : int8_t { EAST = 1, WEST = -1, }; -enum class DirectionY { +enum class DirectionY : int8_t { SOUTH = 1, NORTH = -1, }; diff --git a/Source/engine/render/dun_render.cpp b/Source/engine/render/dun_render.cpp index 11572d395..00df34ffe 100644 --- a/Source/engine/render/dun_render.cpp +++ b/Source/engine/render/dun_render.cpp @@ -28,7 +28,7 @@ namespace { * Each tile type has its own encoding but they all encode data in the order * of bottom-to-top (bottom row first). */ -enum class TileType { +enum class TileType : uint8_t { /** * 🮆 A 32x32 square. Stored as an array of pixels. */ @@ -348,12 +348,12 @@ const std::uint32_t LeftFoliageMask[TILE_HEIGHT] = { 0x00000000, }; -enum class TransparencyType { +enum class TransparencyType : uint8_t { Solid, Blended, }; -enum class LightType { +enum class LightType : uint8_t { FullyDark, PartiallyLit, FullyLit, diff --git a/Source/engine/render/text_render.hpp b/Source/engine/render/text_render.hpp index 309ce34a8..a69a10ff3 100644 --- a/Source/engine/render/text_render.hpp +++ b/Source/engine/render/text_render.hpp @@ -56,7 +56,7 @@ enum text_color : uint8_t { */ class DrawStringFormatArg { public: - enum class Type { + enum class Type : uint8_t { StringView, Int }; diff --git a/Source/hwcursor.cpp b/Source/hwcursor.cpp index da2269e23..f484f07f7 100644 --- a/Source/hwcursor.cpp +++ b/Source/hwcursor.cpp @@ -27,7 +27,7 @@ CursorInfo CurrentCursorInfo; #if SDL_VERSION_ATLEAST(2, 0, 0) SDLCursorUniquePtr CurrentCursor; -enum class HotpointPosition { +enum class HotpointPosition : uint8_t { TopLeft, Center, }; diff --git a/Source/hwcursor.hpp b/Source/hwcursor.hpp index 460105d14..9a3c747db 100644 --- a/Source/hwcursor.hpp +++ b/Source/hwcursor.hpp @@ -31,7 +31,7 @@ inline bool SetHardwareCursorVisible(bool visible) #endif } -enum class CursorType { +enum class CursorType : uint8_t { Unknown, UserInterface, Game, diff --git a/Source/itemdat.h b/Source/itemdat.h index 5c6d95528..49ef15a47 100644 --- a/Source/itemdat.h +++ b/Source/itemdat.h @@ -322,7 +322,7 @@ enum unique_base_item : int8_t { UITYPE_INVALID = -1, }; -enum class ItemSpecialEffect { +enum class ItemSpecialEffect : uint32_t { // clang-format off None = 0, RandomStealLife = 1 << 1, @@ -350,7 +350,7 @@ enum class ItemSpecialEffect { NoMana = 1 << 27, HalfTrapDamage = 1 << 28, TripleDemonDamage = 1 << 30, - ZeroResistance = 1 << 31, + ZeroResistance = 1U << 31, // clang-format on }; use_enum_as_flags(ItemSpecialEffect); diff --git a/Source/misdat.h b/Source/misdat.h index 370dee68c..fd124fe78 100644 --- a/Source/misdat.h +++ b/Source/misdat.h @@ -96,7 +96,7 @@ typedef enum missile_graphic_id : uint8_t { /** * @brief Specifies what if and how movement distribution is applied */ -enum class MissileMovementDistrubution { +enum class MissileMovementDistrubution : uint8_t { /** * @brief No movement distribution is calculated. Normally this means the missile doesn't move at all. */ @@ -127,7 +127,7 @@ struct MissileData { MissileMovementDistrubution MovementDistribution; }; -enum class MissileDataFlags { +enum class MissileDataFlags : uint8_t { // clang-format off None = 0, MonsterOwned = 1 << 0, diff --git a/Source/missiles.h b/Source/missiles.h index cd4ace836..517a40e6e 100644 --- a/Source/missiles.h +++ b/Source/missiles.h @@ -66,7 +66,7 @@ struct MissilePosition { * | * N NNE NE ENE E */ -enum class Direction16 { +enum class Direction16 : uint8_t { South, South_SouthWest, SouthWest, @@ -85,7 +85,7 @@ enum class Direction16 { South_SouthEast, }; -enum class MissileSource { +enum class MissileSource : uint8_t { Player, Monster, Trap, diff --git a/Source/monstdat.h b/Source/monstdat.h index 48641807d..1114fb106 100644 --- a/Source/monstdat.h +++ b/Source/monstdat.h @@ -277,7 +277,7 @@ enum _monster_id : int16_t { /** * @brief Defines if and how a group of monsters should be spawned with the unique monster */ -enum class UniqueMonsterPack { +enum class UniqueMonsterPack : uint8_t { /** * @brief Don't spawn a group of monsters with the unique monster */ diff --git a/Source/monster.h b/Source/monster.h index 7d9cde6e3..cbc47f007 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -153,7 +153,7 @@ struct AnimStruct { int8_t rate; }; -enum class MonsterSound { +enum class MonsterSound : uint8_t { Attack, Hit, Death, diff --git a/Source/options.h b/Source/options.h index fa8eb6689..7812b2703 100644 --- a/Source/options.h +++ b/Source/options.h @@ -15,21 +15,21 @@ namespace devilution { -enum class StartUpGameMode { +enum class StartUpGameMode : uint8_t { /** @brief If hellfire is present, asks the user what game they want to start. */ Ask = 0, Hellfire = 1, Diablo = 2, }; -enum class StartUpIntro { +enum class StartUpIntro : uint8_t { Off = 0, Once = 1, On = 2, }; /** @brief Defines what splash screen should be shown at startup. */ -enum class StartUpSplash { +enum class StartUpSplash : uint8_t { /** @brief Show no splash screen. */ None = 0, /** @brief Show only TitleDialog. */ @@ -38,13 +38,13 @@ enum class StartUpSplash { LogoAndTitleDialog = 2, }; -enum class ScalingQuality { +enum class ScalingQuality : uint8_t { NearestPixel, BilinearFiltering, AnisotropicFiltering, }; -enum class Resampler { +enum class Resampler : uint8_t { #ifdef DEVILUTIONX_RESAMPLER_SPEEX Speex = 0, #endif @@ -56,13 +56,13 @@ enum class Resampler { string_view ResamplerToString(Resampler resampler); std::optional ResamplerFromString(string_view resampler); -enum class OptionEntryType { +enum class OptionEntryType : uint8_t { Boolean, List, Key, }; -enum class OptionEntryFlags { +enum class OptionEntryFlags : uint8_t { /** @brief No special logic. */ None = 0, /** @brief Shouldn't be shown in settings dialog. */ diff --git a/Source/panels/ui_panels.hpp b/Source/panels/ui_panels.hpp index 8309cbbef..13e9b1538 100644 --- a/Source/panels/ui_panels.hpp +++ b/Source/panels/ui_panels.hpp @@ -2,7 +2,7 @@ namespace devilution { -enum class UiPanels { +enum class UiPanels : uint8_t { Main, Quest, Character, diff --git a/Source/pfile.h b/Source/pfile.h index 3168128c7..d02af3f7c 100644 --- a/Source/pfile.h +++ b/Source/pfile.h @@ -18,7 +18,7 @@ extern bool gbValidSaveFile; * @brief Comparsion result of pfile_compare_hero_demo */ struct HeroCompareResult { - enum Status { + enum Status : uint8_t { ReferenceNotFound, Same, Difference, diff --git a/Source/platform/switch/docking.cpp b/Source/platform/switch/docking.cpp index 5f1682046..f4a02a045 100644 --- a/Source/platform/switch/docking.cpp +++ b/Source/platform/switch/docking.cpp @@ -7,7 +7,7 @@ namespace devilution { namespace { -enum class OperationMode { +enum class OperationMode : int8_t { Handheld, Docked, Uninitialized = -1 diff --git a/Source/platform/vita/touch.cpp b/Source/platform/vita/touch.cpp index 073c60b65..b53c6b9b2 100644 --- a/Source/platform/vita/touch.cpp +++ b/Source/platform/vita/touch.cpp @@ -64,7 +64,7 @@ struct Touch { Touch finger[TOUCH_PORT_MAX_NUM][MaxNumFingers]; // keep track of finger status -enum DraggingType { +enum DraggingType : uint8_t { DragNone, DragTwoFinger, DragThreeFinger,