From ce85675e705888f95fe00b6516da20118cbb24e0 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 11 Jul 2011 02:29:51 +0100 Subject: comment out accidential ProcessTaints physics debug line left in code --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index b63168a..0cf2f5d 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -859,7 +859,7 @@ namespace OpenSim.Region.Physics.OdePlugin public void ProcessTaints(float timestep) { -Console.WriteLine("ProcessTaints for " + Name); +//Console.WriteLine("ProcessTaints for " + Name); if (m_taintadd) { changeadd(timestep); -- cgit v1.1 From 2f3d0e209ff5c3028e3e29179b67504be9b2f887 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 11 Jul 2011 03:13:59 +0100 Subject: When a sculpt/mesh texture is received by a part on a callback request, don't do the unnecessary work of copying the base shape. Just setting the new base shape is enough to reinsert the sculpt data and set the taint. Also cleans up a few more left-in debugging messages. --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 3 ++- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 0cf2f5d..123c8ff 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -2104,6 +2104,7 @@ Console.WriteLine("changeshape not need meshing"); parent.ChildSetGeom(this); } } + resetCollisionAccounting(); m_taintshape = false; } @@ -2343,7 +2344,7 @@ Console.WriteLine("changeshape not need meshing"); { lock (_parent_scene.OdeLock) { - m_isVolumeDetect = (param!=0); + m_isVolumeDetect = (param != 0); } } diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index f5172aa..99392cc 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -26,7 +26,7 @@ */ //#define USE_DRAWSTUFF -#define SPAM +//#define SPAM using System; using System.Collections.Generic; -- cgit v1.1 From df0e5cc9fe9b0851ae5442bdeeb49ab7778d5fe1 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 12 Jul 2011 02:33:09 +0100 Subject: When a mesh object is added to a scene, delay adding the physics actor until the sculpt data has been added to the shape (possibly via an async asset service request) This prevents spurious 'no asset data' for meshes added on startup. --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 21 +++++++++--------- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 33 +++++++++++++++------------- 2 files changed, 29 insertions(+), 25 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 123c8ff..56e3b7e 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -638,7 +638,7 @@ namespace OpenSim.Region.Physics.OdePlugin float profileEnd; if (_pbs.PathCurve == (byte)Extrusion.Straight || _pbs.PathCurve == (byte)Extrusion.Flexible) - { + { taperX1 = _pbs.PathScaleX * 0.01f; if (taperX1 > 1.0f) taperX1 = 2.0f - taperX1; @@ -648,9 +648,9 @@ namespace OpenSim.Region.Physics.OdePlugin if (taperY1 > 1.0f) taperY1 = 2.0f - taperY1; taperY = 1.0f - taperY1; - } + } else - { + { taperX = _pbs.PathTaperX * 0.01f; if (taperX < 0.0f) taperX = -taperX; @@ -660,9 +660,7 @@ namespace OpenSim.Region.Physics.OdePlugin if (taperY < 0.0f) taperY = -taperY; taperY1 = 1.0f - taperY; - - } - + } volume *= (taperX1 * taperY1 + 0.5f * (taperX1 * taperY + taperX * taperY1) + 0.3333333333f * taperX * taperY); @@ -859,7 +857,9 @@ namespace OpenSim.Region.Physics.OdePlugin public void ProcessTaints(float timestep) { -//Console.WriteLine("ProcessTaints for " + Name); +#if SPAM +Console.WriteLine("ZProcessTaints for " + Name); +#endif if (m_taintadd) { changeadd(timestep); @@ -1323,7 +1323,9 @@ namespace OpenSim.Region.Physics.OdePlugin public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh) { -//Console.WriteLine("CreateGeom:"); +#if SPAM +Console.WriteLine("CreateGeom:"); +#endif if (_mesh != null) { setMesh(_parent_scene, _mesh); @@ -1944,7 +1946,6 @@ Console.WriteLine(" JointCreateFixed"); if (_parent_scene.needsMeshing(_pbs)) mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); - //IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); #if SPAM Console.WriteLine("changesize 1"); #endif @@ -2056,8 +2057,8 @@ Console.WriteLine("changesize 2"); if (IsPhysical) meshlod = _parent_scene.MeshSculptphysicalLOD; - IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); // createmesh returns null when it doesn't mesh. + IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); #if SPAM Console.WriteLine("changeshape needed meshing"); #endif diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 99392cc..7b8a80c 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -1723,20 +1723,21 @@ namespace OpenSim.Region.Physics.OdePlugin PhysicsActor result; IMesh mesh = null; - if (needsMeshing(pbs)) - { - try - { - mesh = mesher.CreateMesh(primName, pbs, size, 32f, isPhysical); - } - catch(Exception e) - { - m_log.ErrorFormat("[PHYSICS]: Exception while meshing prim {0}.", primName); - m_log.Debug(e.ToString()); - mesh = null; - return null; - } - } + // Don't create the mesh here - wait until the mesh data is loaded from the asset store. +// if (needsMeshing(pbs)) +// { +// try +// { +// mesh = mesher.CreateMesh(primName, pbs, size, 32f, isPhysical); +// } +// catch(Exception e) +// { +// m_log.ErrorFormat("[PHYSICS]: Exception while meshing prim {0}.", primName); +// m_log.Debug(e.ToString()); +// mesh = null; +// return null; +// } +// } result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical); @@ -2590,7 +2591,9 @@ namespace OpenSim.Region.Physics.OdePlugin { if (!(_taintedPrimH.Contains(taintedprim))) { -//Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.m_primName); +#if SPAM +Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); +#endif _taintedPrimH.Add(taintedprim); // HashSet for searching _taintedPrimL.Add(taintedprim); // List for ordered readout } -- cgit v1.1 From f75f906e3560b076105ab9551263617e084d6393 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 12 Jul 2011 03:13:05 +0100 Subject: minor: remove whitespace to trigger another build --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 56e3b7e..27bf942 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -844,7 +844,6 @@ namespace OpenSim.Region.Physics.OdePlugin return; } - // if (IsPhysical && Body == (IntPtr) 0) // { // Recreate the body -- cgit v1.1 From d31e0a67f7d7c2b1882a2030fe01d5d2ee32ad2a Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 12 Jul 2011 03:26:22 +0100 Subject: temporarily fix the build break with building the OdePlugin tests assembly. This needs to be fixed properly. --- OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs b/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs index a7f8baa..fbd1574 100644 --- a/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs +++ b/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs @@ -31,17 +31,18 @@ using NUnit.Framework; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Region.Physics.Manager; +using OpenSim.Region.Physics.OdePlugin; using log4net; using System.Reflection; -namespace OpenSim.Region.Physics.OdePlugin +namespace OpenSim.Region.Physics.OdePlugin.Tests { [TestFixture] public class ODETestClass { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private OdePlugin cbt; + private OpenSim.Region.Physics.OdePlugin.OdePlugin cbt; private PhysicsScene ps; private IMeshingPlugin imp; -- cgit v1.1 From 3e456163dd284fa04ab17465041a1a27f7b632b9 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 12 Jul 2011 22:13:15 +0100 Subject: Port implementation of llCastRay() from Aurora. I haven't been able to test this since the viewer won't parse the llCastRay() function. Maybe some activation cap is missing. Could wait until it is activated by default in the viewer. --- .../Physics/OdePlugin/ODERayCastRequestManager.cs | 92 ++++++++++++++++++---- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 28 +++++++ 2 files changed, 103 insertions(+), 17 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs index ba77dae..6c2bdde 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs @@ -45,11 +45,16 @@ namespace OpenSim.Region.Physics.OdePlugin public class ODERayCastRequestManager { /// - /// Pending Raycast Requests + /// Pending raycast requests /// protected List m_PendingRequests = new List(); /// + /// Pending ray requests + /// + protected List m_PendingRayRequests = new List(); + + /// /// Scene that created this object. /// private OdeScene m_scene; @@ -96,6 +101,29 @@ namespace OpenSim.Region.Physics.OdePlugin } /// + /// Queues a raycast + /// + /// Origin of Ray + /// Ray normal + /// Ray length + /// + /// Return method to send the results + public void QueueRequest(Vector3 position, Vector3 direction, float length, int count, RayCallback retMethod) + { + lock (m_PendingRequests) + { + ODERayRequest req = new ODERayRequest(); + req.callbackMethod = retMethod; + req.length = length; + req.Normal = direction; + req.Origin = position; + req.Count = count; + + m_PendingRayRequests.Add(req); + } + } + + /// /// Process all queued raycast requests /// /// Time in MS the raycasts took to process. @@ -112,15 +140,23 @@ namespace OpenSim.Region.Physics.OdePlugin if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast RayCast(reqs[i]); // if there isn't anyone to send results } - /* - foreach (ODERayCastRequest req in m_PendingRequests) + + m_PendingRequests.Clear(); + } + } + + lock (m_PendingRayRequests) + { + if (m_PendingRayRequests.Count > 0) + { + ODERayRequest[] reqs = m_PendingRayRequests.ToArray(); + for (int i = 0; i < reqs.Length; i++) { - if (req.callbackMethod != null) // quick optimization here, don't raycast - RayCast(req); // if there isn't anyone to send results to - + if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast + RayCast(reqs[i]); // if there isn't anyone to send results } - */ - m_PendingRequests.Clear(); + + m_PendingRayRequests.Clear(); } } @@ -146,7 +182,6 @@ namespace OpenSim.Region.Physics.OdePlugin // Remove Ray d.GeomDestroy(ray); - // Define default results bool hitYN = false; uint hitConsumerID = 0; @@ -177,6 +212,31 @@ namespace OpenSim.Region.Physics.OdePlugin req.callbackMethod(hitYN, closestcontact, hitConsumerID, distance, snormal); } + /// + /// Method that actually initiates the raycast + /// + /// + private void RayCast(ODERayRequest req) + { + // Create the ray + IntPtr ray = d.CreateRay(m_scene.space, req.length); + d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z); + + // Collide test + d.SpaceCollide2(m_scene.space, ray, IntPtr.Zero, nearCallback); + + // Remove Ray + d.GeomDestroy(ray); + + // Find closest contact and object. + lock (m_contactResults) + { + // Return results + if (req.callbackMethod != null) + req.callbackMethod(m_contactResults); + } + } + // This is the standard Near. Uses space AABBs to speed up detection. private void near(IntPtr space, IntPtr g1, IntPtr g2) { @@ -342,10 +402,7 @@ namespace OpenSim.Region.Physics.OdePlugin m_contactResults.Add(collisionresult); } } - - } - } /// @@ -365,11 +422,12 @@ namespace OpenSim.Region.Physics.OdePlugin public RaycastCallback callbackMethod; } - public struct ContactResult + public struct ODERayRequest { - public Vector3 Pos; - public float Depth; - public uint ConsumerID; + public Vector3 Origin; public Vector3 Normal; + public int Count; + public float length; + public RayCallback callbackMethod; } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 7b8a80c..ba8cba4 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -3736,6 +3736,34 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } } + public override void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod) + { + if (retMethod != null) + { + m_rayCastManager.QueueRequest(position, direction, length, Count, retMethod); + } + } + + public override List RaycastWorld(Vector3 position, Vector3 direction, float length, int Count) + { + ContactResult[] ourResults = null; + RayCallback retMethod = delegate(List results) + { + ourResults = new ContactResult[results.Count]; + results.CopyTo(ourResults, 0); + }; + int waitTime = 0; + m_rayCastManager.QueueRequest(position, direction, length, Count, retMethod); + while (ourResults == null && waitTime < 1000) + { + Thread.Sleep(1); + waitTime++; + } + if (ourResults == null) + return new List (); + return new List(ourResults); + } + #if USE_DRAWSTUFF // Keyboard callback public void command(int cmd) -- cgit v1.1 From e9dbe54ab1217e4310b0e7e014516363237e2a21 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 15 Jul 2011 20:07:59 +0100 Subject: Fix some local id issues in physics glue --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 8 +------- OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index ba8cba4..6fda32d 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -1708,13 +1708,7 @@ namespace OpenSim.Region.Physics.OdePlugin } public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, - Vector3 size, Quaternion rotation) //To be removed - { - return AddPrimShape(primName, pbs, position, size, rotation, false); - } - - public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, - Vector3 size, Quaternion rotation, bool isPhysical) + Vector3 size, Quaternion rotation, bool isPhysical, uint localid) { #if SPAM m_log.DebugFormat("[PHYSICS]: Adding physics actor to {0}", primName); diff --git a/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs b/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs index fbd1574..2ea810f 100644 --- a/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs +++ b/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs @@ -84,7 +84,7 @@ namespace OpenSim.Region.Physics.OdePlugin.Tests Vector3 position = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 128f); Vector3 size = new Vector3(0.5f, 0.5f, 0.5f); Quaternion rot = Quaternion.Identity; - PhysicsActor prim = ps.AddPrimShape("CoolShape", newcube, position, size, rot, true); + PhysicsActor prim = ps.AddPrimShape("CoolShape", newcube, position, size, rot, true, 0); OdePrim oprim = (OdePrim)prim; OdeScene pscene = (OdeScene) ps; -- cgit v1.1 From 18652eb87ef0613b66664059581f991448d76af4 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 16 Jul 2011 01:36:27 +0100 Subject: Fix physics proxy regeneration when a mesh with more than one submesh is resized Addresses http://opensimulator.org/mantis/view.php?id=5584 --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 27bf942..b3045bd 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -2284,6 +2284,7 @@ Console.WriteLine("changeshape not need meshing"); if (value.IsFinite()) { _size = value; +// m_log.DebugFormat("[PHYSICS]: Set size on {0} to {1}", Name, value); } else { -- cgit v1.1 From 9fc7d65df7a094649eaa34921827ed1316ab67a5 Mon Sep 17 00:00:00 2001 From: Careminster Team Date: Tue, 19 Jul 2011 10:25:49 -0700 Subject: Apply the localID to the Physics actor to prevent null calls later --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 6 +++--- 1 file changed, 3 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 6fda32d..a307469 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -1677,7 +1677,7 @@ namespace OpenSim.Region.Physics.OdePlugin } private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation, - IMesh mesh, PrimitiveBaseShape pbs, bool isphysical) + IMesh mesh, PrimitiveBaseShape pbs, bool isphysical, uint localID) { Vector3 pos = position; Vector3 siz = size; @@ -1691,7 +1691,7 @@ namespace OpenSim.Region.Physics.OdePlugin lock (_prims) _prims.Add(newPrim); } - + newPrim.LocalID = localID; return newPrim; } @@ -1733,7 +1733,7 @@ namespace OpenSim.Region.Physics.OdePlugin // } // } - result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical); + result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical, localid); return result; } -- cgit v1.1 From 9c6227da661952ddc808e6c5fb0da5ebf774f0cb Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 29 Jul 2011 00:23:42 +0100 Subject: refactor: unindent the OdeScene.Simulate() loop to ignore the long commented out ifs and locks This is to make it more readable. --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 544 ++++++++++++++------------- 1 file changed, 274 insertions(+), 270 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index a307469..a6d737e 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -2687,320 +2687,321 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); //if (!ode.lockquery()) //{ // ode.dlock(world); - try - { - // Insert, remove Characters - bool processedtaints = false; - lock (_taintedActors) - { - if (_taintedActors.Count > 0) - { - foreach (OdeCharacter character in _taintedActors) - { - character.ProcessTaints(timeStep); + try + { + // Insert, remove Characters + bool processedtaints = false; - processedtaints = true; - //character.m_collisionscore = 0; - } + lock (_taintedActors) + { + if (_taintedActors.Count > 0) + { + foreach (OdeCharacter character in _taintedActors) + { + character.ProcessTaints(timeStep); - if (processedtaints) - _taintedActors.Clear(); - } + processedtaints = true; + //character.m_collisionscore = 0; } - // Modify other objects in the scene. - processedtaints = false; + if (processedtaints) + _taintedActors.Clear(); + } + } + + // Modify other objects in the scene. + processedtaints = false; - lock (_taintedPrimLock) + lock (_taintedPrimLock) + { + foreach (OdePrim prim in _taintedPrimL) + { + if (prim.m_taintremove) { - foreach (OdePrim prim in _taintedPrimL) - { - if (prim.m_taintremove) - { - //Console.WriteLine("Simulate calls RemovePrimThreadLocked"); - RemovePrimThreadLocked(prim); - } - else - { - //Console.WriteLine("Simulate calls ProcessTaints"); - prim.ProcessTaints(timeStep); - } - processedtaints = true; - prim.m_collisionscore = 0; - - // This loop can block up the Heartbeat for a very long time on large regions. - // We need to let the Watchdog know that the Heartbeat is not dead - // NOTE: This is currently commented out, but if things like OAR loading are - // timing the heartbeat out we will need to uncomment it - //Watchdog.UpdateThread(); - } + //Console.WriteLine("Simulate calls RemovePrimThreadLocked"); + RemovePrimThreadLocked(prim); + } + else + { + //Console.WriteLine("Simulate calls ProcessTaints"); + prim.ProcessTaints(timeStep); + } + processedtaints = true; + prim.m_collisionscore = 0; + + // This loop can block up the Heartbeat for a very long time on large regions. + // We need to let the Watchdog know that the Heartbeat is not dead + // NOTE: This is currently commented out, but if things like OAR loading are + // timing the heartbeat out we will need to uncomment it + //Watchdog.UpdateThread(); + } - if (SupportsNINJAJoints) - { - // Create pending joints, if possible + if (SupportsNINJAJoints) + { + // Create pending joints, if possible - // joints can only be processed after ALL bodies are processed (and exist in ODE), since creating - // a joint requires specifying the body id of both involved bodies - if (pendingJoints.Count > 0) + // joints can only be processed after ALL bodies are processed (and exist in ODE), since creating + // a joint requires specifying the body id of both involved bodies + if (pendingJoints.Count > 0) + { + List successfullyProcessedPendingJoints = new List(); + //DoJointErrorMessage(joints_connecting_actor, "taint: " + pendingJoints.Count + " pending joints"); + foreach (PhysicsJoint joint in pendingJoints) + { + //DoJointErrorMessage(joint, "taint: time to create joint with parms: " + joint.RawParams); + string[] jointParams = joint.RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); + List jointBodies = new List(); + bool allJointBodiesAreReady = true; + foreach (string jointParam in jointParams) { - List successfullyProcessedPendingJoints = new List(); - //DoJointErrorMessage(joints_connecting_actor, "taint: " + pendingJoints.Count + " pending joints"); - foreach (PhysicsJoint joint in pendingJoints) + if (jointParam == "NULL") { - //DoJointErrorMessage(joint, "taint: time to create joint with parms: " + joint.RawParams); - string[] jointParams = joint.RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); - List jointBodies = new List(); - bool allJointBodiesAreReady = true; - foreach (string jointParam in jointParams) + //DoJointErrorMessage(joint, "attaching NULL joint to world"); + jointBodies.Add(IntPtr.Zero); + } + else + { + //DoJointErrorMessage(joint, "looking for prim name: " + jointParam); + bool foundPrim = false; + lock (_prims) { - if (jointParam == "NULL") - { - //DoJointErrorMessage(joint, "attaching NULL joint to world"); - jointBodies.Add(IntPtr.Zero); - } - else + foreach (OdePrim prim in _prims) // FIXME: inefficient { - //DoJointErrorMessage(joint, "looking for prim name: " + jointParam); - bool foundPrim = false; - lock (_prims) + if (prim.SOPName == jointParam) { - foreach (OdePrim prim in _prims) // FIXME: inefficient + //DoJointErrorMessage(joint, "found for prim name: " + jointParam); + if (prim.IsPhysical && prim.Body != IntPtr.Zero) { - if (prim.SOPName == jointParam) - { - //DoJointErrorMessage(joint, "found for prim name: " + jointParam); - if (prim.IsPhysical && prim.Body != IntPtr.Zero) - { - jointBodies.Add(prim.Body); - foundPrim = true; - break; - } - else - { - DoJointErrorMessage(joint, "prim name " + jointParam + - " exists but is not (yet) physical; deferring joint creation. " + - "IsPhysical property is " + prim.IsPhysical + - " and body is " + prim.Body); - foundPrim = false; - break; - } - } + jointBodies.Add(prim.Body); + foundPrim = true; + break; + } + else + { + DoJointErrorMessage(joint, "prim name " + jointParam + + " exists but is not (yet) physical; deferring joint creation. " + + "IsPhysical property is " + prim.IsPhysical + + " and body is " + prim.Body); + foundPrim = false; + break; } - } - if (foundPrim) - { - // all is fine - } - else - { - allJointBodiesAreReady = false; - break; } } } - if (allJointBodiesAreReady) + if (foundPrim) { - //DoJointErrorMessage(joint, "allJointBodiesAreReady for " + joint.ObjectNameInScene + " with parms " + joint.RawParams); - if (jointBodies[0] == jointBodies[1]) - { - DoJointErrorMessage(joint, "ERROR: joint cannot be created; the joint bodies are the same, body1==body2. Raw body is " + jointBodies[0] + ". raw parms: " + joint.RawParams); - } - else - { - switch (joint.Type) - { - case PhysicsJointType.Ball: - { - IntPtr odeJoint; - //DoJointErrorMessage(joint, "ODE creating ball joint "); - odeJoint = d.JointCreateBall(world, IntPtr.Zero); - //DoJointErrorMessage(joint, "ODE attaching ball joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); - d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); - //DoJointErrorMessage(joint, "ODE setting ball anchor: " + odeJoint + " to vec:" + joint.Position); - d.JointSetBallAnchor(odeJoint, - joint.Position.X, - joint.Position.Y, - joint.Position.Z); - //DoJointErrorMessage(joint, "ODE joint setting OK"); - //DoJointErrorMessage(joint, "The ball joint's bodies are here: b0: "); - //DoJointErrorMessage(joint, "" + (jointBodies[0] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[0]) : "fixed environment")); - //DoJointErrorMessage(joint, "The ball joint's bodies are here: b1: "); - //DoJointErrorMessage(joint, "" + (jointBodies[1] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[1]) : "fixed environment")); - - if (joint is OdePhysicsJoint) - { - ((OdePhysicsJoint)joint).jointID = odeJoint; - } - else - { - DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!"); - } - } - break; - case PhysicsJointType.Hinge: - { - IntPtr odeJoint; - //DoJointErrorMessage(joint, "ODE creating hinge joint "); - odeJoint = d.JointCreateHinge(world, IntPtr.Zero); - //DoJointErrorMessage(joint, "ODE attaching hinge joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); - d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); - //DoJointErrorMessage(joint, "ODE setting hinge anchor: " + odeJoint + " to vec:" + joint.Position); - d.JointSetHingeAnchor(odeJoint, - joint.Position.X, - joint.Position.Y, - joint.Position.Z); - // We use the orientation of the x-axis of the joint's coordinate frame - // as the axis for the hinge. - - // Therefore, we must get the joint's coordinate frame based on the - // joint.Rotation field, which originates from the orientation of the - // joint's proxy object in the scene. - - // The joint's coordinate frame is defined as the transformation matrix - // that converts a vector from joint-local coordinates into world coordinates. - // World coordinates are defined as the XYZ coordinate system of the sim, - // as shown in the top status-bar of the viewer. - - // Once we have the joint's coordinate frame, we extract its X axis (AtAxis) - // and use that as the hinge axis. - - //joint.Rotation.Normalize(); - Matrix4 proxyFrame = Matrix4.CreateFromQuaternion(joint.Rotation); - - // Now extract the X axis of the joint's coordinate frame. - - // Do not try to use proxyFrame.AtAxis or you will become mired in the - // tar pit of transposed, inverted, and generally messed-up orientations. - // (In other words, Matrix4.AtAxis() is borked.) - // Vector3 jointAxis = proxyFrame.AtAxis; <--- this path leadeth to madness - - // Instead, compute the X axis of the coordinate frame by transforming - // the (1,0,0) vector. At least that works. - - //m_log.Debug("PHY: making axis: complete matrix is " + proxyFrame); - Vector3 jointAxis = Vector3.Transform(Vector3.UnitX, proxyFrame); - //m_log.Debug("PHY: making axis: hinge joint axis is " + jointAxis); - //DoJointErrorMessage(joint, "ODE setting hinge axis: " + odeJoint + " to vec:" + jointAxis); - d.JointSetHingeAxis(odeJoint, - jointAxis.X, - jointAxis.Y, - jointAxis.Z); - //d.JointSetHingeParam(odeJoint, (int)dParam.CFM, 0.1f); - if (joint is OdePhysicsJoint) - { - ((OdePhysicsJoint)joint).jointID = odeJoint; - } - else - { - DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!"); - } - } - break; - } - successfullyProcessedPendingJoints.Add(joint); - } + // all is fine } else { - DoJointErrorMessage(joint, "joint could not yet be created; still pending"); + allJointBodiesAreReady = false; + break; } } - foreach (PhysicsJoint successfullyProcessedJoint in successfullyProcessedPendingJoints) + } + if (allJointBodiesAreReady) + { + //DoJointErrorMessage(joint, "allJointBodiesAreReady for " + joint.ObjectNameInScene + " with parms " + joint.RawParams); + if (jointBodies[0] == jointBodies[1]) { - //DoJointErrorMessage(successfullyProcessedJoint, "finalizing succesfully procsssed joint " + successfullyProcessedJoint.ObjectNameInScene + " parms " + successfullyProcessedJoint.RawParams); - //DoJointErrorMessage(successfullyProcessedJoint, "removing from pending"); - InternalRemovePendingJoint(successfullyProcessedJoint); - //DoJointErrorMessage(successfullyProcessedJoint, "adding to active"); - InternalAddActiveJoint(successfullyProcessedJoint); - //DoJointErrorMessage(successfullyProcessedJoint, "done"); + DoJointErrorMessage(joint, "ERROR: joint cannot be created; the joint bodies are the same, body1==body2. Raw body is " + jointBodies[0] + ". raw parms: " + joint.RawParams); + } + else + { + switch (joint.Type) + { + case PhysicsJointType.Ball: + { + IntPtr odeJoint; + //DoJointErrorMessage(joint, "ODE creating ball joint "); + odeJoint = d.JointCreateBall(world, IntPtr.Zero); + //DoJointErrorMessage(joint, "ODE attaching ball joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); + d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); + //DoJointErrorMessage(joint, "ODE setting ball anchor: " + odeJoint + " to vec:" + joint.Position); + d.JointSetBallAnchor(odeJoint, + joint.Position.X, + joint.Position.Y, + joint.Position.Z); + //DoJointErrorMessage(joint, "ODE joint setting OK"); + //DoJointErrorMessage(joint, "The ball joint's bodies are here: b0: "); + //DoJointErrorMessage(joint, "" + (jointBodies[0] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[0]) : "fixed environment")); + //DoJointErrorMessage(joint, "The ball joint's bodies are here: b1: "); + //DoJointErrorMessage(joint, "" + (jointBodies[1] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[1]) : "fixed environment")); + + if (joint is OdePhysicsJoint) + { + ((OdePhysicsJoint)joint).jointID = odeJoint; + } + else + { + DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!"); + } + } + break; + case PhysicsJointType.Hinge: + { + IntPtr odeJoint; + //DoJointErrorMessage(joint, "ODE creating hinge joint "); + odeJoint = d.JointCreateHinge(world, IntPtr.Zero); + //DoJointErrorMessage(joint, "ODE attaching hinge joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); + d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); + //DoJointErrorMessage(joint, "ODE setting hinge anchor: " + odeJoint + " to vec:" + joint.Position); + d.JointSetHingeAnchor(odeJoint, + joint.Position.X, + joint.Position.Y, + joint.Position.Z); + // We use the orientation of the x-axis of the joint's coordinate frame + // as the axis for the hinge. + + // Therefore, we must get the joint's coordinate frame based on the + // joint.Rotation field, which originates from the orientation of the + // joint's proxy object in the scene. + + // The joint's coordinate frame is defined as the transformation matrix + // that converts a vector from joint-local coordinates into world coordinates. + // World coordinates are defined as the XYZ coordinate system of the sim, + // as shown in the top status-bar of the viewer. + + // Once we have the joint's coordinate frame, we extract its X axis (AtAxis) + // and use that as the hinge axis. + + //joint.Rotation.Normalize(); + Matrix4 proxyFrame = Matrix4.CreateFromQuaternion(joint.Rotation); + + // Now extract the X axis of the joint's coordinate frame. + + // Do not try to use proxyFrame.AtAxis or you will become mired in the + // tar pit of transposed, inverted, and generally messed-up orientations. + // (In other words, Matrix4.AtAxis() is borked.) + // Vector3 jointAxis = proxyFrame.AtAxis; <--- this path leadeth to madness + + // Instead, compute the X axis of the coordinate frame by transforming + // the (1,0,0) vector. At least that works. + + //m_log.Debug("PHY: making axis: complete matrix is " + proxyFrame); + Vector3 jointAxis = Vector3.Transform(Vector3.UnitX, proxyFrame); + //m_log.Debug("PHY: making axis: hinge joint axis is " + jointAxis); + //DoJointErrorMessage(joint, "ODE setting hinge axis: " + odeJoint + " to vec:" + jointAxis); + d.JointSetHingeAxis(odeJoint, + jointAxis.X, + jointAxis.Y, + jointAxis.Z); + //d.JointSetHingeParam(odeJoint, (int)dParam.CFM, 0.1f); + if (joint is OdePhysicsJoint) + { + ((OdePhysicsJoint)joint).jointID = odeJoint; + } + else + { + DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!"); + } + } + break; + } + successfullyProcessedPendingJoints.Add(joint); } } - } - - if (processedtaints) -//Console.WriteLine("Simulate calls Clear of _taintedPrim list"); - _taintedPrimH.Clear(); - _taintedPrimL.Clear(); - } - - // Move characters - lock (_characters) - { - List defects = new List(); - foreach (OdeCharacter actor in _characters) - { - if (actor != null) - actor.Move(timeStep, defects); - } - if (0 != defects.Count) - { - foreach (OdeCharacter defect in defects) + else { - RemoveCharacter(defect); + DoJointErrorMessage(joint, "joint could not yet be created; still pending"); } } - } - - // Move other active objects - lock (_activeprims) - { - foreach (OdePrim prim in _activeprims) + foreach (PhysicsJoint successfullyProcessedJoint in successfullyProcessedPendingJoints) { - prim.m_collisionscore = 0; - prim.Move(timeStep); + //DoJointErrorMessage(successfullyProcessedJoint, "finalizing succesfully procsssed joint " + successfullyProcessedJoint.ObjectNameInScene + " parms " + successfullyProcessedJoint.RawParams); + //DoJointErrorMessage(successfullyProcessedJoint, "removing from pending"); + InternalRemovePendingJoint(successfullyProcessedJoint); + //DoJointErrorMessage(successfullyProcessedJoint, "adding to active"); + InternalAddActiveJoint(successfullyProcessedJoint); + //DoJointErrorMessage(successfullyProcessedJoint, "done"); } } + } - //if ((framecount % m_randomizeWater) == 0) - // randomizeWater(waterlevel); + if (processedtaints) +//Console.WriteLine("Simulate calls Clear of _taintedPrim list"); + _taintedPrimH.Clear(); + _taintedPrimL.Clear(); + } - //int RayCastTimeMS = m_rayCastManager.ProcessQueuedRequests(); - m_rayCastManager.ProcessQueuedRequests(); + // Move characters + lock (_characters) + { + List defects = new List(); + foreach (OdeCharacter actor in _characters) + { + if (actor != null) + actor.Move(timeStep, defects); + } + if (0 != defects.Count) + { + foreach (OdeCharacter defect in defects) + { + RemoveCharacter(defect); + } + } + } - collision_optimized(timeStep); + // Move other active objects + lock (_activeprims) + { + foreach (OdePrim prim in _activeprims) + { + prim.m_collisionscore = 0; + prim.Move(timeStep); + } + } - lock (_collisionEventPrim) - { - foreach (PhysicsActor obj in _collisionEventPrim) - { - if (obj == null) - continue; + //if ((framecount % m_randomizeWater) == 0) + // randomizeWater(waterlevel); - switch ((ActorTypes)obj.PhysicsActorType) - { - case ActorTypes.Agent: - OdeCharacter cobj = (OdeCharacter)obj; - cobj.AddCollisionFrameTime(100); - cobj.SendCollisions(); - break; - case ActorTypes.Prim: - OdePrim pobj = (OdePrim)obj; - pobj.SendCollisions(); - break; - } - } - } + //int RayCastTimeMS = m_rayCastManager.ProcessQueuedRequests(); + m_rayCastManager.ProcessQueuedRequests(); - //if (m_global_contactcount > 5) - //{ - // m_log.DebugFormat("[PHYSICS]: Contacts:{0}", m_global_contactcount); - //} + collision_optimized(timeStep); - m_global_contactcount = 0; - - d.WorldQuickStep(world, ODE_STEPSIZE); - d.JointGroupEmpty(contactgroup); - //ode.dunlock(world); - } - catch (Exception e) + lock (_collisionEventPrim) + { + foreach (PhysicsActor obj in _collisionEventPrim) { - m_log.ErrorFormat("[PHYSICS]: {0}, {1}, {2}", e.Message, e.TargetSite, e); - ode.dunlock(world); + if (obj == null) + continue; + + switch ((ActorTypes)obj.PhysicsActorType) + { + case ActorTypes.Agent: + OdeCharacter cobj = (OdeCharacter)obj; + cobj.AddCollisionFrameTime(100); + cobj.SendCollisions(); + break; + case ActorTypes.Prim: + OdePrim pobj = (OdePrim)obj; + pobj.SendCollisions(); + break; + } } + } - step_time -= ODE_STEPSIZE; - i++; + //if (m_global_contactcount > 5) + //{ + // m_log.DebugFormat("[PHYSICS]: Contacts:{0}", m_global_contactcount); + //} + + m_global_contactcount = 0; + + d.WorldQuickStep(world, ODE_STEPSIZE); + d.JointGroupEmpty(contactgroup); + //ode.dunlock(world); + } + catch (Exception e) + { + m_log.ErrorFormat("[PHYSICS]: {0}, {1}, {2}", e.Message, e.TargetSite, e); + ode.dunlock(world); + } + + step_time -= ODE_STEPSIZE; + i++; //} //else //{ @@ -3091,8 +3092,10 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); fwriter.WriteLine(header); fwriter.Close(); } + d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); } + latertickcount = Util.EnvironmentTickCount() - tickCountFrameRun; // OpenSimulator above does 10 fps. 10 fps = means that the main thread loop and physics @@ -3694,6 +3697,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); //d.CloseODE(); } } + public override Dictionary GetTopColliders() { Dictionary returncolliders = new Dictionary(); -- cgit v1.1 From 3f0d8f3cbf0b340848aa938b83638567ba8b02cf Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 29 Jul 2011 00:39:02 +0100 Subject: refactor: Simplify reading OdeScene.Simulate() loop by shunting all the NINJA joints stuff into its own method. Now if ninja joints isn't active (which is the default) don't have to wade through a lot of massively indented irrelevant code. --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 373 ++++++++++++++------------- 1 file changed, 191 insertions(+), 182 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index a6d737e..9d41b15 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -2732,192 +2732,13 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); // This loop can block up the Heartbeat for a very long time on large regions. // We need to let the Watchdog know that the Heartbeat is not dead - // NOTE: This is currently commented out, but if things like OAR loading are + // NOTE: This is currently commented out, but if things like OAR loading are // timing the heartbeat out we will need to uncomment it //Watchdog.UpdateThread(); } if (SupportsNINJAJoints) - { - // Create pending joints, if possible - - // joints can only be processed after ALL bodies are processed (and exist in ODE), since creating - // a joint requires specifying the body id of both involved bodies - if (pendingJoints.Count > 0) - { - List successfullyProcessedPendingJoints = new List(); - //DoJointErrorMessage(joints_connecting_actor, "taint: " + pendingJoints.Count + " pending joints"); - foreach (PhysicsJoint joint in pendingJoints) - { - //DoJointErrorMessage(joint, "taint: time to create joint with parms: " + joint.RawParams); - string[] jointParams = joint.RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); - List jointBodies = new List(); - bool allJointBodiesAreReady = true; - foreach (string jointParam in jointParams) - { - if (jointParam == "NULL") - { - //DoJointErrorMessage(joint, "attaching NULL joint to world"); - jointBodies.Add(IntPtr.Zero); - } - else - { - //DoJointErrorMessage(joint, "looking for prim name: " + jointParam); - bool foundPrim = false; - lock (_prims) - { - foreach (OdePrim prim in _prims) // FIXME: inefficient - { - if (prim.SOPName == jointParam) - { - //DoJointErrorMessage(joint, "found for prim name: " + jointParam); - if (prim.IsPhysical && prim.Body != IntPtr.Zero) - { - jointBodies.Add(prim.Body); - foundPrim = true; - break; - } - else - { - DoJointErrorMessage(joint, "prim name " + jointParam + - " exists but is not (yet) physical; deferring joint creation. " + - "IsPhysical property is " + prim.IsPhysical + - " and body is " + prim.Body); - foundPrim = false; - break; - } - } - } - } - if (foundPrim) - { - // all is fine - } - else - { - allJointBodiesAreReady = false; - break; - } - } - } - if (allJointBodiesAreReady) - { - //DoJointErrorMessage(joint, "allJointBodiesAreReady for " + joint.ObjectNameInScene + " with parms " + joint.RawParams); - if (jointBodies[0] == jointBodies[1]) - { - DoJointErrorMessage(joint, "ERROR: joint cannot be created; the joint bodies are the same, body1==body2. Raw body is " + jointBodies[0] + ". raw parms: " + joint.RawParams); - } - else - { - switch (joint.Type) - { - case PhysicsJointType.Ball: - { - IntPtr odeJoint; - //DoJointErrorMessage(joint, "ODE creating ball joint "); - odeJoint = d.JointCreateBall(world, IntPtr.Zero); - //DoJointErrorMessage(joint, "ODE attaching ball joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); - d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); - //DoJointErrorMessage(joint, "ODE setting ball anchor: " + odeJoint + " to vec:" + joint.Position); - d.JointSetBallAnchor(odeJoint, - joint.Position.X, - joint.Position.Y, - joint.Position.Z); - //DoJointErrorMessage(joint, "ODE joint setting OK"); - //DoJointErrorMessage(joint, "The ball joint's bodies are here: b0: "); - //DoJointErrorMessage(joint, "" + (jointBodies[0] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[0]) : "fixed environment")); - //DoJointErrorMessage(joint, "The ball joint's bodies are here: b1: "); - //DoJointErrorMessage(joint, "" + (jointBodies[1] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[1]) : "fixed environment")); - - if (joint is OdePhysicsJoint) - { - ((OdePhysicsJoint)joint).jointID = odeJoint; - } - else - { - DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!"); - } - } - break; - case PhysicsJointType.Hinge: - { - IntPtr odeJoint; - //DoJointErrorMessage(joint, "ODE creating hinge joint "); - odeJoint = d.JointCreateHinge(world, IntPtr.Zero); - //DoJointErrorMessage(joint, "ODE attaching hinge joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); - d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); - //DoJointErrorMessage(joint, "ODE setting hinge anchor: " + odeJoint + " to vec:" + joint.Position); - d.JointSetHingeAnchor(odeJoint, - joint.Position.X, - joint.Position.Y, - joint.Position.Z); - // We use the orientation of the x-axis of the joint's coordinate frame - // as the axis for the hinge. - - // Therefore, we must get the joint's coordinate frame based on the - // joint.Rotation field, which originates from the orientation of the - // joint's proxy object in the scene. - - // The joint's coordinate frame is defined as the transformation matrix - // that converts a vector from joint-local coordinates into world coordinates. - // World coordinates are defined as the XYZ coordinate system of the sim, - // as shown in the top status-bar of the viewer. - - // Once we have the joint's coordinate frame, we extract its X axis (AtAxis) - // and use that as the hinge axis. - - //joint.Rotation.Normalize(); - Matrix4 proxyFrame = Matrix4.CreateFromQuaternion(joint.Rotation); - - // Now extract the X axis of the joint's coordinate frame. - - // Do not try to use proxyFrame.AtAxis or you will become mired in the - // tar pit of transposed, inverted, and generally messed-up orientations. - // (In other words, Matrix4.AtAxis() is borked.) - // Vector3 jointAxis = proxyFrame.AtAxis; <--- this path leadeth to madness - - // Instead, compute the X axis of the coordinate frame by transforming - // the (1,0,0) vector. At least that works. - - //m_log.Debug("PHY: making axis: complete matrix is " + proxyFrame); - Vector3 jointAxis = Vector3.Transform(Vector3.UnitX, proxyFrame); - //m_log.Debug("PHY: making axis: hinge joint axis is " + jointAxis); - //DoJointErrorMessage(joint, "ODE setting hinge axis: " + odeJoint + " to vec:" + jointAxis); - d.JointSetHingeAxis(odeJoint, - jointAxis.X, - jointAxis.Y, - jointAxis.Z); - //d.JointSetHingeParam(odeJoint, (int)dParam.CFM, 0.1f); - if (joint is OdePhysicsJoint) - { - ((OdePhysicsJoint)joint).jointID = odeJoint; - } - else - { - DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!"); - } - } - break; - } - successfullyProcessedPendingJoints.Add(joint); - } - } - else - { - DoJointErrorMessage(joint, "joint could not yet be created; still pending"); - } - } - foreach (PhysicsJoint successfullyProcessedJoint in successfullyProcessedPendingJoints) - { - //DoJointErrorMessage(successfullyProcessedJoint, "finalizing succesfully procsssed joint " + successfullyProcessedJoint.ObjectNameInScene + " parms " + successfullyProcessedJoint.RawParams); - //DoJointErrorMessage(successfullyProcessedJoint, "removing from pending"); - InternalRemovePendingJoint(successfullyProcessedJoint); - //DoJointErrorMessage(successfullyProcessedJoint, "adding to active"); - InternalAddActiveJoint(successfullyProcessedJoint); - //DoJointErrorMessage(successfullyProcessedJoint, "done"); - } - } - } + SimulateNINJAJoints(); if (processedtaints) //Console.WriteLine("Simulate calls Clear of _taintedPrim list"); @@ -3095,7 +2916,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix); } - + latertickcount = Util.EnvironmentTickCount() - tickCountFrameRun; // OpenSimulator above does 10 fps. 10 fps = means that the main thread loop and physics @@ -3117,6 +2938,194 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); return fps; } + /// + /// Simulate NINJA joints. + /// + /// + /// Called by the main Simulate() loop if NINJA joints are active. Should not be called from anywhere else. + /// + protected void SimulateNINJAJoints() + { + // Create pending joints, if possible + + // joints can only be processed after ALL bodies are processed (and exist in ODE), since creating + // a joint requires specifying the body id of both involved bodies + if (pendingJoints.Count > 0) + { + List successfullyProcessedPendingJoints = new List(); + //DoJointErrorMessage(joints_connecting_actor, "taint: " + pendingJoints.Count + " pending joints"); + foreach (PhysicsJoint joint in pendingJoints) + { + //DoJointErrorMessage(joint, "taint: time to create joint with parms: " + joint.RawParams); + string[] jointParams = joint.RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries); + List jointBodies = new List(); + bool allJointBodiesAreReady = true; + foreach (string jointParam in jointParams) + { + if (jointParam == "NULL") + { + //DoJointErrorMessage(joint, "attaching NULL joint to world"); + jointBodies.Add(IntPtr.Zero); + } + else + { + //DoJointErrorMessage(joint, "looking for prim name: " + jointParam); + bool foundPrim = false; + lock (_prims) + { + foreach (OdePrim prim in _prims) // FIXME: inefficient + { + if (prim.SOPName == jointParam) + { + //DoJointErrorMessage(joint, "found for prim name: " + jointParam); + if (prim.IsPhysical && prim.Body != IntPtr.Zero) + { + jointBodies.Add(prim.Body); + foundPrim = true; + break; + } + else + { + DoJointErrorMessage(joint, "prim name " + jointParam + + " exists but is not (yet) physical; deferring joint creation. " + + "IsPhysical property is " + prim.IsPhysical + + " and body is " + prim.Body); + foundPrim = false; + break; + } + } + } + } + if (foundPrim) + { + // all is fine + } + else + { + allJointBodiesAreReady = false; + break; + } + } + } + if (allJointBodiesAreReady) + { + //DoJointErrorMessage(joint, "allJointBodiesAreReady for " + joint.ObjectNameInScene + " with parms " + joint.RawParams); + if (jointBodies[0] == jointBodies[1]) + { + DoJointErrorMessage(joint, "ERROR: joint cannot be created; the joint bodies are the same, body1==body2. Raw body is " + jointBodies[0] + ". raw parms: " + joint.RawParams); + } + else + { + switch (joint.Type) + { + case PhysicsJointType.Ball: + { + IntPtr odeJoint; + //DoJointErrorMessage(joint, "ODE creating ball joint "); + odeJoint = d.JointCreateBall(world, IntPtr.Zero); + //DoJointErrorMessage(joint, "ODE attaching ball joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); + d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); + //DoJointErrorMessage(joint, "ODE setting ball anchor: " + odeJoint + " to vec:" + joint.Position); + d.JointSetBallAnchor(odeJoint, + joint.Position.X, + joint.Position.Y, + joint.Position.Z); + //DoJointErrorMessage(joint, "ODE joint setting OK"); + //DoJointErrorMessage(joint, "The ball joint's bodies are here: b0: "); + //DoJointErrorMessage(joint, "" + (jointBodies[0] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[0]) : "fixed environment")); + //DoJointErrorMessage(joint, "The ball joint's bodies are here: b1: "); + //DoJointErrorMessage(joint, "" + (jointBodies[1] != IntPtr.Zero ? "" + d.BodyGetPosition(jointBodies[1]) : "fixed environment")); + + if (joint is OdePhysicsJoint) + { + ((OdePhysicsJoint)joint).jointID = odeJoint; + } + else + { + DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!"); + } + } + break; + case PhysicsJointType.Hinge: + { + IntPtr odeJoint; + //DoJointErrorMessage(joint, "ODE creating hinge joint "); + odeJoint = d.JointCreateHinge(world, IntPtr.Zero); + //DoJointErrorMessage(joint, "ODE attaching hinge joint: " + odeJoint + " with b1:" + jointBodies[0] + " b2:" + jointBodies[1]); + d.JointAttach(odeJoint, jointBodies[0], jointBodies[1]); + //DoJointErrorMessage(joint, "ODE setting hinge anchor: " + odeJoint + " to vec:" + joint.Position); + d.JointSetHingeAnchor(odeJoint, + joint.Position.X, + joint.Position.Y, + joint.Position.Z); + // We use the orientation of the x-axis of the joint's coordinate frame + // as the axis for the hinge. + + // Therefore, we must get the joint's coordinate frame based on the + // joint.Rotation field, which originates from the orientation of the + // joint's proxy object in the scene. + + // The joint's coordinate frame is defined as the transformation matrix + // that converts a vector from joint-local coordinates into world coordinates. + // World coordinates are defined as the XYZ coordinate system of the sim, + // as shown in the top status-bar of the viewer. + + // Once we have the joint's coordinate frame, we extract its X axis (AtAxis) + // and use that as the hinge axis. + + //joint.Rotation.Normalize(); + Matrix4 proxyFrame = Matrix4.CreateFromQuaternion(joint.Rotation); + + // Now extract the X axis of the joint's coordinate frame. + + // Do not try to use proxyFrame.AtAxis or you will become mired in the + // tar pit of transposed, inverted, and generally messed-up orientations. + // (In other words, Matrix4.AtAxis() is borked.) + // Vector3 jointAxis = proxyFrame.AtAxis; <--- this path leadeth to madness + + // Instead, compute the X axis of the coordinate frame by transforming + // the (1,0,0) vector. At least that works. + + //m_log.Debug("PHY: making axis: complete matrix is " + proxyFrame); + Vector3 jointAxis = Vector3.Transform(Vector3.UnitX, proxyFrame); + //m_log.Debug("PHY: making axis: hinge joint axis is " + jointAxis); + //DoJointErrorMessage(joint, "ODE setting hinge axis: " + odeJoint + " to vec:" + jointAxis); + d.JointSetHingeAxis(odeJoint, + jointAxis.X, + jointAxis.Y, + jointAxis.Z); + //d.JointSetHingeParam(odeJoint, (int)dParam.CFM, 0.1f); + if (joint is OdePhysicsJoint) + { + ((OdePhysicsJoint)joint).jointID = odeJoint; + } + else + { + DoJointErrorMessage(joint, "WARNING: non-ode joint in ODE!"); + } + } + break; + } + successfullyProcessedPendingJoints.Add(joint); + } + } + else + { + DoJointErrorMessage(joint, "joint could not yet be created; still pending"); + } + } + foreach (PhysicsJoint successfullyProcessedJoint in successfullyProcessedPendingJoints) + { + //DoJointErrorMessage(successfullyProcessedJoint, "finalizing succesfully procsssed joint " + successfullyProcessedJoint.ObjectNameInScene + " parms " + successfullyProcessedJoint.RawParams); + //DoJointErrorMessage(successfullyProcessedJoint, "removing from pending"); + InternalRemovePendingJoint(successfullyProcessedJoint); + //DoJointErrorMessage(successfullyProcessedJoint, "adding to active"); + InternalAddActiveJoint(successfullyProcessedJoint); + //DoJointErrorMessage(successfullyProcessedJoint, "done"); + } + } + } + public override void GetResults() { } -- cgit v1.1 From 2a39d0cdb01dfbcc8d8838a80380dabfd9e468e1 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 29 Jul 2011 00:51:07 +0100 Subject: refactor: Move another chunk of ninja code out of the OdeScene.Simulate() loop for consistency and readability. --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 64 ++++++++++++++++------------ 1 file changed, 36 insertions(+), 28 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 9d41b15..c436fca 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -2738,7 +2738,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } if (SupportsNINJAJoints) - SimulateNINJAJoints(); + SimulatePendingNINJAJoints(); if (processedtaints) //Console.WriteLine("Simulate calls Clear of _taintedPrim list"); @@ -2839,6 +2839,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); { if (actor.bad) m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); + actor.UpdatePositionAndVelocity(); } } @@ -2852,6 +2853,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); { RemoveCharacter(chr); } + _badCharacter.Clear(); } } @@ -2867,30 +2869,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); actor.UpdatePositionAndVelocity(); if (SupportsNINJAJoints) - { - // If an actor moved, move its joint proxy objects as well. - // There seems to be an event PhysicsActor.OnPositionUpdate that could be used - // for this purpose but it is never called! So we just do the joint - // movement code here. - - if (actor.SOPName != null && - joints_connecting_actor.ContainsKey(actor.SOPName) && - joints_connecting_actor[actor.SOPName] != null && - joints_connecting_actor[actor.SOPName].Count > 0) - { - foreach (PhysicsJoint affectedJoint in joints_connecting_actor[actor.SOPName]) - { - if (affectedJoint.IsInPhysicsEngine) - { - DoJointMoved(affectedJoint); - } - else - { - DoJointErrorMessage(affectedJoint, "a body connected to a joint was moved, but the joint doesn't exist yet! this will lead to joint error. joint was: " + affectedJoint.ObjectNameInScene + " parms:" + affectedJoint.RawParams); - } - } - } - } + SimulateActorPendingJoints(actor); } } } @@ -2901,7 +2880,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); // Finished with all sim stepping. If requested, dump world state to file for debugging. // TODO: This call to the export function is already inside lock (OdeLock) - but is an extra lock needed? // TODO: This overwrites all dump files in-place. Should this be a growing logfile, or separate snapshots? - if (physics_logging && (physics_logging_interval>0) && (framecount % physics_logging_interval == 0)) + if (physics_logging && (physics_logging_interval > 0) && (framecount % physics_logging_interval == 0)) { string fname = "state-" + world.ToString() + ".DIF"; // give each physics world a separate filename string prefix = "world" + world.ToString(); // prefix for variable names in exported .DIF file @@ -2925,7 +2904,9 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); // If Physics stalls, it takes longer which makes the tick count ms larger. if (latertickcount < 100) + { m_timeDilation = 1.0f; + } else { m_timeDilation = 100f / latertickcount; @@ -2939,12 +2920,12 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } /// - /// Simulate NINJA joints. + /// Simulate pending NINJA joints. /// /// /// Called by the main Simulate() loop if NINJA joints are active. Should not be called from anywhere else. /// - protected void SimulateNINJAJoints() + protected void SimulatePendingNINJAJoints() { // Create pending joints, if possible @@ -3007,6 +2988,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } } } + if (allJointBodiesAreReady) { //DoJointErrorMessage(joint, "allJointBodiesAreReady for " + joint.ObjectNameInScene + " with parms " + joint.RawParams); @@ -3126,6 +3108,32 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } } + protected void SimulateActorPendingJoints(OdePrim actor) + { + // If an actor moved, move its joint proxy objects as well. + // There seems to be an event PhysicsActor.OnPositionUpdate that could be used + // for this purpose but it is never called! So we just do the joint + // movement code here. + + if (actor.SOPName != null && + joints_connecting_actor.ContainsKey(actor.SOPName) && + joints_connecting_actor[actor.SOPName] != null && + joints_connecting_actor[actor.SOPName].Count > 0) + { + foreach (PhysicsJoint affectedJoint in joints_connecting_actor[actor.SOPName]) + { + if (affectedJoint.IsInPhysicsEngine) + { + DoJointMoved(affectedJoint); + } + else + { + DoJointErrorMessage(affectedJoint, "a body connected to a joint was moved, but the joint doesn't exist yet! this will lead to joint error. joint was: " + affectedJoint.ObjectNameInScene + " parms:" + affectedJoint.RawParams); + } + } + } + } + public override void GetResults() { } -- cgit v1.1 From f3c5a5b745eb134d3dbd63012df3e5f5e964e71c Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 29 Jul 2011 01:18:42 +0100 Subject: fix extremely minor Ode bug where the _taintedPrimL list would always be cleared on every OdeScene.Simulate() even if it was already empty. --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 17 ++++++++++++++--- 1 file changed, 14 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 c436fca..cd2b156 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -2719,14 +2719,15 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); { if (prim.m_taintremove) { - //Console.WriteLine("Simulate calls RemovePrimThreadLocked"); +// Console.WriteLine("Simulate calls RemovePrimThreadLocked for {0}", prim.Name); RemovePrimThreadLocked(prim); } else { - //Console.WriteLine("Simulate calls ProcessTaints"); +// Console.WriteLine("Simulate calls ProcessTaints for {0}", prim.Name); prim.ProcessTaints(timeStep); } + processedtaints = true; prim.m_collisionscore = 0; @@ -2741,9 +2742,11 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); SimulatePendingNINJAJoints(); if (processedtaints) + { //Console.WriteLine("Simulate calls Clear of _taintedPrim list"); _taintedPrimH.Clear(); _taintedPrimL.Clear(); + } } // Move characters @@ -2839,7 +2842,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); { if (actor.bad) m_log.WarnFormat("[PHYSICS]: BAD Actor {0} in _characters list was not removed?", actor.m_uuid); - + actor.UpdatePositionAndVelocity(); } } @@ -3096,6 +3099,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); DoJointErrorMessage(joint, "joint could not yet be created; still pending"); } } + foreach (PhysicsJoint successfullyProcessedJoint in successfullyProcessedPendingJoints) { //DoJointErrorMessage(successfullyProcessedJoint, "finalizing succesfully procsssed joint " + successfullyProcessedJoint.ObjectNameInScene + " parms " + successfullyProcessedJoint.RawParams); @@ -3108,6 +3112,13 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } } + /// + /// Simulate the joint proxies of a NINJA actor. + /// + /// + /// Called as part of the Simulate() loop if NINJA physics is active. Must only be called from there. + /// + /// protected void SimulateActorPendingJoints(OdePrim actor) { // If an actor moved, move its joint proxy objects as well. -- cgit v1.1 From d917010433dda944dd1f6a7afcb827937804e805 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 30 Jul 2011 03:11:36 +0100 Subject: minor: Add method doc to collision subscription methods. Change method case to reflect OpenSim standards. --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 7 +++++-- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 4 ++-- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 22 +++++++++++++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 6b74e74..7766691 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -1220,14 +1220,16 @@ namespace OpenSim.Region.Physics.OdePlugin { m_requestedUpdateFrequency = ms; m_eventsubscription = ms; - _parent_scene.addCollisionEventReporting(this); + _parent_scene.AddCollisionEventReporting(this); } + public override void UnSubscribeEvents() { - _parent_scene.remCollisionEventReporting(this); + _parent_scene.RemoveCollisionEventReporting(this); m_requestedUpdateFrequency = 0; m_eventsubscription = 0; } + public void AddCollisionEvent(uint CollidedWith, ContactPoint contact) { if (m_eventsubscription > 0) @@ -1248,6 +1250,7 @@ namespace OpenSim.Region.Physics.OdePlugin m_eventsubscription = 0; } } + public override bool SubscribedEvents() { if (m_eventsubscription > 0) diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index b3045bd..34c0deb 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -2986,12 +2986,12 @@ Console.WriteLine("changeshape not need meshing"); public override void SubscribeEvents(int ms) { m_eventsubscription = ms; - _parent_scene.addCollisionEventReporting(this); + _parent_scene.AddCollisionEventReporting(this); } public override void UnSubscribeEvents() { - _parent_scene.remCollisionEventReporting(this); + _parent_scene.RemoveCollisionEventReporting(this); m_eventsubscription = 0; } diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index cd2b156..e1e031f 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -198,7 +198,12 @@ namespace OpenSim.Region.Physics.OdePlugin private readonly List _taintedPrimL = new List(); private readonly HashSet _taintedActors = new HashSet(); private readonly List _perloopContact = new List(); + + /// + /// A list of actors that should receive collision events. + /// private readonly List _collisionEventPrim = new List(); + private readonly HashSet _badCharacter = new HashSet(); public Dictionary geom_name_map = new Dictionary(); public Dictionary actor_name_map = new Dictionary(); @@ -1604,7 +1609,11 @@ namespace OpenSim.Region.Physics.OdePlugin } // End recovered. Kitto Flora - public void addCollisionEventReporting(PhysicsActor obj) + /// + /// Add actor to the list that should receive collision events in the simulate loop. + /// + /// + public void AddCollisionEventReporting(PhysicsActor obj) { lock (_collisionEventPrim) { @@ -1613,7 +1622,11 @@ namespace OpenSim.Region.Physics.OdePlugin } } - public void remCollisionEventReporting(PhysicsActor obj) + /// + /// Remove actor from the list that should receive collision events in the simulate loop. + /// + /// + public void RemoveCollisionEventReporting(PhysicsActor obj) { lock (_collisionEventPrim) { @@ -2132,7 +2145,7 @@ namespace OpenSim.Region.Physics.OdePlugin //Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName); lock (prim) { - remCollisionEventReporting(prim); + RemoveCollisionEventReporting(prim); lock (ode) { if (prim.prim_geom != IntPtr.Zero) @@ -2792,6 +2805,8 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); if (obj == null) continue; +// m_log.DebugFormat("[PHYSICS]: Assessing {0} for collision events", obj.SOPName); + switch ((ActorTypes)obj.PhysicsActorType) { case ActorTypes.Agent: @@ -2799,6 +2814,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); cobj.AddCollisionFrameTime(100); cobj.SendCollisions(); break; + case ActorTypes.Prim: OdePrim pobj = (OdePrim)obj; pobj.SendCollisions(); -- cgit v1.1 From 49a3740ee9983ffa99a81924aa01071f4dc13a6b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 30 Jul 2011 03:56:29 +0100 Subject: minor: remove mono compiler warnings, some code spacing adjustments --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 5 ++++- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 2 +- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 8 +++----- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 7766691..4f461ad 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -1229,11 +1229,14 @@ namespace OpenSim.Region.Physics.OdePlugin m_requestedUpdateFrequency = 0; m_eventsubscription = 0; } - + public void AddCollisionEvent(uint CollidedWith, ContactPoint contact) { if (m_eventsubscription > 0) { +// m_log.DebugFormat( +// "[PHYSICS]: Adding collision event for {0}, collidedWith {1}, contact {2}", "", CollidedWith, contact); + CollisionEventsThisFrame.addCollider(CollidedWith, contact); } } diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 34c0deb..44eafb7 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -1457,7 +1457,6 @@ Console.WriteLine("changeadd 1"); { if (m_isphysical) { - if (!m_disabled && !m_taintremove && !childPrim) { if (Body == IntPtr.Zero) @@ -2999,6 +2998,7 @@ Console.WriteLine("changeshape not need meshing"); { if (CollisionEventsThisFrame == null) CollisionEventsThisFrame = new CollisionEventUpdate(); + CollisionEventsThisFrame.addCollider(CollidedWith, contact); } diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index e1e031f..8a24190 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -100,7 +100,7 @@ namespace OpenSim.Region.Physics.OdePlugin Rubber = 6 } - public sealed class OdeScene : PhysicsScene + public class OdeScene : PhysicsScene { private readonly ILog m_log; // private Dictionary m_storedCollisions = new Dictionary(); @@ -957,7 +957,6 @@ namespace OpenSim.Region.Physics.OdePlugin character.SetPidStatus(true); } } - if (p1.PhysicsActorType == (int) ActorTypes.Agent) { @@ -1058,9 +1057,7 @@ namespace OpenSim.Region.Physics.OdePlugin { joint = d.JointCreateContact(world, contactgroup, ref m_materialContacts[material, movintYN]); m_global_contactcount++; - } - } else { @@ -1083,7 +1080,6 @@ namespace OpenSim.Region.Physics.OdePlugin { joint = d.JointCreateContact(world, contactgroup, ref m_materialContacts[material, movintYN]); m_global_contactcount++; - } } } @@ -1295,6 +1291,7 @@ namespace OpenSim.Region.Physics.OdePlugin //returncollisions = true; break; + case ActorTypes.Prim: if (p1 is OdePrim) { @@ -1322,6 +1319,7 @@ namespace OpenSim.Region.Physics.OdePlugin cc2.AddCollisionEvent(obj2LocalID, contact); break; + case ActorTypes.Prim: if (p2 is OdePrim) -- cgit v1.1 From 4f4d0804618e5560964df90e5c5302b9fba8163d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 30 Jul 2011 23:20:43 +0100 Subject: refactor: Rename ODEPrim.ParentPrim() to AddChildPrim() for code readability --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 44eafb7..9c323a4 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -778,6 +778,7 @@ namespace OpenSim.Region.Physics.OdePlugin Body = IntPtr.Zero; } } + m_disabled = true; m_collisionscore = 0; } @@ -968,7 +969,7 @@ Console.WriteLine("ZProcessTaints for " + Name); OdePrim obj = (OdePrim)m_taintparent; //obj.disableBody(); //Console.WriteLine("changelink calls ParentPrim"); - obj.ParentPrim(this); + obj.AddChildPrim(this); /* if (obj.Body != (IntPtr)0 && Body != (IntPtr)0 && obj.Body != Body) @@ -1008,11 +1009,13 @@ Console.WriteLine("ZProcessTaints for " + Name); m_taintPhysics = m_isphysical; } - // I'm the parent - // prim is the child - public void ParentPrim(OdePrim prim) + /// + /// Add a child prim to this parent prim. + /// + /// Child prim + public void AddChildPrim(OdePrim prim) { -//Console.WriteLine("ParentPrim " + Name); +//Console.WriteLine("AddChildPrim " + Name); if (this.m_localID != prim.m_localID) { if (Body == IntPtr.Zero) @@ -1035,7 +1038,6 @@ Console.WriteLine("ZProcessTaints for " + Name); d.MassSetZero(out m2); d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z); - d.Quaternion quat = new d.Quaternion(); quat.W = prm._orientation.W; quat.X = prm._orientation.X; @@ -1105,6 +1107,7 @@ Console.WriteLine("ZProcessTaints for " + Name); prm.Body = Body; _parent_scene.addActivePrim(prm); } + m_collisionCategories |= CollisionCategories.Body; m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); @@ -1113,7 +1116,6 @@ Console.WriteLine("ZProcessTaints for " + Name); //Console.WriteLine(" Post GeomSetCategoryBits 2"); d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); - d.Quaternion quat2 = new d.Quaternion(); quat2.W = _orientation.W; quat2.X = _orientation.X; @@ -1135,7 +1137,6 @@ Console.WriteLine("ZProcessTaints for " + Name); d.BodySetAutoDisableFlag(Body, true); d.BodySetAutoDisableSteps(Body, body_autodisable_frames); - m_interpenetrationcount = 0; m_collisionscore = 0; m_disabled = false; @@ -1146,7 +1147,9 @@ Console.WriteLine("ZProcessTaints for " + Name); createAMotor(m_angularlock); } d.BodySetPosition(Body, Position.X, Position.Y, Position.Z); - if (m_vehicle.Type != Vehicle.TYPE_NONE) m_vehicle.Enable(Body, _parent_scene); + if (m_vehicle.Type != Vehicle.TYPE_NONE) + m_vehicle.Enable(Body, _parent_scene); + _parent_scene.addActivePrim(this); } } @@ -1183,7 +1186,7 @@ Console.WriteLine("ZProcessTaints for " + Name); foreach (OdePrim prm in childrenPrim) { //Console.WriteLine("ChildSetGeom calls ParentPrim"); - ParentPrim(prm); + AddChildPrim(prm); } } @@ -1223,7 +1226,7 @@ Console.WriteLine("ZProcessTaints for " + Name); foreach (OdePrim prm in childrenPrim) { //Console.WriteLine("ChildDelink calls ParentPrim"); - ParentPrim(prm); + AddChildPrim(prm); } } } -- cgit v1.1 From e08be91c846d898fdc79a88e79ac1feb491cb63d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 30 Jul 2011 23:44:47 +0100 Subject: Refactor: Replace instances of m_isphysical with IsPhysical rather than have some code reference the private var and other the public var without any functionality difference. Add some method doc to IsPhysical --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 73 ++++++++++++++++------------- 1 file changed, 40 insertions(+), 33 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 9c323a4..879d30f 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -61,6 +61,22 @@ namespace OpenSim.Region.Physics.OdePlugin { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private bool m_isphysical; + + /// + /// Is this prim subject to physics? Even if not, it's still solid for collision purposes. + /// + public override bool IsPhysical + { + get { return m_isphysical; } + set + { + m_isphysical = value; + if (!m_isphysical) // Zero the remembered last velocity + m_lastVelocity = Vector3.Zero; + } + } + private Vector3 _position; private Vector3 _velocity; private Vector3 _torque; @@ -153,7 +169,6 @@ namespace OpenSim.Region.Physics.OdePlugin private List childrenPrim = new List(); private bool iscolliding; - private bool m_isphysical; private bool m_isSelected; internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively @@ -240,13 +255,15 @@ namespace OpenSim.Region.Physics.OdePlugin m_targetSpace = (IntPtr)0; if (pos.Z < 0) - m_isphysical = false; + { + IsPhysical = false; + } else { - m_isphysical = pisPhysical; + IsPhysical = pisPhysical; // If we're physical, we need to be in the master space for now. // linksets *should* be in a space together.. but are not currently - if (m_isphysical) + if (IsPhysical) m_targetSpace = _parent_scene.space; } @@ -289,7 +306,7 @@ namespace OpenSim.Region.Physics.OdePlugin // through it while it's selected m_collisionscore = 0; - if ((m_isphysical && !_zeroFlag) || !value) + if ((IsPhysical && !_zeroFlag) || !value) { m_taintselected = value; _parent_scene.AddPhysicsActorTaint(this); @@ -332,7 +349,7 @@ namespace OpenSim.Region.Physics.OdePlugin { if (!childPrim) { - if (m_isphysical && Body != IntPtr.Zero) + if (IsPhysical && Body != IntPtr.Zero) { d.BodyEnable(Body); if (m_vehicle.Type != Vehicle.TYPE_NONE) @@ -347,7 +364,7 @@ namespace OpenSim.Region.Physics.OdePlugin { m_disabled = true; - if (m_isphysical && Body != IntPtr.Zero) + if (IsPhysical && Body != IntPtr.Zero) { d.BodyDisable(Body); } @@ -887,7 +904,7 @@ Console.WriteLine("ZProcessTaints for " + Name); } } - if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent)) + if (m_taintPhysics != IsPhysical && !(m_taintparent != _parent)) changePhysicsStatus(timestep); if (!_size.ApproxEquals(m_taintsize, 0f)) @@ -1006,7 +1023,7 @@ Console.WriteLine("ZProcessTaints for " + Name); } _parent = m_taintparent; - m_taintPhysics = m_isphysical; + m_taintPhysics = IsPhysical; } /// @@ -1159,7 +1176,7 @@ Console.WriteLine("ZProcessTaints for " + Name); private void ChildSetGeom(OdePrim odePrim) { - //if (m_isphysical && Body != IntPtr.Zero) + //if (IsPhysical && Body != IntPtr.Zero) lock (childrenPrim) { foreach (OdePrim prm in childrenPrim) @@ -1260,7 +1277,7 @@ Console.WriteLine("ZProcessTaints for " + Name); // first 50 again. then the last 50 are disabled. then the first 50, which were just woken // up, start simulating again, which in turn wakes up the last 50. - if (m_isphysical) + if (IsPhysical) { disableBodySoft(); } @@ -1271,7 +1288,7 @@ Console.WriteLine("ZProcessTaints for " + Name); d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); } - if (m_isphysical) + if (IsPhysical) { disableBodySoft(); } @@ -1280,7 +1297,7 @@ Console.WriteLine("ZProcessTaints for " + Name); { m_collisionCategories = CollisionCategories.Geom; - if (m_isphysical) + if (IsPhysical) m_collisionCategories |= CollisionCategories.Body; m_collisionFlags = m_default_collisionFlags; @@ -1295,7 +1312,8 @@ Console.WriteLine("ZProcessTaints for " + Name); d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); } - if (m_isphysical) + + if (IsPhysical) { if (Body != IntPtr.Zero) { @@ -1314,7 +1332,7 @@ Console.WriteLine("ZProcessTaints for " + Name); { m_taintposition = _position; m_taintrot = _orientation; - m_taintPhysics = m_isphysical; + m_taintPhysics = IsPhysical; m_taintselected = m_isSelected; m_taintsize = _size; m_taintshape = false; @@ -1442,7 +1460,7 @@ Console.WriteLine("changeadd 1"); d.GeomSetQuaternion(prim_geom, ref myrot); } - if (m_isphysical && Body == IntPtr.Zero) + if (IsPhysical && Body == IntPtr.Zero) { enableBody(); } @@ -1458,7 +1476,7 @@ Console.WriteLine("changeadd 1"); public void changemove(float timestep) { - if (m_isphysical) + if (IsPhysical) { if (!m_disabled && !m_taintremove && !childPrim) { @@ -1791,7 +1809,7 @@ Console.WriteLine(" JointCreateFixed"); { // KF: If this is a root prim do BodySet d.BodySetQuaternion(Body, ref myrot); - if (m_isphysical) + if (IsPhysical) { if (!m_angularlock.ApproxEquals(Vector3.One, 0f)) createAMotor(m_angularlock); @@ -1828,7 +1846,7 @@ Console.WriteLine(" JointCreateFixed"); public void changePhysicsStatus(float timestep) { - if (m_isphysical == true) + if (IsPhysical) { if (Body == IntPtr.Zero) { @@ -1848,8 +1866,6 @@ Console.WriteLine(" JointCreateFixed"); { if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim) { - - if (prim_geom != IntPtr.Zero) { try @@ -1867,6 +1883,7 @@ Console.WriteLine(" JointCreateFixed"); //Console.WriteLine("changePhysicsStatus for " + Name); changeadd(2f); } + if (childPrim) { if (_parent != null) @@ -1885,7 +1902,7 @@ Console.WriteLine(" JointCreateFixed"); changeSelectedStatus(timestep); resetCollisionAccounting(); - m_taintPhysics = m_isphysical; + m_taintPhysics = IsPhysical; } public void changesize(float timestamp) @@ -2218,16 +2235,6 @@ Console.WriteLine("changeshape not need meshing"); m_taintVelocity = Vector3.Zero; } - public override bool IsPhysical - { - get { return m_isphysical; } - set { - m_isphysical = value; - if (!m_isphysical) // Zero the remembered last velocity - m_lastVelocity = Vector3.Zero; - } - } - public void setPrimForRemoval() { m_taintremove = true; @@ -2406,7 +2413,7 @@ Console.WriteLine("changeshape not need meshing"); { get { - if (!m_isphysical || Body == IntPtr.Zero) + if (!IsPhysical || Body == IntPtr.Zero) return Vector3.Zero; return _torque; -- cgit v1.1 From f1ce17071dfed560d4785f7b2aabaf25f241f81f Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sun, 31 Jul 2011 00:43:02 +0100 Subject: minor: method doc --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 23 ++++++++++++++++++++--- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 1 - 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 879d30f..e91ee51 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -157,7 +157,12 @@ namespace OpenSim.Region.Physics.OdePlugin private IMesh _mesh; private PrimitiveBaseShape _pbs; private OdeScene _parent_scene; + + /// + /// The physics space which contains prim geometries + /// public IntPtr m_targetSpace = IntPtr.Zero; + public IntPtr prim_geom; public IntPtr prev_geom; public IntPtr _triMeshData; @@ -223,7 +228,6 @@ namespace OpenSim.Region.Physics.OdePlugin // m_tensor = parent_scene.bodyMotorJointMaxforceTensor; body_autodisable_frames = parent_scene.bodyFramesAutoDisable; - prim_geom = IntPtr.Zero; prev_geom = IntPtr.Zero; @@ -322,6 +326,10 @@ namespace OpenSim.Region.Physics.OdePlugin } } + /// + /// Set a new geometry for this prim. + /// + /// public void SetGeom(IntPtr geom) { prev_geom = prim_geom; @@ -370,6 +378,9 @@ namespace OpenSim.Region.Physics.OdePlugin } } + /// + /// Make a prim subject to physics. + /// public void enableBody() { // Don't enable this body if we're a child prim @@ -745,6 +756,9 @@ namespace OpenSim.Region.Physics.OdePlugin } } + /// + /// Stop a prim from being subject to physics. + /// public void disableBody() { //this kills the body so things like 'mesh' can re-create it. @@ -1192,7 +1206,6 @@ Console.WriteLine("ZProcessTaints for " + Name); } disableBody(); - if (Body != IntPtr.Zero) { _parent_scene.remActivePrim(this); @@ -1206,7 +1219,6 @@ Console.WriteLine("ZProcessTaints for " + Name); AddChildPrim(prm); } } - } private void ChildDelink(OdePrim odePrim) @@ -1341,6 +1353,11 @@ Console.WriteLine("ZProcessTaints for " + Name); m_taintVelocity = Vector3.Zero; } + /// + /// Create a geometry for the given mesh in the given target space. + /// + /// + /// /param> public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh) { #if SPAM diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 8a24190..3c702db 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -305,7 +305,6 @@ namespace OpenSim.Region.Physics.OdePlugin world = d.WorldCreate(); space = d.HashSpaceCreate(IntPtr.Zero); - contactgroup = d.JointGroupCreate(0); //contactgroup -- cgit v1.1 From 454312f5bc7e301d44e37f56a1078b8ff020bf5d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sun, 31 Jul 2011 00:44:23 +0100 Subject: refactor: rename CreateGeom _mesh argument to mesh, so as to not confuse this with the pre-existing _mesh field --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index e91ee51..905522d 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -1358,14 +1358,14 @@ Console.WriteLine("ZProcessTaints for " + Name); /// /// /// /param> - public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh) + public void CreateGeom(IntPtr m_targetSpace, IMesh mesh) { #if SPAM Console.WriteLine("CreateGeom:"); #endif - if (_mesh != null) + if (mesh != null) { - setMesh(_parent_scene, _mesh); + setMesh(_parent_scene, mesh); } else { -- cgit v1.1 From 196a774b2453c71403f74959b710335109edfe1a Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sun, 31 Jul 2011 00:45:20 +0100 Subject: minor: correct method doc for last commit --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 905522d..712f7cd 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -1357,7 +1357,7 @@ Console.WriteLine("ZProcessTaints for " + Name); /// Create a geometry for the given mesh in the given target space. /// /// - /// /param> + /// /param> public void CreateGeom(IntPtr m_targetSpace, IMesh mesh) { #if SPAM -- cgit v1.1 From bd8f538f800afeffdb6b8ced11e65940921424ab Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sun, 31 Jul 2011 00:49:49 +0100 Subject: refactor: Remove argument to pass in an initial mesh to OdePrim since this is no longer required and it prevents removal of the _mesh field (which is only used temporarily) If passing in a mesh becomes important again in the future then this can be reinstated. --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 3 +-- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 29 ++++------------------------ 2 files changed, 5 insertions(+), 27 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 712f7cd..cd6a0fb 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -208,7 +208,7 @@ namespace OpenSim.Region.Physics.OdePlugin internal int m_material = (int)Material.Wood; public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size, - Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) + Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) { Name = primName; m_vehicle = new ODEDynamics(); @@ -252,7 +252,6 @@ namespace OpenSim.Region.Physics.OdePlugin _orientation = rotation; m_taintrot = _orientation; - _mesh = mesh; _pbs = pbs; _parent_scene = parent_scene; diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 3c702db..1d4a28e 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -304,7 +304,7 @@ namespace OpenSim.Region.Physics.OdePlugin // Create the world and the first space world = d.WorldCreate(); space = d.HashSpaceCreate(IntPtr.Zero); - + contactgroup = d.JointGroupCreate(0); //contactgroup @@ -1687,7 +1687,7 @@ namespace OpenSim.Region.Physics.OdePlugin } private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation, - IMesh mesh, PrimitiveBaseShape pbs, bool isphysical, uint localID) + PrimitiveBaseShape pbs, bool isphysical, uint localID) { Vector3 pos = position; Vector3 siz = size; @@ -1696,7 +1696,7 @@ namespace OpenSim.Region.Physics.OdePlugin OdePrim newPrim; lock (OdeLock) { - newPrim = new OdePrim(name, this, pos, siz, rot, mesh, pbs, isphysical, ode); + newPrim = new OdePrim(name, this, pos, siz, rot, pbs, isphysical, ode); lock (_prims) _prims.Add(newPrim); @@ -1724,28 +1724,7 @@ namespace OpenSim.Region.Physics.OdePlugin m_log.DebugFormat("[PHYSICS]: Adding physics actor to {0}", primName); #endif - PhysicsActor result; - IMesh mesh = null; - - // Don't create the mesh here - wait until the mesh data is loaded from the asset store. -// if (needsMeshing(pbs)) -// { -// try -// { -// mesh = mesher.CreateMesh(primName, pbs, size, 32f, isPhysical); -// } -// catch(Exception e) -// { -// m_log.ErrorFormat("[PHYSICS]: Exception while meshing prim {0}.", primName); -// m_log.Debug(e.ToString()); -// mesh = null; -// return null; -// } -// } - - result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical, localid); - - return result; + return AddPrim(primName, position, size, rotation, pbs, isPhysical, localid); } public override float TimeDilation -- cgit v1.1 From d0412765172e9431813dee3a30473c8f28c184bc Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sun, 31 Jul 2011 01:03:52 +0100 Subject: Remove _mesh field since the mesh data no longer needs to be stored after it's initially used. This may improve memory usage for regions using mesh and sculpts, though I suspect that it doesn't address the current memory leak. --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 65 +++++++---------------------- 1 file changed, 16 insertions(+), 49 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index cd6a0fb..fdb95cf 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -154,7 +154,6 @@ namespace OpenSim.Region.Physics.OdePlugin private List m_forcelist = new List(); private List m_angularforcelist = new List(); - private IMesh _mesh; private PrimitiveBaseShape _pbs; private OdeScene _parent_scene; @@ -1356,7 +1355,7 @@ Console.WriteLine("ZProcessTaints for " + Name); /// Create a geometry for the given mesh in the given target space. /// /// - /// /param> + /// If null, then a mesh is used that is based on the profile shape data. public void CreateGeom(IntPtr m_targetSpace, IMesh mesh) { #if SPAM @@ -1447,15 +1446,14 @@ Console.WriteLine("CreateGeom:"); m_targetSpace = targetspace; - if (_mesh == null) + IMesh mesh = null; + + if (_parent_scene.needsMeshing(_pbs)) { - if (_parent_scene.needsMeshing(_pbs)) - { - // Don't need to re-enable body.. it's done in SetMesh - _mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical); - // createmesh returns null when it's a shape that isn't a cube. - // m_log.Debug(m_localID); - } + // Don't need to re-enable body.. it's done in SetMesh + mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical); + // createmesh returns null when it's a shape that isn't a cube. + // m_log.Debug(m_localID); } lock (_parent_scene.OdeLock) @@ -1463,7 +1461,7 @@ Console.WriteLine("CreateGeom:"); #if SPAM Console.WriteLine("changeadd 1"); #endif - CreateGeom(m_targetSpace, _mesh); + CreateGeom(m_targetSpace, mesh); if (prim_geom != IntPtr.Zero) { @@ -1888,7 +1886,6 @@ Console.WriteLine(" JointCreateFixed"); { d.GeomDestroy(prim_geom); prim_geom = IntPtr.Zero; - _mesh = null; } catch (System.AccessViolationException) { @@ -1933,12 +1930,6 @@ Console.WriteLine(" JointCreateFixed"); if (_size.Y <= 0) _size.Y = 0.01f; if (_size.Z <= 0) _size.Z = 0.01f; - // Cleanup of old prim geometry - if (_mesh != null) - { - // TODO: Cleanup meshing here - } - //kill body to rebuild if (IsPhysical && Body != IntPtr.Zero) { @@ -1966,6 +1957,8 @@ Console.WriteLine(" JointCreateFixed"); prim_geom = IntPtr.Zero; // we don't need to do space calculation because the client sends a position update also. + IMesh mesh = null; + // Construction of new prim if (_parent_scene.needsMeshing(_pbs)) { @@ -1975,27 +1968,11 @@ Console.WriteLine(" JointCreateFixed"); meshlod = _parent_scene.MeshSculptphysicalLOD; // Don't need to re-enable body.. it's done in SetMesh - IMesh mesh = null; - if (_parent_scene.needsMeshing(_pbs)) mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); - -#if SPAM -Console.WriteLine("changesize 1"); -#endif - CreateGeom(m_targetSpace, mesh); - } - else - { - _mesh = null; - -#if SPAM -Console.WriteLine("changesize 2"); -#endif - - CreateGeom(m_targetSpace, _mesh); } + CreateGeom(m_targetSpace, mesh); d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); d.Quaternion myrot = new d.Quaternion(); myrot.X = _orientation.X; @@ -2083,6 +2060,8 @@ Console.WriteLine("changesize 2"); if (_size.Z <= 0) _size.Z = 0.01f; // Construction of new prim + IMesh mesh = null; + if (_parent_scene.needsMeshing(_pbs)) { // Don't need to re-enable body.. it's done in CreateMesh @@ -2092,22 +2071,10 @@ Console.WriteLine("changesize 2"); meshlod = _parent_scene.MeshSculptphysicalLOD; // createmesh returns null when it doesn't mesh. - IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); -#if SPAM -Console.WriteLine("changeshape needed meshing"); -#endif - CreateGeom(m_targetSpace, mesh); - } - else - { - _mesh = null; - -#if SPAM -Console.WriteLine("changeshape not need meshing"); -#endif - CreateGeom(m_targetSpace, null); + mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); } + CreateGeom(m_targetSpace, mesh); d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); d.Quaternion myrot = new d.Quaternion(); //myrot.W = _orientation.w; -- cgit v1.1 From 210296482634aa2f99f01a2b2990b581ef45eeb6 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 1 Aug 2011 05:14:16 +0100 Subject: minor: indentation correction --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 30 ++++++++++++---------------- 1 file changed, 13 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 1d4a28e..c1c4d11 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -3482,24 +3482,21 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); float hfmin = 2000; float hfmax = -2000; - for (int x = 0; x < heightmapWidthSamples; x++) + for (int x = 0; x < heightmapWidthSamples; x++) + { + for (int y = 0; y < heightmapHeightSamples; y++) { - for (int y = 0; y < heightmapHeightSamples; y++) - { - int xx = Util.Clip(x - 1, 0, regionsize - 1); - int yy = Util.Clip(y - 1, 0, regionsize - 1); - - - float val= heightMap[yy * (int)Constants.RegionSize + xx]; - _heightmap[x * ((int)Constants.RegionSize + 2) + y] = val; - - hfmin = (val < hfmin) ? val : hfmin; - hfmax = (val > hfmax) ? val : hfmax; - } + int xx = Util.Clip(x - 1, 0, regionsize - 1); + int yy = Util.Clip(y - 1, 0, regionsize - 1); + + + float val= heightMap[yy * (int)Constants.RegionSize + xx]; + _heightmap[x * ((int)Constants.RegionSize + 2) + y] = val; + + hfmin = (val < hfmin) ? val : hfmin; + hfmax = (val > hfmax) ? val : hfmax; } - - - + } lock (OdeLock) { @@ -3554,7 +3551,6 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name); } RegionTerrain.Add(pOffset, GroundGeom, GroundGeom); TerrainHeightFieldHeights.Add(GroundGeom,_heightmap); - } } -- cgit v1.1 From dfa2f7d7151ec0e3835c4a008897389353be1cb3 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 1 Aug 2011 05:34:02 +0100 Subject: If a prim changes size or shape, add actor to _parent_scene.actor_name_map with new prim_geom key, as the old one becomes invalid. This resolves http://opensimulator.org/mantis/view.php?id=5603 where changing size or shape would stop collision_start being fired in a running script. In both this and existing code we are not removing old actors from actor_name_map when the existing prim_geom is removed, which leads to a small memory leak over time. This needs to be fixed. --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index fdb95cf..e18e1b4 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -1481,7 +1481,7 @@ Console.WriteLine("changeadd 1"); } _parent_scene.geom_name_map[prim_geom] = this.Name; - _parent_scene.actor_name_map[prim_geom] = (PhysicsActor)this; + _parent_scene.actor_name_map[prim_geom] = this; changeSelectedStatus(timestep); @@ -1991,6 +1991,7 @@ Console.WriteLine(" JointCreateFixed"); } _parent_scene.geom_name_map[prim_geom] = oldname; + _parent_scene.actor_name_map[prim_geom] = this; changeSelectedStatus(timestamp); if (childPrim) @@ -2095,7 +2096,9 @@ Console.WriteLine(" JointCreateFixed"); d.BodyEnable(Body); } } + _parent_scene.geom_name_map[prim_geom] = oldname; + _parent_scene.actor_name_map[prim_geom] = this; changeSelectedStatus(timestamp); if (childPrim) -- cgit v1.1 From 509200d5cd0646a75eaa200165bbae85e09b4380 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 1 Aug 2011 05:48:27 +0100 Subject: minor: add note to RemovePrimThreadLocked() to the effect that it contrary to the summary, it is being called from within Simulate() lock (OdeLock) --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 2 +- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index e18e1b4..61408f0 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -1352,7 +1352,7 @@ Console.WriteLine("ZProcessTaints for " + Name); } /// - /// Create a geometry for the given mesh in the given target space. + /// Create a geometry for the given mesh/shape in the given target space. /// /// /// If null, then a mesh is used that is based on the profile shape data. diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index c1c4d11..4419dff 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -2110,6 +2110,9 @@ namespace OpenSim.Region.Physics.OdePlugin /// /// This is called from within simulate but outside the locked portion /// We need to do our own locking here + /// (Note: As of 20110801 this no longer appears to be true - this is being called within lock (odeLock) in + /// Simulate() -- justincc). + /// /// Essentially, we need to remove the prim from our space segment, whatever segment it's in. /// /// If there are no more prim in the segment, we need to empty (spacedestroy)the segment and reclaim memory -- cgit v1.1 From 6618948ff9b1e98b52f3067855ca1b05e7e36144 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 1 Aug 2011 06:15:02 +0100 Subject: refactor: centralize prim geom removal code from four places to one --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 63 ++++++++++++++++------------ OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 24 ++++------- 2 files changed, 44 insertions(+), 43 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 61408f0..e90df48 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -1352,7 +1352,7 @@ Console.WriteLine("ZProcessTaints for " + Name); } /// - /// Create a geometry for the given mesh/shape in the given target space. + /// Create a geometry for the given mesh in the given target space. /// /// /// If null, then a mesh is used that is based on the profile shape data. @@ -1436,6 +1436,36 @@ Console.WriteLine("CreateGeom:"); } } + /// + /// Remove the existing geom from this prim. + /// + /// + /// If null, then a mesh is used that is based on the profile shape data. + /// true if the geom was successfully removed, false if it was already gone or the remove failed. + public bool RemoveGeom() + { + if (prim_geom != IntPtr.Zero) + { + try + { + d.GeomDestroy(prim_geom); + prim_geom = IntPtr.Zero; + } + catch (System.AccessViolationException) + { + prim_geom = IntPtr.Zero; + m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name); + return false; + } + + return true; + } + else + { + return false; + } + } + public void changeadd(float timestep) { int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position); @@ -1880,19 +1910,8 @@ Console.WriteLine(" JointCreateFixed"); { if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim) { - if (prim_geom != IntPtr.Zero) - { - try - { - d.GeomDestroy(prim_geom); - prim_geom = IntPtr.Zero; - } - catch (System.AccessViolationException) - { - prim_geom = IntPtr.Zero; - m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name); - } - } + RemoveGeom(); + //Console.WriteLine("changePhysicsStatus for " + Name); changeadd(2f); } @@ -1953,8 +1972,8 @@ Console.WriteLine(" JointCreateFixed"); d.SpaceRemove(m_targetSpace, prim_geom); } - d.GeomDestroy(prim_geom); - prim_geom = IntPtr.Zero; + RemoveGeom(); + // we don't need to do space calculation because the client sends a position update also. IMesh mesh = null; @@ -2044,17 +2063,9 @@ Console.WriteLine(" JointCreateFixed"); disableBody(); } } - try - { - d.GeomDestroy(prim_geom); - } - catch (System.AccessViolationException) - { - prim_geom = IntPtr.Zero; - m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name); - } - prim_geom = IntPtr.Zero; + RemoveGeom(); + // we don't need to do space calculation because the client sends a position update also. if (_size.X <= 0) _size.X = 0.01f; if (_size.Y <= 0) _size.Y = 0.01f; diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 4419dff..3402be2 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -2094,6 +2094,8 @@ namespace OpenSim.Region.Physics.OdePlugin public override void RemovePrim(PhysicsActor prim) { + // As with all ODE physics operations, we don't remove the prim immediately but signal that it should be + // removed in the next physics simulate pass. if (prim is OdePrim) { lock (OdeLock) @@ -2169,24 +2171,12 @@ namespace OpenSim.Region.Physics.OdePlugin //} //} //m_log.Warn(prim.prim_geom); - try - { - if (prim.prim_geom != IntPtr.Zero) - { - d.GeomDestroy(prim.prim_geom); - prim.prim_geom = IntPtr.Zero; - } - else - { - m_log.Warn("[PHYSICS]: Unable to remove prim from physics scene"); - } - } - catch (AccessViolationException) - { - m_log.Info("[PHYSICS]: Couldn't remove prim from physics scene, it was already be removed."); - } + + if (!prim.RemoveGeom()) + m_log.Warn("[PHYSICS]: Unable to remove prim from physics scene"); + lock (_prims) - _prims.Remove(prim); + _prims.Remove(prim); //If there are no more geometries in the sub-space, we don't need it in the main space anymore //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0) -- cgit v1.1 From f32dbef64715bb389a0aa8cd7d2a994e6b168b61 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 1 Aug 2011 06:32:30 +0100 Subject: When an ODE geom is removed (as when a non-phantom prim is deleted, resized or shape changed, also remove the OdeScene.actor_name_map entry pointing to the phys actor This is to stop a small memory leak over time when prims are deleted or phantom-toggled --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index e90df48..16764c2 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -1448,6 +1448,7 @@ Console.WriteLine("CreateGeom:"); { try { + _parent_scene.actor_name_map.Remove(prim_geom); d.GeomDestroy(prim_geom); prim_geom = IntPtr.Zero; } @@ -1455,6 +1456,7 @@ Console.WriteLine("CreateGeom:"); { prim_geom = IntPtr.Zero; m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name); + return false; } -- cgit v1.1 From f79df6f43f76fee577e987d1b931b4e30ad8b0d5 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 1 Aug 2011 06:35:59 +0100 Subject: remove the unused ODEPrim.prev_geom field --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 3 --- 1 file changed, 3 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 16764c2..345156e 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -163,7 +163,6 @@ namespace OpenSim.Region.Physics.OdePlugin public IntPtr m_targetSpace = IntPtr.Zero; public IntPtr prim_geom; - public IntPtr prev_geom; public IntPtr _triMeshData; private IntPtr _linkJointGroup = IntPtr.Zero; @@ -228,7 +227,6 @@ namespace OpenSim.Region.Physics.OdePlugin body_autodisable_frames = parent_scene.bodyFramesAutoDisable; prim_geom = IntPtr.Zero; - prev_geom = IntPtr.Zero; if (!pos.IsFinite()) { @@ -330,7 +328,6 @@ namespace OpenSim.Region.Physics.OdePlugin /// public void SetGeom(IntPtr geom) { - prev_geom = prim_geom; prim_geom = geom; //Console.WriteLine("SetGeom to " + prim_geom + " for " + Name); if (prim_geom != IntPtr.Zero) -- cgit v1.1 From ccb4b762427f8f9c88b8d26a250acb96b32ea807 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 1 Aug 2011 06:40:29 +0100 Subject: On geom removal, remove the name from the OdeScene.geom_name_map too --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 345156e..8881c44 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -1445,6 +1445,7 @@ Console.WriteLine("CreateGeom:"); { try { + _parent_scene.geom_name_map.Remove(prim_geom); _parent_scene.actor_name_map.Remove(prim_geom); d.GeomDestroy(prim_geom); prim_geom = IntPtr.Zero; -- cgit v1.1 From 40a78db1828cfd9b159cfc0f0fc64409aa2d1489 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 1 Aug 2011 06:47:45 +0100 Subject: comment out unused code in OdeScene.TriCallback() --- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 3402be2..6e603e8 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -1423,18 +1423,18 @@ namespace OpenSim.Region.Physics.OdePlugin public int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex) { - String name1 = null; - String name2 = null; - - if (!geom_name_map.TryGetValue(trimesh, out name1)) - { - name1 = "null"; - } - - if (!geom_name_map.TryGetValue(refObject, out name2)) - { - name2 = "null"; - } +// String name1 = null; +// String name2 = null; +// +// if (!geom_name_map.TryGetValue(trimesh, out name1)) +// { +// name1 = "null"; +// } +// +// if (!geom_name_map.TryGetValue(refObject, out name2)) +// { +// name2 = "null"; +// } // m_log.InfoFormat("TriCallback: A collision was detected between {1} and {2}. Index was {3}", 0, name1, name2, triangleIndex); -- cgit v1.1 From f9d6a91252366df40ab44220538c9b691156f801 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 1 Aug 2011 06:52:52 +0100 Subject: Instead of preserving old name in geom_name_map in change size or shape, use the Name property instead. This is equivalent since the prim 'name' is never changed. In fact, this propery is never used for prims --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 8881c44..0128cbc 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -1510,7 +1510,7 @@ Console.WriteLine("changeadd 1"); } } - _parent_scene.geom_name_map[prim_geom] = this.Name; + _parent_scene.geom_name_map[prim_geom] = Name; _parent_scene.actor_name_map[prim_geom] = this; changeSelectedStatus(timestep); @@ -1943,8 +1943,6 @@ Console.WriteLine(" JointCreateFixed"); m_log.DebugFormat("[ODE PRIM]: Called changesize"); #endif - string oldname = _parent_scene.geom_name_map[prim_geom]; - if (_size.X <= 0) _size.X = 0.01f; if (_size.Y <= 0) _size.Y = 0.01f; if (_size.Z <= 0) _size.Z = 0.01f; @@ -2009,7 +2007,7 @@ Console.WriteLine(" JointCreateFixed"); d.BodyEnable(Body); } - _parent_scene.geom_name_map[prim_geom] = oldname; + _parent_scene.geom_name_map[prim_geom] = Name; _parent_scene.actor_name_map[prim_geom] = this; changeSelectedStatus(timestamp); @@ -2045,8 +2043,6 @@ Console.WriteLine(" JointCreateFixed"); public void changeshape(float timestamp) { - string oldname = _parent_scene.geom_name_map[prim_geom]; - // Cleanup of old prim geometry and Bodies if (IsPhysical && Body != IntPtr.Zero) { @@ -2108,7 +2104,7 @@ Console.WriteLine(" JointCreateFixed"); } } - _parent_scene.geom_name_map[prim_geom] = oldname; + _parent_scene.geom_name_map[prim_geom] = Name; _parent_scene.actor_name_map[prim_geom] = this; changeSelectedStatus(timestamp); -- cgit v1.1 From 05e94ff27e5dea6283a110d7df52892473087392 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 1 Aug 2011 07:04:13 +0100 Subject: Move common gemo/agent map name code into CreateGeom() Fix build break. --- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 0128cbc..924d7c2 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -334,6 +334,9 @@ namespace OpenSim.Region.Physics.OdePlugin { d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); + + _parent_scene.geom_name_map[prim_geom] = Name; + _parent_scene.actor_name_map[prim_geom] = this; } if (childPrim) @@ -1510,9 +1513,6 @@ Console.WriteLine("changeadd 1"); } } - _parent_scene.geom_name_map[prim_geom] = Name; - _parent_scene.actor_name_map[prim_geom] = this; - changeSelectedStatus(timestep); m_taintadd = false; @@ -1986,7 +1986,7 @@ Console.WriteLine(" JointCreateFixed"); // Don't need to re-enable body.. it's done in SetMesh if (_parent_scene.needsMeshing(_pbs)) - mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); + mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, meshlod, IsPhysical); } CreateGeom(m_targetSpace, mesh); @@ -2007,9 +2007,6 @@ Console.WriteLine(" JointCreateFixed"); d.BodyEnable(Body); } - _parent_scene.geom_name_map[prim_geom] = Name; - _parent_scene.actor_name_map[prim_geom] = this; - changeSelectedStatus(timestamp); if (childPrim) { @@ -2079,7 +2076,7 @@ Console.WriteLine(" JointCreateFixed"); meshlod = _parent_scene.MeshSculptphysicalLOD; // createmesh returns null when it doesn't mesh. - mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); + mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, meshlod, IsPhysical); } CreateGeom(m_targetSpace, mesh); @@ -2104,9 +2101,6 @@ Console.WriteLine(" JointCreateFixed"); } } - _parent_scene.geom_name_map[prim_geom] = Name; - _parent_scene.actor_name_map[prim_geom] = this; - changeSelectedStatus(timestamp); if (childPrim) { -- cgit v1.1 From 7f499ff3f386d57bcd81ebb3f58f110011100604 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 10 Aug 2011 23:56:19 +0100 Subject: Add a OS_NPC_LAND_AT_TARGET option to osMoveToTarget() Default for this function is now not to automatically land. This allows better control by scripts when an avatar is going to be landing on a prim rather than the ground. Stopping the avatar involves faking a collision, to avoid the pid controller making it overshoot. A better approach would be to gradually slow the avatar as we near the target --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 4f461ad..ecf5983 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -305,10 +305,12 @@ namespace OpenSim.Region.Physics.OdePlugin { m_iscolliding = true; } + if (m_wascolliding != m_iscolliding) { //base.SendCollisionUpdate(new CollisionEventUpdate()); } + m_wascolliding = m_iscolliding; } } -- cgit v1.1 From 951ffad81e15a35bc9f847ea1448dd247a2e6e6f Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 11 Aug 2011 00:23:54 +0100 Subject: If SP.MoveToTarget has been called with a force walk, begin by landing the avatar. There is a bug here - once an avatar has landed it glides to its new position instead of performing a walk animation --- OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics/OdePlugin') diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index ecf5983..0a0d13f 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs @@ -258,7 +258,11 @@ namespace OpenSim.Region.Physics.OdePlugin public override bool Flying { get { return flying; } - set { flying = value; } + set + { + flying = value; +// m_log.DebugFormat("[PHYSICS]: Set OdeCharacter Flying to {0}", flying); + } } /// -- cgit v1.1