示例#1
0
void AddressManager::setHost(const QString& host, LookupTrigger trigger) {
    if (host != _host) {

        // if the host is being changed we should store current address in the history
        addCurrentAddressToHistory(trigger);

        _host = host;
        emit hostChanged(_host);
    }
}
示例#2
0
bool AddressManager::setHost(const QString& host, LookupTrigger trigger, quint16 port) {
    if (host != _host || port != _port) {
        
        addCurrentAddressToHistory(trigger);

        _port = port;

        if (host != _host) {
            _host = host;
            emit hostChanged(_host);
        }

        return true;
    }

    return false;
}
示例#3
0
bool AddressManager::handleViewpoint(const QString& viewpointString, bool shouldFace,
                                     bool definitelyPathOnly, const QString& pathString) {
    const QString FLOAT_REGEX_STRING = "([-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?)";
    const QString SPACED_COMMA_REGEX_STRING = "\\s*,\\s*";
    const QString POSITION_REGEX_STRING = QString("\\/") + FLOAT_REGEX_STRING + SPACED_COMMA_REGEX_STRING +
        FLOAT_REGEX_STRING + SPACED_COMMA_REGEX_STRING + FLOAT_REGEX_STRING + "\\s*(?:$|\\/)";
    const QString QUAT_REGEX_STRING = QString("\\/") + FLOAT_REGEX_STRING + SPACED_COMMA_REGEX_STRING +
        FLOAT_REGEX_STRING + SPACED_COMMA_REGEX_STRING + FLOAT_REGEX_STRING + SPACED_COMMA_REGEX_STRING +
        FLOAT_REGEX_STRING + "\\s*$";

    QRegExp positionRegex(POSITION_REGEX_STRING);

    if (positionRegex.indexIn(viewpointString) != -1) {
        // we have at least a position, so emit our signal to say we need to change position
        glm::vec3 newPosition(positionRegex.cap(1).toFloat(),
                              positionRegex.cap(2).toFloat(),
                              positionRegex.cap(3).toFloat());

        // We need to use definitelyPathOnly, pathString and _newHostLookupPath to determine if the current address
        // should be stored in the history before we ask for a position/orientation change. A relative path that was
        // not associated with a host lookup should always trigger a history change (definitelyPathOnly) and a viewpointString
        // with a non empty pathString (suggesting this is the result of a lookup with the domain-server) that does not match
        // _newHostLookupPath should always trigger a history change.
        //
        // We use _newHostLookupPath to determine if the client has already stored its last address
        // before moving to a new host thanks to the information in the same lookup URL.


        if (definitelyPathOnly || (!pathString.isEmpty() && pathString != _newHostLookupPath)) {
            addCurrentAddressToHistory(LookupTrigger::UserInput);
        }

        if (!isNaN(newPosition.x) && !isNaN(newPosition.y) && !isNaN(newPosition.z)) {
            glm::quat newOrientation;

            QRegExp orientationRegex(QUAT_REGEX_STRING);

            // we may also have an orientation
            if (viewpointString[positionRegex.matchedLength() - 1] == QChar('/')
                && orientationRegex.indexIn(viewpointString, positionRegex.matchedLength() - 1) != -1) {

                glm::quat newOrientation = glm::normalize(glm::quat(orientationRegex.cap(4).toFloat(),
                                                                    orientationRegex.cap(1).toFloat(),
                                                                    orientationRegex.cap(2).toFloat(),
                                                                    orientationRegex.cap(3).toFloat()));

                if (!isNaN(newOrientation.x) && !isNaN(newOrientation.y) && !isNaN(newOrientation.z)
                    && !isNaN(newOrientation.w)) {
                    emit locationChangeRequired(newPosition, true, newOrientation, shouldFace);
                    return true;
                } else {
                    qCDebug(networking) << "Orientation parsed from lookup string is invalid. Will not use for location change.";
                }
            }

            emit locationChangeRequired(newPosition, false, newOrientation, shouldFace);

        } else {
            qCDebug(networking) << "Could not jump to position from lookup string because it has an invalid value.";
        }

        return true;
    } else {
        return false;
    }
}