SensorRepeat.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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 OpenSimulator 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. using System;
  28. using System.Collections.Generic;
  29. using System.Linq;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. //using log4net;
  33. using OpenSim.Region.Framework.Interfaces;
  34. using OpenSim.Region.Framework.Scenes;
  35. namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
  36. {
  37. public class SensorRepeat
  38. {
  39. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  40. /// <summary>
  41. /// Used by one-off and repeated sensors
  42. /// </summary>
  43. public class SensorInfo
  44. {
  45. public uint localID;
  46. public UUID itemID;
  47. public double interval;
  48. public DateTime next;
  49. public string name;
  50. public UUID keyID;
  51. public int type;
  52. public float range;
  53. public float arc;
  54. public SceneObjectPart host;
  55. public SensorInfo Clone()
  56. {
  57. return (SensorInfo)MemberwiseClone();
  58. }
  59. }
  60. public AsyncCommandManager m_CmdManager;
  61. /// <summary>
  62. /// Number of sensors active.
  63. /// </summary>
  64. public int SensorsCount
  65. {
  66. get
  67. {
  68. return SenseRepeaters.Count;
  69. }
  70. }
  71. public SensorRepeat(AsyncCommandManager CmdManager)
  72. {
  73. m_CmdManager = CmdManager;
  74. maximumRange = CmdManager.m_ScriptEngine.Config.GetFloat("SensorMaxRange", 96.0f);
  75. maximumToReturn = CmdManager.m_ScriptEngine.Config.GetInt("SensorMaxResults", 16);
  76. m_npcModule = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface<INPCModule>();
  77. }
  78. private readonly INPCModule m_npcModule;
  79. private readonly object SenseLock = new();
  80. private const int AGENT = 1;
  81. private const int AGENT_BY_USERNAME = 0x10;
  82. private const int NPC = 0x20;
  83. private const int ACTIVE = 2;
  84. private const int PASSIVE = 4;
  85. private const int SCRIPTED = 8;
  86. private readonly float maximumRange = 96.0f;
  87. private readonly int maximumToReturn = 16;
  88. //
  89. // Sensed entity
  90. //
  91. private class SensedEntity : IComparable
  92. {
  93. public SensedEntity(float detectedDistance, UUID detectedID)
  94. {
  95. distance = detectedDistance;
  96. itemID = detectedID;
  97. }
  98. public int CompareTo(object obj)
  99. {
  100. if (obj is not SensedEntity ent)
  101. throw new InvalidOperationException();
  102. if (ent.distance < distance) return 1;
  103. if (ent.distance > distance) return -1;
  104. return 0;
  105. }
  106. public UUID itemID;
  107. public float distance;
  108. }
  109. /// <summary>
  110. /// Sensors to process.
  111. /// </summary>
  112. /// <remarks>
  113. /// Always lock SenseRepeatListLock when updating this list.
  114. /// </remarks>
  115. private List<SensorInfo> SenseRepeaters = new();
  116. private readonly object SenseRepeatListLock = new();
  117. public void SetSenseRepeatEvent(uint m_localID, UUID m_itemID,
  118. string name, UUID keyID, int type, double range,
  119. double arc, double sec, SceneObjectPart host)
  120. {
  121. // Always remove first, in case this is a re-set
  122. UnSetSenseRepeaterEvents(m_localID, m_itemID);
  123. if (sec == 0) // Disabling timer
  124. return;
  125. float frange = (float)range;
  126. // Add to timer
  127. SensorInfo ts = new()
  128. {
  129. localID = m_localID,
  130. itemID = m_itemID,
  131. interval = sec,
  132. next = DateTime.UtcNow.AddSeconds(sec),
  133. name = name,
  134. keyID = keyID,
  135. type = type,
  136. range = frange >= maximumRange ? maximumRange : frange,
  137. arc = (float)arc,
  138. host = host
  139. };
  140. AddSenseRepeater(ts);
  141. }
  142. private void AddSenseRepeater(SensorInfo senseRepeater)
  143. {
  144. lock (SenseRepeatListLock)
  145. SenseRepeaters.Add(senseRepeater);
  146. }
  147. public void UnSetSenseRepeaterEvents(uint m_localID, UUID m_itemID)
  148. {
  149. // Remove from timer
  150. lock (SenseRepeatListLock)
  151. {
  152. List<SensorInfo> newSenseRepeaters = new(SenseRepeaters.Count);
  153. foreach (SensorInfo ts in SenseRepeaters)
  154. {
  155. if (ts.localID != m_localID || ts.itemID.NotEqual(m_itemID))
  156. {
  157. newSenseRepeaters.Add(ts);
  158. }
  159. }
  160. SenseRepeaters = newSenseRepeaters;
  161. }
  162. }
  163. public void CheckSenseRepeaterEvents()
  164. {
  165. // Go through all timers
  166. List<SensorInfo> curSensors;
  167. lock(SenseRepeatListLock)
  168. curSensors = SenseRepeaters;
  169. DateTime now = DateTime.UtcNow;
  170. foreach (SensorInfo ts in curSensors)
  171. {
  172. if(ts.interval == 0)
  173. {
  174. SensorSweep(ts);
  175. lock (SenseRepeatListLock)
  176. SenseRepeaters.Remove(ts);
  177. }
  178. // Time has passed?
  179. else if (ts.next < now)
  180. {
  181. SensorSweep(ts);
  182. // set next interval
  183. ts.next = now.AddSeconds(ts.interval);
  184. }
  185. }
  186. }
  187. public void SenseOnce(uint m_localID, UUID m_itemID,
  188. string name, UUID keyID, int type,
  189. double range, double arc, SceneObjectPart host)
  190. {
  191. float frange = (float)range;
  192. // Add to timer
  193. SensorInfo ts = new()
  194. {
  195. localID = m_localID,
  196. itemID = m_itemID,
  197. interval = 0,
  198. name = name,
  199. keyID = keyID,
  200. type = type,
  201. range = frange >= maximumRange ? maximumRange : frange,
  202. arc = (float)arc,
  203. host = host
  204. };
  205. AddSenseRepeater(ts);
  206. }
  207. private void SensorSweep(SensorInfo ts)
  208. {
  209. if (ts.host is null)
  210. return;
  211. List<SensedEntity> sensedEntities = new();
  212. // Is the sensor type is AGENT and not SCRIPTED then include agents
  213. if ((ts.type & (AGENT | AGENT_BY_USERNAME | NPC)) != 0 && (ts.type & SCRIPTED) == 0)
  214. {
  215. sensedEntities.AddRange(doAgentSensor(ts));
  216. }
  217. // If SCRIPTED or PASSIVE or ACTIVE check objects
  218. if ((ts.type & SCRIPTED) != 0 || (ts.type & PASSIVE) != 0 || (ts.type & ACTIVE) != 0)
  219. {
  220. sensedEntities.AddRange(doObjectSensor(ts));
  221. }
  222. lock (SenseLock)
  223. {
  224. if (sensedEntities.Count == 0)
  225. {
  226. // send a "no_sensor"
  227. // Add it to queue
  228. m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
  229. new EventParams("no_sensor", Array.Empty<object>(),
  230. Array.Empty<DetectParams>()));
  231. }
  232. else
  233. {
  234. // Sort the list to get everything ordered by distance
  235. sensedEntities.Sort();
  236. int count = sensedEntities.Count;
  237. int idx;
  238. List<DetectParams> detected = new();
  239. for (idx = 0; idx < count; idx++)
  240. {
  241. try
  242. {
  243. DetectParams detect = new()
  244. {
  245. Key = sensedEntities[idx].itemID
  246. };
  247. detect.Populate(m_CmdManager.m_ScriptEngine.World);
  248. detected.Add(detect);
  249. }
  250. catch (Exception)
  251. {
  252. // Ignore errors, the object has been deleted or the avatar has gone and
  253. // there was a problem in detect.Populate so nothing added to the list
  254. }
  255. if (detected.Count == maximumToReturn)
  256. break;
  257. }
  258. if (detected.Count == 0)
  259. {
  260. // To get here with zero in the list there must have been some sort of problem
  261. // like the object being deleted or the avatar leaving to have caused some
  262. // difficulty during the Populate above so fire a no_sensor event
  263. m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
  264. new EventParams("no_sensor", Array.Empty<object>(),
  265. Array.Empty<DetectParams>()));
  266. }
  267. else
  268. {
  269. m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
  270. new EventParams("sensor",
  271. new Object[] {new LSL_Types.LSLInteger(detected.Count) },
  272. detected.ToArray()));
  273. }
  274. }
  275. }
  276. }
  277. private List<SensedEntity> doObjectSensor(SensorInfo ts)
  278. {
  279. List<EntityBase> Entities;
  280. List<SensedEntity> sensedEntities = new();
  281. // If this is an object sense by key try to get it directly
  282. // rather than getting a list to scan through
  283. if (ts.keyID.IsNotZero())
  284. {
  285. m_CmdManager.m_ScriptEngine.World.Entities.TryGetValue(ts.keyID, out EntityBase e);
  286. if (e is null)
  287. return sensedEntities;
  288. Entities = new List<EntityBase> { e };
  289. }
  290. else
  291. {
  292. Entities = new List<EntityBase>(m_CmdManager.m_ScriptEngine.World.GetEntities());
  293. }
  294. SceneObjectPart sensorPart = ts.host;
  295. bool doarc = ts.arc < MathF.PI;
  296. // pre define some things to avoid repeated definitions in the loop body
  297. float dis;
  298. int objtype;
  299. SceneObjectPart part;
  300. Vector3 fromRegionPos;
  301. Vector3 forward_dir;
  302. float mag_fwd; // to compensate in case rotation is not normalized
  303. if (sensorPart.ParentGroup.IsAttachment)
  304. {
  305. // In attachments, rotate the sensor cone with the
  306. // avatar rotation. This may include a nonzero elevation if
  307. // in mouselook.
  308. // This will not include the rotation and position of the
  309. // attachment point (e.g. your head when a sensor is in your
  310. // hair attached to your scull. Your hair will turn with
  311. // your head but the sensor will stay with your (global)
  312. // avatar rotation and position.
  313. // Position of a sensor in a child prim attached to an avatar
  314. // will be still wrong.
  315. ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(sensorPart.ParentGroup.AttachedAvatar);
  316. if (avatar is null)
  317. return sensedEntities;
  318. fromRegionPos = avatar.AbsolutePosition;
  319. if (doarc)
  320. {
  321. forward_dir = Vector3.UnitXRotated(avatar.Rotation);
  322. mag_fwd = forward_dir.LengthSquared();
  323. }
  324. else
  325. {
  326. forward_dir = Vector3.Zero;
  327. mag_fwd = 1;
  328. }
  329. }
  330. else
  331. {
  332. fromRegionPos = sensorPart.GetWorldPosition();
  333. if (doarc)
  334. {
  335. forward_dir = Vector3.UnitXRotated(sensorPart.GetWorldRotation());
  336. mag_fwd = forward_dir.LengthSquared();
  337. }
  338. else
  339. {
  340. forward_dir = Vector3.Zero;
  341. mag_fwd = 1;
  342. }
  343. }
  344. float rangeSQ = ts.range * ts.range;
  345. bool nameSearch = !string.IsNullOrEmpty(ts.name);
  346. foreach (EntityBase ent in Entities)
  347. {
  348. if (ent.IsDeleted) // taken so long to do this it has gone from the scene
  349. continue;
  350. if (ent is not SceneObjectGroup sog) // dont bother if it is a pesky avatar
  351. continue;
  352. if (sog.IsAttachment) // Attached so ignore
  353. continue;
  354. if (sensorPart.UUID.Equals(ent.UUID))
  355. continue;
  356. if (nameSearch && !ent.Name.Equals(ts.name))
  357. continue;
  358. Vector3 diff = ent.AbsolutePosition - fromRegionPos;
  359. dis = diff.LengthSquared();
  360. if(dis > rangeSQ)
  361. continue;
  362. part = sog.RootPart;
  363. objtype = 0;
  364. if (part.Inventory.ContainsScripts())
  365. {
  366. objtype |= ACTIVE | SCRIPTED; // Scripted and active. It COULD have one hidden ...
  367. }
  368. else
  369. {
  370. if (ent.Velocity.IsZero())
  371. {
  372. objtype |= PASSIVE; // Passive non-moving
  373. }
  374. else
  375. {
  376. objtype |= ACTIVE; // moving so active
  377. }
  378. }
  379. if ((ts.type & objtype) == 0)
  380. continue;
  381. // Right type too, what about the other params , key and name ?
  382. if (doarc)
  383. {
  384. float mag = mag_fwd * dis;
  385. if(mag > 1e-6f)
  386. {
  387. float dot = Vector3.Dot(forward_dir, diff) / MathF.Sqrt(mag);
  388. if(dot < -1.0f)
  389. continue;
  390. if(dot < 1.0f)
  391. {
  392. if (ts.arc < MathF.Acos(dot))
  393. continue;
  394. }
  395. else if(dot > 1.00001f)
  396. continue;
  397. }
  398. }
  399. // add distance for sorting purposes later
  400. sensedEntities.Add(new SensedEntity(dis, ent.UUID));
  401. }
  402. return sensedEntities;
  403. }
  404. private List<SensedEntity> doAgentSensor(SensorInfo ts)
  405. {
  406. List<SensedEntity> sensedEntities = new();
  407. // If nobody about quit fast
  408. if (m_CmdManager.m_ScriptEngine.World.GetRootAgentCount() == 0)
  409. return sensedEntities;
  410. SceneObjectPart SensePoint = ts.host;
  411. Vector3 fromRegionPos = SensePoint.GetWorldPosition();
  412. Quaternion q;
  413. if (SensePoint.ParentGroup.IsAttachment)
  414. {
  415. // In attachments, rotate the sensor cone with the
  416. // avatar rotation. This may include a nonzero elevation if
  417. // in mouselook.
  418. // This will not include the rotation and position of the
  419. // attachment point (e.g. your head when a sensor is in your
  420. // hair attached to your scull. Your hair will turn with
  421. // your head but the sensor will stay with your (global)
  422. // avatar rotation and position.
  423. // Position of a sensor in a child prim attached to an avatar
  424. // will be still wrong.
  425. ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
  426. // Don't proceed if the avatar for this attachment has since been removed from the scene.
  427. if (avatar is null)
  428. return sensedEntities;
  429. fromRegionPos = avatar.AbsolutePosition;
  430. q = avatar.Rotation;
  431. }
  432. else
  433. q = SensePoint.GetWorldRotation();
  434. Vector3 forward_dir = Vector3.UnitXRotated(q);
  435. float mag_fwd = forward_dir.LengthSquared();
  436. bool attached = (SensePoint.ParentGroup.AttachmentPoint != 0);
  437. Vector3 toRegionPos;
  438. Action<ScenePresence> senseEntity = new(presence =>
  439. {
  440. //m_log.DebugFormat(
  441. // "[SENSOR REPEAT]: Inspecting scene presence {0}, type {1} on sensor sweep for {2}, type {3}",
  442. // presence.Name, presence.PresenceType, ts.name, ts.type);
  443. if ((ts.type & NPC) == 0 && presence.PresenceType == PresenceType.Npc)
  444. {
  445. INPC npcData = m_npcModule.GetNPC(presence.UUID, presence.Scene);
  446. if (npcData is null || !npcData.SenseAsAgent)
  447. {
  448. //m_log.DebugFormat(
  449. // "[SENSOR REPEAT]: Discarding NPC {0} from agent sense sweep for script item id {1}",
  450. // presence.Name, ts.itemID);
  451. return;
  452. }
  453. }
  454. if ((ts.type & AGENT) == 0)
  455. {
  456. if (presence.PresenceType == PresenceType.User)
  457. {
  458. return;
  459. }
  460. else
  461. {
  462. INPC npcData = m_npcModule.GetNPC(presence.UUID, presence.Scene);
  463. if (npcData is not null && npcData.SenseAsAgent)
  464. {
  465. //m_log.DebugFormat(
  466. // "[SENSOR REPEAT]: Discarding NPC {0} from non-agent sense sweep for script item id {1}",
  467. // presence.Name, ts.itemID);
  468. return;
  469. }
  470. }
  471. }
  472. if (presence.IsDeleted || presence.IsChildAgent || presence.IsViewerUIGod)
  473. return;
  474. // if the object the script is in is attached and the avatar is the owner
  475. // then this one is not wanted
  476. if (attached && presence.UUID.Equals(SensePoint.OwnerID))
  477. return;
  478. toRegionPos = presence.AbsolutePosition;
  479. float dis = Vector3.Distance(toRegionPos, fromRegionPos);
  480. if (presence.IsSatOnObject && presence.ParentPart is not null &&
  481. presence.ParentPart.ParentGroup is not null &&
  482. presence.ParentPart.ParentGroup.RootPart is not null)
  483. {
  484. Vector3 rpos = presence.ParentPart.ParentGroup.RootPart.AbsolutePosition;
  485. float dis2 = Vector3.Distance(rpos, fromRegionPos);
  486. if (dis > dis2)
  487. dis = dis2;
  488. }
  489. // Disabled for now since all osNpc* methods check for appropriate ownership permission.
  490. // Perhaps could be re-enabled as an NPC setting at some point since being able to make NPCs not
  491. // sensed might be useful.
  492. //if (presence.PresenceType == PresenceType.Npc && npcModule != null)
  493. //{
  494. // UUID npcOwner = npcModule.GetOwner(presence.UUID);
  495. // if (npcOwner != UUID.Zero && npcOwner != SensePoint.OwnerID)
  496. // return;
  497. //}
  498. // are they in range
  499. if (dis <= ts.range)
  500. {
  501. // Are they in the required angle of view
  502. if (ts.arc < MathF.PI)
  503. {
  504. // not omni-directional. Can you see it ?
  505. // vec forward_dir = llRot2Fwd(llGetRot())
  506. // vec obj_dir = toRegionPos-fromRegionPos
  507. // dot=dot(forward_dir,obj_dir)
  508. // mag_fwd = mag(forward_dir)
  509. // mag_obj = mag(obj_dir)
  510. // ang = acos(dot /(mag_fwd*mag_obj))
  511. float ang_obj = 0;
  512. try
  513. {
  514. Vector3 obj_dir = toRegionPos - fromRegionPos;
  515. float dot = Vector3.Dot(forward_dir, obj_dir);
  516. float mag_corr = MathF.Sqrt( mag_fwd * obj_dir.LengthSquared());
  517. ang_obj = MathF.Acos(dot / mag_corr);
  518. }
  519. catch
  520. {
  521. }
  522. if (ang_obj <= ts.arc)
  523. {
  524. sensedEntities.Add(new SensedEntity(dis, presence.UUID));
  525. }
  526. }
  527. else
  528. {
  529. sensedEntities.Add(new SensedEntity(dis, presence.UUID));
  530. }
  531. }
  532. });
  533. // If this is an avatar sense by key try to get them directly
  534. // rather than getting a list to scan through
  535. if (ts.keyID.IsNotZero())
  536. {
  537. // Try direct lookup by UUID
  538. if (!m_CmdManager.m_ScriptEngine.World.TryGetScenePresence(ts.keyID, out ScenePresence sp))
  539. return sensedEntities;
  540. senseEntity(sp);
  541. }
  542. else if (!string.IsNullOrEmpty(ts.name))
  543. {
  544. // Try lookup by name will return if/when found
  545. if (((ts.type & AGENT) != 0) && m_CmdManager.m_ScriptEngine.World.TryGetAvatarByName(ts.name, out ScenePresence sp))
  546. senseEntity(sp);
  547. if ((ts.type & AGENT_BY_USERNAME) != 0)
  548. {
  549. m_CmdManager.m_ScriptEngine.World.ForEachRootScenePresence(
  550. delegate (ScenePresence ssp)
  551. {
  552. if (ssp.Lastname == "Resident")
  553. {
  554. if (ssp.Firstname.ToLower() == ts.name)
  555. senseEntity(ssp);
  556. return;
  557. }
  558. if (ssp.Name.Replace(" ", ".").ToLower() == ts.name)
  559. senseEntity(ssp);
  560. }
  561. );
  562. }
  563. return sensedEntities;
  564. }
  565. else
  566. {
  567. m_CmdManager.m_ScriptEngine.World.ForEachRootScenePresence(senseEntity);
  568. }
  569. return sensedEntities;
  570. }
  571. public Object[] GetSerializationData(UUID itemID)
  572. {
  573. List<Object> data = new();
  574. foreach (SensorInfo ts in SenseRepeaters)
  575. {
  576. if (ts.itemID.Equals(itemID))
  577. {
  578. data.Add(ts.interval);
  579. data.Add(ts.name);
  580. data.Add(ts.keyID);
  581. data.Add(ts.type);
  582. data.Add(ts.range);
  583. data.Add(ts.arc);
  584. }
  585. }
  586. return data.ToArray();
  587. }
  588. public void CreateFromData(uint localID, UUID itemID, UUID objectID, object[] data)
  589. {
  590. SceneObjectPart part = m_CmdManager.m_ScriptEngine.World.GetSceneObjectPart(objectID);
  591. if (part is null)
  592. return;
  593. int idx = 0;
  594. while (idx < data.Length)
  595. {
  596. SensorInfo ts = new()
  597. {
  598. localID = localID,
  599. itemID = itemID,
  600. interval = (double)data[idx],
  601. name = (string)data[idx + 1],
  602. keyID = (UUID)data[idx + 2],
  603. type = (int)data[idx + 3],
  604. range = (float)data[idx + 4],
  605. arc = (float)data[idx + 5],
  606. host = part
  607. };
  608. ts.next = DateTime.UtcNow.AddSeconds(ts.interval);
  609. AddSenseRepeater(ts);
  610. idx += 6;
  611. }
  612. }
  613. public List<SensorInfo> GetSensorInfo()
  614. {
  615. List<SensorInfo> retList = new();
  616. lock (SenseRepeatListLock)
  617. {
  618. foreach (SensorInfo i in SenseRepeaters)
  619. retList.Add(i.Clone());
  620. }
  621. return retList;
  622. }
  623. }
  624. }