From 5abcecc7356bf58c479a7cff86581131a6ab3c9e Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Tue, 16 Oct 2012 12:24:33 +0100 Subject: moving SendSound from SceneObjectPart to ISoundModule --- .../World/Sound/SoundModuleNonShared.cs | 73 ++++++++++++++++++ .../Region/Framework/Interfaces/ISoundModule.cs | 15 ++++ OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 88 +++------------------- .../Scripting/Minimodule/SOPObject.cs | 7 +- .../Shared/Api/Implementation/LSL_Api.cs | 22 ++++-- 5 files changed, 119 insertions(+), 86 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Sound/SoundModuleNonShared.cs b/OpenSim/Region/CoreModules/World/Sound/SoundModuleNonShared.cs index 6f61c32..37863ee 100644 --- a/OpenSim/Region/CoreModules/World/Sound/SoundModuleNonShared.cs +++ b/OpenSim/Region/CoreModules/World/Sound/SoundModuleNonShared.cs @@ -278,6 +278,79 @@ namespace OpenSim.Region.CoreModules.World.Sound m_host.SendFullUpdateToAllClients(); } + public void SendSound(UUID objectID, string sound, double volume, + bool triggered, byte flags, float radius, bool useMaster, + bool isMaster) + { + SceneObjectPart part; + if (!m_scene.TryGetSceneObjectPart(objectID, out part)) + return; + + volume = Util.Clip((float)volume, 0, 1); + + UUID parentID = part.ParentGroup.UUID; + + UUID soundID = UUID.Zero; + Vector3 position = part.AbsolutePosition; // region local + ulong regionHandle = m_scene.RegionInfo.RegionHandle; + + if (!UUID.TryParse(sound, out soundID)) + { + // search sound file from inventory + lock (part.TaskInventory) + { + foreach (KeyValuePair item in part.TaskInventory) + { + if (item.Value.Type == (int)AssetType.Sound && item.Value.Name == sound) + { + soundID = item.Value.ItemID; + break; + } + } + } + } + + if (soundID == UUID.Zero) + return; + + if (useMaster) + { + if (isMaster) + { + if (triggered) + TriggerSound(soundID, part.OwnerID, part.UUID, parentID, volume, position, regionHandle, radius); + else + PlayAttachedSound(soundID, part.OwnerID, part.UUID, volume, position, flags, radius); + part.ParentGroup.PlaySoundMasterPrim = part; + if (triggered) + TriggerSound(soundID, part.OwnerID, part.UUID, parentID, volume, position, regionHandle, radius); + else + PlayAttachedSound(soundID, part.OwnerID, part.UUID, volume, position, flags, radius); + foreach (SceneObjectPart prim in part.ParentGroup.PlaySoundSlavePrims) + { + position = prim.AbsolutePosition; // region local + if (triggered) + TriggerSound(soundID, part.OwnerID, prim.UUID, parentID, volume, position, regionHandle, radius); + else + PlayAttachedSound(soundID, part.OwnerID, prim.UUID, volume, position, flags, radius); + } + part.ParentGroup.PlaySoundSlavePrims.Clear(); + part.ParentGroup.PlaySoundMasterPrim = null; + } + else + { + part.ParentGroup.PlaySoundSlavePrims.Add(part); + } + } + else + { + if (triggered) + TriggerSound(soundID, part.OwnerID, part.UUID, parentID, volume, position, regionHandle, radius); + else + PlayAttachedSound(soundID, part.OwnerID, part.UUID, volume, position, flags, radius); + } + } + #endregion } } diff --git a/OpenSim/Region/Framework/Interfaces/ISoundModule.cs b/OpenSim/Region/Framework/Interfaces/ISoundModule.cs index e514a59..c5edcb0 100644 --- a/OpenSim/Region/Framework/Interfaces/ISoundModule.cs +++ b/OpenSim/Region/Framework/Interfaces/ISoundModule.cs @@ -96,5 +96,20 @@ namespace OpenSim.Region.Framework.Interfaces /// Set object to sync master if true void LoopSound(UUID objectID, UUID soundID, double gain, double radius, bool isMaster); + + /// + /// Trigger or play an attached sound in this part's inventory. + /// + /// + /// + /// + /// + /// + /// + /// + /// + void SendSound(UUID objectID, string sound, double volume, + bool triggered, byte flags, float radius, bool useMaster, + bool isMaster); } } \ No newline at end of file diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 5da4207..cbb92b2 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -2239,7 +2239,15 @@ namespace OpenSim.Region.Framework.Scenes // play the sound. if (startedColliders.Count > 0 && CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f) - SendSound(CollisionSound.ToString(), CollisionSoundVolume, true, (byte)0, 0, false, false); + { + ISoundModule soundModule = ParentGroup.Scene.RequestModuleInterface(); + if (soundModule != null) + { + soundModule.SendSound(UUID, CollisionSound.ToString(), + CollisionSoundVolume, true, (byte)0, 0, false, + false); + } + } SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart); SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding); @@ -2645,84 +2653,6 @@ namespace OpenSim.Region.Framework.Scenes } /// - /// Trigger or play an attached sound in this part's inventory. - /// - /// - /// - /// - /// - public void SendSound(string sound, double volume, bool triggered, byte flags, float radius, bool useMaster, bool isMaster) - { - ISoundModule soundModule = ParentGroup.Scene.RequestModuleInterface(); - if(soundModule == null) - return; - - volume = Util.Clip((float)volume, 0, 1); - - UUID parentID = ParentGroup.UUID; - - UUID soundID = UUID.Zero; - Vector3 position = AbsolutePosition; // region local - ulong regionHandle = ParentGroup.Scene.RegionInfo.RegionHandle; - - if (!UUID.TryParse(sound, out soundID)) - { - // search sound file from inventory - lock (TaskInventory) - { - foreach (KeyValuePair item in TaskInventory) - { - if (item.Value.Type == (int)AssetType.Sound && item.Value.Name == sound) - { - soundID = item.Value.ItemID; - break; - } - } - } - } - - if (soundID == UUID.Zero) - return; - - if (useMaster) - { - if (isMaster) - { - if (triggered) - soundModule.TriggerSound(soundID, OwnerID, UUID, parentID, volume, position, regionHandle, radius); - else - soundModule.PlayAttachedSound(soundID, OwnerID, UUID, volume, position, flags, radius); - ParentGroup.PlaySoundMasterPrim = this; - if (triggered) - soundModule.TriggerSound(soundID, OwnerID, UUID, parentID, volume, position, regionHandle, radius); - else - soundModule.PlayAttachedSound(soundID, OwnerID, UUID, volume, position, flags, radius); - foreach (SceneObjectPart prim in ParentGroup.PlaySoundSlavePrims) - { - position = prim.AbsolutePosition; // region local - if (triggered) - soundModule.TriggerSound(soundID, OwnerID, prim.UUID, parentID, volume, position, regionHandle, radius); - else - soundModule.PlayAttachedSound(soundID, OwnerID, prim.UUID, volume, position, flags, radius); - } - ParentGroup.PlaySoundSlavePrims.Clear(); - ParentGroup.PlaySoundMasterPrim = null; - } - else - { - ParentGroup.PlaySoundSlavePrims.Add(this); - } - } - else - { - if (triggered) - soundModule.TriggerSound(soundID, OwnerID, UUID, parentID, volume, position, regionHandle, radius); - else - soundModule.PlayAttachedSound(soundID, OwnerID, UUID, volume, position, flags, radius); - } - } - - /// /// Send a terse update to all clients /// public void SendTerseUpdateToAllClients() diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs index aa23fee..9e438e2 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs @@ -821,8 +821,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { if (!CanEdit()) return; - - GetSOP().SendSound(asset.ToString(), volume, true, 0, 0, false, false); + ISoundModule module = m_rootScene.RequestModuleInterface(); + if (module != null) + { + module.SendSound(GetSOP().UUID, asset.ToString(), volume, true, 0, 0, false, false); + } } #endregion diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index c479944..f29be92 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -2367,7 +2367,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); // send the sound, once, to all clients in range - m_host.SendSound(KeyOrName(sound).ToString(), volume, false, 0, 0, false, false); + if (m_SoundModule != null) + { + m_SoundModule.SendSound(m_host.UUID, KeyOrName(sound).ToString(), volume, false, 0, 0, false, false); + } } public void llLoopSound(string sound, double volume) @@ -2404,14 +2407,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); // send the sound, once, to all clients in range - m_host.SendSound(KeyOrName(sound).ToString(), volume, false, 0, 0, true, false); + if (m_SoundModule != null) + { + m_SoundModule.SendSound(m_host.UUID, KeyOrName(sound).ToString(), volume, false, 0, 0, true, false); + } } public void llTriggerSound(string sound, double volume) { m_host.AddScriptLPS(1); - // send the sound, once, to all clients in range - m_host.SendSound(KeyOrName(sound).ToString(), volume, true, 0, 0, false, false); + // send the sound, once, to all clients in rangeTrigger or play an attached sound in this part's inventory. + if (m_SoundModule != null) + { + m_SoundModule.SendSound(m_host.UUID, KeyOrName(sound).ToString(), volume, true, 0, 0, false, false); + } } public void llStopSound() @@ -5824,10 +5833,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api LSL_Vector bottom_south_west) { m_host.AddScriptLPS(1); + if (m_SoundModule != null) + { float radius1 = (float)llVecDist(llGetPos(), top_north_east); float radius2 = (float)llVecDist(llGetPos(), bottom_south_west); float radius = Math.Abs(radius1 - radius2); - m_host.SendSound(KeyOrName(sound).ToString(), volume, true, 0, radius, false, false); + m_SoundModule.SendSound(m_host.UUID, KeyOrName(sound).ToString(), volume, true, 0, radius, false, false); + } } public void llEjectFromLand(string pest) -- cgit v1.1