mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 05:03:31 +02:00
send the user's last domain and position to data-server
This commit is contained in:
parent
9112efaa36
commit
d3b95d19a1
5 changed files with 49 additions and 20 deletions
|
@ -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) {
|
||||
|
|
|
@ -31,7 +31,9 @@ private:
|
|||
};
|
||||
|
||||
namespace DataServerKey {
|
||||
const char Domain[] = "domain";
|
||||
const char FaceMeshURL[] = "mesh";
|
||||
const char Position[] = "position";
|
||||
const char UUID[] = "uuid";
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue