From 566327a9482506f2965e06b37172dc42f66cd6e5 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 20 Apr 2012 23:24:24 +0100
Subject: If a physical prim is manually moved (e.g. by a user) then set the
geometry position as well as the body position
This is necessary to stop the moved prim snapping back to the original position on deselection if moved only once
This resolves http://opensimulator.org/mantis/view.php?id=5966
---
OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 1f79cd8..7d67da3 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -1579,23 +1579,21 @@ Console.WriteLine(" JointCreateFixed");
//m_log.Debug("[BUG]: race!");
//}
}
- else
- {
- // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
- // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
-// _parent_scene.waitForSpaceUnlock(m_targetSpace);
- IntPtr tempspace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace);
- m_targetSpace = tempspace;
+ // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
+ // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
+// _parent_scene.waitForSpaceUnlock(m_targetSpace);
+
+ IntPtr tempspace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace);
+ m_targetSpace = tempspace;
// _parent_scene.waitForSpaceUnlock(m_targetSpace);
- if (prim_geom != IntPtr.Zero)
- {
- d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
+ if (prim_geom != IntPtr.Zero)
+ {
+ d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
// _parent_scene.waitForSpaceUnlock(m_targetSpace);
- d.SpaceAdd(m_targetSpace, prim_geom);
- }
+ d.SpaceAdd(m_targetSpace, prim_geom);
}
changeSelectedStatus();
--
cgit v1.1
From 7a574be3fd28ffbd9bce4cfa08451d705728fa20 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 21 Apr 2012 00:12:07 +0100
Subject: Remove redundant prim_geom != IntPtr.Zero checks in ODEPrim.
prim_geom == IntPtr.Zero only before a new add prim taint is processed (which is the first taint) or in operations such as scale change which are done in taint or under lock.
Therefore, we can remove these checks which were not consistently applied anyway.
If there is a genuine problem, better to see it quickly in a NullReferenceException than hide the bug.
---
OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 204 ++++++++++++----------------
1 file changed, 88 insertions(+), 116 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 7d67da3..0a8cf75 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -156,7 +156,15 @@ namespace OpenSim.Region.Physics.OdePlugin
///
public IntPtr m_targetSpace = IntPtr.Zero;
+ ///
+ /// The prim geometry, used for collision detection.
+ ///
+ ///
+ /// This is never null except for a brief period when the geometry needs to be replaced (due to resizing or
+ /// mesh change) or when the physical prim is being removed from the scene.
+ ///
public IntPtr prim_geom { get; private set; }
+
public IntPtr _triMeshData { get; private set; }
private IntPtr _linkJointGroup = IntPtr.Zero;
@@ -325,14 +333,11 @@ namespace OpenSim.Region.Physics.OdePlugin
{
prim_geom = geom;
//Console.WriteLine("SetGeom to " + prim_geom + " for " + Name);
- if (prim_geom != IntPtr.Zero)
- {
- d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
- d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
- _parent_scene.geom_name_map[prim_geom] = Name;
- _parent_scene.actor_name_map[prim_geom] = this;
- }
+ d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
+ d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
+
+ _parent_scene.geom_name_map[prim_geom] = Name;
if (childPrim)
{
@@ -765,11 +770,8 @@ namespace OpenSim.Region.Physics.OdePlugin
m_collisionCategories &= ~CollisionCategories.Body;
m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
- if (prim_geom != IntPtr.Zero)
- {
- d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
- d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
- }
+ d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
+ d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
d.BodyDestroy(Body);
lock (childrenPrim)
@@ -793,11 +795,8 @@ namespace OpenSim.Region.Physics.OdePlugin
m_collisionCategories &= ~CollisionCategories.Body;
m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
- if (prim_geom != IntPtr.Zero)
- {
- d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
- d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
- }
+ d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
+ d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
Body = IntPtr.Zero;
}
@@ -864,10 +863,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// _parent_scene.waitForSpaceUnlock(m_targetSpace);
try
{
- if (prim_geom == IntPtr.Zero)
- {
- SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null));
- }
+ SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null));
}
catch (AccessViolationException)
{
@@ -890,73 +886,67 @@ namespace OpenSim.Region.Physics.OdePlugin
#if SPAM
Console.WriteLine("ZProcessTaints for " + Name);
#endif
+
+ // This must be processed as the very first taint so that later operations have a prim_geom to work with
+ // if this is a new prim.
if (m_taintadd)
- {
changeadd();
- }
-
- if (prim_geom != IntPtr.Zero)
- {
- if (!_position.ApproxEquals(m_taintposition, 0f))
- changemove();
- if (m_taintrot != _orientation)
- {
- if (childPrim && IsPhysical) // For physical child prim...
- {
- rotate();
- // KF: ODE will also rotate the parent prim!
- // so rotate the root back to where it was
- OdePrim parent = (OdePrim)_parent;
- parent.rotate();
- }
- else
- {
- //Just rotate the prim
- rotate();
- }
+ if (!_position.ApproxEquals(m_taintposition, 0f))
+ changemove();
+
+ if (m_taintrot != _orientation)
+ {
+ if (childPrim && IsPhysical) // For physical child prim...
+ {
+ rotate();
+ // KF: ODE will also rotate the parent prim!
+ // so rotate the root back to where it was
+ OdePrim parent = (OdePrim)_parent;
+ parent.rotate();
}
-
- if (m_taintPhysics != IsPhysical && !(m_taintparent != _parent))
- changePhysicsStatus();
+ else
+ {
+ //Just rotate the prim
+ rotate();
+ }
+ }
+
+ if (m_taintPhysics != IsPhysical && !(m_taintparent != _parent))
+ changePhysicsStatus();
- if (!_size.ApproxEquals(m_taintsize, 0f))
- changesize();
+ if (!_size.ApproxEquals(m_taintsize, 0f))
+ changesize();
- if (m_taintshape)
- changeshape();
+ if (m_taintshape)
+ changeshape();
- if (m_taintforce)
- changeAddForce();
+ if (m_taintforce)
+ changeAddForce();
- if (m_taintaddangularforce)
- changeAddAngularForce();
+ if (m_taintaddangularforce)
+ changeAddAngularForce();
- if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f))
- changeSetTorque();
+ if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f))
+ changeSetTorque();
- if (m_taintdisable)
- changedisable();
+ if (m_taintdisable)
+ changedisable();
- if (m_taintselected != m_isSelected)
- changeSelectedStatus();
+ if (m_taintselected != m_isSelected)
+ changeSelectedStatus();
- if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f))
- changevelocity();
+ if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f))
+ changevelocity();
- if (m_taintparent != _parent)
- changelink();
+ if (m_taintparent != _parent)
+ changelink();
- if (m_taintCollidesWater != m_collidesWater)
- changefloatonwater();
+ if (m_taintCollidesWater != m_collidesWater)
+ changefloatonwater();
- if (!m_angularlock.ApproxEquals(m_taintAngularLock,0f))
- changeAngularLock();
- }
- else
- {
- m_log.ErrorFormat("[PHYSICS]: The scene reused a disposed PhysActor for {0}! *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.)", Name);
- }
+ if (!m_angularlock.ApproxEquals(m_taintAngularLock,0f))
+ changeAngularLock();
}
///
@@ -1093,18 +1083,10 @@ Console.WriteLine("ZProcessTaints for " + Name);
prm.m_collisionCategories |= CollisionCategories.Body;
prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
- if (prm.prim_geom == IntPtr.Zero)
- {
- m_log.WarnFormat(
- "[PHYSICS]: Unable to link one of the linkset elements {0} for parent {1}. No geom yet",
- prm.Name, prim.Name);
- continue;
- }
//Console.WriteLine(" GeomSetCategoryBits 1: " + prm.prim_geom + " - " + (int)prm.m_collisionCategories + " for " + Name);
d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories);
d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
-
d.Quaternion quat = new d.Quaternion();
quat.W = prm._orientation.W;
quat.X = prm._orientation.X;
@@ -1303,11 +1285,8 @@ Console.WriteLine("ZProcessTaints for " + Name);
disableBodySoft();
}
- if (prim_geom != IntPtr.Zero)
- {
- d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
- d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
- }
+ d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
+ d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
if (IsPhysical)
{
@@ -1328,11 +1307,8 @@ Console.WriteLine("ZProcessTaints for " + Name);
if (m_collidesWater)
m_collisionFlags |= CollisionCategories.Water;
- if (prim_geom != IntPtr.Zero)
- {
- d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
- d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
- }
+ d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
+ d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
if (IsPhysical)
{
@@ -1472,6 +1448,9 @@ Console.WriteLine("CreateGeom:");
}
else
{
+ m_log.WarnFormat(
+ "[ODE PRIM]: Called RemoveGeom() on {0} {1} where geometry was already null.", Name, LocalID);
+
return false;
}
}
@@ -1505,16 +1484,13 @@ Console.WriteLine("changeadd 1");
#endif
CreateGeom(m_targetSpace, mesh);
- if (prim_geom != IntPtr.Zero)
- {
- 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);
- }
+ 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);
if (IsPhysical && Body == IntPtr.Zero)
enableBody();
@@ -1588,13 +1564,11 @@ Console.WriteLine(" JointCreateFixed");
m_targetSpace = tempspace;
// _parent_scene.waitForSpaceUnlock(m_targetSpace);
- if (prim_geom != IntPtr.Zero)
- {
- d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
+
+ d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
// _parent_scene.waitForSpaceUnlock(m_targetSpace);
- d.SpaceAdd(m_targetSpace, prim_geom);
- }
+ d.SpaceAdd(m_targetSpace, prim_geom);
changeSelectedStatus();
@@ -2045,18 +2019,16 @@ Console.WriteLine(" JointCreateFixed");
{
m_collidesWater = m_taintCollidesWater;
- if (prim_geom != IntPtr.Zero)
+ if (m_collidesWater)
{
- if (m_collidesWater)
- {
- m_collisionFlags |= CollisionCategories.Water;
- }
- else
- {
- m_collisionFlags &= ~CollisionCategories.Water;
- }
- d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
+ m_collisionFlags |= CollisionCategories.Water;
+ }
+ else
+ {
+ m_collisionFlags &= ~CollisionCategories.Water;
}
+
+ d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
}
///
--
cgit v1.1
From f60959459574b1473dbe35d780aa0fbe4d688580 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 21 Apr 2012 03:23:51 +0100
Subject: refactor: Simplify ODEPrim.AddChildPrim() by returning early where
appropriate.
---
OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 232 ++++++++++++++--------------
1 file changed, 117 insertions(+), 115 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 0a8cf75..cbb49ac 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -1042,142 +1042,144 @@ Console.WriteLine("ZProcessTaints for " + Name);
/// Child prim
private void AddChildPrim(OdePrim prim)
{
-//Console.WriteLine("AddChildPrim " + Name);
- if (LocalID != prim.LocalID)
+ if (LocalID == prim.LocalID)
+ return;
+
+ if (Body == IntPtr.Zero)
{
- if (Body == IntPtr.Zero)
+ Body = d.BodyCreate(_parent_scene.world);
+ setMass();
+ }
+
+ lock (childrenPrim)
+ {
+ if (childrenPrim.Contains(prim))
+ return;
+
+//Console.WriteLine("childrenPrim.Add " + prim);
+ childrenPrim.Add(prim);
+
+ foreach (OdePrim prm in childrenPrim)
{
- Body = d.BodyCreate(_parent_scene.world);
- setMass();
+ d.Mass m2;
+ d.MassSetZero(out m2);
+ d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z);
+
+ d.Quaternion quat = new d.Quaternion();
+ quat.W = prm._orientation.W;
+ quat.X = prm._orientation.X;
+ quat.Y = prm._orientation.Y;
+ quat.Z = prm._orientation.Z;
+
+ d.Matrix3 mat = new d.Matrix3();
+ d.RfromQ(out mat, ref quat);
+ d.MassRotate(ref m2, ref mat);
+ d.MassTranslate(ref m2, Position.X - prm.Position.X, Position.Y - prm.Position.Y, Position.Z - prm.Position.Z);
+ d.MassAdd(ref pMass, ref m2);
}
- if (Body != IntPtr.Zero)
+
+ foreach (OdePrim prm in childrenPrim)
{
- lock (childrenPrim)
- {
- if (!childrenPrim.Contains(prim))
- {
-//Console.WriteLine("childrenPrim.Add " + prim);
- childrenPrim.Add(prim);
-
- foreach (OdePrim prm in childrenPrim)
- {
- d.Mass m2;
- d.MassSetZero(out m2);
- d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z);
-
- d.Quaternion quat = new d.Quaternion();
- quat.W = prm._orientation.W;
- quat.X = prm._orientation.X;
- quat.Y = prm._orientation.Y;
- quat.Z = prm._orientation.Z;
-
- d.Matrix3 mat = new d.Matrix3();
- d.RfromQ(out mat, ref quat);
- d.MassRotate(ref m2, ref mat);
- d.MassTranslate(ref m2, Position.X - prm.Position.X, Position.Y - prm.Position.Y, Position.Z - prm.Position.Z);
- d.MassAdd(ref pMass, ref m2);
- }
-
- foreach (OdePrim prm in childrenPrim)
- {
- prm.m_collisionCategories |= CollisionCategories.Body;
- prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
+ prm.m_collisionCategories |= CollisionCategories.Body;
+ prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
//Console.WriteLine(" GeomSetCategoryBits 1: " + prm.prim_geom + " - " + (int)prm.m_collisionCategories + " for " + Name);
- d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories);
- d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
-
- d.Quaternion quat = new d.Quaternion();
- quat.W = prm._orientation.W;
- quat.X = prm._orientation.X;
- quat.Y = prm._orientation.Y;
- quat.Z = prm._orientation.Z;
-
- d.Matrix3 mat = new d.Matrix3();
- d.RfromQ(out mat, ref quat);
- if (Body != IntPtr.Zero)
- {
- d.GeomSetBody(prm.prim_geom, Body);
- prm.childPrim = true;
- d.GeomSetOffsetWorldPosition(prm.prim_geom, prm.Position.X , prm.Position.Y, prm.Position.Z);
- //d.GeomSetOffsetPosition(prim.prim_geom,
- // (Position.X - prm.Position.X) - pMass.c.X,
- // (Position.Y - prm.Position.Y) - pMass.c.Y,
- // (Position.Z - prm.Position.Z) - pMass.c.Z);
- d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat);
- //d.GeomSetOffsetRotation(prm.prim_geom, ref mat);
- d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
- d.BodySetMass(Body, ref pMass);
- }
- else
- {
- m_log.DebugFormat("[PHYSICS]: {0} ain't got no boooooooooddy, no body", Name);
- }
+ d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories);
+ d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
- prm.m_interpenetrationcount = 0;
- prm.m_collisionscore = 0;
- prm.m_disabled = false;
+ d.Quaternion quat = new d.Quaternion();
+ quat.W = prm._orientation.W;
+ quat.X = prm._orientation.X;
+ quat.Y = prm._orientation.Y;
+ quat.Z = prm._orientation.Z;
- // The body doesn't already have a finite rotation mode set here
- if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
- {
- prm.createAMotor(m_angularlock);
- }
- prm.Body = Body;
- _parent_scene.ActivatePrim(prm);
- }
+ d.Matrix3 mat = new d.Matrix3();
+ d.RfromQ(out mat, ref quat);
+ if (Body != IntPtr.Zero)
+ {
+ d.GeomSetBody(prm.prim_geom, Body);
+ prm.childPrim = true;
+ d.GeomSetOffsetWorldPosition(prm.prim_geom, prm.Position.X , prm.Position.Y, prm.Position.Z);
+ //d.GeomSetOffsetPosition(prim.prim_geom,
+ // (Position.X - prm.Position.X) - pMass.c.X,
+ // (Position.Y - prm.Position.Y) - pMass.c.Y,
+ // (Position.Z - prm.Position.Z) - pMass.c.Z);
+ d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat);
+ //d.GeomSetOffsetRotation(prm.prim_geom, ref mat);
+ d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
+ d.BodySetMass(Body, ref pMass);
+ }
+ else
+ {
+ m_log.DebugFormat("[PHYSICS]: {0} ain't got no boooooooooddy, no body", Name);
+ }
+
+ prm.m_interpenetrationcount = 0;
+ prm.m_collisionscore = 0;
+ prm.m_disabled = false;
+
+ // The body doesn't already have a finite rotation mode set here
+ if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
+ {
+ prm.createAMotor(m_angularlock);
+ }
+ prm.Body = Body;
+ _parent_scene.ActivatePrim(prm);
+ }
- m_collisionCategories |= CollisionCategories.Body;
- m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
+ m_collisionCategories |= CollisionCategories.Body;
+ m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
//Console.WriteLine("GeomSetCategoryBits 2: " + prim_geom + " - " + (int)m_collisionCategories + " for " + Name);
- d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
+ d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
//Console.WriteLine(" Post GeomSetCategoryBits 2");
- d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
-
- d.Quaternion quat2 = new d.Quaternion();
- quat2.W = _orientation.W;
- quat2.X = _orientation.X;
- quat2.Y = _orientation.Y;
- quat2.Z = _orientation.Z;
-
- d.Matrix3 mat2 = new d.Matrix3();
- d.RfromQ(out mat2, ref quat2);
- d.GeomSetBody(prim_geom, Body);
- d.GeomSetOffsetWorldPosition(prim_geom, Position.X - pMass.c.X, Position.Y - pMass.c.Y, Position.Z - pMass.c.Z);
- //d.GeomSetOffsetPosition(prim.prim_geom,
- // (Position.X - prm.Position.X) - pMass.c.X,
- // (Position.Y - prm.Position.Y) - pMass.c.Y,
- // (Position.Z - prm.Position.Z) - pMass.c.Z);
- //d.GeomSetOffsetRotation(prim_geom, ref mat2);
- d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
- d.BodySetMass(Body, ref pMass);
-
- d.BodySetAutoDisableFlag(Body, true);
- d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
+ d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
- m_interpenetrationcount = 0;
- m_collisionscore = 0;
- m_disabled = false;
+ d.Quaternion quat2 = new d.Quaternion();
+ quat2.W = _orientation.W;
+ quat2.X = _orientation.X;
+ quat2.Y = _orientation.Y;
+ quat2.Z = _orientation.Z;
- // The body doesn't already have a finite rotation mode set here
- if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
- {
- createAMotor(m_angularlock);
- }
- d.BodySetPosition(Body, Position.X, Position.Y, Position.Z);
- if (m_vehicle.Type != Vehicle.TYPE_NONE)
- m_vehicle.Enable(Body, _parent_scene);
+ d.Matrix3 mat2 = new d.Matrix3();
+ d.RfromQ(out mat2, ref quat2);
+ d.GeomSetBody(prim_geom, Body);
+ d.GeomSetOffsetWorldPosition(prim_geom, Position.X - pMass.c.X, Position.Y - pMass.c.Y, Position.Z - pMass.c.Z);
+ //d.GeomSetOffsetPosition(prim.prim_geom,
+ // (Position.X - prm.Position.X) - pMass.c.X,
+ // (Position.Y - prm.Position.Y) - pMass.c.Y,
+ // (Position.Z - prm.Position.Z) - pMass.c.Z);
+ //d.GeomSetOffsetRotation(prim_geom, ref mat2);
+ d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
+ d.BodySetMass(Body, ref pMass);
- _parent_scene.ActivatePrim(this);
- }
- }
+ d.BodySetAutoDisableFlag(Body, true);
+ d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
+
+ m_interpenetrationcount = 0;
+ m_collisionscore = 0;
+ m_disabled = false;
+
+ // The body doesn't already have a finite rotation mode set here
+ if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
+ {
+ createAMotor(m_angularlock);
}
+
+ d.BodySetPosition(Body, Position.X, Position.Y, Position.Z);
+
+ if (m_vehicle.Type != Vehicle.TYPE_NONE)
+ m_vehicle.Enable(Body, _parent_scene);
+
+ _parent_scene.ActivatePrim(this);
}
}
private void ChildSetGeom(OdePrim odePrim)
{
+// m_log.DebugFormat(
+// "[ODE PRIM]: ChildSetGeom {0} {1} for {2} {3}", odePrim.Name, odePrim.LocalID, Name, LocalID);
+
//if (IsPhysical && Body != IntPtr.Zero)
lock (childrenPrim)
{
--
cgit v1.1
From ae2b8f70074e4dfe2cbbd03dd543c7468fc50cc1 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 21 Apr 2012 03:42:54 +0100
Subject: Comment out spurious Body != IntPtr.Zero code after disableBody(),
since disableBody() sets Body == IntPtr.Zero on all code paths.
---
OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 27 ++++++++++++++++++---------
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 3 ++-
2 files changed, 20 insertions(+), 10 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index cbb49ac..3f88353 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -1056,7 +1056,9 @@ Console.WriteLine("ZProcessTaints for " + Name);
if (childrenPrim.Contains(prim))
return;
-//Console.WriteLine("childrenPrim.Add " + prim);
+// m_log.DebugFormat(
+// "[ODE PRIM]: Linking prim {0} {1} to {2} {3}", prim.Name, prim.LocalID, Name, LocalID);
+
childrenPrim.Add(prim);
foreach (OdePrim prm in childrenPrim)
@@ -1194,12 +1196,14 @@ Console.WriteLine("ZProcessTaints for " + Name);
//prm.childPrim = false;
}
}
+
disableBody();
- if (Body != IntPtr.Zero)
- {
- _parent_scene.DeactivatePrim(this);
- }
+ // Spurious - Body == IntPtr.Zero after disableBody()
+// if (Body != IntPtr.Zero)
+// {
+// _parent_scene.DeactivatePrim(this);
+// }
lock (childrenPrim)
{
@@ -1213,6 +1217,9 @@ Console.WriteLine("ZProcessTaints for " + Name);
private void ChildDelink(OdePrim odePrim)
{
+// m_log.DebugFormat(
+// "[ODE PRIM]: Delinking prim {0} {1} from {2} {3}", odePrim.Name, odePrim.LocalID, Name, LocalID);
+
// Okay, we have a delinked child.. need to rebuild the body.
lock (childrenPrim)
{
@@ -1227,6 +1234,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
//prm.childPrim = false;
}
}
+
disableBody();
lock (childrenPrim)
@@ -1235,10 +1243,11 @@ Console.WriteLine("ZProcessTaints for " + Name);
childrenPrim.Remove(odePrim);
}
- if (Body != IntPtr.Zero)
- {
- _parent_scene.DeactivatePrim(this);
- }
+ // Spurious - Body == IntPtr.Zero after disableBody()
+// if (Body != IntPtr.Zero)
+// {
+// _parent_scene.DeactivatePrim(this);
+// }
lock (childrenPrim)
{
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 842ff91..409b27b 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -2226,7 +2226,8 @@ namespace OpenSim.Region.Physics.OdePlugin
///
internal void RemovePrimThreadLocked(OdePrim prim)
{
-//Console.WriteLine("RemovePrimThreadLocked " + prim.m_primName);
+// m_log.DebugFormat("[ODE SCENE]: Removing physical prim {0} {1}", prim.Name, prim.LocalID);
+
lock (prim)
{
RemoveCollisionEventReporting(prim);
--
cgit v1.1
From 8205fe79ceaeebd31509a044005bf27d226dbe07 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sun, 22 Apr 2012 19:51:51 +0100
Subject: Fix bug where setting phantom on a prim would result in a server log
message rather than setting phantom.
This was an oversight when removing some race conditions from PhysicsActor setting recently.
Regression tests extended to probe this code path.
Extending regression tests required implementation of a BasicPhysicsPrim (there was none before). However, BasicPhysics plugin is still of no current practical use other than to fill in as a component for other parts of regression testing.
---
.../Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs | 344 +++++++++++++++++++++
.../BasicPhysicsPlugin/BasicPhysicsScene.cs | 41 +--
2 files changed, 367 insertions(+), 18 deletions(-)
create mode 100644 OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs
new file mode 100644
index 0000000..ba7fe1e
--- /dev/null
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs
@@ -0,0 +1,344 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Collections.Generic;
+using Nini.Config;
+using OpenMetaverse;
+using OpenSim.Framework;
+using OpenSim.Region.Physics.Manager;
+
+namespace OpenSim.Region.Physics.BasicPhysicsPlugin
+{
+ public class BasicPhysicsPrim : PhysicsActor
+ {
+ private Vector3 _position;
+ private Vector3 _velocity;
+ private Vector3 _acceleration;
+ private Vector3 _size;
+ private PrimitiveBaseShape _shape;
+ private Vector3 m_rotationalVelocity;
+ private bool flying;
+ private bool iscolliding;
+
+ public BasicPhysicsPrim(
+ string name, uint localId, Vector3 position, Vector3 size, Quaternion orientation, PrimitiveBaseShape shape)
+ {
+ Name = name;
+ LocalID = localId;
+ Position = position;
+ Size = size;
+ Orientation = orientation;
+ Shape = shape;
+ }
+
+ public override int PhysicsActorType
+ {
+ get { return (int) ActorTypes.Agent; }
+ set { return; }
+ }
+
+ public override Vector3 RotationalVelocity
+ {
+ get { return m_rotationalVelocity; }
+ set { m_rotationalVelocity = value; }
+ }
+
+ public override bool SetAlwaysRun
+ {
+ get { return false; }
+ set { return; }
+ }
+
+ public override uint LocalID
+ {
+ set { return; }
+ }
+
+ public override bool Grabbed
+ {
+ set { return; }
+ }
+
+ public override bool Selected
+ {
+ set { return; }
+ }
+
+ public override float Buoyancy
+ {
+ get { return 0f; }
+ set { return; }
+ }
+
+ public override bool FloatOnWater
+ {
+ set { return; }
+ }
+
+ public override bool IsPhysical
+ {
+ get { return false; }
+ set { return; }
+ }
+
+ public override bool ThrottleUpdates
+ {
+ get { return false; }
+ set { return; }
+ }
+
+ public override bool Flying
+ {
+ get { return flying; }
+ set { flying = value; }
+ }
+
+ public override bool IsColliding
+ {
+ get { return iscolliding; }
+ set { iscolliding = value; }
+ }
+
+ public override bool CollidingGround
+ {
+ get { return false; }
+ set { return; }
+ }
+
+ public override bool CollidingObj
+ {
+ get { return false; }
+ set { return; }
+ }
+
+ public override bool Stopped
+ {
+ get { return false; }
+ }
+
+ public override Vector3 Position
+ {
+ get { return _position; }
+ set { _position = value; }
+ }
+
+ public override Vector3 Size
+ {
+ get { return _size; }
+ set {
+ _size = value;
+ _size.Z = _size.Z / 2.0f;
+ }
+ }
+
+ public override PrimitiveBaseShape Shape
+ {
+ set { _shape = value; }
+ }
+
+ public override float Mass
+ {
+ get { return 0f; }
+ }
+
+ public override Vector3 Force
+ {
+ get { return Vector3.Zero; }
+ set { return; }
+ }
+
+ public override int VehicleType
+ {
+ get { return 0; }
+ set { return; }
+ }
+
+ public override void VehicleFloatParam(int param, float value)
+ {
+
+ }
+
+ public override void VehicleVectorParam(int param, Vector3 value)
+ {
+
+ }
+
+ public override void VehicleRotationParam(int param, Quaternion rotation)
+ {
+
+ }
+
+ public override void VehicleFlags(int param, bool remove)
+ {
+
+ }
+
+ public override void SetVolumeDetect(int param)
+ {
+
+ }
+
+ public override Vector3 CenterOfMass
+ {
+ get { return Vector3.Zero; }
+ }
+
+ public override Vector3 GeometricCenter
+ {
+ get { return Vector3.Zero; }
+ }
+
+ public override Vector3 Velocity
+ {
+ get { return _velocity; }
+ set { _velocity = value; }
+ }
+
+ public override Vector3 Torque
+ {
+ get { return Vector3.Zero; }
+ set { return; }
+ }
+
+ public override float CollisionScore
+ {
+ get { return 0f; }
+ set { }
+ }
+
+ public override Quaternion Orientation { get; set; }
+
+ public override Vector3 Acceleration
+ {
+ get { return _acceleration; }
+ set { _acceleration = value; }
+ }
+
+ public override bool Kinematic
+ {
+ get { return true; }
+ set { }
+ }
+
+ public override void link(PhysicsActor obj)
+ {
+ }
+
+ public override void delink()
+ {
+ }
+
+ public override void LockAngularMotion(Vector3 axis)
+ {
+ }
+
+ public override void AddForce(Vector3 force, bool pushforce)
+ {
+ }
+
+ public override void AddAngularForce(Vector3 force, bool pushforce)
+ {
+ }
+
+ public override void SetMomentum(Vector3 momentum)
+ {
+ }
+
+ public override void CrossingFailure()
+ {
+ }
+
+ public override Vector3 PIDTarget
+ {
+ set { return; }
+ }
+
+ public override bool PIDActive
+ {
+ set { return; }
+ }
+
+ public override float PIDTau
+ {
+ set { return; }
+ }
+
+ public override float PIDHoverHeight
+ {
+ set { return; }
+ }
+
+ public override bool PIDHoverActive
+ {
+ set { return; }
+ }
+
+ public override PIDHoverType PIDHoverType
+ {
+ set { return; }
+ }
+
+ public override float PIDHoverTau
+ {
+ set { return; }
+ }
+
+ public override Quaternion APIDTarget
+ {
+ set { return; }
+ }
+
+ public override bool APIDActive
+ {
+ set { return; }
+ }
+
+ public override float APIDStrength
+ {
+ set { return; }
+ }
+
+ public override float APIDDamping
+ {
+ set { return; }
+ }
+
+ public override void SubscribeEvents(int ms)
+ {
+ }
+
+ public override void UnSubscribeEvents()
+ {
+ }
+
+ public override bool SubscribedEvents()
+ {
+ return false;
+ }
+ }
+}
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs
index 2e14216..f5826ed 100644
--- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs
@@ -34,9 +34,17 @@ using OpenSim.Region.Physics.Manager;
namespace OpenSim.Region.Physics.BasicPhysicsPlugin
{
+ ///
+ /// This is an incomplete extremely basic physics implementation
+ ///
+ ///
+ /// Not useful for anything at the moment apart from some regression testing in other components where some form
+ /// of physics plugin is needed.
+ ///
public class BasicScene : PhysicsScene
{
private List _actors = new List();
+ private List _prims = new List();
private float[] _heightMap;
//protected internal string sceneIdentifier;
@@ -50,10 +58,19 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
{
}
- public override void Dispose()
+ public override void Dispose() {}
+
+ public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
+ Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
{
+ BasicPhysicsPrim prim = new BasicPhysicsPrim(primName, localid, position, size, rotation, pbs);
+ prim.IsPhysical = isPhysical;
+
+ _prims.Add(prim);
+ return prim;
}
+
public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
{
BasicActor act = new BasicActor(size);
@@ -63,30 +80,18 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
return act;
}
- public override void RemovePrim(PhysicsActor prim)
+ public override void RemovePrim(PhysicsActor actor)
{
+ BasicPhysicsPrim prim = (BasicPhysicsPrim)actor;
+ if (_prims.Contains(prim))
+ _prims.Remove(prim);
}
public override void RemoveAvatar(PhysicsActor actor)
{
- BasicActor act = (BasicActor) actor;
+ BasicActor act = (BasicActor)actor;
if (_actors.Contains(act))
- {
_actors.Remove(act);
- }
- }
-
-/*
- public override PhysicsActor AddPrim(Vector3 position, Vector3 size, Quaternion rotation)
- {
- return null;
- }
-*/
-
- public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
- Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
- {
- return null;
}
public override void AddPhysicsActorTaint(PhysicsActor prim)
--
cgit v1.1
From 49ed68e98c34c752fac407aa9359201e244df19f Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sun, 22 Apr 2012 20:28:12 +0100
Subject: refactor: simply some properties code in BasicPhysicsPlugin
---
.../BasicPhysicsPlugin/BasicPhysicsActor.cs | 42 ++++------------------
.../Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs | 42 ++++------------------
2 files changed, 12 insertions(+), 72 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsActor.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsActor.cs
index b1a3ff9..e43136a 100644
--- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsActor.cs
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsActor.cs
@@ -36,13 +36,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
{
public class BasicActor : PhysicsActor
{
- private Vector3 _position;
- private Vector3 _velocity;
- private Vector3 _acceleration;
private Vector3 _size;
- private Vector3 m_rotationalVelocity;
- private bool flying;
- private bool iscolliding;
public BasicActor(Vector3 size)
{
@@ -55,11 +49,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
set { return; }
}
- public override Vector3 RotationalVelocity
- {
- get { return m_rotationalVelocity; }
- set { m_rotationalVelocity = value; }
- }
+ public override Vector3 RotationalVelocity { get; set; }
public override bool SetAlwaysRun
{
@@ -105,17 +95,9 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
set { return; }
}
- public override bool Flying
- {
- get { return flying; }
- set { flying = value; }
- }
+ public override bool Flying { get; set; }
- public override bool IsColliding
- {
- get { return iscolliding; }
- set { iscolliding = value; }
- }
+ public override bool IsColliding { get; set; }
public override bool CollidingGround
{
@@ -134,11 +116,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
get { return false; }
}
- public override Vector3 Position
- {
- get { return _position; }
- set { _position = value; }
- }
+ public override Vector3 Position { get; set; }
public override Vector3 Size
{
@@ -206,11 +184,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
get { return Vector3.Zero; }
}
- public override Vector3 Velocity
- {
- get { return _velocity; }
- set { _velocity = value; }
- }
+ public override Vector3 Velocity { get; set; }
public override Vector3 Torque
{
@@ -230,11 +204,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
set { }
}
- public override Vector3 Acceleration
- {
- get { return _acceleration; }
- set { _acceleration = value; }
- }
+ public override Vector3 Acceleration { get; set; }
public override bool Kinematic
{
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs
index ba7fe1e..b89eeed 100644
--- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs
@@ -36,14 +36,8 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
{
public class BasicPhysicsPrim : PhysicsActor
{
- private Vector3 _position;
- private Vector3 _velocity;
- private Vector3 _acceleration;
private Vector3 _size;
private PrimitiveBaseShape _shape;
- private Vector3 m_rotationalVelocity;
- private bool flying;
- private bool iscolliding;
public BasicPhysicsPrim(
string name, uint localId, Vector3 position, Vector3 size, Quaternion orientation, PrimitiveBaseShape shape)
@@ -62,11 +56,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
set { return; }
}
- public override Vector3 RotationalVelocity
- {
- get { return m_rotationalVelocity; }
- set { m_rotationalVelocity = value; }
- }
+ public override Vector3 RotationalVelocity { get; set; }
public override bool SetAlwaysRun
{
@@ -112,17 +102,9 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
set { return; }
}
- public override bool Flying
- {
- get { return flying; }
- set { flying = value; }
- }
+ public override bool Flying { get; set; }
- public override bool IsColliding
- {
- get { return iscolliding; }
- set { iscolliding = value; }
- }
+ public override bool IsColliding { get; set; }
public override bool CollidingGround
{
@@ -141,11 +123,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
get { return false; }
}
- public override Vector3 Position
- {
- get { return _position; }
- set { _position = value; }
- }
+ public override Vector3 Position { get; set; }
public override Vector3 Size
{
@@ -213,11 +191,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
get { return Vector3.Zero; }
}
- public override Vector3 Velocity
- {
- get { return _velocity; }
- set { _velocity = value; }
- }
+ public override Vector3 Velocity { get; set; }
public override Vector3 Torque
{
@@ -233,11 +207,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
public override Quaternion Orientation { get; set; }
- public override Vector3 Acceleration
- {
- get { return _acceleration; }
- set { _acceleration = value; }
- }
+ public override Vector3 Acceleration { get; set; }
public override bool Kinematic
{
--
cgit v1.1
From c6f30e044b6cd2ed8493ad0e2914786eef4f7890 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 24 Apr 2012 19:49:52 +0100
Subject: Restore _parent_scene.actor_name_map[prim_geom] = this; accidentally
removed from ODEPrim.SetGeom.
This occurred in 7a574be3fd from Sat 21 Apr 2012.
This should fix collision detection.
Mnay thanks to tglion for the spot and the fix in http://opensimulator.org/mantis/view.php?id=5988
---
OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 1 +
1 file changed, 1 insertion(+)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 3f88353..0716214 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -338,6 +338,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
_parent_scene.geom_name_map[prim_geom] = Name;
+ _parent_scene.actor_name_map[prim_geom] = this;
if (childPrim)
{
--
cgit v1.1
From b18c8c8e78172abebb82491700a0b5f9f40c1d66 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 17 May 2012 23:59:43 +0100
Subject: Don't eagerly clear frame collision events when physics actors
subscribe and unsubscribe from collisions, in order to avoid a race
condition.
Since this is done directly from ScenePresence, it can lead to a race condition with the simulator loop.
There's no real point doing it anyway since the clear will be done very shortly afterwards by the simulate loop and either there are no events (for a new avatar) or events don't matter (for a departing avatar).
This matches existing behaviour in OdePrim
---
OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 8397eb4..1b1c44a 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -1261,14 +1261,20 @@ namespace OpenSim.Region.Physics.OdePlugin
{
m_requestedUpdateFrequency = ms;
m_eventsubscription = ms;
- CollisionEventsThisFrame.Clear();
+
+ // Don't clear collision event reporting here. This is called directly from scene code and so can lead
+ // to a race condition with the simulate loop
+
_parent_scene.AddCollisionEventReporting(this);
}
public override void UnSubscribeEvents()
{
CollisionEventsThisFrame.Clear();
- _parent_scene.RemoveCollisionEventReporting(this);
+
+ // Don't clear collision event reporting here. This is called directly from scene code and so can lead
+ // to a race condition with the simulate loop
+
m_requestedUpdateFrequency = 0;
m_eventsubscription = 0;
}
--
cgit v1.1
From 6501b1b1bb297eb5ed8a44447f771c7b73b0e905 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 18 May 2012 00:38:29 +0100
Subject: refactor: move EventQueueGet path generation into common method.
Rename some local variables in line with code conventions. Add commented out
EQG log lines for future use.
---
OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 1b1c44a..54b69a2 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -1274,7 +1274,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// Don't clear collision event reporting here. This is called directly from scene code and so can lead
// to a race condition with the simulate loop
-
+
m_requestedUpdateFrequency = 0;
m_eventsubscription = 0;
}
--
cgit v1.1
From 0b02a4d42e989609a4e1ba39d2aee9a7f9655613 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 31 May 2012 01:52:26 +0100
Subject: Add an optional mechanism for physics modules to collect and return
arbitrary stats.
If active, the physics module can return arbitrary stat counters that can be seen via the MonitoringModule
(http://opensimulator.org/wiki/Monitoring_Module)
This is only active in OdeScene if collect_stats = true in [ODEPhysicsSettings].
This patch allows OdeScene to collect elapsed time information for calls to the ODE native collision methods to assess what proportion of time this takes compared to total physics processing.
This data is returned as ODENativeCollisionFrameMS in the monitoring module, updated every 3 seconds.
The performance effect of collecting stats is probably extremely minor, dwarfed by the rest of the physics code.
---
OpenSim/Region/Physics/Manager/PhysicsScene.cs | 14 +++
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 139 +++++++++++++++++++++++--
2 files changed, 143 insertions(+), 10 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
index 2a6163c..b32cd30 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
@@ -192,8 +192,22 @@ namespace OpenSim.Region.Physics.Manager
public abstract void AddPhysicsActorTaint(PhysicsActor prim);
+ ///
+ /// Perform a simulation of the current physics scene over the given timestep.
+ ///
+ ///
+ /// The number of frames simulated over that period.
public abstract float Simulate(float timeStep);
+ ///
+ /// Get statistics about this scene.
+ ///
+ /// This facility is currently experimental and subject to change.
+ ///
+ /// A dictionary where the key is the statistic name. If no statistics are supplied then returns null.
+ ///
+ public virtual Dictionary GetStats() { return null; }
+
public abstract void GetResults();
public abstract void SetTerrain(float[] heightMap);
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 409b27b..fa65945 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -131,6 +131,41 @@ namespace OpenSim.Region.Physics.OdePlugin
///
internal static Object UniversalColliderSyncObject = new Object();
+ ///
+ /// Is stats collecting enabled for this ODE scene?
+ ///
+ public bool CollectStats { get; set; }
+
+ ///
+ /// Statistics for this scene.
+ ///
+ private Dictionary m_stats = new Dictionary();
+
+ ///
+ /// Stat name for recording the number of milliseconds that ODE spends in native collision code.
+ ///
+ public const string ODENativeCollisionFrameMsStatName = "ODENativeCollisionFrameMS";
+
+ ///
+ /// Used to hold tick numbers for stat collection purposes.
+ ///
+ private int m_nativeCollisionTickRecorder;
+
+ ///
+ /// A messy way to tell if we need to avoid adding a collision time because this was already done in the callback.
+ ///
+ private bool m_inCollisionTiming;
+
+ ///
+ /// Used in calculating physics frame time dilation
+ ///
+ private int tickCountFrameRun;
+
+ ///
+ /// Used in calculating physics frame time dilation
+ ///
+ private int latertickcount;
+
private Random fluidRandomizer = new Random(Environment.TickCount);
private const uint m_regionWidth = Constants.RegionSize;
@@ -345,9 +380,6 @@ namespace OpenSim.Region.Physics.OdePlugin
private OdePrim cp1;
private OdeCharacter cc2;
private OdePrim cp2;
- private int tickCountFrameRun;
-
- private int latertickcount=0;
//private int cStartStop = 0;
//private string cDictKey = "";
@@ -440,6 +472,8 @@ namespace OpenSim.Region.Physics.OdePlugin
// Initialize the mesh plugin
public override void Initialise(IMesher meshmerizer, IConfigSource config)
{
+ m_stats[ODENativeCollisionFrameMsStatName] = 0;
+
mesher = meshmerizer;
m_config = config;
// Defaults
@@ -464,6 +498,8 @@ namespace OpenSim.Region.Physics.OdePlugin
IConfig physicsconfig = m_config.Configs["ODEPhysicsSettings"];
if (physicsconfig != null)
{
+ CollectStats = physicsconfig.GetBoolean("collect_stats", false);
+
gravityx = physicsconfig.GetFloat("world_gravityx", 0f);
gravityy = physicsconfig.GetFloat("world_gravityy", 0f);
gravityz = physicsconfig.GetFloat("world_gravityz", -9.8f);
@@ -765,6 +801,62 @@ namespace OpenSim.Region.Physics.OdePlugin
#region Collision Detection
///
+ /// Collides two geometries.
+ ///
+ ///
+ ///
+ /// /param>
+ ///
+ ///
+ ///
+ private int CollideGeoms(
+ IntPtr geom1, IntPtr geom2, int maxContacts, Ode.NET.d.ContactGeom[] contactsArray, int contactGeomSize)
+ {
+ int count;
+
+ lock (OdeScene.UniversalColliderSyncObject)
+ {
+ // We do this inside the lock so that we don't count any delay in acquiring it
+ if (CollectStats)
+ m_nativeCollisionTickRecorder = Util.EnvironmentTickCount();
+
+ count = d.Collide(geom1, geom2, maxContacts, contactsArray, contactGeomSize);
+ }
+
+ // We do this outside the lock so that any waiting threads aren't held up, though the effect is probably
+ // negligable
+ if (CollectStats)
+ m_stats[ODENativeCollisionFrameMsStatName]
+ += Util.EnvironmentTickCountSubtract(m_nativeCollisionTickRecorder);
+
+ return count;
+ }
+
+ ///
+ /// Collide two spaces or a space and a geometry.
+ ///
+ ///
+ /// /param>
+ ///
+ private void CollideSpaces(IntPtr space1, IntPtr space2, IntPtr data)
+ {
+ if (CollectStats)
+ {
+ m_inCollisionTiming = true;
+ m_nativeCollisionTickRecorder = Util.EnvironmentTickCount();
+ }
+
+ d.SpaceCollide2(space1, space2, data, nearCallback);
+
+ if (CollectStats && m_inCollisionTiming)
+ {
+ m_stats[ODENativeCollisionFrameMsStatName]
+ += Util.EnvironmentTickCountSubtract(m_nativeCollisionTickRecorder);
+ m_inCollisionTiming = false;
+ }
+ }
+
+ ///
/// This is our near callback. A geometry is near a body
///
/// The space that contains the geoms. Remember, spaces are also geoms
@@ -772,6 +864,13 @@ namespace OpenSim.Region.Physics.OdePlugin
/// another geometry or space
private void near(IntPtr space, IntPtr g1, IntPtr g2)
{
+ if (CollectStats && m_inCollisionTiming)
+ {
+ m_stats[ODENativeCollisionFrameMsStatName]
+ += Util.EnvironmentTickCountSubtract(m_nativeCollisionTickRecorder);
+ m_inCollisionTiming = false;
+ }
+
// m_log.DebugFormat("[PHYSICS]: Colliding {0} and {1} in {2}", g1, g2, space);
// no lock here! It's invoked from within Simulate(), which is thread-locked
@@ -789,7 +888,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// contact points in the space
try
{
- d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback);
+ CollideSpaces(g1, g2, IntPtr.Zero);
}
catch (AccessViolationException)
{
@@ -832,6 +931,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// Figure out how many contact points we have
int count = 0;
+
try
{
// Colliding Geom To Geom
@@ -843,8 +943,7 @@ namespace OpenSim.Region.Physics.OdePlugin
if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact))
return;
- lock (OdeScene.UniversalColliderSyncObject)
- count = d.Collide(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf);
+ count = CollideGeoms(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf);
if (count > contacts.Length)
m_log.Error("[ODE SCENE]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length);
@@ -1578,7 +1677,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// and we'll run it again on all of them.
try
{
- d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback);
+ CollideSpaces(space, chr.Shell, IntPtr.Zero);
}
catch (AccessViolationException)
{
@@ -1593,6 +1692,9 @@ namespace OpenSim.Region.Physics.OdePlugin
//}
}
+// if (framecount % 55 == 0)
+// m_log.DebugFormat("Processed {0} collisions", _perloopContact.Count);
+
List removeprims = null;
foreach (OdePrim chr in _activeprims)
{
@@ -1604,7 +1706,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
if (space != IntPtr.Zero && chr.prim_geom != IntPtr.Zero && chr.m_taintremove == false)
{
- d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback);
+ CollideSpaces(space, chr.prim_geom, IntPtr.Zero);
}
else
{
@@ -2689,7 +2791,7 @@ namespace OpenSim.Region.Physics.OdePlugin
/// It calls the methods that report back to the object owners.. (scenepresence, SceneObjectGroup)
///
///
- ///
+ /// The number of frames simulated over that period.
public override float Simulate(float timeStep)
{
if (framecount >= int.MaxValue)
@@ -3190,7 +3292,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public override bool IsThreaded
{
// for now we won't be multithreaded
- get { return (false); }
+ get { return false; }
}
#region ODE Specific Terrain Fixes
@@ -3955,5 +4057,22 @@ namespace OpenSim.Region.Physics.OdePlugin
ds.SetViewpoint(ref xyz, ref hpr);
}
#endif
+
+ public override Dictionary GetStats()
+ {
+ if (!CollectStats)
+ return null;
+
+ Dictionary returnStats;
+
+ lock (OdeLock)
+ {
+ returnStats = new Dictionary(m_stats);
+
+ m_stats[ODENativeCollisionFrameMsStatName] = 0;
+ }
+
+ return returnStats;
+ }
}
}
\ No newline at end of file
--
cgit v1.1
From 878b67b333320070f643dfdd11e0a9c6ff453543 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 00:26:11 +0100
Subject: Fix OdeScene.GetTopColliders() to return the top 25 colliders rather
than the first 25 that had non-zero collision scores.
Also zeros collisions scores on all prims after report collection, not just the top 25.
As before, this collision scores are only reset after a report is requested, which may give unrealistic numbers on the first request.
So to see more realistic scores, ignore the first report and then refresh the request after a couple of seconds or so.
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 32 +++++++++++-----------------
1 file changed, 13 insertions(+), 19 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index fa65945..25b3266 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -30,20 +30,21 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
-using System.IO;
-using System.Diagnostics;
using log4net;
using Nini.Config;
using Ode.NET;
+using OpenMetaverse;
#if USE_DRAWSTUFF
using Drawstuff.NET;
#endif
using OpenSim.Framework;
using OpenSim.Region.Physics.Manager;
-using OpenMetaverse;
namespace OpenSim.Region.Physics.OdePlugin
{
@@ -3868,26 +3869,19 @@ namespace OpenSim.Region.Physics.OdePlugin
public override Dictionary GetTopColliders()
{
- Dictionary returncolliders = new Dictionary();
- int cnt = 0;
+ Dictionary topColliders;
+
lock (_prims)
{
- foreach (OdePrim prm in _prims)
- {
- if (prm.CollisionScore > 0)
- {
- returncolliders.Add(prm.LocalID, prm.CollisionScore);
- cnt++;
- prm.CollisionScore = 0f;
- if (cnt > 25)
- {
- break;
- }
- }
- }
+ List orderedPrims = new List(_prims);
+ orderedPrims.OrderByDescending(p => p.CollisionScore).Take(25);
+ topColliders = orderedPrims.ToDictionary(p => p.LocalID, p => p.CollisionScore);
+
+ foreach (OdePrim p in _prims)
+ p.CollisionScore = 0;
}
- return returncolliders;
+ return topColliders;
}
public override bool SupportsRayCast()
--
cgit v1.1
From 93fa9e89918f41db01229c61a228724d380552ac Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 00:56:13 +0100
Subject: Add ODE avatar and prim collision numbers if extra stats collection
is enabled.
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 39 ++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 5 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 25b3266..864cdc2 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -148,6 +148,16 @@ namespace OpenSim.Region.Physics.OdePlugin
public const string ODENativeCollisionFrameMsStatName = "ODENativeCollisionFrameMS";
///
+ /// Stat name for the number of avatar collisions with another entity.
+ ///
+ public const string ODEAvatarCollisionsStatName = "ODEAvatarCollisions";
+
+ ///
+ /// Stat name for the number of prim collisions with another entity.
+ ///
+ public const string ODEPrimCollisionsStatName = "ODEPrimCollisions";
+
+ ///
/// Used to hold tick numbers for stat collection purposes.
///
private int m_nativeCollisionTickRecorder;
@@ -158,6 +168,12 @@ namespace OpenSim.Region.Physics.OdePlugin
private bool m_inCollisionTiming;
///
+ /// A temporary holder for the number of avatar collisions in a frame, so we can work out how many object
+ /// collisions occured using the _perloopcontact if stats collection is enabled.
+ ///
+ private int m_tempAvatarCollisionsThisFrame;
+
+ ///
/// Used in calculating physics frame time dilation
///
private int tickCountFrameRun;
@@ -473,7 +489,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// Initialize the mesh plugin
public override void Initialise(IMesher meshmerizer, IConfigSource config)
{
- m_stats[ODENativeCollisionFrameMsStatName] = 0;
+ InitializeExtraStats();
mesher = meshmerizer;
m_config = config;
@@ -1455,7 +1471,7 @@ namespace OpenSim.Region.Physics.OdePlugin
break;
}
}
- //m_log.DebugFormat("[Collsion]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth));
+ //m_log.DebugFormat("[Collision]: Depth {0}", Math.Abs(contact.depth - contactGeom.depth));
//m_log.DebugFormat("[Collision]: <{0},{1},{2}>", Math.Abs(contactGeom.normal.X - contact.normal.X), Math.Abs(contactGeom.normal.Y - contact.normal.Y), Math.Abs(contactGeom.normal.Z - contact.normal.Z));
}
}
@@ -1693,8 +1709,11 @@ namespace OpenSim.Region.Physics.OdePlugin
//}
}
-// if (framecount % 55 == 0)
-// m_log.DebugFormat("Processed {0} collisions", _perloopContact.Count);
+ if (CollectStats)
+ {
+ m_tempAvatarCollisionsThisFrame = _perloopContact.Count;
+ m_stats[ODEAvatarCollisionsStatName] += m_tempAvatarCollisionsThisFrame;
+ }
List removeprims = null;
foreach (OdePrim chr in _activeprims)
@@ -1728,6 +1747,9 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
+ if (CollectStats)
+ m_stats[ODEPrimCollisionsStatName] += _perloopContact.Count - m_tempAvatarCollisionsThisFrame;
+
if (removeprims != null)
{
foreach (OdePrim chr in removeprims)
@@ -4063,10 +4085,17 @@ namespace OpenSim.Region.Physics.OdePlugin
{
returnStats = new Dictionary(m_stats);
- m_stats[ODENativeCollisionFrameMsStatName] = 0;
+ InitializeExtraStats();
}
return returnStats;
}
+
+ private void InitializeExtraStats()
+ {
+ m_stats[ODENativeCollisionFrameMsStatName] = 0;
+ m_stats[ODEAvatarCollisionsStatName] = 0;
+ m_stats[ODEPrimCollisionsStatName] = 0;
+ }
}
}
\ No newline at end of file
--
cgit v1.1
From 8301f7b17f8e524d2412f927530da95f711bd6ac Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 00:57:55 +0100
Subject: minor: comment out currently unused OdeScene.sCollisionData
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 864cdc2..ace0ba5 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -55,15 +55,15 @@ namespace OpenSim.Region.Physics.OdePlugin
End = 2
}
- public struct sCollisionData
- {
- public uint ColliderLocalId;
- public uint CollidedWithLocalId;
- public int NumberOfCollisions;
- public int CollisionType;
- public int StatusIndicator;
- public int lastframe;
- }
+// public struct sCollisionData
+// {
+// public uint ColliderLocalId;
+// public uint CollidedWithLocalId;
+// public int NumberOfCollisions;
+// public int CollisionType;
+// public int StatusIndicator;
+// public int lastframe;
+// }
[Flags]
public enum CollisionCategories : int
--
cgit v1.1
From e1f8d2adb0dc1dffad8caf47611217b1f7f14f47 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 01:12:30 +0100
Subject: Stop adding an unnecessary duplicate _perloopcontact if the avatar is
standing on a prim.
This has already been added earlier on in the method.
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index ace0ba5..55c7e5a 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -1229,14 +1229,12 @@ namespace OpenSim.Region.Physics.OdePlugin
{
_perloopContact.Add(curContact);
- // If we're colliding against terrain
if (name1 == "Terrain" || name2 == "Terrain")
{
- // If we're moving
if ((p2.PhysicsActorType == (int) ActorTypes.Agent) &&
(Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f))
{
- // Use the movement terrain contact
+ // Avatar is moving on terrain, use the movement terrain contact
AvatarMovementTerrainContact.geom = curContact;
if (m_global_contactcount < maxContactsbeforedeath)
@@ -1249,7 +1247,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
if (p2.PhysicsActorType == (int)ActorTypes.Agent)
{
- // Use the non moving terrain contact
+ // Avatar is standing on terrain, use the non moving terrain contact
TerrainContact.geom = curContact;
if (m_global_contactcount < maxContactsbeforedeath)
@@ -1344,13 +1342,11 @@ namespace OpenSim.Region.Physics.OdePlugin
}
else
{
- // we're colliding with prim or avatar
- // check if we're moving
if ((p2.PhysicsActorType == (int)ActorTypes.Agent))
{
if ((Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f))
{
- // Use the Movement prim contact
+ // Avatar is moving on a prim, use the Movement prim contact
AvatarMovementprimContact.geom = curContact;
if (m_global_contactcount < maxContactsbeforedeath)
@@ -1361,9 +1357,8 @@ namespace OpenSim.Region.Physics.OdePlugin
}
else
{
- // Use the non movement contact
+ // Avatar is standing still on a prim, use the non movement contact
contact.geom = curContact;
- _perloopContact.Add(curContact);
if (m_global_contactcount < maxContactsbeforedeath)
{
--
cgit v1.1
From c33c8db8256225b5ec09c0767c8b65341964d678 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 01:15:27 +0100
Subject: Rename new collision stats to 'contacts' - there are/can be multiple
contacts per collision and this is what is actually being measured.
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 55c7e5a..32dac22 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -150,12 +150,12 @@ namespace OpenSim.Region.Physics.OdePlugin
///
/// Stat name for the number of avatar collisions with another entity.
///
- public const string ODEAvatarCollisionsStatName = "ODEAvatarCollisions";
+ public const string ODEAvatarContactsStatsName = "ODEAvatarContacts";
///
/// Stat name for the number of prim collisions with another entity.
///
- public const string ODEPrimCollisionsStatName = "ODEPrimCollisions";
+ public const string ODEPrimContactsStatName = "ODEPrimContacts";
///
/// Used to hold tick numbers for stat collection purposes.
@@ -1707,7 +1707,7 @@ namespace OpenSim.Region.Physics.OdePlugin
if (CollectStats)
{
m_tempAvatarCollisionsThisFrame = _perloopContact.Count;
- m_stats[ODEAvatarCollisionsStatName] += m_tempAvatarCollisionsThisFrame;
+ m_stats[ODEAvatarContactsStatsName] += m_tempAvatarCollisionsThisFrame;
}
List removeprims = null;
@@ -1743,7 +1743,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
if (CollectStats)
- m_stats[ODEPrimCollisionsStatName] += _perloopContact.Count - m_tempAvatarCollisionsThisFrame;
+ m_stats[ODEPrimContactsStatName] += _perloopContact.Count - m_tempAvatarCollisionsThisFrame;
if (removeprims != null)
{
@@ -4089,8 +4089,8 @@ namespace OpenSim.Region.Physics.OdePlugin
private void InitializeExtraStats()
{
m_stats[ODENativeCollisionFrameMsStatName] = 0;
- m_stats[ODEAvatarCollisionsStatName] = 0;
- m_stats[ODEPrimCollisionsStatName] = 0;
+ m_stats[ODEAvatarContactsStatsName] = 0;
+ m_stats[ODEPrimContactsStatName] = 0;
}
}
}
\ No newline at end of file
--
cgit v1.1
From 8333b928fa3353304358ed55293b52478a39ab6e Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 01:27:19 +0100
Subject: Break down native ODE collision frame time stat into native space
collision and geom collision stats
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 32dac22..d4c0b85 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -148,6 +148,16 @@ namespace OpenSim.Region.Physics.OdePlugin
public const string ODENativeCollisionFrameMsStatName = "ODENativeCollisionFrameMS";
///
+ /// Stat name for recording the number of milliseconds that ODE spends in native space collision code.
+ ///
+ public const string ODENativeSpaceCollisionFrameMsStatName = "ODENativeSpaceCollisionFrameMS";
+
+ ///
+ /// Stat name for recording the number of milliseconds that ODE spends in native geom collision code.
+ ///
+ public const string ODENativeGeomCollisionFrameMsStatName = "ODENativeGeomCollisionFrameMS";
+
+ ///
/// Stat name for the number of avatar collisions with another entity.
///
public const string ODEAvatarContactsStatsName = "ODEAvatarContacts";
@@ -843,7 +853,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// We do this outside the lock so that any waiting threads aren't held up, though the effect is probably
// negligable
if (CollectStats)
- m_stats[ODENativeCollisionFrameMsStatName]
+ m_stats[ODENativeGeomCollisionFrameMsStatName]
+= Util.EnvironmentTickCountSubtract(m_nativeCollisionTickRecorder);
return count;
@@ -867,7 +877,7 @@ namespace OpenSim.Region.Physics.OdePlugin
if (CollectStats && m_inCollisionTiming)
{
- m_stats[ODENativeCollisionFrameMsStatName]
+ m_stats[ODENativeSpaceCollisionFrameMsStatName]
+= Util.EnvironmentTickCountSubtract(m_nativeCollisionTickRecorder);
m_inCollisionTiming = false;
}
@@ -883,7 +893,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
if (CollectStats && m_inCollisionTiming)
{
- m_stats[ODENativeCollisionFrameMsStatName]
+ m_stats[ODENativeSpaceCollisionFrameMsStatName]
+= Util.EnvironmentTickCountSubtract(m_nativeCollisionTickRecorder);
m_inCollisionTiming = false;
}
@@ -4079,6 +4089,10 @@ namespace OpenSim.Region.Physics.OdePlugin
lock (OdeLock)
{
returnStats = new Dictionary(m_stats);
+
+ returnStats[ODENativeCollisionFrameMsStatName]
+ = returnStats[ODENativeSpaceCollisionFrameMsStatName]
+ + returnStats[ODENativeGeomCollisionFrameMsStatName];
InitializeExtraStats();
}
@@ -4088,7 +4102,11 @@ namespace OpenSim.Region.Physics.OdePlugin
private void InitializeExtraStats()
{
- m_stats[ODENativeCollisionFrameMsStatName] = 0;
+ // No need to zero since this is calculated by addition
+ // m_stats[ODENativeCollisionFrameMsStatName] = 0;
+
+ m_stats[ODENativeSpaceCollisionFrameMsStatName] = 0;
+ m_stats[ODENativeGeomCollisionFrameMsStatName] = 0;
m_stats[ODEAvatarContactsStatsName] = 0;
m_stats[ODEPrimContactsStatName] = 0;
}
--
cgit v1.1
From f2c8c7a7b8cd6a3d3cbbaafa2ba266658b7d0998 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 01:37:19 +0100
Subject: Add total ODE frame time optional stat, as a sanity check on the main
scene physics stat
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index d4c0b85..ab03696 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -143,6 +143,14 @@ namespace OpenSim.Region.Physics.OdePlugin
private Dictionary m_stats = new Dictionary();
///
+ /// Stat name for the total time spent in ODE frame processing.
+ ///
+ ///
+ /// A sanity check for the main scene loop physics time.
+ ///
+ public const string ODETotalFrameMsStatName = "ODETotalFrameMS";
+
+ ///
/// Stat name for recording the number of milliseconds that ODE spends in native collision code.
///
public const string ODENativeCollisionFrameMsStatName = "ODENativeCollisionFrameMS";
@@ -170,7 +178,7 @@ namespace OpenSim.Region.Physics.OdePlugin
///
/// Used to hold tick numbers for stat collection purposes.
///
- private int m_nativeCollisionTickRecorder;
+ private int m_nativeCollisionStartTick;
///
/// A messy way to tell if we need to avoid adding a collision time because this was already done in the callback.
@@ -845,7 +853,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
// We do this inside the lock so that we don't count any delay in acquiring it
if (CollectStats)
- m_nativeCollisionTickRecorder = Util.EnvironmentTickCount();
+ m_nativeCollisionStartTick = Util.EnvironmentTickCount();
count = d.Collide(geom1, geom2, maxContacts, contactsArray, contactGeomSize);
}
@@ -854,7 +862,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// negligable
if (CollectStats)
m_stats[ODENativeGeomCollisionFrameMsStatName]
- += Util.EnvironmentTickCountSubtract(m_nativeCollisionTickRecorder);
+ += Util.EnvironmentTickCountSubtract(m_nativeCollisionStartTick);
return count;
}
@@ -870,7 +878,7 @@ namespace OpenSim.Region.Physics.OdePlugin
if (CollectStats)
{
m_inCollisionTiming = true;
- m_nativeCollisionTickRecorder = Util.EnvironmentTickCount();
+ m_nativeCollisionStartTick = Util.EnvironmentTickCount();
}
d.SpaceCollide2(space1, space2, data, nearCallback);
@@ -878,7 +886,7 @@ namespace OpenSim.Region.Physics.OdePlugin
if (CollectStats && m_inCollisionTiming)
{
m_stats[ODENativeSpaceCollisionFrameMsStatName]
- += Util.EnvironmentTickCountSubtract(m_nativeCollisionTickRecorder);
+ += Util.EnvironmentTickCountSubtract(m_nativeCollisionStartTick);
m_inCollisionTiming = false;
}
}
@@ -894,7 +902,7 @@ namespace OpenSim.Region.Physics.OdePlugin
if (CollectStats && m_inCollisionTiming)
{
m_stats[ODENativeSpaceCollisionFrameMsStatName]
- += Util.EnvironmentTickCountSubtract(m_nativeCollisionTickRecorder);
+ += Util.EnvironmentTickCountSubtract(m_nativeCollisionStartTick);
m_inCollisionTiming = false;
}
@@ -2822,6 +2830,8 @@ namespace OpenSim.Region.Physics.OdePlugin
/// The number of frames simulated over that period.
public override float Simulate(float timeStep)
{
+ int startFrameTick = Util.EnvironmentTickCount();
+
if (framecount >= int.MaxValue)
framecount = 0;
@@ -3087,6 +3097,9 @@ namespace OpenSim.Region.Physics.OdePlugin
tickCountFrameRun = Util.EnvironmentTickCount();
}
+ if (CollectStats)
+ m_stats[ODETotalFrameMsStatName] += Util.EnvironmentTickCount() - startFrameTick;
+
return fps;
}
@@ -4089,7 +4102,7 @@ namespace OpenSim.Region.Physics.OdePlugin
lock (OdeLock)
{
returnStats = new Dictionary(m_stats);
-
+
returnStats[ODENativeCollisionFrameMsStatName]
= returnStats[ODENativeSpaceCollisionFrameMsStatName]
+ returnStats[ODENativeGeomCollisionFrameMsStatName];
@@ -4105,6 +4118,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// No need to zero since this is calculated by addition
// m_stats[ODENativeCollisionFrameMsStatName] = 0;
+ m_stats[ODETotalFrameMsStatName] = 0;
m_stats[ODENativeSpaceCollisionFrameMsStatName] = 0;
m_stats[ODENativeGeomCollisionFrameMsStatName] = 0;
m_stats[ODEAvatarContactsStatsName] = 0;
--
cgit v1.1
From 5cc9b820e5b0a9490e6499ee5151c5e698c3e110 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 01:58:28 +0100
Subject: Add option native step frame ms stat
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 30 +++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index ab03696..04c4722 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -151,6 +151,11 @@ namespace OpenSim.Region.Physics.OdePlugin
public const string ODETotalFrameMsStatName = "ODETotalFrameMS";
///
+ /// The amount of time spent in native code that actually steps through the simulation.
+ ///
+ public const string ODENativeStepFrameMsStatName = "ODENativeStepFrameMS";
+
+ ///
/// Stat name for recording the number of milliseconds that ODE spends in native collision code.
///
public const string ODENativeCollisionFrameMsStatName = "ODENativeCollisionFrameMS";
@@ -2821,23 +2826,23 @@ namespace OpenSim.Region.Physics.OdePlugin
///
/// This is our main simulate loop
+ ///
+ ///
/// It's thread locked by a Mutex in the scene.
/// It holds Collisions, it instructs ODE to step through the physical reactions
/// It moves the objects around in memory
/// It calls the methods that report back to the object owners.. (scenepresence, SceneObjectGroup)
- ///
+ ///
///
/// The number of frames simulated over that period.
public override float Simulate(float timeStep)
{
- int startFrameTick = Util.EnvironmentTickCount();
+ int startFrameTick = CollectStats ? Util.EnvironmentTickCount() : 0;
+ int quickStepTick = 0;
if (framecount >= int.MaxValue)
framecount = 0;
- //if (m_worldOffset != Vector3.Zero)
- // return 0;
-
framecount++;
float fps = 0;
@@ -2845,7 +2850,7 @@ namespace OpenSim.Region.Physics.OdePlugin
float timeLeft = timeStep;
//m_log.Info(timeStep.ToString());
-// step_time += timeStep;
+// step_time += timeSte
//
// // If We're loaded down by something else,
// // or debugging with the Visual Studio project on pause
@@ -3007,9 +3012,15 @@ namespace OpenSim.Region.Physics.OdePlugin
// "[PHYSICS]: Collision contacts to process this frame = {0}", m_global_contactcount);
m_global_contactcount = 0;
-
+
+ if (CollectStats)
+ quickStepTick = Util.EnvironmentTickCount();
+
d.WorldQuickStep(world, ODE_STEPSIZE);
+ if (CollectStats)
+ m_stats[ODENativeStepFrameMsStatName] += Util.EnvironmentTickCountSubtract(quickStepTick);
+
d.JointGroupEmpty(contactgroup);
}
catch (Exception e)
@@ -3077,7 +3088,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.WorldExportDIF(world, fname, physics_logging_append_existing_logfile, prefix);
}
- latertickcount = Util.EnvironmentTickCount() - tickCountFrameRun;
+ latertickcount = Util.EnvironmentTickCountSubtract(tickCountFrameRun);
// OpenSimulator above does 10 fps. 10 fps = means that the main thread loop and physics
// has a max of 100 ms to run theoretically.
@@ -3098,7 +3109,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
if (CollectStats)
- m_stats[ODETotalFrameMsStatName] += Util.EnvironmentTickCount() - startFrameTick;
+ m_stats[ODETotalFrameMsStatName] += Util.EnvironmentTickCountSubtract(startFrameTick);
return fps;
}
@@ -4119,6 +4130,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// m_stats[ODENativeCollisionFrameMsStatName] = 0;
m_stats[ODETotalFrameMsStatName] = 0;
+ m_stats[ODENativeStepFrameMsStatName] = 0;
m_stats[ODENativeSpaceCollisionFrameMsStatName] = 0;
m_stats[ODENativeGeomCollisionFrameMsStatName] = 0;
m_stats[ODEAvatarContactsStatsName] = 0;
--
cgit v1.1
From 5f44be99ef63f2f5ef7bcf73f61c29318d657e59 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 02:25:42 +0100
Subject: Add avatar and prim update milliseconds per frame optional stats
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 38 +++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 7 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 04c4722..f1fa38e 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -151,26 +151,36 @@ namespace OpenSim.Region.Physics.OdePlugin
public const string ODETotalFrameMsStatName = "ODETotalFrameMS";
///
- /// The amount of time spent in native code that actually steps through the simulation.
+ /// Stat name for the amount of time spent in native code that actually steps through the simulation.
///
public const string ODENativeStepFrameMsStatName = "ODENativeStepFrameMS";
///
- /// Stat name for recording the number of milliseconds that ODE spends in native collision code.
+ /// Stat name for the number of milliseconds that ODE spends in native collision code.
///
public const string ODENativeCollisionFrameMsStatName = "ODENativeCollisionFrameMS";
///
- /// Stat name for recording the number of milliseconds that ODE spends in native space collision code.
+ /// Stat name for the number of milliseconds that ODE spends in native space collision code.
///
public const string ODENativeSpaceCollisionFrameMsStatName = "ODENativeSpaceCollisionFrameMS";
///
- /// Stat name for recording the number of milliseconds that ODE spends in native geom collision code.
+ /// Stat name for the number of milliseconds that ODE spends in native geom collision code.
///
public const string ODENativeGeomCollisionFrameMsStatName = "ODENativeGeomCollisionFrameMS";
///
+ /// Stat name for the milliseconds spent updating avatar position and velocity
+ ///
+ public const string ODEAvatarUpdateFrameMsStatName = "ODEAvatarUpdateFrameMS";
+
+ ///
+ /// Stat name for the milliseconds spent updating prim position and velocity
+ ///
+ public const string ODEPrimUpdateFrameMsStatName = "ODEPrimUpdateFrameMS";
+
+ ///
/// Stat name for the number of avatar collisions with another entity.
///
public const string ODEAvatarContactsStatsName = "ODEAvatarContacts";
@@ -2838,7 +2848,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public override float Simulate(float timeStep)
{
int startFrameTick = CollectStats ? Util.EnvironmentTickCount() : 0;
- int quickStepTick = 0;
+ int tempTick = 0;;
if (framecount >= int.MaxValue)
framecount = 0;
@@ -3014,12 +3024,12 @@ namespace OpenSim.Region.Physics.OdePlugin
m_global_contactcount = 0;
if (CollectStats)
- quickStepTick = Util.EnvironmentTickCount();
+ tempTick = Util.EnvironmentTickCount();
d.WorldQuickStep(world, ODE_STEPSIZE);
if (CollectStats)
- m_stats[ODENativeStepFrameMsStatName] += Util.EnvironmentTickCountSubtract(quickStepTick);
+ m_stats[ODENativeStepFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick);
d.JointGroupEmpty(contactgroup);
}
@@ -3031,6 +3041,9 @@ namespace OpenSim.Region.Physics.OdePlugin
timeLeft -= ODE_STEPSIZE;
}
+ if (CollectStats)
+ tempTick = Util.EnvironmentTickCount();
+
foreach (OdeCharacter actor in _characters)
{
if (actor.bad)
@@ -3054,6 +3067,12 @@ namespace OpenSim.Region.Physics.OdePlugin
defects.Clear();
}
+ if (CollectStats)
+ {
+ m_stats[ODEAvatarUpdateFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick);
+ tempTick = Util.EnvironmentTickCount();
+ }
+
//if (timeStep < 0.2f)
foreach (OdePrim prim in _activeprims)
@@ -3067,6 +3086,9 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
+ if (CollectStats)
+ m_stats[ODEPrimUpdateFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick);
+
//DumpJointInfo();
// Finished with all sim stepping. If requested, dump world state to file for debugging.
@@ -4135,6 +4157,8 @@ namespace OpenSim.Region.Physics.OdePlugin
m_stats[ODENativeGeomCollisionFrameMsStatName] = 0;
m_stats[ODEAvatarContactsStatsName] = 0;
m_stats[ODEPrimContactsStatName] = 0;
+ m_stats[ODEAvatarUpdateFrameMsStatName] = 0;
+ m_stats[ODEPrimUpdateFrameMsStatName] = 0;
}
}
}
\ No newline at end of file
--
cgit v1.1
From 31343aa7c3182f4b7e05d7dc01c4c43bd2d43596 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 02:33:44 +0100
Subject: Add optional stat that records milliseconds spent notifying collision
listeners in physics frames
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index f1fa38e..0b9ad61 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -171,6 +171,11 @@ namespace OpenSim.Region.Physics.OdePlugin
public const string ODENativeGeomCollisionFrameMsStatName = "ODENativeGeomCollisionFrameMS";
///
+ /// Stat name for time spent notifying listeners of collisions
+ ///
+ public const string ODECollisionNotificationFrameMsStatName = "ODECollisionNotificationFrameMS";
+
+ ///
/// Stat name for the milliseconds spent updating avatar position and velocity
///
public const string ODEAvatarUpdateFrameMsStatName = "ODEAvatarUpdateFrameMS";
@@ -2998,6 +3003,9 @@ namespace OpenSim.Region.Physics.OdePlugin
collision_optimized();
+ if (CollectStats)
+ tempTick = Util.EnvironmentTickCount();
+
foreach (PhysicsActor obj in _collisionEventPrim.Values)
{
// m_log.DebugFormat("[PHYSICS]: Assessing {0} {1} for collision events", obj.SOPName, obj.LocalID);
@@ -3024,7 +3032,12 @@ namespace OpenSim.Region.Physics.OdePlugin
m_global_contactcount = 0;
if (CollectStats)
+ {
+ m_stats[ODECollisionNotificationFrameMsStatName]
+ += Util.EnvironmentTickCountSubtract(tempTick);
+
tempTick = Util.EnvironmentTickCount();
+ }
d.WorldQuickStep(world, ODE_STEPSIZE);
@@ -4155,6 +4168,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_stats[ODENativeStepFrameMsStatName] = 0;
m_stats[ODENativeSpaceCollisionFrameMsStatName] = 0;
m_stats[ODENativeGeomCollisionFrameMsStatName] = 0;
+ m_stats[ODECollisionNotificationFrameMsStatName] = 0;
m_stats[ODEAvatarContactsStatsName] = 0;
m_stats[ODEPrimContactsStatName] = 0;
m_stats[ODEAvatarUpdateFrameMsStatName] = 0;
--
cgit v1.1
From d1b5f8d9d76e3c7c4c23f485dd070e3775e8e85f Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 02:35:11 +0100
Subject: Remove recent optional native collision frame milliseconds stat
Unnecessary since this has now been broken down into space collisions and geom collisions
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 0b9ad61..948930b 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -156,11 +156,6 @@ namespace OpenSim.Region.Physics.OdePlugin
public const string ODENativeStepFrameMsStatName = "ODENativeStepFrameMS";
///
- /// Stat name for the number of milliseconds that ODE spends in native collision code.
- ///
- public const string ODENativeCollisionFrameMsStatName = "ODENativeCollisionFrameMS";
-
- ///
/// Stat name for the number of milliseconds that ODE spends in native space collision code.
///
public const string ODENativeSpaceCollisionFrameMsStatName = "ODENativeSpaceCollisionFrameMS";
@@ -3035,7 +3030,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
m_stats[ODECollisionNotificationFrameMsStatName]
+= Util.EnvironmentTickCountSubtract(tempTick);
-
+
tempTick = Util.EnvironmentTickCount();
}
@@ -4149,10 +4144,6 @@ namespace OpenSim.Region.Physics.OdePlugin
{
returnStats = new Dictionary(m_stats);
- returnStats[ODENativeCollisionFrameMsStatName]
- = returnStats[ODENativeSpaceCollisionFrameMsStatName]
- + returnStats[ODENativeGeomCollisionFrameMsStatName];
-
InitializeExtraStats();
}
@@ -4161,9 +4152,6 @@ namespace OpenSim.Region.Physics.OdePlugin
private void InitializeExtraStats()
{
- // No need to zero since this is calculated by addition
- // m_stats[ODENativeCollisionFrameMsStatName] = 0;
-
m_stats[ODETotalFrameMsStatName] = 0;
m_stats[ODENativeStepFrameMsStatName] = 0;
m_stats[ODENativeSpaceCollisionFrameMsStatName] = 0;
--
cgit v1.1
From 9ff8efc72014d8d5e971c3ceb7ec83bf9c19d69f Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 03:03:48 +0100
Subject: Collection optional avatar and prim taint frame millisecond times
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 43 +++++++++++++++++++++++-----
1 file changed, 36 insertions(+), 7 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 948930b..63b999e 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -151,6 +151,16 @@ namespace OpenSim.Region.Physics.OdePlugin
public const string ODETotalFrameMsStatName = "ODETotalFrameMS";
///
+ /// Stat name for amount of time spent processing avatar taints per frame
+ ///
+ public const string ODEAvatarTaintMsStatName = "ODEAvatarTaintFrameMS";
+
+ ///
+ /// Stat name for amount of time spent processing prim taints per frame
+ ///
+ public const string ODEPrimTaintMsStatName = "ODEPrimTaintFrameMS";
+
+ ///
/// Stat name for the amount of time spent in native code that actually steps through the simulation.
///
public const string ODENativeStepFrameMsStatName = "ODENativeStepFrameMS";
@@ -2848,7 +2858,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public override float Simulate(float timeStep)
{
int startFrameTick = CollectStats ? Util.EnvironmentTickCount() : 0;
- int tempTick = 0;;
+ int tempTick = 0, tempTick2 = 0;
if (framecount >= int.MaxValue)
framecount = 0;
@@ -2926,6 +2936,9 @@ namespace OpenSim.Region.Physics.OdePlugin
{
try
{
+ if (CollectStats)
+ tempTick = Util.EnvironmentTickCount();
+
lock (_taintedActors)
{
foreach (OdeCharacter character in _taintedActors)
@@ -2934,6 +2947,13 @@ namespace OpenSim.Region.Physics.OdePlugin
_taintedActors.Clear();
}
+ if (CollectStats)
+ {
+ tempTick2 = Util.EnvironmentTickCount();
+ m_stats[ODEAvatarTaintMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
+ tempTick = tempTick2;
+ }
+
lock (_taintedPrims)
{
foreach (OdePrim prim in _taintedPrims)
@@ -2964,6 +2984,13 @@ namespace OpenSim.Region.Physics.OdePlugin
_taintedPrims.Clear();
}
+ if (CollectStats)
+ {
+ tempTick2 = Util.EnvironmentTickCount();
+ m_stats[ODEPrimTaintMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
+ tempTick = tempTick2;
+ }
+
// Move characters
foreach (OdeCharacter actor in _characters)
actor.Move(defects);
@@ -3028,10 +3055,9 @@ namespace OpenSim.Region.Physics.OdePlugin
if (CollectStats)
{
- m_stats[ODECollisionNotificationFrameMsStatName]
- += Util.EnvironmentTickCountSubtract(tempTick);
-
- tempTick = Util.EnvironmentTickCount();
+ tempTick2 = Util.EnvironmentTickCount();
+ m_stats[ODECollisionNotificationFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
+ tempTick = tempTick2;
}
d.WorldQuickStep(world, ODE_STEPSIZE);
@@ -3077,8 +3103,9 @@ namespace OpenSim.Region.Physics.OdePlugin
if (CollectStats)
{
- m_stats[ODEAvatarUpdateFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick);
- tempTick = Util.EnvironmentTickCount();
+ tempTick2 = Util.EnvironmentTickCount();
+ m_stats[ODEAvatarUpdateFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
+ tempTick = tempTick2;
}
//if (timeStep < 0.2f)
@@ -4153,6 +4180,8 @@ namespace OpenSim.Region.Physics.OdePlugin
private void InitializeExtraStats()
{
m_stats[ODETotalFrameMsStatName] = 0;
+ m_stats[ODEAvatarTaintMsStatName] = 0;
+ m_stats[ODEPrimTaintMsStatName] = 0;
m_stats[ODENativeStepFrameMsStatName] = 0;
m_stats[ODENativeSpaceCollisionFrameMsStatName] = 0;
m_stats[ODENativeGeomCollisionFrameMsStatName] = 0;
--
cgit v1.1
From d34b84b53137f5516f790563588676ac5fbf0e49 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 03:23:19 +0100
Subject: Add avatar forces calculation, prim force and raycasting per frame
millisecond optional stats
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 53 ++++++++++++++++++++++++----
1 file changed, 46 insertions(+), 7 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 63b999e..e44375b 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -151,17 +151,32 @@ namespace OpenSim.Region.Physics.OdePlugin
public const string ODETotalFrameMsStatName = "ODETotalFrameMS";
///
- /// Stat name for amount of time spent processing avatar taints per frame
+ /// Stat name for time spent processing avatar taints per frame
///
public const string ODEAvatarTaintMsStatName = "ODEAvatarTaintFrameMS";
///
- /// Stat name for amount of time spent processing prim taints per frame
+ /// Stat name for time spent processing prim taints per frame
///
public const string ODEPrimTaintMsStatName = "ODEPrimTaintFrameMS";
///
- /// Stat name for the amount of time spent in native code that actually steps through the simulation.
+ /// Stat name for time spent calculating avatar forces per frame.
+ ///
+ public const string ODEAvatarForcesFrameMsStatName = "ODEAvatarForcesFrameMS";
+
+ ///
+ /// Stat name for time spent calculating prim forces per frame
+ ///
+ public const string ODEPrimForcesFrameMsStatName = "ODEPrimForcesFrameMS";
+
+ ///
+ /// Stat name for time spent fulfilling raycasting requests per frame
+ ///
+ public const string ODERaycastingFrameMsStatName = "ODERaycastingFrameMS";
+
+ ///
+ /// Stat name for time spent in native code that actually steps through the simulation.
///
public const string ODENativeStepFrameMsStatName = "ODENativeStepFrameMS";
@@ -171,7 +186,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public const string ODENativeSpaceCollisionFrameMsStatName = "ODENativeSpaceCollisionFrameMS";
///
- /// Stat name for the number of milliseconds that ODE spends in native geom collision code.
+ /// Stat name for milliseconds that ODE spends in native geom collision code.
///
public const string ODENativeGeomCollisionFrameMsStatName = "ODENativeGeomCollisionFrameMS";
@@ -181,7 +196,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public const string ODECollisionNotificationFrameMsStatName = "ODECollisionNotificationFrameMS";
///
- /// Stat name for the milliseconds spent updating avatar position and velocity
+ /// Stat name for milliseconds spent updating avatar position and velocity
///
public const string ODEAvatarUpdateFrameMsStatName = "ODEAvatarUpdateFrameMS";
@@ -191,12 +206,12 @@ namespace OpenSim.Region.Physics.OdePlugin
public const string ODEPrimUpdateFrameMsStatName = "ODEPrimUpdateFrameMS";
///
- /// Stat name for the number of avatar collisions with another entity.
+ /// Stat name for avatar collisions with another entity.
///
public const string ODEAvatarContactsStatsName = "ODEAvatarContacts";
///
- /// Stat name for the number of prim collisions with another entity.
+ /// Stat name for prim collisions with another entity.
///
public const string ODEPrimContactsStatName = "ODEPrimContacts";
@@ -3010,6 +3025,13 @@ namespace OpenSim.Region.Physics.OdePlugin
defects.Clear();
}
+ if (CollectStats)
+ {
+ tempTick2 = Util.EnvironmentTickCount();
+ m_stats[ODEAvatarForcesFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
+ tempTick = tempTick2;
+ }
+
// Move other active objects
foreach (OdePrim prim in _activeprims)
{
@@ -3017,12 +3039,26 @@ namespace OpenSim.Region.Physics.OdePlugin
prim.Move(timeStep);
}
+ if (CollectStats)
+ {
+ tempTick2 = Util.EnvironmentTickCount();
+ m_stats[ODEPrimForcesFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
+ tempTick = tempTick2;
+ }
+
//if ((framecount % m_randomizeWater) == 0)
// randomizeWater(waterlevel);
//int RayCastTimeMS = m_rayCastManager.ProcessQueuedRequests();
m_rayCastManager.ProcessQueuedRequests();
+ if (CollectStats)
+ {
+ tempTick2 = Util.EnvironmentTickCount();
+ m_stats[ODERaycastingFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
+ tempTick = tempTick2;
+ }
+
collision_optimized();
if (CollectStats)
@@ -4182,6 +4218,9 @@ namespace OpenSim.Region.Physics.OdePlugin
m_stats[ODETotalFrameMsStatName] = 0;
m_stats[ODEAvatarTaintMsStatName] = 0;
m_stats[ODEPrimTaintMsStatName] = 0;
+ m_stats[ODEAvatarForcesFrameMsStatName] = 0;
+ m_stats[ODEPrimForcesFrameMsStatName] = 0;
+ m_stats[ODERaycastingFrameMsStatName] = 0;
m_stats[ODENativeStepFrameMsStatName] = 0;
m_stats[ODENativeSpaceCollisionFrameMsStatName] = 0;
m_stats[ODENativeGeomCollisionFrameMsStatName] = 0;
--
cgit v1.1
From 200376b3c4717e9ae00b67ef5f2a57383952f2d5 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 03:49:42 +0100
Subject: Add optional stat for the other collision time per frame not spent in
ODE native spaces or geom collision code
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index e44375b..8590453 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -191,6 +191,11 @@ namespace OpenSim.Region.Physics.OdePlugin
public const string ODENativeGeomCollisionFrameMsStatName = "ODENativeGeomCollisionFrameMS";
///
+ /// Time spent in collision processing that is not spent in native space or geom collision code.
+ ///
+ public const string ODEOtherCollisionFrameMsStatName = "ODEOtherCollisionFrameMS";
+
+ ///
/// Stat name for time spent notifying listeners of collisions
///
public const string ODECollisionNotificationFrameMsStatName = "ODECollisionNotificationFrameMS";
@@ -3062,7 +3067,11 @@ namespace OpenSim.Region.Physics.OdePlugin
collision_optimized();
if (CollectStats)
- tempTick = Util.EnvironmentTickCount();
+ {
+ tempTick2 = Util.EnvironmentTickCount();
+ m_stats[ODEOtherCollisionFrameMsStatName] += Util.EnvironmentTickCountSubtract(tempTick2, tempTick);
+ tempTick = tempTick2;
+ }
foreach (PhysicsActor obj in _collisionEventPrim.Values)
{
@@ -4210,6 +4219,11 @@ namespace OpenSim.Region.Physics.OdePlugin
InitializeExtraStats();
}
+ returnStats[ODEOtherCollisionFrameMsStatName]
+ = returnStats[ODEOtherCollisionFrameMsStatName]
+ - returnStats[ODENativeSpaceCollisionFrameMsStatName]
+ - returnStats[ODENativeGeomCollisionFrameMsStatName];
+
return returnStats;
}
@@ -4224,6 +4238,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_stats[ODENativeStepFrameMsStatName] = 0;
m_stats[ODENativeSpaceCollisionFrameMsStatName] = 0;
m_stats[ODENativeGeomCollisionFrameMsStatName] = 0;
+ m_stats[ODEOtherCollisionFrameMsStatName] = 0;
m_stats[ODECollisionNotificationFrameMsStatName] = 0;
m_stats[ODEAvatarContactsStatsName] = 0;
m_stats[ODEPrimContactsStatName] = 0;
--
cgit v1.1
From 4e06a46dc5e6d0fb6a894932e706e4a01351ec64 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 04:07:39 +0100
Subject: If OdeScene.Near() returns no collision contacts, then exit as early
as possible. All subsequent code is only relevant if there are contacts.
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 8590453..c26c9c5 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -1025,6 +1025,10 @@ namespace OpenSim.Region.Physics.OdePlugin
count = CollideGeoms(g1, g2, contacts.Length, contacts, d.ContactGeom.SizeOf);
+ // All code after this is only relevant if we have any collisions
+ if (count <= 0)
+ return;
+
if (count > contacts.Length)
m_log.Error("[ODE SCENE]: Got " + count + " contacts when we asked for a maximum of " + contacts.Length);
}
--
cgit v1.1
From 6375db1533e6c625d7b6394542f74141092ff780 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 1 Jun 2012 04:23:36 +0100
Subject: Add optional total avatars, total prims and active prims stats to ODE
plugin.
These will act as a sanity check with the main scene stats, to show that physics scene entities are being managed properly.
Total prims will not match scene total prims since physics total does not include phantom prims
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index c26c9c5..c6ecc68 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -143,6 +143,21 @@ namespace OpenSim.Region.Physics.OdePlugin
private Dictionary m_stats = new Dictionary();
///
+ /// Stat name for total number of avatars in this ODE scene.
+ ///
+ public const string ODETotalAvatarsStatName = "ODETotalAvatars";
+
+ ///
+ /// Stat name for total number of prims in this ODE scene.
+ ///
+ public const string ODETotalPrimsStatName = "ODETotalPrims";
+
+ ///
+ /// Stat name for total number of prims with active physics in this ODE scene.
+ ///
+ public const string ODEActivePrimsStatName = "ODEActivePrims";
+
+ ///
/// Stat name for the total time spent in ODE frame processing.
///
///
@@ -4220,6 +4235,12 @@ namespace OpenSim.Region.Physics.OdePlugin
{
returnStats = new Dictionary(m_stats);
+ // FIXME: This is a SUPER DUMB HACK until we can establish stats that aren't subject to a division by
+ // 3 from the SimStatsReporter.
+ returnStats[ODETotalAvatarsStatName] = _characters.Count * 3;
+ returnStats[ODETotalPrimsStatName] = _prims.Count * 3;
+ returnStats[ODEActivePrimsStatName] = _activeprims.Count * 3;
+
InitializeExtraStats();
}
--
cgit v1.1
From 1a7be7b00eaef0140f2dc13f3e14d8150c393b08 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 29 Jun 2012 00:36:50 +0100
Subject: Fix a regression where we stopped removing avatars from collision
event reporting on logout, rather than stopping clearing their collision
events.
This occurred in b18c8c8 (Thu May 17 2012).
This was a cause of very occasional race conditions and likely memory leakage as clients came and went from the region.
---
OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 54b69a2..f3b0630 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -1270,7 +1270,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void UnSubscribeEvents()
{
- CollisionEventsThisFrame.Clear();
+ _parent_scene.RemoveCollisionEventReporting(this);
// Don't clear collision event reporting here. This is called directly from scene code and so can lead
// to a race condition with the simulate loop
--
cgit v1.1
From e420f815dc9be9c7fc93cb94c86517d97abbed86 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 29 Jun 2012 00:54:40 +0100
Subject: refactor: rename _collisionEventPrim to m_collisionEventActors and
_collisionEventPrimChanges to m_collisionEventActorsChanges to reflect their
actual contents.
These dictionaries handle all actor types, not just physical prims.
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index c6ecc68..79de99e 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -387,12 +387,12 @@ namespace OpenSim.Region.Physics.OdePlugin
///
/// A dictionary of actors that should receive collision events.
///
- private readonly Dictionary _collisionEventPrim = new Dictionary();
+ private readonly Dictionary m_collisionEventActors = new Dictionary();
///
/// A dictionary of collision event changes that are waiting to be processed.
///
- private readonly Dictionary _collisionEventPrimChanges = new Dictionary();
+ private readonly Dictionary m_collisionEventActorsChanges = new Dictionary();
///
/// Maps a unique geometry id (a memory location) to a physics actor name.
@@ -1908,8 +1908,8 @@ namespace OpenSim.Region.Physics.OdePlugin
{
// m_log.DebugFormat("[PHYSICS]: Adding {0} {1} to collision event reporting", obj.SOPName, obj.LocalID);
- lock (_collisionEventPrimChanges)
- _collisionEventPrimChanges[obj.LocalID] = obj;
+ lock (m_collisionEventActorsChanges)
+ m_collisionEventActorsChanges[obj.LocalID] = obj;
}
///
@@ -1920,8 +1920,8 @@ namespace OpenSim.Region.Physics.OdePlugin
{
// m_log.DebugFormat("[PHYSICS]: Removing {0} {1} from collision event reporting", obj.SOPName, obj.LocalID);
- lock (_collisionEventPrimChanges)
- _collisionEventPrimChanges[obj.LocalID] = null;
+ lock (m_collisionEventActorsChanges)
+ m_collisionEventActorsChanges[obj.LocalID] = null;
}
#region Add/Remove Entities
@@ -2930,17 +2930,17 @@ namespace OpenSim.Region.Physics.OdePlugin
// We change _collisionEventPrimChanges to avoid locking _collisionEventPrim itself and causing potential
// deadlock if the collision event tries to lock something else later on which is already locked by a
// caller that is adding or removing the collision event.
- lock (_collisionEventPrimChanges)
+ lock (m_collisionEventActorsChanges)
{
- foreach (KeyValuePair kvp in _collisionEventPrimChanges)
+ foreach (KeyValuePair kvp in m_collisionEventActorsChanges)
{
if (kvp.Value == null)
- _collisionEventPrim.Remove(kvp.Key);
+ m_collisionEventActors.Remove(kvp.Key);
else
- _collisionEventPrim[kvp.Key] = kvp.Value;
+ m_collisionEventActors[kvp.Key] = kvp.Value;
}
- _collisionEventPrimChanges.Clear();
+ m_collisionEventActorsChanges.Clear();
}
if (SupportsNINJAJoints)
@@ -3092,7 +3092,7 @@ namespace OpenSim.Region.Physics.OdePlugin
tempTick = tempTick2;
}
- foreach (PhysicsActor obj in _collisionEventPrim.Values)
+ foreach (PhysicsActor obj in m_collisionEventActors.Values)
{
// m_log.DebugFormat("[PHYSICS]: Assessing {0} {1} for collision events", obj.SOPName, obj.LocalID);
--
cgit v1.1
From 0229e90dcc579cee8fe3321a78f6d75b5d70486e Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 29 Jun 2012 01:02:35 +0100
Subject: Move update of the final optional ODE total frame stat inside the
OdeLock rather than outside to avoid a very occasional race condition with
the stat collection thread
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 79de99e..32e81e2 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -3227,10 +3227,10 @@ namespace OpenSim.Region.Physics.OdePlugin
}
tickCountFrameRun = Util.EnvironmentTickCount();
- }
- if (CollectStats)
- m_stats[ODETotalFrameMsStatName] += Util.EnvironmentTickCountSubtract(startFrameTick);
+ if (CollectStats)
+ m_stats[ODETotalFrameMsStatName] += Util.EnvironmentTickCountSubtract(startFrameTick);
+ }
return fps;
}
--
cgit v1.1
From 1926de5a0599051c27c065fb06da3dc536e6784a Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 30 Jun 2012 01:25:27 +0100
Subject: Remove some mono compiler warnings
---
OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs
index b89eeed..47d7df3 100644
--- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPrim.cs
@@ -37,7 +37,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
public class BasicPhysicsPrim : PhysicsActor
{
private Vector3 _size;
- private PrimitiveBaseShape _shape;
+// private PrimitiveBaseShape _shape;
public BasicPhysicsPrim(
string name, uint localId, Vector3 position, Vector3 size, Quaternion orientation, PrimitiveBaseShape shape)
@@ -136,7 +136,8 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
public override PrimitiveBaseShape Shape
{
- set { _shape = value; }
+// set { _shape = value; }
+ set {}
}
public override float Mass
--
cgit v1.1
From e4a6611865848ffcfa6adedd813534e0a0e4abf3 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Fri, 6 Jul 2012 10:01:47 -0700
Subject: Clean up collision reporting code so they are properly passed to
the simulator in batches. More comments.
---
.../Region/Physics/BulletSPlugin/BSCharacter.cs | 102 ++++++++++++---------
OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs | 11 +++
OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 29 +++---
OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 23 ++++-
4 files changed, 107 insertions(+), 58 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index b08d5db..dc0c008 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -74,7 +74,7 @@ public class BSCharacter : PhysicsActor
private float _buoyancy;
private int _subscribedEventsMs = 0;
- private int _lastCollisionTime = 0;
+ private int _nextCollisionOkTime = 0;
private Vector3 _PIDTarget;
private bool _usePID;
@@ -360,17 +360,22 @@ public class BSCharacter : PhysicsActor
}
//m_lastUpdateSent = false;
}
+
public override void AddAngularForce(Vector3 force, bool pushforce) {
}
public override void SetMomentum(Vector3 momentum) {
}
+
+ // Turn on collision events at a rate no faster than one every the given milliseconds
public override void SubscribeEvents(int ms) {
_subscribedEventsMs = ms;
- _lastCollisionTime = Util.EnvironmentTickCount() - _subscribedEventsMs; // make first collision happen
+ _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs; // make first collision happen
}
+ // Stop collision events
public override void UnSubscribeEvents() {
_subscribedEventsMs = 0;
}
+ // Return 'true' if someone has subscribed to events
public override bool SubscribedEvents() {
return (_subscribedEventsMs > 0);
}
@@ -386,47 +391,57 @@ public class BSCharacter : PhysicsActor
_mass = _density * _avatarVolume;
}
+ // Set to 'true' if the individual changed items should be checked
+ // (someday RequestPhysicsTerseUpdate() will take a bitmap of changed properties)
+ const bool SHOULD_CHECK_FOR_INDIVIDUAL_CHANGES = false;
+
// The physics engine says that properties have updated. Update same and inform
// the world that things have changed.
public void UpdateProperties(EntityProperties entprop)
{
bool changed = false;
- // we assign to the local variables so the normal set action does not happen
- if (_position != entprop.Position)
- {
- _position = entprop.Position;
- changed = true;
+ if (SHOULD_CHECK_FOR_INDIVIDUAL_CHANGES) {
+ // we assign to the local variables so the normal set action does not happen
+ if (_position != entprop.Position) {
+ _position = entprop.Position;
+ changed = true;
+ }
+ if (_orientation != entprop.Rotation) {
+ _orientation = entprop.Rotation;
+ changed = true;
+ }
+ if (_velocity != entprop.Velocity) {
+ _velocity = entprop.Velocity;
+ changed = true;
+ }
+ if (_acceleration != entprop.Acceleration) {
+ _acceleration = entprop.Acceleration;
+ changed = true;
+ }
+ if (_rotationalVelocity != entprop.RotationalVelocity) {
+ _rotationalVelocity = entprop.RotationalVelocity;
+ changed = true;
+ }
+ if (changed) {
+ // m_log.DebugFormat("{0}: UpdateProperties: id={1}, c={2}, pos={3}, rot={4}", LogHeader, LocalID, changed, _position, _orientation);
+ // Avatar movement is not done by generating this event. There is code in the heartbeat
+ // loop that updates avatars.
+ // base.RequestPhysicsterseUpdate();
+ }
}
- if (_orientation != entprop.Rotation)
- {
+ else {
+ _position = entprop.Position;
_orientation = entprop.Rotation;
- changed = true;
- }
- if (_velocity != entprop.Velocity)
- {
_velocity = entprop.Velocity;
- changed = true;
- }
- if (_acceleration != entprop.Acceleration)
- {
_acceleration = entprop.Acceleration;
- changed = true;
- }
- if (_rotationalVelocity != entprop.RotationalVelocity)
- {
_rotationalVelocity = entprop.RotationalVelocity;
- changed = true;
- }
- if (changed)
- {
- // m_log.DebugFormat("{0}: UpdateProperties: id={1}, c={2}, pos={3}, rot={4}", LogHeader, LocalID, changed, _position, _orientation);
- // Avatar movement is not done by generating this event. There is a system that
- // checks for avatar updates each heartbeat loop.
// base.RequestPhysicsterseUpdate();
}
}
// Called by the scene when a collision with this object is reported
+ // The collision, if it should be reported to the character, is placed in a collection
+ // that will later be sent to the simulator when SendCollisions() is called.
CollisionEventUpdate collisionCollection = null;
public void Collide(uint collidingWith, ActorTypes type, Vector3 contactPoint, Vector3 contactNormal, float pentrationDepth)
{
@@ -440,29 +455,34 @@ public class BSCharacter : PhysicsActor
}
// throttle collisions to the rate specified in the subscription
- if (_subscribedEventsMs == 0) return; // don't want collisions
- int nowTime = _scene.SimulationNowTime;
- if (nowTime < (_lastCollisionTime + _subscribedEventsMs)) return;
- _lastCollisionTime = nowTime;
+ if (_subscribedEventsMs != 0) {
+ int nowTime = _scene.SimulationNowTime;
+ if (nowTime >= _nextCollisionOkTime) {
+ _nextCollisionOkTime = nowTime + _subscribedEventsMs;
- if (collisionCollection == null)
- collisionCollection = new CollisionEventUpdate();
- collisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
+ if (collisionCollection == null)
+ collisionCollection = new CollisionEventUpdate();
+ collisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
+ }
+ }
}
public void SendCollisions()
{
- // if (collisionCollection != null)
- // {
- // base.SendCollisionUpdate(collisionCollection);
- // collisionCollection = null;
- // }
+ /*
+ if (collisionCollection != null && collisionCollection.Count > 0)
+ {
+ base.SendCollisionUpdate(collisionCollection);
+ collisionCollection = null;
+ }
+ */
// Kludge to make a collision call even if there are no collisions.
// This causes the avatar animation to get updated.
if (collisionCollection == null)
collisionCollection = new CollisionEventUpdate();
base.SendCollisionUpdate(collisionCollection);
- collisionCollection = null;
+ collisionCollection.Clear();
+ // End kludge
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs
index 0730824..0f027b8 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPlugin.cs
@@ -32,6 +32,14 @@ using OpenMetaverse;
namespace OpenSim.Region.Physics.BulletSPlugin
{
+ ///
+ /// Entry for a port of Bullet (http://bulletphysics.org/) to OpenSim.
+ /// This module interfaces to an unmanaged C++ library which makes the
+ /// actual calls into the Bullet physics engine.
+ /// The unmanaged library is found in opensim-libs::trunk/unmanaged/BulletSim/.
+ /// The unmanaged library is compiled and linked statically with Bullet
+ /// to create BulletSim.dll and libBulletSim.so (for both 32 and 64 bit).
+ ///
public class BSPlugin : IPhysicsPlugin
{
//private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
@@ -53,6 +61,9 @@ public class BSPlugin : IPhysicsPlugin
{
if (Util.IsWindows())
Util.LoadArchSpecificWindowsDll("BulletSim.dll");
+ // If not Windows, loading is performed by the
+ // Mono loader as specified in
+ // "bin/Physics/OpenSim.Region.Physics.BulletSPlugin.dll.config".
_mScene = new BSScene(sceneIdentifier);
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 248d1f2..130f1ca 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -90,7 +90,7 @@ public sealed class BSPrim : PhysicsActor
private BSPrim _parentPrim;
private int _subscribedEventsMs = 0;
- private int _lastCollisionTime = 0;
+ private int _nextCollisionOkTime = 0;
long _collidingStep;
long _collidingGroundStep;
@@ -597,7 +597,8 @@ public sealed class BSPrim : PhysicsActor
}
public override void SubscribeEvents(int ms) {
_subscribedEventsMs = ms;
- _lastCollisionTime = Util.EnvironmentTickCount() - _subscribedEventsMs; // make first collision happen
+ // make sure first collision happens
+ _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs;
}
public override void UnSubscribeEvents() {
_subscribedEventsMs = 0;
@@ -1338,23 +1339,27 @@ public sealed class BSPrim : PhysicsActor
_collidingGroundStep = _scene.SimulationStep;
}
- if (_subscribedEventsMs == 0) return; // nothing in the object is waiting for collision events
- // throttle the collisions to the number of milliseconds specified in the subscription
- int nowTime = _scene.SimulationNowTime;
- if (nowTime < (_lastCollisionTime + _subscribedEventsMs)) return;
- _lastCollisionTime = nowTime;
+ // if someone is subscribed to collision events....
+ if (_subscribedEventsMs != 0) {
+ // throttle the collisions to the number of milliseconds specified in the subscription
+ int nowTime = _scene.SimulationNowTime;
+ if (nowTime >= _nextCollisionOkTime) {
+ _nextCollisionOkTime = nowTime + _subscribedEventsMs;
- if (collisionCollection == null)
- collisionCollection = new CollisionEventUpdate();
- collisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
+ if (collisionCollection == null)
+ collisionCollection = new CollisionEventUpdate();
+ collisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
+ }
+ }
}
+ // The scene is telling us it's time to pass our collected collisions into the simulator
public void SendCollisions()
{
- if (collisionCollection != null)
+ if (collisionCollection != null && collisionCollection.Count > 0)
{
base.SendCollisionUpdate(collisionCollection);
- collisionCollection = null;
+ collisionCollection.Clear();
}
}
}
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index 94a0ccf..417cb5f 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -52,6 +52,7 @@ using OpenSim.Region.Framework;
// Should prim.link() and prim.delink() membership checking happen at taint time?
// Mesh sharing. Use meshHash to tell if we already have a hull of that shape and only create once
// Do attachments need to be handled separately? Need collision events. Do not collide with VolumeDetect
+// Use collision masks for collision with terrain and phantom objects
// Implement the genCollisions feature in BulletSim::SetObjectProperties (don't pass up unneeded collisions)
// Implement LockAngularMotion
// Decide if clearing forces is the right thing to do when setting position (BulletSim::SetObjectTranslation)
@@ -62,9 +63,6 @@ using OpenSim.Region.Framework;
// Multiple contact points on collision?
// See code in ode::near... calls to collision_accounting_events()
// (This might not be a problem. ODE collects all the collisions with one object in one tick.)
-// Use collision masks for collision with terrain and phantom objects
-// Figure out how to not allocate a new Dictionary and List for every collision
-// in BSPrim.Collide() and BSCharacter.Collide(). Can the same ones be reused?
// Raycast
//
namespace OpenSim.Region.Physics.BulletSPlugin
@@ -405,6 +403,8 @@ public class BSScene : PhysicsScene, IPhysicsParameters
// prevent simulation until we've been initialized
if (!m_initialized) return 10.0f;
+ long simulateStartTime = Util.EnvironmentTickCount();
+
// update the prim states while we know the physics engine is not busy
ProcessTaints();
@@ -437,13 +437,18 @@ public class BSScene : PhysicsScene, IPhysicsParameters
}
}
- // The SendCollision's batch up the collisions on the objects. Now push the collisions into the simulator.
+ // The above SendCollision's batch up the collisions on the objects.
+ // Now push the collisions into the simulator.
foreach (BSPrim bsp in m_primsWithCollisions)
bsp.SendCollisions();
m_primsWithCollisions.Clear();
+
+ // This is a kludge to get avatar movement updated.
+ // Don't send collisions only if there were collisions -- send everytime.
+ // ODE sends collisions even if there are none and this is used to update
+ // avatar animations and stuff.
// foreach (BSCharacter bsc in m_avatarsWithCollisions)
// bsc.SendCollisions();
- // This is a kludge to get avatar movement updated. ODE sends collisions even if there isn't any
foreach (KeyValuePair kvp in m_avatars)
kvp.Value.SendCollisions();
m_avatarsWithCollisions.Clear();
@@ -465,10 +470,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters
if (m_avatars.TryGetValue(entprop.ID, out actor))
{
actor.UpdateProperties(entprop);
+ continue;
}
}
}
+ // If enabled, call into the physics engine to dump statistics
if (m_detailedStatsStep > 0)
{
if ((m_simulationStep % m_detailedStatsStep) == 0)
@@ -477,6 +484,11 @@ public class BSScene : PhysicsScene, IPhysicsParameters
}
}
+ // this is a waste since the outside routine also calcuates the physics simulation
+ // period. TODO: There should be a way of computing physics frames from simulator computation.
+ // long simulateTotalTime = Util.EnvironmentTickCountSubtract(simulateStartTime);
+ // return (timeStep * (float)simulateTotalTime);
+
// TODO: FIX THIS: fps calculation wrong. This calculation always returns about 1 in normal operation.
return timeStep / (numSubSteps * m_fixedTimeStep) * 1000f;
}
@@ -528,6 +540,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
public override void SetWaterLevel(float baseheight)
{
m_waterLevel = baseheight;
+ // TODO: pass to physics engine so things will float?
}
public float GetWaterLevel()
{
--
cgit v1.1
From 5d3723a47f7ddb32964055561ecf2a601f6b19f2 Mon Sep 17 00:00:00 2001
From: dahlia
Date: Fri, 13 Jul 2012 21:22:15 -0700
Subject: update PrimMesher.cs to dll version r72 which fixes some path errors
in sliced linear prims. Addresses Mantis #6085
---
OpenSim/Region/Physics/Meshing/PrimMesher.cs | 326 +++++++++++++++------------
1 file changed, 183 insertions(+), 143 deletions(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/Meshing/PrimMesher.cs b/OpenSim/Region/Physics/Meshing/PrimMesher.cs
index 53022ad..4049ee1 100644
--- a/OpenSim/Region/Physics/Meshing/PrimMesher.cs
+++ b/OpenSim/Region/Physics/Meshing/PrimMesher.cs
@@ -236,6 +236,13 @@ namespace PrimMesher
this.U = u;
this.V = v;
}
+
+ public UVCoord Flip()
+ {
+ this.U = 1.0f - this.U;
+ this.V = 1.0f - this.V;
+ return this;
+ }
}
public struct Face
@@ -603,40 +610,40 @@ namespace PrimMesher
///
/// generates a profile for extrusion
///
- internal class Profile
+ public class Profile
{
private const float twoPi = 2.0f * (float)Math.PI;
- internal string errorMessage = null;
+ public string errorMessage = null;
- internal List coords;
- internal List faces;
- internal List vertexNormals;
- internal List us;
- internal List faceUVs;
- internal List faceNumbers;
+ public List coords;
+ public List faces;
+ public List vertexNormals;
+ public List us;
+ public List faceUVs;
+ public List faceNumbers;
// use these for making individual meshes for each prim face
- internal List outerCoordIndices = null;
- internal List hollowCoordIndices = null;
- internal List cut1CoordIndices = null;
- internal List cut2CoordIndices = null;
+ public List outerCoordIndices = null;
+ public List hollowCoordIndices = null;
+ public List cut1CoordIndices = null;
+ public List cut2CoordIndices = null;
- internal Coord faceNormal = new Coord(0.0f, 0.0f, 1.0f);
- internal Coord cutNormal1 = new Coord();
- internal Coord cutNormal2 = new Coord();
+ public Coord faceNormal = new Coord(0.0f, 0.0f, 1.0f);
+ public Coord cutNormal1 = new Coord();
+ public Coord cutNormal2 = new Coord();
- internal int numOuterVerts = 0;
- internal int numHollowVerts = 0;
+ public int numOuterVerts = 0;
+ public int numHollowVerts = 0;
- internal int outerFaceNumber = -1;
- internal int hollowFaceNumber = -1;
+ public int outerFaceNumber = -1;
+ public int hollowFaceNumber = -1;
- internal bool calcVertexNormals = false;
- internal int bottomFaceNumber = 0;
- internal int numPrimFaces = 0;
+ public bool calcVertexNormals = false;
+ public int bottomFaceNumber = 0;
+ public int numPrimFaces = 0;
- internal Profile()
+ public Profile()
{
this.coords = new List();
this.faces = new List();
@@ -646,7 +653,7 @@ namespace PrimMesher
this.faceNumbers = new List();
}
- internal Profile(int sides, float profileStart, float profileEnd, float hollow, int hollowSides, bool createFaces, bool calcVertexNormals)
+ public Profile(int sides, float profileStart, float profileEnd, float hollow, int hollowSides, bool createFaces, bool calcVertexNormals)
{
this.calcVertexNormals = calcVertexNormals;
this.coords = new List();
@@ -657,7 +664,6 @@ namespace PrimMesher
this.faceNumbers = new List();
Coord center = new Coord(0.0f, 0.0f, 0.0f);
- //bool hasCenter = false;
List hollowCoords = new List();
List hollowNormals = new List();
@@ -682,8 +688,8 @@ namespace PrimMesher
float yScale = 0.5f;
if (sides == 4) // corners of a square are sqrt(2) from center
{
- xScale = 0.707f;
- yScale = 0.707f;
+ xScale = 0.707107f;
+ yScale = 0.707107f;
}
float startAngle = profileStart * twoPi;
@@ -724,7 +730,6 @@ namespace PrimMesher
else if (!simpleFace)
{
this.coords.Add(center);
- //hasCenter = true;
if (this.calcVertexNormals)
this.vertexNormals.Add(new Coord(0.0f, 0.0f, 1.0f));
this.us.Add(0.0f);
@@ -752,7 +757,10 @@ namespace PrimMesher
else
hollowNormals.Add(new Coord(-angle.X, -angle.Y, 0.0f));
- hollowUs.Add(angle.angle * hollow);
+ if (hollowSides == 4)
+ hollowUs.Add(angle.angle * hollow * 0.707107f);
+ else
+ hollowUs.Add(angle.angle * hollow);
}
}
}
@@ -829,9 +837,6 @@ namespace PrimMesher
if (createFaces)
{
- //int numOuterVerts = this.coords.Count;
- //numOuterVerts = this.coords.Count;
- //int numHollowVerts = hollowCoords.Count;
int numTotalVerts = this.numOuterVerts + this.numHollowVerts;
if (this.numOuterVerts == this.numHollowVerts)
@@ -993,11 +998,7 @@ namespace PrimMesher
if (startVert > 0)
this.faceNumbers.Add(-1);
for (int i = 0; i < this.numOuterVerts - 1; i++)
- //this.faceNumbers.Add(sides < 5 ? faceNum++ : faceNum);
- this.faceNumbers.Add(sides < 5 && i < sides ? faceNum++ : faceNum);
-
- //if (!hasHollow && !hasProfileCut)
- // this.bottomFaceNumber = faceNum++;
+ this.faceNumbers.Add(sides < 5 && i <= sides ? faceNum++ : faceNum);
this.faceNumbers.Add(hasProfileCut ? -1 : faceNum++);
@@ -1014,8 +1015,7 @@ namespace PrimMesher
this.hollowFaceNumber = faceNum++;
}
- //if (hasProfileCut || hasHollow)
- // this.bottomFaceNumber = faceNum++;
+
this.bottomFaceNumber = faceNum++;
if (hasHollow && hasProfileCut)
@@ -1030,19 +1030,19 @@ namespace PrimMesher
}
- internal void MakeFaceUVs()
+ public void MakeFaceUVs()
{
this.faceUVs = new List();
foreach (Coord c in this.coords)
- this.faceUVs.Add(new UVCoord(0.5f + c.X, 0.5f - c.Y));
+ this.faceUVs.Add(new UVCoord(1.0f - (0.5f + c.X), 1.0f - (0.5f - c.Y)));
}
- internal Profile Copy()
+ public Profile Copy()
{
return this.Copy(true);
}
- internal Profile Copy(bool needFaces)
+ public Profile Copy(bool needFaces)
{
Profile copy = new Profile();
@@ -1071,12 +1071,12 @@ namespace PrimMesher
return copy;
}
- internal void AddPos(Coord v)
+ public void AddPos(Coord v)
{
this.AddPos(v.X, v.Y, v.Z);
}
- internal void AddPos(float x, float y, float z)
+ public void AddPos(float x, float y, float z)
{
int i;
int numVerts = this.coords.Count;
@@ -1092,7 +1092,7 @@ namespace PrimMesher
}
}
- internal void AddRot(Quat q)
+ public void AddRot(Quat q)
{
int i;
int numVerts = this.coords.Count;
@@ -1113,7 +1113,7 @@ namespace PrimMesher
}
}
- internal void Scale(float x, float y)
+ public void Scale(float x, float y)
{
int i;
int numVerts = this.coords.Count;
@@ -1131,7 +1131,7 @@ namespace PrimMesher
///
/// Changes order of the vertex indices and negates the center vertex normal. Does not alter vertex normals of radial vertices
///
- internal void FlipNormals()
+ public void FlipNormals()
{
int i;
int numFaces = this.faces.Count;
@@ -1171,7 +1171,7 @@ namespace PrimMesher
}
}
- internal void AddValue2FaceVertexIndices(int num)
+ public void AddValue2FaceVertexIndices(int num)
{
int numFaces = this.faces.Count;
Face tmpFace;
@@ -1186,7 +1186,7 @@ namespace PrimMesher
}
}
- internal void AddValue2FaceNormalIndices(int num)
+ public void AddValue2FaceNormalIndices(int num)
{
if (this.calcVertexNormals)
{
@@ -1204,7 +1204,7 @@ namespace PrimMesher
}
}
- internal void DumpRaw(String path, String name, String title)
+ public void DumpRaw(String path, String name, String title)
{
if (path == null)
return;
@@ -1261,6 +1261,15 @@ namespace PrimMesher
public void Create(PathType pathType, int steps)
{
+ if (this.taperX > 0.999f)
+ this.taperX = 0.999f;
+ if (this.taperX < -0.999f)
+ this.taperX = -0.999f;
+ if (this.taperY > 0.999f)
+ this.taperY = 0.999f;
+ if (this.taperY < -0.999f)
+ this.taperY = -0.999f;
+
if (pathType == PathType.Linear || pathType == PathType.Flexible)
{
int step = 0;
@@ -1273,12 +1282,12 @@ namespace PrimMesher
float start = -0.5f;
float stepSize = length / (float)steps;
- float percentOfPathMultiplier = stepSize;
- float xOffset = 0.0f;
- float yOffset = 0.0f;
+ float percentOfPathMultiplier = stepSize * 0.999999f;
+ float xOffset = this.topShearX * this.pathCutBegin;
+ float yOffset = this.topShearY * this.pathCutBegin;
float zOffset = start;
- float xOffsetStepIncrement = this.topShearX / steps;
- float yOffsetStepIncrement = this.topShearY / steps;
+ float xOffsetStepIncrement = this.topShearX * length / steps;
+ float yOffsetStepIncrement = this.topShearY * length / steps;
float percentOfPath = this.pathCutBegin;
zOffset += percentOfPath;
@@ -1573,13 +1582,6 @@ namespace PrimMesher
this.hollow = 0.99f;
if (hollow < 0.0f)
this.hollow = 0.0f;
-
- //if (sphereMode)
- // this.hasProfileCut = this.profileEnd - this.profileStart < 0.4999f;
- //else
- // //this.hasProfileCut = (this.profileStart > 0.0f || this.profileEnd < 1.0f);
- // this.hasProfileCut = this.profileEnd - this.profileStart < 0.9999f;
- //this.hasHollow = (this.hollow > 0.001f);
}
///
@@ -1614,10 +1616,9 @@ namespace PrimMesher
steps = (int)(steps * 4.5 * length);
}
- if (sphereMode)
+ if (this.sphereMode)
this.hasProfileCut = this.profileEnd - this.profileStart < 0.4999f;
else
- //this.hasProfileCut = (this.profileStart > 0.0f || this.profileEnd < 1.0f);
this.hasProfileCut = this.profileEnd - this.profileStart < 0.9999f;
this.hasHollow = (this.hollow > 0.001f);
@@ -1630,6 +1631,22 @@ namespace PrimMesher
float hollow = this.hollow;
+ if (pathType == PathType.Circular)
+ {
+ needEndFaces = false;
+ if (this.pathCutBegin != 0.0f || this.pathCutEnd != 1.0f)
+ needEndFaces = true;
+ else if (this.taperX != 0.0f || this.taperY != 0.0f)
+ needEndFaces = true;
+ else if (this.skew != 0.0f)
+ needEndFaces = true;
+ else if (twistTotal != 0.0f)
+ needEndFaces = true;
+ else if (this.radius != 0.0f)
+ needEndFaces = true;
+ }
+ else needEndFaces = true;
+
// sanity checks
float initialProfileRot = 0.0f;
if (pathType == PathType.Circular)
@@ -1689,20 +1706,13 @@ namespace PrimMesher
this.numPrimFaces = profile.numPrimFaces;
- //profileOuterFaceNumber = profile.faceNumbers[0];
- //if (!needEndFaces)
- // profileOuterFaceNumber--;
- //profileOuterFaceNumber = needEndFaces ? 1 : 0;
-
-
- //if (hasHollow)
- //{
- // if (needEndFaces)
- // profileHollowFaceNumber = profile.faceNumbers[profile.numOuterVerts + 1];
- // else
- // profileHollowFaceNumber = profile.faceNumbers[profile.numOuterVerts] - 1;
- //}
-
+ int cut1FaceNumber = profile.bottomFaceNumber + 1;
+ int cut2FaceNumber = cut1FaceNumber + 1;
+ if (!needEndFaces)
+ {
+ cut1FaceNumber -= 2;
+ cut2FaceNumber -= 2;
+ }
profileOuterFaceNumber = profile.outerFaceNumber;
if (!needEndFaces)
@@ -1732,7 +1742,8 @@ namespace PrimMesher
Coord lastCutNormal1 = new Coord();
Coord lastCutNormal2 = new Coord();
- float lastV = 1.0f;
+ float thisV = 0.0f;
+ float lastV = 0.0f;
Path path = new Path();
path.twistBegin = twistBegin;
@@ -1754,23 +1765,6 @@ namespace PrimMesher
path.Create(pathType, steps);
-
- if (pathType == PathType.Circular)
- {
- needEndFaces = false;
- if (this.pathCutBegin != 0.0f || this.pathCutEnd != 1.0f)
- needEndFaces = true;
- else if (this.taperX != 0.0f || this.taperY != 0.0f)
- needEndFaces = true;
- else if (this.skew != 0.0f)
- needEndFaces = true;
- else if (twistTotal != 0.0f)
- needEndFaces = true;
- else if (this.radius != 0.0f)
- needEndFaces = true;
- }
- else needEndFaces = true;
-
for (int nodeIndex = 0; nodeIndex < path.pathNodes.Count; nodeIndex++)
{
PathNode node = path.pathNodes[nodeIndex];
@@ -1784,7 +1778,7 @@ namespace PrimMesher
{
newLayer.FlipNormals();
- // add the top faces to the viewerFaces list here
+ // add the bottom faces to the viewerFaces list
if (this.viewerMode)
{
Coord faceNormal = newLayer.faceNormal;
@@ -1811,6 +1805,13 @@ namespace PrimMesher
newViewerFace.uv2 = newLayer.faceUVs[face.v2];
newViewerFace.uv3 = newLayer.faceUVs[face.v3];
+ if (pathType == PathType.Linear)
+ {
+ newViewerFace.uv1.Flip();
+ newViewerFace.uv2.Flip();
+ newViewerFace.uv3.Flip();
+ }
+
this.viewerFaces.Add(newViewerFace);
}
}
@@ -1835,7 +1836,10 @@ namespace PrimMesher
// fill faces between layers
int numVerts = newLayer.coords.Count;
- Face newFace = new Face();
+ Face newFace1 = new Face();
+ Face newFace2 = new Face();
+
+ thisV = 1.0f - node.percentOfPath;
if (nodeIndex > 0)
{
@@ -1853,14 +1857,23 @@ namespace PrimMesher
int whichVert = i - startVert;
- newFace.v1 = i;
- newFace.v2 = i - numVerts;
- newFace.v3 = iNext - numVerts;
- this.faces.Add(newFace);
+ newFace1.v1 = i;
+ newFace1.v2 = i - numVerts;
+ newFace1.v3 = iNext;
+
+ newFace1.n1 = newFace1.v1;
+ newFace1.n2 = newFace1.v2;
+ newFace1.n3 = newFace1.v3;
+ this.faces.Add(newFace1);
- newFace.v2 = iNext - numVerts;
- newFace.v3 = iNext;
- this.faces.Add(newFace);
+ newFace2.v1 = iNext;
+ newFace2.v2 = i - numVerts;
+ newFace2.v3 = iNext - numVerts;
+
+ newFace2.n1 = newFace2.v1;
+ newFace2.n2 = newFace2.v2;
+ newFace2.n3 = newFace2.v3;
+ this.faces.Add(newFace2);
if (this.viewerMode)
{
@@ -1873,10 +1886,16 @@ namespace PrimMesher
ViewerFace newViewerFace1 = new ViewerFace(primFaceNum);
ViewerFace newViewerFace2 = new ViewerFace(primFaceNum);
- float u1 = newLayer.us[whichVert];
+ int uIndex = whichVert;
+ if (!hasHollow && sides > 4 && uIndex < newLayer.us.Count - 1)
+ {
+ uIndex++;
+ }
+
+ float u1 = newLayer.us[uIndex];
float u2 = 1.0f;
- if (whichVert < newLayer.us.Count - 1)
- u2 = newLayer.us[whichVert + 1];
+ if (uIndex < (int)newLayer.us.Count - 1)
+ u2 = newLayer.us[uIndex + 1];
if (whichVert == cut1Vert || whichVert == cut2Vert)
{
@@ -1894,13 +1913,22 @@ namespace PrimMesher
u1 -= (int)u1;
if (u2 < 0.1f)
u2 = 1.0f;
- //this.profileOuterFaceNumber = primFaceNum;
}
- else if (whichVert > profile.coords.Count - profile.numHollowVerts - 1)
+ }
+
+ if (this.sphereMode)
+ {
+ if (whichVert != cut1Vert && whichVert != cut2Vert)
{
- u1 *= 2.0f;
- u2 *= 2.0f;
- //this.profileHollowFaceNumber = primFaceNum;
+ u1 = u1 * 2.0f - 1.0f;
+ u2 = u2 * 2.0f - 1.0f;
+
+ if (whichVert >= newLayer.numOuterVerts)
+ {
+ u1 -= hollow;
+ u2 -= hollow;
+ }
+
}
}
@@ -1908,37 +1936,39 @@ namespace PrimMesher
newViewerFace1.uv2.U = u1;
newViewerFace1.uv3.U = u2;
- newViewerFace1.uv1.V = 1.0f - node.percentOfPath;
+ newViewerFace1.uv1.V = thisV;
newViewerFace1.uv2.V = lastV;
- newViewerFace1.uv3.V = lastV;
+ newViewerFace1.uv3.V = thisV;
- newViewerFace2.uv1.U = u1;
- newViewerFace2.uv2.U = u2;
+ newViewerFace2.uv1.U = u2;
+ newViewerFace2.uv2.U = u1;
newViewerFace2.uv3.U = u2;
- newViewerFace2.uv1.V = 1.0f - node.percentOfPath;
+ newViewerFace2.uv1.V = thisV;
newViewerFace2.uv2.V = lastV;
- newViewerFace2.uv3.V = 1.0f - node.percentOfPath;
+ newViewerFace2.uv3.V = lastV;
- newViewerFace1.v1 = this.coords[i];
- newViewerFace1.v2 = this.coords[i - numVerts];
- newViewerFace1.v3 = this.coords[iNext - numVerts];
+ newViewerFace1.v1 = this.coords[newFace1.v1];
+ newViewerFace1.v2 = this.coords[newFace1.v2];
+ newViewerFace1.v3 = this.coords[newFace1.v3];
- newViewerFace2.v1 = this.coords[i];
- newViewerFace2.v2 = this.coords[iNext - numVerts];
- newViewerFace2.v3 = this.coords[iNext];
+ newViewerFace2.v1 = this.coords[newFace2.v1];
+ newViewerFace2.v2 = this.coords[newFace2.v2];
+ newViewerFace2.v3 = this.coords[newFace2.v3];
- newViewerFace1.coordIndex1 = i;
- newViewerFace1.coordIndex2 = i - numVerts;
- newViewerFace1.coordIndex3 = iNext - numVerts;
+ newViewerFace1.coordIndex1 = newFace1.v1;
+ newViewerFace1.coordIndex2 = newFace1.v2;
+ newViewerFace1.coordIndex3 = newFace1.v3;
- newViewerFace2.coordIndex1 = i;
- newViewerFace2.coordIndex2 = iNext - numVerts;
- newViewerFace2.coordIndex3 = iNext;
+ newViewerFace2.coordIndex1 = newFace2.v1;
+ newViewerFace2.coordIndex2 = newFace2.v2;
+ newViewerFace2.coordIndex3 = newFace2.v3;
// profile cut faces
if (whichVert == cut1Vert)
{
+ newViewerFace1.primFaceNumber = cut1FaceNumber;
+ newViewerFace2.primFaceNumber = cut1FaceNumber;
newViewerFace1.n1 = newLayer.cutNormal1;
newViewerFace1.n2 = newViewerFace1.n3 = lastCutNormal1;
@@ -1947,10 +1977,14 @@ namespace PrimMesher
}
else if (whichVert == cut2Vert)
{
+ newViewerFace1.primFaceNumber = cut2FaceNumber;
+ newViewerFace2.primFaceNumber = cut2FaceNumber;
newViewerFace1.n1 = newLayer.cutNormal2;
- newViewerFace1.n2 = newViewerFace1.n3 = lastCutNormal2;
+ newViewerFace1.n2 = lastCutNormal2;
+ newViewerFace1.n3 = lastCutNormal2;
- newViewerFace2.n1 = newViewerFace2.n3 = newLayer.cutNormal2;
+ newViewerFace2.n1 = newLayer.cutNormal2;
+ newViewerFace2.n3 = newLayer.cutNormal2;
newViewerFace2.n2 = lastCutNormal2;
}
@@ -1963,13 +1997,13 @@ namespace PrimMesher
}
else
{
- newViewerFace1.n1 = this.normals[i];
- newViewerFace1.n2 = this.normals[i - numVerts];
- newViewerFace1.n3 = this.normals[iNext - numVerts];
+ newViewerFace1.n1 = this.normals[newFace1.n1];
+ newViewerFace1.n2 = this.normals[newFace1.n2];
+ newViewerFace1.n3 = this.normals[newFace1.n3];
- newViewerFace2.n1 = this.normals[i];
- newViewerFace2.n2 = this.normals[iNext - numVerts];
- newViewerFace2.n3 = this.normals[iNext];
+ newViewerFace2.n1 = this.normals[newFace2.n1];
+ newViewerFace2.n2 = this.normals[newFace2.n2];
+ newViewerFace2.n3 = this.normals[newFace2.n3];
}
}
@@ -1982,14 +2016,13 @@ namespace PrimMesher
lastCutNormal1 = newLayer.cutNormal1;
lastCutNormal2 = newLayer.cutNormal2;
- lastV = 1.0f - node.percentOfPath;
+ lastV = thisV;
if (needEndFaces && nodeIndex == path.pathNodes.Count - 1 && viewerMode)
{
// add the top faces to the viewerFaces list here
Coord faceNormal = newLayer.faceNormal;
- ViewerFace newViewerFace = new ViewerFace();
- newViewerFace.primFaceNumber = 0;
+ ViewerFace newViewerFace = new ViewerFace(0);
int numFaces = newLayer.faces.Count;
List faces = newLayer.faces;
@@ -2012,6 +2045,13 @@ namespace PrimMesher
newViewerFace.uv2 = newLayer.faceUVs[face.v2 - coordsLen];
newViewerFace.uv3 = newLayer.faceUVs[face.v3 - coordsLen];
+ if (pathType == PathType.Linear)
+ {
+ newViewerFace.uv1.Flip();
+ newViewerFace.uv2.Flip();
+ newViewerFace.uv3.Flip();
+ }
+
this.viewerFaces.Add(newViewerFace);
}
}
--
cgit v1.1