From 7b327848d0a74296e0180bb8d27544e6c5570215 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 4 Jul 2012 22:21:47 +0100 Subject: Use GetInventoryItem() in llRezAtRoot rather than iterating through a cloned dictionary --- .../Shared/Api/Implementation/LSL_Api.cs | 76 ++++++++++------------ 1 file changed, 36 insertions(+), 40 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index cf65abb..0a25454 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -2738,67 +2738,63 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); - Util.FireAndForget(delegate (object x) + Util.FireAndForget(x => { 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(); + TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory); - foreach (KeyValuePair inv in partInventory) + if (item == null) { - if (inv.Value.Name == inventory) - { - // 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; - } + llSay(0, "Could not find object " + inventory); + 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); + if (item.InvType != (int)InventoryType.Object) + { + llSay(0, "Unable to create requested object. Object is missing from database."); + return; + } - // need the magnitude later - // float velmag = (float)Util.GetMagnitude(llvel); + 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); - SceneObjectGroup new_group = World.RezObject(m_host, inv.Value, llpos, Rot2Quaternion(rot), llvel, param); + // need the magnitude later + // float velmag = (float)Util.GetMagnitude(llvel); - // If either of these are null, then there was an unknown error. - if (new_group == null) - continue; + SceneObjectGroup new_group = World.RezObject(m_host, item, llpos, Rot2Quaternion(rot), llvel, param); - // objects rezzed with this method are die_at_edge by default. - new_group.RootPart.SetDieAtEdge(true); + // If either of these are null, then there was an unknown error. + if (new_group == null) + return; - new_group.ResumeScripts(); + // objects rezzed with this method are die_at_edge by default. + new_group.RootPart.SetDieAtEdge(true); - m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams( - "object_rez", new Object[] { - new LSL_String( - new_group.RootPart.UUID.ToString()) }, - new DetectParams[0])); + new_group.ResumeScripts(); - float groupmass = new_group.GetMass(); + m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams( + "object_rez", new Object[] { + new LSL_String( + new_group.RootPart.UUID.ToString()) }, + new DetectParams[0])); - PhysicsActor pa = new_group.RootPart.PhysActor; + float groupmass = new_group.GetMass(); - if (pa != null && pa.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; - } - } + PhysicsActor pa = new_group.RootPart.PhysActor; - llSay(0, "Could not find object " + inventory); + if (pa != null && pa.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)); -- cgit v1.1