aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs102
1 files changed, 88 insertions, 14 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index 662b19d..4a31c7d 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -48,6 +48,7 @@ public sealed class BSShapeCollection : IDisposable
48 public IntPtr ptr; 48 public IntPtr ptr;
49 public int referenceCount; 49 public int referenceCount;
50 public DateTime lastReferenced; 50 public DateTime lastReferenced;
51 public UInt64 shapeKey;
51 } 52 }
52 53
53 // Description of a hull. 54 // Description of a hull.
@@ -57,6 +58,7 @@ public sealed class BSShapeCollection : IDisposable
57 public IntPtr ptr; 58 public IntPtr ptr;
58 public int referenceCount; 59 public int referenceCount;
59 public DateTime lastReferenced; 60 public DateTime lastReferenced;
61 public UInt64 shapeKey;
60 } 62 }
61 63
62 // The sharable set of meshes and hulls. Indexed by their shape hash. 64 // The sharable set of meshes and hulls. Indexed by their shape hash.
@@ -116,7 +118,7 @@ public sealed class BSShapeCollection : IDisposable
116 return ret; 118 return ret;
117 } 119 }
118 120
119 // Track another user of a body 121 // Track another user of a body.
120 // We presume the caller has allocated the body. 122 // We presume the caller has allocated the body.
121 // Bodies only have one user so the body is just put into the world if not already there. 123 // Bodies only have one user so the body is just put into the world if not already there.
122 public void ReferenceBody(BulletBody body, bool inTaintTime) 124 public void ReferenceBody(BulletBody body, bool inTaintTime)
@@ -146,13 +148,16 @@ public sealed class BSShapeCollection : IDisposable
146 { 148 {
147 PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceBody", delegate() 149 PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceBody", delegate()
148 { 150 {
149 DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody. ptr={1}, inTaintTime={2}", 151 DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody,body={1},inTaintTime={2}",
150 body.ID, body.ptr.ToString("X"), inTaintTime); 152 body.ID, body, inTaintTime);
151 // If the caller needs to know the old body is going away, pass the event up. 153 // If the caller needs to know the old body is going away, pass the event up.
152 if (bodyCallback != null) bodyCallback(body); 154 if (bodyCallback != null) bodyCallback(body);
153 155
154 // It may have already been removed from the world in which case the next is a NOOP. 156 if (BulletSimAPI.IsInWorld2(body.ptr))
155 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr); 157 {
158 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, body.ptr);
159 DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body);
160 }
156 161
157 // Zero any reference to the shape so it is not freed when the body is deleted. 162 // Zero any reference to the shape so it is not freed when the body is deleted.
158 BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero); 163 BulletSimAPI.SetCollisionShape2(PhysicsScene.World.ptr, body.ptr, IntPtr.Zero);
@@ -185,6 +190,7 @@ public sealed class BSShapeCollection : IDisposable
185 { 190 {
186 // This is a new reference to a mesh 191 // This is a new reference to a mesh
187 meshDesc.ptr = shape.ptr; 192 meshDesc.ptr = shape.ptr;
193 meshDesc.shapeKey = shape.shapeKey;
188 // We keep a reference to the underlying IMesh data so a hull can be built 194 // We keep a reference to the underlying IMesh data so a hull can be built
189 meshDesc.referenceCount = 1; 195 meshDesc.referenceCount = 1;
190 DetailLog("{0},BSShapeCollection.ReferenceShape,newMesh,key={1},cnt={2}", 196 DetailLog("{0},BSShapeCollection.ReferenceShape,newMesh,key={1},cnt={2}",
@@ -207,6 +213,7 @@ public sealed class BSShapeCollection : IDisposable
207 { 213 {
208 // This is a new reference to a hull 214 // This is a new reference to a hull
209 hullDesc.ptr = shape.ptr; 215 hullDesc.ptr = shape.ptr;
216 hullDesc.shapeKey = shape.shapeKey;
210 hullDesc.referenceCount = 1; 217 hullDesc.referenceCount = 1;
211 DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}", 218 DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}",
212 BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount); 219 BSScene.DetailLogZero, shape.shapeKey.ToString("X"), hullDesc.referenceCount);
@@ -306,7 +313,7 @@ public sealed class BSShapeCollection : IDisposable
306 313
307 // Remove a reference to a compound shape. 314 // Remove a reference to a compound shape.
308 // Taking a compound shape apart is a little tricky because if you just delete the 315 // Taking a compound shape apart is a little tricky because if you just delete the
309 // physical object, it will free all the underlying children. We can't do that because 316 // physical shape, it will free all the underlying children. We can't do that because
310 // they could be shared. So, this removes each of the children from the compound and 317 // they could be shared. So, this removes each of the children from the compound and
311 // dereferences them separately before destroying the compound collision object itself. 318 // dereferences them separately before destroying the compound collision object itself.
312 // Called at taint-time. 319 // Called at taint-time.
@@ -335,22 +342,53 @@ public sealed class BSShapeCollection : IDisposable
335 342
336 // Sometimes we have a pointer to a collision shape but don't know what type it is. 343 // Sometimes we have a pointer to a collision shape but don't know what type it is.
337 // Figure out type and call the correct dereference routine. 344 // Figure out type and call the correct dereference routine.
338 // This is coming from a compound shape that we created so we know it is either native or mesh.
339 // Called at taint-time. 345 // Called at taint-time.
340 private void DereferenceAnonCollisionShape(IntPtr cShape) 346 private void DereferenceAnonCollisionShape(IntPtr cShape)
341 { 347 {
342 BulletShape shapeInfo = new BulletShape(cShape, ShapeData.PhysicsShapeType.SHAPE_MESH); 348 MeshDesc meshDesc;
343 if (BulletSimAPI.IsCompound2(cShape)) 349 HullDesc hullDesc;
344 shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_COMPOUND;
345 350
346 if (BulletSimAPI.IsNativeShape2(cShape)) 351 BulletShape shapeInfo = new BulletShape(cShape);
352 if (TryGetMeshByPtr(cShape, out meshDesc))
353 {
354 shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_MESH;
355 shapeInfo.shapeKey = meshDesc.shapeKey;
356 }
357 else
347 { 358 {
348 shapeInfo.isNativeShape = true; 359 if (TryGetHullByPtr(cShape, out hullDesc))
349 shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter) 360 {
361 shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_HULL;
362 shapeInfo.shapeKey = hullDesc.shapeKey;
363 }
364 else
365 {
366 if (BulletSimAPI.IsCompound2(cShape))
367 {
368 shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_COMPOUND;
369 }
370 else
371 {
372 if (BulletSimAPI.IsNativeShape2(cShape))
373 {
374 shapeInfo.isNativeShape = true;
375 shapeInfo.type = ShapeData.PhysicsShapeType.SHAPE_BOX; // (technically, type doesn't matter)
376 }
377 }
378 }
350 } 379 }
380
351 DetailLog("{0},BSShapeCollection.DereferenceAnonCollisionShape,shape={1}", BSScene.DetailLogZero, shapeInfo); 381 DetailLog("{0},BSShapeCollection.DereferenceAnonCollisionShape,shape={1}", BSScene.DetailLogZero, shapeInfo);
352 382
353 DereferenceShape(shapeInfo, true, null); 383 if (shapeInfo.type != ShapeData.PhysicsShapeType.SHAPE_UNKNOWN)
384 {
385 DereferenceShape(shapeInfo, true, null);
386 }
387 else
388 {
389 PhysicsScene.Logger.ErrorFormat("{0} Could not decypher shape type. Region={1}, addr={2}",
390 LogHeader, PhysicsScene.RegionName, cShape.ToString("X"));
391 }
354 } 392 }
355 393
356 // Create the geometry information in Bullet for later use. 394 // Create the geometry information in Bullet for later use.
@@ -913,6 +951,42 @@ public sealed class BSShapeCollection : IDisposable
913 return ret; 951 return ret;
914 } 952 }
915 953
954 private bool TryGetMeshByPtr(IntPtr addr, out MeshDesc outDesc)
955 {
956 bool ret = false;
957 MeshDesc foundDesc = new MeshDesc();
958 foreach (MeshDesc md in Meshes.Values)
959 {
960 if (md.ptr == addr)
961 {
962 foundDesc = md;
963 ret = true;
964 break;
965 }
966
967 }
968 outDesc = foundDesc;
969 return ret;
970 }
971
972 private bool TryGetHullByPtr(IntPtr addr, out HullDesc outDesc)
973 {
974 bool ret = false;
975 HullDesc foundDesc = new HullDesc();
976 foreach (HullDesc hd in Hulls.Values)
977 {
978 if (hd.ptr == addr)
979 {
980 foundDesc = hd;
981 ret = true;
982 break;
983 }
984
985 }
986 outDesc = foundDesc;
987 return ret;
988 }
989
916 private void DetailLog(string msg, params Object[] args) 990 private void DetailLog(string msg, params Object[] args)
917 { 991 {
918 if (PhysicsScene.PhysicsLogging.Enabled) 992 if (PhysicsScene.PhysicsLogging.Enabled)