diff options
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin')
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs | 79 | ||||
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | 121 | ||||
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | 70 |
3 files changed, 145 insertions, 125 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs index b36b933..ca294b8 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs | |||
@@ -128,9 +128,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
128 | public d.Mass ShellMass; | 128 | public d.Mass ShellMass; |
129 | // public bool collidelock = false; | 129 | // public bool collidelock = false; |
130 | 130 | ||
131 | private bool m_haseventsubscription = false; | ||
132 | public int m_eventsubscription = 0; | 131 | public int m_eventsubscription = 0; |
133 | private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate(); | 132 | private int m_cureventsubscription = 0; |
133 | private CollisionEventUpdate CollisionEventsThisFrame = null; | ||
134 | private bool SentEmptyCollisionsEvent; | ||
134 | 135 | ||
135 | // unique UUID of this character object | 136 | // unique UUID of this character object |
136 | public UUID m_uuid; | 137 | public UUID m_uuid; |
@@ -1120,47 +1121,72 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1120 | 1121 | ||
1121 | public override void SubscribeEvents(int ms) | 1122 | public override void SubscribeEvents(int ms) |
1122 | { | 1123 | { |
1123 | m_requestedUpdateFrequency = ms; | ||
1124 | m_eventsubscription = ms; | 1124 | m_eventsubscription = ms; |
1125 | _parent_scene.AddCollisionEventReporting(this); | 1125 | m_cureventsubscription = 0; |
1126 | m_haseventsubscription = true; | 1126 | if (CollisionEventsThisFrame == null) |
1127 | CollisionEventsThisFrame = new CollisionEventUpdate(); | ||
1128 | SentEmptyCollisionsEvent = false; | ||
1127 | } | 1129 | } |
1128 | 1130 | ||
1129 | public override void UnSubscribeEvents() | 1131 | public override void UnSubscribeEvents() |
1130 | { | 1132 | { |
1131 | m_haseventsubscription = false; | 1133 | if (CollisionEventsThisFrame != null) |
1132 | _parent_scene.RemoveCollisionEventReporting(this); | 1134 | { |
1133 | m_requestedUpdateFrequency = 0; | 1135 | CollisionEventsThisFrame.Clear(); |
1136 | CollisionEventsThisFrame = null; | ||
1137 | } | ||
1134 | m_eventsubscription = 0; | 1138 | m_eventsubscription = 0; |
1135 | } | 1139 | } |
1136 | 1140 | ||
1137 | public void AddCollisionEvent(uint CollidedWith, ContactPoint contact) | 1141 | public void AddCollisionEvent(uint CollidedWith, ContactPoint contact) |
1138 | { | 1142 | { |
1139 | if (m_haseventsubscription) | 1143 | if (CollisionEventsThisFrame == null) |
1140 | { | 1144 | CollisionEventsThisFrame = new CollisionEventUpdate(); |
1141 | // m_log.DebugFormat( | 1145 | CollisionEventsThisFrame.AddCollider(CollidedWith, contact); |
1142 | // "[PHYSICS]: Adding collision event for {0}, collidedWith {1}, contact {2}", "", CollidedWith, contact); | ||
1143 | |||
1144 | CollisionEventsThisFrame.AddCollider(CollidedWith, contact); | ||
1145 | } | ||
1146 | } | 1146 | } |
1147 | 1147 | ||
1148 | public void SendCollisions() | 1148 | public void SendCollisions() |
1149 | { | 1149 | { |
1150 | if (m_haseventsubscription && m_eventsubscription > m_requestedUpdateFrequency) | 1150 | if (CollisionEventsThisFrame == null) |
1151 | return; | ||
1152 | |||
1153 | if (m_cureventsubscription < m_eventsubscription) | ||
1154 | return; | ||
1155 | |||
1156 | m_cureventsubscription = 0; | ||
1157 | |||
1158 | int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count; | ||
1159 | |||
1160 | if (!SentEmptyCollisionsEvent || ncolisions > 0) | ||
1151 | { | 1161 | { |
1152 | if (CollisionEventsThisFrame != null) | 1162 | base.SendCollisionUpdate(CollisionEventsThisFrame); |
1163 | |||
1164 | if (ncolisions == 0) | ||
1153 | { | 1165 | { |
1154 | base.SendCollisionUpdate(CollisionEventsThisFrame); | 1166 | SentEmptyCollisionsEvent = true; |
1167 | _parent_scene.RemoveCollisionEventReporting(this); | ||
1155 | } | 1168 | } |
1156 | CollisionEventsThisFrame = new CollisionEventUpdate(); | 1169 | else |
1157 | m_eventsubscription = 0; | 1170 | { |
1158 | } | 1171 | SentEmptyCollisionsEvent = false; |
1172 | CollisionEventsThisFrame.Clear(); | ||
1173 | } | ||
1174 | } | ||
1175 | } | ||
1176 | |||
1177 | internal void AddCollisionFrameTime(int t) | ||
1178 | { | ||
1179 | // protect it from overflow crashing | ||
1180 | if (m_cureventsubscription + t >= int.MaxValue) | ||
1181 | m_cureventsubscription = 0; | ||
1182 | m_cureventsubscription += t; | ||
1159 | } | 1183 | } |
1160 | 1184 | ||
1161 | public override bool SubscribedEvents() | 1185 | public override bool SubscribedEvents() |
1162 | { | 1186 | { |
1163 | return m_haseventsubscription; | 1187 | if (m_eventsubscription > 0) |
1188 | return true; | ||
1189 | return false; | ||
1164 | } | 1190 | } |
1165 | 1191 | ||
1166 | private void changePhysicsStatus(bool NewStatus) | 1192 | private void changePhysicsStatus(bool NewStatus) |
@@ -1466,14 +1492,5 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1466 | { | 1492 | { |
1467 | _parent_scene.AddChange((PhysicsActor)this, what, arg); | 1493 | _parent_scene.AddChange((PhysicsActor)this, what, arg); |
1468 | } | 1494 | } |
1469 | |||
1470 | |||
1471 | internal void AddCollisionFrameTime(int p) | ||
1472 | { | ||
1473 | // protect it from overflow crashing | ||
1474 | if (m_eventsubscription + p >= int.MaxValue) | ||
1475 | m_eventsubscription = 0; | ||
1476 | m_eventsubscription += p; | ||
1477 | } | ||
1478 | } | 1495 | } |
1479 | } | 1496 | } |
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs index 5db4f17..b2af180 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | |||
@@ -477,58 +477,58 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
477 | 477 | ||
478 | // if(childPrim) we only know about physical linksets | 478 | // if(childPrim) we only know about physical linksets |
479 | return Ptot; | 479 | return Ptot; |
480 | /* | 480 | /* |
481 | float tmass = _mass; | 481 | float tmass = _mass; |
482 | Ptot *= tmass; | 482 | Ptot *= tmass; |
483 | 483 | ||
484 | float m; | 484 | float m; |
485 | 485 | ||
486 | foreach (OdePrim prm in childrenPrim) | 486 | foreach (OdePrim prm in childrenPrim) |
487 | { | 487 | { |
488 | m = prm._mass; | 488 | m = prm._mass; |
489 | Ptot += prm.CenterOfMass * m; | 489 | Ptot += prm.CenterOfMass * m; |
490 | tmass += m; | 490 | tmass += m; |
491 | } | 491 | } |
492 | 492 | ||
493 | if (tmass == 0) | 493 | if (tmass == 0) |
494 | tmass = 0; | 494 | tmass = 0; |
495 | else | 495 | else |
496 | tmass = 1.0f / tmass; | 496 | tmass = 1.0f / tmass; |
497 | 497 | ||
498 | Ptot *= tmass; | 498 | Ptot *= tmass; |
499 | return Ptot; | 499 | return Ptot; |
500 | */ | 500 | */ |
501 | } | 501 | } |
502 | else | 502 | else |
503 | return _position; | 503 | return _position; |
504 | } | 504 | } |
505 | } | 505 | } |
506 | } | 506 | } |
507 | /* | 507 | /* |
508 | public override Vector3 PrimOOBsize | 508 | public override Vector3 PrimOOBsize |
509 | { | 509 | { |
510 | get | 510 | get |
511 | { | 511 | { |
512 | return primOOBsize; | 512 | return primOOBsize; |
513 | } | 513 | } |
514 | } | 514 | } |
515 | 515 | ||
516 | public override Vector3 PrimOOBoffset | 516 | public override Vector3 PrimOOBoffset |
517 | { | 517 | { |
518 | get | 518 | get |
519 | { | 519 | { |
520 | return primOOBoffset; | 520 | return primOOBoffset; |
521 | } | 521 | } |
522 | } | 522 | } |
523 | 523 | ||
524 | public override float PrimOOBRadiusSQ | 524 | public override float PrimOOBRadiusSQ |
525 | { | 525 | { |
526 | get | 526 | get |
527 | { | 527 | { |
528 | return primOOBradiusSQ; | 528 | return primOOBradiusSQ; |
529 | } | 529 | } |
530 | } | 530 | } |
531 | */ | 531 | */ |
532 | public override PrimitiveBaseShape Shape | 532 | public override PrimitiveBaseShape Shape |
533 | { | 533 | { |
534 | set | 534 | set |
@@ -582,7 +582,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
582 | if (value.IsFinite()) | 582 | if (value.IsFinite()) |
583 | { | 583 | { |
584 | AddChange(changes.Velocity, value); | 584 | AddChange(changes.Velocity, value); |
585 | // _velocity = value; | 585 | // _velocity = value; |
586 | 586 | ||
587 | } | 587 | } |
588 | else | 588 | else |
@@ -937,12 +937,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
937 | if (CollisionEventsThisFrame == null) | 937 | if (CollisionEventsThisFrame == null) |
938 | CollisionEventsThisFrame = new CollisionEventUpdate(); | 938 | CollisionEventsThisFrame = new CollisionEventUpdate(); |
939 | SentEmptyCollisionsEvent = false; | 939 | SentEmptyCollisionsEvent = false; |
940 | _parent_scene.AddCollisionEventReporting(this); | ||
941 | } | 940 | } |
942 | 941 | ||
943 | public override void UnSubscribeEvents() | 942 | public override void UnSubscribeEvents() |
944 | { | 943 | { |
945 | _parent_scene.RemoveCollisionEventReporting(this); | ||
946 | if (CollisionEventsThisFrame != null) | 944 | if (CollisionEventsThisFrame != null) |
947 | { | 945 | { |
948 | CollisionEventsThisFrame.Clear(); | 946 | CollisionEventsThisFrame.Clear(); |
@@ -975,7 +973,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
975 | base.SendCollisionUpdate(CollisionEventsThisFrame); | 973 | base.SendCollisionUpdate(CollisionEventsThisFrame); |
976 | 974 | ||
977 | if (ncolisions == 0) | 975 | if (ncolisions == 0) |
976 | { | ||
978 | SentEmptyCollisionsEvent = true; | 977 | SentEmptyCollisionsEvent = true; |
978 | _parent_scene.RemoveCollisionEventReporting(this); | ||
979 | } | ||
979 | else | 980 | else |
980 | { | 981 | { |
981 | SentEmptyCollisionsEvent = false; | 982 | SentEmptyCollisionsEvent = false; |
@@ -1735,8 +1736,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1735 | 1736 | ||
1736 | d.BodySetAutoDisableFlag(Body, true); | 1737 | d.BodySetAutoDisableFlag(Body, true); |
1737 | d.BodySetAutoDisableSteps(Body, body_autodisable_frames); | 1738 | d.BodySetAutoDisableSteps(Body, body_autodisable_frames); |
1738 | // d.BodySetLinearDampingThreshold(Body, 0.01f); | 1739 | // d.BodySetLinearDampingThreshold(Body, 0.01f); |
1739 | // d.BodySetAngularDampingThreshold(Body, 0.001f); | 1740 | // d.BodySetAngularDampingThreshold(Body, 0.001f); |
1740 | d.BodySetDamping(Body, .002f, .002f); | 1741 | d.BodySetDamping(Body, .002f, .002f); |
1741 | 1742 | ||
1742 | if (m_targetSpace != IntPtr.Zero) | 1743 | if (m_targetSpace != IntPtr.Zero) |
@@ -2966,7 +2967,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2966 | givefakepos--; | 2967 | givefakepos--; |
2967 | if (givefakepos < 0) | 2968 | if (givefakepos < 0) |
2968 | givefakepos = 0; | 2969 | givefakepos = 0; |
2969 | // changeSelectedStatus(); | 2970 | // changeSelectedStatus(); |
2970 | resetCollisionAccounting(); | 2971 | resetCollisionAccounting(); |
2971 | } | 2972 | } |
2972 | 2973 | ||
@@ -2981,14 +2982,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2981 | { | 2982 | { |
2982 | _orientation = newOri; | 2983 | _orientation = newOri; |
2983 | } | 2984 | } |
2984 | /* | 2985 | /* |
2985 | else if (m_forcePosOrRotation && _orientation != newOri && Body != IntPtr.Zero) | 2986 | else if (m_forcePosOrRotation && _orientation != newOri && Body != IntPtr.Zero) |
2986 | { | 2987 | { |
2987 | FixInertia(_position, newOri); | 2988 | FixInertia(_position, newOri); |
2988 | if (!d.BodyIsEnabled(Body)) | 2989 | if (!d.BodyIsEnabled(Body)) |
2989 | d.BodyEnable(Body); | 2990 | d.BodyEnable(Body); |
2990 | } | 2991 | } |
2991 | */ | 2992 | */ |
2992 | } | 2993 | } |
2993 | else | 2994 | else |
2994 | { | 2995 | { |
@@ -3939,12 +3940,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3939 | changevelocity((Vector3)arg); | 3940 | changevelocity((Vector3)arg); |
3940 | break; | 3941 | break; |
3941 | 3942 | ||
3942 | // case changes.Acceleration: | 3943 | // case changes.Acceleration: |
3943 | // changeacceleration((Vector3)arg); | 3944 | // changeacceleration((Vector3)arg); |
3944 | // break; | 3945 | // break; |
3945 | // case changes.AngVelocity: | 3946 | // case changes.AngVelocity: |
3946 | // changeangvelocity((Vector3)arg); | 3947 | // changeangvelocity((Vector3)arg); |
3947 | // break; | 3948 | // break; |
3948 | 3949 | ||
3949 | case changes.Force: | 3950 | case changes.Force: |
3950 | changeForce((Vector3)arg); | 3951 | changeForce((Vector3)arg); |
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index 11638d7..0f341b9 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | |||
@@ -247,6 +247,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
247 | /// A list of actors that should receive collision events. | 247 | /// A list of actors that should receive collision events. |
248 | /// </summary> | 248 | /// </summary> |
249 | private readonly List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>(); | 249 | private readonly List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>(); |
250 | private readonly List<PhysicsActor> _collisionEventPrimRemove = new List<PhysicsActor>(); | ||
250 | 251 | ||
251 | private readonly HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>(); | 252 | private readonly HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>(); |
252 | public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); | 253 | public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); |
@@ -1073,6 +1074,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1073 | if (!(p2events || p1events)) | 1074 | if (!(p2events || p1events)) |
1074 | return; | 1075 | return; |
1075 | 1076 | ||
1077 | if (p1events) | ||
1078 | AddCollisionEventReporting(p1); | ||
1079 | |||
1080 | if (p2events) | ||
1081 | AddCollisionEventReporting(p2); | ||
1082 | |||
1076 | Vector3 vel = Vector3.Zero; | 1083 | Vector3 vel = Vector3.Zero; |
1077 | if (p2 != null && p2.IsPhysical) | 1084 | if (p2 != null && p2.IsPhysical) |
1078 | vel = p2.Velocity; | 1085 | vel = p2.Velocity; |
@@ -1255,20 +1262,14 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1255 | } | 1262 | } |
1256 | 1263 | ||
1257 | #endregion | 1264 | #endregion |
1258 | |||
1259 | |||
1260 | |||
1261 | /// <summary> | 1265 | /// <summary> |
1262 | /// Add actor to the list that should receive collision events in the simulate loop. | 1266 | /// Add actor to the list that should receive collision events in the simulate loop. |
1263 | /// </summary> | 1267 | /// </summary> |
1264 | /// <param name="obj"></param> | 1268 | /// <param name="obj"></param> |
1265 | public void AddCollisionEventReporting(PhysicsActor obj) | 1269 | public void AddCollisionEventReporting(PhysicsActor obj) |
1266 | { | 1270 | { |
1267 | lock (_collisionEventPrim) | 1271 | if (!_collisionEventPrim.Contains(obj)) |
1268 | { | 1272 | _collisionEventPrim.Add(obj); |
1269 | if (!_collisionEventPrim.Contains(obj)) | ||
1270 | _collisionEventPrim.Add(obj); | ||
1271 | } | ||
1272 | } | 1273 | } |
1273 | 1274 | ||
1274 | /// <summary> | 1275 | /// <summary> |
@@ -1277,13 +1278,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1277 | /// <param name="obj"></param> | 1278 | /// <param name="obj"></param> |
1278 | public void RemoveCollisionEventReporting(PhysicsActor obj) | 1279 | public void RemoveCollisionEventReporting(PhysicsActor obj) |
1279 | { | 1280 | { |
1280 | lock (_collisionEventPrim) | 1281 | if (_collisionEventPrim.Contains(obj) && !_collisionEventPrimRemove.Contains(obj)) |
1281 | { | 1282 | _collisionEventPrimRemove.Add(obj); |
1282 | if (_collisionEventPrim.Contains(obj)) | ||
1283 | _collisionEventPrim.Remove(obj); | ||
1284 | } | ||
1285 | } | 1283 | } |
1286 | 1284 | ||
1285 | |||
1287 | #region Add/Remove Entities | 1286 | #region Add/Remove Entities |
1288 | 1287 | ||
1289 | public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying) | 1288 | public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying) |
@@ -1472,6 +1471,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1472 | { | 1471 | { |
1473 | // lock (OdeLock) | 1472 | // lock (OdeLock) |
1474 | { | 1473 | { |
1474 | |||
1475 | OdePrim p = (OdePrim)prim; | 1475 | OdePrim p = (OdePrim)prim; |
1476 | p.setPrimForRemoval(); | 1476 | p.setPrimForRemoval(); |
1477 | } | 1477 | } |
@@ -1890,33 +1890,35 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1890 | 1890 | ||
1891 | collision_optimized(); | 1891 | collision_optimized(); |
1892 | 1892 | ||
1893 | lock (_collisionEventPrim) | 1893 | foreach (PhysicsActor obj in _collisionEventPrim) |
1894 | { | 1894 | { |
1895 | foreach (PhysicsActor obj in _collisionEventPrim) | 1895 | if (obj == null) |
1896 | continue; | ||
1897 | |||
1898 | switch ((ActorTypes)obj.PhysicsActorType) | ||
1896 | { | 1899 | { |
1897 | if (obj == null) | 1900 | case ActorTypes.Agent: |
1898 | continue; | 1901 | OdeCharacter cobj = (OdeCharacter)obj; |
1902 | cobj.AddCollisionFrameTime((int)(ODE_STEPSIZE * 1000.0f)); | ||
1903 | cobj.SendCollisions(); | ||
1904 | break; | ||
1899 | 1905 | ||
1900 | switch ((ActorTypes)obj.PhysicsActorType) | 1906 | case ActorTypes.Prim: |
1901 | { | 1907 | OdePrim pobj = (OdePrim)obj; |
1902 | case ActorTypes.Agent: | 1908 | if (pobj.Body == IntPtr.Zero || (d.BodyIsEnabled(pobj.Body) && !pobj.m_outbounds)) |
1903 | OdeCharacter cobj = (OdeCharacter)obj; | 1909 | { |
1904 | cobj.AddCollisionFrameTime((int)(ODE_STEPSIZE*1000.0f)); | 1910 | pobj.AddCollisionFrameTime((int)(ODE_STEPSIZE * 1000.0f)); |
1905 | cobj.SendCollisions(); | 1911 | pobj.SendCollisions(); |
1906 | break; | 1912 | } |
1907 | 1913 | break; | |
1908 | case ActorTypes.Prim: | ||
1909 | OdePrim pobj = (OdePrim)obj; | ||
1910 | if (pobj.Body == IntPtr.Zero || (d.BodyIsEnabled(pobj.Body) && !pobj.m_outbounds)) | ||
1911 | { | ||
1912 | pobj.AddCollisionFrameTime((int)(ODE_STEPSIZE * 1000.0f)); | ||
1913 | pobj.SendCollisions(); | ||
1914 | } | ||
1915 | break; | ||
1916 | } | ||
1917 | } | 1914 | } |
1918 | } | 1915 | } |
1919 | 1916 | ||
1917 | foreach (PhysicsActor obj in _collisionEventPrimRemove) | ||
1918 | _collisionEventPrim.Remove(obj); | ||
1919 | |||
1920 | _collisionEventPrimRemove.Clear(); | ||
1921 | |||
1920 | // do a ode simulation step | 1922 | // do a ode simulation step |
1921 | d.WorldQuickStep(world, ODE_STEPSIZE); | 1923 | d.WorldQuickStep(world, ODE_STEPSIZE); |
1922 | d.JointGroupEmpty(contactgroup); | 1924 | d.JointGroupEmpty(contactgroup); |