MCPcopy Create free account
hub / github.com/BoomingTech/Piccolo / Update

Method Update

engine/3rdparty/JoltPhysics/Jolt/Physics/PhysicsSystem.cpp:111–608  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111void PhysicsSystem::Update(float inDeltaTime, int inCollisionSteps, int inIntegrationSubSteps, TempAllocator *inTempAllocator, JobSystem *inJobSystem)
112{
113 JPH_PROFILE_FUNCTION();
114
115 JPH_ASSERT(inDeltaTime >= 0.0f);
116 JPH_ASSERT(inIntegrationSubSteps <= PhysicsUpdateContext::cMaxSubSteps);
117
118 // Sync point for the broadphase. This will allow it to do clean up operations without having any mutexes locked yet.
119 mBroadPhase->FrameSync();
120
121 // If there are no active bodies or there's no time delta
122 uint32 num_active_bodies = mBodyManager.GetNumActiveBodies();
123 if (num_active_bodies == 0 || inDeltaTime <= 0.0f)
124 {
125 mBodyManager.LockAllBodies();
126
127 // Update broadphase
128 mBroadPhase->LockModifications();
129 BroadPhase::UpdateState update_state = mBroadPhase->UpdatePrepare();
130 mBroadPhase->UpdateFinalize(update_state);
131 mBroadPhase->UnlockModifications();
132
133 // Call contact removal callbacks from contacts that existed in the previous update
134 mContactManager.ContactPointRemovedCallbacks();
135 mContactManager.FinalizeContactCache(0, 0);
136
137 mBodyManager.UnlockAllBodies();
138 return;
139 }
140
141 // Calculate ratio between current and previous frame delta time to scale initial constraint forces
142 float sub_step_delta_time = inDeltaTime / (inCollisionSteps * inIntegrationSubSteps);
143 float warm_start_impulse_ratio = mPhysicsSettings.mConstraintWarmStart && mPreviousSubStepDeltaTime > 0.0f? sub_step_delta_time / mPreviousSubStepDeltaTime : 0.0f;
144 mPreviousSubStepDeltaTime = sub_step_delta_time;
145
146 // Create the context used for passing information between jobs
147 PhysicsUpdateContext context;
148 context.mPhysicsSystem = this;
149 context.mTempAllocator = inTempAllocator;
150 context.mJobSystem = inJobSystem;
151 context.mBarrier = inJobSystem->CreateBarrier();
152 context.mIslandBuilder = &mIslandBuilder;
153 context.mStepDeltaTime = inDeltaTime / inCollisionSteps;
154 context.mSubStepDeltaTime = sub_step_delta_time;
155 context.mWarmStartImpulseRatio = warm_start_impulse_ratio;
156
157 // Allocate space for body pairs
158 JPH_ASSERT(context.mBodyPairs == nullptr);
159 context.mBodyPairs = static_cast<BodyPair *>(inTempAllocator->Allocate(sizeof(BodyPair) * mPhysicsSettings.mMaxInFlightBodyPairs));
160
161 // Lock all bodies for write so that we can freely touch them
162 mStepListenersMutex.lock();
163 mBodyManager.LockAllBodies();
164 mBroadPhase->LockModifications();
165
166 // Get max number of concurrent jobs
167 int max_concurrency = context.GetMaxConcurrency();
168

Callers 6

mainFunction · 0.45
mainFunction · 0.45
SimulateMethod · 0.45
SimulateSingleStepMethod · 0.45
StepPhysicsMethod · 0.45
PrePhysicsUpdateMethod · 0.45

Calls 15

minFunction · 0.85
GetNumActiveBodiesMethod · 0.80
LockAllBodiesMethod · 0.80
FinalizeContactCacheMethod · 0.80
UnlockAllBodiesMethod · 0.80
CreateBarrierMethod · 0.80
GetMaxConcurrencyMethod · 0.80
CreateJobMethod · 0.80
RemoveDependencyMethod · 0.80
JobFindCollisionsMethod · 0.80
LockAllConstraintsMethod · 0.80

Tested by 4

mainFunction · 0.36
SimulateMethod · 0.36
SimulateSingleStepMethod · 0.36
PrePhysicsUpdateMethod · 0.36