From 67e5a6409e9c70f4083598287f55a1415774a772 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Jul 2013 14:07:08 -0700 Subject: [PATCH 1/8] don't not kill NODE_TYPE_VOXEL_SERVER in removeSilentNodes --- libraries/shared/src/NodeList.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 87ee133dbb..91fe1f4a21 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -472,8 +472,7 @@ void *removeSilentNodes(void *args) { for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); ++node) { - if ((checkTimeUSecs - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS - && node->getType() != NODE_TYPE_VOXEL_SERVER) { + if ((checkTimeUSecs - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) { qDebug() << "Killed" << *node << "\n"; From 04a2dd3b8612c6fb451a382938298a441782fbaa Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Jul 2013 14:36:55 -0700 Subject: [PATCH 2/8] clear environment data on domain server switch --- interface/src/Application.cpp | 6 +++++- interface/src/Environment.cpp | 5 +++++ interface/src/Environment.h | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index adb88147e9..e67d938bf1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1148,15 +1148,19 @@ void Application::editPreferences() { // check if the domain server hostname is new if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname, sizeof(&newHostname)) != 0) { - // if so we need to clear the nodelist and delete the local voxels + // if so we need to clear the nodelist and delete the existing voxel and environment data Node *voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER); if (voxelServer) { voxelServer->lock(); } + // kill the local voxels _voxels.killLocalVoxels(); + // reset the environment to default + _environment.resetToDefault(); + if (voxelServer) { voxelServer->unlock(); } diff --git a/interface/src/Environment.cpp b/interface/src/Environment.cpp index 35ed121e38..adfb1cfb3b 100644 --- a/interface/src/Environment.cpp +++ b/interface/src/Environment.cpp @@ -47,6 +47,11 @@ void Environment::init() { _data[getZeroAddress()][0]; } +void Environment::resetToDefault() { + _data.clear(); + _data[getZeroAddress()][0]; +} + void Environment::renderAtmospheres(Camera& camera) { // get the lock for the duration of the call QMutexLocker locker(&_mutex); diff --git a/interface/src/Environment.h b/interface/src/Environment.h index f711f0c38c..7bdbfa600b 100644 --- a/interface/src/Environment.h +++ b/interface/src/Environment.h @@ -24,6 +24,7 @@ class Environment { public: void init(); + void resetToDefault(); void renderAtmospheres(Camera& camera); glm::vec3 getGravity (const glm::vec3& position); From 4dd6afc08f41dcb2a463c196aa6378ad42f55113 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Jul 2013 14:59:11 -0700 Subject: [PATCH 3/8] fix grabbing of domain server hostname from QString --- interface/src/Application.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e67d938bf1..3a8d6cff48 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1143,8 +1143,7 @@ void Application::editPreferences() { return; } - - const char* newHostname = domainServerHostname->text().toLocal8Bit().data(); + const char* newHostname = domainServerHostname->text().toStdString().c_str(); // check if the domain server hostname is new if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname, sizeof(&newHostname)) != 0) { From 4f36a0cda1e326ce53bd1f7849c8f7e335c77674 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 18 Jul 2013 15:13:55 -0700 Subject: [PATCH 4/8] adjust server sleep time to allow 60fps (cherry picked from commit 4d1ae4308546214abbd5be295a2cc002fab91d44) --- voxel-server/src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index 5b1ad57861..8a8048035b 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -44,9 +44,9 @@ const int MIN_BRIGHTNESS = 64; const float DEATH_STAR_RADIUS = 4.0; const float MAX_CUBE = 0.05f; -const int VOXEL_SEND_INTERVAL_USECS = 100 * 1000; -int PACKETS_PER_CLIENT_PER_INTERVAL = 30; -const int SENDING_TIME_TO_SPARE = 20 * 1000; // usec of sending interval to spare for calculating voxels +const int VOXEL_SEND_INTERVAL_USECS = 17 * 1000; // approximately 60fps +int PACKETS_PER_CLIENT_PER_INTERVAL = 20; +const int SENDING_TIME_TO_SPARE = 5 * 1000; // usec of sending interval to spare for calculating voxels const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4; From 45d82dc97cbd3c3a8289eb8a01d6332dba6bf419 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Jul 2013 15:20:05 -0700 Subject: [PATCH 5/8] correct reference to new hostname for Qt temp variable changes --- interface/src/Application.cpp | 7 ++++--- libraries/shared/src/NodeList.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3a8d6cff48..f9cebf41b4 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1143,10 +1143,11 @@ void Application::editPreferences() { return; } - const char* newHostname = domainServerHostname->text().toStdString().c_str(); - + char newHostname[MAX_HOSTNAME_BYTES] = {}; + memcpy(newHostname, domainServerHostname->text().toAscii().data(), domainServerHostname->text().size()); + // check if the domain server hostname is new - if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname, sizeof(&newHostname)) != 0) { + if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname, strlen(newHostname)) != 0) { // if so we need to clear the nodelist and delete the existing voxel and environment data Node *voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER); diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index 20eaddc738..0c8a68d38c 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -32,7 +32,7 @@ const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000; extern const char SOLO_NODE_TYPES[3]; -const int MAX_HOSTNAME_BYTES = 255; +const int MAX_HOSTNAME_BYTES = 256; extern const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES]; extern const char DEFAULT_DOMAIN_IP[INET_ADDRSTRLEN]; // IP Address will be re-set by lookup on startup From a00b95666a619dbdd09bd180c0d913940c3b1463 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Jul 2013 15:49:07 -0700 Subject: [PATCH 6/8] don't listen to VS packets not from current VS --- interface/src/Application.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f9cebf41b4..eb99feca47 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1148,12 +1148,8 @@ void Application::editPreferences() { // check if the domain server hostname is new if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname, strlen(newHostname)) != 0) { - // if so we need to clear the nodelist and delete the existing voxel and environment data - Node *voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER); - if (voxelServer) { - voxelServer->lock(); - } + NodeList::getInstance()->clear(); // kill the local voxels _voxels.killLocalVoxels(); @@ -1161,11 +1157,6 @@ void Application::editPreferences() { // reset the environment to default _environment.resetToDefault(); - if (voxelServer) { - voxelServer->unlock(); - } - - NodeList::getInstance()->clear(); NodeList::getInstance()->setDomainHostname(newHostname); } @@ -3356,7 +3347,7 @@ void* Application::networkReceive(void* args) { case PACKET_TYPE_ENVIRONMENT_DATA: { if (app->_renderVoxels->isChecked()) { Node* voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER); - if (voxelServer) { + if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) { voxelServer->lock(); if (app->_incomingPacket[0] == PACKET_TYPE_ENVIRONMENT_DATA) { From 01e6891fd3d1403434c0b12f5e58b6ae1f2c7633 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Jul 2013 17:23:52 -0700 Subject: [PATCH 7/8] save custom domain server hostname to QSettings --- interface/src/Application.cpp | 48 +++++++++++++++++++------------ libraries/shared/src/NodeList.cpp | 26 +++++++++++++++++ libraries/shared/src/NodeList.h | 5 ++++ 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index eb99feca47..9b57ccd433 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -235,6 +235,31 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : NodeList::getInstance()->getNodeSocket()->setBlocking(false); } + // setup QSettings +#ifdef Q_WS_MAC + QString resourcesPath = QCoreApplication::applicationDirPath() + "/../Resources"; +#else + QString resourcesPath = QCoreApplication::applicationDirPath() + "/resources"; +#endif + + // read the ApplicationInfo.ini file for Name/Version/Domain information + QSettings applicationInfo(resourcesPath + "/info/ApplicationInfo.ini", QSettings::IniFormat); + + // set the associated application properties + applicationInfo.beginGroup("INFO"); + + setApplicationName(applicationInfo.value("name").toString()); + setApplicationVersion(applicationInfo.value("version").toString()); + setOrganizationName(applicationInfo.value("organizationName").toString()); + setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); + + _settings = new QSettings(this); + + // check if there is a saved domain server hostname + // this must be done now instead of with the other setting checks to allow manual override with + // --domain or --local options + NodeList::getInstance()->loadData(_settings); + const char* domainIP = getCmdOption(argc, constArgv, "--domain"); if (domainIP) { NodeList::getInstance()->setDomainIP(domainIP); @@ -268,23 +293,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _window->setCentralWidget(_glWidget); -#ifdef Q_WS_MAC - QString resourcesPath = QCoreApplication::applicationDirPath() + "/../Resources"; -#else - QString resourcesPath = QCoreApplication::applicationDirPath() + "/resources"; -#endif - - // read the ApplicationInfo.ini file for Name/Version/Domain information - QSettings applicationInfo(resourcesPath + "/info/ApplicationInfo.ini", QSettings::IniFormat); - - // set the associated application properties - applicationInfo.beginGroup("INFO"); - - setApplicationName(applicationInfo.value("name").toString()); - setApplicationVersion(applicationInfo.value("version").toString()); - setOrganizationName(applicationInfo.value("organizationName").toString()); - setOrganizationDomain(applicationInfo.value("organizationDomain").toString()); - #if defined(Q_WS_MAC) && defined(QT_NO_DEBUG) // if this is a release OS X build use fervor to check for an update FvUpdater::sharedUpdater()->SetFeedURL("https://s3-us-west-1.amazonaws.com/highfidelity/appcast.xml"); @@ -1781,7 +1789,6 @@ void Application::initMenu() { settingsMenu->addAction("Export settings", this, SLOT(exportSettings())); _networkAccessManager = new QNetworkAccessManager(this); - _settings = new QSettings(this); } void Application::updateFrustumRenderModeAction() { @@ -3451,7 +3458,7 @@ void Application::saveSettings(QSettings* settings) { if (!settings) { settings = getSettings(); } - + settings->setValue("headCameraPitchYawScale", _headCameraPitchYawScale); settings->setValue("audioJitterBufferSamples", _audioJitterBufferSamples); settings->setValue("horizontalFieldOfView", _horizontalFieldOfView); @@ -3466,6 +3473,9 @@ void Application::saveSettings(QSettings* settings) { scanMenuBar(&Application::saveAction, settings); getAvatar()->saveData(settings); _swatch.saveData(settings); + + // ask the NodeList to save its data + NodeList::getInstance()->saveData(settings); } void Application::importSettings() { diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 91fe1f4a21..184cb346e8 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -499,6 +499,32 @@ void NodeList::startSilentNodeRemovalThread() { void NodeList::stopSilentNodeRemovalThread() { silentNodeThreadStopFlag = true; pthread_join(removeSilentNodesThread, NULL); + +} + +const QString QSETTINGS_GROUP_NAME = "NodeList"; +const QString DOMAIN_SERVER_SETTING_KEY = "domainServerHostname"; + +void NodeList::loadData(QSettings *settings) { + settings->beginGroup(DOMAIN_SERVER_SETTING_KEY); + + QString domainServerHostname = settings->value(DOMAIN_SERVER_SETTING_KEY).toString(); + + if (domainServerHostname.size() > 0) { + memset(_domainHostname, 0, MAX_HOSTNAME_BYTES); + memcpy(_domainHostname, domainServerHostname.toAscii().constData(), domainServerHostname.size()); + } + + settings->endGroup(); +} + +void NodeList::saveData(QSettings* settings) { + if (memcmp(_domainHostname, DEFAULT_DOMAIN_HOSTNAME, strlen(DEFAULT_DOMAIN_HOSTNAME)) != 0) { + // the user is using a different hostname, store it + settings->beginGroup(DOMAIN_SERVER_SETTING_KEY); + settings->setValue(DOMAIN_SERVER_SETTING_KEY, QVariant(_domainHostname)); + settings->endGroup(); + } } NodeList::iterator NodeList::begin() const { diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index 0c8a68d38c..2a66fc7374 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -14,6 +14,8 @@ #include #include +#include + #include "Node.h" #include "UDPSocket.h" @@ -99,6 +101,9 @@ public: void startSilentNodeRemovalThread(); void stopSilentNodeRemovalThread(); + void loadData(QSettings* settings); + void saveData(QSettings* settings); + friend class NodeListIterator; private: static NodeList* _sharedInstance; From ef7dc4a39abc40ce408b0713f94c1cd14688c05c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Jul 2013 17:42:25 -0700 Subject: [PATCH 8/8] if the hostname field is left blank reset to DEFAULT_DOMAIN_HOSTNAME --- interface/src/Application.cpp | 16 ++++++++++++---- libraries/shared/src/NodeList.cpp | 9 +++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9b57ccd433..c5c18c9fdb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1151,11 +1151,18 @@ void Application::editPreferences() { return; } - char newHostname[MAX_HOSTNAME_BYTES] = {}; - memcpy(newHostname, domainServerHostname->text().toAscii().data(), domainServerHostname->text().size()); + QByteArray newHostname; + + if (domainServerHostname->text().size() > 0) { + // the user input a new hostname, use that + newHostname = domainServerHostname->text().toAscii(); + } else { + // the user left the field blank, use the default hostname + newHostname = QByteArray(DEFAULT_DOMAIN_HOSTNAME); + } // check if the domain server hostname is new - if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname, strlen(newHostname)) != 0) { + if (memcmp(NodeList::getInstance()->getDomainHostname(), newHostname.constData(), newHostname.size()) != 0) { NodeList::getInstance()->clear(); @@ -1165,7 +1172,8 @@ void Application::editPreferences() { // reset the environment to default _environment.resetToDefault(); - NodeList::getInstance()->setDomainHostname(newHostname); + // set the new hostname + NodeList::getInstance()->setDomainHostname(newHostname.constData()); } QUrl url(avatarURL->text()); diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 184cb346e8..9406c6b14d 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -519,12 +519,17 @@ void NodeList::loadData(QSettings *settings) { } void NodeList::saveData(QSettings* settings) { + settings->beginGroup(DOMAIN_SERVER_SETTING_KEY); + if (memcmp(_domainHostname, DEFAULT_DOMAIN_HOSTNAME, strlen(DEFAULT_DOMAIN_HOSTNAME)) != 0) { // the user is using a different hostname, store it - settings->beginGroup(DOMAIN_SERVER_SETTING_KEY); settings->setValue(DOMAIN_SERVER_SETTING_KEY, QVariant(_domainHostname)); - settings->endGroup(); + } else { + // the user has switched back to default, remove the current setting + settings->remove(DOMAIN_SERVER_SETTING_KEY); } + + settings->endGroup(); } NodeList::iterator NodeList::begin() const {