From 4c2523b1c2dd518cc21baf7674775fa2e11e1ca9 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 12 Jul 2012 20:05:00 +0100 Subject: Use faster any contact point collision detection for Volumedetect, plus some clean up --- OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | 123 +++++------------------ OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs | 2 + OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | 14 ++- 3 files changed, 41 insertions(+), 98 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs index ff17a6e..8d5f269 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs @@ -134,7 +134,7 @@ namespace OpenSim.Region.Physics.OdePlugin // private bool m_collidesLand = true; private bool m_collidesWater; - public bool m_returnCollisions; +// public bool m_returnCollisions; private bool m_NoColide; // for now only for internal use for bad meshs @@ -164,8 +164,8 @@ namespace OpenSim.Region.Physics.OdePlugin private List childrenPrim = new List(); - private bool m_throttleUpdates; - private int throttleCounter; +// private bool m_throttleUpdates; +// private int throttleCounter; public float m_collisionscore; int m_colliderfilter = 0; @@ -363,12 +363,14 @@ namespace OpenSim.Region.Physics.OdePlugin set { return; } } - public override bool ThrottleUpdates + + public override bool ThrottleUpdates {get;set;} +/* { get { return m_throttleUpdates; } set { m_throttleUpdates = value; } } - +*/ public override bool Stopped { get { return _zeroFlag; } @@ -951,7 +953,8 @@ namespace OpenSim.Region.Physics.OdePlugin { if (CollisionEventsThisFrame == null) CollisionEventsThisFrame = new CollisionEventUpdate(); - CollisionEventsThisFrame.AddCollider(CollidedWith, contact); +// if(CollisionEventsThisFrame.Count < 32) + CollisionEventsThisFrame.AddCollider(CollidedWith, contact); } public void SendCollisions() @@ -977,6 +980,10 @@ namespace OpenSim.Region.Physics.OdePlugin } else { + if (ncolisions > 10) + { + } + SentEmptyCollisionsEvent = false; CollisionEventsThisFrame.Clear(); } @@ -1746,8 +1753,7 @@ namespace OpenSim.Region.Physics.OdePlugin if (childrenPrim.Count == 0) { collide_geom = prim_geom; - m_targetSpace = _parent_scene.ActiveSpace; - d.SpaceAdd(m_targetSpace, prim_geom); + m_targetSpace = _parent_scene.ActiveSpace; } else { @@ -1755,7 +1761,6 @@ namespace OpenSim.Region.Physics.OdePlugin d.HashSpaceSetLevels(m_targetSpace, -2, 8); d.SpaceSetSublevel(m_targetSpace, 3); d.SpaceSetCleanup(m_targetSpace, false); - d.SpaceAdd(m_targetSpace, prim_geom); d.GeomSetCategoryBits(m_targetSpace, (uint)(CollisionCategories.Space | CollisionCategories.Geom | @@ -1766,12 +1771,21 @@ namespace OpenSim.Region.Physics.OdePlugin collide_geom = m_targetSpace; } + d.SpaceAdd(m_targetSpace, prim_geom); + if (m_delaySelect) { m_isSelected = true; m_delaySelect = false; } + m_collisionscore = 0; + + UpdateCollisionCatFlags(); + ApplyCollisionCatFlags(); + + _parent_scene.addActivePrim(this); + lock (childrenPrim) { foreach (OdePrim prm in childrenPrim) @@ -1809,10 +1823,6 @@ namespace OpenSim.Region.Physics.OdePlugin createAMotor(m_angularlock); } - m_collisionscore = 0; - - UpdateCollisionCatFlags(); - ApplyCollisionCatFlags(); if (m_isSelected || m_disabled) { @@ -1824,7 +1834,6 @@ namespace OpenSim.Region.Physics.OdePlugin d.BodySetLinearVel(Body, _velocity.X, _velocity.Y, _velocity.Z); } - _parent_scene.addActivePrim(this); _parent_scene.addActiveGroups(this); } @@ -3441,92 +3450,14 @@ namespace OpenSim.Region.Physics.OdePlugin if (++bodydisablecontrol < 20) return; - bodydisablecontrol = 0; + d.BodyEnable(Body); } - d.Vector3 lpos = d.GeomGetPosition(prim_geom); // root position that is seem by rest of simulator - -/* moved down to UpdateMove... where it belongs again - - // check outside region - - if (lpos.Z < -100 || lpos.Z > 100000f) - { - m_outbounds = true; - - lpos.Z = Util.Clip(lpos.Z, -100f, 100000f); - _acceleration.X = 0; - _acceleration.Y = 0; - _acceleration.Z = 0; - - _velocity.X = 0; - _velocity.Y = 0; - _velocity.Z = 0; - m_rotationalVelocity.X = 0; - m_rotationalVelocity.Y = 0; - m_rotationalVelocity.Z = 0; - - d.BodySetLinearVel(Body, 0, 0, 0); // stop it - d.BodySetAngularVel(Body, 0, 0, 0); // stop it - d.BodySetPosition(Body, lpos.X, lpos.Y, lpos.Z); // put it somewhere - m_lastposition = _position; - m_lastorientation = _orientation; - - base.RequestPhysicsterseUpdate(); - - throttleCounter = 0; - _zeroFlag = true; - - disableBodySoft(); // disable it and colisions - base.RaiseOutOfBounds(_position); - return; - } - - if (lpos.X < 0f) - { - _position.X = Util.Clip(lpos.X, -2f, -0.1f); - m_outbounds = true; - } - else if (lpos.X > _parent_scene.WorldExtents.X) - { - _position.X = Util.Clip(lpos.X, _parent_scene.WorldExtents.X + 0.1f, _parent_scene.WorldExtents.X + 2f); - m_outbounds = true; - } - if (lpos.Y < 0f) - { - _position.Y = Util.Clip(lpos.Y, -2f, -0.1f); - m_outbounds = true; - } - else if (lpos.Y > _parent_scene.WorldExtents.Y) - { - _position.Y = Util.Clip(lpos.Y, _parent_scene.WorldExtents.Y + 0.1f, _parent_scene.WorldExtents.Y + 2f); - m_outbounds = true; - } + bodydisablecontrol = 0; - if (m_outbounds) - { - m_lastposition = _position; - m_lastorientation = _orientation; - - d.Vector3 dtmp = d.BodyGetAngularVel(Body); - m_rotationalVelocity.X = dtmp.X; - m_rotationalVelocity.Y = dtmp.Y; - m_rotationalVelocity.Z = dtmp.Z; - - dtmp = d.BodyGetLinearVel(Body); - _velocity.X = dtmp.X; - _velocity.Y = dtmp.Y; - _velocity.Z = dtmp.Z; + d.Vector3 lpos = d.GeomGetPosition(prim_geom); // root position that is seem by rest of simulator - d.BodySetLinearVel(Body, 0, 0, 0); // stop it - d.BodySetAngularVel(Body, 0, 0, 0); - d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); - disableBodySoft(); // stop collisions - base.RequestPhysicsterseUpdate(); - return; - } -*/ if (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE) { // 'VEHICLES' are dealt with in ODEDynamics.cs @@ -3721,7 +3652,7 @@ namespace OpenSim.Region.Physics.OdePlugin base.RequestPhysicsterseUpdate(); - throttleCounter = 0; +// throttleCounter = 0; _zeroFlag = true; disableBodySoft(); // disable it and colisions diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs index 2341186..ee48db5 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeApi.cs @@ -61,6 +61,8 @@ namespace OdeAPI public static int NTotalBodies = 0; public static int NTotalGeoms = 0; + public const uint CONTACTS_UNIMPORTANT = 0x80000000; + #region Flags and Enumerations [Flags] diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index 7848b35..088d2ba 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs @@ -713,8 +713,18 @@ namespace OpenSim.Region.Physics.OdePlugin if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) return; - - count = d.CollidePtr(g1, g2, (contactsPerCollision & 0xffff), ContactgeomsArray, d.ContactGeom.unmanagedSizeOf); + if(d.GeomGetCategoryBits(g1) == (uint)CollisionCategories.VolumeDtc || + d.GeomGetCategoryBits(g1) == (uint)CollisionCategories.VolumeDtc) + { + int cflags; + unchecked + { + cflags = (int)(1 | d.CONTACTS_UNIMPORTANT); + } + count = d.CollidePtr(g1, g2, cflags, ContactgeomsArray, d.ContactGeom.unmanagedSizeOf); + } + else + count = d.CollidePtr(g1, g2, (contactsPerCollision & 0xffff), ContactgeomsArray, d.ContactGeom.unmanagedSizeOf); } catch (SEHException) { -- cgit v1.1 From 5cfea5934ba2aa19bc864c950c60a4c29f017316 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 13 Jul 2012 19:32:43 +0100 Subject: fix bad vehicle reference frame --- OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs index e900c02..a7dda7a 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs @@ -425,7 +425,8 @@ namespace OpenSim.Region.Physics.OdePlugin switch (pParam) { case Vehicle.REFERENCE_FRAME: - m_referenceFrame = Quaternion.Inverse(pValue); + // m_referenceFrame = Quaternion.Inverse(pValue); + m_referenceFrame = pValue; break; case Vehicle.ROLL_FRAME: m_RollreferenceFrame = pValue; -- cgit v1.1 From 72e2b9409462861d183ac7b391f5911defcd3bb0 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 13 Jul 2012 23:57:45 +0100 Subject: In collisions report linksets root parts to parts, and not all parts. Temporary suspend collision checks on full stopped bodies, until a better away is found wake them, avoiding spurius collision end and start events. Until a nice way is found to avoid them, this may cause some higher cpu load. plus some clean up --- .../Region/Physics/UbitOdePlugin/ODECharacter.cs | 3 +- OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | 39 ++++++++++----------- .../UbitOdePlugin/ODERayCastRequestManager.cs | 4 +-- OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | 40 +++++++++++++--------- 4 files changed, 45 insertions(+), 41 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs index 865180f..b506b1c 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs @@ -95,7 +95,7 @@ namespace OpenSim.Region.Physics.OdePlugin private bool m_iscollidingObj = false; private bool m_alwaysRun = false; private int m_requestedUpdateFrequency = 0; - public uint m_localID = 0; + private uint m_localID = 0; public bool m_returnCollisions = false; // taints and their non-tainted counterparts public bool m_isPhysical = false; // the current physical status @@ -214,6 +214,7 @@ namespace OpenSim.Region.Physics.OdePlugin public override uint LocalID { + get { return m_localID; } set { m_localID = value; } } diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs index 8d5f269..6d322e2 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs @@ -101,7 +101,6 @@ namespace OpenSim.Region.Physics.OdePlugin private float m_invTimeStep = 50.0f; private float m_timeStep = .02f; - private Vector3 m_PIDTarget; private float m_PIDTau; private bool m_usePID; @@ -119,7 +118,7 @@ namespace OpenSim.Region.Physics.OdePlugin private float m_buoyancy; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle. private int body_autodisable_frames = 5; - private int bodydisablecontrol = 0; + public int bodydisablecontrol = 0; // Default we're a Geometry @@ -144,7 +143,7 @@ namespace OpenSim.Region.Physics.OdePlugin public bool m_disabled; - public uint m_localID; + private uint m_localID; private IMesh m_mesh; private object m_meshlock = new object(); @@ -167,7 +166,7 @@ namespace OpenSim.Region.Physics.OdePlugin // private bool m_throttleUpdates; // private int throttleCounter; public float m_collisionscore; - int m_colliderfilter = 0; + private int m_colliderfilter = 0; public IntPtr collide_geom; // for objects: geom if single prim space it linkset @@ -235,7 +234,6 @@ namespace OpenSim.Region.Physics.OdePlugin } } - public override bool Phantom // this is not reliable for internal use { get { return m_fakeisphantom; } @@ -293,14 +291,18 @@ namespace OpenSim.Region.Physics.OdePlugin public override uint LocalID { + get { return m_localID; } + set { m_localID = value; } + } + + public OdePrim Parent + { get { - return m_localID; - } - set - { - //m_log.Info("[PHYSICS]: Setting TrackerID: " + value); - m_localID = value; + if (childPrim) + return (OdePrim)_parent; + else + return this; } } @@ -945,8 +947,7 @@ namespace OpenSim.Region.Physics.OdePlugin CollisionEventsThisFrame = null; } m_eventsubscription = 0; - // for now still done on odescene -// _parent_scene.RemoveCollisionEventReporting(this); + _parent_scene.RemoveCollisionEventReporting(this); } public void AddCollisionEvent(uint CollidedWith, ContactPoint contact) @@ -980,10 +981,6 @@ namespace OpenSim.Region.Physics.OdePlugin } else { - if (ncolisions > 10) - { - } - SentEmptyCollisionsEvent = false; CollisionEventsThisFrame.Clear(); } @@ -1832,8 +1829,7 @@ namespace OpenSim.Region.Physics.OdePlugin { d.BodySetAngularVel(Body, m_rotationalVelocity.X, m_rotationalVelocity.Y, m_rotationalVelocity.Z); d.BodySetLinearVel(Body, _velocity.X, _velocity.Y, _velocity.Z); - } - + } _parent_scene.addActiveGroups(this); } @@ -3700,6 +3696,8 @@ namespace OpenSim.Region.Physics.OdePlugin d.BodySetAngularVel(Body, 0, 0, 0); d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); disableBodySoft(); // stop collisions + UnSubscribeEvents(); + base.RequestPhysicsterseUpdate(); return; } @@ -3871,8 +3869,7 @@ namespace OpenSim.Region.Physics.OdePlugin m_vehicle = null; RemoveGeom(); m_targetSpace = IntPtr.Zero; - if (m_eventsubscription > 0) - UnSubscribeEvents(); + UnSubscribeEvents(); return true; case changes.Link: diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs index 5122ebf..3d108f8 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODERayCastRequestManager.cs @@ -509,14 +509,14 @@ namespace OpenSim.Region.Physics.OdePlugin if ((thisFlags & CurrentRayFilter) == 0) return; - ID = ((OdePrim)p2).m_localID; + ID = ((OdePrim)p2).LocalID; } else if (p2 is OdeCharacter) { if ((CurrentRayFilter & RayFilterFlags.agent) == 0) return; else - ID = ((OdeCharacter)p2).m_localID; + ID = ((OdeCharacter)p2).LocalID; } else //?? return; diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index 088d2ba..659180d 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs @@ -1171,6 +1171,8 @@ namespace OpenSim.Region.Physics.OdePlugin OdePrim cp1; OdeCharacter cc2; OdePrim cp2; + OdePrim cp1Parent; + OdePrim cp2Parent; uint obj2LocalID = 0; bool p1events = p1.SubscribedEvents(); @@ -1207,18 +1209,19 @@ namespace OpenSim.Region.Physics.OdePlugin { case ActorTypes.Agent: cc2 = (OdeCharacter)p2; - obj2LocalID = cc2.m_localID; + obj2LocalID = cc2.LocalID; if (p2events) - cc2.AddCollisionEvent(cc1.m_localID, contact); + cc2.AddCollisionEvent(cc1.LocalID, contact); break; case ActorTypes.Prim: if (p2 is OdePrim) { cp2 = (OdePrim)p2; - obj2LocalID = cp2.m_localID; if (p2events) - cp2.AddCollisionEvent(cc1.m_localID, contact); + cp2.AddCollisionEvent(cc1.LocalID, contact); + cp2 = cp2.Parent; + obj2LocalID = cp2.LocalID; } break; @@ -1240,17 +1243,16 @@ namespace OpenSim.Region.Physics.OdePlugin if (p1 is OdePrim) { cp1 = (OdePrim)p1; - - // obj1LocalID = cp2.m_localID; + cp1Parent = cp1.Parent; switch ((ActorTypes)p2.PhysicsActorType) { case ActorTypes.Agent: if (p2 is OdeCharacter) { cc2 = (OdeCharacter)p2; - obj2LocalID = cc2.m_localID; + obj2LocalID = cc2.LocalID; if (p2events) - cc2.AddCollisionEvent(cp1.m_localID, contact); + cc2.AddCollisionEvent(cp1Parent.LocalID, contact); } break; case ActorTypes.Prim: @@ -1258,9 +1260,10 @@ namespace OpenSim.Region.Physics.OdePlugin if (p2 is OdePrim) { cp2 = (OdePrim)p2; - obj2LocalID = cp2.m_localID; if (p2events) - cp2.AddCollisionEvent(cp1.m_localID, contact); + cp2.AddCollisionEvent(cp1Parent.LocalID, contact); + cp2 = cp2.Parent; + obj2LocalID = cp2.LocalID; } break; @@ -1286,7 +1289,7 @@ namespace OpenSim.Region.Physics.OdePlugin if (p2 is OdeCharacter) { cc2 = (OdeCharacter)p2; - obj2LocalID = cc2.m_localID; + obj2LocalID = cc2.LocalID; if (p2events) cc2.AddCollisionEvent(0, contact); } @@ -1295,7 +1298,7 @@ namespace OpenSim.Region.Physics.OdePlugin if (p2 is OdePrim) { cp2 = (OdePrim)p2; - obj2LocalID = cp2.m_localID; + obj2LocalID = cp2.LocalID; if (p2events) cp2.AddCollisionEvent(0, contact); } @@ -1350,8 +1353,11 @@ namespace OpenSim.Region.Physics.OdePlugin { foreach (OdePrim prm in _activegroups) { - if (d.BodyIsEnabled(prm.Body) && !prm.m_outbounds) - d.SpaceCollide2(StaticSpace, prm.collide_geom, IntPtr.Zero, nearCallback); + if (!prm.m_outbounds) + { +// if (d.BodyIsEnabled(prm.Body)) + d.SpaceCollide2(StaticSpace, prm.collide_geom, IntPtr.Zero, nearCallback); + } } } catch (AccessViolationException) @@ -1604,7 +1610,7 @@ namespace OpenSim.Region.Physics.OdePlugin //Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName); lock (prim) { - RemoveCollisionEventReporting(prim); +// RemoveCollisionEventReporting(prim); lock (_prims) _prims.Remove(prim); } @@ -2012,6 +2018,7 @@ namespace OpenSim.Region.Physics.OdePlugin case ActorTypes.Prim: OdePrim pobj = (OdePrim)obj; if (pobj.Body == IntPtr.Zero || (d.BodyIsEnabled(pobj.Body) && !pobj.m_outbounds)) + if (!pobj.m_outbounds) { pobj.AddCollisionFrameTime((int)(odetimestepMS)); pobj.SendCollisions(); @@ -2728,7 +2735,6 @@ namespace OpenSim.Region.Physics.OdePlugin WaterMapHandler.Free(); } - if (ContactgeomsArray != IntPtr.Zero) Marshal.FreeHGlobal(ContactgeomsArray); if (GlobalContactsArray != IntPtr.Zero) @@ -2751,7 +2757,7 @@ namespace OpenSim.Region.Physics.OdePlugin { if (prm.CollisionScore > 0) { - returncolliders.Add(prm.m_localID, prm.CollisionScore); + returncolliders.Add(prm.LocalID, prm.CollisionScore); cnt++; prm.CollisionScore = 0f; if (cnt > 25) -- cgit v1.1 From 95f2d8654989807c1bc4fe39cd8715210ac1a9ae Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 14 Jul 2012 09:13:27 +0200 Subject: Reinstate sleeping because less CPU is preferred over reporting accuracy. Who needs accurate collisions when the sim lags and crashes? --- OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index 659180d..2928257 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs @@ -1355,7 +1355,7 @@ namespace OpenSim.Region.Physics.OdePlugin { if (!prm.m_outbounds) { -// if (d.BodyIsEnabled(prm.Body)) + if (d.BodyIsEnabled(prm.Body)) d.SpaceCollide2(StaticSpace, prm.collide_geom, IntPtr.Zero, nearCallback); } } -- cgit v1.1