aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/SensorRepeat.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/SensorRepeat.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/SensorRepeat.cs334
1 files changed, 0 insertions, 334 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/SensorRepeat.cs
deleted file mode 100644
index 7059a1b..0000000
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/SensorRepeat.cs
+++ /dev/null
@@ -1,334 +0,0 @@
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//#define SPAM
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Region.Environment.Scenes;
33using OpenSim.Framework.Communications.Cache;
34using OpenSim.Region.ScriptEngine.Shared;
35
36namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins
37{
38 public class SensorRepeat
39 {
40 public AsyncCommandManager m_CmdManager;
41
42 public SensorRepeat(AsyncCommandManager CmdManager)
43 {
44 m_CmdManager = CmdManager;
45 }
46
47 public Dictionary<uint, Dictionary<UUID, LSL_Types.list>> SenseEvents =
48 new Dictionary<uint, Dictionary<UUID, LSL_Types.list>>();
49 private Object SenseLock = new Object();
50
51 //
52 // SenseRepeater and Sensors
53 //
54 private class SenseRepeatClass
55 {
56 public uint localID;
57 public UUID itemID;
58 public double interval;
59 public DateTime next;
60
61 public string name;
62 public UUID keyID;
63 public int type;
64 public double range;
65 public double arc;
66 public SceneObjectPart host;
67 }
68
69 private List<SenseRepeatClass> SenseRepeaters = new List<SenseRepeatClass>();
70 private object SenseRepeatListLock = new object();
71
72 public void SetSenseRepeatEvent(uint m_localID, UUID m_itemID,
73 string name, UUID keyID, int type, double range, double arc, double sec, SceneObjectPart host)
74 {
75 #if SPAM
76 Console.WriteLine("SetSensorEvent");
77 #endif
78 // Always remove first, in case this is a re-set
79 UnSetSenseRepeaterEvents(m_localID, m_itemID);
80 if (sec == 0) // Disabling timer
81 return;
82
83 // Add to timer
84 SenseRepeatClass ts = new SenseRepeatClass();
85 ts.localID = m_localID;
86 ts.itemID = m_itemID;
87 ts.interval = sec;
88 ts.name = name;
89 ts.keyID = keyID;
90 ts.type = type;
91 ts.range = range;
92 ts.arc = arc;
93 ts.host = host;
94
95 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
96 lock (SenseRepeatListLock)
97 {
98 SenseRepeaters.Add(ts);
99 }
100 }
101
102 public void UnSetSenseRepeaterEvents(uint m_localID, UUID m_itemID)
103 {
104 // Remove from timer
105 lock (SenseRepeatListLock)
106 {
107 List<SenseRepeatClass> NewSensors = new List<SenseRepeatClass>();
108 foreach (SenseRepeatClass ts in SenseRepeaters)
109 {
110 if (ts.localID != m_localID && ts.itemID != m_itemID)
111 {
112 NewSensors.Add(ts);
113 }
114 }
115 SenseRepeaters.Clear();
116 SenseRepeaters = NewSensors;
117 }
118 }
119
120 public void CheckSenseRepeaterEvents()
121 {
122 // Nothing to do here?
123 if (SenseRepeaters.Count == 0)
124 return;
125
126 lock (SenseRepeatListLock)
127 {
128 // Go through all timers
129 foreach (SenseRepeatClass ts in SenseRepeaters)
130 {
131 // Time has passed?
132 if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime())
133 {
134 SensorSweep(ts);
135 // set next interval
136 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
137 }
138 }
139 } // lock
140 }
141
142 public void SenseOnce(uint m_localID, UUID m_itemID,
143 string name, UUID keyID, int type,
144 double range, double arc, SceneObjectPart host)
145 {
146 // Add to timer
147 SenseRepeatClass ts = new SenseRepeatClass();
148 ts.localID = m_localID;
149 ts.itemID = m_itemID;
150 ts.interval = 0;
151 ts.name = name;
152 ts.keyID = keyID;
153 ts.type = type;
154 ts.range = range;
155 ts.arc = arc;
156 ts.host = host;
157 SensorSweep(ts);
158 }
159
160 public LSL_Types.list GetSensorList(uint m_localID, UUID m_itemID)
161 {
162 lock (SenseLock)
163 {
164 Dictionary<UUID, LSL_Types.list> Obj = null;
165 if (!SenseEvents.TryGetValue(m_localID, out Obj))
166 {
167 #if SPAM
168 m_CmdManager.m_ScriptEngine.Log.Info("[AsyncLSL]: GetSensorList missing localID: " + m_localID);
169 #endif
170 return null;
171 }
172 lock (Obj)
173 {
174 // Get script
175 LSL_Types.list SenseList = null;
176 if (!Obj.TryGetValue(m_itemID, out SenseList))
177 {
178 #if SPAM
179 m_CmdManager.m_ScriptEngine.Log.Info("[AsyncLSL]: GetSensorList missing itemID: " + m_itemID);
180 #endif
181 return null;
182 }
183 return SenseList;
184 }
185 }
186 }
187
188 private void SensorSweep(SenseRepeatClass ts)
189 {
190 //m_ScriptEngine.Log.Info("[AsyncLSL]:Enter SensorSweep");
191 SceneObjectPart SensePoint = ts.host;
192
193 if (SensePoint == null)
194 {
195
196 #if SPAM
197 //m_ScriptEngine.Log.Info("[AsyncLSL]: Enter SensorSweep (SensePoint == null) for "+ts.itemID.ToString());
198 #endif
199 return;
200 }
201 //m_ScriptEngine.Log.Info("[AsyncLSL]: Enter SensorSweep Scan");
202
203 Vector3 sensorPos = SensePoint.AbsolutePosition;
204 Vector3 regionPos = new Vector3(m_CmdManager.m_ScriptEngine.World.RegionInfo.RegionLocX * Constants.RegionSize, m_CmdManager.m_ScriptEngine.World.RegionInfo.RegionLocY * Constants.RegionSize, 0);
205 Vector3 fromRegionPos = sensorPos + regionPos;
206
207 Quaternion q = SensePoint.RotationOffset;
208 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
209 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
210 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
211
212 // Here we should do some smart culling ...
213 // math seems quicker than strings so try that first
214 LSL_Types.list SensedObjects = new LSL_Types.list();
215 LSL_Types.Vector3 ZeroVector = new LSL_Types.Vector3(0, 0, 0);
216
217 foreach (EntityBase ent in m_CmdManager.m_ScriptEngine.World.Entities.Values)
218 {
219 Vector3 toRegionPos = ent.AbsolutePosition + regionPos;
220 double dis = Math.Abs((double)Util.GetDistanceTo(toRegionPos, fromRegionPos));
221 if (dis <= ts.range)
222 {
223 // In Range, is it the right Type ?
224 int objtype = 0;
225
226 if (m_CmdManager.m_ScriptEngine.World.GetScenePresence(ent.UUID) != null) objtype |= 0x01; // actor
227 if (ent.Velocity.Equals(ZeroVector))
228 objtype |= 0x04; // passive non-moving
229 else
230 objtype |= 0x02; // active moving
231 if (ent is IScript) objtype |= 0x08; // Scripted. It COULD have one hidden ...
232
233 if (((ts.type & objtype) != 0) || ((ts.type & objtype) == ts.type))
234 {
235 // docs claim AGENT|ACTIVE should find agent objects OR active objects
236 // so the bitwise AND with object type should be non-zero
237
238 // Right type too, what about the other params , key and name ?
239 bool keep = true;
240 if (ts.arc < Math.PI)
241 {
242 // not omni-directional. Can you see it ?
243 // vec forward_dir = llRot2Fwd(llGetRot())
244 // vec obj_dir = toRegionPos-fromRegionPos
245 // dot=dot(forward_dir,obj_dir)
246 // mag_fwd = mag(forward_dir)
247 // mag_obj = mag(obj_dir)
248 // ang = acos(dot /(mag_fwd*mag_obj))
249 double ang_obj = 0;
250 try
251 {
252 Vector3 diff = toRegionPos - fromRegionPos;
253 LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(diff.X, diff.Y, diff.Z);
254 double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir);
255 double mag_obj = LSL_Types.Vector3.Mag(obj_dir);
256 ang_obj = Math.Acos(dot / (mag_fwd * mag_obj));
257 }
258 catch
259 {
260 }
261
262 if (ang_obj > ts.arc) keep = false;
263 }
264
265 if (keep && (ts.keyID != UUID.Zero) && (ts.keyID != ent.UUID))
266 {
267 keep = false;
268 }
269
270 if (keep && (ts.name.Length > 0))
271 {
272 string avatarname=null;
273 string objectname=null;
274 string entname =ent.Name;
275
276 // try avatar username surname
277 CachedUserInfo profile = m_CmdManager.m_ScriptEngine.World.CommsManager.UserProfileCacheService.GetUserDetails(ent.UUID);
278 if (profile != null && profile.UserProfile != null)
279 {
280 avatarname = profile.UserProfile.FirstName + " " + profile.UserProfile.SurName;
281 }
282 // try an scene object
283 SceneObjectPart SOP = m_CmdManager.m_ScriptEngine.World.GetSceneObjectPart(ent.UUID);
284 if (SOP != null)
285 {
286 objectname = SOP.Name;
287 }
288
289 if ((ts.name != entname) && (ts.name != avatarname) && (ts.name != objectname))
290 {
291 keep = false;
292 }
293 }
294
295 if (keep == true) SensedObjects.Add(ent.UUID);
296 }
297 }
298 }
299 #if SPAM
300 //m_ScriptEngine.Log.Info("[AsyncLSL]: Enter SensorSweep SenseLock");
301 #endif
302 lock (SenseLock)
303 {
304 // Create object if it doesn't exist
305 if (SenseEvents.ContainsKey(ts.localID) == false)
306 {
307 SenseEvents.Add(ts.localID, new Dictionary<UUID, LSL_Types.list>());
308 }
309 // clear if previous traces exist
310 Dictionary<UUID, LSL_Types.list> Obj;
311 SenseEvents.TryGetValue(ts.localID, out Obj);
312 if (Obj.ContainsKey(ts.itemID) == true)
313 Obj.Remove(ts.itemID);
314
315 // note list may be zero length
316 Obj.Add(ts.itemID, SensedObjects);
317
318 if (SensedObjects.Length == 0)
319 {
320 // send a "no_sensor"
321 // Add it to queue
322 m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "no_sensor", EventQueueManager.llDetectNull,
323 new object[] { });
324 }
325 else
326 {
327 m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "sensor", EventQueueManager.llDetectNull,
328 new object[] { new LSL_Types.LSLInteger(SensedObjects.Length) });
329 }
330 m_CmdManager.m_ScriptEngine.World.EventManager.TriggerTimerEvent(ts.localID, ts.interval);
331 }
332 }
333 }
334}