send the user's last domain and position to data-server

This commit is contained in:
Stephen Birarda 2013-10-09 15:09:57 -07:00
parent 9112efaa36
commit d3b95d19a1
5 changed files with 49 additions and 20 deletions

View file

@ -182,6 +182,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_settings = new QSettings(this); _settings = new QSettings(this);
// load user profile data
_profile.loadData(_settings);
// check if there is a saved domain server hostname // 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 // this must be done now instead of with the other setting checks to allow manual override with
// --domain or --local options // --domain or --local options
@ -1166,6 +1169,9 @@ void Application::timer() {
// ask the node list to check in with the domain server // ask the node list to check in with the domain server
NodeList::getInstance()->sendDomainServerCheckIn(); 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) { static glm::vec3 getFaceVector(BoxFace face) {
@ -3516,9 +3522,13 @@ void Application::attachNewHeadToNode(Node* newNode) {
void Application::domainChanged(QString domain) { void Application::domainChanged(QString domain) {
qDebug("Application title set to: %s.\n", domain.toStdString().c_str()); qDebug("Application title set to: %s.\n", domain.toStdString().c_str());
_window->setWindowTitle(domain); _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::nodeAdded(Node* node) {
} }
void Application::nodeKilled(Node* node) { void Application::nodeKilled(Node* node) {

View file

@ -31,7 +31,9 @@ private:
}; };
namespace DataServerKey { namespace DataServerKey {
const char Domain[] = "domain";
const char FaceMeshURL[] = "mesh"; const char FaceMeshURL[] = "mesh";
const char Position[] = "position";
const char UUID[] = "uuid"; const char UUID[] = "uuid";
} }

View file

@ -510,9 +510,10 @@ void Menu::loadSettings(QSettings* settings) {
settings->endGroup(); settings->endGroup();
scanMenuBar(&loadAction, settings); scanMenuBar(&loadAction, settings);
Application::getInstance()->getProfile()->loadData(settings);
Application::getInstance()->getAvatar()->loadData(settings); Application::getInstance()->getAvatar()->loadData(settings);
Application::getInstance()->getSwatch()->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) { void Menu::saveSettings(QSettings* settings) {
@ -533,9 +534,11 @@ void Menu::saveSettings(QSettings* settings) {
scanMenuBar(&saveAction, settings); scanMenuBar(&saveAction, settings);
Application::getInstance()->getAvatar()->saveData(settings); Application::getInstance()->getAvatar()->saveData(settings);
Application::getInstance()->getProfile()->saveData(settings);
Application::getInstance()->getSwatch()->saveData(settings); Application::getInstance()->getSwatch()->saveData(settings);
// save the user profile
Application::getInstance()->getProfile()->saveData(settings);
// ask the NodeList to save its data // ask the NodeList to save its data
NodeList::getInstance()->saveData(settings); NodeList::getInstance()->saveData(settings);
} }

View file

@ -39,24 +39,39 @@ void Profile::setFaceModelURL(const QUrl& faceModelURL) {
Q_ARG(QUrl, _faceModelURL)); Q_ARG(QUrl, _faceModelURL));
} }
void Profile::updatePositionInDomain(const QString& domain, const glm::vec3 position) { void Profile::updateDomain(const QString& domain) {
if (!_username.isEmpty()) { if (_lastDomain != domain) {
bool updateRequired = false; _lastDomain = domain;
if (_lastDomain != domain) { // send the changed domain to the data-server
_lastDomain = domain; DataServerClient::putValueForKey(DataServerKey::Domain, domain.toLocal8Bit().constData());
updateRequired = true; }
} }
void Profile::updatePosition(const glm::vec3 position) {
if (_lastPosition != position) {
if (_lastPosition != position) { static timeval lastPositionSend = {};
_lastPosition = position; const uint64_t DATA_SERVER_POSITION_UPDATE_INTERVAL_USECS = 5 * 1000 * 1000;
updateRequired = true; const float DATA_SERVER_POSITION_CHANGE_THRESHOLD_METERS = 1;
}
if (updateRequired) { if (usecTimestampNow() - usecTimestamp(&lastPositionSend) >= DATA_SERVER_POSITION_UPDATE_INTERVAL_USECS &&
// either the domain or position or both have changed, time to send update to data-server (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());
}
} }
} }

View file

@ -27,13 +27,12 @@ public:
void setFaceModelURL(const QUrl& faceModelURL); void setFaceModelURL(const QUrl& faceModelURL);
const QUrl& getFaceModelURL() const { return _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; } QString getLastDomain() const { return _lastDomain; }
const glm::vec3& getLastPosition() const { return _lastPosition; } const glm::vec3& getLastPosition() const { return _lastPosition; }
void updateLastLocation(const glm::vec3 lastLocation);
void saveData(QSettings* settings); void saveData(QSettings* settings);
void loadData(QSettings* settings); void loadData(QSettings* settings);
private: private: