From bf51eda5502ebf1e65b40479cea82ab13b717a42 Mon Sep 17 00:00:00 2001 From: Shauren Date: Mon, 4 Dec 2023 22:14:02 +0100 Subject: [PATCH] Core/Misc: PackedGuid refactoring to remove ByteBuffer.h include from ObjectGuid --- src/server/game/Entities/Object/Object.cpp | 2 +- .../game/Entities/Object/ObjectGuid.cpp | 20 +++++++++++++++++-- src/server/game/Entities/Object/ObjectGuid.h | 17 ++++++++-------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 2d1e0618703..9dbc980b318 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -70,7 +70,7 @@ constexpr float VisibilityDistances[AsUnderlyingType(VisibilityDistanceType::Max MAX_VISIBILITY_DISTANCE }; -Object::Object() : m_PackGUID(sizeof(uint64)+1) +Object::Object() { m_objectTypeId = TYPEID_OBJECT; m_objectType = TYPEMASK_OBJECT; diff --git a/src/server/game/Entities/Object/ObjectGuid.cpp b/src/server/game/Entities/Object/ObjectGuid.cpp index c4520bda129..13188c18b17 100644 --- a/src/server/game/Entities/Object/ObjectGuid.cpp +++ b/src/server/game/Entities/Object/ObjectGuid.cpp @@ -17,7 +17,7 @@ #include "ObjectGuid.h" #include "Errors.h" -#include "Hash.h" +#include "ByteBuffer.h" #include "Log.h" #include "World.h" #include @@ -83,6 +83,22 @@ ObjectGuid ObjectGuid::MapSpecific(HighGuid type, uint32 entry, LowType counter) return ObjectGuid(type, entry, counter); } +void PackedGuid::Set(ObjectGuid guid) +{ + _packedSize = 1; + uint64 raw = guid.GetRawValue(); + for (uint8 i = 0; i < 8; ++i) + { + uint8 byte = (raw >> (i * 8)) & 0xFF; + _packedGuid[_packedSize] = byte; + if (byte) + { + _packedGuid[0] |= uint8(1 << i); + ++_packedSize; + } + } +} + ByteBuffer& operator<<(ByteBuffer& buf, ObjectGuid const& guid) { buf << uint64(guid.GetRawValue()); @@ -97,7 +113,7 @@ ByteBuffer& operator>>(ByteBuffer& buf, ObjectGuid& guid) ByteBuffer& operator<<(ByteBuffer& buf, PackedGuid const& guid) { - buf.append(guid._packedGuid); + buf.append(guid._packedGuid.data(), guid._packedSize); return buf; } diff --git a/src/server/game/Entities/Object/ObjectGuid.h b/src/server/game/Entities/Object/ObjectGuid.h index a330622f97f..a966a6a4184 100644 --- a/src/server/game/Entities/Object/ObjectGuid.h +++ b/src/server/game/Entities/Object/ObjectGuid.h @@ -19,11 +19,12 @@ #define ObjectGuid_h__ #include "Define.h" -#include "ByteBuffer.h" +#include #include #include #include #include +#include #include #include #include @@ -118,6 +119,7 @@ GUID_TRAIT_MAP_SPECIFIC(HighGuid::AreaTrigger); #undef GUID_TRAIT_REALM_SPECIFIC #undef GUID_TRAIT_MAP_SPECIFIC +class ByteBuffer; class ObjectGuid; class PackedGuid; @@ -291,17 +293,16 @@ class TC_GAME_API PackedGuid friend TC_GAME_API ByteBuffer& operator<<(ByteBuffer& buf, PackedGuid const& guid); public: - explicit PackedGuid() : _packedGuid(PACKED_GUID_MIN_BUFFER_SIZE) { _packedGuid.appendPackGUID(0); } - explicit PackedGuid(uint64 guid) : _packedGuid(PACKED_GUID_MIN_BUFFER_SIZE) { _packedGuid.appendPackGUID(guid); } - explicit PackedGuid(ObjectGuid guid) : _packedGuid(PACKED_GUID_MIN_BUFFER_SIZE) { _packedGuid.appendPackGUID(guid.GetRawValue()); } + explicit PackedGuid() : _packedSize(1), _packedGuid() { } + explicit PackedGuid(ObjectGuid guid) { Set(guid); } - void Set(uint64 guid) { _packedGuid.wpos(0); _packedGuid.appendPackGUID(guid); } - void Set(ObjectGuid guid) { _packedGuid.wpos(0); _packedGuid.appendPackGUID(guid.GetRawValue()); } + void Set(ObjectGuid guid); - std::size_t size() const { return _packedGuid.size(); } + std::size_t size() const { return _packedSize; } private: - ByteBuffer _packedGuid; + uint8 _packedSize; + std::array _packedGuid; }; class TC_GAME_API ObjectGuidGeneratorBase