diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 4ca7a7bd7f..1f4856abf7 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -121,6 +121,8 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { // called on the other agents - assigns it to my views of the others int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { +//printf("AvatarData::parseData()\n"); + // increment to push past the packet header sourceBuffer += sizeof(PACKET_HEADER_HEAD_DATA); diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 0476ca0d40..d22073a54b 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -853,10 +853,8 @@ int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEnco for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { VoxelNode* childNode = node->getChildAtIndex(i); bool childIsInView = (childNode && (!viewFrustum || childNode->isInView(*viewFrustum))); - bool childWasInView = (childNode && deltaViewFrustum && - (lastViewFrustum && ViewFrustum::INSIDE == childNode->inFrustum(*lastViewFrustum))); - if (childIsInView && !childWasInView) { + if (childIsInView) { // Before we determine consider this further, let's see if it's in our LOD scope... float distance = viewFrustum ? childNode->distanceToCamera(*viewFrustum) : 0; float boundaryDistance = viewFrustum ? boundaryDistanceForRenderLevel(*childNode->getOctalCode() + 1) : 1; @@ -871,9 +869,12 @@ int VoxelTree::encodeTreeBitstreamRecursion(int maxEncodeLevel, int& currentEnco childrenExistBits += (1 << (7 - i)); inViewNotLeafCount++; } + + bool childWasInView = (childNode && deltaViewFrustum && + (lastViewFrustum && ViewFrustum::INSIDE == childNode->inFrustum(*lastViewFrustum))); - // track children with actual color - if (childNode && childNode->isColored()) { + // track children with actual color, only if the child wasn't previously in view! + if (childNode && childNode->isColored() && !childWasInView) { childrenColoredBits += (1 << (7 - i)); inViewWithColorCount++; } diff --git a/voxel-server/src/VoxelAgentData.cpp b/voxel-server/src/VoxelAgentData.cpp index b265ccb2ba..4eb971f275 100644 --- a/voxel-server/src/VoxelAgentData.cpp +++ b/voxel-server/src/VoxelAgentData.cpp @@ -22,6 +22,7 @@ void VoxelAgentData::init() { _maxSearchLevel = 1; _maxLevelReachedInLastSearch = 1; resetVoxelPacket(); + _viewSent = false; } void VoxelAgentData::resetVoxelPacket() { diff --git a/voxel-server/src/VoxelAgentData.h b/voxel-server/src/VoxelAgentData.h index 4bdbb6069d..99be7e6042 100644 --- a/voxel-server/src/VoxelAgentData.h +++ b/voxel-server/src/VoxelAgentData.h @@ -49,7 +49,11 @@ public: bool updateCurrentViewFrustum(); void updateLastKnownViewFrustum(); + bool getViewSent() const { return _viewSent; }; + void setViewSent(bool viewSent) { _viewSent = viewSent; } + private: + bool _viewSent; unsigned char* _voxelPacket; unsigned char* _voxelPacketAt; int _voxelPacketAvailableBytes; diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 88ad060cf9..d15a5325f6 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -234,12 +234,21 @@ void deepestLevelVoxelDistributor(AgentList* agentList, bool wantDelta = agentData->getWantDelta(); const ViewFrustum* lastViewFrustum = wantDelta ? &agentData->getLastKnownViewFrustum() : NULL; +printf("deepestLevelVoxelDistributor() viewFrustumChanged=%s, nodeBag.isEmpty=%s, viewSent=%s\n", + viewFrustumChanged ? "yes" : "no", + agentData->nodeBag.isEmpty() ? "yes" : "no", + agentData->getViewSent() ? "yes" : "no" + ); + // If the current view frustum has changed OR we have nothing to send, then search against // the current view frustum for things to send. if (viewFrustumChanged || agentData->nodeBag.isEmpty()) { // If the bag was empty, then send everything in view, not just the delta maxLevelReached = randomTree.searchForColoredNodes(INT_MAX, randomTree.rootNode, agentData->getCurrentViewFrustum(), agentData->nodeBag, wantDelta, lastViewFrustum); + + agentData->setViewSent(false); + } double end = usecTimestampNow(); double elapsedmsec = (end - start)/1000.0; @@ -323,6 +332,7 @@ void deepestLevelVoxelDistributor(AgentList* agentList, // the voxels from the current view frustum if (agentData->nodeBag.isEmpty()) { agentData->updateLastKnownViewFrustum(); + agentData->setViewSent(true); } @@ -354,6 +364,7 @@ void *distributeVoxelsToListeners(void *args) { // Sometimes the agent data has not yet been linked, in which case we can't really do anything if (agentData) { bool viewFrustumChanged = agentData->updateCurrentViewFrustum(); + printf("agentData->updateCurrentViewFrustum() viewFrustumChanged=%s\n", (viewFrustumChanged ? "yes" : "no")); if (agentData->getWantResIn()) { resInVoxelDistributor(agentList, agent, agentData);