OSDN Git Service

Attached sound finds correct root prim. It's complicated
authorLatif Khalifa <latifer@streamgrid.net>
Thu, 3 Jun 2010 06:33:20 +0000 (06:33 +0000)
committerLatif Khalifa <latifer@streamgrid.net>
Thu, 3 Jun 2010 06:33:20 +0000 (06:33 +0000)
since tha worst case we have this hierarchy:

attachment non root prim -> attachment root prim ->
   avatar -> avatar seat

git-svn-id: https://radegast.googlecode.com/svn/trunk@673 f7a694da-4d33-11de-9ad6-1127a62b9fcd

Radegast/Core/Media/BufferSound.cs
Radegast/Core/Media/MediaManager.cs

index 088fe56..fca9e9b 100644 (file)
@@ -157,9 +157,6 @@ namespace Radegast.Media
         public BufferSound(UUID soundId)\r
             : base()\r
         {\r
-            lock (allBuffers)\r
-                allBuffers[soundId] = this;\r
-\r
             prefetchOnly = true;\r
             ContainerId = UUID.Zero;\r
             Id = soundId;\r
@@ -189,8 +186,6 @@ namespace Radegast.Media
                 // If this was a Prefetch, just stop here.\r
                 if (prefetchOnly)\r
                 {\r
-                    lock (allBuffers)\r
-                        allBuffers.Remove(Id);\r
                     return;\r
                 }\r
 \r
@@ -306,10 +301,13 @@ namespace Radegast.Media
                 // Release the buffer to avoid a big memory leak.\r
                 if (channel != null)\r
                 {\r
+                    lock(allChannels)\r
+                        allChannels.Remove(channel.getRaw());\r
                     chanStr = channel.getRaw().ToString("X");\r
                     channel.stop();\r
                     channel = null;\r
                 }\r
+\r
                 if (sound != null)\r
                 {\r
                     soundStr = sound.getRaw().ToString("X");\r
index f5e7bf8..0964e16 100644 (file)
@@ -353,31 +353,47 @@ namespace Radegast.Media
         /// <param name="e"></param>
         private void Sound_AttachedSound(object sender, AttachedSoundEventArgs e)
         {
-            // We seem to get a lot of these zero sounds.
-            if (e.SoundID == UUID.Zero) return;
+            // This event tells us the Object ID, but not the Prim info directly.
+            // So we look it up in our internal Object memory.
+            Simulator sim = e.Simulator;
+            Primitive p = sim.ObjectsPrimitives.Find((Primitive p2) => { return p2.ID == e.ObjectID; });
+            if (p == null) return;
+
+            // Only one attached sound per prim, so we kill any previous
+            BufferSound.Kill(p.ID);
 
+            // If this is stop sound, we're done since we've already killed sound for this object
             if ((e.Flags & SoundFlags.Stop) == SoundFlags.Stop)
             {
-                BufferSound.Kill(e.SoundID);
                 return;
             }
 
-            // This event tells us the Object ID, but not the Prim info directly.
-            // So we look it up in our internal Object memory.
-            Simulator sim = Instance.Client.Network.CurrentSim;
-            Primitive p = sim.ObjectsPrimitives.Find((Primitive p2) => { return p2.ID == e.ObjectID; });
-            if (p==null) return;
+            // We seem to get a lot of these zero sounds.
+            if (e.SoundID == UUID.Zero) return;
 
             // If this is a child prim, its position is relative to the root.
             Vector3 fullPosition = p.Position;
-            if (p.ParentID != 0)
+
+            while (p != null && p.ParentID != 0)
             {
-                Primitive parentP;
-                sim.ObjectsPrimitives.TryGetValue(p.ParentID, out parentP);
-                if (parentP == null) return;
-                fullPosition += parentP.Position;
+                Avatar av;
+                if (sim.ObjectsAvatars.TryGetValue(p.ParentID, out av))
+                {
+                    p = av;
+                    fullPosition += p.Position;
+                }
+                else
+                {
+                    if (sim.ObjectsPrimitives.TryGetValue(p.ParentID, out p))
+                    {
+                        fullPosition += p.Position;
+                    }
+                }
             }
 
+            // Didn't find root prim
+            if (p == null) return;
+
             new BufferSound(
                 e.ObjectID,
                 e.SoundID,
@@ -429,7 +445,7 @@ namespace Radegast.Media
             if (p.Sound == null) return;
             if (p.Sound == UUID.Zero) return;
 
-            BufferSound.Kill(p.Sound);
+            BufferSound.Kill(p.ID);
         }
 
         /// <summary>