aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities/Object
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2014-10-23 17:01:26 +0200
committerShauren <shauren.trinity@gmail.com>2014-10-23 17:01:26 +0200
commit08c56eb1109aed2c6dabe728c945d4afd4943753 (patch)
tree27c73ebb9fcf30c3a7fd08fef6d58a6f4a585190 /src/server/game/Entities/Object
parentff781978a56b33567d704a860a94e5e28a53aee4 (diff)
Core/Entities: First step to 128 bit guids
* Database fields storing full guid have been converted to BINARY(16)
Diffstat (limited to 'src/server/game/Entities/Object')
-rw-r--r--src/server/game/Entities/Object/ObjectGuid.cpp49
-rw-r--r--src/server/game/Entities/Object/ObjectGuid.h86
2 files changed, 97 insertions, 38 deletions
diff --git a/src/server/game/Entities/Object/ObjectGuid.cpp b/src/server/game/Entities/Object/ObjectGuid.cpp
index 81442ac37ad..9f40b914c58 100644
--- a/src/server/game/Entities/Object/ObjectGuid.cpp
+++ b/src/server/game/Entities/Object/ObjectGuid.cpp
@@ -51,7 +51,7 @@ char const* ObjectGuid::GetTypeName(HighGuid high)
std::string ObjectGuid::ToString() const
{
std::ostringstream str;
- str << "GUID Full: 0x" << std::hex << std::setw(16) << std::setfill('0') << _guid << std::dec;
+ str << "GUID Full: 0x" << std::hex << std::setw(16) << std::setfill('0') << _low << std::dec;
str << " Type: " << GetTypeName();
if (HasEntry())
str << (IsPet() ? " Pet number: " : " Entry: ") << GetEntry() << " ";
@@ -60,6 +60,36 @@ std::string ObjectGuid::ToString() const
return str.str();
}
+std::vector<uint8> ObjectGuid::GetRawValue() const
+{
+ std::vector<uint8> raw(16);
+ memcpy(raw.data(), this, sizeof(*this));
+ return raw;
+}
+
+void ObjectGuid::SetRawValue(std::vector<uint8> const& guid)
+{
+ ASSERT(guid.size() == sizeof(*this));
+ memcpy(this, guid.data(), sizeof(*this));
+}
+
+void PackedGuid::Set(ObjectGuid guid)
+{
+ uint8 lowMask = 0;
+ uint8 highMask = 0;
+ _packedGuid << uint8(lowMask);
+ _packedGuid << uint8(highMask);
+
+ uint8 packed[8];
+ if (size_t packedSize = _packedGuid.PackUInt64(guid._low, &lowMask, packed))
+ _packedGuid.append(packed, packedSize);
+ if (size_t packedSize = _packedGuid.PackUInt64(guid._high, &highMask, packed))
+ _packedGuid.append(packed, packedSize);
+
+ _packedGuid.put(0, lowMask);
+ _packedGuid.put(1, highMask);
+}
+
template<HighGuid high>
uint64 ObjectGuidGenerator<high>::Generate()
{
@@ -73,13 +103,13 @@ uint64 ObjectGuidGenerator<high>::Generate()
ByteBuffer& operator<<(ByteBuffer& buf, ObjectGuid const& guid)
{
- buf << uint64(guid.GetRawValue());
+ buf << guid.WriteAsPacked();
return buf;
}
ByteBuffer& operator>>(ByteBuffer& buf, ObjectGuid& guid)
{
- guid.Set(buf.read<uint64>());
+ buf >> guid.ReadAsPacked();
return buf;
}
@@ -91,10 +121,21 @@ ByteBuffer& operator<<(ByteBuffer& buf, PackedGuid const& guid)
ByteBuffer& operator>>(ByteBuffer& buf, PackedGuidReader const& guid)
{
- buf.readPackGUID(*reinterpret_cast<uint64*>(guid.GuidPtr));
+ uint8 lowMask, highMask;
+ buf >> lowMask >> highMask;
+ buf.ReadPackedUInt64(lowMask, guid.GuidPtr->_low);
+ buf.ReadPackedUInt64(highMask, guid.GuidPtr->_high);
return buf;
}
+std::ostream& operator<<(std::ostream& stream, ObjectGuid const& guid)
+{
+ std::ostringstream tmp;
+ tmp << std::hex << std::setw(16) << std::setfill('0') << guid._high << std::setw(16) << std::setfill('0') << guid._low;
+ stream << tmp.str();
+ return stream;
+}
+
template uint64 ObjectGuidGenerator<HIGHGUID_ITEM>::Generate();
template uint64 ObjectGuidGenerator<HIGHGUID_PLAYER>::Generate();
template uint64 ObjectGuidGenerator<HIGHGUID_GAMEOBJECT>::Generate();
diff --git a/src/server/game/Entities/Object/ObjectGuid.h b/src/server/game/Entities/Object/ObjectGuid.h
index 039cd6aad8b..6cefc8bc34e 100644
--- a/src/server/game/Entities/Object/ObjectGuid.h
+++ b/src/server/game/Entities/Object/ObjectGuid.h
@@ -21,6 +21,7 @@
#include "Common.h"
#include "ByteBuffer.h"
+#include <boost/functional/hash.hpp>
#include <functional>
@@ -82,34 +83,40 @@ struct PackedGuidReader
ObjectGuid* GuidPtr;
};
+#pragma pack(push, 1)
+
class ObjectGuid
{
+ friend std::ostream& operator<<(std::ostream& stream, ObjectGuid const& guid);
+ friend ByteBuffer& operator>>(ByteBuffer& buf, PackedGuidReader const& guid);
+ friend class PackedGuid;
+
public:
static ObjectGuid const Empty;
- ObjectGuid() { _guid = UI64LIT(0); }
- explicit ObjectGuid(uint64 guid) { _guid = guid; }
- ObjectGuid(HighGuid hi, uint32 entry, uint64 counter) { _guid = counter ? uint64(counter) | (uint64(entry) << 32) | (uint64(hi) << ((hi == HIGHGUID_CORPSE || hi == HIGHGUID_AREATRIGGER) ? 48 : 52)) : 0; }
- ObjectGuid(HighGuid hi, uint64 counter) { _guid = counter ? uint64(counter) | (uint64(hi) << ((hi == HIGHGUID_CORPSE || hi == HIGHGUID_AREATRIGGER) ? 48 : 52)) : 0; }
+ ObjectGuid() : _low(0), _high(0) { }
+ ObjectGuid(uint64 high, uint64 low) : _low(low), _high(high) { }
+ ObjectGuid(HighGuid hi, uint32 entry, uint64 counter) : _low(counter ? uint64(counter) | (uint64(entry) << 32) | (uint64(hi) << ((hi == HIGHGUID_CORPSE || hi == HIGHGUID_AREATRIGGER) ? 48 : 52)) : 0), _high(0) { }
+ ObjectGuid(HighGuid hi, uint64 counter) : _low(counter ? uint64(counter) | (uint64(hi) << ((hi == HIGHGUID_CORPSE || hi == HIGHGUID_AREATRIGGER) ? 48 : 52)) : 0), _high(0) { }
+ ObjectGuid(ObjectGuid const&) = default;
- operator uint64() const { return _guid; }
- DECLSPEC_DEPRECATED PackedGuidReader ReadAsPacked() ATTR_DEPRECATED { return PackedGuidReader(*this); }
+ PackedGuidReader ReadAsPacked() { return PackedGuidReader(*this); }
- void Set(uint64 guid) { _guid = guid; }
- void Clear() { _guid = 0; }
+ std::vector<uint8> GetRawValue() const;
+ void SetRawValue(std::vector<uint8> const& guid);
+ void Clear() { _low = 0; }
- DECLSPEC_DEPRECATED PackedGuid WriteAsPacked() const ATTR_DEPRECATED;
+ PackedGuid WriteAsPacked() const;
- uint64 GetRawValue() const { return _guid; }
HighGuid GetHigh() const
{
- uint32 temp = ((uint64(_guid) >> 48) & 0x0000FFFF);
+ uint32 temp = ((uint64(_low) >> 48) & 0x0000FFFF);
return HighGuid((temp == HIGHGUID_CORPSE || temp == HIGHGUID_AREATRIGGER) ? temp : ((temp >> 4) & 0x00000FFF));
}
- uint32 GetEntry() const { return HasEntry() ? uint32((_guid >> 32) & UI64LIT(0x00000000000FFFFF)) : 0; }
- uint32 GetCounter() const
+ uint32 GetEntry() const { return HasEntry() ? uint32((_low >> 32) & UI64LIT(0x00000000000FFFFF)) : 0; }
+ uint32 GetCounter() const
{
- return uint32(_guid & UI64LIT(0x00000000FFFFFFFF));
+ return uint32(_low & UI64LIT(0x00000000FFFFFFFF));
}
static uint32 GetMaxCounter(HighGuid /*high*/)
@@ -119,19 +126,19 @@ class ObjectGuid
uint32 GetMaxCounter() const { return GetMaxCounter(GetHigh()); }
- DECLSPEC_DEPRECATED uint8& operator[](uint32 index) ATTR_DEPRECATED
+ uint8& operator[](uint32 index)
{
- ASSERT(index < sizeof(uint64));
- return ((uint8*)&_guid)[index];
+ ASSERT(index < sizeof(uint64) * 2);
+ return ((uint8*)&_low)[index];
}
- DECLSPEC_DEPRECATED uint8 const& operator[](uint32 index) const ATTR_DEPRECATED
+ uint8 const& operator[](uint32 index) const
{
- ASSERT(index < sizeof(uint64));
- return ((uint8 const*)&_guid)[index];
+ ASSERT(index < sizeof(uint64) * 2);
+ return ((uint8 const*)&_low)[index];
}
- bool IsEmpty() const { return _guid == 0; }
+ bool IsEmpty() const { return _low == 0 && _high == 0; }
bool IsCreature() const { return GetHigh() == HIGHGUID_UNIT; }
bool IsPet() const { return GetHigh() == HIGHGUID_PET; }
bool IsVehicle() const { return GetHigh() == HIGHGUID_VEHICLE; }
@@ -180,9 +187,17 @@ class ObjectGuid
TypeID GetTypeId() const { return GetTypeId(GetHigh()); }
bool operator!() const { return IsEmpty(); }
- bool operator== (ObjectGuid const& guid) const { return GetRawValue() == guid.GetRawValue(); }
- bool operator!= (ObjectGuid const& guid) const { return GetRawValue() != guid.GetRawValue(); }
- bool operator< (ObjectGuid const& guid) const { return GetRawValue() < guid.GetRawValue(); }
+ bool operator== (ObjectGuid const& guid) const { return _low == guid._low && _high == guid._high; }
+ bool operator!= (ObjectGuid const& guid) const { return !(*this == guid); }
+ bool operator< (ObjectGuid const& guid) const
+ {
+ if (_high < guid._high)
+ return true;
+ else if (_high > guid._high)
+ return false;
+
+ return _low < guid._low;
+ }
static char const* GetTypeName(HighGuid high);
char const* GetTypeName() const { return !IsEmpty() ? GetTypeName(GetHigh()) : "None"; }
@@ -215,29 +230,30 @@ class ObjectGuid
explicit ObjectGuid(uint32 const&) = delete; // no implementation, used to catch wrong type assignment
- uint64 _guid;
+ uint64 _low;
+ uint64 _high;
};
+#pragma pack(pop)
+
// Some Shared defines
typedef std::set<ObjectGuid> GuidSet;
typedef std::list<ObjectGuid> GuidList;
typedef std::deque<ObjectGuid> GuidDeque;
typedef std::vector<ObjectGuid> GuidVector;
-// minimum buffer size for packed guid is 9 bytes
-#define PACKED_GUID_MIN_BUFFER_SIZE 9
+// maximum buffer size for packed guid is 18 bytes
+#define PACKED_GUID_MIN_BUFFER_SIZE 18
class PackedGuid
{
friend 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() : _packedGuid(PACKED_GUID_MIN_BUFFER_SIZE) { _packedGuid << uint16(0); }
+ explicit PackedGuid(ObjectGuid guid) : _packedGuid(PACKED_GUID_MIN_BUFFER_SIZE) { 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);
size_t size() const { return _packedGuid.size(); }
@@ -251,7 +267,7 @@ class ObjectGuidGenerator
public:
explicit ObjectGuidGenerator(uint64 start = 1) : _nextGuid(start) { }
- void Set(uint32 val) { _nextGuid = val; }
+ void Set(uint64 val) { _nextGuid = val; }
uint64 Generate();
uint64 GetNextAfterMaxUsed() const { return _nextGuid; }
@@ -265,6 +281,8 @@ ByteBuffer& operator>>(ByteBuffer& buf, ObjectGuid& guid);
ByteBuffer& operator<<(ByteBuffer& buf, PackedGuid const& guid);
ByteBuffer& operator>>(ByteBuffer& buf, PackedGuidReader const& guid);
+std::ostream& operator<<(std::ostream& stream, ObjectGuid const& guid);
+
inline PackedGuid ObjectGuid::WriteAsPacked() const { return PackedGuid(*this); }
namespace std
@@ -275,7 +293,7 @@ namespace std
public:
size_t operator()(ObjectGuid const& key) const
{
- return hash<uint64>()(key.GetRawValue());
+ return boost::hash_range(reinterpret_cast<uint64 const*>(&key), reinterpret_cast<uint64 const*>(&key) + 2);
}
};
}