From 4485007fce3578079d200d15e5988355772fa592 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 17:04:54 +0000 Subject: Instead of generating a new list for bad characters on every physics pass, keep reusing the same list. --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 43d852b..fe2b2b2 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -188,11 +188,20 @@ namespace OpenSim.Region.Physics.OdePlugin private d.NearCallback nearCallback; public d.TriCallback triCallback; public d.TriArrayCallback triArrayCallback; + private readonly HashSet _characters = new HashSet(); private readonly HashSet _prims = new HashSet(); private readonly HashSet _activeprims = new HashSet(); /// + /// Defects list to remove characters that no longer have finite positions due to some other bug. + /// + /// + /// Used repeatedly in Simulate() but initialized once here. + /// + private readonly List defects = new List(); + + /// /// Used to lock on manipulation of _taintedPrimL and _taintedPrimH /// private readonly Object _taintedPrimLock = new Object(); @@ -2773,18 +2782,18 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); // Move characters lock (_characters) { - List defects = new List(); foreach (OdeCharacter actor in _characters) { if (actor != null) actor.Move(defects); } + if (0 != defects.Count) { foreach (OdeCharacter defect in defects) - { RemoveCharacter(defect); - } + + defects.Clear(); } } -- cgit v1.1 From cead87005bbcb7a4f19440a3bb7876252a7b77ac Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 18:06:04 +0000 Subject: Have ODECharacter and ODEPrim both use PhysicsActor.Name instead of maintaining their own properties --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 13 +++++-------- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 1 - 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index c37d588..20bc7f6 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -123,9 +123,6 @@ namespace OpenSim.Region.Physics.OdePlugin private float m_buoyancy = 0f; // private CollisionLocker ode; - - private string m_name = String.Empty; - private bool[] m_colliderarr = new bool[11]; private bool[] m_colliderGroundarr = new bool[11]; @@ -212,7 +209,7 @@ namespace OpenSim.Region.Physics.OdePlugin _parent_scene.AddPhysicsActorTaint(this); - m_name = avName; + Name = avName; } public override int PhysicsActorType @@ -1068,7 +1065,7 @@ namespace OpenSim.Region.Physics.OdePlugin _parent_scene.BadCharacter(this); newPos = new d.Vector3(_position.X, _position.Y, _position.Z); base.RaiseOutOfBounds(_position); // Tells ScenePresence that there's a problem! - m_log.WarnFormat("[ODEPLUGIN]: Avatar Null reference for Avatar {0}, physical actor {1}", m_name, m_uuid); + m_log.WarnFormat("[ODEPLUGIN]: Avatar Null reference for Avatar {0}, physical actor {1}", Name, m_uuid); } // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) @@ -1284,8 +1281,8 @@ namespace OpenSim.Region.Physics.OdePlugin } AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z, m_tensor); - _parent_scene.geom_name_map[Shell] = m_name; - _parent_scene.actor_name_map[Shell] = (PhysicsActor)this; + _parent_scene.geom_name_map[Shell] = Name; + _parent_scene.actor_name_map[Shell] = this; _parent_scene.AddCharacter(this); } else @@ -1320,7 +1317,7 @@ namespace OpenSim.Region.Physics.OdePlugin // appear to stall initial region crossings when done here. Being done for consistency. // Velocity = Vector3.Zero; - _parent_scene.geom_name_map[Shell] = m_name; + _parent_scene.geom_name_map[Shell] = Name; _parent_scene.actor_name_map[Shell] = (PhysicsActor)this; } else diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 1ba7ef7..5f21c9d 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -184,7 +184,6 @@ namespace OpenSim.Region.Physics.OdePlugin private bool m_lastUpdateSent; public IntPtr Body = IntPtr.Zero; - public String Name { get; private set; } private Vector3 _target_velocity; private d.Mass pMass; -- cgit v1.1 From 898904d83d371b69d001b669588f29c2befd6aa9 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 18:27:41 +0000 Subject: When an ODECharacter is removed (e.g. when an avatar leaves a scene), remove the actor reference in OdeScene.actor_name_map rather than leaving it dangling. This also largely centralizes adds/removes in OdeScene.AddCharacter()/RemoveCharacter() --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 11 ++--------- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 20bc7f6..3e7fadf 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -599,13 +599,11 @@ namespace OpenSim.Region.Physics.OdePlugin d.RFromAxisAndAngle(out m_caprot, 0, 0, 1, (float)(Math.PI / 2)); } - d.GeomSetRotation(Shell, ref m_caprot); d.BodySetRotation(Body, ref m_caprot); d.GeomSetBody(Shell, Body); - // The purpose of the AMotor here is to keep the avatar's physical // surrogate from rotating while moving Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero); @@ -660,7 +658,6 @@ namespace OpenSim.Region.Physics.OdePlugin //standupStraight(); } - // /// /// Uses the capped cyllinder volume formula to calculate the avatar's mass. /// This may be used in calculations in the scene/scenepresence @@ -1162,14 +1159,12 @@ namespace OpenSim.Region.Physics.OdePlugin { //kill the body d.BodyDestroy(Body); - Body = IntPtr.Zero; } if (Shell != IntPtr.Zero) { d.GeomDestroy(Shell); - _parent_scene.geom_name_map.Remove(Shell); Shell = IntPtr.Zero; } } @@ -1279,10 +1274,8 @@ namespace OpenSim.Region.Physics.OdePlugin + (Body!=IntPtr.Zero ? "Body ":"") + (Amotor!=IntPtr.Zero ? "Amotor ":"")); } + AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z, m_tensor); - - _parent_scene.geom_name_map[Shell] = Name; - _parent_scene.actor_name_map[Shell] = this; _parent_scene.AddCharacter(this); } else @@ -1318,7 +1311,7 @@ namespace OpenSim.Region.Physics.OdePlugin // Velocity = Vector3.Zero; _parent_scene.geom_name_map[Shell] = Name; - _parent_scene.actor_name_map[Shell] = (PhysicsActor)this; + _parent_scene.actor_name_map[Shell] = this; } else { diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index fe2b2b2..9dee07b 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -238,8 +238,23 @@ namespace OpenSim.Region.Physics.OdePlugin private readonly Dictionary _collisionEventPrimChanges = new Dictionary(); private readonly HashSet _badCharacter = new HashSet(); + + /// + /// Maps a unique geometry id (a memory location) to a physics actor name. + /// + /// + /// Only actors participating in collisions have geometries. + /// public Dictionary geom_name_map = new Dictionary(); + + /// + /// Maps a unique geometry id (a memory location) to a physics actor. + /// + /// + /// Only actors participating in collisions have geometries. + /// public Dictionary actor_name_map = new Dictionary(); + private bool m_NINJA_physics_joints_enabled = false; //private Dictionary jointpart_name_map = new Dictionary(); private readonly Dictionary> joints_connecting_actor = new Dictionary>(); @@ -1699,8 +1714,11 @@ namespace OpenSim.Region.Physics.OdePlugin if (!_characters.Contains(chr)) { _characters.Add(chr); + geom_name_map[chr.Shell] = Name; + actor_name_map[chr.Shell] = chr; + if (chr.bad) - m_log.DebugFormat("[PHYSICS] Added BAD actor {0} to characters list", chr.m_uuid); + m_log.ErrorFormat("[PHYSICS] Added BAD actor {0} to characters list", chr.m_uuid); } } } @@ -1712,6 +1730,8 @@ namespace OpenSim.Region.Physics.OdePlugin if (_characters.Contains(chr)) { _characters.Remove(chr); + geom_name_map.Remove(chr.Shell); + actor_name_map.Remove(chr.Shell); } } } -- cgit v1.1 From 4faac1f090b668274e9a07356b8a093d1b662b7e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 19:06:53 +0000 Subject: When changing avatar size in ODE, remove the old actor from the name and actor maps --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 18 +++++++++++------- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 4 +++- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 3e7fadf..efe3b7e 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -526,7 +526,6 @@ namespace OpenSim.Region.Physics.OdePlugin } } - // movementVector.Z is zero // calculate tilt components based on desired amount of tilt and current (snapped) heading. @@ -1291,16 +1290,21 @@ namespace OpenSim.Region.Physics.OdePlugin { if (Shell != IntPtr.Zero && Body != IntPtr.Zero && Amotor != IntPtr.Zero) { -// m_log.DebugFormat("[PHYSICS]: Changing capsule size"); +// m_log.DebugFormat( +// "[ODE CHARACTER]: Changing capsule size from {0} to {1} for {2}", +// CAPSULE_LENGTH, m_tainted_CAPSULE_LENGTH, Name); m_pidControllerActive = true; + + _parent_scene.geom_name_map.Remove(Shell); + _parent_scene.actor_name_map.Remove(Shell); + // no lock needed on _parent_scene.OdeLock because we are called from within the thread lock in OdePlugin's simulate() - d.JointDestroy(Amotor); + DestroyOdeStructures(); + float prevCapsule = CAPSULE_LENGTH; CAPSULE_LENGTH = m_tainted_CAPSULE_LENGTH; - //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString()); - d.BodyDestroy(Body); - d.GeomDestroy(Shell); + AvatarGeomAndBodyCreation( _position.X, _position.Y, @@ -1315,7 +1319,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Warn("[PHYSICS]: trying to change capsule size, but the following ODE data is missing - " + m_log.Warn("[ODE CHARACTER]: trying to change capsule size, but the following ODE data is missing - " + (Shell==IntPtr.Zero ? "Shell ":"") + (Body==IntPtr.Zero ? "Body ":"") + (Amotor==IntPtr.Zero ? "Amotor ":"")); diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 9dee07b..d5c3250 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -243,7 +243,9 @@ namespace OpenSim.Region.Physics.OdePlugin /// Maps a unique geometry id (a memory location) to a physics actor name. /// /// - /// Only actors participating in collisions have geometries. + /// Only actors participating in collisions have geometries. This has to be maintained separately from + /// actor_name_map because terrain and water currently don't conceptually have a physics actor of their own + /// apart from the singleton PANull /// public Dictionary geom_name_map = new Dictionary(); -- cgit v1.1 From 3becda919e0cb82e29742c50923f1b72c1a02241 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 19:30:21 +0000 Subject: move geom/actor map maintenance into DestroyODEStructures()/AvatarGeomAndBodyCreation(). This saves us having to do it separately when a character capsule size is changed --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 17 +++++++++-------- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 2 -- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index efe3b7e..0f1a897 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -655,6 +655,9 @@ namespace OpenSim.Region.Physics.OdePlugin // //m_log.Info("[PHYSICSAV]: Rotation: " + bodyrotation.M00 + " : " + bodyrotation.M01 + " : " + bodyrotation.M02 + " : " + bodyrotation.M10 + " : " + bodyrotation.M11 + " : " + bodyrotation.M12 + " : " + bodyrotation.M20 + " : " + bodyrotation.M21 + " : " + bodyrotation.M22); //standupStraight(); + + _parent_scene.geom_name_map[Shell] = Name; + _parent_scene.actor_name_map[Shell] = this; } /// @@ -896,7 +899,7 @@ namespace OpenSim.Region.Physics.OdePlugin if (!localPos.IsFinite()) { - m_log.Warn("[PHYSICS]: Avatar Position is non-finite!"); + m_log.WarnFormat("[PHYSICS]: Avatar Position of {0} is non-finite!", Name); defects.Add(this); // _parent_scene.RemoveCharacter(this); @@ -1059,9 +1062,10 @@ namespace OpenSim.Region.Physics.OdePlugin { bad = true; _parent_scene.BadCharacter(this); + DestroyOdeStructures(); newPos = new d.Vector3(_position.X, _position.Y, _position.Z); base.RaiseOutOfBounds(_position); // Tells ScenePresence that there's a problem! - m_log.WarnFormat("[ODEPLUGIN]: Avatar Null reference for Avatar {0}, physical actor {1}", Name, m_uuid); + m_log.WarnFormat("[ODE CHARACTER]: Avatar Null reference for Avatar {0}, physical actor {1}", Name, m_uuid); } // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) @@ -1164,6 +1168,9 @@ namespace OpenSim.Region.Physics.OdePlugin if (Shell != IntPtr.Zero) { d.GeomDestroy(Shell); + _parent_scene.geom_name_map.Remove(Shell); + _parent_scene.actor_name_map.Remove(Shell); + Shell = IntPtr.Zero; } } @@ -1296,9 +1303,6 @@ namespace OpenSim.Region.Physics.OdePlugin m_pidControllerActive = true; - _parent_scene.geom_name_map.Remove(Shell); - _parent_scene.actor_name_map.Remove(Shell); - // no lock needed on _parent_scene.OdeLock because we are called from within the thread lock in OdePlugin's simulate() DestroyOdeStructures(); @@ -1313,9 +1317,6 @@ namespace OpenSim.Region.Physics.OdePlugin // As with Size, we reset velocity. However, this isn't strictly necessary since it doesn't // appear to stall initial region crossings when done here. Being done for consistency. // Velocity = Vector3.Zero; - - _parent_scene.geom_name_map[Shell] = Name; - _parent_scene.actor_name_map[Shell] = this; } else { diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index d5c3250..05455dc 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -1716,8 +1716,6 @@ namespace OpenSim.Region.Physics.OdePlugin if (!_characters.Contains(chr)) { _characters.Add(chr); - geom_name_map[chr.Shell] = Name; - actor_name_map[chr.Shell] = chr; if (chr.bad) m_log.ErrorFormat("[PHYSICS] Added BAD actor {0} to characters list", chr.m_uuid); -- cgit v1.1 From 54789706f40d0800d1277eeb71afd61edcefd9ab Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 19:45:22 +0000 Subject: Reduce complexity of OdeScene.Simulate() by fully removing bad characters at point of detection rather than later on. --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 57 ++++++++++++------------ OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 42 +---------------- 2 files changed, 29 insertions(+), 70 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 0f1a897..c838587 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -178,7 +178,7 @@ namespace OpenSim.Region.Physics.OdePlugin parent_scene.GetTerrainHeightAtXY(128f, 128f) + 10f); m_taintPosition = _position; - m_log.Warn("[PHYSICS]: Got NaN Position on Character Create"); + m_log.WarnFormat("[ODE CHARACTER]: Got NaN Position on Character Create for {0}", avName); } _parent_scene = parent_scene; @@ -201,7 +201,7 @@ namespace OpenSim.Region.Physics.OdePlugin m_colliderarr[i] = false; } CAPSULE_LENGTH = (size.Z * 1.15f) - CAPSULE_RADIUS * 2.0f; - //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString()); + //m_log.Info("[ODE CHARACTER]: " + CAPSULE_LENGTH.ToString()); m_tainted_CAPSULE_LENGTH = CAPSULE_LENGTH; m_isPhysical = false; // current status: no ODE information exists @@ -266,7 +266,7 @@ namespace OpenSim.Region.Physics.OdePlugin set { flying = value; -// m_log.DebugFormat("[PHYSICS]: Set OdeCharacter Flying to {0}", flying); +// m_log.DebugFormat("[ODE CHARACTER]: Set OdeCharacter Flying to {0}", flying); } } @@ -437,7 +437,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Warn("[PHYSICS]: Got a NaN Position from Scene on a Character"); + m_log.WarnFormat("[ODE CHARACTER]: Got a NaN Position from Scene on character {0}", Name); } } } @@ -464,7 +464,7 @@ namespace OpenSim.Region.Physics.OdePlugin Vector3 SetSize = value; m_tainted_CAPSULE_LENGTH = (SetSize.Z * 1.15f) - CAPSULE_RADIUS * 2.0f; -// m_log.Info("[SIZE]: " + CAPSULE_LENGTH); +// m_log.Info("[ODE CHARACTER]: " + CAPSULE_LENGTH); // If we reset velocity here, then an avatar stalls when it crosses a border for the first time // (as the height of the new root agent is set). @@ -474,7 +474,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Warn("[PHYSICS]: Got a NaN Size from Scene on a Character"); + m_log.WarnFormat("[ODE CHARACTER]: Got a NaN Size from Scene on {0}", Name); } } } @@ -533,7 +533,7 @@ namespace OpenSim.Region.Physics.OdePlugin float xTiltComponent = -movementVector.X * m_tiltMagnitudeWhenProjectedOnXYPlane; float yTiltComponent = -movementVector.Y * m_tiltMagnitudeWhenProjectedOnXYPlane; - //m_log.Debug("[PHYSICS] changing avatar tilt"); + //m_log.Debug("[ODE CHARACTER]: changing avatar tilt"); d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, xTiltComponent); d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, xTiltComponent); // must be same as lowstop, else a different, spurious tilt is introduced d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, yTiltComponent); @@ -560,17 +560,16 @@ namespace OpenSim.Region.Physics.OdePlugin _parent_scene.waitForSpaceUnlock(_parent_scene.space); if (CAPSULE_LENGTH <= 0) { - m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); + m_log.Warn("[ODE CHARACTER]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); CAPSULE_LENGTH = 0.01f; - } if (CAPSULE_RADIUS <= 0) { - m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); + m_log.Warn("[ODE CHARACTER]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); CAPSULE_RADIUS = 0.01f; - } + Shell = d.CreateCapsule(_parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH); d.GeomSetCategoryBits(Shell, (int)m_collisionCategories); @@ -770,7 +769,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Warn("[PHYSICS]: Got a NaN velocity from Scene in a Character"); + m_log.WarnFormat("[ODE CHARACTER]: Got a NaN velocity from Scene for {0}", Name); } // m_log.DebugFormat("[PHYSICS]: Set target velocity of {0}", m_taintTargetVelocity); @@ -848,7 +847,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Warn("[PHYSICS]: Got a NaN force applied to a Character"); + m_log.WarnFormat("[ODE CHARACTER]: Got a NaN force applied to {0}", Name); } //m_lastUpdateSent = false; } @@ -874,11 +873,11 @@ namespace OpenSim.Region.Physics.OdePlugin /// Called from Simulate /// This is the avatar's movement control + PID Controller /// - /// - /// If there is something wrong with the character (e.g. its position is non-finite) - /// then it is added to this list. The ODE structures associated with it are also destroyed. - /// - internal void Move(List defects) + /// + /// This routine will remove the character from the physics scene if it detects something wrong (non-finite + /// position or velocity). + /// + internal void Move() { // no lock; for now it's only called from within Simulate() @@ -899,11 +898,11 @@ namespace OpenSim.Region.Physics.OdePlugin if (!localPos.IsFinite()) { - m_log.WarnFormat("[PHYSICS]: Avatar Position of {0} is non-finite!", Name); - - defects.Add(this); - // _parent_scene.RemoveCharacter(this); + m_log.WarnFormat( + "[ODE CHARACTER]: Avatar position of {0} for {1} is non-finite! Removing from physics scene.", + localPos, Name); + _parent_scene.RemoveCharacter(this); DestroyOdeStructures(); return; @@ -1038,11 +1037,11 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Warn("[PHYSICS]: Got a NaN force vector in Move()"); - m_log.Warn("[PHYSICS]: Avatar Position is non-finite!"); - defects.Add(this); - // _parent_scene.RemoveCharacter(this); + m_log.WarnFormat( + "[ODE CHARACTER]: Got a NaN force vector {0} in Move() for {1}. Removing character from physics scene.", + vec, Name); + _parent_scene.RemoveCharacter(this); DestroyOdeStructures(); } } @@ -1061,7 +1060,7 @@ namespace OpenSim.Region.Physics.OdePlugin catch (NullReferenceException) { bad = true; - _parent_scene.BadCharacter(this); + _parent_scene.RemoveCharacter(this); DestroyOdeStructures(); newPos = new d.Vector3(_position.X, _position.Y, _position.Z); base.RaiseOutOfBounds(_position); // Tells ScenePresence that there's a problem! @@ -1275,7 +1274,7 @@ namespace OpenSim.Region.Physics.OdePlugin // Create avatar capsule and related ODE data if (!(Shell == IntPtr.Zero && Body == IntPtr.Zero && Amotor == IntPtr.Zero)) { - m_log.Warn("[PHYSICS]: re-creating the following avatar ODE data, even though it already exists - " + m_log.Warn("[ODE CHARACTER]: re-creating the following avatar ODE data for " + Name + ", even though it already exists - " + (Shell!=IntPtr.Zero ? "Shell ":"") + (Body!=IntPtr.Zero ? "Body ":"") + (Amotor!=IntPtr.Zero ? "Amotor ":"")); @@ -1320,7 +1319,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Warn("[ODE CHARACTER]: trying to change capsule size, but the following ODE data is missing - " + m_log.Warn("[ODE CHARACTER]: trying to change capsule size for " + Name + ", but the following ODE data is missing - " + (Shell==IntPtr.Zero ? "Shell ":"") + (Body==IntPtr.Zero ? "Body ":"") + (Amotor==IntPtr.Zero ? "Amotor ":"")); diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 05455dc..9c3c077 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -194,14 +194,6 @@ namespace OpenSim.Region.Physics.OdePlugin private readonly HashSet _activeprims = new HashSet(); /// - /// Defects list to remove characters that no longer have finite positions due to some other bug. - /// - /// - /// Used repeatedly in Simulate() but initialized once here. - /// - private readonly List defects = new List(); - - /// /// Used to lock on manipulation of _taintedPrimL and _taintedPrimH /// private readonly Object _taintedPrimLock = new Object(); @@ -236,8 +228,6 @@ namespace OpenSim.Region.Physics.OdePlugin /// A dictionary of collision event changes that are waiting to be processed. /// private readonly Dictionary _collisionEventPrimChanges = new Dictionary(); - - private readonly HashSet _badCharacter = new HashSet(); /// /// Maps a unique geometry id (a memory location) to a physics actor name. @@ -1736,15 +1726,6 @@ namespace OpenSim.Region.Physics.OdePlugin } } - internal void BadCharacter(OdeCharacter chr) - { - lock (_badCharacter) - { - if (!_badCharacter.Contains(chr)) - _badCharacter.Add(chr); - } - } - private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation, PrimitiveBaseShape pbs, bool isphysical, uint localID) { @@ -2805,15 +2786,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); foreach (OdeCharacter actor in _characters) { if (actor != null) - actor.Move(defects); - } - - if (0 != defects.Count) - { - foreach (OdeCharacter defect in defects) - RemoveCharacter(defect); - - defects.Clear(); + actor.Move(); } } @@ -2885,19 +2858,6 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } } - lock (_badCharacter) - { - if (_badCharacter.Count > 0) - { - foreach (OdeCharacter chr in _badCharacter) - { - RemoveCharacter(chr); - } - - _badCharacter.Clear(); - } - } - lock (_activeprims) { //if (timeStep < 0.2f) -- cgit v1.1 From 225b925f4ec6a0b7dfec27589d0aea40ce0a8e54 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 19:48:31 +0000 Subject: Comment out calls to OdeScene.waitForSpaceUnlock() since that method does nothing right now --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 4 ++-- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 18 ++++++++--------- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 25 ++++++++++++------------ 3 files changed, 24 insertions(+), 23 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index c838587..af67407 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -557,7 +557,7 @@ namespace OpenSim.Region.Physics.OdePlugin //CAPSULE_LENGTH = -5; //CAPSULE_RADIUS = -5; int dAMotorEuler = 1; - _parent_scene.waitForSpaceUnlock(_parent_scene.space); +// _parent_scene.waitForSpaceUnlock(_parent_scene.space); if (CAPSULE_LENGTH <= 0) { m_log.Warn("[ODE CHARACTER]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); @@ -1155,7 +1155,7 @@ namespace OpenSim.Region.Physics.OdePlugin } //kill the Geometry - _parent_scene.waitForSpaceUnlock(_parent_scene.space); +// _parent_scene.waitForSpaceUnlock(_parent_scene.space); if (Body != IntPtr.Zero) { diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 5f21c9d..fec4693 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -856,7 +856,7 @@ namespace OpenSim.Region.Physics.OdePlugin m_MeshToTriMeshMap[mesh] = _triMeshData; } - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); try { if (prim_geom == IntPtr.Zero) @@ -1379,7 +1379,7 @@ Console.WriteLine("CreateGeom:"); { if (((_size.X / 2f) > 0f)) { - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); try { //Console.WriteLine(" CreateGeom 1"); @@ -1393,7 +1393,7 @@ Console.WriteLine("CreateGeom:"); } else { - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); try { //Console.WriteLine(" CreateGeom 2"); @@ -1408,7 +1408,7 @@ Console.WriteLine("CreateGeom:"); } else { - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); try { //Console.WriteLine(" CreateGeom 3"); @@ -1423,7 +1423,7 @@ Console.WriteLine("CreateGeom:"); } else { - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); try { //Console.WriteLine(" CreateGeom 4"); @@ -1576,17 +1576,17 @@ Console.WriteLine(" JointCreateFixed"); { // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position); // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position); - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); IntPtr tempspace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace); m_targetSpace = tempspace; - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); if (prim_geom != IntPtr.Zero) { d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); d.SpaceAdd(m_targetSpace, prim_geom); } } @@ -1977,7 +1977,7 @@ Console.WriteLine(" JointCreateFixed"); if (d.SpaceQuery(m_targetSpace, prim_geom)) { - _parent_scene.waitForSpaceUnlock(m_targetSpace); +// _parent_scene.waitForSpaceUnlock(m_targetSpace); d.SpaceRemove(m_targetSpace, prim_geom); } diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 9c3c077..b952b30 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -679,11 +679,11 @@ namespace OpenSim.Region.Physics.OdePlugin } } - internal void waitForSpaceUnlock(IntPtr space) - { - //if (space != IntPtr.Zero) - //while (d.SpaceLockQuery(space)) { } // Wait and do nothing - } +// internal void waitForSpaceUnlock(IntPtr space) +// { +// //if (space != IntPtr.Zero) +// //while (d.SpaceLockQuery(space)) { } // Wait and do nothing +// } // /// // /// Debug space message for printing the space that a prim/avatar is in. @@ -2303,7 +2303,7 @@ namespace OpenSim.Region.Physics.OdePlugin { if (d.GeomIsSpace(currentspace)) { - waitForSpaceUnlock(currentspace); +// waitForSpaceUnlock(currentspace); d.SpaceRemove(currentspace, geom); } else @@ -2319,7 +2319,7 @@ namespace OpenSim.Region.Physics.OdePlugin { if (d.GeomIsSpace(currentspace)) { - waitForSpaceUnlock(sGeomIsIn); +// waitForSpaceUnlock(sGeomIsIn); d.SpaceRemove(sGeomIsIn, geom); } else @@ -2337,8 +2337,8 @@ namespace OpenSim.Region.Physics.OdePlugin { if (d.GeomIsSpace(currentspace)) { - waitForSpaceUnlock(currentspace); - waitForSpaceUnlock(space); +// waitForSpaceUnlock(currentspace); +// waitForSpaceUnlock(space); d.SpaceRemove(space, currentspace); // free up memory used by the space. @@ -2362,7 +2362,7 @@ namespace OpenSim.Region.Physics.OdePlugin { if (d.GeomIsSpace(currentspace)) { - waitForSpaceUnlock(currentspace); +// waitForSpaceUnlock(currentspace); d.SpaceRemove(currentspace, geom); } else @@ -2378,7 +2378,7 @@ namespace OpenSim.Region.Physics.OdePlugin { if (d.GeomIsSpace(sGeomIsIn)) { - waitForSpaceUnlock(sGeomIsIn); +// waitForSpaceUnlock(sGeomIsIn); d.SpaceRemove(sGeomIsIn, geom); } else @@ -2417,9 +2417,10 @@ namespace OpenSim.Region.Physics.OdePlugin // creating a new space for prim and inserting it into main space. staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero); d.GeomSetCategoryBits(staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY], (int)CollisionCategories.Space); - waitForSpaceUnlock(space); +// waitForSpaceUnlock(space); d.SpaceSetSublevel(space, 1); d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]); + return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]; } -- cgit v1.1 From 063f0f5d97d8b8d38a57c7a0601e9133d0054a26 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 19:58:37 +0000 Subject: refactor: Eliminate one line ODECharacter.doForce() method for code clarity --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index af67407..afa8de5 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -70,7 +70,6 @@ namespace OpenSim.Region.Physics.OdePlugin private Vector3 _position; private d.Vector3 _zeroPosition; - // private d.Matrix3 m_StandUpRotation; private bool _zeroFlag = false; private bool m_lastUpdateSent = false; private Vector3 _velocity; @@ -554,8 +553,6 @@ namespace OpenSim.Region.Physics.OdePlugin // place that is safe to call this routine AvatarGeomAndBodyCreation. private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ, float tensor) { - //CAPSULE_LENGTH = -5; - //CAPSULE_RADIUS = -5; int dAMotorEuler = 1; // _parent_scene.waitForSpaceUnlock(_parent_scene.space); if (CAPSULE_LENGTH <= 0) @@ -831,7 +828,6 @@ namespace OpenSim.Region.Physics.OdePlugin m_taintForce += force; _parent_scene.AddPhysicsActorTaint(this); - //doForce(force); // If uncommented, things get pushed off world // // m_log.Debug("Push!"); @@ -856,15 +852,6 @@ namespace OpenSim.Region.Physics.OdePlugin { } - /// - /// After all of the forces add up with 'add force' we apply them with doForce - /// - /// - public void doForce(Vector3 force) - { - d.BodyAddForce(Body, force.X, force.Y, force.Z); - } - public override void SetMomentum(Vector3 momentum) { } @@ -1030,7 +1017,8 @@ namespace OpenSim.Region.Physics.OdePlugin if (vec.IsFinite()) { - doForce(vec); + // Apply the total force acting on this avatar + d.BodyAddForce(Body, vec.X, vec.Y, vec.Z); if (!_zeroFlag) AlignAvatarTiltWithCurrentDirectionOfMovement(vec); @@ -1258,7 +1246,7 @@ namespace OpenSim.Region.Physics.OdePlugin // FIXME: This is not a good solution since it's subject to a race condition if a force is another // thread sets a new force while we're in this loop (since it could be obliterated by // m_taintForce = Vector3.Zero. Need to lock ProcessTaints() when we set a new tainted force. - doForce(m_taintForce); + d.BodyAddForce(Body, m_taintForce.X, m_taintForce.Y, m_taintForce.Z); } m_taintForce = Vector3.Zero; -- cgit v1.1 From e67ba0ad06a0ff54834892257d8e7bc39b4fc892 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 20:01:34 +0000 Subject: rename ODECharacter.AvatarGeomAndBodyCreation() -> CreateOdeStructures() to match existing DestroyOdeStructures() --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index afa8de5..5a7626e 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -542,16 +542,18 @@ namespace OpenSim.Region.Physics.OdePlugin } /// - /// This creates the Avatar's physical Surrogate at the position supplied + /// This creates the Avatar's physical Surrogate in ODE at the position supplied /// + /// + /// WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access + /// to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only + /// place that is safe to call this routine AvatarGeomAndBodyCreation. + /// /// /// /// - - // WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access - // to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only - // place that is safe to call this routine AvatarGeomAndBodyCreation. - private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ, float tensor) + /// + private void CreateOdeStructures(float npositionX, float npositionY, float npositionZ, float tensor) { int dAMotorEuler = 1; // _parent_scene.waitForSpaceUnlock(_parent_scene.space); @@ -1268,7 +1270,7 @@ namespace OpenSim.Region.Physics.OdePlugin + (Amotor!=IntPtr.Zero ? "Amotor ":"")); } - AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z, m_tensor); + CreateOdeStructures(_position.X, _position.Y, _position.Z, m_tensor); _parent_scene.AddCharacter(this); } else @@ -1296,7 +1298,7 @@ namespace OpenSim.Region.Physics.OdePlugin float prevCapsule = CAPSULE_LENGTH; CAPSULE_LENGTH = m_tainted_CAPSULE_LENGTH; - AvatarGeomAndBodyCreation( + CreateOdeStructures( _position.X, _position.Y, _position.Z + (Math.Abs(CAPSULE_LENGTH - prevCapsule) * 2), m_tensor); -- cgit v1.1 From e33b0fa35bf6bef47849c82b1ef1f5f81420217e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 20:12:04 +0000 Subject: don't lock OdeScene.contacts since only ever accessed by a single thread --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 34 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index b952b30..92dd2dd 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -251,10 +251,27 @@ namespace OpenSim.Region.Physics.OdePlugin //private Dictionary jointpart_name_map = new Dictionary(); private readonly Dictionary> joints_connecting_actor = new Dictionary>(); private d.ContactGeom[] contacts; - private readonly List requestedJointsToBeCreated = new List(); // lock only briefly. accessed by external code (to request new joints) and by OdeScene.Simulate() to move those joints into pending/active - private readonly List pendingJoints = new List(); // can lock for longer. accessed only by OdeScene. - private readonly List activeJoints = new List(); // can lock for longer. accessed only by OdeScene. - private readonly List requestedJointsToBeDeleted = new List(); // lock only briefly. accessed by external code (to request deletion of joints) and by OdeScene.Simulate() to move those joints out of pending/active + + /// + /// Lock only briefly. accessed by external code (to request new joints) and by OdeScene.Simulate() to move those joints into pending/active + /// + private readonly List requestedJointsToBeCreated = new List(); + + /// + /// can lock for longer. accessed only by OdeScene. + /// + private readonly List pendingJoints = new List(); + + /// + /// can lock for longer. accessed only by OdeScene. + /// + private readonly List activeJoints = new List(); + + /// + /// lock only briefly. accessed by external code (to request deletion of joints) and by OdeScene.Simulate() to move those joints out of pending/active + /// + private readonly List requestedJointsToBeDeleted = new List(); + private Object externalJointRequestsLock = new Object(); private readonly Dictionary SOPName_to_activeJoint = new Dictionary(); private readonly Dictionary SOPName_to_pendingJoint = new Dictionary(); @@ -776,12 +793,9 @@ namespace OpenSim.Region.Physics.OdePlugin if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) return; - lock (contacts) - { - count = d.Collide(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf); - if (count > contacts.Length) - m_log.Error("[PHYSICS]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length); - } + count = d.Collide(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf); + if (count > contacts.Length) + m_log.Error("[PHYSICS]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length); } catch (SEHException) { -- cgit v1.1 From 25d9001de1225a7d1c938f440b43c37bcca0e69e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 20:17:36 +0000 Subject: don't bother locking OdeScene._perloopContact in single threaded code --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 89 +++++++++++++--------------- 1 file changed, 42 insertions(+), 47 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 92dd2dd..897ab82 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -1247,69 +1247,64 @@ namespace OpenSim.Region.Physics.OdePlugin private bool checkDupe(d.ContactGeom contactGeom, int atype) { - bool result = false; - //return result; if (!m_filterCollisions) return false; + + bool result = false; ActorTypes at = (ActorTypes)atype; - lock (_perloopContact) + + foreach (d.ContactGeom contact in _perloopContact) { - foreach (d.ContactGeom contact in _perloopContact) + //if ((contact.g1 == contactGeom.g1 && contact.g2 == contactGeom.g2)) + //{ + // || (contact.g2 == contactGeom.g1 && contact.g1 == contactGeom.g2) + if (at == ActorTypes.Agent) { - //if ((contact.g1 == contactGeom.g1 && contact.g2 == contactGeom.g2)) - //{ - // || (contact.g2 == contactGeom.g1 && contact.g1 == contactGeom.g2) - if (at == ActorTypes.Agent) - { - if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom) + if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom) + { + + if (Math.Abs(contact.depth - contactGeom.depth) < 0.052f) { - - if (Math.Abs(contact.depth - contactGeom.depth) < 0.052f) - { - //contactGeom.depth *= .00005f; - //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); - // m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); - result = true; - break; - } - else - { - //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); - } + //contactGeom.depth *= .00005f; + //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); + // m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); + result = true; + break; } else { - //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); - //int i = 0; + //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); } - } - else if (at == ActorTypes.Prim) - { - //d.AABB aabb1 = new d.AABB(); - //d.AABB aabb2 = new d.AABB(); + } + else + { + //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); + //int i = 0; + } + } + else if (at == ActorTypes.Prim) + { + //d.AABB aabb1 = new d.AABB(); + //d.AABB aabb2 = new d.AABB(); - //d.GeomGetAABB(contactGeom.g2, out aabb2); - //d.GeomGetAABB(contactGeom.g1, out aabb1); - //aabb1. - if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom) + //d.GeomGetAABB(contactGeom.g2, out aabb2); + //d.GeomGetAABB(contactGeom.g1, out aabb1); + //aabb1. + if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom) + { + if (contactGeom.normal.X == contact.normal.X && contactGeom.normal.Y == contact.normal.Y && contactGeom.normal.Z == contact.normal.Z) { - if (contactGeom.normal.X == contact.normal.X && contactGeom.normal.Y == contact.normal.Y && contactGeom.normal.Z == contact.normal.Z) + if (Math.Abs(contact.depth - contactGeom.depth) < 0.272f) { - if (Math.Abs(contact.depth - contactGeom.depth) < 0.272f) - { - result = true; - break; - } + result = true; + break; } - //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); - //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); } - - } - - //} - + //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); + //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); + } + } } -- cgit v1.1 From 546259b2ffdb7dfdc450dd5386ec6794bb06223d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 20:30:37 +0000 Subject: simplify operation of OdeScene._perloopContact --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 96 +++++++++++++++------------- 1 file changed, 51 insertions(+), 45 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 897ab82..7db188f 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -216,7 +216,14 @@ namespace OpenSim.Region.Physics.OdePlugin /// private readonly HashSet _taintedPrimH = new HashSet(); + /// + /// Record a character that has taints to be processed. + /// private readonly HashSet _taintedActors = new HashSet(); + + /// + /// Keep record of contacts in the physics loop so that we can remove duplicates. + /// private readonly List _perloopContact = new List(); /// @@ -1059,6 +1066,8 @@ namespace OpenSim.Region.Physics.OdePlugin if (!skipThisContact) { + _perloopContact.Add(curContact); + // If we're colliding against terrain if (name1 == "Terrain" || name2 == "Terrain") { @@ -1068,7 +1077,7 @@ namespace OpenSim.Region.Physics.OdePlugin { // Use the movement terrain contact AvatarMovementTerrainContact.geom = curContact; - _perloopContact.Add(curContact); + if (m_global_contactcount < maxContactsbeforedeath) { joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementTerrainContact); @@ -1081,7 +1090,7 @@ namespace OpenSim.Region.Physics.OdePlugin { // Use the non moving terrain contact TerrainContact.geom = curContact; - _perloopContact.Add(curContact); + if (m_global_contactcount < maxContactsbeforedeath) { joint = d.JointCreateContact(world, contactgroup, ref TerrainContact); @@ -1107,7 +1116,6 @@ namespace OpenSim.Region.Physics.OdePlugin //m_log.DebugFormat("Material: {0}", material); m_materialContacts[material, movintYN].geom = curContact; - _perloopContact.Add(curContact); if (m_global_contactcount < maxContactsbeforedeath) { @@ -1128,9 +1136,9 @@ namespace OpenSim.Region.Physics.OdePlugin if (p2 is OdePrim) material = ((OdePrim)p2).m_material; + //m_log.DebugFormat("Material: {0}", material); m_materialContacts[material, movintYN].geom = curContact; - _perloopContact.Add(curContact); if (m_global_contactcount < maxContactsbeforedeath) { @@ -1163,8 +1171,9 @@ namespace OpenSim.Region.Physics.OdePlugin //contact.normal = new d.Vector3(0, 0, 1); //contact.pos = new d.Vector3(0, 0, contact.pos.Z - 5f); } + WaterContact.geom = curContact; - _perloopContact.Add(curContact); + if (m_global_contactcount < maxContactsbeforedeath) { joint = d.JointCreateContact(world, contactgroup, ref WaterContact); @@ -1182,7 +1191,7 @@ namespace OpenSim.Region.Physics.OdePlugin { // Use the Movement prim contact AvatarMovementprimContact.geom = curContact; - _perloopContact.Add(curContact); + if (m_global_contactcount < maxContactsbeforedeath) { joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementprimContact); @@ -1212,13 +1221,11 @@ namespace OpenSim.Region.Physics.OdePlugin //m_log.DebugFormat("Material: {0}", material); m_materialContacts[material, 0].geom = curContact; - _perloopContact.Add(curContact); if (m_global_contactcount < maxContactsbeforedeath) { joint = d.JointCreateContact(world, contactgroup, ref m_materialContacts[material, 0]); m_global_contactcount++; - } } } @@ -1249,7 +1256,7 @@ namespace OpenSim.Region.Physics.OdePlugin { if (!m_filterCollisions) return false; - + bool result = false; ActorTypes at = (ActorTypes)atype; @@ -1261,50 +1268,51 @@ namespace OpenSim.Region.Physics.OdePlugin // || (contact.g2 == contactGeom.g1 && contact.g1 == contactGeom.g2) if (at == ActorTypes.Agent) { - if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom) - { - - if (Math.Abs(contact.depth - contactGeom.depth) < 0.052f) - { - //contactGeom.depth *= .00005f; - //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); - // m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); - result = true; - break; - } - else - { - //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); - } - } - else + if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) + && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) + && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) + && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom) + { + if (Math.Abs(contact.depth - contactGeom.depth) < 0.052f) { - //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); - //int i = 0; + //contactGeom.depth *= .00005f; + //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); + // m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); + result = true; + break; } +// else +// { +// //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); +// } + } +// else +// { +// //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); +// //int i = 0; +// } } else if (at == ActorTypes.Prim) { - //d.AABB aabb1 = new d.AABB(); - //d.AABB aabb2 = new d.AABB(); + //d.AABB aabb1 = new d.AABB(); + //d.AABB aabb2 = new d.AABB(); - //d.GeomGetAABB(contactGeom.g2, out aabb2); - //d.GeomGetAABB(contactGeom.g1, out aabb1); - //aabb1. - if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom) + //d.GeomGetAABB(contactGeom.g2, out aabb2); + //d.GeomGetAABB(contactGeom.g1, out aabb1); + //aabb1. + if (((Math.Abs(contactGeom.normal.X - contact.normal.X) < 1.026f) && (Math.Abs(contactGeom.normal.Y - contact.normal.Y) < 0.303f) && (Math.Abs(contactGeom.normal.Z - contact.normal.Z) < 0.065f)) && contactGeom.g1 != LandGeom && contactGeom.g2 != LandGeom) + { + if (contactGeom.normal.X == contact.normal.X && contactGeom.normal.Y == contact.normal.Y && contactGeom.normal.Z == contact.normal.Z) { - if (contactGeom.normal.X == contact.normal.X && contactGeom.normal.Y == contact.normal.Y && contactGeom.normal.Z == contact.normal.Z) + if (Math.Abs(contact.depth - contactGeom.depth) < 0.272f) { - if (Math.Abs(contact.depth - contactGeom.depth) < 0.272f) - { - result = true; - break; - } + result = true; + break; } - //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); - //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); } - + //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth)); + //m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z)); + } } } @@ -1589,8 +1597,6 @@ namespace OpenSim.Region.Physics.OdePlugin } } } - - _perloopContact.Clear(); } #endregion -- cgit v1.1 From 7480f2fd0e5482d366890b34d4aca72c887e02c3 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 21:04:24 +0000 Subject: Restore defects list. In hindsight, the reason for this is becuase we can't remove the character whilst iterating over the list. This commit also removes locking on OdeScene._characters since code is single threaded --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 27 ++-- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 177 +++++++++++++---------- 2 files changed, 112 insertions(+), 92 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 5a7626e..cfe64f2 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -862,11 +862,10 @@ namespace OpenSim.Region.Physics.OdePlugin /// Called from Simulate /// This is the avatar's movement control + PID Controller /// - /// - /// This routine will remove the character from the physics scene if it detects something wrong (non-finite + /// The character will be added to this list if there is something wrong (non-finite /// position or velocity). - /// - internal void Move() + /// + internal void Move(List defects) { // no lock; for now it's only called from within Simulate() @@ -891,8 +890,7 @@ namespace OpenSim.Region.Physics.OdePlugin "[ODE CHARACTER]: Avatar position of {0} for {1} is non-finite! Removing from physics scene.", localPos, Name); - _parent_scene.RemoveCharacter(this); - DestroyOdeStructures(); + defects.Add(this); return; } @@ -1031,15 +1029,19 @@ namespace OpenSim.Region.Physics.OdePlugin "[ODE CHARACTER]: Got a NaN force vector {0} in Move() for {1}. Removing character from physics scene.", vec, Name); - _parent_scene.RemoveCharacter(this); - DestroyOdeStructures(); + defects.Add(this); + + return; } } /// /// Updates the reported position and velocity. This essentially sends the data up to ScenePresence. /// - internal void UpdatePositionAndVelocity() + /// The character will be added to this list if there is something wrong (non-finite + /// position or velocity). + /// + internal void UpdatePositionAndVelocity(List defects) { // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! d.Vector3 newPos; @@ -1050,11 +1052,12 @@ namespace OpenSim.Region.Physics.OdePlugin catch (NullReferenceException) { bad = true; - _parent_scene.RemoveCharacter(this); - DestroyOdeStructures(); + defects.Add(this); newPos = new d.Vector3(_position.X, _position.Y, _position.Z); base.RaiseOutOfBounds(_position); // Tells ScenePresence that there's a problem! m_log.WarnFormat("[ODE CHARACTER]: Avatar Null reference for Avatar {0}, physical actor {1}", Name, m_uuid); + + return; } // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) @@ -1134,7 +1137,7 @@ namespace OpenSim.Region.Physics.OdePlugin /// /// Used internally to destroy the ODE structures associated with this character. /// - private void DestroyOdeStructures() + internal void DestroyOdeStructures() { // destroy avatar capsule and related ODE data if (Amotor != IntPtr.Zero) diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 7db188f..89568b6 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -189,7 +189,11 @@ namespace OpenSim.Region.Physics.OdePlugin public d.TriCallback triCallback; public d.TriArrayCallback triArrayCallback; + /// + /// Avatars in the physics scene. + /// private readonly HashSet _characters = new HashSet(); + private readonly HashSet _prims = new HashSet(); private readonly HashSet _activeprims = new HashSet(); @@ -254,6 +258,14 @@ namespace OpenSim.Region.Physics.OdePlugin /// public Dictionary actor_name_map = new Dictionary(); + /// + /// Defects list to remove characters that no longer have finite positions due to some other bug. + /// + /// + /// Used repeatedly in Simulate() but initialized once here. + /// + private readonly List defects = new List(); + private bool m_NINJA_physics_joints_enabled = false; //private Dictionary jointpart_name_map = new Dictionary(); private readonly Dictionary> joints_connecting_actor = new Dictionary>(); @@ -1515,45 +1527,42 @@ namespace OpenSim.Region.Physics.OdePlugin { _perloopContact.Clear(); - lock (_characters) + foreach (OdeCharacter chr in _characters) { - foreach (OdeCharacter chr in _characters) + // Reset the collision values to false + // since we don't know if we're colliding yet + + // For some reason this can happen. Don't ask... + // + if (chr == null) + continue; + + if (chr.Shell == IntPtr.Zero || chr.Body == IntPtr.Zero) + continue; + + chr.IsColliding = false; + chr.CollidingGround = false; + chr.CollidingObj = false; + + // test the avatar's geometry for collision with the space + // This will return near and the space that they are the closest to + // And we'll run this again against the avatar and the space segment + // This will return with a bunch of possible objects in the space segment + // and we'll run it again on all of them. + try { - // Reset the collision values to false - // since we don't know if we're colliding yet - - // For some reason this can happen. Don't ask... - // - if (chr == null) - continue; - - if (chr.Shell == IntPtr.Zero || chr.Body == IntPtr.Zero) - continue; - - chr.IsColliding = false; - chr.CollidingGround = false; - chr.CollidingObj = false; - - // test the avatar's geometry for collision with the space - // This will return near and the space that they are the closest to - // And we'll run this again against the avatar and the space segment - // This will return with a bunch of possible objects in the space segment - // and we'll run it again on all of them. - try - { - d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); - } - catch (AccessViolationException) - { - m_log.Warn("[PHYSICS]: Unable to space collide"); - } - //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y); - //if (chr.Position.Z + (chr.Velocity.Z * timeStep) < terrainheight + 10) - //{ - //chr.Position.Z = terrainheight + 10.0f; - //forcedZ = true; - //} + d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); + } + catch (AccessViolationException) + { + m_log.Warn("[PHYSICS]: Unable to space collide"); } + //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y); + //if (chr.Position.Z + (chr.Velocity.Z * timeStep) < terrainheight + 10) + //{ + //chr.Position.Z = terrainheight + 10.0f; + //forcedZ = true; + //} } lock (_activeprims) @@ -1716,28 +1725,22 @@ namespace OpenSim.Region.Physics.OdePlugin internal void AddCharacter(OdeCharacter chr) { - lock (_characters) + if (!_characters.Contains(chr)) { - if (!_characters.Contains(chr)) - { - _characters.Add(chr); + _characters.Add(chr); - if (chr.bad) - m_log.ErrorFormat("[PHYSICS] Added BAD actor {0} to characters list", chr.m_uuid); - } + if (chr.bad) + m_log.ErrorFormat("[PHYSICS] Added BAD actor {0} to characters list", chr.m_uuid); } } internal void RemoveCharacter(OdeCharacter chr) { - lock (_characters) + if (_characters.Contains(chr)) { - if (_characters.Contains(chr)) - { - _characters.Remove(chr); - geom_name_map.Remove(chr.Shell); - actor_name_map.Remove(chr.Shell); - } + _characters.Remove(chr); + geom_name_map.Remove(chr.Shell); + actor_name_map.Remove(chr.Shell); } } @@ -2797,13 +2800,21 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } // Move characters - lock (_characters) + foreach (OdeCharacter actor in _characters) { - foreach (OdeCharacter actor in _characters) + if (actor != null) + actor.Move(defects); + } + + if (defects.Count != 0) + { + foreach (OdeCharacter actor in defects) { - if (actor != null) - actor.Move(); + RemoveCharacter(actor); + actor.DestroyOdeStructures(); } + + defects.Clear(); } // Move other active objects @@ -2860,18 +2871,26 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); timeLeft -= ODE_STEPSIZE; } - lock (_characters) + foreach (OdeCharacter actor in _characters) { - foreach (OdeCharacter actor in _characters) + if (actor != null) { - if (actor != null) - { - if (actor.bad) - m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); + if (actor.bad) + m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); - actor.UpdatePositionAndVelocity(); - } + actor.UpdatePositionAndVelocity(defects); + } + } + + if (defects.Count != 0) + { + foreach (OdeCharacter actor in defects) + { + RemoveCharacter(actor); + actor.DestroyOdeStructures(); } + + defects.Clear(); } lock (_activeprims) @@ -3899,30 +3918,28 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } } ds.SetColor(1.0f, 0.0f, 0.0f); - lock (_characters) + + foreach (OdeCharacter chr in _characters) { - foreach (OdeCharacter chr in _characters) + if (chr.Shell != IntPtr.Zero) { - if (chr.Shell != IntPtr.Zero) - { - IntPtr body = d.GeomGetBody(chr.Shell); + IntPtr body = d.GeomGetBody(chr.Shell); - d.Vector3 pos; - d.GeomCopyPosition(chr.Shell, out pos); - //d.BodyCopyPosition(body, out pos); + d.Vector3 pos; + d.GeomCopyPosition(chr.Shell, out pos); + //d.BodyCopyPosition(body, out pos); - d.Matrix3 R; - d.GeomCopyRotation(chr.Shell, out R); - //d.BodyCopyRotation(body, out R); + d.Matrix3 R; + d.GeomCopyRotation(chr.Shell, out R); + //d.BodyCopyRotation(body, out R); - ds.DrawCapsule(ref pos, ref R, chr.Size.Z, 0.35f); - d.Vector3 sides = new d.Vector3(); - sides.X = 0.5f; - sides.Y = 0.5f; - sides.Z = 0.5f; + ds.DrawCapsule(ref pos, ref R, chr.Size.Z, 0.35f); + d.Vector3 sides = new d.Vector3(); + sides.X = 0.5f; + sides.Y = 0.5f; + sides.Z = 0.5f; - ds.DrawBox(ref pos, ref R, ref sides); - } + ds.DrawBox(ref pos, ref R, ref sides); } } } -- cgit v1.1 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/Physics/OdePlugin') 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 From 4ddff7eb0ffbb1cc43eac2543296e241574e31be Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 21:29:56 +0000 Subject: Get rid of OdeCharacter != null checks since OdeScene._characters can never contain a null character. Ignoring the ancient code glyphs not to do this.... --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index d1c1c25..e6cf915 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -1538,12 +1538,6 @@ namespace OpenSim.Region.Physics.OdePlugin { // Reset the collision values to false // since we don't know if we're colliding yet - - // For some reason this can happen. Don't ask... - // - if (chr == null) - continue; - if (chr.Shell == IntPtr.Zero || chr.Body == IntPtr.Zero) continue; @@ -2056,7 +2050,6 @@ namespace OpenSim.Region.Physics.OdePlugin //m_log.Debug("RemoveAllJointsConnectedToActor: start"); if (actor.SOPName != null && joints_connecting_actor.ContainsKey(actor.SOPName) && joints_connecting_actor[actor.SOPName] != null) { - List jointsToRemove = new List(); //TODO: merge these 2 loops (originally it was needed to avoid altering a list being iterated over, but it is no longer needed due to the joint request queue mechanism) foreach (PhysicsJoint j in joints_connecting_actor[actor.SOPName]) @@ -2801,10 +2794,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); // Move characters foreach (OdeCharacter actor in _characters) - { - if (actor != null) - actor.Move(defects); - } + actor.Move(defects); if (defects.Count != 0) { @@ -2870,13 +2860,10 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); foreach (OdeCharacter actor in _characters) { - if (actor != null) - { - if (actor.bad) - m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); + if (actor.bad) + m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); - actor.UpdatePositionAndVelocity(defects); - } + actor.UpdatePositionAndVelocity(defects); } if (defects.Count != 0) -- cgit v1.1 From c4e4a29478c635bb5759fa5b815d86e39cb3a794 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 21 Nov 2011 21:31:26 +0000 Subject: Slightly improve "Unable to space collide" logging message, though I don't think I've ever seen this. --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index e6cf915..e219535 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -1556,8 +1556,9 @@ namespace OpenSim.Region.Physics.OdePlugin } catch (AccessViolationException) { - m_log.Warn("[PHYSICS]: Unable to space collide"); + m_log.WarnFormat("[PHYSICS]: Unable to space collide {0}", Name); } + //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y); //if (chr.Position.Z + (chr.Velocity.Z * timeStep) < terrainheight + 10) //{ -- cgit v1.1 From daf99f8c0ac874971c829b18a2372be1c4ee9541 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 22 Nov 2011 21:51:00 +0000 Subject: slightly simplify OdeScene.Simulate() by removing bool processtaints, since we can inspect count of taint lists instead. also groups OdeCharacter.CreateOdeStructures() and DestroyOdeStructures() together --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 234 +++++++++++------------ OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 1 - OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 34 ++-- 3 files changed, 128 insertions(+), 141 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index cfe64f2..489a23a 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -542,123 +542,6 @@ namespace OpenSim.Region.Physics.OdePlugin } /// - /// This creates the Avatar's physical Surrogate in ODE at the position supplied - /// - /// - /// WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access - /// to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only - /// place that is safe to call this routine AvatarGeomAndBodyCreation. - /// - /// - /// - /// - /// - private void CreateOdeStructures(float npositionX, float npositionY, float npositionZ, float tensor) - { - int dAMotorEuler = 1; -// _parent_scene.waitForSpaceUnlock(_parent_scene.space); - if (CAPSULE_LENGTH <= 0) - { - m_log.Warn("[ODE CHARACTER]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); - CAPSULE_LENGTH = 0.01f; - } - - if (CAPSULE_RADIUS <= 0) - { - m_log.Warn("[ODE CHARACTER]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); - CAPSULE_RADIUS = 0.01f; - } - - Shell = d.CreateCapsule(_parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH); - - d.GeomSetCategoryBits(Shell, (int)m_collisionCategories); - d.GeomSetCollideBits(Shell, (int)m_collisionFlags); - - d.MassSetCapsuleTotal(out ShellMass, m_mass, 2, CAPSULE_RADIUS, CAPSULE_LENGTH); - Body = d.BodyCreate(_parent_scene.world); - d.BodySetPosition(Body, npositionX, npositionY, npositionZ); - - _position.X = npositionX; - _position.Y = npositionY; - _position.Z = npositionZ; - - m_taintPosition = _position; - - d.BodySetMass(Body, ref ShellMass); - d.Matrix3 m_caprot; - // 90 Stand up on the cap of the capped cyllinder - if (_parent_scene.IsAvCapsuleTilted) - { - d.RFromAxisAndAngle(out m_caprot, 1, 0, 1, (float)(Math.PI / 2)); - } - else - { - d.RFromAxisAndAngle(out m_caprot, 0, 0, 1, (float)(Math.PI / 2)); - } - - d.GeomSetRotation(Shell, ref m_caprot); - d.BodySetRotation(Body, ref m_caprot); - - d.GeomSetBody(Shell, Body); - - // The purpose of the AMotor here is to keep the avatar's physical - // surrogate from rotating while moving - Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero); - d.JointAttach(Amotor, Body, IntPtr.Zero); - d.JointSetAMotorMode(Amotor, dAMotorEuler); - d.JointSetAMotorNumAxes(Amotor, 3); - d.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0); - d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0); - d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1); - d.JointSetAMotorAngle(Amotor, 0, 0); - d.JointSetAMotorAngle(Amotor, 1, 0); - d.JointSetAMotorAngle(Amotor, 2, 0); - - // These lowstops and high stops are effectively (no wiggle room) - if (_parent_scene.IsAvCapsuleTilted) - { - d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -0.000000000001f); - d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0.000000000001f); - d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -0.000000000001f); - d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.000000000001f); - d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0.000000000001f); - d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.000000000001f); - } - else - { - #region Documentation of capsule motor LowStop and HighStop parameters - // Intentionally introduce some tilt into the capsule by setting - // the motor stops to small epsilon values. This small tilt prevents - // the capsule from falling into the terrain; a straight-up capsule - // (with -0..0 motor stops) falls into the terrain for reasons yet - // to be comprehended in their entirety. - #endregion - AlignAvatarTiltWithCurrentDirectionOfMovement(Vector3.Zero); - d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f); - d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f); - d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f); - d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.08f); // must be same as lowstop, else a different, spurious tilt is introduced - d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop - d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.08f); // same as lowstop - } - - // Fudge factor is 1f by default, we're setting it to 0. We don't want it to Fudge or the - // capped cyllinder will fall over - d.JointSetAMotorParam(Amotor, (int)dParam.FudgeFactor, 0f); - d.JointSetAMotorParam(Amotor, (int)dParam.FMax, tensor); - - //d.Matrix3 bodyrotation = d.BodyGetRotation(Body); - //d.QfromR( - //d.Matrix3 checkrotation = new d.Matrix3(0.7071068,0.5, -0.7071068, - // - //m_log.Info("[PHYSICSAV]: Rotation: " + bodyrotation.M00 + " : " + bodyrotation.M01 + " : " + bodyrotation.M02 + " : " + bodyrotation.M10 + " : " + bodyrotation.M11 + " : " + bodyrotation.M12 + " : " + bodyrotation.M20 + " : " + bodyrotation.M21 + " : " + bodyrotation.M22); - //standupStraight(); - - _parent_scene.geom_name_map[Shell] = Name; - _parent_scene.actor_name_map[Shell] = this; - } - - /// /// Uses the capped cyllinder volume formula to calculate the avatar's mass. /// This may be used in calculations in the scene/scenepresence /// @@ -1126,6 +1009,123 @@ namespace OpenSim.Region.Physics.OdePlugin } /// + /// This creates the Avatar's physical Surrogate in ODE at the position supplied + /// + /// + /// WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access + /// to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only + /// place that is safe to call this routine AvatarGeomAndBodyCreation. + /// + /// + /// + /// + /// + private void CreateOdeStructures(float npositionX, float npositionY, float npositionZ, float tensor) + { + int dAMotorEuler = 1; +// _parent_scene.waitForSpaceUnlock(_parent_scene.space); + if (CAPSULE_LENGTH <= 0) + { + m_log.Warn("[ODE CHARACTER]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); + CAPSULE_LENGTH = 0.01f; + } + + if (CAPSULE_RADIUS <= 0) + { + m_log.Warn("[ODE CHARACTER]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); + CAPSULE_RADIUS = 0.01f; + } + + Shell = d.CreateCapsule(_parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH); + + d.GeomSetCategoryBits(Shell, (int)m_collisionCategories); + d.GeomSetCollideBits(Shell, (int)m_collisionFlags); + + d.MassSetCapsuleTotal(out ShellMass, m_mass, 2, CAPSULE_RADIUS, CAPSULE_LENGTH); + Body = d.BodyCreate(_parent_scene.world); + d.BodySetPosition(Body, npositionX, npositionY, npositionZ); + + _position.X = npositionX; + _position.Y = npositionY; + _position.Z = npositionZ; + + m_taintPosition = _position; + + d.BodySetMass(Body, ref ShellMass); + d.Matrix3 m_caprot; + // 90 Stand up on the cap of the capped cyllinder + if (_parent_scene.IsAvCapsuleTilted) + { + d.RFromAxisAndAngle(out m_caprot, 1, 0, 1, (float)(Math.PI / 2)); + } + else + { + d.RFromAxisAndAngle(out m_caprot, 0, 0, 1, (float)(Math.PI / 2)); + } + + d.GeomSetRotation(Shell, ref m_caprot); + d.BodySetRotation(Body, ref m_caprot); + + d.GeomSetBody(Shell, Body); + + // The purpose of the AMotor here is to keep the avatar's physical + // surrogate from rotating while moving + Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero); + d.JointAttach(Amotor, Body, IntPtr.Zero); + d.JointSetAMotorMode(Amotor, dAMotorEuler); + d.JointSetAMotorNumAxes(Amotor, 3); + d.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0); + d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0); + d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1); + d.JointSetAMotorAngle(Amotor, 0, 0); + d.JointSetAMotorAngle(Amotor, 1, 0); + d.JointSetAMotorAngle(Amotor, 2, 0); + + // These lowstops and high stops are effectively (no wiggle room) + if (_parent_scene.IsAvCapsuleTilted) + { + d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -0.000000000001f); + d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0.000000000001f); + d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -0.000000000001f); + d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.000000000001f); + d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0.000000000001f); + d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.000000000001f); + } + else + { + #region Documentation of capsule motor LowStop and HighStop parameters + // Intentionally introduce some tilt into the capsule by setting + // the motor stops to small epsilon values. This small tilt prevents + // the capsule from falling into the terrain; a straight-up capsule + // (with -0..0 motor stops) falls into the terrain for reasons yet + // to be comprehended in their entirety. + #endregion + AlignAvatarTiltWithCurrentDirectionOfMovement(Vector3.Zero); + d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f); + d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f); + d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f); + d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.08f); // must be same as lowstop, else a different, spurious tilt is introduced + d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop + d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.08f); // same as lowstop + } + + // Fudge factor is 1f by default, we're setting it to 0. We don't want it to Fudge or the + // capped cyllinder will fall over + d.JointSetAMotorParam(Amotor, (int)dParam.FudgeFactor, 0f); + d.JointSetAMotorParam(Amotor, (int)dParam.FMax, tensor); + + //d.Matrix3 bodyrotation = d.BodyGetRotation(Body); + //d.QfromR( + //d.Matrix3 checkrotation = new d.Matrix3(0.7071068,0.5, -0.7071068, + // + //m_log.Info("[PHYSICSAV]: Rotation: " + bodyrotation.M00 + " : " + bodyrotation.M01 + " : " + bodyrotation.M02 + " : " + bodyrotation.M10 + " : " + bodyrotation.M11 + " : " + bodyrotation.M12 + " : " + bodyrotation.M20 + " : " + bodyrotation.M21 + " : " + bodyrotation.M22); + //standupStraight(); + + _parent_scene.geom_name_map[Shell] = Name; + _parent_scene.actor_name_map[Shell] = this; + } + + /// /// Cleanup the things we use in the scene. /// internal void Destroy() diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index fec4693..94e6185 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -272,7 +272,6 @@ namespace OpenSim.Region.Physics.OdePlugin m_taintadd = true; _parent_scene.AddPhysicsActorTaint(this); - // don't do .add() here; old geoms get recycled with the same hash } public override int PhysicsActorType diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index e219535..72e9ca0 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -2160,7 +2160,6 @@ namespace OpenSim.Region.Physics.OdePlugin p.setPrimForRemoval(); AddPhysicsActorTaint(prim); - //RemovePrimThreadLocked(p); } } } @@ -2607,15 +2606,17 @@ namespace OpenSim.Region.Physics.OdePlugin /// /// Called after our prim properties are set Scale, position etc. + /// + /// /// We use this event queue like method to keep changes to the physical scene occuring in the threadlocked mutex /// This assures us that we have no race conditions - /// - /// - public override void AddPhysicsActorTaint(PhysicsActor prim) + /// + /// + public override void AddPhysicsActorTaint(PhysicsActor actor) { - if (prim is OdePrim) + if (actor is OdePrim) { - OdePrim taintedprim = ((OdePrim) prim); + OdePrim taintedprim = ((OdePrim)actor); lock (_taintedPrimLock) { if (!(_taintedPrimH.Contains(taintedprim))) @@ -2627,11 +2628,10 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); _taintedPrimL.Add(taintedprim); // List for ordered readout } } - return; } - else if (prim is OdeCharacter) + else if (actor is OdeCharacter) { - OdeCharacter taintedchar = ((OdeCharacter)prim); + OdeCharacter taintedchar = ((OdeCharacter)actor); lock (_taintedActors) { if (!(_taintedActors.Contains(taintedchar))) @@ -2734,29 +2734,18 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); { try { - // Insert, remove Characters - bool processedtaints = false; - lock (_taintedActors) { if (_taintedActors.Count > 0) { foreach (OdeCharacter character in _taintedActors) - { character.ProcessTaints(); - processedtaints = true; - //character.m_collisionscore = 0; - } - - if (processedtaints) + if (_taintedActors.Count > 0) _taintedActors.Clear(); } } - // Modify other objects in the scene. - processedtaints = false; - lock (_taintedPrimLock) { foreach (OdePrim prim in _taintedPrimL) @@ -2772,7 +2761,6 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); prim.ProcessTaints(); } - processedtaints = true; prim.m_collisionscore = 0; // This loop can block up the Heartbeat for a very long time on large regions. @@ -2785,7 +2773,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); if (SupportsNINJAJoints) SimulatePendingNINJAJoints(); - if (processedtaints) + if (_taintedPrimL.Count > 0) { //Console.WriteLine("Simulate calls Clear of _taintedPrim list"); _taintedPrimH.Clear(); -- cgit v1.1 From af90b527314d6cf441dcd593886739ac77b68558 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 22 Nov 2011 22:28:46 +0000 Subject: Comment out uncalled OdeScene.UnCombine() --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 116 +++++++++++++-------------- 1 file changed, 58 insertions(+), 58 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 72e9ca0..b5436bd 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -3583,64 +3583,64 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); return true; } - public override void UnCombine(PhysicsScene pScene) - { - IntPtr localGround = IntPtr.Zero; -// float[] localHeightfield; - bool proceed = false; - List geomDestroyList = new List(); - - lock (OdeLock) - { - if (RegionTerrain.TryGetValue(Vector3.Zero, out localGround)) - { - foreach (IntPtr geom in TerrainHeightFieldHeights.Keys) - { - if (geom == localGround) - { -// localHeightfield = TerrainHeightFieldHeights[geom]; - proceed = true; - } - else - { - geomDestroyList.Add(geom); - } - } - - if (proceed) - { - m_worldOffset = Vector3.Zero; - WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); - m_parentScene = null; - - foreach (IntPtr g in geomDestroyList) - { - // removingHeightField needs to be done or the garbage collector will - // collect the terrain data before we tell ODE to destroy it causing - // memory corruption - if (TerrainHeightFieldHeights.ContainsKey(g)) - { -// float[] removingHeightField = TerrainHeightFieldHeights[g]; - TerrainHeightFieldHeights.Remove(g); - - if (RegionTerrain.ContainsKey(g)) - { - RegionTerrain.Remove(g); - } - - d.GeomDestroy(g); - //removingHeightField = new float[0]; - } - } - - } - else - { - m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data."); - } - } - } - } +// public override void UnCombine(PhysicsScene pScene) +// { +// IntPtr localGround = IntPtr.Zero; +//// float[] localHeightfield; +// bool proceed = false; +// List geomDestroyList = new List(); +// +// lock (OdeLock) +// { +// if (RegionTerrain.TryGetValue(Vector3.Zero, out localGround)) +// { +// foreach (IntPtr geom in TerrainHeightFieldHeights.Keys) +// { +// if (geom == localGround) +// { +//// localHeightfield = TerrainHeightFieldHeights[geom]; +// proceed = true; +// } +// else +// { +// geomDestroyList.Add(geom); +// } +// } +// +// if (proceed) +// { +// m_worldOffset = Vector3.Zero; +// WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); +// m_parentScene = null; +// +// foreach (IntPtr g in geomDestroyList) +// { +// // removingHeightField needs to be done or the garbage collector will +// // collect the terrain data before we tell ODE to destroy it causing +// // memory corruption +// if (TerrainHeightFieldHeights.ContainsKey(g)) +// { +//// float[] removingHeightField = TerrainHeightFieldHeights[g]; +// TerrainHeightFieldHeights.Remove(g); +// +// if (RegionTerrain.ContainsKey(g)) +// { +// RegionTerrain.Remove(g); +// } +// +// d.GeomDestroy(g); +// //removingHeightField = new float[0]; +// } +// } +// +// } +// else +// { +// m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data."); +// } +// } +// } +// } public override void SetWaterLevel(float baseheight) { -- cgit v1.1 From ace4324e753435e317ec388b5b25a8e3ffd84db4 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 22 Nov 2011 22:37:06 +0000 Subject: Stop removing actor from the hash maps in OdeScene.RemoveCharacter() since this is now being down in OdeCharacter.DestroyOdeStructures() --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index b5436bd..7b04bcf 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -1735,12 +1735,7 @@ namespace OpenSim.Region.Physics.OdePlugin internal void RemoveCharacter(OdeCharacter chr) { - if (_characters.Contains(chr)) - { - _characters.Remove(chr); - geom_name_map.Remove(chr.Shell); - actor_name_map.Remove(chr.Shell); - } + _characters.Remove(chr); } private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation, -- cgit v1.1 From b56410285b1af7c5fc2b4a84d8c9c734d2238ff0 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 22 Nov 2011 22:46:25 +0000 Subject: Log error if we attempt to add/remove an OdeCharacter from the _characters list inappropriately --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 56 ++++++++++++++++------------ 1 file changed, 33 insertions(+), 23 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 7b04bcf..0456f56 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -377,8 +377,7 @@ namespace OpenSim.Region.Physics.OdePlugin /// Name of the scene. Useful in debug messages. public OdeScene(string name) { - m_log - = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "." + name); + m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.ToString() + "." + name); Name = name; @@ -769,7 +768,7 @@ namespace OpenSim.Region.Physics.OdePlugin } catch (AccessViolationException) { - m_log.Warn("[PHYSICS]: Unable to collide test a space"); + m_log.Warn("[ODE SCENE]: Unable to collide test a space"); return; } //Colliding a space or a geom with a space or a geom. so drill down @@ -821,17 +820,17 @@ namespace OpenSim.Region.Physics.OdePlugin count = d.Collide(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf); if (count > contacts.Length) - m_log.Error("[PHYSICS]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length); + m_log.Error("[ODE SCENE]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length); } catch (SEHException) { m_log.Error( - "[PHYSICS]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim."); + "[ODE SCENE]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim."); base.TriggerPhysicsBasedRestart(); } catch (Exception e) { - m_log.WarnFormat("[PHYSICS]: Unable to collide test an object: {0}", e.Message); + m_log.WarnFormat("[ODE SCENE]: Unable to collide test an object: {0}", e.Message); return; } @@ -1556,7 +1555,7 @@ namespace OpenSim.Region.Physics.OdePlugin } catch (AccessViolationException) { - m_log.WarnFormat("[PHYSICS]: Unable to space collide {0}", Name); + m_log.WarnFormat("[ODE SCENE]: Unable to space collide {0}", Name); } //float terrainheight = GetTerrainHeightAtXY(chr.Position.X, chr.Position.Y); @@ -1587,13 +1586,13 @@ namespace OpenSim.Region.Physics.OdePlugin 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!"); + m_log.Debug("[ODE SCENE]: 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"); + m_log.Warn("[ODE SCENE]: Unable to space collide"); } } } @@ -1729,13 +1728,24 @@ namespace OpenSim.Region.Physics.OdePlugin _characters.Add(chr); if (chr.bad) - m_log.ErrorFormat("[PHYSICS] Added BAD actor {0} to characters list", chr.m_uuid); + m_log.ErrorFormat("[ODE SCENE]: Added BAD actor {0} to characters list", chr.m_uuid); + } + else + { + m_log.ErrorFormat( + "[ODE SCENE]: Tried to add character {0} {1} but they are already in the set!", + chr.Name, chr.LocalID); } } internal void RemoveCharacter(OdeCharacter chr) { - _characters.Remove(chr); + if (_characters.Contains(chr)) + _characters.Remove(chr); + else + m_log.ErrorFormat( + "[ODE SCENE]: Tried to remove character {0} {1} but they are not in the list!", + chr.Name, chr.LocalID); } private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation, @@ -2222,7 +2232,7 @@ namespace OpenSim.Region.Physics.OdePlugin //m_log.Warn(prim.prim_geom); if (!prim.RemoveGeom()) - m_log.Warn("[PHYSICS]: Unable to remove prim from physics scene"); + m_log.Warn("[ODE SCENE]: Unable to remove prim from physics scene"); lock (_prims) _prims.Remove(prim); @@ -2314,7 +2324,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + currentspace + + m_log.Info("[ODE SCENE]: Invalid Scene passed to 'recalculatespace':" + currentspace + " Geom:" + geom); } } @@ -2330,7 +2340,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + + m_log.Info("[ODE SCENE]: Invalid Scene passed to 'recalculatespace':" + sGeomIsIn + " Geom:" + geom); } } @@ -2353,7 +2363,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + + m_log.Info("[ODE SCENE]: Invalid Scene passed to 'recalculatespace':" + currentspace + " Geom:" + geom); } } @@ -2373,7 +2383,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + + m_log.Info("[ODE SCENE]: Invalid Scene passed to 'recalculatespace':" + currentspace + " Geom:" + geom); } } @@ -2389,7 +2399,7 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - m_log.Info("[Physics]: Invalid Scene passed to 'recalculatespace':" + + m_log.Info("[ODE SCENE]: Invalid Scene passed to 'recalculatespace':" + sGeomIsIn + " Geom:" + geom); } } @@ -2633,7 +2643,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); { _taintedActors.Add(taintedchar); if (taintedchar.bad) - m_log.DebugFormat("[PHYSICS]: Added BAD actor {0} to tainted actors", taintedchar.m_uuid); + m_log.DebugFormat("[ODE SCENE]: Added BAD actor {0} to tainted actors", taintedchar.m_uuid); } } } @@ -2836,7 +2846,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } catch (Exception e) { - m_log.ErrorFormat("[PHYSICS]: {0}, {1}, {2}", e.Message, e.TargetSite, e); + m_log.ErrorFormat("[ODE SCENE]: {0}, {1}, {2}", e.Message, e.TargetSite, e); } timeLeft -= ODE_STEPSIZE; @@ -2845,7 +2855,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); foreach (OdeCharacter actor in _characters) { if (actor.bad) - m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); + m_log.WarnFormat("[ODE SCENE]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); actor.UpdatePositionAndVelocity(defects); } @@ -3405,7 +3415,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); { if (Single.IsNaN(resultarr2[y, x]) || Single.IsInfinity(resultarr2[y, x])) { - m_log.Warn("[PHYSICS]: Non finite heightfield element detected. Setting it to 0"); + m_log.Warn("[ODE SCENE]: Non finite heightfield element detected. Setting it to 0"); resultarr2[y, x] = 0; } returnarr[i] = resultarr2[y, x]; @@ -3436,7 +3446,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); private void SetTerrain(float[] heightMap, Vector3 pOffset) { int startTime = Util.EnvironmentTickCount(); - m_log.DebugFormat("[PHYSICS]: Setting terrain for {0}", Name); + m_log.DebugFormat("[ODE SCENE]: Setting terrain for {0}", Name); // this._heightmap[i] = (double)heightMap[i]; // dbm (danx0r) -- creating a buffer zone of one extra sample all around @@ -3561,7 +3571,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } m_log.DebugFormat( - "[PHYSICS]: Setting terrain for {0} took {1}ms", Name, Util.EnvironmentTickCountSubtract(startTime)); + "[ODE SCENE]: Setting terrain for {0} took {1}ms", Name, Util.EnvironmentTickCountSubtract(startTime)); } public override void DeleteTerrain() -- cgit v1.1