예제 #1
0
        protected Simulation(BufferPool bufferPool, SimulationAllocationSizes initialAllocationSizes, int solverIterationCount, int solverFallbackBatchThreshold, ITimestepper timestepper)
        {
            BufferPool      = bufferPool;
            PhysicsShapes3D = new PhysicsShapes3D(bufferPool, initialAllocationSizes.ShapesPerType);
            BroadPhase      = new BroadPhase(bufferPool, initialAllocationSizes.Bodies, initialAllocationSizes.Bodies + initialAllocationSizes.Statics);
            Bodies3D        = new Bodies3D(bufferPool, PhysicsShapes3D, BroadPhase,
                                           initialAllocationSizes.Bodies,
                                           initialAllocationSizes.Islands,
                                           initialAllocationSizes.ConstraintCountPerBodyEstimate);
            Statics = new Statics(bufferPool, PhysicsShapes3D, Bodies3D, BroadPhase, initialAllocationSizes.Statics);

            Solver = new Solver(Bodies3D, BufferPool, solverIterationCount, solverFallbackBatchThreshold,
                                initialCapacity: initialAllocationSizes.Constraints,
                                initialIslandCapacity: initialAllocationSizes.Islands,
                                minimumCapacityPerTypeBatch: initialAllocationSizes.ConstraintsPerTypeBatch);
            constraintRemover = new ConstraintRemover(BufferPool, Bodies3D, Solver);
            Sleeper           = new IslandSleeper(Bodies3D, Solver, BroadPhase, constraintRemover, BufferPool);
            Awakener          = new IslandAwakener(Bodies3D, Statics, Solver, BroadPhase, Sleeper, bufferPool);
            Statics.awakener  = Awakener;
            Solver.awakener   = Awakener;
            Bodies3D.Initialize(Solver, Awakener, Sleeper);
            SolverBatchCompressor     = new BatchCompressor(Solver, Bodies3D);
            BodyLayoutOptimizer       = new BodyLayoutOptimizer(Bodies3D, BroadPhase, Solver, bufferPool);
            ConstraintLayoutOptimizer = new ConstraintLayoutOptimizer(Bodies3D, Solver);
            Timestepper = timestepper;
        }
예제 #2
0
 /// <summary>
 /// Checks if a set of children shape indices are all valid.
 /// </summary>
 /// <param name="children">Children to examine.</param>
 /// <param name="physicsShape3DBatches">Shape collection into which the children index.</param>
 /// <returns>True if all child indices are valid, false otherwise.</returns>
 public static bool ValidateChildIndices(ref Buffer <CompoundChild> children, PhysicsShapes3D physicsShape3DBatches)
 {
     for (int i = 0; i < children.Length; ++i)
     {
         ValidateChildIndex(children[i].ShapeIndex, physicsShape3DBatches);
     }
     return(true);
 }
예제 #3
0
        public unsafe Statics(BufferPool pool, PhysicsShapes3D shapes, Bodies3D bodies3D, BroadPhase broadPhase, int initialCapacity = 4096)
        {
            this.pool = pool;
            InternalResize(Math.Max(1, initialCapacity));

            this.shapes     = shapes;
            this.bodies3D   = bodies3D;
            this.broadPhase = broadPhase;

            HandlePool = new IdPool(initialCapacity, pool);
        }
예제 #4
0
 public unsafe BoundingBoxBatcher(Bodies3D bodies3D, PhysicsShapes3D shapes, BroadPhase broadPhase, BufferPool pool, float dt)
 {
     this.bodies3D   = bodies3D;
     this.shapes     = shapes;
     this.broadPhase = broadPhase;
     this.pool       = pool;
     this.dt         = dt;
     pool.TakeAtLeast(shapes.RegisteredTypeSpan, out batches);
     //Clearing is required ensure that we know when a batch needs to be created and when a batch needs to be disposed.
     batches.Clear(0, shapes.RegisteredTypeSpan);
     minimumBatchIndex = shapes.RegisteredTypeSpan;
     maximumBatchIndex = -1;
 }
