diff --git a/src/collision/CollisionDetection.cpp b/src/collision/CollisionDetection.cpp index 59625aac..a5b9726b 100644 --- a/src/collision/CollisionDetection.cpp +++ b/src/collision/CollisionDetection.cpp @@ -204,6 +204,8 @@ void CollisionDetection::computeMiddlePhase() { void CollisionDetection::computeConvexVsConcaveMiddlePhase(OverlappingPair* pair, MemoryAllocator& allocator, NarrowPhaseInfo** firstNarrowPhaseInfo) { + RP3D_PROFILE("CollisionDetection::computeConvexVsConcaveMiddlePhase()", mProfiler); + ProxyShape* shape1 = pair->getShape1(); ProxyShape* shape2 = pair->getShape2(); @@ -311,6 +313,8 @@ void CollisionDetection::computeNarrowPhase() { /// This method is called by the broad-phase collision detection algorithm void CollisionDetection::broadPhaseNotifyOverlappingPair(ProxyShape* shape1, ProxyShape* shape2) { + RP3D_PROFILE("CollisionDetection::broadPhaseNotifyOverlappingPair()", mProfiler); + assert(shape1->getBroadPhaseId() != -1); assert(shape2->getBroadPhaseId() != -1); assert(shape1->getBroadPhaseId() != shape2->getBroadPhaseId()); @@ -331,6 +335,7 @@ void CollisionDetection::broadPhaseNotifyOverlappingPair(ProxyShape* shape1, Pro mMemoryManager.getSingleFrameAllocator(), mWorld->mConfig); assert(newPair != nullptr); + newPair->setProfiler(mProfiler); mOverlappingPairs.add(Pair, OverlappingPair*>(pairID, newPair)); // Wake up the two bodies diff --git a/src/collision/broadphase/BroadPhaseAlgorithm.cpp b/src/collision/broadphase/BroadPhaseAlgorithm.cpp index 572e1507..ea14b3c2 100644 --- a/src/collision/broadphase/BroadPhaseAlgorithm.cpp +++ b/src/collision/broadphase/BroadPhaseAlgorithm.cpp @@ -52,6 +52,8 @@ BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection) bool BroadPhaseAlgorithm::testOverlappingShapes(const ProxyShape* shape1, const ProxyShape* shape2) const { + RP3D_PROFILE("BroadPhaseAlgorithm::testOverlappingShapes()", mProfiler); + if (shape1->getBroadPhaseId() == -1 || shape2->getBroadPhaseId() == -1) return false; // Get the two AABBs of the collision shapes @@ -139,6 +141,8 @@ void BroadPhaseAlgorithm::reportAllShapesOverlappingWithAABB(const AABB& aabb, // Compute all the overlapping pairs of collision shapes void BroadPhaseAlgorithm::computeOverlappingPairs(MemoryManager& memoryManager) { + RP3D_PROFILE("BroadPhaseAlgorithm::computeOverlappingPairs()", mProfiler); + // TODO : Try to see if we can allocate potential pairs in single frame allocator // Reset the potential overlapping pairs @@ -218,6 +222,8 @@ void BroadPhaseAlgorithm::computeOverlappingPairs(MemoryManager& memoryManager) // Notify the broad-phase about a potential overlapping pair in the dynamic AABB tree void BroadPhaseAlgorithm::addOverlappingNodes(int referenceNodeId, const LinkedList& overlappingNodes) { + RP3D_PROFILE("BroadPhaseAlgorithm::addOverlappingNodes()", mProfiler); + // For each overlapping node in the linked list LinkedList::ListElement* elem = overlappingNodes.getListHead(); while (elem != nullptr) { diff --git a/src/collision/broadphase/DynamicAABBTree.cpp b/src/collision/broadphase/DynamicAABBTree.cpp index 3924aae3..19a53d7e 100644 --- a/src/collision/broadphase/DynamicAABBTree.cpp +++ b/src/collision/broadphase/DynamicAABBTree.cpp @@ -597,6 +597,8 @@ int DynamicAABBTree::balanceSubTreeAtNode(int nodeID) { void DynamicAABBTree::reportAllShapesOverlappingWithAABB(const AABB& aabb, DynamicAABBTreeOverlapCallback& callback) const { + RP3D_PROFILE("DynamicAABBTree::reportAllShapesOverlappingWithAABB()", mProfiler); + // Create a stack with the nodes to visit Stack stack(mAllocator); stack.push(mRootNodeID); diff --git a/src/engine/OverlappingPair.cpp b/src/engine/OverlappingPair.cpp index 0bad85c6..d9aa4b6f 100644 --- a/src/engine/OverlappingPair.cpp +++ b/src/engine/OverlappingPair.cpp @@ -41,7 +41,13 @@ OverlappingPair::OverlappingPair(ProxyShape* shape1, ProxyShape* shape2, mPersistentAllocator(persistentMemoryAllocator), mTempMemoryAllocator(temporaryMemoryAllocator), mLastFrameCollisionInfos(mPersistentAllocator), mWorldSettings(worldSettings) { -} +#ifdef IS_PROFILING_ACTIVE + + mProfiler = nullptr; + +#endif + +} // Destructor OverlappingPair::~OverlappingPair() { diff --git a/src/engine/OverlappingPair.h b/src/engine/OverlappingPair.h index c2f5ec29..705ea054 100644 --- a/src/engine/OverlappingPair.h +++ b/src/engine/OverlappingPair.h @@ -128,6 +128,13 @@ class OverlappingPair { /// World settings const WorldSettings& mWorldSettings; +#ifdef IS_PROFILING_ACTIVE + + /// Pointer to the profiler + Profiler* mProfiler; + +#endif + public: // -------------------- Methods -------------------- // @@ -208,6 +215,13 @@ class OverlappingPair { /// Return the pair of bodies index of the pair static bodyindexpair computeBodiesIndexPair(CollisionBody* body1, CollisionBody* body2); +#ifdef IS_PROFILING_ACTIVE + + /// Set the profiler + void setProfiler(Profiler* profiler); + +#endif + // -------------------- Friendship -------------------- // friend class DynamicsWorld; @@ -309,6 +323,15 @@ inline LastFrameCollisionInfo* OverlappingPair::getLastFrameCollisionInfo(uint s return mLastFrameCollisionInfos[ShapeIdPair(shapeId1, shapeId2)]; } +#ifdef IS_PROFILING_ACTIVE + +// Set the profiler +inline void OverlappingPair::setProfiler(Profiler* profiler) { + mProfiler = profiler; +} + +#endif + } #endif