Core/PacketIO: Reduce size of SMSG_UPDATE_OBJECT by trimming trailing zeros in values updatemask
This commit is contained in:
1 parent
7a1ce34333
commit
f3e0650886
5 files changed
+75
-92
No files matched your search
@@ -176,8 +176,7 @@ void DynamicObject::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player
|
||||
return;
|
||||
|
||||
ByteBuffer fieldBuffer;
|
||||
UpdateMask updateMask;
|
||||
updateMask.SetCount(m_valuesCount);
|
||||
UpdateMaskPacketBuilder updateMask(m_valuesCount);
|
||||
|
||||
uint32* flags = nullptr;
|
||||
uint32 visibleFlag = GetUpdateFieldData(target, flags);
|
||||
@@ -214,7 +213,6 @@ void DynamicObject::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player
|
||||
}
|
||||
}
|
||||
|
||||
*data << uint8(updateMask.GetBlockCount());
|
||||
updateMask.AppendToPacket(data);
|
||||
data->append(fieldBuffer);
|
||||
}
|
||||
|
||||
@@ -2524,8 +2524,7 @@ void GameObject::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* t
|
||||
|
||||
ByteBuffer fieldBuffer;
|
||||
|
||||
UpdateMask updateMask;
|
||||
updateMask.SetCount(m_valuesCount);
|
||||
UpdateMaskPacketBuilder updateMask(m_valuesCount);
|
||||
|
||||
uint32* flags = GameObjectUpdateFieldFlags;
|
||||
uint32 visibleFlag = UF_FLAG_PUBLIC;
|
||||
@@ -2593,7 +2592,6 @@ void GameObject::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* t
|
||||
}
|
||||
}
|
||||
|
||||
*data << uint8(updateMask.GetBlockCount());
|
||||
updateMask.AppendToPacket(data);
|
||||
data->append(fieldBuffer);
|
||||
}
|
||||
|
||||
@@ -665,8 +665,7 @@ void Object::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* targe
|
||||
return;
|
||||
|
||||
ByteBuffer fieldBuffer;
|
||||
UpdateMask updateMask;
|
||||
updateMask.SetCount(m_valuesCount);
|
||||
UpdateMaskPacketBuilder updateMask(m_valuesCount);
|
||||
|
||||
uint32* flags = nullptr;
|
||||
uint32 visibleFlag = GetUpdateFieldData(target, flags);
|
||||
@@ -682,7 +681,6 @@ void Object::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* targe
|
||||
}
|
||||
}
|
||||
|
||||
*data << uint8(updateMask.GetBlockCount());
|
||||
updateMask.AppendToPacket(data);
|
||||
data->append(fieldBuffer);
|
||||
}
|
||||
|
||||
@@ -24,101 +24,92 @@
|
||||
|
||||
class UpdateMask
|
||||
{
|
||||
public:
|
||||
/// Type representing how client reads update mask
|
||||
typedef uint32 ClientUpdateMaskType;
|
||||
public:
|
||||
UpdateMask() : _bits(nullptr), _fieldCount(0) { }
|
||||
|
||||
enum UpdateMaskCount
|
||||
{
|
||||
CLIENT_UPDATE_MASK_BITS = sizeof(ClientUpdateMaskType) * 8,
|
||||
};
|
||||
void SetBit(uint32 index)
|
||||
{
|
||||
_bits[index] = 1;
|
||||
}
|
||||
|
||||
UpdateMask() : _fieldCount(0), _blockCount(0), _bits(nullptr) { }
|
||||
void UnsetBit(uint32 index)
|
||||
{
|
||||
_bits[index] = 0;
|
||||
}
|
||||
|
||||
UpdateMask(UpdateMask const& right) : _bits(nullptr)
|
||||
{
|
||||
SetCount(right.GetCount());
|
||||
memcpy(_bits, right._bits, sizeof(uint8) * _blockCount * 32);
|
||||
}
|
||||
bool GetBit(uint32 index) const
|
||||
{
|
||||
return _bits[index] != 0;
|
||||
}
|
||||
|
||||
~UpdateMask() { delete[] _bits; }
|
||||
void SetCount(uint32 valuesCount)
|
||||
{
|
||||
_bits = std::make_unique<uint8[]>(valuesCount);
|
||||
std::uninitialized_fill_n(&_bits[0], valuesCount, 0);
|
||||
_fieldCount = valuesCount;
|
||||
}
|
||||
|
||||
void SetBit(uint32 index) { _bits[index] = 1; }
|
||||
void UnsetBit(uint32 index) { _bits[index] = 0; }
|
||||
bool GetBit(uint32 index) const { return _bits[index] != 0; }
|
||||
void Clear()
|
||||
{
|
||||
if (_bits)
|
||||
std::fill_n(&_bits[0], _fieldCount, 0);
|
||||
}
|
||||
|
||||
void AppendToPacket(ByteBuffer* data)
|
||||
{
|
||||
for (uint32 i = 0; i < GetBlockCount(); ++i)
|
||||
{
|
||||
ClientUpdateMaskType maskPart = 0;
|
||||
for (uint32 j = 0; j < CLIENT_UPDATE_MASK_BITS; ++j)
|
||||
if (_bits[CLIENT_UPDATE_MASK_BITS * i + j])
|
||||
maskPart |= 1 << j;
|
||||
private:
|
||||
std::unique_ptr<uint8[]> _bits;
|
||||
uint32 _fieldCount;
|
||||
};
|
||||
|
||||
*data << maskPart;
|
||||
}
|
||||
}
|
||||
class UpdateMaskPacketBuilder
|
||||
{
|
||||
public:
|
||||
/// Type representing how client reads update mask
|
||||
using ClientUpdateMaskType = uint32;
|
||||
|
||||
uint32 GetBlockCount() const { return _blockCount; }
|
||||
uint32 GetCount() const { return _fieldCount; }
|
||||
enum UpdateMaskCount
|
||||
{
|
||||
CLIENT_UPDATE_MASK_BITS = sizeof(ClientUpdateMaskType) * 8,
|
||||
};
|
||||
|
||||
void SetCount(uint32 valuesCount)
|
||||
{
|
||||
delete[] _bits;
|
||||
explicit UpdateMaskPacketBuilder(uint32 valuesCount) : _lastSetBit(0)
|
||||
{
|
||||
std::size_t blockCount = CalculateBlockCount(valuesCount);
|
||||
_mask = std::make_unique<ClientUpdateMaskType[]>(blockCount);
|
||||
std::uninitialized_fill_n(&_mask[0], blockCount, 0);
|
||||
}
|
||||
|
||||
_fieldCount = valuesCount;
|
||||
_blockCount = (valuesCount + CLIENT_UPDATE_MASK_BITS - 1) / CLIENT_UPDATE_MASK_BITS;
|
||||
void SetBit(uint32 bit)
|
||||
{
|
||||
_mask[GetBlockIndex(bit)] |= GetBlockFlag(bit);
|
||||
_lastSetBit = bit;
|
||||
}
|
||||
|
||||
_bits = new uint8[_blockCount * CLIENT_UPDATE_MASK_BITS];
|
||||
memset(_bits, 0, sizeof(uint8) * _blockCount * CLIENT_UPDATE_MASK_BITS);
|
||||
}
|
||||
void AppendToPacket(ByteBuffer* data)
|
||||
{
|
||||
uint8 blockCount = CalculateBlockCount(_lastSetBit + 1);
|
||||
*data << uint8(blockCount);
|
||||
if (blockCount)
|
||||
data->append(&_mask[0], blockCount);
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
if (_bits)
|
||||
memset(_bits, 0, sizeof(uint8) * _blockCount * CLIENT_UPDATE_MASK_BITS);
|
||||
}
|
||||
private:
|
||||
static constexpr uint8 CalculateBlockCount(uint32 fieldCount)
|
||||
{
|
||||
return (fieldCount + CLIENT_UPDATE_MASK_BITS - 1) / CLIENT_UPDATE_MASK_BITS;
|
||||
}
|
||||
|
||||
UpdateMask& operator=(UpdateMask const& right)
|
||||
{
|
||||
if (this == &right)
|
||||
return *this;
|
||||
static constexpr std::size_t GetBlockIndex(uint32 bit)
|
||||
{
|
||||
return bit / 32;
|
||||
}
|
||||
|
||||
SetCount(right.GetCount());
|
||||
memcpy(_bits, right._bits, sizeof(uint8) * _blockCount * CLIENT_UPDATE_MASK_BITS);
|
||||
return *this;
|
||||
}
|
||||
static constexpr uint32 GetBlockFlag(uint32 bit)
|
||||
{
|
||||
return 1u << (bit % 32);
|
||||
}
|
||||
|
||||
UpdateMask& operator&=(UpdateMask const& right)
|
||||
{
|
||||
ASSERT(right.GetCount() <= GetCount());
|
||||
for (uint32 i = 0; i < _fieldCount; ++i)
|
||||
_bits[i] &= right._bits[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
UpdateMask& operator|=(UpdateMask const& right)
|
||||
{
|
||||
ASSERT(right.GetCount() <= GetCount());
|
||||
for (uint32 i = 0; i < _fieldCount; ++i)
|
||||
_bits[i] |= right._bits[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
UpdateMask operator|(UpdateMask const& right)
|
||||
{
|
||||
UpdateMask ret(*this);
|
||||
ret |= right;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32 _fieldCount;
|
||||
uint32 _blockCount;
|
||||
uint8* _bits;
|
||||
std::unique_ptr<ClientUpdateMaskType[]> _mask;
|
||||
uint32 _lastSetBit;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -14204,7 +14204,6 @@ void Unit::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* target)
|
||||
return;
|
||||
|
||||
ByteBuffer fieldBuffer;
|
||||
UpdateMask updateMask;
|
||||
|
||||
uint32 valCount = m_valuesCount;
|
||||
|
||||
@@ -14216,7 +14215,7 @@ void Unit::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* target)
|
||||
else if (GetTypeId() == TYPEID_PLAYER)
|
||||
valCount = PLAYER_END_NOT_SELF;
|
||||
|
||||
updateMask.SetCount(valCount);
|
||||
UpdateMaskPacketBuilder updateMask(valCount);
|
||||
|
||||
Player* plr = GetCharmerOrOwnerPlayerOrPlayerItself();
|
||||
if (GetOwnerGUID() == target->GetGUID())
|
||||
@@ -14365,7 +14364,6 @@ void Unit::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* target)
|
||||
}
|
||||
}
|
||||
|
||||
*data << uint8(updateMask.GetBlockCount());
|
||||
updateMask.AppendToPacket(data);
|
||||
data->append(fieldBuffer);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user