From 8774cb7ca08d7a66c8ecad3c4f1596f067d08e75 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 11 Jul 2013 15:48:17 -0700 Subject: [PATCH 1/3] fix hungergames circle bug, and improve performance of isLeafOrLOD logic --- libraries/voxels/src/VoxelTree.cpp | 33 ++++++++---------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 8dccb8fcb1..e1f4f27c08 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -1346,33 +1346,16 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp // There are two types of nodes for which we want to send colors: // 1) Leaves - obviously - // 2) Non-leaves who's children would be visible and beyond our LOD. - // NOTE: This code works, but it's pretty expensive, because we're calculating distances for all the grand - // children, which we'll end up doing again later in the next level of recursion. We need to optimize this - // in the future. + // 2) Non-leaves who's children would be visible but are beyond our LOD. bool isLeafOrLOD = childNode->isLeaf(); if (params.viewFrustum && childNode->isColored() && !childNode->isLeaf()) { - int grandChildrenInView = 0; - int grandChildrenInLOD = 0; - float grandChildBoundaryDistance = boundaryDistanceForRenderLevel(childNode->getLevel() + - 1 + params.boundaryLevelAdjust); - for (int grandChildIndex = 0; grandChildIndex < NUMBER_OF_CHILDREN; grandChildIndex++) { - VoxelNode* grandChild = childNode->getChildAtIndex(grandChildIndex); - - if (grandChild && grandChild->isColored() && grandChild->isInView(*params.viewFrustum)) { - grandChildrenInView++; - - float grandChildDistance = grandChild->distanceToCamera(*params.viewFrustum); - if (grandChildDistance < grandChildBoundaryDistance) { - grandChildrenInLOD++; - } - } - } - // if any of our grandchildren ARE in view, then we don't want to include our color. If none are, then - // we do want to include our color - if (grandChildrenInView > 0 && grandChildrenInLOD == 0) { - isLeafOrLOD = true; - } + float distanceToNode = distance; + int childLevel = childNode->getLevel(); + float childBoundary = boundaryDistanceForRenderLevel(childLevel + params.boundaryLevelAdjust); + float grandChildBoundary = boundaryDistanceForRenderLevel(childLevel + 1 + params.boundaryLevelAdjust); + bool inChildBoundary = (distanceToNode <= childBoundary); + bool inGrandChildBoundary = (distanceToNode <= grandChildBoundary); + isLeafOrLOD = (inChildBoundary && !inGrandChildBoundary); } // track children with actual color, only if the child wasn't previously in view! From 58b50067ade0849fc1d306460e5c26d96023f0f4 Mon Sep 17 00:00:00 2001 From: Eric Johnston Date: Thu, 11 Jul 2013 16:06:31 -0700 Subject: [PATCH 2/3] Some Leap finger fixes, but also temporarily disable Leap data sending, due to a crash. Will resolve the crash before re-enabling. --- interface/src/Hand.cpp | 2 +- libraries/avatars/src/AvatarData.cpp | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/interface/src/Hand.cpp b/interface/src/Hand.cpp index 950a5fe556..29a2c32bf1 100755 --- a/interface/src/Hand.cpp +++ b/interface/src/Hand.cpp @@ -54,7 +54,7 @@ void Hand::calculateGeometry() { _position = head.getPosition() + head.getOrientation() * offset; _orientation = head.getOrientation(); - int numLeapBalls = _fingerTips.size() + _fingerRoots.size(); + int numLeapBalls = _fingerTips.size(); _leapBalls.resize(numLeapBalls); for (int i = 0; i < _fingerTips.size(); ++i) { diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 2c941be9be..27a755e03f 100755 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -137,6 +137,11 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { if (numFingerVectors > 255) numFingerVectors = 0; // safety. We shouldn't ever get over 255, so consider that invalid. + ///////////////////////////////// + // Temporarily disable Leap finger sending, as it's causing a crash whenever someone's got a Leap connected + numFingerVectors = 0; + ///////////////////////////////// + *destinationBuffer++ = (unsigned char)numFingerVectors; if (numFingerVectors > 0) { @@ -255,8 +260,8 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { // leap hand data if (sourceBuffer - startPosition < numBytes) // safety check { - std::vector fingerTips = _handData->getFingerTips(); - std::vector fingerRoots = _handData->getFingerRoots(); + std::vector fingerTips; + std::vector fingerRoots; unsigned int numFingerVectors = *sourceBuffer++; unsigned int numFingerTips = numFingerVectors / 2; unsigned int numFingerRoots = numFingerVectors - numFingerTips; @@ -267,6 +272,11 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerTips[i].y), 4); sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerTips[i].z), 4); } + for (size_t i = 0; i < numFingerRoots; ++i) { + sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerRoots[i].x), 4); + sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerRoots[i].y), 4); + sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerRoots[i].z), 4); + } _handData->setFingerTips(fingerTips); _handData->setFingerRoots(fingerRoots); } From 323644d8771ad99c5562af116d533fa15b7aa654 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 11 Jul 2013 16:09:08 -0700 Subject: [PATCH 3/3] CR feedback --- libraries/voxels/src/VoxelTree.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index e1f4f27c08..d2ea383b8e 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -1349,13 +1349,10 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp // 2) Non-leaves who's children would be visible but are beyond our LOD. bool isLeafOrLOD = childNode->isLeaf(); if (params.viewFrustum && childNode->isColored() && !childNode->isLeaf()) { - float distanceToNode = distance; int childLevel = childNode->getLevel(); float childBoundary = boundaryDistanceForRenderLevel(childLevel + params.boundaryLevelAdjust); float grandChildBoundary = boundaryDistanceForRenderLevel(childLevel + 1 + params.boundaryLevelAdjust); - bool inChildBoundary = (distanceToNode <= childBoundary); - bool inGrandChildBoundary = (distanceToNode <= grandChildBoundary); - isLeafOrLOD = (inChildBoundary && !inGrandChildBoundary); + isLeafOrLOD = ((distance <= childBoundary) && !(distance <= grandChildBoundary)); } // track children with actual color, only if the child wasn't previously in view!