From ac26f3a23b3337cd5d5c391fa5b38560ecced4b2 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Tue, 11 Oct 2022 10:57:07 +0900 Subject: [PATCH] Item: Optimize to save 16 bytes (312->288) --- Source/itemdat.h | 2 +- Source/items.h | 16 ++++++++-------- Source/pack.cpp | 2 +- Source/pack.h | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/itemdat.h b/Source/itemdat.h index 49ef15a47..ce3124926 100644 --- a/Source/itemdat.h +++ b/Source/itemdat.h @@ -355,7 +355,7 @@ enum class ItemSpecialEffect : uint32_t { }; use_enum_as_flags(ItemSpecialEffect); -enum class ItemSpecialEffectHf : uint32_t { +enum class ItemSpecialEffectHf : uint8_t { // clang-format off None = 0, Devastation = 1 << 0, diff --git a/Source/items.h b/Source/items.h index dacd69b3d..a8681a98a 100644 --- a/Source/items.h +++ b/Source/items.h @@ -179,9 +179,9 @@ struct Item { /** Randomly generated identifier */ int32_t _iSeed = 0; uint16_t _iCreateInfo = 0; - enum ItemType _itype = ItemType::None; - Point position = { 0, 0 }; + ItemType _itype = ItemType::None; bool _iAnimFlag = false; + Point position = { 0, 0 }; /* * @brief Contains Information for current Animation */ @@ -193,8 +193,8 @@ struct Item { item_quality _iMagical = ITEM_QUALITY_NORMAL; char _iName[64] = {}; char _iIName[64] = {}; - enum item_equip_type _iLoc = ILOC_NONE; - enum item_class _iClass = ICLASS_NONE; + item_equip_type _iLoc = ILOC_NONE; + item_class _iClass = ICLASS_NONE; uint8_t _iCurs = 0; int _ivalue = 0; int _iIvalue = 0; @@ -202,8 +202,9 @@ struct Item { uint8_t _iMaxDam = 0; int16_t _iAC = 0; ItemSpecialEffect _iFlags = ItemSpecialEffect::None; - enum item_misc_id _iMiscId = IMISC_NONE; - enum spell_id _iSpell = SPL_NULL; + item_misc_id _iMiscId = IMISC_NONE; + spell_id _iSpell = SPL_NULL; + _item_indexes IDidx = IDI_NONE; int _iCharges = 0; int _iMaxCharges = 0; int _iDurability = 0; @@ -242,9 +243,8 @@ struct Item { uint8_t _iMinMag = 0; int8_t _iMinDex = 0; bool _iStatFlag = false; - _item_indexes IDidx = IDI_NONE; - uint32_t dwBuff = 0; ItemSpecialEffectHf _iDamAcFlags = ItemSpecialEffectHf::None; + uint32_t dwBuff = 0; /** * @brief Clears this item and returns the old value diff --git a/Source/pack.cpp b/Source/pack.cpp index 418df808b..41418a79b 100644 --- a/Source/pack.cpp +++ b/Source/pack.cpp @@ -132,7 +132,7 @@ void PackPlayer(PlayerPack *pPack, const Player &player, bool manashield, bool n pPack->wReflections = SDL_SwapLE16(player.wReflections); pPack->pDifficulty = SDL_SwapLE32(player.pDifficulty); - pPack->pDamAcFlags = static_cast(SDL_SwapLE32(static_cast(player.pDamAcFlags))); + pPack->pDamAcFlags = SDL_SwapLE32(static_cast(player.pDamAcFlags)); pPack->pDiabloKillLevel = SDL_SwapLE32(player.pDiabloKillLevel); pPack->bIsHellfire = gbIsHellfire ? 1 : 0; diff --git a/Source/pack.h b/Source/pack.h index 33f51f13e..89b8f2de5 100644 --- a/Source/pack.h +++ b/Source/pack.h @@ -74,7 +74,7 @@ struct PlayerPack { int16_t wReserved8; // For future use uint32_t pDiabloKillLevel; uint32_t pDifficulty; - ItemSpecialEffectHf pDamAcFlags; + uint32_t pDamAcFlags; // `ItemSpecialEffectHf` is 1 byte but this is 4 bytes. /**@brief Only used in multiplayer sync (SendPlayerInfo/recv_plrinfo). Never used in save games (single- or multiplayer). */ uint8_t friendlyMode; /**@brief Only used in multiplayer sync (SendPlayerInfo/recv_plrinfo). Never used in save games (single- or multiplayer). */