diff --git a/src/collision/shapes/ConcaveMeshShape.cpp b/src/collision/shapes/ConcaveMeshShape.cpp index dd664b04..f017a471 100644 --- a/src/collision/shapes/ConcaveMeshShape.cpp +++ b/src/collision/shapes/ConcaveMeshShape.cpp @@ -35,7 +35,6 @@ using namespace reactphysics3d; // Constructor ConcaveMeshShape::ConcaveMeshShape(TriangleMesh* triangleMesh, MemoryAllocator& allocator, const Vector3& scaling) - // TODO : Do not use the default base allocator here : ConcaveShape(CollisionShapeName::TRIANGLE_MESH), mDynamicAABBTree(allocator), mScaling(scaling) { mTriangleMesh = triangleMesh; diff --git a/src/engine/CollisionWorld.cpp b/src/engine/CollisionWorld.cpp index 7ba4151a..97732177 100644 --- a/src/engine/CollisionWorld.cpp +++ b/src/engine/CollisionWorld.cpp @@ -36,15 +36,15 @@ using namespace std; uint CollisionWorld::mNbWorlds = 0; // Constructor -CollisionWorld::CollisionWorld(const WorldSettings& worldSettings, Logger* logger, Profiler* profiler, MemoryAllocator* baseMemoryAllocator) - : mMemoryManager(baseMemoryAllocator), mConfig(worldSettings), mEntityManager(mMemoryManager.getPoolAllocator()), - mCollisionBodyComponents(mMemoryManager.getBaseAllocator()), mRigidBodyComponents(mMemoryManager.getBaseAllocator()), - mTransformComponents(mMemoryManager.getBaseAllocator()), mProxyShapesComponents(mMemoryManager.getBaseAllocator()), - mJointsComponents(mMemoryManager.getBaseAllocator()), mBallAndSocketJointsComponents(mMemoryManager.getBaseAllocator()), - mFixedJointsComponents(mMemoryManager.getBaseAllocator()), mHingeJointsComponents(mMemoryManager.getBaseAllocator()), - mSliderJointsComponents(mMemoryManager.getBaseAllocator()), +CollisionWorld::CollisionWorld(MemoryManager& memoryManager, const WorldSettings& worldSettings, Logger* logger, Profiler* profiler) + : mMemoryManager(memoryManager), mConfig(worldSettings), mEntityManager(mMemoryManager.getHeapAllocator()), + mCollisionBodyComponents(mMemoryManager.getHeapAllocator()), mRigidBodyComponents(mMemoryManager.getHeapAllocator()), + mTransformComponents(mMemoryManager.getHeapAllocator()), mProxyShapesComponents(mMemoryManager.getHeapAllocator()), + mJointsComponents(mMemoryManager.getHeapAllocator()), mBallAndSocketJointsComponents(mMemoryManager.getHeapAllocator()), + mFixedJointsComponents(mMemoryManager.getHeapAllocator()), mHingeJointsComponents(mMemoryManager.getHeapAllocator()), + mSliderJointsComponents(mMemoryManager.getHeapAllocator()), mCollisionDetection(this, mProxyShapesComponents, mTransformComponents, mCollisionBodyComponents, mRigidBodyComponents, mMemoryManager), - mBodies(mMemoryManager.getPoolAllocator()), mEventListener(nullptr), + mBodies(mMemoryManager.getHeapAllocator()), mEventListener(nullptr), mName(worldSettings.worldName), mIsProfilerCreatedByUser(profiler != nullptr), mIsLoggerCreatedByUser(logger != nullptr) { diff --git a/src/engine/CollisionWorld.h b/src/engine/CollisionWorld.h index 8739f9cf..6259f3f2 100644 --- a/src/engine/CollisionWorld.h +++ b/src/engine/CollisionWorld.h @@ -73,7 +73,7 @@ class CollisionWorld { // -------------------- Attributes -------------------- // /// Memory manager - MemoryManager mMemoryManager; + MemoryManager& mMemoryManager; /// Configuration of the physics world WorldSettings mConfig; @@ -144,8 +144,8 @@ class CollisionWorld { // -------------------- Methods -------------------- // /// Constructor - CollisionWorld(const WorldSettings& worldSettings = WorldSettings(), Logger* logger = nullptr, - Profiler* profiler = nullptr, MemoryAllocator* baseMemoryAllocator = nullptr); + CollisionWorld(MemoryManager& memoryManager, const WorldSettings& worldSettings = WorldSettings(), Logger* logger = nullptr, + Profiler* profiler = nullptr); /// Notify the world if a body is disabled (slepping or inactive) or not void setBodyDisabled(Entity entity, bool isDisabled); diff --git a/src/engine/DynamicsWorld.cpp b/src/engine/DynamicsWorld.cpp index 24e55327..af2e8afa 100644 --- a/src/engine/DynamicsWorld.cpp +++ b/src/engine/DynamicsWorld.cpp @@ -47,8 +47,8 @@ using namespace std; * @param logger Pointer to the logger * @param profiler Pointer to the profiler */ -DynamicsWorld::DynamicsWorld(const Vector3& gravity, const WorldSettings& worldSettings, Logger* logger, Profiler* profiler) - : CollisionWorld(worldSettings, logger, profiler), +DynamicsWorld::DynamicsWorld(const Vector3& gravity, MemoryManager& memoryManager, const WorldSettings& worldSettings, Logger* logger, Profiler* profiler) + : CollisionWorld(memoryManager, worldSettings, logger, profiler), mIslands(mMemoryManager.getSingleFrameAllocator()), mContactSolverSystem(mMemoryManager, *this, mIslands, mCollisionBodyComponents, mRigidBodyComponents, mProxyShapesComponents, mConfig), diff --git a/src/engine/DynamicsWorld.h b/src/engine/DynamicsWorld.h index 549d5573..2f5cc868 100644 --- a/src/engine/DynamicsWorld.h +++ b/src/engine/DynamicsWorld.h @@ -101,7 +101,7 @@ class DynamicsWorld : public CollisionWorld { // -------------------- Methods -------------------- // /// Constructor - DynamicsWorld(const Vector3& mGravity, const WorldSettings& worldSettings = WorldSettings(), + DynamicsWorld(const Vector3& mGravity, MemoryManager& memoryManager, const WorldSettings& worldSettings = WorldSettings(), Logger* logger = nullptr, Profiler* profiler = nullptr); /// Solve the contacts and constraints diff --git a/src/engine/PhysicsCommon.cpp b/src/engine/PhysicsCommon.cpp index 8f72814b..0a29c7d4 100644 --- a/src/engine/PhysicsCommon.cpp +++ b/src/engine/PhysicsCommon.cpp @@ -30,13 +30,12 @@ using namespace reactphysics3d; /// Constructor PhysicsCommon::PhysicsCommon(MemoryAllocator* baseMemoryAllocator) - // TODO : Use Heap allocator for internal Sets<> here instead of Pool allocator - : mMemoryManager(baseMemoryAllocator), mCollisionWorlds(mMemoryManager.getPoolAllocator()), - mDynamicsWorlds(mMemoryManager.getPoolAllocator()), mSphereShapes(mMemoryManager.getPoolAllocator()), - mBoxShapes(mMemoryManager.getPoolAllocator()), mCapsuleShapes(mMemoryManager.getPoolAllocator()), - mConvexMeshShapes(mMemoryManager.getPoolAllocator()), mConcaveMeshShapes(mMemoryManager.getPoolAllocator()), - mHeightFieldShapes(mMemoryManager.getPoolAllocator()), mPolyhedronMeshes(mMemoryManager.getPoolAllocator()), - mTriangleMeshes(mMemoryManager.getPoolAllocator()) { + : mMemoryManager(baseMemoryAllocator), mCollisionWorlds(mMemoryManager.getHeapAllocator()), + mDynamicsWorlds(mMemoryManager.getHeapAllocator()), mSphereShapes(mMemoryManager.getHeapAllocator()), + mBoxShapes(mMemoryManager.getHeapAllocator()), mCapsuleShapes(mMemoryManager.getHeapAllocator()), + mConvexMeshShapes(mMemoryManager.getHeapAllocator()), mConcaveMeshShapes(mMemoryManager.getHeapAllocator()), + mHeightFieldShapes(mMemoryManager.getHeapAllocator()), mPolyhedronMeshes(mMemoryManager.getHeapAllocator()), + mTriangleMeshes(mMemoryManager.getHeapAllocator()) { } @@ -104,8 +103,7 @@ void PhysicsCommon::release() { // Create and return an instance of CollisionWorld CollisionWorld* PhysicsCommon::createCollisionWorld(const WorldSettings& worldSettings, Logger* logger, Profiler* profiler) { - // TODO : Allocate in heap allocator here instead of pool - CollisionWorld* world = new(mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(CollisionWorld))) CollisionWorld(worldSettings, logger, profiler); + CollisionWorld* world = new(mMemoryManager.allocate(MemoryManager::AllocationType::Heap, sizeof(CollisionWorld))) CollisionWorld(mMemoryManager, worldSettings, logger, profiler); mCollisionWorlds.add(world); return world; @@ -118,8 +116,7 @@ void PhysicsCommon::destroyCollisionWorld(CollisionWorld* world) { world->~CollisionWorld(); // Release allocated memory - // TODO : Use Heap allocator for internal Sets<> here instead of Pool allocator - mMemoryManager.release(MemoryManager::AllocationType::Pool, world, sizeof(CollisionWorld)); + mMemoryManager.release(MemoryManager::AllocationType::Heap, world, sizeof(CollisionWorld)); mCollisionWorlds.remove(world); } @@ -128,8 +125,7 @@ void PhysicsCommon::destroyCollisionWorld(CollisionWorld* world) { DynamicsWorld* PhysicsCommon::createDynamicsWorld(const Vector3& gravity, const WorldSettings& worldSettings, Logger* logger, Profiler* profiler) { - // TODO : Allocate in heap allocator here instead of pool - DynamicsWorld* world = new(mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(DynamicsWorld))) DynamicsWorld(gravity, worldSettings, logger, profiler); + DynamicsWorld* world = new(mMemoryManager.allocate(MemoryManager::AllocationType::Heap, sizeof(DynamicsWorld))) DynamicsWorld(gravity, mMemoryManager, worldSettings, logger, profiler); mDynamicsWorlds.add(world); @@ -143,8 +139,7 @@ DynamicsWorld* PhysicsCommon::destroyDynamicsWorld(DynamicsWorld* world) { world->~DynamicsWorld(); // Release allocated memory - // TODO : Use Heap allocator for internal Sets<> here instead of Pool allocator - mMemoryManager.release(MemoryManager::AllocationType::Pool, world, sizeof(DynamicsWorld)); + mMemoryManager.release(MemoryManager::AllocationType::Heap, world, sizeof(DynamicsWorld)); mDynamicsWorlds.remove(world); } @@ -165,7 +160,6 @@ void PhysicsCommon::destroySphereShape(SphereShape* sphereShape) { sphereShape->~SphereShape(); // Release allocated memory - // TODO : Use Heap allocator for internal Sets<> here instead of Pool allocator mMemoryManager.release(MemoryManager::AllocationType::Pool, sphereShape, sizeof(SphereShape)); mSphereShapes.remove(sphereShape); @@ -174,8 +168,7 @@ void PhysicsCommon::destroySphereShape(SphereShape* sphereShape) { // Create and return a box collision shape BoxShape* PhysicsCommon::createBoxShape(const Vector3& extent) { - // TODO : Pass heap allocator here in parameter - BoxShape* shape = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(BoxShape))) BoxShape(extent, mMemoryManager.getPoolAllocator()); + BoxShape* shape = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(BoxShape))) BoxShape(extent, mMemoryManager.getHeapAllocator()); mBoxShapes.add(shape); @@ -189,7 +182,6 @@ void PhysicsCommon::destroyBoxShape(BoxShape* boxShape) { boxShape->~BoxShape(); // Release allocated memory - // TODO : Use Heap allocator for internal Sets<> here instead of Pool allocator mMemoryManager.release(MemoryManager::AllocationType::Pool, boxShape, sizeof(BoxShape)); mBoxShapes.remove(boxShape); @@ -212,7 +204,6 @@ void PhysicsCommon::destroyCapsuleShape(CapsuleShape* capsuleShape) { capsuleShape->~CapsuleShape(); // Release allocated memory - // TODO : Use Heap allocator for internal Sets<> here instead of Pool allocator mMemoryManager.release(MemoryManager::AllocationType::Pool, capsuleShape, sizeof(CapsuleShape)); mCapsuleShapes.remove(capsuleShape); @@ -235,7 +226,6 @@ void PhysicsCommon::destroyConvexMeshShape(ConvexMeshShape* convexMeshShape) { convexMeshShape->~ConvexMeshShape(); // Release allocated memory - // TODO : Use Heap allocator for internal Sets<> here instead of Pool allocator mMemoryManager.release(MemoryManager::AllocationType::Pool, convexMeshShape, sizeof(ConvexMeshShape)); mConvexMeshShapes.remove(convexMeshShape); @@ -261,7 +251,6 @@ void PhysicsCommon::destroyHeightFieldShape(HeightFieldShape* heightFieldShape) heightFieldShape->~HeightFieldShape(); // Release allocated memory - // TODO : Use Heap allocator for internal Sets<> here instead of Pool allocator mMemoryManager.release(MemoryManager::AllocationType::Pool, heightFieldShape, sizeof(HeightFieldShape)); mHeightFieldShapes.remove(heightFieldShape); @@ -270,8 +259,7 @@ void PhysicsCommon::destroyHeightFieldShape(HeightFieldShape* heightFieldShape) // Create and return a concave mesh shape ConcaveMeshShape* PhysicsCommon::createConcaveMeshShape(TriangleMesh* triangleMesh, const Vector3& scaling) { - // TODO : Pass heap allocator here in parameter - ConcaveMeshShape* shape = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(ConcaveMeshShape))) ConcaveMeshShape(triangleMesh, mMemoryManager.getPoolAllocator(), scaling); + ConcaveMeshShape* shape = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(ConcaveMeshShape))) ConcaveMeshShape(triangleMesh, mMemoryManager.getHeapAllocator(), scaling); mConcaveMeshShapes.add(shape); @@ -285,7 +273,6 @@ void PhysicsCommon::destroyConcaveMeshShape(ConcaveMeshShape* concaveMeshShape) concaveMeshShape->~ConcaveMeshShape(); // Release allocated memory - // TODO : Use Heap allocator for internal Sets<> here instead of Pool allocator mMemoryManager.release(MemoryManager::AllocationType::Pool, concaveMeshShape, sizeof(ConcaveMeshShape)); mConcaveMeshShapes.remove(concaveMeshShape); @@ -294,8 +281,7 @@ void PhysicsCommon::destroyConcaveMeshShape(ConcaveMeshShape* concaveMeshShape) // Create a polyhedron mesh PolyhedronMesh* PhysicsCommon::createPolyhedronMesh(PolygonVertexArray* polygonVertexArray) { - // TODO : Pass heap allocator here in parameter - PolyhedronMesh* mesh = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(PolyhedronMesh))) PolyhedronMesh(polygonVertexArray, mMemoryManager.getPoolAllocator()); + PolyhedronMesh* mesh = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(PolyhedronMesh))) PolyhedronMesh(polygonVertexArray, mMemoryManager.getHeapAllocator()); mPolyhedronMeshes.add(mesh); @@ -309,7 +295,6 @@ void PhysicsCommon::destroyPolyhedronMesh(PolyhedronMesh* polyhedronMesh) { polyhedronMesh->~PolyhedronMesh(); // Release allocated memory - // TODO : Use Heap allocator for internal Sets<> here instead of Pool allocator mMemoryManager.release(MemoryManager::AllocationType::Pool, polyhedronMesh, sizeof(PolyhedronMesh)); mPolyhedronMeshes.remove(polyhedronMesh); @@ -318,8 +303,7 @@ void PhysicsCommon::destroyPolyhedronMesh(PolyhedronMesh* polyhedronMesh) { // Create a triangle mesh TriangleMesh* PhysicsCommon::createTriangleMesh() { - // TODO : Pass heap allocator here in parameter - TriangleMesh* mesh = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(TriangleMesh))) TriangleMesh(mMemoryManager.getPoolAllocator()); + TriangleMesh* mesh = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(TriangleMesh))) TriangleMesh(mMemoryManager.getHeapAllocator()); mTriangleMeshes.add(mesh); @@ -333,7 +317,6 @@ void PhysicsCommon::destroyTriangleMesh(TriangleMesh* triangleMesh) { triangleMesh->~TriangleMesh(); // Release allocated memory - // TODO : Use Heap allocator for internal Sets<> here instead of Pool allocator mMemoryManager.release(MemoryManager::AllocationType::Pool, triangleMesh, sizeof(TriangleMesh)); mTriangleMeshes.remove(triangleMesh); diff --git a/src/memory/DefaultAllocator.h b/src/memory/DefaultAllocator.h index ce4d1741..451770f7 100644 --- a/src/memory/DefaultAllocator.h +++ b/src/memory/DefaultAllocator.h @@ -29,6 +29,7 @@ // Libraries #include "memory/MemoryAllocator.h" #include +#include /// ReactPhysics3D namespace namespace reactphysics3d { @@ -51,9 +52,6 @@ class DefaultAllocator : public MemoryAllocator { /// allocated memory. virtual void* allocate(size_t size) override { - // TODO : Make sure to reduce the calls to default allocator is not called within a frame. For instance by a call - // to a pool allocator with size too large - return malloc(size); } diff --git a/src/memory/HeapAllocator.cpp b/src/memory/HeapAllocator.cpp index 2988ab90..d2e2315c 100644 --- a/src/memory/HeapAllocator.cpp +++ b/src/memory/HeapAllocator.cpp @@ -32,23 +32,19 @@ using namespace reactphysics3d; -size_t HeapAllocator::INIT_ALLOCATED_SIZE = 1024; +size_t HeapAllocator::INIT_ALLOCATED_SIZE = 5 * 1048576; // 5 Mb // Constructor -HeapAllocator::HeapAllocator(MemoryAllocator& baseAllocator) +HeapAllocator::HeapAllocator(MemoryAllocator& baseAllocator, size_t initAllocatedMemory) : mBaseAllocator(baseAllocator), mAllocatedMemory(0), mMemoryUnits(nullptr), mCachedFreeUnit(nullptr), - mNbTimesAllocateMethodCalled(0), mDebug(baseAllocator) { + mNbTimesAllocateMethodCalled(0) { - reserve(INIT_ALLOCATED_SIZE); + reserve(initAllocatedMemory == 0 ? INIT_ALLOCATED_SIZE : initAllocatedMemory); } // Destructor HeapAllocator::~HeapAllocator() { - for (auto it = mDebug.begin(); it != mDebug.end(); ++it) { - std::cout << "Size: " << (*it).first << " -> " << (*it).second << std::endl; - } - #ifndef NDEBUG // Check that the allocate() and release() methods have been called the same // number of times to avoid memory leaks. @@ -113,13 +109,6 @@ void* HeapAllocator::allocate(size_t size) { // We cannot allocate zero bytes if (size == 0) return nullptr; - if (mDebug.containsKey(size)) { - mDebug[size]++; - } - else { - mDebug.add(Pair(size, 1)); - } - #ifndef NDEBUG mNbTimesAllocateMethodCalled++; #endif @@ -189,11 +178,6 @@ void HeapAllocator::release(void* pointer, size_t size) { // Cannot release a 0-byte allocated memory if (size == 0) return; - mDebug[size]--; - if (mDebug[size] == 0) { - mDebug.remove(size); - } - #ifndef NDEBUG mNbTimesAllocateMethodCalled--; #endif diff --git a/src/memory/HeapAllocator.h b/src/memory/HeapAllocator.h index 28f4e268..437fb3dd 100644 --- a/src/memory/HeapAllocator.h +++ b/src/memory/HeapAllocator.h @@ -100,9 +100,6 @@ class HeapAllocator : public MemoryAllocator { /// Pointer to a cached free memory unit MemoryUnitHeader* mCachedFreeUnit; - // TODO : REMOVE THIS - Map mDebug; - #ifndef NDEBUG /// This variable is incremented by one when the allocate() method has been /// called and decreased by one when the release() method has been called. @@ -125,7 +122,7 @@ class HeapAllocator : public MemoryAllocator { // -------------------- Methods -------------------- // /// Constructor - HeapAllocator(MemoryAllocator& baseAllocator); + HeapAllocator(MemoryAllocator& baseAllocator, size_t initAllocatedMemory = 0); /// Destructor virtual ~HeapAllocator() override; diff --git a/src/memory/MemoryManager.cpp b/src/memory/MemoryManager.cpp index 3590d6d0..a5aff544 100644 --- a/src/memory/MemoryManager.cpp +++ b/src/memory/MemoryManager.cpp @@ -29,9 +29,9 @@ using namespace reactphysics3d; // Constructor -MemoryManager::MemoryManager(MemoryAllocator* baseAllocator) : +MemoryManager::MemoryManager(MemoryAllocator* baseAllocator, size_t initAllocatedMemory) : mBaseAllocator(baseAllocator == nullptr ? &mDefaultAllocator : baseAllocator), - mHeapAllocator(*mBaseAllocator), + mHeapAllocator(*mBaseAllocator, initAllocatedMemory), mPoolAllocator(mHeapAllocator), mSingleFrameAllocator(mHeapAllocator) { diff --git a/src/memory/MemoryManager.h b/src/memory/MemoryManager.h index 1dd05076..838c0ca0 100644 --- a/src/memory/MemoryManager.h +++ b/src/memory/MemoryManager.h @@ -72,11 +72,12 @@ class MemoryManager { enum class AllocationType { Base, // Base memory allocator Pool, // Memory pool allocator + Heap, // Memory pool allocator Frame, // Single frame memory allocator }; /// Constructor - MemoryManager(MemoryAllocator* baseAllocator); + MemoryManager(MemoryAllocator* baseAllocator, size_t initAllocatedMemory = 0); /// Destructor ~MemoryManager() = default; @@ -93,8 +94,8 @@ class MemoryManager { /// Return the single frame stack allocator SingleFrameAllocator& getSingleFrameAllocator(); - /// Return the base memory allocator - MemoryAllocator& getBaseAllocator(); + /// Return the heap allocator + HeapAllocator& getHeapAllocator(); /// Reset the single frame allocator void resetFrameAllocator(); @@ -106,6 +107,7 @@ inline void* MemoryManager::allocate(AllocationType allocationType, size_t size) switch (allocationType) { case AllocationType::Base: return mBaseAllocator->allocate(size); case AllocationType::Pool: return mPoolAllocator.allocate(size); + case AllocationType::Heap: return mHeapAllocator.allocate(size); case AllocationType::Frame: return mSingleFrameAllocator.allocate(size); } @@ -118,6 +120,7 @@ inline void MemoryManager::release(AllocationType allocationType, void* pointer, switch (allocationType) { case AllocationType::Base: mBaseAllocator->release(pointer, size); break; case AllocationType::Pool: mPoolAllocator.release(pointer, size); break; + case AllocationType::Heap: mHeapAllocator.release(pointer, size); break; case AllocationType::Frame: mSingleFrameAllocator.release(pointer, size); break; } } @@ -132,9 +135,9 @@ inline SingleFrameAllocator& MemoryManager::getSingleFrameAllocator() { return mSingleFrameAllocator; } -// Return the base memory allocator -inline MemoryAllocator& MemoryManager::getBaseAllocator() { - return *mBaseAllocator; +// Return the heap allocator +inline HeapAllocator& MemoryManager::getHeapAllocator() { + return mHeapAllocator; } // Reset the single frame allocator diff --git a/src/systems/CollisionDetectionSystem.cpp b/src/systems/CollisionDetectionSystem.cpp index 0da6697a..c5db7a48 100644 --- a/src/systems/CollisionDetectionSystem.cpp +++ b/src/systems/CollisionDetectionSystem.cpp @@ -61,7 +61,6 @@ CollisionDetectionSystem::CollisionDetectionSystem(CollisionWorld* world, ProxyS mBroadPhaseSystem(*this, mProxyShapesComponents, transformComponents, rigidBodyComponents), mMapBroadPhaseIdToProxyShapeEntity(memoryManager.getPoolAllocator()), mNarrowPhaseInput(mMemoryManager.getSingleFrameAllocator(), mOverlappingPairs), mPotentialContactPoints(mMemoryManager.getSingleFrameAllocator()), - // TODO : We should probably use single frame allocator for mPotentialContactPoints, mPotentialContactManifolds, mMapPairIdToOverlappingPairContacts mPotentialContactManifolds(mMemoryManager.getSingleFrameAllocator()), mContactPairs1(mMemoryManager.getPoolAllocator()), mContactPairs2(mMemoryManager.getPoolAllocator()), mPreviousContactPairs(&mContactPairs1), mCurrentContactPairs(&mContactPairs2), mMapPairIdToContactPairIndex1(mMemoryManager.getPoolAllocator()), mMapPairIdToContactPairIndex2(mMemoryManager.getPoolAllocator()), @@ -582,7 +581,7 @@ bool CollisionDetectionSystem::computeNarrowPhaseCollisionSnapshot(NarrowPhaseIn RP3D_PROFILE("CollisionDetectionSystem::computeNarrowPhaseCollisionSnapshot()", mProfiler); - MemoryAllocator& allocator = mMemoryManager.getPoolAllocator(); + MemoryAllocator& allocator = mMemoryManager.getHeapAllocator(); // Test the narrow-phase collision detection on the batches to be tested bool collisionFound = testNarrowPhaseCollision(narrowPhaseInput, true, false, allocator); @@ -928,8 +927,6 @@ void CollisionDetectionSystem::processPotentialContacts(NarrowPhaseInfoBatch& na // Add the contact point to the list of potential contact points const uint contactPointIndex = static_cast(potentialContactPoints.size()); - // TODO : We should probably use single frame allocator here for potentialContactPoints - // If so, do not forget to call potentialContactPoints.clear(true) at the end of frame potentialContactPoints.add(contactPoint); bool similarManifoldFound = false; @@ -975,8 +972,6 @@ void CollisionDetectionSystem::processPotentialContacts(NarrowPhaseInfoBatch& na if (!similarManifoldFound) { // Create a new contact manifold for the overlapping pair - // TODO : We should probably use single frame allocator here - // If so, do not forget to call potentialContactPoints.clear(true) at the end of frame ContactManifoldInfo contactManifoldInfo(pairId, mMemoryManager.getPoolAllocator()); // Add the contact point to the manifold @@ -993,11 +988,10 @@ void CollisionDetectionSystem::processPotentialContacts(NarrowPhaseInfoBatch& na assert(!mWorld->mCollisionBodyComponents.getIsEntityDisabled(body1Entity) || !mWorld->mCollisionBodyComponents.getIsEntityDisabled(body2Entity)); - // TODO : We should probably use a single frame allocator here const uint newContactPairIndex = contactPairs->size(); ContactPair overlappingPairContact(pairId, body1Entity, body2Entity, proxyShape1Entity, proxyShape2Entity, - newContactPairIndex, mMemoryManager.getPoolAllocator()); + newContactPairIndex, mMemoryManager.getHeapAllocator()); contactPairs->add(overlappingPairContact); pairContact = &((*contactPairs)[newContactPairIndex]); mapPairIdToContactPairIndex->add(Pair(pairId, newContactPairIndex)); diff --git a/test/tests/collision/TestPointInside.h b/test/tests/collision/TestPointInside.h index ba545181..cecc6656 100644 --- a/test/tests/collision/TestPointInside.h +++ b/test/tests/collision/TestPointInside.h @@ -181,9 +181,9 @@ class TestPointInside : public Test { mPhysicsCommon.destroyCapsuleShape(mCapsuleShape); mPhysicsCommon.destroyConvexMeshShape(mConvexMeshShape); mPhysicsCommon.destroyCollisionWorld(mWorld); + mPhysicsCommon.destroyPolyhedronMesh(mConvexMeshPolyhedronMesh); delete[] mConvexMeshPolygonFaces; delete mConvexMeshPolygonVertexArray; - delete mConvexMeshPolyhedronMesh; } /// Run the tests diff --git a/test/tests/collision/TestRaycast.h b/test/tests/collision/TestRaycast.h index 09e3aba8..ae14883b 100644 --- a/test/tests/collision/TestRaycast.h +++ b/test/tests/collision/TestRaycast.h @@ -279,6 +279,7 @@ class TestRaycast : public Test { vertexType, TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE); // Add the triangle vertex array of the subpart to the triangle mesh + mConcaveTriangleMesh = mPhysicsCommon.createTriangleMesh(); mConcaveTriangleMesh->addSubpart(mConcaveMeshVertexArray); mConcaveMeshShape = mPhysicsCommon.createConcaveMeshShape(mConcaveTriangleMesh); mConcaveMeshProxyShape = mConcaveMeshBody->addCollisionShape(mConcaveMeshShape, mShapeTransform); @@ -314,7 +315,7 @@ class TestRaycast : public Test { delete mConcaveMeshVertexArray; delete mPolygonVertexArray; - delete mPolyhedronMesh; + mPhysicsCommon.destroyPolyhedronMesh(mPolyhedronMesh); } /// Run the tests