From 9d675232359a30c56d2b68d50fe15958374ec773 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 15 May 2012 15:45:01 +0100 Subject: ubitODE: if stopped having collisions do report zero colisions once, so collision_end event can be triggered. Changed reports rate to the requested rate and not full ode rate. --- OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | 46 +++++++++++++++++++----- OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | 6 +++- 2 files changed, 43 insertions(+), 9 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs index 87a7e51..5db4f17 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs @@ -194,8 +194,10 @@ namespace OpenSim.Region.Physics.OdePlugin public int givefakeori = 0; private Quaternion fakeori; - public int m_eventsubscription; - private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate(); + private int m_eventsubscription; + private int m_cureventsubscription; + private CollisionEventUpdate CollisionEventsThisFrame = null; + private bool SentEmptyCollisionsEvent; public volatile bool childPrim; @@ -931,12 +933,21 @@ namespace OpenSim.Region.Physics.OdePlugin public override void SubscribeEvents(int ms) { m_eventsubscription = ms; + m_cureventsubscription = 0; + if (CollisionEventsThisFrame == null) + CollisionEventsThisFrame = new CollisionEventUpdate(); + SentEmptyCollisionsEvent = false; _parent_scene.AddCollisionEventReporting(this); } public override void UnSubscribeEvents() { _parent_scene.RemoveCollisionEventReporting(this); + if (CollisionEventsThisFrame != null) + { + CollisionEventsThisFrame.Clear(); + CollisionEventsThisFrame = null; + } m_eventsubscription = 0; } @@ -944,7 +955,6 @@ namespace OpenSim.Region.Physics.OdePlugin { if (CollisionEventsThisFrame == null) CollisionEventsThisFrame = new CollisionEventUpdate(); - CollisionEventsThisFrame.AddCollider(CollidedWith, contact); } @@ -953,14 +963,34 @@ namespace OpenSim.Region.Physics.OdePlugin if (CollisionEventsThisFrame == null) return; - base.SendCollisionUpdate(CollisionEventsThisFrame); + if (m_cureventsubscription < m_eventsubscription) + return; - if (CollisionEventsThisFrame.m_objCollisionList.Count == 0) - CollisionEventsThisFrame = null; - else - CollisionEventsThisFrame = new CollisionEventUpdate(); + m_cureventsubscription = 0; + + int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count; + + if (!SentEmptyCollisionsEvent || ncolisions > 0) + { + base.SendCollisionUpdate(CollisionEventsThisFrame); + + if (ncolisions == 0) + SentEmptyCollisionsEvent = true; + else + { + SentEmptyCollisionsEvent = false; + CollisionEventsThisFrame.Clear(); + } + } } + internal void AddCollisionFrameTime(int t) + { + // protect it from overflow crashing + if (m_cureventsubscription + t >= int.MaxValue) + m_cureventsubscription = 0; + m_cureventsubscription += t; + } public override bool SubscribedEvents() { if (m_eventsubscription > 0) diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index dd912da..ddfdea4 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs @@ -1898,7 +1898,11 @@ namespace OpenSim.Region.Physics.OdePlugin case ActorTypes.Prim: OdePrim pobj = (OdePrim)obj; - pobj.SendCollisions(); + if (pobj.Body == IntPtr.Zero || (d.BodyIsEnabled(pobj.Body) && !pobj.m_outbounds)) + { + pobj.AddCollisionFrameTime((int)(ODE_STEPSIZE * 1000.0f)); + pobj.SendCollisions(); + } break; } } -- cgit v1.1