예제 #5
0
 public BigCompound(Buffer <CompoundChild> children, PhysicsShapes3D physicsShapes3D, BufferPool pool)
 {
     Debug.Assert(children.Length > 0, "Compounds must have a nonzero number of children.");
     Debug.Assert(Compound.ValidateChildIndices(ref children, physicsShapes3D), "Children must all be convex.");
     Children = children;
     Tree     = new Tree(pool, children.Length);
     pool.Take(children.Length, out Buffer <BoundingBox> leafBounds);
     Compound.ComputeChildBounds(Children[0], Quaternion.Identity, physicsShapes3D, out leafBounds[0].Min, out leafBounds[0].Max);
     for (int i = 1; i < Children.Length; ++i)
     {
         ref var bounds = ref leafBounds[i];
         Compound.ComputeChildBounds(Children[i], Quaternion.Identity, physicsShapes3D, out bounds.Min, out bounds.Max);
     }
예제 #6
0
 public unsafe CollisionBatcher(BufferPool pool, PhysicsShapes3D shapes, CollisionTaskRegistry collisionTypeMatrix, float dt, TCallbacks callbacks)
 {
     Pool            = pool;
     PhysicsShapes3D = shapes;
     typeMatrix      = collisionTypeMatrix;
     Dt        = dt;
     Callbacks = callbacks;
     pool.TakeAtLeast(collisionTypeMatrix.tasks.Length, out batches);
     //Clearing is required ensure that we know when a batch needs to be created and when a batch needs to be disposed.
     batches.Clear(0, collisionTypeMatrix.tasks.Length);
     NonconvexReductions    = new BatcherContinuations <NonconvexReduction>();
     MeshReductions         = new BatcherContinuations <MeshReduction>();
     CompoundMeshReductions = new BatcherContinuations <CompoundMeshReduction>();
     minimumBatchIndex      = collisionTypeMatrix.tasks.Length;
     maximumBatchIndex      = -1;
 }
예제 #7
0
        /// <summary>
        /// Checks if a shape index.
        /// </summary>
        /// <param name="shapeIndex">Shape index to analyze.</param>
        /// <param name="physicsShape3DBatches">Shape collection into which the index indexes.</param>
        /// <returns>True if the index is valid, false otherwise.</returns>
        public static bool ValidateChildIndex(TypedIndex shapeIndex, PhysicsShapes3D physicsShape3DBatches)
        {
            if (shapeIndex.Type < 0 || shapeIndex.Type >= physicsShape3DBatches.RegisteredTypeSpan)
            {
                Debug.Fail("Child shape type needs to fit within the shape batch registered types.");
                return(false);
            }
            var batch = physicsShape3DBatches[shapeIndex.Type];

            if (shapeIndex.Index < 0 || shapeIndex.Index >= batch.Capacity)
            {
                Debug.Fail("Child shape index should point to a valid buffer location in the sahpe batch.");
                return(false);
            }
            if (physicsShape3DBatches[shapeIndex.Type].Compound)
            {
                Debug.Fail("Child shape type should be convex.");
                return(false);
            }
            //TODO: We don't have a cheap way to verify that a specific index actually contains a shape right now.
            return(true);
        }
예제 #8
0
 public CompoundBuilder(BufferPool pool, PhysicsShapes3D physicsShapes3D, int builderCapacity)
 {
     Pool = pool;
     this.physicsShapes3D = physicsShapes3D;
     Children             = new QuickList <Child>(builderCapacity, Pool);
 }
예제 #9
0
 public void RecursivelyRemoveAndDispose(int index, PhysicsShapes3D shapes, BufferPool pool)
 {
     RemoveAndDisposeChildren(index, shapes, pool);
     RemoveAndDispose(index, pool);
 }
예제 #10
0
 protected abstract void RemoveAndDisposeChildren(int index, PhysicsShapes3D physicsShapes3D, BufferPool pool);
예제 #11
0
 public unsafe void FindLocalOverlaps(ref Buffer <BoundsTestedPair> pairs, int pairCount, BufferPool pool, PhysicsShapes3D shapes, float dt, out ConvexCompoundTaskOverlaps overlaps)
 {
     overlaps = new ConvexCompoundTaskOverlaps(pool, pairCount);
     ref var        pairsToTest             = ref overlaps.subpairQueries;
예제 #12
0
        public unsafe void FindLocalOverlaps(ref Buffer <BoundsTestedPair> pairs, int pairCount, BufferPool pool, PhysicsShapes3D shapes, float dt, out CompoundPairOverlaps overlaps)
        {
            var totalCompoundChildCount = 0;

            for (int i = 0; i < pairCount; ++i)
            {
                totalCompoundChildCount += Unsafe.AsRef <TMeshA>(pairs[i].A).ChildCount;
            }
            overlaps = new CompoundPairOverlaps(pool, pairCount, totalCompoundChildCount);
            ref var pairsToTest      = ref overlaps.pairQueries;