store an in-memory history of the last addresses

This commit is contained in:
Stephen Birarda 2015-06-09 18:59:58 -07:00
parent 091ed5b514
commit 8b67710022
2 changed files with 35 additions and 2 deletions
libraries/networking/src

View file

@ -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<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::HandleAddress);
DependencyManager::get<NodeList>()->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();
}
}
}

View file

@ -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<QUrl> _history;
quint64 _lastHistoryAppend = 0;
};
#endif // hifi_AddressManager_h