BepuPhysics/CollisionDetection/ConstraintRemover.cs
/// <summary>
/// Returns the handles associated with all removed constraints to the solver's handle pool.
/// </summary>
/// <param name="deterministic">True if the return should be deterministic, false otherwise.</param>
/// <param name="threadPool">Pool to allocate from to support the deterministic sort.</param>
Returns the handles associated with all removed constraints to the solver's handle pool.
Returns the handles associated with all removed constraints to the solver ' s handle pool .
public void ReturnConstraintHandles(bool deterministic, BufferPool threadPool)
        {
            if (deterministic)
            {
                var intPool = threadPool.SpecializeFor<int>();
                int count = 0;
                for (int workerIndex = 0; workerIndex < threadCount; ++workerIndex)
                {
                    ref var workerCache = ref workerCaches[workerIndex];
                    for (int batchIndex = 0; batchIndex < workerCache.BatchHandles.Count; ++batchIndex)
                    {
                        count += workerCache.BatchHandles[batchIndex].Count;
                    }
                }
                if (count > 0)
                {
                    intPool.Take(count, out var sortedHandles);
                    int sortIndex = 0;
                    for (int workerIndex = 0; workerIndex < threadCount; ++workerIndex)
                    {
                        ref var workerCache = ref workerCaches[workerIndex];
                        for (int batchIndex = 0; batchIndex < workerCache.BatchHandles.Count; ++batchIndex)
                        {
                            ref var handles = ref workerCache.BatchHandles[batchIndex];
                            for (int handleIndex = 0; handleIndex < handles.Count; ++handleIndex)
                            {
                                sortedHandles[sortIndex++] = handles[handleIndex];
                            }
                        }
                    }
                    var comparer = new PrimitiveComparer<int>();
                    QuickSort.Sort(ref sortedHandles[0], 0, count - 1, ref comparer);
                    for (int i = 0; i < count; ++i)
                    {
                        solver.HandlePool.ReturnUnsafely(sortedHandles[i]);
                    }
                    intPool.Return(ref sortedHandles);
                }
            }
            else
            {
                for (int workerIndex = 0; workerIndex < threadCount; ++workerIndex)
                {
                    ref var workerCache = ref workerCaches[workerIndex];
                    for (int batchIndex = 0; batchIndex < workerCache.BatchHandles.Count; ++batchIndex)
                    {
                        ref var handles = ref workerCache.BatchHandles[batchIndex];
                        for (int handleIndex = 0; handleIndex < handles.Count; ++handleIndex)
                        {
                            solver.HandlePool.ReturnUnsafely(handles[handleIndex]);
                        }
                    }
                }
            }
        }
public void ReturnConstraintHandles ( bool deterministic , BufferPool threadPool ) { if ( deterministic ) { var intPool = threadPool . SpecializeFor < int > ( ) ; int count = 0 ; for ( int workerIndex = 0 ; workerIndex < threadCount ; ++ workerIndex ) { ref var workerCache = ref workerCaches [ workerIndex ] ; for ( int batchIndex = 0 ; batchIndex < workerCache . BatchHandles . Count ; ++ batchIndex ) { count += workerCache . BatchHandles [ batchIndex ] . Count ; } } if ( count > 0 ) { intPool . Take ( count , out var sortedHandles ) ; int sortIndex = 0 ; for ( int workerIndex = 0 ; workerIndex < threadCount ; ++ workerIndex ) { ref var workerCache = ref workerCaches [ workerIndex ] ; for ( int batchIndex = 0 ; batchIndex < workerCache . BatchHandles . Count ; ++ batchIndex ) { ref var handles = ref workerCache . BatchHandles [ batchIndex ] ; for ( int handleIndex = 0 ; handleIndex < handles . Count ; ++ handleIndex ) { sortedHandles [ sortIndex ++ ] = handles [ handleIndex ] ; } } } var comparer = new PrimitiveComparer < int > ( ) ; QuickSort . Sort ( ref sortedHandles [ 0 ] , 0 , count - 1 , ref comparer ) ; for ( int i = 0 ; i < count ; ++ i ) { solver . HandlePool . ReturnUnsafely ( sortedHandles [ i ] ) ; } intPool . Return ( ref sortedHandles ) ; } } else { for ( int workerIndex = 0 ; workerIndex < threadCount ; ++ workerIndex ) { ref var workerCache = ref workerCaches [ workerIndex ] ; for ( int batchIndex = 0 ; batchIndex < workerCache . BatchHandles . Count ; ++ batchIndex ) { ref var handles = ref workerCache . BatchHandles [ batchIndex ] ; for ( int handleIndex = 0 ; handleIndex < handles . Count ; ++ handleIndex ) { solver . HandlePool . ReturnUnsafely ( handles [ handleIndex ] ) ; } } } } }
Returns the handles associated with all removed constraints to the solver's handle pool.
Returns the handles associated with all removed constraints to the solver ' s handle pool .
//Note that neither of these paths actually zero out the slot associated with the handle. It is assumed that the typebatch removal is proceeding in parallel. //It will attempt to look up handle->index mappings, so we can't corrupt them. //The batch compressor requires constraint handles to be deterministic. While that could be changed, ensuring handle determinism fits conceptually //with the user-managed constraint handles- they are all deterministic, so the contact ones might as well be too. //We ensured the capacity of the handle pool during job creation; no need to worry about resizing. //If it's nondeterministic anyway, don't worry about the handle ordering. //We ensured the capacity of the handle pool during job creation; no need to worry about resizing.
deterministic
bool
True if the return should be deterministic, false otherwise.
True if the return should be deterministic false otherwise .
threadPool
BufferPool
Pool to allocate from to support the deterministic sort.
Pool to allocate from to support the deterministic sort .