From df4b64447bd2084299417fe861802450ce1cd128 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 1 Oct 2013 13:02:32 -0700 Subject: [PATCH] cleanup calls to markWithChangedTime() to happen after all changes made --- libraries/voxels/src/VoxelNode.cpp | 21 ++++++++++++--------- libraries/voxels/src/VoxelNode.h | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/libraries/voxels/src/VoxelNode.cpp b/libraries/voxels/src/VoxelNode.cpp index bb501449c5..a7675f4609 100644 --- a/libraries/voxels/src/VoxelNode.cpp +++ b/libraries/voxels/src/VoxelNode.cpp @@ -54,8 +54,8 @@ void VoxelNode::init(unsigned char * octalCode) { _isDirty = true; _shouldRender = false; _sourceID = UNKNOWN_NODE_ID; - markWithChangedTime(); calculateAABox(); + markWithChangedTime(); } 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 // 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 @@ -78,14 +83,13 @@ VoxelNode::~VoxelNode() { // 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(); } recalculateSubTreeNodeCount(); + markWithChangedTime(); } void VoxelNode::recalculateSubTreeNodeCount() { @@ -134,8 +138,8 @@ void VoxelNode::deleteChildAtIndex(int childIndex) { delete _children[childIndex]; _children[childIndex] = NULL; _isDirty = true; - markWithChangedTime(); _childCount--; + markWithChangedTime(); } } @@ -145,8 +149,8 @@ VoxelNode* VoxelNode::removeChildAtIndex(int childIndex) { if (_children[childIndex]) { _children[childIndex] = NULL; _isDirty = true; - markWithChangedTime(); _childCount--; + markWithChangedTime(); } return returnedChild; } @@ -156,8 +160,8 @@ VoxelNode* VoxelNode::addChildAtIndex(int childIndex) { _children[childIndex] = new VoxelNode(childOctalCode(_octalCode, childIndex)); _children[childIndex]->setVoxelSystem(_voxelSystem); // our child is always part of our voxel system NULL ok _isDirty = true; - markWithChangedTime(); _childCount++; + markWithChangedTime(); } return _children[childIndex]; } @@ -243,9 +247,8 @@ void VoxelNode::setFalseColored(bool isFalseColored) { } _falseColored = isFalseColored; _isDirty = true; - markWithChangedTime(); _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)); } _isDirty = true; - markWithChangedTime(); _density = 1.0f; // If color set, assume leaf, re-averaging will update density if needed. + markWithChangedTime(); } } #endif diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index c9418ca154..9664b33a29 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -79,7 +79,7 @@ public: void clearDirtyBit() { _isDirty = false; } void setDirtyBit() { _isDirty = true; } bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); } - void markWithChangedTime() { _lastChanged = usecTimestampNow(); notifyUpdateHooks(); } + void markWithChangedTime(); uint64_t getLastChanged() const { return _lastChanged; } void handleSubtreeChanged(VoxelTree* myTree);