Пример #1
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
}
Пример #2
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
}
Пример #3
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
}