refactor: Replace calls to InventorySelf() with existing m_itemID in LSL_Api

There's no point look up an item ID that we already have.
0.7.3-extended
Justin Clark-Casey (justincc) 2012-04-23 22:23:47 +01:00
parent 0c8b44d514
commit 6610cd2332
1 changed files with 42 additions and 94 deletions

View File

@ -85,7 +85,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
protected IScriptEngine m_ScriptEngine;
protected SceneObjectPart m_host;
protected uint m_localID;
/// <summary>
/// The UUID of the item that hosts this script
/// </summary>
protected UUID m_itemID;
protected bool throwErrorOnNotImplemented = true;
protected AsyncCommandManager AsyncCommands = null;
protected float m_ScriptDelayFactor = 1.0f;
@ -267,25 +272,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
protected UUID InventorySelf()
{
UUID invItemID = new UUID();
lock (m_host.TaskInventory)
{
foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
{
if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
{
invItemID = inv.Key;
break;
}
}
}
return invItemID;
}
protected UUID InventoryKey(string name, int type)
{
m_host.AddScriptLPS(1);
@ -2696,17 +2682,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Integer llGiveMoney(string destination, int amount)
{
UUID invItemID=InventorySelf();
if (invItemID == UUID.Zero)
return 0;
m_host.AddScriptLPS(1);
TaskInventoryItem item = m_host.TaskInventory[invItemID];
TaskInventoryItem item;
lock (m_host.TaskInventory)
{
item = m_host.TaskInventory[invItemID];
item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter == UUID.Zero)
@ -2930,10 +2912,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
lock (m_host.TaskInventory)
{
if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
item = m_host.TaskInventory[InventorySelf()];
item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter != UUID.Zero)
@ -2958,10 +2940,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
lock (m_host.TaskInventory)
{
if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
item = m_host.TaskInventory[InventorySelf()];
item = m_host.TaskInventory[m_itemID];
}
m_host.AddScriptLPS(1);
@ -3001,10 +2983,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
lock (m_host.TaskInventory)
{
if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
item = m_host.TaskInventory[InventorySelf()];
item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter != m_host.OwnerID)
@ -3033,10 +3015,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
lock (m_host.TaskInventory)
{
if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
item = m_host.TaskInventory[InventorySelf()];
item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter != m_host.OwnerID)
@ -3288,18 +3270,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
UUID invItemID = InventorySelf();
if (invItemID == UUID.Zero)
return;
TaskInventoryItem item;
lock (m_host.TaskInventory)
{
if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
item = m_host.TaskInventory[InventorySelf()];
item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter == UUID.Zero)
@ -3325,18 +3303,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
UUID invItemID=InventorySelf();
if (invItemID == UUID.Zero)
return;
TaskInventoryItem item;
lock (m_host.TaskInventory)
{
if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
item = m_host.TaskInventory[InventorySelf()];
item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter == UUID.Zero)
@ -3392,21 +3366,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void llRequestPermissions(string agent, int perm)
{
UUID agentID = new UUID();
UUID agentID;
if (!UUID.TryParse(agent, out agentID))
return;
UUID invItemID = InventorySelf();
if (invItemID == UUID.Zero)
return; // Not in a prim? How??
TaskInventoryItem item;
lock (m_host.TaskInventory)
{
item = m_host.TaskInventory[invItemID];
item = m_host.TaskInventory[m_itemID];
}
if (agentID == UUID.Zero || perm == 0) // Releasing permissions
@ -3441,8 +3410,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
lock (m_host.TaskInventory)
{
m_host.TaskInventory[invItemID].PermsGranter = agentID;
m_host.TaskInventory[invItemID].PermsMask = perm;
m_host.TaskInventory[m_itemID].PermsGranter = agentID;
m_host.TaskInventory[m_itemID].PermsMask = perm;
}
m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
@ -3465,8 +3434,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
lock (m_host.TaskInventory)
{
m_host.TaskInventory[invItemID].PermsGranter = agentID;
m_host.TaskInventory[invItemID].PermsMask = perm;
m_host.TaskInventory[m_itemID].PermsGranter = agentID;
m_host.TaskInventory[m_itemID].PermsMask = perm;
}
m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
@ -3490,8 +3459,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
lock (m_host.TaskInventory)
{
m_host.TaskInventory[invItemID].PermsGranter = agentID;
m_host.TaskInventory[invItemID].PermsMask = 0;
m_host.TaskInventory[m_itemID].PermsGranter = agentID;
m_host.TaskInventory[m_itemID].PermsMask = 0;
}
presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
@ -3499,7 +3468,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
presence.ControllingClient.SendScriptQuestion(
m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm);
m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_itemID, perm);
return;
}
@ -3516,20 +3485,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (taskID != m_host.UUID)
return;
UUID invItemID = InventorySelf();
if (invItemID == UUID.Zero)
return;
client.OnScriptAnswer-=handleScriptAnswer;
m_waitingForScriptAnswer=false;
client.OnScriptAnswer -= handleScriptAnswer;
m_waitingForScriptAnswer = false;
if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
llReleaseControls();
lock (m_host.TaskInventory)
{
m_host.TaskInventory[invItemID].PermsMask = answer;
m_host.TaskInventory[m_itemID].PermsMask = answer;
}
m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
@ -3602,7 +3566,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void llCreateLink(string target, int parent)
{
m_host.AddScriptLPS(1);
UUID invItemID = InventorySelf();
UUID targetID;
if (!UUID.TryParse(target, out targetID))
@ -3611,7 +3575,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
TaskInventoryItem item;
lock (m_host.TaskInventory)
{
item = m_host.TaskInventory[invItemID];
item = m_host.TaskInventory[m_itemID];
}
if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
@ -3663,11 +3627,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void llBreakLink(int linknum)
{
m_host.AddScriptLPS(1);
UUID invItemID = InventorySelf();
lock (m_host.TaskInventory)
{
if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
&& !m_automaticLinkPermission)
{
ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
@ -9672,17 +9635,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Vector llGetCameraPos()
{
m_host.AddScriptLPS(1);
UUID invItemID = InventorySelf();
if (invItemID == UUID.Zero)
return new LSL_Vector();
lock (m_host.TaskInventory)
{
if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
if (m_host.TaskInventory[m_itemID].PermsGranter == UUID.Zero)
return new LSL_Vector();
if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
{
ShoutError("No permissions to track the camera");
return new LSL_Vector();
@ -9701,16 +9660,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Rotation llGetCameraRot()
{
m_host.AddScriptLPS(1);
UUID invItemID = InventorySelf();
if (invItemID == UUID.Zero)
return new LSL_Rotation();
lock (m_host.TaskInventory)
{
if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
if (m_host.TaskInventory[m_itemID].PermsGranter == UUID.Zero)
return new LSL_Rotation();
if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
{
ShoutError("No permissions to track the camera");
return new LSL_Rotation();
@ -9888,10 +9844,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
// our key in the object we are in
UUID invItemID = InventorySelf();
if (invItemID == UUID.Zero) return;
// the object we are in
UUID objectID = m_host.ParentUUID;
if (objectID == UUID.Zero) return;
@ -9900,10 +9852,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
lock (m_host.TaskInventory)
{
// we need the permission first, to know which avatar we want to set the camera for
agentID = m_host.TaskInventory[invItemID].PermsGranter;
agentID = m_host.TaskInventory[m_itemID].PermsGranter;
if (agentID == UUID.Zero) return;
if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
}
ScenePresence presence = World.GetScenePresence(agentID);
@ -9944,10 +9896,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
// our key in the object we are in
UUID invItemID=InventorySelf();
if (invItemID == UUID.Zero) return;
// the object we are in
UUID objectID = m_host.ParentUUID;
if (objectID == UUID.Zero) return;
@ -9956,9 +9904,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
UUID agentID;
lock (m_host.TaskInventory)
{
agentID = m_host.TaskInventory[invItemID].PermsGranter;
agentID = m_host.TaskInventory[m_itemID].PermsGranter;
if (agentID == UUID.Zero) return;
if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
}
ScenePresence presence = World.GetScenePresence(agentID);