mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Objects: Use span/array instead of vector for raw ObjectGuid manipulations
This commit is contained in:
@@ -797,17 +797,17 @@ std::size_t ObjectGuid::GetHash() const
|
||||
return hashVal;
|
||||
}
|
||||
|
||||
std::vector<uint8> ObjectGuid::GetRawValue() const
|
||||
std::array<uint8, 16> ObjectGuid::GetRawValue() const
|
||||
{
|
||||
std::vector<uint8> raw(16);
|
||||
memcpy(raw.data(), this, sizeof(*this));
|
||||
std::array<uint8, 16> raw;
|
||||
memcpy(raw.data(), _data.data(), BytesSize);
|
||||
return raw;
|
||||
}
|
||||
|
||||
void ObjectGuid::SetRawValue(std::vector<uint8> const& guid)
|
||||
void ObjectGuid::SetRawValue(std::span<uint8 const> rawBytes)
|
||||
{
|
||||
ASSERT(guid.size() == sizeof(*this));
|
||||
memcpy(this, guid.data(), sizeof(*this));
|
||||
ASSERT(rawBytes.size() == BytesSize, SZFMTD " == " SZFMTD, rawBytes.size(), BytesSize);
|
||||
memcpy(_data.data(), rawBytes.data(), BytesSize);
|
||||
}
|
||||
|
||||
static inline uint32 GetRealmIdForObjectGuid(uint32 realmId)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <span>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
@@ -263,8 +264,6 @@ public:
|
||||
static ObjectGuid CreateLMMLobby(uint32 realmId, uint32 arg2, uint8 arg3, uint8 arg4, uint64 counter);
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
class TC_GAME_API ObjectGuid
|
||||
{
|
||||
friend class ObjectGuidFactory;
|
||||
@@ -277,13 +276,15 @@ class TC_GAME_API ObjectGuid
|
||||
static ObjectGuid const FromStringFailed;
|
||||
static ObjectGuid const TradeItem;
|
||||
|
||||
static constexpr std::size_t BytesSize = 16;
|
||||
|
||||
using LowType = uint64;
|
||||
|
||||
ObjectGuid() = default;
|
||||
|
||||
uint64 GetRawValue(std::size_t i) const { return _data[i]; }
|
||||
std::vector<uint8> GetRawValue() const;
|
||||
void SetRawValue(std::vector<uint8> const& guid);
|
||||
std::array<uint8, 16> GetRawValue() const;
|
||||
void SetRawValue(std::span<uint8 const> rawBytes);
|
||||
void SetRawValue(uint64 high, uint64 low) { _data[0] = low; _data[1] = high; }
|
||||
void Clear() { _data = { }; }
|
||||
|
||||
@@ -387,8 +388,6 @@ class TC_GAME_API ObjectGuid
|
||||
std::array<uint64, 2> _data = { };
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
// Some Shared defines
|
||||
using GuidSet = std::set<ObjectGuid>;
|
||||
using GuidList = std::list<ObjectGuid>;
|
||||
|
||||
@@ -1189,7 +1189,11 @@ void Pet::_LoadAuras(PreparedQueryResult auraResult, PreparedQueryResult effectR
|
||||
uint32 effectIndex = fields[3].GetUInt8();
|
||||
if (effectIndex < MAX_SPELL_EFFECTS)
|
||||
{
|
||||
casterGuid.SetRawValue(fields[0].GetBinary());
|
||||
std::span<uint8 const> rawGuidBytes = fields[0].GetBinaryView();
|
||||
if (rawGuidBytes.size() != ObjectGuid::BytesSize)
|
||||
continue;
|
||||
|
||||
casterGuid.SetRawValue(rawGuidBytes);
|
||||
if (casterGuid.IsEmpty())
|
||||
casterGuid = GetGUID();
|
||||
|
||||
@@ -1211,7 +1215,11 @@ void Pet::_LoadAuras(PreparedQueryResult auraResult, PreparedQueryResult effectR
|
||||
{
|
||||
Field* fields = auraResult->Fetch();
|
||||
// NULL guid stored - pet is the caster of the spell - see Pet::_SaveAuras
|
||||
casterGuid.SetRawValue(fields[0].GetBinary());
|
||||
std::span<uint8 const> rawGuidBytes = fields[0].GetBinaryView();
|
||||
if (rawGuidBytes.size() != ObjectGuid::BytesSize)
|
||||
continue;
|
||||
|
||||
casterGuid.SetRawValue(rawGuidBytes);
|
||||
if (casterGuid.IsEmpty())
|
||||
casterGuid = GetGUID();
|
||||
|
||||
|
||||
@@ -18733,8 +18733,17 @@ void Player::_LoadAuras(PreparedQueryResult auraResult, PreparedQueryResult effe
|
||||
uint32 effectIndex = fields[4].GetUInt8();
|
||||
if (effectIndex < MAX_SPELL_EFFECTS)
|
||||
{
|
||||
casterGuid.SetRawValue(fields[0].GetBinary());
|
||||
itemGuid.SetRawValue(fields[1].GetBinary());
|
||||
std::span<uint8 const> rawGuidBytes = fields[0].GetBinaryView();
|
||||
if (rawGuidBytes.size() != ObjectGuid::BytesSize)
|
||||
continue;
|
||||
|
||||
casterGuid.SetRawValue(rawGuidBytes);
|
||||
|
||||
rawGuidBytes = fields[1].GetBinaryView();
|
||||
if (rawGuidBytes.size() != ObjectGuid::BytesSize)
|
||||
continue;
|
||||
|
||||
itemGuid.SetRawValue(rawGuidBytes);
|
||||
AuraKey key{ casterGuid, itemGuid, fields[2].GetUInt32(), fields[3].GetUInt32() };
|
||||
AuraLoadEffectInfo& info = effectInfo[key];
|
||||
info.Amounts[effectIndex] = fields[5].GetInt32();
|
||||
@@ -18753,8 +18762,17 @@ void Player::_LoadAuras(PreparedQueryResult auraResult, PreparedQueryResult effe
|
||||
do
|
||||
{
|
||||
Field* fields = auraResult->Fetch();
|
||||
casterGuid.SetRawValue(fields[0].GetBinary());
|
||||
itemGuid.SetRawValue(fields[1].GetBinary());
|
||||
std::span<uint8 const> rawGuidBytes = fields[0].GetBinaryView();
|
||||
if (rawGuidBytes.size() != ObjectGuid::BytesSize)
|
||||
continue;
|
||||
|
||||
casterGuid.SetRawValue(rawGuidBytes);
|
||||
|
||||
rawGuidBytes = fields[1].GetBinaryView();
|
||||
if (rawGuidBytes.size() != ObjectGuid::BytesSize)
|
||||
continue;
|
||||
|
||||
itemGuid.SetRawValue(rawGuidBytes);
|
||||
AuraKey key{ casterGuid, itemGuid, fields[2].GetUInt32(), fields[3].GetUInt32() };
|
||||
uint32 recalculateMask = fields[4].GetUInt32();
|
||||
Difficulty difficulty = Difficulty(fields[5].GetUInt8());
|
||||
|
||||
@@ -185,14 +185,8 @@ bool Group::Create(Player* leader)
|
||||
stmt->setUInt8(index++, uint8(m_lootMethod));
|
||||
stmt->setUInt64(index++, m_looterGuid.GetCounter());
|
||||
stmt->setUInt8(index++, uint8(m_lootThreshold));
|
||||
stmt->setBinary(index++, m_targetIcons[0].GetRawValue());
|
||||
stmt->setBinary(index++, m_targetIcons[1].GetRawValue());
|
||||
stmt->setBinary(index++, m_targetIcons[2].GetRawValue());
|
||||
stmt->setBinary(index++, m_targetIcons[3].GetRawValue());
|
||||
stmt->setBinary(index++, m_targetIcons[4].GetRawValue());
|
||||
stmt->setBinary(index++, m_targetIcons[5].GetRawValue());
|
||||
stmt->setBinary(index++, m_targetIcons[6].GetRawValue());
|
||||
stmt->setBinary(index++, m_targetIcons[7].GetRawValue());
|
||||
for (uint8 i = 0; i < TARGET_ICONS_COUNT; ++i)
|
||||
stmt->setBinary(index++, m_targetIcons[i].GetRawValue());
|
||||
stmt->setUInt16(index++, m_groupFlags);
|
||||
stmt->setUInt32(index++, uint8(m_dungeonDifficulty));
|
||||
stmt->setUInt32(index++, uint8(m_raidDifficulty));
|
||||
@@ -232,7 +226,8 @@ void Group::LoadGroupFromDB(Field* fields)
|
||||
m_lootThreshold = ItemQualities(fields[3].GetUInt8());
|
||||
|
||||
for (uint8 i = 0; i < TARGET_ICONS_COUNT; ++i)
|
||||
m_targetIcons[i].SetRawValue(fields[4 + i].GetBinary());
|
||||
if (std::span<uint8 const> rawGuidBytes = fields[4 + i].GetBinaryView(); rawGuidBytes.size() == ObjectGuid::BytesSize)
|
||||
m_targetIcons[i].SetRawValue(rawGuidBytes);
|
||||
|
||||
m_groupFlags = GroupFlags(fields[12].GetUInt16());
|
||||
if (m_groupFlags & GROUP_FLAG_RAID)
|
||||
|
||||
Reference in New Issue
Block a user