mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 00:17:35 +02:00
have AddressManager know its current domain and current path
This commit is contained in:
parent
cb6e420392
commit
f27105100a
5 changed files with 66 additions and 19 deletions
|
@ -299,6 +299,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
|
|
||||||
AddressManager& addressManager = AddressManager::getInstance();
|
AddressManager& addressManager = AddressManager::getInstance();
|
||||||
|
|
||||||
|
// use our MyAvatar position and quat for address manager path
|
||||||
|
addressManager.setPositionGetter(getPositionForPath);
|
||||||
|
addressManager.setOrientationGetter(getOrientationForPath);
|
||||||
|
|
||||||
// handle domain change signals from AddressManager
|
// handle domain change signals from AddressManager
|
||||||
connect(&addressManager, &AddressManager::possibleDomainChangeRequiredToHostname,
|
connect(&addressManager, &AddressManager::possibleDomainChangeRequiredToHostname,
|
||||||
this, &Application::changeDomainHostname);
|
this, &Application::changeDomainHostname);
|
||||||
|
@ -3458,9 +3462,7 @@ void Application::updateLocationInServer() {
|
||||||
|
|
||||||
QJsonObject locationObject;
|
QJsonObject locationObject;
|
||||||
|
|
||||||
QString pathString = AddressManager::pathForPositionAndOrientation(_myAvatar->getPosition(),
|
QString pathString = AddressManager::getInstance().currentPath();
|
||||||
true,
|
|
||||||
_myAvatar->getOrientation());
|
|
||||||
|
|
||||||
const QString LOCATION_KEY_IN_ROOT = "location";
|
const QString LOCATION_KEY_IN_ROOT = "location";
|
||||||
const QString PATH_KEY_IN_LOCATION = "path";
|
const QString PATH_KEY_IN_LOCATION = "path";
|
||||||
|
|
|
@ -140,6 +140,8 @@ class Application : public QApplication {
|
||||||
public:
|
public:
|
||||||
static Application* getInstance() { return static_cast<Application*>(QCoreApplication::instance()); }
|
static Application* getInstance() { return static_cast<Application*>(QCoreApplication::instance()); }
|
||||||
static QString& resourcesPath();
|
static QString& resourcesPath();
|
||||||
|
static const glm::vec3& getPositionForPath() { return getInstance()->_myAvatar->getPosition(); }
|
||||||
|
static glm::quat getOrientationForPath() { return getInstance()->_myAvatar->getOrientation(); }
|
||||||
|
|
||||||
Application(int& argc, char** argv, QElapsedTimer &startup_time);
|
Application(int& argc, char** argv, QElapsedTimer &startup_time);
|
||||||
~Application();
|
~Application();
|
||||||
|
|
|
@ -29,9 +29,7 @@ QString LocationScriptingInterface::getHref() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LocationScriptingInterface::getPathname() {
|
QString LocationScriptingInterface::getPathname() {
|
||||||
MyAvatar* applicationAvatar = Application::getInstance()->getAvatar();
|
return AddressManager::getInstance().currentPath();
|
||||||
return AddressManager::pathForPositionAndOrientation(applicationAvatar->getPosition(),
|
|
||||||
true, applicationAvatar->getOrientation());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LocationScriptingInterface::getHostname() {
|
QString LocationScriptingInterface::getHostname() {
|
||||||
|
|
|
@ -22,17 +22,36 @@ AddressManager& AddressManager::getInstance() {
|
||||||
return sharedInstance;
|
return sharedInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AddressManager::pathForPositionAndOrientation(const glm::vec3& position, bool hasOrientation,
|
AddressManager::AddressManager() :
|
||||||
const glm::quat& orientation) {
|
_currentDomain(),
|
||||||
|
_positionGetter(NULL),
|
||||||
|
_orientationGetter(NULL)
|
||||||
|
{
|
||||||
|
|
||||||
QString pathString = "/" + createByteArray(position);
|
}
|
||||||
|
|
||||||
|
const QString AddressManager::currentPath(bool withOrientation) const {
|
||||||
|
|
||||||
if (hasOrientation) {
|
if (_positionGetter) {
|
||||||
QString orientationString = createByteArray(orientation);
|
QString pathString = "/" + createByteArray(_positionGetter());
|
||||||
pathString += "/" + orientationString;
|
|
||||||
|
if (withOrientation) {
|
||||||
|
if (_orientationGetter) {
|
||||||
|
QString orientationString = createByteArray(_orientationGetter());
|
||||||
|
pathString += "/" + orientationString;
|
||||||
|
} else {
|
||||||
|
qDebug() << "Cannot add orientation to path without a getter for position."
|
||||||
|
<< "Call AdressManager::setOrientationGetter to pass a function that will return a glm::quat";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return pathString;
|
||||||
|
} else {
|
||||||
|
qDebug() << "Cannot create address path without a getter for position."
|
||||||
|
<< "Call AdressManager::setPositionGetter to pass a function that will return a const glm::vec3&";
|
||||||
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const JSONCallbackParameters& AddressManager::apiCallbackParameters() {
|
const JSONCallbackParameters& AddressManager::apiCallbackParameters() {
|
||||||
|
@ -134,6 +153,11 @@ void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
|
||||||
emit possibleDomainChangeRequiredViaICEForID(iceServerAddress, domainID);
|
emit possibleDomainChangeRequiredViaICEForID(iceServerAddress, domainID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set our current domain to the name that came back
|
||||||
|
const QString DOMAIN_NAME_KEY = "name";
|
||||||
|
|
||||||
|
_currentDomain = domainObject[DOMAIN_NAME_KEY].toString();
|
||||||
|
|
||||||
// take the path that came back
|
// take the path that came back
|
||||||
const QString LOCATION_KEY = "location";
|
const QString LOCATION_KEY = "location";
|
||||||
const QString LOCATION_PATH_KEY = "path";
|
const QString LOCATION_PATH_KEY = "path";
|
||||||
|
@ -144,7 +168,7 @@ void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
|
||||||
} else if (domainObject.contains(LOCATION_KEY)) {
|
} else if (domainObject.contains(LOCATION_KEY)) {
|
||||||
returnedPath = domainObject[LOCATION_KEY].toObject()[LOCATION_PATH_KEY].toString();
|
returnedPath = domainObject[LOCATION_KEY].toObject()[LOCATION_PATH_KEY].toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldFaceViewpoint = dataObject.contains(ADDRESS_API_ONLINE_KEY);
|
bool shouldFaceViewpoint = dataObject.contains(ADDRESS_API_ONLINE_KEY);
|
||||||
|
|
||||||
if (!returnedPath.isEmpty()) {
|
if (!returnedPath.isEmpty()) {
|
||||||
|
@ -194,16 +218,25 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) {
|
||||||
QRegExp hostnameRegex(HOSTNAME_REGEX_STRING, Qt::CaseInsensitive);
|
QRegExp hostnameRegex(HOSTNAME_REGEX_STRING, Qt::CaseInsensitive);
|
||||||
|
|
||||||
if (hostnameRegex.indexIn(lookupString) != -1) {
|
if (hostnameRegex.indexIn(lookupString) != -1) {
|
||||||
emit possibleDomainChangeRequiredToHostname(hostnameRegex.cap(0));
|
QString domainHostname = hostnameRegex.cap(0);
|
||||||
|
|
||||||
|
emit possibleDomainChangeRequiredToHostname(domainHostname);
|
||||||
emit lookupResultsFinished();
|
emit lookupResultsFinished();
|
||||||
|
|
||||||
|
_currentDomain = domainHostname;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegExp ipAddressRegex(IP_ADDRESS_REGEX_STRING);
|
QRegExp ipAddressRegex(IP_ADDRESS_REGEX_STRING);
|
||||||
|
|
||||||
if (ipAddressRegex.indexIn(lookupString) != -1) {
|
if (ipAddressRegex.indexIn(lookupString) != -1) {
|
||||||
emit possibleDomainChangeRequiredToHostname(ipAddressRegex.cap(0));
|
QString domainIPString = ipAddressRegex.cap(0);
|
||||||
|
|
||||||
|
emit possibleDomainChangeRequiredToHostname(domainIPString);
|
||||||
emit lookupResultsFinished();
|
emit lookupResultsFinished();
|
||||||
|
|
||||||
|
_currentDomain = domainIPString;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,15 +21,21 @@
|
||||||
|
|
||||||
static const QString HIFI_URL_SCHEME = "hifi";
|
static const QString HIFI_URL_SCHEME = "hifi";
|
||||||
|
|
||||||
|
typedef const glm::vec3& (*PositionGetter)();
|
||||||
|
typedef glm::quat (*OrientationGetter)();
|
||||||
|
|
||||||
class AddressManager : public QObject {
|
class AddressManager : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static AddressManager& getInstance();
|
static AddressManager& getInstance();
|
||||||
|
|
||||||
static QString pathForPositionAndOrientation(const glm::vec3& position, bool hasOrientation = false,
|
const QString currentPath(bool withOrientation = true) const;
|
||||||
const glm::quat& orientation = glm::quat());
|
|
||||||
|
|
||||||
void attemptPlaceNameLookup(const QString& lookupString);
|
void attemptPlaceNameLookup(const QString& lookupString);
|
||||||
|
|
||||||
|
void setPositionGetter(PositionGetter positionGetter) { _positionGetter = positionGetter; }
|
||||||
|
void setOrientationGetter(OrientationGetter orientationGetter) { _orientationGetter = orientationGetter; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void handleLookupString(const QString& lookupString);
|
void handleLookupString(const QString& lookupString);
|
||||||
|
|
||||||
|
@ -46,6 +52,8 @@ signals:
|
||||||
bool hasOrientationChange, const glm::quat& newOrientation,
|
bool hasOrientationChange, const glm::quat& newOrientation,
|
||||||
bool shouldFaceLocation);
|
bool shouldFaceLocation);
|
||||||
private:
|
private:
|
||||||
|
AddressManager();
|
||||||
|
|
||||||
const JSONCallbackParameters& apiCallbackParameters();
|
const JSONCallbackParameters& apiCallbackParameters();
|
||||||
|
|
||||||
bool handleUrl(const QUrl& lookupUrl);
|
bool handleUrl(const QUrl& lookupUrl);
|
||||||
|
@ -53,6 +61,10 @@ private:
|
||||||
bool handleNetworkAddress(const QString& lookupString);
|
bool handleNetworkAddress(const QString& lookupString);
|
||||||
bool handleRelativeViewpoint(const QString& pathSubsection, bool shouldFace = false);
|
bool handleRelativeViewpoint(const QString& pathSubsection, bool shouldFace = false);
|
||||||
bool handleUsername(const QString& lookupString);
|
bool handleUsername(const QString& lookupString);
|
||||||
|
|
||||||
|
QString _currentDomain;
|
||||||
|
PositionGetter _positionGetter;
|
||||||
|
OrientationGetter _orientationGetter;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AddressManager_h
|
#endif // hifi_AddressManager_h
|
Loading…
Reference in a new issue