allow standalone voxel-server to specify port and domain, add VoxelServerType to assignment-client

This commit is contained in:
ZappoMan 2013-09-16 19:34:07 -07:00
parent b484951cc2
commit 92fb393e14
9 changed files with 92 additions and 73 deletions

View file

@ -23,4 +23,5 @@ include_glm(${TARGET_NAME} ${ROOT_DIR})
include(${MACRO_DIR}/LinkHifiLibrary.cmake) include(${MACRO_DIR}/LinkHifiLibrary.cmake)
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(audio ${TARGET_NAME} ${ROOT_DIR}) link_hifi_library(audio ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR}) link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(voxel-server-library ${TARGET_NAME} ${ROOT_DIR})

View file

@ -22,6 +22,7 @@
#include <NodeList.h> #include <NodeList.h>
#include <PacketHeaders.h> #include <PacketHeaders.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include <VoxelServer.h>
const long long ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000; const long long ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000;
const char PARENT_TARGET_NAME[] = "assignment-client-monitor"; const char PARENT_TARGET_NAME[] = "assignment-client-monitor";
@ -97,6 +98,8 @@ void childClient() {
AudioMixer::run(); AudioMixer::run();
} else if (deployedAssignment.getType() == Assignment::AvatarMixerType) { } else if (deployedAssignment.getType() == Assignment::AvatarMixerType) {
AvatarMixer::run(); AvatarMixer::run();
} else if (deployedAssignment.getType() == Assignment::VoxelServerType) {
VoxelServer::run();
} else { } else {
// figure out the URL for the script for this agent assignment // figure out the URL for the script for this agent assignment
QString scriptURLString("http://%1:8080/assignment/%2"); QString scriptURLString("http://%1:8080/assignment/%2");

View file

@ -142,6 +142,10 @@ int main(int argc, const char* argv[]) {
Assignment avatarMixerAssignment(Assignment::CreateCommand, Assignment avatarMixerAssignment(Assignment::CreateCommand,
Assignment::AvatarMixerType, Assignment::AvatarMixerType,
Assignment::LocalLocation); Assignment::LocalLocation);
Assignment voxelServerAssignment(Assignment::CreateCommand,
Assignment::VoxelServerType,
Assignment::LocalLocation);
// construct a local socket to send with our created assignments to the global AS // construct a local socket to send with our created assignments to the global AS
sockaddr_in localSocket = {}; 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"); qDebug("Missing an audio mixer and assignment not in queue. Adding.\n");
::assignmentQueue.push_front(&audioMixerAssignment); ::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(); ::assignmentQueueMutex.unlock();
while (nodeList->getNodeSocket()->receive((sockaddr *)&nodePublicAddress, packetData, &receivedBytes) && while (nodeList->getNodeSocket()->receive((sockaddr *)&nodePublicAddress, packetData, &receivedBytes) &&

View file

@ -23,6 +23,7 @@ public:
AudioMixerType, AudioMixerType,
AvatarMixerType, AvatarMixerType,
AgentType, AgentType,
VoxelServerType,
AllTypes AllTypes
}; };

View file

@ -11,9 +11,12 @@
#include <NodeList.h> #include <NodeList.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include <PacketHeaders.h> #include <PacketHeaders.h>
#include <EnvironmentData.h>
extern EnvironmentData environmentData[3];
#include "VoxelSendThread.h" #include "VoxelSendThread.h"
#include "VoxelServer.h" #include "VoxelServer.h"
#include "VoxelServerState.h"
VoxelSendThread::VoxelSendThread(uint16_t nodeID) : VoxelSendThread::VoxelSendThread(uint16_t nodeID) :
_nodeID(nodeID) { _nodeID(nodeID) {

View file

@ -38,6 +38,7 @@
#endif #endif
#include "VoxelServer.h" #include "VoxelServer.h"
#include "VoxelServerState.h"
const char* LOCAL_VOXELS_PERSIST_FILE = "resources/voxels.svo"; const char* LOCAL_VOXELS_PERSIST_FILE = "resources/voxels.svo";
const char* VOXELS_PERSIST_FILE = "/etc/highfidelity/voxel-server/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<const char**>(argv); _argv = const_cast<const char**>(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[]) { //int main(int argc, const char * argv[]) {
void VoxelServer::run() { void VoxelServer::run() {
@ -83,18 +99,6 @@ void VoxelServer::run() {
qInstallMessageHandler(sharedMessageHandler); 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* JURISDICTION_FILE = "--jurisdictionFile";
const char* jurisdictionFile = getCmdOption(_argc, _argv, JURISDICTION_FILE); const char* jurisdictionFile = getCmdOption(_argc, _argv, JURISDICTION_FILE);
if (jurisdictionFile) { if (jurisdictionFile) {
@ -140,26 +144,15 @@ void VoxelServer::run() {
} }
printf("Sending environments=%s\n", debug::valueOf(::sendEnvironments)); 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); setvbuf(stdout, NULL, _IOLBF, 0);
// tell our NodeList about our desire to get notifications // tell our NodeList about our desire to get notifications
nodeList->addHook(&nodeWatcher); nodeList->addHook(&nodeWatcher);
nodeList->linkedDataCreateCallback = &attachVoxelNodeDataToNode; 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(); nodeList->startSilentNodeRemovalThread();
srand((unsigned)time(0)); srand((unsigned)time(0));
@ -196,7 +189,8 @@ void VoxelServer::run() {
if (voxelsPersistFilenameParameter) { if (voxelsPersistFilenameParameter) {
strcpy(voxelPersistFilename, voxelsPersistFilenameParameter); strcpy(voxelPersistFilename, voxelsPersistFilenameParameter);
} else { } 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); printf("loading voxels from file: %s...\n", voxelPersistFilename);
@ -278,7 +272,11 @@ void VoxelServer::run() {
// loop to send to nodes requesting data // loop to send to nodes requesting data
while (true) { 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 // 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) { if (usecTimestampNow() - usecTimestamp(&lastDomainServerCheckIn) >= DOMAIN_SERVER_CHECK_IN_USECS) {
gettimeofday(&lastDomainServerCheckIn, NULL); gettimeofday(&lastDomainServerCheckIn, NULL);

View file

@ -9,50 +9,6 @@
#ifndef __voxel_server__VoxelServer__ #ifndef __voxel_server__VoxelServer__
#define __voxel_server__VoxelServer__ #define __voxel_server__VoxelServer__
#include <SharedUtil.h>
#include <NodeList.h> // for MAX_PACKET_SIZE
#include <EnvironmentData.h>
#include <JurisdictionSender.h>
#include <VoxelTree.h>
#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. /// Handles assignments of type VoxelServer - sending voxels to various clients.
class VoxelServer { class VoxelServer {
public: public:
@ -61,6 +17,13 @@ public:
/// allows setting of run arguments /// allows setting of run arguments
static void setArguments(int argc, char** argv); 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: private:
static int _argc; static int _argc;

View file

@ -12,6 +12,7 @@
#include <PerfStat.h> #include <PerfStat.h>
#include "VoxelServer.h" #include "VoxelServer.h"
#include "VoxelServerState.h"
#include "VoxelServerPacketProcessor.h" #include "VoxelServerPacketProcessor.h"

View file

@ -6,9 +6,38 @@
// Copyright (c) 2012 High Fidelity, Inc. All rights reserved. // Copyright (c) 2012 High Fidelity, Inc. All rights reserved.
// //
#include <SharedUtil.h>
#include <VoxelServer.h> #include <VoxelServer.h>
const int VOXEL_LISTEN_PORT = 40106;
int main(int argc, const char * argv[]) { 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<char**>(argv)); VoxelServer::setArguments(argc, const_cast<char**>(argv));
VoxelServer::run(); VoxelServer::run();
} }