Struct Tree
- Namespace
- BepuPhysics.Trees
- Assembly
- BepuPhysics.dll
public struct Tree
- Inherited Members
Constructors
Tree(BufferPool, int)
Constructs an empty tree.
public Tree(BufferPool pool, int initialLeafCapacity = 4096)
Parameters
pool
BufferPoolBuffer pool to use to allocate resources in the tree.
initialLeafCapacity
intInitial number of leaves to allocate room for.
Tree(Span<byte>, BufferPool)
Loads a tree from a byte buffer created by the Serialize function.
public Tree(Span<byte> data, BufferPool pool)
Parameters
Fields
LeafCount
Number of leaves in the tree.
public int LeafCount
Field Value
Leaves
Buffer of leaves in the tree.
public Buffer<Leaf> Leaves
Field Value
- Buffer<Leaf>
Metanodes
Buffer of metanodes in the tree. Metanodes contain metadata that aren't read during most query operations but are useful for bookkeeping.
public Buffer<Metanode> Metanodes
Field Value
- Buffer<Metanode>
NodeCount
Number of nodes in the tree.
public int NodeCount
Field Value
Nodes
Buffer of nodes in the tree.
public Buffer<Node> Nodes
Field Value
- Buffer<Node>
Times
public static Tree.NodeTimes[] Times
Field Value
Methods
Add(BoundingBox, BufferPool)
Adds a leaf to the tree with the given bounding box and returns the index of the added leaf.
public int Add(BoundingBox bounds, BufferPool pool)
Parameters
bounds
BoundingBoxExtents of the leaf bounds.
pool
BufferPoolResource pool to use if resizing is required.
Returns
- int
Index of the leaf allocated in the tree's leaf array.
Remarks
Performs incrementally refining tree rotations down along the insertion path, unlike AddWithoutRefinement(BoundingBox, BufferPool).
For a given tree, this is slightly slower than AddWithoutRefinement(BoundingBox, BufferPool) and slightly faster than AddWithBottomUpRefinement(BoundingBox, BufferPool). Trees built with repeated insertions of this kind tend to have decent quality, but slightly worse than AddWithBottomUpRefinement(BoundingBox, BufferPool).AddWithBottomUpRefinement(BoundingBox, BufferPool)
Adds a leaf to the tree with the given bounding box and returns the index of the added leaf.
public int AddWithBottomUpRefinement(BoundingBox bounds, BufferPool pool)
Parameters
bounds
BoundingBoxExtents of the leaf bounds.
pool
BufferPoolResource pool to use if resizing is required.
Returns
- int
Index of the leaf allocated in the tree's leaf array.
Remarks
Performs incrementally refining tree rotations up along the insertion path, unlike AddWithoutRefinement(BoundingBox, BufferPool).
Trees built with repeated insertions of this kind tend to have slightly better quality than Add(BoundingBox, BufferPool), but it is also slightly more expensive.AddWithoutRefinement(BoundingBox, BufferPool)
Adds a leaf to the tree with the given bounding box and returns the index of the added leaf.
public int AddWithoutRefinement(BoundingBox bounds, BufferPool pool)
Parameters
bounds
BoundingBoxExtents of the leaf bounds.
pool
BufferPoolResource pool to use if resizing is required.
Returns
- int
Index of the leaf allocated in the tree's leaf array.
Remarks
This performs no incremental refinement. When acting on the same tree, it's slightly cheaper than Add(BoundingBox, BufferPool), but the quality of the tree depends on insertion order.
Pathological insertion orders can result in a maximally imbalanced tree, quadratic insertion times across the full tree build, and query performance linear in the number of leaves. This is typically best reserved for cases where the insertion order is known to be randomized or otherwise conducive to building decent trees.BinnedBuild(Buffer<NodeChild>, BufferPool, IThreadDispatcher, TaskStack*, int, int, int, int, int, int, float, int, bool)
Runs a binned build across the subtrees buffer.
public void BinnedBuild(Buffer<NodeChild> subtrees, BufferPool pool = null, IThreadDispatcher dispatcher = null, TaskStack* taskStackPointer = null, int workerIndex = 0, int workerCount = -1, int targetTaskCount = -1, int maximumSubtreeStackAllocationCount = 4096, int minimumBinCount = 16, int maximumBinCount = 64, float leafToBinMultiplier = 0.0625, int microsweepThreshold = 64, bool deterministic = false)
Parameters
subtrees
Buffer<NodeChild>Subtrees (either leaves or nodes) to run the builder over. The builder may make in-place modifications to the input buffer; the input buffer should not be assumed to be in a valid state after the builder runs.
pool
BufferPoolBuffer pool used to preallocate a pingpong buffer if the number of subtrees exceeds maximumSubtreeStackAllocationCount. If null, stack allocation or a slower in-place partitioning will be used.
A pool must be provided if a thread dispatcher is given.dispatcher
IThreadDispatcherDispatcher used to multithread the execution of the build. If the dispatcher is not null, pool must also not be null.
taskStackPointer
TaskStack*Task stack being used to run the build process, if any. If provided, the builder assumes the refinement is running within an existing multithreaded dispatch and will not call IThreadDispatcher.DispatchWorkers. If null, the builder will create its own task stack and call IThreadDispatcher.DispatchWorkers internally.
workerIndex
intIndex of the currently executing worker. If not running within a dispatch, 0 is valid.
workerCount
intNumber of workers that may be used in the builder. This should span all worker indices that may contribute to the build process even only a subset are expected to be used at any one time. If negative, the dispatcher's thread count will be used.
targetTaskCount
intNumber of tasks to try to use in the builder. If negative, the dispatcher's thread count will be used.
maximumSubtreeStackAllocationCount
intMaximum number of subtrees to try putting on the stack for the binned builder's pong buffers.
Subtree counts larger than this threshold will either resort to a buffer pool allocation (if available) or slower in-place partition operations.minimumBinCount
intMinimum number of bins the builder should use per node.
maximumBinCount
intMaximum number of bins the builder should use per node.
leafToBinMultiplier
floatMultiplier to apply to the subtree count within a node to decide the bin count. Resulting value will then be clamped by the minimum/maximum bin counts.
microsweepThreshold
intThreshold at or under which the binned builder resorts to local counting sort sweeps.
deterministic
boolWhether to force determinism at a slightly higher cost when using internally multithreaded execution.
If the build is single threaded, it is already deterministic and this flag has no effect.
BinnedBuild(Buffer<NodeChild>, Buffer<Node>, Buffer<Metanode>, Buffer<Leaf>, BufferPool, IThreadDispatcher, TaskStack*, int, int, int, int, int, int, float, int, bool)
Runs a multithreaded binned build across the subtrees buffer.
public static void BinnedBuild(Buffer<NodeChild> subtrees, Buffer<Node> nodes, Buffer<Metanode> metanodes, Buffer<Leaf> leaves, BufferPool pool = null, IThreadDispatcher dispatcher = null, TaskStack* taskStackPointer = null, int workerIndex = 0, int workerCount = -1, int targetTaskCount = -1, int maximumSubtreeStackAllocationCount = 4096, int minimumBinCount = 16, int maximumBinCount = 64, float leafToBinMultiplier = 0.0625, int microsweepThreshold = 64, bool deterministic = false)
Parameters
subtrees
Buffer<NodeChild>Subtrees (either leaves or nodes) to run the builder over. The builder may make in-place modifications to the input buffer; the input buffer should not be assumed to be in a valid state after the builder runs.
nodes
Buffer<Node>Buffer holding the nodes created by the build process.
Nodes are created in a depth first ordering with respect to the input buffer.metanodes
Buffer<Metanode>Buffer holding the metanodes created by the build process.
Metanodes, like nodes, are created in a depth first ordering with respect to the input buffer. Metanodes are in the same order and in the same slots; they simply contain data about nodes that most traversals don't need to know about.leaves
Buffer<Leaf>Buffer holding the leaf references created by the build process.
The indices written by the build process are those defined in the inputs; any Index that is negative is encoded according to Encode(int) and points into the leaf buffer. If a default-valued (unallocated) buffer is passed in, the binned builder will ignore leaves.pool
BufferPoolBuffer pool used to preallocate a pingpong buffer if the number of subtrees exceeds maximumSubtreeStackAllocationCount. If null, stack allocation or a slower in-place partitioning will be used. Dispatcher used to multithread the execution of the build. If the dispatcher is not null, pool must also not be null.Task stack being used to run the build process, if any. If provided, the builder assumes the refinement is running within an existing multithreaded dispatch and will not call IThreadDispatcher.DispatchWorkers. If null, the builder will create its own task stack and call IThreadDispatcher.DispatchWorkers internally.
A pool must be provided if a thread dispatcher is given.dispatcher
IThreadDispatchertaskStackPointer
TaskStack*workerIndex
intIndex of the currently executing worker. If not running within a dispatch, 0 is valid.
workerCount
intNumber of workers that may be used in the builder. This should span all worker indices that may contribute to the build process even only a subset are expected to be used at any one time. If negative, the dispatcher's thread count will be used.
targetTaskCount
intNumber of tasks to try to use in the builder. If negative, the dispatcher's thread count will be used.
maximumSubtreeStackAllocationCount
intMaximum number of subtrees to try putting on the stack for the binned builder's pong buffers.
Subtree counts larger than this threshold will either resort to a buffer pool allocation (if available) or slower in-place partition operations.minimumBinCount
intMinimum number of bins the builder should use per node.
maximumBinCount
intMaximum number of bins the builder should use per node.
leafToBinMultiplier
floatMultiplier to apply to the subtree count within a node to decide the bin count. Resulting value will then be clamped by the minimum/maximum bin counts.
microsweepThreshold
intThreshold at or under which the binned builder resorts to local counting sort sweeps.
deterministic
boolWhether to force determinism at a slightly higher cost when using internally multithreaded execution.
If the build is single threaded, it is already deterministic and this flag has no effect.
BinnedRefine(int, ref QuickList<int>, int, ref QuickList<int>, ref BinnedResources, BufferPool)
public void BinnedRefine(int nodeIndex, ref QuickList<int> subtreeReferences, int maximumSubtrees, ref QuickList<int> treeletInternalNodes, ref BinnedResources resources, BufferPool pool)
Parameters
nodeIndex
intsubtreeReferences
QuickList<int>maximumSubtrees
inttreeletInternalNodes
QuickList<int>resources
BinnedResourcespool
BufferPool
CacheOptimize(int)
Begins a cache optimization at the given node and proceeds all the way to the bottom of the tree. Requires that the targeted node is already at the global optimum position.
public void CacheOptimize(int nodeIndex)
Parameters
nodeIndex
intNode to begin the optimization process at.
CacheOptimizeLimitedSubtree(int, int)
Starts a cache optimization process at the target node index and the nodeOptimizationCount closest nodes in the tree.
public void CacheOptimizeLimitedSubtree(int nodeIndex, int nodeOptimizationCount)
Parameters
nodeIndex
intNode index to start the optimization process at.
nodeOptimizationCount
intNumber of nodes to move.
Remarks
This optimizer will move the targeted node index to the globally optimal location if necessary.
CacheOptimizeRegion(int, int)
Puts all nodes starting from the given node index into depth first traversal order. If the count is larger than the number of nodes beneath the starting node, the optimization will stop early.
public int CacheOptimizeRegion(int startingNodeIndex, int targetCount)
Parameters
startingNodeIndex
intNode index to start the optimization at.
targetCount
intNumber of nodes to try to optimize.
Returns
- int
Number of nodes optimized.
Clear()
Resets the tree to a fresh post-construction state, clearing out leaves and nodes but leaving the backing resources intact.
public void Clear()
CollectSubtrees(int, int, SubtreeHeapEntry*, ref QuickList<int>, ref QuickList<int>, out float)
public void CollectSubtrees(int nodeIndex, int maximumSubtrees, SubtreeHeapEntry* entries, ref QuickList<int> subtrees, ref QuickList<int> internalNodes, out float treeletCost)
Parameters
nodeIndex
intmaximumSubtrees
intentries
SubtreeHeapEntry*subtrees
QuickList<int>internalNodes
QuickList<int>treeletCost
float
ComputeCacheOptimalLocation(int)
Computes the index where the given node would be located if the tree were in depth first traversal order.
public int ComputeCacheOptimalLocation(int nodeIndex)
Parameters
nodeIndex
intNode index to find the location for in a depth first traversal order.
Returns
- int
Target index of the node if the tree were in depth first traversal order.
ComputeMaximumDepth()
public readonly int ComputeMaximumDepth()
Returns
ConvertBoxToCentroidWithExtent(Vector3, Vector3, out Vector3, out Vector3)
public static void ConvertBoxToCentroidWithExtent(Vector3 min, Vector3 max, out Vector3 origin, out Vector3 expansion)
Parameters
CreateBinnedResources(BufferPool, int, out Buffer<byte>, out BinnedResources)
public static void CreateBinnedResources(BufferPool bufferPool, int maximumSubtreeCount, out Buffer<byte> buffer, out BinnedResources resources)
Parameters
bufferPool
BufferPoolmaximumSubtreeCount
intbuffer
Buffer<byte>resources
BinnedResources
Dispose(BufferPool)
Disposes the tree's backing resources, returning them to the Pool currently associated with the tree.
public void Dispose(BufferPool pool)
Parameters
pool
BufferPoolPool to return resources to.
Remarks
Disposed trees can be reused if EnsureCapacity or Resize is used to rehydrate them.
Encode(int)
public static int Encode(int index)
Parameters
index
int
Returns
Equals(in Tree, in Tree)
Tests if two tree references point to the same data.
public static bool Equals(in Tree a, in Tree b)
Parameters
Returns
- bool
True if the two trees have the same nodes and node count, false otherwise.
GetBoundsPointers(int, out Vector3*, out Vector3*)
Gets bounds pointerse for a leaf in the tree.
public readonly void GetBoundsPointers(int leafIndex, out Vector3* minPointer, out Vector3* maxPointer)
Parameters
leafIndex
intIndex of the leaf in the tree.
minPointer
Vector3*Pointer to the minimum bounds vector in the tree.
maxPointer
Vector3*Pointer to the maximum bounds vector in the tree.
GetLeftPackMask(Vector128<int>, out int)
public static Vector128<int> GetLeftPackMask(Vector128<int> mask, out int count)
Parameters
Returns
GetNodeChildForLeaf(Leaf)
Gets a reference to the node child representing the leaf within the tree.
public readonly ref NodeChild GetNodeChildForLeaf(Leaf leaf)
Parameters
leaf
LeafLeaf to look up in the tree.
Returns
- NodeChild
A reference to the node child within the tree.
GetNodeChildForLeaf(int)
Gets a reference to the node child representing the leaf within the tree.
public readonly ref NodeChild GetNodeChildForLeaf(int leafIndex)
Parameters
leafIndex
intIndex of the leaf to look up in the tree.
Returns
- NodeChild
A reference to the node child within the tree.
GetOverlaps<TOverlapHandler>(ref Tree, ref TOverlapHandler)
Gets pairs of leaf indices with bounding boxes which overlap.
public void GetOverlaps<TOverlapHandler>(ref Tree treeB, ref TOverlapHandler overlapHandler) where TOverlapHandler : struct, IOverlapHandler
Parameters
treeB
TreeTree to test this tree against.
overlapHandler
TOverlapHandlerHandler to report pairs to.
Type Parameters
TOverlapHandler
Type of the IOverlapHandler implementation to report pairs to.
GetOverlaps<TEnumerator>(BoundingBox, ref TEnumerator)
public readonly void GetOverlaps<TEnumerator>(BoundingBox boundingBox, ref TEnumerator leafEnumerator) where TEnumerator : IBreakableForEach<int>
Parameters
boundingBox
BoundingBoxleafEnumerator
TEnumerator
Type Parameters
TEnumerator
GetOverlaps<TEnumerator>(Vector3, Vector3, ref TEnumerator)
public readonly void GetOverlaps<TEnumerator>(Vector3 min, Vector3 max, ref TEnumerator leafEnumerator) where TEnumerator : IBreakableForEach<int>
Parameters
Type Parameters
TEnumerator
GetSelfOverlaps2<TOverlapHandler>(ref TOverlapHandler)
Reports all bounding box overlaps between leaves in the tree to the given TOverlapHandler
.
public readonly void GetSelfOverlaps2<TOverlapHandler>(ref TOverlapHandler results) where TOverlapHandler : IOverlapHandler
Parameters
results
TOverlapHandlerHandler to report results to.
Type Parameters
TOverlapHandler
GetSelfOverlaps2<TOverlapHandler>(ref TOverlapHandler, BufferPool, IThreadDispatcher, TaskStack*, int, int)
Reports all bounding box overlaps between leaves in the tree to the given TOverlapHandler
.
public void GetSelfOverlaps2<TOverlapHandler>(ref TOverlapHandler results, BufferPool pool, IThreadDispatcher threadDispatcher, TaskStack* taskStack, int workerIndex, int targetTaskCount = -1) where TOverlapHandler : unmanaged, IThreadedOverlapHandler
Parameters
results
TOverlapHandlerHandler to report results to.
pool
BufferPoolPool used for ephemeral allocations.
threadDispatcher
IThreadDispatcherThread dispatcher used during the overlap test.
taskStack
TaskStack*BepuUtilities.TaskScheduling.TaskStack that the overlap test will push tasks onto as needed.
workerIndex
intIndex of the worker calling the function.
targetTaskCount
intNumber of tasks the overlap testing should try to create during execution. If negative, uses BepuUtilities.IThreadDispatcher.ThreadCount.
Type Parameters
TOverlapHandler
Remarks
This does not dispatch workers on the BepuUtilities.IThreadDispatcher directly. If the overlap handler requires managed context, that should be provided by whatever dispatched the workers.
GetSelfOverlaps2<TOverlapHandler>(ref TOverlapHandler, BufferPool, IThreadDispatcher, object)
Reports all bounding box overlaps between leaves in the tree to the given TOverlapHandler
. Uses the thread dispatcher to parallelize overlap testing.
public void GetSelfOverlaps2<TOverlapHandler>(ref TOverlapHandler results, BufferPool pool, IThreadDispatcher threadDispatcher, object managedContext = null) where TOverlapHandler : unmanaged, IThreadedOverlapHandler
Parameters
results
TOverlapHandlerHandler to report results to.
pool
BufferPoolPool used for ephemeral allocations.
threadDispatcher
IThreadDispatcherThread dispatcher used during the overlap testing.
managedContext
objectManaged context to provide to the overlap handler, if any.
Type Parameters
TOverlapHandler
GetSelfOverlapsBatched<TOverlapHandler>(ref TOverlapHandler, BufferPool)
public void GetSelfOverlapsBatched<TOverlapHandler>(ref TOverlapHandler results, BufferPool pool) where TOverlapHandler : IOverlapHandler
Parameters
results
TOverlapHandlerpool
BufferPool
Type Parameters
TOverlapHandler
GetSelfOverlaps<TOverlapHandler>(ref TOverlapHandler)
public readonly void GetSelfOverlaps<TOverlapHandler>(ref TOverlapHandler results) where TOverlapHandler : IOverlapHandler
Parameters
results
TOverlapHandler
Type Parameters
TOverlapHandler
GetSerializedByteCount()
Gets the number of bytes required to store the tree.
public readonly int GetSerializedByteCount()
Returns
- int
Number of bytes required to store the tree.
Intersects(Vector3, Vector3, TreeRay*, out float)
public static bool Intersects(Vector3 min, Vector3 max, TreeRay* ray, out float t)
Parameters
Returns
MeasureCacheQuality()
public readonly float MeasureCacheQuality()
Returns
MeasureCacheQuality(int)
public readonly float MeasureCacheQuality(int nodeIndex)
Parameters
nodeIndex
int
Returns
MeasureCostMetric()
public float MeasureCostMetric()
Returns
RayCast<TLeafTester>(Vector3, Vector3, ref float, ref TLeafTester, int)
public readonly void RayCast<TLeafTester>(Vector3 origin, Vector3 direction, ref float maximumT, ref TLeafTester leafTester, int id = 0) where TLeafTester : IRayLeafTester
Parameters
Type Parameters
TLeafTester
Refine2(int, ref int, int, int, BufferPool, IThreadDispatcher, TaskStack*, int, int, bool, bool)
Incrementally refines a subset of the tree by running a binned builder over subtrees.
Pushes tasks into the provided BepuUtilities.TaskScheduling.TaskStack. Does not dispatch threads internally; this is intended to be used as a part of a caller-managed dispatch.public void Refine2(int rootRefinementSize, ref int subtreeRefinementStartIndex, int subtreeRefinementCount, int subtreeRefinementSize, BufferPool pool, IThreadDispatcher threadDispatcher, TaskStack* taskStack, int workerIndex, int targetTaskCount = -1, bool deterministic = false, bool usePriorityQueue = true)
Parameters
rootRefinementSize
intSize of the refinement run on nodes near the root. Nonpositive values will cause the root refinement to be skipped.
subtreeRefinementStartIndex
intIndex used to distribute subtree refinements over multiple executions.
subtreeRefinementCount
intNumber of subtree refinements to execute.
subtreeRefinementSize
intTarget size of subtree refinements. The actual size of refinement will usually be larger or smaller.
pool
BufferPoolPool used for ephemeral allocations during the refinement.
threadDispatcher
IThreadDispatcherThread dispatcher used during the refinement.
taskStack
TaskStack*BepuUtilities.TaskScheduling.TaskStack that the refine operation will push tasks onto as needed.
workerIndex
intIndex of the worker calling the function.
targetTaskCount
intNumber of tasks the refinement should try to create during execution. If negative, uses BepuUtilities.IThreadDispatcher.ThreadCount.
deterministic
boolWhether to force determinism at a slightly higher cost when using internally multithreaded execution for an individual refinement operation.
If the refine is single threaded, it is already deterministic and this flag has no effect.usePriorityQueue
boolTrue if the root refinement should use a priority queue during subtree collection to find larger nodes, false if it should try to collect a more balanced tree.
Remarks
Nodes will not be refit.
Refine2(int, ref int, int, int, BufferPool, IThreadDispatcher, bool, bool)
Incrementally refines a subset of the tree by running a binned builder over subtrees.
public void Refine2(int rootRefinementSize, ref int subtreeRefinementStartIndex, int subtreeRefinementCount, int subtreeRefinementSize, BufferPool pool, IThreadDispatcher threadDispatcher, bool deterministic = false, bool usePriorityQueue = true)
Parameters
rootRefinementSize
intSize of the refinement run on nodes near the root. Nonpositive values will cause the root refinement to be skipped.
subtreeRefinementStartIndex
intIndex used to distribute subtree refinements over multiple executions.
subtreeRefinementCount
intNumber of subtree refinements to execute.
subtreeRefinementSize
intTarget size of subtree refinements. The actual size of refinement will usually be larger or smaller.
pool
BufferPoolPool used for ephemeral allocations during the refinement.
threadDispatcher
IThreadDispatcherThread dispatcher used during the refinement.
deterministic
boolWhether to force determinism at a slightly higher cost when using internally multithreaded execution for an individual refinement operation.
If the refine is single threaded, it is already deterministic and this flag has no effect.usePriorityQueue
boolTrue if the root refinement should use a priority queue during subtree collection to find larger nodes, false if it should try to collect a more balanced tree.
Remarks
Nodes will not be refit.
Refine2(int, ref int, int, int, BufferPool, bool)
Incrementally refines a subset of the tree by running a binned builder over subtrees.
public void Refine2(int rootRefinementSize, ref int subtreeRefinementStartIndex, int subtreeRefinementCount, int subtreeRefinementSize, BufferPool pool, bool usePriorityQueue = true)
Parameters
rootRefinementSize
intSize of the refinement run on nodes near the root. Nonpositive values will cause the root refinement to be skipped.
subtreeRefinementStartIndex
intIndex used to distribute subtree refinements over multiple executions.
subtreeRefinementCount
intNumber of subtree refinements to execute.
subtreeRefinementSize
intTarget size of subtree refinements. The actual size of refinement will usually be larger or smaller.
pool
BufferPoolPool used for ephemeral allocations during the refinement.
usePriorityQueue
boolTrue if the root refinement should use a priority queue during subtree collection to find larger nodes, false if it should try to collect a more balanced tree.
Remarks
Nodes will not be refit.
Refit()
Updates the bounding boxes of all internal nodes in the tree.
public readonly void Refit()
Refit2()
Updates the bounding boxes of all internal nodes in the tree.
public readonly void Refit2()
Refit2(BufferPool, IThreadDispatcher)
Refits all bounding boxes in the tree using multiple threads.
public readonly void Refit2(BufferPool pool, IThreadDispatcher dispatcher)
Parameters
pool
BufferPoolPool used for main thread temporary allocations during execution.
dispatcher
IThreadDispatcherDispatcher used during execution.
Refit2(BufferPool, IThreadDispatcher, TaskStack*, int, int)
Refits all bounding boxes in the tree using multiple threads.
Pushes tasks into the provided BepuUtilities.TaskScheduling.TaskStack. Does not dispatch threads internally; this is intended to be used as a part of a caller-managed dispatch.public readonly void Refit2(BufferPool pool, IThreadDispatcher dispatcher, TaskStack* taskStack, int workerIndex, int targetTaskCount = -1)
Parameters
pool
BufferPoolPool used for allocations during execution.
dispatcher
IThreadDispatcherDispatcher used during execution.
taskStack
TaskStack*BepuUtilities.TaskScheduling.TaskStack that the refit operation will push tasks onto as needed.
workerIndex
intIndex of the worker calling the function.
targetTaskCount
intNumber of tasks the refit should try to create during execution.
Refit2WithCacheOptimization(BufferPool, IThreadDispatcher, TaskStack*, int, int, bool)
Refits all bounding boxes in the tree using multiple threads. Reallocates the nodes and writes the refit tree into them in depth first traversal order. The tree instance is modified to point to the new nodes.
Pushes tasks into the provided BepuUtilities.TaskScheduling.TaskStack. Does not dispatch threads internally; this is intended to be used as a part of a caller-managed dispatch.public void Refit2WithCacheOptimization(BufferPool pool, IThreadDispatcher dispatcher, TaskStack* taskStack, int workerIndex, int targetTaskCount = -1, bool disposeOriginalNodes = true)
Parameters
pool
BufferPoolPool used for allocations during execution.
dispatcher
IThreadDispatcherDispatcher used during execution.
taskStack
TaskStack*BepuUtilities.TaskScheduling.TaskStack that the refit operation will push tasks onto as needed.
workerIndex
intIndex of the worker calling the function.
targetTaskCount
intNumber of tasks the refit should try to create during execution. If negative, uses BepuUtilities.IThreadDispatcher.ThreadCount.
disposeOriginalNodes
boolWhether to dispose of the original nodes buffer. If false, it's up to the caller to dispose of it appropriately.
Refit2WithCacheOptimization(BufferPool, IThreadDispatcher, bool)
Refits all bounding boxes in the tree using multiple threads. Reallocates the nodes and metanodes and writes the refit tree into them in depth first traversal order. The tree instance is modified to point to the new nodes and metanodes.
public void Refit2WithCacheOptimization(BufferPool pool, IThreadDispatcher dispatcher, bool disposeOriginalNodes = true)
Parameters
pool
BufferPoolPool used for main thread temporary allocations during execution.
dispatcher
IThreadDispatcherDispatcher used during execution.
disposeOriginalNodes
boolWhether to dispose of the original nodes buffer. If false, it's up to the caller to dispose of it appropriately.
Refit2WithCacheOptimization(BufferPool, bool)
Updates the bounding boxes of all internal nodes in the tree. Reallocates the nodes and metanodes and writes the refit tree into them in depth first traversal order. The tree instance is modified to point to the new nodes and metanodes.
public void Refit2WithCacheOptimization(BufferPool pool, bool disposeOriginalNodes = true)
Parameters
pool
BufferPoolPool to allocate from. If disposeOriginals is true, this must be the same pool from which the Nodes buffer was allocated from.
disposeOriginalNodes
boolWhether to dispose of the original nodes buffer. If false, it's up to the caller to dispose of it appropriately.
Refit2WithCacheOptimization(Buffer<Node>)
Updates the bounding boxes of all internal nodes in the tree. The refit is based on the provided sourceNodes, and the results are written into the tree's current Nodes, Metanodes, and Leaves buffers. The nodes and metanodes will be in depth traversal order. The input source buffer is not modified.
public void Refit2WithCacheOptimization(Buffer<Node> sourceNodes)
Parameters
sourceNodes
Buffer<Node>Nodes to base the refit on.
Refit2WithCacheOptimization(Buffer<Node>, BufferPool, IThreadDispatcher, TaskStack*, int, int)
Updates the bounding boxes of all internal nodes in the tree using multiple threads. The refit is based on the provided sourceNodes, and the results are written into the tree's current Nodes, Metanodes, and Leaves buffers. The nodes and metanodes will be in depth traversal order. The input source buffer is not modified.
Pushes tasks into the provided BepuUtilities.TaskScheduling.TaskStack. Does not dispatch threads internally; this is intended to be used as a part of a caller-managed dispatch.public void Refit2WithCacheOptimization(Buffer<Node> sourceNodes, BufferPool pool, IThreadDispatcher dispatcher, TaskStack* taskStack, int workerIndex, int targetTaskCount = -1)
Parameters
sourceNodes
Buffer<Node>Nodes to base the refit on.
pool
BufferPoolPool used for allocations during execution.
dispatcher
IThreadDispatcherDispatcher used during execution.
taskStack
TaskStack*BepuUtilities.TaskScheduling.TaskStack that the refit operation will push tasks onto as needed.
workerIndex
intIndex of the worker calling the function.
targetTaskCount
intNumber of tasks the refit should try to create during execution. If negative, uses BepuUtilities.IThreadDispatcher.ThreadCount.
RefitAndRefine(BufferPool, int, float)
public void RefitAndRefine(BufferPool pool, int frameIndex, float refineAggressivenessScale = 1)
Parameters
RefitForNodeBoundsChange(int)
Refits the bounding box of every parent of the node recursively to the root.
public readonly void RefitForNodeBoundsChange(int nodeIndex)
Parameters
nodeIndex
intNode to propagate a node change for.
RemoveAt(int)
Removes a leaf at an index. If the index is not at the end of the leaf list, the last leaf is swapped into the removed location.
public int RemoveAt(int leafIndex)
Parameters
leafIndex
intIndex of the leaf to remove.
Returns
- int
Former index of the leaf that was moved into the removed leaf's slot, if any. If leafIndex pointed at the last slot in the list, then this returns -1 since no leaf was moved.
Resize(BufferPool, int)
Resizes the buffers backing the tree's nodes and leaves. Will not shrink the buffers below the size needed by the currently resident nodes and leaves.
public void Resize(BufferPool pool, int targetLeafSlotCount)
Parameters
pool
BufferPoolPool from which to take and return resources.
targetLeafSlotCount
intThe desired number of available leaf slots.
Serialize(Span<byte>)
Writes a tree into a byte buffer.
public readonly void Serialize(Span<byte> bytes)
Parameters
SweepBuild(BufferPool, Buffer<BoundingBox>)
public void SweepBuild(BufferPool pool, Buffer<BoundingBox> leafBounds)
Parameters
pool
BufferPoolleafBounds
Buffer<BoundingBox>
Sweep<TLeafTester>(in BoundingBox, Vector3, float, ref TLeafTester)
public readonly void Sweep<TLeafTester>(in BoundingBox boundingBox, Vector3 direction, float maximumT, ref TLeafTester sweepTester) where TLeafTester : ISweepLeafTester
Parameters
Type Parameters
TLeafTester
Sweep<TLeafTester>(Vector3, Vector3, Vector3, float, ref TLeafTester)
public readonly void Sweep<TLeafTester>(Vector3 min, Vector3 max, Vector3 direction, float maximumT, ref TLeafTester sweepTester) where TLeafTester : ISweepLeafTester
Parameters
Type Parameters
TLeafTester
UpdateBounds(int, Vector3, Vector3)
Applies updated bounds to the given leaf index in the tree, refitting the tree to match.
public readonly void UpdateBounds(int leafIndex, Vector3 min, Vector3 max)
Parameters
leafIndex
intIndex of the leaf in the tree to update.
min
Vector3New minimum bounds for the leaf.
max
Vector3New maximum bounds for the leaf.
Validate()
public readonly void Validate()