From cce1b096dbd8aba46c405b7654d67d3ba96de33a Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Tue, 23 Dec 2008 17:54:13 +0000 Subject: * refactor: Replace part of SceneObjectPart with the identical sound playing code in the SoundModule --- .../Region/Environment/Interfaces/ISoundModule.cs | 4 +++- .../Environment/Modules/World/Sound/SoundModule.cs | 23 +++++++++++++++++++--- .../Region/Environment/Scenes/SceneObjectPart.cs | 20 +++++-------------- 3 files changed, 28 insertions(+), 19 deletions(-) (limited to 'OpenSim/Region/Environment') diff --git a/OpenSim/Region/Environment/Interfaces/ISoundModule.cs b/OpenSim/Region/Environment/Interfaces/ISoundModule.cs index 0ec5652..3bb4c57 100644 --- a/OpenSim/Region/Environment/Interfaces/ISoundModule.cs +++ b/OpenSim/Region/Environment/Interfaces/ISoundModule.cs @@ -33,7 +33,9 @@ namespace OpenSim.Region.Environment { public interface ISoundModule { + void PlayAttachedSound(UUID soundID, UUID ownerID, UUID objectID, double gain, Vector3 position, byte flags); + void TriggerSound( - UUID soundId, UUID ownerID, UUID objectID, UUID parentID, float gain, Vector3 position, UInt64 handle); + UUID soundId, UUID ownerID, UUID objectID, UUID parentID, double gain, Vector3 position, UInt64 handle); } } \ No newline at end of file diff --git a/OpenSim/Region/Environment/Modules/World/Sound/SoundModule.cs b/OpenSim/Region/Environment/Modules/World/Sound/SoundModule.cs index 7c89466..4547480 100644 --- a/OpenSim/Region/Environment/Modules/World/Sound/SoundModule.cs +++ b/OpenSim/Region/Environment/Modules/World/Sound/SoundModule.cs @@ -61,20 +61,37 @@ namespace OpenSim.Region.Environment.World.Sound client.OnSoundTrigger += TriggerSound; } + public virtual void PlayAttachedSound( + UUID soundID, UUID ownerID, UUID objectID, double gain, Vector3 position, byte flags) + { + foreach (ScenePresence p in m_scene.GetAvatars()) + { + double dis = Util.GetDistanceTo(p.AbsolutePosition, position); + if (dis > 100.0) // Max audio distance + continue; + + // Scale by distance + gain = (float)((double)gain*((100.0 - dis) / 100.0)); + + p.ControllingClient.SendPlayAttachedSound(soundID, objectID, ownerID, (float)gain, flags); + } + } + public virtual void TriggerSound( - UUID soundId, UUID ownerID, UUID objectID, UUID parentID, float gain, Vector3 position, UInt64 handle) + UUID soundId, UUID ownerID, UUID objectID, UUID parentID, double gain, Vector3 position, UInt64 handle) { foreach (ScenePresence p in m_scene.GetAvatars()) { double dis = Util.GetDistanceTo(p.AbsolutePosition, position); if (dis > 100.0) // Max audio distance continue; - + // Scale by distance gain = (float)((double)gain*((100.0 - dis) / 100.0)); + p.ControllingClient.SendTriggeredSound( soundId, ownerID, objectID, parentID, handle, position, (float)gain); } - } + } } } diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index ddfb413..6795c0a 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -37,6 +37,7 @@ using log4net; using OpenMetaverse; using OpenMetaverse.Packets; using OpenSim.Framework; +using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Scenes.Scripting; using OpenSim.Region.Physics.Manager; @@ -2362,24 +2363,13 @@ if (m_shape != null) { if (soundID == UUID.Zero) return; - List avatarts = m_parentGroup.Scene.GetAvatars(); - foreach (ScenePresence p in avatarts) + ISoundModule soundModule = m_parentGroup.Scene.RequestModuleInterface(); + if (soundModule != null) { - double dis=Util.GetDistanceTo(p.AbsolutePosition, position); - if (dis > 100.0) // Max audio distance - continue; - - // Scale by distance - volume*=((100.0-dis)/100.0); - if (triggered) - { - p.ControllingClient.SendTriggeredSound(soundID, ownerID, objectID, parentID, regionHandle, position, (float)volume); - } + soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle); else - { - p.ControllingClient.SendPlayAttachedSound(soundID, objectID, ownerID, (float)volume, flags); - } + soundModule.PlayAttachedSound(soundID, ownerID, objectID, volume, position, flags); } } -- cgit v1.1