Example #1
0
        public WorkerPairCache(int workerIndex, BufferPool pool,
                               ref QuickList <PreallocationSizes> minimumSizesPerConstraintType,
                               ref QuickList <PreallocationSizes> minimumSizesPerCollisionType,
                               int pendingCapacity, int minimumPerTypeCapacity = 128)
        {
            this.workerIndex            = workerIndex;
            this.pool                   = pool;
            this.minimumPerTypeCapacity = minimumPerTypeCapacity;
            const float previousCountMultiplier = 1.25f;

            pool.TakeAtLeast(PairCache.CollisionConstraintTypeCount, out constraintCaches);
            pool.TakeAtLeast(PairCache.CollisionTypeCount, out collisionCaches);
            for (int i = 0; i < minimumSizesPerConstraintType.Count; ++i)
            {
                ref var sizes = ref minimumSizesPerConstraintType[i];
                if (sizes.ElementCount > 0)
                {
                    constraintCaches[i] = new UntypedList(sizes.ElementSizeInBytes, Math.Max(minimumPerTypeCapacity, (int)(previousCountMultiplier * sizes.ElementCount)), pool);
                }
                else
                {
                    constraintCaches[i] = new UntypedList();
                }
            }
 //Note that we leave the details of input and output of a task's execution to be undefined.
 //A task can reach into the batcher and create new entries or trigger continuations as required.
 /// <summary>
 /// Executes the task on the given input.
 /// </summary>
 /// <typeparam name="TCallbacks">Type of the callbacks used to handle results of collision tasks.</typeparam>
 /// <param name="batcher">Batcher responsible for the invocation.</param>
 /// <param name="batch">Batch of pairs to test.</param>
 /// <param name="continuations">Continuations to invoke upon completion of a top level pair.</param>
 /// <param name="filters">Filters to use to influence execution of the collision tasks.</param>
 public abstract void ExecuteBatch <TCallbacks>(ref UntypedList batch, ref CollisionBatcher <TCallbacks> batcher)
     where TCallbacks : struct, ICollisionCallbacks;