From 3ff5ad1ed3118525c31974f8ea9b3cf16861c783 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Mon, 4 Feb 2008 14:40:46 +0000 Subject: Patch from mikkopa/_someone Thanks! adds support for llPreloadSound, llTriggerSound, llPlaySound, llPreloadSound. * Time to make music boxes? --- OpenSim/Region/ClientStack/ClientView.cs | 14 ++++ .../Region/Examples/SimpleApp/MyNpcCharacter.cs | 6 +- .../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 96 +++++++++++++++++++++- 3 files changed, 111 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs index 167e4c3..e89b722 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 453320c..19bd6cd 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 76183ae..367a5f7 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 +} -- cgit v1.1