aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics
diff options
context:
space:
mode:
authorRobert Adams2012-07-12 11:29:45 -0700
committerRobert Adams2012-07-20 14:02:22 -0700
commitf9913b6ef7e7f18075e1e42ed5e347ce2a8b8ef5 (patch)
tree4fd98992014819aaede4a53243ab35324b0f1fea /OpenSim/Region/Physics
parentAs per opensim-dev mailing list discussion, extend llGetDetectedType() to ret... (diff)
downloadopensim-SC-f9913b6ef7e7f18075e1e42ed5e347ce2a8b8ef5.zip
opensim-SC-f9913b6ef7e7f18075e1e42ed5e347ce2a8b8ef5.tar.gz
opensim-SC-f9913b6ef7e7f18075e1e42ed5e347ce2a8b8ef5.tar.bz2
opensim-SC-f9913b6ef7e7f18075e1e42ed5e347ce2a8b8ef5.tar.xz
BulletSim: Add detailed and voluminous debug logging that is enabled
with an ini configuration parameter. Correct computation of relative offsets of children in a linkset. Remove a prim from any link relationship before deleting it. Minor code flow cleanups.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs52
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSScene.cs53
2 files changed, 65 insertions, 40 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 130f1ca..9b28a06 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -42,6 +42,8 @@ public sealed class BSPrim : PhysicsActor
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 private static readonly string LogHeader = "[BULLETS PRIM]"; 43 private static readonly string LogHeader = "[BULLETS PRIM]";
44 44
45 private void DebugLog(string mm, params Object[] xx) { if (_scene.shouldDebugLog) m_log.DebugFormat(mm, xx); }
46
45 private IMesh _mesh; 47 private IMesh _mesh;
46 private PrimitiveBaseShape _pbs; 48 private PrimitiveBaseShape _pbs;
47 private ShapeData.PhysicsShapeType _shapeType; 49 private ShapeData.PhysicsShapeType _shapeType;
@@ -86,8 +88,8 @@ public sealed class BSPrim : PhysicsActor
86 private bool _kinematic; 88 private bool _kinematic;
87 private float _buoyancy; 89 private float _buoyancy;
88 90
89 private List<BSPrim> _childrenPrims;
90 private BSPrim _parentPrim; 91 private BSPrim _parentPrim;
92 private List<BSPrim> _childrenPrims;
91 93
92 private int _subscribedEventsMs = 0; 94 private int _subscribedEventsMs = 0;
93 private int _nextCollisionOkTime = 0; 95 private int _nextCollisionOkTime = 0;
@@ -148,6 +150,15 @@ public sealed class BSPrim : PhysicsActor
148 // Undo any vehicle properties 150 // Undo any vehicle properties
149 _vehicle.ProcessTypeChange(Vehicle.TYPE_NONE); 151 _vehicle.ProcessTypeChange(Vehicle.TYPE_NONE);
150 _scene.RemoveVehiclePrim(this); // just to make sure 152 _scene.RemoveVehiclePrim(this); // just to make sure
153
154 // undo any dependance with/on other objects
155 if (_parentPrim != null)
156 {
157 // If I'm someone's child, tell them to forget about me.
158 _parentPrim.RemoveChildFromLinkset(this);
159 _parentPrim = null;
160 }
161
151 _scene.TaintedObject(delegate() 162 _scene.TaintedObject(delegate()
152 { 163 {
153 // everything in the C# world will get garbage collected. Tell the C++ world to free stuff. 164 // everything in the C# world will get garbage collected. Tell the C++ world to free stuff.
@@ -202,7 +213,7 @@ public sealed class BSPrim : PhysicsActor
202 // link me to the specified parent 213 // link me to the specified parent
203 public override void link(PhysicsActor obj) { 214 public override void link(PhysicsActor obj) {
204 BSPrim parent = obj as BSPrim; 215 BSPrim parent = obj as BSPrim;
205 // m_log.DebugFormat("{0}: link {1}/{2} to {3}", LogHeader, _avName, _localID, obj.LocalID); 216 DebugLog("{0}: link {1}/{2} to {3}", LogHeader, _avName, _localID, obj.LocalID);
206 // TODO: decide if this parent checking needs to happen at taint time 217 // TODO: decide if this parent checking needs to happen at taint time
207 if (_parentPrim == null) 218 if (_parentPrim == null)
208 { 219 {
@@ -225,7 +236,7 @@ public sealed class BSPrim : PhysicsActor
225 else 236 else
226 { 237 {
227 // asking to reparent a prim should not happen 238 // asking to reparent a prim should not happen
228 m_log.ErrorFormat("{0}: Reparenting a prim. ", LogHeader); 239 m_log.ErrorFormat("{0}: link(): Reparenting a prim. ", LogHeader);
229 } 240 }
230 } 241 }
231 } 242 }
@@ -236,7 +247,8 @@ public sealed class BSPrim : PhysicsActor
236 public override void delink() { 247 public override void delink() {
237 // TODO: decide if this parent checking needs to happen at taint time 248 // TODO: decide if this parent checking needs to happen at taint time
238 // Race condition here: if link() and delink() in same simulation tick, the delink will not happen 249 // Race condition here: if link() and delink() in same simulation tick, the delink will not happen
239 // m_log.DebugFormat("{0}: delink {1}/{2}", LogHeader, _avName, _localID); 250 DebugLog("{0}: delink {1}/{2}. Parent={3}", LogHeader, _avName, _localID,
251 (_parentPrim==null ? "NULL" : _parentPrim._avName+"/"+_parentPrim.LocalID.ToString()));
240 if (_parentPrim != null) 252 if (_parentPrim != null)
241 { 253 {
242 _parentPrim.RemoveChildFromLinkset(this); 254 _parentPrim.RemoveChildFromLinkset(this);
@@ -252,8 +264,9 @@ public sealed class BSPrim : PhysicsActor
252 { 264 {
253 if (!_childrenPrims.Contains(child)) 265 if (!_childrenPrims.Contains(child))
254 { 266 {
267 DebugLog("{0}: AddChildToLinkset: adding child {1} to {2}", LogHeader, child.LocalID, this.LocalID);
255 _childrenPrims.Add(child); 268 _childrenPrims.Add(child);
256 child.ParentPrim = this; // the child has gained a parent 269 child._parentPrim = this; // the child has gained a parent
257 RecreateGeomAndObject(); // rebuild my shape with the new child added 270 RecreateGeomAndObject(); // rebuild my shape with the new child added
258 } 271 }
259 }); 272 });
@@ -269,9 +282,13 @@ public sealed class BSPrim : PhysicsActor
269 { 282 {
270 if (_childrenPrims.Contains(child)) 283 if (_childrenPrims.Contains(child))
271 { 284 {
272 BulletSimAPI.RemoveConstraint(_scene.WorldID, child.LocalID, this.LocalID); 285 DebugLog("{0}: RemoveChildFromLinkset: Removing constraint to {1}", LogHeader, child.LocalID);
286 if (!BulletSimAPI.RemoveConstraintByID(_scene.WorldID, child.LocalID))
287 {
288 m_log.ErrorFormat("{0}: RemoveChildFromLinkset: Failed remove constraint for {1}", LogHeader, child.LocalID);
289 }
273 _childrenPrims.Remove(child); 290 _childrenPrims.Remove(child);
274 child.ParentPrim = null; // the child has lost its parent 291 child._parentPrim = null; // the child has lost its parent
275 RecreateGeomAndObject(); // rebuild my shape with the child removed 292 RecreateGeomAndObject(); // rebuild my shape with the child removed
276 } 293 }
277 else 294 else
@@ -282,11 +299,6 @@ public sealed class BSPrim : PhysicsActor
282 return; 299 return;
283 } 300 }
284 301
285 public BSPrim ParentPrim
286 {
287 set { _parentPrim = value; }
288 }
289
290 // return true if we are the root of a linkset (there are children to manage) 302 // return true if we are the root of a linkset (there are children to manage)
291 public bool IsRootOfLinkset 303 public bool IsRootOfLinkset
292 { 304 {
@@ -981,7 +993,6 @@ public sealed class BSPrim : PhysicsActor
981 int vi = 0; 993 int vi = 0;
982 foreach (OMV.Vector3 vv in vertices) 994 foreach (OMV.Vector3 vv in vertices)
983 { 995 {
984 // m_log.DebugFormat("{0}: {1}: <{2:0.00}, {3:0.00}, {4:0.00}>", LogHeader, vi / 3, vv.X, vv.Y, vv.Z);
985 verticesAsFloats[vi++] = vv.X; 996 verticesAsFloats[vi++] = vv.X;
986 verticesAsFloats[vi++] = vv.Y; 997 verticesAsFloats[vi++] = vv.Y;
987 verticesAsFloats[vi++] = vv.Z; 998 verticesAsFloats[vi++] = vv.Z;
@@ -1129,7 +1140,6 @@ public sealed class BSPrim : PhysicsActor
1129 if (IsRootOfLinkset) 1140 if (IsRootOfLinkset)
1130 { 1141 {
1131 // Create a linkset around this object 1142 // Create a linkset around this object
1132 // CreateLinksetWithCompoundHull();
1133 CreateLinksetWithConstraints(); 1143 CreateLinksetWithConstraints();
1134 } 1144 }
1135 else 1145 else
@@ -1191,33 +1201,33 @@ public sealed class BSPrim : PhysicsActor
1191 // TODO: make this more effeicient: a large linkset gets rebuilt over and over and prims are added 1201 // TODO: make this more effeicient: a large linkset gets rebuilt over and over and prims are added
1192 void CreateLinksetWithConstraints() 1202 void CreateLinksetWithConstraints()
1193 { 1203 {
1194 // m_log.DebugFormat("{0}: CreateLinkset. Root prim={1}, prims={2}", LogHeader, LocalID, _childrenPrims.Count+1); 1204 DebugLog("{0}: CreateLinkset. Root prim={1}, prims={2}", LogHeader, LocalID, _childrenPrims.Count+1);
1195 1205
1196 // remove any constraints that might be in place 1206 // remove any constraints that might be in place
1197 foreach (BSPrim prim in _childrenPrims) 1207 foreach (BSPrim prim in _childrenPrims)
1198 { 1208 {
1199 // m_log.DebugFormat("{0}: CreateLinkset: RemoveConstraint between root prim {1} and child prim {2}", LogHeader, LocalID, prim.LocalID); 1209 DebugLog("{0}: CreateLinkset: RemoveConstraint between root prim {1} and child prim {2}", LogHeader, LocalID, prim.LocalID);
1200 BulletSimAPI.RemoveConstraint(_scene.WorldID, LocalID, prim.LocalID); 1210 BulletSimAPI.RemoveConstraint(_scene.WorldID, LocalID, prim.LocalID);
1201 } 1211 }
1202 // create constraints between the root prim and each of the children 1212 // create constraints between the root prim and each of the children
1203 foreach (BSPrim prim in _childrenPrims) 1213 foreach (BSPrim prim in _childrenPrims)
1204 { 1214 {
1205 // m_log.DebugFormat("{0}: CreateLinkset: AddConstraint between root prim {1} and child prim {2}", LogHeader, LocalID, prim.LocalID);
1206
1207 // Zero motion for children so they don't interpolate 1215 // Zero motion for children so they don't interpolate
1208 prim.ZeroMotion(); 1216 prim.ZeroMotion();
1209 1217
1210 // relative position normalized to the root prim 1218 // relative position normalized to the root prim
1211 OMV.Vector3 childRelativePosition = (prim._position - this._position) * OMV.Quaternion.Inverse(this._orientation); 1219 OMV.Quaternion invThisOrientation = OMV.Quaternion.Inverse(this._orientation);
1220 OMV.Vector3 childRelativePosition = (prim._position - this._position) * invThisOrientation;
1212 1221
1213 // relative rotation of the child to the parent 1222 // relative rotation of the child to the parent
1214 OMV.Quaternion relativeRotation = OMV.Quaternion.Inverse(prim._orientation) * this._orientation; 1223 OMV.Quaternion childRelativeRotation = invThisOrientation * prim._orientation;
1215 1224
1216 // this is a constraint that allows no freedom of movement between the two objects 1225 // this is a constraint that allows no freedom of movement between the two objects
1217 // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 1226 // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818
1227 DebugLog("{0}: CreateLinkset: Adding a constraint between root prim {1} and child prim {2}", LogHeader, LocalID, prim.LocalID);
1218 BulletSimAPI.AddConstraint(_scene.WorldID, LocalID, prim.LocalID, 1228 BulletSimAPI.AddConstraint(_scene.WorldID, LocalID, prim.LocalID,
1219 childRelativePosition, 1229 childRelativePosition,
1220 relativeRotation, 1230 childRelativeRotation,
1221 OMV.Vector3.Zero, 1231 OMV.Vector3.Zero,
1222 OMV.Quaternion.Identity, 1232 OMV.Quaternion.Identity,
1223 OMV.Vector3.Zero, OMV.Vector3.Zero, 1233 OMV.Vector3.Zero, OMV.Vector3.Zero,
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index 417cb5f..eb1d798 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -72,6 +72,8 @@ public class BSScene : PhysicsScene, IPhysicsParameters
72 private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 72 private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
73 private static readonly string LogHeader = "[BULLETS SCENE]"; 73 private static readonly string LogHeader = "[BULLETS SCENE]";
74 74
75 private void DebugLog(string mm, params Object[] xx) { if (shouldDebugLog) m_log.DebugFormat(mm, xx); }
76
75 public string BulletSimVersion = "?"; 77 public string BulletSimVersion = "?";
76 78
77 private Dictionary<uint, BSCharacter> m_avatars = new Dictionary<uint, BSCharacter>(); 79 private Dictionary<uint, BSCharacter> m_avatars = new Dictionary<uint, BSCharacter>();
@@ -147,6 +149,8 @@ public class BSScene : PhysicsScene, IPhysicsParameters
147 ConfigurationParameters[] m_params; 149 ConfigurationParameters[] m_params;
148 GCHandle m_paramsHandle; 150 GCHandle m_paramsHandle;
149 151
152 public bool shouldDebugLog { get; private set; }
153
150 private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle; 154 private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle;
151 155
152 public BSScene(string identifier) 156 public BSScene(string identifier)
@@ -209,6 +213,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
209 m_meshLOD = 8f; 213 m_meshLOD = 8f;
210 m_sculptLOD = 32f; 214 m_sculptLOD = 32f;
211 215
216 shouldDebugLog = false;
212 m_detailedStatsStep = 0; // disabled 217 m_detailedStatsStep = 0; // disabled
213 218
214 m_maxSubSteps = 10; 219 m_maxSubSteps = 10;
@@ -261,7 +266,9 @@ public class BSScene : PhysicsScene, IPhysicsParameters
261 _meshSculptedPrim = pConfig.GetBoolean("MeshSculptedPrim", _meshSculptedPrim); 266 _meshSculptedPrim = pConfig.GetBoolean("MeshSculptedPrim", _meshSculptedPrim);
262 _forceSimplePrimMeshing = pConfig.GetBoolean("ForceSimplePrimMeshing", _forceSimplePrimMeshing); 267 _forceSimplePrimMeshing = pConfig.GetBoolean("ForceSimplePrimMeshing", _forceSimplePrimMeshing);
263 268
269 shouldDebugLog = pConfig.GetBoolean("ShouldDebugLog", shouldDebugLog);
264 m_detailedStatsStep = pConfig.GetInt("DetailedStatsStep", m_detailedStatsStep); 270 m_detailedStatsStep = pConfig.GetInt("DetailedStatsStep", m_detailedStatsStep);
271
265 m_meshLOD = pConfig.GetFloat("MeshLevelOfDetail", m_meshLOD); 272 m_meshLOD = pConfig.GetFloat("MeshLevelOfDetail", m_meshLOD);
266 m_sculptLOD = pConfig.GetFloat("SculptLevelOfDetail", m_sculptLOD); 273 m_sculptLOD = pConfig.GetFloat("SculptLevelOfDetail", m_sculptLOD);
267 274
@@ -347,34 +354,42 @@ public class BSScene : PhysicsScene, IPhysicsParameters
347 public override void RemoveAvatar(PhysicsActor actor) 354 public override void RemoveAvatar(PhysicsActor actor)
348 { 355 {
349 // m_log.DebugFormat("{0}: RemoveAvatar", LogHeader); 356 // m_log.DebugFormat("{0}: RemoveAvatar", LogHeader);
350 if (actor is BSCharacter) 357 BSCharacter bsactor = actor as BSCharacter;
351 { 358 if (bsactor != null)
352 ((BSCharacter)actor).Destroy();
353 }
354 try
355 { 359 {
356 lock (m_avatars) m_avatars.Remove(actor.LocalID); 360 try
357 } 361 {
358 catch (Exception e) 362 lock (m_avatars) m_avatars.Remove(actor.LocalID);
359 { 363 }
360 m_log.WarnFormat("{0}: Attempt to remove avatar that is not in physics scene: {1}", LogHeader, e); 364 catch (Exception e)
365 {
366 m_log.WarnFormat("{0}: Attempt to remove avatar that is not in physics scene: {1}", LogHeader, e);
367 }
368 bsactor.Destroy();
369 // bsactor.dispose();
361 } 370 }
362 } 371 }
363 372
364 public override void RemovePrim(PhysicsActor prim) 373 public override void RemovePrim(PhysicsActor prim)
365 { 374 {
366 // m_log.DebugFormat("{0}: RemovePrim", LogHeader); 375 BSPrim bsprim = prim as BSPrim;
367 if (prim is BSPrim) 376 if (bsprim != null)
368 {
369 ((BSPrim)prim).Destroy();
370 }
371 try
372 { 377 {
373 lock (m_prims) m_prims.Remove(prim.LocalID); 378 m_log.DebugFormat("{0}: RemovePrim. id={1}/{2}", LogHeader, bsprim.Name, bsprim.LocalID);
379 try
380 {
381 lock (m_prims) m_prims.Remove(bsprim.LocalID);
382 }
383 catch (Exception e)
384 {
385 m_log.ErrorFormat("{0}: Attempt to remove prim that is not in physics scene: {1}", LogHeader, e);
386 }
387 bsprim.Destroy();
388 // bsprim.dispose();
374 } 389 }
375 catch (Exception e) 390 else
376 { 391 {
377 m_log.WarnFormat("{0}: Attempt to remove prim that is not in physics scene: {1}", LogHeader, e); 392 m_log.ErrorFormat("{0}: Attempt to remove prim that is not a BSPrim type.", LogHeader);
378 } 393 }
379 } 394 }
380 395