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
|
// 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);
|
assert(contactInfo != NULL);
|
||||||
|
|
||||||
// If it is the first contact since the pairs are overlapping
|
// If it is the first contact since the pairs are overlapping
|
||||||
if (overlappingPair->getNbContactPoints() == 0) {
|
if (overlappingPair->getNbContactPoints() == 0) {
|
||||||
|
|
||||||
// Trigger a callback event
|
// 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
|
// Create a new contact
|
||||||
createContact(overlappingPair, contactInfo);
|
createContact(overlappingPair, contactInfo);
|
||||||
|
|
||||||
// Trigger a callback event for the new contact
|
// Trigger a callback event for the new contact
|
||||||
if (mWorld->mEventListener != NULL) mWorld->mEventListener->newContact(*contactInfo);
|
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new contact
|
// Create a new contact
|
||||||
void CollisionDetection::createContact(OverlappingPair* overlappingPair,
|
void CollisionDetection::createContact(OverlappingPair* overlappingPair,
|
||||||
const ContactPointInfo* contactInfo) {
|
const ContactPointInfo& contactInfo) {
|
||||||
|
|
||||||
// Create a new contact
|
// Create a new contact
|
||||||
ContactPoint* contact = new (mWorld->mMemoryAllocator.allocate(sizeof(ContactPoint)))
|
ContactPoint* contact = new (mWorld->mMemoryAllocator.allocate(sizeof(ContactPoint)))
|
||||||
ContactPoint(*contactInfo);
|
ContactPoint(contactInfo);
|
||||||
assert(contact != NULL);
|
|
||||||
|
|
||||||
// Add the contact to the contact manifold set of the corresponding overlapping pair
|
// Add the contact to the contact manifold set of the corresponding overlapping pair
|
||||||
overlappingPair->addContact(contact);
|
overlappingPair->addContact(contact);
|
||||||
|
|
|
@ -204,10 +204,10 @@ class CollisionDetection : public NarrowPhaseCallback {
|
||||||
MemoryAllocator& getWorldMemoryAllocator();
|
MemoryAllocator& getWorldMemoryAllocator();
|
||||||
|
|
||||||
/// Called by a narrow-phase collision algorithm when a new contact has been found
|
/// 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
|
/// Create a new contact
|
||||||
void createContact(OverlappingPair* overlappingPair, const ContactPointInfo* contactInfo);
|
void createContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo);
|
||||||
|
|
||||||
// -------------------- Friendship -------------------- //
|
// -------------------- Friendship -------------------- //
|
||||||
|
|
||||||
|
|
|
@ -427,9 +427,8 @@ bool EPAAlgorithm::computePenetrationDepthAndContactPoints(const Simplex& simple
|
||||||
assert(penetrationDepth > 0.0);
|
assert(penetrationDepth > 0.0);
|
||||||
|
|
||||||
// Create the contact info object
|
// Create the contact info object
|
||||||
ContactPointInfo* contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo)))
|
ContactPointInfo contactInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||||
ContactPointInfo(shape1Info.proxyShape, shape2Info.proxyShape, normal,
|
normal, penetrationDepth, pALocal, pBLocal);
|
||||||
penetrationDepth, pALocal, pBLocal);
|
|
||||||
|
|
||||||
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
||||||
|
|
||||||
|
|
|
@ -147,9 +147,8 @@ bool GJKAlgorithm::testCollision(const CollisionShapeInfo& shape1Info,
|
||||||
if (penetrationDepth <= 0.0) return false;
|
if (penetrationDepth <= 0.0) return false;
|
||||||
|
|
||||||
// Create the contact info object
|
// Create the contact info object
|
||||||
ContactPointInfo* contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo)))
|
ContactPointInfo contactInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||||
ContactPointInfo(shape1Info.proxyShape, shape2Info.proxyShape, normal,
|
normal, penetrationDepth, pA, pB);
|
||||||
penetrationDepth, pA, pB);
|
|
||||||
|
|
||||||
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
||||||
|
|
||||||
|
@ -181,9 +180,8 @@ bool GJKAlgorithm::testCollision(const CollisionShapeInfo& shape1Info,
|
||||||
if (penetrationDepth <= 0.0) return false;
|
if (penetrationDepth <= 0.0) return false;
|
||||||
|
|
||||||
// Create the contact info object
|
// Create the contact info object
|
||||||
ContactPointInfo* contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo)))
|
ContactPointInfo contactInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||||
ContactPointInfo(shape1Info.proxyShape, shape2Info.proxyShape, normal,
|
normal, penetrationDepth, pA, pB);
|
||||||
penetrationDepth, pA, pB);
|
|
||||||
|
|
||||||
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
||||||
|
|
||||||
|
@ -213,9 +211,8 @@ bool GJKAlgorithm::testCollision(const CollisionShapeInfo& shape1Info,
|
||||||
if (penetrationDepth <= 0.0) return false;
|
if (penetrationDepth <= 0.0) return false;
|
||||||
|
|
||||||
// Create the contact info object
|
// Create the contact info object
|
||||||
ContactPointInfo* contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo)))
|
ContactPointInfo contactInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||||
ContactPointInfo(shape1Info.proxyShape, shape2Info.proxyShape, normal,
|
normal, penetrationDepth, pA, pB);
|
||||||
penetrationDepth, pA, pB);
|
|
||||||
|
|
||||||
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
||||||
|
|
||||||
|
@ -252,9 +249,8 @@ bool GJKAlgorithm::testCollision(const CollisionShapeInfo& shape1Info,
|
||||||
if (penetrationDepth <= 0.0) return false;
|
if (penetrationDepth <= 0.0) return false;
|
||||||
|
|
||||||
// Create the contact info object
|
// Create the contact info object
|
||||||
ContactPointInfo* contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo)))
|
ContactPointInfo contactInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||||
ContactPointInfo(shape1Info.proxyShape, shape2Info.proxyShape, normal,
|
normal, penetrationDepth, pA, pB);
|
||||||
penetrationDepth, pA, pB);
|
|
||||||
|
|
||||||
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,8 @@ class NarrowPhaseCallback {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Called by a narrow-phase collision algorithm when a new contact has been found
|
/// 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,10 +70,9 @@ bool SphereVsSphereAlgorithm::testCollision(const CollisionShapeInfo& shape1Info
|
||||||
decimal penetrationDepth = sumRadius - std::sqrt(squaredDistanceBetweenCenters);
|
decimal penetrationDepth = sumRadius - std::sqrt(squaredDistanceBetweenCenters);
|
||||||
|
|
||||||
// Create the contact info object
|
// Create the contact info object
|
||||||
ContactPointInfo* contactInfo = new (mMemoryAllocator->allocate(sizeof(ContactPointInfo)))
|
ContactPointInfo contactInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
||||||
ContactPointInfo(shape1Info.proxyShape, shape2Info.proxyShape,
|
vectorBetweenCenters.getUnit(), penetrationDepth,
|
||||||
vectorBetweenCenters.getUnit(), penetrationDepth,
|
intersectionOnBody1, intersectionOnBody2);
|
||||||
intersectionOnBody1, intersectionOnBody2);
|
|
||||||
|
|
||||||
// Notify about the new contact
|
// Notify about the new contact
|
||||||
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
narrowPhaseCallback->notifyContact(shape1Info.overlappingPair, contactInfo);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user