From 6d3ee8bb39d47ed7b32e8905fa0b2fc31c5a9f80 Mon Sep 17 00:00:00 2001 From: BlueWall Date: Sat, 23 Jun 2012 04:11:31 -0400 Subject: [PATCH] Fix script "Running" behavior Unchecking "Running" box in script editor now persists. This fixes http://opensimulator.org/mantis/view.php?id=6057 --- .../Region/Framework/Interfaces/IScriptModule.cs | 2 ++ OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 14 ++++++++++++++ .../ScriptEngine/Interfaces/IScriptInstance.cs | 10 ++++++++++ .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 9 +++++++++ .../Shared/Instance/ScriptSerializer.cs | 11 +++++++++++ OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 7 +++++++ 6 files changed, 53 insertions(+) diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs index 0d488dffd7..cbaf24139d 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs @@ -75,6 +75,8 @@ namespace OpenSim.Region.Framework.Interfaces /// The item ID of the script. bool GetScriptState(UUID itemID); + void SetRunEnable(UUID instanceID, bool enable); + void SaveAllState(); /// diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index e4132817ac..9ff8467086 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -2143,10 +2143,24 @@ namespace OpenSim.Region.Framework.Scenes if (part == null) return; + IScriptModule[] engines = RequestModuleInterfaces(); + if (running) + { + foreach (IScriptModule engine in engines) + { + engine.SetRunEnable(itemID, true); + } EventManager.TriggerStartScript(part.LocalId, itemID); + } else + { + foreach (IScriptModule engine in engines) + { + engine.SetRunEnable(itemID, false); + } EventManager.TriggerStopScript(part.LocalId, itemID); + } } public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID) diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs index b04f6b6624..ec13b6cc01 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs @@ -63,6 +63,16 @@ namespace OpenSim.Region.ScriptEngine.Interfaces /// bool Running { get; set; } + /// + /// Gets or sets a value indicating whether this + /// is run. + /// For viewer script editor control + /// + /// + /// true if run; otherwise, false. + /// + bool Run { get; set; } + /// /// Is the script suspended? /// diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 5dfe58e2f9..306090e60c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -120,6 +120,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public bool Running { get; set; } + public bool Run { get; set; } + public bool Suspended { get { return m_Suspended; } @@ -215,6 +217,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance m_postOnRez = postOnRez; m_AttachedAvatar = part.ParentGroup.AttachedAvatar; m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID; + Run = true; if (part != null) { @@ -359,6 +362,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance if (m_startedFromSavedState) { + if (!Run) + return; + Start(); if (m_postOnRez) { @@ -391,6 +397,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } else { + if (!Run) + return; + Start(); PostEvent(new EventParams("state_entry", new Object[0], new DetectParams[0])); diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs index bcdc7bf5dd..797bce3ce1 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs @@ -55,6 +55,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public static string Serialize(ScriptInstance instance) { bool running = instance.Running; + bool enabled = instance.Run; XmlDocument xmldoc = new XmlDocument(); @@ -77,6 +78,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance rootElement.AppendChild(run); + XmlElement run_enable = xmldoc.CreateElement("", "Run", ""); + run_enable.AppendChild(xmldoc.CreateTextNode( + enabled.ToString())); + + rootElement.AppendChild(run_enable); + Dictionary vars = instance.GetVars(); XmlElement variables = xmldoc.CreateElement("", "Variables", ""); @@ -225,6 +232,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { object varValue; XmlNodeList partL = rootNode.ChildNodes; + instance.Run = true; foreach (XmlNode part in partL) { @@ -236,6 +244,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance case "Running": instance.Running=bool.Parse(part.InnerText); break; + case "Run": + instance.Run = bool.Parse(part.InnerText); + break; case "Variables": XmlNodeList varL = part.ChildNodes; foreach (XmlNode var in varL) diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 25b27b90c5..06ed9d6deb 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1503,6 +1503,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine } } + public void SetRunEnable(UUID instanceID, bool enable) + { + IScriptInstance instance = GetInstance(instanceID); + if (instance != null) + instance.Run = enable; + } + public bool GetScriptState(UUID itemID) { IScriptInstance instance = GetInstance(itemID);