BulletSim: replace use of funky nullable values for vehicle property update control (m_known* stuff). Bitmaps will be quicker to test and to clear.

0.7.5-pf-bulletsim
Robert Adams 2012-12-20 10:32:33 -08:00
parent e73dac4deb
commit a5b2539cf9
1 changed files with 43 additions and 26 deletions

View File

@ -602,21 +602,22 @@ namespace OpenSim.Region.Physics.BulletSPlugin
#region Known vehicle value functions #region Known vehicle value functions
// Vehicle physical parameters that we buffer from constant getting and setting. // Vehicle physical parameters that we buffer from constant getting and setting.
// The "m_known*" variables are initialized to 'null', fetched only if referenced // The "m_known*" values are unknown until they are fetched and the m_knownHas flag is set.
// and stored back into the physics engine only if updated. // Changing is remembered and the parameter is stored back into the physics engine only if updated.
// This does two things: 1) saves continuious calls into unmanaged code, and // This does two things: 1) saves continuious calls into unmanaged code, and
// 2) signals when a physics property update must happen back to the simulator // 2) signals when a physics property update must happen back to the simulator
// to update values modified for the vehicle. // to update values modified for the vehicle.
private int m_knownChanged; private int m_knownChanged;
private float? m_knownTerrainHeight; private int m_knownHas;
private float? m_knownWaterLevel; private float m_knownTerrainHeight;
private Vector3? m_knownPosition; private float m_knownWaterLevel;
private Vector3? m_knownVelocity; private Vector3 m_knownPosition;
private Vector3 m_knownVelocity;
private Vector3 m_knownForce; private Vector3 m_knownForce;
private Quaternion? m_knownOrientation; private Quaternion m_knownOrientation;
private Vector3? m_knownRotationalVelocity; private Vector3 m_knownRotationalVelocity;
private Vector3 m_knownRotationalForce; private Vector3 m_knownRotationalForce;
private Vector3? m_knownForwardVelocity; // vehicle relative forward speed private Vector3 m_knownForwardVelocity; // vehicle relative forward speed
private const int m_knownChangedPosition = 1 << 0; private const int m_knownChangedPosition = 1 << 0;
private const int m_knownChangedVelocity = 1 << 1; private const int m_knownChangedVelocity = 1 << 1;
@ -624,18 +625,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
private const int m_knownChangedOrientation = 1 << 3; private const int m_knownChangedOrientation = 1 << 3;
private const int m_knownChangedRotationalVelocity = 1 << 4; private const int m_knownChangedRotationalVelocity = 1 << 4;
private const int m_knownChangedRotationalForce = 1 << 5; private const int m_knownChangedRotationalForce = 1 << 5;
private const int m_knownChangedTerrainHeight = 1 << 6;
private const int m_knownChangedWaterLevel = 1 << 7;
private const int m_knownChangedForwardVelocity = 1 << 7;
private void ForgetKnownVehicleProperties() private void ForgetKnownVehicleProperties()
{ {
m_knownTerrainHeight = null; m_knownHas = 0;
m_knownWaterLevel = null;
m_knownPosition = null;
m_knownVelocity = null;
m_knownForce = Vector3.Zero;
m_knownOrientation = null;
m_knownRotationalVelocity = null;
m_knownRotationalForce = Vector3.Zero;
m_knownForwardVelocity = null;
m_knownChanged = 0; m_knownChanged = 0;
} }
private void PushKnownChanged() private void PushKnownChanged()
@ -674,17 +670,23 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// is used ot fetch the height only once for each vehicle simulation step. // is used ot fetch the height only once for each vehicle simulation step.
private float GetTerrainHeight(Vector3 pos) private float GetTerrainHeight(Vector3 pos)
{ {
if (m_knownTerrainHeight == null) if ((m_knownHas & m_knownChangedTerrainHeight) == 0)
{
m_knownTerrainHeight = Prim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos); m_knownTerrainHeight = Prim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos);
return (float)m_knownTerrainHeight; m_knownHas |= m_knownChangedTerrainHeight;
}
return m_knownTerrainHeight;
} }
// Since the computation of water level can be a little involved, this routine // Since the computation of water level can be a little involved, this routine
// is used ot fetch the level only once for each vehicle simulation step. // is used ot fetch the level only once for each vehicle simulation step.
private float GetWaterLevel(Vector3 pos) private float GetWaterLevel(Vector3 pos)
{ {
if (m_knownWaterLevel == null) if ((m_knownHas & m_knownChangedWaterLevel) == 0)
{
m_knownWaterLevel = Prim.PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(pos); m_knownWaterLevel = Prim.PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(pos);
m_knownHas |= m_knownChangedWaterLevel;
}
return (float)m_knownWaterLevel; return (float)m_knownWaterLevel;
} }
@ -692,8 +694,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{ {
get get
{ {
if (m_knownPosition == null) if ((m_knownHas & m_knownChangedPosition) == 0)
{
m_knownPosition = Prim.ForcePosition; m_knownPosition = Prim.ForcePosition;
m_knownHas |= m_knownChangedPosition;
}
return (Vector3)m_knownPosition; return (Vector3)m_knownPosition;
} }
set set
@ -707,8 +712,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{ {
get get
{ {
if (m_knownOrientation == null) if ((m_knownHas & m_knownChangedOrientation) == 0)
{
m_knownOrientation = Prim.ForceOrientation; m_knownOrientation = Prim.ForceOrientation;
m_knownHas |= m_knownChangedOrientation;
}
return (Quaternion)m_knownOrientation; return (Quaternion)m_knownOrientation;
} }
set set
@ -722,8 +730,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{ {
get get
{ {
if (m_knownVelocity == null) if ((m_knownHas & m_knownChangedVelocity) == 0)
{
m_knownVelocity = Prim.ForceVelocity; m_knownVelocity = Prim.ForceVelocity;
m_knownHas |= m_knownChangedVelocity;
}
return (Vector3)m_knownVelocity; return (Vector3)m_knownVelocity;
} }
set set
@ -743,8 +754,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{ {
get get
{ {
if (m_knownRotationalVelocity == null) if ((m_knownHas & m_knownChangedRotationalVelocity) == 0)
{
m_knownRotationalVelocity = Prim.ForceRotationalVelocity; m_knownRotationalVelocity = Prim.ForceRotationalVelocity;
m_knownHas |= m_knownChangedRotationalVelocity;
}
return (Vector3)m_knownRotationalVelocity; return (Vector3)m_knownRotationalVelocity;
} }
set set
@ -763,8 +777,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
{ {
get get
{ {
if (m_knownForwardVelocity == null) if ((m_knownHas & m_knownChangedForwardVelocity) == 0)
{
m_knownForwardVelocity = VehicleVelocity * Quaternion.Inverse(Quaternion.Normalize(VehicleOrientation)); m_knownForwardVelocity = VehicleVelocity * Quaternion.Inverse(Quaternion.Normalize(VehicleOrientation));
m_knownHas |= m_knownChangedForwardVelocity;
}
return (Vector3)m_knownForwardVelocity; return (Vector3)m_knownForwardVelocity;
} }
} }