refactor: move 3x copy/pasted ode structure removal code in ODECharacter into a DestroyOdeStructures() method
also adds some method doc0.7.2-post-fixes
parent
b342fb9c0a
commit
64c42a729a
|
@ -75,8 +75,25 @@ namespace OpenSim.Region.Physics.Manager
|
|||
|
||||
public abstract void Initialise(IMesher meshmerizer, IConfigSource config);
|
||||
|
||||
/// <summary>
|
||||
/// Add an avatar
|
||||
/// </summary>
|
||||
/// <param name="avName"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <param name="size"></param>
|
||||
/// <param name="isFlying"></param>
|
||||
/// <returns></returns>
|
||||
public abstract PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying);
|
||||
|
||||
/// <summary>
|
||||
/// Add an avatar
|
||||
/// </summary>
|
||||
/// <param name="localID"></param>
|
||||
/// <param name="avName"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <param name="size"></param>
|
||||
/// <param name="isFlying"></param>
|
||||
/// <returns></returns>
|
||||
public virtual PhysicsActor AddAvatar(uint localID, string avName, Vector3 position, Vector3 size, bool isFlying)
|
||||
{
|
||||
PhysicsActor ret = AddAvatar(avName, position, size, isFlying);
|
||||
|
@ -84,10 +101,14 @@ namespace OpenSim.Region.Physics.Manager
|
|||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove an avatar.
|
||||
/// </summary>
|
||||
/// <param name="actor"></param>
|
||||
public abstract void RemoveAvatar(PhysicsActor actor);
|
||||
|
||||
/// <summary>
|
||||
/// Remove a prim from the physics scene.
|
||||
/// Remove a prim.
|
||||
/// </summary>
|
||||
/// <param name="prim"></param>
|
||||
public abstract void RemovePrim(PhysicsActor prim);
|
||||
|
|
|
@ -39,7 +39,6 @@ namespace OpenSim.Region.Physics.OdePlugin
|
|||
/// <summary>
|
||||
/// Various properties that ODE uses for AMotors but isn't exposed in ODE.NET so we must define them ourselves.
|
||||
/// </summary>
|
||||
|
||||
public enum dParam : int
|
||||
{
|
||||
LowStop = 0,
|
||||
|
@ -64,6 +63,7 @@ namespace OpenSim.Region.Physics.OdePlugin
|
|||
StopERP3 = 7 + 512,
|
||||
StopCFM3 = 8 + 512
|
||||
}
|
||||
|
||||
public class OdeCharacter : PhysicsActor
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
@ -108,8 +108,11 @@ namespace OpenSim.Region.Physics.OdePlugin
|
|||
public float MinimumGroundFlightOffset = 3f;
|
||||
|
||||
private float m_tainted_CAPSULE_LENGTH; // set when the capsule length changes.
|
||||
private float m_tiltMagnitudeWhenProjectedOnXYPlane = 0.1131371f; // used to introduce a fixed tilt because a straight-up capsule falls through terrain, probably a bug in terrain collider
|
||||
|
||||
/// <summary>
|
||||
/// Used to introduce a fixed tilt because a straight-up capsule falls through terrain, probably a bug in terrain collider
|
||||
/// </summary>
|
||||
private float m_tiltMagnitudeWhenProjectedOnXYPlane = 0.1131371f;
|
||||
|
||||
private float m_buoyancy = 0f;
|
||||
|
||||
|
@ -891,12 +894,14 @@ namespace OpenSim.Region.Physics.OdePlugin
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Called from Simulate
|
||||
/// This is the avatar's movement control + PID Controller
|
||||
/// </summary>
|
||||
/// <param name="timeStep"></param>
|
||||
/// <param name="defects">
|
||||
/// If there is something wrong with the character (e.g. its position is non-finite)
|
||||
/// then it is added to this list. The ODE structures associated with it are also destroyed.</param>
|
||||
public void Move(float timeStep, List<OdeCharacter> defects)
|
||||
{
|
||||
// no lock; for now it's only called from within Simulate()
|
||||
|
@ -918,36 +923,12 @@ namespace OpenSim.Region.Physics.OdePlugin
|
|||
|
||||
if (!localPos.IsFinite())
|
||||
{
|
||||
|
||||
m_log.Warn("[PHYSICS]: Avatar Position is non-finite!");
|
||||
|
||||
defects.Add(this);
|
||||
// _parent_scene.RemoveCharacter(this);
|
||||
|
||||
// destroy avatar capsule and related ODE data
|
||||
if (Amotor != IntPtr.Zero)
|
||||
{
|
||||
// Kill the Amotor
|
||||
d.JointDestroy(Amotor);
|
||||
Amotor = IntPtr.Zero;
|
||||
}
|
||||
|
||||
//kill the Geometry
|
||||
_parent_scene.waitForSpaceUnlock(_parent_scene.space);
|
||||
|
||||
if (Body != IntPtr.Zero)
|
||||
{
|
||||
//kill the body
|
||||
d.BodyDestroy(Body);
|
||||
|
||||
Body = IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (Shell != IntPtr.Zero)
|
||||
{
|
||||
d.GeomDestroy(Shell);
|
||||
_parent_scene.geom_name_map.Remove(Shell);
|
||||
Shell = IntPtr.Zero;
|
||||
}
|
||||
DestroyOdeStructures();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -975,6 +956,7 @@ namespace OpenSim.Region.Physics.OdePlugin
|
|||
_zeroFlag = true;
|
||||
_zeroPosition = d.BodyGetPosition(Body);
|
||||
}
|
||||
|
||||
if (m_pidControllerActive)
|
||||
{
|
||||
// We only want to deactivate the PID Controller if we think we want to have our surrogate
|
||||
|
@ -1051,6 +1033,7 @@ namespace OpenSim.Region.Physics.OdePlugin
|
|||
vec.Z = (_target_velocity.Z - vel.Z) * (PID_D);
|
||||
}
|
||||
}
|
||||
|
||||
if (flying)
|
||||
{
|
||||
vec.Z += ((-1 * _parent_scene.gravityz) * m_mass);
|
||||
|
@ -1065,44 +1048,22 @@ namespace OpenSim.Region.Physics.OdePlugin
|
|||
}
|
||||
// end add Kitto Flora
|
||||
}
|
||||
|
||||
if (vec.IsFinite())
|
||||
{
|
||||
doForce(vec);
|
||||
|
||||
if (!_zeroFlag)
|
||||
{
|
||||
AlignAvatarTiltWithCurrentDirectionOfMovement(vec);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Warn("[PHYSICS]: Got a NaN force vector in Move()");
|
||||
m_log.Warn("[PHYSICS]: Avatar Position is non-finite!");
|
||||
defects.Add(this);
|
||||
// _parent_scene.RemoveCharacter(this);
|
||||
// destroy avatar capsule and related ODE data
|
||||
if (Amotor != IntPtr.Zero)
|
||||
{
|
||||
// Kill the Amotor
|
||||
d.JointDestroy(Amotor);
|
||||
Amotor = IntPtr.Zero;
|
||||
}
|
||||
//kill the Geometry
|
||||
_parent_scene.waitForSpaceUnlock(_parent_scene.space);
|
||||
|
||||
if (Body != IntPtr.Zero)
|
||||
{
|
||||
//kill the body
|
||||
d.BodyDestroy(Body);
|
||||
|
||||
Body = IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (Shell != IntPtr.Zero)
|
||||
{
|
||||
d.GeomDestroy(Shell);
|
||||
_parent_scene.geom_name_map.Remove(Shell);
|
||||
Shell = IntPtr.Zero;
|
||||
}
|
||||
DestroyOdeStructures();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1126,7 +1087,6 @@ namespace OpenSim.Region.Physics.OdePlugin
|
|||
m_log.WarnFormat("[ODEPLUGIN]: Avatar Null reference for Avatar {0}, physical actor {1}", m_name, m_uuid);
|
||||
}
|
||||
|
||||
|
||||
// kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!)
|
||||
if (vec.X < 0.0f) vec.X = 0.0f;
|
||||
if (vec.Y < 0.0f) vec.Y = 0.0f;
|
||||
|
@ -1204,6 +1164,38 @@ namespace OpenSim.Region.Physics.OdePlugin
|
|||
_parent_scene.AddPhysicsActorTaint(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used internally to destroy the ODE structures associated with this character.
|
||||
/// </summary>
|
||||
public void DestroyOdeStructures()
|
||||
{
|
||||
// destroy avatar capsule and related ODE data
|
||||
if (Amotor != IntPtr.Zero)
|
||||
{
|
||||
// Kill the Amotor
|
||||
d.JointDestroy(Amotor);
|
||||
Amotor = IntPtr.Zero;
|
||||
}
|
||||
|
||||
//kill the Geometry
|
||||
_parent_scene.waitForSpaceUnlock(_parent_scene.space);
|
||||
|
||||
if (Body != IntPtr.Zero)
|
||||
{
|
||||
//kill the body
|
||||
d.BodyDestroy(Body);
|
||||
|
||||
Body = IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (Shell != IntPtr.Zero)
|
||||
{
|
||||
d.GeomDestroy(Shell);
|
||||
_parent_scene.geom_name_map.Remove(Shell);
|
||||
Shell = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
public override void CrossingFailure()
|
||||
{
|
||||
}
|
||||
|
@ -1273,7 +1265,6 @@ namespace OpenSim.Region.Physics.OdePlugin
|
|||
|
||||
public void ProcessTaints(float timestep)
|
||||
{
|
||||
|
||||
if (m_tainted_isPhysical != m_isPhysical)
|
||||
{
|
||||
if (m_tainted_isPhysical)
|
||||
|
@ -1295,31 +1286,7 @@ namespace OpenSim.Region.Physics.OdePlugin
|
|||
else
|
||||
{
|
||||
_parent_scene.RemoveCharacter(this);
|
||||
// destroy avatar capsule and related ODE data
|
||||
if (Amotor != IntPtr.Zero)
|
||||
{
|
||||
// Kill the Amotor
|
||||
d.JointDestroy(Amotor);
|
||||
Amotor = IntPtr.Zero;
|
||||
}
|
||||
//kill the Geometry
|
||||
_parent_scene.waitForSpaceUnlock(_parent_scene.space);
|
||||
|
||||
if (Body != IntPtr.Zero)
|
||||
{
|
||||
//kill the body
|
||||
d.BodyDestroy(Body);
|
||||
|
||||
Body = IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (Shell != IntPtr.Zero)
|
||||
{
|
||||
d.GeomDestroy(Shell);
|
||||
_parent_scene.geom_name_map.Remove(Shell);
|
||||
Shell = IntPtr.Zero;
|
||||
}
|
||||
|
||||
DestroyOdeStructures();
|
||||
}
|
||||
|
||||
m_isPhysical = m_tainted_isPhysical;
|
||||
|
|
Loading…
Reference in New Issue