Modifs in NarrowPhaseBatch info classes

This commit is contained in:
Daniel Chappuis 2018-12-01 13:17:32 +01:00
parent 05d05c3fd8
commit 6e67b83ca4
9 changed files with 52 additions and 21 deletions

View File

@ -64,7 +64,12 @@ void CapsuleVsCapsuleNarrowPhaseInfoBatch::addNarrowPhaseInfo(OverlappingPair* p
// Initialize the containers using cached capacity
void CapsuleVsCapsuleNarrowPhaseInfoBatch::reserveMemory() {
NarrowPhaseInfoBatch::reserveMemory();
overlappingPairs.reserve(mCachedCapacity);
shape1ToWorldTransforms.reserve(mCachedCapacity);
shape2ToWorldTransforms.reserve(mCachedCapacity);
lastFrameCollisionInfos.reserve(mCachedCapacity);
isColliding.reserve(mCachedCapacity);
contactPoints.reserve(mCachedCapacity);
capsule1Radiuses.reserve(mCachedCapacity);
capsule2Radiuses.reserve(mCachedCapacity);
@ -75,13 +80,20 @@ void CapsuleVsCapsuleNarrowPhaseInfoBatch::reserveMemory() {
// Clear all the objects in the batch
void CapsuleVsCapsuleNarrowPhaseInfoBatch::clear() {
NarrowPhaseInfoBatch::clear();
// Note that we clear the following containers and we release their allocated memory. Therefore,
// if the memory allocator is a single frame allocator, the memory is deallocated and will be
// allocated in the next frame at a possibly different location in memory (remember that the
// location of the allocated memory of a single frame allocator might change between two frames)
mCachedCapacity = overlappingPairs.size();
overlappingPairs.clear(true);
shape1ToWorldTransforms.clear(true);
shape2ToWorldTransforms.clear(true);
lastFrameCollisionInfos.clear(true);
isColliding.clear(true);
contactPoints.clear(true);
capsule1Radiuses.clear(true);
capsule2Radiuses.clear(true);
capsule1Heights.clear(true);

View File

@ -66,7 +66,7 @@ struct CapsuleVsCapsuleNarrowPhaseInfoBatch : public NarrowPhaseInfoBatch {
const Transform& shape2Transform);
// Initialize the containers using cached capacity
void reserveMemory();
virtual void reserveMemory();
/// Clear all the objects in the batch
virtual void clear();

View File

@ -59,7 +59,6 @@ class NarrowPhaseCallback {
};
// TODO DOD : Try to delete this class
// Class NarrowPhaseAlgorithm
/**
* This abstract class is the base class for a narrow-phase collision

View File

@ -125,7 +125,6 @@ void NarrowPhaseInfoBatch::clear() {
// Release the memory of the TriangleShape (this memory was allocated in the
// MiddlePhaseTriangleCallback::testTriangle() method)
// TODO DOD : Try to move this code
if (collisionShapes1.size() > 0 && collisionShapes1[i]->getName() == CollisionShapeName::TRIANGLE) {
collisionShapes1[i]->~CollisionShape();
collisionShapeAllocators[i]->release(collisionShapes1[i], sizeof(TriangleShape));

View File

@ -57,8 +57,6 @@ struct NarrowPhaseInfoBatch {
public:
// TODO DOD : Try to remove most of the following lists
/// List of Broadphase overlapping pairs
List<OverlappingPair*> overlappingPairs;
@ -96,20 +94,19 @@ struct NarrowPhaseInfoBatch {
uint getNbObjects() const;
/// Add shapes to be tested during narrow-phase collision detection into the batch
// TODO DOD : Remove this method (only use the one in specialized classed)
void addNarrowPhaseInfo(OverlappingPair* pair, CollisionShape* shape1,
CollisionShape* shape2, const Transform& shape1Transform,
const Transform& shape2Transform, MemoryAllocator& shapeAllocator);
/// Add a new contact point
void addContactPoint(uint index, const Vector3& contactNormal, decimal penDepth,
virtual void addContactPoint(uint index, const Vector3& contactNormal, decimal penDepth,
const Vector3& localPt1, const Vector3& localPt2);
/// Reset the remaining contact points
void resetContactPoints(uint index);
// Initialize the containers using cached capacity
void reserveMemory();
virtual void reserveMemory();
/// Clear all the objects in the batch
virtual void clear();

View File

@ -67,7 +67,12 @@ void SphereVsCapsuleNarrowPhaseInfoBatch::addNarrowPhaseInfo(OverlappingPair* pa
// Initialize the containers using cached capacity
void SphereVsCapsuleNarrowPhaseInfoBatch::reserveMemory() {
NarrowPhaseInfoBatch::reserveMemory();
overlappingPairs.reserve(mCachedCapacity);
shape1ToWorldTransforms.reserve(mCachedCapacity);
shape2ToWorldTransforms.reserve(mCachedCapacity);
lastFrameCollisionInfos.reserve(mCachedCapacity);
isColliding.reserve(mCachedCapacity);
contactPoints.reserve(mCachedCapacity);
isSpheresShape1.reserve(mCachedCapacity);
sphereRadiuses.reserve(mCachedCapacity);
@ -78,13 +83,20 @@ void SphereVsCapsuleNarrowPhaseInfoBatch::reserveMemory() {
// Clear all the objects in the batch
void SphereVsCapsuleNarrowPhaseInfoBatch::clear() {
NarrowPhaseInfoBatch::clear();
// Note that we clear the following containers and we release their allocated memory. Therefore,
// if the memory allocator is a single frame allocator, the memory is deallocated and will be
// allocated in the next frame at a possibly different location in memory (remember that the
// location of the allocated memory of a single frame allocator might change between two frames)
mCachedCapacity = overlappingPairs.size();
overlappingPairs.clear(true);
shape1ToWorldTransforms.clear(true);
shape2ToWorldTransforms.clear(true);
lastFrameCollisionInfos.clear(true);
isColliding.clear(true);
contactPoints.clear(true);
isSpheresShape1.clear(true);
sphereRadiuses.clear(true);
capsuleRadiuses.clear(true);

View File

@ -66,7 +66,7 @@ struct SphereVsCapsuleNarrowPhaseInfoBatch : public NarrowPhaseInfoBatch {
const Transform& shape2Transform);
// Initialize the containers using cached capacity
void reserveMemory();
virtual void reserveMemory();
/// Clear all the objects in the batch
virtual void clear();

View File

@ -61,7 +61,12 @@ void SphereVsSphereNarrowPhaseInfoBatch::addNarrowPhaseInfo(OverlappingPair* pai
// Initialize the containers using cached capacity
void SphereVsSphereNarrowPhaseInfoBatch::reserveMemory() {
NarrowPhaseInfoBatch::reserveMemory();
overlappingPairs.reserve(mCachedCapacity);
shape1ToWorldTransforms.reserve(mCachedCapacity);
shape2ToWorldTransforms.reserve(mCachedCapacity);
lastFrameCollisionInfos.reserve(mCachedCapacity);
isColliding.reserve(mCachedCapacity);
contactPoints.reserve(mCachedCapacity);
sphere1Radiuses.reserve(mCachedCapacity);
sphere2Radiuses.reserve(mCachedCapacity);
@ -70,13 +75,20 @@ void SphereVsSphereNarrowPhaseInfoBatch::reserveMemory() {
// Clear all the objects in the batch
void SphereVsSphereNarrowPhaseInfoBatch::clear() {
NarrowPhaseInfoBatch::clear();
// Note that we clear the following containers and we release their allocated memory. Therefore,
// if the memory allocator is a single frame allocator, the memory is deallocated and will be
// allocated in the next frame at a possibly different location in memory (remember that the
// location of the allocated memory of a single frame allocator might change between two frames)
mCachedCapacity = overlappingPairs.size();
overlappingPairs.clear(true);
shape1ToWorldTransforms.clear(true);
shape2ToWorldTransforms.clear(true);
lastFrameCollisionInfos.clear(true);
isColliding.clear(true);
contactPoints.clear(true);
sphere1Radiuses.clear(true);
sphere2Radiuses.clear(true);
}

View File

@ -52,7 +52,7 @@ struct SphereVsSphereNarrowPhaseInfoBatch : public NarrowPhaseInfoBatch {
SphereVsSphereNarrowPhaseInfoBatch(MemoryAllocator& allocator);
/// Destructor
virtual ~SphereVsSphereNarrowPhaseInfoBatch() = default;
virtual ~SphereVsSphereNarrowPhaseInfoBatch() override = default;
/// Add shapes to be tested during narrow-phase collision detection into the batch
virtual void addNarrowPhaseInfo(OverlappingPair* pair, CollisionShape* shape1,
@ -60,10 +60,10 @@ struct SphereVsSphereNarrowPhaseInfoBatch : public NarrowPhaseInfoBatch {
const Transform& shape2Transform);
// Initialize the containers using cached capacity
void reserveMemory();
virtual void reserveMemory() override;
/// Clear all the objects in the batch
virtual void clear();
virtual void clear() override;
};
}