added method for general subtree change bookkeeping

This commit is contained in:
ZappoMan 2013-06-06 10:55:11 -07:00
parent 66ebb7d01c
commit ae3db89f63
4 changed files with 28 additions and 4 deletions

View file

@ -12,6 +12,7 @@
#include "SharedUtil.h"
#include "Log.h"
#include "VoxelNode.h"
#include "VoxelTree.h"
#include "VoxelConstants.h"
#include "OctalCode.h"
#include "AABox.h"
@ -61,6 +62,22 @@ VoxelNode::~VoxelNode() {
}
}
// This method is called by VoxelTree when the subtree below this node
// is known to have changed. It's intended to be used as a place to do
// bookkeeping that a node may need to do when the subtree below it has
// changed. However, you should hopefully make your bookkeeping relatively
// localized, because this method will get called for every node in an
// recursive unwinding case like delete or add voxel
void VoxelNode::handleSubtreeChanged(VoxelTree* myTree) {
markWithChangedTime();
// here's a good place to do color re-averaging...
if (myTree->getShouldReaverage()) {
setColorFromAverageOfChildren();
}
}
void VoxelNode::setShouldRender(bool shouldRender) {
// if shouldRender is changing, then consider ourselves dirty
if (shouldRender != _shouldRender) {

View file

@ -14,6 +14,8 @@
#include "ViewFrustum.h"
#include "VoxelConstants.h"
class VoxelTree; // forward delclaration
typedef unsigned char colorPart;
typedef unsigned char nodeColor[4];
typedef unsigned char rgbColor[3];
@ -79,6 +81,7 @@ public:
void clearDirtyBit() { _isDirty = false; };
bool hasChangedSince(double time) const { return (_lastChanged > time); };
void markWithChangedTime() { _lastChanged = usecTimestampNow(); };
void handleSubtreeChanged(VoxelTree* myTree);
glBufferIndex getBufferIndex() const { return _glBufferIndex; };
bool isKnownBufferIndex() const { return (_glBufferIndex != GLBUFFER_INDEX_UNKNOWN); };

View file

@ -388,9 +388,10 @@ void VoxelTree::deleteVoxelCodeFromTreeRecursion(VoxelNode* node, void* extraDat
}
}
// If the lower level did some work, then we need to track our lastChanged status.
// If the lower level did some work, then we need to let this node know, so it can
// do any bookkeeping it wants to, like color re-averaging, time stamp marking, etc
if (args->pathChanged) {
node->markWithChangedTime();
node->handleSubtreeChanged(this);
}
}
@ -482,9 +483,10 @@ void VoxelTree::readCodeColorBufferToTreeRecursion(VoxelNode* node, void* extraD
// Unwinding...
// If the lower level did some work, then we need to track our lastChanged status.
// If the lower level did some work, then we need to let this node know, so it can
// do any bookkeeping it wants to, like color re-averaging, time stamp marking, etc
if (args->pathChanged) {
node->markWithChangedTime();
node->handleSubtreeChanged(this);
}
}

View file

@ -99,6 +99,8 @@ public:
void copySubTreeIntoNewTree(VoxelNode* startNode, VoxelTree* destinationTree, bool rebaseToRoot);
void copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelNode* destinationNode);
bool getShouldReaverage() const { return _shouldReaverage; }
private:
void deleteVoxelCodeFromTreeRecursion(VoxelNode* node, void* extraData);
void readCodeColorBufferToTreeRecursion(VoxelNode* node, void* extraData);