From ab8e2916d32aca4bcc8ed84e60e990e73fff15c1 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 10 Jul 2013 19:49:50 -0700 Subject: [PATCH] improvements to delta sending --- libraries/voxels/src/VoxelTree.cpp | 31 ++++++++++++++++++++++-------- libraries/voxels/src/VoxelTree.h | 3 +++ voxel-server/src/main.cpp | 6 +++++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 2f0ec4727c..70bca504cb 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -1331,10 +1331,6 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp } // wants occlusion culling & isLeaf() - bool childWasInView = (childNode && params.deltaViewFrustum && - - (params.lastViewFrustum && ViewFrustum::INSIDE == childNode->inFrustum(*params.lastViewFrustum))); - // 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. @@ -1360,15 +1356,34 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp } // 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) { + if (grandChildrenInView > 0 && grandChildrenInLOD == 0) { isLeafOrLOD = true; } } // track children with actual color, only if the child wasn't previously in view! - if (childNode && isLeafOrLOD && childNode->isColored() && !childWasInView && !childIsOccluded) { - childrenColoredBits += (1 << (7 - originalIndex)); - inViewWithColorCount++; + if (childNode && isLeafOrLOD && childNode->isColored() && !childIsOccluded) { + bool childWasInView = false; + + if (childNode && params.deltaViewFrustum && params.lastViewFrustum) { + ViewFrustum::location location = childNode->inFrustum(*params.lastViewFrustum); + + // If we're a leaf, then either intersect or inside is considered "formerly in view" + if (childNode->isLeaf()) { + childWasInView = location != ViewFrustum::OUTSIDE; + } else { + childWasInView = location == ViewFrustum::INSIDE; + } + } + + // If our child wasn't in view (or we're ignoring wasInView) then we add it to our sending items + if (!childWasInView) { + childrenColoredBits += (1 << (7 - originalIndex)); + inViewWithColorCount++; + } else { + // otherwise just track stats of the items we discarded + params.childWasInViewDiscarded++; + } } } } diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 4c0e7d33c4..a94afe0d79 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -45,6 +45,8 @@ public: bool deltaViewFrustum; const ViewFrustum* lastViewFrustum; bool wantOcclusionCulling; + long childWasInViewDiscarded; + CoverageMap* map; EncodeBitstreamParams( @@ -66,6 +68,7 @@ public: deltaViewFrustum (deltaViewFrustum), lastViewFrustum (lastViewFrustum), wantOcclusionCulling(wantOcclusionCulling), + childWasInViewDiscarded(0), map (map) {} }; diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 74780ed52a..e71e456359 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -127,7 +127,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList, long long start = usecTimestampNow(); // FOR NOW... node tells us if it wants to receive only view frustum deltas - bool wantDelta = nodeData->getWantDelta(); + bool wantDelta = viewFrustumChanged && nodeData->getWantDelta(); const ViewFrustum* lastViewFrustum = wantDelta ? &nodeData->getLastKnownViewFrustum() : NULL; if (::debugVoxelSending) { @@ -233,6 +233,10 @@ void deepestLevelVoxelDistributor(NodeList* nodeList, bytesWritten = serverTree.encodeTreeBitstream(subTree, &tempOutputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, nodeData->nodeBag, params); + + if (::debugVoxelSending && wantDelta) { + printf("encodeTreeBitstream() childWasInViewDiscarded=%ld\n", params.childWasInViewDiscarded); + } if (nodeData->getAvailable() >= bytesWritten) { nodeData->writeToPacket(&tempOutputBuffer[0], bytesWritten);