Advertisement
Quantumplation

Updated World.Step Function

Sep 1st, 2011
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.23 KB | None | 0 0
  1.         /// <summary>
  2.         /// Take a time step. This performs collision detection, integration,
  3.         /// and constraint solution.
  4.         /// </summary>
  5.         /// <param name="dt">The amount of time to simulate, this should not vary.</param>
  6.         public void Step(float dt)
  7.         {
  8. #if (!SILVERLIGHT)
  9.             if (Settings.EnableDiagnostics)
  10.                 _watch.Start();
  11. #endif
  12.  
  13.             ProcessChanges();
  14.  
  15. #if (!SILVERLIGHT)
  16.             if (Settings.EnableDiagnostics)
  17.                 AddRemoveTime = _watch.ElapsedTicks;
  18. #endif
  19.  
  20.             // If new fixtures were added, we need to find the new contacts.
  21.             if ((Flags & WorldFlags.NewFixture) == WorldFlags.NewFixture)
  22.             {
  23.                 ContactManager.FindNewContacts();
  24.                 Flags &= ~WorldFlags.NewFixture;
  25.             }
  26.  
  27.             // Update contacts. This is where some contacts are destroyed.
  28.             ContactManager.Collide();
  29.  
  30. #if (!SILVERLIGHT)
  31.             if (Settings.EnableDiagnostics)
  32.                 ContactsUpdateTime = _watch.ElapsedTicks - (AddRemoveTime + ControllersUpdateTime);
  33. #endif
  34.  
  35.             //If there is no change in time, no need to calculate anything.
  36.             if (dt == 0 || !Enabled)
  37.             {
  38. #if (!SILVERLIGHT)
  39.                 if (Settings.EnableDiagnostics)
  40.                 {
  41.                     _watch.Stop();
  42.                     _watch.Reset();
  43.                 }
  44. #endif
  45.                 return;
  46.             }
  47.  
  48.             TimeStep step;
  49.             step.inv_dt = 1.0f / dt;
  50.             step.dt = dt;
  51.             step.dtRatio = _invDt0 * dt;
  52.  
  53.             //Update controllers
  54.             for (int i = 0; i < ControllerList.Count; i++)
  55.             {
  56.                 ControllerList[i].Update(dt);
  57.             }
  58.  
  59. #if (!SILVERLIGHT)
  60.             if (Settings.EnableDiagnostics)
  61.                 ControllersUpdateTime = _watch.ElapsedTicks - AddRemoveTime;
  62. #endif
  63.  
  64.             // Integrate velocities, solve velocity raints, and integrate positions.
  65.             Solve(ref step);
  66.  
  67. #if (!SILVERLIGHT)
  68.             if (Settings.EnableDiagnostics)
  69.                 SolveUpdateTime = _watch.ElapsedTicks - (AddRemoveTime + ControllersUpdateTime + ContactsUpdateTime);
  70. #endif
  71.  
  72.             // Handle TOI events.
  73.             if (Settings.ContinuousPhysics)
  74.             {
  75.                 SolveTOI(ref step);
  76.             }
  77.  
  78. #if (!SILVERLIGHT)
  79.             if (Settings.EnableDiagnostics)
  80.                 ContinuousPhysicsTime = _watch.ElapsedTicks -
  81.                                         (AddRemoveTime + ControllersUpdateTime + ContactsUpdateTime + SolveUpdateTime);
  82. #endif
  83.             _invDt0 = step.inv_dt;
  84.  
  85.             if ((Flags & WorldFlags.ClearForces) != 0)
  86.             {
  87.                 ClearForces();
  88.             }
  89.  
  90.             for (int i = 0; i < BreakableBodyList.Count; i++)
  91.             {
  92.                 BreakableBodyList[i].Update();
  93.             }
  94.  
  95. #if (!SILVERLIGHT)
  96.             if (Settings.EnableDiagnostics)
  97.             {
  98.                 _watch.Stop();
  99.                 //AddRemoveTime = 1000 * AddRemoveTime / Stopwatch.Frequency;
  100.  
  101.                 UpdateTime = _watch.ElapsedTicks;
  102.                 _watch.Reset();
  103.             }
  104. #endif
  105.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement