refactor: make methods that do not need to be public in ODE private or internal to aid code reading/analysis. Remove some unused method arguments

0.7.2-post-fixes
Justin Clark-Casey (justincc) 2011-10-15 01:20:40 +01:00
parent acb0a5b6c1
commit 47c412ca1e
3 changed files with 195 additions and 129 deletions

View File

@ -185,7 +185,6 @@ namespace OpenSim.Region.Physics.Manager
public virtual Vector3 GetJointAxis(PhysicsJoint joint) public virtual Vector3 GetJointAxis(PhysicsJoint joint)
{ return Vector3.Zero; } { return Vector3.Zero; }
public abstract void AddPhysicsActorTaint(PhysicsActor prim); public abstract void AddPhysicsActorTaint(PhysicsActor prim);
public abstract float Simulate(float timeStep); public abstract float Simulate(float timeStep);

View File

@ -326,7 +326,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// Set a new geometry for this prim. /// Set a new geometry for this prim.
/// </summary> /// </summary>
/// <param name="geom"></param> /// <param name="geom"></param>
public void SetGeom(IntPtr geom) private void SetGeom(IntPtr geom)
{ {
prim_geom = geom; prim_geom = geom;
//Console.WriteLine("SetGeom to " + prim_geom + " for " + Name); //Console.WriteLine("SetGeom to " + prim_geom + " for " + Name);
@ -351,7 +351,7 @@ namespace OpenSim.Region.Physics.OdePlugin
//m_log.Warn("Setting Geom to: " + prim_geom); //m_log.Warn("Setting Geom to: " + prim_geom);
} }
public void enableBodySoft() private void enableBodySoft()
{ {
if (!childPrim) if (!childPrim)
{ {
@ -366,7 +366,7 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
} }
public void disableBodySoft() private void disableBodySoft()
{ {
m_disabled = true; m_disabled = true;
@ -379,7 +379,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// <summary> /// <summary>
/// Make a prim subject to physics. /// Make a prim subject to physics.
/// </summary> /// </summary>
public void enableBody() private void enableBody()
{ {
// Don't enable this body if we're a child prim // Don't enable this body if we're a child prim
// this should be taken care of in the parent function not here // this should be taken care of in the parent function not here
@ -423,7 +423,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_vehicle.Enable(Body, _parent_scene); m_vehicle.Enable(Body, _parent_scene);
} }
_parent_scene.addActivePrim(this); _parent_scene.ActivatePrim(this);
} }
} }
@ -741,7 +741,7 @@ namespace OpenSim.Region.Physics.OdePlugin
#endregion #endregion
public void setMass() private void setMass()
{ {
if (Body != (IntPtr) 0) if (Body != (IntPtr) 0)
{ {
@ -757,7 +757,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// <summary> /// <summary>
/// Stop a prim from being subject to physics. /// Stop a prim from being subject to physics.
/// </summary> /// </summary>
public void disableBody() internal void disableBody()
{ {
//this kills the body so things like 'mesh' can re-create it. //this kills the body so things like 'mesh' can re-create it.
lock (this) lock (this)
@ -766,7 +766,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
_parent_scene.remActivePrim(this); _parent_scene.DeactivatePrim(this);
m_collisionCategories &= ~CollisionCategories.Body; m_collisionCategories &= ~CollisionCategories.Body;
m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
@ -783,7 +783,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
foreach (OdePrim prm in childrenPrim) foreach (OdePrim prm in childrenPrim)
{ {
_parent_scene.remActivePrim(prm); _parent_scene.DeactivatePrim(prm);
prm.Body = IntPtr.Zero; prm.Body = IntPtr.Zero;
} }
} }
@ -793,7 +793,7 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
else else
{ {
_parent_scene.remActivePrim(this); _parent_scene.DeactivatePrim(this);
m_collisionCategories &= ~CollisionCategories.Body; m_collisionCategories &= ~CollisionCategories.Body;
m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
@ -814,7 +814,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private static Dictionary<IMesh, IntPtr> m_MeshToTriMeshMap = new Dictionary<IMesh, IntPtr>(); private static Dictionary<IMesh, IntPtr> m_MeshToTriMeshMap = new Dictionary<IMesh, IntPtr>();
public void setMesh(OdeScene parent_scene, IMesh mesh) private void setMesh(OdeScene parent_scene, IMesh mesh)
{ {
// m_log.DebugFormat("[ODE PRIM]: Setting mesh on {0} to {1}", Name, mesh); // m_log.DebugFormat("[ODE PRIM]: Setting mesh on {0} to {1}", Name, mesh);
@ -884,73 +884,73 @@ namespace OpenSim.Region.Physics.OdePlugin
// } // }
} }
public void ProcessTaints(float timestep) internal void ProcessTaints()
{ {
#if SPAM #if SPAM
Console.WriteLine("ZProcessTaints for " + Name); Console.WriteLine("ZProcessTaints for " + Name);
#endif #endif
if (m_taintadd) if (m_taintadd)
{ {
changeadd(timestep); changeadd();
} }
if (prim_geom != IntPtr.Zero) if (prim_geom != IntPtr.Zero)
{ {
if (!_position.ApproxEquals(m_taintposition, 0f)) if (!_position.ApproxEquals(m_taintposition, 0f))
changemove(timestep); changemove();
if (m_taintrot != _orientation) if (m_taintrot != _orientation)
{ {
if (childPrim && IsPhysical) // For physical child prim... if (childPrim && IsPhysical) // For physical child prim...
{ {
rotate(timestep); rotate();
// KF: ODE will also rotate the parent prim! // KF: ODE will also rotate the parent prim!
// so rotate the root back to where it was // so rotate the root back to where it was
OdePrim parent = (OdePrim)_parent; OdePrim parent = (OdePrim)_parent;
parent.rotate(timestep); parent.rotate();
} }
else else
{ {
//Just rotate the prim //Just rotate the prim
rotate(timestep); rotate();
} }
} }
if (m_taintPhysics != IsPhysical && !(m_taintparent != _parent)) if (m_taintPhysics != IsPhysical && !(m_taintparent != _parent))
changePhysicsStatus(timestep); changePhysicsStatus();
if (!_size.ApproxEquals(m_taintsize, 0f)) if (!_size.ApproxEquals(m_taintsize, 0f))
changesize(timestep); changesize();
if (m_taintshape) if (m_taintshape)
changeshape(timestep); changeshape();
if (m_taintforce) if (m_taintforce)
changeAddForce(timestep); changeAddForce();
if (m_taintaddangularforce) if (m_taintaddangularforce)
changeAddAngularForce(timestep); changeAddAngularForce();
if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f)) if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f))
changeSetTorque(timestep); changeSetTorque();
if (m_taintdisable) if (m_taintdisable)
changedisable(timestep); changedisable();
if (m_taintselected != m_isSelected) if (m_taintselected != m_isSelected)
changeSelectedStatus(timestep); changeSelectedStatus();
if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f)) if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f))
changevelocity(timestep); changevelocity();
if (m_taintparent != _parent) if (m_taintparent != _parent)
changelink(timestep); changelink();
if (m_taintCollidesWater != m_collidesWater) if (m_taintCollidesWater != m_collidesWater)
changefloatonwater(timestep); changefloatonwater();
if (!m_angularlock.ApproxEquals(m_taintAngularLock,0f)) if (!m_angularlock.ApproxEquals(m_taintAngularLock,0f))
changeAngularLock(timestep); changeAngularLock();
} }
else else
{ {
@ -958,7 +958,10 @@ Console.WriteLine("ZProcessTaints for " + Name);
} }
} }
private void changeAngularLock(float timestep) /// <summary>
/// Change prim in response to an angular lock taint.
/// </summary>
private void changeAngularLock()
{ {
// do we have a Physical object? // do we have a Physical object?
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
@ -983,11 +986,15 @@ Console.WriteLine("ZProcessTaints for " + Name);
} }
} }
} }
// Store this for later in case we get turned into a separate body // Store this for later in case we get turned into a separate body
m_angularlock = m_taintAngularLock; m_angularlock = m_taintAngularLock;
} }
private void changelink(float timestep) /// <summary>
/// Change prim in response to a link taint.
/// </summary>
private void changelink()
{ {
// If the newly set parent is not null // If the newly set parent is not null
// create link // create link
@ -1042,7 +1049,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
/// Add a child prim to this parent prim. /// Add a child prim to this parent prim.
/// </summary> /// </summary>
/// <param name="prim">Child prim</param> /// <param name="prim">Child prim</param>
public void AddChildPrim(OdePrim prim) private void AddChildPrim(OdePrim prim)
{ {
//Console.WriteLine("AddChildPrim " + Name); //Console.WriteLine("AddChildPrim " + Name);
if (this.m_localID != prim.m_localID) if (this.m_localID != prim.m_localID)
@ -1134,7 +1141,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
prm.createAMotor(m_angularlock); prm.createAMotor(m_angularlock);
} }
prm.Body = Body; prm.Body = Body;
_parent_scene.addActivePrim(prm); _parent_scene.ActivatePrim(prm);
} }
m_collisionCategories |= CollisionCategories.Body; m_collisionCategories |= CollisionCategories.Body;
@ -1179,7 +1186,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
if (m_vehicle.Type != Vehicle.TYPE_NONE) if (m_vehicle.Type != Vehicle.TYPE_NONE)
m_vehicle.Enable(Body, _parent_scene); m_vehicle.Enable(Body, _parent_scene);
_parent_scene.addActivePrim(this); _parent_scene.ActivatePrim(this);
} }
} }
} }
@ -1206,7 +1213,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
_parent_scene.remActivePrim(this); _parent_scene.DeactivatePrim(this);
} }
lock (childrenPrim) lock (childrenPrim)
@ -1245,7 +1252,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
_parent_scene.remActivePrim(this); _parent_scene.DeactivatePrim(this);
} }
lock (childrenPrim) lock (childrenPrim)
@ -1258,7 +1265,10 @@ Console.WriteLine("ZProcessTaints for " + Name);
} }
} }
private void changeSelectedStatus(float timestep) /// <summary>
/// Change prim in response to a selection taint.
/// </summary>
private void changeSelectedStatus()
{ {
if (m_taintselected) if (m_taintselected)
{ {
@ -1338,7 +1348,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
m_isSelected = m_taintselected; m_isSelected = m_taintselected;
}//end changeSelectedStatus }//end changeSelectedStatus
public void ResetTaints() internal void ResetTaints()
{ {
m_taintposition = _position; m_taintposition = _position;
m_taintrot = _orientation; m_taintrot = _orientation;
@ -1356,7 +1366,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
/// </summary> /// </summary>
/// <param name="m_targetSpace"></param> /// <param name="m_targetSpace"></param>
/// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param> /// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param>
public void CreateGeom(IntPtr m_targetSpace, IMesh mesh) private void CreateGeom(IntPtr m_targetSpace, IMesh mesh)
{ {
#if SPAM #if SPAM
Console.WriteLine("CreateGeom:"); Console.WriteLine("CreateGeom:");
@ -1442,7 +1452,7 @@ Console.WriteLine("CreateGeom:");
/// <param name="m_targetSpace"></param> /// <param name="m_targetSpace"></param>
/// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param> /// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param>
/// <returns>true if the geom was successfully removed, false if it was already gone or the remove failed.</returns> /// <returns>true if the geom was successfully removed, false if it was already gone or the remove failed.</returns>
public bool RemoveGeom() internal bool RemoveGeom()
{ {
if (prim_geom != IntPtr.Zero) if (prim_geom != IntPtr.Zero)
{ {
@ -1468,8 +1478,10 @@ Console.WriteLine("CreateGeom:");
return false; return false;
} }
} }
/// <summary>
public void changeadd(float timestep) /// Add prim in response to an add taint.
/// </summary>
private void changeadd()
{ {
int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position); int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
IntPtr targetspace = _parent_scene.calculateSpaceForGeom(_position); IntPtr targetspace = _parent_scene.calculateSpaceForGeom(_position);
@ -1513,12 +1525,15 @@ Console.WriteLine("changeadd 1");
} }
} }
changeSelectedStatus(timestep); changeSelectedStatus();
m_taintadd = false; m_taintadd = false;
} }
public void changemove(float timestep) /// <summary>
/// Move prim in response to a move taint.
/// </summary>
private void changemove()
{ {
if (IsPhysical) if (IsPhysical)
{ {
@ -1589,13 +1604,13 @@ Console.WriteLine(" JointCreateFixed");
} }
} }
changeSelectedStatus(timestep); changeSelectedStatus();
resetCollisionAccounting(); resetCollisionAccounting();
m_taintposition = _position; m_taintposition = _position;
} }
public void Move(float timestep) internal void Move(float timestep)
{ {
float fx = 0; float fx = 0;
float fy = 0; float fy = 0;
@ -1842,7 +1857,7 @@ Console.WriteLine(" JointCreateFixed");
} }
} }
public void rotate(float timestep) private void rotate()
{ {
d.Quaternion myrot = new d.Quaternion(); d.Quaternion myrot = new d.Quaternion();
myrot.X = _orientation.X; myrot.X = _orientation.X;
@ -1876,7 +1891,10 @@ Console.WriteLine(" JointCreateFixed");
m_disabled = false; m_disabled = false;
} }
public void changedisable(float timestep) /// <summary>
/// Change prim in response to a disable taint.
/// </summary>
private void changedisable()
{ {
m_disabled = true; m_disabled = true;
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
@ -1888,7 +1906,10 @@ Console.WriteLine(" JointCreateFixed");
m_taintdisable = false; m_taintdisable = false;
} }
public void changePhysicsStatus(float timestep) /// <summary>
/// Change prim in response to a physics status taint
/// </summary>
private void changePhysicsStatus()
{ {
if (IsPhysical) if (IsPhysical)
{ {
@ -1896,7 +1917,7 @@ Console.WriteLine(" JointCreateFixed");
{ {
if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim) if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
{ {
changeshape(2f); changeshape();
} }
else else
{ {
@ -1913,7 +1934,7 @@ Console.WriteLine(" JointCreateFixed");
RemoveGeom(); RemoveGeom();
//Console.WriteLine("changePhysicsStatus for " + Name); //Console.WriteLine("changePhysicsStatus for " + Name);
changeadd(2f); changeadd();
} }
if (childPrim) if (childPrim)
@ -1931,13 +1952,16 @@ Console.WriteLine(" JointCreateFixed");
} }
} }
changeSelectedStatus(timestep); changeSelectedStatus();
resetCollisionAccounting(); resetCollisionAccounting();
m_taintPhysics = IsPhysical; m_taintPhysics = IsPhysical;
} }
public void changesize(float timestamp) /// <summary>
/// Change prim in response to a size taint.
/// </summary>
private void changesize()
{ {
#if SPAM #if SPAM
m_log.DebugFormat("[ODE PRIM]: Called changesize"); m_log.DebugFormat("[ODE PRIM]: Called changesize");
@ -2007,7 +2031,8 @@ Console.WriteLine(" JointCreateFixed");
d.BodyEnable(Body); d.BodyEnable(Body);
} }
changeSelectedStatus(timestamp); changeSelectedStatus();
if (childPrim) if (childPrim)
{ {
if (_parent is OdePrim) if (_parent is OdePrim)
@ -2020,7 +2045,11 @@ Console.WriteLine(" JointCreateFixed");
m_taintsize = _size; m_taintsize = _size;
} }
public void changefloatonwater(float timestep) /// <summary>
/// Change prim in response to a float on water taint.
/// </summary>
/// <param name="timestep"></param>
private void changefloatonwater()
{ {
m_collidesWater = m_taintCollidesWater; m_collidesWater = m_taintCollidesWater;
@ -2038,7 +2067,10 @@ Console.WriteLine(" JointCreateFixed");
} }
} }
public void changeshape(float timestamp) /// <summary>
/// Change prim in response to a shape taint.
/// </summary>
private void changeshape()
{ {
// Cleanup of old prim geometry and Bodies // Cleanup of old prim geometry and Bodies
if (IsPhysical && Body != IntPtr.Zero) if (IsPhysical && Body != IntPtr.Zero)
@ -2101,7 +2133,8 @@ Console.WriteLine(" JointCreateFixed");
} }
} }
changeSelectedStatus(timestamp); changeSelectedStatus();
if (childPrim) if (childPrim)
{ {
if (_parent is OdePrim) if (_parent is OdePrim)
@ -2115,7 +2148,10 @@ Console.WriteLine(" JointCreateFixed");
m_taintshape = false; m_taintshape = false;
} }
public void changeAddForce(float timestamp) /// <summary>
/// Change prim in response to an add force taint.
/// </summary>
private void changeAddForce()
{ {
if (!m_isSelected) if (!m_isSelected)
{ {
@ -2163,7 +2199,10 @@ Console.WriteLine(" JointCreateFixed");
m_taintforce = false; m_taintforce = false;
} }
public void changeSetTorque(float timestamp) /// <summary>
/// Change prim in response to a torque taint.
/// </summary>
private void changeSetTorque()
{ {
if (!m_isSelected) if (!m_isSelected)
{ {
@ -2176,7 +2215,10 @@ Console.WriteLine(" JointCreateFixed");
m_taintTorque = Vector3.Zero; m_taintTorque = Vector3.Zero;
} }
public void changeAddAngularForce(float timestamp) /// <summary>
/// Change prim in response to an angular force taint.
/// </summary>
private void changeAddAngularForce()
{ {
if (!m_isSelected) if (!m_isSelected)
{ {
@ -2204,7 +2246,10 @@ Console.WriteLine(" JointCreateFixed");
m_taintaddangularforce = false; m_taintaddangularforce = false;
} }
private void changevelocity(float timestep) /// <summary>
/// Change prim in response to a velocity taint.
/// </summary>
private void changevelocity()
{ {
if (!m_isSelected) if (!m_isSelected)
{ {
@ -2219,10 +2264,11 @@ Console.WriteLine(" JointCreateFixed");
//resetCollisionAccounting(); //resetCollisionAccounting();
} }
m_taintVelocity = Vector3.Zero; m_taintVelocity = Vector3.Zero;
} }
public void setPrimForRemoval() internal void setPrimForRemoval()
{ {
m_taintremove = true; m_taintremove = true;
} }
@ -2438,16 +2484,13 @@ Console.WriteLine(" JointCreateFixed");
set set
{ {
if (QuaternionIsFinite(value)) if (QuaternionIsFinite(value))
{
_orientation = value; _orientation = value;
}
else else
m_log.WarnFormat("[PHYSICS]: Got NaN quaternion Orientation from Scene in Object {0}", Name); m_log.WarnFormat("[PHYSICS]: Got NaN quaternion Orientation from Scene in Object {0}", Name);
} }
} }
internal static bool QuaternionIsFinite(Quaternion q) private static bool QuaternionIsFinite(Quaternion q)
{ {
if (Single.IsNaN(q.X) || Single.IsInfinity(q.X)) if (Single.IsNaN(q.X) || Single.IsInfinity(q.X))
return false; return false;
@ -2465,12 +2508,6 @@ Console.WriteLine(" JointCreateFixed");
get { return _acceleration; } get { return _acceleration; }
} }
public void SetAcceleration(Vector3 accel)
{
_acceleration = accel;
}
public override void AddForce(Vector3 force, bool pushforce) public override void AddForce(Vector3 force, bool pushforce)
{ {
if (force.IsFinite()) if (force.IsFinite())
@ -2574,7 +2611,7 @@ Console.WriteLine(" JointCreateFixed");
} }
} }
public void UpdatePositionAndVelocity() internal void UpdatePositionAndVelocity()
{ {
// no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
if (_parent == null) if (_parent == null)
@ -2943,7 +2980,7 @@ Console.WriteLine(" JointCreateFixed");
d.JointSetAMotorParam(Amotor, (int)dParam.FMax, Mass * 50f);// d.JointSetAMotorParam(Amotor, (int)dParam.FMax, Mass * 50f);//
} }
public Matrix4 FromDMass(d.Mass pMass) private Matrix4 FromDMass(d.Mass pMass)
{ {
Matrix4 obj; Matrix4 obj;
obj.M11 = pMass.I.M00; obj.M11 = pMass.I.M00;
@ -2965,7 +3002,7 @@ Console.WriteLine(" JointCreateFixed");
return obj; return obj;
} }
public d.Mass FromMatrix4(Matrix4 pMat, ref d.Mass obj) private d.Mass FromMatrix4(Matrix4 pMat, ref d.Mass obj)
{ {
obj.I.M00 = pMat[0, 0]; obj.I.M00 = pMat[0, 0];
obj.I.M01 = pMat[0, 1]; obj.I.M01 = pMat[0, 1];
@ -3153,6 +3190,7 @@ Console.WriteLine(" JointCreateFixed");
break; break;
} }
} }
private static float determinant3x3(Matrix4 pMat) private static float determinant3x3(Matrix4 pMat)
{ {
float det = 0; float det = 0;
@ -3190,4 +3228,4 @@ Console.WriteLine(" JointCreateFixed");
m_material = pMaterial; m_material = pMaterial;
} }
} }
} }

View File

@ -193,9 +193,30 @@ namespace OpenSim.Region.Physics.OdePlugin
private readonly HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>(); private readonly HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>();
private readonly HashSet<OdePrim> _prims = new HashSet<OdePrim>(); private readonly HashSet<OdePrim> _prims = new HashSet<OdePrim>();
private readonly HashSet<OdePrim> _activeprims = new HashSet<OdePrim>(); private readonly HashSet<OdePrim> _activeprims = new HashSet<OdePrim>();
private readonly HashSet<OdePrim> _taintedPrimH = new HashSet<OdePrim>();
/// <summary>
/// Used to lock on manipulation of _taintedPrimL and _taintedPrimH
/// </summary>
private readonly Object _taintedPrimLock = new Object(); private readonly Object _taintedPrimLock = new Object();
/// <summary>
/// List of tainted prims.
/// </summary>
/// <remarks>
/// A tainted prim is one that has taints to process before performing any other operations. The list is
/// cleared after processing.
/// </remarks>
private readonly List<OdePrim> _taintedPrimL = new List<OdePrim>(); private readonly List<OdePrim> _taintedPrimL = new List<OdePrim>();
/// <summary>
/// HashSet of tainted prims.
/// </summary>
/// <remarks>
/// A tainted prim is one that has taints to process before performing any other operations. The hashset is
/// cleared after processing.
/// </remarks>
private readonly HashSet<OdePrim> _taintedPrimH = new HashSet<OdePrim>();
private readonly HashSet<OdeCharacter> _taintedActors = new HashSet<OdeCharacter>(); private readonly HashSet<OdeCharacter> _taintedActors = new HashSet<OdeCharacter>();
private readonly List<d.ContactGeom> _perloopContact = new List<d.ContactGeom>(); private readonly List<d.ContactGeom> _perloopContact = new List<d.ContactGeom>();
@ -257,6 +278,9 @@ namespace OpenSim.Region.Physics.OdePlugin
// split static geometry collision handling into spaces of 30 meters // split static geometry collision handling into spaces of 30 meters
public IntPtr[,] staticPrimspace; public IntPtr[,] staticPrimspace;
/// <summary>
/// Used to lock the entire physics scene. Locked during the main part of Simulate()
/// </summary>
public Object OdeLock; public Object OdeLock;
public IMesher mesher; public IMesher mesher;
@ -643,15 +667,15 @@ namespace OpenSim.Region.Physics.OdePlugin
//while (d.SpaceLockQuery(space)) { } // Wait and do nothing //while (d.SpaceLockQuery(space)) { } // Wait and do nothing
} }
/// <summary> // /// <summary>
/// Debug space message for printing the space that a prim/avatar is in. // /// Debug space message for printing the space that a prim/avatar is in.
/// </summary> // /// </summary>
/// <param name="pos"></param> // /// <param name="pos"></param>
/// <returns>Returns which split up space the given position is in.</returns> // /// <returns>Returns which split up space the given position is in.</returns>
public string whichspaceamIin(Vector3 pos) // public string whichspaceamIin(Vector3 pos)
{ // {
return calculateSpaceForGeom(pos).ToString(); // return calculateSpaceForGeom(pos).ToString();
} // }
#region Collision Detection #region Collision Detection
@ -1402,7 +1426,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// } // }
} }
public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount) private int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount)
{ {
/* String name1 = null; /* String name1 = null;
String name2 = null; String name2 = null;
@ -1421,7 +1445,7 @@ namespace OpenSim.Region.Physics.OdePlugin
return 1; return 1;
} }
public int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex) private int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex)
{ {
// String name1 = null; // String name1 = null;
// String name2 = null; // String name2 = null;
@ -1551,7 +1575,7 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
// Recovered for use by fly height. Kitto Flora // Recovered for use by fly height. Kitto Flora
public float GetTerrainHeightAtXY(float x, float y) internal float GetTerrainHeightAtXY(float x, float y)
{ {
int offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize; int offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
int offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize; int offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
@ -1609,7 +1633,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// Add actor to the list that should receive collision events in the simulate loop. /// Add actor to the list that should receive collision events in the simulate loop.
/// </summary> /// </summary>
/// <param name="obj"></param> /// <param name="obj"></param>
public void AddCollisionEventReporting(PhysicsActor obj) internal void AddCollisionEventReporting(PhysicsActor obj)
{ {
lock (_collisionEventPrim) lock (_collisionEventPrim)
{ {
@ -1622,7 +1646,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// Remove actor from the list that should receive collision events in the simulate loop. /// Remove actor from the list that should receive collision events in the simulate loop.
/// </summary> /// </summary>
/// <param name="obj"></param> /// <param name="obj"></param>
public void RemoveCollisionEventReporting(PhysicsActor obj) internal void RemoveCollisionEventReporting(PhysicsActor obj)
{ {
lock (_collisionEventPrim) lock (_collisionEventPrim)
{ {
@ -1646,7 +1670,13 @@ namespace OpenSim.Region.Physics.OdePlugin
return newAv; return newAv;
} }
public void AddCharacter(OdeCharacter chr) public override void RemoveAvatar(PhysicsActor actor)
{
//m_log.Debug("[PHYSICS]:ODELOCK");
((OdeCharacter) actor).Destroy();
}
internal void AddCharacter(OdeCharacter chr)
{ {
lock (_characters) lock (_characters)
{ {
@ -1659,7 +1689,7 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
} }
public void RemoveCharacter(OdeCharacter chr) internal void RemoveCharacter(OdeCharacter chr)
{ {
lock (_characters) lock (_characters)
{ {
@ -1670,7 +1700,7 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
} }
public void BadCharacter(OdeCharacter chr) internal void BadCharacter(OdeCharacter chr)
{ {
lock (_badCharacter) lock (_badCharacter)
{ {
@ -1679,12 +1709,6 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
} }
public override void RemoveAvatar(PhysicsActor actor)
{
//m_log.Debug("[PHYSICS]:ODELOCK");
((OdeCharacter) actor).Destroy();
}
private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation, private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation,
PrimitiveBaseShape pbs, bool isphysical, uint localID) PrimitiveBaseShape pbs, bool isphysical, uint localID)
{ {
@ -1704,13 +1728,17 @@ namespace OpenSim.Region.Physics.OdePlugin
return newPrim; return newPrim;
} }
public void addActivePrim(OdePrim activatePrim) /// <summary>
/// Make this prim subject to physics.
/// </summary>
/// <param name="prim"></param>
internal void ActivatePrim(OdePrim prim)
{ {
// adds active prim.. (ones that should be iterated over in collisions_optimized // adds active prim.. (ones that should be iterated over in collisions_optimized
lock (_activeprims) lock (_activeprims)
{ {
if (!_activeprims.Contains(activatePrim)) if (!_activeprims.Contains(prim))
_activeprims.Add(activatePrim); _activeprims.Add(prim);
//else //else
// m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent"); // m_log.Warn("[PHYSICS]: Double Entry in _activeprims detected, potential crash immenent");
} }
@ -2083,12 +2111,14 @@ namespace OpenSim.Region.Physics.OdePlugin
return new Vector3(axis.X, axis.Y, axis.Z); return new Vector3(axis.X, axis.Y, axis.Z);
} }
public void remActivePrim(OdePrim deactivatePrim) /// <summary>
/// Stop this prim being subject to physics
/// </summary>
/// <param name="prim"></param>
internal void DeactivatePrim(OdePrim prim)
{ {
lock (_activeprims) lock (_activeprims)
{ _activeprims.Remove(prim);
_activeprims.Remove(deactivatePrim);
}
} }
public override void RemovePrim(PhysicsActor prim) public override void RemovePrim(PhysicsActor prim)
@ -2120,7 +2150,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// that the space was using. /// that the space was using.
/// </summary> /// </summary>
/// <param name="prim"></param> /// <param name="prim"></param>
public void RemovePrimThreadLocked(OdePrim prim) internal void RemovePrimThreadLocked(OdePrim prim)
{ {
//Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName); //Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName);
lock (prim) lock (prim)
@ -2216,7 +2246,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// Takes a space pointer and zeros out the array we're using to hold the spaces /// Takes a space pointer and zeros out the array we're using to hold the spaces
/// </summary> /// </summary>
/// <param name="pSpace"></param> /// <param name="pSpace"></param>
public void resetSpaceArrayItemToZero(IntPtr pSpace) private void resetSpaceArrayItemToZero(IntPtr pSpace)
{ {
for (int x = 0; x < staticPrimspace.GetLength(0); x++) for (int x = 0; x < staticPrimspace.GetLength(0); x++)
{ {
@ -2228,10 +2258,10 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
} }
public void resetSpaceArrayItemToZero(int arrayitemX, int arrayitemY) // private void resetSpaceArrayItemToZero(int arrayitemX, int arrayitemY)
{ // {
staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero; // staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero;
} // }
/// <summary> /// <summary>
/// Called when a static prim moves. Allocates a space for the prim based on its position /// Called when a static prim moves. Allocates a space for the prim based on its position
@ -2240,7 +2270,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// <param name="pos">the position that the geom moved to</param> /// <param name="pos">the position that the geom moved to</param>
/// <param name="currentspace">a pointer to the space it was in before it was moved.</param> /// <param name="currentspace">a pointer to the space it was in before it was moved.</param>
/// <returns>a pointer to the new space it's in</returns> /// <returns>a pointer to the new space it's in</returns>
public IntPtr recalculateSpaceForGeom(IntPtr geom, Vector3 pos, IntPtr currentspace) internal IntPtr recalculateSpaceForGeom(IntPtr geom, Vector3 pos, IntPtr currentspace)
{ {
// Called from setting the Position and Size of an ODEPrim so // Called from setting the Position and Size of an ODEPrim so
// it's already in locked space. // it's already in locked space.
@ -2371,7 +2401,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// <param name="iprimspaceArrItemX"></param> /// <param name="iprimspaceArrItemX"></param>
/// <param name="iprimspaceArrItemY"></param> /// <param name="iprimspaceArrItemY"></param>
/// <returns>A pointer to the created space</returns> /// <returns>A pointer to the created space</returns>
public IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY) internal IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY)
{ {
// creating a new space for prim and inserting it into main space. // creating a new space for prim and inserting it into main space.
staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero); staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero);
@ -2387,7 +2417,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// </summary> /// </summary>
/// <param name="pos"></param> /// <param name="pos"></param>
/// <returns>a pointer to the space. This could be a new space or reused space.</returns> /// <returns>a pointer to the space. This could be a new space or reused space.</returns>
public IntPtr calculateSpaceForGeom(Vector3 pos) internal IntPtr calculateSpaceForGeom(Vector3 pos)
{ {
int[] xyspace = calculateSpaceArrayItemFromPos(pos); int[] xyspace = calculateSpaceArrayItemFromPos(pos);
//m_log.Info("[Physics]: Attempting to use arrayItem: " + xyspace[0].ToString() + "," + xyspace[1].ToString()); //m_log.Info("[Physics]: Attempting to use arrayItem: " + xyspace[0].ToString() + "," + xyspace[1].ToString());
@ -2399,7 +2429,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// </summary> /// </summary>
/// <param name="pos"></param> /// <param name="pos"></param>
/// <returns>an array item based on the position</returns> /// <returns>an array item based on the position</returns>
public int[] calculateSpaceArrayItemFromPos(Vector3 pos) internal int[] calculateSpaceArrayItemFromPos(Vector3 pos)
{ {
int[] returnint = new int[2]; int[] returnint = new int[2];
@ -2426,7 +2456,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// </summary> /// </summary>
/// <param name="pbs"></param> /// <param name="pbs"></param>
/// <returns></returns> /// <returns></returns>
public bool needsMeshing(PrimitiveBaseShape pbs) internal bool needsMeshing(PrimitiveBaseShape pbs)
{ {
// most of this is redundant now as the mesher will return null if it cant mesh a prim // most of this is redundant now as the mesher will return null if it cant mesh a prim
// but we still need to check for sculptie meshing being enabled so this is the most // but we still need to check for sculptie meshing being enabled so this is the most
@ -2699,7 +2729,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
else else
{ {
// Console.WriteLine("Simulate calls ProcessTaints for {0}", prim.Name); // Console.WriteLine("Simulate calls ProcessTaints for {0}", prim.Name);
prim.ProcessTaints(timeStep); prim.ProcessTaints();
} }
processedtaints = true; processedtaints = true;
@ -2893,7 +2923,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
/// <remarks> /// <remarks>
/// Called by the main Simulate() loop if NINJA joints are active. Should not be called from anywhere else. /// Called by the main Simulate() loop if NINJA joints are active. Should not be called from anywhere else.
/// </remarks> /// </remarks>
protected void SimulatePendingNINJAJoints() private void SimulatePendingNINJAJoints()
{ {
// Create pending joints, if possible // Create pending joints, if possible
@ -3084,7 +3114,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
/// Called as part of the Simulate() loop if NINJA physics is active. Must only be called from there. /// Called as part of the Simulate() loop if NINJA physics is active. Must only be called from there.
/// </remarks> /// </remarks>
/// <param name="actor"></param> /// <param name="actor"></param>
protected void SimulateActorPendingJoints(OdePrim actor) private void SimulateActorPendingJoints(OdePrim actor)
{ {
// If an actor moved, move its joint proxy objects as well. // If an actor moved, move its joint proxy objects as well.
// There seems to be an event PhysicsActor.OnPositionUpdate that could be used // There seems to be an event PhysicsActor.OnPositionUpdate that could be used
@ -3121,7 +3151,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
} }
#region ODE Specific Terrain Fixes #region ODE Specific Terrain Fixes
public float[] ResizeTerrain512NearestNeighbour(float[] heightMap) private float[] ResizeTerrain512NearestNeighbour(float[] heightMap)
{ {
float[] returnarr = new float[262144]; float[] returnarr = new float[262144];
float[,] resultarr = new float[(int)WorldExtents.X, (int)WorldExtents.Y]; float[,] resultarr = new float[(int)WorldExtents.X, (int)WorldExtents.Y];
@ -3234,7 +3264,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
return returnarr; return returnarr;
} }
public float[] ResizeTerrain512Interpolation(float[] heightMap) private float[] ResizeTerrain512Interpolation(float[] heightMap)
{ {
float[] returnarr = new float[262144]; float[] returnarr = new float[262144];
float[,] resultarr = new float[512,512]; float[,] resultarr = new float[512,512];
@ -3402,7 +3432,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
} }
} }
public void SetTerrain(float[] heightMap, Vector3 pOffset) private void SetTerrain(float[] heightMap, Vector3 pOffset)
{ {
// this._heightmap[i] = (double)heightMap[i]; // this._heightmap[i] = (double)heightMap[i];
// dbm (danx0r) -- creating a buffer zone of one extra sample all around // dbm (danx0r) -- creating a buffer zone of one extra sample all around
@ -3531,7 +3561,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
{ {
} }
public float GetWaterLevel() internal float GetWaterLevel()
{ {
return waterlevel; return waterlevel;
} }
@ -3606,7 +3636,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
randomizeWater(waterlevel); randomizeWater(waterlevel);
} }
public void randomizeWater(float baseheight) private void randomizeWater(float baseheight)
{ {
const uint heightmapWidth = m_regionWidth + 2; const uint heightmapWidth = m_regionWidth + 2;
const uint heightmapHeight = m_regionHeight + 2; const uint heightmapHeight = m_regionHeight + 2;
@ -3658,9 +3688,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle); d.RFromAxisAndAngle(out R, v3.X, v3.Y, v3.Z, angle);
d.GeomSetRotation(WaterGeom, ref R); d.GeomSetRotation(WaterGeom, ref R);
d.GeomSetPosition(WaterGeom, 128, 128, 0); d.GeomSetPosition(WaterGeom, 128, 128, 0);
} }
} }
public override void Dispose() public override void Dispose()
@ -3707,6 +3735,7 @@ Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
} }
} }
} }
return returncolliders; return returncolliders;
} }