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/CoreModules/World/WorldMap/WorldMapModule.cs | |
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 '')
-rw-r--r-- | OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs | 87 |
1 files changed, 21 insertions, 66 deletions
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs index b63d014..f1cc0dd 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs | |||
@@ -304,25 +304,11 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
304 | /// <param name="AgentId">AgentID that logged out</param> | 304 | /// <param name="AgentId">AgentID that logged out</param> |
305 | private void ClientLoggedOut(UUID AgentId, Scene scene) | 305 | private void ClientLoggedOut(UUID AgentId, Scene scene) |
306 | { | 306 | { |
307 | List<ScenePresence> presences = m_scene.GetAvatars(); | ||
308 | int rootcount = 0; | ||
309 | for (int i=0;i<presences.Count;i++) | ||
310 | { | ||
311 | if (presences[i] != null) | ||
312 | { | ||
313 | if (!presences[i].IsChildAgent) | ||
314 | rootcount++; | ||
315 | } | ||
316 | } | ||
317 | if (rootcount <= 1) | ||
318 | StopThread(); | ||
319 | |||
320 | lock (m_rootAgents) | 307 | lock (m_rootAgents) |
321 | { | 308 | { |
322 | if (m_rootAgents.Contains(AgentId)) | 309 | m_rootAgents.Remove(AgentId); |
323 | { | 310 | if(m_rootAgents.Count == 0) |
324 | m_rootAgents.Remove(AgentId); | 311 | StopThread(); |
325 | } | ||
326 | } | 312 | } |
327 | } | 313 | } |
328 | #endregion | 314 | #endregion |
@@ -375,11 +361,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
375 | if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle) | 361 | if (regionhandle == 0 || regionhandle == m_scene.RegionInfo.RegionHandle) |
376 | { | 362 | { |
377 | // Local Map Item Request | 363 | // Local Map Item Request |
378 | List<ScenePresence> avatars = m_scene.GetAvatars(); | ||
379 | int tc = Environment.TickCount; | 364 | int tc = Environment.TickCount; |
380 | List<mapItemReply> mapitems = new List<mapItemReply>(); | 365 | List<mapItemReply> mapitems = new List<mapItemReply>(); |
381 | mapItemReply mapitem = new mapItemReply(); | 366 | mapItemReply mapitem = new mapItemReply(); |
382 | if (avatars.Count == 0 || avatars.Count == 1) | 367 | if (m_scene.GetRootAgentCount() <= 1) |
383 | { | 368 | { |
384 | mapitem = new mapItemReply(); | 369 | mapitem = new mapItemReply(); |
385 | mapitem.x = (uint)(xstart + 1); | 370 | mapitem.x = (uint)(xstart + 1); |
@@ -392,21 +377,21 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
392 | } | 377 | } |
393 | else | 378 | else |
394 | { | 379 | { |
395 | foreach (ScenePresence av in avatars) | 380 | m_scene.ForEachScenePresence(delegate(ScenePresence sp) |
396 | { | 381 | { |
397 | // Don't send a green dot for yourself | 382 | // Don't send a green dot for yourself |
398 | if (av.UUID != remoteClient.AgentId) | 383 | if (!sp.IsChildAgent && sp.UUID != remoteClient.AgentId) |
399 | { | 384 | { |
400 | mapitem = new mapItemReply(); | 385 | mapitem = new mapItemReply(); |
401 | mapitem.x = (uint)(xstart + av.AbsolutePosition.X); | 386 | mapitem.x = (uint)(xstart + sp.AbsolutePosition.X); |
402 | mapitem.y = (uint)(ystart + av.AbsolutePosition.Y); | 387 | mapitem.y = (uint)(ystart + sp.AbsolutePosition.Y); |
403 | mapitem.id = UUID.Zero; | 388 | mapitem.id = UUID.Zero; |
404 | mapitem.name = Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()); | 389 | mapitem.name = Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString()); |
405 | mapitem.Extra = 1; | 390 | mapitem.Extra = 1; |
406 | mapitem.Extra2 = 0; | 391 | mapitem.Extra2 = 0; |
407 | mapitems.Add(mapitem); | 392 | mapitems.Add(mapitem); |
408 | } | 393 | } |
409 | } | 394 | }); |
410 | } | 395 | } |
411 | remoteClient.SendMapItemReply(mapitems.ToArray(), itemtype, flags); | 396 | remoteClient.SendMapItemReply(mapitems.ToArray(), itemtype, flags); |
412 | } | 397 | } |
@@ -981,51 +966,35 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
981 | Utils.LongToUInts(m_scene.RegionInfo.RegionHandle,out xstart,out ystart); | 966 | Utils.LongToUInts(m_scene.RegionInfo.RegionHandle,out xstart,out ystart); |
982 | 967 | ||
983 | OSDMap responsemap = new OSDMap(); | 968 | OSDMap responsemap = new OSDMap(); |
984 | List<ScenePresence> avatars = m_scene.GetAvatars(); | ||
985 | OSDArray responsearr = new OSDArray(avatars.Count); | ||
986 | OSDMap responsemapdata = new OSDMap(); | ||
987 | int tc = Environment.TickCount; | 969 | int tc = Environment.TickCount; |
988 | /* | 970 | if (m_scene.GetRootAgentCount() == 0) |
989 | foreach (ScenePresence av in avatars) | ||
990 | { | ||
991 | responsemapdata = new OSDMap(); | ||
992 | responsemapdata["X"] = OSD.FromInteger((int)(xstart + av.AbsolutePosition.X)); | ||
993 | responsemapdata["Y"] = OSD.FromInteger((int)(ystart + av.AbsolutePosition.Y)); | ||
994 | responsemapdata["ID"] = OSD.FromUUID(UUID.Zero); | ||
995 | responsemapdata["Name"] = OSD.FromString("TH"); | ||
996 | responsemapdata["Extra"] = OSD.FromInteger(0); | ||
997 | responsemapdata["Extra2"] = OSD.FromInteger(0); | ||
998 | responsearr.Add(responsemapdata); | ||
999 | } | ||
1000 | responsemap["1"] = responsearr; | ||
1001 | */ | ||
1002 | if (avatars.Count == 0) | ||
1003 | { | 971 | { |
1004 | responsemapdata = new OSDMap(); | 972 | OSDMap responsemapdata = new OSDMap(); |
1005 | responsemapdata["X"] = OSD.FromInteger((int)(xstart + 1)); | 973 | responsemapdata["X"] = OSD.FromInteger((int)(xstart + 1)); |
1006 | responsemapdata["Y"] = OSD.FromInteger((int)(ystart + 1)); | 974 | responsemapdata["Y"] = OSD.FromInteger((int)(ystart + 1)); |
1007 | responsemapdata["ID"] = OSD.FromUUID(UUID.Zero); | 975 | responsemapdata["ID"] = OSD.FromUUID(UUID.Zero); |
1008 | responsemapdata["Name"] = OSD.FromString(Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString())); | 976 | responsemapdata["Name"] = OSD.FromString(Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString())); |
1009 | responsemapdata["Extra"] = OSD.FromInteger(0); | 977 | responsemapdata["Extra"] = OSD.FromInteger(0); |
1010 | responsemapdata["Extra2"] = OSD.FromInteger(0); | 978 | responsemapdata["Extra2"] = OSD.FromInteger(0); |
979 | OSDArray responsearr = new OSDArray(); | ||
1011 | responsearr.Add(responsemapdata); | 980 | responsearr.Add(responsemapdata); |
1012 | 981 | ||
1013 | responsemap["6"] = responsearr; | 982 | responsemap["6"] = responsearr; |
1014 | } | 983 | } |
1015 | else | 984 | else |
1016 | { | 985 | { |
1017 | responsearr = new OSDArray(avatars.Count); | 986 | OSDArray responsearr = new OSDArray(m_scene.GetRootAgentCount()); |
1018 | foreach (ScenePresence av in avatars) | 987 | m_scene.ForEachScenePresence(delegate(ScenePresence sp) |
1019 | { | 988 | { |
1020 | responsemapdata = new OSDMap(); | 989 | OSDMap responsemapdata = new OSDMap(); |
1021 | responsemapdata["X"] = OSD.FromInteger((int)(xstart + av.AbsolutePosition.X)); | 990 | responsemapdata["X"] = OSD.FromInteger((int)(xstart + sp.AbsolutePosition.X)); |
1022 | responsemapdata["Y"] = OSD.FromInteger((int)(ystart + av.AbsolutePosition.Y)); | 991 | responsemapdata["Y"] = OSD.FromInteger((int)(ystart + sp.AbsolutePosition.Y)); |
1023 | responsemapdata["ID"] = OSD.FromUUID(UUID.Zero); | 992 | responsemapdata["ID"] = OSD.FromUUID(UUID.Zero); |
1024 | responsemapdata["Name"] = OSD.FromString(Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString())); | 993 | responsemapdata["Name"] = OSD.FromString(Util.Md5Hash(m_scene.RegionInfo.RegionName + tc.ToString())); |
1025 | responsemapdata["Extra"] = OSD.FromInteger(1); | 994 | responsemapdata["Extra"] = OSD.FromInteger(1); |
1026 | responsemapdata["Extra2"] = OSD.FromInteger(0); | 995 | responsemapdata["Extra2"] = OSD.FromInteger(0); |
1027 | responsearr.Add(responsemapdata); | 996 | responsearr.Add(responsemapdata); |
1028 | } | 997 | }); |
1029 | responsemap["6"] = responsearr; | 998 | responsemap["6"] = responsearr; |
1030 | } | 999 | } |
1031 | return responsemap; | 1000 | return responsemap; |
@@ -1107,25 +1076,11 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
1107 | 1076 | ||
1108 | private void MakeChildAgent(ScenePresence avatar) | 1077 | private void MakeChildAgent(ScenePresence avatar) |
1109 | { | 1078 | { |
1110 | List<ScenePresence> presences = m_scene.GetAvatars(); | ||
1111 | int rootcount = 0; | ||
1112 | for (int i = 0; i < presences.Count; i++) | ||
1113 | { | ||
1114 | if (presences[i] != null) | ||
1115 | { | ||
1116 | if (!presences[i].IsChildAgent) | ||
1117 | rootcount++; | ||
1118 | } | ||
1119 | } | ||
1120 | if (rootcount <= 1) | ||
1121 | StopThread(); | ||
1122 | |||
1123 | lock (m_rootAgents) | 1079 | lock (m_rootAgents) |
1124 | { | 1080 | { |
1125 | if (m_rootAgents.Contains(avatar.UUID)) | 1081 | m_rootAgents.Remove(avatar.UUID); |
1126 | { | 1082 | if (m_rootAgents.Count == 0) |
1127 | m_rootAgents.Remove(avatar.UUID); | 1083 | StopThread(); |
1128 | } | ||
1129 | } | 1084 | } |
1130 | } | 1085 | } |
1131 | 1086 | ||