mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 12:04:18 +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();
|
||||
|
||||
// use our MyAvatar position and quat for address manager path
|
||||
addressManager.setPositionGetter(getPositionForPath);
|
||||
addressManager.setOrientationGetter(getOrientationForPath);
|
||||
|
||||
// handle domain change signals from AddressManager
|
||||
connect(&addressManager, &AddressManager::possibleDomainChangeRequiredToHostname,
|
||||
this, &Application::changeDomainHostname);
|
||||
|
@ -3458,9 +3462,7 @@ void Application::updateLocationInServer() {
|
|||
|
||||
QJsonObject locationObject;
|
||||
|
||||
QString pathString = AddressManager::pathForPositionAndOrientation(_myAvatar->getPosition(),
|
||||
true,
|
||||
_myAvatar->getOrientation());
|
||||
QString pathString = AddressManager::getInstance().currentPath();
|
||||
|
||||
const QString LOCATION_KEY_IN_ROOT = "location";
|
||||
const QString PATH_KEY_IN_LOCATION = "path";
|
||||
|
|
|
@ -140,6 +140,8 @@ class Application : public QApplication {
|
|||
public:
|
||||
static Application* getInstance() { return static_cast<Application*>(QCoreApplication::instance()); }
|
||||
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();
|
||||
|
|
|
@ -29,9 +29,7 @@ QString LocationScriptingInterface::getHref() {
|
|||
}
|
||||
|
||||
QString LocationScriptingInterface::getPathname() {
|
||||
MyAvatar* applicationAvatar = Application::getInstance()->getAvatar();
|
||||
return AddressManager::pathForPositionAndOrientation(applicationAvatar->getPosition(),
|
||||
true, applicationAvatar->getOrientation());
|
||||
return AddressManager::getInstance().currentPath();
|
||||
}
|
||||
|
||||
QString LocationScriptingInterface::getHostname() {
|
||||
|
|
|
@ -22,17 +22,36 @@ AddressManager& AddressManager::getInstance() {
|
|||
return sharedInstance;
|
||||
}
|
||||
|
||||
QString AddressManager::pathForPositionAndOrientation(const glm::vec3& position, bool hasOrientation,
|
||||
const glm::quat& orientation) {
|
||||
AddressManager::AddressManager() :
|
||||
_currentDomain(),
|
||||
_positionGetter(NULL),
|
||||
_orientationGetter(NULL)
|
||||
{
|
||||
|
||||
QString pathString = "/" + createByteArray(position);
|
||||
}
|
||||
|
||||
const QString AddressManager::currentPath(bool withOrientation) const {
|
||||
|
||||
if (hasOrientation) {
|
||||
QString orientationString = createByteArray(orientation);
|
||||
pathString += "/" + orientationString;
|
||||
if (_positionGetter) {
|
||||
QString pathString = "/" + createByteArray(_positionGetter());
|
||||
|
||||
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() {
|
||||
|
@ -134,6 +153,11 @@ void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
|
|||
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
|
||||
const QString LOCATION_KEY = "location";
|
||||
const QString LOCATION_PATH_KEY = "path";
|
||||
|
@ -144,7 +168,7 @@ void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
|
|||
} else if (domainObject.contains(LOCATION_KEY)) {
|
||||
returnedPath = domainObject[LOCATION_KEY].toObject()[LOCATION_PATH_KEY].toString();
|
||||
}
|
||||
|
||||
|
||||
bool shouldFaceViewpoint = dataObject.contains(ADDRESS_API_ONLINE_KEY);
|
||||
|
||||
if (!returnedPath.isEmpty()) {
|
||||
|
@ -194,16 +218,25 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) {
|
|||
QRegExp hostnameRegex(HOSTNAME_REGEX_STRING, Qt::CaseInsensitive);
|
||||
|
||||
if (hostnameRegex.indexIn(lookupString) != -1) {
|
||||
emit possibleDomainChangeRequiredToHostname(hostnameRegex.cap(0));
|
||||
QString domainHostname = hostnameRegex.cap(0);
|
||||
|
||||
emit possibleDomainChangeRequiredToHostname(domainHostname);
|
||||
emit lookupResultsFinished();
|
||||
|
||||
_currentDomain = domainHostname;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QRegExp ipAddressRegex(IP_ADDRESS_REGEX_STRING);
|
||||
|
||||
if (ipAddressRegex.indexIn(lookupString) != -1) {
|
||||
emit possibleDomainChangeRequiredToHostname(ipAddressRegex.cap(0));
|
||||
QString domainIPString = ipAddressRegex.cap(0);
|
||||
|
||||
emit possibleDomainChangeRequiredToHostname(domainIPString);
|
||||
emit lookupResultsFinished();
|
||||
|
||||
_currentDomain = domainIPString;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,15 +21,21 @@
|
|||
|
||||
static const QString HIFI_URL_SCHEME = "hifi";
|
||||
|
||||
typedef const glm::vec3& (*PositionGetter)();
|
||||
typedef glm::quat (*OrientationGetter)();
|
||||
|
||||
class AddressManager : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static AddressManager& getInstance();
|
||||
|
||||
static QString pathForPositionAndOrientation(const glm::vec3& position, bool hasOrientation = false,
|
||||
const glm::quat& orientation = glm::quat());
|
||||
const QString currentPath(bool withOrientation = true) const;
|
||||
|
||||
void attemptPlaceNameLookup(const QString& lookupString);
|
||||
|
||||
void setPositionGetter(PositionGetter positionGetter) { _positionGetter = positionGetter; }
|
||||
void setOrientationGetter(OrientationGetter orientationGetter) { _orientationGetter = orientationGetter; }
|
||||
|
||||
public slots:
|
||||
void handleLookupString(const QString& lookupString);
|
||||
|
||||
|
@ -46,6 +52,8 @@ signals:
|
|||
bool hasOrientationChange, const glm::quat& newOrientation,
|
||||
bool shouldFaceLocation);
|
||||
private:
|
||||
AddressManager();
|
||||
|
||||
const JSONCallbackParameters& apiCallbackParameters();
|
||||
|
||||
bool handleUrl(const QUrl& lookupUrl);
|
||||
|
@ -53,6 +61,10 @@ private:
|
|||
bool handleNetworkAddress(const QString& lookupString);
|
||||
bool handleRelativeViewpoint(const QString& pathSubsection, bool shouldFace = false);
|
||||
bool handleUsername(const QString& lookupString);
|
||||
|
||||
QString _currentDomain;
|
||||
PositionGetter _positionGetter;
|
||||
OrientationGetter _orientationGetter;
|
||||
};
|
||||
|
||||
#endif // hifi_AddressManager_h
|
Loading…
Reference in a new issue