Add profiling code

This commit is contained in:
Daniel Chappuis 2019-10-22 17:34:36 +02:00
parent bcb4febb16
commit 87614b7dad
5 changed files with 43 additions and 1 deletions

View File

@ -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<Pair<uint, uint>, OverlappingPair*>(pairID, newPair));
// Wake up the two bodies

View File

@ -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<int>& overlappingNodes) {
RP3D_PROFILE("BroadPhaseAlgorithm::addOverlappingNodes()", mProfiler);
// For each overlapping node in the linked list
LinkedList<int>::ListElement* elem = overlappingNodes.getListHead();
while (elem != nullptr) {

View File

@ -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<int, 64> stack(mAllocator);
stack.push(mRootNodeID);

View File

@ -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() {

View File

@ -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