mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 11:53:28 +02:00
Fixed getCommandOption and cmOptionExists to be more porable
added support for --NoConnect command line option to test running without connecting added pruneTree to VoxelTree
This commit is contained in:
parent
0711539fc6
commit
2f6b2466ea
6 changed files with 101 additions and 21 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -34,7 +34,8 @@ public:
|
|||
VoxelNode *currentVoxelNode,
|
||||
int deepestLevel);
|
||||
void printTreeForDebugging(VoxelNode *startNode);
|
||||
|
||||
|
||||
void pruneTree(VoxelNode* pruneAt);
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__VoxelTree__) */
|
||||
|
|
Loading…
Reference in a new issue