diff options
author | UbitUmarov | 2012-04-23 20:16:53 +0100 |
---|---|---|
committer | UbitUmarov | 2012-04-23 20:16:53 +0100 |
commit | 5a8fdc8a0b79c14382872571b113b5c5559083c4 (patch) | |
tree | deeda42505621facef6c158bce472b81d5b1ab36 /OpenSim/Region | |
parent | ubitODE - several changes... (diff) | |
download | opensim-SC-5a8fdc8a0b79c14382872571b113b5c5559083c4.zip opensim-SC-5a8fdc8a0b79c14382872571b113b5c5559083c4.tar.gz opensim-SC-5a8fdc8a0b79c14382872571b113b5c5559083c4.tar.bz2 opensim-SC-5a8fdc8a0b79c14382872571b113b5c5559083c4.tar.xz |
ubitODE - do own timing control (as chODE does) until heartbeat does it right
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | 8 | ||||
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | 47 |
2 files changed, 34 insertions, 21 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs index 7c0bbef..dc6c18d 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | |||
@@ -695,7 +695,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
695 | m_PIDTau = 0; | 695 | m_PIDTau = 0; |
696 | else | 696 | else |
697 | { | 697 | { |
698 | float mint = (0.05f > _parent_scene.ODE_STEPSIZE ? 0.05f : _parent_scene.ODE_STEPSIZE); | 698 | float mint = (0.05f > m_timeStep ? 0.05f : m_timeStep); |
699 | if (value < mint) | 699 | if (value < mint) |
700 | m_PIDTau = mint; | 700 | m_PIDTau = mint; |
701 | else | 701 | else |
@@ -723,7 +723,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
723 | m_PIDHoverTau = 0; | 723 | m_PIDHoverTau = 0; |
724 | else | 724 | else |
725 | { | 725 | { |
726 | float mint = (0.05f > _parent_scene.ODE_STEPSIZE ? 0.05f : _parent_scene.ODE_STEPSIZE); | 726 | float mint = (0.05f > m_timeStep ? 0.05f : m_timeStep); |
727 | if (value < mint) | 727 | if (value < mint) |
728 | m_PIDHoverTau = mint; | 728 | m_PIDHoverTau = mint; |
729 | else | 729 | else |
@@ -801,7 +801,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
801 | { | 801 | { |
802 | if (force.IsFinite()) | 802 | if (force.IsFinite()) |
803 | { | 803 | { |
804 | AddChange(changes.AddForce, force / _parent_scene.ODE_STEPSIZE); | 804 | AddChange(changes.AddForce, force * m_invTimeStep); |
805 | } | 805 | } |
806 | else | 806 | else |
807 | { | 807 | { |
@@ -814,7 +814,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
814 | { | 814 | { |
815 | if (force.IsFinite()) | 815 | if (force.IsFinite()) |
816 | { | 816 | { |
817 | AddChange(changes.AddAngForce, force / _parent_scene.ODE_STEPSIZE); | 817 | AddChange(changes.AddAngForce, force * m_invTimeStep); |
818 | } | 818 | } |
819 | else | 819 | else |
820 | { | 820 | { |
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index 1d9fa93..cf74f14 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | |||
@@ -189,9 +189,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
189 | private const uint m_regionHeight = Constants.RegionSize; | 189 | private const uint m_regionHeight = Constants.RegionSize; |
190 | 190 | ||
191 | public float ODE_STEPSIZE = 0.020f; | 191 | public float ODE_STEPSIZE = 0.020f; |
192 | public float HalfOdeStep = 0.01f; | ||
192 | private float metersInSpace = 25.6f; | 193 | private float metersInSpace = 25.6f; |
193 | private float m_timeDilation = 1.0f; | 194 | private float m_timeDilation = 1.0f; |
194 | 195 | ||
196 | DateTime m_lastframe; | ||
197 | |||
195 | public float gravityx = 0f; | 198 | public float gravityx = 0f; |
196 | public float gravityy = 0f; | 199 | public float gravityy = 0f; |
197 | public float gravityz = -9.8f; | 200 | public float gravityz = -9.8f; |
@@ -485,6 +488,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
485 | } | 488 | } |
486 | } | 489 | } |
487 | 490 | ||
491 | HalfOdeStep = ODE_STEPSIZE * 0.5f; | ||
492 | |||
488 | ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf); | 493 | ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf); |
489 | GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf); | 494 | GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf); |
490 | 495 | ||
@@ -564,6 +569,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
564 | // let this now be real maximum values | 569 | // let this now be real maximum values |
565 | spaceGridMaxX--; | 570 | spaceGridMaxX--; |
566 | spaceGridMaxY--; | 571 | spaceGridMaxY--; |
572 | m_lastframe = DateTime.UtcNow; | ||
567 | } | 573 | } |
568 | 574 | ||
569 | internal void waitForSpaceUnlock(IntPtr space) | 575 | internal void waitForSpaceUnlock(IntPtr space) |
@@ -1685,24 +1691,30 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1685 | /// <returns></returns> | 1691 | /// <returns></returns> |
1686 | public override float Simulate(float timeStep) | 1692 | public override float Simulate(float timeStep) |
1687 | { | 1693 | { |
1694 | |||
1695 | DateTime now = DateTime.UtcNow; | ||
1696 | TimeSpan SinceLastFrame = now - m_lastframe; | ||
1697 | m_lastframe = now; | ||
1698 | timeStep = (float)SinceLastFrame.TotalSeconds; | ||
1699 | |||
1688 | // acumulate time so we can reduce error | 1700 | // acumulate time so we can reduce error |
1689 | step_time += timeStep; | 1701 | step_time += timeStep; |
1690 | 1702 | ||
1691 | if (step_time < ODE_STEPSIZE) | 1703 | if (step_time < HalfOdeStep) |
1692 | return 0; | 1704 | return 0; |
1693 | 1705 | ||
1694 | if (framecount >= int.MaxValue) | 1706 | if (framecount < 0) |
1695 | framecount = 0; | 1707 | framecount = 0; |
1696 | 1708 | ||
1697 | framecount++; | 1709 | framecount++; |
1698 | 1710 | ||
1699 | int curphysiteractions = m_physicsiterations; | 1711 | int curphysiteractions; |
1700 | 1712 | ||
1713 | // if in trouble reduce step resolution | ||
1701 | if (step_time >= m_SkipFramesAtms) | 1714 | if (step_time >= m_SkipFramesAtms) |
1702 | { | 1715 | curphysiteractions = m_physicsiterations / 2; |
1703 | // if in trouble reduce step resolution | 1716 | else |
1704 | curphysiteractions /= 2; | 1717 | curphysiteractions = m_physicsiterations; |
1705 | } | ||
1706 | 1718 | ||
1707 | int nodeframes = 0; | 1719 | int nodeframes = 0; |
1708 | 1720 | ||
@@ -1722,8 +1734,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1722 | base.TriggerPhysicsBasedRestart(); | 1734 | base.TriggerPhysicsBasedRestart(); |
1723 | } | 1735 | } |
1724 | 1736 | ||
1725 | 1737 | while (step_time >= HalfOdeStep && nodeframes < 10) //limit number of steps so we don't say here for ever | |
1726 | while (step_time >= ODE_STEPSIZE && nodeframes < 10) //limit number of steps so we don't say here for ever | ||
1727 | { | 1738 | { |
1728 | try | 1739 | try |
1729 | { | 1740 | { |
@@ -1905,15 +1916,17 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1905 | d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); | 1916 | d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); |
1906 | } | 1917 | } |
1907 | 1918 | ||
1908 | // think time dilation is not a physics issue alone.. but ok let's fake something | 1919 | // think time dilation as to do with dinamic step size that we dont' have |
1909 | if (step_time < ODE_STEPSIZE) // we did the required loops | 1920 | // even so tell something to world |
1921 | if (nodeframes < 10) // we did the requested loops | ||
1910 | m_timeDilation = 1.0f; | 1922 | m_timeDilation = 1.0f; |
1911 | else | 1923 | else if (step_time > 0) |
1912 | { // we didn't forget the lost ones and let user know something | 1924 | { |
1913 | m_timeDilation = 1 - step_time / timeStep; | 1925 | m_timeDilation = timeStep / step_time; |
1914 | if (m_timeDilation < 0) | 1926 | if (m_timeDilation > 1) |
1915 | m_timeDilation = 0; | 1927 | m_timeDilation = 1; |
1916 | step_time = 0; | 1928 | if (step_time > m_SkipFramesAtms) |
1929 | step_time = 0; | ||
1917 | } | 1930 | } |
1918 | } | 1931 | } |
1919 | 1932 | ||