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