aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs125
1 files changed, 59 insertions, 66 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
index 473ef10..37bccbc 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
@@ -116,8 +116,7 @@ public sealed class BSShapeCollection : IDisposable
116 // rebuild the body around it. 116 // rebuild the body around it.
117 // Updates prim.BSBody with information/pointers to requested body 117 // Updates prim.BSBody with information/pointers to requested body
118 // Returns 'true' if BSBody was changed. 118 // Returns 'true' if BSBody was changed.
119 bool newBody = CreateBody((newGeom || forceRebuild), prim, PhysicsScene.World, 119 bool newBody = CreateBody((newGeom || forceRebuild), prim, PhysicsScene.World, bodyCallback);
120 prim.PhysShape, bodyCallback);
121 ret = newGeom || newBody; 120 ret = newGeom || newBody;
122 } 121 }
123 DetailLog("{0},BSShapeCollection.GetBodyAndShape,taintExit,force={1},ret={2},body={3},shape={4}", 122 DetailLog("{0},BSShapeCollection.GetBodyAndShape,taintExit,force={1},ret={2},body={3},shape={4}",
@@ -134,48 +133,44 @@ public sealed class BSShapeCollection : IDisposable
134 // Track another user of a body. 133 // Track another user of a body.
135 // We presume the caller has allocated the body. 134 // We presume the caller has allocated the body.
136 // Bodies only have one user so the body is just put into the world if not already there. 135 // Bodies only have one user so the body is just put into the world if not already there.
137 public void ReferenceBody(BulletBody body, bool inTaintTime) 136 private void ReferenceBody(BulletBody body)
138 { 137 {
139 lock (m_collectionActivityLock) 138 lock (m_collectionActivityLock)
140 { 139 {
141 if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body); 140 if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,newBody,body={1}", body.ID, body);
142 PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.ReferenceBody", delegate() 141 if (!PhysicsScene.PE.IsInWorld(PhysicsScene.World, body))
143 { 142 {
144 if (!PhysicsScene.PE.IsInWorld(PhysicsScene.World, body)) 143 PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, body);
145 { 144 if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body);
146 PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, body); 145 }
147 if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceBody,addedToWorld,ref={1}", body.ID, body);
148 }
149 });
150 } 146 }
151 } 147 }
152 148
153 // Release the usage of a body. 149 // Release the usage of a body.
154 // Called when releasing use of a BSBody. BSShape is handled separately. 150 // Called when releasing use of a BSBody. BSShape is handled separately.
155 public void DereferenceBody(BulletBody body, bool inTaintTime, BodyDestructionCallback bodyCallback ) 151 // Called in taint time.
152 public void DereferenceBody(BulletBody body, BodyDestructionCallback bodyCallback )
156 { 153 {
157 if (!body.HasPhysicalBody) 154 if (!body.HasPhysicalBody)
158 return; 155 return;
159 156
157 PhysicsScene.AssertInTaintTime("BSShapeCollection.DereferenceBody");
158
160 lock (m_collectionActivityLock) 159 lock (m_collectionActivityLock)
161 { 160 {
162 PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceBody", delegate() 161 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody,body={1}", body.ID, body);
163 { 162 // If the caller needs to know the old body is going away, pass the event up.
164 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,DestroyingBody,body={1},inTaintTime={2}", 163 if (bodyCallback != null) bodyCallback(body);
165 body.ID, body, inTaintTime);
166 // If the caller needs to know the old body is going away, pass the event up.
167 if (bodyCallback != null) bodyCallback(body);
168 164
169 if (PhysicsScene.PE.IsInWorld(PhysicsScene.World, body)) 165 if (PhysicsScene.PE.IsInWorld(PhysicsScene.World, body))
170 { 166 {
171 PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, body); 167 PhysicsScene.PE.RemoveObjectFromWorld(PhysicsScene.World, body);
172 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body); 168 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceBody,removingFromWorld. Body={1}", body.ID, body);
173 } 169 }
174 170
175 // Zero any reference to the shape so it is not freed when the body is deleted. 171 // Zero any reference to the shape so it is not freed when the body is deleted.
176 PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, null); 172 PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, null);
177 PhysicsScene.PE.DestroyObject(PhysicsScene.World, body); 173 PhysicsScene.PE.DestroyObject(PhysicsScene.World, body);
178 });
179 } 174 }
180 } 175 }
181 176
@@ -246,44 +241,43 @@ public sealed class BSShapeCollection : IDisposable
246 } 241 }
247 242
248 // Release the usage of a shape. 243 // Release the usage of a shape.
249 public void DereferenceShape(BulletShape shape, bool inTaintTime, ShapeDestructionCallback shapeCallback) 244 public void DereferenceShape(BulletShape shape, ShapeDestructionCallback shapeCallback)
250 { 245 {
251 if (!shape.HasPhysicalShape) 246 if (!shape.HasPhysicalShape)
252 return; 247 return;
253 248
254 PhysicsScene.TaintedObject(inTaintTime, "BSShapeCollection.DereferenceShape", delegate() 249 PhysicsScene.AssertInTaintTime("BSShapeCollection.DereferenceShape");
250
251 if (shape.HasPhysicalShape)
255 { 252 {
256 if (shape.HasPhysicalShape) 253 if (shape.isNativeShape)
257 { 254 {
258 if (shape.isNativeShape) 255 // Native shapes are not tracked and are released immediately
259 { 256 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1}",
260 // Native shapes are not tracked and are released immediately 257 BSScene.DetailLogZero, shape.AddrString);
261 if (DDetail) DetailLog("{0},BSShapeCollection.DereferenceShape,deleteNativeShape,ptr={1},taintTime={2}", 258 if (shapeCallback != null) shapeCallback(shape);
262 BSScene.DetailLogZero, shape.AddrString, inTaintTime); 259 PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape);
263 if (shapeCallback != null) shapeCallback(shape); 260 }
264 PhysicsScene.PE.DeleteCollisionShape(PhysicsScene.World, shape); 261 else
265 } 262 {
266 else 263 switch (shape.type)
267 { 264 {
268 switch (shape.type) 265 case BSPhysicsShapeType.SHAPE_HULL:
269 { 266 DereferenceHull(shape, shapeCallback);
270 case BSPhysicsShapeType.SHAPE_HULL: 267 break;
271 DereferenceHull(shape, shapeCallback); 268 case BSPhysicsShapeType.SHAPE_MESH:
272 break; 269 DereferenceMesh(shape, shapeCallback);
273 case BSPhysicsShapeType.SHAPE_MESH: 270 break;
274 DereferenceMesh(shape, shapeCallback); 271 case BSPhysicsShapeType.SHAPE_COMPOUND:
275 break; 272 DereferenceCompound(shape, shapeCallback);
276 case BSPhysicsShapeType.SHAPE_COMPOUND: 273 break;
277 DereferenceCompound(shape, shapeCallback); 274 case BSPhysicsShapeType.SHAPE_UNKNOWN:
278 break; 275 break;
279 case BSPhysicsShapeType.SHAPE_UNKNOWN: 276 default:
280 break; 277 break;
281 default:
282 break;
283 }
284 } 278 }
285 } 279 }
286 }); 280 }
287 } 281 }
288 282
289 // Count down the reference count for a mesh shape 283 // Count down the reference count for a mesh shape
@@ -394,7 +388,7 @@ public sealed class BSShapeCollection : IDisposable
394 388
395 if (shapeInfo.type != BSPhysicsShapeType.SHAPE_UNKNOWN) 389 if (shapeInfo.type != BSPhysicsShapeType.SHAPE_UNKNOWN)
396 { 390 {
397 DereferenceShape(shapeInfo, true, null); 391 DereferenceShape(shapeInfo, null);
398 } 392 }
399 else 393 else
400 { 394 {
@@ -544,7 +538,7 @@ public sealed class BSShapeCollection : IDisposable
544 ShapeDestructionCallback shapeCallback) 538 ShapeDestructionCallback shapeCallback)
545 { 539 {
546 // release any previous shape 540 // release any previous shape
547 DereferenceShape(prim.PhysShape, true, shapeCallback); 541 DereferenceShape(prim.PhysShape, shapeCallback);
548 542
549 BulletShape newShape = BuildPhysicalNativeShape(prim, shapeType, shapeKey); 543 BulletShape newShape = BuildPhysicalNativeShape(prim, shapeType, shapeKey);
550 544
@@ -612,7 +606,7 @@ public sealed class BSShapeCollection : IDisposable
612 prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newMeshKey.ToString("X")); 606 prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newMeshKey.ToString("X"));
613 607
614 // Since we're recreating new, get rid of the reference to the previous shape 608 // Since we're recreating new, get rid of the reference to the previous shape
615 DereferenceShape(prim.PhysShape, true, shapeCallback); 609 DereferenceShape(prim.PhysShape, shapeCallback);
616 610
617 newShape = CreatePhysicalMesh(prim.PhysObjectName, newMeshKey, prim.BaseShape, prim.Size, lod); 611 newShape = CreatePhysicalMesh(prim.PhysObjectName, newMeshKey, prim.BaseShape, prim.Size, lod);
618 // Take evasive action if the mesh was not constructed. 612 // Take evasive action if the mesh was not constructed.
@@ -683,7 +677,7 @@ public sealed class BSShapeCollection : IDisposable
683 prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newHullKey.ToString("X")); 677 prim.LocalID, prim.PhysShape.shapeKey.ToString("X"), newHullKey.ToString("X"));
684 678
685 // Remove usage of the previous shape. 679 // Remove usage of the previous shape.
686 DereferenceShape(prim.PhysShape, true, shapeCallback); 680 DereferenceShape(prim.PhysShape, shapeCallback);
687 681
688 newShape = CreatePhysicalHull(prim.PhysObjectName, newHullKey, prim.BaseShape, prim.Size, lod); 682 newShape = CreatePhysicalHull(prim.PhysObjectName, newHullKey, prim.BaseShape, prim.Size, lod);
689 newShape = VerifyMeshCreated(newShape, prim); 683 newShape = VerifyMeshCreated(newShape, prim);
@@ -818,7 +812,6 @@ public sealed class BSShapeCollection : IDisposable
818 // Don't need to do this as the shape is freed when the new root shape is created below. 812 // Don't need to do this as the shape is freed when the new root shape is created below.
819 // DereferenceShape(prim.PhysShape, true, shapeCallback); 813 // DereferenceShape(prim.PhysShape, true, shapeCallback);
820 814
821
822 BulletShape cShape = PhysicsScene.PE.CreateCompoundShape(PhysicsScene.World, false); 815 BulletShape cShape = PhysicsScene.PE.CreateCompoundShape(PhysicsScene.World, false);
823 816
824 // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape. 817 // Create the shape for the root prim and add it to the compound shape. Cannot be a native shape.
@@ -933,8 +926,7 @@ public sealed class BSShapeCollection : IDisposable
933 // Updates prim.BSBody with the information about the new body if one is created. 926 // Updates prim.BSBody with the information about the new body if one is created.
934 // Returns 'true' if an object was actually created. 927 // Returns 'true' if an object was actually created.
935 // Called at taint-time. 928 // Called at taint-time.
936 private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletWorld sim, BulletShape shape, 929 private bool CreateBody(bool forceRebuild, BSPhysObject prim, BulletWorld sim, BodyDestructionCallback bodyCallback)
937 BodyDestructionCallback bodyCallback)
938 { 930 {
939 bool ret = false; 931 bool ret = false;
940 932
@@ -951,27 +943,28 @@ public sealed class BSShapeCollection : IDisposable
951 { 943 {
952 // If the collisionObject is not the correct type for solidness, rebuild what's there 944 // If the collisionObject is not the correct type for solidness, rebuild what's there
953 mustRebuild = true; 945 mustRebuild = true;
946 if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,forceRebuildBecauseChangingBodyType,bodyType={1}", prim.LocalID, bodyType);
954 } 947 }
955 } 948 }
956 949
957 if (mustRebuild || forceRebuild) 950 if (mustRebuild || forceRebuild)
958 { 951 {
959 // Free any old body 952 // Free any old body
960 DereferenceBody(prim.PhysBody, true, bodyCallback); 953 DereferenceBody(prim.PhysBody, bodyCallback);
961 954
962 BulletBody aBody; 955 BulletBody aBody;
963 if (prim.IsSolid) 956 if (prim.IsSolid)
964 { 957 {
965 aBody = PhysicsScene.PE.CreateBodyFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation); 958 aBody = PhysicsScene.PE.CreateBodyFromShape(sim, prim.PhysShape, prim.LocalID, prim.RawPosition, prim.RawOrientation);
966 if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,body={1}", prim.LocalID, aBody); 959 if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,mesh,body={1}", prim.LocalID, aBody);
967 } 960 }
968 else 961 else
969 { 962 {
970 aBody = PhysicsScene.PE.CreateGhostFromShape(sim, shape, prim.LocalID, prim.RawPosition, prim.RawOrientation); 963 aBody = PhysicsScene.PE.CreateGhostFromShape(sim, prim.PhysShape, prim.LocalID, prim.RawPosition, prim.RawOrientation);
971 if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,body={1}", prim.LocalID, aBody); 964 if (DDetail) DetailLog("{0},BSShapeCollection.CreateBody,ghost,body={1}", prim.LocalID, aBody);
972 } 965 }
973 966
974 ReferenceBody(aBody, true); 967 ReferenceBody(aBody);
975 968
976 prim.PhysBody = aBody; 969 prim.PhysBody = aBody;
977 970