diff options
author | UbitUmarov | 2012-05-15 15:54:02 +0100 |
---|---|---|
committer | UbitUmarov | 2012-05-15 15:54:02 +0100 |
commit | ca14534b91342f55e30838ccafba25424628f5b4 (patch) | |
tree | 0689ad742368e974b1f3a6c58d76267fba379e0d /OpenSim/Region/Framework/Scenes | |
parent | ubitODE: if stopped having collisions do report zero colisions once, so colli... (diff) | |
download | opensim-SC_OLD-ca14534b91342f55e30838ccafba25424628f5b4.zip opensim-SC_OLD-ca14534b91342f55e30838ccafba25424628f5b4.tar.gz opensim-SC_OLD-ca14534b91342f55e30838ccafba25424628f5b4.tar.bz2 opensim-SC_OLD-ca14534b91342f55e30838ccafba25424628f5b4.tar.xz |
sop: - added UpdatePhysicsSubscribedEvents() to update physics ator collision events subcription where needed. Made it consider also VolumeDtc and phantom cases. - added extra calls to it on physics ator proprieties changes. - Fixed land collisions reports. - Handle the case of physics sending a last zero colisions reports to trigger collision_end. - Made the physics collisions report rate be 20 per second. (needs review/testing)
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 166 |
1 files changed, 118 insertions, 48 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 7a1720c..11d6b57 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | |||
@@ -123,11 +123,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
123 | /// </value> | 123 | /// </value> |
124 | public const int ALL_SIDES = -1; | 124 | public const int ALL_SIDES = -1; |
125 | 125 | ||
126 | private const scriptEvents PhyscicsNeededSubsEvents = ( | 126 | private const scriptEvents PhysicsNeededSubsEvents = ( |
127 | scriptEvents.collision | scriptEvents.collision_start | scriptEvents.collision_end | | 127 | scriptEvents.collision | scriptEvents.collision_start | scriptEvents.collision_end | |
128 | scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end | 128 | scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end |
129 | ); | 129 | ); |
130 | 130 | private const scriptEvents PhyscicsPhantonSubsEvents = ( | |
131 | scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end | ||
132 | ); | ||
133 | private const scriptEvents PhyscicsVolumeDtcSubsEvents = ( | ||
134 | scriptEvents.collision_start | scriptEvents.collision_end | ||
135 | ); | ||
136 | |||
131 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 137 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
132 | 138 | ||
133 | /// <value> | 139 | /// <value> |
@@ -1882,7 +1888,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
1882 | { | 1888 | { |
1883 | if ((!isPhantom || isPhysical || _VolumeDetectActive) && !ParentGroup.IsAttachment | 1889 | if ((!isPhantom || isPhysical || _VolumeDetectActive) && !ParentGroup.IsAttachment |
1884 | && !(Shape.PathCurve == (byte)Extrusion.Flexible)) | 1890 | && !(Shape.PathCurve == (byte)Extrusion.Flexible)) |
1891 | { | ||
1885 | AddToPhysics(isPhysical, isPhantom, building, isPhysical); | 1892 | AddToPhysics(isPhysical, isPhantom, building, isPhysical); |
1893 | UpdatePhysicsSubscribedEvents(); // not sure if appliable here | ||
1894 | } | ||
1886 | else | 1895 | else |
1887 | PhysActor = null; // just to be sure | 1896 | PhysActor = null; // just to be sure |
1888 | } | 1897 | } |
@@ -1975,6 +1984,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1975 | 1984 | ||
1976 | bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0); | 1985 | bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0); |
1977 | dupe.DoPhysicsPropertyUpdate(UsePhysics, true); | 1986 | dupe.DoPhysicsPropertyUpdate(UsePhysics, true); |
1987 | // dupe.UpdatePhysicsSubscribedEvents(); // not sure... | ||
1978 | } | 1988 | } |
1979 | 1989 | ||
1980 | if (dupe.PhysActor != null) | 1990 | if (dupe.PhysActor != null) |
@@ -2602,30 +2612,45 @@ namespace OpenSim.Region.Framework.Scenes | |||
2602 | List<uint> endedColliders = new List<uint>(); | 2612 | List<uint> endedColliders = new List<uint>(); |
2603 | List<uint> startedColliders = new List<uint>(); | 2613 | List<uint> startedColliders = new List<uint>(); |
2604 | 2614 | ||
2605 | // calculate things that started colliding this time | 2615 | if (collissionswith.Count == 0) |
2606 | // and build up list of colliders this time | ||
2607 | foreach (uint localid in collissionswith.Keys) | ||
2608 | { | 2616 | { |
2609 | thisHitColliders.Add(localid); | 2617 | if (m_lastColliders.Count == 0) |
2610 | if (!m_lastColliders.Contains(localid)) | 2618 | return; // nothing to do |
2611 | startedColliders.Add(localid); | ||
2612 | } | ||
2613 | 2619 | ||
2614 | // calculate things that ended colliding | 2620 | foreach (uint localID in m_lastColliders) |
2615 | foreach (uint localID in m_lastColliders) | 2621 | { |
2616 | { | ||
2617 | if (!thisHitColliders.Contains(localID)) | ||
2618 | endedColliders.Add(localID); | 2622 | endedColliders.Add(localID); |
2623 | } | ||
2624 | m_lastColliders.Clear(); | ||
2619 | } | 2625 | } |
2620 | 2626 | ||
2621 | //add the items that started colliding this time to the last colliders list. | 2627 | else |
2622 | foreach (uint localID in startedColliders) | 2628 | { |
2623 | m_lastColliders.Add(localID); | 2629 | |
2630 | // calculate things that started colliding this time | ||
2631 | // and build up list of colliders this time | ||
2632 | foreach (uint localid in collissionswith.Keys) | ||
2633 | { | ||
2634 | thisHitColliders.Add(localid); | ||
2635 | if (!m_lastColliders.Contains(localid)) | ||
2636 | startedColliders.Add(localid); | ||
2637 | } | ||
2638 | |||
2639 | // calculate things that ended colliding | ||
2640 | foreach (uint localID in m_lastColliders) | ||
2641 | { | ||
2642 | if (!thisHitColliders.Contains(localID)) | ||
2643 | endedColliders.Add(localID); | ||
2644 | } | ||
2624 | 2645 | ||
2625 | // remove things that ended colliding from the last colliders list | 2646 | //add the items that started colliding this time to the last colliders list. |
2626 | foreach (uint localID in endedColliders) | 2647 | foreach (uint localID in startedColliders) |
2627 | m_lastColliders.Remove(localID); | 2648 | m_lastColliders.Add(localID); |
2628 | 2649 | ||
2650 | // remove things that ended colliding from the last colliders list | ||
2651 | foreach (uint localID in endedColliders) | ||
2652 | m_lastColliders.Remove(localID); | ||
2653 | } | ||
2629 | // play the sound. | 2654 | // play the sound. |
2630 | if (startedColliders.Count > 0 && CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f) | 2655 | if (startedColliders.Count > 0 && CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f) |
2631 | SendSound(CollisionSound.ToString(), CollisionSoundVolume, true, (byte)0, 0, false, false); | 2656 | SendSound(CollisionSound.ToString(), CollisionSoundVolume, true, (byte)0, 0, false, false); |
@@ -2636,12 +2661,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
2636 | SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd); | 2661 | SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd); |
2637 | 2662 | ||
2638 | if (startedColliders.Contains(0)) | 2663 | if (startedColliders.Contains(0)) |
2639 | { | 2664 | SendLandCollisionEvent(scriptEvents.land_collision_start, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingStart); |
2640 | if (m_lastColliders.Contains(0)) | 2665 | if (m_lastColliders.Contains(0)) |
2641 | SendLandCollisionEvent(scriptEvents.land_collision, ParentGroup.Scene.EventManager.TriggerScriptLandColliding); | 2666 | SendLandCollisionEvent(scriptEvents.land_collision, ParentGroup.Scene.EventManager.TriggerScriptLandColliding); |
2642 | else | ||
2643 | SendLandCollisionEvent(scriptEvents.land_collision_start, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingStart); | ||
2644 | } | ||
2645 | if (endedColliders.Contains(0)) | 2667 | if (endedColliders.Contains(0)) |
2646 | SendLandCollisionEvent(scriptEvents.land_collision_end, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd); | 2668 | SendLandCollisionEvent(scriptEvents.land_collision_end, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd); |
2647 | } | 2669 | } |
@@ -4383,26 +4405,28 @@ namespace OpenSim.Region.Framework.Scenes | |||
4383 | { | 4405 | { |
4384 | if (pa == null) | 4406 | if (pa == null) |
4385 | { | 4407 | { |
4386 | AddToPhysics(UsePhysics, SetPhantom, building , false); | 4408 | AddToPhysics(UsePhysics, SetPhantom, building, false); |
4387 | pa = PhysActor; | 4409 | pa = PhysActor; |
4388 | 4410 | /* | |
4389 | if (pa != null) | 4411 | if (pa != null) |
4390 | { | 4412 | { |
4391 | if ( | 4413 | if ( |
4392 | // ((AggregateScriptEvents & scriptEvents.collision) != 0) || | 4414 | // ((AggregateScriptEvents & scriptEvents.collision) != 0) || |
4393 | // ((AggregateScriptEvents & scriptEvents.collision_end) != 0) || | 4415 | // ((AggregateScriptEvents & scriptEvents.collision_end) != 0) || |
4394 | // ((AggregateScriptEvents & scriptEvents.collision_start) != 0) || | 4416 | // ((AggregateScriptEvents & scriptEvents.collision_start) != 0) || |
4395 | // ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) || | 4417 | // ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) || |
4396 | // ((AggregateScriptEvents & scriptEvents.land_collision) != 0) || | 4418 | // ((AggregateScriptEvents & scriptEvents.land_collision) != 0) || |
4397 | // ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) || | 4419 | // ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) || |
4398 | ((AggregateScriptEvents & PhyscicsNeededSubsEvents) != 0) || ((ParentGroup.RootPart.AggregateScriptEvents & PhyscicsNeededSubsEvents) != 0) || (CollisionSound != UUID.Zero) | 4420 | ((AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) || |
4399 | // (CollisionSound != UUID.Zero) | 4421 | ((ParentGroup.RootPart.AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) || |
4400 | ) | 4422 | (CollisionSound != UUID.Zero) |
4401 | { | 4423 | ) |
4402 | pa.OnCollisionUpdate += PhysicsCollision; | 4424 | { |
4403 | pa.SubscribeEvents(1000); | 4425 | pa.OnCollisionUpdate += PhysicsCollision; |
4404 | } | 4426 | pa.SubscribeEvents(1000); |
4405 | } | 4427 | } |
4428 | } | ||
4429 | */ | ||
4406 | } | 4430 | } |
4407 | 4431 | ||
4408 | else // it already has a physical representation | 4432 | else // it already has a physical representation |
@@ -4414,9 +4438,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
4414 | else | 4438 | else |
4415 | pa.SetVolumeDetect(0); | 4439 | pa.SetVolumeDetect(0); |
4416 | */ | 4440 | */ |
4441 | |||
4442 | |||
4417 | if (pa.Building != building) | 4443 | if (pa.Building != building) |
4418 | pa.Building = building; | 4444 | pa.Building = building; |
4419 | } | 4445 | } |
4446 | |||
4447 | UpdatePhysicsSubscribedEvents(); | ||
4420 | } | 4448 | } |
4421 | } | 4449 | } |
4422 | 4450 | ||
@@ -4539,8 +4567,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
4539 | /// </summary> | 4567 | /// </summary> |
4540 | /// <remarks> | 4568 | /// <remarks> |
4541 | /// This isn't the same as turning off physical, since even without being physical the prim has a physics | 4569 | /// This isn't the same as turning off physical, since even without being physical the prim has a physics |
4542 | /// representation for collision detection. Rather, this would be used in situations such as making a prim | 4570 | /// representation for collision detection. |
4543 | /// phantom. | ||
4544 | /// </remarks> | 4571 | /// </remarks> |
4545 | public void RemoveFromPhysics() | 4572 | public void RemoveFromPhysics() |
4546 | { | 4573 | { |
@@ -4704,6 +4731,46 @@ namespace OpenSim.Region.Framework.Scenes | |||
4704 | ScheduleFullUpdate(); | 4731 | ScheduleFullUpdate(); |
4705 | } | 4732 | } |
4706 | 4733 | ||
4734 | |||
4735 | private void UpdatePhysicsSubscribedEvents() | ||
4736 | { | ||
4737 | PhysicsActor pa = PhysActor; | ||
4738 | if (pa == null) | ||
4739 | return; | ||
4740 | |||
4741 | pa.OnCollisionUpdate -= PhysicsCollision; | ||
4742 | |||
4743 | bool hassound = ( CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f); | ||
4744 | scriptEvents CombinedEvents = AggregateScriptEvents; | ||
4745 | |||
4746 | // merge with root part | ||
4747 | if (ParentGroup != null && ParentGroup.RootPart != null) | ||
4748 | CombinedEvents |= ParentGroup.RootPart.AggregateScriptEvents; | ||
4749 | |||
4750 | // submit to this part case | ||
4751 | if (VolumeDetectActive) | ||
4752 | { | ||
4753 | CombinedEvents &= PhyscicsVolumeDtcSubsEvents; | ||
4754 | hassound = false; | ||
4755 | } | ||
4756 | else if ((Flags & PrimFlags.Phantom) != 0) | ||
4757 | CombinedEvents &= PhyscicsPhantonSubsEvents; | ||
4758 | else | ||
4759 | CombinedEvents &= PhysicsNeededSubsEvents; | ||
4760 | |||
4761 | if (hassound || CombinedEvents != 0) | ||
4762 | { | ||
4763 | // subscribe to physics updates. | ||
4764 | pa.OnCollisionUpdate += PhysicsCollision; | ||
4765 | pa.SubscribeEvents(50); // 20 reports per second | ||
4766 | } | ||
4767 | else | ||
4768 | { | ||
4769 | pa.UnSubscribeEvents(); | ||
4770 | } | ||
4771 | } | ||
4772 | |||
4773 | |||
4707 | public void aggregateScriptEvents() | 4774 | public void aggregateScriptEvents() |
4708 | { | 4775 | { |
4709 | if (ParentGroup == null || ParentGroup.RootPart == null) | 4776 | if (ParentGroup == null || ParentGroup.RootPart == null) |
@@ -4740,7 +4807,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
4740 | { | 4807 | { |
4741 | objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop; | 4808 | objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop; |
4742 | } | 4809 | } |
4743 | 4810 | /* | |
4744 | PhysicsActor pa = PhysActor; | 4811 | PhysicsActor pa = PhysActor; |
4745 | if (pa != null) | 4812 | if (pa != null) |
4746 | { | 4813 | { |
@@ -4751,7 +4818,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
4751 | // ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) || | 4818 | // ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) || |
4752 | // ((AggregateScriptEvents & scriptEvents.land_collision) != 0) || | 4819 | // ((AggregateScriptEvents & scriptEvents.land_collision) != 0) || |
4753 | // ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) || | 4820 | // ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) || |
4754 | ((AggregateScriptEvents & PhyscicsNeededSubsEvents) != 0) || ((ParentGroup.RootPart.AggregateScriptEvents & PhyscicsNeededSubsEvents) != 0) || (CollisionSound != UUID.Zero) | 4821 | ((AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) || ((ParentGroup.RootPart.AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) || (CollisionSound != UUID.Zero) |
4755 | ) | 4822 | ) |
4756 | { | 4823 | { |
4757 | // subscribe to physics updates. | 4824 | // subscribe to physics updates. |
@@ -4764,6 +4831,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
4764 | pa.OnCollisionUpdate -= PhysicsCollision; | 4831 | pa.OnCollisionUpdate -= PhysicsCollision; |
4765 | } | 4832 | } |
4766 | } | 4833 | } |
4834 | */ | ||
4835 | UpdatePhysicsSubscribedEvents(); | ||
4836 | |||
4767 | //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0) | 4837 | //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0) |
4768 | //{ | 4838 | //{ |
4769 | // ParentGroup.Scene.EventManager.OnScriptTimerEvent += handleTimerAccounting; | 4839 | // ParentGroup.Scene.EventManager.OnScriptTimerEvent += handleTimerAccounting; |