Showing the changes to interface/src/Application.cpp (1 of 2 files). Show all
Unified · Split
| @@ -483,32 +483,41 @@ void Application::resizeGL(int width, int height) { · 482 unmodified lines | ||
| 483 | 483 | glLoadIdentity(); |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | −void Application::broadcastToNodes(unsigned char* data, size_t bytes, const char type) { | |
| 487 | − | |
| 486 | +void Application::controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes, | |
| 487 | + const char* nodeTypes, int numNodeTypes) { | |
| 488 | 488 | Application* self = getInstance(); |
| 489 | − BandwidthMeter::ChannelIndex channel; | |
| 490 | − switch (type) { | |
| 491 | − case NODE_TYPE_AGENT: | |
| 492 | − case NODE_TYPE_AVATAR_MIXER: | |
| 493 | − channel = BandwidthMeter::AVATARS; | |
| 494 | − break; | |
| 495 | − case NODE_TYPE_VOXEL_SERVER: | |
| 496 | − channel = BandwidthMeter::VOXELS; | |
| 497 | − if (self->_renderVoxels->isChecked()) { | |
| 489 | + for (int i = 0; i < numNodeTypes; ++i) { | |
| 490 | + | |
| 491 | + // Intercept data to voxel server when voxels are disabled | |
| 492 | + if (nodeTypes[i] == NODE_TYPE_VOXEL_SERVER && ! self->_renderVoxels->isChecked()) { | |
| 493 | + continue; | |
| 494 | + } | |
| 495 | + | |
| 496 | + // Perform the broadcast for one type | |
| 497 | + int nReceivingNodes = NodeList::getInstance()->broadcastToNodes(broadcastData, dataBytes, & nodeTypes[i], 1); | |
| 498 | + | |
| 499 | + // Feed number of bytes to corresponding channel of the bandwidth meter, if any (done otherwise) | |
| 500 | + BandwidthMeter::ChannelIndex channel; | |
| 501 | + switch (nodeTypes[i]) { | |
| 502 | + case NODE_TYPE_AGENT: | |
| 503 | + case NODE_TYPE_AVATAR_MIXER: | |
| 504 | + channel = BandwidthMeter::AVATARS; | |
| 505 | + break; | |
| 506 | + case NODE_TYPE_VOXEL_SERVER: | |
| 507 | + channel = BandwidthMeter::VOXELS; | |
| 498 | 508 | break; |
| 509 | + default: | |
| 510 | + continue; | |
| 499 | 511 | } |
| 500 | − default: | |
| 501 | − return; | |
| 512 | + self->_bandwidthMeter.outputStream(channel).updateValue(nReceivingNodes * dataBytes); | |
| 502 | 513 | } |
| 503 | − int n = NodeList::getInstance()->broadcastToNodes(data, bytes, & type, 1); | |
| 504 | − self->_bandwidthMeter.outputStream(channel).updateValue(n * bytes); | |
| 505 | 514 | } |
| 506 | 515 | |
| 507 | 516 | void Application::sendVoxelServerAddScene() { |
| 508 | 517 | char message[100]; |
| 509 | 518 | sprintf(message,"%c%s",'Z',"add scene"); |
| 510 | 519 | int messageSize = strlen(message) + 1; |
| 511 | − broadcastToNodes((unsigned char*)message, messageSize, NODE_TYPE_VOXEL_SERVER); | |
| 520 | + controlledBroadcastToNodes((unsigned char*)message, messageSize, & NODE_TYPE_VOXEL_SERVER, 1); | |
| 512 | 521 | } |
| 513 | 522 | |
| 514 | 523 | void Application::keyPressEvent(QKeyEvent* event) { |
| @@ -887,10 +896,8 @@ void Application::sendPingPackets() { · 372 unmodified lines | ||
| 887 | 896 | pingPacket[0] = PACKET_HEADER_PING; |
| 888 | 897 | |
| 889 | 898 | memcpy(&pingPacket[1], ¤tTime, sizeof(currentTime)); |
| 890 | − for (int i = 0; i < sizeof(nodeTypesOfInterest) / sizeof(char); ++i) { | |
| 891 | − getInstance()->broadcastToNodes(pingPacket, 1 + sizeof(currentTime), nodeTypesOfInterest[i]); | |
| 892 | − } | |
| 893 | − | |
| 899 | + getInstance()->controlledBroadcastToNodes(pingPacket, 1 + sizeof(currentTime), | |
| 900 | + nodeTypesOfInterest, sizeof(nodeTypesOfInterest)); | |
| 894 | 901 | } |
| 895 | 902 | |
| 896 | 903 | // Every second, check the frame rates and other stuff |
| @@ -991,7 +998,7 @@ void Application::sendAvatarVoxelURLMessage(const QUrl& url) { · 94 unmodified lines | ||
| 991 | 998 | message.append((const char*)&ownerID, sizeof(ownerID)); |
| 992 | 999 | message.append(url.toEncoded()); |
| 993 | 1000 | |
| 994 | − broadcastToNodes((unsigned char*)message.data(), message.size(), NODE_TYPE_AVATAR_MIXER); | |
| 1001 | + controlledBroadcastToNodes((unsigned char*)message.data(), message.size(), & NODE_TYPE_AVATAR_MIXER, 1); | |
| 995 | 1002 | } |
| 996 | 1003 | |
| 997 | 1004 | void Application::processAvatarVoxelURLMessage(unsigned char *packetData, size_t dataBytes) { |
| @@ -1224,7 +1231,7 @@ void Application::sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail · 226 unmodified lines | ||
| 1224 | 1231 | int sizeOut; |
| 1225 | 1232 | |
| 1226 | 1233 | if (createVoxelEditMessage(header, 0, 1, &detail, bufferOut, sizeOut)){ |
| 1227 | − Application::broadcastToNodes(bufferOut, sizeOut, NODE_TYPE_VOXEL_SERVER); | |
| 1234 | + Application::controlledBroadcastToNodes(bufferOut, sizeOut, & NODE_TYPE_VOXEL_SERVER, 1); | |
| 1228 | 1235 | delete[] bufferOut; |
| 1229 | 1236 | } |
| 1230 | 1237 | } |
| @@ -1305,7 +1312,7 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 74 unmodified lines | ||
| 1305 | 1312 | |
| 1306 | 1313 | // if we have room don't have room in the buffer, then send the previously generated message first |
| 1307 | 1314 | if (args->bufferInUse + codeAndColorLength > MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE) { |
| 1308 | − broadcastToNodes(args->messageBuffer, args->bufferInUse, NODE_TYPE_VOXEL_SERVER); | |
| 1315 | + controlledBroadcastToNodes(args->messageBuffer, args->bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1); | |
| 1309 | 1316 | args->bufferInUse = sizeof(PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int); // reset |
| 1310 | 1317 | } |
| 1311 | 1318 | |
| @@ -1386,7 +1393,7 @@ void Application::importVoxels() { · 74 unmodified lines | ||
| 1386 | 1393 | |
| 1387 | 1394 | // If we have voxels left in the packet, then send the packet |
| 1388 | 1395 | if (args.bufferInUse > (sizeof(PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int))) { |
| 1389 | − broadcastToNodes(args.messageBuffer, args.bufferInUse, NODE_TYPE_VOXEL_SERVER); | |
| 1396 | + controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1); | |
| 1390 | 1397 | } |
| 1391 | 1398 | |
| 1392 | 1399 | if (calculatedOctCode) { |
| @@ -1438,7 +1445,7 @@ void Application::pasteVoxels() { · 45 unmodified lines | ||
| 1438 | 1445 | |
| 1439 | 1446 | // If we have voxels left in the packet, then send the packet |
| 1440 | 1447 | if (args.bufferInUse > (sizeof(PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int))) { |
| 1441 | − broadcastToNodes(args.messageBuffer, args.bufferInUse, NODE_TYPE_VOXEL_SERVER); | |
| 1448 | + controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1); | |
| 1442 | 1449 | } |
| 1443 | 1450 | |
| 1444 | 1451 | if (calculatedOctCode) { |
| @@ -1986,9 +1993,10 @@ void Application::updateAvatar(float deltaTime) { · 541 unmodified lines | ||
| 1986 | 1993 | endOfBroadcastStringWrite += packNodeId(endOfBroadcastStringWrite, nodeList->getOwnerID()); |
| 1987 | 1994 | |
| 1988 | 1995 | endOfBroadcastStringWrite += _myAvatar.getBroadcastData(endOfBroadcastStringWrite); |
| 1989 | − | |
| 1990 | − broadcastToNodes(broadcastString, endOfBroadcastStringWrite - broadcastString, NODE_TYPE_VOXEL_SERVER); | |
| 1991 | − broadcastToNodes(broadcastString, endOfBroadcastStringWrite - broadcastString, NODE_TYPE_AVATAR_MIXER); | |
| 1996 | + | |
| 1997 | + const char nodeTypesOfInterest[] = { NODE_TYPE_VOXEL_SERVER, NODE_TYPE_AVATAR_MIXER }; | |
| 1998 | + controlledBroadcastToNodes(broadcastString, endOfBroadcastStringWrite - broadcastString, | |
| 1999 | + nodeTypesOfInterest, sizeof(nodeTypesOfInterest)); | |
| 1992 | 2000 | |
| 1993 | 2001 | // once in a while, send my voxel url |
| 1994 | 2002 | const float AVATAR_VOXEL_URL_SEND_INTERVAL = 1.0f; // seconds |