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 --- OpenSim/Framework/IClientAPI.cs | 6 ++---- .../Region/ClientStack/LindenUDP/LLClientView.cs | 9 ++++----- .../Region/Environment/Interfaces/ISoundModule.cs | 4 +++- .../Environment/Modules/World/Sound/SoundModule.cs | 23 +++++++++++++++++++--- .../Region/Environment/Scenes/SceneObjectPart.cs | 20 +++++-------------- 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index e3163d7..f9071a5 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -406,9 +406,9 @@ namespace OpenSim.Framework public delegate void AcceptCallingCard(IClientAPI remoteClient, UUID transactionID, UUID folderID); public delegate void DeclineCallingCard(IClientAPI remoteClient, UUID transactionID); - - public delegate void SoundTrigger(UUID soundId,UUID ownerid,UUID objid, UUID parentid,float Gain, Vector3 Position,UInt64 Handle); + public delegate void SoundTrigger( + UUID soundId, UUID ownerid, UUID objid, UUID parentid, double Gain, Vector3 Position, UInt64 Handle); public delegate void StartLure(byte lureType, string message, UUID targetID, IClientAPI client); public delegate void TeleportLureRequest(UUID lureID, uint teleportFlags, IClientAPI client); @@ -723,8 +723,6 @@ namespace OpenSim.Framework event TeleportLureRequest OnTeleportLureRequest; event NetworkStats OnNetworkStatsUpdate; - // void ActivateGesture(UUID assetId, UUID gestureId); - /// /// Tell this client what items it should be wearing now /// diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 9d8ecf0..8922364 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -4597,6 +4597,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP agentRequestSit.TargetObject.TargetID, agentRequestSit.TargetObject.Offset); } break; + case PacketType.AgentSit: if (OnAgentSit != null) { @@ -4609,13 +4610,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP } } break; + case PacketType.SoundTrigger: - // TODO: handle this packet - // SM 200811 SoundTriggerPacket soundTriggerPacket = (SoundTriggerPacket)Pack; handlerSoundTrigger = OnSoundTrigger; if (handlerSoundTrigger != null) - //UUID ownerID, UUID objectID, UUID parentID { handlerSoundTrigger(soundTriggerPacket.SoundData.SoundID, soundTriggerPacket.SoundData.OwnerID, soundTriggerPacket.SoundData.ObjectID, soundTriggerPacket.SoundData.ParentID, @@ -4623,9 +4622,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP soundTriggerPacket.SoundData.Handle); } - else - m_log.Error("Null pointer for Soundtrigger"); break; + case PacketType.AvatarPickerRequest: AvatarPickerRequestPacket avRequestQuery = (AvatarPickerRequestPacket)Pack; AvatarPickerRequestPacket.AgentDataBlock Requestdata = avRequestQuery.AgentData; @@ -4639,6 +4637,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP Utils.BytesToString(querydata.Name)); } break; + case PacketType.AgentDataUpdateRequest: AgentDataUpdateRequestPacket avRequestDataUpdatePacket = (AgentDataUpdateRequestPacket)Pack; 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