Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <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 (!SILVERLIGHT)
- if (Settings.EnableDiagnostics)
- _watch.Start();
- #endif
- ProcessChanges();
- #if (!SILVERLIGHT)
- if (Settings.EnableDiagnostics)
- AddRemoveTime = _watch.ElapsedTicks;
- #endif
- // If new fixtures were added, we need to find the new contacts.
- if ((Flags & WorldFlags.NewFixture) == WorldFlags.NewFixture)
- {
- ContactManager.FindNewContacts();
- Flags &= ~WorldFlags.NewFixture;
- }
- // Update contacts. This is where some contacts are destroyed.
- ContactManager.Collide();
- #if (!SILVERLIGHT)
- if (Settings.EnableDiagnostics)
- ContactsUpdateTime = _watch.ElapsedTicks - (AddRemoveTime + ControllersUpdateTime);
- #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;
- }
- 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
- // 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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement