Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all
Unified · Split
| @@ -2338,8 +2338,13 @@ void Application::updateAvatar(float deltaTime) { · 2337 unmodified lines | ||
| 2338 | 2338 | } |
| 2339 | 2339 | |
| 2340 | 2340 | void Application::queryVoxels() { |
| 2341 | − // Need to update this to support multiple different servers... | |
| 2341 | + | |
| 2342 | + // if voxels are disabled, then don't send this at all... | |
| 2343 | + if (!Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) { | |
| 2344 | + return; | |
| 2345 | + } | |
| 2342 | 2346 | |
| 2347 | + // These will be the same for all servers, so we can set them up once and then reuse for each server we send to. | |
| 2343 | 2348 | _voxelQuery.setCameraPosition(_viewFrustum.getPosition()); |
| 2344 | 2349 | _voxelQuery.setCameraOrientation(_viewFrustum.getOrientation()); |
| 2345 | 2350 | _voxelQuery.setCameraFov(_viewFrustum.getFieldOfView()); |
| @@ -2348,24 +2353,59 @@ void Application::queryVoxels() { · 2 unmodified lines | ||
| 2348 | 2353 | _voxelQuery.setCameraFarClip(_viewFrustum.getFarClip()); |
| 2349 | 2354 | _voxelQuery.setCameraEyeOffsetPosition(_viewFrustum.getEyeOffsetPosition()); |
| 2350 | 2355 | |
| 2351 | − NodeList* nodeList = NodeList::getInstance(); | |
| 2352 | − | |
| 2353 | − // send head/hand data to the avatar mixer and voxel server | |
| 2354 | 2356 | unsigned char voxelQueryPacket[MAX_PACKET_SIZE]; |
| 2355 | − unsigned char* endOfVoxelQueryPacket = voxelQueryPacket; | |
| 2356 | − | |
| 2357 | − endOfVoxelQueryPacket += populateTypeAndVersion(endOfVoxelQueryPacket, PACKET_TYPE_VOXEL_QUERY); | |
| 2357 | + | |
| 2358 | + NodeList* nodeList = NodeList::getInstance(); | |
| 2359 | + | |
| 2360 | + // Iterate all of the nodes, and get a count of how many voxel servers we have... | |
| 2361 | + int voxelServerCount = 0; | |
| 2362 | + for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | |
| 2363 | + // only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER | |
| 2364 | + if (node->getActiveSocket() != NULL && node->getType() == NODE_TYPE_VOXEL_SERVER) { | |
| 2365 | + voxelServerCount++; | |
| 2366 | + } | |
| 2367 | + } | |
| 2368 | + | |
| 2369 | + // make sure there's at least one voxel server | |
| 2370 | + if (voxelServerCount < 1) { | |
| 2371 | + return; // no voxel servers to talk to, we can bail. | |
| 2372 | + } | |
| 2358 | 2373 | |
| 2359 | − QByteArray ownerUUID = nodeList->getOwnerUUID().toRfc4122(); | |
| 2360 | − memcpy(endOfVoxelQueryPacket, ownerUUID.constData(), ownerUUID.size()); | |
| 2361 | − endOfVoxelQueryPacket += ownerUUID.size(); | |
| 2374 | + // set our preferred PPS to be exactly evenly divided among all of the voxel servers... | |
| 2375 | + int perServerPPS = DEFAULT_MAX_VOXEL_PPS/voxelServerCount; | |
| 2376 | + printf("queryVoxels()... perServerPPS=%d\n",perServerPPS); | |
| 2362 | 2377 | |
| 2363 | − endOfVoxelQueryPacket += _voxelQuery.getBroadcastData(endOfVoxelQueryPacket); | |
| 2378 | + _voxelQuery.setMaxVoxelPacketsPerSecond(perServerPPS); | |
| 2364 | 2379 | |
| 2365 | − const char nodeTypesOfInterest[] = { NODE_TYPE_VOXEL_SERVER }; | |
| 2366 | − controlledBroadcastToNodes(voxelQueryPacket, endOfVoxelQueryPacket - voxelQueryPacket, | |
| 2367 | − nodeTypesOfInterest, sizeof(nodeTypesOfInterest)); | |
| 2380 | + UDPSocket* nodeSocket = NodeList::getInstance()->getNodeSocket(); | |
| 2381 | + for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | |
| 2382 | + // only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER | |
| 2383 | + if (node->getActiveSocket() != NULL && node->getType() == NODE_TYPE_VOXEL_SERVER) { | |
| 2384 | + | |
| 2385 | + // we can use this to get the voxel server details | |
| 2386 | + //QUuid nodeUUID = node->getUUID(); | |
| 2387 | + //const JurisdictionMap& map = (_voxelServerJurisdictions)[nodeUUID]; | |
| 2388 | + | |
| 2389 | + // set up the packet for sending... | |
| 2390 | + unsigned char* endOfVoxelQueryPacket = voxelQueryPacket; | |
| 2368 | 2391 | |
| 2392 | + // insert packet type/version and node UUID | |
| 2393 | + endOfVoxelQueryPacket += populateTypeAndVersion(endOfVoxelQueryPacket, PACKET_TYPE_VOXEL_QUERY); | |
| 2394 | + QByteArray ownerUUID = nodeList->getOwnerUUID().toRfc4122(); | |
| 2395 | + memcpy(endOfVoxelQueryPacket, ownerUUID.constData(), ownerUUID.size()); | |
| 2396 | + endOfVoxelQueryPacket += ownerUUID.size(); | |
| 2397 | + | |
| 2398 | + // encode the query data... | |
| 2399 | + endOfVoxelQueryPacket += _voxelQuery.getBroadcastData(endOfVoxelQueryPacket); | |
| 2400 | + | |
| 2401 | + int packetLength = endOfVoxelQueryPacket - voxelQueryPacket; | |
| 2402 | + | |
| 2403 | + nodeSocket->send(node->getActiveSocket(), voxelQueryPacket, packetLength); | |
| 2404 | + | |
| 2405 | + // Feed number of bytes to corresponding channel of the bandwidth meter | |
| 2406 | + _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(packetLength); | |
| 2407 | + } | |
| 2408 | + } | |
| 2369 | 2409 | } |
| 2370 | 2410 | |
| 2371 | 2411 | ///////////////////////////////////////////////////////////////////////////////////// |