* Cleaned up tons of code duplication in ODEPrim

* Re-enabled the native ODE prim types when possible
* Fixed several invalid assumptions in the prim recycle process.
* Added better message for 'reused a disposed physicsactor'
* Added a way to recover from errors during collision_optimized
* Added a way to recover from an error condition where prim_geom wasn't reset properly
0.6.0-stable
Teravus Ovares 2008-10-14 02:48:30 +00:00
parent 55fa9c7378
commit 180e3de50f
2 changed files with 253 additions and 331 deletions

View File

@ -161,22 +161,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_density = parent_scene.geomDefaultDensity;
m_tensor = parent_scene.bodyMotorJointMaxforceTensor;
body_autodisable_frames = parent_scene.bodyFramesAutoDisable;
//if (_position.X > 257)
//{
//_position.X = 257;
//}
//if (_position.X < 0)
//{
//_position.X = 0;
//}
//if (_position.Y > 257)
//{
//_position.Y = 257;
//}
//if (_position.Y < 0)
//{
// _position.Y = 0;
//}
prim_geom = (IntPtr)0;
prev_geom = (IntPtr)0;
@ -715,14 +700,14 @@ namespace OpenSim.Region.Physics.OdePlugin
oldMesh = null;
}
if (IsPhysical && Body == (IntPtr) 0)
{
// if (IsPhysical && Body == (IntPtr) 0)
// {
// Recreate the body
m_interpenetrationcount = 0;
m_collisionscore = 0;
// m_interpenetrationcount = 0;
// m_collisionscore = 0;
enableBody();
}
// enableBody();
// }
}
public void ProcessTaints(float timestep)
@ -775,7 +760,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
else
{
m_log.Error("[PHYSICS]: The scene reused a disposed PhysActor! *waves finger*, Don't be evil.");
m_log.Error("[PHYSICS]: The scene reused a disposed PhysActor! *waves finger*, Don't be evil. A couple of things can cause this. An improper prim breakdown(be sure to set prim_geom to zero after d.GeomDestroy! An improper buildup (creating the geom failed). Or, the Scene Reused a physics actor after disposing it.)");
}
}
@ -910,31 +895,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_taintVelocity = PhysicsVector.Zero;
}
public void changeadd(float timestep)
{
int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
IntPtr targetspace = _parent_scene.calculateSpaceForGeom(_position);
if (targetspace == IntPtr.Zero)
targetspace = _parent_scene.createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]);
m_targetSpace = targetspace;
if (_mesh == null)
{
if (_parent_scene.needsMeshing(_pbs))
{
// Don't need to re-enable body.. it's done in SetMesh
_mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical);
// createmesh returns null when it's a shape that isn't a cube.
}
}
//if (_mesh == null )
// _mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical);
lock (OdeScene.OdeLock)
public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh)
{
if (_mesh != null)
{
@ -990,18 +951,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
}
//else if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight)
//{
//Cyllinder
//if (_size.X == _size.Y)
//{
//prim_geom = d.CreateCylinder(m_targetSpace, _size.X / 2, _size.Z);
//}
//else
//{
//prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
//}
//}
else
{
_parent_scene.waitForSpaceUnlock(m_targetSpace);
@ -1017,6 +967,33 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
}
}
public void changeadd(float timestep)
{
int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
IntPtr targetspace = _parent_scene.calculateSpaceForGeom(_position);
if (targetspace == IntPtr.Zero)
targetspace = _parent_scene.createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]);
m_targetSpace = targetspace;
if (_mesh == null)
{
if (_parent_scene.needsMeshing(_pbs))
{
// Don't need to re-enable body.. it's done in SetMesh
_mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical);
// createmesh returns null when it's a shape that isn't a cube.
}
}
lock (OdeScene.OdeLock)
{
CreateGeom(m_targetSpace, _mesh);
if (prim_geom != (IntPtr) 0)
{
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
@ -1277,8 +1254,22 @@ namespace OpenSim.Region.Physics.OdePlugin
{
if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
{
if (prim_geom != IntPtr.Zero)
{
try
{
d.GeomDestroy(prim_geom);
prim_geom = IntPtr.Zero;
_mesh = null;
}
catch (System.AccessViolationException)
{
prim_geom = IntPtr.Zero;
m_log.Error("[PHYSICS]: PrimGeom dead");
}
}
changeadd(2f);
}
@ -1340,9 +1331,16 @@ namespace OpenSim.Region.Physics.OdePlugin
//IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
if (mesh != null)
CreateGeom(m_targetSpace, mesh);
}
else
{
setMesh(_parent_scene, mesh);
_mesh = null;
CreateGeom(m_targetSpace, _mesh);
}
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion();
myrot.X = _orientation.X;
@ -1359,48 +1357,6 @@ namespace OpenSim.Region.Physics.OdePlugin
enableBody();
d.BodyEnable(Body);
}
}
else
{
if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1)
{
if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z)
{
if (((_size.X / 2f) > 0f) && ((_size.X / 2f) < 1000))
{
_parent_scene.waitForSpaceUnlock(m_targetSpace);
SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2));
}
else
{
m_log.Info("[PHYSICS]: Failed to load a sphere bad size");
_parent_scene.waitForSpaceUnlock(m_targetSpace);
SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
}
}
else
{
_parent_scene.waitForSpaceUnlock(m_targetSpace);
SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
}
}
else
{
_parent_scene.waitForSpaceUnlock(m_targetSpace);
SetGeom(prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
}
//prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion();
myrot.X = _orientation.X;
myrot.Y = _orientation.Y;
myrot.Z = _orientation.Z;
myrot.W = _orientation.W;
d.GeomSetQuaternion(prim_geom, ref myrot);
}
}
_parent_scene.geom_name_map[prim_geom] = oldname;
@ -1609,7 +1565,15 @@ namespace OpenSim.Region.Physics.OdePlugin
{
disableBody();
}
try
{
d.GeomDestroy(prim_geom);
}
catch (System.AccessViolationException)
{
prim_geom = IntPtr.Zero;
m_log.Error("[PHYSICS]: PrimGeom dead");
}
prim_geom = (IntPtr) 0;
// we don't need to do space calculation because the client sends a position update also.
if (_size.X <= 0) _size.X = 0.01f;
@ -1626,109 +1590,15 @@ namespace OpenSim.Region.Physics.OdePlugin
meshlod = _parent_scene.MeshSculptphysicalLOD;
IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
// createmesh returns null when it's a shape that isn't a cube.
if (mesh != null)
// createmesh returns null when it doesn't mesh.
CreateGeom(m_targetSpace, mesh);
}
else
{
setMesh(_parent_scene, mesh);
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion();
myrot.X = _orientation.X;
myrot.Y = _orientation.Y;
myrot.Z = _orientation.Z;
myrot.W = _orientation.W;
d.GeomSetQuaternion(prim_geom, ref myrot);
_mesh = null;
CreateGeom(m_targetSpace, null);
}
//d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
if (IsPhysical && Body == (IntPtr)0)
{
// Re creates body on size.
// EnableBody also does setMass()
enableBody();
}
}
else
{
if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1)
{
if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z)
{
if (((_size.X / 2f) > 0f) && ((_size.X / 2f) < 1000))
{
_parent_scene.waitForSpaceUnlock(m_targetSpace);
SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2));
}
else
{
m_log.Info("[PHYSICS]: Failed to load a sphere bad size");
_parent_scene.waitForSpaceUnlock(m_targetSpace);
SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
}
}
else
{
_parent_scene.waitForSpaceUnlock(m_targetSpace);
SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
}
}
//else if (_pbs.ProfileShape == ProfileShape.Circle && _pbs.PathCurve == (byte)Extrusion.Straight)
//{
//Cyllinder
//if (_size.X == _size.Y)
//{
// prim_geom = d.CreateCylinder(m_targetSpace, _size.X / 2, _size.Z);
//}
//else
//{
//prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
//}
//}
else
{
_parent_scene.waitForSpaceUnlock(m_targetSpace);
SetGeom(prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
}
//prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion();
myrot.X = _orientation.X;
myrot.Y = _orientation.Y;
myrot.Z = _orientation.Z;
myrot.W = _orientation.W;
d.GeomSetQuaternion(prim_geom, ref myrot);
}
}
else
{
if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1)
{
if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z)
{
_parent_scene.waitForSpaceUnlock(m_targetSpace);
SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2));
}
else
{
_parent_scene.waitForSpaceUnlock(m_targetSpace);
SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
}
}
//else if (_pbs.ProfileShape == ProfileShape.Circle && _pbs.PathCurve == (byte)Extrusion.Straight)
//{
//Cyllinder
//if (_size.X == _size.Y)
//{
//prim_geom = d.CreateCylinder(m_targetSpace, _size.X / 2, _size.Z);
//}
//else
//{
//prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
//}
//}
else
{
_parent_scene.waitForSpaceUnlock(m_targetSpace);
SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
}
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion();
//myrot.W = _orientation.w;
@ -1746,8 +1616,6 @@ namespace OpenSim.Region.Physics.OdePlugin
enableBody();
d.BodyEnable(Body);
}
}
_parent_scene.geom_name_map[prim_geom] = oldname;
changeSelectedStatus(timestamp);

