diff --git a/Extras/BulletMultiThreaded/SpuBatchRaycaster.cpp b/Extras/BulletMultiThreaded/SpuBatchRaycaster.cpp index 79bd97833..64d073685 100644 --- a/Extras/BulletMultiThreaded/SpuBatchRaycaster.cpp +++ b/Extras/BulletMultiThreaded/SpuBatchRaycaster.cpp @@ -14,6 +14,7 @@ subject to the following restrictions: */ #include +#include "BulletCollision/CollisionShapes/btCollisionShape.h" #include "LinearMath/btAlignedAllocator.h" #include "SpuBatchRaycaster.h" @@ -55,10 +56,57 @@ SpuBatchRaycaster::setCollisionObjects (btCollisionObjectArray& castUponObjects, } void -SpuBatchRaycaster::addRay (const btVector3& rayFrom, const btVector3& rayTo) +SpuBatchRaycaster::setCollisionObjectsSkipPE (btCollisionObjectArray& castUponObjects, int numCastUponObjects) +{ + if (castUponObjectWrappers) + { + btAlignedFree (castUponObjectWrappers); + castUponObjectWrappers = NULL; + } + + int numNonPEShapes = 0; + for (int i = 0; i < numCastUponObjects; i++) + { + const btCollisionShape* shape = castUponObjects[i]->getCollisionShape(); + + if (shape->getShapeType () == BOX_SHAPE_PROXYTYPE || + shape->getShapeType () == SPHERE_SHAPE_PROXYTYPE || + shape->getShapeType () == CAPSULE_SHAPE_PROXYTYPE) + { + continue; + } + + numNonPEShapes++; + } + + castUponObjectWrappers = (SpuCollisionObjectWrapper*)btAlignedAlloc (sizeof(SpuCollisionObjectWrapper) * numNonPEShapes,16); + numCastUponObjectWrappers = numNonPEShapes; + + int index = 0; + for (int i = 0; i < numCastUponObjects; i++) + { + const btCollisionShape* shape = castUponObjects[i]->getCollisionShape(); + + if (shape->getShapeType () == BOX_SHAPE_PROXYTYPE || + shape->getShapeType () == SPHERE_SHAPE_PROXYTYPE || + shape->getShapeType () == CAPSULE_SHAPE_PROXYTYPE) + { + continue; + } + + castUponObjectWrappers[index] = SpuCollisionObjectWrapper(castUponObjects[i]); + index++; + } + + printf("Number of shapes bullet is casting against: %d\n", numNonPEShapes); + btAssert (index == numNonPEShapes); +} + +void +SpuBatchRaycaster::addRay (const btVector3& rayFrom, const btVector3& rayTo, const btScalar hitFraction) { SpuRaycastTaskWorkUnitOut workUnitOut; - workUnitOut.hitFraction = 1.0; + workUnitOut.hitFraction = hitFraction; workUnitOut.hitNormal = btVector3(0.0, 1.0, 0.0); rayBatchOutput.push_back (workUnitOut); diff --git a/Extras/BulletMultiThreaded/SpuBatchRaycaster.h b/Extras/BulletMultiThreaded/SpuBatchRaycaster.h index da2f65de6..88271fbd7 100644 --- a/Extras/BulletMultiThreaded/SpuBatchRaycaster.h +++ b/Extras/BulletMultiThreaded/SpuBatchRaycaster.h @@ -38,8 +38,8 @@ public: SpuBatchRaycaster (class btThreadSupportInterface* threadInterface, int maxNumOutstandingTasks); ~SpuBatchRaycaster (); void setCollisionObjects (btCollisionObjectArray& castUponObjects, int numCastUponObjects); - - void addRay (const btVector3& rayFrom, const btVector3& rayTo); + void setCollisionObjectsSkipPE (btCollisionObjectArray& castUponObjects, int numCastUponObjects); + void addRay (const btVector3& rayFrom, const btVector3& rayTo, const btScalar hitFraction = 1.0); void clearRays (); void performBatchRaycast (); const SpuRaycastTaskWorkUnitOut& operator [] (int i) const; diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.cpp b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.cpp index 5dec4d4ff..8d987165c 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.cpp +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.cpp @@ -298,7 +298,11 @@ void dmaBvhShapeData (bvhMeshShape_LocalStoreMemory* bvhMeshShape, btBvhTriangle dmaSize = sizeof(btTriangleIndexVertexArray); dmaPpuAddress2 = reinterpret_cast(triMeshShape->getMeshInterface()); // spu_printf("trimeshShape->getMeshInterface() == %llx\n",dmaPpuAddress2); +#ifdef DISABLE_CELL_DMA_GET_READ_ONLY // needed for PE ray caster + cellDmaGet(&bvhMeshShape->gTriangleMeshInterfaceStorage, dmaPpuAddress2 , dmaSize, DMA_TAG(1), 0, 0); +#else bvhMeshShape->gTriangleMeshInterfacePtr = (btTriangleIndexVertexArray*)cellDmaGetReadOnly(&bvhMeshShape->gTriangleMeshInterfaceStorage, dmaPpuAddress2 , dmaSize, DMA_TAG(1), 0, 0); +#endif //cellDmaWaitTagStatusAll(DMA_MASK(1)); ///now DMA over the BVH