From 42a7a8506262f69155ee6393c601f3a427f1ef77 Mon Sep 17 00:00:00 2001 From: Melanie Date: Fri, 9 Mar 2012 00:57:49 +0000 Subject: [PATCH] FireAndForget scripted rez - port from Avination --- .../Shared/Api/Implementation/LSL_Api.cs | 107 +++++++++--------- 1 file changed, 56 insertions(+), 51 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 00035154d1..786ae6e6ff 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -2771,64 +2771,69 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); - if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s)) - return; - float dist = (float)llVecDist(llGetPos(), pos); - - if (dist > m_ScriptDistanceFactor * 10.0f) - return; - - TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); - - foreach (KeyValuePair inv in partInventory) + Util.FireAndForget(delegate (object x) { - if (inv.Value.Name == inventory) + if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s)) + return; + float dist = (float)llVecDist(llGetPos(), pos); + + if (dist > m_ScriptDistanceFactor * 10.0f) + return; + + //Clone is thread-safe + TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); + + foreach (KeyValuePair inv in partInventory) { - // make sure we're an object. - if (inv.Value.InvType != (int)InventoryType.Object) + if (inv.Value.Name == inventory) { - llSay(0, "Unable to create requested object. Object is missing from database."); + // make sure we're an object. + if (inv.Value.InvType != (int)InventoryType.Object) + { + llSay(0, "Unable to create requested object. Object is missing from database."); + return; + } + + Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z); + Vector3 llvel = new Vector3((float)vel.x, (float)vel.y, (float)vel.z); + + // need the magnitude later + // float velmag = (float)Util.GetMagnitude(llvel); + + SceneObjectGroup new_group = World.RezObject(m_host, inv.Value, llpos, Rot2Quaternion(rot), llvel, param); + + // If either of these are null, then there was an unknown error. + if (new_group == null) + continue; + + // objects rezzed with this method are die_at_edge by default. + new_group.RootPart.SetDieAtEdge(true); + + new_group.ResumeScripts(); + + m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams( + "object_rez", new Object[] { + new LSL_String( + new_group.RootPart.UUID.ToString()) }, + new DetectParams[0])); + + float groupmass = new_group.GetMass(); + + if (new_group.RootPart.PhysActor != null && new_group.RootPart.PhysActor.IsPhysical && llvel != Vector3.Zero) + { + //Recoil. + llApplyImpulse(new LSL_Vector(llvel.X * groupmass, llvel.Y * groupmass, llvel.Z * groupmass), 0); + } + // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) return; } - - Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z); - Vector3 llvel = new Vector3((float)vel.x, (float)vel.y, (float)vel.z); - - // need the magnitude later - float velmag = (float)Util.GetMagnitude(llvel); - - SceneObjectGroup new_group = World.RezObject(m_host, inv.Value, llpos, Rot2Quaternion(rot), llvel, param); - - // If either of these are null, then there was an unknown error. - if (new_group == null) - continue; - - // objects rezzed with this method are die_at_edge by default. - new_group.RootPart.SetDieAtEdge(true); - - new_group.ResumeScripts(); - - m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams( - "object_rez", new Object[] { - new LSL_String( - new_group.RootPart.UUID.ToString()) }, - new DetectParams[0])); - - float groupmass = new_group.GetMass(); - - if (new_group.RootPart.PhysActor != null && new_group.RootPart.PhysActor.IsPhysical && llvel != Vector3.Zero) - { - //Recoil. - llApplyImpulse(new LSL_Vector(llvel.X * groupmass, llvel.Y * groupmass, llvel.Z * groupmass), 0); - } - // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) - ScriptSleep((int)((groupmass * velmag) / 10)); - ScriptSleep(100); - return; } - } - llSay(0, "Could not find object " + inventory); + llSay(0, "Could not find object " + inventory); + }); + + //ScriptSleep((int)((groupmass * velmag) / 10)); + ScriptSleep(100); } public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)