aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Timer.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Timer.cs142
1 files changed, 139 insertions, 3 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Timer.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Timer.cs
index 6bd3752..02ef1a2 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Timer.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Timer.cs
@@ -1,10 +1,146 @@
1using System; 1/*
2* Copyright (c) Contributors, http://opensimulator.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28
29using System;
30using System.Collections;
2using System.Collections.Generic; 31using System.Collections.Generic;
3using System.Text; 32using System.Threading;
33using libsecondlife;
34using Axiom.Math;
35using OpenSim.Region.Environment.Interfaces;
36using OpenSim.Region.Environment.Modules;
37using OpenSim.Region.Environment.Scenes;
38using OpenSim.Framework;
39using OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins;
4 40
5namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins 41namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins
6{ 42{
7 class Timer 43 public class Timer
8 { 44 {
45 public AsyncCommandManager m_CmdManager;
46
47 public Timer(AsyncCommandManager CmdManager)
48 {
49 m_CmdManager = CmdManager;
50 }
51
52 //
53 // TIMER
54 //
55 private class TimerClass
56 {
57 public uint localID;
58 public LLUUID itemID;
59 //public double interval;
60 public long interval;
61 //public DateTime next;
62 public long next;
63 }
64
65 private List<TimerClass> Timers = new List<TimerClass>();
66 private object TimerListLock = new object();
67
68 public void SetTimerEvent(uint m_localID, LLUUID m_itemID, double sec)
69 {
70 Console.WriteLine("SetTimerEvent");
71
72 // Always remove first, in case this is a re-set
73 UnSetTimerEvents(m_localID, m_itemID);
74 if (sec == 0) // Disabling timer
75 return;
76
77 // Add to timer
78 TimerClass ts = new TimerClass();
79 ts.localID = m_localID;
80 ts.itemID = m_itemID;
81 ts.interval = Convert.ToInt64(sec * 10000000); // How many 100 nanoseconds (ticks) should we wait
82 // 2193386136332921 ticks
83 // 219338613 seconds
84
85 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
86 ts.next = DateTime.Now.Ticks + ts.interval;
87 lock (TimerListLock)
88 {
89 Timers.Add(ts);
90 }
91 }
92
93 public void UnSetTimerEvents(uint m_localID, LLUUID m_itemID)
94 {
95 // Remove from timer
96 lock (TimerListLock)
97 {
98 foreach (TimerClass ts in new ArrayList(Timers))
99 {
100 if (ts.localID == m_localID && ts.itemID == m_itemID)
101 Timers.Remove(ts);
102 }
103 }
104
105 // Old method: Create new list
106 //List<TimerClass> NewTimers = new List<TimerClass>();
107 //foreach (TimerClass ts in Timers)
108 //{
109 // if (ts.localID != m_localID && ts.itemID != m_itemID)
110 // {
111 // NewTimers.Add(ts);
112 // }
113 //}
114 //Timers.Clear();
115 //Timers = NewTimers;
116 //}
117 }
118
119 public void CheckTimerEvents()
120 {
121 // Nothing to do here?
122 if (Timers.Count == 0)
123 return;
124
125 lock (TimerListLock)
126 {
127 // Go through all timers
128 foreach (TimerClass ts in Timers)
129 {
130 // Time has passed?
131 if (ts.next < DateTime.Now.Ticks)
132 {
133 // Console.WriteLine("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next);
134 // Add it to queue
135 m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "timer", EventQueueManager.llDetectNull,
136 null);
137 // set next interval
138
139 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
140 ts.next = DateTime.Now.Ticks + ts.interval;
141 }
142 }
143 }
144 }
9 } 145 }
10} 146}