UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Particles.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
6#include "Chaos/Core.h"
8#include "Chaos/Vector.h"
9#include "ChaosArchive.h"
11
12
13#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
14#define PARTICLE_ITERATOR_RANGED_FOR_CHECK 1
15#else
16#define PARTICLE_ITERATOR_RANGED_FOR_CHECK 0
17#endif
18
19namespace Chaos
20{
21 template<class T, int d>
23
25 {
26 RemoveAtSwap, //O(1) but reorders particles relative to one another
27 Remove //Keeps particles relative to one another, but O(n)
28 };
29
30 template<class T, int d>
32 {
33 public:
35 : MRemoveParticleBehavior(ERemoveParticleBehavior::RemoveAtSwap)
36 {
37 AddArray(&MX);
38#if PARTICLE_ITERATOR_RANGED_FOR_CHECK
39 MDirtyValidationCount = 0;
40#endif
41 }
45 , MRemoveParticleBehavior(Other.MRemoveParticleBehavior)
46 {
47 AddParticles(Other.Size());
48 AddArray(&MX);
49 Other.MSize = 0;
50#if PARTICLE_ITERATOR_RANGED_FOR_CHECK
51 MDirtyValidationCount = 0;
52#endif
53 }
54
57 , MRemoveParticleBehavior(ERemoveParticleBehavior::RemoveAtSwap)
58 {
59 AddParticles(MX.Num());
60 AddArray(&MX);
61
62#if PARTICLE_ITERATOR_RANGED_FOR_CHECK
63 MDirtyValidationCount = 0;
64#endif
65 }
66
67 virtual ~TParticles()
68 {}
69
71 {
73 IncrementDirtyValidation();
74 }
75
76 void DestroyParticle(const int32 Idx)
77 {
78 if (MRemoveParticleBehavior == ERemoveParticleBehavior::RemoveAtSwap)
79 {
81 }
82 else
83 {
84 RemoveAtHelper(Idx, 1);
85 }
86 IncrementDirtyValidation();
87 }
88
89 ERemoveParticleBehavior RemoveParticleBehavior() const { return MRemoveParticleBehavior; }
90 ERemoveParticleBehavior& RemoveParticleBehavior() { return MRemoveParticleBehavior; }
91
93 {
95 IncrementDirtyValidation();
96 }
97
98 void Resize(const int32 Num)
99 {
101 IncrementDirtyValidation();
102 }
103
105 {
106 MX = MoveTemp(Other.MX);
107 ResizeHelper(Other.Size());
108 Other.MSize = 0;
109
110#if PARTICLE_ITERATOR_RANGED_FOR_CHECK
111 MDirtyValidationCount = 0;
112 ++Other.MDirtyValidationCount;
113#endif
114 return *this;
115 }
116
118 {
119 return MX;
120 }
121
123 {
124 bool bSerialize = true; //leftover from when we had view support
125 Ar << bSerialize;
126 if (ensureMsgf(bSerialize, TEXT("Cannot serialize shared views. Refactor needed to reduce memory")))
127 {
128 Ar << MX;
129 ResizeHelper(MX.Num());
130 }
131 IncrementDirtyValidation();
132 }
133
135 {
136 return MX;
137 }
138
140 {
141 return MX;
142 }
143
144 UE_DEPRECATED(5.4, "Use GetX instead")
145 const TVector<T, d>& X(const int32 Index) const
146 {
147 return MX[Index];
148 }
149
150 UE_DEPRECATED(5.4, "Use GetX or SetX instead")
151 TVector<T, d>& X(const int32 Index)
152 {
153 return MX[Index];
154 }
155
156 const TVector<T, d>& GetX(const int32 Index) const
157 {
158 return MX[Index];
159 }
160
161 void SetX(const int32 Index, const TVector<T, d>& InX)
162 {
163 MX[Index] = InX;
164 }
165
166 FString ToString(int32 index) const
167 {
168 return FString::Printf(TEXT("MX:%s"), *GetX(index).ToString());
169 }
170
172 {
173 uint32 OutHash = 0;
174 const int32 NumXEntries = MX.Num();
175
176 if(NumXEntries > 0)
177 {
179
180 for(int32 XIndex = 1; XIndex < NumXEntries; ++XIndex)
181 {
183 }
184 }
185
186 return OutHash;
187 }
188
190 {
191 return MX.GetAllocatedSize();
192 }
193
194#if PARTICLE_ITERATOR_RANGED_FOR_CHECK
195 int32 DirtyValidationCount() const { return MDirtyValidationCount; }
196#endif
197
199 FORCEINLINE const TArray<TVector<T, d>>& AllX() const { return MX; }
200
201 private:
203
204 ERemoveParticleBehavior MRemoveParticleBehavior;
205
206#if PARTICLE_ITERATOR_RANGED_FOR_CHECK
207 int32 MDirtyValidationCount;
208#endif
209
210 void IncrementDirtyValidation()
211 {
212#if PARTICLE_ITERATOR_RANGED_FOR_CHECK
213 ++MDirtyValidationCount;
214#endif
215 }
216
218 {
220 return Ar;
221 }
222 };
223
224 template<typename T, int d>
226 {
227 return InParticles.GetTypeHash();
228 }
229
243
245} // namespace Chaos
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define ensureMsgf( InExpression, InFormat,...)
Definition AssertionMacros.h:465
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
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
@ Num
Definition MetalRHIPrivate.h:234
constexpr uint32 HashCombine(uint32 A, uint32 C)
Definition TypeHash.h:36
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition ArrayCollectionArray.h:15
Definition ArrayCollection.h:10
void MoveToOtherArrayCollection(const int32 Index, TArrayCollection &Other)
Definition ArrayCollection.h:132
int32 AddArray(TArrayCollectionArrayBase *Array)
Definition ArrayCollection.h:36
void ResizeHelper(const int32 Num)
Definition ArrayCollection.h:93
void RemoveAtSwapHelper(const int32 Index)
Definition ArrayCollection.h:119
void AddElementsHelper(const int32 Num)
Definition ArrayCollection.h:84
void RemoveAtHelper(const int32 Index, const int32 Count)
Definition ArrayCollection.h:106
Definition Particles.h:22
Definition Particles.h:32
uint32 GetTypeHash() const
Definition Particles.h:171
void AddParticles(const int32 Num)
Definition Particles.h:70
void MoveToOtherParticles(const int32 Idx, TParticles< T, d > &Other)
Definition Particles.h:92
FORCEINLINE const TArray< TVector< T, d > > & AllX() const
Definition Particles.h:199
const TVector< T, d > & GetX(const int32 Index) const
Definition Particles.h:156
TParticles & operator=(TParticles< T, d > &&Other)
Definition Particles.h:104
int32 DirtyValidationCount() const
Definition Particles.h:195
const TArrayCollectionArray< TVector< T, d > > & XArray() const
Definition Particles.h:134
FORCEINLINE TArray< TVector< T, d > > & AllX()
Definition Particles.h:198
void Resize(const int32 Num)
Definition Particles.h:98
virtual ~TParticles()
Definition Particles.h:67
void Serialize(FArchive &Ar)
Definition Particles.h:122
TParticles(TParticles< T, d > &&Other)
Definition Particles.h:43
ERemoveParticleBehavior & RemoveParticleBehavior()
Definition Particles.h:90
ERemoveParticleBehavior RemoveParticleBehavior() const
Definition Particles.h:89
void DestroyParticle(const int32 Idx)
Definition Particles.h:76
const TArrayCollectionArray< TVector< T, d > > & X() const
Definition Particles.h:117
SIZE_T GetAllocatedSize() const
Definition Particles.h:189
FString ToString(int32 index) const
Definition Particles.h:166
void SetX(const int32 Index, const TVector< T, d > &InX)
Definition Particles.h:161
TParticles(const TParticles< T, d > &Other)=delete
TParticles()
Definition Particles.h:34
TParticles(TArray< TVector< T, d > > &&Positions)
Definition Particles.h:55
friend FArchive & operator<<(FArchive &Ar, TParticles< T, d > &InParticles)
Definition Particles.h:217
TArrayCollectionArray< TVector< T, d > > & XArray()
Definition Particles.h:139
Definition Vector.h:41
Definition Archive.h:1208
virtual void Serialize(void *V, int64 Length)
Definition Archive.h:1689
Definition Array.h:670
Definition SkeletalMeshComponent.h:307
ERemoveParticleBehavior
Definition Particles.h:25
EChaosCollisionTraceFlag
Definition Particles.h:231
FORCEINLINE uint32 GetTypeHash(const FParticleID &Unique)
Definition GeometryParticles.h:99
TParticles< FReal, 3 > FParticles
Definition ImplicitObject.h:35
uint32 GetTypeHash(const TBox< T > &Box)
Definition Box.h:1008
U16 Index
Definition radfft.cpp:71