From 1edfe05c16d13b5bbc18f753a32bdf7c7d176fe8 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Mon, 21 Nov 2011 21:15:15 +0000 Subject: [PATCH] remove unnecessary OdeScene._activeprims locking. Code is single-threaded --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 103 +++++++++---------- 1 file changed, 48 insertions(+), 55 deletions(-) diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index df2c69b503..9e50b20e22 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(); /// @@ -1562,45 +1569,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 + { + if (removeprims == null) { - d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback); - } - else - { - 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, @@ -2152,8 +2153,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) @@ -2804,13 +2804,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) @@ -2882,20 +2879,16 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); defects.Clear(); } - lock (_activeprims) - { - //if (timeStep < 0.2f) - { - foreach (OdePrim prim in _activeprims) - { - if (prim.IsPhysical && (d.BodyIsEnabled(prim.Body) || !prim._zeroFlag)) - { - prim.UpdatePositionAndVelocity(); + //if (timeStep < 0.2f) - if (SupportsNINJAJoints) - SimulateActorPendingJoints(prim); - } - } + foreach (OdePrim prim in _activeprims) + { + if (prim.IsPhysical && (d.BodyIsEnabled(prim.Body) || !prim._zeroFlag)) + { + prim.UpdatePositionAndVelocity(); + + if (SupportsNINJAJoints) + SimulateActorPendingJoints(prim); } }