History

Merge remote-tracking branch 'upstream/master' into menu

Stephen Birarda committed 13 years ago

Commit 44320322 parents 811fc87 ace9da523 files · +840 −257Browse files

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

Unified · Split

interface/src/Application.cpp+43−160
@@ -114,8 +114,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 113 unmodified lines
114114 _justEditedVoxel(false),
115115 _isLookingAtOtherAvatar(false),
116116 _lookatIndicatorScale(1.0f),
117− _paintOn(false),
118− _dominantColor(0),
119117 _perfStatsOn(false),
120118 _chatEntryOn(false),
121119 _oculusTextureID(0),
@@ -125,7 +123,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 3 unmodified lines
125123 _audio(&_audioScope, STARTUP_JITTER_SAMPLES),
126124 #endif
127125 _stopNetworkReceiveThread(false),
128− _stopProcessVoxelsThread(false),
126+ _voxelProcessor(this),
127+ _voxelEditSender(this),
129128 _packetCount(0),
130129 _packetsPerSecond(0),
131130 _bytesPerSecond(0),
@@ -278,9 +277,10 @@ void Application::initializeGL() { · 146 unmodified lines
278277 }
279278
280279 // create thread for parsing of voxel data independent of the main network and rendering threads
280+ _voxelProcessor.initialize(_enableProcessVoxelsThread);
281+ _voxelEditSender.initialize(_enableProcessVoxelsThread);
281282 if (_enableProcessVoxelsThread) {
282− pthread_create(&_processVoxelsThread, NULL, processVoxels, NULL);
283− qDebug("Voxel parsing thread created.\n");
283+ qDebug("Voxel parsing thread created.\n");
284284 }
285285
286286 // call terminate before exiting
@@ -319,7 +319,7 @@ void Application::paintGL() { · 32 unmodified lines
319319 PerfStat("display");
320320
321321 glEnable(GL_LINE_SMOOTH);
322−
322+
323323 if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
324324 _myCamera.setTightness (100.0f);
325325 _myCamera.setTargetPosition(_myAvatar.getUprightHeadPosition());
@@ -451,27 +451,20 @@ void Application::controlledBroadcastToNodes(unsigned char* broadcastData, size_ · 125 unmodified lines
451451 // Feed number of bytes to corresponding channel of the bandwidth meter, if any (done otherwise)
452452 BandwidthMeter::ChannelIndex channel;
453453 switch (nodeTypes[i]) {
454− case NODE_TYPE_AGENT:
455− case NODE_TYPE_AVATAR_MIXER:
456− channel = BandwidthMeter::AVATARS;
457− break;
458− case NODE_TYPE_VOXEL_SERVER:
459− channel = BandwidthMeter::VOXELS;
460− break;
461− default:
462− continue;
454+ case NODE_TYPE_AGENT:
455+ case NODE_TYPE_AVATAR_MIXER:
456+ channel = BandwidthMeter::AVATARS;
457+ break;
458+ case NODE_TYPE_VOXEL_SERVER:
459+ channel = BandwidthMeter::VOXELS;
460+ break;
461+ default:
462+ continue;
463463 }
464464 self->_bandwidthMeter.outputStream(channel).updateValue(nReceivingNodes * dataBytes);
465465 }
466466 }
467467
468−void Application::sendVoxelServerAddScene() {
469− char message[100];
470− sprintf(message,"%c%s",'Z',"add scene");
471− int messageSize = strlen(message) + 1;
472− controlledBroadcastToNodes((unsigned char*)message, messageSize, & NODE_TYPE_VOXEL_SERVER, 1);
473−}
474−
475468 void Application::keyPressEvent(QKeyEvent* event) {
476469 if (activeWindow() == _window) {
477470 if (_chatEntryOn) {
@@ -1056,10 +1049,8 @@ void Application::terminate() { · 578 unmodified lines
10561049 pthread_join(_networkReceiveThread, NULL);
10571050 }
10581051
1059− if (_enableProcessVoxelsThread) {
1060− _stopProcessVoxelsThread = true;
1061− pthread_join(_processVoxelsThread, NULL);
1062− }
1052+ _voxelProcessor.terminate();
1053+ _voxelEditSender.terminate();
10631054 }
10641055
10651056 static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& dataBytes) {
@@ -1251,12 +1242,7 @@ void Application::resetSwatchColors() { · 185 unmodified lines
12511242
12521243 const int MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE = 1500;
12531244 struct SendVoxelsOperationArgs {
1254− unsigned char* newBaseOctCode;
1255− unsigned char messageBuffer[MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE];
1256− int bufferInUse;
1257− uint64_t lastSendTime;
1258− int packetsSent;
1259− uint64_t bytesSent;
1245+ unsigned char* newBaseOctCode;
12601246 };
12611247
12621248 bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) {
@@ -1287,38 +1273,11 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 24 unmodified lines
12871273 codeColorBuffer[bytesInCode + RED_INDEX ] = node->getColor()[RED_INDEX ];
12881274 codeColorBuffer[bytesInCode + GREEN_INDEX] = node->getColor()[GREEN_INDEX];
12891275 codeColorBuffer[bytesInCode + BLUE_INDEX ] = node->getColor()[BLUE_INDEX ];
1290−
1291− // if we have room don't have room in the buffer, then send the previously generated message first
1292− if (args->bufferInUse + codeAndColorLength > MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE) {
1293−
1294− args->packetsSent++;
1295− args->bytesSent += args->bufferInUse;
12961276
1297− controlledBroadcastToNodes(args->messageBuffer, args->bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
1298− args->bufferInUse = numBytesForPacketHeader((unsigned char*) &PACKET_TYPE_SET_VOXEL_DESTRUCTIVE)
1299− + sizeof(unsigned short int); // reset
1300−
1301− uint64_t now = usecTimestampNow();
1302− // dynamically sleep until we need to fire off the next set of voxels
1303− uint64_t elapsed = now - args->lastSendTime;
1304− int usecToSleep = CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS - elapsed;
1305− if (usecToSleep > 0) {
1306− //qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, sleeping for %d usecs!\n",
1307− // args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed, usecToSleep);
1308−
1309− Application::getInstance()->timer();
1310−
1311− usleep(usecToSleep);
1312− } else {
1313− //qDebug("sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, no need to sleep!\n",
1314− // args->packetsSent, (long long int)args->bytesSent, (long long int)elapsed);
1315− }
1316− args->lastSendTime = now;
1317− }
1277+ getInstance()->_voxelEditSender.queueVoxelEditMessage(PACKET_TYPE_SET_VOXEL_DESTRUCTIVE,
1278+ codeColorBuffer, codeAndColorLength);
13181279
1319− // copy this node's code color details into our buffer.
1320− memcpy(&args->messageBuffer[args->bufferInUse], codeColorBuffer, codeAndColorLength);
1321− args->bufferInUse += codeAndColorLength;
1280+ delete[] codeColorBuffer;
13221281 }
13231282 return true; // keep going
13241283 }
@@ -1500,15 +1459,6 @@ void Application::importVoxels() { · 175 unmodified lines
15001459 // the server as an set voxel message, this will also rebase the voxels to the new location
15011460 unsigned char* calculatedOctCode = NULL;
15021461 SendVoxelsOperationArgs args;
1503− args.lastSendTime = usecTimestampNow();
1504− args.packetsSent = 0;
1505− args.bytesSent = 0;
1506−
1507− int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
1508−
1509− unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader];
1510− *sequenceAt = 0;
1511− args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence
15121462
15131463 // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
15141464 // voxel size/position details.
@@ -1522,31 +1472,8 @@ void Application::importVoxels() { · 7 unmodified lines
15221472
15231473 // send the insert/paste of these voxels
15241474 importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args);
1475+ _voxelEditSender.flushQueue();
15251476
1526− // If we have voxels left in the packet, then send the packet
1527− if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) {
1528− controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
1529−
1530−
1531− args.packetsSent++;
1532− args.bytesSent += args.bufferInUse;
1533−
1534− uint64_t now = usecTimestampNow();
1535− // dynamically sleep until we need to fire off the next set of voxels
1536− uint64_t elapsed = now - args.lastSendTime;
1537− int usecToSleep = CLIENT_TO_SERVER_VOXEL_SEND_INTERVAL_USECS - elapsed;
1538−
1539− if (usecToSleep > 0) {
1540− //qDebug("after sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, sleeping for %d usecs!\n",
1541− // args.packetsSent, (long long int)args.bytesSent, (long long int)elapsed, usecToSleep);
1542− usleep(usecToSleep);
1543− } else {
1544− //qDebug("after sendVoxelsOperation: packet: %d bytes:%lld elapsed %lld usecs, no need to sleep!\n",
1545− // args.packetsSent, (long long int)args.bytesSent, (long long int)elapsed);
1546− }
1547− args.lastSendTime = now;
1548− }
1549−
15501477 if (calculatedOctCode) {
15511478 delete[] calculatedOctCode;
15521479 }
@@ -1580,15 +1507,6 @@ void Application::pasteVoxels() { · 27 unmodified lines
15801507 // Recurse the clipboard tree, where everything is root relative, and send all the colored voxels to
15811508 // the server as an set voxel message, this will also rebase the voxels to the new location
15821509 SendVoxelsOperationArgs args;
1583− args.lastSendTime = usecTimestampNow();
1584− args.packetsSent = 0;
1585− args.bytesSent = 0;
1586−
1587− int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
1588−
1589− unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader];
1590− *sequenceAt = 0;
1591− args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence
15921510
15931511 // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
15941512 // voxel size/position details. If we don't have an actual selectedNode then use the mouseVoxel to create a
@@ -1600,14 +1518,7 @@ void Application::pasteVoxels() { · 5 unmodified lines
16001518 }
16011519
16021520 _clipboardTree.recurseTreeWithOperation(sendVoxelsOperation, &args);
1603−
1604− // If we have voxels left in the packet, then send the packet
1605− if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) {
1606− controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
1607− qDebug("sending packet: %d\n", ++args.packetsSent);
1608− args.bytesSent += args.bufferInUse;
1609− qDebug("total bytes sent: %lld\n", (long long int)args.bytesSent);
1610− }
1521+ _voxelEditSender.flushQueue();
16111522
16121523 if (calculatedOctCode) {
16131524 delete[] calculatedOctCode;
@@ -1654,7 +1565,7 @@ void Application::init() { · 40 unmodified lines
16541565 _voxels.init();
16551566
16561567 _environment.init();
1657−
1568+
16581569 _glowEffect.init();
16591570
16601571 _handControl.setScreenDimensions(_glWidget->width(), _glWidget->height());
@@ -2025,7 +1936,8 @@ void Application::update(float deltaTime) { · 364 unmodified lines
20251936
20261937 // parse voxel packets
20271938 if (!_enableProcessVoxelsThread) {
2028− processVoxels(0);
1939+ _voxelProcessor.threadRoutine();
1940+ _voxelEditSender.threadRoutine();
20291941 }
20301942
20311943 //loop through all the other avatars and simulate them...
@@ -2725,15 +2637,6 @@ void Application::displayOverlay() { · 693 unmodified lines
27252637 sprintf(nodes, "Servers: %d, Avatars: %d\n", totalServers, totalAvatars);
27262638 drawtext(_glWidget->width() - 150, 20, 0.10, 0, 1.0, 0, nodes, 1, 0, 0);
27272639
2728− if (_paintOn) {
2729−
2730− char paintMessage[100];
2731− sprintf(paintMessage,"Painting (%.3f,%.3f,%.3f/%.3f/%d,%d,%d)",
2732− _paintingVoxel.x, _paintingVoxel.y, _paintingVoxel.z, _paintingVoxel.s,
2733− (unsigned int)_paintingVoxel.red, (unsigned int)_paintingVoxel.green, (unsigned int)_paintingVoxel.blue);
2734− drawtext(_glWidget->width() - 350, 50, 0.10, 0, 1.0, 0, paintMessage, 1, 1, 0);
2735− }
2736−
27372640 // render the webcam input frame
27382641 _webcam.renderPreview(_glWidget->width(), _glWidget->height());
27392642
@@ -3199,26 +3102,6 @@ void Application::renderViewFrustum(ViewFrustum& viewFrustum) { · 459 unmodified lines
31993102 }
32003103 }
32013104
3202−void Application::setupPaintingVoxel() {
3203− glm::vec3 avatarPos = _myAvatar.getPosition();
3204−
3205− _paintingVoxel.x = avatarPos.z/-10.0; // voxel space x is negative z head space
3206− _paintingVoxel.y = avatarPos.y/-10.0; // voxel space y is negative y head space
3207− _paintingVoxel.z = avatarPos.x/-10.0; // voxel space z is negative x head space
3208− _paintingVoxel.s = 1.0/256;
3209−
3210− shiftPaintingColor();
3211−}
3212−
3213−void Application::shiftPaintingColor() {
3214− // About the color of the paintbrush... first determine the dominant color
3215− _dominantColor = (_dominantColor + 1) % 3; // 0=red,1=green,2=blue
3216− _paintingVoxel.red = (_dominantColor == 0) ? randIntInRange(200, 255) : randIntInRange(40, 100);
3217− _paintingVoxel.green = (_dominantColor == 1) ? randIntInRange(200, 255) : randIntInRange(40, 100);
3218− _paintingVoxel.blue = (_dominantColor == 2) ? randIntInRange(200, 255) : randIntInRange(40, 100);
3219−}
3220−
3221−
32223105 void Application::injectVoxelAddedSoundEffect() {
32233106 AudioInjector* voxelInjector = AudioInjectionManager::injectorWithCapacity(11025);
32243107
@@ -3329,7 +3212,7 @@ bool Application::maybeEditVoxelUnderCursor() { · 104 unmodified lines
33293212 void Application::deleteVoxelUnderCursor() {
33303213 if (_mouseVoxel.s != 0) {
33313214 // sending delete to the server is sufficient, server will send new version so we see updates soon enough
3332− sendVoxelEditMessage(PACKET_TYPE_ERASE_VOXEL, _mouseVoxel);
3215+ _voxelEditSender.sendVoxelEditMessage(PACKET_TYPE_ERASE_VOXEL, _mouseVoxel);
33333216 AudioInjector* voxelInjector = AudioInjectionManager::injectorWithCapacity(5000);
33343217
33353218 if (voxelInjector) {
@@ -3433,15 +3316,16 @@ void Application::nodeKilled(Node* node) { · 97 unmodified lines
34333316 uint16_t nodeID = node->getNodeID();
34343317 // see if this is the first we've heard of this node...
34353318 if (_voxelServerJurisdictions.find(nodeID) != _voxelServerJurisdictions.end()) {
3436− VoxelPositionSize jurisditionDetails;
3437− jurisditionDetails = _voxelServerJurisdictions[nodeID];
3319+ unsigned char* rootCode = _voxelServerJurisdictions[nodeID].getRootOctalCode();
3320+ VoxelPositionSize rootDetails;
3321+ voxelDetailsForCode(rootCode, rootDetails);
34383322
34393323 printf("voxel server going away...... v[%f, %f, %f, %f]\n",
3440− jurisditionDetails.x, jurisditionDetails.y, jurisditionDetails.z, jurisditionDetails.s);
3324+ rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s);
34413325
34423326 // Add the jurisditionDetails object to the list of "fade outs"
34433327 VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE);
3444− fade.voxelDetails = jurisditionDetails;
3328+ fade.voxelDetails = rootDetails;
34453329 const float slightly_smaller = 0.99;
34463330 fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;
34473331 _voxelFades.push_back(fade);
@@ -3462,23 +3346,28 @@ int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLeng · 14 unmodified lines
34623346 if (voxelServer) {
34633347 uint16_t nodeID = voxelServer->getNodeID();
34643348
3465− VoxelPositionSize jurisditionDetails;
3466− voxelDetailsForCode(_voxelSceneStats.getJurisdictionRoot(), jurisditionDetails);
3349+ VoxelPositionSize rootDetails;
3350+ voxelDetailsForCode(_voxelSceneStats.getJurisdictionRoot(), rootDetails);
34673351
34683352 // see if this is the first we've heard of this node...
34693353 if (_voxelServerJurisdictions.find(nodeID) == _voxelServerJurisdictions.end()) {
34703354 printf("stats from new voxel server... v[%f, %f, %f, %f]\n",
3471− jurisditionDetails.x, jurisditionDetails.y, jurisditionDetails.z, jurisditionDetails.s);
3355+ rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s);
34723356
34733357 // Add the jurisditionDetails object to the list of "fade outs"
34743358 VoxelFade fade(VoxelFade::FADE_OUT, NODE_ADDED_RED, NODE_ADDED_GREEN, NODE_ADDED_BLUE);
3475− fade.voxelDetails = jurisditionDetails;
3359+ fade.voxelDetails = rootDetails;
34763360 const float slightly_smaller = 0.99;
34773361 fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;
34783362 _voxelFades.push_back(fade);
34793363 }
34803364 // store jurisdiction details for later use
3481− _voxelServerJurisdictions[nodeID] = jurisditionDetails;
3365+ // This is bit of fiddling is because JurisdictionMap assumes it is the owner of the values used to construct it
3366+ // but VoxelSceneStats thinks it's just returning a reference to it's contents. So we need to make a copy of the
3367+ // details from the VoxelSceneStats to construct the JurisdictionMap
3368+ JurisdictionMap jurisdictionMap;
3369+ jurisdictionMap.copyContents(_voxelSceneStats.getJurisdictionRoot(), _voxelSceneStats.getJurisdictionEndNodes());
3370+ _voxelServerJurisdictions[nodeID] = jurisdictionMap;
34823371 }
34833372 return statsMessageLength;
34843373 }
@@ -3563,12 +3452,6 @@ void* Application::networkReceive(void* args) { · 78 unmodified lines
35633452
35643453 Application* app = Application::getInstance();
35653454 while (!app->_stopNetworkReceiveThread) {
3566− // check to see if the UI thread asked us to kill the voxel tree. since we're the only thread allowed to do that
3567− if (app->_wantToKillLocalVoxels) {
3568− app->_voxels.killLocalVoxels();
3569− app->_wantToKillLocalVoxels = false;
3570− }
3571−
35723455 if (NodeList::getInstance()->getNodeSocket()->receive(&senderAddress, app->_incomingPacket, &bytesReceived)) {
35733456
35743457 app->_packetCount++;
@@ -3592,7 +3475,7 @@ void* Application::networkReceive(void* args) { · 17 unmodified lines
35923475 case PACKET_TYPE_VOXEL_STATS:
35933476 case PACKET_TYPE_ENVIRONMENT_DATA: {
35943477 // add this packet to our list of voxel packets and process them on the voxel processing
3595− app->queueVoxelPacket(senderAddress, app->_incomingPacket, bytesReceived);
3478+ app->_voxelProcessor.queuePacket(senderAddress, app->_incomingPacket, bytesReceived);
35963479 break;
35973480 }
35983481 case PACKET_TYPE_BULK_AVATAR_DATA:

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