From 3ff5ad1ed3118525c31974f8ea9b3cf16861c783 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Mon, 4 Feb 2008 14:40:46 +0000 Subject: [PATCH] Patch from mikkopa/_someone Thanks! adds support for llPreloadSound, llTriggerSound, llPlaySound, llPreloadSound. * Time to make music boxes? --- OpenSim/Framework/IClientAPI.cs | 3 +- OpenSim/Region/ClientStack/ClientView.cs | 14 +++ .../Examples/SimpleApp/MyNpcCharacter.cs | 6 +- .../Common/LSL_BuiltIn_Commands.cs | 96 ++++++++++++++++++- prebuild.xml | 1 + 5 files changed, 114 insertions(+), 6 deletions(-) diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index 529614b4b0..2ef05ae820 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -605,6 +605,7 @@ namespace OpenSim.Framework void SendPreLoadSound(LLUUID objectID, LLUUID ownerID, LLUUID soundID); void SendPlayAttachedSound(LLUUID soundID, LLUUID objectID, LLUUID ownerID, float gain, byte flags); + void SendTriggeredSound(LLUUID soundID, LLUUID ownerID, LLUUID objectID, LLUUID parentID, ulong handle, LLVector3 position, float gain); void SendNameReply(LLUUID profileId, string firstname, string lastname); void SendAlertMessage(string message); @@ -636,4 +637,4 @@ namespace OpenSim.Framework void SendLogoutPacket(); } -} \ No newline at end of file +} diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs index 167e4c3093..e89b722951 100644 --- a/OpenSim/Region/ClientStack/ClientView.cs +++ b/OpenSim/Region/ClientStack/ClientView.cs @@ -1349,6 +1349,20 @@ namespace OpenSim.Region.ClientStack OutPacket(sound, ThrottleOutPacketType.Task); } + public void SendTriggeredSound(LLUUID soundID, LLUUID ownerID, LLUUID objectID, LLUUID parentID, ulong handle, LLVector3 position, float gain) + { + SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger); + sound.SoundData.SoundID = soundID; + sound.SoundData.OwnerID = ownerID; + sound.SoundData.ObjectID = objectID; + sound.SoundData.ParentID = parentID; + sound.SoundData.Handle = handle; + sound.SoundData.Position = position; + sound.SoundData.Gain = gain; + + OutPacket(sound, ThrottleOutPacketType.Task); + } + public void SendSunPos(LLVector3 sunPos, LLVector3 sunVel) { SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage); diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs index 453320c9df..19bd6cdeb2 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs @@ -392,6 +392,10 @@ namespace SimpleApp { } + public void SendTriggeredSound(LLUUID soundID, LLUUID ownerID, LLUUID objectID, LLUUID parentID, ulong handle, LLVector3 position, float gain) + { + } + public void SendAlertMessage(string message) { } @@ -519,4 +523,4 @@ namespace SimpleApp { } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index 76183ae3bc..367a5f74ce 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -34,6 +34,7 @@ using System.Threading; using Axiom.Math; using libsecondlife; using OpenSim.Framework; +using OpenSim.Framework.Communications; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Scenes; using OpenSim.Region.ScriptEngine.Common; @@ -898,12 +899,44 @@ namespace OpenSim.Region.ScriptEngine.Common public void llSound() { + // This function has been deprecated + // see http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSound NotImplemented("llSound"); } public void llPlaySound(string sound, double volume) { - NotImplemented("llPlaySound"); + if (volume > 1) + volume = 1; + if (volume < 0) + volume = 0; + + LLUUID ownerID = m_host.OwnerID; + LLUUID objectID = m_host.UUID; + LLUUID soundID = LLUUID.Zero; + byte flags = 0; + + if (!LLUUID.TryParse(sound, out soundID)) + { + //Trys to fetch sound id from prim's inventory. + //Prim's inventory doesn't support non script items yet + SceneObjectPart op = World.GetSceneObjectPart(objectID); + foreach (KeyValuePair item in op.TaskInventory) + { + if (item.Value.Name == sound) + { + soundID = item.Value.ItemID; + break; + } + } + } + + List avatarts = World.GetAvatars(); + foreach (ScenePresence p in avatarts) + { + // TODO: some filtering by distance of avatar + p.ControllingClient.SendPlayAttachedSound(soundID, objectID, ownerID, (float)volume, flags); + } } public void llLoopSound(string sound, double volume) @@ -928,7 +961,38 @@ namespace OpenSim.Region.ScriptEngine.Common public void llTriggerSound(string sound, double volume) { - NotImplemented("llTriggerSound"); + if (volume > 1) + volume = 1; + if (volume < 0) + volume = 0; + + LLUUID ownerID = m_host.OwnerID; + LLUUID objectID = m_host.UUID; + LLUUID parentID = this.m_host.GetRootPartUUID(); + LLUUID soundID = LLUUID.Zero; + LLVector3 position = this.m_host.AbsolutePosition; // region local + ulong regionHandle = World.RegionInfo.RegionHandle; + + if (!LLUUID.TryParse(sound, out soundID)) + { + // search sound file from inventory + SceneObjectPart op = World.GetSceneObjectPart(objectID); + foreach (KeyValuePair item in op.TaskInventory) + { + if (item.Value.Name == sound) + { + soundID = item.Value.ItemID; + break; + } + } + } + + List avatarts = World.GetAvatars(); + foreach (ScenePresence p in avatarts) + { + // TODO: some filtering by distance of avatar + p.ControllingClient.SendTriggeredSound(soundID, ownerID, objectID, parentID, regionHandle, position, (float)volume); + } } public void llStopSound() @@ -938,7 +1002,31 @@ namespace OpenSim.Region.ScriptEngine.Common public void llPreloadSound(string sound) { - NotImplemented("llPreloadSound"); + LLUUID ownerID = m_host.OwnerID; + LLUUID objectID = m_host.UUID; + LLUUID soundID = LLUUID.Zero; + + if (!LLUUID.TryParse(sound, out soundID)) + { + //Trys to fetch sound id from prim's inventory. + //Prim's inventory doesn't support non script items yet + SceneObjectPart op = World.GetSceneObjectPart(objectID); + foreach (KeyValuePair item in op.TaskInventory) + { + if (item.Value.Name == sound) + { + soundID = item.Value.ItemID; + break; + } + } + } + + List avatarts = World.GetAvatars(); + foreach (ScenePresence p in avatarts) + { + // TODO: some filtering by distance of avatar + p.ControllingClient.SendPreLoadSound(objectID, objectID, soundID); + } } public string llGetSubString(string src, int start, int end) @@ -3241,4 +3329,4 @@ namespace OpenSim.Region.ScriptEngine.Common throw new Exception("LSL Runtime Error: " + msg); } } -} \ No newline at end of file +} diff --git a/prebuild.xml b/prebuild.xml index 0517d8ab9c..11a98f63e9 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1171,6 +1171,7 @@ +