public PhysicsWorld CreateWorld(Action <PhysicsWorldBuilder> builderAction) { var builder = new PhysicsWorldBuilder(this.logger); builderAction(builder); return(builder.Build()); }
protected override void OnUpdate() { // Make sure last frame's physics jobs are complete before any new ones start m_InputDependencyToComplete.Complete(); float timeStep = Time.DeltaTime; // Tweak if you want a different simulation for this world PhysicsStep stepComponent = PhysicsStep.Default; if (HasSingleton <PhysicsStep>()) { stepComponent = GetSingleton <PhysicsStep>(); } #region Build World Dependency = PhysicsWorldBuilder.SchedulePhysicsWorldBuild(this, ref PhysicsData, Dependency, timeStep, stepComponent.MultiThreaded > 0, stepComponent.Gravity, LastSystemVersion); #endregion #region Step World // Early-out to prevent simulation context creation in stepper, generally not required if (PhysicsData.PhysicsWorld.NumBodies <= 1) { return; } var stepInput = new SimulationStepInput() { World = PhysicsData.PhysicsWorld, TimeStep = timeStep, Gravity = stepComponent.Gravity, SynchronizeCollisionWorld = false, NumSolverIterations = stepComponent.SolverIterationCount, SolverStabilizationHeuristicSettings = stepComponent.SolverStabilizationHeuristicSettings, HaveStaticBodiesChanged = PhysicsData.HaveStaticBodiesChanged, }; m_Stepper.ScheduleSimulationStepJobs(stepComponent.SimulationType, WorldFilter.Value, stepInput, Dependency, stepComponent.MultiThreaded > 0); // Include the final simulation handle // (Not FinalJobHandle since other systems shouldn't need to depend on the dispose jobs) Dependency = JobHandle.CombineDependencies(Dependency, m_Stepper.FinalSimulationJobHandle); #endregion #region Export World Dependency = PhysicsWorldExporter.SchedulePhysicsWorldExport(this, in PhysicsData.PhysicsWorld, Dependency, PhysicsData.DynamicEntityGroup); #endregion // Just to make sure current server step jobs are complete before next step starts m_InputDependencyToComplete = Dependency; }
protected override void OnUpdate() { // Make sure dependencies are complete, we'll run everything immediately Dependency.Complete(); float timeStep = Time.DeltaTime; // Tweak if you want a different simulation for this world PhysicsStep stepComponent = PhysicsStep.Default; if (HasSingleton <PhysicsStep>()) { stepComponent = GetSingleton <PhysicsStep>(); } // Build PhysicsWorld immediately PhysicsWorldBuilder.BuildPhysicsWorldImmediate(this, ref PhysicsData, timeStep, stepComponent.Gravity, LastSystemVersion); // Early out if world is static if (PhysicsData.PhysicsWorld.NumDynamicBodies == 0) { return; } // Run simulation on main thread m_Stepper.StepImmediate(stepComponent.SimulationType, ref PhysicsData.PhysicsWorld, new SimulationStepInput() { World = PhysicsData.PhysicsWorld, TimeStep = timeStep, Gravity = stepComponent.Gravity, SynchronizeCollisionWorld = false, NumSolverIterations = 4, SolverStabilizationHeuristicSettings = Solver.StabilizationHeuristicSettings.Default, HaveStaticBodiesChanged = PhysicsData.HaveStaticBodiesChanged }); // Export physics world only (don't copy CollisionWorld) PhysicsWorldExporter.ExportPhysicsWorldImmediate(this, in PhysicsData.PhysicsWorld, PhysicsData.DynamicEntityGroup); }