UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DeltaCompressionBaselineManager.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
9
11
12namespace UE::Net
13{
15}
16
17namespace UE::Net::Private
18{
19 struct FChangeMaskCache;
20 class FDeltaCompressionBaselineInvalidationTracker;
22 class FNetRefHandleManager;
23 class FReplicationConnections;
24}
25
26namespace UE::Net::Private
27{
28
31
43
48
52
54{
55public:
59
62
64 void Deinit();
65
68
71
72 void AddConnection(uint32 ConnectionId);
73 void RemoveConnection(uint32 ConnectionId);
74
77
79
88
90 void DestroyBaseline(uint32 ConnId, uint32 ObjectIndex, uint32 BaselineIndex);
95 void LostBaseline(uint32 ConnId, uint32 ObjectIndex, uint32 BaselineIndex);
96
102
103 [[nodiscard]] FString PrintDeltaCompressionStatus(uint32 ConnectionId, FInternalNetRefIndex ObjectIndex) const;
104
105private:
106 using ObjectInfoIndexType = uint16;
107
108 enum : unsigned
109 {
110 InvalidObjectInfoIndex = 0,
111 InvalidBaselineStateInfoIndex = 0,
112
113 // Must match NetRefHandleManager::InvalidInternalIndex
114 InvalidInternalIndex = 0,
115
116 ObjectInfoGrowCount = 128,
117 };
118
119 enum class EChangeMaskBehavior : unsigned
120 {
121 Discard,
122 Merge,
123 };
124
125 class FInternalBaseline
126 {
127 public:
128 bool IsValid() const { return BaselineStateInfoIndex != InvalidBaselineStateInfoIndex; }
129
130 ChangeMaskStorageType* ChangeMask = nullptr;
131 uint32 BaselineStateInfoIndex = InvalidBaselineStateInfoIndex;
132 };
133
134 class FObjectBaselineInfo
135 {
136 public:
137 FInternalBaseline Baselines[2];
138 };
139
140 class FPerObjectInfo
141 {
142 private:
143 // Use ConstructPerObjectInfo instead.
144 FPerObjectInfo() = delete;
145 // Use DestructPerObjectInfo instead.
146 ~FPerObjectInfo() = delete;
147
148 public:
149 // Single pointer for changemasks for all connections.
150 ChangeMaskStorageType* ChangeMasksForConnections;
151
152 // ObjectIndex
153 uint32 ObjectIndex;
154
155 // Local frame number of when this object last had a baseline created.
156 uint32 PrevBaselineCreationFrame;
157
158 // How many ChangeMaskStorageTypes per change mask.
159 uint16 ChangeMaskStride;
160
161 // Baselines for all connections. Array has same size as MaxConnectionCount. This member needs to be last!
162 FObjectBaselineInfo BaselinesForConnections[1];
163
164 // No members after BaselinesForConnections!
165 };
166
167 struct FBaselineSharingContext
168 {
169 FNetBitArray ObjectInfoIndicesWithNewBaseline;
170 TArray<DeltaCompressionBaselineStateInfoIndexType> ObjectInfoIndexToBaselineInfoIndex;
171 uint32 CreatedBaselineCount = 0;
172 };
173
174private:
175
176 void UpdateScope();
177 void UpdateDirtyStateMasks(const FChangeMaskCache* ChangeMaskCache);
178
179 void AddObjectToScope(uint32 ObjectIndex);
180 void RemoveObjectFromScope(uint32 ObjectIndex);
181
182 FPerObjectInfo* AllocPerObjectInfoForObject(uint32 ObjectIndex);
183 void FreePerObjectInfoForObject(uint32 ObjectIndex);
184
185 void ConstructPerObjectInfo(FPerObjectInfo*) const;
186 void DestructPerObjectInfo(FPerObjectInfo*);
187
188 ObjectInfoIndexType AllocPerObjectInfo();
189 void FreePerObjectInfo(ObjectInfoIndexType Index);
190
191 FPerObjectInfo* GetPerObjectInfo(ObjectInfoIndexType Index);
192 const FPerObjectInfo* GetPerObjectInfo(ObjectInfoIndexType Index) const;
193
194 FPerObjectInfo* GetPerObjectInfoForObject(uint32 ObjectIndex);
195 const FPerObjectInfo* GetPerObjectInfoForObject(uint32 ObjectIndex) const;
196
197 void FreeAllPerObjectInfos();
198
199 void DestroyBaseline(uint32 ConnId, uint32 ObjectIndex, uint32 BaselineIndex, EChangeMaskBehavior ChangeMaskBehavior);
200
201 void ReleaseInternalBaseline(FInternalBaseline& InternalBaseline);
202
203 void AdjustBaselineCount(const FPerObjectInfo* ObjectInfo, ObjectInfoIndexType ObjectInfoIndex, int16 Adjustment);
204
205 void ReleaseBaselinesForConnection(uint32 ConnId);
206
207 void ConstructBaselineSharingContext(FBaselineSharingContext&);
208 void DestructBaselineSharingContext(FBaselineSharingContext&);
209
210 bool DoesObjectSupportDeltaCompression(uint32 ObjectIndex) const;
211
212 ChangeMaskStorageType* GetChangeMaskPointerForBaseline(const FPerObjectInfo*, uint32 ConnId, uint32 BaselineIndex) const;
213 ChangeMaskStorageType* GetChangeMaskPointerForConnection(const FPerObjectInfo*, uint32 ConnId) const;
214
219 bool IsAllowedToCreateBaselineForObject(uint32 ConnId, uint32 ObjectIndex, const FPerObjectInfo*, ObjectInfoIndexType InfoIndex) const;
220
221 void InvalidateBaselinesDueToModifiedConditionals();
222
223private:
224 FDeltaCompressionBaselineStorage BaselineStorage;
225
226 FNetBitArray DeltaCompressionEnabledObjects;
227 FNetBitArray UsedPerObjectInfos;
228 TArray<ObjectInfoIndexType> ObjectIndexToObjectInfoIndex;
229 TArray<uint8, TAlignedHeapAllocator<alignof(FPerObjectInfo)>> ObjectInfoStorage;
230 // This array will only be large enough to hold baseline counts for MaxDeltaCompressedObjectCount baselines.
231 // Indexed using ObjectInfoIndex.
232 TArray<uint16> BaselineCounts;
233
234 FGlobalChangeMaskAllocator ChangeMaskAllocator;
235
236 FReplicationConnections* Connections = nullptr;
237 const FNetRefHandleManager* NetRefHandleManager = nullptr;
238 UReplicationSystem* ReplicationSystem = nullptr;
239 const FDeltaCompressionBaselineInvalidationTracker* BaselineInvalidationTracker = nullptr;
240 uint32 MaxConnectionCount = 0;
241 uint32 BytesPerObjectInfo = 0;
242 uint32 MaxDeltaCompressedObjectCount = 0;
243 uint32 FrameCounter = 0;
244
245 // Only used during send update to prevent creating multiple baselines for the same object.
246 FBaselineSharingContext BaselineSharingContext;
247};
248
249
251{
252 return MaxDeltaCompressedObjectCount;
253}
254
255inline FDeltaCompressionBaselineManager::FPerObjectInfo* FDeltaCompressionBaselineManager::GetPerObjectInfo(ObjectInfoIndexType Index)
256{
257 const SIZE_T ObjectInfoStorageIndex = Index*BytesPerObjectInfo;
258
259 checkSlow(ObjectInfoStorageIndex < (uint32)ObjectInfoStorage.Num());
260
261 uint8* StoragePointer = ObjectInfoStorage.GetData() + ObjectInfoStorageIndex;
262 return reinterpret_cast<FPerObjectInfo*>(StoragePointer);
263}
264
265inline const FDeltaCompressionBaselineManager::FPerObjectInfo* FDeltaCompressionBaselineManager::GetPerObjectInfo(ObjectInfoIndexType Index) const
266{
267 const SIZE_T ObjectInfoStorageIndex = Index*BytesPerObjectInfo;
268
269 checkSlow(ObjectInfoStorageIndex < (uint32)ObjectInfoStorage.Num());
270
271 const uint8* StoragePointer = ObjectInfoStorage.GetData() + ObjectInfoStorageIndex;
272 return reinterpret_cast<const FPerObjectInfo*>(StoragePointer);
273}
274
275inline FDeltaCompressionBaselineManager::FPerObjectInfo* FDeltaCompressionBaselineManager::GetPerObjectInfoForObject(uint32 ObjectIndex)
276{
277 checkSlow(ObjectIndex != InvalidInternalIndex);
278 checkSlow(ObjectIndex < (uint32)ObjectIndexToObjectInfoIndex.Num());
279
280 const ObjectInfoIndexType InfoIndex = ObjectIndexToObjectInfoIndex[ObjectIndex];
281 if (InfoIndex != InvalidObjectInfoIndex)
282 {
283 return GetPerObjectInfo(InfoIndex);
284 }
285
286 return nullptr;
287}
288
289inline const FDeltaCompressionBaselineManager::FPerObjectInfo* FDeltaCompressionBaselineManager::GetPerObjectInfoForObject(uint32 ObjectIndex) const
290{
291 checkSlow(ObjectIndex != InvalidInternalIndex);
292 checkSlow(ObjectIndex < (uint32)ObjectIndexToObjectInfoIndex.Num());
293
294 const ObjectInfoIndexType InfoIndex = ObjectIndexToObjectInfoIndex[ObjectIndex];
295 if (InfoIndex != InvalidObjectInfoIndex)
296 {
297 return GetPerObjectInfo(InfoIndex);
298 }
299
300 return nullptr;
301}
302
303inline ChangeMaskStorageType* FDeltaCompressionBaselineManager::GetChangeMaskPointerForBaseline(const FPerObjectInfo* ObjectInfo, uint32 ConnId, uint32 BaselineIndex) const
304{
305 // Layout of storage per object is:
306 // ChangeMaskForConnections[0 .. ConnectionCount]
307 // ChangeMaskForBaselines[Conn0[0+1] .. ConnConnectionCount[0+1]]
308 const uint32 ChangeMaskStride = ObjectInfo->ChangeMaskStride;
309 const SIZE_T BaselineChangeMaskOffset = (MaxConnectionCount + 2U*ConnId + BaselineIndex)*ChangeMaskStride;
310 ChangeMaskStorageType* ChangeMaskPointer = ObjectInfo->ChangeMasksForConnections + BaselineChangeMaskOffset;
311 return ChangeMaskPointer;
312}
313
314inline ChangeMaskStorageType* FDeltaCompressionBaselineManager::GetChangeMaskPointerForConnection(const FPerObjectInfo* ObjectInfo, uint32 ConnId) const
315{
316 const uint32 ChangeMaskStride = ObjectInfo->ChangeMaskStride;
317 const SIZE_T ConnectionChangeMaskOffset = ConnId*ChangeMaskStride;
318 ChangeMaskStorageType* ChangeMaskPointer = ObjectInfo->ChangeMasksForConnections + ConnectionChangeMaskOffset;
319 return ChangeMaskPointer;
320}
321
322}
#define checkSlow(expr)
Definition AssertionMacros.h:332
FPlatformTypes::int16 int16
A 16-bit signed integer.
Definition Platform.h:1123
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
void Init()
Definition LockFreeList.h:4
UE_FORCEINLINE_HINT bool IsValid(const UObject *Test)
Definition Object.h:1875
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition ContainerAllocationPolicies.h:447
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT ElementType * GetData() UE_LIFETIMEBOUND
Definition Array.h:1027
Definition ReplicationStateStorage.h:48
Definition DeltaCompressionBaselineInvalidationTracker.h:28
Definition DeltaCompressionBaselineManager.h:54
void DestroyBaseline(uint32 ConnId, uint32 ObjectIndex, uint32 BaselineIndex)
Definition DeltaCompressionBaselineManager.cpp:469
ENetObjectDeltaCompressionStatus GetDeltaCompressionStatus(FInternalNetRefIndex Index) const
Definition DeltaCompressionBaselineManager.cpp:144
void PostSendUpdate(FDeltaCompressionBaselineManagerPostSendUpdateParams &UpdateParams)
Definition DeltaCompressionBaselineManager.cpp:128
void Deinit()
Definition DeltaCompressionBaselineManager.cpp:100
FString PrintDeltaCompressionStatus(uint32 ConnectionId, FInternalNetRefIndex ObjectIndex) const
Definition DeltaCompressionBaselineManager.cpp:730
@ MaxBaselineCount
Definition DeltaCompressionBaselineManager.h:56
void LostBaseline(uint32 ConnId, uint32 ObjectIndex, uint32 BaselineIndex)
Definition DeltaCompressionBaselineManager.cpp:474
void PreSendUpdate(FDeltaCompressionBaselineManagerPreSendUpdateParams &UpdateParams)
Definition DeltaCompressionBaselineManager.cpp:113
@ InvalidBaselineIndex
Definition DeltaCompressionBaselineManager.h:57
void AddConnection(uint32 ConnectionId)
Definition DeltaCompressionBaselineManager.cpp:135
~FDeltaCompressionBaselineManager()
Definition DeltaCompressionBaselineManager.cpp:61
FDeltaCompressionBaselineManager()
Definition DeltaCompressionBaselineManager.cpp:54
uint32 GetMaxDeltaCompressedObjectCount() const
Definition DeltaCompressionBaselineManager.h:250
FDeltaCompressionBaseline GetBaseline(uint32 ConnId, uint32 ObjectIndex, uint32 BaselineIndex) const
Definition DeltaCompressionBaselineManager.cpp:479
@ BaselineIndexBitCount
Definition DeltaCompressionBaselineManager.h:58
void SetDeltaCompressionStatus(FInternalNetRefIndex Index, ENetObjectDeltaCompressionStatus Status)
Definition DeltaCompressionBaselineManager.cpp:149
FDeltaCompressionBaseline CreateBaseline(uint32 ConnId, uint32 ObjectIndex, uint32 BaselineIndex)
Definition DeltaCompressionBaselineManager.cpp:390
void OnMaxInternalNetRefIndexIncreased(UE::Net::Private::FInternalNetRefIndex NewMaxInternalIndex)
Definition DeltaCompressionBaselineManager.cpp:107
void RemoveConnection(uint32 ConnectionId)
Definition DeltaCompressionBaselineManager.cpp:139
Definition DeltaCompressionBaseline.h:11
Definition NetRefHandleManager.h:72
Definition ReplicationConnections.h:32
Definition ReplicationSystem.h:70
Definition NetworkVersion.cpp:28
bool IsDeltaCompressionEnabled()
Definition DeltaCompressionBaselineManager.cpp:44
uint32 FInternalNetRefIndex
Definition ReplicationStateStorage.h:20
FNetBitArrayView::StorageWordType ChangeMaskStorageType
Definition ChangeMaskUtil.h:11
Definition NetworkVersion.cpp:28
ENetObjectDeltaCompressionStatus
Definition ReplicationSystemTypes.h:13
U16 Index
Definition radfft.cpp:71
Definition ChangeMaskCache.h:17
Definition DeltaCompressionBaselineManager.h:33
const FDeltaCompressionBaselineInvalidationTracker * BaselineInvalidationTracker
Definition DeltaCompressionBaselineManager.h:34
UReplicationSystem * ReplicationSystem
Definition DeltaCompressionBaselineManager.h:38
FReplicationStateStorage * ReplicationStateStorage
Definition DeltaCompressionBaselineManager.h:37
FInternalNetRefIndex MaxInternalNetRefIndex
Definition DeltaCompressionBaselineManager.h:40
FInternalNetRefIndex MaxNetObjectCount
Definition DeltaCompressionBaselineManager.h:39
FReplicationConnections * Connections
Definition DeltaCompressionBaselineManager.h:35
const FNetRefHandleManager * NetRefHandleManager
Definition DeltaCompressionBaselineManager.h:36
uint32 MaxDeltaCompressedObjectCount
Definition DeltaCompressionBaselineManager.h:41
Definition DeltaCompressionBaselineManager.h:50
Definition DeltaCompressionBaselineManager.h:45
const FChangeMaskCache * ChangeMaskCache
Definition DeltaCompressionBaselineManager.h:46