mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:37:51 +02:00
more robust ShapeManager garbage collector
This commit is contained in:
parent
10e5e9e0c3
commit
17ab0cb92e
3 changed files with 13 additions and 3 deletions
|
@ -57,7 +57,14 @@ bool ShapeManager::releaseShapeByKey(const HashKey& key) {
|
||||||
if (shapeRef->refCount > 0) {
|
if (shapeRef->refCount > 0) {
|
||||||
shapeRef->refCount--;
|
shapeRef->refCount--;
|
||||||
if (shapeRef->refCount == 0) {
|
if (shapeRef->refCount == 0) {
|
||||||
_pendingGarbage.push_back(key);
|
// look for existing entry in _pendingGarbage, starting from the back
|
||||||
|
for (int32_t i = _pendingGarbage.size() - 1; i > -1; --i) {
|
||||||
|
if (_pendingGarbage[i] == key.getHash64()) {
|
||||||
|
// already on the list, don't add it again
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_pendingGarbage.push_back(key.getHash64());
|
||||||
const int MAX_SHAPE_GARBAGE_CAPACITY = 255;
|
const int MAX_SHAPE_GARBAGE_CAPACITY = 255;
|
||||||
if (_pendingGarbage.size() > MAX_SHAPE_GARBAGE_CAPACITY) {
|
if (_pendingGarbage.size() > MAX_SHAPE_GARBAGE_CAPACITY) {
|
||||||
collectGarbage();
|
collectGarbage();
|
||||||
|
@ -89,7 +96,7 @@ bool ShapeManager::releaseShape(const btCollisionShape* shape) {
|
||||||
void ShapeManager::collectGarbage() {
|
void ShapeManager::collectGarbage() {
|
||||||
int numShapes = _pendingGarbage.size();
|
int numShapes = _pendingGarbage.size();
|
||||||
for (int i = 0; i < numShapes; ++i) {
|
for (int i = 0; i < numShapes; ++i) {
|
||||||
HashKey& key = _pendingGarbage[i];
|
HashKey key(_pendingGarbage[i]);
|
||||||
ShapeReference* shapeRef = _shapeMap.find(key);
|
ShapeReference* shapeRef = _shapeMap.find(key);
|
||||||
if (shapeRef && shapeRef->refCount == 0) {
|
if (shapeRef && shapeRef->refCount == 0) {
|
||||||
ShapeFactory::deleteShape(shapeRef->shape);
|
ShapeFactory::deleteShape(shapeRef->shape);
|
||||||
|
|
|
@ -75,7 +75,7 @@ private:
|
||||||
|
|
||||||
// btHashMap is required because it supports memory alignment of the btCollisionShapes
|
// btHashMap is required because it supports memory alignment of the btCollisionShapes
|
||||||
btHashMap<HashKey, ShapeReference> _shapeMap;
|
btHashMap<HashKey, ShapeReference> _shapeMap;
|
||||||
btAlignedObjectArray<HashKey> _pendingGarbage;
|
btAlignedObjectArray<uint64_t> _pendingGarbage;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ShapeManager_h
|
#endif // hifi_ShapeManager_h
|
||||||
|
|
|
@ -32,6 +32,9 @@ class HashKey {
|
||||||
public:
|
public:
|
||||||
static float getNumQuantizedValuesPerMeter();
|
static float getNumQuantizedValuesPerMeter();
|
||||||
|
|
||||||
|
HashKey() {}
|
||||||
|
HashKey(uint64_t hash) : _hash(hash) {}
|
||||||
|
|
||||||
// These two methods are required by btHashMap.
|
// These two methods are required by btHashMap.
|
||||||
bool equals(const HashKey& other) const { return _hash == other._hash; }
|
bool equals(const HashKey& other) const { return _hash == other._hash; }
|
||||||
int32_t getHash() const { return (int32_t)((uint32_t)_hash); }
|
int32_t getHash() const { return (int32_t)((uint32_t)_hash); }
|
||||||
|
|
Loading…
Reference in a new issue