fixed wasted bitmasks bug where we would include colors and extra layers

This commit is contained in:
ZappoMan 2013-11-25 01:42:19 -08:00
parent 8bb2bd2ecf
commit 17f5530893
3 changed files with 30 additions and 9 deletions

View file

@ -69,20 +69,20 @@ void outputBufferBits(const unsigned char* buffer, int length, bool withNewLine)
} }
} }
void outputBits(unsigned char byte, bool withNewLine) { void outputBits(unsigned char byte, bool withNewLine, bool usePrintf) {
if (isalnum(byte)) { if (isalnum(byte)) {
qDebug("[ %d (%c): ", byte, byte); usePrintf ? (void)printf("[ %d (%c): ", byte, byte) : qDebug("[ %d (%c): ", byte, byte);
} else { } else {
qDebug("[ %d (0x%x): ", byte, byte); usePrintf ? (void)printf("[ %d (0x%x): ", byte, byte) : qDebug("[ %d (0x%x): ", byte, byte);
} }
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
qDebug("%d", byte >> (7 - i) & 1); usePrintf ? (void)printf("%d", byte >> (7 - i) & 1) : qDebug("%d", byte >> (7 - i) & 1);
} }
qDebug(" ] "); usePrintf ? (void)printf(" ] ") : qDebug(" ] ");
if (withNewLine) { if (withNewLine) {
qDebug("\n"); usePrintf ? (void)printf("\n") : qDebug("\n");
} }
} }

View file

@ -53,7 +53,7 @@ bool randomBoolean();
bool shouldDo(float desiredInterval, float deltaTime); bool shouldDo(float desiredInterval, float deltaTime);
void outputBufferBits(const unsigned char* buffer, int length, bool withNewLine = true); void outputBufferBits(const unsigned char* buffer, int length, bool withNewLine = true);
void outputBits(unsigned char byte, bool withNewLine = true); void outputBits(unsigned char byte, bool withNewLine = true, bool usePrintf = false);
void printVoxelCode(unsigned char* voxelCode); void printVoxelCode(unsigned char* voxelCode);
int numberOfOnes(unsigned char byte); int numberOfOnes(unsigned char byte);
bool oneAtBit(unsigned char byte, int bitIndex); bool oneAtBit(unsigned char byte, int bitIndex);

View file

@ -1419,6 +1419,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node,
if (!childWasInView || if (!childWasInView ||
(params.deltaViewFrustum && (params.deltaViewFrustum &&
childNode->hasChangedSince(params.lastViewFrustumSent - CHANGE_FUDGE))){ childNode->hasChangedSince(params.lastViewFrustumSent - CHANGE_FUDGE))){
childrenColoredBits += (1 << (7 - originalIndex)); childrenColoredBits += (1 << (7 - originalIndex));
inViewWithColorCount++; inViewWithColorCount++;
} else { } else {
@ -1530,7 +1531,17 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node,
// remember this for reshuffling // remember this for reshuffling
recursiveSliceStarts[originalIndex] = packet->getUncompressedData() + packet->getUncompressedSize(); recursiveSliceStarts[originalIndex] = packet->getUncompressedData() + packet->getUncompressedSize();
int childTreeBytesOut = encodeTreeBitstreamRecursion(childNode, packet, bag, params, thisLevel); int childTreeBytesOut = 0;
// XXXBHG - Note, this seems like the correct logic here, if we included the color in this packet, then
// the LOD logic determined that the child nodes do not need to be visible... and if so, we shouldn't recurse
// them further. But... this isn't how the code has been for a while... but it's a major savings (~30%) and
// it seems to work correctly. I'd like to discuss...
//
// only recurse if we DIDN'T include colore on this level
if (!oneAtBit(childrenColoredBits, originalIndex)) {
childTreeBytesOut = encodeTreeBitstreamRecursion(childNode, packet, bag, params, thisLevel);
}
// remember this for reshuffling // remember this for reshuffling
recursiveSliceSizes[originalIndex] = childTreeBytesOut; recursiveSliceSizes[originalIndex] = childTreeBytesOut;
@ -1612,9 +1623,19 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node,
} }
} // end keepDiggingDeeper } // end keepDiggingDeeper
// At this point all our BitMasks are complete... so let's output them to see how they compare...
/**
printf("This Level's BitMasks: childInTree:");
outputBits(childrenExistInTreeBits, false, true);
printf(" childInPacket:");
outputBits(childrenExistInPacketBits, false, true);
printf(" childrenColored:");
outputBits(childrenColoredBits, false, true);
printf("\n");
**/
// if we were unable to fit this level in our packet, then rewind and add it to the node bag for // if we were unable to fit this level in our packet, then rewind and add it to the node bag for
// sending later... // sending later...
if (continueThisLevel) { if (continueThisLevel) {
continueThisLevel = packet->endLevel(thisLevelKey); continueThisLevel = packet->endLevel(thisLevelKey);
} else { } else {