Ejemplo n.º 1
0
void *distributeVoxelsToListeners(void *args) {
    
    NodeList* nodeList = NodeList::getInstance();
    timeval lastSendTime;
    
    while (true) {
        gettimeofday(&lastSendTime, NULL);
        
        // enumerate the nodes to send 3 packets to each
        for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
            VoxelNodeData* nodeData = (VoxelNodeData*) 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();
                if (::debugVoxelSending) {
                    printf("nodeData->updateCurrentViewFrustum() changed=%s\n", debug::valueOf(viewFrustumChanged));
                }
                deepestLevelVoxelDistributor(nodeList, node, nodeData, viewFrustumChanged);
            }
        }
        
        // dynamically sleep until we need to fire off the next set of voxels
        int usecToSleep =  VOXEL_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSendTime));
        
        if (usecToSleep > 0) {
            usleep(usecToSleep);
        } else {
            if (::debugVoxelSending) {
                std::cout << "Last send took too much time, not sleeping!\n";
            }
        }
    }
    
    pthread_exit(0);
}