History

Merge branch 'master' of https://github.com/worklist/hifi into occlusion_culling

ZappoMan committed 13 years ago

Commit c26e3972 parents 241bd7c 717518633 files · +485 −336Browse files

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

Unified · Split

interface/src/Application.cpp+108−59
@@ -251,7 +251,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 250 unmodified lines
251251
252252 // start the nodeList threads
253253 NodeList::getInstance()->startSilentNodeRemovalThread();
254− NodeList::getInstance()->startPingUnknownNodesThread();
255254
256255 _window->setCentralWidget(_glWidget);
257256
@@ -905,14 +904,15 @@ void Application::wheelEvent(QWheelEvent* event) { · 647 unmodified lines
905904
906905 void Application::sendPingPackets() {
907906
908− char nodeTypesOfInterest[] = {NODE_TYPE_VOXEL_SERVER, NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER};
907+ const char nodesToPing[] = {NODE_TYPE_VOXEL_SERVER, NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER};
908+
909909 uint64_t currentTime = usecTimestampNow();
910− unsigned char pingPacket[1 + sizeof(currentTime)];
911− pingPacket[0] = PACKET_HEADER_PING;
910+ unsigned char pingPacket[numBytesForPacketHeader((unsigned char*) &PACKET_TYPE_PING) + sizeof(currentTime)];
911+ int numHeaderBytes = populateTypeAndVersion(pingPacket, PACKET_TYPE_PING);
912912
913− memcpy(&pingPacket[1], &currentTime, sizeof(currentTime));
914− getInstance()->controlledBroadcastToNodes(pingPacket, 1 + sizeof(currentTime),
915− nodeTypesOfInterest, sizeof(nodeTypesOfInterest));
913+ memcpy(pingPacket + numHeaderBytes, &currentTime, sizeof(currentTime));
914+ getInstance()->controlledBroadcastToNodes(pingPacket, sizeof(pingPacket),
915+ nodesToPing, sizeof(nodesToPing));
916916 }
917917
918918 // Every second, check the frame rates and other stuff
@@ -1020,7 +1020,11 @@ void Application::sendAvatarVoxelURLMessage(const QUrl& url) { · 101 unmodified lines
10201020 return; // we don't yet know who we are
10211021 }
10221022 QByteArray message;
1023− message.append(PACKET_HEADER_AVATAR_VOXEL_URL);
1023+
1024+ char packetHeader[MAX_PACKET_HEADER_BYTES];
1025+ int numBytesPacketHeader = populateTypeAndVersion((unsigned char*) packetHeader, PACKET_TYPE_AVATAR_VOXEL_URL);
1026+
1027+ message.append(packetHeader, numBytesPacketHeader);
10241028 message.append((const char*)&ownerID, sizeof(ownerID));
10251029 message.append(url.toEncoded());
10261030
@@ -1029,8 +1033,9 @@ void Application::sendAvatarVoxelURLMessage(const QUrl& url) { · 2 unmodified lines
10291033
10301034 void Application::processAvatarVoxelURLMessage(unsigned char *packetData, size_t dataBytes) {
10311035 // skip the header
1032− packetData++;
1033− dataBytes--;
1036+ int numBytesPacketHeader = numBytesForPacketHeader(packetData);
1037+ packetData += numBytesPacketHeader;
1038+ dataBytes -= numBytesPacketHeader;
10341039
10351040 // read the node id
10361041 uint16_t nodeID = *(uint16_t*)packetData;
@@ -1256,11 +1261,11 @@ void Application::updateVoxelModeActions() { · 219 unmodified lines
12561261 }
12571262 }
12581263
1259−void Application::sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail) {
1264+void Application::sendVoxelEditMessage(PACKET_TYPE type, VoxelDetail& detail) {
12601265 unsigned char* bufferOut;
12611266 int sizeOut;
12621267
1263− if (createVoxelEditMessage(header, 0, 1, &detail, bufferOut, sizeOut)){
1268+ if (createVoxelEditMessage(type, 0, 1, &detail, bufferOut, sizeOut)){
12641269 Application::controlledBroadcastToNodes(bufferOut, sizeOut, & NODE_TYPE_VOXEL_SERVER, 1);
12651270 delete[] bufferOut;
12661271 }
@@ -1347,7 +1352,8 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 80 unmodified lines
13471352 // if we have room don't have room in the buffer, then send the previously generated message first
13481353 if (args->bufferInUse + codeAndColorLength > MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE) {
13491354 controlledBroadcastToNodes(args->messageBuffer, args->bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
1350− args->bufferInUse = sizeof(PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int); // reset
1355+ args->bufferInUse = numBytesForPacketHeader((unsigned char*) &PACKET_TYPE_SET_VOXEL_DESTRUCTIVE)
1356+ + sizeof(unsigned short int); // reset
13511357 }
13521358
13531359 // copy this node's code color details into our buffer.
@@ -1414,10 +1420,12 @@ void Application::importVoxels() { · 60 unmodified lines
14141420 // the server as an set voxel message, this will also rebase the voxels to the new location
14151421 unsigned char* calculatedOctCode = NULL;
14161422 SendVoxelsOperationArgs args;
1417− args.messageBuffer[0] = PACKET_HEADER_SET_VOXEL_DESTRUCTIVE;
1418− unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[sizeof(PACKET_HEADER_SET_VOXEL_DESTRUCTIVE)];
1423+
1424+ int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
1425+
1426+ unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader];
14191427 *sequenceAt = 0;
1420− args.bufferInUse = sizeof(PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int); // set to command + sequence
1428+ args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence
14211429
14221430 // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
14231431 // voxel size/position details.
@@ -1430,7 +1438,7 @@ void Application::importVoxels() { · 6 unmodified lines
14301438 importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args);
14311439
14321440 // If we have voxels left in the packet, then send the packet
1433− if (args.bufferInUse > (sizeof(PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int))) {
1441+ if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) {
14341442 controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
14351443 }
14361444
@@ -1465,10 +1473,12 @@ void Application::pasteVoxels() { · 28 unmodified lines
14651473 // Recurse the clipboard tree, where everything is root relative, and send all the colored voxels to
14661474 // the server as an set voxel message, this will also rebase the voxels to the new location
14671475 SendVoxelsOperationArgs args;
1468− args.messageBuffer[0] = PACKET_HEADER_SET_VOXEL_DESTRUCTIVE;
1469− unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[sizeof(PACKET_HEADER_SET_VOXEL_DESTRUCTIVE)];
1476+
1477+ int numBytesPacketHeader = populateTypeAndVersion(args.messageBuffer, PACKET_TYPE_SET_VOXEL_DESTRUCTIVE);
1478+
1479+ unsigned short int* sequenceAt = (unsigned short int*)&args.messageBuffer[numBytesPacketHeader];
14701480 *sequenceAt = 0;
1471− args.bufferInUse = sizeof(PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int); // set to command + sequence
1481+ args.bufferInUse = numBytesPacketHeader + sizeof(unsigned short int); // set to command + sequence
14721482
14731483 // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the
14741484 // voxel size/position details. If we don't have an actual selectedNode then use the mouseVoxel to create a
@@ -1482,7 +1492,7 @@ void Application::pasteVoxels() { · 7 unmodified lines
14821492 _clipboardTree.recurseTreeWithOperation(sendVoxelsOperation, &args);
14831493
14841494 // If we have voxels left in the packet, then send the packet
1485− if (args.bufferInUse > (sizeof(PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) + sizeof(unsigned short int))) {
1495+ if (args.bufferInUse > (numBytesPacketHeader + sizeof(unsigned short int))) {
14861496 controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1);
14871497 }
14881498
@@ -1740,6 +1750,22 @@ void Application::init() { · 251 unmodified lines
17401750
17411751 const float MAX_AVATAR_EDIT_VELOCITY = 1.0f;
17421752 const float MAX_VOXEL_EDIT_DISTANCE = 20.0f;
1753+const float HEAD_SPHERE_RADIUS = 0.07;
1754+
1755+bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, glm::vec3& eyePosition) {
1756+ NodeList* nodeList = NodeList::getInstance();
1757+ for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
1758+ if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
1759+ Avatar* avatar = (Avatar *) node->getLinkedData();
1760+ glm::vec3 headPosition = avatar->getHead().getPosition();
1761+ if (rayIntersectsSphere(mouseRayOrigin, mouseRayDirection, headPosition, HEAD_SPHERE_RADIUS)) {
1762+ eyePosition = avatar->getHead().getEyeLevelPosition();
1763+ return true;
1764+ }
1765+ }
1766+ }
1767+ return false;
1768+}
17431769
17441770 void Application::update(float deltaTime) {
17451771 // Use Transmitter Hand to move hand if connected, else use mouse
@@ -1767,8 +1793,15 @@ void Application::update(float deltaTime) { · 21 unmodified lines
17671793 _myAvatar.setMouseRay(mouseRayOrigin, mouseRayDirection);
17681794
17691795 // Set where I am looking based on my mouse ray (so that other people can see)
1770− glm::vec3 myLookAtFromMouse(mouseRayOrigin + mouseRayDirection);
1771− _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
1796+ glm::vec3 eyePosition;
1797+ if (isLookingAtOtherAvatar(mouseRayOrigin, mouseRayDirection, eyePosition)) {
1798+ // If the mouse is over another avatar's head...
1799+ glm::vec3 myLookAtFromMouse(eyePosition);
1800+ _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
1801+ } else {
1802+ glm::vec3 myLookAtFromMouse(mouseRayOrigin + mouseRayDirection);
1803+ _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
1804+ }
17721805
17731806 // If we are dragging on a voxel, add thrust according to the amount the mouse is dragging
17741807 const float VOXEL_GRAB_THRUST = 0.0f;
@@ -2004,6 +2037,18 @@ void Application::updateAvatar(float deltaTime) { · 229 unmodified lines
20042037 _headMouseY = max(_headMouseY, 0);
20052038 _headMouseY = min(_headMouseY, _glWidget->height());
20062039
2040+ const float MIDPOINT_OF_SCREEN = 0.5;
2041+
2042+ // Set lookAtPosition if an avatar is at the center of the screen
2043+ glm::vec3 screenCenterRayOrigin, screenCenterRayDirection;
2044+ _viewFrustum.computePickRay(MIDPOINT_OF_SCREEN, MIDPOINT_OF_SCREEN, screenCenterRayOrigin, screenCenterRayDirection);
2045+
2046+ glm::vec3 eyePosition;
2047+ if (isLookingAtOtherAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition)) {
2048+ glm::vec3 myLookAtFromMouse(eyePosition);
2049+ _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
2050+ }
2051+
20072052 }
20082053
20092054 if (OculusManager::isConnected()) {
@@ -2040,7 +2085,8 @@ void Application::updateAvatar(float deltaTime) { · 30 unmodified lines
20402085 unsigned char broadcastString[200];
20412086 unsigned char* endOfBroadcastStringWrite = broadcastString;
20422087
2043− *(endOfBroadcastStringWrite++) = PACKET_HEADER_HEAD_DATA;
2088+ endOfBroadcastStringWrite += populateTypeAndVersion(endOfBroadcastStringWrite, PACKET_TYPE_HEAD_DATA);
2089+
20442090 endOfBroadcastStringWrite += packNodeId(endOfBroadcastStringWrite, nodeList->getOwnerID());
20452091
20462092 endOfBroadcastStringWrite += _myAvatar.getBroadcastData(endOfBroadcastStringWrite);
@@ -2070,8 +2116,8 @@ void Application::updateAvatar(float deltaTime) { · 23 unmodified lines
20702116 _paintingVoxel.y >= 0.0 && _paintingVoxel.y <= 1.0 &&
20712117 _paintingVoxel.z >= 0.0 && _paintingVoxel.z <= 1.0) {
20722118
2073− PACKET_HEADER message = (_destructiveAddVoxel->isChecked() ?
2074− PACKET_HEADER_SET_VOXEL_DESTRUCTIVE : PACKET_HEADER_SET_VOXEL);
2119+ PACKET_TYPE message = (_destructiveAddVoxel->isChecked() ?
2120+ PACKET_TYPE_SET_VOXEL_DESTRUCTIVE : PACKET_TYPE_SET_VOXEL);
20752121 sendVoxelEditMessage(message, _paintingVoxel);
20762122 }
20772123 }
@@ -2953,8 +2999,8 @@ void Application::shiftPaintingColor() { · 875 unmodified lines
29532999 void Application::maybeEditVoxelUnderCursor() {
29543000 if (_addVoxelMode->isChecked() || _colorVoxelMode->isChecked()) {
29553001 if (_mouseVoxel.s != 0) {
2956− PACKET_HEADER message = (_destructiveAddVoxel->isChecked() ?
2957− PACKET_HEADER_SET_VOXEL_DESTRUCTIVE : PACKET_HEADER_SET_VOXEL);
3002+ PACKET_TYPE message = (_destructiveAddVoxel->isChecked() ?
3003+ PACKET_TYPE_SET_VOXEL_DESTRUCTIVE : PACKET_TYPE_SET_VOXEL);
29583004 sendVoxelEditMessage(message, _mouseVoxel);
29593005
29603006 // create the voxel locally so it appears immediately
@@ -3027,7 +3073,7 @@ void Application::maybeEditVoxelUnderCursor() { · 66 unmodified lines
30273073 void Application::deleteVoxelUnderCursor() {
30283074 if (_mouseVoxel.s != 0) {
30293075 // sending delete to the server is sufficient, server will send new version so we see updates soon enough
3030− sendVoxelEditMessage(PACKET_HEADER_ERASE_VOXEL, _mouseVoxel);
3076+ sendVoxelEditMessage(PACKET_TYPE_ERASE_VOXEL, _mouseVoxel);
30313077 AudioInjector* voxelInjector = AudioInjectionManager::injectorWithCapacity(5000);
30323078 voxelInjector->setPosition(glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z));
30333079 // voxelInjector->setBearing(0); //straight down the z axis
@@ -3137,36 +3183,39 @@ void* Application::networkReceive(void* args) { · 103 unmodified lines
31373183 app->_packetCount++;
31383184 app->_bytesCount += bytesReceived;
31393185
3140− switch (app->_incomingPacket[0]) {
3141− case PACKET_HEADER_TRANSMITTER_DATA_V2:
3142− // V2 = IOS transmitter app
3143− app->_myTransmitter.processIncomingData(app->_incomingPacket, bytesReceived);
3144−
3145− break;
3146− case PACKET_HEADER_MIXED_AUDIO:
3147− app->_audio.addReceivedAudioToBuffer(app->_incomingPacket, bytesReceived);
3148− break;
3149− case PACKET_HEADER_VOXEL_DATA:
3150− case PACKET_HEADER_VOXEL_DATA_MONOCHROME:
3151− case PACKET_HEADER_Z_COMMAND:
3152− case PACKET_HEADER_ERASE_VOXEL:
3153− app->_voxels.parseData(app->_incomingPacket, bytesReceived);
3154− break;
3155− case PACKET_HEADER_ENVIRONMENT_DATA:
3156− app->_environment.parseData(&senderAddress, app->_incomingPacket, bytesReceived);
3157− break;
3158− case PACKET_HEADER_BULK_AVATAR_DATA:
3159− NodeList::getInstance()->processBulkNodeData(&senderAddress,
3160− app->_incomingPacket,
3161− bytesReceived);
3162− getInstance()->_bandwidthMeter.inputStream(BandwidthMeter::AVATARS).updateValue(bytesReceived);
3163− break;
3164− case PACKET_HEADER_AVATAR_VOXEL_URL:
3165− processAvatarVoxelURLMessage(app->_incomingPacket, bytesReceived);
3166− break;
3167− default:
3168− NodeList::getInstance()->processNodeData(&senderAddress, app->_incomingPacket, bytesReceived);
3169− break;
3186+ if (packetVersionMatch(app->_incomingPacket)) {
3187+ // only process this packet if we have a match on the packet version
3188+ switch (app->_incomingPacket[0]) {
3189+ case PACKET_TYPE_TRANSMITTER_DATA_V2:
3190+ // V2 = IOS transmitter app
3191+ app->_myTransmitter.processIncomingData(app->_incomingPacket, bytesReceived);
3192+
3193+ break;
3194+ case PACKET_TYPE_MIXED_AUDIO:
3195+ app->_audio.addReceivedAudioToBuffer(app->_incomingPacket, bytesReceived);
3196+ break;
3197+ case PACKET_TYPE_VOXEL_DATA:
3198+ case PACKET_TYPE_VOXEL_DATA_MONOCHROME:
3199+ case PACKET_TYPE_Z_COMMAND:
3200+ case PACKET_TYPE_ERASE_VOXEL:
3201+ app->_voxels.parseData(app->_incomingPacket, bytesReceived);
3202+ break;
3203+ case PACKET_TYPE_ENVIRONMENT_DATA:
3204+ app->_environment.parseData(&senderAddress, app->_incomingPacket, bytesReceived);
3205+ break;
3206+ case PACKET_TYPE_BULK_AVATAR_DATA:
3207+ NodeList::getInstance()->processBulkNodeData(&senderAddress,
3208+ app->_incomingPacket,
3209+ bytesReceived);
3210+ getInstance()->_bandwidthMeter.inputStream(BandwidthMeter::AVATARS).updateValue(bytesReceived);
3211+ break;
3212+ case PACKET_TYPE_AVATAR_VOXEL_URL:
3213+ processAvatarVoxelURLMessage(app->_incomingPacket, bytesReceived);
3214+ break;
3215+ default:
3216+ NodeList::getInstance()->processNodeData(&senderAddress, app->_incomingPacket, bytesReceived);
3217+ break;
3218+ }
31703219 }
31713220 } else if (!app->_enableNetworkThread) {
31723221 break;

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