Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
CalculateSolverSteps.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2023 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
10
13{
14public:
16 JPH_INLINE explicit CalculateSolverSteps(const PhysicsSettings &inSettings) : mSettings(inSettings) { }
17
19 template <class Type>
20 JPH_INLINE void operator () (const Type *inObject)
21 {
22 uint num_velocity_steps = inObject->GetNumVelocityStepsOverride();
23 mNumVelocitySteps = max(mNumVelocitySteps, num_velocity_steps);
24 mApplyDefaultVelocity |= num_velocity_steps == 0;
25
26 uint num_position_steps = inObject->GetNumPositionStepsOverride();
27 mNumPositionSteps = max(mNumPositionSteps, num_position_steps);
28 mApplyDefaultPosition |= num_position_steps == 0;
29 }
30
32 JPH_INLINE void Finalize()
33 {
34 // If we have a default velocity/position step count, take the max of the default and the overrides
35 if (mApplyDefaultVelocity)
36 mNumVelocitySteps = max(mNumVelocitySteps, mSettings.mNumVelocitySteps);
37 if (mApplyDefaultPosition)
38 mNumPositionSteps = max(mNumPositionSteps, mSettings.mNumPositionSteps);
39 }
40
42 JPH_INLINE uint GetNumPositionSteps() const { return mNumPositionSteps; }
43 JPH_INLINE uint GetNumVelocitySteps() const { return mNumVelocitySteps; }
44
45private:
46 const PhysicsSettings & mSettings;
47
48 uint mNumVelocitySteps = 0;
49 uint mNumPositionSteps = 0;
50
51 bool mApplyDefaultVelocity = false;
52 bool mApplyDefaultPosition = false;
53};
54
57{
58public:
59 template <class Type>
60 JPH_INLINE void operator () (const Type *) const
61 {
62 /* Nothing to do */
63 }
64};
65
unsigned int uint
Definition Core.h:453
#define JPH_NAMESPACE_END
Definition Core.h:379
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
Class used to calculate the total number of velocity and position steps.
Definition CalculateSolverSteps.h:13
JPH_INLINE CalculateSolverSteps(const PhysicsSettings &inSettings)
Constructor.
Definition CalculateSolverSteps.h:16
JPH_INLINE uint GetNumVelocitySteps() const
Definition CalculateSolverSteps.h:43
JPH_INLINE void Finalize()
Must be called after all bodies/constraints have been processed.
Definition CalculateSolverSteps.h:32
JPH_INLINE void operator()(const Type *inObject)
Combine the number of velocity and position steps for this body/constraint with the current values.
Definition CalculateSolverSteps.h:20
JPH_INLINE uint GetNumPositionSteps() const
Get the results of the calculation.
Definition CalculateSolverSteps.h:42
Dummy class to replace the steps calculator when we don't need the result.
Definition CalculateSolverSteps.h:57
JPH_INLINE void operator()(const Type *) const
Definition CalculateSolverSteps.h:60
Definition PhysicsSettings.h:28
uint mNumPositionSteps
Number of solver position iterations to run.
Definition PhysicsSettings.h:81
uint mNumVelocitySteps
Definition PhysicsSettings.h:78