aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSShapes.cs39
1 files changed, 32 insertions, 7 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
index 006a9c1..fbe320b 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs
@@ -71,7 +71,7 @@ public abstract class BSShape
71 lastReferenced = DateTime.Now; 71 lastReferenced = DateTime.Now;
72 } 72 }
73 73
74 // Called when this shape is being used again. 74 // Called when this shape is done being used.
75 protected virtual void DecrementReference() 75 protected virtual void DecrementReference()
76 { 76 {
77 referenceCount--; 77 referenceCount--;
@@ -866,6 +866,8 @@ public class BSShapeHull : BSShape
866public class BSShapeCompound : BSShape 866public class BSShapeCompound : BSShape
867{ 867{
868 private static string LogHeader = "[BULLETSIM SHAPE COMPOUND]"; 868 private static string LogHeader = "[BULLETSIM SHAPE COMPOUND]";
869 public static Dictionary<string, BSShapeCompound> CompoundShapes = new Dictionary<string, BSShapeCompound>();
870
869 public BSShapeCompound(BulletShape pShape) : base(pShape) 871 public BSShapeCompound(BulletShape pShape) : base(pShape)
870 { 872 {
871 } 873 }
@@ -873,7 +875,9 @@ public class BSShapeCompound : BSShape
873 { 875 {
874 // Base compound shapes are not shared so this returns a raw shape. 876 // Base compound shapes are not shared so this returns a raw shape.
875 // A built compound shape can be reused in linksets. 877 // A built compound shape can be reused in linksets.
876 return new BSShapeCompound(CreatePhysicalCompoundShape(physicsScene)); 878 BSShapeCompound ret = new BSShapeCompound(CreatePhysicalCompoundShape(physicsScene));
879 CompoundShapes.Add(ret.AddrString, ret);
880 return ret;
877 } 881 }
878 public override BSShape GetReference(BSScene physicsScene, BSPhysObject prim) 882 public override BSShape GetReference(BSScene physicsScene, BSPhysObject prim)
879 { 883 {
@@ -911,10 +915,21 @@ public class BSShapeCompound : BSShape
911 BulletShape childShape = physicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(physShapeInfo, ii); 915 BulletShape childShape = physicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(physShapeInfo, ii);
912 DereferenceAnonCollisionShape(physicsScene, childShape); 916 DereferenceAnonCollisionShape(physicsScene, childShape);
913 } 917 }
918
919 lock (CompoundShapes)
920 CompoundShapes.Remove(physShapeInfo.AddrString);
914 physicsScene.PE.DeleteCollisionShape(physicsScene.World, physShapeInfo); 921 physicsScene.PE.DeleteCollisionShape(physicsScene.World, physShapeInfo);
915 } 922 }
916 } 923 }
917 } 924 }
925 public static bool TryGetCompoundByPtr(BulletShape pShape, out BSShapeCompound outCompound)
926 {
927 lock (CompoundShapes)
928 {
929 string addr = pShape.AddrString;
930 return CompoundShapes.TryGetValue(addr, out outCompound);
931 }
932 }
918 private static BulletShape CreatePhysicalCompoundShape(BSScene physicsScene) 933 private static BulletShape CreatePhysicalCompoundShape(BSScene physicsScene)
919 { 934 {
920 BulletShape cShape = physicsScene.PE.CreateCompoundShape(physicsScene.World, false); 935 BulletShape cShape = physicsScene.PE.CreateCompoundShape(physicsScene.World, false);
@@ -926,10 +941,13 @@ public class BSShapeCompound : BSShape
926 private void DereferenceAnonCollisionShape(BSScene physicsScene, BulletShape pShape) 941 private void DereferenceAnonCollisionShape(BSScene physicsScene, BulletShape pShape)
927 { 942 {
928 // TODO: figure a better way to go through all the shape types and find a possible instance. 943 // TODO: figure a better way to go through all the shape types and find a possible instance.
944 physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,shape={1}",
945 BSScene.DetailLogZero, pShape);
929 BSShapeMesh meshDesc; 946 BSShapeMesh meshDesc;
930 if (BSShapeMesh.TryGetMeshByPtr(pShape, out meshDesc)) 947 if (BSShapeMesh.TryGetMeshByPtr(pShape, out meshDesc))
931 { 948 {
932 meshDesc.Dereference(physicsScene); 949 meshDesc.Dereference(physicsScene);
950 // physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,foundMesh,shape={1}", BSScene.DetailLogZero, pShape);
933 } 951 }
934 else 952 else
935 { 953 {
@@ -937,13 +955,15 @@ public class BSShapeCompound : BSShape
937 if (BSShapeHull.TryGetHullByPtr(pShape, out hullDesc)) 955 if (BSShapeHull.TryGetHullByPtr(pShape, out hullDesc))
938 { 956 {
939 hullDesc.Dereference(physicsScene); 957 hullDesc.Dereference(physicsScene);
958 // physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,foundHull,shape={1}", BSScene.DetailLogZero, pShape);
940 } 959 }
941 else 960 else
942 { 961 {
943 BSShapeConvexHull chullDesc; 962 BSShapeConvexHull chullDesc;
944 if (BSShapeConvexHull.TryGetHullByPtr(pShape, out chullDesc)) 963 if (BSShapeConvexHull.TryGetConvexHullByPtr(pShape, out chullDesc))
945 { 964 {
946 chullDesc.Dereference(physicsScene); 965 chullDesc.Dereference(physicsScene);
966 // physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,foundConvexHull,shape={1}", BSScene.DetailLogZero, pShape);
947 } 967 }
948 else 968 else
949 { 969 {
@@ -951,20 +971,23 @@ public class BSShapeCompound : BSShape
951 if (BSShapeGImpact.TryGetGImpactByPtr(pShape, out gImpactDesc)) 971 if (BSShapeGImpact.TryGetGImpactByPtr(pShape, out gImpactDesc))
952 { 972 {
953 gImpactDesc.Dereference(physicsScene); 973 gImpactDesc.Dereference(physicsScene);
974 // physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,foundgImpact,shape={1}", BSScene.DetailLogZero, pShape);
954 } 975 }
955 else 976 else
956 { 977 {
957 // Didn't find it in the lists of specific types. It could be compound. 978 // Didn't find it in the lists of specific types. It could be compound.
958 if (physicsScene.PE.IsCompound(pShape)) 979 BSShapeCompound compoundDesc;
980 if (BSShapeCompound.TryGetCompoundByPtr(pShape, out compoundDesc))
959 { 981 {
960 BSShapeCompound recursiveCompound = new BSShapeCompound(pShape); 982 compoundDesc.Dereference(physicsScene);
961 recursiveCompound.Dereference(physicsScene); 983 // physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,recursiveCompoundShape,shape={1}", BSScene.DetailLogZero, pShape);
962 } 984 }
963 else 985 else
964 { 986 {
965 // If none of the above, maybe it is a simple native shape. 987 // If none of the above, maybe it is a simple native shape.
966 if (physicsScene.PE.IsNativeShape(pShape)) 988 if (physicsScene.PE.IsNativeShape(pShape))
967 { 989 {
990 // physicsScene.DetailLog("{0},BSShapeCompound.DereferenceAnonCollisionShape,assumingNative,shape={1}", BSScene.DetailLogZero, pShape);
968 BSShapeNative nativeShape = new BSShapeNative(pShape); 991 BSShapeNative nativeShape = new BSShapeNative(pShape);
969 nativeShape.Dereference(physicsScene); 992 nativeShape.Dereference(physicsScene);
970 } 993 }
@@ -1021,6 +1044,8 @@ public class BSShapeConvexHull : BSShape
1021 convexShape = physicsScene.PE.BuildConvexHullShapeFromMesh(physicsScene.World, baseMesh.physShapeInfo); 1044 convexShape = physicsScene.PE.BuildConvexHullShapeFromMesh(physicsScene.World, baseMesh.physShapeInfo);
1022 convexShape.shapeKey = newMeshKey; 1045 convexShape.shapeKey = newMeshKey;
1023 ConvexHulls.Add(convexShape.shapeKey, retConvexHull); 1046 ConvexHulls.Add(convexShape.shapeKey, retConvexHull);
1047 physicsScene.DetailLog("{0},BSShapeConvexHull.GetReference,addingNewlyCreatedShape,shape={1}",
1048 BSScene.DetailLogZero, convexShape);
1024 } 1049 }
1025 1050
1026 // Done with the base mesh 1051 // Done with the base mesh
@@ -1049,7 +1074,7 @@ public class BSShapeConvexHull : BSShape
1049 } 1074 }
1050 } 1075 }
1051 // Loop through all the known hulls and return the description based on the physical address. 1076 // Loop through all the known hulls and return the description based on the physical address.
1052 public static bool TryGetHullByPtr(BulletShape pShape, out BSShapeConvexHull outHull) 1077 public static bool TryGetConvexHullByPtr(BulletShape pShape, out BSShapeConvexHull outHull)
1053 { 1078 {
1054 bool ret = false; 1079 bool ret = false;
1055 BSShapeConvexHull foundDesc = null; 1080 BSShapeConvexHull foundDesc = null;