Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Core/Misc: PackedGuid refactoring to remove ByteBuffer.h include from…
Browse files Browse the repository at this point in the history
… ObjectGuid
  • Loading branch information
Shauren authored and Ovahlord committed Dec 4, 2023
1 parent b4f6bee commit bf51eda
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/server/game/Entities/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 18 additions & 2 deletions src/server/game/Entities/Object/ObjectGuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "ObjectGuid.h"
#include "Errors.h"
#include "Hash.h"
#include "ByteBuffer.h"
#include "Log.h"
#include "World.h"
#include <iomanip>
Expand Down Expand Up @@ -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());
Expand All @@ -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;
}

Expand Down
17 changes: 9 additions & 8 deletions src/server/game/Entities/Object/ObjectGuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
#define ObjectGuid_h__

#include "Define.h"
#include "ByteBuffer.h"
#include <array>
#include <deque>
#include <functional>
#include <list>
#include <set>
#include <string>
#include <type_traits>
#include <unordered_set>
#include <vector>
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<uint8, PACKED_GUID_MIN_BUFFER_SIZE> _packedGuid;
};

class TC_GAME_API ObjectGuidGeneratorBase
Expand Down

0 comments on commit bf51eda

Please sign in to comment.