aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/SceneGraph.cs
diff options
context:
space:
mode:
authorMelanie2010-03-30 21:34:27 +0100
committerMelanie2010-03-30 21:34:27 +0100
commit5693870fe26fae35a28f2d5103780434f4f40e57 (patch)
tree0e070fb6f11ab8763ac4f1f9a851a0061101d4d6 /OpenSim/Region/Framework/Scenes/SceneGraph.cs
parentMerge branch 'careminster-presence-refactor' of ssh://3dhosting.de/var/git/ca... (diff)
parentminor: commented out code removal (diff)
downloadopensim-SC_OLD-5693870fe26fae35a28f2d5103780434f4f40e57.zip
opensim-SC_OLD-5693870fe26fae35a28f2d5103780434f4f40e57.tar.gz
opensim-SC_OLD-5693870fe26fae35a28f2d5103780434f4f40e57.tar.bz2
opensim-SC_OLD-5693870fe26fae35a28f2d5103780434f4f40e57.tar.xz
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneGraph.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneGraph.cs186
1 files changed, 79 insertions, 107 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index 19298d2..3a1962c 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -723,116 +723,84 @@ namespace OpenSim.Region.Framework.Scenes
723 return null; 723 return null;
724 } 724 }
725 725
726 // The idea is to have a group of method that return a list of avatars meeting some requirement
727 // ie it could be all m_scenePresences within a certain range of the calling prim/avatar.
728 //
729 // GetAvatars returns a new list of all root agent presences in the scene
730 // GetScenePresences returns a new list of all presences in the scene or a filter may be passed.
731 // GetScenePresence returns the presence with matching UUID or the first presence matching the passed filter.
732 // ForEachScenePresence requests the Scene to run a delegate function against all presences.
733
734 /// <summary> 726 /// <summary>
735 /// Request a list of all avatars in this region (no child agents) 727 /// Request a copy of m_scenePresences in this World
736 /// This list is a new object, so it can be iterated over without locking. 728 /// There is no guarantee that presences will remain in the scene after the list is returned.
729 /// This list should remain private to SceneGraph. Callers wishing to iterate should instead
730 /// pass a delegate to ForEachScenePresence.
737 /// </summary> 731 /// </summary>
738 /// <returns></returns> 732 /// <returns></returns>
739 public List<ScenePresence> GetAvatars() 733 private List<ScenePresence> GetScenePresences()
740 { 734 {
741 return GetScenePresences(delegate(ScenePresence scenePresence) 735 lock (m_scenePresences)
742 { 736 return new List<ScenePresence>(m_scenePresenceArray);
743 return !scenePresence.IsChildAgent;
744 });
745 } 737 }
746 738
747 /// <summary> 739 /// <summary>
748 /// Request a list of m_scenePresences in this World 740 /// Request a scene presence by UUID. Fast, indexed lookup.
749 /// Returns a copy so it can be iterated without a lock.
750 /// There is no guarantee that presences will remain in the scene after the list is returned.
751 /// </summary> 741 /// </summary>
752 /// <returns></returns> 742 /// <param name="agentID"></param>
753 protected internal List<ScenePresence> GetScenePresences() 743 /// <returns>null if the presence was not found</returns>
744 protected internal ScenePresence GetScenePresence(UUID agentID)
754 { 745 {
755 List<ScenePresence> result; 746 ScenePresence sp;
756 lock (m_scenePresences) 747 lock (m_scenePresences)
757 { 748 {
758 result = new List<ScenePresence>(m_scenePresenceArray.Length); 749 m_scenePresences.TryGetValue(agentID, out sp);
759 result.AddRange(m_scenePresenceArray);
760 } 750 }
761 return result; 751 return sp;
762 } 752 }
763 753
764 /// <summary> 754 /// <summary>
765 /// Request a filtered list of m_scenePresences in this World 755 /// Request the scene presence by name.
766 /// Returns a copy so it can be iterated without a lock.
767 /// There is no guarantee that presences will remain in the scene after the list is returned.
768 /// </summary> 756 /// </summary>
769 /// <returns></returns> 757 /// <param name="firstName"></param>
770 protected internal List<ScenePresence> GetScenePresences(FilterAvatarList filter) 758 /// <param name="lastName"></param>
759 /// <returns>null if the presence was not found</returns>
760 protected internal ScenePresence GetScenePresence(string firstName, string lastName)
771 { 761 {
772 List<ScenePresence> result = new List<ScenePresence>(); 762 foreach (ScenePresence presence in GetScenePresences())
773 // Check each ScenePresence against the filter
774 ForEachScenePresence(delegate(ScenePresence presence)
775 { 763 {
776 if (filter(presence)) 764 if (presence.Firstname == firstName && presence.Lastname == lastName)
777 result.Add(presence); 765 return presence;
778 }); 766 }
779 return result; 767 return null;
780 } 768 }
781 769
782 /// <summary> 770 /// <summary>
783 /// Request the ScenePresence in this region matching filter. 771 /// Request the scene presence by localID.
784 /// Only the first match is returned.
785 ///
786 /// </summary> 772 /// </summary>
787 /// <param name="filter"></param> 773 /// <param name="localID"></param>
788 /// <returns></returns> 774 /// <returns>null if the presence was not found</returns>
789 protected internal ScenePresence GetScenePresence(FilterAvatarList filter) 775 protected internal ScenePresence GetScenePresence(uint localID)
790 { 776 {
791 ScenePresence result = null; 777 foreach (ScenePresence presence in GetScenePresences())
792 // Get all of the ScenePresences 778 if (presence.LocalId == localID)
793 List<ScenePresence> presences = GetScenePresences(); 779 return presence;
794 foreach (ScenePresence presence in presences) 780 return null;
795 {
796 if (filter(presence))
797 {
798 result = presence;
799 break;
800 }
801 }
802 return result;
803 } 781 }
804 782
805 protected internal ScenePresence GetScenePresence(string firstName, string lastName) 783 protected internal bool TryGetScenePresence(UUID agentID, out ScenePresence avatar)
806 { 784 {
807 return GetScenePresence(delegate(ScenePresence presence) 785 lock (m_scenePresences)
808 { 786 {
809 return(presence.Firstname == firstName && presence.Lastname == lastName); 787 m_scenePresences.TryGetValue(agentID, out avatar);
810 }); 788 }
811 } 789 return (avatar != null);
812
813 /// <summary>
814 /// Request a scene presence by UUID
815 /// </summary>
816 /// <param name="agentID"></param>
817 /// <returns>null if the agent was not found</returns>
818 protected internal ScenePresence GetScenePresence(UUID agentID)
819 {
820 ScenePresence sp;
821 TryGetAvatar(agentID, out sp);
822 return sp;
823 } 790 }
824 791
825 /// <summary> 792 protected internal bool TryGetAvatarByName(string name, out ScenePresence avatar)
826 /// Request the ScenePresence in this region by localID.
827 /// </summary>
828 /// <param name="localID"></param>
829 /// <returns></returns>
830 protected internal ScenePresence GetScenePresence(uint localID)
831 { 793 {
832 return GetScenePresence(delegate(ScenePresence presence) 794 avatar = null;
795 foreach (ScenePresence presence in GetScenePresences())
833 { 796 {
834 return (presence.LocalId == localID); 797 if (String.Compare(name, presence.ControllingClient.Name, true) == 0)
835 }); 798 {
799 avatar = presence;
800 break;
801 }
802 }
803 return (avatar != null);
836 } 804 }
837 805
838 /// <summary> 806 /// <summary>
@@ -986,24 +954,6 @@ namespace OpenSim.Region.Framework.Scenes
986 return group.GetChildPart(fullID); 954 return group.GetChildPart(fullID);
987 } 955 }
988 956
989 protected internal bool TryGetAvatar(UUID avatarId, out ScenePresence avatar)
990 {
991 lock (m_scenePresences)
992 {
993 m_scenePresences.TryGetValue(avatarId, out avatar);
994 }
995 return (avatar != null);
996 }
997
998 protected internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
999 {
1000 avatar = GetScenePresence(delegate(ScenePresence presence)
1001 {
1002 return (String.Compare(avatarName, presence.ControllingClient.Name, true) == 0);
1003 });
1004 return (avatar != null);
1005 }
1006
1007 /// <summary> 957 /// <summary>
1008 /// Returns a list of the entities in the scene. This is a new list so no locking is required to iterate over 958 /// Returns a list of the entities in the scene. This is a new list so no locking is required to iterate over
1009 /// it 959 /// it
@@ -1066,6 +1016,10 @@ namespace OpenSim.Region.Framework.Scenes
1066 return UUID.Zero; 1016 return UUID.Zero;
1067 } 1017 }
1068 1018
1019 /// <summary>
1020 /// Performs action on all scene object groups.
1021 /// </summary>
1022 /// <param name="action"></param>
1069 protected internal void ForEachSOG(Action<SceneObjectGroup> action) 1023 protected internal void ForEachSOG(Action<SceneObjectGroup> action)
1070 { 1024 {
1071 List<SceneObjectGroup> objlist = new List<SceneObjectGroup>(SceneObjectGroupsByFullID.Values); 1025 List<SceneObjectGroup> objlist = new List<SceneObjectGroup>(SceneObjectGroupsByFullID.Values);
@@ -1085,23 +1039,41 @@ namespace OpenSim.Region.Framework.Scenes
1085 1039
1086 1040
1087 /// <summary> 1041 /// <summary>
1088 /// Performs action on all scene presences. 1042 /// Performs action on all scene presences. This can ultimately run the actions in parallel but
1043 /// any delegates passed in will need to implement their own locking on data they reference and
1044 /// modify outside of the scope of the delegate.
1089 /// </summary> 1045 /// </summary>
1090 /// <param name="action"></param> 1046 /// <param name="action"></param>
1091 public void ForEachScenePresence(Action<ScenePresence> action) 1047 public void ForEachScenePresence(Action<ScenePresence> action)
1092 { 1048 {
1093 List<ScenePresence> presences = GetScenePresences(); 1049 // Once all callers have their delegates configured for parallelism, we can unleash this
1094 try 1050 /*
1051 Action<ScenePresence> protectedAction = new Action<ScenePresence>(delegate(ScenePresence sp)
1052 {
1053 try
1054 {
1055 action(sp);
1056 }
1057 catch (Exception e)
1058 {
1059 m_log.Info("[BUG] in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString());
1060 m_log.Info("[BUG] Stack Trace: " + e.StackTrace);
1061 }
1062 });
1063 Parallel.ForEach<ScenePresence>(GetScenePresences(), protectedAction);
1064 */
1065 // For now, perform actiona serially
1066 foreach (ScenePresence sp in GetScenePresences())
1095 { 1067 {
1096 foreach(ScenePresence presence in presences) 1068 try
1097 { 1069 {
1098 action(presence); 1070 action(sp);
1071 }
1072 catch (Exception e)
1073 {
1074 m_log.Info("[BUG] in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString());
1075 m_log.Info("[BUG] Stack Trace: " + e.StackTrace);
1099 } 1076 }
1100 }
1101 catch (Exception e)
1102 {
1103 m_log.Info("[BUG] in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString());
1104 m_log.Info("[BUG] Stack Trace: " + e.StackTrace);
1105 } 1077 }
1106 } 1078 }
1107 1079