UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ArrayND.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4// HEADER_UNIT_SKIP - Bad include. Some headers are in Chaos while this is in ChaosCore
5
6#include "Chaos/Core.h"
7#include "Chaos/Array.h"
8#include "Chaos/UniformGrid.h"
9#include "Chaos/Vector.h"
11#include "Chaos/ChaosArchive.h"
12
13namespace Chaos
14{
15
16template <typename T>
21
23{
24 Array.BulkSerialize(Ar);
25}
26
28{
29 Array.BulkSerialize(Ar);
30}
31
32inline float ConvertDoubleToFloat(double DoubleValue)
33{
34 return (float)DoubleValue; // LWC_TODO : Perf pessimization
35}
36
38{
39 return TVec3<float>((float)DoubleValue.X, (float)DoubleValue.Y, (float)DoubleValue.Z); // LWC_TODO : Perf pessimization
40}
41
42inline double ConvertFloatToDouble(float FloatValue)
43{
44 return (double)FloatValue;
45}
46
48{
49 return TVec3<double>((double)FloatValue.X, (double)FloatValue.Y, (double)FloatValue.Z);
50}
51
52// LWC_TODO : Perf pessimization : this is sub-optimal but will do until we sort the serialization out
53template<typename DOUBLE_T, typename FLOAT_T>
55{
57 if (Ar.IsSaving())
58 {
60 for (int i = 0; i < DoubleTypedArray.Num(); ++i)
61 {
63 }
64 }
65
67
68 if (Ar.IsLoading())
69 {
70 DoubleTypedArray.SetNumUninitialized(FloatTypedArray.Num());
71 for (int i = 0; i < FloatTypedArray.Num(); ++i)
72 {
74 }
75 }
76}
77
78// LWC_TODO : Perf pessimization : this is sub-optimal but will do until we sort the serialization out
83
84// LWC_TODO : Perf pessimization : this is sub-optimal but will do until we sort the serialization out
89
90template<class T_DERIVED, class T, int d>
92{
93 public:
94
96
102#if COMPILE_WITHOUT_UNREAL_SUPPORT
103 FORCEINLINE TArrayNDBase(std::istream& Stream)
104 : MCounts(Stream)
105 {
106 MArray.SetNum(MCounts[0] * MCounts[1] * MCounts[2]);
107 Stream.read(reinterpret_cast<char*>(MArray.GetData()), sizeof(T) * MArray.Num());
108 }
109 FORCEINLINE void Write(std::ostream& Stream) const
110 {
111 MCounts.Write(Stream);
112 Stream.write(reinterpret_cast<const char*>(MArray.GetData()), sizeof(T) * MArray.Num());
113 }
114#endif
129
131 {
132 Ar << MCounts;
133 Ar << MArray;
134 }
135
137 {
138 MCounts = Other.MCounts;
139 MArray = Other.MArray;
140 return *this;
141 }
142
150 FORCEINLINE void Copy(const TArrayNDBase<T_DERIVED, T, d>& Source) { MCounts = Source.MCounts; MArray = Source.MArray; }
151 FORCEINLINE void Fill(const T& Value)
152 {
153 for (auto& Elem : MArray)
154 {
155 Elem = Value;
156 }
157 }
158 FORCEINLINE const T& operator[](const int32 i) const { return MArray[i]; }
159 FORCEINLINE T& operator[](const int32 i) { return MArray[i]; }
160
161 FORCEINLINE int32 Num() const { return MArray.Num(); }
163
165 {
167 MArray.Reset();
168 }
169
171 FORCEINLINE const T* GetData() const { return MArray.GetData(); }
172
173 protected:
176};
177
178template <typename Derived, typename T, int d>
184
185template <typename Derived, typename T, int d>
191
192template<class T, int d>
193class TArrayND : public TArrayNDBase<TArrayND<T, d>, T, d>
194{
195 typedef TArrayNDBase<TArrayND<T, d>, T, d> Base;
196 using Base::MArray;
197 using Base::MCounts;
198
199 public:
206#if COMPILE_WITHOUT_UNREAL_SUPPORT
207 FORCEINLINE TArrayND(std::istream& Stream)
208 : Base(Stream) {}
209#endif
211 {
213 return *this;
214 }
221 {
222 int32 SingleIndex = 0;
223 int32 count = 1;
224 for (int32 i = d - 1; i >= 0; ++i)
225 {
226 SingleIndex += count * Index[i];
227 count *= MCounts[i];
228 }
229 return MArray[SingleIndex];
230 }
231};
232
233template<class T>
234class TArrayND<T, 3> : public TArrayNDBase<TArrayND<T, 3>, T, 3>
235{
236 typedef TArrayNDBase<TArrayND<T, 3>, T, 3> Base;
237 using Base::MArray;
238 using Base::MCounts;
239
240 public:
241#if UE_BUILD_SHIPPING || UE_BUILD_TEST
243#else
245#endif
246 template<typename U>
248 {
249 SetCounts(Grid, NodeValues);
250 }
252 {
253 SetCounts(Counts);
254 }
260#if COMPILE_WITHOUT_UNREAL_SUPPORT
261 FORCEINLINE TArrayND(std::istream& Stream)
262 : Base(Stream) {}
263#endif
265 {
267 return *this;
268 }
274 FORCEINLINE T& operator()(const TVec3<int32>& Index) { return (*this)(Index[0], Index[1], Index[2]); }
275 FORCEINLINE const T& operator()(const TVec3<int32>& Index) const { return (*this)(Index[0], Index[1], Index[2]); }
276 FORCEINLINE T& operator()(const int32& x, const int32& y, const int32& z)
277 {
278 return MArray[(x * MCounts[1] + y) * MCounts[2] + z];
279 }
280 FORCEINLINE const T& operator()(const int32& x, const int32& y, const int32& z) const
281 {
282 return MArray[(x * MCounts[1] + y) * MCounts[2] + z];
283 }
284
286 {
287 MCounts = Counts;
288 MArray.SetNum(MCounts[0] * MCounts[1] * MCounts[2]);
289 }
290
291 template<typename U>
293 {
294 MCounts = NodeValues ? Grid.NodeCounts() : Grid.Counts();
295 MArray.SetNum(MCounts[0] * MCounts[1] * MCounts[2]);
296 }
297
298};
299
300#if COMPILE_WITHOUT_UNREAL_SUPPORT
301template<>
302class TArrayND<bool, 3> : public TArrayNDBase<TArrayND<bool, 3>, char, 3>
303{
304 typedef bool T;
305 typedef TArrayNDBase<TArrayND<T, 3>, char, 3> Base;
306 using Base::MArray;
307 using Base::MCounts;
308
309 public:
310 FORCEINLINE TArrayND() {}
312 {
313 MCounts = grid.Counts();
314 MArray.SetNum(MCounts[0] * MCounts[1] * MCounts[2]);
315 }
317 {
318 MCounts = Counts;
319 MArray.SetNum(MCounts[0] * MCounts[1] * MCounts[2]);
320 }
322 : Base(Counts, Array) {}
323 FORCEINLINE TArrayND(const TArrayND<T, 3>& Other) = delete;
324 FORCEINLINE TArrayND(TArrayND<T, 3>&& Other)
325 : Base(std::move(Other)) {}
326 FORCEINLINE char& operator()(const Vector<int32, 3>& Index) { return (*this)(Index[0], Index[1], Index[2]); }
327 FORCEINLINE const T& operator()(const Vector<int32, 3>& Index) const { return (*this)(Index[0], Index[1], Index[2]); }
328 FORCEINLINE char& operator()(const int32& x, const int32& y, const int32& z)
329 {
330 return MArray[(x * MCounts[1] + y) * MCounts[2] + z];
331 }
332 FORCEINLINE const T& operator()(const int32& x, const int32& y, const int32& z) const
333 {
334 return MArray[(x * MCounts[1] + y) * MCounts[2] + z];
335 }
336};
337#endif
338}
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define check(expr)
Definition AssertionMacros.h:314
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
const bool
Definition NetworkReplayStreaming.h:178
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition ChaosArchive.h:167
Definition ArrayND.h:92
FORCEINLINE TArrayNDBase(const TArrayNDBase< T_DERIVED, T, d > &Other)=delete
FORCEINLINE void Fill(const T &Value)
Definition ArrayND.h:151
void Serialize(FChaosArchive &Ar)
Definition ArrayND.h:130
FORCEINLINE T & operator[](const int32 i)
Definition ArrayND.h:159
FORCEINLINE TArrayNDBase< T_DERIVED, T, d > & operator=(const TArrayNDBase< T_DERIVED, T, d > &Other)
Definition ArrayND.h:136
TArray< T > MArray
Definition ArrayND.h:175
FORCEINLINE int32 Num() const
Definition ArrayND.h:161
void Serialize(FArchive &Ar)
Definition ArrayND.h:115
FORCEINLINE void Copy(const TArrayNDBase< T_DERIVED, T, d > &Source)
Definition ArrayND.h:150
FORCEINLINE TArrayNDBase(TArrayNDBase< T_DERIVED, T, d > &&Other)
Definition ArrayND.h:100
TVector< int32, d > MCounts
Definition ArrayND.h:174
FORCEINLINE const T * GetData() const
Definition ArrayND.h:171
FORCEINLINE TVector< int32, d > Counts() const
Definition ArrayND.h:162
FORCEINLINE T * GetData()
Definition ArrayND.h:170
FORCEINLINE TArrayNDBase()
Definition ArrayND.h:95
FORCEINLINE const T & operator[](const int32 i) const
Definition ArrayND.h:158
FORCEINLINE T_DERIVED Copy() const
Definition ArrayND.h:149
FORCEINLINE TArrayNDBase(const TVector< int32, d > &Counts, const TArray< T > &Array)
Definition ArrayND.h:97
FORCEINLINE void Reset()
Definition ArrayND.h:164
FORCEINLINE TArrayNDBase< T_DERIVED, T, d > & operator=(TArrayNDBase< T_DERIVED, T, d > &&Other)
Definition ArrayND.h:143
FORCEINLINE TArrayND(const TArrayND< T, 3 > &Other)=delete
FORCEINLINE TArrayND(const TVec3< int32 > &Counts, const TArray< T > &Array)
Definition ArrayND.h:255
FORCEINLINE T & operator()(const TVec3< int32 > &Index)
Definition ArrayND.h:274
FORCEINLINE TArrayND(TArrayND< T, 3 > &&Other)
Definition ArrayND.h:258
FORCEINLINE TArrayND< T, 3 > & operator=(TArrayND< T, 3 > &&Other)
Definition ArrayND.h:269
FORCEINLINE TArrayND()
Definition ArrayND.h:244
FORCEINLINE TArrayND(const TVec3< int32 > &Counts)
Definition ArrayND.h:251
FORCEINLINE void SetCounts(const TVector< int32, 3 > &Counts)
Definition ArrayND.h:285
FORCEINLINE void SetCounts(const TUniformGrid< U, 3 > &Grid, bool NodeValues=false)
Definition ArrayND.h:292
FORCEINLINE T & operator()(const int32 &x, const int32 &y, const int32 &z)
Definition ArrayND.h:276
FORCEINLINE TArrayND< T, 3 > & operator=(const TArrayND< T, 3 > &Other)
Definition ArrayND.h:264
FORCEINLINE TArrayND(const TUniformGrid< U, 3 > &Grid, bool NodeValues=false)
Definition ArrayND.h:247
FORCEINLINE const T & operator()(const int32 &x, const int32 &y, const int32 &z) const
Definition ArrayND.h:280
FORCEINLINE const T & operator()(const TVec3< int32 > &Index) const
Definition ArrayND.h:275
Definition ArrayND.h:194
FORCEINLINE TArrayND(const TArrayND< T, d > &Other)=delete
FORCEINLINE TArrayND< T, d > & operator=(const TArrayND< T, d > &Other)
Definition ArrayND.h:210
FORCEINLINE TArrayND(TArrayND< T, d > &&Other)
Definition ArrayND.h:204
FORCEINLINE TArrayND< T, d > & operator=(TArrayND< T, d > &&Other)
Definition ArrayND.h:215
FORCEINLINE TArrayND(const TVector< int32, d > &Counts, const TArray< T > &Array)
Definition ArrayND.h:201
FORCEINLINE T & operator()(const TVector< int32, d > &Index)
Definition ArrayND.h:220
FORCEINLINE TArrayND(const TVector< int32, d > &Counts)
Definition ArrayND.h:200
Definition UniformGrid.h:267
Definition Vector.h:1000
T X
Definition Vector.h:1168
T Z
Definition Vector.h:1170
T Y
Definition Vector.h:1169
Definition Vector.h:41
int32 Num() const
Definition Vector.h:150
virtual void Serialize(void *V, int64 Length) override
Definition ArchiveProxy.h:97
Definition Archive.h:1208
virtual CORE_API void UsingCustomVersion(const struct FGuid &Guid)
Definition Archive.cpp:590
UE_FORCEINLINE_HINT bool IsLoading() const
Definition Archive.h:236
CORE_API int32 CustomVer(const struct FGuid &Key) const
Definition Archive.cpp:602
UE_FORCEINLINE_HINT bool IsSaving() const
Definition Archive.h:248
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Reset(SizeType NewSize=0)
Definition Array.h:2246
UE_NODEBUG UE_FORCEINLINE_HINT ElementType * GetData() UE_LIFETIMEBOUND
Definition Array.h:1027
void SetNum(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2308
void SetNumUninitialized(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2369
Definition SkeletalMeshComponent.h:307
float ConvertDoubleToFloat(double DoubleValue)
Definition ArrayND.h:32
FChaosArchive & operator<<(FChaosArchive &Ar, FRigidParticleControlFlags &Flags)
Definition RigidParticleControlFlags.cpp:15
void TryBulkSerializeArrayNDBaseForDoubles(FArchive &Ar, TArray< DOUBLE_T > &DoubleTypedArray)
Definition ArrayND.h:54
double ConvertFloatToDouble(float FloatValue)
Definition ArrayND.h:42
void TryBulkSerializeArrayNDBase(FArchive &Ar, TArray< T > &Array)
Definition ArrayND.h:17
U16 Index
Definition radfft.cpp:71
CORE_API static const FGuid GUID
Definition DestructionObjectVersion.h:52
@ BulkSerializeArrays
Definition DestructionObjectVersion.h:37