From 86bf268eef4f939ceb08f763a16742b8e0e906d0 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 29 Jul 2013 14:56:33 -0700 Subject: [PATCH] first cut at multiple voxel servers --- interface/src/Application.cpp | 3 ++- libraries/shared/src/NodeList.cpp | 7 +++--- libraries/shared/src/NodeList.h | 2 +- libraries/voxels/src/VoxelTree.cpp | 2 +- voxel-server/src/main.cpp | 40 +++++++++++++++++++++++++++--- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c56a58ce90..3122dcdb4f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3496,7 +3496,8 @@ void* Application::networkReceive(void* args) { } // fall through to piggyback message if (app->_renderVoxels->isChecked()) { - Node* voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER); + //Node* voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER); + Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress); if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) { voxelServer->lock(); diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 9406c6b14d..4e24a6636c 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -24,10 +24,11 @@ #include #endif -const char SOLO_NODE_TYPES[3] = { +// NODE_TYPE_VOXEL_SERVER - removed! + +const char SOLO_NODE_TYPES[2] = { NODE_TYPE_AVATAR_MIXER, - NODE_TYPE_AUDIO_MIXER, - NODE_TYPE_VOXEL_SERVER + NODE_TYPE_AUDIO_MIXER }; const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES] = "root.highfidelity.io"; diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index 2a66fc7374..4c4795bdb0 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -32,7 +32,7 @@ const unsigned int NODE_SOCKET_LISTEN_PORT = 40103; const int NODE_SILENCE_THRESHOLD_USECS = 2 * 1000000; const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000; -extern const char SOLO_NODE_TYPES[3]; +extern const char SOLO_NODE_TYPES[2]; const int MAX_HOSTNAME_BYTES = 256; diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index fe67a50dee..9df72e8f4b 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -306,7 +306,7 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, unsigned char* nodeData, } - if (includeExistsBits) { + if (false && includeExistsBits) { for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { // now also check the childrenInTreeMask, if the mask is missing the bit, then it means we need to delete this child // subtree/node, because it shouldn't actually exist in the tree. diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index c009eec2a5..58a1dd036b 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -32,8 +32,12 @@ const char* LOCAL_VOXELS_PERSIST_FILE = "resources/voxels.svo"; const char* VOXELS_PERSIST_FILE = "/etc/highfidelity/voxel-server/resources/voxels.svo"; +const int MAX_FILENAME_LENGTH = 1024; +char voxelPersistFilename[MAX_FILENAME_LENGTH]; const int VOXEL_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds +//::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE + const int VOXEL_LISTEN_PORT = 40106; @@ -375,7 +379,7 @@ void persistVoxelsWhenDirty() { "persistVoxelsWhenDirty() - writeToSVOFile()", ::shouldShowAnimationDebug); printf("saving voxels to file...\n"); - serverTree.writeToSVOFile(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE); + serverTree.writeToSVOFile(::voxelPersistFilename); serverTree.clearDirtyBit(); // tree is clean after saving printf("DONE saving voxels to file...\n"); } @@ -431,7 +435,20 @@ int main(int argc, const char * argv[]) { qInstallMsgHandler(sharedMessageHandler); - NodeList* nodeList = NodeList::createInstance(NODE_TYPE_VOXEL_SERVER, VOXEL_LISTEN_PORT); + int listenPort = VOXEL_LISTEN_PORT; + // Check to see if the user passed in a command line option for setting listen port + const char* PORT_PARAMETER = "--port"; + const char* portParameter = getCmdOption(argc, argv, PORT_PARAMETER); + if (portParameter) { + listenPort = atoi(portParameter); + if (listenPort < 1) { + listenPort = VOXEL_LISTEN_PORT; + } + printf("portParameter=%s listenPort=%d\n", portParameter, listenPort); + } + + + NodeList* nodeList = NodeList::createInstance(NODE_TYPE_VOXEL_SERVER, listenPort); setvbuf(stdout, NULL, _IOLBF, 0); // Handle Local Domain testing with the --local command line @@ -473,8 +490,19 @@ int main(int argc, const char * argv[]) { // if we want Voxel Persistance, load the local file now... bool persistantFileRead = false; if (::wantVoxelPersist) { - printf("loading voxels from file...\n"); - persistantFileRead = ::serverTree.readFromSVOFile(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE); + + // Check to see if the user passed in a command line option for setting packet send rate + const char* VOXELS_PERSIST_FILENAME = "--voxelsPersistFilename"; + const char* voxelsPersistFilenameParameter = getCmdOption(argc, argv, VOXELS_PERSIST_FILENAME); + if (voxelsPersistFilenameParameter) { + strcpy(voxelPersistFilename, voxelsPersistFilenameParameter); + } else { + strcpy(voxelPersistFilename, ::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE); + } + + printf("loading voxels from file: %s...\n", voxelPersistFilename); + + persistantFileRead = ::serverTree.readFromSVOFile(::voxelPersistFilename); if (persistantFileRead) { PerformanceWarning warn(::shouldShowAnimationDebug, "persistVoxelsWhenDirty() - reaverageVoxelColors()", ::shouldShowAnimationDebug); @@ -672,11 +700,15 @@ int main(int argc, const char * argv[]) { nodeList->broadcastToNodes(packetData, receivedBytes, &NODE_TYPE_AGENT, 1); } } else if (packetData[0] == PACKET_TYPE_HEAD_DATA) { + // If we got a PACKET_TYPE_HEAD_DATA, then we're talking to an NODE_TYPE_AVATAR, and we // need to make sure we have it in our nodeList. uint16_t nodeID = 0; unpackNodeId(packetData + numBytesPacketHeader, &nodeID); + +printf("got PACKET_TYPE_HEAD_DATA... nodeID=%d\n", nodeID); + Node* node = nodeList->addOrUpdateNode(&nodePublicAddress, &nodePublicAddress, NODE_TYPE_AGENT,