BulletSim: finish the post step event for physical object actions. Modify vehicle to use post step event for logging.
parent
776cc33541
commit
c44a8e9f92
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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<string, BSScene.PreStepAction> RegisteredActions = new Dictionary<string, BSScene.PreStepAction>();
|
||||
private Dictionary<string, BSScene.PreStepAction> RegisteredPrestepActions = new Dictionary<string, BSScene.PreStepAction>();
|
||||
private Dictionary<string, BSScene.PostStepAction> RegisteredPoststepActions = new Dictionary<string, BSScene.PostStepAction>();
|
||||
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<string, BSScene.PreStepAction> kvp in RegisteredActions)
|
||||
foreach (KeyValuePair<string, BSScene.PreStepAction> 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<string, BSScene.PostStepAction> kvp in RegisteredPoststepActions)
|
||||
{
|
||||
PhysicsScene.AfterStep -= kvp.Value;
|
||||
}
|
||||
RegisteredPoststepActions.Clear();
|
||||
}
|
||||
DetailLog("{0},BSPhysObject.UnRegisterAllPostStepActions,", LocalID);
|
||||
}
|
||||
|
||||
#endregion // Per Simulation Step actions
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue