diff --git a/src/collision/CollisionDetection.cpp b/src/collision/CollisionDetection.cpp index d47b6691..9ef9078e 100644 --- a/src/collision/CollisionDetection.cpp +++ b/src/collision/CollisionDetection.cpp @@ -242,7 +242,7 @@ void CollisionDetection::computeNarrowPhase() { NarrowPhaseInfo* narrowPhaseInfo = mNarrowPhaseInfos[i]; - assert(narrowPhaseInfo->contactPoints == nullptr); + assert(narrowPhaseInfo->contactPoints.size() == 0); // Select the narrow phase algorithm to use according to the two collision shapes const CollisionShapeType shape1Type = narrowPhaseInfo->collisionShape1->getType(); @@ -434,7 +434,7 @@ void CollisionDetection::processAllPotentialContacts(const ListcontactPoints != nullptr); + assert(narrowPhaseInfo->contactPoints.size() > 0); // Transfer the contact points from the narrow phase info to the overlapping pair narrowPhaseInfo->overlappingPair->addPotentialContactPoints(narrowPhaseInfo); diff --git a/src/collision/ContactManifoldSet.cpp b/src/collision/ContactManifoldSet.cpp index 0dc40ebd..8c3b43fa 100644 --- a/src/collision/ContactManifoldSet.cpp +++ b/src/collision/ContactManifoldSet.cpp @@ -51,11 +51,12 @@ ContactManifoldSet::~ContactManifoldSet() { void ContactManifoldSet::addContactPoints(NarrowPhaseInfo* narrowPhaseInfo) { - assert(narrowPhaseInfo->contactPoints != nullptr); + assert(narrowPhaseInfo->contactPoints.size() > 0); // For each potential contact point to add - ContactPointInfo* contactPoint = narrowPhaseInfo->contactPoints; - while (contactPoint != nullptr) { + for (uint i=0; i < narrowPhaseInfo->contactPoints.size(); i++) { + + ContactPointInfo* contactPoint = narrowPhaseInfo->contactPoints[i]; // Look if the contact point correspond to an existing potential manifold // (if the contact point normal is similar to the normal of an existing manifold) @@ -91,8 +92,6 @@ void ContactManifoldSet::addContactPoints(NarrowPhaseInfo* narrowPhaseInfo) { // Add the contact point to the manifold manifold->addContactPoint(contactPoint); } - - contactPoint = contactPoint->next; } } diff --git a/src/collision/NarrowPhaseInfo.cpp b/src/collision/NarrowPhaseInfo.cpp index 0ee63d0a..b1394c98 100644 --- a/src/collision/NarrowPhaseInfo.cpp +++ b/src/collision/NarrowPhaseInfo.cpp @@ -37,7 +37,7 @@ NarrowPhaseInfo::NarrowPhaseInfo(OverlappingPair* pair, CollisionShape* shape1, const Transform& shape2Transform, MemoryAllocator& shapeAllocator) : overlappingPair(pair), collisionShape1(shape1), collisionShape2(shape2), shape1ToWorldTransform(shape1Transform), shape2ToWorldTransform(shape2Transform), - contactPoints(nullptr), collisionShapeAllocator(shapeAllocator) { + contactPoints(overlappingPair->getTemporaryAllocator()), collisionShapeAllocator(shapeAllocator) { // Add a collision info for the two collision shapes into the overlapping pair (if not present yet) overlappingPair->addLastFrameInfoIfNecessary(shape1->getId(), shape2->getId()); @@ -46,7 +46,7 @@ NarrowPhaseInfo::NarrowPhaseInfo(OverlappingPair* pair, CollisionShape* shape1, // Destructor NarrowPhaseInfo::~NarrowPhaseInfo() { - assert(contactPoints == nullptr); + assert(contactPoints.size() == 0); // Release the memory of the TriangleShape (this memory was allocated in the // MiddlePhaseTriangleCallback::testTriangle() method) @@ -73,9 +73,8 @@ void NarrowPhaseInfo::addContactPoint(const Vector3& contactNormal, decimal penD ContactPointInfo* contactPointInfo = new (allocator.allocate(sizeof(ContactPointInfo))) ContactPointInfo(contactNormal, penDepth, localPt1, localPt2); - // Add it into the linked list of contact points - contactPointInfo->next = contactPoints; - contactPoints = contactPointInfo; + // Add it into the list of contact points + contactPoints.add(contactPointInfo); } // Reset the remaining contact points @@ -85,19 +84,16 @@ void NarrowPhaseInfo::resetContactPoints() { MemoryAllocator& allocator = overlappingPair->getTemporaryAllocator(); // For each remaining contact point info - ContactPointInfo* element = contactPoints; - while(element != nullptr) { + for (uint i=0; i < contactPoints.size(); i++) { - ContactPointInfo* elementToDelete = element; - - element = element->next; + ContactPointInfo* contactPoint = contactPoints[i]; // Call the destructor - elementToDelete->~ContactPointInfo(); + contactPoint->~ContactPointInfo(); // Delete the current element - allocator.release(elementToDelete, sizeof(ContactPointInfo)); + allocator.release(contactPoint, sizeof(ContactPointInfo)); } - contactPoints = nullptr; + contactPoints.clear(); } diff --git a/src/collision/NarrowPhaseInfo.h b/src/collision/NarrowPhaseInfo.h index 38aa6af6..ff2cf5a0 100644 --- a/src/collision/NarrowPhaseInfo.h +++ b/src/collision/NarrowPhaseInfo.h @@ -62,8 +62,8 @@ struct NarrowPhaseInfo { /// Transform that maps from collision shape 2 local-space to world-space Transform shape2ToWorldTransform; - /// Linked-list of contact points created during the narrow-phase - ContactPointInfo* contactPoints; + /// List of contact points created during the narrow-phase + List contactPoints; /// Memory allocator for the collision shape (Used to release TriangleShape memory in destructor) MemoryAllocator& collisionShapeAllocator; diff --git a/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp b/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp index cb3ee5b8..5751578e 100644 --- a/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp +++ b/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp @@ -76,8 +76,8 @@ bool CapsuleVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfo* narrowPh // two contact points instead of a single one (as in the deep contact case with SAT algorithm) // Get the contact point created by GJK - ContactPointInfo* contactPoint = narrowPhaseInfo->contactPoints; - assert(contactPoint != nullptr); + assert(narrowPhaseInfo->contactPoints.size() > 0); + ContactPointInfo*& contactPoint = narrowPhaseInfo->contactPoints[0]; bool isCapsuleShape1 = narrowPhaseInfo->collisionShape1->getType() == CollisionShapeType::CAPSULE;