Showing the changes to interface/src/Application.cpp (1 of 33 files). Show all
Unified · Split
| @@ -251,7 +251,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 250 unmodified lines | ||
| 251 | 251 | |
| 252 | 252 | // start the nodeList threads |
| 253 | 253 | NodeList::getInstance()->startSilentNodeRemovalThread(); |
| 254 | − NodeList::getInstance()->startPingUnknownNodesThread(); | |
| 255 | 254 | |
| 256 | 255 | _window->setCentralWidget(_glWidget); |
| 257 | 256 | |
| @@ -905,14 +904,15 @@ void Application::wheelEvent(QWheelEvent* event) { · 647 unmodified lines | ||
| 905 | 904 | |
| 906 | 905 | void Application::sendPingPackets() { |
| 907 | 906 | |
| 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 | + | |
| 909 | 909 | 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); | |
| 912 | 912 | |
| 913 | − memcpy(&pingPacket[1], ¤tTime, sizeof(currentTime)); | |
| 914 | − getInstance()->controlledBroadcastToNodes(pingPacket, 1 + sizeof(currentTime), | |
| 915 | − nodeTypesOfInterest, sizeof(nodeTypesOfInterest)); | |
| 913 | + memcpy(pingPacket + numHeaderBytes, ¤tTime, sizeof(currentTime)); | |
| 914 | + getInstance()->controlledBroadcastToNodes(pingPacket, sizeof(pingPacket), | |
| 915 | + nodesToPing, sizeof(nodesToPing)); | |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | // Every second, check the frame rates and other stuff |
| @@ -1020,7 +1020,11 @@ void Application::sendAvatarVoxelURLMessage(const QUrl& url) { · 101 unmodified lines | ||
| 1020 | 1020 | return; // we don't yet know who we are |
| 1021 | 1021 | } |
| 1022 | 1022 | 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); | |
| 1024 | 1028 | message.append((const char*)&ownerID, sizeof(ownerID)); |
| 1025 | 1029 | message.append(url.toEncoded()); |
| 1026 | 1030 | |
| @@ -1029,8 +1033,9 @@ void Application::sendAvatarVoxelURLMessage(const QUrl& url) { · 2 unmodified lines | ||
| 1029 | 1033 | |
| 1030 | 1034 | void Application::processAvatarVoxelURLMessage(unsigned char *packetData, size_t dataBytes) { |
| 1031 | 1035 | // skip the header |
| 1032 | − packetData++; | |
| 1033 | − dataBytes--; | |
| 1036 | + int numBytesPacketHeader = numBytesForPacketHeader(packetData); | |
| 1037 | + packetData += numBytesPacketHeader; | |
| 1038 | + dataBytes -= numBytesPacketHeader; | |
| 1034 | 1039 | |
| 1035 | 1040 | // read the node id |
| 1036 | 1041 | uint16_t nodeID = *(uint16_t*)packetData; |
| @@ -1256,11 +1261,11 @@ void Application::updateVoxelModeActions() { · 219 unmodified lines | ||
| 1256 | 1261 | } |
| 1257 | 1262 | } |
| 1258 | 1263 | |
| 1259 | −void Application::sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail) { | |
| 1264 | +void Application::sendVoxelEditMessage(PACKET_TYPE type, VoxelDetail& detail) { | |
| 1260 | 1265 | unsigned char* bufferOut; |
| 1261 | 1266 | int sizeOut; |
| 1262 | 1267 | |
| 1263 | − if (createVoxelEditMessage(header, 0, 1, &detail, bufferOut, sizeOut)){ | |
| 1268 | + if (createVoxelEditMessage(type, 0, 1, &detail, bufferOut, sizeOut)){ | |
| 1264 | 1269 | Application::controlledBroadcastToNodes(bufferOut, sizeOut, & NODE_TYPE_VOXEL_SERVER, 1); |
| 1265 | 1270 | delete[] bufferOut; |
| 1266 | 1271 | } |
| @@ -1347,7 +1352,8 @@ bool Application::sendVoxelsOperation(VoxelNode* node, void* extraData) { · 80 unmodified lines | ||
| 1347 | 1352 | // if we have room don't have room in the buffer, then send the previously generated message first |
| 1348 | 1353 | if (args->bufferInUse + codeAndColorLength > MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE) { |
| 1349 | 1354 | 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 | |
| 1351 | 1357 | } |
| 1352 | 1358 | |
| 1353 | 1359 | // copy this node's code color details into our buffer. |
| @@ -1414,10 +1420,12 @@ void Application::importVoxels() { · 60 unmodified lines | ||
| 1414 | 1420 | // the server as an set voxel message, this will also rebase the voxels to the new location |
| 1415 | 1421 | unsigned char* calculatedOctCode = NULL; |
| 1416 | 1422 | 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]; | |
| 1419 | 1427 | *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 | |
| 1421 | 1429 | |
| 1422 | 1430 | // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the |
| 1423 | 1431 | // voxel size/position details. |
| @@ -1430,7 +1438,7 @@ void Application::importVoxels() { · 6 unmodified lines | ||
| 1430 | 1438 | importVoxels.recurseTreeWithOperation(sendVoxelsOperation, &args); |
| 1431 | 1439 | |
| 1432 | 1440 | // 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))) { | |
| 1434 | 1442 | controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1); |
| 1435 | 1443 | } |
| 1436 | 1444 | |
| @@ -1465,10 +1473,12 @@ void Application::pasteVoxels() { · 28 unmodified lines | ||
| 1465 | 1473 | // Recurse the clipboard tree, where everything is root relative, and send all the colored voxels to |
| 1466 | 1474 | // the server as an set voxel message, this will also rebase the voxels to the new location |
| 1467 | 1475 | 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]; | |
| 1470 | 1480 | *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 | |
| 1472 | 1482 | |
| 1473 | 1483 | // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the |
| 1474 | 1484 | // 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 | ||
| 1482 | 1492 | _clipboardTree.recurseTreeWithOperation(sendVoxelsOperation, &args); |
| 1483 | 1493 | |
| 1484 | 1494 | // 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))) { | |
| 1486 | 1496 | controlledBroadcastToNodes(args.messageBuffer, args.bufferInUse, & NODE_TYPE_VOXEL_SERVER, 1); |
| 1487 | 1497 | } |
| 1488 | 1498 | |
| @@ -1740,6 +1750,22 @@ void Application::init() { · 251 unmodified lines | ||
| 1740 | 1750 | |
| 1741 | 1751 | const float MAX_AVATAR_EDIT_VELOCITY = 1.0f; |
| 1742 | 1752 | 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 | +} | |
| 1743 | 1769 | |
| 1744 | 1770 | void Application::update(float deltaTime) { |
| 1745 | 1771 | // Use Transmitter Hand to move hand if connected, else use mouse |
| @@ -1767,8 +1793,15 @@ void Application::update(float deltaTime) { · 21 unmodified lines | ||
| 1767 | 1793 | _myAvatar.setMouseRay(mouseRayOrigin, mouseRayDirection); |
| 1768 | 1794 | |
| 1769 | 1795 | // 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 | + } | |
| 1772 | 1805 | |
| 1773 | 1806 | // If we are dragging on a voxel, add thrust according to the amount the mouse is dragging |
| 1774 | 1807 | const float VOXEL_GRAB_THRUST = 0.0f; |
| @@ -2004,6 +2037,18 @@ void Application::updateAvatar(float deltaTime) { · 229 unmodified lines | ||
| 2004 | 2037 | _headMouseY = max(_headMouseY, 0); |
| 2005 | 2038 | _headMouseY = min(_headMouseY, _glWidget->height()); |
| 2006 | 2039 | |
| 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 | + | |
| 2007 | 2052 | } |
| 2008 | 2053 | |
| 2009 | 2054 | if (OculusManager::isConnected()) { |
| @@ -2040,7 +2085,8 @@ void Application::updateAvatar(float deltaTime) { · 30 unmodified lines | ||
| 2040 | 2085 | unsigned char broadcastString[200]; |
| 2041 | 2086 | unsigned char* endOfBroadcastStringWrite = broadcastString; |
| 2042 | 2087 | |
| 2043 | − *(endOfBroadcastStringWrite++) = PACKET_HEADER_HEAD_DATA; | |
| 2088 | + endOfBroadcastStringWrite += populateTypeAndVersion(endOfBroadcastStringWrite, PACKET_TYPE_HEAD_DATA); | |
| 2089 | + | |
| 2044 | 2090 | endOfBroadcastStringWrite += packNodeId(endOfBroadcastStringWrite, nodeList->getOwnerID()); |
| 2045 | 2091 | |
| 2046 | 2092 | endOfBroadcastStringWrite += _myAvatar.getBroadcastData(endOfBroadcastStringWrite); |
| @@ -2070,8 +2116,8 @@ void Application::updateAvatar(float deltaTime) { · 23 unmodified lines | ||
| 2070 | 2116 | _paintingVoxel.y >= 0.0 && _paintingVoxel.y <= 1.0 && |
| 2071 | 2117 | _paintingVoxel.z >= 0.0 && _paintingVoxel.z <= 1.0) { |
| 2072 | 2118 | |
| 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); | |
| 2075 | 2121 | sendVoxelEditMessage(message, _paintingVoxel); |
| 2076 | 2122 | } |
| 2077 | 2123 | } |
| @@ -2953,8 +2999,8 @@ void Application::shiftPaintingColor() { · 875 unmodified lines | ||
| 2953 | 2999 | void Application::maybeEditVoxelUnderCursor() { |
| 2954 | 3000 | if (_addVoxelMode->isChecked() || _colorVoxelMode->isChecked()) { |
| 2955 | 3001 | 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); | |
| 2958 | 3004 | sendVoxelEditMessage(message, _mouseVoxel); |
| 2959 | 3005 | |
| 2960 | 3006 | // create the voxel locally so it appears immediately |
| @@ -3027,7 +3073,7 @@ void Application::maybeEditVoxelUnderCursor() { · 66 unmodified lines | ||
| 3027 | 3073 | void Application::deleteVoxelUnderCursor() { |
| 3028 | 3074 | if (_mouseVoxel.s != 0) { |
| 3029 | 3075 | // 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); | |
| 3031 | 3077 | AudioInjector* voxelInjector = AudioInjectionManager::injectorWithCapacity(5000); |
| 3032 | 3078 | voxelInjector->setPosition(glm::vec3(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z)); |
| 3033 | 3079 | // voxelInjector->setBearing(0); //straight down the z axis |
| @@ -3137,36 +3183,39 @@ void* Application::networkReceive(void* args) { · 103 unmodified lines | ||
| 3137 | 3183 | app->_packetCount++; |
| 3138 | 3184 | app->_bytesCount += bytesReceived; |
| 3139 | 3185 | |
| 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 | + } | |
| 3170 | 3219 | } |
| 3171 | 3220 | } else if (!app->_enableNetworkThread) { |
| 3172 | 3221 | break; |