mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 10:13:15 +02:00
cleanup ShapeManager API and fix bitrot in tests
This commit is contained in:
parent
a52ac3cc50
commit
119ef24d5d
5 changed files with 11 additions and 14 deletions
|
@ -58,7 +58,7 @@ btCollisionShape* ShapeManager::getShape(const ShapeInfo& info) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// private helper method
|
// private helper method
|
||||||
bool ShapeManager::releaseShape(const DoubleHashKey& key) {
|
bool ShapeManager::releaseShapeByKey(const DoubleHashKey& key) {
|
||||||
ShapeReference* shapeRef = _shapeMap.find(key);
|
ShapeReference* shapeRef = _shapeMap.find(key);
|
||||||
if (shapeRef) {
|
if (shapeRef) {
|
||||||
if (shapeRef->refCount > 0) {
|
if (shapeRef->refCount > 0) {
|
||||||
|
@ -82,16 +82,12 @@ bool ShapeManager::releaseShape(const DoubleHashKey& key) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShapeManager::releaseShape(const ShapeInfo& info) {
|
|
||||||
return releaseShape(info.getHash());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ShapeManager::releaseShape(const btCollisionShape* shape) {
|
bool ShapeManager::releaseShape(const btCollisionShape* shape) {
|
||||||
int numShapes = _shapeMap.size();
|
int numShapes = _shapeMap.size();
|
||||||
for (int i = 0; i < numShapes; ++i) {
|
for (int i = 0; i < numShapes; ++i) {
|
||||||
ShapeReference* shapeRef = _shapeMap.getAtIndex(i);
|
ShapeReference* shapeRef = _shapeMap.getAtIndex(i);
|
||||||
if (shape == shapeRef->shape) {
|
if (shape == shapeRef->shape) {
|
||||||
return releaseShape(shapeRef->key);
|
return releaseShapeByKey(shapeRef->key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -29,7 +29,6 @@ public:
|
||||||
btCollisionShape* getShape(const ShapeInfo& info);
|
btCollisionShape* getShape(const ShapeInfo& info);
|
||||||
|
|
||||||
/// \return true if shape was found and released
|
/// \return true if shape was found and released
|
||||||
bool releaseShape(const ShapeInfo& info);
|
|
||||||
bool releaseShape(const btCollisionShape* shape);
|
bool releaseShape(const btCollisionShape* shape);
|
||||||
|
|
||||||
/// delete shapes that have zero references
|
/// delete shapes that have zero references
|
||||||
|
@ -39,10 +38,10 @@ public:
|
||||||
int getNumShapes() const { return _shapeMap.size(); }
|
int getNumShapes() const { return _shapeMap.size(); }
|
||||||
int getNumReferences(const ShapeInfo& info) const;
|
int getNumReferences(const ShapeInfo& info) const;
|
||||||
int getNumReferences(const btCollisionShape* shape) const;
|
int getNumReferences(const btCollisionShape* shape) const;
|
||||||
bool hasShape(const btCollisionShape* shape) const;
|
bool hasShape(const btCollisionShape* shape) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool releaseShape(const DoubleHashKey& key);
|
bool releaseShapeByKey(const DoubleHashKey& key);
|
||||||
|
|
||||||
struct ShapeReference {
|
struct ShapeReference {
|
||||||
int refCount;
|
int refCount;
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include <BulletUtil.h>
|
#include <BulletUtil.h>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
// Implements functionality in QTestExtensions.h for glm types
|
// 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):
|
// There are 3 functions in here (which need to be defined for all types that use them):
|
||||||
//
|
//
|
||||||
|
|
|
@ -21,7 +21,7 @@ void ShapeManagerTests::testShapeAccounting() {
|
||||||
ShapeManager shapeManager;
|
ShapeManager shapeManager;
|
||||||
ShapeInfo info;
|
ShapeInfo info;
|
||||||
info.setBox(glm::vec3(1.0f, 1.0f, 1.0f));
|
info.setBox(glm::vec3(1.0f, 1.0f, 1.0f));
|
||||||
|
|
||||||
int numReferences = shapeManager.getNumReferences(info);
|
int numReferences = shapeManager.getNumReferences(info);
|
||||||
QCOMPARE(numReferences, 0);
|
QCOMPARE(numReferences, 0);
|
||||||
|
|
||||||
|
@ -42,10 +42,10 @@ void ShapeManagerTests::testShapeAccounting() {
|
||||||
QCOMPARE(numReferences, expectedNumReferences);
|
QCOMPARE(numReferences, expectedNumReferences);
|
||||||
|
|
||||||
// release all references
|
// release all references
|
||||||
bool released = shapeManager.releaseShape(info);
|
bool released = shapeManager.releaseShape(shape);
|
||||||
numReferences--;
|
numReferences--;
|
||||||
while (numReferences > 0) {
|
while (numReferences > 0) {
|
||||||
released = shapeManager.releaseShape(info) && released;
|
released = shapeManager.releaseShape(shape) && released;
|
||||||
numReferences--;
|
numReferences--;
|
||||||
}
|
}
|
||||||
QCOMPARE(released, true);
|
QCOMPARE(released, true);
|
||||||
|
@ -69,7 +69,7 @@ void ShapeManagerTests::testShapeAccounting() {
|
||||||
QCOMPARE(numReferences, 1);
|
QCOMPARE(numReferences, 1);
|
||||||
|
|
||||||
// release reference and verify that it is collected as garbage
|
// release reference and verify that it is collected as garbage
|
||||||
released = shapeManager.releaseShape(info);
|
released = shapeManager.releaseShape(shape);
|
||||||
shapeManager.collectGarbage();
|
shapeManager.collectGarbage();
|
||||||
QCOMPARE(shapeManager.getNumShapes(), 0);
|
QCOMPARE(shapeManager.getNumShapes(), 0);
|
||||||
QCOMPARE(shapeManager.hasShape(shape), false);
|
QCOMPARE(shapeManager.hasShape(shape), false);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
class ShapeManagerTests : public QObject {
|
class ShapeManagerTests : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void testShapeAccounting();
|
void testShapeAccounting();
|
||||||
void addManyShapes();
|
void addManyShapes();
|
||||||
|
|
Loading…
Reference in a new issue