UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SolverBodyContainer.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
6#include "Chaos/ObjectPool.h"
10
11#include "Containers/Array.h"
12#include "Containers/Map.h"
13
14namespace Chaos
15{
16 class FSolverBody;
17 class FSolverBodyContainer;
18
37 {
38 private:
39 // Settings for the Solver Body array.
40 static const int32 NumBodiesPerChunk = 256;
41 static const int32 BodyArrayChunkSize = NumBodiesPerChunk * sizeof(FSolverBody);
42
43 public:
45
47 : bLocked(true)
48 {
49 }
50
51 // Clear the bodies array and allocate enough space for at least MaxBodies bodies.
52 // @param MaxBodies The number of bodies that will get added to the container. The container asserts if we attempt to add more than this.
53 inline void Reset(int MaxBodies)
54 {
55 SolverBodies.Reset();
56 Particles.Reset(MaxBodies);
57 ParticleToIndexMap.Reset();
58 bLocked = false;
59 }
60
61 // The number of bodies in the container
62 inline int Num() const
63 {
64 return SolverBodies.Num();
65 }
66
67 // The maximum number of bodies the container can hold (until Reset() is called again)
68 inline int Max() const
69 {
71 }
72
73 // Get the particle associated with the solver body at Index
75 {
76 return Particles[Index];
77 }
78
79 // Get the solver body at Index
80 inline const FSolverBody& GetSolverBody(const int32 Index) const
81 {
82 return SolverBodies[Index];
83 }
84
85 // Get the solver body at Index
87 {
88 return SolverBodies[Index];
89 }
90
91 // Add a solver body to represent the solver state of the particle
92 // This should ideally be called in the order in which the bodies will be accessed
93 // (or as close as we can get, given most constraints access 2 bodies so there is no perfect order)
94 // NOTE: This does not populate the solver body with any data from the particle - we must also call
95 // GatherInput for that to happen (GatherInput is highly parallizable but FindOrAdd is not)
97
98 // Collect all the data we need from the particles represented by our SolverBodies
99 void GatherInput(const FReal Dt, const int32 BeginIndex, const int32 EndIndex);
100
101 // Scatter the solver results back to the particles represented by our SolverBodies. Range version used for parallization.
102 void ScatterOutput(const int32 BeginIndex, const int32 EndIndex);
103
104 // Recalculate the velocities of all bodies based on their transform deltas
106
107 // Apply accumulated transform deltas to the body transforms
108 void ApplyCorrections();
109
110 // Can be called after ApplyCorrections to update inertia to match the current transform
112
113 // Indicate that no more bodies should be added until the next tick (when Reset is called).
114 // Used to ensure that no bodies are added in parallel calls to GatherInput.
115 void Lock()
116 {
117 bLocked = true;
118 }
119
120 // Used to AB test solvers - not intended for general use (very expensive!)
122 {
123 Dest.SolverBodies = SolverBodies;
124 Dest.Particles = Particles;
125 Dest.ParticleToIndexMap = ParticleToIndexMap;
126 Dest.bLocked = bLocked;
127 }
128
129 private:
131
132 // All the solver bodies
133 FSolverBodyArray SolverBodies;
134
135 // The particles that map to each solver body
137
138 // Used to determine if a (non-dynamic) body is already present in the container.
139 // Dynamic bodies are not in this map - the particle stores its index in this case because
140 // dynamic bodies can only be in one island whereas non-dynamics may be const-referenced in many.
141 TMap<FGenericParticleHandle, int32> ParticleToIndexMap;
142
143 // To trap incorrect use of the solve bodies. We do not support adding bodies once we have started
144 // to call GatherInput because GatherInput is parallelized but FindOrAdd is not
145 bool bLocked;
146 };
147
148}
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
return true
Definition ExternalRpcRegistry.cpp:601
Definition ParticleHandle.h:2590
Definition SolverBodyContainer.h:37
void ApplyCorrections()
Definition SolverBodyContainer.cpp:183
int Num() const
Definition SolverBodyContainer.h:62
Private::TChaosChunkedArray< FSolverBody, BodyArrayChunkSize > FSolverBodyArray
Definition SolverBodyContainer.h:44
void CopyTo(FSolverBodyContainer &Dest)
Definition SolverBodyContainer.h:121
FGeometryParticleHandle * GetParticle(const int32 Index) const
Definition SolverBodyContainer.h:74
FSolverBody & GetSolverBody(const int32 Index)
Definition SolverBodyContainer.h:86
FSolverBody * FindOrAdd(FGenericParticleHandle InParticle)
Definition SolverBodyContainer.cpp:105
void Reset(int MaxBodies)
Definition SolverBodyContainer.h:53
void GatherInput(const FReal Dt, const int32 BeginIndex, const int32 EndIndex)
Definition SolverBodyContainer.cpp:149
void Lock()
Definition SolverBodyContainer.h:115
const FSolverBody & GetSolverBody(const int32 Index) const
Definition SolverBodyContainer.h:80
int Max() const
Definition SolverBodyContainer.h:68
FSolverBodyContainer()
Definition SolverBodyContainer.h:46
void SetImplicitVelocities(FReal Dt)
Definition SolverBodyContainer.cpp:175
void UpdateRotationDependentState()
Definition SolverBodyContainer.cpp:191
void ScatterOutput(const int32 BeginIndex, const int32 EndIndex)
Definition SolverBodyContainer.cpp:160
Definition SolverBody.h:99
void Reset()
Definition ChunkedArray.h:16
Definition ParticleHandle.h:436
Definition Array.h:670
int32 Num() const
Definition ChunkedArray.h:164
Definition UnrealString.h.inl:34
Definition SkeletalMeshComponent.h:307
FRealDouble FReal
Definition Real.h:22
U16 Index
Definition radfft.cpp:71
Definition NumericLimits.h:41