Centralize duplicated code in SceneObjectPart for subscribing to

collision events. Improve logic for knowing when to add processing
routine to physics actor.
cpu-performance
Robert Adams 2013-07-11 16:57:07 -07:00
parent ba8f9c9d0a
commit 1909ee70f8
1 changed files with 43 additions and 54 deletions

View File

@ -4213,31 +4213,12 @@ namespace OpenSim.Region.Framework.Scenes
AddToPhysics(UsePhysics, SetPhantom, false); AddToPhysics(UsePhysics, SetPhantom, false);
pa = PhysActor; pa = PhysActor;
if (pa != null) if (pa != null)
{ {
pa.SetMaterial(Material); pa.SetMaterial(Material);
DoPhysicsPropertyUpdate(UsePhysics, true); DoPhysicsPropertyUpdate(UsePhysics, true);
if ( SubscribeForCollisionEvents();
((AggregateScriptEvents & scriptEvents.collision) != 0) ||
((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
(CollisionSound != UUID.Zero)
)
{
pa.OnCollisionUpdate += PhysicsCollision;
pa.SubscribeEvents(1000);
}
} }
} }
else // it already has a physical representation else // it already has a physical representation
@ -4291,6 +4272,46 @@ namespace OpenSim.Region.Framework.Scenes
// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags); // m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags);
} }
// Subscribe for physics collision events if needed for scripts and sounds
public void SubscribeForCollisionEvents()
{
if (PhysActor != null)
{
if (
((AggregateScriptEvents & scriptEvents.collision) != 0) ||
((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
(CollisionSound != UUID.Zero)
)
{
if (!PhysActor.SubscribedEvents())
{
// If not already subscribed for event, set up for a collision event.
PhysActor.OnCollisionUpdate += PhysicsCollision;
PhysActor.SubscribeEvents(1000);
}
}
else
{
// There is no need to be subscribed to collisions so, if subscribed, remove subscription
if (PhysActor.SubscribedEvents())
{
PhysActor.OnCollisionUpdate -= PhysicsCollision;
PhysActor.UnSubscribeEvents();
}
}
}
}
/// <summary> /// <summary>
/// Adds this part to the physics scene. /// Adds this part to the physics scene.
/// </summary> /// </summary>
@ -4680,39 +4701,7 @@ namespace OpenSim.Region.Framework.Scenes
objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop; objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop;
} }
PhysicsActor pa = PhysActor; SubscribeForCollisionEvents();
if (
((AggregateScriptEvents & scriptEvents.collision) != 0) ||
((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
(CollisionSound != UUID.Zero)
)
{
// subscribe to physics updates.
if (pa != null)
{
pa.OnCollisionUpdate += PhysicsCollision;
pa.SubscribeEvents(1000);
}
}
else
{
if (pa != null)
{
pa.UnSubscribeEvents();
pa.OnCollisionUpdate -= PhysicsCollision;
}
}
//if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0) //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0)
//{ //{