From d3b95d19a1c79634c8ecaff98a14ae58b70b944a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 9 Oct 2013 15:09:57 -0700 Subject: [PATCH] send the user's last domain and position to data-server --- interface/src/Application.cpp | 10 +++++++ interface/src/DataServerClient.h | 2 ++ interface/src/Menu.cpp | 7 +++-- interface/src/avatar/Profile.cpp | 45 +++++++++++++++++++++----------- interface/src/avatar/Profile.h | 5 ++-- 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8d38343e3d..96249cee02 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -182,6 +182,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _settings = new QSettings(this); + // load user profile data + _profile.loadData(_settings); + // 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 @@ -1166,6 +1169,9 @@ void Application::timer() { // ask the node list to check in with the domain server NodeList::getInstance()->sendDomainServerCheckIn(); + + // give the MyAvatar object position to the Profile so it can propagate to the data-server + _profile.updatePosition(_myAvatar.getPosition()); } static glm::vec3 getFaceVector(BoxFace face) { @@ -3516,9 +3522,13 @@ void Application::attachNewHeadToNode(Node* newNode) { void Application::domainChanged(QString domain) { qDebug("Application title set to: %s.\n", domain.toStdString().c_str()); _window->setWindowTitle(domain); + + // update the user's last domain in their Profile (which will propagate to data-server) + _profile.updateDomain(domain); } void Application::nodeAdded(Node* node) { + } void Application::nodeKilled(Node* node) { diff --git a/interface/src/DataServerClient.h b/interface/src/DataServerClient.h index e4f5290fd5..1b8df7c00c 100644 --- a/interface/src/DataServerClient.h +++ b/interface/src/DataServerClient.h @@ -31,7 +31,9 @@ private: }; namespace DataServerKey { + const char Domain[] = "domain"; const char FaceMeshURL[] = "mesh"; + const char Position[] = "position"; const char UUID[] = "uuid"; } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index d3f9c66a26..efc1c5b775 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -510,9 +510,10 @@ void Menu::loadSettings(QSettings* settings) { settings->endGroup(); scanMenuBar(&loadAction, settings); - Application::getInstance()->getProfile()->loadData(settings); Application::getInstance()->getAvatar()->loadData(settings); Application::getInstance()->getSwatch()->loadData(settings); + + // NodeList and profile settings are not loaded here because the Application will load them immediately on start } void Menu::saveSettings(QSettings* settings) { @@ -533,9 +534,11 @@ void Menu::saveSettings(QSettings* settings) { scanMenuBar(&saveAction, settings); Application::getInstance()->getAvatar()->saveData(settings); - Application::getInstance()->getProfile()->saveData(settings); Application::getInstance()->getSwatch()->saveData(settings); + // save the user profile + Application::getInstance()->getProfile()->saveData(settings); + // ask the NodeList to save its data NodeList::getInstance()->saveData(settings); } diff --git a/interface/src/avatar/Profile.cpp b/interface/src/avatar/Profile.cpp index 360a97d2c1..7326edd9e6 100644 --- a/interface/src/avatar/Profile.cpp +++ b/interface/src/avatar/Profile.cpp @@ -39,24 +39,39 @@ void Profile::setFaceModelURL(const QUrl& faceModelURL) { Q_ARG(QUrl, _faceModelURL)); } -void Profile::updatePositionInDomain(const QString& domain, const glm::vec3 position) { - if (!_username.isEmpty()) { - bool updateRequired = false; +void Profile::updateDomain(const QString& domain) { + if (_lastDomain != domain) { + _lastDomain = domain; - if (_lastDomain != domain) { - _lastDomain = domain; - updateRequired = true; - } + // send the changed domain to the data-server + DataServerClient::putValueForKey(DataServerKey::Domain, domain.toLocal8Bit().constData()); + } +} + +void Profile::updatePosition(const glm::vec3 position) { + if (_lastPosition != position) { - if (_lastPosition != position) { - _lastPosition = position; - updateRequired = true; - } + static timeval lastPositionSend = {}; + const uint64_t DATA_SERVER_POSITION_UPDATE_INTERVAL_USECS = 5 * 1000 * 1000; + const float DATA_SERVER_POSITION_CHANGE_THRESHOLD_METERS = 1; - if (updateRequired) { - // either the domain or position or both have changed, time to send update to data-server - - } + if (usecTimestampNow() - usecTimestamp(&lastPositionSend) >= DATA_SERVER_POSITION_UPDATE_INTERVAL_USECS && + (fabsf(_lastPosition.x - position.x) >= DATA_SERVER_POSITION_CHANGE_THRESHOLD_METERS || + fabsf(_lastPosition.y - position.y) >= DATA_SERVER_POSITION_CHANGE_THRESHOLD_METERS || + fabsf(_lastPosition.z - position.z) >= DATA_SERVER_POSITION_CHANGE_THRESHOLD_METERS)) { + + // if it has been 5 seconds since the last position change and the user has moved >= the threshold + // in at least one of the axis then send the position update to the data-server + + _lastPosition = position; + + // update the lastPositionSend to now + gettimeofday(&lastPositionSend, NULL); + + // send the changed position to the data-server + QString positionString = QString("%1,%2,%3").arg(position.x).arg(position.y).arg(position.z); + DataServerClient::putValueForKey(DataServerKey::Position, positionString.toLocal8Bit().constData()); + } } } diff --git a/interface/src/avatar/Profile.h b/interface/src/avatar/Profile.h index 90b9f883ec..398d0204fb 100644 --- a/interface/src/avatar/Profile.h +++ b/interface/src/avatar/Profile.h @@ -27,13 +27,12 @@ public: void setFaceModelURL(const QUrl& faceModelURL); const QUrl& getFaceModelURL() const { return _faceModelURL; } - void updatePositionInDomain(const QString& domain, const glm::vec3 position); + void updateDomain(const QString& domain); + void updatePosition(const glm::vec3 position); QString getLastDomain() const { return _lastDomain; } const glm::vec3& getLastPosition() const { return _lastPosition; } - void updateLastLocation(const glm::vec3 lastLocation); - void saveData(QSettings* settings); void loadData(QSettings* settings); private: