refactor: Simplify ScriptInstance by retaining reference to SceneObjectPart instead of sometimes but not always looking it up.
parent
660d36a5b0
commit
7978b349bd
|
@ -157,19 +157,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
|
||||
public UUID AppDomain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Scene part in which this script instance is contained.
|
||||
/// </summary>
|
||||
public SceneObjectPart Part { get; private set; }
|
||||
|
||||
public string PrimName { get; private set; }
|
||||
|
||||
public string ScriptName { get; private set; }
|
||||
|
||||
public UUID ItemID { get; private set; }
|
||||
|
||||
public UUID ObjectID { get; private set; }
|
||||
public UUID ObjectID { get { return Part.UUID; } }
|
||||
|
||||
public uint LocalID { get; private set; }
|
||||
public uint LocalID { get { return Part.LocalId; } }
|
||||
|
||||
public UUID RootObjectID { get; private set; }
|
||||
public UUID RootObjectID { get { return Part.ParentGroup.UUID; } }
|
||||
|
||||
public uint RootLocalID { get; private set; }
|
||||
public uint RootLocalID { get { return Part.ParentGroup.LocalId; } }
|
||||
|
||||
public UUID AssetID { get; private set; }
|
||||
|
||||
|
@ -214,10 +219,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
EventQueue = new Queue(32);
|
||||
|
||||
Engine = engine;
|
||||
LocalID = part.LocalId;
|
||||
ObjectID = part.UUID;
|
||||
RootLocalID = part.ParentGroup.LocalId;
|
||||
RootObjectID = part.ParentGroup.UUID;
|
||||
Part = part;
|
||||
ItemID = itemID;
|
||||
AssetID = assetID;
|
||||
PrimName = primName;
|
||||
|
@ -227,17 +229,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
m_MaxScriptQueue = maxScriptQueue;
|
||||
m_stateSource = stateSource;
|
||||
m_postOnRez = postOnRez;
|
||||
m_AttachedAvatar = part.ParentGroup.AttachedAvatar;
|
||||
m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
|
||||
m_AttachedAvatar = Part.ParentGroup.AttachedAvatar;
|
||||
m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID;
|
||||
|
||||
if (part != null)
|
||||
lock (Part.TaskInventory)
|
||||
{
|
||||
lock (part.TaskInventory)
|
||||
if (Part.TaskInventory.ContainsKey(ItemID))
|
||||
{
|
||||
if (part.TaskInventory.ContainsKey(ItemID))
|
||||
{
|
||||
ScriptTask = part.TaskInventory[ItemID];
|
||||
}
|
||||
ScriptTask = Part.TaskInventory[ItemID];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,7 +321,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
|
||||
// m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", PrimName, m_ScriptName);
|
||||
|
||||
part.SetScriptEvents(ItemID,
|
||||
Part.SetScriptEvents(ItemID,
|
||||
(int)m_Script.GetStateEventFlags(State));
|
||||
|
||||
if (!Running)
|
||||
|
@ -418,33 +417,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
PostEvent(new EventParams("attach",
|
||||
new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0]));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void ReleaseControls()
|
||||
{
|
||||
SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
|
||||
|
||||
if (part != null)
|
||||
int permsMask;
|
||||
UUID permsGranter;
|
||||
lock (Part.TaskInventory)
|
||||
{
|
||||
int permsMask;
|
||||
UUID permsGranter;
|
||||
lock (part.TaskInventory)
|
||||
{
|
||||
if (!part.TaskInventory.ContainsKey(ItemID))
|
||||
return;
|
||||
if (!Part.TaskInventory.ContainsKey(ItemID))
|
||||
return;
|
||||
|
||||
permsGranter = part.TaskInventory[ItemID].PermsGranter;
|
||||
permsMask = part.TaskInventory[ItemID].PermsMask;
|
||||
}
|
||||
permsGranter = Part.TaskInventory[ItemID].PermsGranter;
|
||||
permsMask = Part.TaskInventory[ItemID].PermsMask;
|
||||
}
|
||||
|
||||
if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
|
||||
{
|
||||
ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
|
||||
if (presence != null)
|
||||
presence.UnRegisterControlEventsToScript(LocalID, ItemID);
|
||||
}
|
||||
if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
|
||||
{
|
||||
ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
|
||||
if (presence != null)
|
||||
presence.UnRegisterControlEventsToScript(LocalID, ItemID);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -706,19 +699,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
m_CollisionInQueue = false;
|
||||
}
|
||||
|
||||
SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
|
||||
|
||||
if (DebugLevel >= 2)
|
||||
m_log.DebugFormat(
|
||||
"[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
|
||||
data.EventName,
|
||||
ScriptName,
|
||||
part.Name,
|
||||
part.LocalId,
|
||||
part.ParentGroup.Name,
|
||||
part.ParentGroup.UUID,
|
||||
part.AbsolutePosition,
|
||||
part.ParentGroup.Scene.Name);
|
||||
Part.Name,
|
||||
Part.LocalId,
|
||||
Part.ParentGroup.Name,
|
||||
Part.ParentGroup.UUID,
|
||||
Part.AbsolutePosition,
|
||||
Part.ParentGroup.Scene.Name);
|
||||
|
||||
m_DetectParams = data.DetectParams;
|
||||
|
||||
|
@ -731,21 +722,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
"[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
|
||||
State,
|
||||
ScriptName,
|
||||
part.Name,
|
||||
part.LocalId,
|
||||
part.ParentGroup.Name,
|
||||
part.ParentGroup.UUID,
|
||||
part.AbsolutePosition,
|
||||
part.ParentGroup.Scene.Name);
|
||||
Part.Name,
|
||||
Part.LocalId,
|
||||
Part.ParentGroup.Name,
|
||||
Part.ParentGroup.UUID,
|
||||
Part.AbsolutePosition,
|
||||
Part.ParentGroup.Scene.Name);
|
||||
|
||||
AsyncCommandManager.RemoveScript(Engine,
|
||||
LocalID, ItemID);
|
||||
|
||||
if (part != null)
|
||||
{
|
||||
part.SetScriptEvents(ItemID,
|
||||
(int)m_Script.GetStateEventFlags(State));
|
||||
}
|
||||
Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -804,17 +791,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
text = text.Substring(0, 1000);
|
||||
Engine.World.SimChat(Utils.StringToBytes(text),
|
||||
ChatTypeEnum.DebugChannel, 2147483647,
|
||||
part.AbsolutePosition,
|
||||
part.Name, part.UUID, false);
|
||||
Part.AbsolutePosition,
|
||||
Part.Name, Part.UUID, false);
|
||||
|
||||
|
||||
m_log.DebugFormat(
|
||||
"[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}",
|
||||
ScriptName,
|
||||
PrimName,
|
||||
part.UUID,
|
||||
part.AbsolutePosition,
|
||||
part.ParentGroup.Scene.Name,
|
||||
Part.UUID,
|
||||
Part.AbsolutePosition,
|
||||
Part.ParentGroup.Scene.Name,
|
||||
text.Replace("\n", "\\n"),
|
||||
e.InnerException);
|
||||
}
|
||||
|
@ -834,14 +821,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
|
||||
{
|
||||
m_InSelfDelete = true;
|
||||
if (part != null)
|
||||
Engine.World.DeleteSceneObject(part.ParentGroup, false);
|
||||
Engine.World.DeleteSceneObject(Part.ParentGroup, false);
|
||||
}
|
||||
else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException))
|
||||
{
|
||||
m_InSelfDelete = true;
|
||||
if (part != null)
|
||||
part.Inventory.RemoveInventoryItem(ItemID);
|
||||
Part.Inventory.RemoveInventoryItem(ItemID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -888,15 +873,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
ReleaseControls();
|
||||
|
||||
Stop(timeout);
|
||||
SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
|
||||
part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
|
||||
part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
|
||||
Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
|
||||
Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
|
||||
AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
|
||||
EventQueue.Clear();
|
||||
m_Script.ResetVars();
|
||||
State = "default";
|
||||
|
||||
part.SetScriptEvents(ItemID,
|
||||
Part.SetScriptEvents(ItemID,
|
||||
(int)m_Script.GetStateEventFlags(State));
|
||||
if (running)
|
||||
Start();
|
||||
|
@ -913,16 +897,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
ReleaseControls();
|
||||
|
||||
m_Script.ResetVars();
|
||||
SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
|
||||
part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
|
||||
part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
|
||||
Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
|
||||
Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
|
||||
AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
|
||||
|
||||
EventQueue.Clear();
|
||||
m_Script.ResetVars();
|
||||
State = "default";
|
||||
|
||||
part.SetScriptEvents(ItemID,
|
||||
Part.SetScriptEvents(ItemID,
|
||||
(int)m_Script.GetStateEventFlags(State));
|
||||
|
||||
if (m_CurrentEvent != "state_entry")
|
||||
|
|
Loading…
Reference in New Issue