Optimization of contacts processing

This commit is contained in:
Daniel Chappuis 2020-07-11 14:06:39 +02:00
parent 98ac47cbad
commit 8fd5c58986
5 changed files with 11 additions and 8 deletions

View File

@ -55,7 +55,7 @@ struct ContactManifoldInfo {
/// Constructor
ContactManifoldInfo(uint64 pairId, MemoryAllocator& allocator)
: potentialContactPointsIndices(allocator), pairId(pairId) {
: potentialContactPointsIndices(allocator, 4), pairId(pairId) {
}

View File

@ -91,7 +91,7 @@ struct ContactPair {
/// Constructor
ContactPair(uint64 pairId, Entity body1Entity, Entity body2Entity, Entity collider1Entity,
Entity collider2Entity, uint contactPairIndex, bool collidingInPreviousFrame, bool isTrigger, MemoryAllocator& allocator)
: pairId(pairId), potentialContactManifoldsIndices(allocator), body1Entity(body1Entity), body2Entity(body2Entity),
: pairId(pairId), potentialContactManifoldsIndices(allocator, 8), body1Entity(body1Entity), body2Entity(body2Entity),
collider1Entity(collider1Entity), collider2Entity(collider2Entity),
isAlreadyInIsland(false), contactPairIndex(contactPairIndex), contactManifoldsIndex(0), nbContactManifolds(0),
contactPointsIndex(0), nbToTalContactPoints(0), collidingInPreviousFrame(collidingInPreviousFrame), isTrigger(isTrigger) {

View File

@ -36,7 +36,7 @@ ContactPoint::ContactPoint(const ContactPointInfo* contactInfo, decimal persiste
mPenetrationDepth(contactInfo->penetrationDepth),
mLocalPointOnShape1(contactInfo->localPoint1),
mLocalPointOnShape2(contactInfo->localPoint2),
mIsRestingContact(false), mIsObsolete(false), mNext(nullptr), mPrevious(nullptr),
mIsRestingContact(false), mIsObsolete(false),
mPersistentContactDistanceThreshold(persistentContactDistanceThreshold) {
assert(mPenetrationDepth > decimal(0.0));

View File

@ -520,6 +520,9 @@ void CollisionDetectionSystem::computeNarrowPhase() {
// Swap the previous and current contacts lists
swapPreviousAndCurrentContacts();
mPotentialContactManifolds.reserve(mPreviousContactManifolds->size());
mPotentialContactPoints.reserve(mPreviousContactPoints->size());
// Test the narrow-phase collision detection on the batches to be tested
testNarrowPhaseCollision(mNarrowPhaseInput, true, allocator);

View File

@ -125,17 +125,17 @@ void ContactSolverSystem::initializeForIsland(uint islandIndex) {
assert(externalManifold.nbContactPoints > 0);
const uint rigidBodyIndex1 = mRigidBodyComponents.getEntityIndex(externalManifold.bodyEntity1);
const uint rigidBodyIndex2 = mRigidBodyComponents.getEntityIndex(externalManifold.bodyEntity2);
// Get the two bodies of the contact
RigidBody* body1 = static_cast<RigidBody*>(mBodyComponents.getBody(externalManifold.bodyEntity1));
RigidBody* body2 = static_cast<RigidBody*>(mBodyComponents.getBody(externalManifold.bodyEntity2));
RigidBody* body1 = mRigidBodyComponents.mRigidBodies[rigidBodyIndex1];
RigidBody* body2 = mRigidBodyComponents.mRigidBodies[rigidBodyIndex2];
assert(body1 != nullptr);
assert(body2 != nullptr);
assert(!mBodyComponents.getIsEntityDisabled(externalManifold.bodyEntity1));
assert(!mBodyComponents.getIsEntityDisabled(externalManifold.bodyEntity2));
const uint rigidBodyIndex1 = mRigidBodyComponents.getEntityIndex(externalManifold.bodyEntity1);
const uint rigidBodyIndex2 = mRigidBodyComponents.getEntityIndex(externalManifold.bodyEntity2);
Collider* collider1 = mColliderComponents.getCollider(externalManifold.colliderEntity1);
Collider* collider2 = mColliderComponents.getCollider(externalManifold.colliderEntity2);