Remove dynamic memory allocation of ContactPointInfo instances during narrow-phase
This commit is contained in:
parent
c7846d4a29
commit
3acdeb8cd2
|
@ -413,37 +413,30 @@ void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
|||
}
|
||||
|
||||
// Called by a narrow-phase collision algorithm when a new contact has been found
|
||||
void CollisionDetection::notifyContact(OverlappingPair* overlappingPair, ContactPointInfo* contactInfo) {
|
||||
void CollisionDetection::notifyContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo) {
|
||||
assert(contactInfo != NULL);
|
||||
|
||||
// If it is the first contact since the pairs are overlapping
|
||||
if (overlappingPair->getNbContactPoints() == 0) {
|
||||
|
||||
// Trigger a callback event
|
||||
if (mWorld->mEventListener != NULL) mWorld->mEventListener->beginContact(*contactInfo);
|
||||
if (mWorld->mEventListener != NULL) mWorld->mEventListener->beginContact(contactInfo);
|
||||
}
|
||||
|
||||
// TODO : Try not to allocate ContactPointInfo dynamically
|
||||
|
||||
// Create a new contact
|
||||
createContact(overlappingPair, contactInfo);
|
||||
|
||||
// Trigger a callback event for the new contact
|
||||
if (mWorld->mEventListener != NULL) mWorld->mEventListener->newContact(*contactInfo);
|
||||
|
||||
// Delete and remove the contact info from the memory allocator
|
||||
contactInfo->~ContactPointInfo();
|
||||
mWorld->mMemoryAllocator.release(contactInfo, sizeof(ContactPointInfo));
|
||||
if (mWorld->mEventListener != NULL) mWorld->mEventListener->newContact(contactInfo);
|
||||
}
|
||||
|
||||
// Create a new contact
|
||||
void CollisionDetection::createContact(OverlappingPair* overlappingPair,
|
||||
const ContactPointInfo* contactInfo) {
|
||||
const ContactPointInfo& contactInfo) {
|
||||
|
||||
// Create a new contact
|
||||
ContactPoint* contact = new (mWorld->mMemoryAllocator.allocate(sizeof(ContactPoint)))
|
||||
ContactPoint(*contactInfo);
|
||||
assert(contact != NULL);
|
||||
ContactPoint(contactInfo);
|
||||
|
||||
// Add the contact to the contact manifold set of the corresponding overlapping pair
|
||||
overlappingPair->addContact(contact);
|
||||
|
|
|
@ -204,10 +204,10 @@ class CollisionDetection : public NarrowPhaseCallback {
|
|||
MemoryAllocator& getWorldMemoryAllocator();
|
||||
|
||||
/// Called by a narrow-phase collision algorithm when a new contact has been found
|
||||
virtual void notifyContact(OverlappingPair* overlappingPair, ContactPointInfo* contactInfo);
|
||||
virtual void notifyContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo);
|
||||
|
||||
/// Create a new contact
|
||||
void createContact(OverlappingPair* overlappingPair, const ContactPointInfo* contactInfo);
|
||||
void createContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo);
|
||||
|
||||
// -------------------- Friendship -------------------- //
|
||||
|
||||
|
|
|
@ -427,9 +427,8 @@ bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const Simplex& simple
|
|||
assert(penetrationDepth > 0.0);
|
||||
|
||||
// Create the contact info object
|
||||
ContactPointInfo* contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo)))
|
||||
ContactPointInfo(shape1Info.proxyShape, shape2Info.proxyShape, normal,
|
||||
penetrationDepth, pALocal, pBLocal);
|
||||
ContactPointInfo contactInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||
normal, penetrationDepth, pALocal, pBLocal);
|
||||
|
||||
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
||||
|
||||
|
|
|
@ -147,9 +147,8 @@ bool GJKAlgorithm::testCollision(const CollisionShapeInfo& shape1Info,
|
|||
if (penetrationDepth <= 0.0) return false;
|
||||
|
||||
// Create the contact info object
|
||||
ContactPointInfo* contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo)))
|
||||
ContactPointInfo(shape1Info.proxyShape, shape2Info.proxyShape, normal,
|
||||
penetrationDepth, pA, pB);
|
||||
ContactPointInfo contactInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||
normal, penetrationDepth, pA, pB);
|
||||
|
||||
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
||||
|
||||
|
@ -181,9 +180,8 @@ bool GJKAlgorithm::testCollision(const CollisionShapeInfo& shape1Info,
|
|||
if (penetrationDepth <= 0.0) return false;
|
||||
|
||||
// Create the contact info object
|
||||
ContactPointInfo* contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo)))
|
||||
ContactPointInfo(shape1Info.proxyShape, shape2Info.proxyShape, normal,
|
||||
penetrationDepth, pA, pB);
|
||||
ContactPointInfo contactInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||
normal, penetrationDepth, pA, pB);
|
||||
|
||||
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
||||
|
||||
|
@ -213,9 +211,8 @@ bool GJKAlgorithm::testCollision(const CollisionShapeInfo& shape1Info,
|
|||
if (penetrationDepth <= 0.0) return false;
|
||||
|
||||
// Create the contact info object
|
||||
ContactPointInfo* contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo)))
|
||||
ContactPointInfo(shape1Info.proxyShape, shape2Info.proxyShape, normal,
|
||||
penetrationDepth, pA, pB);
|
||||
ContactPointInfo contactInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||
normal, penetrationDepth, pA, pB);
|
||||
|
||||
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
||||
|
||||
|
@ -252,9 +249,8 @@ bool GJKAlgorithm::testCollision(const CollisionShapeInfo& shape1Info,
|
|||
if (penetrationDepth <= 0.0) return false;
|
||||
|
||||
// Create the contact info object
|
||||
ContactPointInfo* contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo)))
|
||||
ContactPointInfo(shape1Info.proxyShape, shape2Info.proxyShape, normal,
|
||||
penetrationDepth, pA, pB);
|
||||
ContactPointInfo contactInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||
normal, penetrationDepth, pA, pB);
|
||||
|
||||
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
||||
|
||||
|
|
|
@ -48,7 +48,8 @@ class NarrowPhaseCallback {
|
|||
public:
|
||||
|
||||
/// Called by a narrow-phase collision algorithm when a new contact has been found
|
||||
virtual void notifyContact(OverlappingPair* overlappingPair, ContactPointInfo* contactInfo)=0;
|
||||
virtual void notifyContact(OverlappingPair* overlappingPair,
|
||||
const ContactPointInfo& contactInfo)=0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -70,8 +70,7 @@ bool SphereVsSphereAlgorithm::testCollision(const CollisionShapeInfo& shape1Info
|
|||
decimal penetrationDepth = sumRadius - std::sqrt(squaredDistanceBetweenCenters);
|
||||
|
||||
// Create the contact info object
|
||||
ContactPointInfo* contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo)))
|
||||
ContactPointInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||
ContactPointInfo contactInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||
vectorBetweenCenters.getUnit(), penetrationDepth,
|
||||
intersectionOnBody1, intersectionOnBody2);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user