diff options
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs')
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | 119 |
1 files changed, 63 insertions, 56 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index ddfdea4..bfcfd21 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | |||
@@ -190,6 +190,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
190 | 190 | ||
191 | public float ODE_STEPSIZE = 0.020f; | 191 | public float ODE_STEPSIZE = 0.020f; |
192 | public float HalfOdeStep = 0.01f; | 192 | public float HalfOdeStep = 0.01f; |
193 | public int odetimestepMS = 20; // rounded | ||
193 | private float metersInSpace = 25.6f; | 194 | private float metersInSpace = 25.6f; |
194 | private float m_timeDilation = 1.0f; | 195 | private float m_timeDilation = 1.0f; |
195 | 196 | ||
@@ -247,6 +248,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
247 | /// A list of actors that should receive collision events. | 248 | /// A list of actors that should receive collision events. |
248 | /// </summary> | 249 | /// </summary> |
249 | private readonly List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>(); | 250 | private readonly List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>(); |
251 | private readonly List<PhysicsActor> _collisionEventPrimRemove = new List<PhysicsActor>(); | ||
250 | 252 | ||
251 | private readonly HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>(); | 253 | private readonly HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>(); |
252 | public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); | 254 | public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); |
@@ -489,6 +491,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
489 | } | 491 | } |
490 | 492 | ||
491 | HalfOdeStep = ODE_STEPSIZE * 0.5f; | 493 | HalfOdeStep = ODE_STEPSIZE * 0.5f; |
494 | odetimestepMS = (int)(1000.0f * ODE_STEPSIZE +0.5f); | ||
492 | 495 | ||
493 | ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf); | 496 | ContactgeomsArray = Marshal.AllocHGlobal(contactsPerCollision * d.ContactGeom.unmanagedSizeOf); |
494 | GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf); | 497 | GlobalContactsArray = GlobalContactsArray = Marshal.AllocHGlobal(maxContactsbeforedeath * d.Contact.unmanagedSizeOf); |
@@ -1064,7 +1067,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1064 | obj2LocalID = 0; | 1067 | obj2LocalID = 0; |
1065 | bool p1events = p1.SubscribedEvents(); | 1068 | bool p1events = p1.SubscribedEvents(); |
1066 | bool p2events = p2.SubscribedEvents(); | 1069 | bool p2events = p2.SubscribedEvents(); |
1067 | 1070 | ||
1068 | if (p1.IsVolumeDtc) | 1071 | if (p1.IsVolumeDtc) |
1069 | p2events = false; | 1072 | p2events = false; |
1070 | if (p2.IsVolumeDtc) | 1073 | if (p2.IsVolumeDtc) |
@@ -1073,6 +1076,21 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1073 | if (!(p2events || p1events)) | 1076 | if (!(p2events || p1events)) |
1074 | return; | 1077 | return; |
1075 | 1078 | ||
1079 | if (p1events) | ||
1080 | AddCollisionEventReporting(p1); | ||
1081 | |||
1082 | if (p2events) | ||
1083 | AddCollisionEventReporting(p2); | ||
1084 | |||
1085 | Vector3 vel = Vector3.Zero; | ||
1086 | if (p2 != null && p2.IsPhysical) | ||
1087 | vel = p2.Velocity; | ||
1088 | |||
1089 | if (p1 != null && p1.IsPhysical) | ||
1090 | vel -= p1.Velocity; | ||
1091 | |||
1092 | contact.RelativeSpeed = Vector3.Dot(vel, contact.SurfaceNormal); | ||
1093 | |||
1076 | switch ((ActorTypes)p1.PhysicsActorType) | 1094 | switch ((ActorTypes)p1.PhysicsActorType) |
1077 | { | 1095 | { |
1078 | case ActorTypes.Agent: | 1096 | case ActorTypes.Agent: |
@@ -1246,20 +1264,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1246 | } | 1264 | } |
1247 | 1265 | ||
1248 | #endregion | 1266 | #endregion |
1249 | |||
1250 | |||
1251 | |||
1252 | /// <summary> | 1267 | /// <summary> |
1253 | /// Add actor to the list that should receive collision events in the simulate loop. | 1268 | /// Add actor to the list that should receive collision events in the simulate loop. |
1254 | /// </summary> | 1269 | /// </summary> |
1255 | /// <param name="obj"></param> | 1270 | /// <param name="obj"></param> |
1256 | public void AddCollisionEventReporting(PhysicsActor obj) | 1271 | public void AddCollisionEventReporting(PhysicsActor obj) |
1257 | { | 1272 | { |
1258 | lock (_collisionEventPrim) | 1273 | if (!_collisionEventPrim.Contains(obj)) |
1259 | { | 1274 | _collisionEventPrim.Add(obj); |
1260 | if (!_collisionEventPrim.Contains(obj)) | ||
1261 | _collisionEventPrim.Add(obj); | ||
1262 | } | ||
1263 | } | 1275 | } |
1264 | 1276 | ||
1265 | /// <summary> | 1277 | /// <summary> |
@@ -1268,13 +1280,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1268 | /// <param name="obj"></param> | 1280 | /// <param name="obj"></param> |
1269 | public void RemoveCollisionEventReporting(PhysicsActor obj) | 1281 | public void RemoveCollisionEventReporting(PhysicsActor obj) |
1270 | { | 1282 | { |
1271 | lock (_collisionEventPrim) | 1283 | if (_collisionEventPrim.Contains(obj) && !_collisionEventPrimRemove.Contains(obj)) |
1272 | { | 1284 | _collisionEventPrimRemove.Add(obj); |
1273 | if (_collisionEventPrim.Contains(obj)) | ||
1274 | _collisionEventPrim.Remove(obj); | ||
1275 | } | ||
1276 | } | 1285 | } |
1277 | 1286 | ||
1287 | |||
1278 | #region Add/Remove Entities | 1288 | #region Add/Remove Entities |
1279 | 1289 | ||
1280 | public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying) | 1290 | public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying) |
@@ -1463,6 +1473,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1463 | { | 1473 | { |
1464 | // lock (OdeLock) | 1474 | // lock (OdeLock) |
1465 | { | 1475 | { |
1476 | |||
1466 | OdePrim p = (OdePrim)prim; | 1477 | OdePrim p = (OdePrim)prim; |
1467 | p.setPrimForRemoval(); | 1478 | p.setPrimForRemoval(); |
1468 | } | 1479 | } |
@@ -1818,7 +1829,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1818 | { | 1829 | { |
1819 | int ttmpstart = Util.EnvironmentTickCount(); | 1830 | int ttmpstart = Util.EnvironmentTickCount(); |
1820 | int ttmp; | 1831 | int ttmp; |
1821 | int ttmp2; | ||
1822 | 1832 | ||
1823 | while(ChangesQueue.Dequeue(out item)) | 1833 | while(ChangesQueue.Dequeue(out item)) |
1824 | { | 1834 | { |
@@ -1840,11 +1850,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1840 | if (ttmp > 20) | 1850 | if (ttmp > 20) |
1841 | break; | 1851 | break; |
1842 | } | 1852 | } |
1843 | |||
1844 | ttmp2 = Util.EnvironmentTickCountSubtract(ttmpstart); | ||
1845 | if (ttmp2 > 50) | ||
1846 | ttmp2 = 0; | ||
1847 | |||
1848 | } | 1853 | } |
1849 | 1854 | ||
1850 | // Move characters | 1855 | // Move characters |
@@ -1881,53 +1886,55 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1881 | 1886 | ||
1882 | collision_optimized(); | 1887 | collision_optimized(); |
1883 | 1888 | ||
1884 | lock (_collisionEventPrim) | 1889 | foreach (PhysicsActor obj in _collisionEventPrim) |
1885 | { | 1890 | { |
1886 | foreach (PhysicsActor obj in _collisionEventPrim) | 1891 | if (obj == null) |
1892 | continue; | ||
1893 | |||
1894 | switch ((ActorTypes)obj.PhysicsActorType) | ||
1887 | { | 1895 | { |
1888 | if (obj == null) | 1896 | case ActorTypes.Agent: |
1889 | continue; | 1897 | OdeCharacter cobj = (OdeCharacter)obj; |
1898 | cobj.AddCollisionFrameTime((int)(odetimestepMS)); | ||
1899 | cobj.SendCollisions(); | ||
1900 | break; | ||
1890 | 1901 | ||
1891 | switch ((ActorTypes)obj.PhysicsActorType) | 1902 | case ActorTypes.Prim: |
1892 | { | 1903 | OdePrim pobj = (OdePrim)obj; |
1893 | case ActorTypes.Agent: | 1904 | if (pobj.Body == IntPtr.Zero || (d.BodyIsEnabled(pobj.Body) && !pobj.m_outbounds)) |
1894 | OdeCharacter cobj = (OdeCharacter)obj; | 1905 | { |
1895 | cobj.AddCollisionFrameTime((int)(ODE_STEPSIZE*1000.0f)); | 1906 | pobj.AddCollisionFrameTime((int)(odetimestepMS)); |
1896 | cobj.SendCollisions(); | 1907 | pobj.SendCollisions(); |
1897 | break; | 1908 | } |
1898 | 1909 | break; | |
1899 | case ActorTypes.Prim: | ||
1900 | OdePrim pobj = (OdePrim)obj; | ||
1901 | if (pobj.Body == IntPtr.Zero || (d.BodyIsEnabled(pobj.Body) && !pobj.m_outbounds)) | ||
1902 | { | ||
1903 | pobj.AddCollisionFrameTime((int)(ODE_STEPSIZE * 1000.0f)); | ||
1904 | pobj.SendCollisions(); | ||
1905 | } | ||
1906 | break; | ||
1907 | } | ||
1908 | } | 1910 | } |
1909 | } | 1911 | } |
1910 | 1912 | ||
1913 | foreach (PhysicsActor obj in _collisionEventPrimRemove) | ||
1914 | _collisionEventPrim.Remove(obj); | ||
1915 | |||
1916 | _collisionEventPrimRemove.Clear(); | ||
1917 | |||
1911 | // do a ode simulation step | 1918 | // do a ode simulation step |
1912 | d.WorldQuickStep(world, ODE_STEPSIZE); | 1919 | d.WorldQuickStep(world, ODE_STEPSIZE); |
1913 | d.JointGroupEmpty(contactgroup); | 1920 | d.JointGroupEmpty(contactgroup); |
1914 | 1921 | ||
1915 | // update managed ideia of physical data and do updates to core | 1922 | // update managed ideia of physical data and do updates to core |
1916 | /* | 1923 | /* |
1917 | lock (_characters) | 1924 | lock (_characters) |
1918 | { | 1925 | { |
1919 | foreach (OdeCharacter actor in _characters) | 1926 | foreach (OdeCharacter actor in _characters) |
1920 | { | 1927 | { |
1921 | if (actor != null) | 1928 | if (actor != null) |
1922 | { | 1929 | { |
1923 | if (actor.bad) | 1930 | if (actor.bad) |
1924 | m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); | 1931 | m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); |
1925 | 1932 | ||
1926 | actor.UpdatePositionAndVelocity(); | 1933 | actor.UpdatePositionAndVelocity(); |
1927 | } | 1934 | } |
1928 | } | 1935 | } |
1929 | } | 1936 | } |
1930 | */ | 1937 | */ |
1931 | 1938 | ||
1932 | lock (_activegroups) | 1939 | lock (_activegroups) |
1933 | { | 1940 | { |