View File

@ -1042,6 +1042,7 @@ namespace OpenSim.Region.Physics.OdePlugin
lock (_activeprims)
{
List<OdePrim> removeprims = null;
foreach (OdePrim chr in _activeprims)
{
if (d.BodyIsEnabled(chr.Body) && (!chr.m_disabled))
@ -1056,7 +1057,12 @@ namespace OpenSim.Region.Physics.OdePlugin
}
else
{
m_log.Debug("[PHYSICS]: unable to collide test active prim against space. The space was zero, the geom was zero or it was in the process of being removed");
if (removeprims == null)
{
removeprims = new List<OdePrim>();
}
removeprims.Add(chr);
m_log.Debug("[PHYSICS]: unable to collide test active prim against space. The space was zero, the geom was zero or it was in the process of being removed. Removed it from the active prim list. This needs to be fixed!");
}
}
}
@ -1066,6 +1072,13 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
}
if (removeprims != null)
{
foreach (OdePrim chr in removeprims)
{
_activeprims.Remove(chr);
}
}
}
}
@ -1466,6 +1479,7 @@ namespace OpenSim.Region.Physics.OdePlugin
staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero);
d.GeomSetCategoryBits(staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY], (int)CollisionCategories.Space);
waitForSpaceUnlock(space);
d.SpaceSetSublevel(space, 1);
d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]);
return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY];
}
@ -1522,72 +1536,112 @@ namespace OpenSim.Region.Physics.OdePlugin
// //if (pbs.PathCurve == (byte)Primitive.PathCurve.Circle && pbs.ProfileCurve == (byte)Primitive.ProfileCurve.Circle && pbs.PathScaleY <= 0.75f)
// //Console.WriteLine("needsMeshing: " + " pathCurve: " + pbs.PathCurve.ToString() + " profileCurve: " + pbs.ProfileCurve.ToString() + " pathScaleY: " + Primitive.UnpackPathScale(pbs.PathScaleY).ToString());
int iPropertiesNotSupportedDefault = 0;
if (pbs.SculptEntry && !meshSculptedPrim)
{
#if SPAM
m_log.Warn("NonMesh");
#endif
return false;
}
// if it's a standard box or sphere with no cuts or hollows or twist, return false since ODE can use an internal representation for the prim
//if ((pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight)
// || (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1
// && pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z))
//{
// if (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0
// && pbs.ProfileHollow == 0
// && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0
// && pbs.PathBegin == 0 && pbs.PathEnd == 0
// //&& pbs.PathTaperX == 0 && pbs.PathTaperY == 0
// && pbs.PathScaleX == 100 && pbs.PathScaleY == 100)
// return false;
//}
if ((pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight)
|| (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1
&& pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z))
{
// if (pbs.ProfileHollow != 0)
// return true;
if (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0
&& pbs.ProfileHollow == 0
&& pbs.PathTwist == 0 && pbs.PathTwistBegin == 0
&& pbs.PathBegin == 0 && pbs.PathEnd == 0
&& pbs.PathTaperX == 0 && pbs.PathTaperY == 0
&& pbs.PathScaleX == 100 && pbs.PathScaleY == 100)
{
#if SPAM
m_log.Warn("NonMesh");
#endif
return false;
}
}
// if (((Int16)pbs.PathTwistBegin != 0) || ((Int16)pbs.PathTwist != 0))
// return true;
if (pbs.ProfileHollow != 0)
iPropertiesNotSupportedDefault++;
// if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0)
// return true;
if (((Int16)pbs.PathTwistBegin != 0) || ((Int16)pbs.PathTwist != 0))
iPropertiesNotSupportedDefault++;
// if ((pbs.PathScaleX != 100) || (pbs.PathScaleY != 100))
// return true;
if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0)
iPropertiesNotSupportedDefault++;
// if ((pbs.PathShearX != 0) || (pbs.PathShearY != 0))
// return true;
if ((pbs.PathScaleX != 100) || (pbs.PathScaleY != 100))
iPropertiesNotSupportedDefault++;
// if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight)
// return true;
// //if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1 && (pbs.Scale.X != pbs.Scale.Y || pbs.Scale.Y != pbs.Scale.Z || pbs.Scale.Z != pbs.Scale.X))
// // return true;
if ((pbs.PathShearX != 0) || (pbs.PathShearY != 0))
iPropertiesNotSupportedDefault++;
// if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte) Extrusion.Curve1)
// return true;
if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight)
iPropertiesNotSupportedDefault++;
// // test for torus
// if (pbs.PathCurve == (byte)Primitive.PathCurve.Circle
// && (pbs.ProfileCurve & 0x07) == (byte)Primitive.ProfileCurve.Circle
// && Primitive.UnpackPathScale(pbs.PathScaleY) <= 0.75f)
// return true;
if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1 && (pbs.Scale.X != pbs.Scale.Y || pbs.Scale.Y != pbs.Scale.Z || pbs.Scale.Z != pbs.Scale.X))
iPropertiesNotSupportedDefault++;
// // test for tube
// if (pbs.PathCurve == (byte)Primitive.PathCurve.Circle
// && (pbs.ProfileCurve & 0x07) == (byte)Primitive.ProfileCurve.EqualTriangle)
// return true;
if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte) Extrusion.Curve1)
iPropertiesNotSupportedDefault++;
// // test for ring
// if (pbs.PathCurve == (byte)Primitive.PathCurve.Circle
// && (pbs.ProfileCurve & 0x07) == (byte)Primitive.ProfileCurve.EqualTriangle)
// return true;
// test for torus
if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Square)
{
if (pbs.PathCurve == (byte)Extrusion.Curve1)
{
iPropertiesNotSupportedDefault++;
}
}
else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Circle)
{
if (pbs.PathCurve == (byte)Extrusion.Straight)
{
iPropertiesNotSupportedDefault++;
}
// if (pbs.ProfileShape == ProfileShape.EquilateralTriangle)
// return true;
// ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits
else if (pbs.PathCurve == (byte)Extrusion.Curve1)
{
iPropertiesNotSupportedDefault++;
}
}
else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle)
{
if (pbs.PathCurve == (byte)Extrusion.Curve1 || pbs.PathCurve == (byte)Extrusion.Curve2)
{
iPropertiesNotSupportedDefault++;
}
}
else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle)
{
if (pbs.PathCurve == (byte)Extrusion.Straight)
{
iPropertiesNotSupportedDefault++;
}
else if (pbs.PathCurve == (byte)Extrusion.Curve1)
{
iPropertiesNotSupportedDefault++;
}
}
// return false;
return true; // assume the mesher will return a default shape or null and later code can deal with this
if (iPropertiesNotSupportedDefault == 0)
{
#if SPAM
m_log.Warn("NonMesh");
#endif
return false;
}
#if SPAM
m_log.Debug("Mesh");
#endif
return true;
}
/// <summary>