From 37584244e60eb20f83c6a010c2ccf13b49eb9c10 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 24 Oct 2013 18:37:31 -0700 Subject: [PATCH 1/2] only send PACKET_TYPE_VOXEL_QUERY to voxel servers in view --- interface/src/Application.cpp | 97 ++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 19 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e4ab1be8ab..01eb347b87 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2362,18 +2362,56 @@ void Application::queryVoxels() { for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { // only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER if (node->getActiveSocket() != NULL && node->getType() == NODE_TYPE_VOXEL_SERVER) { - voxelServerCount++; + + // get the server bounds for this server + QUuid nodeUUID = node->getUUID(); + const JurisdictionMap& map = (_voxelServerJurisdictions)[nodeUUID]; + + unsigned char* rootCode = map.getRootOctalCode(); + + if (rootCode) { + VoxelPositionSize rootDetails; + voxelDetailsForCode(rootCode, rootDetails); + AABox serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s); + serverBounds.scale(TREE_SCALE); + + ViewFrustum::location serverFrustumLocation = _viewFrustum.boxInFrustum(serverBounds); + + /** + printf("queryVoxels()... checking to server UUID=%s bounds=[%f, %f, %f, %f] ", + node->getUUID().toString().toLocal8Bit().constData(), + rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s); + switch (serverFrustumLocation) { + case ViewFrustum::OUTSIDE: { + printf("location=ViewFrustum::OUTSIDE\n"); + } break; + + case ViewFrustum::INSIDE: { + printf("location=ViewFrustum::INSIDE\n"); + } break; + + case ViewFrustum::INTERSECT: { + printf("location=ViewFrustum::INTERSECT\n"); + } break; + } + **/ + + if (serverFrustumLocation != ViewFrustum::OUTSIDE) { + voxelServerCount++; + } + } } } // make sure there's at least one voxel server if (voxelServerCount < 1) { + //printf("queryVoxels()... no servers in view, not sending PACKET_TYPE_VOXEL_QUERY\n"); return; // no voxel servers to talk to, we can bail. } // set our preferred PPS to be exactly evenly divided among all of the voxel servers... int perServerPPS = DEFAULT_MAX_VOXEL_PPS/voxelServerCount; - printf("queryVoxels()... perServerPPS=%d\n",perServerPPS); + //printf("queryVoxels()... perServerPPS=%d\n",perServerPPS); _voxelQuery.setMaxVoxelPacketsPerSecond(perServerPPS); @@ -2382,28 +2420,49 @@ void Application::queryVoxels() { // only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER if (node->getActiveSocket() != NULL && node->getType() == NODE_TYPE_VOXEL_SERVER) { - // we can use this to get the voxel server details - //QUuid nodeUUID = node->getUUID(); - //const JurisdictionMap& map = (_voxelServerJurisdictions)[nodeUUID]; - // set up the packet for sending... - unsigned char* endOfVoxelQueryPacket = voxelQueryPacket; + // get the server bounds for this server + QUuid nodeUUID = node->getUUID(); + const JurisdictionMap& map = (_voxelServerJurisdictions)[nodeUUID]; - // insert packet type/version and node UUID - endOfVoxelQueryPacket += populateTypeAndVersion(endOfVoxelQueryPacket, PACKET_TYPE_VOXEL_QUERY); - QByteArray ownerUUID = nodeList->getOwnerUUID().toRfc4122(); - memcpy(endOfVoxelQueryPacket, ownerUUID.constData(), ownerUUID.size()); - endOfVoxelQueryPacket += ownerUUID.size(); - - // encode the query data... - endOfVoxelQueryPacket += _voxelQuery.getBroadcastData(endOfVoxelQueryPacket); + unsigned char* rootCode = map.getRootOctalCode(); - int packetLength = endOfVoxelQueryPacket - voxelQueryPacket; + if (rootCode) { + VoxelPositionSize rootDetails; + voxelDetailsForCode(rootCode, rootDetails); + AABox serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s); + serverBounds.scale(TREE_SCALE); - nodeSocket->send(node->getActiveSocket(), voxelQueryPacket, packetLength); + ViewFrustum::location serverFrustumLocation = _viewFrustum.boxInFrustum(serverBounds); + + if (serverFrustumLocation != ViewFrustum::OUTSIDE) { + + /** + printf("queryVoxels()... sending PACKET_TYPE_VOXEL_QUERY to server UUID=%s bounds=[%f, %f, %f, %f] PPS=%d\n", + node->getUUID().toString().toLocal8Bit().constData(), + rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s, perServerPPS); + **/ + + // set up the packet for sending... + unsigned char* endOfVoxelQueryPacket = voxelQueryPacket; - // Feed number of bytes to corresponding channel of the bandwidth meter - _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(packetLength); + // insert packet type/version and node UUID + endOfVoxelQueryPacket += populateTypeAndVersion(endOfVoxelQueryPacket, PACKET_TYPE_VOXEL_QUERY); + QByteArray ownerUUID = nodeList->getOwnerUUID().toRfc4122(); + memcpy(endOfVoxelQueryPacket, ownerUUID.constData(), ownerUUID.size()); + endOfVoxelQueryPacket += ownerUUID.size(); + + // encode the query data... + endOfVoxelQueryPacket += _voxelQuery.getBroadcastData(endOfVoxelQueryPacket); + + int packetLength = endOfVoxelQueryPacket - voxelQueryPacket; + + nodeSocket->send(node->getActiveSocket(), voxelQueryPacket, packetLength); + + // Feed number of bytes to corresponding channel of the bandwidth meter + _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(packetLength); + } + } } } } From 660edddf66799087f93651556b6f8e526028992f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 24 Oct 2013 18:38:33 -0700 Subject: [PATCH 2/2] only send PACKET_TYPE_VOXEL_QUERY to voxel servers in view --- interface/src/Application.cpp | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 01eb347b87..d7debc3528 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2377,25 +2377,6 @@ void Application::queryVoxels() { ViewFrustum::location serverFrustumLocation = _viewFrustum.boxInFrustum(serverBounds); - /** - printf("queryVoxels()... checking to server UUID=%s bounds=[%f, %f, %f, %f] ", - node->getUUID().toString().toLocal8Bit().constData(), - rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s); - switch (serverFrustumLocation) { - case ViewFrustum::OUTSIDE: { - printf("location=ViewFrustum::OUTSIDE\n"); - } break; - - case ViewFrustum::INSIDE: { - printf("location=ViewFrustum::INSIDE\n"); - } break; - - case ViewFrustum::INTERSECT: { - printf("location=ViewFrustum::INTERSECT\n"); - } break; - } - **/ - if (serverFrustumLocation != ViewFrustum::OUTSIDE) { voxelServerCount++; } @@ -2405,13 +2386,11 @@ void Application::queryVoxels() { // make sure there's at least one voxel server if (voxelServerCount < 1) { - //printf("queryVoxels()... no servers in view, not sending PACKET_TYPE_VOXEL_QUERY\n"); return; // no voxel servers to talk to, we can bail. } // set our preferred PPS to be exactly evenly divided among all of the voxel servers... int perServerPPS = DEFAULT_MAX_VOXEL_PPS/voxelServerCount; - //printf("queryVoxels()... perServerPPS=%d\n",perServerPPS); _voxelQuery.setMaxVoxelPacketsPerSecond(perServerPPS); @@ -2436,13 +2415,6 @@ void Application::queryVoxels() { ViewFrustum::location serverFrustumLocation = _viewFrustum.boxInFrustum(serverBounds); if (serverFrustumLocation != ViewFrustum::OUTSIDE) { - - /** - printf("queryVoxels()... sending PACKET_TYPE_VOXEL_QUERY to server UUID=%s bounds=[%f, %f, %f, %f] PPS=%d\n", - node->getUUID().toString().toLocal8Bit().constData(), - rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s, perServerPPS); - **/ - // set up the packet for sending... unsigned char* endOfVoxelQueryPacket = voxelQueryPacket;