History

changes broadcast function in Application to use a different name but the same signature as in NodeList

tosh committed 13 years ago

Commit c2e2ff01 parent 2da132b2 files · +39 −29Browse files

Showing the changes to interface/src/Application.cpp (1 of 2 files). Show all

Unified · Split

interface/src/Application.cpp+36−28
@@ -483,32 +483,41 @@ void Application::resizeGL(int width, int height) { · 482 unmodified lines
483483 glLoadIdentity();
484484 }
485485
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) {
488488 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;
498508 break;
509+ default:
510+ continue;
499511 }
500− default:
501− return;
512+ self->_bandwidthMeter.outputStream(channel).updateValue(nReceivingNodes * dataBytes);
502513 }
503− int n = NodeList::getInstance()->broadcastToNodes(data, bytes, & type, 1);
504− self->_bandwidthMeter.outputStream(channel).updateValue(n * bytes);
505514 }
506515
507516 void Application::sendVoxelServerAddScene() {
508517 char message[100];
509518 sprintf(message,"%c%s",'Z',"add scene");
510519 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);
512521 }
513522
514523 void Application::keyPressEvent(QKeyEvent* event) {
@@ -887,10 +896,8 @@ void Application::sendPingPackets() { · 372 unmodified lines
887896 pingPacket[0] = PACKET_HEADER_PING;
888897
889898 memcpy(&pingPacket[1], &currentTime, 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));
894901 }
895902
896903 // Every second, check the frame rates and other stuff
@@ -991,7 +998,7 @@ void Application::sendAvatarVoxelURLMessage(const QUrl& url) { · 94 unmodified lines
991998 message.append((const char*)&ownerID, sizeof(ownerID));
992999 message.append(url.toEncoded());
9931000
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);
9951002 }
9961003
9971004 void Application::processAvatarVoxelURLMessage(unsigned char *packetData, size_t dataBytes) {
@@ -1224,7 +1231,7 @@ void Application::sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail · 226 unmodified lines
12241231 int sizeOut;
12251232
12261233 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);
12281235 delete[] bufferOut;
12291236 }
12301237 }
@@ -1305,7 +1312,7 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 74 unmodified lines
13051312
13061313 // if we have room don't have room in the buffer, then send the previously generated message first
13071314 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);
13091316 args->bufferInUse = sizeof(PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int); // reset
13101317 }
13111318
@@ -1386,7 +1393,7 @@ void Application::importVoxels() { · 74 unmodified lines
13861393
13871394 // If we have voxels left in the packet, then send the packet
13881395 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);
13901397 }
13911398
13921399 if (calculatedOctCode) {
@@ -1438,7 +1445,7 @@ void Application::pasteVoxels() { · 45 unmodified lines
14381445
14391446 // If we have voxels left in the packet, then send the packet
14401447 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);
14421449 }
14431450
14441451 if (calculatedOctCode) {
@@ -1986,9 +1993,10 @@ void Application::updateAvatar(float deltaTime) { · 541 unmodified lines
19861993 endOfBroadcastStringWrite += packNodeId(endOfBroadcastStringWrite, nodeList->getOwnerID());
19871994
19881995 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));
19922000
19932001 // once in a while, send my voxel url
19942002 const float AVATAR_VOXEL_URL_SEND_INTERVAL = 1.0f; // seconds

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t