BulletSim: update the motion actors so they completely clean themselves

when Dispose() is called. This reduces chance of object leakage when
    destroying objects.
Rearrange initialization and shut down of BSActorLockAxis so it is
    consistant with other actors.
0.8.2-post-fixes
Robert Adams 2015-08-09 15:34:06 -07:00
parent f3c883a26d
commit fe86df0ec9
7 changed files with 41 additions and 29 deletions

View File

@ -71,8 +71,7 @@ public class BSActorAvatarMove : BSActor
public override void Dispose()
{
base.SetEnabled(false);
// Now that turned off, remove any state we have in the scene.
Refresh();
DeactivateAvatarMove();
}
// Called when physical parameters (properties set in Bullet) need to be re-applied.

View File

@ -58,6 +58,7 @@ public class BSActorHover : BSActor
public override void Dispose()
{
Enabled = false;
DeactivateHover();
}
// Called when physical parameters (properties set in Bullet) need to be re-applied.

View File

@ -36,7 +36,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{
public class BSActorLockAxis : BSActor
{
BSConstraint LockAxisConstraint = null;
private BSConstraint LockAxisConstraint = null;
private bool HaveRegisteredForBeforeStepCallback = false;
// The lock access flags (which axises were locked) when the contraint was built.
// Used to see if locking has changed since when the constraint was built.
OMV.Vector3 LockAxisLinearFlags;
@ -47,9 +49,7 @@ public class BSActorLockAxis : BSActor
{
m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID);
LockAxisConstraint = null;
// we place our constraint just before the simulation step to make sure the linkset is complete
m_physicsScene.BeforeStep += PhysicsScene_BeforeStep;
HaveRegisteredForBeforeStepCallback = false;
}
// BSActor.isActive
@ -62,7 +62,8 @@ public class BSActorLockAxis : BSActor
// BSActor.Dispose()
public override void Dispose()
{
m_physicsScene.BeforeStep -= PhysicsScene_BeforeStep;
Enabled = false;
UnRegisterForBeforeStepCallback();
RemoveAxisLockConstraint();
}
@ -74,37 +75,26 @@ public class BSActorLockAxis : BSActor
// Since the axis logging is done with a constraint, Refresh() time is good for
// changing parameters but this needs to wait until the prim/linkset is physically
// constructed. Therefore, the constraint itself is placed at pre-step time.
/*
m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedLinear={1},lockedAngular={2},enabled={3},pActive={4}",
m_controllingPrim.LocalID,
m_controllingPrim.LockedLinearAxis,
m_controllingPrim.LockedAngularAxis,
Enabled, m_controllingPrim.IsPhysicallyActive);
// If all the axis are free, we don't need to exist
// Refresh() only turns off. Enabling is done by InitializeAxisActor()
// whenever parameters are changed.
// This leaves 'enable' free to turn off an actor when it is not wanted to run.
if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree
&& m_controllingPrim.LockedLinearAxis == m_controllingPrim.LockedAxisFree)
{
Enabled = false;
}
// If the object is physically active, add the axis locking constraint
if (isActive)
{
// Check to see if the locking parameters have changed
if (m_controllingPrim.LockedLinearAxis != this.LockAxisLinearFlags
|| m_controllingPrim.LockedAngularAxis != this.LockAxisAngularFlags)
{
// The locking has changed. Remove the old constraint and build a new one
RemoveAxisLockConstraint();
}
AddAxisLockConstraint();
RegisterForBeforeStepCallback();
}
else
{
RemoveAxisLockConstraint();
RemoveDependencies();
UnRegisterForBeforeStepCallback();
}
*/
}
// The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...).
@ -114,7 +104,24 @@ public class BSActorLockAxis : BSActor
public override void RemoveDependencies()
{
RemoveAxisLockConstraint();
// The pre-step action will restore the constraint of needed
}
private void RegisterForBeforeStepCallback()
{
if (!HaveRegisteredForBeforeStepCallback)
{
m_physicsScene.BeforeStep += PhysicsScene_BeforeStep;
HaveRegisteredForBeforeStepCallback = true;
}
}
private void UnRegisterForBeforeStepCallback()
{
if (HaveRegisteredForBeforeStepCallback)
{
m_physicsScene.BeforeStep -= PhysicsScene_BeforeStep;
HaveRegisteredForBeforeStepCallback = false;
}
}
private void PhysicsScene_BeforeStep(float timestep)
@ -145,6 +152,7 @@ public class BSActorLockAxis : BSActor
}
}
// Note that this relies on being called at TaintTime
private void AddAxisLockConstraint()
{
if (LockAxisConstraint == null)
@ -192,11 +200,14 @@ public class BSActorLockAxis : BSActor
axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f);
axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass);
RegisterForBeforeStepCallback();
}
}
private void RemoveAxisLockConstraint()
{
UnRegisterForBeforeStepCallback();
if (LockAxisConstraint != null)
{
m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint);

View File

@ -59,6 +59,7 @@ public class BSActorMoveToTarget : BSActor
public override void Dispose()
{
Enabled = false;
DeactivateMoveToTarget();
}
// Called when physical parameters (properties set in Bullet) need to be re-applied.

View File

@ -58,6 +58,7 @@ public class BSActorSetForce : BSActor
public override void Dispose()
{
Enabled = false;
DeactivateSetForce();
}
// Called when physical parameters (properties set in Bullet) need to be re-applied.

View File

@ -58,6 +58,7 @@ public class BSActorSetTorque : BSActor
public override void Dispose()
{
Enabled = false;
DeactivateSetTorque();
}
// Called when physical parameters (properties set in Bullet) need to be re-applied.

View File

@ -32,12 +32,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{
public class BSActorCollection
{
private BSScene m_physicsScene { get; set; }
private Dictionary<string, BSActor> m_actors;
public BSActorCollection(BSScene physicsScene)
public BSActorCollection()
{
m_physicsScene = physicsScene;
m_actors = new Dictionary<string, BSActor>();
}
public void Add(string name, BSActor actor)