aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2023-12-03 22:34:40 +0100
committerShauren <shauren.trinity@gmail.com>2023-12-03 22:34:40 +0100
commit1af040223973010e60a419c76002f096a5bc5f6e (patch)
tree11da35ca101f23122e1e97529bde664e979ab142
parente688424a260887fd97657aa1a445f855e94db990 (diff)
Core/Misc: PackedGuid refactoring to remove ByteBuffer.h include from ObjectGuid
-rw-r--r--src/server/game/Entities/Object/Object.cpp2
-rw-r--r--src/server/game/Entities/Object/ObjectGuid.cpp20
-rw-r--r--src/server/game/Entities/Object/ObjectGuid.h17
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 3fa2ebf40c0..416df2cce7b 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -61,7 +61,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 ba0a75f2db2..9a8bd07fe76 100644
--- a/src/server/game/Entities/Object/ObjectGuid.cpp
+++ b/src/server/game/Entities/Object/ObjectGuid.cpp
@@ -16,7 +16,7 @@
*/
#include "ObjectGuid.h"
-#include "Hash.h"
+#include "ByteBuffer.h"
#include "Log.h"
#include "World.h"
#include <sstream>
@@ -67,6 +67,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());
@@ -81,7 +97,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 965040adee7..cc720effc9e 100644
--- a/src/server/game/Entities/Object/ObjectGuid.h
+++ b/src/server/game/Entities/Object/ObjectGuid.h
@@ -18,12 +18,13 @@
#ifndef ObjectGuid_h__
#define ObjectGuid_h__
-#include "ByteBuffer.h"
#include "Define.h"
+#include <array>
#include <functional>
#include <list>
#include <memory>
#include <set>
+#include <string>
#include <type_traits>
#include <vector>
#include <unordered_set>
@@ -106,6 +107,7 @@ GUID_TRAIT_MAP_SPECIFIC(HighGuid::GameObject)
GUID_TRAIT_MAP_SPECIFIC(HighGuid::DynamicObject)
GUID_TRAIT_MAP_SPECIFIC(HighGuid::Corpse)
+class ByteBuffer;
class ObjectGuid;
class PackedGuid;
@@ -265,17 +267,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<uint8, PACKED_GUID_MIN_BUFFER_SIZE> _packedGuid;
};
class TC_GAME_API ObjectGuidGenerator