mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 16:30:39 +02:00
add more tracing details in PrePhysics
This commit is contained in:
parent
d7f38bac17
commit
c9b142531b
1 changed files with 26 additions and 10 deletions
|
@ -17,7 +17,10 @@
|
||||||
|
|
||||||
#include "ShapeFactory.h"
|
#include "ShapeFactory.h"
|
||||||
|
|
||||||
|
const int MAX_RING_SIZE = 256;
|
||||||
|
|
||||||
ShapeManager::ShapeManager() {
|
ShapeManager::ShapeManager() {
|
||||||
|
_garbageRing.reserve(MAX_RING_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapeManager::~ShapeManager() {
|
ShapeManager::~ShapeManager() {
|
||||||
|
@ -58,17 +61,29 @@ bool ShapeManager::releaseShapeByKey(uint64_t key) {
|
||||||
if (shapeRef->refCount > 0) {
|
if (shapeRef->refCount > 0) {
|
||||||
shapeRef->refCount--;
|
shapeRef->refCount--;
|
||||||
if (shapeRef->refCount == 0) {
|
if (shapeRef->refCount == 0) {
|
||||||
// look for existing entry in _pendingGarbage, starting from the back
|
// look for existing entry in _garbageRing
|
||||||
for (int32_t i = _pendingGarbage.size() - 1; i > -1; --i) {
|
int32_t ringSize = _garbageRing.size();
|
||||||
if (_pendingGarbage[i] == key) {
|
for (int32_t i = 0; i < ringSize; ++i) {
|
||||||
|
int32_t j = (_ringIndex + ringSize) % ringSize;
|
||||||
|
if (_garbageRing[j] == key) {
|
||||||
// already on the list, don't add it again
|
// already on the list, don't add it again
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_pendingGarbage.push_back(key);
|
if (ringSize == MAX_RING_SIZE) {
|
||||||
const int MAX_SHAPE_GARBAGE_CAPACITY = 255;
|
// remove one
|
||||||
if (_pendingGarbage.size() > MAX_SHAPE_GARBAGE_CAPACITY) {
|
HashKey hashKeyToRemove(_garbageRing[_ringIndex]);
|
||||||
collectGarbage();
|
ShapeReference* shapeRef = _shapeMap.find(hashKeyToRemove);
|
||||||
|
if (shapeRef && shapeRef->refCount == 0) {
|
||||||
|
ShapeFactory::deleteShape(shapeRef->shape);
|
||||||
|
_shapeMap.remove(hashKeyToRemove);
|
||||||
|
}
|
||||||
|
// replace at _ringIndex and advance
|
||||||
|
_garbageRing[_ringIndex] = key;
|
||||||
|
_ringIndex = (_ringIndex + 1) % ringSize;
|
||||||
|
} else {
|
||||||
|
// add one
|
||||||
|
_garbageRing.push_back(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -95,16 +110,17 @@ bool ShapeManager::releaseShape(const btCollisionShape* shape) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapeManager::collectGarbage() {
|
void ShapeManager::collectGarbage() {
|
||||||
int numShapes = _pendingGarbage.size();
|
int numShapes = _garbageRing.size();
|
||||||
for (int i = 0; i < numShapes; ++i) {
|
for (int i = 0; i < numShapes; ++i) {
|
||||||
HashKey key(_pendingGarbage[i]);
|
HashKey key(_garbageRing[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);
|
||||||
_shapeMap.remove(key);
|
_shapeMap.remove(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_pendingGarbage.clear();
|
_ringIndex = 0;
|
||||||
|
_garbageRing.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ShapeManager::getNumReferences(const ShapeInfo& info) const {
|
int ShapeManager::getNumReferences(const ShapeInfo& info) const {
|
||||||
|
|
Loading…
Reference in a new issue