Add an overlapping pair
| 395 | |
| 396 | // Add an overlapping pair |
| 397 | uint64 OverlappingPairs::addPair(uint32 collider1Index, uint32 collider2Index, bool isConvexVsConvex) { |
| 398 | |
| 399 | RP3D_PROFILE("OverlappingPairs::addPair()", mProfiler); |
| 400 | |
| 401 | assert(mColliderComponents.mBroadPhaseIds[collider1Index] >= 0 && mColliderComponents.mBroadPhaseIds[collider2Index] >= 0); |
| 402 | |
| 403 | const CollisionShape* collisionShape1 = mColliderComponents.mCollisionShapes[collider1Index]; |
| 404 | const CollisionShape* collisionShape2 = mColliderComponents.mCollisionShapes[collider2Index]; |
| 405 | |
| 406 | const Entity collider1Entity = mColliderComponents.mCollidersEntities[collider1Index]; |
| 407 | const Entity collider2Entity = mColliderComponents.mCollidersEntities[collider2Index]; |
| 408 | |
| 409 | const uint32 broadPhase1Id = static_cast<uint32>(mColliderComponents.mBroadPhaseIds[collider1Index]); |
| 410 | const uint32 broadPhase2Id = static_cast<uint32>(mColliderComponents.mBroadPhaseIds[collider2Index]); |
| 411 | |
| 412 | // Compute a unique id for the overlapping pair |
| 413 | const uint64 pairId = pairNumbers(std::max(broadPhase1Id, broadPhase2Id), std::min(broadPhase1Id, broadPhase2Id)); |
| 414 | |
| 415 | // Select the narrow phase algorithm to use according to the two collision shapes |
| 416 | if (isConvexVsConvex) { |
| 417 | |
| 418 | assert(!mMapConvexPairIdToPairIndex.containsKey(pairId)); |
| 419 | NarrowPhaseAlgorithmType algorithmType = mCollisionDispatch.selectNarrowPhaseAlgorithm(collisionShape1->getType(), collisionShape2->getType()); |
| 420 | |
| 421 | // Map the entity with the new component lookup index |
| 422 | mMapConvexPairIdToPairIndex.add(Pair<uint64, uint64>(pairId, mConvexPairs.size())); |
| 423 | |
| 424 | // Create and add a new convex pair |
| 425 | mConvexPairs.emplace(pairId, broadPhase1Id, broadPhase2Id, collider1Entity, collider2Entity, algorithmType, true); |
| 426 | } |
| 427 | else { |
| 428 | |
| 429 | const bool isShape1Convex = collisionShape1->isConvex(); |
| 430 | |
| 431 | assert(!mMapConcavePairIdToPairIndex.containsKey(pairId)); |
| 432 | NarrowPhaseAlgorithmType algorithmType = mCollisionDispatch.selectNarrowPhaseAlgorithm(isShape1Convex ? collisionShape1->getType() : collisionShape2->getType(), |
| 433 | CollisionShapeType::CONVEX_POLYHEDRON); |
| 434 | // Map the entity with the new component lookup index |
| 435 | mMapConcavePairIdToPairIndex.add(Pair<uint64, uint64>(pairId, mConcavePairs.size())); |
| 436 | |
| 437 | // Create and add a new concave pair |
| 438 | mConcavePairs.emplace(pairId, broadPhase1Id, broadPhase2Id, collider1Entity, collider2Entity, algorithmType, |
| 439 | isShape1Convex, mPoolAllocator, mHeapAllocator, true); |
| 440 | } |
| 441 | |
| 442 | // Add the involved overlapping pair to the two colliders |
| 443 | assert(mColliderComponents.mOverlappingPairs[collider1Index].find(pairId) == mColliderComponents.mOverlappingPairs[collider1Index].end()); |
| 444 | assert(mColliderComponents.mOverlappingPairs[collider2Index].find(pairId) == mColliderComponents.mOverlappingPairs[collider2Index].end()); |
| 445 | mColliderComponents.mOverlappingPairs[collider1Index].add(pairId); |
| 446 | mColliderComponents.mOverlappingPairs[collider2Index].add(pairId); |
| 447 | |
| 448 | return pairId; |
| 449 | } |
| 450 | |
| 451 | // Delete all the obsolete last frame collision info |
| 452 | void OverlappingPairs::clearObsoleteLastFrameCollisionInfos() { |
no test coverage detected