From 2f6b2466ea714304d310f7afd14d1f9849a08f60 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 25 Mar 2013 22:39:24 -0700 Subject: [PATCH] Fixed getCommandOption and cmOptionExists to be more porable added support for --NoConnect command line option to test running without connecting added pruneTree to VoxelTree --- interface/src/VoxelSystem.cpp | 32 ++++++++++++++++++++++------- interface/src/main.cpp | 12 +++++++++-- shared/src/SharedUtil.cpp | 33 +++++++++++++++++++++--------- shared/src/SharedUtil.h | 4 ++-- shared/src/VoxelTree.cpp | 38 +++++++++++++++++++++++++++++++++++ shared/src/VoxelTree.h | 3 ++- 6 files changed, 101 insertions(+), 21 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 4e88d01ddf..bf1f8bbedb 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -56,6 +56,7 @@ VoxelSystem::~VoxelSystem() { // Complaints: Brad :) // To Do: Need to add color data to the file. void VoxelSystem::loadVoxelsFile(char* fileName) { + int vCount = 0; std::ifstream file(fileName, std::ios::in|std::ios::binary); @@ -65,10 +66,11 @@ void VoxelSystem::loadVoxelsFile(char* fileName) { int totalBytesRead = 0; if(file.is_open()) { - while (!file.eof()) { + bool bail = false; + while (!file.eof() && !bail) { file.get(octets); totalBytesRead++; - lengthInBytes = (octets*3/8)+1; + lengthInBytes = bytesRequiredForCodeLength(octets)-1; //(octets*3/8)+1; unsigned char * voxelData = new unsigned char[lengthInBytes+1+3]; voxelData[0]=octets; char byte; @@ -78,16 +80,32 @@ void VoxelSystem::loadVoxelsFile(char* fileName) { totalBytesRead++; voxelData[i+1] = byte; } - // random color data - voxelData[lengthInBytes+1] = randomColorValue(65); - voxelData[lengthInBytes+2] = randomColorValue(65); - voxelData[lengthInBytes+3] = randomColorValue(65); - + // read color data + char red,green,blue; + file.get(red); + file.get(green); + file.get(blue); + + //printf("red:%d\n",red); + //printf("green:%d\n",green); + //printf("blue:%d\n",blue); + vCount++; + //printf("vCount:%d\n",vCount); + + //randomColorValue(65); + float rf = randFloatInRange(.5,1); // add a little bit of variance to colors so we can see the voxels + voxelData[lengthInBytes+1] = red * rf; + voxelData[lengthInBytes+2] = green * rf; + voxelData[lengthInBytes+3] = blue * rf; + + //printVoxelCode(voxelData); tree->readCodeColorBufferToTree(voxelData); delete voxelData; } file.close(); } + + tree->pruneTree(tree->rootNode); // reset the verticesEndPointer so we're writing to the beginning of the array verticesEndPointer = verticesArray; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 3df7672a2f..4bfc5d1a63 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -64,7 +64,7 @@ int simulate_on = 1; // Network Socket and network constants // -char DOMAIN_HOSTNAME[] = "highfidelity.below92.com"; +char DOMAIN_HOSTNAME[100] = "highfidelity.below92.com"; char DOMAIN_IP[100] = ""; // IP Address will be used first if not empty string const int DOMAINSERVER_PORT = 40102; @@ -948,6 +948,14 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) { int main(int argc, char** argv) { + // pass --NoConnect as a command line option to force NOT connecting + // to the hifidelity domain, and therefore run locally. + if (cmdOptionExists(argc, argv, "--NoConnect")) + { + strcpy(DOMAIN_HOSTNAME,""); + } + + #ifndef _WIN32 struct ifaddrs * ifAddrStruct=NULL; struct ifaddrs * ifa=NULL; @@ -1018,7 +1026,7 @@ int main(int argc, char** argv) // Check to see if the user passed in a command line option for loading a local // Voxel File. If so, load it now. - char* voxelsFilename = getCmdOption(argv, argv + argc, "-i"); + char* voxelsFilename = getCmdOption(argc, argv, "-i"); if (voxelsFilename) { voxels.loadVoxelsFile(voxelsFilename); diff --git a/shared/src/SharedUtil.cpp b/shared/src/SharedUtil.cpp index 3e9e75e2bb..c52ce2a1b6 100644 --- a/shared/src/SharedUtil.cpp +++ b/shared/src/SharedUtil.cpp @@ -86,27 +86,42 @@ void switchToResourcesIfRequired() { // immediately following the flag. For example if you ran: // ./app -i filename.txt // then you're using the "-i" flag to set the input file name. -// Usage: char * inputFilename = getCmdOption(argv, argv + argc, "-i"); +// Usage: char * inputFilename = getCmdOption(argc, argv, "-i"); // Complaints: Brad :) -char* getCmdOption(char ** begin, char ** end, const std::string & option) +char* getCmdOption(int argc, char** argv,char* option) { - char ** itr = std::find(begin, end, option); - if (itr != end && ++itr != end) + // check each arg + for (int i=0; i < argc; i++) { - return *itr; + // if the arg matches the desired option + if (strcmp(option,argv[i])==0 && i+1 < argc) + { + // then return the next option + return argv[i+1]; + } } - return 0; + return NULL; } ////////////////////////////////////////////////////////////////////////////////////////// // Function: getCmdOption() // Description: Handy little function to tell you if a command line option flag was // included while launching the application. Returns bool true/false -// Usage: bool wantDump = cmdOptionExists(argv, argv+argc, "-d"); +// Usage: bool wantDump = cmdOptionExists(argc, argv, "-d"); // Complaints: Brad :) -bool cmdOptionExists(char** begin, char** end, const std::string& option) +bool cmdOptionExists(int argc, char** argv,char* option) { - return std::find(begin, end, option) != end; + // check each arg + for (int i=0; i < argc; i++) + { + // if the arg matches the desired option + if (strcmp(option,argv[i])==0) + { + // then return the next option + return true; + } + } + return false; } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/shared/src/SharedUtil.h b/shared/src/SharedUtil.h index 1ba5ff8280..432dea0b29 100644 --- a/shared/src/SharedUtil.h +++ b/shared/src/SharedUtil.h @@ -33,8 +33,8 @@ bool oneAtBit(unsigned char byte, int bitIndex); void switchToResourcesIfRequired(); -char* getCmdOption(char ** begin, char ** end, const std::string& option); -bool cmdOptionExists(char** begin, char** end, const std::string& option); +char* getCmdOption(int argc, char** argv,char* option); +bool cmdOptionExists(int argc, char** argv,char* option); unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, unsigned char g, unsigned char b ); diff --git a/shared/src/VoxelTree.cpp b/shared/src/VoxelTree.cpp index 1c5f18b666..ca76f4067a 100644 --- a/shared/src/VoxelTree.cpp +++ b/shared/src/VoxelTree.cpp @@ -77,6 +77,44 @@ VoxelNode * VoxelTree::createMissingNode(VoxelNode *lastParentNode, unsigned cha } } +/// If node has color & <= 4 children then prune children +void VoxelTree::pruneTree(VoxelNode* pruneAt) { + int childCount = 0; + + // determine how many children we have + for (int i = 0; i < 8; i++) + { + if (pruneAt->children[i]) + { + childCount++; + } + } + // if appropriate, prune them + if (pruneAt->color[3] && childCount <= 4) + { + for (int i = 0; i < 8; i++) + { + if (pruneAt->children[i]) + { + delete pruneAt->children[i]; + pruneAt->children[i]=NULL; + } + } + } + else + { + // Otherwise, iterate the children and recursively call + // prune on all of them + for (int i = 0; i < 8; i++) + { + if (pruneAt->children[i]) + { + this->pruneTree(pruneAt->children[i]); + } + } + } +} + int VoxelTree::readNodeData(VoxelNode *destinationNode, unsigned char * nodeData, int bytesLeftToRead) { // instantiate variable for bytes already read diff --git a/shared/src/VoxelTree.h b/shared/src/VoxelTree.h index f5b8aeeced..bea2533543 100644 --- a/shared/src/VoxelTree.h +++ b/shared/src/VoxelTree.h @@ -34,7 +34,8 @@ public: VoxelNode *currentVoxelNode, int deepestLevel); void printTreeForDebugging(VoxelNode *startNode); - + + void pruneTree(VoxelNode* pruneAt); }; #endif /* defined(__hifi__VoxelTree__) */