UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
JointConstraintProxy.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
11#include "PhysicsCoreTypes.h"
12#include "Chaos/Defines.h"
14#include "Framework/Threading.h"
16#include "RewindData.h"
17
18namespace Chaos
19{
20class FJointConstraint;
21
22class FPBDRigidsEvolutionGBF;
23
24struct FDirtyJointConstraintData;
25
26template <bool bExternal>
27class TThreadedJointConstraintPhysicsProxyBase;
28
31
33{
34 using Base = IPhysicsProxyBase;
35
36public:
39
41
42 //
43 // Lifespan Management
44 //
45
47
49
51
53
55
60
65
66 //Note this is a pointer because the internal handle may have already been deleted
71
72 //Note this is a pointer because the internal handle may have already been deleted
74 {
75 return GetHandle() == nullptr ? nullptr : (const Chaos::FJointConstraintHandle_Internal*)this;
76 }
77
78
79 //
80 // Member Access
81 //
82
83 FPBDJointConstraintHandle* GetHandle() { return Constraint_PT; }
84 const FPBDJointConstraintHandle* GetHandle() const { return Constraint_PT; }
85
86 virtual void* GetHandleUnsafe() const override { return Constraint_PT; }
87
89
90 FJointConstraint* GetConstraint(){ return Constraint_GT; }
91 const FJointConstraint* GetConstraint() const { return Constraint_GT; }
92
93 //
94 // Threading API
95 //
96
97
99
100
102
103private:
104 FJointConstraint* Constraint_GT;
105 FPBDJointConstraintHandle* Constraint_PT;
106 FParticlePair OriginalParticleHandles_PT;
107 bool bInitialized = false;
108};
109
110
112template <bool bExternal>
114{
115public:
116
117#define CHAOS_INNER_JOINT_PROPERTY(OuterProp, FuncName, Inner, InnerType)\
118 const InnerType& Get##FuncName() const { return ReadRef([](const auto& Data){ return Data.Inner;}); }\
119 void Set##FuncName(const InnerType& Val) { Write([&Val](auto& Data){ Data.Inner = Val;}); }\
120
122
123private:
124
125 void VerifyContext() const
126 {
127#if PHYSICS_THREAD_CONTEXT
128 //Are you using the wrong API type for the thread this code runs in?
129 //GetGameThreadAPI should be used for gamethread, GetPhysicsThreadAPI should be used for callbacks and internal physics thread
130 //Note if you are using a ParallelFor you must use PhysicsParallelFor to ensure the right context is inherited from parent thread
131 if (bExternal)
132 {
133 //if proxy is registered with solver, we need a lock
134 if (GetSolverBase() != nullptr)
135 {
137 }
138 }
139 else
140 {
142 }
143#endif
144 }
145
146 template <typename TLambda>
147 const auto& ReadRef(const TLambda& Lambda) const { VerifyContext(); return bExternal ? Lambda(GetConstraint()) : Lambda(GetHandle()); }
148
149 template <typename TLambda>
150 void Write(const TLambda& Lambda)
151 {
152 VerifyContext();
153 if (bExternal)
154 {
155 Lambda(GetConstraint());
156 }
157 else
158 {
159 //Mark entire joint as dirty from PT. TODO: use property system
160 FPhysicsSolverBase* SolverBase = GetSolverBase(); //internal so must have solver already
161 if (FRewindData* RewindData = SolverBase->GetRewindData())
162 {
163 RewindData->MarkDirtyJointFromPT(*GetHandle());
164 }
165
166 Lambda(GetHandle());
167 }
168 }
169};
170
171}
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define ensure( InExpression)
Definition AssertionMacros.h:464
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 ParticleDirtyFlags.h:1129
Definition ParticleDirtyFlags.h:1039
Definition JointConstraintProxy.h:33
FORCEINLINE Chaos::FJointConstraintHandle_Internal * GetPhysicsThreadAPI()
Definition JointConstraintProxy.h:67
void BufferPhysicsResults(FDirtyJointConstraintData &Buffer)
Definition JointConstraintProxy.cpp:46
void SetHandle(FPBDJointConstraintHandle *InHandle)
Definition JointConstraintProxy.h:88
void CHAOS_API DestroyOnPhysicsThread(FPBDRigidsSolver *InSolver)
Definition JointConstraintProxy.cpp:137
FORCEINLINE const Chaos::FJointConstraintHandle_Internal * GetPhysicsThreadAPI() const
Definition JointConstraintProxy.h:73
bool CHAOS_API PullFromPhysicsState(const FDirtyJointConstraintData &Buffer, const int32 SolverSyncTimestamp)
Definition JointConstraintProxy.cpp:67
FJointConstraint * GetConstraint()
Definition JointConstraintProxy.h:90
static FGeometryParticleHandle * GetParticleHandleFromProxy(IPhysicsProxyBase *ProxyBase)
Definition JointConstraintProxy.cpp:33
FPBDJointConstraintHandle * GetHandle()
Definition JointConstraintProxy.h:83
virtual void * GetHandleUnsafe() const override
Definition JointConstraintProxy.h:86
const FJointConstraint * GetConstraint() const
Definition JointConstraintProxy.h:91
void CHAOS_API PushStateOnGameThread(FDirtyPropertiesManager &Manager, int32 DataIdx, FDirtyChaosProperties &RemoteData)
Definition JointConstraintProxy.cpp:155
const FPBDJointConstraintHandle * GetHandle() const
Definition JointConstraintProxy.h:84
FORCEINLINE Chaos::FJointConstraintHandle_External & GetGameThreadAPI()
Definition JointConstraintProxy.h:56
void CHAOS_API InitializeOnPhysicsThread(FPBDRigidsSolver *InSolver, FDirtyPropertiesManager &Manager, int32 DataIdx, FDirtyChaosProperties &RemoteData)
Definition JointConstraintProxy.cpp:101
FORCEINLINE const Chaos::FJointConstraintHandle_External & GetGameThreadAPI() const
Definition JointConstraintProxy.h:61
void CHAOS_API PushStateOnPhysicsThread(FPBDRigidsSolver *InSolver, const FDirtyPropertiesManager &Manager, int32 DataIdx, const FDirtyChaosProperties &RemoteData)
Definition JointConstraintProxy.cpp:164
void CHAOS_API DestroyOnGameThread()
Definition JointConstraintProxy.cpp:148
Definition PBDJointConstraintData.h:38
Definition PBDJointConstraints.h:28
Definition PBDRigidsSolver.h:84
Definition ParticleHandle.h:436
Definition JointConstraintProxy.h:114
Definition Vector.h:41
Definition PhysicsProxyBase.h:97
Chaos::FPhysicsSolverBase * GetSolverBase() const
Definition PhysicsProxyBase.h:112
Definition Object.h:95
Definition SkeletalMeshComponent.h:307
FORCEINLINE bool IsInPhysicsThreadContext()
Definition Threading.h:280
FORCEINLINE bool IsInGameThreadContext()
Definition Threading.h:285
Definition PullPhysicsDataImp.h:148