Table of Contents

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

int

typeId

protected int typeId

Field Value

int

Properties

BodiesPerConstraint

Gets the number of bodies associated with each constraint in this type processor.

public int BodiesPerConstraint { get; }

Property Value

int

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

int

InternalBodiesPerConstraint

protected abstract int InternalBodiesPerConstraint { get; }

Property Value

int

InternalConstrainedDegreesOfFreedom

protected abstract int InternalConstrainedDegreesOfFreedom { get; }

Property Value

int

RequiresIncrementalSubstepUpdates

Gets whether this type requires incremental updates for each substep in a frame beyond the first.

public abstract bool RequiresIncrementalSubstepUpdates { get; }

Property Value

bool

TypeId

public int TypeId { get; }

Property Value

int

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 TypeBatch

Type batch to allocate in.

handle ConstraintHandle

Handle 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 BufferPool

Allocation 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 TypeBatch

Type batch to allocate in.

handle ConstraintHandle

Handle 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 BufferPool

Allocation 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

typeBatch TypeBatch
indexInTypeBatch int
enumerator TEnumerator

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

typeBatch TypeBatch
bodies Bodies
dt float
inverseDt float
startBundle int
end int

Initialize(ref TypeBatch, int, BufferPool)

public abstract void Initialize(ref TypeBatch typeBatch, int initialCapacity, BufferPool pool)

Parameters

typeBatch TypeBatch
initialCapacity int
pool BufferPool

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 TypeBatch
index int
handlesToConstraints Buffer<ConstraintLocation>
isFallback bool

Resize(ref TypeBatch, int, BufferPool)

public abstract void Resize(ref TypeBatch typeBatch, int newCapacity, BufferPool pool)

Parameters

typeBatch TypeBatch
newCapacity int
pool BufferPool

ScaleAccumulatedImpulses(ref TypeBatch, float)

public abstract void ScaleAccumulatedImpulses(ref TypeBatch typeBatch, float scale)

Parameters

typeBatch TypeBatch
scale float

Scramble(ref TypeBatch, Random, ref Buffer<ConstraintLocation>)

public abstract void Scramble(ref TypeBatch typeBatch, Random random, ref Buffer<ConstraintLocation> handlesToConstraints)

Parameters

typeBatch TypeBatch
random Random
handlesToConstraints 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

typeBatch TypeBatch
bodies Bodies
dt float
inverseDt float
startBundle int
exclusiveEndBundle int

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 TypeBatch

Source type batch to transfer the constraint out of.

sourceBatchIndex int

Index of the batch that owns the type batch that is the source of the constraint transfer.

indexInTypeBatch int

Index of the constraint to move in the current type batch.

solver Solver

Solver that owns the batches.

bodies Bodies

Bodies set that owns all the constraint's bodies.

targetBatchIndex int

Index 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 TypeBatch

Source type batch to transfer the constraint out of.

sourceBatchIndex int

Index of the batch that owns the type batch that is the source of the constraint transfer.

indexInTypeBatch int

Index of the constraint to move in the current type batch.

solver Solver

Solver that owns the batches.

bodies Bodies

Bodies set that owns all the constraint's bodies.

targetBatchIndex int

Index 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 TypeBatch

Type batch containing a constraint that references the body.

indexInTypeBatch int

Index of the constraint in the type batch.

bodyIndexInConstraint int

Index within the constraint of the body.

newBodyLocation int

New 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 TypeBatch
integrationFlags Buffer<IndexSet>
bodies Bodies
poseIntegratorCallbacks TIntegratorCallbacks
dt float
inverseDt float
startBundle int
exclusiveEndBundle int
workerIndex int

Type Parameters

TIntegratorCallbacks
TBatchIntegrationMode
TAllowPoseIntegration