diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index e517389..f7317c0 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | |||
@@ -471,7 +471,14 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
471 | // We must generate a collision for avatars whether they collide or not. | 471 | // We must generate a collision for avatars whether they collide or not. |
472 | // This is required by OpenSim to update avatar animations, etc. | 472 | // This is required by OpenSim to update avatar animations, etc. |
473 | lock (m_avatars) | 473 | lock (m_avatars) |
474 | m_avatars.Add(actor); | 474 | { |
475 | // The funky copy is because this list has few and infrequent changes but is | ||
476 | // read zillions of times. This allows the reader/iterator to use the | ||
477 | // list and this creates a new list with any updates. | ||
478 | HashSet<BSPhysObject> avatarTemp = new HashSet<BSPhysObject>(m_avatars); | ||
479 | avatarTemp.Add(actor); | ||
480 | m_avatars = avatarTemp; | ||
481 | } | ||
475 | 482 | ||
476 | return actor; | 483 | return actor; |
477 | } | 484 | } |
@@ -491,7 +498,11 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
491 | PhysObjects.Remove(bsactor.LocalID); | 498 | PhysObjects.Remove(bsactor.LocalID); |
492 | // Remove kludge someday | 499 | // Remove kludge someday |
493 | lock (m_avatars) | 500 | lock (m_avatars) |
494 | m_avatars.Remove(bsactor); | 501 | { |
502 | HashSet<BSPhysObject> avatarTemp = new HashSet<BSPhysObject>(m_avatars); | ||
503 | avatarTemp.Remove(bsactor); | ||
504 | m_avatars = avatarTemp; | ||
505 | } | ||
495 | } | 506 | } |
496 | catch (Exception e) | 507 | catch (Exception e) |
497 | { | 508 | { |
@@ -736,9 +747,13 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
736 | // The simulator expects collisions for avatars even if there are have been no collisions. | 747 | // The simulator expects collisions for avatars even if there are have been no collisions. |
737 | // The event updates avatar animations and stuff. | 748 | // The event updates avatar animations and stuff. |
738 | // If you fix avatar animation updates, remove this overhead and let normal collision processing happen. | 749 | // If you fix avatar animation updates, remove this overhead and let normal collision processing happen. |
739 | foreach (BSPhysObject bsp in m_avatars) | 750 | // Note that we copy the root of the list to search. Any updates will create a new list |
751 | // thus freeing this code from having to do an extra lock for every collision. | ||
752 | HashSet<BSPhysObject> avatarTemp = m_avatars; | ||
753 | foreach (BSPhysObject bsp in avatarTemp) | ||
740 | if (!ObjectsWithCollisions.Contains(bsp)) // don't call avatars twice | 754 | if (!ObjectsWithCollisions.Contains(bsp)) // don't call avatars twice |
741 | bsp.SendCollisions(); | 755 | bsp.SendCollisions(); |
756 | avatarTemp = null; | ||
742 | 757 | ||
743 | // Objects that are done colliding are removed from the ObjectsWithCollisions list. | 758 | // Objects that are done colliding are removed from the ObjectsWithCollisions list. |
744 | // Not done above because it is inside an iteration of ObjectWithCollisions. | 759 | // Not done above because it is inside an iteration of ObjectWithCollisions. |