/// <summary> /// Take a time step. This performs collision detection, integration, /// and consraint solution. /// </summary> /// <param name="dt">The amount of time to simulate, this should not vary.</param> public void Step(float dt) { ProcessChanges(); //If there is no change in time, no need to calculate anything. if (dt == 0 || !Enabled) { return; } // If new fixtures were added, we need to find the new contacts. if ((Flags & WorldFlags.NewFixture) == WorldFlags.NewFixture) { ContactManager.FindNewContacts(); Flags &= ~WorldFlags.NewFixture; } TimeStep step; step.inv_dt = 1.0f / dt; step.dt = dt; step.dtRatio = _invDt0 * dt; //Update controllers for (int i = 0; i < ControllerList.Count; i++) { ControllerList[i].Update(dt); } // Update contacts. This is where some contacts are destroyed. ContactManager.Collide(); // Integrate velocities, solve velocity raints, and integrate positions. Solve(ref step); // Handle TOI events. if (Settings.ContinuousPhysics) { SolveTOI(ref step); } _invDt0 = step.inv_dt; if ((Flags & WorldFlags.ClearForces) != 0) { ClearForces(); } for (int i = 0; i < BreakableBodyList.Count; i++) { BreakableBodyList[i].Update(); } }
/// <summary> /// Take a time step. This performs collision detection, integration, /// and consraint solution. /// </summary> /// <param name="dt">The amount of time to simulate, this should not vary.</param> public void Step(float dt) { #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { _watch.Start(); } #endif ProcessChanges(); #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { AddRemoveTime = _watch.ElapsedTicks; } #endif //If there is no change in time, no need to calculate anything. if (dt == 0 || !Enabled) { #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { _watch.Stop(); _watch.Reset(); } #endif return; } // If new fixtures were added, we need to find the new contacts. if ((Flags & WorldFlags.NewFixture) == WorldFlags.NewFixture) { ContactManager.FindNewContacts(); Flags &= ~WorldFlags.NewFixture; } TimeStep step; step.inv_dt = 1.0f / dt; step.dt = dt; step.dtRatio = _invDt0 * dt; //Update controllers for (int i = 0; i < ControllerList.Count; i++) { ControllerList[i].Update(dt); } #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { ControllersUpdateTime = _watch.ElapsedTicks - AddRemoveTime; } #endif // Update contacts. This is where some contacts are destroyed. ContactManager.Collide(); #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { ContactsUpdateTime = _watch.ElapsedTicks - (AddRemoveTime + ControllersUpdateTime); } #endif // Integrate velocities, solve velocity raints, and integrate positions. Solve(ref step); #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { SolveUpdateTime = _watch.ElapsedTicks - (AddRemoveTime + ControllersUpdateTime + ContactsUpdateTime); } #endif // Handle TOI events. if (Settings.ContinuousPhysics) { SolveTOI(ref step); } #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { ContinuousPhysicsTime = _watch.ElapsedTicks - (AddRemoveTime + ControllersUpdateTime + ContactsUpdateTime + SolveUpdateTime); } #endif _invDt0 = step.inv_dt; if ((Flags & WorldFlags.ClearForces) != 0) { ClearForces(); } for (int i = 0; i < BreakableBodyList.Count; i++) { BreakableBodyList[i].Update(); } #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { _watch.Stop(); //AddRemoveTime = 1000 * AddRemoveTime / Stopwatch.Frequency; UpdateTime = _watch.ElapsedTicks; _watch.Reset(); } #endif }
/// <summary> /// Take a time step. This performs collision detection, integration, /// and consraint solution. /// </summary> /// <param name="dt">The amount of time to simulate, this should not vary.</param> public void Step(float dt) { #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { _watch.Start(); } #endif // If new fixtures were added, we need to find the new contacts. if ((Flags & WorldFlags.NewFixture) == WorldFlags.NewFixture) { ContactManager.FindNewContacts(); Flags &= ~WorldFlags.NewFixture; } #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { NewContactsTime = _watch.ElapsedTicks; } #endif Flags |= WorldFlags.Locked; TimeStep step; step.dt = dt; if (dt > 0.0f) { step.inv_dt = 1.0f / dt; } else { step.inv_dt = 0.0f; } step.dtRatio = _invDt0 * dt; // Update controllers foreach (Controller controller in Controllers) { controller.Update(dt); } #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { ControllersUpdateTime = _watch.ElapsedTicks - NewContactsTime; } #endif // Update contacts. This is where some contacts are destroyed. ContactManager.Collide(); #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { ContactsUpdateTime = _watch.ElapsedTicks - (NewContactsTime + ControllersUpdateTime); } #endif // Integrate velocities, solve velocity raints, and integrate positions. if (step.dt > 0.0f) { Solve(ref step); } #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { SolveUpdateTime = _watch.ElapsedTicks - (NewContactsTime + ControllersUpdateTime + ContactsUpdateTime); } #endif // Handle TOI events. if (Settings.ContinuousPhysics && step.dt > 0.0f) { SolveTOI(); } #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { ContinuousPhysicsTime = _watch.ElapsedTicks - (NewContactsTime + ControllersUpdateTime + ContactsUpdateTime + SolveUpdateTime); } #endif if (step.dt > 0.0f) { _invDt0 = step.inv_dt; } if ((Flags & WorldFlags.ClearForces) != 0) { ClearForces(); } // We have to unlock the world here to support breakable bodies. Flags &= ~WorldFlags.Locked; foreach (BreakableBody breakableBody in BreakableBodyList) { breakableBody.Update(); } #if (!SILVERLIGHT) if (Settings.EnableDiagnostics) { BreakableBodyTime = _watch.ElapsedTicks - (NewContactsTime + ControllersUpdateTime + ContactsUpdateTime + SolveUpdateTime + ContinuousPhysicsTime); } if (Settings.EnableDiagnostics) { _watch.Stop(); UpdateTime = _watch.ElapsedTicks; _watch.Reset(); } #endif }