mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
send an updated address to data-server with domain (when changed)
This commit is contained in:
parent
491e915c93
commit
8e9defad3e
6 changed files with 42 additions and 31 deletions
|
@ -237,6 +237,13 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
|
||||
connect(&nodeList->getDomainHandler(), SIGNAL(hostnameChanged(const QString&)), SLOT(domainChanged(const QString&)));
|
||||
connect(&nodeList->getDomainHandler(), SIGNAL(connectedToDomain(const QString&)), SLOT(connectedToDomain(const QString&)));
|
||||
|
||||
// update our location every 5 seconds in the data-server, assuming that we are authenticated with one
|
||||
const float DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5.0f * 1000.0f;
|
||||
|
||||
QTimer* locationUpdateTimer = new QTimer(this);
|
||||
connect(locationUpdateTimer, &QTimer::timeout, this, &Application::updateLocationInServer);
|
||||
locationUpdateTimer->start(DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS);
|
||||
|
||||
connect(nodeList, &NodeList::nodeAdded, this, &Application::nodeAdded);
|
||||
connect(nodeList, &NodeList::nodeKilled, this, &Application::nodeKilled);
|
||||
|
@ -3113,6 +3120,34 @@ void Application::updateWindowTitle(){
|
|||
_window->setWindowTitle(title);
|
||||
}
|
||||
|
||||
void Application::updateLocationInServer() {
|
||||
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
|
||||
if (accountManager.isLoggedIn()) {
|
||||
|
||||
static QJsonObject lastLocationObject;
|
||||
|
||||
// construct a QJsonObject given the user's current address information
|
||||
QJsonObject updatedLocationObject;
|
||||
|
||||
QJsonObject addressObject;
|
||||
addressObject.insert("position", QString(createByteArray(_myAvatar->getPosition())));
|
||||
addressObject.insert("orientation", QString(createByteArray(glm::degrees(safeEulerAngles(_myAvatar->getOrientation())))));
|
||||
addressObject.insert("domain", NodeList::getInstance()->getDomainHandler().getHostname());
|
||||
|
||||
updatedLocationObject.insert("address", addressObject);
|
||||
|
||||
if (updatedLocationObject != lastLocationObject) {
|
||||
|
||||
accountManager.authenticatedRequest("/api/v1/users/address", QNetworkAccessManager::PutOperation,
|
||||
JSONCallbackParameters(), QJsonDocument(updatedLocationObject).toJson());
|
||||
|
||||
lastLocationObject = updatedLocationObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::domainChanged(const QString& domainHostname) {
|
||||
updateWindowTitle();
|
||||
|
||||
|
|
|
@ -278,6 +278,7 @@ signals:
|
|||
public slots:
|
||||
void domainChanged(const QString& domainHostname);
|
||||
void updateWindowTitle();
|
||||
void updateLocationInServer();
|
||||
void nodeAdded(SharedNodePointer node);
|
||||
void nodeKilled(SharedNodePointer node);
|
||||
void packetSent(quint64 length);
|
||||
|
|
|
@ -49,8 +49,6 @@ const float COLLISION_RADIUS_SCALE = 0.125f;
|
|||
const float MIN_KEYBOARD_CONTROL_SPEED = 2.0f;
|
||||
const float MAX_WALKING_SPEED = 3.0f * MIN_KEYBOARD_CONTROL_SPEED;
|
||||
|
||||
const float DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS = 5.0f * 1000.0f;
|
||||
|
||||
// TODO: normalize avatar speed for standard avatar size, then scale all motion logic
|
||||
// to properly follow avatar size.
|
||||
float DEFAULT_MOTOR_TIMESCALE = 0.25f;
|
||||
|
@ -83,11 +81,6 @@ MyAvatar::MyAvatar() :
|
|||
for (int i = 0; i < MAX_DRIVE_KEYS; i++) {
|
||||
_driveKeys[i] = 0.0f;
|
||||
}
|
||||
|
||||
// update our location every 5 seconds in the data-server, assuming that we are authenticated with one
|
||||
QTimer* locationUpdateTimer = new QTimer(this);
|
||||
connect(locationUpdateTimer, &QTimer::timeout, this, &MyAvatar::updateLocationInDataServer);
|
||||
locationUpdateTimer->start(DATA_SERVER_LOCATION_CHANGE_UPDATE_MSECS);
|
||||
}
|
||||
|
||||
MyAvatar::~MyAvatar() {
|
||||
|
@ -1434,29 +1427,6 @@ void MyAvatar::resetSize() {
|
|||
qDebug("Reseted scale to %f", _targetScale);
|
||||
}
|
||||
|
||||
static QByteArray createByteArray(const glm::vec3& vector) {
|
||||
return QByteArray::number(vector.x) + ',' + QByteArray::number(vector.y) + ',' + QByteArray::number(vector.z);
|
||||
}
|
||||
|
||||
void MyAvatar::updateLocationInDataServer() {
|
||||
// TODO: don't re-send this when it hasn't change or doesn't change by some threshold
|
||||
// This will required storing the last sent values and clearing them when the AccountManager rootURL changes
|
||||
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
|
||||
if (accountManager.isLoggedIn()) {
|
||||
QString positionString(createByteArray(_position));
|
||||
QString orientationString(createByteArray(glm::degrees(safeEulerAngles(getOrientation()))));
|
||||
|
||||
// construct the json to put the user's location
|
||||
QString locationPutJson = QString() + "{\"address\":{\"position\":\""
|
||||
+ positionString + "\", \"orientation\":\"" + orientationString + "\"}}";
|
||||
|
||||
accountManager.authenticatedRequest("/api/v1/users/address", QNetworkAccessManager::PutOperation,
|
||||
JSONCallbackParameters(), locationPutJson.toUtf8());
|
||||
}
|
||||
}
|
||||
|
||||
void MyAvatar::goToLocationFromResponse(const QJsonObject& jsonObject) {
|
||||
|
||||
if (jsonObject["status"].toString() == "success") {
|
||||
|
|
|
@ -108,7 +108,6 @@ public slots:
|
|||
void decreaseSize();
|
||||
void resetSize();
|
||||
|
||||
void updateLocationInDataServer();
|
||||
void goToLocationFromResponse(const QJsonObject& jsonObject);
|
||||
|
||||
// Set/Get update the thrust that will move the avatar around
|
||||
|
|
|
@ -828,3 +828,7 @@ bool isSimilarPosition(const glm::vec3& positionA, const glm::vec3& positionB, f
|
|||
float positionDistance = glm::distance(positionA, positionB);
|
||||
return (positionDistance <= similarEnough);
|
||||
}
|
||||
|
||||
QByteArray createByteArray(const glm::vec3& vector) {
|
||||
return QByteArray::number(vector.x) + ',' + QByteArray::number(vector.y) + ',' + QByteArray::number(vector.z);
|
||||
}
|
||||
|
|
|
@ -187,4 +187,6 @@ bool isSimilarPosition(const glm::vec3& positionA, const glm::vec3& positionB, f
|
|||
/// \return bool is the float NaN
|
||||
bool isNaN(float value);
|
||||
|
||||
QByteArray createByteArray(const glm::vec3& vector);
|
||||
|
||||
#endif // hifi_SharedUtil_h
|
||||
|
|
Loading…
Reference in a new issue