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

            pool.SpecializeFor <UntypedList>().Take((int)(minimumSizesPerConstraintType.Count * previousCountMultiplier), out constraintCaches);
            pool.SpecializeFor <UntypedList>().Take((int)(minimumSizesPerCollisionType.Count * previousCountMultiplier), out collisionCaches);
            for (int i = 0; i < minimumSizesPerConstraintType.Count; ++i)
            {
                if (minimumSizesPerConstraintType[i] > 0)
                {
                    constraintCaches[i] = new UntypedList(Math.Max(minimumPerTypeCapacity, (int)(previousCountMultiplier * minimumSizesPerConstraintType[i])), pool);
                }
                else
                {
                    constraintCaches[i] = new UntypedList();
                }
            }
            //Clear out the remainder of slots to avoid invalid data.
            constraintCaches.Clear(minimumSizesPerConstraintType.Count, constraintCaches.Length - minimumSizesPerConstraintType.Count);
            for (int i = 0; i < minimumSizesPerCollisionType.Count; ++i)
            {
                if (minimumSizesPerCollisionType[i] > 0)
                {
                    collisionCaches[i] = new UntypedList(Math.Max(minimumPerTypeCapacity, (int)(previousCountMultiplier * minimumSizesPerCollisionType[i])), pool);
                }
                else
                {
                    collisionCaches[i] = new UntypedList();
                }
            }
            //Clear out the remainder of slots to avoid invalid data.
            collisionCaches.Clear(minimumSizesPerCollisionType.Count, collisionCaches.Length - minimumSizesPerCollisionType.Count);

            QuickList <PendingAdd, Buffer <PendingAdd> > .Create(pool.SpecializeFor <PendingAdd>(), pendingCapacity, out PendingAdds);

            QuickList <CollidablePair, Buffer <CollidablePair> > .Create(pool.SpecializeFor <CollidablePair>(), pendingCapacity, out PendingRemoves);
        }
예제 #2
0
        public WorkerPairCache(int workerIndex, BufferPool pool,
                               ref QuickList <PreallocationSizes, Buffer <PreallocationSizes> > minimumSizesPerConstraintType,
                               ref QuickList <PreallocationSizes, Buffer <PreallocationSizes> > minimumSizesPerCollisionType,
                               int pendingCapacity, int minimumPerTypeCapacity = 128)
        {
            this.workerIndex            = workerIndex;
            this.pool                   = pool;
            this.minimumPerTypeCapacity = minimumPerTypeCapacity;
            const float previousCountMultiplier = 1.25f;

            pool.SpecializeFor <UntypedList>().Take(PairCache.CollisionConstraintTypeCount, out constraintCaches);
            pool.SpecializeFor <UntypedList>().Take(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;
 //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="TFilters">Type of the filters used to influence execution of collision tasks.</typeparam>
 /// <typeparam name="TContinuations">Type of the continuations that can be triggered by the this execution.</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 <TContinuations, TFilters>(ref UntypedList batch, ref StreamingBatcher batcher, ref TContinuations continuations, ref TFilters filters)
     where TContinuations : struct, IContinuations
     where TFilters : struct, ICollisionSubtaskFilters;