Showing the changes to interface/src/Application.cpp (1 of 44 files). Show all
Unified · Split
| @@ -128,7 +128,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 127 unmodified lines | |||
| 128 | _perfStatsOn(false), | 128 | _perfStatsOn(false), |
| 129 | _chatEntryOn(false), | 129 | _chatEntryOn(false), |
| 130 | _audio(&_audioScope, STARTUP_JITTER_SAMPLES), | 130 | _audio(&_audioScope, STARTUP_JITTER_SAMPLES), |
| 131 | _stopNetworkReceiveThread(false), | 131 | _enableProcessVoxelsThread(true), |
| 132 | _voxelProcessor(), | 132 | _voxelProcessor(), |
| 133 | _voxelHideShowThread(&_voxels), | 133 | _voxelHideShowThread(&_voxels), |
| 134 | _voxelEditSender(this), | 134 | _voxelEditSender(this), |
| @@ -165,6 +165,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 30 unmodified lines | |||
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AGENT, listenPort); | 167 | NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AGENT, listenPort); |
| 168 | |||
| 169 | // connect our processDatagrams slot to the QUDPSocket readyRead() signal | ||
| 170 | connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), SLOT(processDatagrams())); | ||
| 168 | 171 | ||
| 169 | // put the audio processing on a separate thread | 172 | // put the audio processing on a separate thread |
| 170 | QThread* audioThread = new QThread(this); | 173 | QThread* audioThread = new QThread(this); |
| @@ -173,14 +176,13 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 2 unmodified lines | |||
| 173 | connect(audioThread, SIGNAL(started()), &_audio, SLOT(start())); | 176 | connect(audioThread, SIGNAL(started()), &_audio, SLOT(start())); |
| 174 | 177 | ||
| 175 | audioThread->start(); | 178 | audioThread->start(); |
| 176 | 179 | ||
| 177 | nodeList->addHook(&_voxels); | 180 | connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer))); |
| 178 | nodeList->addHook(this); | 181 | connect(nodeList, SIGNAL(nodeAdded(SharedNodePointer)), &_voxels, SLOT(nodeAdded(SharedNodePointer))); |
| 182 | connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), &_voxels, SLOT(nodeKilled(SharedNodePointer))); | ||
| 183 | |||
| 179 | nodeList->addDomainListener(this); | 184 | nodeList->addDomainListener(this); |
| 180 | 185 | ||
| 181 | // network receive thread and voxel parsing thread are both controlled by the --nonblocking command line | ||
| 182 | _enableProcessVoxelsThread = _enableNetworkThread = !cmdOptionExists(argc, constArgv, "--nonblocking"); | ||
| 183 | |||
| 184 | // read the ApplicationInfo.ini file for Name/Version/Domain information | 186 | // read the ApplicationInfo.ini file for Name/Version/Domain information |
| 185 | QSettings applicationInfo("resources/info/ApplicationInfo.ini", QSettings::IniFormat); | 187 | QSettings applicationInfo("resources/info/ApplicationInfo.ini", QSettings::IniFormat); |
| 186 | 188 | ||
| @@ -263,8 +265,6 @@ Application::~Application() { · 76 unmodified lines | |||
| 263 | _audio.thread()->wait(); | 265 | _audio.thread()->wait(); |
| 264 | 266 | ||
| 265 | storeSizeAndPosition(); | 267 | storeSizeAndPosition(); |
| 266 | NodeList::getInstance()->removeHook(&_voxels); | ||
| 267 | NodeList::getInstance()->removeHook(this); | ||
| 268 | NodeList::getInstance()->removeDomainListener(this); | 268 | NodeList::getInstance()->removeDomainListener(this); |
| 269 | 269 | ||
| 270 | _sharedVoxelSystem.changeTree(new VoxelTree); | 270 | _sharedVoxelSystem.changeTree(new VoxelTree); |
| @@ -274,7 +274,6 @@ Application::~Application() { · 3 unmodified lines | |||
| 274 | 274 | ||
| 275 | delete _logger; | 275 | delete _logger; |
| 276 | delete _settings; | 276 | delete _settings; |
| 277 | delete _followMode; | ||
| 278 | delete _glWidget; | 277 | delete _glWidget; |
| 279 | } | 278 | } |
| 280 | 279 | ||
| @@ -330,12 +329,6 @@ void Application::initializeGL() { · 49 unmodified lines | |||
| 330 | init(); | 329 | init(); |
| 331 | qDebug( "init() complete."); | 330 | qDebug( "init() complete."); |
| 332 | 331 | ||
| 333 | // create thread for receipt of data via UDP | ||
| 334 | if (_enableNetworkThread) { | ||
| 335 | pthread_create(&_networkReceiveThread, NULL, networkReceive, NULL); | ||
| 336 | qDebug("Network receive thread created."); | ||
| 337 | } | ||
| 338 | |||
| 339 | // create thread for parsing of voxel data independent of the main network and rendering threads | 332 | // create thread for parsing of voxel data independent of the main network and rendering threads |
| 340 | _voxelProcessor.initialize(_enableProcessVoxelsThread); | 333 | _voxelProcessor.initialize(_enableProcessVoxelsThread); |
| 341 | _voxelEditSender.initialize(_enableProcessVoxelsThread); | 334 | _voxelEditSender.initialize(_enableProcessVoxelsThread); |
| @@ -1416,11 +1409,6 @@ void Application::terminate() { · 1074 unmodified lines | |||
| 1416 | // let the avatar mixer know we're out | 1409 | // let the avatar mixer know we're out |
| 1417 | NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1); | 1410 | NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1); |
| 1418 | 1411 | ||
| 1419 | if (_enableNetworkThread) { | ||
| 1420 | _stopNetworkReceiveThread = true; | ||
| 1421 | pthread_join(_networkReceiveThread, NULL); | ||
| 1422 | } | ||
| 1423 | |||
| 1424 | printf(""); | 1412 | printf(""); |
| 1425 | _voxelProcessor.terminate(); | 1413 | _voxelProcessor.terminate(); |
| 1426 | _voxelHideShowThread.terminate(); | 1414 | _voxelHideShowThread.terminate(); |
| @@ -1433,7 +1421,7 @@ void Application::terminate() { · 6 unmodified lines | |||
| 1433 | static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& dataBytes) { | 1421 | static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& dataBytes) { |
| 1434 | // record the packet for stats-tracking | 1422 | // record the packet for stats-tracking |
| 1435 | Application::getInstance()->getBandwidthMeter()->inputStream(BandwidthMeter::AVATARS).updateValue(dataBytes); | 1423 | Application::getInstance()->getBandwidthMeter()->inputStream(BandwidthMeter::AVATARS).updateValue(dataBytes); |
| 1436 | Node* avatarMixerNode = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER); | 1424 | SharedNodePointer avatarMixerNode = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER); |
| 1437 | if (avatarMixerNode) { | 1425 | if (avatarMixerNode) { |
| 1438 | avatarMixerNode->recordBytesReceived(dataBytes); | 1426 | avatarMixerNode->recordBytesReceived(dataBytes); |
| 1439 | } | 1427 | } |
| @@ -1450,7 +1438,7 @@ static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& da · 10 unmodified lines | |||
| 1450 | dataBytes -= NUM_BYTES_RFC4122_UUID; | 1438 | dataBytes -= NUM_BYTES_RFC4122_UUID; |
| 1451 | 1439 | ||
| 1452 | // make sure the node exists | 1440 | // make sure the node exists |
| 1453 | Node* node = NodeList::getInstance()->nodeWithUUID(nodeUUID); | 1441 | SharedNodePointer node = NodeList::getInstance()->nodeWithUUID(nodeUUID); |
| 1454 | if (!node || !node->getLinkedData()) { | 1442 | if (!node || !node->getLinkedData()) { |
| 1455 | return NULL; | 1443 | return NULL; |
| 1456 | } | 1444 | } |
| @@ -1915,10 +1903,6 @@ void Application::init() { · 458 unmodified lines | |||
| 1915 | _glWidget->width(), | 1903 | _glWidget->width(), |
| 1916 | _glWidget->height()); | 1904 | _glWidget->height()); |
| 1917 | 1905 | ||
| 1918 | _followMode = new QAction(this); | ||
| 1919 | connect(_followMode, SIGNAL(triggered()), this, SLOT(toggleFollowMode())); | ||
| 1920 | _pieMenu.addAction(_followMode); | ||
| 1921 | |||
| 1922 | _audio.init(_glWidget); | 1906 | _audio.init(_glWidget); |
| 1923 | 1907 | ||
| 1924 | _rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect, _settings); | 1908 | _rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect, _settings); |
| @@ -1976,16 +1960,16 @@ void Application::updateLookatTargetAvatar(const glm::vec3& mouseRayOrigin, cons · 51 unmodified lines | |||
| 1976 | Avatar* Application::findLookatTargetAvatar(const glm::vec3& mouseRayOrigin, const glm::vec3& mouseRayDirection, | 1960 | Avatar* Application::findLookatTargetAvatar(const glm::vec3& mouseRayOrigin, const glm::vec3& mouseRayDirection, |
| 1977 | glm::vec3& eyePosition, QUuid& nodeUUID = DEFAULT_NODE_ID_REF) { | 1961 | glm::vec3& eyePosition, QUuid& nodeUUID = DEFAULT_NODE_ID_REF) { |
| 1978 | 1962 | ||
| 1979 | NodeList* nodeList = NodeList::getInstance(); | 1963 | foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { |
| 1980 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | ||
| 1981 | if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { | 1964 | if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { |
| 1982 | Avatar* avatar = (Avatar*)node->getLinkedData(); | 1965 | Avatar* avatar = (Avatar*)node->getLinkedData(); |
| 1983 | float distance; | 1966 | float distance; |
| 1967 | |||
| 1984 | if (avatar->findRayIntersection(mouseRayOrigin, mouseRayDirection, distance)) { | 1968 | if (avatar->findRayIntersection(mouseRayOrigin, mouseRayDirection, distance)) { |
| 1985 | // rescale to compensate for head embiggening | 1969 | // rescale to compensate for head embiggening |
| 1986 | eyePosition = (avatar->getHead().calculateAverageEyePosition() - avatar->getHead().getScalePivot()) * | 1970 | eyePosition = (avatar->getHead().calculateAverageEyePosition() - avatar->getHead().getScalePivot()) * |
| 1987 | (avatar->getScale() / avatar->getHead().getScale()) + avatar->getHead().getScalePivot(); | 1971 | (avatar->getScale() / avatar->getHead().getScale()) + avatar->getHead().getScalePivot(); |
| 1988 | 1972 | ||
| 1989 | _lookatIndicatorScale = avatar->getHead().getScale(); | 1973 | _lookatIndicatorScale = avatar->getHead().getScale(); |
| 1990 | _lookatOtherPosition = avatar->getHead().getPosition(); | 1974 | _lookatOtherPosition = avatar->getHead().getPosition(); |
| 1991 | nodeUUID = avatar->getOwningNode()->getUUID(); | 1975 | nodeUUID = avatar->getOwningNode()->getUUID(); |
| @@ -1993,6 +1977,7 @@ Avatar* Application::findLookatTargetAvatar(const glm::vec3& mouseRayOrigin, con · 1 unmodified line | |||
| 1993 | } | 1977 | } |
| 1994 | } | 1978 | } |
| 1995 | } | 1979 | } |
| 1980 | |||
| 1996 | return NULL; | 1981 | return NULL; |
| 1997 | } | 1982 | } |
| 1998 | 1983 | ||
| @@ -2017,71 +2002,6 @@ void Application::renderLookatIndicator(glm::vec3 pointOfInterest) { · 18 unmodified lines | |||
| 2017 | renderCircle(haloOrigin, INDICATOR_RADIUS, IDENTITY_UP, NUM_SEGMENTS); | 2002 | renderCircle(haloOrigin, INDICATOR_RADIUS, IDENTITY_UP, NUM_SEGMENTS); |
| 2018 | } | 2003 | } |
| 2019 | 2004 | ||
| 2020 | void maybeBeginFollowIndicator(bool& began) { | ||
| 2021 | if (!began) { | ||
| 2022 | Application::getInstance()->getGlowEffect()->begin(); | ||
| 2023 | glLineWidth(5); | ||
| 2024 | glBegin(GL_LINES); | ||
| 2025 | began = true; | ||
| 2026 | } | ||
| 2027 | } | ||
| 2028 | |||
| 2029 | void Application::renderFollowIndicator() { | ||
| 2030 | NodeList* nodeList = NodeList::getInstance(); | ||
| 2031 | |||
| 2032 | // initialize lazily so that we don't enable the glow effect unnecessarily | ||
| 2033 | bool began = false; | ||
| 2034 | |||
| 2035 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); ++node) { | ||
| 2036 | if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { | ||
| 2037 | Avatar* avatar = (Avatar *) node->getLinkedData(); | ||
| 2038 | Avatar* leader = NULL; | ||
| 2039 | |||
| 2040 | if (!avatar->getLeaderUUID().isNull()) { | ||
| 2041 | if (avatar->getLeaderUUID() == NodeList::getInstance()->getOwnerUUID()) { | ||
| 2042 | leader = &_myAvatar; | ||
| 2043 | } else { | ||
| 2044 | for (NodeList::iterator it = nodeList->begin(); it != nodeList->end(); ++it) { | ||
| 2045 | if(it->getUUID() == avatar->getLeaderUUID() | ||
| 2046 | && it->getType() == NODE_TYPE_AGENT) { | ||
| 2047 | leader = (Avatar*) it->getLinkedData(); | ||
| 2048 | } | ||
| 2049 | } | ||
| 2050 | } | ||
| 2051 | |||
| 2052 | if (leader != NULL) { | ||
| 2053 | maybeBeginFollowIndicator(began); | ||
| 2054 | glColor3f(1.f, 0.f, 0.f); | ||
| 2055 | glVertex3f((avatar->getHead().getPosition().x + avatar->getPosition().x) / 2.f, | ||
| 2056 | (avatar->getHead().getPosition().y + avatar->getPosition().y) / 2.f, | ||
| 2057 | (avatar->getHead().getPosition().z + avatar->getPosition().z) / 2.f); | ||
| 2058 | glColor3f(0.f, 1.f, 0.f); | ||
| 2059 | glVertex3f((leader->getHead().getPosition().x + leader->getPosition().x) / 2.f, | ||
| 2060 | (leader->getHead().getPosition().y + leader->getPosition().y) / 2.f, | ||
| 2061 | (leader->getHead().getPosition().z + leader->getPosition().z) / 2.f); | ||
| 2062 | } | ||
| 2063 | } | ||
| 2064 | } | ||
| 2065 | } | ||
| 2066 | |||
| 2067 | if (_myAvatar.getLeadingAvatar() != NULL) { | ||
| 2068 | maybeBeginFollowIndicator(began); | ||
| 2069 | glColor3f(1.f, 0.f, 0.f); | ||
| 2070 | glVertex3f((_myAvatar.getHead().getPosition().x + _myAvatar.getPosition().x) / 2.f, | ||
| 2071 | (_myAvatar.getHead().getPosition().y + _myAvatar.getPosition().y) / 2.f, | ||
| 2072 | (_myAvatar.getHead().getPosition().z + _myAvatar.getPosition().z) / 2.f); | ||
| 2073 | glColor3f(0.f, 1.f, 0.f); | ||
| 2074 | glVertex3f((_myAvatar.getLeadingAvatar()->getHead().getPosition().x + _myAvatar.getLeadingAvatar()->getPosition().x) / 2.f, | ||
| 2075 | (_myAvatar.getLeadingAvatar()->getHead().getPosition().y + _myAvatar.getLeadingAvatar()->getPosition().y) / 2.f, | ||
| 2076 | (_myAvatar.getLeadingAvatar()->getHead().getPosition().z + _myAvatar.getLeadingAvatar()->getPosition().z) / 2.f); | ||
| 2077 | } | ||
| 2078 | |||
| 2079 | if (began) { | ||
| 2080 | glEnd(); | ||
| 2081 | _glowEffect.end(); | ||
| 2082 | } | ||
| 2083 | } | ||
| 2084 | |||
| 2085 | void Application::renderHighlightVoxel(VoxelDetail voxel) { | 2005 | void Application::renderHighlightVoxel(VoxelDetail voxel) { |
| 2086 | glDisable(GL_LIGHTING); | 2006 | glDisable(GL_LIGHTING); |
| 2087 | glPushMatrix(); | 2007 | glPushMatrix(); |
| @@ -2099,10 +2019,9 @@ void Application::renderHighlightVoxel(VoxelDetail voxel) { · 11 unmodified lines | |||
| 2099 | void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm::vec3 mouseRayDirection) { | 2019 | void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm::vec3 mouseRayDirection) { |
| 2100 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | 2020 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| 2101 | PerformanceWarning warn(showWarnings, "Application::updateAvatars()"); | 2021 | PerformanceWarning warn(showWarnings, "Application::updateAvatars()"); |
| 2102 | NodeList* nodeList = NodeList::getInstance(); | 2022 | |
| 2103 | 2023 | foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { | |
| 2104 | for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | 2024 | QMutexLocker(&node->getMutex()); |
| 2105 | node->lock(); | ||
| 2106 | if (node->getLinkedData()) { | 2025 | if (node->getLinkedData()) { |
| 2107 | Avatar *avatar = (Avatar *)node->getLinkedData(); | 2026 | Avatar *avatar = (Avatar *)node->getLinkedData(); |
| 2108 | if (!avatar->isInitialized()) { | 2027 | if (!avatar->isInitialized()) { |
| @@ -2111,7 +2030,6 @@ void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm:: · 2 unmodified lines | |||
| 2111 | avatar->simulate(deltaTime, NULL); | 2030 | avatar->simulate(deltaTime, NULL); |
| 2112 | avatar->setMouseRay(mouseRayOrigin, mouseRayDirection); | 2031 | avatar->setMouseRay(mouseRayOrigin, mouseRayDirection); |
| 2113 | } | 2032 | } |
| 2114 | node->unlock(); | ||
| 2115 | } | 2033 | } |
| 2116 | 2034 | ||
| 2117 | // simulate avatar fades | 2035 | // simulate avatar fades |
| @@ -2377,11 +2295,6 @@ void Application::updateThreads(float deltaTime) { · 259 unmodified lines | |||
| 2377 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | 2295 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| 2378 | PerformanceWarning warn(showWarnings, "Application::updateThreads()"); | 2296 | PerformanceWarning warn(showWarnings, "Application::updateThreads()"); |
| 2379 | 2297 | ||
| 2380 | // read incoming packets from network | ||
| 2381 | if (!_enableNetworkThread) { | ||
| 2382 | networkReceive(0); | ||
| 2383 | } | ||
| 2384 | |||
| 2385 | // parse voxel packets | 2298 | // parse voxel packets |
| 2386 | if (!_enableProcessVoxelsThread) { | 2299 | if (!_enableProcessVoxelsThread) { |
| 2387 | _voxelProcessor.threadRoutine(); | 2300 | _voxelProcessor.threadRoutine(); |
| @@ -2694,39 +2607,36 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 306 unmodified lines | |||
| 2694 | 2607 | ||
| 2695 | unsigned char voxelQueryPacket[MAX_PACKET_SIZE]; | 2608 | unsigned char voxelQueryPacket[MAX_PACKET_SIZE]; |
| 2696 | 2609 | ||
| 2697 | NodeList* nodeList = NodeList::getInstance(); | ||
| 2698 | |||
| 2699 | // Iterate all of the nodes, and get a count of how many voxel servers we have... | 2610 | // Iterate all of the nodes, and get a count of how many voxel servers we have... |
| 2700 | int totalServers = 0; | 2611 | int totalServers = 0; |
| 2701 | int inViewServers = 0; | 2612 | int inViewServers = 0; |
| 2702 | int unknownJurisdictionServers = 0; | 2613 | int unknownJurisdictionServers = 0; |
| 2703 | 2614 | ||
| 2704 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | 2615 | foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { |
| 2705 | |||
| 2706 | // only send to the NodeTypes that are serverType | 2616 | // only send to the NodeTypes that are serverType |
| 2707 | if (node->getActiveSocket() != NULL && node->getType() == serverType) { | 2617 | if (node->getActiveSocket() != NULL && node->getType() == serverType) { |
| 2708 | totalServers++; | 2618 | totalServers++; |
| 2709 | 2619 | ||
| 2710 | // get the server bounds for this server | 2620 | // get the server bounds for this server |
| 2711 | QUuid nodeUUID = node->getUUID(); | 2621 | QUuid nodeUUID = node->getUUID(); |
| 2712 | 2622 | ||
| 2713 | // if we haven't heard from this voxel server, go ahead and send it a query, so we | 2623 | // if we haven't heard from this voxel server, go ahead and send it a query, so we |
| 2714 | // can get the jurisdiction... | 2624 | // can get the jurisdiction... |
| 2715 | if (jurisdictions.find(nodeUUID) == jurisdictions.end()) { | 2625 | if (jurisdictions.find(nodeUUID) == jurisdictions.end()) { |
| 2716 | unknownJurisdictionServers++; | 2626 | unknownJurisdictionServers++; |
| 2717 | } else { | 2627 | } else { |
| 2718 | const JurisdictionMap& map = (jurisdictions)[nodeUUID]; | 2628 | const JurisdictionMap& map = (jurisdictions)[nodeUUID]; |
| 2719 | 2629 | ||
| 2720 | unsigned char* rootCode = map.getRootOctalCode(); | 2630 | unsigned char* rootCode = map.getRootOctalCode(); |
| 2721 | 2631 | ||
| 2722 | if (rootCode) { | 2632 | if (rootCode) { |
| 2723 | VoxelPositionSize rootDetails; | 2633 | VoxelPositionSize rootDetails; |
| 2724 | voxelDetailsForCode(rootCode, rootDetails); | 2634 | voxelDetailsForCode(rootCode, rootDetails); |
| 2725 | AABox serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s); | 2635 | AABox serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s); |
| 2726 | serverBounds.scale(TREE_SCALE); | 2636 | serverBounds.scale(TREE_SCALE); |
| 2727 | 2637 | ||
| 2728 | ViewFrustum::location serverFrustumLocation = _viewFrustum.boxInFrustum(serverBounds); | 2638 | ViewFrustum::location serverFrustumLocation = _viewFrustum.boxInFrustum(serverBounds); |
| 2729 | 2639 | ||
| 2730 | if (serverFrustumLocation != ViewFrustum::OUTSIDE) { | 2640 | if (serverFrustumLocation != ViewFrustum::OUTSIDE) { |
| 2731 | inViewServers++; | 2641 | inViewServers++; |
| 2732 | } | 2642 | } |
| @@ -2759,18 +2669,20 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 26 unmodified lines | |||
| 2759 | if (wantExtraDebugging && unknownJurisdictionServers > 0) { | 2669 | if (wantExtraDebugging && unknownJurisdictionServers > 0) { |
| 2760 | qDebug("perServerPPS: %d perUnknownServer: %d", perServerPPS, perUnknownServer); | 2670 | qDebug("perServerPPS: %d perUnknownServer: %d", perServerPPS, perUnknownServer); |
| 2761 | } | 2671 | } |
| 2762 | 2672 | ||
| 2763 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | 2673 | NodeList* nodeList = NodeList::getInstance(); |
| 2674 | |||
| 2675 | foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { | ||
| 2764 | // only send to the NodeTypes that are serverType | 2676 | // only send to the NodeTypes that are serverType |
| 2765 | if (node->getActiveSocket() != NULL && node->getType() == serverType) { | 2677 | if (node->getActiveSocket() != NULL && node->getType() == serverType) { |
| 2766 | 2678 | ||
| 2767 | 2679 | ||
| 2768 | // get the server bounds for this server | 2680 | // get the server bounds for this server |
| 2769 | QUuid nodeUUID = node->getUUID(); | 2681 | QUuid nodeUUID = node->getUUID(); |
| 2770 | 2682 | ||
| 2771 | bool inView = false; | 2683 | bool inView = false; |
| 2772 | bool unknownView = false; | 2684 | bool unknownView = false; |
| 2773 | 2685 | ||
| 2774 | // if we haven't heard from this voxel server, go ahead and send it a query, so we | 2686 | // if we haven't heard from this voxel server, go ahead and send it a query, so we |
| 2775 | // can get the jurisdiction... | 2687 | // can get the jurisdiction... |
| 2776 | if (jurisdictions.find(nodeUUID) == jurisdictions.end()) { | 2688 | if (jurisdictions.find(nodeUUID) == jurisdictions.end()) { |
| @@ -2780,15 +2692,15 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 3 unmodified lines | |||
| 2780 | } | 2692 | } |
| 2781 | } else { | 2693 | } else { |
| 2782 | const JurisdictionMap& map = (jurisdictions)[nodeUUID]; | 2694 | const JurisdictionMap& map = (jurisdictions)[nodeUUID]; |
| 2783 | 2695 | ||
| 2784 | unsigned char* rootCode = map.getRootOctalCode(); | 2696 | unsigned char* rootCode = map.getRootOctalCode(); |
| 2785 | 2697 | ||
| 2786 | if (rootCode) { | 2698 | if (rootCode) { |
| 2787 | VoxelPositionSize rootDetails; | 2699 | VoxelPositionSize rootDetails; |
| 2788 | voxelDetailsForCode(rootCode, rootDetails); | 2700 | voxelDetailsForCode(rootCode, rootDetails); |
| 2789 | AABox serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s); | 2701 | AABox serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s); |
| 2790 | serverBounds.scale(TREE_SCALE); | 2702 | serverBounds.scale(TREE_SCALE); |
| 2791 | 2703 | ||
| 2792 | ViewFrustum::location serverFrustumLocation = _viewFrustum.boxInFrustum(serverBounds); | 2704 | ViewFrustum::location serverFrustumLocation = _viewFrustum.boxInFrustum(serverBounds); |
| 2793 | if (serverFrustumLocation != ViewFrustum::OUTSIDE) { | 2705 | if (serverFrustumLocation != ViewFrustum::OUTSIDE) { |
| 2794 | inView = true; | 2706 | inView = true; |
| @@ -2801,7 +2713,7 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 6 unmodified lines | |||
| 2801 | } | 2713 | } |
| 2802 | } | 2714 | } |
| 2803 | } | 2715 | } |
| 2804 | 2716 | ||
| 2805 | if (inView) { | 2717 | if (inView) { |
| 2806 | _voxelQuery.setMaxOctreePacketsPerSecond(perServerPPS); | 2718 | _voxelQuery.setMaxOctreePacketsPerSecond(perServerPPS); |
| 2807 | } else if (unknownView) { | 2719 | } else if (unknownView) { |
| @@ -2809,7 +2721,7 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 1 unmodified line | |||
| 2809 | qDebug() << "no known jurisdiction for node " << *node << ", give it budget of " | 2721 | qDebug() << "no known jurisdiction for node " << *node << ", give it budget of " |
| 2810 | << perUnknownServer << " to send us jurisdiction."; | 2722 | << perUnknownServer << " to send us jurisdiction."; |
| 2811 | } | 2723 | } |
| 2812 | 2724 | ||
| 2813 | // set the query's position/orientation to be degenerate in a manner that will get the scene quickly | 2725 | // set the query's position/orientation to be degenerate in a manner that will get the scene quickly |
| 2814 | // If there's only one server, then don't do this, and just let the normal voxel query pass through | 2726 | // If there's only one server, then don't do this, and just let the normal voxel query pass through |
| 2815 | // as expected... this way, we will actually get a valid scene if there is one to be seen | 2727 | // as expected... this way, we will actually get a valid scene if there is one to be seen |
| @@ -2833,24 +2745,24 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 17 unmodified lines | |||
| 2833 | } | 2745 | } |
| 2834 | // set up the packet for sending... | 2746 | // set up the packet for sending... |
| 2835 | unsigned char* endOfVoxelQueryPacket = voxelQueryPacket; | 2747 | unsigned char* endOfVoxelQueryPacket = voxelQueryPacket; |
| 2836 | 2748 | ||
| 2837 | // insert packet type/version and node UUID | 2749 | // insert packet type/version and node UUID |
| 2838 | endOfVoxelQueryPacket += populateTypeAndVersion(endOfVoxelQueryPacket, packetType); | 2750 | endOfVoxelQueryPacket += populateTypeAndVersion(endOfVoxelQueryPacket, packetType); |
| 2839 | QByteArray ownerUUID = nodeList->getOwnerUUID().toRfc4122(); | 2751 | QByteArray ownerUUID = nodeList->getOwnerUUID().toRfc4122(); |
| 2840 | memcpy(endOfVoxelQueryPacket, ownerUUID.constData(), ownerUUID.size()); | 2752 | memcpy(endOfVoxelQueryPacket, ownerUUID.constData(), ownerUUID.size()); |
| 2841 | endOfVoxelQueryPacket += ownerUUID.size(); | 2753 | endOfVoxelQueryPacket += ownerUUID.size(); |
| 2842 | 2754 | ||
| 2843 | // encode the query data... | 2755 | // encode the query data... |
| 2844 | endOfVoxelQueryPacket += _voxelQuery.getBroadcastData(endOfVoxelQueryPacket); | 2756 | endOfVoxelQueryPacket += _voxelQuery.getBroadcastData(endOfVoxelQueryPacket); |
| 2845 | 2757 | ||
| 2846 | int packetLength = endOfVoxelQueryPacket - voxelQueryPacket; | 2758 | int packetLength = endOfVoxelQueryPacket - voxelQueryPacket; |
| 2847 | 2759 | ||
| 2848 | // make sure we still have an active socket | 2760 | // make sure we still have an active socket |
| 2849 | if (node->getActiveSocket()) { | 2761 | if (node->getActiveSocket()) { |
| 2850 | nodeList->getNodeSocket().writeDatagram((char*) voxelQueryPacket, packetLength, | 2762 | nodeList->getNodeSocket().writeDatagram((char*) voxelQueryPacket, packetLength, |
| 2851 | node->getActiveSocket()->getAddress(), node->getActiveSocket()->getPort()); | 2763 | node->getActiveSocket()->getAddress(), node->getActiveSocket()->getPort()); |
| 2852 | } | 2764 | } |
| 2853 | 2765 | ||
| 2854 | // Feed number of bytes to corresponding channel of the bandwidth meter | 2766 | // Feed number of bytes to corresponding channel of the bandwidth meter |
| 2855 | _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(packetLength); | 2767 | _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(packetLength); |
| 2856 | } | 2768 | } |
| @@ -3207,12 +3119,6 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { · 350 unmodified lines | |||
| 3207 | } | 3119 | } |
| 3208 | } | 3120 | } |
| 3209 | 3121 | ||
| 3210 | { | ||
| 3211 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | ||
| 3212 | "Application::displaySide() ... renderFollowIndicator..."); | ||
| 3213 | renderFollowIndicator(); | ||
| 3214 | } | ||
| 3215 | |||
| 3216 | // render transmitter pick ray, if non-empty | 3122 | // render transmitter pick ray, if non-empty |
| 3217 | if (_transmitterPickStart != _transmitterPickEnd) { | 3123 | if (_transmitterPickStart != _transmitterPickEnd) { |
| 3218 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | 3124 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| @@ -3335,12 +3241,12 @@ void Application::displayOverlay() { · 116 unmodified lines | |||
| 3335 | glPointSize(1.0f); | 3241 | glPointSize(1.0f); |
| 3336 | char nodes[100]; | 3242 | char nodes[100]; |
| 3337 | 3243 | ||
| 3338 | NodeList* nodeList = NodeList::getInstance(); | ||
| 3339 | int totalAvatars = 0, totalServers = 0; | 3244 | int totalAvatars = 0, totalServers = 0; |
| 3340 | 3245 | ||
| 3341 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | 3246 | foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { |
| 3342 | node->getType() == NODE_TYPE_AGENT ? totalAvatars++ : totalServers++; | 3247 | node->getType() == NODE_TYPE_AGENT ? totalAvatars++ : totalServers++; |
| 3343 | } | 3248 | } |
| 3249 | |||
| 3344 | sprintf(nodes, "Servers: %d, Avatars: %d\n", totalServers, totalAvatars); | 3250 | sprintf(nodes, "Servers: %d, Avatars: %d\n", totalServers, totalAvatars); |
| 3345 | drawtext(_glWidget->width() - 150, 20, 0.10, 0, 1.0, 0, nodes, 1, 0, 0); | 3251 | drawtext(_glWidget->width() - 150, 20, 0.10, 0, 1.0, 0, nodes, 1, 0, 0); |
| 3346 | } | 3252 | } |
| @@ -3440,8 +3346,8 @@ void Application::displayStats() { · 93 unmodified lines | |||
| 3440 | int pingAudio = 0, pingAvatar = 0, pingVoxel = 0, pingVoxelMax = 0; | 3346 | int pingAudio = 0, pingAvatar = 0, pingVoxel = 0, pingVoxelMax = 0; |
| 3441 | 3347 | ||
| 3442 | NodeList* nodeList = NodeList::getInstance(); | 3348 | NodeList* nodeList = NodeList::getInstance(); |
| 3443 | Node* audioMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER); | 3349 | SharedNodePointer audioMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER); |
| 3444 | Node* avatarMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER); | 3350 | SharedNodePointer avatarMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER); |
| 3445 | 3351 | ||
| 3446 | pingAudio = audioMixerNode ? audioMixerNode->getPingMs() : 0; | 3352 | pingAudio = audioMixerNode ? audioMixerNode->getPingMs() : 0; |
| 3447 | pingAvatar = avatarMixerNode ? avatarMixerNode->getPingMs() : 0; | 3353 | pingAvatar = avatarMixerNode ? avatarMixerNode->getPingMs() : 0; |
| @@ -3450,7 +3356,8 @@ void Application::displayStats() { · 2 unmodified lines | |||
| 3450 | // Now handle voxel servers, since there could be more than one, we average their ping times | 3356 | // Now handle voxel servers, since there could be more than one, we average their ping times |
| 3451 | unsigned long totalPingVoxel = 0; | 3357 | unsigned long totalPingVoxel = 0; |
| 3452 | int voxelServerCount = 0; | 3358 | int voxelServerCount = 0; |
| 3453 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | 3359 | |
| 3360 | foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { | ||
| 3454 | if (node->getType() == NODE_TYPE_VOXEL_SERVER) { | 3361 | if (node->getType() == NODE_TYPE_VOXEL_SERVER) { |
| 3455 | totalPingVoxel += node->getPingMs(); | 3362 | totalPingVoxel += node->getPingMs(); |
| 3456 | voxelServerCount++; | 3363 | voxelServerCount++; |
| @@ -3459,6 +3366,7 @@ void Application::displayStats() { · 2 unmodified lines | |||
| 3459 | } | 3366 | } |
| 3460 | } | 3367 | } |
| 3461 | } | 3368 | } |
| 3369 | |||
| 3462 | if (voxelServerCount) { | 3370 | if (voxelServerCount) { |
| 3463 | pingVoxel = totalPingVoxel/voxelServerCount; | 3371 | pingVoxel = totalPingVoxel/voxelServerCount; |
| 3464 | } | 3372 | } |
| @@ -3475,7 +3383,7 @@ void Application::displayStats() { · 10 unmodified lines | |||
| 3475 | sprintf(avatarStats, "Avatar: pos %.3f, %.3f, %.3f, vel %.1f, yaw = %.2f", avatarPos.x, avatarPos.y, avatarPos.z, glm::length(_myAvatar.getVelocity()), _myAvatar.getBodyYaw()); | 3383 | sprintf(avatarStats, "Avatar: pos %.3f, %.3f, %.3f, vel %.1f, yaw = %.2f", avatarPos.x, avatarPos.y, avatarPos.z, glm::length(_myAvatar.getVelocity()), _myAvatar.getBodyYaw()); |
| 3476 | drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, avatarStats); | 3384 | drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, avatarStats); |
| 3477 | 3385 | ||
| 3478 | Node* avatarMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER); | 3386 | SharedNodePointer avatarMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER); |
| 3479 | char avatarMixerStats[200]; | 3387 | char avatarMixerStats[200]; |
| 3480 | if (avatarMixer) { | 3388 | if (avatarMixer) { |
| 3481 | sprintf(avatarMixerStats, "Avatar Mixer: %.f kbps, %.f pps", | 3389 | sprintf(avatarMixerStats, "Avatar Mixer: %.f kbps, %.f pps", |
| @@ -3794,10 +3702,10 @@ void Application::renderAvatars(bool forceRenderHead, bool selfAvatarOnly) { · 312 unmodified lines | |||
| 3794 | if (!selfAvatarOnly) { | 3702 | if (!selfAvatarOnly) { |
| 3795 | // Render avatars of other nodes | 3703 | // Render avatars of other nodes |
| 3796 | NodeList* nodeList = NodeList::getInstance(); | 3704 | NodeList* nodeList = NodeList::getInstance(); |
| 3797 | 3705 | ||
| 3798 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | 3706 | foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { |
| 3799 | node->lock(); | 3707 | QMutexLocker(&node->getMutex()); |
| 3800 | 3708 | ||
| 3801 | if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { | 3709 | if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { |
| 3802 | Avatar *avatar = (Avatar *)node->getLinkedData(); | 3710 | Avatar *avatar = (Avatar *)node->getLinkedData(); |
| 3803 | if (!avatar->isInitialized()) { | 3711 | if (!avatar->isInitialized()) { |
| @@ -3806,8 +3714,6 @@ void Application::renderAvatars(bool forceRenderHead, bool selfAvatarOnly) { · 2 unmodified lines | |||
| 3806 | avatar->render(false); | 3714 | avatar->render(false); |
| 3807 | avatar->setDisplayingLookatVectors(Menu::getInstance()->isOptionChecked(MenuOption::LookAtVectors)); | 3715 | avatar->setDisplayingLookatVectors(Menu::getInstance()->isOptionChecked(MenuOption::LookAtVectors)); |
| 3808 | } | 3716 | } |
| 3809 | |||
| 3810 | node->unlock(); | ||
| 3811 | } | 3717 | } |
| 3812 | 3718 | ||
| 3813 | // render avatar fades | 3719 | // render avatar fades |
| @@ -4052,18 +3958,6 @@ void Application::eyedropperVoxelUnderCursor() { · 238 unmodified lines | |||
| 4052 | } | 3958 | } |
| 4053 | } | 3959 | } |
| 4054 | 3960 | ||
| 4055 | void Application::toggleFollowMode() { | ||
| 4056 | glm::vec3 mouseRayOrigin, mouseRayDirection; | ||
| 4057 | _viewFrustum.computePickRay(_pieMenu.getX() / (float)_glWidget->width(), | ||
| 4058 | _pieMenu.getY() / (float)_glWidget->height(), | ||
| 4059 | mouseRayOrigin, mouseRayDirection); | ||
| 4060 | glm::vec3 eyePositionIgnored; | ||
| 4061 | QUuid nodeUUIDIgnored; | ||
| 4062 | Avatar* leadingAvatar = findLookatTargetAvatar(mouseRayOrigin, mouseRayDirection, eyePositionIgnored, nodeUUIDIgnored); | ||
| 4063 | |||
| 4064 | _myAvatar.follow(leadingAvatar); | ||
| 4065 | } | ||
| 4066 | |||
| 4067 | void Application::resetSensors() { | 3961 | void Application::resetSensors() { |
| 4068 | _headMouseX = _mouseX = _glWidget->width() / 2; | 3962 | _headMouseX = _mouseX = _glWidget->width() / 2; |
| 4069 | _headMouseY = _mouseY = _glWidget->height() / 2; | 3963 | _headMouseY = _mouseY = _glWidget->height() / 2; |
| @@ -4143,11 +4037,7 @@ void Application::domainChanged(QString domain) { · 73 unmodified lines | |||
| 4143 | updateLocalOctreeCache(); | 4037 | updateLocalOctreeCache(); |
| 4144 | } | 4038 | } |
| 4145 | 4039 | ||
| 4146 | void Application::nodeAdded(Node* node) { | 4040 | void Application::nodeKilled(SharedNodePointer node) { |
| 4147 | |||
| 4148 | } | ||
| 4149 | |||
| 4150 | void Application::nodeKilled(Node* node) { | ||
| 4151 | if (node->getType() == NODE_TYPE_VOXEL_SERVER) { | 4041 | if (node->getType() == NODE_TYPE_VOXEL_SERVER) { |
| 4152 | QUuid nodeUUID = node->getUUID(); | 4042 | QUuid nodeUUID = node->getUUID(); |
| 4153 | // see if this is the first we've heard of this node... | 4043 | // see if this is the first we've heard of this node... |
| @@ -4227,7 +4117,7 @@ void Application::trackIncomingVoxelPacket(unsigned char* messageData, ssize_t m · 73 unmodified lines | |||
| 4227 | const HifiSockAddr& senderSockAddr, bool wasStatsPacket) { | 4117 | const HifiSockAddr& senderSockAddr, bool wasStatsPacket) { |
| 4228 | 4118 | ||
| 4229 | // Attempt to identify the sender from it's address. | 4119 | // Attempt to identify the sender from it's address. |
| 4230 | Node* serverNode = NodeList::getInstance()->nodeWithAddress(senderSockAddr); | 4120 | SharedNodePointer serverNode = NodeList::getInstance()->nodeWithAddress(senderSockAddr); |
| 4231 | if (serverNode) { | 4121 | if (serverNode) { |
| 4232 | QUuid nodeUUID = serverNode->getUUID(); | 4122 | QUuid nodeUUID = serverNode->getUUID(); |
| 4233 | 4123 | ||
| @@ -4244,7 +4134,7 @@ void Application::trackIncomingVoxelPacket(unsigned char* messageData, ssize_t m · 10 unmodified lines | |||
| 4244 | int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLength, const HifiSockAddr& senderSockAddr) { | 4134 | int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLength, const HifiSockAddr& senderSockAddr) { |
| 4245 | 4135 | ||
| 4246 | // But, also identify the sender, and keep track of the contained jurisdiction root for this server | 4136 | // But, also identify the sender, and keep track of the contained jurisdiction root for this server |
| 4247 | Node* server = NodeList::getInstance()->nodeWithAddress(senderSockAddr); | 4137 | SharedNodePointer server = NodeList::getInstance()->nodeWithAddress(senderSockAddr); |
| 4248 | 4138 | ||
| 4249 | // parse the incoming stats datas stick it in a temporary object for now, while we | 4139 | // parse the incoming stats datas stick it in a temporary object for now, while we |
| 4250 | // determine which server it belongs to | 4140 | // determine which server it belongs to |
| @@ -4301,105 +4191,95 @@ int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLen · 50 unmodified lines | |||
| 4301 | } | 4191 | } |
| 4302 | 4192 | ||
| 4303 | // Receive packets from other nodes/servers and decide what to do with them! | 4193 | // Receive packets from other nodes/servers and decide what to do with them! |
| 4304 | void* Application::networkReceive(void* args) { | 4194 | void Application::processDatagrams() { |
| 4305 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | 4195 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 4306 | "Application::networkReceive()"); | 4196 | "Application::networkReceive()"); |
| 4307 | 4197 | ||
| 4308 | HifiSockAddr senderSockAddr; | 4198 | HifiSockAddr senderSockAddr; |
| 4309 | ssize_t bytesReceived; | 4199 | ssize_t bytesReceived; |
| 4310 | 4200 | ||
| 4311 | Application* app = Application::getInstance(); | 4201 | while (NodeList::getInstance()->getNodeSocket().hasPendingDatagrams() && |
| 4312 | while (!app->_stopNetworkReceiveThread) { | 4202 | (bytesReceived = NodeList::getInstance()->getNodeSocket().readDatagram((char*) _incomingPacket, |
| 4313 | if (NodeList::getInstance()->getNodeSocket().hasPendingDatagrams() && | 4203 | MAX_PACKET_SIZE, |
| 4314 | (bytesReceived = NodeList::getInstance()->getNodeSocket().readDatagram((char*) app->_incomingPacket, | 4204 | senderSockAddr.getAddressPointer(), |
| 4315 | MAX_PACKET_SIZE, | 4205 | senderSockAddr.getPortPointer()))) { |
| 4316 | senderSockAddr.getAddressPointer(), | 4206 | |
| 4317 | senderSockAddr.getPortPointer()))) { | 4207 | _packetCount++; |
| 4318 | 4208 | _bytesCount += bytesReceived; | |
| 4319 | app->_packetCount++; | 4209 | |
| 4320 | app->_bytesCount += bytesReceived; | 4210 | if (packetVersionMatch(_incomingPacket)) { |
| 4321 | 4211 | // only process this packet if we have a match on the packet version | |
| 4322 | if (packetVersionMatch(app->_incomingPacket)) { | 4212 | switch (_incomingPacket[0]) { |
| 4323 | // only process this packet if we have a match on the packet version | 4213 | case PACKET_TYPE_TRANSMITTER_DATA_V2: |
| 4324 | switch (app->_incomingPacket[0]) { | 4214 | // V2 = IOS transmitter app |
| 4325 | case PACKET_TYPE_TRANSMITTER_DATA_V2: | 4215 | _myTransmitter.processIncomingData(_incomingPacket, bytesReceived); |
| 4326 | // V2 = IOS transmitter app | 4216 | |
| 4327 | app->_myTransmitter.processIncomingData(app->_incomingPacket, bytesReceived); | 4217 | break; |
| 4328 | 4218 | case PACKET_TYPE_MIXED_AUDIO: | |
| 4329 | break; | 4219 | QMetaObject::invokeMethod(&_audio, "addReceivedAudioToBuffer", Qt::QueuedConnection, |
| 4330 | case PACKET_TYPE_MIXED_AUDIO: | 4220 | Q_ARG(QByteArray, QByteArray((char*) _incomingPacket, bytesReceived))); |
| 4331 | QMetaObject::invokeMethod(&app->_audio, "addReceivedAudioToBuffer", Qt::QueuedConnection, | 4221 | break; |
| 4332 | Q_ARG(QByteArray, QByteArray((char*) app->_incomingPacket, bytesReceived))); | 4222 | |
| 4333 | break; | 4223 | case PACKET_TYPE_PARTICLE_ADD_RESPONSE: |
| 4334 | 4224 | // look up our ParticleEditHanders.... | |
| 4335 | case PACKET_TYPE_PARTICLE_ADD_RESPONSE: | 4225 | ParticleEditHandle::handleAddResponse(_incomingPacket, bytesReceived); |
| 4336 | // look up our ParticleEditHanders.... | 4226 | break; |
| 4337 | ParticleEditHandle::handleAddResponse(app->_incomingPacket, bytesReceived); | 4227 | |
| 4338 | break; | 4228 | case PACKET_TYPE_PARTICLE_DATA: |
| 4339 | 4229 | case PACKET_TYPE_VOXEL_DATA: | |
| 4340 | case PACKET_TYPE_PARTICLE_DATA: | 4230 | case PACKET_TYPE_VOXEL_ERASE: |
| 4341 | case PACKET_TYPE_VOXEL_DATA: | 4231 | case PACKET_TYPE_OCTREE_STATS: |
| 4342 | case PACKET_TYPE_VOXEL_ERASE: | 4232 | case PACKET_TYPE_ENVIRONMENT_DATA: { |
| 4343 | case PACKET_TYPE_OCTREE_STATS: | 4233 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 4344 | case PACKET_TYPE_ENVIRONMENT_DATA: { | 4234 | "Application::networkReceive()... _voxelProcessor.queueReceivedPacket()"); |
| 4345 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | 4235 | |
| 4346 | "Application::networkReceive()... _voxelProcessor.queueReceivedPacket()"); | 4236 | bool wantExtraDebugging = getLogger()->extraDebugging(); |
| 4347 | 4237 | if (wantExtraDebugging && _incomingPacket[0] == PACKET_TYPE_VOXEL_DATA) { | |
| 4348 | bool wantExtraDebugging = app->getLogger()->extraDebugging(); | 4238 | int numBytesPacketHeader = numBytesForPacketHeader(_incomingPacket); |
| 4349 | if (wantExtraDebugging && app->_incomingPacket[0] == PACKET_TYPE_VOXEL_DATA) { | 4239 | unsigned char* dataAt = _incomingPacket + numBytesPacketHeader; |
| 4350 | int numBytesPacketHeader = numBytesForPacketHeader(app->_incomingPacket); | 4240 | dataAt += sizeof(VOXEL_PACKET_FLAGS); |
| 4351 | unsigned char* dataAt = app->_incomingPacket + numBytesPacketHeader; | 4241 | VOXEL_PACKET_SEQUENCE sequence = (*(VOXEL_PACKET_SEQUENCE*)dataAt); |
| 4352 | dataAt += sizeof(VOXEL_PACKET_FLAGS); | 4242 | dataAt += sizeof(VOXEL_PACKET_SEQUENCE); |
| 4353 | VOXEL_PACKET_SEQUENCE sequence = (*(VOXEL_PACKET_SEQUENCE*)dataAt); | 4243 | VOXEL_PACKET_SENT_TIME sentAt = (*(VOXEL_PACKET_SENT_TIME*)dataAt); |
| 4354 | dataAt += sizeof(VOXEL_PACKET_SEQUENCE); | 4244 | dataAt += sizeof(VOXEL_PACKET_SENT_TIME); |
| 4355 | VOXEL_PACKET_SENT_TIME sentAt = (*(VOXEL_PACKET_SENT_TIME*)dataAt); | 4245 | VOXEL_PACKET_SENT_TIME arrivedAt = usecTimestampNow(); |
| 4356 | dataAt += sizeof(VOXEL_PACKET_SENT_TIME); | 4246 | int flightTime = arrivedAt - sentAt; |
| 4357 | VOXEL_PACKET_SENT_TIME arrivedAt = usecTimestampNow(); | 4247 | |
| 4358 | int flightTime = arrivedAt - sentAt; | 4248 | printf("got PACKET_TYPE_VOXEL_DATA, sequence:%d flightTime:%d\n", sequence, flightTime); |
| 4359 | |||
| 4360 | printf("got PACKET_TYPE_VOXEL_DATA, sequence:%d flightTime:%d\n", sequence, flightTime); | ||
| 4361 | } | ||
| 4362 | |||
| 4363 | // add this packet to our list of voxel packets and process them on the voxel processing | ||
| 4364 | app->_voxelProcessor.queueReceivedPacket(senderSockAddr, app->_incomingPacket, bytesReceived); | ||
| 4365 | break; | ||
| 4366 | } | 4249 | } |
| 4367 | case PACKET_TYPE_METAVOXEL_DATA: | 4250 | |
| 4368 | app->_metavoxels.processData(QByteArray((const char*)app->_incomingPacket, bytesReceived), | 4251 | // add this packet to our list of voxel packets and process them on the voxel processing |
| 4369 | senderSockAddr); | 4252 | _voxelProcessor.queueReceivedPacket(senderSockAddr, _incomingPacket, bytesReceived); |
| 4370 | break; | 4253 | break; |
| 4371 | case PACKET_TYPE_BULK_AVATAR_DATA: | ||
| 4372 | NodeList::getInstance()->processBulkNodeData(senderSockAddr, | ||
| 4373 | app->_incomingPacket, | ||
| 4374 | bytesReceived); | ||
| 4375 | getInstance()->_bandwidthMeter.inputStream(BandwidthMeter::AVATARS).updateValue(bytesReceived); | ||
| 4376 | break; | ||
| 4377 | case PACKET_TYPE_AVATAR_URLS: | ||
| 4378 | processAvatarURLsMessage(app->_incomingPacket, bytesReceived); | ||
| 4379 | break; | ||
| 4380 | case PACKET_TYPE_AVATAR_FACE_VIDEO: | ||
| 4381 | processAvatarFaceVideoMessage(app->_incomingPacket, bytesReceived); | ||
| 4382 | break; | ||
| 4383 | case PACKET_TYPE_DATA_SERVER_GET: | ||
| 4384 | case PACKET_TYPE_DATA_SERVER_PUT: | ||
| 4385 | case PACKET_TYPE_DATA_SERVER_SEND: | ||
| 4386 | case PACKET_TYPE_DATA_SERVER_CONFIRM: | ||
| 4387 | DataServerClient::processMessageFromDataServer(app->_incomingPacket, bytesReceived); | ||
| 4388 | break; | ||
| 4389 | default: | ||
| 4390 | NodeList::getInstance()->processNodeData(senderSockAddr, app->_incomingPacket, bytesReceived); | ||
| 4391 | break; | ||
| 4392 | } | 4254 | } |
| 4255 | case PACKET_TYPE_METAVOXEL_DATA: | ||
| 4256 | _metavoxels.processData(QByteArray((const char*) _incomingPacket, bytesReceived), | ||
| 4257 | senderSockAddr); | ||
| 4258 | break; | ||
| 4259 | case PACKET_TYPE_BULK_AVATAR_DATA: | ||
| 4260 | NodeList::getInstance()->processBulkNodeData(senderSockAddr, | ||
| 4261 | _incomingPacket, | ||
| 4262 | bytesReceived); | ||
| 4263 | getInstance()->_bandwidthMeter.inputStream(BandwidthMeter::AVATARS).updateValue(bytesReceived); | ||
| 4264 | break; | ||
| 4265 | case PACKET_TYPE_AVATAR_URLS: | ||
| 4266 | processAvatarURLsMessage(_incomingPacket, bytesReceived); | ||
| 4267 | break; | ||
| 4268 | case PACKET_TYPE_AVATAR_FACE_VIDEO: | ||
| 4269 | processAvatarFaceVideoMessage(_incomingPacket, bytesReceived); | ||
| 4270 | break; | ||
| 4271 | case PACKET_TYPE_DATA_SERVER_GET: | ||
| 4272 | case PACKET_TYPE_DATA_SERVER_PUT: | ||
| 4273 | case PACKET_TYPE_DATA_SERVER_SEND: | ||
| 4274 | case PACKET_TYPE_DATA_SERVER_CONFIRM: | ||
| 4275 | DataServerClient::processMessageFromDataServer(_incomingPacket, bytesReceived); | ||
| 4276 | break; | ||
| 4277 | default: | ||
| 4278 | NodeList::getInstance()->processNodeData(senderSockAddr, _incomingPacket, bytesReceived); | ||
| 4279 | break; | ||
| 4393 | } | 4280 | } |
| 4394 | } else if (!app->_enableNetworkThread) { | ||
| 4395 | break; | ||
| 4396 | } | 4281 | } |
| 4397 | } | 4282 | } |
| 4398 | |||
| 4399 | if (app->_enableNetworkThread) { | ||
| 4400 | pthread_exit(0); | ||
| 4401 | } | ||
| 4402 | return NULL; | ||
| 4403 | } | 4283 | } |
| 4404 | 4284 | ||
| 4405 | void Application::packetSentNotification(ssize_t length) { | 4285 | void Application::packetSentNotification(ssize_t length) { |