UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
WorldLocations.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"
9#include "Math/Vector.h"
10#include "Misc/Optional.h"
11#include "WorldLocations.generated.h"
12
14
15namespace UE::Net::Private
16{
18 class FNetRefHandleManager;
19}
20
24UCLASS(Config=Engine)
26{
28
29public:
31 UPROPERTY(Config)
32 FVector MinPos = { -0.5f * 2097152.0f, -0.5f * 2097152.0f, -0.5f * 2097152.0f };
33
35 UPROPERTY(Config)
36 FVector MaxPos = { +0.5f * 2097152.0f, +0.5f * 2097152.0f, +0.5f * 2097152.0f };
37
39 UPROPERTY(Config)
40 float MaxNetCullDistance = 150000.f;
41};
42
43namespace UE::Net
44{
45
47{
48 TObjectPtr<UReplicationSystem> ReplicationSystem = nullptr;
49
50 UE::Net::Private::FInternalNetRefIndex MaxInternalNetRefIndex = 0;
51
53 uint32 PreallocatedStorageCount = 0;
54};
55
57{
58public:
59
62 {
65
67 float CullDistance = 0.0f;
68 };
69
70public:
71
72 void Init(const FWorldLocationsInitParams& InitParams);
73 void PostSendUpdate();
74
77 {
78 return ValidInfoIndexes.IsBitSet(ObjectIndex);
79 }
80
82 inline FVector GetWorldLocation(UE::Net::Private::FInternalNetRefIndex ObjectIndex) const;
83
85 inline float GetCullDistance(UE::Net::Private::FInternalNetRefIndex ObjectIndex) const;
86
89
91 void SetObjectInfo(UE::Net::Private::FInternalNetRefIndex ObjectIndex, const FVector& Location, float NetCullDistance);
92
94 void InitObjectInfoCache(UE::Net::Private::FInternalNetRefIndex ObjectIndex);
95
97 void RemoveObjectInfoCache(UE::Net::Private::FInternalNetRefIndex ObjectIndex);
98
105 {
106 ObjectsRequiringFrequentWorldLocationUpdate.SetBitValue(ObjectIndex, ValidInfoIndexes.GetBit(ObjectIndex) && bRequiresFrequentUpdate);
107 }
108
111 {
112 return ObjectsRequiringFrequentWorldLocationUpdate.GetBit(ObjectIndex);
113 }
114
119 bool SetCullDistanceOverride(UE::Net::Private::FInternalNetRefIndex ObjectIndex, float CullDistance);
120
125 bool ClearCullDistanceOverride(UE::Net::Private::FInternalNetRefIndex ObjectIndex);
126
129 {
130 return ValidInfoIndexes.IsBitSet(ObjectIndex) ? GetObjectInfo(ObjectIndex).CullDistanceOverride != FLT_MAX : false;
131 }
132
134 const FNetBitArrayView GetObjectsRequiringFrequentWorldLocationUpdate() const { return MakeNetBitArrayView(ObjectsRequiringFrequentWorldLocationUpdate); }
135
137 const FNetBitArrayView GetObjectsWithDirtyInfo() const { return MakeNetBitArrayView(ObjectsWithDirtyInfo); }
138
140 const FNetBitArrayView GetObjectsWithWorldInfo() const { return MakeNetBitArrayView(ValidInfoIndexes); }
141
144
146 void LockDirtyInfoList(bool bLock);
147
149 const FVector& GetWorldMinPos() const { return MinWorldPos; };
150 const FVector& GetWorldMaxPos() const { return MaxWorldPos; };
151
154 {
155 return Position.BoundToBox(GetWorldMinPos(), GetWorldMaxPos());
156 }
157
159 bool IsValidLocation(const FVector& Location) const
160 {
161 return (Location.X >= MinWorldPos.X && Location.Y >= MinWorldPos.Y && Location.Z >= MinWorldPos.Z &&
162 Location.X <= MaxWorldPos.X && Location.Y <= MaxWorldPos.Y && Location.Z <= MaxWorldPos.Z);
163 }
164
165 void OnMaxInternalNetRefIndexIncreased(UE::Net::Private::FInternalNetRefIndex NewMaxInternalIndex);
166
167private:
168
170 struct FObjectInfo
171 {
173 FVector WorldLocation = FVector::ZeroVector;
174
176 float CullDistance = 0.0f;
177
179 float CullDistanceOverride = FLT_MAX;
180 };
181
182 enum : uint32
183 {
184 StorageElementsPerChunk = 65536U / sizeof(FObjectInfo),
185 };
186
187private:
188
189 const int32 GetStorageIndex(UE::Net::Private::FInternalNetRefIndex ObjectIndex) const
190 {
191 return StorageIndexes[ObjectIndex];
192 }
193
194 const FObjectInfo& GetObjectInfo(UE::Net::Private::FInternalNetRefIndex ObjectIndex) const
195 {
196 return StoredObjectInfo[GetStorageIndex(ObjectIndex)];
197 }
198
199 FObjectInfo& GetObjectInfo(UE::Net::Private::FInternalNetRefIndex ObjectIndex)
200 {
201 return StoredObjectInfo[GetStorageIndex(ObjectIndex)];
202 }
203
204private:
205
207 FNetBitArray ValidInfoIndexes;
208
210 FNetBitArray ObjectsWithDirtyInfo;
211
213 FNetBitArray ObjectsRequiringFrequentWorldLocationUpdate;
214
216 TArray<int32> StorageIndexes;
217
219 FNetBitArray ReservedStorageSlot;
220
221 TNetChunkedArray<FObjectInfo, StorageElementsPerChunk> StoredObjectInfo;
222
223 const UE::Net::Private::FNetRefHandleManager* NetRefHandleManager = nullptr;
224
226 FVector MinWorldPos;
227 FVector MaxWorldPos;
228 float MaxNetCullDistance;
229
231 bool bLockdownDirtyList = false;
232};
233
234inline FVector FWorldLocations::GetWorldLocation(UE::Net::Private::FInternalNetRefIndex ObjectIndex) const
235{
236 return ValidInfoIndexes.IsBitSet(ObjectIndex) ? GetObjectInfo(ObjectIndex).WorldLocation : FVector::Zero();
237}
238
239inline float FWorldLocations::GetCullDistance(UE::Net::Private::FInternalNetRefIndex ObjectIndex) const
240{
241 if (ValidInfoIndexes.IsBitSet(ObjectIndex))
242 {
243 const FObjectInfo& Info = GetObjectInfo(ObjectIndex);
244 return Info.CullDistanceOverride == FLT_MAX ? Info.CullDistance : Info.CullDistanceOverride;
245 }
246
247 return 0.0f;
248}
249
250inline TOptional<FWorldLocations::FWorldInfo> FWorldLocations::GetWorldInfo(UE::Net::Private::FInternalNetRefIndex ObjectIndex) const
251{
252 if (ValidInfoIndexes.IsBitSet(ObjectIndex))
253 {
254 const FObjectInfo& Info = GetObjectInfo(ObjectIndex);
255 return FWorldInfo
256 {
257 .WorldLocation = Info.WorldLocation,
258 .CullDistance = Info.CullDistanceOverride == FLT_MAX ? Info.CullDistance : Info.CullDistanceOverride,
259 };
260 }
261
262 return NullOpt;
263}
264
265} // end namespace UE::Net
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
constexpr FNullOpt NullOpt
Definition Optional.h:15
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
void Init()
Definition LockFreeList.h:4
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UCLASS(...)
Definition ObjectMacros.h:776
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Engine.Build.cs:7
Definition Array.h:670
Definition NetBitArray.h:337
Definition WorldLocations.h:57
const FNetBitArrayView GetObjectsWithWorldInfo() const
Definition WorldLocations.h:140
bool HasInfoForObject(UE::Net::Private::FInternalNetRefIndex ObjectIndex) const
Definition WorldLocations.h:76
const FVector & GetWorldMaxPos() const
Definition WorldLocations.h:150
const FVector & GetWorldMinPos() const
Definition WorldLocations.h:149
const FNetBitArrayView GetObjectsRequiringFrequentWorldLocationUpdate() const
Definition WorldLocations.h:134
void SetObjectRequiresFrequentWorldLocationUpdate(UE::Net::Private::FInternalNetRefIndex ObjectIndex, bool bRequiresFrequentUpdate)
Definition WorldLocations.h:104
bool HasCullDistanceOverride(UE::Net::Private::FInternalNetRefIndex ObjectIndex) const
Definition WorldLocations.h:128
bool IsValidLocation(const FVector &Location) const
Definition WorldLocations.h:159
FVector ClampPositionToBoundary(const FVector &Position) const
Definition WorldLocations.h:153
const FNetBitArrayView GetObjectsWithDirtyInfo() const
Definition WorldLocations.h:137
bool GetObjectRequiresFrequentWorldLocationUpdate(UE::Net::Private::FInternalNetRefIndex ObjectIndex) const
Definition WorldLocations.h:110
Definition NetRefHandleManager.h:72
Definition Object.h:95
Definition ReplicationSystem.h:70
Definition WorldLocations.h:26
Definition NetworkVersion.cpp:28
uint32 FInternalNetRefIndex
Definition ReplicationStateStorage.h:20
FNetBitArrayView MakeNetBitArrayView(const FNetBitArrayView::StorageWordType *Storage, uint32 BitCount)
Definition NetBitArray.h:1677
Definition AdvancedWidgetsModule.cpp:13
Definition ObjectPtr.h:488
Definition Optional.h:131
static TVector< double > Zero()
Definition Vector.h:112
static CORE_API const TVector< double > ZeroVector
Definition Vector.h:79
TVector< T > BoundToBox(const TVector< T > &Min, const TVector< T > &Max) const
Definition Vector.h:1872
Definition WorldLocations.h:47
Definition WorldLocations.h:62
FVector WorldLocation
Definition WorldLocations.h:64