particle tree pruning on update

This commit is contained in:
ZappoMan 2013-12-12 15:09:30 -08:00
parent d3197ef8f9
commit 18cbb2d00f
6 changed files with 37 additions and 14 deletions

View file

@ -68,7 +68,9 @@ bool OctreePersistThread::process() {
usleep(USECS_TO_SLEEP);
// do our updates then check to save...
_tree->lockForWrite();
_tree->update();
_tree->unlock();
uint64_t now = usecTimestampNow();
uint64_t sinceLastSave = now - _lastCheck;

View file

@ -1083,19 +1083,22 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
if (oneAtBit(childrenColoredBits, i)) {
OctreeElement* childNode = node->getChildAtIndex(i);
continueThisLevel = childNode->appendElementData(packetData);
if (!continueThisLevel) {
break; // no point in continuing
}
bytesAtThisLevel += BYTES_PER_COLOR; // keep track of byte count for color
if (childNode) {
int bytesBeforeChild = packetData->getUncompressedSize();
continueThisLevel = childNode->appendElementData(packetData);
int bytesAfterChild = packetData->getUncompressedSize();
if (!continueThisLevel) {
break; // no point in continuing
}
bytesAtThisLevel += (bytesAfterChild - bytesBeforeChild); // keep track of byte count for this child
// don't need to check childNode here, because we can't get here with no childNode
if (params.stats) {
params.stats->colorSent(childNode);
// don't need to check childNode here, because we can't get here with no childNode
if (params.stats) {
params.stats->colorSent(childNode);
}
}
}
}
}

View file

@ -196,7 +196,7 @@ void OctreeElement::calculateAABox() {
void OctreeElement::deleteChildAtIndex(int childIndex) {
OctreeElement* childAt = getChildAtIndex(childIndex);
if (childAt) {
printf("deleteChildAtIndex()... about to call delete childAt=%p\n",childAt);
//printf("deleteChildAtIndex()... about to call delete childAt=%p\n",childAt);
delete childAt;
setChildAtIndex(childIndex, NULL);
_isDirty = true;
@ -1292,7 +1292,9 @@ OctreeElement* OctreeElement::getOrCreateChildElementAt(float x, float y, float
float ourScale = getScale();
float halfOurScale = ourScale / 2.0f;
assert(s <= ourScale); // This should never happen
if(s > ourScale) {
printf("UNEXPECTED -- OctreeElement::getOrCreateChildElementAt() s=[%f] > ourScale=[%f] \n", s, ourScale);
}
if (s > halfOurScale) {
return this;

View file

@ -169,6 +169,17 @@ bool ParticleTree::updateOperation(OctreeElement* element, void* extraData) {
return true;
}
bool ParticleTree::pruneOperation(OctreeElement* element, void* extraData) {
ParticleTreeElement* particleTreeElement = static_cast<ParticleTreeElement*>(element);
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
ParticleTreeElement* childAt = particleTreeElement->getChildAtIndex(i);
if (childAt && childAt->isLeaf() && !childAt->hasParticles()) {
particleTreeElement->deleteChildAtIndex(i);
}
}
return true;
}
void ParticleTree::update() {
_isDirty = true;
@ -187,6 +198,9 @@ void ParticleTree::update() {
storeParticle(args._movingParticles[i]);
}
}
// prune the tree...
recurseTreeWithOperation(pruneOperation, NULL);
}

View file

@ -53,6 +53,7 @@ private:
static bool updateOperation(OctreeElement* element, void* extraData);
static bool findAndUpdateOperation(OctreeElement* element, void* extraData);
static bool findNearPointOperation(OctreeElement* element, void* extraData);
static bool pruneOperation(OctreeElement* element, void* extraData);
void notifyNewlyCreatedParticle(const Particle& newParticle, Node* senderNode);

View file

@ -71,9 +71,10 @@ public:
/// shouldRender() state, the tree will remark elements as changed even in cases there the elements have not changed.
virtual bool isRendered() const { return getShouldRender(); }
virtual bool deleteApproved() const { return (_particles.size() == 0); }
virtual bool deleteApproved() const { return !hasParticles(); }
const std::vector<Particle>& getParticles() const { return _particles; }
bool hasParticles() const { return _particles.size() > 0; }
void update(ParticleTreeUpdateArgs& args);
void setTree(ParticleTree* tree) { _myTree = tree; }