Centralize duplicated code in SceneObjectPart for subscribing to
collision events. Improve logic for knowing when to add processing routine to physics actor.cpu-performance
parent
ba8f9c9d0a
commit
1909ee70f8
|
@ -4213,31 +4213,12 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
AddToPhysics(UsePhysics, SetPhantom, false);
|
||||
pa = PhysActor;
|
||||
|
||||
|
||||
if (pa != null)
|
||||
{
|
||||
pa.SetMaterial(Material);
|
||||
DoPhysicsPropertyUpdate(UsePhysics, true);
|
||||
|
||||
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)
|
||||
)
|
||||
{
|
||||
pa.OnCollisionUpdate += PhysicsCollision;
|
||||
pa.SubscribeEvents(1000);
|
||||
}
|
||||
SubscribeForCollisionEvents();
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
// 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>
|
||||
/// Adds this part to the physics scene.
|
||||
/// </summary>
|
||||
|
@ -4680,39 +4701,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop;
|
||||
}
|
||||
|
||||
PhysicsActor pa = PhysActor;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
SubscribeForCollisionEvents();
|
||||
|
||||
//if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0)
|
||||
//{
|
||||
|
|
Loading…
Reference in New Issue