UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
NetExportContext.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"
6#include "Containers/Array.h"
7#include "Containers/Set.h"
12
13namespace UE::Net::Private
14{
15
17{
18public:
23
29
48
49public:
50
52
53 // Returns true if the Handle is acknowledged as delivered or if it is exported in the current batch
55
56 // Returns true if the Handle is acknowledged as delivered or if it is exported in the current batch
57 bool IsExported(FNetToken Token) const;
58
59 // Add a Handle to the current export batch
61
62 // Add a Handle to the current export batch
63 void AddExported(FNetToken Token);
64
65 // Add a reference to the current pending exports arr.
67
68 // Add a NetToken to the current pending export array
69 void AddPendingExport(FNetToken Token);
70
71 // Add NetTokens to the current pending export array
73
74 // Returns true if the Reference is in PendingExports array
75 bool IsPendingExport(const FNetObjectReference& Ref) const;
76
77 // Clear the list of pending exports
83
84 // Get current batch exports
85 const FNetExportContext::FBatchExports& GetBatchExports() const { return BatchExports; }
86
87private:
89
90 // Acknowledged exports
91 const FAcknowledgedExports& AcknowledgedExports;
92
93 // Exports for the current batch which we can treat as exported within the batch
94 FBatchExports& BatchExports;
95};
96
97// Rollback scope to be able to rollback exports with bitstream
99{
100public:
103
104 void Rollback();
105
106private:
108 int32 StartNumNetHandleExports;
109 int32 StartNumNetTokenExports;
110 int32 StartNumPendingExports;
111 int32 StartNumNetTokensPendingExports;
112};
113
116{
117 const FNetExportContext* ExportContext = Context.GetExportContext();
118
119 StartNumNetHandleExports = ExportContext ? ExportContext->BatchExports.HandlesExportedInCurrentBatch.Num() : 0;
120 StartNumNetTokenExports = ExportContext ? ExportContext->BatchExports.NetTokensExportedInCurrentBatch.Num() : 0;
121 StartNumPendingExports = ExportContext ? ExportContext->BatchExports.ReferencesPendingExportInCurrentBatch.Num() : 0;
122 StartNumNetTokensPendingExports = ExportContext ? ExportContext->BatchExports.NetTokensPendingExportInCurrentBatch.Num() : 0;
123}
124
126{
127 if (const FNetExportContext* ExportContext = Context.GetExportContext())
128 {
129 ExportContext->BatchExports.HandlesExportedInCurrentBatch.SetNum(StartNumNetHandleExports);
130 ExportContext->BatchExports.NetTokensExportedInCurrentBatch.SetNum(StartNumNetTokenExports);
131 ExportContext->BatchExports.NetTokensPendingExportInCurrentBatch.SetNum(StartNumNetTokensPendingExports);
132 ExportContext->BatchExports.ReferencesPendingExportInCurrentBatch.SetNum(StartNumPendingExports);
133 }
134}
135
137{
138 // Trigger rollback if we have encountered an error
139 if (Context.HasErrorOrOverflow())
140 {
141 Rollback();
142 }
143}
144
150
152{
153 return AcknowledgedExports.AcknowledgedExportedHandles.Contains(Handle) || (BatchExports.HandlesExportedInCurrentBatch.Find(Handle) != INDEX_NONE);
154}
155
160
162{
163 return AcknowledgedExports.AcknowledgedExportedNetTokens.Contains(Token) || (BatchExports.NetTokensExportedInCurrentBatch.Find(Token) != INDEX_NONE);
164}
165
167{
168 BatchExports.NetTokensExportedInCurrentBatch.Add(Token);
169}
170
175
177{
178 BatchExports.NetTokensPendingExportInCurrentBatch.AddUnique(NetToken);
179}
180
182{
183 for (const FNetToken& NetToken : NetTokens)
184 {
185 AddPendingExport(NetToken);
186 }
187}
188
190{
191 return BatchExports.ReferencesPendingExportInCurrentBatch.Contains(Ref);
192}
193
194
195}
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition ArrayView.h:139
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
bool Contains(const ComparisonType &Item) const
Definition Array.h:1518
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
UE_NODEBUG UE_FORCEINLINE_HINT bool Find(const ElementType &Item, SizeType &Index) const
Definition Array.h:1302
UE_FORCEINLINE_HINT SizeType AddUnique(ElementType &&Item)
Definition Array.h:2993
void Empty(SizeType Slack=0)
Definition Array.h:2273
Definition NetObjectReference.h:38
Definition NetRefHandle.h:25
Definition NetSerializationContext.h:31
bool HasErrorOrOverflow() const
Definition NetSerializationContext.h:197
Private::FNetExportContext * GetExportContext()
Definition NetSerializationContext.h:101
Definition NetToken.h:22
Definition NetExportContext.h:17
TArray< FNetToken, TInlineAllocator< 32 > > FNetTokenPendingExportArray
Definition NetExportContext.h:22
void AddExported(FNetRefHandle Handle)
Definition NetExportContext.h:156
bool IsExported(FNetRefHandle Handle) const
Definition NetExportContext.h:151
bool IsPendingExport(const FNetObjectReference &Ref) const
Definition NetExportContext.h:189
void AddPendingExports(TArrayView< const FNetToken > NetTokens)
Definition NetExportContext.h:181
void AddPendingExport(const FNetObjectReference &Ref)
Definition NetExportContext.h:171
TArray< FNetRefHandle, TInlineAllocator< 32 > > FExportsArray
Definition NetExportContext.h:19
const FNetExportContext::FBatchExports & GetBatchExports() const
Definition NetExportContext.h:85
void ClearPendingExports()
Definition NetExportContext.h:78
TArray< FNetToken, TInlineAllocator< 32 > > FNetTokenExportsArray
Definition NetExportContext.h:20
FNetExportContext(const FAcknowledgedExports &InAcknowledgedExports, FBatchExports &BatchExports)
Definition NetExportContext.h:145
TArray< FNetObjectReference, TInlineAllocator< 32 > > FPendingExportArray
Definition NetExportContext.h:21
Definition NetExportContext.h:99
~FNetExportRollbackScope()
Definition NetExportContext.h:136
void Rollback()
Definition NetExportContext.h:125
FNetExportRollbackScope(FNetSerializationContext &InContext)
Definition NetExportContext.h:114
Definition NetworkVersion.cpp:28
TSet< FNetToken > AcknowledgedExportedNetTokens
Definition NetExportContext.h:27
TSet< FNetRefHandle > AcknowledgedExportedHandles
Definition NetExportContext.h:26
FPendingExportArray ReferencesPendingExportInCurrentBatch
Definition NetExportContext.h:45
void Reset()
Definition NetExportContext.h:32
FNetTokenExportsArray NetTokensExportedInCurrentBatch
Definition NetExportContext.h:44
bool HasPendingExports() const
Definition NetExportContext.h:40
FExportsArray HandlesExportedInCurrentBatch
Definition NetExportContext.h:43
FNetTokenPendingExportArray NetTokensPendingExportInCurrentBatch
Definition NetExportContext.h:46