From 3fe966d6b32f858da37a263e0568f28c7700b03b Mon Sep 17 00:00:00 2001 From: idb Date: Sun, 21 Dec 2008 19:04:06 +0000 Subject: [PATCH] An initial implementation of llMinEventDelay in XEngine. Not implemented yet in DotNetEngine. Fixes Mantis #2830 --- .../ScriptEngine/DotNetEngine/ScriptEngine.cs | 7 ++++ .../ScriptEngine/Interfaces/IScriptEngine.cs | 1 + .../Interfaces/IScriptInstance.cs | 1 + .../Shared/Api/Implementation/LSL_Api.cs | 10 +++++- .../Shared/Instance/ScriptInstance.cs | 33 +++++++++++++++++++ .../Shared/Instance/ScriptSerializer.cs | 14 +++++++- .../Region/ScriptEngine/XEngine/XEngine.cs | 7 ++++ 7 files changed, 71 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs index 269afaa4c7..28e1278088 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs @@ -240,6 +240,13 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine { return m_ScriptManager.GetStartParameter(itemID); } + + public void SetMinEventDelay(UUID itemID, double delay) + { + // TODO in DotNet, done in XEngine + throw new NotImplementedException(); + } + #endregion public void SetState(UUID itemID, string state) diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptEngine.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptEngine.cs index db05d47b86..04af705859 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptEngine.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptEngine.cs @@ -61,6 +61,7 @@ namespace OpenSim.Region.ScriptEngine.Interfaces bool PostObjectEvent(uint localID, EventParams parms); DetectParams GetDetectParams(UUID item, int number); + void SetMinEventDelay(UUID itemID, double delay); int GetStartParameter(UUID itemID); void SetScriptState(UUID itemID, bool state); diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs index 31202e261d..3367b7703c 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs @@ -102,5 +102,6 @@ namespace OpenSim.Region.ScriptEngine.Interfaces string GetAssemblyName(); string GetXMLState(); + double MinEventDelay { set; } } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 5ef94719b2..a005b01a53 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -2756,7 +2756,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llMinEventDelay(double delay) { m_host.AddScriptLPS(1); - NotImplemented("llMinEventDelay"); + try + { + m_ScriptEngine.SetMinEventDelay(m_itemID, delay); + } + catch (NotImplementedException) + { + // Currently not implemented in DotNetEngine only XEngine + NotImplemented("llMinEventDelay in DotNetEngine"); + } } /// diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 1f57c130ad..8d6966ff2a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -84,6 +84,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance private int m_LastControlLevel = 0; private bool m_CollisionInQueue = false; private TaskInventoryItem m_thisScriptTask; + // The following is for setting a minimum delay between events + private double m_minEventDelay = 0; + private long m_eventDelayTicks = 0; + private long m_nextEventTimeTicks = 0; //private ISponsor m_ScriptSponsor; private Dictionary, KeyValuePair> @@ -103,6 +107,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public Object[] PluginData = new Object[0]; + /// + /// Used by llMinEventDelay to suppress events happening any faster than this speed. + /// This currently restricts all events in one go. Not sure if each event type has + /// its own check so take the simple route first. + /// + public double MinEventDelay + { + get { return m_minEventDelay; } + set + { + if (value > 0.001) + m_minEventDelay = value; + else + m_minEventDelay = 0.0; + m_eventDelayTicks = (long)(m_minEventDelay * 10000000L); + m_nextEventTimeTicks = DateTime.Now.Ticks; + } + } + public bool Running { get { return m_RunEvents; } @@ -498,6 +521,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance if (!Running) return; + // If min event delay is set then ignore any events untill the time has expired + // This currently only allows 1 event of any type in the given time period. + // This may need extending to allow for a time for each individual event type. + if (m_eventDelayTicks != 0) + { + if (DateTime.Now.Ticks < m_nextEventTimeTicks) + return; + m_nextEventTimeTicks = DateTime.Now.Ticks + m_eventDelayTicks; + } + lock (m_EventQueue) { if (m_EventQueue.Count >= m_MaxScriptQueue) diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs index 0ec039bcbd..c06960b83a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs @@ -194,6 +194,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } } + if (instance.MinEventDelay > 0.0) + { + XmlElement eventDelay = xmldoc.CreateElement("", "MinEventDelay", ""); + eventDelay.AppendChild(xmldoc.CreateTextNode(instance.MinEventDelay.ToString())); + rootElement.AppendChild(eventDelay); + } + return xmldoc.InnerXml; } @@ -380,8 +387,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } } break; - } + case "MinEventDelay": + double minEventDelay = 0.0; + double.TryParse(part.InnerText, out minEventDelay); + instance.MinEventDelay = minEventDelay; + break; } + } } } diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 6ad8923fa3..32714b2ad6 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -891,6 +891,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine return null; } + public void SetMinEventDelay(UUID itemID, double delay) + { + IScriptInstance instance = GetInstance(itemID); + if (instance != null) + instance.MinEventDelay = delay; + } + public UUID GetDetectID(UUID itemID, int idx) { IScriptInstance instance = GetInstance(itemID);