Remove property/field duplication in ScriptInstance where it's unnecessary.

0.7.4.1
Justin Clark-Casey (justincc) 2012-03-15 02:02:31 +00:00
parent 2d32401e23
commit acb1355ff2
2 changed files with 114 additions and 169 deletions

View File

@ -68,8 +68,16 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
/// </summary>
bool Suspended { get; set; }
/// <summary>
/// Is the script shutting down?
/// </summary>
bool ShuttingDown { get; set; }
/// <summary>
/// Script state
/// </summary>
string State { get; set; }
IScriptEngine Engine { get; }
UUID AppDomain { get; set; }
string PrimName { get; }

View File

@ -57,42 +57,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IScriptEngine m_Engine;
/// <summary>
/// The current work item if an event for this script is running or waiting to run,
/// </summary>
/// <remarks>
/// Null if there is no running or waiting to run event. Must be changed only under an m_EventQueue lock.
/// Null if there is no running or waiting to run event. Must be changed only under an EventQueue lock.
/// </remarks>
private IScriptWorkItem m_CurrentWorkItem;
private Queue m_EventQueue = new Queue(32);
private UUID m_ItemID;
private uint m_LocalID;
private UUID m_ObjectID;
private UUID m_AssetID;
private IScript m_Script;
private UUID m_AppDomain;
private DetectParams[] m_DetectParams;
private bool m_TimerQueued;
private DateTime m_EventStart;
private bool m_InEvent;
private string m_PrimName;
private string m_ScriptName;
private string m_Assembly;
private int m_StartParam;
private string m_CurrentEvent = String.Empty;
private bool m_InSelfDelete;
private int m_MaxScriptQueue;
private bool m_SaveState = true;
private bool m_ShuttingDown;
private int m_ControlEventsInQueue;
private int m_LastControlLevel;
private bool m_CollisionInQueue;
private TaskInventoryItem m_thisScriptTask;
// The following is for setting a minimum delay between events
private double m_minEventDelay;
private long m_eventDelayTicks;
private long m_nextEventTimeTicks;
private bool m_startOnInit = true;
@ -103,21 +92,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
private UUID m_CurrentStateHash;
private UUID m_RegionID;
private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>
m_LineMap;
public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>
LineMap
{
get { return m_LineMap; }
set { m_LineMap = value; }
}
public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap { get; set; }
private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>();
// Script state
private string m_State = "default";
public Object[] PluginData = new Object[0];
/// <summary>
@ -156,11 +134,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
if (wasSuspended && !m_Suspended)
{
lock (m_EventQueue)
lock (EventQueue)
{
// Need to place ourselves back in a work item if there are events to process
if ((m_EventQueue.Count > 0) && Running && (!m_ShuttingDown))
m_CurrentWorkItem = m_Engine.QueueEventHandler(this);
if (EventQueue.Count > 0 && Running && !ShuttingDown)
m_CurrentWorkItem = Engine.QueueEventHandler(this);
}
}
}
@ -168,79 +146,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
}
private bool m_Suspended;
public bool ShuttingDown
{
get { return m_ShuttingDown; }
set { m_ShuttingDown = value; }
}
public bool ShuttingDown { get; set; }
public string State
{
get { return m_State; }
set { m_State = value; }
}
public string State { get; set; }
public IScriptEngine Engine
{
get { return m_Engine; }
}
public IScriptEngine Engine { get; private set; }
public UUID AppDomain
{
get { return m_AppDomain; }
set { m_AppDomain = value; }
}
public UUID AppDomain { get; set; }
public string PrimName
{
get { return m_PrimName; }
}
public string PrimName { get; private set; }
public string ScriptName
{
get { return m_ScriptName; }
}
public string ScriptName { get; private set; }
public UUID ItemID
{
get { return m_ItemID; }
}
public UUID ItemID { get; private set; }
public UUID ObjectID
{
get { return m_ObjectID; }
}
public UUID ObjectID { get; private set; }
public uint LocalID
{
get { return m_LocalID; }
}
public uint LocalID { get; private set; }
public UUID AssetID
{
get { return m_AssetID; }
}
public UUID AssetID { get; private set; }
public Queue EventQueue
{
get { return m_EventQueue; }
}
public Queue EventQueue { get; private set; }
public int StartParam { get; set; }
public TaskInventoryItem ScriptTask { get; private set; }
public void ClearQueue()
{
m_TimerQueued = false;
m_EventQueue.Clear();
}
public int StartParam
{
get { return m_StartParam; }
set { m_StartParam = value; }
}
public TaskInventoryItem ScriptTask
{
get { return m_thisScriptTask; }
EventQueue.Clear();
}
public ScriptInstance(IScriptEngine engine, SceneObjectPart part,
@ -249,16 +184,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
int startParam, bool postOnRez, StateSource stateSource,
int maxScriptQueue)
{
m_Engine = engine;
State = "default";
EventQueue = new Queue(32);
m_LocalID = part.LocalId;
m_ObjectID = part.UUID;
m_ItemID = itemID;
m_AssetID = assetID;
m_PrimName = primName;
m_ScriptName = scriptName;
Engine = engine;
LocalID = part.LocalId;
ObjectID = part.UUID;
ItemID = itemID;
AssetID = assetID;
PrimName = primName;
ScriptName = scriptName;
m_Assembly = assembly;
m_StartParam = startParam;
StartParam = startParam;
m_MaxScriptQueue = maxScriptQueue;
m_stateSource = stateSource;
m_postOnRez = postOnRez;
@ -269,9 +206,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
{
lock (part.TaskInventory)
{
if (part.TaskInventory.ContainsKey(m_ItemID))
if (part.TaskInventory.ContainsKey(ItemID))
{
m_thisScriptTask = part.TaskInventory[m_ItemID];
ScriptTask = part.TaskInventory[ItemID];
}
}
}
@ -281,7 +218,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
foreach (string api in am.GetApis())
{
m_Apis[api] = am.CreateApi(api);
m_Apis[api].Initialize(engine, part, m_LocalID, itemID);
m_Apis[api].Initialize(engine, part, LocalID, itemID);
}
try
@ -315,7 +252,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
// // m_log.Debug("[Script] Script instance created");
part.SetScriptEvents(m_ItemID,
part.SetScriptEvents(ItemID,
(int)m_Script.GetStateEventFlags(State));
}
catch (Exception e)
@ -330,7 +267,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
m_SaveState = true;
string savedState = Path.Combine(Path.GetDirectoryName(assembly),
m_ItemID.ToString() + ".state");
ItemID.ToString() + ".state");
if (File.Exists(savedState))
{
string xml = String.Empty;
@ -354,18 +291,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
ScriptSerializer.Deserialize(xml, this);
AsyncCommandManager.CreateFromData(m_Engine,
m_LocalID, m_ItemID, m_ObjectID,
AsyncCommandManager.CreateFromData(Engine,
LocalID, ItemID, ObjectID,
PluginData);
// m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", m_PrimName, m_ScriptName);
// m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", PrimName, m_ScriptName);
part.SetScriptEvents(m_ItemID,
part.SetScriptEvents(ItemID,
(int)m_Script.GetStateEventFlags(State));
Running = false;
if (m_ShuttingDown)
if (ShuttingDown)
m_startOnInit = false;
// we get new rez events on sim restart, too
@ -393,7 +330,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
}
// else
// {
// ScenePresence presence = m_Engine.World.GetScenePresence(part.OwnerID);
// ScenePresence presence = Engine.World.GetScenePresence(part.OwnerID);
// if (presence != null && (!postOnRez))
// presence.ControllingClient.SendAgentAlertMessage("Compile successful", false);
@ -411,7 +348,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
if (m_postOnRez)
{
PostEvent(new EventParams("on_rez",
new Object[] {new LSL_Types.LSLInteger(m_StartParam)}, new DetectParams[0]));
new Object[] {new LSL_Types.LSLInteger(StartParam)}, new DetectParams[0]));
}
if (m_stateSource == StateSource.AttachedRez)
@ -445,7 +382,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
if (m_postOnRez)
{
PostEvent(new EventParams("on_rez",
new Object[] {new LSL_Types.LSLInteger(m_StartParam)}, new DetectParams[0]));
new Object[] {new LSL_Types.LSLInteger(StartParam)}, new DetectParams[0]));
}
if (m_stateSource == StateSource.AttachedRez)
@ -459,7 +396,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
private void ReleaseControls()
{
SceneObjectPart part = m_Engine.World.GetSceneObjectPart(m_LocalID);
SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
if (part != null)
{
@ -467,18 +404,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
UUID permsGranter;
lock (part.TaskInventory)
{
if (!part.TaskInventory.ContainsKey(m_ItemID))
if (!part.TaskInventory.ContainsKey(ItemID))
return;
permsGranter = part.TaskInventory[m_ItemID].PermsGranter;
permsMask = part.TaskInventory[m_ItemID].PermsMask;
permsGranter = part.TaskInventory[ItemID].PermsGranter;
permsMask = part.TaskInventory[ItemID].PermsMask;
}
if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
{
ScenePresence presence = m_Engine.World.GetScenePresence(permsGranter);
ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
if (presence != null)
presence.UnRegisterControlEventsToScript(m_LocalID, m_ItemID);
presence.UnRegisterControlEventsToScript(LocalID, ItemID);
}
}
}
@ -486,13 +423,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public void DestroyScriptInstance()
{
ReleaseControls();
AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID);
AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
}
public void RemoveState()
{
string savedState = Path.Combine(Path.GetDirectoryName(m_Assembly),
m_ItemID.ToString() + ".state");
ItemID.ToString() + ".state");
try
{
@ -505,7 +442,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public void VarDump(Dictionary<string, object> vars)
{
// m_log.Info("Variable dump for script "+ m_ItemID.ToString());
// m_log.Info("Variable dump for script "+ ItemID.ToString());
// foreach (KeyValuePair<string, object> v in vars)
// {
// m_log.Info("Variable: "+v.Key+" = "+v.Value.ToString());
@ -514,17 +451,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public void Start()
{
lock (m_EventQueue)
lock (EventQueue)
{
if (Running)
return;
Running = true;
if (m_EventQueue.Count > 0)
if (EventQueue.Count > 0)
{
if (m_CurrentWorkItem == null)
m_CurrentWorkItem = m_Engine.QueueEventHandler(this);
m_CurrentWorkItem = Engine.QueueEventHandler(this);
// else
// m_log.Error("[Script] Tried to start a script that was already queued");
}
@ -539,7 +476,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
IScriptWorkItem workItem;
lock (m_EventQueue)
lock (EventQueue)
{
if (!Running)
return true;
@ -569,7 +506,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
return true;
}
lock (m_EventQueue)
lock (EventQueue)
{
workItem = m_CurrentWorkItem;
}
@ -588,7 +525,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
workItem.Abort();
}
lock (m_EventQueue)
lock (EventQueue)
{
m_CurrentWorkItem = null;
}
@ -621,7 +558,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public void PostEvent(EventParams data)
{
// m_log.DebugFormat("[Script] Posted event {2} in state {3} to {0}.{1}",
// m_PrimName, m_ScriptName, data.EventName, m_State);
// PrimName, ScriptName, data.EventName, State);
if (!Running)
return;
@ -636,9 +573,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
m_nextEventTimeTicks = DateTime.Now.Ticks + m_eventDelayTicks;
}
lock (m_EventQueue)
lock (EventQueue)
{
if (m_EventQueue.Count >= m_MaxScriptQueue)
if (EventQueue.Count >= m_MaxScriptQueue)
return;
if (data.EventName == "timer")
@ -682,11 +619,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
m_CollisionInQueue = true;
}
m_EventQueue.Enqueue(data);
EventQueue.Enqueue(data);
if (m_CurrentWorkItem == null)
{
m_CurrentWorkItem = m_Engine.QueueEventHandler(this);
m_CurrentWorkItem = Engine.QueueEventHandler(this);
}
}
}
@ -710,14 +647,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
EventParams data = null;
lock (m_EventQueue)
lock (EventQueue)
{
data = (EventParams) m_EventQueue.Dequeue();
data = (EventParams)EventQueue.Dequeue();
if (data == null) // Shouldn't happen
{
if (m_EventQueue.Count > 0 && Running && !m_ShuttingDown)
if (EventQueue.Count > 0 && Running && !ShuttingDown)
{
m_CurrentWorkItem = m_Engine.QueueEventHandler(this);
m_CurrentWorkItem = Engine.QueueEventHandler(this);
}
else
{
@ -744,28 +681,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
if (data.EventName == "state") // Hardcoded state change
{
// m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}",
// m_PrimName, m_ScriptName, data.Params[0].ToString());
m_State = data.Params[0].ToString();
AsyncCommandManager.RemoveScript(m_Engine,
m_LocalID, m_ItemID);
// PrimName, ScriptName, data.Params[0].ToString());
State = data.Params[0].ToString();
AsyncCommandManager.RemoveScript(Engine,
LocalID, ItemID);
SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
m_LocalID);
SceneObjectPart part = Engine.World.GetSceneObjectPart(
LocalID);
if (part != null)
{
part.SetScriptEvents(m_ItemID,
part.SetScriptEvents(ItemID,
(int)m_Script.GetStateEventFlags(State));
}
}
else
{
if (m_Engine.World.PipeEventsForScript(m_LocalID) ||
if (Engine.World.PipeEventsForScript(LocalID) ||
data.EventName == "control") // Don't freeze avies!
{
SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
m_LocalID);
SceneObjectPart part = Engine.World.GetSceneObjectPart(
LocalID);
// m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
// m_PrimName, m_ScriptName, data.EventName, m_State);
// PrimName, ScriptName, data.EventName, State);
try
{
@ -807,7 +744,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
if (text.Length > 1000)
text = text.Substring(0, 1000);
m_Engine.World.SimChat(Utils.StringToBytes(text),
Engine.World.SimChat(Utils.StringToBytes(text),
ChatTypeEnum.DebugChannel, 2147483647,
part.AbsolutePosition,
part.Name, part.UUID, false);
@ -829,13 +766,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
{
m_InSelfDelete = true;
if (part != null)
m_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(m_ItemID);
part.Inventory.RemoveInventoryItem(ItemID);
}
}
}
@ -843,11 +780,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
// If there are more events and we are currently running and not shutting down, then ask the
// script engine to run the next event.
lock (m_EventQueue)
lock (EventQueue)
{
if (m_EventQueue.Count > 0 && Running && (!m_ShuttingDown))
if (EventQueue.Count > 0 && Running && !ShuttingDown)
{
m_CurrentWorkItem = m_Engine.QueueEventHandler(this);
m_CurrentWorkItem = Engine.QueueEventHandler(this);
}
else
{
@ -880,15 +817,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
ReleaseControls();
Stop(0);
SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID);
part.Inventory.GetInventoryItem(m_ItemID).PermsMask = 0;
part.Inventory.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero;
AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID);
m_EventQueue.Clear();
SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
EventQueue.Clear();
m_Script.ResetVars();
m_State = "default";
State = "default";
part.SetScriptEvents(m_ItemID,
part.SetScriptEvents(ItemID,
(int)m_Script.GetStateEventFlags(State));
if (running)
Start();
@ -905,16 +842,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
ReleaseControls();
m_Script.ResetVars();
SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID);
part.Inventory.GetInventoryItem(m_ItemID).PermsMask = 0;
part.Inventory.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero;
AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID);
SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
m_EventQueue.Clear();
EventQueue.Clear();
m_Script.ResetVars();
m_State = "default";
State = "default";
part.SetScriptEvents(m_ItemID,
part.SetScriptEvents(ItemID,
(int)m_Script.GetStateEventFlags(State));
if (m_CurrentEvent != "state_entry")
@ -969,7 +906,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
return;
}
PluginData = AsyncCommandManager.GetSerializationData(m_Engine, m_ItemID);
PluginData = AsyncCommandManager.GetSerializationData(Engine, ItemID);
string xml = ScriptSerializer.Serialize(this);
@ -981,7 +918,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
{
try
{
FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state"));
FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), ItemID.ToString() + ".state"));
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
Byte[] buf = enc.GetBytes(xml);
fs.Write(buf, 0, buf.Length);
@ -991,7 +928,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
{
// m_log.Error("Unable to save xml\n"+e.ToString());
}
//if (!File.Exists(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state")))
//if (!File.Exists(Path.Combine(Path.GetDirectoryName(assembly), ItemID.ToString() + ".state")))
//{
// throw new Exception("Completed persistence save, but no file was created");
//}
@ -1008,7 +945,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public override string ToString()
{
return String.Format("{0} {1} on {2}", m_ScriptName, m_ItemID, m_PrimName);
return String.Format("{0} {1} on {2}", ScriptName, ItemID, PrimName);
}
string FormatException(Exception e)
@ -1076,7 +1013,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
// Force an update of the in-memory plugin data
//
PluginData = AsyncCommandManager.GetSerializationData(m_Engine, m_ItemID);
PluginData = AsyncCommandManager.GetSerializationData(Engine, ItemID);
return ScriptSerializer.Serialize(this);
}