Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a simulation supporting dynamic movement and constraints with the specified narrow phase callbacks.
        /// </summary>
        /// <param name="bufferPool">Buffer pool used to fill persistent structures and main thread ephemeral resources across the engine.</param>
        /// <param name="narrowPhaseCallbacks">Callbacks to use in the narrow phase.</param>
        /// <param name="initialAllocationSizes">Allocation sizes to initialize the simulation with. If left null, default values are chosen.</param>
        /// <returns>New simulation.</returns>
        public static Simulation Create <TNarrowPhaseCallbacks>(BufferPool bufferPool, TNarrowPhaseCallbacks narrowPhaseCallbacks,
                                                                SimulationAllocationSizes?initialAllocationSizes = null)
            where TNarrowPhaseCallbacks : struct, INarrowPhaseCallbacks
        {
            if (initialAllocationSizes == null)
            {
                initialAllocationSizes = new SimulationAllocationSizes
                {
                    Bodies        = 4096,
                    Statics       = 4096,
                    ShapesPerType = 128,
                    ConstraintCountPerBodyEstimate = 8,
                    Constraints             = 16384,
                    ConstraintsPerTypeBatch = 256
                };
            }

            var simulation  = new Simulation(bufferPool, initialAllocationSizes.Value);
            var narrowPhase = new NarrowPhase <TNarrowPhaseCallbacks>(simulation, DefaultTypes.CreateDefaultCollisionTaskRegistry(),
                                                                      narrowPhaseCallbacks, initialAllocationSizes.Value.Islands + 1);

            DefaultTypes.RegisterDefaults(simulation.Solver, narrowPhase);
            simulation.NarrowPhase             = narrowPhase;
            simulation.Sleeper.pairCache       = narrowPhase.PairCache;
            simulation.Awakener.pairCache      = narrowPhase.PairCache;
            simulation.Solver.pairCache        = narrowPhase.PairCache;
            simulation.BroadPhaseOverlapFinder = new CollidableOverlapFinder <TNarrowPhaseCallbacks>(narrowPhase, simulation.BroadPhase);

            return(simulation);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a simulation supporting dynamic movement and constraints with the specified narrow phase callbacks.
        /// </summary>
        /// <param name="bufferPool">Buffer pool used to fill persistent structures and main thread ephemeral resources across the engine.</param>
        /// <param name="narrowPhaseCallbacks">Callbacks to use in the narrow phase.</param>
        /// <param name="poseIntegratorCallbacks">Callbacks to use in the pose integrator.</param>
        /// <param name="timestepper">Timestepper that defines how the simulation state should be updated. If null, defaults to PositionFirstTimestepper.</param>
        /// <param name="solverIterationCount">Number of iterations the solver should use.</param>
        /// <param name="solverFallbackBatchThreshold">Number of synchronized batches the solver should maintain before falling back to a lower quality jacobi hybrid solver.</param>
        /// <param name="initialAllocationSizes">Allocation sizes to initialize the simulation with. If left null, default values are chosen.</param>
        /// <returns>New simulation.</returns>
        public static Simulation Create <TNarrowPhaseCallbacks, TPoseIntegratorCallbacks>(
            BufferPool bufferPool, TNarrowPhaseCallbacks narrowPhaseCallbacks, TPoseIntegratorCallbacks poseIntegratorCallbacks, ITimestepper timestepper = null,
            int solverIterationCount = 8, int solverFallbackBatchThreshold = 32, SimulationAllocationSizes?initialAllocationSizes = null)
            where TNarrowPhaseCallbacks : struct, INarrowPhaseCallbacks
            where TPoseIntegratorCallbacks : struct, IPoseIntegratorCallbacks
        {
            if (initialAllocationSizes == null)
            {
                initialAllocationSizes = new SimulationAllocationSizes
                {
                    Bodies        = 4096,
                    Statics       = 4096,
                    ShapesPerType = 128,
                    ConstraintCountPerBodyEstimate = 8,
                    Constraints             = 16384,
                    ConstraintsPerTypeBatch = 256
                };
            }

            var simulation = new Simulation(bufferPool, initialAllocationSizes.Value, solverIterationCount, solverFallbackBatchThreshold, timestepper == null ? new PositionFirstTimestepper() : timestepper);

            simulation.PoseIntegrator = new PoseIntegrator <TPoseIntegratorCallbacks>(simulation.Bodies, simulation.Shapes, simulation.BroadPhase, poseIntegratorCallbacks);
            var narrowPhase = new NarrowPhase <TNarrowPhaseCallbacks>(simulation,
                                                                      DefaultTypes.CreateDefaultCollisionTaskRegistry(), DefaultTypes.CreateDefaultSweepTaskRegistry(),
                                                                      narrowPhaseCallbacks, initialAllocationSizes.Value.Islands + 1);

            DefaultTypes.RegisterDefaults(simulation.Solver, narrowPhase);
            simulation.NarrowPhase             = narrowPhase;
            simulation.Sleeper.pairCache       = narrowPhase.PairCache;
            simulation.Awakener.pairCache      = narrowPhase.PairCache;
            simulation.Solver.pairCache        = narrowPhase.PairCache;
            simulation.BroadPhaseOverlapFinder = new CollidableOverlapFinder <TNarrowPhaseCallbacks>(narrowPhase, simulation.BroadPhase);

            return(simulation);
        }