From 82dc7886fc8e7517530077a593d352939f7a29d2 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 21:15:15 +0000 Subject: remove unnecessary OdeScene._activeprims locking. Code is single-threaded --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 99 +++++++++++++--------------- 1 file changed, 46 insertions(+), 53 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 89568b6..d1c1c25 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -193,8 +193,15 @@ namespace OpenSim.Region.Physics.OdePlugin /// Avatars in the physics scene. /// private readonly HashSet _characters = new HashSet(); - + + /// + /// Prims in the physics scene. + /// private readonly HashSet _prims = new HashSet(); + + /// + /// Prims in the physics scene that are subject to physics, not just collisions. + /// private readonly HashSet _activeprims = new HashSet(); /// @@ -1565,45 +1572,42 @@ namespace OpenSim.Region.Physics.OdePlugin //} } - lock (_activeprims) + List removeprims = null; + foreach (OdePrim chr in _activeprims) { - List removeprims = null; - foreach (OdePrim chr in _activeprims) + if (chr.Body != IntPtr.Zero && d.BodyIsEnabled(chr.Body) && (!chr.m_disabled)) { - if (chr.Body != IntPtr.Zero && d.BodyIsEnabled(chr.Body) && (!chr.m_disabled)) + try { - try + lock (chr) { - lock (chr) + if (space != IntPtr.Zero && chr.prim_geom != IntPtr.Zero && chr.m_taintremove == false) { - if (space != IntPtr.Zero && chr.prim_geom != IntPtr.Zero && chr.m_taintremove == false) - { - d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback); - } - else + d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback); + } + else + { + if (removeprims == null) { - if (removeprims == null) - { - removeprims = new List(); - } - removeprims.Add(chr); - m_log.Debug("[PHYSICS]: unable to collide test active prim against space. The space was zero, the geom was zero or it was in the process of being removed. Removed it from the active prim list. This needs to be fixed!"); + removeprims = new List(); } + removeprims.Add(chr); + m_log.Debug("[PHYSICS]: unable to collide test active prim against space. The space was zero, the geom was zero or it was in the process of being removed. Removed it from the active prim list. This needs to be fixed!"); } } - catch (AccessViolationException) - { - m_log.Warn("[PHYSICS]: Unable to space collide"); - } + } + catch (AccessViolationException) + { + m_log.Warn("[PHYSICS]: Unable to space collide"); } } + } - if (removeprims != null) + if (removeprims != null) + { + foreach (OdePrim chr in removeprims) { - foreach (OdePrim chr in removeprims) - { - _activeprims.Remove(chr); - } + _activeprims.Remove(chr); } } } @@ -1770,13 +1774,10 @@ namespace OpenSim.Region.Physics.OdePlugin internal void ActivatePrim(OdePrim prim) { // adds active prim.. (ones that should be iterated over in collisions_optimized - lock (_activeprims) - { - if (!_activeprims.Contains(prim)) - _activeprims.Add(prim); - //else - // m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent"); - } + if (!_activeprims.Contains(prim)) + _activeprims.Add(prim); + //else + // m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent"); } public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, @@ -2150,8 +2151,7 @@ namespace OpenSim.Region.Physics.OdePlugin /// internal void DeactivatePrim(OdePrim prim) { - lock (_activeprims) - _activeprims.Remove(prim); + _activeprims.Remove(prim); } public override void RemovePrim(PhysicsActor prim) @@ -2818,13 +2818,10 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } // Move other active objects - lock (_activeprims) + foreach (OdePrim prim in _activeprims) { - foreach (OdePrim prim in _activeprims) - { - prim.m_collisionscore = 0; - prim.Move(timeStep); - } + prim.m_collisionscore = 0; + prim.Move(timeStep); } //if ((framecount % m_randomizeWater) == 0) @@ -2893,20 +2890,16 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); defects.Clear(); } - lock (_activeprims) + //if (timeStep < 0.2f) + + foreach (OdePrim prim in _activeprims) { - //if (timeStep < 0.2f) + if (prim.IsPhysical && (d.BodyIsEnabled(prim.Body) || !prim._zeroFlag)) { - foreach (OdePrim prim in _activeprims) - { - if (prim.IsPhysical && (d.BodyIsEnabled(prim.Body) || !prim._zeroFlag)) - { - prim.UpdatePositionAndVelocity(); + prim.UpdatePositionAndVelocity(); - if (SupportsNINJAJoints) - SimulateActorPendingJoints(prim); - } - } + if (SupportsNINJAJoints) + SimulateActorPendingJoints(prim); } } -- cgit v1.1