Exemplo n.º 1
0
        protected Simulation(BufferPool bufferPool, SimulationAllocationSizes initialAllocationSizes)
        {
            BufferPool = bufferPool;
            Shapes     = new Shapes(bufferPool, initialAllocationSizes.ShapesPerType);
            BroadPhase = new BroadPhase(bufferPool, initialAllocationSizes.Bodies, initialAllocationSizes.Bodies + initialAllocationSizes.Statics);
            Bodies     = new Bodies(bufferPool, Shapes, BroadPhase,
                                    initialAllocationSizes.Bodies,
                                    initialAllocationSizes.Islands,
                                    initialAllocationSizes.ConstraintCountPerBodyEstimate);
            Statics = new Statics(bufferPool, Shapes, Bodies, BroadPhase, Activator, initialAllocationSizes.Statics);

            Solver = new Solver(Bodies, BufferPool, 8,
                                initialCapacity: initialAllocationSizes.Constraints,
                                initialIslandCapacity: initialAllocationSizes.Islands,
                                minimumCapacityPerTypeBatch: initialAllocationSizes.ConstraintsPerTypeBatch);
            constraintRemover = new ConstraintRemover(BufferPool, Bodies, Solver);
            Deactivator       = new Deactivator(Bodies, Solver, BroadPhase, constraintRemover, BufferPool);
            Activator         = new IslandActivator(Bodies, Statics, Solver, BroadPhase, Deactivator, bufferPool);
            Bodies.Initialize(Solver, Activator);
            Solver.activator          = Activator;
            PoseIntegrator            = new PoseIntegrator(Bodies, Shapes, BroadPhase);
            SolverBatchCompressor     = new BatchCompressor(Solver, Bodies);
            BodyLayoutOptimizer       = new BodyLayoutOptimizer(Bodies, BroadPhase, Solver, bufferPool);
            ConstraintLayoutOptimizer = new ConstraintLayoutOptimizer(Bodies, Solver);
        }
Exemplo n.º 2
0
        public unsafe Statics(BufferPool pool, Shapes shapes, Bodies bodies, BroadPhase broadPhase, IslandActivator activator, int initialCapacity = 4096)
        {
            this.pool = pool;
            InternalResize(Math.Max(1, initialCapacity));

            this.shapes     = shapes;
            this.bodies     = bodies;
            this.broadPhase = broadPhase;
            this.activator  = activator;

            IdPool <Buffer <int> > .Create(pool.SpecializeFor <int>(), initialCapacity, out HandlePool);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs a new bodies collection. Initialize must be called for the instance to be ready for use.
        /// </summary>
        /// <param name="pool">Pool for the collection to pull persistent allocations from.</param>
        /// <param name="activator">Island activator to use when bodies undergo transitions requiring that they exist in the active set.</param>
        /// <param name="shapes">Shapes referenced by the collection's bodies.</param>
        /// <param name="broadPhase">Broad phase containing the body collidables.</param>
        /// <param name="initialBodyCapacity">Initial number of bodies to allocate space for in the active set.</param>
        /// <param name="initialIslandCapacity">Initial number of islands to allocate space for in the Sets buffer.</param>
        /// <param name="initialConstraintCapacityPerBody">Expected number of constraint references per body to allocate space for.</param>
        public unsafe Bodies(BufferPool pool, IslandActivator activator, Shapes shapes, BroadPhase broadPhase,
                             int initialBodyCapacity, int initialIslandCapacity, int initialConstraintCapacityPerBody)
        {
            this.pool = pool;

            //Note that the id pool only grows upon removal, so this is just a heuristic initialization.
            //You could get by with something a lot less aggressive, but it does tend to avoid resizes in the case of extreme churn.
            IdPool <Buffer <int> > .Create(pool.SpecializeFor <int>(), initialBodyCapacity, out HandlePool);

            ResizeHandles(initialBodyCapacity);
            pool.SpecializeFor <BodySet>().Take(initialIslandCapacity + 1, out Sets);
            ActiveSet       = new BodySet(initialBodyCapacity, pool);
            this.activator  = activator;
            this.shapes     = shapes;
            this.broadPhase = broadPhase;
            MinimumConstraintCapacityPerBody = initialConstraintCapacityPerBody;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes the bodies set. Used to complete bidirectional dependencies.
 /// </summary>
 /// <param name="solver">Solver responsible for the constraints connected to the collection's bodies.</param>
 /// <param name="activator">Island activator to use when bodies undergo transitions requiring that they exist in the active set.</param>
 public void Initialize(Solver solver, IslandActivator activator)
 {
     this.solver    = solver;
     this.activator = activator;
 }