From 8b67710022d854ba945909135fb10c5b86bf1223 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 9 Jun 2015 18:59:58 -0700 Subject: [PATCH] store an in-memory history of the last addresses --- libraries/networking/src/AddressManager.cpp | 32 +++++++++++++++++++-- libraries/networking/src/AddressManager.h | 5 ++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index a86ce78655..642ca4748d 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -35,6 +35,7 @@ AddressManager::AddressManager() : _positionGetter(NULL), _orientationGetter(NULL) { + } bool AddressManager::isConnected() { @@ -217,7 +218,7 @@ void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const const QString DOMAIN_NETWORK_PORT_KEY = "network_port"; const QString DOMAIN_ICE_SERVER_ADDRESS_KEY = "ice_server_address"; - DependencyManager::get()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::HandleAddress); + DependencyManager::get()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::HandleAddress); const QString DOMAIN_ID_KEY = "id"; QString domainIDString = domainObject[DOMAIN_ID_KEY].toString(); @@ -415,6 +416,9 @@ bool AddressManager::handleViewpoint(const QString& viewpointString, bool should positionRegex.cap(2).toFloat(), positionRegex.cap(3).toFloat()); + // we're about to jump positions - store the current address in our history + addCurrentAddressToHistory(); + if (!isNaN(newPosition.x) && !isNaN(newPosition.y) && !isNaN(newPosition.z)) { glm::quat newOrientation; @@ -467,6 +471,10 @@ bool AddressManager::handleUsername(const QString& lookupString) { void AddressManager::setHost(const QString& host) { if (host != _host) { + + // if the host is being changed we should store current address in the history + addCurrentAddressToHistory(); + _host = host; emit hostChanged(_host); } @@ -474,7 +482,8 @@ void AddressManager::setHost(const QString& host) { void AddressManager::setDomainInfo(const QString& hostname, quint16 port) { - _host = hostname; + setHost(hostname); + _rootPlaceID = QUuid(); qCDebug(networking) << "Possible domain change required to connect to domain at" << hostname << "on" << port; @@ -500,3 +509,22 @@ void AddressManager::copyAddress() { void AddressManager::copyPath() { QApplication::clipboard()->setText(currentPath()); } + +void AddressManager::addCurrentAddressToHistory() { + if (_lastHistoryAppend == 0) { + // we don't store the first address on application load + // just update the last append time so the next is stored + _lastHistoryAppend = usecTimestampNow(); + } else { + const quint64 DOUBLE_STORE_THRESHOLD_USECS = 500000; + + // avoid double storing when the host changes and the viewpoint changes immediately after + if (usecTimestampNow() - _lastHistoryAppend > DOUBLE_STORE_THRESHOLD_USECS) { + // add the current address to the history + _history.append(currentAddress()); + + // change our last history append to now + _lastHistoryAppend = usecTimestampNow(); + } + } +} diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h index 2b587a9bd7..d950ae0275 100644 --- a/libraries/networking/src/AddressManager.h +++ b/libraries/networking/src/AddressManager.h @@ -98,10 +98,15 @@ private: bool handleUsername(const QString& lookupString); bool handleDomainID(const QString& host); + void addCurrentAddressToHistory(); + QString _host; QUuid _rootPlaceID; PositionGetter _positionGetter; OrientationGetter _orientationGetter; + + QList _history; + quint64 _lastHistoryAppend = 0; }; #endif // hifi_AddressManager_h