diff options
author | Robert Adams | 2013-01-01 09:30:49 -0800 |
---|---|---|
committer | Robert Adams | 2013-01-01 17:27:32 -0800 |
commit | 04132d3af4c8f44639ea842091f86274513e2dfd (patch) | |
tree | 8afd4aa11cb7bcf15ffd7156204f73859e762f31 /OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |
parent | Fixed bugs when getting the root folder. (diff) | |
download | opensim-SC-04132d3af4c8f44639ea842091f86274513e2dfd.zip opensim-SC-04132d3af4c8f44639ea842091f86274513e2dfd.tar.gz opensim-SC-04132d3af4c8f44639ea842091f86274513e2dfd.tar.bz2 opensim-SC-04132d3af4c8f44639ea842091f86274513e2dfd.tar.xz |
BulletSim: subclass Bullet[World|Body|Shape|Constraint] for unmanaged
to have pointers and managed to have objects.
Initial paste of XNA code. Commented out.
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index cd77581..2b652f5 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -45,7 +45,7 @@ public sealed class BSShapeCollection : IDisposable | |||
45 | // Description of a Mesh | 45 | // Description of a Mesh |
46 | private struct MeshDesc | 46 | private struct MeshDesc |
47 | { | 47 | { |
48 | public IntPtr ptr; | 48 | public BulletShape shape; |
49 | public int referenceCount; | 49 | public int referenceCount; |
50 | public DateTime lastReferenced; | 50 | public DateTime lastReferenced; |
51 | public UInt64 shapeKey; | 51 | public UInt64 shapeKey; |
@@ -55,7 +55,7 @@ public sealed class BSShapeCollection : IDisposable | |||
55 | // Meshes and hulls have the same shape hash key but we only need hulls for efficient collision calculations. | 55 | // Meshes and hulls have the same shape hash key but we only need hulls for efficient collision calculations. |
56 | private struct HullDesc | 56 | private struct HullDesc |
57 | { | 57 | { |
58 | public IntPtr ptr; | 58 | public BulletShape shape; |
59 | public int referenceCount; | 59 | public int referenceCount; |
60 | public DateTime lastReferenced; | 60 | public DateTime lastReferenced; |
61 | public UInt64 shapeKey; | 61 | public UInt64 shapeKey; |
@@ -173,7 +173,7 @@ public sealed class BSShapeCollection : IDisposable | |||
173 | } | 173 | } |
174 | 174 | ||
175 | // Zero any reference to the shape so it is not freed when the body is deleted. | 175 | // Zero any reference to the shape so it is not freed when the body is deleted. |
176 | PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, new BulletShape()); | 176 | PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, body, null); |
177 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, body); | 177 | PhysicsScene.PE.DestroyObject(PhysicsScene.World, body); |
178 | }); | 178 | }); |
179 | } | 179 | } |
@@ -202,7 +202,7 @@ public sealed class BSShapeCollection : IDisposable | |||
202 | else | 202 | else |
203 | { | 203 | { |
204 | // This is a new reference to a mesh | 204 | // This is a new reference to a mesh |
205 | meshDesc.ptr = shape.ptr; | 205 | meshDesc.shape = shape.Clone(); |
206 | meshDesc.shapeKey = shape.shapeKey; | 206 | meshDesc.shapeKey = shape.shapeKey; |
207 | // We keep a reference to the underlying IMesh data so a hull can be built | 207 | // We keep a reference to the underlying IMesh data so a hull can be built |
208 | meshDesc.referenceCount = 1; | 208 | meshDesc.referenceCount = 1; |
@@ -225,7 +225,7 @@ public sealed class BSShapeCollection : IDisposable | |||
225 | else | 225 | else |
226 | { | 226 | { |
227 | // This is a new reference to a hull | 227 | // This is a new reference to a hull |
228 | hullDesc.ptr = shape.ptr; | 228 | hullDesc.shape = shape.Clone(); |
229 | hullDesc.shapeKey = shape.shapeKey; | 229 | hullDesc.shapeKey = shape.shapeKey; |
230 | hullDesc.referenceCount = 1; | 230 | hullDesc.referenceCount = 1; |
231 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}", | 231 | if (DDetail) DetailLog("{0},BSShapeCollection.ReferenceShape,newHull,key={1},cnt={2}", |
@@ -361,15 +361,14 @@ public sealed class BSShapeCollection : IDisposable | |||
361 | MeshDesc meshDesc; | 361 | MeshDesc meshDesc; |
362 | HullDesc hullDesc; | 362 | HullDesc hullDesc; |
363 | 363 | ||
364 | IntPtr cShape = shapeInfo.ptr; | 364 | if (TryGetMeshByPtr(shapeInfo, out meshDesc)) |
365 | if (TryGetMeshByPtr(cShape, out meshDesc)) | ||
366 | { | 365 | { |
367 | shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH; | 366 | shapeInfo.type = BSPhysicsShapeType.SHAPE_MESH; |
368 | shapeInfo.shapeKey = meshDesc.shapeKey; | 367 | shapeInfo.shapeKey = meshDesc.shapeKey; |
369 | } | 368 | } |
370 | else | 369 | else |
371 | { | 370 | { |
372 | if (TryGetHullByPtr(cShape, out hullDesc)) | 371 | if (TryGetHullByPtr(shapeInfo, out hullDesc)) |
373 | { | 372 | { |
374 | shapeInfo.type = BSPhysicsShapeType.SHAPE_HULL; | 373 | shapeInfo.type = BSPhysicsShapeType.SHAPE_HULL; |
375 | shapeInfo.shapeKey = hullDesc.shapeKey; | 374 | shapeInfo.shapeKey = hullDesc.shapeKey; |
@@ -632,7 +631,7 @@ public sealed class BSShapeCollection : IDisposable | |||
632 | if (Meshes.TryGetValue(newMeshKey, out meshDesc)) | 631 | if (Meshes.TryGetValue(newMeshKey, out meshDesc)) |
633 | { | 632 | { |
634 | // If the mesh has already been built just use it. | 633 | // If the mesh has already been built just use it. |
635 | newShape = new BulletShape(meshDesc.ptr, BSPhysicsShapeType.SHAPE_MESH); | 634 | newShape = meshDesc.shape.Clone(); |
636 | } | 635 | } |
637 | else | 636 | else |
638 | { | 637 | { |
@@ -703,7 +702,7 @@ public sealed class BSShapeCollection : IDisposable | |||
703 | if (Hulls.TryGetValue(newHullKey, out hullDesc)) | 702 | if (Hulls.TryGetValue(newHullKey, out hullDesc)) |
704 | { | 703 | { |
705 | // If the hull shape already is created, just use it. | 704 | // If the hull shape already is created, just use it. |
706 | newShape = new BulletShape(hullDesc.ptr, BSPhysicsShapeType.SHAPE_HULL); | 705 | newShape = hullDesc.shape.Clone(); |
707 | } | 706 | } |
708 | else | 707 | else |
709 | { | 708 | { |
@@ -965,13 +964,13 @@ public sealed class BSShapeCollection : IDisposable | |||
965 | return ret; | 964 | return ret; |
966 | } | 965 | } |
967 | 966 | ||
968 | private bool TryGetMeshByPtr(IntPtr addr, out MeshDesc outDesc) | 967 | private bool TryGetMeshByPtr(BulletShape shape, out MeshDesc outDesc) |
969 | { | 968 | { |
970 | bool ret = false; | 969 | bool ret = false; |
971 | MeshDesc foundDesc = new MeshDesc(); | 970 | MeshDesc foundDesc = new MeshDesc(); |
972 | foreach (MeshDesc md in Meshes.Values) | 971 | foreach (MeshDesc md in Meshes.Values) |
973 | { | 972 | { |
974 | if (md.ptr == addr) | 973 | if (md.shape.ReferenceSame(shape)) |
975 | { | 974 | { |
976 | foundDesc = md; | 975 | foundDesc = md; |
977 | ret = true; | 976 | ret = true; |
@@ -983,13 +982,13 @@ public sealed class BSShapeCollection : IDisposable | |||
983 | return ret; | 982 | return ret; |
984 | } | 983 | } |
985 | 984 | ||
986 | private bool TryGetHullByPtr(IntPtr addr, out HullDesc outDesc) | 985 | private bool TryGetHullByPtr(BulletShape shape, out HullDesc outDesc) |
987 | { | 986 | { |
988 | bool ret = false; | 987 | bool ret = false; |
989 | HullDesc foundDesc = new HullDesc(); | 988 | HullDesc foundDesc = new HullDesc(); |
990 | foreach (HullDesc hd in Hulls.Values) | 989 | foreach (HullDesc hd in Hulls.Values) |
991 | { | 990 | { |
992 | if (hd.ptr == addr) | 991 | if (hd.shape.ReferenceSame(shape)) |
993 | { | 992 | { |
994 | foundDesc = hd; | 993 | foundDesc = hd; |
995 | ret = true; | 994 | ret = true; |