Class TypeProcessor
- Namespace
- BepuPhysics.Constraints
- Assembly
- BepuPhysics.dll
Superclass of constraint type batch processors. Responsible for interpreting raw type batches for the purposes of bookkeeping and solving.
public abstract class TypeProcessor
- Inheritance
-
TypeProcessor
- Derived
- Inherited Members
Remarks
This class holds no actual state of its own. A solver creates a unique type processor for each registered constraint type, and all instances are held in untyped memory. Splitting the functionality from the data allows for far fewer GC-tracked instances and allows the raw data layout to be shared more easily.
For example, sleeping simulation islands store type batches, but they are created and used differently- and for convenience, they are stored on a per-island basis. Using the same system but with reference type TypeBatches, tens of thousands of inactive islands would imply tens of thousands of GC-tracked objects.
That's not acceptable, so here we are.Conceptually, you can think of the solver's array of TypeProcessors like C function pointers.
Fields
bodiesPerConstraint
protected int bodiesPerConstraint
Field Value
typeId
protected int typeId
Field Value
Properties
BodiesPerConstraint
Gets the number of bodies associated with each constraint in this type processor.
public int BodiesPerConstraint { get; }
Property Value
ConstrainedDegreesOfFreedom
Gets the number of degrees of freedom that each constraint in this type processor constrains. Equal to the number of entries in the accumulated impulses.
public int ConstrainedDegreesOfFreedom { get; }
Property Value
InternalBodiesPerConstraint
protected abstract int InternalBodiesPerConstraint { get; }
Property Value
InternalConstrainedDegreesOfFreedom
protected abstract int InternalConstrainedDegreesOfFreedom { get; }
Property Value
RequiresIncrementalSubstepUpdates
Gets whether this type requires incremental updates for each substep in a frame beyond the first.
public abstract bool RequiresIncrementalSubstepUpdates { get; }
Property Value
TypeId
public int TypeId { get; }
Property Value
Methods
AllocateInTypeBatch(ref TypeBatch, ConstraintHandle, Span<int>, BufferPool)
Allocates a slot in the batch, assuming the batch is not a fallback batch.
public abstract int AllocateInTypeBatch(ref TypeBatch typeBatch, ConstraintHandle handle, Span<int> encodedBodyIndices, BufferPool pool)
Parameters
typeBatch
TypeBatchType batch to allocate in.
handle
ConstraintHandleHandle of the constraint to allocate. Establishes a link from the allocated constraint to its handle.
encodedBodyIndices
Span<int>List of body indices (not handles!) with count equal to the type batch's expected number of involved bodies.
pool
BufferPoolAllocation provider to use if the type batch has to be resized.
Returns
- int
Index of the slot in the batch.
AllocateInTypeBatchForFallback(ref TypeBatch, ConstraintHandle, Span<int>, BufferPool)
Allocates a slot in the batch, assuming the batch is a fallback batch.
public abstract int AllocateInTypeBatchForFallback(ref TypeBatch typeBatch, ConstraintHandle handle, Span<int> encodedBodyIndices, BufferPool pool)
Parameters
typeBatch
TypeBatchType batch to allocate in.
handle
ConstraintHandleHandle of the constraint to allocate. Establishes a link from the allocated constraint to its handle.
encodedBodyIndices
Span<int>List of body indices (not handles!) with count equal to the type batch's expected number of involved bodies.
pool
BufferPoolAllocation provider to use if the type batch has to be resized.
Returns
- int
Index of the slot in the batch.
EnumerateAccumulatedImpulses<TEnumerator>(ref TypeBatch, int, ref TEnumerator)
public void EnumerateAccumulatedImpulses<TEnumerator>(ref TypeBatch typeBatch, int indexInTypeBatch, ref TEnumerator enumerator) where TEnumerator : IForEach<float>
Parameters
Type Parameters
TEnumerator
IncrementallyUpdateForSubstep(ref TypeBatch, Bodies, float, float, int, int)
public virtual void IncrementallyUpdateForSubstep(ref TypeBatch typeBatch, Bodies bodies, float dt, float inverseDt, int startBundle, int end)
Parameters
Initialize(ref TypeBatch, int, BufferPool)
public abstract void Initialize(ref TypeBatch typeBatch, int initialCapacity, BufferPool pool)
Parameters
Initialize(int)
public void Initialize(int typeId)
Parameters
typeId
int
Remove(ref TypeBatch, int, ref Buffer<ConstraintLocation>, bool)
public abstract void Remove(ref TypeBatch typeBatch, int index, ref Buffer<ConstraintLocation> handlesToConstraints, bool isFallback)
Parameters
typeBatch
TypeBatchindex
inthandlesToConstraints
Buffer<ConstraintLocation>isFallback
bool
Resize(ref TypeBatch, int, BufferPool)
public abstract void Resize(ref TypeBatch typeBatch, int newCapacity, BufferPool pool)
Parameters
ScaleAccumulatedImpulses(ref TypeBatch, float)
public abstract void ScaleAccumulatedImpulses(ref TypeBatch typeBatch, float scale)
Parameters
Scramble(ref TypeBatch, Random, ref Buffer<ConstraintLocation>)
public abstract void Scramble(ref TypeBatch typeBatch, Random random, ref Buffer<ConstraintLocation> handlesToConstraints)
Parameters
typeBatch
TypeBatchrandom
RandomhandlesToConstraints
Buffer<ConstraintLocation>
Solve(ref TypeBatch, Bodies, float, float, int, int)
public abstract void Solve(ref TypeBatch typeBatch, Bodies bodies, float dt, float inverseDt, int startBundle, int exclusiveEndBundle)
Parameters
TransferConstraint(ref TypeBatch, int, int, Solver, Bodies, int)
Moves a constraint from one ConstraintBatch's TypeBatch to another ConstraintBatch's TypeBatch of the same type.
public void TransferConstraint(ref TypeBatch sourceTypeBatch, int sourceBatchIndex, int indexInTypeBatch, Solver solver, Bodies bodies, int targetBatchIndex)
Parameters
sourceTypeBatch
TypeBatchSource type batch to transfer the constraint out of.
sourceBatchIndex
intIndex of the batch that owns the type batch that is the source of the constraint transfer.
indexInTypeBatch
intIndex of the constraint to move in the current type batch.
solver
SolverSolver that owns the batches.
bodies
BodiesBodies set that owns all the constraint's bodies.
targetBatchIndex
intIndex of the ConstraintBatch in the solver to copy the constraint into.
TransferConstraint(ref TypeBatch, int, int, Solver, Bodies, int, Span<BodyHandle>, Span<int>)
Moves a constraint from one ConstraintBatch's TypeBatch to another ConstraintBatch's TypeBatch of the same type.
public abstract void TransferConstraint(ref TypeBatch sourceTypeBatch, int sourceBatchIndex, int indexInTypeBatch, Solver solver, Bodies bodies, int targetBatchIndex, Span<BodyHandle> dynamicBodyHandles, Span<int> encodedBodyIndices)
Parameters
sourceTypeBatch
TypeBatchSource type batch to transfer the constraint out of.
sourceBatchIndex
intIndex of the batch that owns the type batch that is the source of the constraint transfer.
indexInTypeBatch
intIndex of the constraint to move in the current type batch.
solver
SolverSolver that owns the batches.
bodies
BodiesBodies set that owns all the constraint's bodies.
targetBatchIndex
intIndex of the ConstraintBatch in the solver to copy the constraint into.
dynamicBodyHandles
Span<BodyHandle>Set of body handles in the constraint referring to dynamic bodies.
encodedBodyIndices
Span<int>Set of encoded body indices to use in the new constraint allocation.
UpdateForBodyMemoryMove(ref TypeBatch, int, int, int)
Updates a type batch's body index references for the movement of a body in memory.
public abstract bool UpdateForBodyMemoryMove(ref TypeBatch typeBatch, int indexInTypeBatch, int bodyIndexInConstraint, int newBodyLocation)
Parameters
typeBatch
TypeBatchType batch containing a constraint that references the body.
indexInTypeBatch
intIndex of the constraint in the type batch.
bodyIndexInConstraint
intIndex within the constraint of the body.
newBodyLocation
intNew index of the body in the bodies active set.
Returns
- bool
True if the body being moved was kinematic according to the constraint's reference.
ValidateAccumulatedImpulsesSizeInBytes(int)
[Conditional("DEBUG")]
protected abstract void ValidateAccumulatedImpulsesSizeInBytes(int sizeInBytes)
Parameters
sizeInBytes
int
WarmStart<TIntegratorCallbacks, TBatchIntegrationMode, TAllowPoseIntegration>(ref TypeBatch, ref Buffer<IndexSet>, Bodies, ref TIntegratorCallbacks, float, float, int, int, int)
public abstract void WarmStart<TIntegratorCallbacks, TBatchIntegrationMode, TAllowPoseIntegration>(ref TypeBatch typeBatch, ref Buffer<IndexSet> integrationFlags, Bodies bodies, ref TIntegratorCallbacks poseIntegratorCallbacks, float dt, float inverseDt, int startBundle, int exclusiveEndBundle, int workerIndex) where TIntegratorCallbacks : struct, IPoseIntegratorCallbacks where TBatchIntegrationMode : unmanaged, IBatchIntegrationMode where TAllowPoseIntegration : unmanaged, IBatchPoseIntegrationAllowed
Parameters
typeBatch
TypeBatchintegrationFlags
Buffer<IndexSet>bodies
BodiesposeIntegratorCallbacks
TIntegratorCallbacksdt
floatinverseDt
floatstartBundle
intexclusiveEndBundle
intworkerIndex
int
Type Parameters
TIntegratorCallbacks
TBatchIntegrationMode
TAllowPoseIntegration