diff options
author | Dan Lake | 2010-03-19 05:51:16 -0700 |
---|---|---|
committer | John Hurliman | 2010-03-19 15:16:35 -0700 |
commit | 859bc717a4fe4cd5810ad9889cfb9b1e7f5c2046 (patch) | |
tree | dcce6c74d201b52c1a04ec9ec2cb90ce068fc020 /OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins | |
parent | Inconsistent locking of ScenePresence array in SceneGraph. Fixed by eliminati... (diff) | |
download | opensim-SC_OLD-859bc717a4fe4cd5810ad9889cfb9b1e7f5c2046.zip opensim-SC_OLD-859bc717a4fe4cd5810ad9889cfb9b1e7f5c2046.tar.gz opensim-SC_OLD-859bc717a4fe4cd5810ad9889cfb9b1e7f5c2046.tar.bz2 opensim-SC_OLD-859bc717a4fe4cd5810ad9889cfb9b1e7f5c2046.tar.xz |
Cleaned up access to scenepresences in scenegraph. GetScenePresences and GetAvatars have been removed to consolidate locking and iteration within SceneGraph. All callers which used these to then iterate over presences have been refactored to instead pass their delegates to Scene.ForEachScenePresence(Action<ScenePresence>).
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs | 93 |
1 files changed, 36 insertions, 57 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index 829fbb7..6cbf260 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs | |||
@@ -404,70 +404,40 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
404 | 404 | ||
405 | private List<SensedEntity> doAgentSensor(SenseRepeatClass ts) | 405 | private List<SensedEntity> doAgentSensor(SenseRepeatClass ts) |
406 | { | 406 | { |
407 | List<ScenePresence> presences; | ||
408 | List<SensedEntity> sensedEntities = new List<SensedEntity>(); | 407 | List<SensedEntity> sensedEntities = new List<SensedEntity>(); |
409 | 408 | ||
410 | // If this is an avatar sense by key try to get them directly | ||
411 | // rather than getting a list to scan through | ||
412 | if (ts.keyID != UUID.Zero) | ||
413 | { | ||
414 | ScenePresence p = m_CmdManager.m_ScriptEngine.World.GetScenePresence(ts.keyID); | ||
415 | if (p == null) | ||
416 | return sensedEntities; | ||
417 | presences = new List<ScenePresence>(); | ||
418 | presences.Add(p); | ||
419 | } | ||
420 | else | ||
421 | { | ||
422 | presences = new List<ScenePresence>(m_CmdManager.m_ScriptEngine.World.GetScenePresences()); | ||
423 | } | ||
424 | |||
425 | // If nobody about quit fast | 409 | // If nobody about quit fast |
426 | if (presences.Count == 0) | 410 | if(m_CmdManager.m_ScriptEngine.World.GetRootAgentCount() == 0) |
427 | return sensedEntities; | 411 | return sensedEntities; |
428 | 412 | ||
429 | SceneObjectPart SensePoint = ts.host; | 413 | SceneObjectPart SensePoint = ts.host; |
430 | |||
431 | Vector3 fromRegionPos = SensePoint.AbsolutePosition; | 414 | Vector3 fromRegionPos = SensePoint.AbsolutePosition; |
432 | |||
433 | Quaternion q = SensePoint.RotationOffset; | 415 | Quaternion q = SensePoint.RotationOffset; |
434 | LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); | 416 | LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); |
435 | LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); | 417 | LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); |
436 | double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); | 418 | double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); |
437 | |||
438 | bool attached = (SensePoint.AttachmentPoint != 0); | 419 | bool attached = (SensePoint.AttachmentPoint != 0); |
439 | bool nameSearch = (ts.name != null && ts.name != ""); | ||
440 | Vector3 toRegionPos; | 420 | Vector3 toRegionPos; |
441 | double dis; | 421 | double dis; |
442 | 422 | ||
443 | for (int i = 0; i < presences.Count; i++) | 423 | Action<ScenePresence> senseEntity = new Action<ScenePresence>(delegate(ScenePresence presence) |
444 | { | 424 | { |
445 | ScenePresence presence = presences[i]; | 425 | if (presence.IsDeleted || presence.IsChildAgent || presence.GodLevel > 0.0) |
446 | bool keep = true; | 426 | return; |
427 | |||
428 | // if the object the script is in is attached and the avatar is the owner | ||
429 | // then this one is not wanted | ||
430 | if (attached && presence.UUID == SensePoint.OwnerID) | ||
431 | return; | ||
447 | 432 | ||
448 | if (presence.IsDeleted) | ||
449 | continue; | ||
450 | |||
451 | if (presence.IsChildAgent) | ||
452 | keep = false; | ||
453 | toRegionPos = presence.AbsolutePosition; | 433 | toRegionPos = presence.AbsolutePosition; |
454 | |||
455 | dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos)); | 434 | dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos)); |
456 | 435 | ||
457 | // are they in range | 436 | // are they in range |
458 | if (keep && dis <= ts.range) | 437 | if (dis <= ts.range) |
459 | { | 438 | { |
460 | // if the object the script is in is attached and the avatar is the owner | ||
461 | // then this one is not wanted | ||
462 | if (attached && presence.UUID == SensePoint.OwnerID) | ||
463 | keep = false; | ||
464 | |||
465 | // check the name if needed | ||
466 | if (keep && nameSearch && ts.name != presence.Name) | ||
467 | keep = false; | ||
468 | |||
469 | // Are they in the required angle of view | 439 | // Are they in the required angle of view |
470 | if (keep && ts.arc < Math.PI) | 440 | if (ts.arc < Math.PI) |
471 | { | 441 | { |
472 | // not omni-directional. Can you see it ? | 442 | // not omni-directional. Can you see it ? |
473 | // vec forward_dir = llRot2Fwd(llGetRot()) | 443 | // vec forward_dir = llRot2Fwd(llGetRot()) |
@@ -488,26 +458,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
488 | catch | 458 | catch |
489 | { | 459 | { |
490 | } | 460 | } |
491 | if (ang_obj > ts.arc) keep = false; | 461 | if (ang_obj <= ts.arc) |
462 | { | ||
463 | sensedEntities.Add(new SensedEntity(dis, presence.UUID)); | ||
464 | } | ||
492 | } | 465 | } |
493 | } | 466 | } |
494 | else | 467 | }); |
495 | { | ||
496 | keep = false; | ||
497 | } | ||
498 | 468 | ||
499 | // Do not report gods, not even minor ones | 469 | // If this is an avatar sense by key try to get them directly |
500 | if (keep && presence.GodLevel > 0.0) | 470 | // rather than getting a list to scan through |
501 | keep = false; | 471 | if (ts.keyID != UUID.Zero) |
502 | 472 | { | |
503 | if (keep) // add to list with distance | 473 | ScenePresence sp; |
504 | { | 474 | // Try direct lookup by UUID |
505 | sensedEntities.Add(new SensedEntity(dis, presence.UUID)); | 475 | if(!m_CmdManager.m_ScriptEngine.World.TryGetAvatar(ts.keyID, out sp)) |
506 | } | ||
507 | |||
508 | // If this is a search by name and we have just found it then no more to do | ||
509 | if (nameSearch && ts.name == presence.Name) | ||
510 | return sensedEntities; | 476 | return sensedEntities; |
477 | senseEntity(sp); | ||
478 | } | ||
479 | else if (ts.name != null && ts.name != "") | ||
480 | { | ||
481 | ScenePresence sp; | ||
482 | // Try lookup by name will return if/when found | ||
483 | if (!m_CmdManager.m_ScriptEngine.World.TryGetAvatarByName(ts.name, out sp)) | ||
484 | return sensedEntities; | ||
485 | senseEntity(sp); | ||
486 | } | ||
487 | else | ||
488 | { | ||
489 | m_CmdManager.m_ScriptEngine.World.ForEachScenePresence(senseEntity); | ||
511 | } | 490 | } |
512 | return sensedEntities; | 491 | return sensedEntities; |
513 | } | 492 | } |