/// <summary>Take a time step. This performs collision detection, integration, and constraint solution.</summary> /// <param name="dt">The amount of time to simulate, this should not vary.</param> public void Step(float dt) { if (!Enabled) { return; } if (Settings.EnableDiagnostics) { _watch.Start(); } ProcessChanges(); if (Settings.EnableDiagnostics) { InternalTimings.AddRemoveTime = _watch.ElapsedTicks; } // If new fixtures were added, we need to find the new contacts. if (_worldHasNewFixture) { ContactManager.FindNewContacts(); _worldHasNewFixture = false; } if (Settings.EnableDiagnostics) { InternalTimings.NewContactsTimeDelta = _watch.ElapsedTicks; } //Velcro only: moved position and velocity iterations into Settings.cs TimeStep step; step.InvertedDeltaTime = dt > 0.0f ? 1.0f / dt : 0.0f; step.DeltaTime = dt; step.DeltaTimeRatio = _invDt0 * dt; //Update controllers for (int i = 0; i < ControllerList.Count; i++) { ControllerList[i].Update(dt); } if (Settings.EnableDiagnostics) { InternalTimings.ControllersUpdateTimeDelta = _watch.ElapsedTicks; } // Update contacts. This is where some contacts are destroyed. ContactManager.Collide(); if (Settings.EnableDiagnostics) { InternalTimings.ContactsUpdateTimeDelta = _watch.ElapsedTicks; } // Integrate velocities, solve velocity constraints, and integrate positions. Solve(ref step); if (Settings.EnableDiagnostics) { InternalTimings.SolveUpdateTimeDelta = _watch.ElapsedTicks; } // Handle TOI events. if (Settings.ContinuousPhysics) { SolveTOI(ref step); } if (Settings.EnableDiagnostics) { InternalTimings.ContinuousPhysicsTimeDelta = _watch.ElapsedTicks; } if (Settings.AutoClearForces) { ClearForces(); } for (int i = 0; i < BreakableBodyList.Count; i++) { BreakableBodyList[i].Update(); } _invDt0 = step.InvertedDeltaTime; if (Settings.EnableDiagnostics) { _watch.Stop(); InternalTimings.UpdateTime = _watch.ElapsedTicks; _watch.Reset(); } }