aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapes.cs125
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt9
2 files changed, 102 insertions, 32 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
index 5c58ad5..f0c9fd5 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
@@ -47,26 +47,31 @@ public abstract class BSShape
47 47
48 public BSShape() 48 public BSShape()
49 { 49 {
50 referenceCount = 0; 50 referenceCount = 1;
51 lastReferenced = DateTime.Now; 51 lastReferenced = DateTime.Now;
52 physShapeInfo = new BulletShape(); 52 physShapeInfo = new BulletShape();
53 } 53 }
54 public BSShape(BulletShape pShape) 54 public BSShape(BulletShape pShape)
55 { 55 {
56 referenceCount = 0; 56 referenceCount = 1;
57 lastReferenced = DateTime.Now; 57 lastReferenced = DateTime.Now;
58 physShapeInfo = pShape; 58 physShapeInfo = pShape;
59 } 59 }
60 60
61 // Get another reference to this shape.
62 public abstract BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim);
63
61 // Called when this shape is being used again. 64 // Called when this shape is being used again.
62 public virtual void IncrementReference() 65 // Used internally. External callers should call instance.GetReference() to properly copy/reference
66 // the shape.
67 protected virtual void IncrementReference()
63 { 68 {
64 referenceCount++; 69 referenceCount++;
65 lastReferenced = DateTime.Now; 70 lastReferenced = DateTime.Now;
66 } 71 }
67 72
68 // Called when this shape is being used again. 73 // Called when this shape is being used again.
69 public virtual void DecrementReference() 74 protected virtual void DecrementReference()
70 { 75 {
71 referenceCount--; 76 referenceCount--;
72 lastReferenced = DateTime.Now; 77 lastReferenced = DateTime.Now;
@@ -99,12 +104,19 @@ public abstract class BSShape
99 // Returns a string for debugging that uniquily identifies the memory used by this instance 104 // Returns a string for debugging that uniquily identifies the memory used by this instance
100 public virtual string AddrString 105 public virtual string AddrString
101 { 106 {
102 get { return "unknown"; } 107 get
108 {
109 if (physShapeInfo != null)
110 return physShapeInfo.AddrString;
111 return "unknown";
112 }
103 } 113 }
104 114
105 public override string ToString() 115 public override string ToString()
106 { 116 {
107 StringBuilder buff = new StringBuilder(); 117 StringBuilder buff = new StringBuilder();
118 buff.Append("<t=");
119 buff.Append(ShapeType.ToString());
108 buff.Append("<p="); 120 buff.Append("<p=");
109 buff.Append(AddrString); 121 buff.Append(AddrString);
110 buff.Append(",c="); 122 buff.Append(",c=");
@@ -113,6 +125,7 @@ public abstract class BSShape
113 return buff.ToString(); 125 return buff.ToString();
114 } 126 }
115 127
128 #region Common shape routines
116 // Create a hash of all the shape parameters to be used as a key for this particular shape. 129 // Create a hash of all the shape parameters to be used as a key for this particular shape.
117 public static System.UInt64 ComputeShapeKey(OMV.Vector3 size, PrimitiveBaseShape pbs, out float retLod) 130 public static System.UInt64 ComputeShapeKey(OMV.Vector3 size, PrimitiveBaseShape pbs, out float retLod)
118 { 131 {
@@ -225,6 +238,7 @@ public abstract class BSShape
225 return fillShape.physShapeInfo; 238 return fillShape.physShapeInfo;
226 } 239 }
227 240
241 #endregion // Common shape routines
228} 242}
229 243
230// ============================================================================================================ 244// ============================================================================================================
@@ -234,6 +248,7 @@ public class BSShapeNull : BSShape
234 { 248 {
235 } 249 }
236 public static BSShape GetReference() { return new BSShapeNull(); } 250 public static BSShape GetReference() { return new BSShapeNull(); }
251 public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) { return new BSShapeNull(); }
237 public override void Dereference(BSScene physicsScene) { /* The magic of garbage collection will make this go away */ } 252 public override void Dereference(BSScene physicsScene) { /* The magic of garbage collection will make this go away */ }
238} 253}
239 254
@@ -252,17 +267,27 @@ public class BSShapeNative : BSShape
252 return new BSShapeNative(CreatePhysicalNativeShape(physicsScene, prim, shapeType, shapeKey)); 267 return new BSShapeNative(CreatePhysicalNativeShape(physicsScene, prim, shapeType, shapeKey));
253 } 268 }
254 269
270 public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim)
271 {
272 // Native shapes are not shared so we return a new shape.
273 return new BSShapeNative(CreatePhysicalNativeShape(pPhysicsScene, pPrim,
274 physShapeInfo.shapeType, (FixedShapeKey)physShapeInfo.shapeKey) );
275 }
276
255 // Make this reference to the physical shape go away since native shapes are not shared. 277 // Make this reference to the physical shape go away since native shapes are not shared.
256 public override void Dereference(BSScene physicsScene) 278 public override void Dereference(BSScene physicsScene)
257 { 279 {
258 // Native shapes are not tracked and are released immediately 280 // Native shapes are not tracked and are released immediately
259 if (physShapeInfo.HasPhysicalShape) 281 lock (physShapeInfo)
260 { 282 {
261 physicsScene.DetailLog("{0},BSShapeNative.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this); 283 if (physShapeInfo.HasPhysicalShape)
262 physicsScene.PE.DeleteCollisionShape(physicsScene.World, physShapeInfo); 284 {
285 physicsScene.DetailLog("{0},BSShapeNative.DereferenceShape,deleteNativeShape,shape={1}", BSScene.DetailLogZero, this);
286 physicsScene.PE.DeleteCollisionShape(physicsScene.World, physShapeInfo);
287 }
288 physShapeInfo.Clear();
289 // Garbage collection will free up this instance.
263 } 290 }
264 physShapeInfo.Clear();
265 // Garbage collection will free up this instance.
266 } 291 }
267 292
268 private static BulletShape CreatePhysicalNativeShape(BSScene physicsScene, BSPhysObject prim, 293 private static BulletShape CreatePhysicalNativeShape(BSScene physicsScene, BSPhysObject prim,
@@ -345,6 +370,12 @@ public class BSShapeMesh : BSShape
345 } 370 }
346 return retMesh; 371 return retMesh;
347 } 372 }
373 public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim)
374 {
375 // Another reference to this shape is just counted.
376 IncrementReference();
377 return this;
378 }
348 public override void Dereference(BSScene physicsScene) 379 public override void Dereference(BSScene physicsScene)
349 { 380 {
350 lock (Meshes) 381 lock (Meshes)
@@ -487,8 +518,19 @@ public class BSShapeHull : BSShape
487 } 518 }
488 return retHull; 519 return retHull;
489 } 520 }
521 public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim)
522 {
523 // Another reference to this shape is just counted.
524 IncrementReference();
525 return this;
526 }
490 public override void Dereference(BSScene physicsScene) 527 public override void Dereference(BSScene physicsScene)
491 { 528 {
529 lock (Hulls)
530 {
531 this.DecrementReference();
532 // TODO: schedule aging and destruction of unused meshes.
533 }
492 } 534 }
493 List<ConvexResult> m_hulls; 535 List<ConvexResult> m_hulls;
494 private BulletShape CreatePhysicalHull(BSScene physicsScene, BSPhysObject prim, System.UInt64 newHullKey, 536 private BulletShape CreatePhysicalHull(BSScene physicsScene, BSPhysObject prim, System.UInt64 newHullKey,
@@ -520,7 +562,7 @@ public class BSShapeHull : BSShape
520 physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,hullFromMesh,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape); 562 physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,hullFromMesh,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape);
521 } 563 }
522 // Now done with the mesh shape. 564 // Now done with the mesh shape.
523 meshShape.DecrementReference(); 565 meshShape.Dereference(physicsScene);
524 physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,shouldUseBulletHACD,exit,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape); 566 physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,shouldUseBulletHACD,exit,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape);
525 } 567 }
526 if (!newShape.HasPhysicalShape) 568 if (!newShape.HasPhysicalShape)
@@ -671,37 +713,52 @@ public class BSShapeCompound : BSShape
671 public BSShapeCompound(BulletShape pShape) : base(pShape) 713 public BSShapeCompound(BulletShape pShape) : base(pShape)
672 { 714 {
673 } 715 }
674 public static BSShape GetReference(BSScene physicsScene, BSPhysObject prim) 716 public static BSShape GetReference(BSScene physicsScene)
717 {
718 // Base compound shapes are not shared so this returns a raw shape.
719 // A built compound shape can be reused in linksets.
720 return new BSShapeCompound(CreatePhysicalCompoundShape(physicsScene));
721 }
722 public override BSShape GetReference(BSScene physicsScene, BSPhysObject prim)
675 { 723 {
676 // Compound shapes are not shared so a new one is created every time. 724 // Calling this reference means we want another handle to an existing compound shape
677 return new BSShapeCompound(CreatePhysicalCompoundShape(physicsScene, prim)); 725 // (usually linksets) so return this copy.
726 IncrementReference();
727 return this;
678 } 728 }
679 // Dereferencing a compound shape releases the hold on all the child shapes. 729 // Dereferencing a compound shape releases the hold on all the child shapes.
680 public override void Dereference(BSScene physicsScene) 730 public override void Dereference(BSScene physicsScene)
681 { 731 {
682 if (!physicsScene.PE.IsCompound(physShapeInfo)) 732 lock (physShapeInfo)
683 { 733 {
684 // Failed the sanity check!! 734 Dereference(physicsScene);
685 physicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", 735 if (referenceCount <= 0)
686 LogHeader, physShapeInfo.shapeType, physShapeInfo.AddrString); 736 {
687 physicsScene.DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", 737 if (!physicsScene.PE.IsCompound(physShapeInfo))
688 BSScene.DetailLogZero, physShapeInfo.shapeType, physShapeInfo.AddrString); 738 {
689 return; 739 // Failed the sanity check!!
690 } 740 physicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}",
741 LogHeader, physShapeInfo.shapeType, physShapeInfo.AddrString);
742 physicsScene.DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}",
743 BSScene.DetailLogZero, physShapeInfo.shapeType, physShapeInfo.AddrString);
744 return;
745 }
691 746
692 int numChildren = physicsScene.PE.GetNumberOfCompoundChildren(physShapeInfo); 747 int numChildren = physicsScene.PE.GetNumberOfCompoundChildren(physShapeInfo);
693 physicsScene.DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", 748 physicsScene.DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}",
694 BSScene.DetailLogZero, physShapeInfo, numChildren); 749 BSScene.DetailLogZero, physShapeInfo, numChildren);
695 750
696 // Loop through all the children dereferencing each. 751 // Loop through all the children dereferencing each.
697 for (int ii = numChildren - 1; ii >= 0; ii--) 752 for (int ii = numChildren - 1; ii >= 0; ii--)
698 { 753 {
699 BulletShape childShape = physicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(physShapeInfo, ii); 754 BulletShape childShape = physicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(physShapeInfo, ii);
700 DereferenceAnonCollisionShape(physicsScene, childShape); 755 DereferenceAnonCollisionShape(physicsScene, childShape);
756 }
757 physicsScene.PE.DeleteCollisionShape(physicsScene.World, physShapeInfo);
758 }
701 } 759 }
702 physicsScene.PE.DeleteCollisionShape(physicsScene.World, physShapeInfo);
703 } 760 }
704 private static BulletShape CreatePhysicalCompoundShape(BSScene physicsScene, BSPhysObject prim) 761 private static BulletShape CreatePhysicalCompoundShape(BSScene physicsScene)
705 { 762 {
706 BulletShape cShape = physicsScene.PE.CreateCompoundShape(physicsScene.World, false); 763 BulletShape cShape = physicsScene.PE.CreateCompoundShape(physicsScene.World, false);
707 return cShape; 764 return cShape;
@@ -754,6 +811,10 @@ public class BSShapeAvatar : BSShape
754 { 811 {
755 return new BSShapeNull(); 812 return new BSShapeNull();
756 } 813 }
814 public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim)
815 {
816 return new BSShapeNull();
817 }
757 public override void Dereference(BSScene physicsScene) { } 818 public override void Dereference(BSScene physicsScene) { }
758 819
759 // From the front: 820 // From the front:
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
index c67081a..559a73f 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt
@@ -1,3 +1,12 @@
1PROBLEMS TO LOOK INTO
2=================================================
3Nebadon vehicle ride, get up, ride again. Second time vehicle does not act correctly.
4 Have to rez new vehicle and delete the old to fix situation.
5Hitting RESET on Nebadon's vehicle while riding causes vehicle to get into odd
6 position state where it will not settle onto ground properly, etc
7Two of Nebadon vehicles in a sim max the CPU. This is new.
8A sitting, active vehicle bobs up and down a small amount.
9
1CURRENT PRIORITIES 10CURRENT PRIORITIES
2================================================= 11=================================================
3Use the HACD convex hull routine in Bullet rather than the C# version. 12Use the HACD convex hull routine in Bullet rather than the C# version.