more cast coding standard fixes

This commit is contained in:
Brad Hefta-Gaub 2014-01-09 19:00:57 -08:00
parent cdb4b8c5f3
commit 5787d3d9e9

View file

@ -43,7 +43,7 @@ Octree::Octree(bool shouldReaverage) :
_shouldReaverage(shouldReaverage), _shouldReaverage(shouldReaverage),
_stopImport(false) { _stopImport(false) {
_rootNode = NULL; _rootNode = NULL;
pthread_mutex_init(&_encodeSetLock, NULL); pthread_mutex_init(&_encodeSetLock, NULL);
pthread_mutex_init(&_deleteSetLock, NULL); pthread_mutex_init(&_deleteSetLock, NULL);
pthread_mutex_init(&_deletePendingSetLock, NULL); pthread_mutex_init(&_deletePendingSetLock, NULL);
@ -66,13 +66,13 @@ void Octree::recurseTreeWithOperation(RecurseOctreeOperation operation, void* ex
} }
// Recurses voxel node with an operation function // Recurses voxel node with an operation function
void Octree::recurseNodeWithOperation(OctreeElement* node, RecurseOctreeOperation operation, void* extraData, void Octree::recurseNodeWithOperation(OctreeElement* node, RecurseOctreeOperation operation, void* extraData,
int recursionCount) { int recursionCount) {
if (recursionCount > DANGEROUSLY_DEEP_RECURSION) { if (recursionCount > DANGEROUSLY_DEEP_RECURSION) {
qDebug() << "Octree::recurseNodeWithOperation() reached DANGEROUSLY_DEEP_RECURSION, bailing!\n"; qDebug() << "Octree::recurseNodeWithOperation() reached DANGEROUSLY_DEEP_RECURSION, bailing!\n";
return; return;
} }
if (operation(node, extraData)) { if (operation(node, extraData)) {
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
OctreeElement* child = node->getChildAtIndex(i); OctreeElement* child = node->getChildAtIndex(i);
@ -92,7 +92,7 @@ void Octree::recurseTreeWithOperationDistanceSorted(RecurseOctreeOperation opera
} }
// Recurses voxel node with an operation function // Recurses voxel node with an operation function
void Octree::recurseNodeWithOperationDistanceSorted(OctreeElement* node, RecurseOctreeOperation operation, void Octree::recurseNodeWithOperationDistanceSorted(OctreeElement* node, RecurseOctreeOperation operation,
const glm::vec3& point, void* extraData, int recursionCount) { const glm::vec3& point, void* extraData, int recursionCount) {
if (recursionCount > DANGEROUSLY_DEEP_RECURSION) { if (recursionCount > DANGEROUSLY_DEEP_RECURSION) {
@ -138,7 +138,7 @@ OctreeElement* Octree::nodeForOctalCode(OctreeElement* ancestorNode,
if (needleCode == NULL) { if (needleCode == NULL) {
return _rootNode; return _rootNode;
} }
// find the appropriate branch index based on this ancestorNode // find the appropriate branch index based on this ancestorNode
if (*needleCode > 0) { if (*needleCode > 0) {
int branchForNeedle = branchIndexWithDescendant(ancestorNode->getOctalCode(), needleCode); int branchForNeedle = branchIndexWithDescendant(ancestorNode->getOctalCode(), needleCode);
@ -213,13 +213,13 @@ int Octree::readNodeData(OctreeElement* destinationNode, const unsigned char* no
nodeWasDirty = childNodeAt->isDirty(); nodeWasDirty = childNodeAt->isDirty();
bytesRead += childNodeAt->readElementDataFromBuffer(nodeData + bytesRead, bytesLeftToRead, args); bytesRead += childNodeAt->readElementDataFromBuffer(nodeData + bytesRead, bytesLeftToRead, args);
childNodeAt->setSourceUUID(args.sourceUUID); childNodeAt->setSourceUUID(args.sourceUUID);
// if we had a local version of the node already, it's possible that we have it already but // if we had a local version of the node already, it's possible that we have it already but
// with the same color data, so this won't count as a change. To address this we check the following // with the same color data, so this won't count as a change. To address this we check the following
if (!childNodeAt->isDirty() && childNodeAt->getShouldRender() && !childNodeAt->isRendered()) { if (!childNodeAt->isDirty() && childNodeAt->getShouldRender() && !childNodeAt->isRendered()) {
childNodeAt->setDirtyBit(); // force dirty! childNodeAt->setDirtyBit(); // force dirty!
} }
nodeIsDirty = childNodeAt->isDirty(); nodeIsDirty = childNodeAt->isDirty();
} }
if (nodeIsDirty) { if (nodeIsDirty) {
@ -299,8 +299,8 @@ void Octree::readBitstreamToTree(const unsigned char * bitstream, unsigned long
int octalCodeBytes = bytesRequiredForCodeLength(*bitstreamAt); int octalCodeBytes = bytesRequiredForCodeLength(*bitstreamAt);
int theseBytesRead = 0; int theseBytesRead = 0;
theseBytesRead += octalCodeBytes; theseBytesRead += octalCodeBytes;
theseBytesRead += readNodeData(bitstreamRootNode, bitstreamAt + octalCodeBytes, theseBytesRead += readNodeData(bitstreamRootNode, bitstreamAt + octalCodeBytes,
bufferSizeBytes - (bytesRead + octalCodeBytes), args); bufferSizeBytes - (bytesRead + octalCodeBytes), args);
// skip bitstream to new startPoint // skip bitstream to new startPoint
@ -341,7 +341,7 @@ void Octree::deleteOctalCodeFromTree(const unsigned char* codeBuffer, bool colla
args.pathChanged = false; args.pathChanged = false;
OctreeElement* node = _rootNode; OctreeElement* node = _rootNode;
// We can't encode and delete nodes at the same time, so we guard against deleting any node that is actively // We can't encode and delete nodes at the same time, so we guard against deleting any node that is actively
// being encoded. And we stick that code on our pendingDelete list. // being encoded. And we stick that code on our pendingDelete list.
if (isEncoding(codeBuffer)) { if (isEncoding(codeBuffer)) {
@ -380,15 +380,15 @@ void Octree::deleteOctalCodeFromTreeRecursion(OctreeElement* node, void* extraDa
OctreeElement* ancestorNode = node; OctreeElement* ancestorNode = node;
while (true) { while (true) {
int index = branchIndexWithDescendant(ancestorNode->getOctalCode(), args->codeBuffer); int index = branchIndexWithDescendant(ancestorNode->getOctalCode(), args->codeBuffer);
// we end up with all the children, even the one we want to delete // we end up with all the children, even the one we want to delete
ancestorNode->splitChildren(); ancestorNode->splitChildren();
int lengthOfAncestorNode = numberOfThreeBitSectionsInCode(ancestorNode->getOctalCode()); int lengthOfAncestorNode = numberOfThreeBitSectionsInCode(ancestorNode->getOctalCode());
// If we've reached the parent of the target, then stop breaking up children // If we've reached the parent of the target, then stop breaking up children
if (lengthOfAncestorNode == (args->lengthOfCode - 1)) { if (lengthOfAncestorNode == (args->lengthOfCode - 1)) {
// since we created all the children when we split, we need to delete this target one // since we created all the children when we split, we need to delete this target one
ancestorNode->deleteChildAtIndex(index); ancestorNode->deleteChildAtIndex(index);
break; break;
@ -454,21 +454,21 @@ void Octree::processRemoveOctreeElementsBitstream(const unsigned char* bitstream
int numBytesPacketHeader = numBytesForPacketHeader(bitstream); int numBytesPacketHeader = numBytesForPacketHeader(bitstream);
unsigned short int sequence = (*((unsigned short int*)(bitstream + numBytesPacketHeader))); unsigned short int sequence = (*((unsigned short int*)(bitstream + numBytesPacketHeader)));
uint64_t sentAt = (*((uint64_t*)(bitstream + numBytesPacketHeader + sizeof(sequence)))); uint64_t sentAt = (*((uint64_t*)(bitstream + numBytesPacketHeader + sizeof(sequence))));
int atByte = numBytesPacketHeader + sizeof(sequence) + sizeof(sentAt); int atByte = numBytesPacketHeader + sizeof(sequence) + sizeof(sentAt);
unsigned char* voxelCode = (unsigned char*)&bitstream[atByte]; unsigned char* voxelCode = (unsigned char*)&bitstream[atByte];
while (atByte < bufferSizeBytes) { while (atByte < bufferSizeBytes) {
int maxSize = bufferSizeBytes - atByte; int maxSize = bufferSizeBytes - atByte;
int codeLength = numberOfThreeBitSectionsInCode(voxelCode, maxSize); int codeLength = numberOfThreeBitSectionsInCode(voxelCode, maxSize);
if (codeLength == OVERFLOWED_OCTCODE_BUFFER) { if (codeLength == OVERFLOWED_OCTCODE_BUFFER) {
printf("WARNING! Got remove voxel bitstream that would overflow buffer in numberOfThreeBitSectionsInCode(), "); printf("WARNING! Got remove voxel bitstream that would overflow buffer in numberOfThreeBitSectionsInCode(), ");
printf("bailing processing of packet!\n"); printf("bailing processing of packet!\n");
break; break;
} }
int voxelDataSize = bytesRequiredForCodeLength(codeLength) + SIZE_OF_COLOR_DATA; int voxelDataSize = bytesRequiredForCodeLength(codeLength) + SIZE_OF_COLOR_DATA;
if (atByte + voxelDataSize <= bufferSizeBytes) { if (atByte + voxelDataSize <= bufferSizeBytes) {
deleteOctalCodeFromTree(voxelCode, COLLAPSE_EMPTY_TREE); deleteOctalCodeFromTree(voxelCode, COLLAPSE_EMPTY_TREE);
voxelCode += voxelDataSize; voxelCode += voxelDataSize;
@ -572,7 +572,7 @@ bool findRayIntersectionOp(OctreeElement* node, void* extraData) {
bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
OctreeElement*& node, float& distance, BoxFace& face) { OctreeElement*& node, float& distance, BoxFace& face) {
RayArgs args = { origin / static_cast<float>(TREE_SCALE), direction, node, distance, face }; RayArgs args = { origin / (float)(TREE_SCALE), direction, node, distance, face };
recurseTreeWithOperation(findRayIntersectionOp, &args); recurseTreeWithOperation(findRayIntersectionOp, &args);
return args.found; return args.found;
} }
@ -600,21 +600,21 @@ bool findSpherePenetrationOp(OctreeElement* element, void* extraData) {
if (element->hasContent()) { if (element->hasContent()) {
glm::vec3 elementPenetration; glm::vec3 elementPenetration;
if (element->findSpherePenetration(args->center, args->radius, elementPenetration, &args->penetratedObject)) { if (element->findSpherePenetration(args->center, args->radius, elementPenetration, &args->penetratedObject)) {
args->penetration = addPenetrations(args->penetration, elementPenetration * static_cast<float>(TREE_SCALE)); args->penetration = addPenetrations(args->penetration, elementPenetration * (float)(TREE_SCALE));
args->found = true; args->found = true;
} }
} }
return false; return false;
} }
bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration,
void** penetratedObject) { void** penetratedObject) {
SphereArgs args = { SphereArgs args = {
center / static_cast<float>(TREE_SCALE), center / (float)(TREE_SCALE),
radius / static_cast<float>(TREE_SCALE), radius / (float)(TREE_SCALE),
penetration, penetration,
false, false,
NULL }; NULL };
penetration = glm::vec3(0.0f, 0.0f, 0.0f); penetration = glm::vec3(0.0f, 0.0f, 0.0f);
recurseTreeWithOperation(findSpherePenetrationOp, &args); recurseTreeWithOperation(findSpherePenetrationOp, &args);
@ -647,7 +647,7 @@ bool findCapsulePenetrationOp(OctreeElement* node, void* extraData) {
if (node->hasContent()) { if (node->hasContent()) {
glm::vec3 nodePenetration; glm::vec3 nodePenetration;
if (box.findCapsulePenetration(args->start, args->end, args->radius, nodePenetration)) { if (box.findCapsulePenetration(args->start, args->end, args->radius, nodePenetration)) {
args->penetration = addPenetrations(args->penetration, nodePenetration * static_cast<float>(TREE_SCALE)); args->penetration = addPenetrations(args->penetration, nodePenetration * (float)(TREE_SCALE));
args->found = true; args->found = true;
} }
} }
@ -655,17 +655,17 @@ bool findCapsulePenetrationOp(OctreeElement* node, void* extraData) {
} }
bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) { bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) {
CapsuleArgs args = { CapsuleArgs args = {
start / static_cast<float>(TREE_SCALE), start / (float)(TREE_SCALE),
end / static_cast<float>(TREE_SCALE), end / (float)(TREE_SCALE),
radius / static_cast<float>(TREE_SCALE), radius / (float)(TREE_SCALE),
penetration }; penetration };
penetration = glm::vec3(0.0f, 0.0f, 0.0f); penetration = glm::vec3(0.0f, 0.0f, 0.0f);
recurseTreeWithOperation(findCapsulePenetrationOp, &args); recurseTreeWithOperation(findCapsulePenetrationOp, &args);
return args.found; return args.found;
} }
int Octree::encodeTreeBitstream(OctreeElement* node, int Octree::encodeTreeBitstream(OctreeElement* node,
OctreePacketData* packetData, OctreeElementBag& bag, OctreePacketData* packetData, OctreeElementBag& bag,
EncodeBitstreamParams& params) { EncodeBitstreamParams& params) {
@ -680,7 +680,7 @@ int Octree::encodeTreeBitstream(OctreeElement* node,
} }
startEncoding(node); startEncoding(node);
// If we're at a node that is out of view, then we can return, because no nodes below us will be in view! // If we're at a node that is out of view, then we can return, because no nodes below us will be in view!
if (params.viewFrustum && !node->isInView(*params.viewFrustum)) { if (params.viewFrustum && !node->isInView(*params.viewFrustum)) {
doneEncoding(node); doneEncoding(node);
@ -696,7 +696,7 @@ int Octree::encodeTreeBitstream(OctreeElement* node,
roomForOctalCode = packetData->startSubTree(newCode); roomForOctalCode = packetData->startSubTree(newCode);
if (newCode) { if (newCode) {
delete newCode; delete newCode;
} else { } else {
codeLength = 1; codeLength = 1;
} }
@ -712,23 +712,23 @@ int Octree::encodeTreeBitstream(OctreeElement* node,
params.stopReason = EncodeBitstreamParams::DIDNT_FIT; params.stopReason = EncodeBitstreamParams::DIDNT_FIT;
return bytesWritten; return bytesWritten;
} }
bytesWritten += codeLength; // keep track of byte count bytesWritten += codeLength; // keep track of byte count
int currentEncodeLevel = 0; int currentEncodeLevel = 0;
// record some stats, this is the one node that we won't record below in the recursion function, so we need to // record some stats, this is the one node that we won't record below in the recursion function, so we need to
// track it here // track it here
if (params.stats) { if (params.stats) {
params.stats->traversed(node); params.stats->traversed(node);
} }
int childBytesWritten = encodeTreeBitstreamRecursion(node, packetData, bag, params, currentEncodeLevel); int childBytesWritten = encodeTreeBitstreamRecursion(node, packetData, bag, params, currentEncodeLevel);
// if childBytesWritten == 1 then something went wrong... that's not possible // if childBytesWritten == 1 then something went wrong... that's not possible
assert(childBytesWritten != 1); assert(childBytesWritten != 1);
// if includeColor and childBytesWritten == 2, then it can only mean that the lower level trees don't exist or for some // if includeColor and childBytesWritten == 2, then it can only mean that the lower level trees don't exist or for some
// reason couldn't be written... so reset them here... This isn't true for the non-color included case // reason couldn't be written... so reset them here... This isn't true for the non-color included case
if (params.includeColor && childBytesWritten == 2) { if (params.includeColor && childBytesWritten == 2) {
childBytesWritten = 0; childBytesWritten = 0;
@ -743,19 +743,19 @@ int Octree::encodeTreeBitstream(OctreeElement* node,
bytesWritten = 0; bytesWritten = 0;
//params.stopReason = EncodeBitstreamParams::DIDNT_FIT; //params.stopReason = EncodeBitstreamParams::DIDNT_FIT;
} }
if (bytesWritten == 0) { if (bytesWritten == 0) {
packetData->discardSubTree(); packetData->discardSubTree();
} else { } else {
packetData->endSubTree(); packetData->endSubTree();
} }
doneEncoding(node); doneEncoding(node);
return bytesWritten; return bytesWritten;
} }
int Octree::encodeTreeBitstreamRecursion(OctreeElement* node, int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
OctreePacketData* packetData, OctreeElementBag& bag, OctreePacketData* packetData, OctreeElementBag& bag,
EncodeBitstreamParams& params, int& currentEncodeLevel) const { EncodeBitstreamParams& params, int& currentEncodeLevel) const {
// How many bytes have we written so far at this level; // How many bytes have we written so far at this level;
@ -770,7 +770,7 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
// Keep track of how deep we've encoded. // Keep track of how deep we've encoded.
currentEncodeLevel++; currentEncodeLevel++;
params.maxLevelReached = std::max(currentEncodeLevel,params.maxLevelReached); params.maxLevelReached = std::max(currentEncodeLevel,params.maxLevelReached);
// If we've reached our max Search Level, then stop searching. // If we've reached our max Search Level, then stop searching.
@ -788,11 +788,11 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
return bytesAtThisLevel; return bytesAtThisLevel;
} }
} }
// caller can pass NULL as viewFrustum if they want everything // caller can pass NULL as viewFrustum if they want everything
if (params.viewFrustum) { if (params.viewFrustum) {
float distance = node->distanceToCamera(*params.viewFrustum); float distance = node->distanceToCamera(*params.viewFrustum);
float boundaryDistance = boundaryDistanceForRenderLevel(node->getLevel() + params.boundaryLevelAdjust, float boundaryDistance = boundaryDistanceForRenderLevel(node->getLevel() + params.boundaryLevelAdjust,
params.octreeElementSizeScale); params.octreeElementSizeScale);
// If we're too far away for our render level, then just return // If we're too far away for our render level, then just return
@ -814,28 +814,28 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
params.stopReason = EncodeBitstreamParams::OUT_OF_VIEW; params.stopReason = EncodeBitstreamParams::OUT_OF_VIEW;
return bytesAtThisLevel; return bytesAtThisLevel;
} }
// Ok, we are in view, but if we're in delta mode, then we also want to make sure we weren't already in view // Ok, we are in view, but if we're in delta mode, then we also want to make sure we weren't already in view
// because we don't send nodes from the previously know in view frustum. // because we don't send nodes from the previously know in view frustum.
bool wasInView = false; bool wasInView = false;
if (params.deltaViewFrustum && params.lastViewFrustum) { if (params.deltaViewFrustum && params.lastViewFrustum) {
ViewFrustum::location location = node->inFrustum(*params.lastViewFrustum); ViewFrustum::location location = node->inFrustum(*params.lastViewFrustum);
// If we're a leaf, then either intersect or inside is considered "formerly in view" // If we're a leaf, then either intersect or inside is considered "formerly in view"
if (node->isLeaf()) { if (node->isLeaf()) {
wasInView = location != ViewFrustum::OUTSIDE; wasInView = location != ViewFrustum::OUTSIDE;
} else { } else {
wasInView = location == ViewFrustum::INSIDE; wasInView = location == ViewFrustum::INSIDE;
} }
// If we were in view, double check that we didn't switch LOD visibility... namely, the was in view doesn't // If we were in view, double check that we didn't switch LOD visibility... namely, the was in view doesn't
// tell us if it was so small we wouldn't have rendered it. Which may be the case. And we may have moved closer // tell us if it was so small we wouldn't have rendered it. Which may be the case. And we may have moved closer
// to it, and so therefore it may now be visible from an LOD perspective, in which case we don't consider it // to it, and so therefore it may now be visible from an LOD perspective, in which case we don't consider it
// as "was in view"... // as "was in view"...
if (wasInView) { if (wasInView) {
float distance = node->distanceToCamera(*params.lastViewFrustum); float distance = node->distanceToCamera(*params.lastViewFrustum);
float boundaryDistance = boundaryDistanceForRenderLevel(node->getLevel() + params.boundaryLevelAdjust, float boundaryDistance = boundaryDistanceForRenderLevel(node->getLevel() + params.boundaryLevelAdjust,
params.octreeElementSizeScale); params.octreeElementSizeScale);
if (distance >= boundaryDistance) { if (distance >= boundaryDistance) {
// This would have been invisible... but now should be visible (we wouldn't be here otherwise)... // This would have been invisible... but now should be visible (we wouldn't be here otherwise)...
@ -855,9 +855,9 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
return bytesAtThisLevel; return bytesAtThisLevel;
} }
// If we're not in delta sending mode, and we weren't asked to do a force send, and the voxel hasn't changed, // If we're not in delta sending mode, and we weren't asked to do a force send, and the voxel hasn't changed,
// then we can also bail early and save bits // then we can also bail early and save bits
if (!params.forceSendScene && !params.deltaViewFrustum && if (!params.forceSendScene && !params.deltaViewFrustum &&
!node->hasChangedSince(params.lastViewFrustumSent - CHANGE_FUDGE)) { !node->hasChangedSince(params.lastViewFrustumSent - CHANGE_FUDGE)) {
if (params.stats) { if (params.stats) {
params.stats->skippedNoChange(node); params.stats->skippedNoChange(node);
@ -896,9 +896,9 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
bool keepDiggingDeeper = true; // Assuming we're in view we have a great work ethic, we're always ready for more! bool keepDiggingDeeper = true; // Assuming we're in view we have a great work ethic, we're always ready for more!
// At any given point in writing the bitstream, the largest minimum we might need to flesh out the current level // At any given point in writing the bitstream, the largest minimum we might need to flesh out the current level
// is 1 byte for child colors + 3*NUMBER_OF_CHILDREN bytes for the actual colors + 1 byte for child trees. // is 1 byte for child colors + 3*NUMBER_OF_CHILDREN bytes for the actual colors + 1 byte for child trees.
// There could be sub trees below this point, which might take many more bytes, but that's ok, because we can // There could be sub trees below this point, which might take many more bytes, but that's ok, because we can
// always mark our subtrees as not existing and stop the packet at this point, then start up with a new packet // always mark our subtrees as not existing and stop the packet at this point, then start up with a new packet
// for the remaining sub trees. // for the remaining sub trees.
unsigned char childrenExistInTreeBits = 0; unsigned char childrenExistInTreeBits = 0;
unsigned char childrenExistInPacketBits = 0; unsigned char childrenExistInPacketBits = 0;
@ -972,7 +972,7 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
// Before we determine consider this further, let's see if it's in our LOD scope... // Before we determine consider this further, let's see if it's in our LOD scope...
float distance = distancesToChildren[i]; // params.viewFrustum ? childNode->distanceToCamera(*params.viewFrustum) : 0; float distance = distancesToChildren[i]; // params.viewFrustum ? childNode->distanceToCamera(*params.viewFrustum) : 0;
float boundaryDistance = !params.viewFrustum ? 1 : float boundaryDistance = !params.viewFrustum ? 1 :
boundaryDistanceForRenderLevel(childNode->getLevel() + params.boundaryLevelAdjust, boundaryDistanceForRenderLevel(childNode->getLevel() + params.boundaryLevelAdjust,
params.octreeElementSizeScale); params.octreeElementSizeScale);
if (!(distance < boundaryDistance)) { if (!(distance < boundaryDistance)) {
@ -1024,12 +1024,12 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
} // wants occlusion culling & isLeaf() } // wants occlusion culling & isLeaf()
bool shouldRender = !params.viewFrustum bool shouldRender = !params.viewFrustum
? true ? true
: childNode->calculateShouldRender(params.viewFrustum, : childNode->calculateShouldRender(params.viewFrustum,
params.octreeElementSizeScale, params.boundaryLevelAdjust); params.octreeElementSizeScale, params.boundaryLevelAdjust);
// track some stats // track some stats
if (params.stats) { if (params.stats) {
// don't need to check childNode here, because we can't get here with no childNode // don't need to check childNode here, because we can't get here with no childNode
if (!shouldRender && childNode->isLeaf()) { if (!shouldRender && childNode->isLeaf()) {
@ -1040,29 +1040,29 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
params.stats->skippedOccluded(childNode); params.stats->skippedOccluded(childNode);
} }
} }
// track children with actual color, only if the child wasn't previously in view! // track children with actual color, only if the child wasn't previously in view!
if (shouldRender && !childIsOccluded) { if (shouldRender && !childIsOccluded) {
bool childWasInView = false; bool childWasInView = false;
if (childNode && params.deltaViewFrustum && params.lastViewFrustum) { if (childNode && params.deltaViewFrustum && params.lastViewFrustum) {
ViewFrustum::location location = childNode->inFrustum(*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 we're a leaf, then either intersect or inside is considered "formerly in view"
if (childNode->isLeaf()) { if (childNode->isLeaf()) {
childWasInView = location != ViewFrustum::OUTSIDE; childWasInView = location != ViewFrustum::OUTSIDE;
} else { } else {
childWasInView = location == ViewFrustum::INSIDE; 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 our child wasn't in view (or we're ignoring wasInView) then we add it to our sending items.
// Or if we were previously in the view, but this node has changed since it was last sent, then we do // Or if we were previously in the view, but this node has changed since it was last sent, then we do
// need to send it. // need to send it.
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 {
@ -1080,10 +1080,10 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
} }
} }
} }
bool continueThisLevel = true; bool continueThisLevel = true;
continueThisLevel = packetData->appendBitMask(childrenColoredBits); continueThisLevel = packetData->appendBitMask(childrenColoredBits);
if (continueThisLevel) { if (continueThisLevel) {
bytesAtThisLevel += sizeof(childrenColoredBits); // keep track of byte count bytesAtThisLevel += sizeof(childrenColoredBits); // keep track of byte count
if (params.stats) { if (params.stats) {
@ -1100,11 +1100,11 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
int bytesBeforeChild = packetData->getUncompressedSize(); int bytesBeforeChild = packetData->getUncompressedSize();
continueThisLevel = childNode->appendElementData(packetData); continueThisLevel = childNode->appendElementData(packetData);
int bytesAfterChild = packetData->getUncompressedSize(); int bytesAfterChild = packetData->getUncompressedSize();
if (!continueThisLevel) { if (!continueThisLevel) {
break; // no point in continuing break; // no point in continuing
} }
bytesAtThisLevel += (bytesAfterChild - bytesBeforeChild); // keep track of byte count for this child bytesAtThisLevel += (bytesAfterChild - bytesBeforeChild); // keep track of byte count for this child
// don't need to check childNode here, because we can't get here with no childNode // don't need to check childNode here, because we can't get here with no childNode
@ -1138,7 +1138,7 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
} }
} }
} }
// We only need to keep digging, if there is at least one child that is inView, and not a leaf. // We only need to keep digging, if there is at least one child that is inView, and not a leaf.
keepDiggingDeeper = (inViewNotLeafCount > 0); keepDiggingDeeper = (inViewNotLeafCount > 0);
@ -1181,7 +1181,7 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
// XXXBHG - Note, this seems like the correct logic here, if we included the color in this packet, then // 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 would not be visible... and if so, we shouldn't recurse // the LOD logic determined that the child nodes would not be visible... and if so, we shouldn't recurse
// them further. But... for some time now the code has included and recursed into these child nodes, which // them further. But... for some time now the code has included and recursed into these child nodes, which
// would likely still send the child content, even though the client wouldn't render it. This change is // would likely still send the child content, even though the client wouldn't render it. This change is
// a major savings (~30%) and it seems to work correctly. But I want us to discuss as a group when we do // a major savings (~30%) and it seems to work correctly. But I want us to discuss as a group when we do
// a voxel protocol review. // a voxel protocol review.
// //
@ -1232,7 +1232,7 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
// repair the child exists mask // repair the child exists mask
continueThisLevel = packetData->updatePriorBitMask(childExistsPlaceHolder, childrenExistInPacketBits); continueThisLevel = packetData->updatePriorBitMask(childExistsPlaceHolder, childrenExistInPacketBits);
// If this is the last of the child exists bits, then we're actually be rolling out the entire tree // If this is the last of the child exists bits, then we're actually be rolling out the entire tree
if (params.stats && childrenExistInPacketBits == 0) { if (params.stats && childrenExistInPacketBits == 0) {
params.stats->childBitsRemoved(params.includeExistsBits, params.includeColor); params.stats->childBitsRemoved(params.includeExistsBits, params.includeColor);
@ -1241,7 +1241,7 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
if (!continueThisLevel) { if (!continueThisLevel) {
break; // can't continue... break; // can't continue...
} }
// Note: no need to move the pointer, cause we already stored this // Note: no need to move the pointer, cause we already stored this
} // end if (childTreeBytesOut == 0) } // end if (childTreeBytesOut == 0)
} // end if (oneAtBit(childrenExistInPacketBits, originalIndex)) } // end if (oneAtBit(childrenExistInPacketBits, originalIndex))
@ -1282,14 +1282,14 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* node,
printf("\n"); 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 = packetData->endLevel(thisLevelKey); continueThisLevel = packetData->endLevel(thisLevelKey);
} else { } else {
packetData->discardLevel(thisLevelKey); packetData->discardLevel(thisLevelKey);
} }
if (!continueThisLevel) { if (!continueThisLevel) {
bag.insert(node); bag.insert(node);
@ -1325,7 +1325,7 @@ bool Octree::readFromSVOFile(const char* fileName) {
unsigned char* dataAt = entireFile; unsigned char* dataAt = entireFile;
unsigned long dataLength = fileLength; unsigned long dataLength = fileLength;
// before reading the file, check to see if this version of the Octree supports file versions // before reading the file, check to see if this version of the Octree supports file versions
if (getWantSVOfileVersions()) { if (getWantSVOfileVersions()) {
// if so, read the first byte of the file and see if it matches the expected version code // if so, read the first byte of the file and see if it matches the expected version code
@ -1368,7 +1368,7 @@ void Octree::writeToSVOFile(const char* fileName, OctreeElement* node) {
if(file.is_open()) { if(file.is_open()) {
qDebug("saving to file %s...\n", fileName); qDebug("saving to file %s...\n", fileName);
// before reading the file, check to see if this version of the Octree supports file versions // before reading the file, check to see if this version of the Octree supports file versions
if (getWantSVOfileVersions()) { if (getWantSVOfileVersions()) {
// if so, read the first byte of the file and see if it matches the expected version code // if so, read the first byte of the file and see if it matches the expected version code
@ -1377,7 +1377,7 @@ void Octree::writeToSVOFile(const char* fileName, OctreeElement* node) {
file.write(&expectedType, sizeof(expectedType)); file.write(&expectedType, sizeof(expectedType));
file.write(&expectedVersion, sizeof(expectedType)); file.write(&expectedVersion, sizeof(expectedType));
} }
OctreeElementBag nodeBag; OctreeElementBag nodeBag;
// If we were given a specific node, start from there, otherwise start from root // If we were given a specific node, start from there, otherwise start from root
if (node) { if (node) {
@ -1392,7 +1392,7 @@ void Octree::writeToSVOFile(const char* fileName, OctreeElement* node) {
while (!nodeBag.isEmpty()) { while (!nodeBag.isEmpty()) {
OctreeElement* subTree = nodeBag.extract(); OctreeElement* subTree = nodeBag.extract();
lockForRead(); // do tree locking down here so that we have shorter slices and less thread contention lockForRead(); // do tree locking down here so that we have shorter slices and less thread contention
EncodeBitstreamParams params(INT_MAX, IGNORE_VIEW_FRUSTUM, WANT_COLOR, NO_EXISTS_BITS); EncodeBitstreamParams params(INT_MAX, IGNORE_VIEW_FRUSTUM, WANT_COLOR, NO_EXISTS_BITS);
bytesWritten = encodeTreeBitstream(subTree, &packetData, nodeBag, params); bytesWritten = encodeTreeBitstream(subTree, &packetData, nodeBag, params);
@ -1480,7 +1480,7 @@ void Octree::copyFromTreeIntoSubTree(Octree* sourceTree, OctreeElement* destinat
while (!nodeBag.isEmpty()) { while (!nodeBag.isEmpty()) {
OctreeElement* subTree = nodeBag.extract(); OctreeElement* subTree = nodeBag.extract();
packetData.reset(); // reset between usage packetData.reset(); // reset between usage
// ask our tree to write a bitsteam // ask our tree to write a bitsteam
@ -1513,7 +1513,7 @@ void Octree::doneEncoding(OctreeElement* node) {
pthread_mutex_lock(&_encodeSetLock); pthread_mutex_lock(&_encodeSetLock);
_codesBeingEncoded.erase(node->getOctalCode()); _codesBeingEncoded.erase(node->getOctalCode());
pthread_mutex_unlock(&_encodeSetLock); pthread_mutex_unlock(&_encodeSetLock);
// if we have any pending delete codes, then delete them now. // if we have any pending delete codes, then delete them now.
emptyDeleteQueue(); emptyDeleteQueue();
} }