From ce778f47b1c6fc29999a5f9a865ba1c1514f866f Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 20 Jun 2014 14:08:39 -0700 Subject: [PATCH] More work on stream testing, fixed bug with differently-ordered edits. --- libraries/metavoxels/src/MetavoxelData.cpp | 21 +++++++++++++++++---- tests/metavoxels/src/MetavoxelTests.cpp | 8 ++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/libraries/metavoxels/src/MetavoxelData.cpp b/libraries/metavoxels/src/MetavoxelData.cpp index d7528d1959..6d1031d3cf 100644 --- a/libraries/metavoxels/src/MetavoxelData.cpp +++ b/libraries/metavoxels/src/MetavoxelData.cpp @@ -1153,8 +1153,23 @@ int MetavoxelVisitor::encodeOrder(const glm::vec3& direction) { indexDistances.at(6).index, indexDistances.at(7).index); } +const int ORDER_ELEMENT_BITS = 3; +const int ORDER_ELEMENT_MASK = (1 << ORDER_ELEMENT_BITS) - 1; + int MetavoxelVisitor::encodeRandomOrder() { - return DEFAULT_ORDER; + // see http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_.22inside-out.22_algorithm + int order; + int randomValues = rand(); + for (int i = 0, iShift = 0; i < MetavoxelNode::CHILD_COUNT; i++, iShift += ORDER_ELEMENT_BITS) { + int j = (randomValues >> iShift) % (i + 1); + int jShift = j * ORDER_ELEMENT_BITS; + if (j != i) { + int jValue = (order >> jShift) & ORDER_ELEMENT_MASK; + order = (order & ~(ORDER_ELEMENT_MASK << iShift)) | (jValue << iShift); + } + order = (order & ~(ORDER_ELEMENT_MASK << jShift)) | (i << jShift); + } + return order; } const int MetavoxelVisitor::DEFAULT_ORDER = encodeOrder(0, 1, 2, 3, 4, 5, 6, 7); @@ -1350,8 +1365,6 @@ bool DefaultMetavoxelGuide::guide(MetavoxelVisitation& visitation) { QVector(visitation.outputNodes.size()) } }; for (int i = 0; i < MetavoxelNode::CHILD_COUNT; i++) { // the encoded order tells us the child indices for each iteration - const int ORDER_ELEMENT_BITS = 3; - const int ORDER_ELEMENT_MASK = (1 << ORDER_ELEMENT_BITS) - 1; int index = encodedOrder & ORDER_ELEMENT_MASK; encodedOrder >>= ORDER_ELEMENT_BITS; for (int j = 0; j < visitation.inputNodes.size(); j++) { @@ -1392,7 +1405,7 @@ bool DefaultMetavoxelGuide::guide(MetavoxelVisitation& visitation) { } } MetavoxelNode* node = visitation.outputNodes.at(j); - MetavoxelNode* child = node->getChild(i); + MetavoxelNode* child = node->getChild(index); if (child) { child->decrementReferenceCount(value.getAttribute()); } else { diff --git a/tests/metavoxels/src/MetavoxelTests.cpp b/tests/metavoxels/src/MetavoxelTests.cpp index d261d9d926..6aef40eab1 100644 --- a/tests/metavoxels/src/MetavoxelTests.cpp +++ b/tests/metavoxels/src/MetavoxelTests.cpp @@ -598,17 +598,17 @@ public: private: - bool _finished; + int _mutationsRemaining; }; MutateVisitor::MutateVisitor() : MetavoxelVisitor(QVector(), QVector() << AttributeRegistry::getInstance()->getColorAttribute()), - _finished(false) { + _mutationsRemaining(randIntInRange(2, 4)) { } int MutateVisitor::visit(MetavoxelInfo& info) { - if (_finished) { + if (_mutationsRemaining <= 0) { return STOP_RECURSION; } if (info.size > MAXIMUM_LEAF_SIZE || (info.size > MINIMUM_LEAF_SIZE && randomBoolean())) { @@ -616,7 +616,7 @@ int MutateVisitor::visit(MetavoxelInfo& info) { } info.outputValues[0] = OwnedAttributeValue(_outputs.at(0), encodeInline(qRgb(randIntInRange(0, 255), randIntInRange(0, 255), randIntInRange(0, 255)))); - _finished = true; + _mutationsRemaining--; return STOP_RECURSION; }