TrinityCore
Loading...
Searching...
No Matches
WowCSEntityDefinitions.h
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#ifndef TRINITYCORE_WOWCS_ENTITY_DEFINITIONS_H
19#define TRINITYCORE_WOWCS_ENTITY_DEFINITIONS_H
20
21#include "Define.h"
22#include <array>
23#include <span>
24
25class BaseEntity;
26class ByteBuffer;
27class Player;
28
29namespace UF
30{
31enum class UpdateFieldFlag : uint8;
32}
33
34namespace WowCS
35{
37{
39 CGObject = 2, // UPDATEABLE, INDIRECT,
42 CActor = 15, // INDIRECT,
43 FVendor_C = 17, // UPDATEABLE,
45 FMeshObjectData_C = 19, // UPDATEABLE,
46 FHousingDecor_C = 20, // UPDATEABLE,
47 FHousingRoom_C = 21, // UPDATEABLE,
48 FHousingRoomComponentMesh_C = 22, // UPDATEABLE,
49 FHousingPlayerHouse_C = 23, // UPDATEABLE,
50 FJamHousingCornerstone_C = 27, // UPDATEABLE,
52 FNeighborhoodMirrorData_C = 30, // UPDATEABLE,
53 FMirroredPositionData_C = 31, // UPDATEABLE,
54 PlayerHouseInfoComponent_C = 32, // UPDATEABLE, INDIRECT,
55 FHousingStorage_C = 33, // UPDATEABLE,
56 FHousingFixture_C = 34, // UPDATEABLE,
57 PlayerInitiativeComponent_C = 37, // UPDATEABLE, INDIRECT,
58 Tag_Item = 200, // TAG,
59 Tag_Container = 201, // TAG,
60 Tag_AzeriteEmpoweredItem = 202, // TAG,
61 Tag_AzeriteItem = 203, // TAG,
62 Tag_Unit = 204, // TAG,
63 Tag_Player = 205, // TAG,
64 Tag_GameObject = 206, // TAG,
65 Tag_DynamicObject = 207, // TAG,
66 Tag_Corpse = 208, // TAG,
67 Tag_AreaTrigger = 209, // TAG,
68 Tag_SceneObject = 210, // TAG,
69 Tag_Conversation = 211, // TAG,
70 Tag_AIGroup = 212, // TAG,
71 Tag_Scenario = 213, // TAG,
72 Tag_LootObject = 214, // TAG,
73 Tag_ActivePlayer = 215, // TAG,
74 Tag_ActiveClient_S = 216, // TAG,
75 Tag_ActiveObject_C = 217, // TAG,
76 Tag_VisibleObject_C = 218, // TAG,
77 Tag_UnitVehicle = 219, // TAG,
78 Tag_HousingRoom = 220, // TAG,
79 Tag_MeshObject = 221, // TAG,
80 Tag_HouseExteriorPiece = 224, // TAG,
81 Tag_HouseExteriorRoot = 225, // TAG,
83 End = 255,
84};
85
103
111
113{
119
121 {
122 static constexpr std::size_t N = 4;
123
124 std::array<EntityFragment, N> Ids =
125 {
127 };
128 std::array<uint8, N> Masks = { };
129 std::array<void const*, N> Data;
130 };
131
133
135 bool IdsChanged = false;
136
139
140 void Add(EntityFragment fragment, bool update, void const* data = nullptr);
141
142 void Remove(EntityFragment fragment);
143
144 std::span<EntityFragment const> GetIds() const { return std::span(Ids.begin(), Count); }
145};
146
148{
149 Full = 0,
150 Partial = 1
151};
152
153template <typename T>
154inline void const* GetRawFragmentData(T const& fragmentData)
155{
156 return std::addressof(*fragmentData);
157}
158
159template <typename FragmentData>
161{
162 static void BuildCreate(void const* rawFragmentData, UF::UpdateFieldFlag flags, ByteBuffer& data, Player const* target, BaseEntity const* baseEntity)
163 {
164 static_cast<FragmentData const*>(rawFragmentData)->WriteCreate(flags, data, target, reinterpret_cast<typename FragmentData::OwnerObject const*>(baseEntity));
165 }
166
167 static void BuildUpdate(void const* rawFragmentData, UF::UpdateFieldFlag flags, ByteBuffer& data, Player const* target, BaseEntity const* baseEntity)
168 {
169 static_cast<FragmentData const*>(rawFragmentData)->WriteUpdate(flags, data, target, reinterpret_cast<typename FragmentData::OwnerObject const*>(baseEntity));
170 }
171
172 static bool IsChanged(void const* rawFragmentData)
173 {
174 return static_cast<FragmentData const*>(rawFragmentData)->GetChangesMask().IsAnySet();
175 }
176
177 static void ClearChanged(void const* rawFragmentData)
178 {
179 const_cast<FragmentData*>(static_cast<FragmentData const*>(rawFragmentData))->ClearChangesMask();
180 }
181};
182
183using EntityFragmentSerializeFn = void (*)(void const* rawFragmentData, UF::UpdateFieldFlag flags, ByteBuffer& data, Player const* target, BaseEntity const* baseEntity);
184using EntityFragmentIsChangedFn = bool (*)(void const* rawFragmentData);
185using EntityFragmentClearChangedFn = void (*)(void const* rawFragmentData);
186
188{
189 static constexpr std::size_t N = static_cast<std::size_t>(EntityFragment::End) + 1;
190
191 std::array<EntityFragmentSerializeFn, N> SerializeCreate = { };
192 std::array<EntityFragmentSerializeFn, N> SerializeUpdate = { };
193 std::array<EntityFragmentIsChangedFn, N> IsChanged = { };
194 std::array<EntityFragmentClearChangedFn, N> ClearChanged = { };
195
196 static void Register(EntityFragment fragment,
197 EntityFragmentSerializeFn serializeCreate, EntityFragmentSerializeFn serializeUpdate,
199
200 template <typename SerializationTraits>
201 inline static void Register(EntityFragment fragment, SerializationTraits)
202 {
203 EntityFragmentInfos::Register(fragment, &SerializationTraits::BuildCreate, &SerializationTraits::BuildUpdate,
204 &SerializationTraits::IsChanged, &SerializationTraits::ClearChanged);
205 }
206
207private:
209};
210
211extern EntityFragmentInfos const* EntityFragmentInfo;
212}
213
214#endif // TRINITYCORE_WOWCS_ENTITY_DEFINITIONS_H
uint8_t uint8
Definition Define.h:156
uint16 flags
UpdateFieldFlag
Definition UpdateField.h:37
bool(*)(void const *rawFragmentData) EntityFragmentIsChangedFn
void const * GetRawFragmentData(T const &fragmentData)
EntityFragmentInfos const * EntityFragmentInfo
constexpr bool IsUpdateableFragment(EntityFragment frag)
void(*)(void const *rawFragmentData) EntityFragmentClearChangedFn
void(*)(void const *rawFragmentData, UF::UpdateFieldFlag flags, ByteBuffer &data, Player const *target, BaseEntity const *baseEntity) EntityFragmentSerializeFn
constexpr bool IsIndirectFragment(EntityFragment frag)
static constexpr std::size_t N
std::array< EntityFragmentSerializeFn, N > SerializeUpdate
std::array< EntityFragmentIsChangedFn, N > IsChanged
std::array< EntityFragmentClearChangedFn, N > ClearChanged
static void Register(EntityFragment fragment, SerializationTraits)
std::array< EntityFragmentSerializeFn, N > SerializeCreate
static void Register(EntityFragment fragment, EntityFragmentSerializeFn serializeCreate, EntityFragmentSerializeFn serializeUpdate, EntityFragmentIsChangedFn isChanged, EntityFragmentClearChangedFn clearChanged)
std::span< EntityFragment const > GetIds() const
std::array< EntityFragment, 8 > Ids
void Add(EntityFragment fragment, bool update, void const *data=nullptr)
static bool IsChanged(void const *rawFragmentData)
static void BuildUpdate(void const *rawFragmentData, UF::UpdateFieldFlag flags, ByteBuffer &data, Player const *target, BaseEntity const *baseEntity)
static void ClearChanged(void const *rawFragmentData)
static void BuildCreate(void const *rawFragmentData, UF::UpdateFieldFlag flags, ByteBuffer &data, Player const *target, BaseEntity const *baseEntity)