UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IrisFastArraySerializerInternal.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
5
6namespace UE::Net
7{
8 class FNetBitArray;
9 class FNetBitArrayView;
10}
11
12namespace UE::Net
13{
14
15namespace Private
16{
17
18/*
19 * Internal access of FastArraySerializer, for internal use only
20*/
22{
26
27 /*
28 * Mark array as dirty and notify DirtyObjectTracker that the object is dirty if it has not been done before
29 */
31
32 /*
33 * Mark array and all bits in changemask as dirty and notify DirtyObjectTracker that the object is dirty if it has not been done before
34 */
36
37 /*
38 * Mark array dirty and mark changemask bit used for array Item as dirty and notify DirtyObjectTracker that the object is dirty if it has not been done before
39 * Currently the same changemask bit might be used to indicate dirtiness for multiple array items
40 */
42};
43
44} // end namespace Private
45
50template <typename FastArrayType>
52{
53public:
54 typedef typename FastArrayType::ItemArrayType FastArrayItemArrayType;
55 typedef typename FastArrayItemArrayType::ElementType FastArrayItemType;
56
58
59 TIrisFastArrayEditor(FastArrayType& InFastArray) : FastArray(InFastArray) {}
60
65
69 void MarkArrayDirty() { FastArray.MarkArrayDirty(); };
70
74 void AddLocal(const FastArrayItemType& ItemEntry) { FastArray.GetItemArray().Add(ItemEntry); }
75
79 FastArrayItemType& EditLocal(int32 ItemIdx) { return FastArray.GetItemArray()[ItemIdx]; }
80
84 void Add(const FastArrayItemType& ItemEntry);
85
90
95
99 void Remove(int32 ItemIdx);
100
105
106 int32 Num() const { return FastArray.GetItemArray().Num(); }
107
111 void Empty();
112
113private:
114 friend FastArrayType;
115 FastArrayType& FastArray;
116};
117
118template <typename FastArrayType>
120{
122 if (!Header.IsBound())
123 {
124 FastArray.MarkItemDirty(Item);
125 return;
126 }
127
128 const FastArrayItemArrayType& Array = FastArray.GetItemArray();
129 const uint64 Index64 = &Item - Array.GetData();
131 {
132 const int32 Index = static_cast<int32>(Index64);
133 if (Array.IsValidIndex(Index))
134 {
135 // If this is a new element make sure it is at the end, otherwise we must dirty array
136 if ((Item.ReplicationID == INDEX_NONE) && (Index != (Array.Num() - 1)))
137 {
138 // Must mark all items that might have been shifted dirty, including the new one, this is to mimic behavior of current FastArraySerializer
139 for (FastArrayItemType& ArrayItem : MakeArrayView(&Item, Array.Num() - Index))
140 {
141 const bool bIsWritingOnClient = false;
142 if (FastArray.template ShouldWriteFastArrayItem<FastArrayItemType, FastArrayType>(ArrayItem, bIsWritingOnClient))
143 {
144 if (ArrayItem.ReplicationID == INDEX_NONE)
145 {
146 FastArray.MarkItemDirty(ArrayItem);
147 }
148
149 const uint64 ItemIndex64 = &ArrayItem - Array.GetData();
151 {
152 // Mark item dirty in changemask
154 }
155 }
156 }
157 }
158 else
159 {
160 // This is in order to execute old logic
161 FastArray.MarkItemDirty(Item);
162 // Mark item dirty in changemask
164 }
165 }
166 }
167};
168
169
170// The idea is to provide an interface that is modeled after what we can do with a TArray but with dirty tracking per member
171// This way we can update changemask directly and does not need to poll for changes
172template <typename FastArrayType>
174{
175 FastArrayItemArrayType& ItemArray = FastArray.GetItemArray();
176 int32 Idx = ItemArray.Add(ItemEntry);
177 MarkItemDirty(ItemArray.GetData()[Idx]);
178}
179
180template <typename FastArrayType>
182{
183 FastArrayItemType& Item = FastArray.GetItemArray()[ItemIdx]; //-V758
184 MarkItemDirty(Item);
185 return Item;
186}
187
188template <typename FastArrayType>
190{
191 FastArrayItemArrayType& ItemArray = FastArray.GetItemArray();
192
193 if (ItemIdx >= 0 && ItemArray.Num() > ItemIdx)
194 {
195 // If the Item is at the end we only need to mark the array as dirty
196 ItemArray.RemoveAt(ItemIdx);
197 MarkArrayDirty();
198
199 if (ItemIdx < ItemArray.Num())
200 {
202 if (Header.IsBound())
203 {
205 }
206 }
207 }
208}
209
210template <typename FastArrayType>
212{
213 FastArrayItemArrayType& ItemArray = FastArray.GetItemArray();
214
215 if (ItemIdx >= 0 && ItemArray.Num() > ItemIdx)
216 {
217 ItemArray.RemoveAtSwap(ItemIdx);
218
219 // We just need to dirty the modified item
220 if (ItemArray.Num() != 0)
221 {
222 MarkItemDirty(ItemIdx);
223 }
224 else
225 {
226 MarkArrayDirty();
227 }
228 }
229}
230
231template <typename FastArrayType>
233{
234 FastArray.GetItemArray().Empty();
235 MarkArrayDirty();
236}
237
238} // end namespace UE::Net
239
240
241
constexpr auto MakeArrayView(OtherRangeType &&Other)
Definition ArrayView.h:873
#define ensure( InExpression)
Definition AssertionMacros.h:464
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition NetBitArray.h:337
Definition IrisFastArraySerializerInternal.h:52
int32 Num() const
Definition IrisFastArraySerializerInternal.h:106
FastArrayItemType & Edit(int32 ItemIdx)
Definition IrisFastArraySerializerInternal.h:181
FastArrayType::ItemArrayType FastArrayItemArrayType
Definition IrisFastArraySerializerInternal.h:54
FastArrayItemType & EditLocal(int32 ItemIdx)
Definition IrisFastArraySerializerInternal.h:79
void AddLocal(const FastArrayItemType &ItemEntry)
Definition IrisFastArraySerializerInternal.h:74
TIrisFastArrayEditor(FastArrayType &InFastArray)
Definition IrisFastArraySerializerInternal.h:59
void MarkArrayDirty()
Definition IrisFastArraySerializerInternal.h:69
FastArrayItemType & operator[](int32 ItemIdx)
Definition IrisFastArraySerializerInternal.h:94
void MarkItemDirty(FastArrayItemType &Item)
Definition IrisFastArraySerializerInternal.h:119
void Remove(int32 ItemIdx)
Definition IrisFastArraySerializerInternal.h:189
FastArrayItemArrayType::ElementType FastArrayItemType
Definition IrisFastArraySerializerInternal.h:55
void RemoveAtSwap(int32 ItemIdx)
Definition IrisFastArraySerializerInternal.h:211
void Empty()
Definition IrisFastArraySerializerInternal.h:232
void Add(const FastArrayItemType &ItemEntry)
Definition IrisFastArraySerializerInternal.h:173
Definition OverriddenPropertySet.cpp:45
Definition NetworkVersion.cpp:28
U16 Index
Definition radfft.cpp:71
Definition IrisFastArraySerializer.h:27
Definition ReplicationStateFwd.h:20
Definition IrisFastArraySerializerInternal.h:22
static IRISCORE_API FNetBitArrayView GetChangeMask(FIrisFastArraySerializer &Array)
Definition IrisFastArraySerializer.cpp:95
static IRISCORE_API void MarkArrayItemDirty(FIrisFastArraySerializer &Array, int32 Index)
Definition IrisFastArraySerializer.cpp:139
static IRISCORE_API void MarkArrayDirty(FIrisFastArraySerializer &Array)
Definition IrisFastArraySerializer.cpp:125
static IRISCORE_API void MarkAllArrayItemsDirty(FIrisFastArraySerializer &Array, uint32 StartingIndex=0U)
Definition IrisFastArraySerializer.cpp:105
static FReplicationStateHeader & GetReplicationStateHeader(FIrisFastArraySerializer &Array)
Definition IrisFastArraySerializerInternal.h:25
static IRISCORE_API FNetBitArrayView GetConditionalChangeMask(FIrisFastArraySerializer &Array)
Definition IrisFastArraySerializer.cpp:100