diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs b/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs
index a9498dd40c..cfc362cb17 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs
@@ -1092,17 +1092,27 @@ namespace OpenSim.Region.ScriptEngine.Yengine
if(stateN == null)
return false;
- if(stateN.GetAttribute("Engine") != ScriptEngineName)
+ bool isX = false;
+ string sen = stateN.GetAttribute("Engine");
+ if (sen == null)
return false;
-
- // ... contains contents of .state file.
- XmlElement scriptStateN = (XmlElement)stateN.SelectSingleNode("ScriptState");
+ if (sen != ScriptEngineName)
+ {
+ if(sen != "XEngine")
+ return false;
+ isX = true;
+ }
+ // ... contains contents of .state file.
+ XmlElement scriptStateN = (XmlElement)stateN.SelectSingleNode("ScriptState");
if(scriptStateN == null)
return false;
- string sen = stateN.GetAttribute("Engine");
- if((sen == null) || (sen != ScriptEngineName))
- return false;
+ if(!isX)
+ {
+ sen = stateN.GetAttribute("Engine");
+ if ((sen == null) || (sen != ScriptEngineName))
+ return false;
+ }
XmlAttribute assetA = doc.CreateAttribute("", "Asset", "");
assetA.Value = stateN.GetAttribute("Asset");
@@ -1110,11 +1120,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine
// Write out the .state file with the ... XML text
string statePath = XMRInstance.GetStateFileName(m_ScriptBasePath, itemID);
- FileStream ss = File.Create(statePath);
- StreamWriter sw = new StreamWriter(ss);
- sw.Write(scriptStateN.OuterXml);
- sw.Close();
- ss.Close();
+ using (FileStream ss = File.Create(statePath))
+ {
+ using (StreamWriter sw = new StreamWriter(ss))
+ sw.Write(scriptStateN.OuterXml);
+ }
return true;
}
diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs
index 490de74463..092d9c2b99 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs
@@ -452,6 +452,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine
return newuse;
}
+ public virtual void AddHeapUse(int delta)
+ {
+ Interlocked.Add(ref heapUsed, delta);
+ }
+
public int xmrHeapLeft()
{
return heapLimit - heapUsed;
diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs
index f7c4a7d640..577a03dcbb 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstCtor.cs
@@ -378,13 +378,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine
}
else
{
- FileStream fs = File.Open(m_StateFileName,
+ string xml;
+ using (FileStream fs = File.Open(m_StateFileName,
FileMode.Open,
- FileAccess.Read);
- StreamReader ss = new StreamReader(fs);
- string xml = ss.ReadToEnd();
- ss.Close();
- fs.Close();
+ FileAccess.Read))
+ {
+ using(StreamReader ss = new StreamReader(fs))
+ xml = ss.ReadToEnd();
+ }
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
@@ -471,17 +472,22 @@ namespace OpenSim.Region.ScriptEngine.Yengine
*/
private void LoadScriptState(XmlDocument doc)
{
- DetectParams[] detParams;
- LinkedList eventQueue;
// Everything we know is enclosed in ...
XmlElement scriptStateN = (XmlElement)doc.SelectSingleNode("ScriptState");
if(scriptStateN == null)
throw new Exception("no tag");
+ XmlElement XvariablesN = null;
string sen = scriptStateN.GetAttribute("Engine");
if((sen == null) || (sen != m_Engine.ScriptEngineName))
- throw new Exception(" missing Engine=\"YEngine\" attribute");
+ {
+ XvariablesN = (XmlElement)scriptStateN.SelectSingleNode("Variables");
+ if(XvariablesN == null)
+ throw new Exception(" missing Engine=\"YEngine\" attribute");
+ processXstate(doc);
+ return;
+ }
// AssetID is unique for the script source text so make sure the
// state file was written for that source file
@@ -508,18 +514,17 @@ namespace OpenSim.Region.ScriptEngine.Yengine
m_Part.Inventory.UpdateInventoryItem(m_Item, false, false);
// get values used by stuff like llDetectedGrab, etc.
- detParams = RestoreDetectParams(scriptStateN.SelectSingleNode("DetectArray"));
+ DetectParams[] detParams = RestoreDetectParams(scriptStateN.SelectSingleNode("DetectArray"));
// Restore queued events
- eventQueue = RestoreEventQueue(scriptStateN.SelectSingleNode("EventQueue"));
+ LinkedList eventQueue = RestoreEventQueue(scriptStateN.SelectSingleNode("EventQueue"));
// Restore timers and listeners
XmlElement pluginN = (XmlElement)scriptStateN.SelectSingleNode("Plugins");
Object[] pluginData = ExtractXMLObjectArray(pluginN, "plugin");
// Script's global variables and stack contents
- XmlElement snapshotN =
- (XmlElement)scriptStateN.SelectSingleNode("Snapshot");
+ XmlElement snapshotN = (XmlElement)scriptStateN.SelectSingleNode("Snapshot");
Byte[] data = Convert.FromBase64String(snapshotN.InnerText);
MemoryStream ms = new MemoryStream();
@@ -553,16 +558,424 @@ namespace OpenSim.Region.ScriptEngine.Yengine
pluginData);
}
- /**
- * @brief Read llDetectedGrab, etc, values from XML
- *
- * ...
- * .
- * .
- * .
- *
- */
- private LinkedList RestoreEventQueue(XmlNode eventsN)
+ private void processXstate(XmlDocument doc)
+ {
+
+ XmlNodeList rootL = doc.GetElementsByTagName("ScriptState");
+ if (rootL.Count != 1)
+ throw new Exception("Xstate missing");
+
+ XmlNode rootNode = rootL[0];
+ if (rootNode == null)
+ throw new Exception("Xstate root missing");
+
+ string stateName = "";
+ bool running = false;
+
+ UUID permsGranter = UUID.Zero;
+ int permsMask = 0;
+ double minEventDelay = 0.0;
+ Object[] pluginData = new Object[0];
+
+ LinkedList eventQueue = new LinkedList();
+
+ Dictionary intNames = new Dictionary();
+ Dictionary doubleNames = new Dictionary();
+ Dictionary stringNames = new Dictionary();
+ Dictionary vectorNames = new Dictionary();
+ Dictionary rotationNames = new Dictionary();
+ Dictionary listNames = new Dictionary();
+
+ int nn = m_ObjCode.globalVarNames.Count;
+ int[] ints = null;
+ double[] doubles = null;
+ string[] strings = null;
+ LSL_Vector[] vectors = null;
+ LSL_Rotation[] rotations = null;
+ LSL_List[] lists = null;
+
+ if (nn > 0)
+ {
+ if (m_ObjCode.globalVarNames.ContainsKey("iarIntegers"))
+ {
+ getvarNames(m_ObjCode.globalVarNames["iarIntegers"], intNames);
+ ints = new int[m_ObjCode.globalVarNames["iarIntegers"].Count];
+ }
+ if (m_ObjCode.globalVarNames.ContainsKey("iarFloats"))
+ {
+ getvarNames(m_ObjCode.globalVarNames["iarFloats"], doubleNames);
+ doubles = new double[m_ObjCode.globalVarNames["iarFloats"].Count];
+ }
+ if (m_ObjCode.globalVarNames.ContainsKey("iarVectors"))
+ {
+ getvarNames(m_ObjCode.globalVarNames["iarVectors"], vectorNames);
+ vectors = new LSL_Vector[m_ObjCode.globalVarNames["iarVectors"].Count];
+ }
+ if (m_ObjCode.globalVarNames.ContainsKey("iarRotations"))
+ {
+ getvarNames(m_ObjCode.globalVarNames["iarRotations"], rotationNames);
+ rotations = new LSL_Rotation[m_ObjCode.globalVarNames["iarRotations"].Count];
+ }
+ if (m_ObjCode.globalVarNames.ContainsKey("iarStrings"))
+ {
+ getvarNames(m_ObjCode.globalVarNames["iarStrings"], stringNames);
+ strings = new string[m_ObjCode.globalVarNames["iarStrings"].Count];
+ }
+ if (m_ObjCode.globalVarNames.ContainsKey("iarLists"))
+ {
+ getvarNames(m_ObjCode.globalVarNames["iarLists"], listNames);
+ lists = new LSL_List[m_ObjCode.globalVarNames["iarLists"].Count];
+ }
+ }
+
+ int heapsz = 0;
+
+ try
+ {
+ XmlNodeList partL = rootNode.ChildNodes;
+ foreach (XmlNode part in partL)
+ {
+ switch (part.Name)
+ {
+ case "State":
+ stateName = part.InnerText;
+ break;
+ case "Running":
+ running = bool.Parse(part.InnerText);
+ break;
+ case "Variables":
+ int indx;
+ XmlNodeList varL = part.ChildNodes;
+ foreach (XmlNode var in varL)
+ {
+ string varName;
+ object o = ReadXTypedValue(var, out varName);
+ Type otype = o.GetType();
+ if (otype == typeof(LSL_Integer))
+ {
+ if (intNames.TryGetValue(varName, out indx))
+ ints[indx] = ((LSL_Integer)o);
+ continue;
+ }
+ if (otype == typeof(LSL_Float))
+ {
+ if (doubleNames.TryGetValue(varName, out indx))
+ doubles[indx] = ((LSL_Float)o);
+ continue;
+ }
+ if (otype == typeof(LSL_String))
+ {
+ if (stringNames.TryGetValue(varName, out indx))
+ {
+ strings[indx] = ((LSL_String)o);
+ heapsz += ((LSL_String)o).Length;
+ }
+ continue;
+ }
+ if (otype == typeof(LSL_Rotation))
+ {
+ if (rotationNames.TryGetValue(varName, out indx))
+ rotations[indx] = ((LSL_Rotation)o);
+ continue;
+ }
+ if (otype == typeof(LSL_Vector))
+ {
+ if (vectorNames.TryGetValue(varName, out indx))
+ vectors[indx] = ((LSL_Vector)o);
+ continue;
+ }
+ if (otype == typeof(LSL_Key))
+ {
+ if (stringNames.TryGetValue(varName, out indx))
+ {
+ strings[indx] = ((LSL_Key)o);
+ heapsz += ((LSL_String)o).Length;
+ }
+ continue;
+ }
+ if (otype == typeof(UUID))
+ {
+ if (stringNames.TryGetValue(varName, out indx))
+ {
+ LSL_String id = ((UUID)o).ToString();
+ strings[indx] = (id);
+ heapsz += id.Length;
+ }
+ continue;
+ }
+ if (otype == typeof(LSL_List))
+ {
+ if (listNames.TryGetValue(varName, out indx))
+ {
+ LSL_List lo = (LSL_List)o;
+ lists[indx] = (lo);
+ heapsz += lo.Size;
+ }
+ continue;
+ }
+ }
+ break;
+ case "Queue":
+ XmlNodeList itemL = part.ChildNodes;
+ foreach (XmlNode item in itemL)
+ {
+ List