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