From 85c6a2eaf519a076999a7da4c397a69883c40995 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Thu, 15 Oct 2015 07:48:28 +0200 Subject: [PATCH] Return manifold set by reference and not by pointer --- src/collision/CollisionDetection.cpp | 12 ++++++------ src/collision/ContactManifoldSet.h | 4 ++-- src/engine/DynamicsWorld.cpp | 6 +++--- src/engine/OverlappingPair.h | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/collision/CollisionDetection.cpp b/src/collision/CollisionDetection.cpp index cdee7927..673d4539 100644 --- a/src/collision/CollisionDetection.cpp +++ b/src/collision/CollisionDetection.cpp @@ -120,10 +120,10 @@ void CollisionDetection::reportCollisionBetweenShapes(CollisionCallback* callbac } // For each contact manifold set of the overlapping pair - ContactManifoldSet* manifoldSet = pair->getContactManifoldSet(); - for (uint j=0; jgetNbContactManifolds(); j++) { + const ContactManifoldSet& manifoldSet = pair->getContactManifoldSet(); + for (uint j=0; jgetContactManifold(j); + const ContactManifold* manifold = manifoldSet.getContactManifold(j); // For each contact manifold of the manifold set for (uint i=0; igetNbContactPoints(); i++) { @@ -467,12 +467,12 @@ void CollisionDetection::addContactManifoldToBody(OverlappingPair* pair) { CollisionBody* body1 = pair->getShape1()->getBody(); CollisionBody* body2 = pair->getShape2()->getBody(); - ContactManifoldSet* manifoldSet = pair->getContactManifoldSet(); + const ContactManifoldSet& manifoldSet = pair->getContactManifoldSet(); // For each contact manifold in the set of manifolds in the pair - for (int i=0; igetNbContactManifolds(); i++) { + for (int i=0; igetContactManifold(i); + ContactManifold* contactManifold = manifoldSet.getContactManifold(i); // Add the contact manifold at the beginning of the linked // list of contact manifolds of the first body diff --git a/src/collision/ContactManifoldSet.h b/src/collision/ContactManifoldSet.h index cb0bd2a7..c24ebc3c 100644 --- a/src/collision/ContactManifoldSet.h +++ b/src/collision/ContactManifoldSet.h @@ -112,7 +112,7 @@ class ContactManifoldSet { int getNbContactManifolds() const; /// Return a given contact manifold - ContactManifold* getContactManifold(uint index); + ContactManifold* getContactManifold(uint index) const; /// Return the total number of contact points in the set of manifolds int getTotalNbContactPoints() const; @@ -134,7 +134,7 @@ inline int ContactManifoldSet::getNbContactManifolds() const { } // Return a given contact manifold -inline ContactManifold* ContactManifoldSet::getContactManifold(uint index) { +inline ContactManifold* ContactManifoldSet::getContactManifold(uint index) const { assert(index < mNbManifolds); return mManifolds[index]; } diff --git a/src/engine/DynamicsWorld.cpp b/src/engine/DynamicsWorld.cpp index ea98c4df..aebc375d 100644 --- a/src/engine/DynamicsWorld.cpp +++ b/src/engine/DynamicsWorld.cpp @@ -985,10 +985,10 @@ std::vector DynamicsWorld::getContactsList() const { OverlappingPair* pair = it->second; // For each contact manifold of the pair - ContactManifoldSet* manifoldSet = pair->getContactManifoldSet(); - for (int i=0; igetNbContactManifolds(); i++) { + const ContactManifoldSet& manifoldSet = pair->getContactManifoldSet(); + for (int i=0; igetContactManifold(i); + ContactManifold* manifold = manifoldSet.getContactManifold(i); // Get the contact manifold contactManifolds.push_back(manifold); diff --git a/src/engine/OverlappingPair.h b/src/engine/OverlappingPair.h index 134770f0..fe2de6c2 100644 --- a/src/engine/OverlappingPair.h +++ b/src/engine/OverlappingPair.h @@ -97,8 +97,8 @@ class OverlappingPair { /// Return the number of contacts in the cache uint getNbContactPoints() const; - /// Return the contact manifold set - ContactManifoldSet* getContactManifoldSet(); + /// Return the a reference to the contact manifold set + const ContactManifoldSet& getContactManifoldSet(); /// Clear the contact points of the contact manifold void clearContactPoints(); @@ -151,8 +151,8 @@ inline uint OverlappingPair::getNbContactPoints() const { } // Return the contact manifold -inline ContactManifoldSet* OverlappingPair::getContactManifoldSet() { - return &mContactManifoldSet; +inline const ContactManifoldSet& OverlappingPair::getContactManifoldSet() { + return mContactManifoldSet; } // Return the pair of bodies index