From e57db88c07f5b9e6ce23b2a2e65c49f14935195c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 7 Jun 2013 10:28:25 -0700 Subject: [PATCH 1/3] remove redundant calls to reaverageVoxelColors() now only use recursion unwinding --- libraries/voxels/src/VoxelTree.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index ab724d92a9..4e2de6afc6 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -261,7 +261,6 @@ void VoxelTree::deleteVoxelAt(float x, float y, float z, float s, bool stage) { unsigned char* octalCode = pointToVoxel(x,y,z,s,0,0,0); deleteVoxelCodeFromTree(octalCode, stage); delete octalCode; // cleanup memory - reaverageVoxelColors(rootNode); } @@ -365,9 +364,6 @@ void VoxelTree::deleteVoxelCodeFromTreeRecursion(VoxelNode* node, void* extraDat childNode->stageForDeletion(); } else { node->deleteChildAtIndex(childIndex); // note: this will track dirtiness and lastChanged for this node - if (_shouldReaverage) { - node->setColorFromAverageOfChildren(); - } } // track our tree dirtiness @@ -503,7 +499,6 @@ void VoxelTree::processRemoveVoxelBitstream(unsigned char * bitstream, int buffe voxelCode+=voxelDataSize; atByte+=voxelDataSize; } - reaverageVoxelColors(rootNode); // Fix our colors!! Need to call it on rootNode } void VoxelTree::printTreeForDebugging(VoxelNode *startNode) { @@ -552,6 +547,7 @@ void VoxelTree::printTreeForDebugging(VoxelNode *startNode) { } } +// Note: this is an expensive call. Don't call it unless you really need to reaverage the entire tree (from startNode) void VoxelTree::reaverageVoxelColors(VoxelNode *startNode) { // if our tree is a reaveraging tree, then we do this, otherwise we don't do anything if (_shouldReaverage) { @@ -785,7 +781,6 @@ void VoxelTree::createSphere(float radius, float xc, float yc, float zc, float v thisRadius += thisVoxelSize; thisVoxelSize = std::max(voxelSize, thisVoxelSize / 2.0f); } - this->reaverageVoxelColors(this->rootNode); } int VoxelTree::searchForColoredNodes(int maxSearchLevel, VoxelNode* node, const ViewFrustum& viewFrustum, VoxelNodeBag& bag, From 479e8c78110d9ff9c8bc02cc72582b836f041d11 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 7 Jun 2013 10:29:05 -0700 Subject: [PATCH 2/3] add shortcut key for Kill Local Voxels to help debugging of LOD --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 01eb42239b..94b9643bf9 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1456,7 +1456,7 @@ void Application::initMenu() { QMenu* renderDebugMenu = debugMenu->addMenu("Render Debugging Tools"); renderDebugMenu->addAction("Show Render Pipeline Warnings", this, SLOT(setRenderWarnings(bool)))->setCheckable(true); - renderDebugMenu->addAction("Kill Local Voxels", this, SLOT(doKillLocalVoxels())); + renderDebugMenu->addAction("Kill Local Voxels", this, SLOT(doKillLocalVoxels()), Qt::CTRL | Qt::Key_K); renderDebugMenu->addAction("Randomize Voxel TRUE Colors", this, SLOT(doRandomizeVoxelColors()), Qt::CTRL | Qt::Key_R); renderDebugMenu->addAction("FALSE Color Voxels Randomly", this, SLOT(doFalseRandomizeVoxelColors())); renderDebugMenu->addAction("FALSE Color Voxel Every Other Randomly", this, SLOT(doFalseRandomizeEveryOtherVoxelColors())); From 065e85e328b48b91b561cc9efdf0b24dc0ed4f12 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 7 Jun 2013 10:29:56 -0700 Subject: [PATCH 3/3] rename server's VoxelTree and make it a color reaveragging tree --- voxel-server/src/main.cpp | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 9bf4a1dcc4..81a92d4d07 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -51,7 +51,7 @@ const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4; const int ENVIRONMENT_SEND_INTERVAL_USECS = 1000000; -VoxelTree randomTree(false); // this is NOT a reaveraging tree +VoxelTree serverTree(true); // this IS a reaveraging tree bool wantVoxelPersist = true; bool wantLocalDomain = false; @@ -98,7 +98,7 @@ void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) { void eraseVoxelTreeAndCleanupAgentVisitData() { // As our tree to erase all it's voxels - ::randomTree.eraseAllVoxels(); + ::serverTree.eraseAllVoxels(); // enumerate the agents clean up their marker nodes for (AgentList::iterator agent = AgentList::getInstance()->begin(); agent != AgentList::getInstance()->end(); agent++) { VoxelAgentData* agentData = (VoxelAgentData*) agent->getLinkedData(); @@ -123,7 +123,7 @@ void resInVoxelDistributor(AgentList* agentList, searchLoops++; searchLevelWas = agentData->getMaxSearchLevel(); - int maxLevelReached = randomTree.searchForColoredNodes(agentData->getMaxSearchLevel(), randomTree.rootNode, + int maxLevelReached = serverTree.searchForColoredNodes(agentData->getMaxSearchLevel(), serverTree.rootNode, viewFrustum, agentData->nodeBag); agentData->setMaxLevelReached(maxLevelReached); @@ -167,7 +167,7 @@ void resInVoxelDistributor(AgentList* agentList, while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) { if (!agentData->nodeBag.isEmpty()) { VoxelNode* subTree = agentData->nodeBag.extract(); - bytesWritten = randomTree.encodeTreeBitstream(agentData->getMaxSearchLevel(), subTree, + bytesWritten = serverTree.encodeTreeBitstream(agentData->getMaxSearchLevel(), subTree, &tempOutputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, agentData->nodeBag, &viewFrustum, agentData->getWantColor(), WANT_EXISTS_BITS); @@ -268,16 +268,16 @@ void deepestLevelVoxelDistributor(AgentList* agentList, // helps improve overall bitrate performance. if (::wantSearchForColoredNodes) { // If the bag was empty, then send everything in view, not just the delta - maxLevelReached = randomTree.searchForColoredNodes(INT_MAX, randomTree.rootNode, agentData->getCurrentViewFrustum(), + maxLevelReached = serverTree.searchForColoredNodes(INT_MAX, serverTree.rootNode, agentData->getCurrentViewFrustum(), agentData->nodeBag, wantDelta, lastViewFrustum); // if nothing was found in view, send the root node. if (agentData->nodeBag.isEmpty()){ - agentData->nodeBag.insert(randomTree.rootNode); + agentData->nodeBag.insert(serverTree.rootNode); } agentData->setViewSent(false); } else { - agentData->nodeBag.insert(randomTree.rootNode); + agentData->nodeBag.insert(serverTree.rootNode); } } @@ -310,7 +310,7 @@ void deepestLevelVoxelDistributor(AgentList* agentList, while (packetsSentThisInterval < PACKETS_PER_CLIENT_PER_INTERVAL - (shouldSendEnvironments ? 1 : 0)) { if (!agentData->nodeBag.isEmpty()) { VoxelNode* subTree = agentData->nodeBag.extract(); - bytesWritten = randomTree.encodeTreeBitstream(INT_MAX, subTree, + bytesWritten = serverTree.encodeTreeBitstream(INT_MAX, subTree, &tempOutputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, agentData->nodeBag, &agentData->getCurrentViewFrustum(), agentData->getWantColor(), WANT_EXISTS_BITS, @@ -386,14 +386,14 @@ void persistVoxelsWhenDirty() { double sinceLastTime = (now - ::lastPersistVoxels) / 1000.0; // check the dirty bit and persist here... - if (::wantVoxelPersist && ::randomTree.isDirty() && sinceLastTime > VOXEL_PERSIST_INTERVAL) { + if (::wantVoxelPersist && ::serverTree.isDirty() && sinceLastTime > VOXEL_PERSIST_INTERVAL) { { PerformanceWarning warn(::shouldShowAnimationDebug, "persistVoxelsWhenDirty() - reaverageVoxelColors()", ::shouldShowAnimationDebug); // after done inserting all these voxels, then reaverage colors - randomTree.reaverageVoxelColors(randomTree.rootNode); + serverTree.reaverageVoxelColors(serverTree.rootNode); } @@ -402,8 +402,8 @@ void persistVoxelsWhenDirty() { "persistVoxelsWhenDirty() - writeToSVOFile()", ::shouldShowAnimationDebug); printf("saving voxels to file...\n"); - randomTree.writeToSVOFile(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE); - randomTree.clearDirtyBit(); // tree is clean after saving + serverTree.writeToSVOFile(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE); + serverTree.clearDirtyBit(); // tree is clean after saving printf("DONE saving voxels to file...\n"); } ::lastPersistVoxels = usecTimestampNow(); @@ -505,10 +505,10 @@ int main(int argc, const char * argv[]) { bool persistantFileRead = false; if (::wantVoxelPersist) { printf("loading voxels from file...\n"); - persistantFileRead = ::randomTree.readFromSVOFile(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE); - ::randomTree.clearDirtyBit(); // the tree is clean since we just loaded it + persistantFileRead = ::serverTree.readFromSVOFile(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE); + ::serverTree.clearDirtyBit(); // the tree is clean since we just loaded it printf("DONE loading voxels from file... fileRead=%s\n", debug::valueOf(persistantFileRead)); - unsigned long nodeCount = ::randomTree.getVoxelCount(); + unsigned long nodeCount = ::serverTree.getVoxelCount(); printf("Nodes after loading scene %ld nodes\n", nodeCount); } @@ -517,7 +517,7 @@ int main(int argc, const char * argv[]) { const char* INPUT_FILE = "-i"; const char* voxelsFilename = getCmdOption(argc, argv, INPUT_FILE); if (voxelsFilename) { - randomTree.readFromSVOFile(voxelsFilename); + serverTree.readFromSVOFile(voxelsFilename); } // Check to see if the user passed in a command line option for setting packet send rate @@ -535,7 +535,7 @@ int main(int argc, const char * argv[]) { if (cmdOptionExists(argc, argv, ADD_RANDOM_VOXELS)) { // create an octal code buffer and load it with 0 so that the recursive tree fill can give // octal codes to the tree nodes that it is creating - randomlyFillVoxelTree(MAX_VOXEL_TREE_DEPTH_LEVELS, randomTree.rootNode); + randomlyFillVoxelTree(MAX_VOXEL_TREE_DEPTH_LEVELS, serverTree.rootNode); } const char* ADD_SCENE = "--AddScene"; @@ -554,7 +554,7 @@ int main(int argc, const char * argv[]) { // TEMPORARILY DISABLED!!! bool actuallyAddScene = false; // !noAddScene && (addScene || (::wantVoxelPersist && !persistantFileRead)); if (actuallyAddScene) { - addSphereScene(&randomTree); + addSphereScene(&serverTree); } // for now, initialize the environments with fixed values @@ -633,7 +633,7 @@ int main(int argc, const char * argv[]) { delete []vertices; } - randomTree.readCodeColorBufferToTree(voxelData, destructive); + serverTree.readCodeColorBufferToTree(voxelData, destructive); // skip to next voxelData += voxelDataSize; atByte += voxelDataSize; @@ -643,7 +643,7 @@ int main(int argc, const char * argv[]) { // Send these bits off to the VoxelTree class to process them pthread_mutex_lock(&::treeLock); - randomTree.processRemoveVoxelBitstream((unsigned char*)packetData, receivedBytes); + serverTree.processRemoveVoxelBitstream((unsigned char*)packetData, receivedBytes); pthread_mutex_unlock(&::treeLock); } if (packetData[0] == PACKET_HEADER_Z_COMMAND) { @@ -664,7 +664,7 @@ int main(int argc, const char * argv[]) { } if (strcmp(command, ADD_SCENE_COMMAND) == 0) { printf("got Z message == add scene\n"); - addSphereScene(&randomTree); + addSphereScene(&serverTree); rebroadcast = false; } if (strcmp(command, TEST_COMMAND) == 0) {