From 92fb393e14c932bc28c1ec34db72f93aa8634b31 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 16 Sep 2013 19:34:07 -0700 Subject: [PATCH] allow standalone voxel-server to specify port and domain, add VoxelServerType to assignment-client --- assignment-client/CMakeLists.txt | 3 +- assignment-client/src/main.cpp | 3 ++ domain-server/src/main.cpp | 20 +++++++ libraries/shared/src/Assignment.h | 1 + .../src/VoxelSendThread.cpp | 3 ++ .../voxel-server-library/src/VoxelServer.cpp | 54 +++++++++---------- .../voxel-server-library/src/VoxelServer.h | 51 +++--------------- .../src/VoxelServerPacketProcessor.cpp | 1 + voxel-server/src/main.cpp | 29 ++++++++++ 9 files changed, 92 insertions(+), 73 deletions(-) diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index 1315b0ce84..39d1eecca6 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -23,4 +23,5 @@ include_glm(${TARGET_NAME} ${ROOT_DIR}) include(${MACRO_DIR}/LinkHifiLibrary.cmake) link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) link_hifi_library(audio ${TARGET_NAME} ${ROOT_DIR}) -link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR}) \ No newline at end of file +link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR}) +link_hifi_library(voxel-server-library ${TARGET_NAME} ${ROOT_DIR}) \ No newline at end of file diff --git a/assignment-client/src/main.cpp b/assignment-client/src/main.cpp index 16522a2d87..63943c97b5 100644 --- a/assignment-client/src/main.cpp +++ b/assignment-client/src/main.cpp @@ -22,6 +22,7 @@ #include #include #include +#include const long long ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000; const char PARENT_TARGET_NAME[] = "assignment-client-monitor"; @@ -97,6 +98,8 @@ void childClient() { AudioMixer::run(); } else if (deployedAssignment.getType() == Assignment::AvatarMixerType) { AvatarMixer::run(); + } else if (deployedAssignment.getType() == Assignment::VoxelServerType) { + VoxelServer::run(); } else { // figure out the URL for the script for this agent assignment QString scriptURLString("http://%1:8080/assignment/%2"); diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index 959130833f..bfd0d3da21 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -142,6 +142,10 @@ int main(int argc, const char* argv[]) { Assignment avatarMixerAssignment(Assignment::CreateCommand, Assignment::AvatarMixerType, Assignment::LocalLocation); + + Assignment voxelServerAssignment(Assignment::CreateCommand, + Assignment::VoxelServerType, + Assignment::LocalLocation); // construct a local socket to send with our created assignments to the global AS sockaddr_in localSocket = {}; @@ -179,6 +183,22 @@ int main(int argc, const char* argv[]) { qDebug("Missing an audio mixer and assignment not in queue. Adding.\n"); ::assignmentQueue.push_front(&audioMixerAssignment); } + + // Now handle voxel servers, since there could be more than one, we look for any of them + int voxelServerCount = 0; + for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { + if (node->getType() == NODE_TYPE_VOXEL_SERVER) { + voxelServerCount++; + } + } + + if (voxelServerCount == 0 && + std::find(::assignmentQueue.begin(), ::assignmentQueue.end(), &voxelServerAssignment) == ::assignmentQueue.end()) { + qDebug("Missing an Voxel Server and assignment not in queue. Adding.\n"); + ::assignmentQueue.push_front(&voxelServerAssignment); + } + + ::assignmentQueueMutex.unlock(); while (nodeList->getNodeSocket()->receive((sockaddr *)&nodePublicAddress, packetData, &receivedBytes) && diff --git a/libraries/shared/src/Assignment.h b/libraries/shared/src/Assignment.h index 6985f21535..4fdbeed838 100644 --- a/libraries/shared/src/Assignment.h +++ b/libraries/shared/src/Assignment.h @@ -23,6 +23,7 @@ public: AudioMixerType, AvatarMixerType, AgentType, + VoxelServerType, AllTypes }; diff --git a/libraries/voxel-server-library/src/VoxelSendThread.cpp b/libraries/voxel-server-library/src/VoxelSendThread.cpp index 38f8c6f9b8..b9bb861349 100644 --- a/libraries/voxel-server-library/src/VoxelSendThread.cpp +++ b/libraries/voxel-server-library/src/VoxelSendThread.cpp @@ -11,9 +11,12 @@ #include #include #include +#include +extern EnvironmentData environmentData[3]; #include "VoxelSendThread.h" #include "VoxelServer.h" +#include "VoxelServerState.h" VoxelSendThread::VoxelSendThread(uint16_t nodeID) : _nodeID(nodeID) { diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index e865037082..f56232264f 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -38,6 +38,7 @@ #endif #include "VoxelServer.h" +#include "VoxelServerState.h" const char* LOCAL_VOXELS_PERSIST_FILE = "resources/voxels.svo"; const char* VOXELS_PERSIST_FILE = "/etc/highfidelity/voxel-server/resources/voxels.svo"; @@ -76,6 +77,21 @@ void VoxelServer::setArguments(int argc, char** argv) { _argv = const_cast(argv); } +void VoxelServer::setupDomainAndPort(const char* domain, int port) { + NodeList::createInstance(NODE_TYPE_VOXEL_SERVER, port); + + // Handle Local Domain testing with the --local command line + const char* local = "--local"; + ::wantLocalDomain = strcmp(domain, local) == 0; + if (::wantLocalDomain) { + printf("Local Domain MODE!\n"); + NodeList::getInstance()->setDomainIPToLocalhost(); + } else { + if (domain) { + NodeList::getInstance()->setDomainHostname(domain); + } + } +} //int main(int argc, const char * argv[]) { void VoxelServer::run() { @@ -83,18 +99,6 @@ void VoxelServer::run() { qInstallMessageHandler(sharedMessageHandler); - 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); - } - const char* JURISDICTION_FILE = "--jurisdictionFile"; const char* jurisdictionFile = getCmdOption(_argc, _argv, JURISDICTION_FILE); if (jurisdictionFile) { @@ -140,26 +144,15 @@ void VoxelServer::run() { } printf("Sending environments=%s\n", debug::valueOf(::sendEnvironments)); - NodeList* nodeList = NodeList::createInstance(NODE_TYPE_VOXEL_SERVER, listenPort); + NodeList* nodeList = NodeList::getInstance(); + nodeList->setOwnerType(NODE_TYPE_VOXEL_SERVER); + setvbuf(stdout, NULL, _IOLBF, 0); // tell our NodeList about our desire to get notifications nodeList->addHook(&nodeWatcher); nodeList->linkedDataCreateCallback = &attachVoxelNodeDataToNode; - // Handle Local Domain testing with the --local command line - const char* local = "--local"; - ::wantLocalDomain = cmdOptionExists(_argc, _argv, local); - if (::wantLocalDomain) { - printf("Local Domain MODE!\n"); - NodeList::getInstance()->setDomainIPToLocalhost(); - } else { - const char* domainIP = getCmdOption(_argc, _argv, "--domain"); - if (domainIP) { - NodeList::getInstance()->setDomainHostname(domainIP); - } - } - nodeList->startSilentNodeRemovalThread(); srand((unsigned)time(0)); @@ -196,7 +189,8 @@ void VoxelServer::run() { if (voxelsPersistFilenameParameter) { strcpy(voxelPersistFilename, voxelsPersistFilenameParameter); } else { - strcpy(voxelPersistFilename, ::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE); + //strcpy(voxelPersistFilename, ::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE); + strcpy(voxelPersistFilename, LOCAL_VOXELS_PERSIST_FILE); } printf("loading voxels from file: %s...\n", voxelPersistFilename); @@ -278,7 +272,11 @@ void VoxelServer::run() { // loop to send to nodes requesting data while (true) { - + + if (NodeList::getInstance()->getNumNoReplyDomainCheckIns() == MAX_SILENT_DOMAIN_SERVER_CHECK_INS) { + break; + } + // send a check in packet to the domain server if DOMAIN_SERVER_CHECK_IN_USECS has elapsed if (usecTimestampNow() - usecTimestamp(&lastDomainServerCheckIn) >= DOMAIN_SERVER_CHECK_IN_USECS) { gettimeofday(&lastDomainServerCheckIn, NULL); diff --git a/libraries/voxel-server-library/src/VoxelServer.h b/libraries/voxel-server-library/src/VoxelServer.h index f9740e8c4b..bf9d3c798b 100644 --- a/libraries/voxel-server-library/src/VoxelServer.h +++ b/libraries/voxel-server-library/src/VoxelServer.h @@ -9,50 +9,6 @@ #ifndef __voxel_server__VoxelServer__ #define __voxel_server__VoxelServer__ -#include -#include // for MAX_PACKET_SIZE -#include -#include -#include - -#include "VoxelServerPacketProcessor.h" - - -const int MAX_FILENAME_LENGTH = 1024; -const int VOXEL_LISTEN_PORT = 40106; -const int VOXEL_SIZE_BYTES = 3 + (3 * sizeof(float)); -const int VOXELS_PER_PACKET = (MAX_PACKET_SIZE - 1) / VOXEL_SIZE_BYTES; -const int MIN_BRIGHTNESS = 64; -const float DEATH_STAR_RADIUS = 4.0; -const float MAX_CUBE = 0.05f; -const int VOXEL_SEND_INTERVAL_USECS = 17 * 1000; // approximately 60fps -const int SENDING_TIME_TO_SPARE = 5 * 1000; // usec of sending interval to spare for calculating voxels -const int INTERVALS_PER_SECOND = 1000 * 1000 / VOXEL_SEND_INTERVAL_USECS; -const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4; -const int ENVIRONMENT_SEND_INTERVAL_USECS = 1000000; - -extern const char* LOCAL_VOXELS_PERSIST_FILE; -extern const char* VOXELS_PERSIST_FILE; -extern char voxelPersistFilename[MAX_FILENAME_LENGTH]; -extern int PACKETS_PER_CLIENT_PER_INTERVAL; - -extern VoxelTree serverTree; // this IS a reaveraging tree -extern bool wantVoxelPersist; -extern bool wantLocalDomain; -extern bool debugVoxelSending; -extern bool shouldShowAnimationDebug; -extern bool displayVoxelStats; -extern bool debugVoxelReceiving; -extern bool sendEnvironments; -extern bool sendMinimalEnvironment; -extern bool dumpVoxelsOnMove; -extern EnvironmentData environmentData[3]; -extern int receivedPacketCount; -extern JurisdictionMap* jurisdiction; -extern JurisdictionSender* jurisdictionSender; -extern VoxelServerPacketProcessor* voxelServerPacketProcessor; -extern pthread_mutex_t treeLock; - /// Handles assignments of type VoxelServer - sending voxels to various clients. class VoxelServer { public: @@ -61,6 +17,13 @@ public: /// allows setting of run arguments static void setArguments(int argc, char** argv); + + /// when VoxelServer class is used by voxel-server stand alone executable it calls this to specify the domain + /// and port it is handling. When called by assignment-client, this is not needed because assignment-client + /// handles ports and domains automatically. + /// \param const char* domain domain name, IP address, or local to specify the domain the voxel server is serving + /// \param int port port the voxel server will listen on + static void setupDomainAndPort(const char* domain, int port); private: static int _argc; diff --git a/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp b/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp index aaa347ee86..d283296e6f 100644 --- a/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp +++ b/libraries/voxel-server-library/src/VoxelServerPacketProcessor.cpp @@ -12,6 +12,7 @@ #include #include "VoxelServer.h" +#include "VoxelServerState.h" #include "VoxelServerPacketProcessor.h" diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 5a21b9fc76..f854df84cf 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -6,9 +6,38 @@ // Copyright (c) 2012 High Fidelity, Inc. All rights reserved. // +#include #include +const int VOXEL_LISTEN_PORT = 40106; + int main(int argc, const char * argv[]) { + + // Handle Local Domain testing with the --local command line + const char* local = "--local"; + bool wantLocalDomain = cmdOptionExists(argc, argv, local); + const char* domainIP = getCmdOption(argc, argv, "--domain"); + + 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); + } + + if (wantLocalDomain) { + VoxelServer::setupDomainAndPort(local, listenPort); + } else { + if (domainIP) { + VoxelServer::setupDomainAndPort(domainIP, listenPort); + } + } + VoxelServer::setArguments(argc, const_cast(argv)); VoxelServer::run(); }