From d322625f9062d7748a1a896b6fd37c51f7f41435 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 29 Apr 2013 17:30:54 -0700 Subject: BulletSim: Add non-static BSShape.GetReference for getting another reference to an existing shape instance. BSShapeNative rebuilds shape for all references. BSShapeCompound returns another reference copy if the compound shape already exists (for linksets). --- OpenSim/Region/Physics/BulletSPlugin/BSShapes.cs | 125 +++++++++++++++------ .../Region/Physics/BulletSPlugin/BulletSimTODO.txt | 9 ++ 2 files changed, 102 insertions(+), 32 deletions(-) (limited to 'OpenSim') 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 public BSShape() { - referenceCount = 0; + referenceCount = 1; lastReferenced = DateTime.Now; physShapeInfo = new BulletShape(); } public BSShape(BulletShape pShape) { - referenceCount = 0; + referenceCount = 1; lastReferenced = DateTime.Now; physShapeInfo = pShape; } + // Get another reference to this shape. + public abstract BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim); + // Called when this shape is being used again. - public virtual void IncrementReference() + // Used internally. External callers should call instance.GetReference() to properly copy/reference + // the shape. + protected virtual void IncrementReference() { referenceCount++; lastReferenced = DateTime.Now; } // Called when this shape is being used again. - public virtual void DecrementReference() + protected virtual void DecrementReference() { referenceCount--; lastReferenced = DateTime.Now; @@ -99,12 +104,19 @@ public abstract class BSShape // Returns a string for debugging that uniquily identifies the memory used by this instance public virtual string AddrString { - get { return "unknown"; } + get + { + if (physShapeInfo != null) + return physShapeInfo.AddrString; + return "unknown"; + } } public override string ToString() { StringBuilder buff = new StringBuilder(); + buff.Append(" m_hulls; private BulletShape CreatePhysicalHull(BSScene physicsScene, BSPhysObject prim, System.UInt64 newHullKey, @@ -520,7 +562,7 @@ public class BSShapeHull : BSShape physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,hullFromMesh,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape); } // Now done with the mesh shape. - meshShape.DecrementReference(); + meshShape.Dereference(physicsScene); physicsScene.DetailLog("{0},BSShapeHull.CreatePhysicalHull,shouldUseBulletHACD,exit,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape); } if (!newShape.HasPhysicalShape) @@ -671,37 +713,52 @@ public class BSShapeCompound : BSShape public BSShapeCompound(BulletShape pShape) : base(pShape) { } - public static BSShape GetReference(BSScene physicsScene, BSPhysObject prim) + public static BSShape GetReference(BSScene physicsScene) + { + // Base compound shapes are not shared so this returns a raw shape. + // A built compound shape can be reused in linksets. + return new BSShapeCompound(CreatePhysicalCompoundShape(physicsScene)); + } + public override BSShape GetReference(BSScene physicsScene, BSPhysObject prim) { - // Compound shapes are not shared so a new one is created every time. - return new BSShapeCompound(CreatePhysicalCompoundShape(physicsScene, prim)); + // Calling this reference means we want another handle to an existing compound shape + // (usually linksets) so return this copy. + IncrementReference(); + return this; } // Dereferencing a compound shape releases the hold on all the child shapes. public override void Dereference(BSScene physicsScene) { - if (!physicsScene.PE.IsCompound(physShapeInfo)) + lock (physShapeInfo) { - // Failed the sanity check!! - physicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", - LogHeader, physShapeInfo.shapeType, physShapeInfo.AddrString); - physicsScene.DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", - BSScene.DetailLogZero, physShapeInfo.shapeType, physShapeInfo.AddrString); - return; - } + Dereference(physicsScene); + if (referenceCount <= 0) + { + if (!physicsScene.PE.IsCompound(physShapeInfo)) + { + // Failed the sanity check!! + physicsScene.Logger.ErrorFormat("{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}", + LogHeader, physShapeInfo.shapeType, physShapeInfo.AddrString); + physicsScene.DetailLog("{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}", + BSScene.DetailLogZero, physShapeInfo.shapeType, physShapeInfo.AddrString); + return; + } - int numChildren = physicsScene.PE.GetNumberOfCompoundChildren(physShapeInfo); - physicsScene.DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", - BSScene.DetailLogZero, physShapeInfo, numChildren); + int numChildren = physicsScene.PE.GetNumberOfCompoundChildren(physShapeInfo); + physicsScene.DetailLog("{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}", + BSScene.DetailLogZero, physShapeInfo, numChildren); - // Loop through all the children dereferencing each. - for (int ii = numChildren - 1; ii >= 0; ii--) - { - BulletShape childShape = physicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(physShapeInfo, ii); - DereferenceAnonCollisionShape(physicsScene, childShape); + // Loop through all the children dereferencing each. + for (int ii = numChildren - 1; ii >= 0; ii--) + { + BulletShape childShape = physicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(physShapeInfo, ii); + DereferenceAnonCollisionShape(physicsScene, childShape); + } + physicsScene.PE.DeleteCollisionShape(physicsScene.World, physShapeInfo); + } } - physicsScene.PE.DeleteCollisionShape(physicsScene.World, physShapeInfo); } - private static BulletShape CreatePhysicalCompoundShape(BSScene physicsScene, BSPhysObject prim) + private static BulletShape CreatePhysicalCompoundShape(BSScene physicsScene) { BulletShape cShape = physicsScene.PE.CreateCompoundShape(physicsScene.World, false); return cShape; @@ -754,6 +811,10 @@ public class BSShapeAvatar : BSShape { return new BSShapeNull(); } + public override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim) + { + return new BSShapeNull(); + } public override void Dereference(BSScene physicsScene) { } // 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 @@ +PROBLEMS TO LOOK INTO +================================================= +Nebadon vehicle ride, get up, ride again. Second time vehicle does not act correctly. + Have to rez new vehicle and delete the old to fix situation. +Hitting RESET on Nebadon's vehicle while riding causes vehicle to get into odd + position state where it will not settle onto ground properly, etc +Two of Nebadon vehicles in a sim max the CPU. This is new. +A sitting, active vehicle bobs up and down a small amount. + CURRENT PRIORITIES ================================================= Use the HACD convex hull routine in Bullet rather than the C# version. -- cgit v1.1