TrinityCore
UpdateData.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "UpdateData.h"
19#include "Errors.h"
20#include "WorldPacket.h"
21#include "Opcodes.h"
22
23UpdateData::UpdateData(uint32 map) : m_map(map), m_blockCount(0) { }
24
26{
27 m_destroyGUIDs.insert(guid);
28}
29
31{
32 m_outOfRangeGUIDs.insert(guids.begin(), guids.end());
33}
34
36{
37 m_outOfRangeGUIDs.insert(guid);
38}
39
41{
42 ASSERT(packet->empty()); // shouldn't happen
43 packet->Initialize(SMSG_UPDATE_OBJECT, 4 + 2 + 1 + (2 + 4 + 17 * (m_destroyGUIDs.size() + m_outOfRangeGUIDs.size())) + m_data.wpos());
44
45 *packet << uint32(m_blockCount);
46 *packet << uint16(m_map);
47
48 if (packet->WriteBit(!m_outOfRangeGUIDs.empty() || !m_destroyGUIDs.empty()))
49 {
50 *packet << uint16(m_destroyGUIDs.size());
51 *packet << uint32(m_destroyGUIDs.size() + m_outOfRangeGUIDs.size());
52
53 for (ObjectGuid const& destroyGuid : m_destroyGUIDs)
54 *packet << destroyGuid;
55
56 for (ObjectGuid const& outOfRangeGuid : m_outOfRangeGUIDs)
57 *packet << outOfRangeGuid;
58 }
59
60 *packet << uint32(m_data.size());
61 packet->append(m_data);
62 return true;
63}
64
66{
67 m_data.clear();
68 m_destroyGUIDs.clear();
69 m_outOfRangeGUIDs.clear();
70 m_blockCount = 0;
71 m_map = 0;
72}
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
#define ASSERT
Definition: Errors.h:68
std::set< ObjectGuid > GuidSet
Definition: ObjectGuid.h:393
void append(T value)
Definition: ByteBuffer.h:143
size_t wpos() const
Definition: ByteBuffer.h:412
bool WriteBit(bool bit)
Definition: ByteBuffer.h:175
void clear()
Definition: ByteBuffer.h:133
size_t size() const
Definition: ByteBuffer.h:536
bool empty() const
Definition: ByteBuffer.h:537
GuidSet m_destroyGUIDs
Definition: UpdateData.h:60
void AddDestroyObject(ObjectGuid guid)
Definition: UpdateData.cpp:25
uint32 m_blockCount
Definition: UpdateData.h:59
void AddOutOfRangeGUID(GuidSet &guids)
Definition: UpdateData.cpp:30
UpdateData(uint32 map)
Definition: UpdateData.cpp:23
bool BuildPacket(WorldPacket *packet)
Definition: UpdateData.cpp:40
ByteBuffer m_data
Definition: UpdateData.h:62
void Clear()
Definition: UpdateData.cpp:65
GuidSet m_outOfRangeGUIDs
Definition: UpdateData.h:61
uint32 m_map
Definition: UpdateData.h:58
void Initialize(uint32 opcode, size_t newres=200, ConnectionType connection=CONNECTION_TYPE_DEFAULT)
Definition: WorldPacket.h:76
@ SMSG_UPDATE_OBJECT
Definition: Opcodes.h:2037