aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-04-03 01:14:39 +0100
committerJustin Clark-Casey (justincc)2014-04-03 01:14:39 +0100
commit6ac9c9c97277e510cbe7eb908f3cf7883a01c1c3 (patch)
treeaf88d18d76d7212252f8c8215dd42e3e0d2b025e /OpenSim/Region/Framework/Scenes
parentminor: Fix warning in AvatarFactoryModule (diff)
downloadopensim-SC_OLD-6ac9c9c97277e510cbe7eb908f3cf7883a01c1c3.zip
opensim-SC_OLD-6ac9c9c97277e510cbe7eb908f3cf7883a01c1c3.tar.gz
opensim-SC_OLD-6ac9c9c97277e510cbe7eb908f3cf7883a01c1c3.tar.bz2
opensim-SC_OLD-6ac9c9c97277e510cbe7eb908f3cf7883a01c1c3.tar.xz
refactor: Use m_sittingAvatars to maintain the list of sitting avatars instead of two independent structures that do exactly the same thing
m_sittingAvatars code also already properly handles locking to avoid races.
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs54
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs28
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs12
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneObjectCrossingTests.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs8
5 files changed, 28 insertions, 76 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index 7ede725..529bc9f 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -121,7 +121,6 @@ namespace OpenSim.Region.Framework.Scenes
121 private bool m_hasGroupChanged = false; 121 private bool m_hasGroupChanged = false;
122 private long timeFirstChanged; 122 private long timeFirstChanged;
123 private long timeLastChanged; 123 private long timeLastChanged;
124 private List<ScenePresence> m_linkedAvatars = new List<ScenePresence>();
125 124
126 /// <summary> 125 /// <summary>
127 /// This indicates whether the object has changed such that it needs to be repersisted to permenant storage 126 /// This indicates whether the object has changed such that it needs to be repersisted to permenant storage
@@ -484,7 +483,7 @@ namespace OpenSim.Region.Framework.Scenes
484 m_rootPart.KeyframeMotion.StartCrossingCheck(); 483 m_rootPart.KeyframeMotion.StartCrossingCheck();
485 484
486 bool canCross = true; 485 bool canCross = true;
487 foreach (ScenePresence av in m_linkedAvatars) 486 foreach (ScenePresence av in GetSittingAvatars())
488 { 487 {
489 // We need to cross these agents. First, let's find 488 // We need to cross these agents. First, let's find
490 // out if any of them can't cross for some reason. 489 // out if any of them can't cross for some reason.
@@ -511,7 +510,7 @@ namespace OpenSim.Region.Framework.Scenes
511 510
512 List<avtocrossInfo> avsToCross = new List<avtocrossInfo>(); 511 List<avtocrossInfo> avsToCross = new List<avtocrossInfo>();
513 512
514 foreach (ScenePresence av in m_linkedAvatars) 513 foreach (ScenePresence av in GetSittingAvatars())
515 { 514 {
516 avtocrossInfo avinfo = new avtocrossInfo(); 515 avtocrossInfo avinfo = new avtocrossInfo();
517 SceneObjectPart parentPart = m_scene.GetSceneObjectPart(av.ParentID); 516 SceneObjectPart parentPart = m_scene.GetSceneObjectPart(av.ParentID);
@@ -838,7 +837,7 @@ namespace OpenSim.Region.Framework.Scenes
838 /// No avatar should appear more than once in this list. 837 /// No avatar should appear more than once in this list.
839 /// Do not manipulate this list directly - use the Add/Remove sitting avatar methods on SceneObjectPart. 838 /// Do not manipulate this list directly - use the Add/Remove sitting avatar methods on SceneObjectPart.
840 /// </remarks> 839 /// </remarks>
841 protected internal List<UUID> m_sittingAvatars = new List<UUID>(); 840 protected internal List<ScenePresence> m_sittingAvatars = new List<ScenePresence>();
842 841
843 #endregion 842 #endregion
844 843
@@ -1281,46 +1280,6 @@ namespace OpenSim.Region.Framework.Scenes
1281 part.ParentID = m_rootPart.LocalId; 1280 part.ParentID = m_rootPart.LocalId;
1282 part.ClearUndoState(); 1281 part.ClearUndoState();
1283 } 1282 }
1284 /// <summary>
1285 /// Add the avatar to this linkset (avatar is sat).
1286 /// </summary>
1287 /// <param name="agentID"></param>
1288 public void AddAvatar(UUID agentID)
1289 {
1290 ScenePresence presence;
1291 if (m_scene.TryGetScenePresence(agentID, out presence))
1292 {
1293 if (!m_linkedAvatars.Contains(presence))
1294 {
1295 m_linkedAvatars.Add(presence);
1296 }
1297 }
1298 }
1299
1300 /// <summary>
1301 /// Delete the avatar from this linkset (avatar is unsat).
1302 /// </summary>
1303 /// <param name="agentID"></param>
1304 public void DeleteAvatar(UUID agentID)
1305 {
1306 ScenePresence presence;
1307 if (m_scene.TryGetScenePresence(agentID, out presence))
1308 {
1309 if (m_linkedAvatars.Contains(presence))
1310 {
1311 m_linkedAvatars.Remove(presence);
1312 }
1313 }
1314 }
1315
1316 /// <summary>
1317 /// Returns the list of linked presences (avatars sat on this group)
1318 /// </summary>
1319 /// <param name="agentID"></param>
1320 public List<ScenePresence> GetLinkedAvatars()
1321 {
1322 return m_linkedAvatars;
1323 }
1324 1283
1325 public ushort GetTimeDilation() 1284 public ushort GetTimeDilation()
1326 { 1285 {
@@ -1714,8 +1673,7 @@ namespace OpenSim.Region.Framework.Scenes
1714 1673
1715 dupe.Backup = false; 1674 dupe.Backup = false;
1716 dupe.m_parts = new MapAndArray<OpenMetaverse.UUID, SceneObjectPart>(); 1675 dupe.m_parts = new MapAndArray<OpenMetaverse.UUID, SceneObjectPart>();
1717 dupe.m_sittingAvatars = new List<UUID>(); 1676 dupe.m_sittingAvatars = new List<ScenePresence>();
1718 dupe.m_linkedAvatars = new List<ScenePresence>();
1719 dupe.CopyRootPart(m_rootPart, OwnerID, GroupID, userExposed); 1677 dupe.CopyRootPart(m_rootPart, OwnerID, GroupID, userExposed);
1720 dupe.m_rootPart.LinkNum = m_rootPart.LinkNum; 1678 dupe.m_rootPart.LinkNum = m_rootPart.LinkNum;
1721 1679
@@ -3833,10 +3791,10 @@ namespace OpenSim.Region.Framework.Scenes
3833 /// down after it move one place down the list. 3791 /// down after it move one place down the list.
3834 /// </remarks> 3792 /// </remarks>
3835 /// <returns>A list of the sitting avatars. Returns an empty list if there are no sitting avatars.</returns> 3793 /// <returns>A list of the sitting avatars. Returns an empty list if there are no sitting avatars.</returns>
3836 public List<UUID> GetSittingAvatars() 3794 public List<ScenePresence> GetSittingAvatars()
3837 { 3795 {
3838 lock (m_sittingAvatars) 3796 lock (m_sittingAvatars)
3839 return new List<UUID>(m_sittingAvatars); 3797 return new List<ScenePresence>(m_sittingAvatars);
3840 } 3798 }
3841 3799
3842 /// <summary> 3800 /// <summary>
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index c06175e..43fec35 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -1299,7 +1299,7 @@ namespace OpenSim.Region.Framework.Scenes
1299 /// <value> 1299 /// <value>
1300 /// null if there are no sitting avatars. This is to save us create a hashset for every prim in a scene. 1300 /// null if there are no sitting avatars. This is to save us create a hashset for every prim in a scene.
1301 /// </value> 1301 /// </value>
1302 private HashSet<UUID> m_sittingAvatars; 1302 private HashSet<ScenePresence> m_sittingAvatars;
1303 1303
1304 public virtual UUID RegionID 1304 public virtual UUID RegionID
1305 { 1305 {
@@ -1803,7 +1803,7 @@ namespace OpenSim.Region.Framework.Scenes
1803 Array.Copy(Shape.ExtraParams, extraP, extraP.Length); 1803 Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
1804 dupe.Shape.ExtraParams = extraP; 1804 dupe.Shape.ExtraParams = extraP;
1805 1805
1806 dupe.m_sittingAvatars = new HashSet<OpenMetaverse.UUID>(); 1806 dupe.m_sittingAvatars = new HashSet<ScenePresence>();
1807 1807
1808 // safeguard actual copy is done in sog.copy 1808 // safeguard actual copy is done in sog.copy
1809 dupe.KeyframeMotion = null; 1809 dupe.KeyframeMotion = null;
@@ -4917,19 +4917,19 @@ namespace OpenSim.Region.Framework.Scenes
4917 /// true if the avatar was not already recorded, false otherwise. 4917 /// true if the avatar was not already recorded, false otherwise.
4918 /// </returns> 4918 /// </returns>
4919 /// <param name='avatarId'></param> 4919 /// <param name='avatarId'></param>
4920 protected internal bool AddSittingAvatar(UUID avatarId) 4920 protected internal bool AddSittingAvatar(ScenePresence sp)
4921 { 4921 {
4922 lock (ParentGroup.m_sittingAvatars) 4922 lock (ParentGroup.m_sittingAvatars)
4923 { 4923 {
4924 if (IsSitTargetSet && SitTargetAvatar == UUID.Zero) 4924 if (IsSitTargetSet && SitTargetAvatar == UUID.Zero)
4925 SitTargetAvatar = avatarId; 4925 SitTargetAvatar = sp.UUID;
4926 4926
4927 if (m_sittingAvatars == null) 4927 if (m_sittingAvatars == null)
4928 m_sittingAvatars = new HashSet<UUID>(); 4928 m_sittingAvatars = new HashSet<ScenePresence>();
4929 4929
4930 if (m_sittingAvatars.Add(avatarId)) 4930 if (m_sittingAvatars.Add(sp))
4931 { 4931 {
4932 ParentGroup.m_sittingAvatars.Add(avatarId); 4932 ParentGroup.m_sittingAvatars.Add(sp);
4933 4933
4934 return true; 4934 return true;
4935 } 4935 }
@@ -4946,22 +4946,22 @@ namespace OpenSim.Region.Framework.Scenes
4946 /// true if the avatar was present and removed, false if it was not present. 4946 /// true if the avatar was present and removed, false if it was not present.
4947 /// </returns> 4947 /// </returns>
4948 /// <param name='avatarId'></param> 4948 /// <param name='avatarId'></param>
4949 protected internal bool RemoveSittingAvatar(UUID avatarId) 4949 protected internal bool RemoveSittingAvatar(ScenePresence sp)
4950 { 4950 {
4951 lock (ParentGroup.m_sittingAvatars) 4951 lock (ParentGroup.m_sittingAvatars)
4952 { 4952 {
4953 if (SitTargetAvatar == avatarId) 4953 if (SitTargetAvatar == sp.UUID)
4954 SitTargetAvatar = UUID.Zero; 4954 SitTargetAvatar = UUID.Zero;
4955 4955
4956 if (m_sittingAvatars == null) 4956 if (m_sittingAvatars == null)
4957 return false; 4957 return false;
4958 4958
4959 if (m_sittingAvatars.Remove(avatarId)) 4959 if (m_sittingAvatars.Remove(sp))
4960 { 4960 {
4961 if (m_sittingAvatars.Count == 0) 4961 if (m_sittingAvatars.Count == 0)
4962 m_sittingAvatars = null; 4962 m_sittingAvatars = null;
4963 4963
4964 ParentGroup.m_sittingAvatars.Remove(avatarId); 4964 ParentGroup.m_sittingAvatars.Remove(sp);
4965 4965
4966 return true; 4966 return true;
4967 } 4967 }
@@ -4975,14 +4975,14 @@ namespace OpenSim.Region.Framework.Scenes
4975 /// </summary> 4975 /// </summary>
4976 /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks> 4976 /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks>
4977 /// <returns>A hashset of the sitting avatars. Returns null if there are no sitting avatars.</returns> 4977 /// <returns>A hashset of the sitting avatars. Returns null if there are no sitting avatars.</returns>
4978 public HashSet<UUID> GetSittingAvatars() 4978 public HashSet<ScenePresence> GetSittingAvatars()
4979 { 4979 {
4980 lock (ParentGroup.m_sittingAvatars) 4980 lock (ParentGroup.m_sittingAvatars)
4981 { 4981 {
4982 if (m_sittingAvatars == null) 4982 if (m_sittingAvatars == null)
4983 return null; 4983 return null;
4984 else 4984 else
4985 return new HashSet<UUID>(m_sittingAvatars); 4985 return new HashSet<ScenePresence>(m_sittingAvatars);
4986 } 4986 }
4987 } 4987 }
4988 4988
@@ -5002,4 +5002,4 @@ namespace OpenSim.Region.Framework.Scenes
5002 } 5002 }
5003 } 5003 }
5004 } 5004 }
5005} 5005} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 6386a45..3d1c58c 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -1022,8 +1022,7 @@ namespace OpenSim.Region.Framework.Scenes
1022 } 1022 }
1023 else 1023 else
1024 { 1024 {
1025 part.ParentGroup.AddAvatar(UUID); 1025 part.AddSittingAvatar(this);
1026 part.AddSittingAvatar(UUID);
1027 if (part.SitTargetPosition != Vector3.Zero) 1026 if (part.SitTargetPosition != Vector3.Zero)
1028 part.SitTargetAvatar = UUID; 1027 part.SitTargetAvatar = UUID;
1029 // ParentPosition = part.GetWorldPosition(); 1028 // ParentPosition = part.GetWorldPosition();
@@ -2522,7 +2521,6 @@ namespace OpenSim.Region.Framework.Scenes
2522 } 2521 }
2523 } 2522 }
2524 2523
2525 part.ParentGroup.DeleteAvatar(UUID);
2526 Vector3 sitPartWorldPosition = part.GetWorldPosition(); 2524 Vector3 sitPartWorldPosition = part.GetWorldPosition();
2527 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 2525 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
2528 2526
@@ -2578,7 +2576,7 @@ namespace OpenSim.Region.Framework.Scenes
2578 SendAvatarDataToAllAgents(); 2576 SendAvatarDataToAllAgents();
2579 m_requestedSitTargetID = 0; 2577 m_requestedSitTargetID = 0;
2580 2578
2581 part.RemoveSittingAvatar(UUID); 2579 part.RemoveSittingAvatar(this);
2582 2580
2583 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 2581 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2584 } 2582 }
@@ -2688,7 +2686,7 @@ namespace OpenSim.Region.Framework.Scenes
2688 2686
2689 Velocity = Vector3.Zero; 2687 Velocity = Vector3.Zero;
2690 2688
2691 part.AddSittingAvatar(UUID); 2689 part.AddSittingAvatar(this);
2692 2690
2693 cameraAtOffset = part.GetCameraAtOffset(); 2691 cameraAtOffset = part.GetCameraAtOffset();
2694 cameraEyeOffset = part.GetCameraEyeOffset(); 2692 cameraEyeOffset = part.GetCameraEyeOffset();
@@ -2821,7 +2819,7 @@ namespace OpenSim.Region.Framework.Scenes
2821 2819
2822 Velocity = Vector3.Zero; 2820 Velocity = Vector3.Zero;
2823 2821
2824 part.AddSittingAvatar(UUID); 2822 part.AddSittingAvatar(this);
2825 2823
2826 Vector3 cameraAtOffset = part.GetCameraAtOffset(); 2824 Vector3 cameraAtOffset = part.GetCameraAtOffset();
2827 Vector3 cameraEyeOffset = part.GetCameraEyeOffset(); 2825 Vector3 cameraEyeOffset = part.GetCameraEyeOffset();
@@ -2836,7 +2834,6 @@ namespace OpenSim.Region.Framework.Scenes
2836 m_pos = offset; 2834 m_pos = offset;
2837 2835
2838 m_requestedSitTargetID = 0; 2836 m_requestedSitTargetID = 0;
2839 part.ParentGroup.AddAvatar(UUID);
2840 2837
2841 ParentPart = part; 2838 ParentPart = part;
2842 ParentID = part.LocalId; 2839 ParentID = part.LocalId;
@@ -2936,7 +2933,6 @@ namespace OpenSim.Region.Framework.Scenes
2936// Name, part.AbsolutePosition, m_pos, ParentPosition, part.Name, part.LocalId); 2933// Name, part.AbsolutePosition, m_pos, ParentPosition, part.Name, part.LocalId);
2937 } 2934 }
2938 2935
2939 part.ParentGroup.AddAvatar(UUID);
2940 ParentPart = m_scene.GetSceneObjectPart(m_requestedSitTargetID); 2936 ParentPart = m_scene.GetSceneObjectPart(m_requestedSitTargetID);
2941 ParentID = m_requestedSitTargetID; 2937 ParentID = m_requestedSitTargetID;
2942 m_AngularVelocity = Vector3.Zero; 2938 m_AngularVelocity = Vector3.Zero;
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectCrossingTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectCrossingTests.cs
index d65b0b6..969f73d 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectCrossingTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectCrossingTests.cs
@@ -172,7 +172,6 @@ namespace OpenSim.Region.Framework.Scenes.Tests
172 so1PostCross = sceneB.GetSceneObjectGroup(so1Id); 172 so1PostCross = sceneB.GetSceneObjectGroup(so1Id);
173 Assert.NotNull(so1PostCross); 173 Assert.NotNull(so1PostCross);
174 Assert.AreEqual(1, so1PostCross.GetSittingAvatarsCount()); 174 Assert.AreEqual(1, so1PostCross.GetSittingAvatarsCount());
175 Assert.AreEqual(1, so1PostCross.GetLinkedAvatars().Count);
176 } 175 }
177 176
178 Vector3 so1PostCrossPos = so1PostCross.AbsolutePosition; 177 Vector3 so1PostCrossPos = so1PostCross.AbsolutePosition;
@@ -198,7 +197,6 @@ namespace OpenSim.Region.Framework.Scenes.Tests
198 SceneObjectGroup so1PostReCross = sceneA.GetSceneObjectGroup(so1Id); 197 SceneObjectGroup so1PostReCross = sceneA.GetSceneObjectGroup(so1Id);
199 Assert.NotNull(so1PostReCross); 198 Assert.NotNull(so1PostReCross);
200 Assert.AreEqual(1, so1PostReCross.GetSittingAvatarsCount()); 199 Assert.AreEqual(1, so1PostReCross.GetSittingAvatarsCount());
201 Assert.AreEqual(1, so1PostReCross.GetLinkedAvatars().Count);
202 } 200 }
203 } 201 }
204 202
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
index 0911f00..dcdec5c 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
@@ -93,9 +93,9 @@ namespace OpenSim.Region.Framework.Scenes.Tests
93 93
94 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); 94 Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
95 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1)); 95 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
96 HashSet<UUID> sittingAvatars = part.GetSittingAvatars(); 96 HashSet<ScenePresence> sittingAvatars = part.GetSittingAvatars();
97 Assert.That(sittingAvatars.Count, Is.EqualTo(1)); 97 Assert.That(sittingAvatars.Count, Is.EqualTo(1));
98 Assert.That(sittingAvatars.Contains(m_sp.UUID)); 98 Assert.That(sittingAvatars.Contains(m_sp));
99 Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId)); 99 Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
100 } 100 }
101 101
@@ -151,9 +151,9 @@ namespace OpenSim.Region.Framework.Scenes.Tests
151 Assert.That(m_sp.PhysicsActor, Is.Null); 151 Assert.That(m_sp.PhysicsActor, Is.Null);
152 152
153 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1)); 153 Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
154 HashSet<UUID> sittingAvatars = part.GetSittingAvatars(); 154 HashSet<ScenePresence> sittingAvatars = part.GetSittingAvatars();
155 Assert.That(sittingAvatars.Count, Is.EqualTo(1)); 155 Assert.That(sittingAvatars.Count, Is.EqualTo(1));
156 Assert.That(sittingAvatars.Contains(m_sp.UUID)); 156 Assert.That(sittingAvatars.Contains(m_sp));
157 157
158 m_sp.StandUp(); 158 m_sp.StandUp();
159 159