From c44a8e9f925c0195c4754c5e763af06dae657b53 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 25 Jan 2013 10:17:20 -0800 Subject: BulletSim: finish the post step event for physical object actions. Modify vehicle to use post step event for logging. --- OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 14 ++++- .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 66 ++++++++++++++++++---- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 6 ++ 3 files changed, 73 insertions(+), 13 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 7ad7c89..a369c1f 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -583,6 +583,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Some of the properties of this prim may have changed. // Do any updating needed for a vehicle + Vector3 m_physicsLinearFactor = new Vector3(0.2f, 0.2f, 0.2f); // DEBUG DEBUG + Vector3 m_physicsAngularFactor = new Vector3(0.2f, 0.2f, 0.2f); // DEBUG DEBUG public void Refresh() { if (IsActive) @@ -599,6 +601,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Maybe compute linear and angular factor and damping from params. float angularDamping = BSParam.VehicleAngularDamping; PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, angularDamping); + PhysicsScene.PE.SetLinearFactor(Prim.PhysBody, m_physicsLinearFactor); // DEBUG DEBUG + PhysicsScene.PE.SetAngularFactorV(Prim.PhysBody, m_physicsAngularFactor); // DEBUG DEBUG // Vehicles report collision events so we know when it's on the ground PhysicsScene.PE.AddToCollisionFlags(Prim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); @@ -898,9 +902,6 @@ namespace OpenSim.Region.Physics.BulletSPlugin { if (!IsActive) return; - if (PhysicsScene.VehiclePhysicalLoggingEnabled) - PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); - ForgetKnownVehicleProperties(); MoveLinear(pTimestep); @@ -922,6 +923,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin Prim.LocalID, VehiclePosition, m_knownForce, VehicleVelocity, VehicleRotationalVelocity); } + // Called after the simulation step + internal void PostStep(float pTimestep) + { + if (PhysicsScene.VehiclePhysicalLoggingEnabled) + PhysicsScene.PE.DumpRigidBody(PhysicsScene.World, Prim.PhysBody); + } + // Apply the effect of the linear motor and other linear motions (like hover and float). private void MoveLinear(float pTimestep) { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 027c786..285d4a2 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -101,6 +101,7 @@ public abstract class BSPhysObject : PhysicsActor public virtual void Destroy() { UnRegisterAllPreStepActions(); + UnRegisterAllPostStepActions(); } public BSScene PhysicsScene { get; protected set; } @@ -393,17 +394,18 @@ public abstract class BSPhysObject : PhysicsActor // These actions are optional so, rather than scanning all the physical objects and asking them // if they have anything to do, a physical object registers for an event call before the step is performed. // This bookkeeping makes it easy to add, remove and clean up after all these registrations. - private Dictionary RegisteredActions = new Dictionary(); + private Dictionary RegisteredPrestepActions = new Dictionary(); + private Dictionary RegisteredPoststepActions = new Dictionary(); protected void RegisterPreStepAction(string op, uint id, BSScene.PreStepAction actn) { string identifier = op + "-" + id.ToString(); - lock (RegisteredActions) + lock (RegisteredPrestepActions) { // Clean out any existing action UnRegisterPreStepAction(op, id); - RegisteredActions[identifier] = actn; + RegisteredPrestepActions[identifier] = actn; } PhysicsScene.BeforeStep += actn; DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier); @@ -414,12 +416,12 @@ public abstract class BSPhysObject : PhysicsActor { string identifier = op + "-" + id.ToString(); bool removed = false; - lock (RegisteredActions) + lock (RegisteredPrestepActions) { - if (RegisteredActions.ContainsKey(identifier)) + if (RegisteredPrestepActions.ContainsKey(identifier)) { - PhysicsScene.BeforeStep -= RegisteredActions[identifier]; - RegisteredActions.Remove(identifier); + PhysicsScene.BeforeStep -= RegisteredPrestepActions[identifier]; + RegisteredPrestepActions.Remove(identifier); removed = true; } } @@ -428,17 +430,61 @@ public abstract class BSPhysObject : PhysicsActor protected void UnRegisterAllPreStepActions() { - lock (RegisteredActions) + lock (RegisteredPrestepActions) { - foreach (KeyValuePair kvp in RegisteredActions) + foreach (KeyValuePair kvp in RegisteredPrestepActions) { PhysicsScene.BeforeStep -= kvp.Value; } - RegisteredActions.Clear(); + RegisteredPrestepActions.Clear(); } DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID); } + + protected void RegisterPostStepAction(string op, uint id, BSScene.PostStepAction actn) + { + string identifier = op + "-" + id.ToString(); + + lock (RegisteredPoststepActions) + { + // Clean out any existing action + UnRegisterPostStepAction(op, id); + + RegisteredPoststepActions[identifier] = actn; + } + PhysicsScene.AfterStep += actn; + DetailLog("{0},BSPhysObject.RegisterPostStepAction,id={1}", LocalID, identifier); + } + + // Unregister a pre step action. Safe to call if the action has not been registered. + protected void UnRegisterPostStepAction(string op, uint id) + { + string identifier = op + "-" + id.ToString(); + bool removed = false; + lock (RegisteredPoststepActions) + { + if (RegisteredPoststepActions.ContainsKey(identifier)) + { + PhysicsScene.AfterStep -= RegisteredPoststepActions[identifier]; + RegisteredPoststepActions.Remove(identifier); + removed = true; + } + } + DetailLog("{0},BSPhysObject.UnRegisterPostStepAction,id={1},removed={2}", LocalID, identifier, removed); + } + protected void UnRegisterAllPostStepActions() + { + lock (RegisteredPoststepActions) + { + foreach (KeyValuePair kvp in RegisteredPoststepActions) + { + PhysicsScene.AfterStep -= kvp.Value; + } + RegisteredPoststepActions.Clear(); + } + DetailLog("{0},BSPhysObject.UnRegisterAllPostStepActions,", LocalID); + } #endregion // Per Simulation Step actions diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 8b00a33..99903f5 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -527,9 +527,15 @@ public sealed class BSPrim : BSPhysObject // If an active vehicle, register the vehicle code to be called before each step if (_vehicle.Type == Vehicle.TYPE_NONE) + { UnRegisterPreStepAction("BSPrim.Vehicle", LocalID); + PhysicsScene.AfterStep -= _vehicle.PostStep; + } else + { RegisterPreStepAction("BSPrim.Vehicle", LocalID, _vehicle.Step); + PhysicsScene.AfterStep += _vehicle.PostStep; + } }); } } -- cgit v1.1