From 89ffa80883f78c95eee6724127c281ec2bf91ba0 Mon Sep 17 00:00:00 2001 From: Latif Khalifa Date: Thu, 11 Jun 2015 00:02:57 +0200 Subject: [PATCH] Merge req #3 --- OpenMetaverse/ObjectManager.cs | 51 ++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/OpenMetaverse/ObjectManager.cs b/OpenMetaverse/ObjectManager.cs index e407cec8..a76b8030 100644 --- a/OpenMetaverse/ObjectManager.cs +++ b/OpenMetaverse/ObjectManager.cs @@ -266,6 +266,7 @@ namespace OpenMetaverse #region AvatarUpdate event /// The event subscribers, null of no subscribers private EventHandler m_AvatarUpdate; + private EventHandler m_ParticleUpdate; ///Raises the AvatarUpdate Event /// A AvatarUpdateEventArgs object containing @@ -276,10 +277,22 @@ namespace OpenMetaverse if (handler != null) handler(this, e); } + /// + /// Raises the ParticleUpdate Event + /// + /// A ParticleUpdateEventArgs object containing + /// the data sent from the simulator + protected virtual void OnParticleUpdate(ParticleUpdateEventArgs e) { + EventHandler handler = m_ParticleUpdate; + if (handler != null) + handler(this, e); + } /// Thread sync lock object private readonly object m_AvatarUpdateLock = new object(); + private readonly object m_ParticleUpdateLock = new object(); + /// Raised when the simulator sends us data containing /// updated information for an public event EventHandler AvatarUpdate @@ -290,6 +303,11 @@ namespace OpenMetaverse #endregion AvatarUpdate event #region TerseObjectUpdate event + public event EventHandler ParticleUpdate { + add { lock (m_ParticleUpdateLock) { m_ParticleUpdate += value; } } + remove { lock (m_ParticleUpdateLock) { m_ParticleUpdate -= value; } } + } + /// The event subscribers, null of no subscribers private EventHandler m_TerseObjectUpdate; @@ -2097,13 +2115,17 @@ namespace OpenMetaverse prim.Rotation = objectupdate.Rotation; prim.AngularVelocity = objectupdate.AngularVelocity; #endregion - + EventHandler handler = m_ObjectUpdate; if (handler != null) { WorkPool.QueueUserWorkItem(delegate(object o) { handler(this, new PrimEventArgs(simulator, prim, update.RegionData.TimeDilation, isNewObject, attachment)); }); } + //OnParticleUpdate handler replacing decode particles, PCode.Particle system appears to be deprecated this is a fix + if (prim.ParticleSys.PartMaxAge != 0) { + OnParticleUpdate(new ParticleUpdateEventArgs(simulator, prim.ParticleSys, prim)); + } break; #endregion Prim and Foliage @@ -2177,7 +2199,6 @@ namespace OpenMetaverse #endregion Avatar case PCode.ParticleSystem: DecodeParticleUpdate(block); - // TODO: Create a callback for particle updates break; default: Logger.DebugLog("Got an ObjectUpdate block with an unrecognized PCode " + pcode.ToString(), Client); @@ -2189,7 +2210,6 @@ namespace OpenMetaverse protected void DecodeParticleUpdate(ObjectUpdatePacket.ObjectDataBlock block) { // TODO: Handle ParticleSystem ObjectUpdate blocks - // float bounce_b // Vector4 scale_range // Vector4 alpha_range @@ -3460,6 +3480,31 @@ namespace OpenMetaverse } } + public class ParticleUpdateEventArgs : EventArgs { + private readonly Simulator m_Simulator; + private readonly Primitive.ParticleSystem m_ParticleSystem; + private readonly Primitive m_Source; + + /// Get the simulator the object originated from + public Simulator Simulator { get { return m_Simulator; } } + /// Get the data + public Primitive.ParticleSystem ParticleSystem { get { return m_ParticleSystem; } } + /// Get source + public Primitive Source { get { return m_Source; } } + + /// + /// Construct a new instance of the ParticleUpdateEventArgs class + /// + /// The simulator the packet originated from + /// The ParticleSystem data + /// The Primitive source + public ParticleUpdateEventArgs(Simulator simulator, Primitive.ParticleSystem particlesystem, Primitive source) { + this.m_Simulator = simulator; + this.m_ParticleSystem = particlesystem; + this.m_Source = source; + } + } + /// Provides additional primitive data for the event /// The event occurs when the simulator sends /// an containing additional details for a Primitive, Foliage data or Attachment data