Exemple #1
0
void OctreeServer::attachQueryNodeToNode(Node* newNode) {
    if (!newNode->getLinkedData()) {
        OctreeQueryNode* newQueryNodeData = _instance->createOctreeQueryNode();
        newQueryNodeData->resetOctreePacket(true); // don't bump sequence
        newNode->setLinkedData(newQueryNodeData);
    }
}
Exemple #2
0
bool OctreeSendThread::process() {
    quint64  start = usecTimestampNow();
    bool gotLock = false;

    // don't do any send processing until the initial load of the octree is complete...
    if (_myServer->isInitialLoadComplete()) {
        SharedNodePointer node = NodeList::getInstance()->nodeWithUUID(_nodeUUID);

        if (node) {
            // make sure the node list doesn't kill our node while we're using it
            if (node->getMutex().tryLock()) {
                gotLock = true;
                OctreeQueryNode* nodeData = NULL;

                nodeData = (OctreeQueryNode*) node->getLinkedData();

                int packetsSent = 0;

                // Sometimes the node data has not yet been linked, in which case we can't really do anything
                if (nodeData) {
                    bool viewFrustumChanged = nodeData->updateCurrentViewFrustum();
                    if (_myServer->wantsDebugSending() && _myServer->wantsVerboseDebug()) {
                        printf("nodeData->updateCurrentViewFrustum() changed=%s\n", debug::valueOf(viewFrustumChanged));
                    }
                    packetsSent = packetDistributor(node, nodeData, viewFrustumChanged);
                }

                node->getMutex().unlock(); // we're done with this node for now.
            }
        }
    } else {
        if (_myServer->wantsDebugSending() && _myServer->wantsVerboseDebug()) {
            qDebug("OctreeSendThread::process() waiting for isInitialLoadComplete()");
        }
    }

    // Only sleep if we're still running and we got the lock last time we tried, otherwise try to get the lock asap
    if (isStillRunning() && gotLock) {
        // dynamically sleep until we need to fire off the next set of octree elements
        int elapsed = (usecTimestampNow() - start);
        int usecToSleep =  OCTREE_SEND_INTERVAL_USECS - elapsed;

        if (usecToSleep > 0) {
            PerformanceWarning warn(false,"OctreeSendThread... usleep()",false,&_usleepTime,&_usleepCalls);
            usleep(usecToSleep);
        } else {
            if (_myServer->wantsDebugSending() && _myServer->wantsVerboseDebug()) {
                std::cout << "Last send took too much time, not sleeping!\n";
            }
        }
    }

    return isStillRunning();  // keep running till they terminate us
}
Exemple #3
0
bool OctreeSendThread::process() {
    if (_isShuttingDown) {
        return false; // exit early if we're shutting down
    }

    // check that our server and assignment is still valid
    if (!_myServer || !_myAssignment) {
        return false; // exit early if it's not, it means the server is shutting down
    }

    OctreeServer::didProcess(this);

    quint64  start = usecTimestampNow();

    // don't do any send processing until the initial load of the octree is complete...
    if (_myServer->isInitialLoadComplete()) {
        if (_node) {
            _nodeMissingCount = 0;
            OctreeQueryNode* nodeData = static_cast<OctreeQueryNode*>(_node->getLinkedData());

            // Sometimes the node data has not yet been linked, in which case we can't really do anything
            if (nodeData && !nodeData->isShuttingDown()) {
                bool viewFrustumChanged = nodeData->updateCurrentViewFrustum();
                packetDistributor(nodeData, viewFrustumChanged);
            }
        }
    }

    if (_isShuttingDown) {
        return false; // exit early if we're shutting down
    }

    // Only sleep if we're still running and we got the lock last time we tried, otherwise try to get the lock asap
    if (isStillRunning()) {
        // dynamically sleep until we need to fire off the next set of octree elements
        int elapsed = (usecTimestampNow() - start);
        int usecToSleep =  OCTREE_SEND_INTERVAL_USECS - elapsed;

        if (usecToSleep > 0) {
            PerformanceWarning warn(false,"OctreeSendThread... usleep()",false,&_usleepTime,&_usleepCalls);
            usleep(usecToSleep);
        } else {
            const int MIN_USEC_TO_SLEEP = 1;
            usleep(MIN_USEC_TO_SLEEP);
        }
    }

    return isStillRunning();  // keep running till they terminate us
}
Exemple #4
0
bool OctreeSendThread::process() {
    const int MAX_NODE_MISSING_CHECKS = 10;
    if (_nodeMissingCount > MAX_NODE_MISSING_CHECKS) {
        qDebug() << "our target node:" << _nodeUUID << "has been missing the last" << _nodeMissingCount 
                        << "times we checked, we are going to stop attempting to send.";
        return false; // stop processing and shutdown, our node no longer exists
    }

    quint64  start = usecTimestampNow();

    // don't do any send processing until the initial load of the octree is complete...
    if (_myServer->isInitialLoadComplete()) {
        SharedNodePointer node = NodeList::getInstance()->nodeWithUUID(_nodeUUID);

        if (node) {
            _nodeMissingCount = 0;
            OctreeQueryNode* nodeData = NULL;

            nodeData = (OctreeQueryNode*) node->getLinkedData();

            // Sometimes the node data has not yet been linked, in which case we can't really do anything
            if (nodeData) {
                bool viewFrustumChanged = nodeData->updateCurrentViewFrustum();
                packetDistributor(node, nodeData, viewFrustumChanged);
            }
        } else {
            _nodeMissingCount++;
        }
    }

    // Only sleep if we're still running and we got the lock last time we tried, otherwise try to get the lock asap
    if (isStillRunning()) {
        // dynamically sleep until we need to fire off the next set of octree elements
        int elapsed = (usecTimestampNow() - start);
        int usecToSleep =  OCTREE_SEND_INTERVAL_USECS - elapsed;

        if (usecToSleep > 0) {
            PerformanceWarning warn(false,"OctreeSendThread... usleep()",false,&_usleepTime,&_usleepCalls);
            usleep(usecToSleep);
        } else {
            const int MIN_USEC_TO_SLEEP = 1;
            usleep(MIN_USEC_TO_SLEEP);
        }
    }

    return isStillRunning();  // keep running till they terminate us
}
Exemple #5
0
void OctreeServer::processDatagram(const QByteArray& dataByteArray, const HifiSockAddr& senderSockAddr) {
    NodeList* nodeList = NodeList::getInstance();
    
    PACKET_TYPE packetType = dataByteArray[0];
    
    if (packetType == getMyQueryMessageType()) {
        bool debug = false;
        if (debug) {
            qDebug("Got PACKET_TYPE_VOXEL_QUERY at %llu.\n", usecTimestampNow());
        }
        
        int numBytesPacketHeader = numBytesForPacketHeader((unsigned char*) dataByteArray.data());
        
        // If we got a PACKET_TYPE_VOXEL_QUERY, then we're talking to an NODE_TYPE_AVATAR, and we
        // need to make sure we have it in our nodeList.
        QUuid nodeUUID = QUuid::fromRfc4122(dataByteArray.mid(numBytesPacketHeader,
                                                              NUM_BYTES_RFC4122_UUID));
        
        Node* node = nodeList->nodeWithUUID(nodeUUID);
        
        if (node) {
            nodeList->updateNodeWithData(node, senderSockAddr, (unsigned char *) dataByteArray.data(),
                                         dataByteArray.size());
            if (!node->getActiveSocket()) {
                // we don't have an active socket for this node, but they're talking to us
                // this means they've heard from us and can reply, let's assume public is active
                node->activatePublicSocket();
            }
            OctreeQueryNode* nodeData = (OctreeQueryNode*) node->getLinkedData();
            if (nodeData && !nodeData->isOctreeSendThreadInitalized()) {
                nodeData->initializeOctreeSendThread(this);
            }
        }
    } else if (packetType == PACKET_TYPE_JURISDICTION_REQUEST) {
        _jurisdictionSender->queueReceivedPacket(senderSockAddr, (unsigned char*) dataByteArray.data(),
                                                 dataByteArray.size());
    } else if (_octreeInboundPacketProcessor && getOctree()->handlesEditPacketType(packetType)) {
       _octreeInboundPacketProcessor->queueReceivedPacket(senderSockAddr, (unsigned char*) dataByteArray.data(),
                                                                    dataByteArray.size());
   } else {
       // let processNodeData handle it.
       NodeList::getInstance()->processNodeData(senderSockAddr, (unsigned char*) dataByteArray.data(),
                                                dataByteArray.size());
    }
}