From 416d75282900ebd4af5434a95f70765f078a5b69 Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Wed, 20 Feb 2008 17:35:28 +0000 Subject: llSetTimerEvent updated to use ticks instead of DateTime for internal timing. --- OpenSim/Region/ScriptEngine/Common/Executor.cs | 6 +-- .../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 2 +- .../ScriptEngineBase/AsyncLSLCommandManager.cs | 57 ++++++++++++++-------- 3 files changed, 41 insertions(+), 24 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Common/Executor.cs b/OpenSim/Region/ScriptEngine/Common/Executor.cs index 21cca6b..ac2164a 100644 --- a/OpenSim/Region/ScriptEngine/Common/Executor.cs +++ b/OpenSim/Region/ScriptEngine/Common/Executor.cs @@ -49,9 +49,9 @@ namespace OpenSim.Region.ScriptEngine.Common string EventName = m_Script.State + "_event_" + FunctionName; -#if DEBUG - Console.WriteLine("ScriptEngine: Script event function name: " + EventName); -#endif +//#if DEBUG +// Console.WriteLine("ScriptEngine: Script event function name: " + EventName); +//#endif if (Events.ContainsKey(EventName) == false) { diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index c14a74f..1ab2a43 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -1244,7 +1244,7 @@ namespace OpenSim.Region.ScriptEngine.Common { m_host.AddScriptLPS(1); // Setting timer repeat - m_ScriptEngine.m_ASYNCLSLCommandManager.SetTimerEvent(m_localID, m_itemID, sec / 1000); + m_ScriptEngine.m_ASYNCLSLCommandManager.SetTimerEvent(m_localID, m_itemID, sec); } public void llSleep(double sec) diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncLSLCommandManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncLSLCommandManager.cs index baab096..830ca99 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncLSLCommandManager.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncLSLCommandManager.cs @@ -27,6 +27,7 @@ */ using System; +using System.Collections; using System.Collections.Generic; using System.Threading; using libsecondlife; @@ -128,7 +129,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase xmlrpc.DeleteChannels(itemID); xmlrpc.CancelSRDRequests(itemID); - + } #region TIMER @@ -140,8 +141,10 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase { public uint localID; public LLUUID itemID; - public double interval; - public DateTime next; + //public double interval; + public long interval; + //public DateTime next; + public long next; } private List Timers = new List(); @@ -160,8 +163,12 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase TimerClass ts = new TimerClass(); ts.localID = m_localID; ts.itemID = m_itemID; - ts.interval = sec / 1000; - ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); + ts.interval = Convert.ToInt64(sec * 10000000); // How many 100 nanoseconds (ticks) should we wait + // 2193386136332921 ticks + // 219338613 seconds + + //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); + ts.next = DateTime.Now.Ticks + ts.interval; lock (TimerListLock) { Timers.Add(ts); @@ -173,17 +180,25 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase // Remove from timer lock (TimerListLock) { - List NewTimers = new List(); - foreach (TimerClass ts in Timers) + foreach (TimerClass ts in new ArrayList(Timers)) { - if (ts.localID != m_localID && ts.itemID != m_itemID) - { - NewTimers.Add(ts); - } + if (ts.localID == m_localID && ts.itemID == m_itemID) + Timers.Remove(ts); } - Timers.Clear(); - Timers = NewTimers; } + + // Old method: Create new list + //List NewTimers = new List(); + //foreach (TimerClass ts in Timers) + //{ + // if (ts.localID != m_localID && ts.itemID != m_itemID) + // { + // NewTimers.Add(ts); + // } + //} + //Timers.Clear(); + //Timers = NewTimers; + //} } public void CheckTimerEvents() @@ -198,15 +213,17 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase foreach (TimerClass ts in Timers) { // Time has passed? - if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime()) + if (ts.next < DateTime.Now.Ticks) { + + Console.WriteLine("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next); // Add it to queue - m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "timer", EventQueueManager.llDetectNull, - new object[] {}); + m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "timer", EventQueueManager.llDetectNull, + null); // set next interval - - ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); + //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); + ts.next = DateTime.Now.Ticks + ts.interval; } } } // lock @@ -322,7 +339,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase } - + } } @@ -356,7 +373,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase ); } - } + } } } -- cgit v1.1