UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ReplicationStateStorage.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
11#if UE_NET_VALIDATE_DC_BASELINES
12#include "Containers/Map.h"
13#endif
14
15namespace UE::Net
16{
17 struct FReplicationProtocol;
18 namespace Private
19 {
22 };
23}
24
25namespace UE::Net
26{
27
37
46
48{
49public:
51 {
52 public:
53 bool IsValid() const { return ReservedStorage != nullptr; }
54
55 // The uninitalized memory that was reserved.
57 /*
58 * The state presumed to be cloned if the reservation is committed. N.B.
59 * Can only be valid if CurrentSendState or CurrentRecvState was the base.
60 */
61 const uint8* BaselineBaseStorage = nullptr;
62 };
63
64public:
67
69 void Deinit();
70
71 /*
72 * Returns a buffer to a state of the requested type. Only supports CurrentSendState and CurrentRecvState. May return null
73 * for example if requesting CurrentSendState on the receiving end. Returned pointer may not be written to.
74 */
75 const uint8* GetState(uint32 ObjectIndex, EReplicationStateType Base) const;
76
77 /*
78 * Allocates an internal state buffer large enough to accommodate the entire internal state, including init state,
79 * for an object and initializes it to the desired state, using cloning if needed.
80 * Returns a non-null pointer if there's memory to fulfill the request.
81 * If the requested state type is "Uninitialized" the memory must be properly initialized, zeroed or copied from other state,
82 * before calling FreeBaseline!
83 */
85 /* Frees a baseline allocated with AllocBaseline(). The Storage must have been properly initialized as any dynamic state will be freed as well. */
86 void FreeBaseline(uint32 ObjectIndex, uint8* Storage);
87
88 /*
89 * Allocates memory for a baseline but does not initialize it.
90 * The memory should either be committed or canceled. A committed baseline
91 * must later be freed.
92 */
94 /* Cancels a baseline reservation. The pointer is invalid to use after this call. */
95 void CancelBaselineReservation(uint32 ObjectIndex, uint8* Storage);
96 /*
97 * Initializes a buffer previously returned by ReserveBaseline. The Base must identical to that in the ReserveBaseline call.
98 * The baseline should later be freed by FreeBaseline.
99 */
100 void CommitBaselineReservation(uint32 ObjectIndex, uint8* Storage, EReplicationStateType Base);
101
104
105private:
106 using ObjectInfoIndexType = uint16;
107
108 enum : unsigned
109 {
110 InvalidObjectInfoIndex = 0,
111
112 ObjectInfoGrowCount = 256,
113 };
114
115 enum class EStateBufferType : unsigned
116 {
117 SendState,
118 RecvState,
119
120 Count
121 };
122
123 struct FPerObjectInfo
124 {
125 const FReplicationProtocol* Protocol = nullptr;
126 const uint8* StateBuffers[(unsigned)EStateBufferType::Count] = {};
127 uint16 AllocationCount = 0;
128 };
129
130 FPerObjectInfo* GetOrCreatePerObjectInfoForObject(uint32 ObjectIndex);
131 FPerObjectInfo* GetPerObjectInfoForObject(uint32 ObjectIndex);
132 const FPerObjectInfo* GetPerObjectInfoForObject(uint32 ObjectIndex) const;
133 void FreePerObjectInfoForObject(uint32 ObjectIndex);
134
135 ObjectInfoIndexType AllocPerObjectInfo();
136 void FreePerObjectInfo(ObjectInfoIndexType Index);
137
138 void CloneState(const FReplicationProtocol* Protocol, uint8* TargetState, const uint8* SourceState);
139 void CloneDefaultState(const FReplicationProtocol* Protocol, uint8* TargetState);
140 void FreeState(const FReplicationProtocol* Protocol, uint8* State);
141
142private:
143#if UE_NET_VALIDATE_DC_BASELINES
145#endif
146
147 const Private::FNetRefHandleManager* NetRefHandleManager = nullptr;
148
149 FNetSerializationContext SerializationContext;
150 Private::FInternalNetSerializationContext InternalSerializationContext;
151
152 FNetBitArray UsedPerObjectInfos;
153 TArray<ObjectInfoIndexType> ObjectIndexToObjectInfoIndex;
154 TChunkedArray<FPerObjectInfo, ObjectInfoGrowCount*sizeof(FPerObjectInfo)> ObjectInfos;
155};
156
157}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_FORCEINLINE_HINT uint64 GetState() const
Definition LockFreeList.h:46
void Init()
Definition LockFreeList.h:4
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 Array.h:670
Definition ChunkedArray.h:56
Definition ReplicationStateStorage.h:51
const uint8 * BaselineBaseStorage
Definition ReplicationStateStorage.h:61
bool IsValid() const
Definition ReplicationStateStorage.h:53
uint8 * ReservedStorage
Definition ReplicationStateStorage.h:56
Definition ReplicationStateStorage.h:48
~FReplicationStateStorage()
Definition ReplicationStateStorage.cpp:21
void CommitBaselineReservation(uint32 ObjectIndex, uint8 *Storage, EReplicationStateType Base)
Definition ReplicationStateStorage.cpp:271
void CancelBaselineReservation(uint32 ObjectIndex, uint8 *Storage)
Definition ReplicationStateStorage.cpp:248
void OnMaxInternalNetRefIndexIncreased(UE::Net::Private::FInternalNetRefIndex NewMaxInternalIndex)
Definition ReplicationStateStorage.cpp:50
FReplicationStateStorage()
Definition ReplicationStateStorage.cpp:16
void Deinit()
Definition ReplicationStateStorage.cpp:43
FBaselineReservation ReserveBaseline(uint32 ObjectIndex, EReplicationStateType Base)
Definition ReplicationStateStorage.cpp:193
uint8 * AllocBaseline(uint32 ObjectIndex, EReplicationStateType Base)
Definition ReplicationStateStorage.cpp:102
void FreeBaseline(uint32 ObjectIndex, uint8 *Storage)
Definition ReplicationStateStorage.cpp:169
Definition NetRefHandleManager.h:72
Definition ReplicationSystem.h:70
Definition OverriddenPropertySet.cpp:45
uint32 FInternalNetRefIndex
Definition ReplicationStateStorage.h:20
Definition NetworkVersion.cpp:28
EReplicationStateType
Definition ReplicationStateStorage.h:39
U16 Index
Definition radfft.cpp:71
Definition ReplicationStateStorage.h:29
uint32 MaxDeltaCompressedObjectCount
Definition ReplicationStateStorage.h:35
UReplicationSystem * ReplicationSystem
Definition ReplicationStateStorage.h:30
uint32 MaxConnectionCount
Definition ReplicationStateStorage.h:34
uint32 MaxObjectCount
Definition ReplicationStateStorage.h:32
const Private::FNetRefHandleManager * NetRefHandleManager
Definition ReplicationStateStorage.h:31
uint32 MaxInternalNetRefIndex
Definition ReplicationStateStorage.h:33