Skip to content

Commit

Permalink
[Core/PacketIO] Use ByteBuffer from UpdateData
Browse files Browse the repository at this point in the history
instead of copying to it after
  • Loading branch information
Lordron authored and billy1arm committed Aug 28, 2024
1 parent 7ac665e commit 90a5551
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/game/WorldHandlers/UpdateData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,19 @@ void UpdateData::Compress(void* dst, uint32* dst_size, void* src, int src_size)
*dst_size = c_stream.total_out;
}

bool UpdateData::BuildPacket(WorldPacket* packet)
bool UpdateData::BuildPacket(WorldPacket* packet, bool hasTransport)
{
MANGOS_ASSERT(packet->empty()); // shouldn't happen

#if defined(CLASSIC) || defined(TBC)
ByteBuffer buf(4 + 1 + (m_outOfRangeGUIDs.empty() ? 0 : 1 + 4 + 9 * m_outOfRangeGUIDs.size()) + m_data.wpos());
#else
ByteBuffer buf(4 + (m_outOfRangeGUIDs.empty() ? 0 : 1 + 4 + 9 * m_outOfRangeGUIDs.size()) + m_data.wpos());

#endif
buf << (uint32)(!m_outOfRangeGUIDs.empty() ? m_blockCount + 1 : m_blockCount);

#if defined(CLASSIC) || defined(TBC)
buf << (uint8)(hasTransport ? 1 : 0);
#endif
if (!m_outOfRangeGUIDs.empty())
{
buf << (uint8) UPDATETYPE_OUT_OF_RANGE_OBJECTS;
Expand Down
2 changes: 1 addition & 1 deletion src/game/WorldHandlers/UpdateData.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class UpdateData
void AddOutOfRangeGUID(ObjectGuid const& guid);
void AddUpdateBlock() { ++m_blockCount; }
ByteBuffer& GetBuffer() { return m_data; }
bool BuildPacket(WorldPacket* packet);
bool BuildPacket(WorldPacket* packet, bool hasTransport = false);
bool HasData() { return m_blockCount > 0 || !m_outOfRangeGUIDs.empty(); }
void Clear();

Expand Down

0 comments on commit 90a5551

Please sign in to comment.