cleanup calls to markWithChangedTime() to happen after all changes made

This commit is contained in:
ZappoMan 2013-10-01 13:02:32 -07:00
parent 1aa7855166
commit df4b64447b
2 changed files with 13 additions and 10 deletions

View file

@ -54,8 +54,8 @@ void VoxelNode::init(unsigned char * octalCode) {
_isDirty = true; _isDirty = true;
_shouldRender = false; _shouldRender = false;
_sourceID = UNKNOWN_NODE_ID; _sourceID = UNKNOWN_NODE_ID;
markWithChangedTime();
calculateAABox(); calculateAABox();
markWithChangedTime();
} }
VoxelNode::~VoxelNode() { VoxelNode::~VoxelNode() {
@ -71,6 +71,11 @@ VoxelNode::~VoxelNode() {
} }
} }
void VoxelNode::markWithChangedTime() {
_lastChanged = usecTimestampNow();
notifyUpdateHooks(); // if the node has changed, notify our hooks
}
// This method is called by VoxelTree when the subtree below this node // 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 // 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 // bookkeeping that a node may need to do when the subtree below it has
@ -78,14 +83,13 @@ VoxelNode::~VoxelNode() {
// localized, because this method will get called for every node in an // localized, because this method will get called for every node in an
// recursive unwinding case like delete or add voxel // recursive unwinding case like delete or add voxel
void VoxelNode::handleSubtreeChanged(VoxelTree* myTree) { void VoxelNode::handleSubtreeChanged(VoxelTree* myTree) {
markWithChangedTime();
// here's a good place to do color re-averaging... // here's a good place to do color re-averaging...
if (myTree->getShouldReaverage()) { if (myTree->getShouldReaverage()) {
setColorFromAverageOfChildren(); setColorFromAverageOfChildren();
} }
recalculateSubTreeNodeCount(); recalculateSubTreeNodeCount();
markWithChangedTime();
} }
void VoxelNode::recalculateSubTreeNodeCount() { void VoxelNode::recalculateSubTreeNodeCount() {
@ -134,8 +138,8 @@ void VoxelNode::deleteChildAtIndex(int childIndex) {
delete _children[childIndex]; delete _children[childIndex];
_children[childIndex] = NULL; _children[childIndex] = NULL;
_isDirty = true; _isDirty = true;
markWithChangedTime();
_childCount--; _childCount--;
markWithChangedTime();
} }
} }
@ -145,8 +149,8 @@ VoxelNode* VoxelNode::removeChildAtIndex(int childIndex) {
if (_children[childIndex]) { if (_children[childIndex]) {
_children[childIndex] = NULL; _children[childIndex] = NULL;
_isDirty = true; _isDirty = true;
markWithChangedTime();
_childCount--; _childCount--;
markWithChangedTime();
} }
return returnedChild; return returnedChild;
} }
@ -156,8 +160,8 @@ VoxelNode* VoxelNode::addChildAtIndex(int childIndex) {
_children[childIndex] = new VoxelNode(childOctalCode(_octalCode, childIndex)); _children[childIndex] = new VoxelNode(childOctalCode(_octalCode, childIndex));
_children[childIndex]->setVoxelSystem(_voxelSystem); // our child is always part of our voxel system NULL ok _children[childIndex]->setVoxelSystem(_voxelSystem); // our child is always part of our voxel system NULL ok
_isDirty = true; _isDirty = true;
markWithChangedTime();
_childCount++; _childCount++;
markWithChangedTime();
} }
return _children[childIndex]; return _children[childIndex];
} }
@ -243,9 +247,8 @@ void VoxelNode::setFalseColored(bool isFalseColored) {
} }
_falseColored = isFalseColored; _falseColored = isFalseColored;
_isDirty = true; _isDirty = true;
markWithChangedTime();
_density = 1.0f; // If color set, assume leaf, re-averaging will update density if needed. _density = 1.0f; // If color set, assume leaf, re-averaging will update density if needed.
markWithChangedTime();
} }
}; };
@ -257,8 +260,8 @@ void VoxelNode::setColor(const nodeColor& color) {
memcpy(&_currentColor,&color,sizeof(nodeColor)); memcpy(&_currentColor,&color,sizeof(nodeColor));
} }
_isDirty = true; _isDirty = true;
markWithChangedTime();
_density = 1.0f; // If color set, assume leaf, re-averaging will update density if needed. _density = 1.0f; // If color set, assume leaf, re-averaging will update density if needed.
markWithChangedTime();
} }
} }
#endif #endif

View file

@ -79,7 +79,7 @@ public:
void clearDirtyBit() { _isDirty = false; } void clearDirtyBit() { _isDirty = false; }
void setDirtyBit() { _isDirty = true; } void setDirtyBit() { _isDirty = true; }
bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); } bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); }
void markWithChangedTime() { _lastChanged = usecTimestampNow(); notifyUpdateHooks(); } void markWithChangedTime();
uint64_t getLastChanged() const { return _lastChanged; } uint64_t getLastChanged() const { return _lastChanged; }
void handleSubtreeChanged(VoxelTree* myTree); void handleSubtreeChanged(VoxelTree* myTree);