From 119ef24d5def7f688611af1a7ea3bd2240c63110 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 22 Mar 2016 11:41:45 -0700 Subject: [PATCH] cleanup ShapeManager API and fix bitrot in tests --- libraries/physics/src/ShapeManager.cpp | 8 ++------ libraries/physics/src/ShapeManager.h | 5 ++--- tests/physics/src/BulletTestUtils.h | 2 ++ tests/physics/src/ShapeManagerTests.cpp | 8 ++++---- tests/physics/src/ShapeManagerTests.h | 2 +- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/libraries/physics/src/ShapeManager.cpp b/libraries/physics/src/ShapeManager.cpp index 7a3065dfff..e9430b36db 100644 --- a/libraries/physics/src/ShapeManager.cpp +++ b/libraries/physics/src/ShapeManager.cpp @@ -58,7 +58,7 @@ btCollisionShape* ShapeManager::getShape(const ShapeInfo& info) { } // private helper method -bool ShapeManager::releaseShape(const DoubleHashKey& key) { +bool ShapeManager::releaseShapeByKey(const DoubleHashKey& key) { ShapeReference* shapeRef = _shapeMap.find(key); if (shapeRef) { if (shapeRef->refCount > 0) { @@ -82,16 +82,12 @@ bool ShapeManager::releaseShape(const DoubleHashKey& key) { return false; } -bool ShapeManager::releaseShape(const ShapeInfo& info) { - return releaseShape(info.getHash()); -} - bool ShapeManager::releaseShape(const btCollisionShape* shape) { int numShapes = _shapeMap.size(); for (int i = 0; i < numShapes; ++i) { ShapeReference* shapeRef = _shapeMap.getAtIndex(i); if (shape == shapeRef->shape) { - return releaseShape(shapeRef->key); + return releaseShapeByKey(shapeRef->key); } } return false; diff --git a/libraries/physics/src/ShapeManager.h b/libraries/physics/src/ShapeManager.h index e04fa1280c..0c411f5f62 100644 --- a/libraries/physics/src/ShapeManager.h +++ b/libraries/physics/src/ShapeManager.h @@ -29,7 +29,6 @@ public: btCollisionShape* getShape(const ShapeInfo& info); /// \return true if shape was found and released - bool releaseShape(const ShapeInfo& info); bool releaseShape(const btCollisionShape* shape); /// delete shapes that have zero references @@ -39,10 +38,10 @@ public: int getNumShapes() const { return _shapeMap.size(); } int getNumReferences(const ShapeInfo& info) const; int getNumReferences(const btCollisionShape* shape) const; - bool hasShape(const btCollisionShape* shape) const; + bool hasShape(const btCollisionShape* shape) const; private: - bool releaseShape(const DoubleHashKey& key); + bool releaseShapeByKey(const DoubleHashKey& key); struct ShapeReference { int refCount; diff --git a/tests/physics/src/BulletTestUtils.h b/tests/physics/src/BulletTestUtils.h index 9166f80ba1..c047a2c1ce 100644 --- a/tests/physics/src/BulletTestUtils.h +++ b/tests/physics/src/BulletTestUtils.h @@ -14,6 +14,8 @@ #include +#include + // Implements functionality in QTestExtensions.h for glm types // There are 3 functions in here (which need to be defined for all types that use them): // diff --git a/tests/physics/src/ShapeManagerTests.cpp b/tests/physics/src/ShapeManagerTests.cpp index 1ee7cd561e..75ad8b3d3a 100644 --- a/tests/physics/src/ShapeManagerTests.cpp +++ b/tests/physics/src/ShapeManagerTests.cpp @@ -21,7 +21,7 @@ void ShapeManagerTests::testShapeAccounting() { ShapeManager shapeManager; ShapeInfo info; info.setBox(glm::vec3(1.0f, 1.0f, 1.0f)); - + int numReferences = shapeManager.getNumReferences(info); QCOMPARE(numReferences, 0); @@ -42,10 +42,10 @@ void ShapeManagerTests::testShapeAccounting() { QCOMPARE(numReferences, expectedNumReferences); // release all references - bool released = shapeManager.releaseShape(info); + bool released = shapeManager.releaseShape(shape); numReferences--; while (numReferences > 0) { - released = shapeManager.releaseShape(info) && released; + released = shapeManager.releaseShape(shape) && released; numReferences--; } QCOMPARE(released, true); @@ -69,7 +69,7 @@ void ShapeManagerTests::testShapeAccounting() { QCOMPARE(numReferences, 1); // release reference and verify that it is collected as garbage - released = shapeManager.releaseShape(info); + released = shapeManager.releaseShape(shape); shapeManager.collectGarbage(); QCOMPARE(shapeManager.getNumShapes(), 0); QCOMPARE(shapeManager.hasShape(shape), false); diff --git a/tests/physics/src/ShapeManagerTests.h b/tests/physics/src/ShapeManagerTests.h index a4b7fbecd1..1dac307413 100644 --- a/tests/physics/src/ShapeManagerTests.h +++ b/tests/physics/src/ShapeManagerTests.h @@ -16,7 +16,7 @@ class ShapeManagerTests : public QObject { Q_OBJECT - + private slots: void testShapeAccounting(); void addManyShapes();