History

Merge branch 'master' of git://github.com/worklist/hifi into 19485

Lucas Crisman committed 12 years ago

Commit 73dfc5d2 parents 2410374 8325753158 files · +4174 −4205Browse files

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

Unified · Split

interface/src/Application.cpp+237−372
@@ -55,7 +55,6 @@ · 54 unmodified lines
5555 #include "Menu.h"
5656 #include "Swatch.h"
5757 #include "Util.h"
58−#include "devices/LeapManager.h"
5958 #include "devices/OculusManager.h"
6059 #include "devices/TV3DManager.h"
6160 #include "renderer/ProgramObject.h"
@@ -86,17 +85,16 @@ const float MIRROR_FULLSCREEN_DISTANCE = 0.35f; · 24 unmodified lines
8685 const float MIRROR_REARVIEW_DISTANCE = 0.65f;
8786 const float MIRROR_REARVIEW_BODY_DISTANCE = 2.3f;
8887
89−
9088 void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) {
91− fprintf(stdout, "%s", message.toLocal8Bit().constData());
92− Application::getInstance()->getLogger()->addMessage(message.toLocal8Bit().constData());
89+ QString messageWithNewLine = message + "\n";
90+ fprintf(stdout, "%s", messageWithNewLine.toLocal8Bit().constData());
91+ Application::getInstance()->getLogger()->addMessage(messageWithNewLine.toLocal8Bit().constData());
9392 }
9493
9594 Application::Application(int& argc, char** argv, timeval &startup_time) :
9695 QApplication(argc, argv),
9796 _window(new QMainWindow(desktop())),
9897 _glWidget(new GLCanvas()),
99− _displayLevels(false),
10098 _frameCount(0),
10199 _fps(120.0f),
102100 _justStarted(true),
@@ -130,7 +128,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 27 unmodified lines
130128 _perfStatsOn(false),
131129 _chatEntryOn(false),
132130 _audio(&_audioScope, STARTUP_JITTER_SAMPLES),
133− _stopNetworkReceiveThread(false),
131+ _enableProcessVoxelsThread(true),
134132 _voxelProcessor(),
135133 _voxelHideShowThread(&_voxels),
136134 _voxelEditSender(this),
@@ -143,7 +141,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 6 unmodified lines
143141 _resetRecentMaxPacketsSoon(true),
144142 _swatch(NULL),
145143 _pasteMode(false),
146− _logger(new FileLogger())
144+ _logger(new FileLogger()),
145+ _persistThread(NULL)
147146 {
148147 _applicationStartupTime = startup_time;
149148
@@ -156,7 +155,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 6 unmodified lines
156155 // call Menu getInstance static method to set up the menu
157156 _window->setMenuBar(Menu::getInstance());
158157
159− qDebug("[VERSION] Build sequence: %i\n", BUILD_VERSION);
158+ qDebug("[VERSION] Build sequence: %i", BUILD_VERSION);
160159
161160 unsigned int listenPort = 0; // bind to an ephemeral port by default
162161 const char** constArgv = const_cast<const char**>(argv);
@@ -166,6 +165,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 3 unmodified lines
166165 }
167166
168167 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()));
169171
170172 // put the audio processing on a separate thread
171173 QThread* audioThread = new QThread(this);
@@ -174,14 +176,12 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 2 unmodified lines
174176 connect(audioThread, SIGNAL(started()), &_audio, SLOT(start()));
175177
176178 audioThread->start();
179+
180+ connect(nodeList, SIGNAL(domainChanged(const QString&)), SLOT(domainChanged(const QString&)));
177181
178− nodeList->addHook(&_voxels);
179− nodeList->addHook(this);
180− nodeList->addDomainListener(this);
181− nodeList->addDomainListener(&_voxels);
182−
183− // network receive thread and voxel parsing thread are both controlled by the --nonblocking command line
184− _enableProcessVoxelsThread = _enableNetworkThread = !cmdOptionExists(argc, constArgv, "--nonblocking");
182+ connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer)));
183+ connect(nodeList, SIGNAL(nodeAdded(SharedNodePointer)), &_voxels, SLOT(nodeAdded(SharedNodePointer)));
184+ connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), &_voxels, SLOT(nodeKilled(SharedNodePointer)));
185185
186186 // read the ApplicationInfo.ini file for Name/Version/Domain information
187187 QSettings applicationInfo("resources/info/ApplicationInfo.ini", QSettings::IniFormat);
@@ -209,8 +209,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 21 unmodified lines
209209 #endif
210210
211211 // tell the NodeList instance who to tell the domain server we care about
212− const char nodeTypesOfInterest[] = {NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER, NODE_TYPE_VOXEL_SERVER,
213− NODE_TYPE_PARTICLE_SERVER};
212+ const char nodeTypesOfInterest[] = {NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER, NODE_TYPE_VOXEL_SERVER,
213+ NODE_TYPE_PARTICLE_SERVER, NODE_TYPE_METAVOXEL_SERVER};
214214 nodeList->setNodeTypesOfInterest(nodeTypesOfInterest, sizeof(nodeTypesOfInterest));
215215
216216 QTimer* silentNodeTimer = new QTimer(this);
@@ -250,6 +250,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 33 unmodified lines
250250
251251 // Set the sixense filtering
252252 _sixenseManager.setFilter(Menu::getInstance()->isOptionChecked(MenuOption::FilterSixense));
253+
253254 }
254255
255256 Application::~Application() {
@@ -264,9 +265,6 @@ Application::~Application() { · 8 unmodified lines
264265 _audio.thread()->wait();
265266
266267 storeSizeAndPosition();
267− NodeList::getInstance()->removeHook(&_voxels);
268− NodeList::getInstance()->removeHook(this);
269− NodeList::getInstance()->removeDomainListener(this);
270268
271269 _sharedVoxelSystem.changeTree(new VoxelTree);
272270
@@ -275,7 +273,6 @@ Application::~Application() { · 2 unmodified lines
275273
276274 delete _logger;
277275 delete _settings;
278− delete _followMode;
279276 delete _glWidget;
280277 }
281278
@@ -311,7 +308,7 @@ void Application::storeSizeAndPosition() { · 29 unmodified lines
311308 }
312309
313310 void Application::initializeGL() {
314− qDebug( "Created Display Window.\n" );
311+ qDebug( "Created Display Window.");
315312
316313 // initialize glut for shape drawing; Qt apparently initializes it on OS X
317314 #ifndef __APPLE__
@@ -326,16 +323,10 @@ void Application::initializeGL() { · 8 unmodified lines
326323 _viewFrustumOffsetCamera.setFarClip(500.0 * TREE_SCALE);
327324
328325 initDisplay();
329− qDebug( "Initialized Display.\n" );
326+ qDebug( "Initialized Display.");
330327
331328 init();
332− qDebug( "Init() complete.\n" );
333−
334− // create thread for receipt of data via UDP
335− if (_enableNetworkThread) {
336− pthread_create(&_networkReceiveThread, NULL, networkReceive, NULL);
337− qDebug("Network receive thread created.\n");
338− }
329+ qDebug( "init() complete.");
339330
340331 // create thread for parsing of voxel data independent of the main network and rendering threads
341332 _voxelProcessor.initialize(_enableProcessVoxelsThread);
@@ -343,7 +334,7 @@ void Application::initializeGL() { · 1 unmodified line
343334 _voxelHideShowThread.initialize(_enableProcessVoxelsThread);
344335 _particleEditSender.initialize(_enableProcessVoxelsThread);
345336 if (_enableProcessVoxelsThread) {
346− qDebug("Voxel parsing thread created.\n");
337+ qDebug("Voxel parsing thread created.");
347338 }
348339
349340 // call terminate before exiting
@@ -363,9 +354,7 @@ void Application::initializeGL() { · 13 unmodified lines
363354 if (_justStarted) {
364355 float startupTime = (usecTimestampNow() - usecTimestamp(&_applicationStartupTime)) / 1000000.0;
365356 _justStarted = false;
366− char title[50];
367− sprintf(title, "Interface: %4.2f seconds\n", startupTime);
368− qDebug("%s", title);
357+ qDebug("Startup time: %4.2f seconds.", startupTime);
369358 const char LOGSTASH_INTERFACE_START_TIME_KEY[] = "interface-start-time";
370359
371360 // ask the Logstash class to record the startup time
@@ -672,9 +661,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 300 unmodified lines
672661 _audioScope.inputPaused = !_audioScope.inputPaused;
673662 break;
674663 case Qt::Key_L:
675− if (!isShifted && !isMeta) {
676− _displayLevels = !_displayLevels;
677− } else if (isShifted) {
664+ if (isShifted) {
678665 Menu::getInstance()->triggerOption(MenuOption::LodTools);
679666 } else if (isMeta) {
680667 Menu::getInstance()->triggerOption(MenuOption::Log);
@@ -1125,7 +1112,7 @@ void Application::mouseMoveEvent(QMouseEvent* event) { · 444 unmodified lines
11251112 return;
11261113 }
11271114 if (_isHoverVoxel) {
1128− _myAvatar.orbit(glm::vec3(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z) * (float)TREE_SCALE, deltaX, deltaY);
1115+ _myAvatar.orbit(getMouseVoxelWorldCoordinates(_hoverVoxel), deltaX, deltaY);
11291116 return;
11301117 }
11311118 }
@@ -1285,7 +1272,7 @@ void Application::wheelEvent(QWheelEvent* event) { · 153 unmodified lines
12851272 void Application::sendPingPackets() {
12861273
12871274 const char nodesToPing[] = {NODE_TYPE_VOXEL_SERVER, NODE_TYPE_PARTICLE_SERVER,
1288− NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER};
1275+ NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER, NODE_TYPE_METAVOXEL_SERVER};
12891276
12901277 unsigned char pingPacket[MAX_PACKET_SIZE];
12911278 int length = NodeList::getInstance()->fillPingPacket(pingPacket);
@@ -1343,16 +1330,12 @@ void Application::timer() { · 51 unmodified lines
13431330
13441331 gettimeofday(&_timerStart, NULL);
13451332
1346− // if we haven't detected gyros, check for them now
1347− if (!_serialHeadSensor.isActive()) {
1348− _serialHeadSensor.pair();
1349− }
1350−
13511333 // ask the node list to check in with the domain server
13521334 NodeList::getInstance()->sendDomainServerCheckIn();
13531335
1354− // give the MyAvatar object position to the Profile so it can propagate to the data-server
1336+ // give the MyAvatar object position, orientation to the Profile so it can propagate to the data-server
13551337 _profile.updatePosition(_myAvatar.getPosition());
1338+ _profile.updateOrientation(_myAvatar.getOrientation());
13561339 }
13571340
13581341 static glm::vec3 getFaceVector(BoxFace face) {
@@ -1421,7 +1404,6 @@ void Application::terminate() { · 62 unmodified lines
14211404 // Close serial port
14221405 // close(serial_fd);
14231406
1424− LeapManager::terminate();
14251407 Menu::getInstance()->saveSettings();
14261408 _rearMirrorTools->saveSettings(_settings);
14271409 _settings->sync();
@@ -1429,22 +1411,19 @@ void Application::terminate() { · 1 unmodified line
14291411 // let the avatar mixer know we're out
14301412 NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1);
14311413
1432− if (_enableNetworkThread) {
1433− _stopNetworkReceiveThread = true;
1434− pthread_join(_networkReceiveThread, NULL);
1435− }
1436−
14371414 printf("");
14381415 _voxelProcessor.terminate();
14391416 _voxelHideShowThread.terminate();
14401417 _voxelEditSender.terminate();
14411418 _particleEditSender.terminate();
1419+ _persistThread->terminate();
1420+ _persistThread = NULL;
14421421 }
14431422
14441423 static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& dataBytes) {
14451424 // record the packet for stats-tracking
14461425 Application::getInstance()->getBandwidthMeter()->inputStream(BandwidthMeter::AVATARS).updateValue(dataBytes);
1447− Node* avatarMixerNode = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
1426+ SharedNodePointer avatarMixerNode = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
14481427 if (avatarMixerNode) {
14491428 avatarMixerNode->recordBytesReceived(dataBytes);
14501429 }
@@ -1461,7 +1440,7 @@ static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& da · 10 unmodified lines
14611440 dataBytes -= NUM_BYTES_RFC4122_UUID;
14621441
14631442 // make sure the node exists
1464− Node* node = NodeList::getInstance()->nodeWithUUID(nodeUUID);
1443+ SharedNodePointer node = NodeList::getInstance()->nodeWithUUID(nodeUUID);
14651444 if (!node || !node->getLinkedData()) {
14661445 return NULL;
14671446 }
@@ -1620,10 +1599,9 @@ void Application::makeVoxel(glm::vec3 position, · 152 unmodified lines
16201599 isDestructive);
16211600 }
16221601
1623−const glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel) {
1624− return glm::vec3((_mouseVoxel.x + _mouseVoxel.s / 2.f) * TREE_SCALE,
1625− (_mouseVoxel.y + _mouseVoxel.s / 2.f) * TREE_SCALE,
1626− (_mouseVoxel.z + _mouseVoxel.s / 2.f) * TREE_SCALE);
1602+glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVoxel) {
1603+ return glm::vec3((mouseVoxel.x + mouseVoxel.s / 2.f) * TREE_SCALE, (mouseVoxel.y + mouseVoxel.s / 2.f) * TREE_SCALE,
1604+ (mouseVoxel.z + mouseVoxel.s / 2.f) * TREE_SCALE);
16271605 }
16281606
16291607 const float NUDGE_PRECISION_MIN = 1 / pow(2.0, 12.0);
@@ -1710,9 +1688,9 @@ void Application::exportVoxels() { · 80 unmodified lines
17101688
17111689 void Application::importVoxels() {
17121690 if (_voxelImporter.exec()) {
1713− qDebug("[DEBUG] Import succedded.\n");
1691+ qDebug("[DEBUG] Import succeeded.");
17141692 } else {
1715− qDebug("[DEBUG] Import failed.\n");
1693+ qDebug("[DEBUG] Import failed.");
17161694 }
17171695
17181696 // restore the main window's active state
@@ -1886,8 +1864,6 @@ void Application::init() { · 167 unmodified lines
18861864 Qt::QueuedConnection);
18871865 }
18881866
1889− LeapManager::initialize();
1890−
18911867 gettimeofday(&_timerStart, NULL);
18921868 gettimeofday(&_lastTimeUpdated, NULL);
18931869
@@ -1895,7 +1871,7 @@ void Application::init() { · 1 unmodified line
18951871 if (Menu::getInstance()->getAudioJitterBufferSamples() != 0) {
18961872 _audio.setJitterBufferSamples(Menu::getInstance()->getAudioJitterBufferSamples());
18971873 }
1898− qDebug("Loaded settings.\n");
1874+ qDebug("Loaded settings");
18991875
19001876 if (!_profile.getUsername().isEmpty()) {
19011877 // we have a username for this avatar, ask the data-server for the mesh URL for this avatar
@@ -1929,10 +1905,6 @@ void Application::init() { · 27 unmodified lines
19291905 _glWidget->width(),
19301906 _glWidget->height());
19311907
1932− _followMode = new QAction(this);
1933− connect(_followMode, SIGNAL(triggered()), this, SLOT(toggleFollowMode()));
1934− _pieMenu.addAction(_followMode);
1935−
19361908 _audio.init(_glWidget);
19371909
19381910 _rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect, _settings);
@@ -1940,6 +1912,9 @@ void Application::init() { · 1 unmodified line
19401912 connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView()));
19411913 connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));
19421914 connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors()));
1915+
1916+
1917+ updateLocalOctreeCache(true);
19431918 }
19441919
19451920 void Application::closeMirrorView() {
@@ -1987,16 +1962,16 @@ void Application::updateLookatTargetAvatar(const glm::vec3& mouseRayOrigin, cons · 41 unmodified lines
19871962 Avatar* Application::findLookatTargetAvatar(const glm::vec3& mouseRayOrigin, const glm::vec3& mouseRayDirection,
19881963 glm::vec3& eyePosition, QUuid& nodeUUID = DEFAULT_NODE_ID_REF) {
19891964
1990− NodeList* nodeList = NodeList::getInstance();
1991− for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
1965+ foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
19921966 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
19931967 Avatar* avatar = (Avatar*)node->getLinkedData();
19941968 float distance;
1969+
19951970 if (avatar->findRayIntersection(mouseRayOrigin, mouseRayDirection, distance)) {
19961971 // rescale to compensate for head embiggening
19971972 eyePosition = (avatar->getHead().calculateAverageEyePosition() - avatar->getHead().getScalePivot()) *
1998− (avatar->getScale() / avatar->getHead().getScale()) + avatar->getHead().getScalePivot();
1999−
1973+ (avatar->getScale() / avatar->getHead().getScale()) + avatar->getHead().getScalePivot();
1974+
20001975 _lookatIndicatorScale = avatar->getHead().getScale();
20011976 _lookatOtherPosition = avatar->getHead().getPosition();
20021977 nodeUUID = avatar->getOwningNode()->getUUID();
@@ -2004,6 +1979,7 @@ Avatar* Application::findLookatTargetAvatar(const glm::vec3& mouseRayOrigin, con · 1 unmodified line
20041979 }
20051980 }
20061981 }
1982+
20071983 return NULL;
20081984 }
20091985
@@ -2028,71 +2004,6 @@ void Application::renderLookatIndicator(glm::vec3 pointOfInterest) { · 18 unmodified lines
20282004 renderCircle(haloOrigin, INDICATOR_RADIUS, IDENTITY_UP, NUM_SEGMENTS);
20292005 }
20302006
2031−void maybeBeginFollowIndicator(bool& began) {
2032− if (!began) {
2033− Application::getInstance()->getGlowEffect()->begin();
2034− glLineWidth(5);
2035− glBegin(GL_LINES);
2036− began = true;
2037− }
2038−}
2039−
2040−void Application::renderFollowIndicator() {
2041− NodeList* nodeList = NodeList::getInstance();
2042−
2043− // initialize lazily so that we don't enable the glow effect unnecessarily
2044− bool began = false;
2045−
2046− for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); ++node) {
2047− if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
2048− Avatar* avatar = (Avatar *) node->getLinkedData();
2049− Avatar* leader = NULL;
2050−
2051− if (!avatar->getLeaderUUID().isNull()) {
2052− if (avatar->getLeaderUUID() == NodeList::getInstance()->getOwnerUUID()) {
2053− leader = &_myAvatar;
2054− } else {
2055− for (NodeList::iterator it = nodeList->begin(); it != nodeList->end(); ++it) {
2056− if(it->getUUID() == avatar->getLeaderUUID()
2057− && it->getType() == NODE_TYPE_AGENT) {
2058− leader = (Avatar*) it->getLinkedData();
2059− }
2060− }
2061− }
2062−
2063− if (leader != NULL) {
2064− maybeBeginFollowIndicator(began);
2065− glColor3f(1.f, 0.f, 0.f);
2066− glVertex3f((avatar->getHead().getPosition().x + avatar->getPosition().x) / 2.f,
2067− (avatar->getHead().getPosition().y + avatar->getPosition().y) / 2.f,
2068− (avatar->getHead().getPosition().z + avatar->getPosition().z) / 2.f);
2069− glColor3f(0.f, 1.f, 0.f);
2070− glVertex3f((leader->getHead().getPosition().x + leader->getPosition().x) / 2.f,
2071− (leader->getHead().getPosition().y + leader->getPosition().y) / 2.f,
2072− (leader->getHead().getPosition().z + leader->getPosition().z) / 2.f);
2073− }
2074− }
2075− }
2076− }
2077−
2078− if (_myAvatar.getLeadingAvatar() != NULL) {
2079− maybeBeginFollowIndicator(began);
2080− glColor3f(1.f, 0.f, 0.f);
2081− glVertex3f((_myAvatar.getHead().getPosition().x + _myAvatar.getPosition().x) / 2.f,
2082− (_myAvatar.getHead().getPosition().y + _myAvatar.getPosition().y) / 2.f,
2083− (_myAvatar.getHead().getPosition().z + _myAvatar.getPosition().z) / 2.f);
2084− glColor3f(0.f, 1.f, 0.f);
2085− glVertex3f((_myAvatar.getLeadingAvatar()->getHead().getPosition().x + _myAvatar.getLeadingAvatar()->getPosition().x) / 2.f,
2086− (_myAvatar.getLeadingAvatar()->getHead().getPosition().y + _myAvatar.getLeadingAvatar()->getPosition().y) / 2.f,
2087− (_myAvatar.getLeadingAvatar()->getHead().getPosition().z + _myAvatar.getLeadingAvatar()->getPosition().z) / 2.f);
2088− }
2089−
2090− if (began) {
2091− glEnd();
2092− _glowEffect.end();
2093− }
2094−}
2095−
20962007 void Application::renderHighlightVoxel(VoxelDetail voxel) {
20972008 glDisable(GL_LIGHTING);
20982009 glPushMatrix();
@@ -2110,10 +2021,9 @@ void Application::renderHighlightVoxel(VoxelDetail voxel) { · 11 unmodified lines
21102021 void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm::vec3 mouseRayDirection) {
21112022 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
21122023 PerformanceWarning warn(showWarnings, "Application::updateAvatars()");
2113− NodeList* nodeList = NodeList::getInstance();
2114−
2115− for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
2116− node->lock();
2024+
2025+ foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
2026+ QMutexLocker(&node->getMutex());
21172027 if (node->getLinkedData()) {
21182028 Avatar *avatar = (Avatar *)node->getLinkedData();
21192029 if (!avatar->isInitialized()) {
@@ -2122,16 +2032,18 @@ void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm:: · 2 unmodified lines
21222032 avatar->simulate(deltaTime, NULL);
21232033 avatar->setMouseRay(mouseRayOrigin, mouseRayDirection);
21242034 }
2125− node->unlock();
21262035 }
21272036
21282037 // simulate avatar fades
21292038 for (vector<Avatar*>::iterator fade = _avatarFades.begin(); fade != _avatarFades.end(); fade++) {
21302039 Avatar* avatar = *fade;
21312040 const float SHRINK_RATE = 0.9f;
2132− avatar->setNewScale(avatar->getNewScale() * SHRINK_RATE);
2133− const float MINIMUM_SCALE = 0.001f;
2134− if (avatar->getNewScale() < MINIMUM_SCALE) {
2041+
2042+ avatar->setTargetScale(avatar->getScale() * SHRINK_RATE);
2043+
2044+ const float MIN_FADE_SCALE = 0.001;
2045+
2046+ if (avatar->getTargetScale() < MIN_FADE_SCALE) {
21352047 delete avatar;
21362048 _avatarFades.erase(fade--);
21372049
@@ -2367,9 +2279,6 @@ void Application::updateHandAndTouch(float deltaTime) { · 229 unmodified lines
23672279 void Application::updateLeap(float deltaTime) {
23682280 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
23692281 PerformanceWarning warn(showWarnings, "Application::updateLeap()");
2370−
2371− LeapManager::enableFakeFingers(Menu::getInstance()->isOptionChecked(MenuOption::SimulateLeapHand));
2372− LeapManager::nextFrame();
23732282 }
23742283
23752284 void Application::updateSixense(float deltaTime) {
@@ -2382,27 +2291,19 @@ void Application::updateSixense(float deltaTime) { · 6 unmodified lines
23822291 void Application::updateSerialDevices(float deltaTime) {
23832292 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
23842293 PerformanceWarning warn(showWarnings, "Application::updateSerialDevices()");
2385−
2386− if (_serialHeadSensor.isActive()) {
2387− _serialHeadSensor.readData(deltaTime);
2388− }
23892294 }
23902295
23912296 void Application::updateThreads(float deltaTime) {
23922297 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
23932298 PerformanceWarning warn(showWarnings, "Application::updateThreads()");
23942299
2395− // read incoming packets from network
2396− if (!_enableNetworkThread) {
2397− networkReceive(0);
2398− }
2399−
24002300 // parse voxel packets
24012301 if (!_enableProcessVoxelsThread) {
24022302 _voxelProcessor.threadRoutine();
24032303 _voxelHideShowThread.threadRoutine();
24042304 _voxelEditSender.threadRoutine();
24052305 _particleEditSender.threadRoutine();
2306+ _persistThread->threadRoutine();
24062307 }
24072308 }
24082309
@@ -2628,41 +2529,6 @@ void Application::updateAvatar(float deltaTime) { · 219 unmodified lines
26282529 _headMouseY -= headVelocity.x * HEADMOUSE_FACESHIFT_PITCH_SCALE;
26292530 }
26302531
2631− if (_serialHeadSensor.isActive()) {
2632−
2633− // Grab latest readings from the gyros
2634− float measuredPitchRate = _serialHeadSensor.getLastPitchRate();
2635− float measuredYawRate = _serialHeadSensor.getLastYawRate();
2636−
2637− // Update gyro-based mouse (X,Y on screen)
2638− const float MIN_MOUSE_RATE = 3.0;
2639− const float HORIZONTAL_PIXELS_PER_DEGREE = 2880.f / 45.f;
2640− const float VERTICAL_PIXELS_PER_DEGREE = 1800.f / 30.f;
2641− if (powf(measuredYawRate * measuredYawRate +
2642− measuredPitchRate * measuredPitchRate, 0.5) > MIN_MOUSE_RATE) {
2643− _headMouseX -= measuredYawRate * HORIZONTAL_PIXELS_PER_DEGREE * deltaTime;
2644− _headMouseY -= measuredPitchRate * VERTICAL_PIXELS_PER_DEGREE * deltaTime;
2645− }
2646−
2647− const float MIDPOINT_OF_SCREEN = 0.5;
2648−
2649− // Only use gyro to set lookAt if mouse hasn't selected an avatar
2650− if (!_lookatTargetAvatar) {
2651−
2652− // Set lookAtPosition if an avatar is at the center of the screen
2653− glm::vec3 screenCenterRayOrigin, screenCenterRayDirection;
2654− _viewFrustum.computePickRay(MIDPOINT_OF_SCREEN, MIDPOINT_OF_SCREEN, screenCenterRayOrigin, screenCenterRayDirection);
2655−
2656− glm::vec3 eyePosition;
2657− updateLookatTargetAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition);
2658− if (_lookatTargetAvatar) {
2659− glm::vec3 myLookAtFromMouse(eyePosition);
2660− _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
2661− }
2662− }
2663−
2664− }
2665−
26662532 // Constrain head-driven mouse to edges of screen
26672533 _headMouseX = glm::clamp(_headMouseX, 0, _glWidget->width());
26682534 _headMouseY = glm::clamp(_headMouseY, 0, _glWidget->height());
@@ -2743,39 +2609,36 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 74 unmodified lines
27432609
27442610 unsigned char voxelQueryPacket[MAX_PACKET_SIZE];
27452611
2746− NodeList* nodeList = NodeList::getInstance();
2747−
27482612 // Iterate all of the nodes, and get a count of how many voxel servers we have...
27492613 int totalServers = 0;
27502614 int inViewServers = 0;
27512615 int unknownJurisdictionServers = 0;
2752−
2753− for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
2754−
2616+
2617+ foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
27552618 // only send to the NodeTypes that are serverType
27562619 if (node->getActiveSocket() != NULL && node->getType() == serverType) {
27572620 totalServers++;
2758−
2621+
27592622 // get the server bounds for this server
27602623 QUuid nodeUUID = node->getUUID();
2761−
2624+
27622625 // if we haven't heard from this voxel server, go ahead and send it a query, so we
27632626 // can get the jurisdiction...
27642627 if (jurisdictions.find(nodeUUID) == jurisdictions.end()) {
27652628 unknownJurisdictionServers++;
27662629 } else {
27672630 const JurisdictionMap& map = (jurisdictions)[nodeUUID];
2768−
2631+
27692632 unsigned char* rootCode = map.getRootOctalCode();
2770−
2633+
27712634 if (rootCode) {
27722635 VoxelPositionSize rootDetails;
27732636 voxelDetailsForCode(rootCode, rootDetails);
27742637 AABox serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s);
27752638 serverBounds.scale(TREE_SCALE);
2776−
2639+
27772640 ViewFrustum::location serverFrustumLocation = _viewFrustum.boxInFrustum(serverBounds);
2778−
2641+
27792642 if (serverFrustumLocation != ViewFrustum::OUTSIDE) {
27802643 inViewServers++;
27812644 }
@@ -2785,7 +2648,7 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 3 unmodified lines
27852648 }
27862649
27872650 if (wantExtraDebugging && unknownJurisdictionServers > 0) {
2788− qDebug("Servers: total %d, in view %d, unknown jurisdiction %d \n",
2651+ qDebug("Servers: total %d, in view %d, unknown jurisdiction %d",
27892652 totalServers, inViewServers, unknownJurisdictionServers);
27902653 }
27912654
@@ -2806,38 +2669,40 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 14 unmodified lines
28062669 }
28072670
28082671 if (wantExtraDebugging && unknownJurisdictionServers > 0) {
2809− qDebug("perServerPPS: %d perUnknownServer: %d\n", perServerPPS, perUnknownServer);
2672+ qDebug("perServerPPS: %d perUnknownServer: %d", perServerPPS, perUnknownServer);
28102673 }
2811−
2812− for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
2674+
2675+ NodeList* nodeList = NodeList::getInstance();
2676+
2677+ foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {
28132678 // only send to the NodeTypes that are serverType
28142679 if (node->getActiveSocket() != NULL && node->getType() == serverType) {
2815−
2816−
2680+
2681+
28172682 // get the server bounds for this server
28182683 QUuid nodeUUID = node->getUUID();
2819−
2684+
28202685 bool inView = false;
28212686 bool unknownView = false;
2822−
2687+
28232688 // if we haven't heard from this voxel server, go ahead and send it a query, so we
28242689 // can get the jurisdiction...
28252690 if (jurisdictions.find(nodeUUID) == jurisdictions.end()) {
28262691 unknownView = true; // assume it's in view
28272692 if (wantExtraDebugging) {
2828− qDebug() << "no known jurisdiction for node " << *node << ", assume it's visible.\n";
2693+ qDebug() << "no known jurisdiction for node " << *node << ", assume it's visible.";
28292694 }
28302695 } else {
28312696 const JurisdictionMap& map = (jurisdictions)[nodeUUID];
2832−
2697+
28332698 unsigned char* rootCode = map.getRootOctalCode();
2834−
2699+
28352700 if (rootCode) {
28362701 VoxelPositionSize rootDetails;
28372702 voxelDetailsForCode(rootCode, rootDetails);
28382703 AABox serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s);
28392704 serverBounds.scale(TREE_SCALE);
2840−
2705+
28412706 ViewFrustum::location serverFrustumLocation = _viewFrustum.boxInFrustum(serverBounds);
28422707 if (serverFrustumLocation != ViewFrustum::OUTSIDE) {
28432708 inView = true;
@@ -2846,19 +2711,19 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 2 unmodified lines
28462711 }
28472712 } else {
28482713 if (wantExtraDebugging) {
2849− qDebug() << "Jurisdiction without RootCode for node " << *node << ". That's unusual!\n";
2714+ qDebug() << "Jurisdiction without RootCode for node " << *node << ". That's unusual!";
28502715 }
28512716 }
28522717 }
2853−
2718+
28542719 if (inView) {
28552720 _voxelQuery.setMaxOctreePacketsPerSecond(perServerPPS);
28562721 } else if (unknownView) {
28572722 if (wantExtraDebugging) {
28582723 qDebug() << "no known jurisdiction for node " << *node << ", give it budget of "
2859− << perUnknownServer << " to send us jurisdiction.\n";
2724+ << perUnknownServer << " to send us jurisdiction.";
28602725 }
2861−
2726+
28622727 // set the query's position/orientation to be degenerate in a manner that will get the scene quickly
28632728 // If there's only one server, then don't do this, and just let the normal voxel query pass through
28642729 // as expected... this way, we will actually get a valid scene if there is one to be seen
@@ -2869,11 +2734,11 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 4 unmodified lines
28692734 _voxelQuery.setCameraNearClip(0.1);
28702735 _voxelQuery.setCameraFarClip(0.1);
28712736 if (wantExtraDebugging) {
2872− qDebug() << "Using 'minimal' camera position for node " << *node << "\n";
2737+ qDebug() << "Using 'minimal' camera position for node" << *node;
28732738 }
28742739 } else {
28752740 if (wantExtraDebugging) {
2876− qDebug() << "Using regular camera position for node " << *node << "\n";
2741+ qDebug() << "Using regular camera position for node" << *node;
28772742 }
28782743 }
28792744 _voxelQuery.setMaxOctreePacketsPerSecond(perUnknownServer);
@@ -2882,24 +2747,24 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 2 unmodified lines
28822747 }
28832748 // set up the packet for sending...
28842749 unsigned char* endOfVoxelQueryPacket = voxelQueryPacket;
2885−
2750+
28862751 // insert packet type/version and node UUID
28872752 endOfVoxelQueryPacket += populateTypeAndVersion(endOfVoxelQueryPacket, packetType);
28882753 QByteArray ownerUUID = nodeList->getOwnerUUID().toRfc4122();
28892754 memcpy(endOfVoxelQueryPacket, ownerUUID.constData(), ownerUUID.size());
28902755 endOfVoxelQueryPacket += ownerUUID.size();
2891−
2756+
28922757 // encode the query data...
28932758 endOfVoxelQueryPacket += _voxelQuery.getBroadcastData(endOfVoxelQueryPacket);
2894−
2759+
28952760 int packetLength = endOfVoxelQueryPacket - voxelQueryPacket;
2896−
2761+
28972762 // make sure we still have an active socket
28982763 if (node->getActiveSocket()) {
28992764 nodeList->getNodeSocket().writeDatagram((char*) voxelQueryPacket, packetLength,
2900− node->getActiveSocket()->getAddress(), node->getActiveSocket()->getPort());
2765+ node->getActiveSocket()->getAddress(), node->getActiveSocket()->getPort());
29012766 }
2902−
2767+
29032768 // Feed number of bytes to corresponding channel of the bandwidth meter
29042769 _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(packetLength);
29052770 }
@@ -3256,12 +3121,6 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { · 350 unmodified lines
32563121 }
32573122 }
32583123
3259− {
3260− PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
3261− "Application::displaySide() ... renderFollowIndicator...");
3262− renderFollowIndicator();
3263− }
3264−
32653124 // render transmitter pick ray, if non-empty
32663125 if (_transmitterPickStart != _transmitterPickEnd) {
32673126 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
@@ -3329,8 +3188,7 @@ void Application::displayOverlay() { · 61 unmodified lines
33293188
33303189 //noiseTest(_glWidget->width(), _glWidget->height());
33313190
3332− if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)
3333− && USING_INVENSENSE_MPU9150) {
3191+ if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)) {
33343192 // Display small target box at center or head mouse target that can also be used to measure LOD
33353193 glColor3f(1.0, 1.0, 1.0);
33363194 glDisable(GL_LINE_SMOOTH);
@@ -3366,9 +3224,6 @@ void Application::displayOverlay() { · 29 unmodified lines
33663224 }
33673225 }
33683226
3369− // Show detected levels from the serial I/O ADC channel sensors
3370− if (_displayLevels) _serialHeadSensor.renderLevels(_glWidget->width(), _glWidget->height());
3371−
33723227 // Show hand transmitter data if detected
33733228 if (_myTransmitter.isConnected()) {
33743229 _myTransmitter.renderLevels(_glWidget->width(), _glWidget->height());
@@ -3388,12 +3243,12 @@ void Application::displayOverlay() { · 13 unmodified lines
33883243 glPointSize(1.0f);
33893244 char nodes[100];
33903245
3391− NodeList* nodeList = NodeList::getInstance();
33923246 int totalAvatars = 0, totalServers = 0;
3393−
3394− for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
3247+
3248+ foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
33953249 node->getType() == NODE_TYPE_AGENT ? totalAvatars++ : totalServers++;
33963250 }
3251+
33973252 sprintf(nodes, "Servers: %d, Avatars: %d\n", totalServers, totalAvatars);
33983253 drawtext(_glWidget->width() - 150, 20, 0.10, 0, 1.0, 0, nodes, 1, 0, 0);
33993254 }
@@ -3493,8 +3348,8 @@ void Application::displayStats() { · 93 unmodified lines
34933348 int pingAudio = 0, pingAvatar = 0, pingVoxel = 0, pingVoxelMax = 0;
34943349
34953350 NodeList* nodeList = NodeList::getInstance();
3496− Node* audioMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER);
3497− Node* avatarMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
3351+ SharedNodePointer audioMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER);
3352+ SharedNodePointer avatarMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
34983353
34993354 pingAudio = audioMixerNode ? audioMixerNode->getPingMs() : 0;
35003355 pingAvatar = avatarMixerNode ? avatarMixerNode->getPingMs() : 0;
@@ -3503,7 +3358,8 @@ void Application::displayStats() { · 2 unmodified lines
35033358 // Now handle voxel servers, since there could be more than one, we average their ping times
35043359 unsigned long totalPingVoxel = 0;
35053360 int voxelServerCount = 0;
3506− for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
3361+
3362+ foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {
35073363 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
35083364 totalPingVoxel += node->getPingMs();
35093365 voxelServerCount++;
@@ -3512,6 +3368,7 @@ void Application::displayStats() { · 2 unmodified lines
35123368 }
35133369 }
35143370 }
3371+
35153372 if (voxelServerCount) {
35163373 pingVoxel = totalPingVoxel/voxelServerCount;
35173374 }
@@ -3528,7 +3385,7 @@ void Application::displayStats() { · 10 unmodified lines
35283385 sprintf(avatarStats, "Avatar: pos %.3f, %.3f, %.3f, vel %.1f, yaw = %.2f", avatarPos.x, avatarPos.y, avatarPos.z, glm::length(_myAvatar.getVelocity()), _myAvatar.getBodyYaw());
35293386 drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, avatarStats);
35303387
3531− Node* avatarMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
3388+ SharedNodePointer avatarMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
35323389 char avatarMixerStats[200];
35333390 if (avatarMixer) {
35343391 sprintf(avatarMixerStats, "Avatar Mixer: %.f kbps, %.f pps",
@@ -3660,11 +3517,6 @@ void Application::displayStats() { · 125 unmodified lines
36603517 statsVerticalOffset += PELS_PER_LINE;
36613518 drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, (char*)voxelStats.str().c_str());
36623519
3663−
3664− // Leap data
3665− statsVerticalOffset += PELS_PER_LINE;
3666− drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, (char*)LeapManager::statusString().c_str());
3667−
36683520 if (_perfStatsOn) {
36693521 // Get the PerfStats group details. We need to allocate and array of char* long enough to hold 1+groups
36703522 char** perfStatLinesArray = new char*[PerfStat::getGroupCount()+1];
@@ -3735,9 +3587,6 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { · 64 unmodified lines
37353587
37363588 // render the coverage map on screen
37373589 void Application::renderCoverageMapV2() {
3738−
3739− //qDebug("renderCoverageMap()\n");
3740−
37413590 glDisable(GL_LIGHTING);
37423591 glLineWidth(2.0);
37433592 glBegin(GL_LINES);
@@ -3781,8 +3630,6 @@ void Application::renderCoverageMapsV2Recursively(CoverageMapV2* map) { · 37 unmodified lines
37813630 // render the coverage map on screen
37823631 void Application::renderCoverageMap() {
37833632
3784− //qDebug("renderCoverageMap()\n");
3785−
37863633 glDisable(GL_LIGHTING);
37873634 glLineWidth(2.0);
37883635 glBegin(GL_LINES);
@@ -3857,10 +3704,10 @@ void Application::renderAvatars(bool forceRenderHead, bool selfAvatarOnly) { · 68 unmodified lines
38573704 if (!selfAvatarOnly) {
38583705 // Render avatars of other nodes
38593706 NodeList* nodeList = NodeList::getInstance();
3860−
3861− for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
3862− node->lock();
3863−
3707+
3708+ foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {
3709+ QMutexLocker(&node->getMutex());
3710+
38643711 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
38653712 Avatar *avatar = (Avatar *)node->getLinkedData();
38663713 if (!avatar->isInitialized()) {
@@ -3869,8 +3716,6 @@ void Application::renderAvatars(bool forceRenderHead, bool selfAvatarOnly) { · 2 unmodified lines
38693716 avatar->render(false);
38703717 avatar->setDisplayingLookatVectors(Menu::getInstance()->isOptionChecked(MenuOption::LookAtVectors));
38713718 }
3872−
3873− node->unlock();
38743719 }
38753720
38763721 // render avatar fades
@@ -4115,28 +3960,12 @@ void Application::eyedropperVoxelUnderCursor() { · 238 unmodified lines
41153960 }
41163961 }
41173962
4118−void Application::toggleFollowMode() {
4119− glm::vec3 mouseRayOrigin, mouseRayDirection;
4120− _viewFrustum.computePickRay(_pieMenu.getX() / (float)_glWidget->width(),
4121− _pieMenu.getY() / (float)_glWidget->height(),
4122− mouseRayOrigin, mouseRayDirection);
4123− glm::vec3 eyePositionIgnored;
4124− QUuid nodeUUIDIgnored;
4125− Avatar* leadingAvatar = findLookatTargetAvatar(mouseRayOrigin, mouseRayDirection, eyePositionIgnored, nodeUUIDIgnored);
4126−
4127− _myAvatar.follow(leadingAvatar);
4128−}
4129−
41303963 void Application::resetSensors() {
41313964 _headMouseX = _mouseX = _glWidget->width() / 2;
41323965 _headMouseY = _mouseY = _glWidget->height() / 2;
41333966
4134− if (_serialHeadSensor.isActive()) {
4135− _serialHeadSensor.resetAverages();
4136− }
41373967 _webcam.reset();
41383968 _faceshift.reset();
4139− LeapManager::reset();
41403969
41413970 if (OculusManager::isConnected()) {
41423971 OculusManager::reset();
@@ -4187,13 +4016,13 @@ void Application::updateWindowTitle(){ · 44 unmodified lines
41874016 title += _profile.getLastDomain();
41884017 title += buildVersion;
41894018
4190− qDebug("Application title set to: %s.\n", title.toStdString().c_str());
4019+ qDebug("Application title set to: %s", title.toStdString().c_str());
41914020 _window->setWindowTitle(title);
41924021 }
41934022
4194−void Application::domainChanged(QString domain) {
4023+void Application::domainChanged(const QString& domainHostname) {
41954024 // update the user's last domain in their Profile (which will propagate to data-server)
4196− _profile.updateDomain(domain);
4025+ _profile.updateDomain(domainHostname);
41974026
41984027 updateWindowTitle();
41994028
@@ -4204,13 +4033,13 @@ void Application::domainChanged(QString domain) { · 4 unmodified lines
42044033 _voxelServerJurisdictions.clear();
42054034 _octreeServerSceneStats.clear();
42064035 _particleServerJurisdictions.clear();
4207−}
4208−
4209−void Application::nodeAdded(Node* node) {
42104036
4037+ // reset our persist thread
4038+ qDebug() << "Domain changed to" << domainHostname << ". Swapping persist cache.";
4039+ updateLocalOctreeCache();
42114040 }
42124041
4213−void Application::nodeKilled(Node* node) {
4042+void Application::nodeKilled(SharedNodePointer node) {
42144043 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
42154044 QUuid nodeUUID = node->getUUID();
42164045 // see if this is the first we've heard of this node...
@@ -4290,7 +4119,7 @@ void Application::trackIncomingVoxelPacket(unsigned char* messageData, ssize_t m · 73 unmodified lines
42904119 const HifiSockAddr& senderSockAddr, bool wasStatsPacket) {
42914120
42924121 // Attempt to identify the sender from it's address.
4293− Node* serverNode = NodeList::getInstance()->nodeWithAddress(senderSockAddr);
4122+ SharedNodePointer serverNode = NodeList::getInstance()->nodeWithAddress(senderSockAddr);
42944123 if (serverNode) {
42954124 QUuid nodeUUID = serverNode->getUUID();
42964125
@@ -4307,7 +4136,7 @@ void Application::trackIncomingVoxelPacket(unsigned char* messageData, ssize_t m · 10 unmodified lines
43074136 int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLength, const HifiSockAddr& senderSockAddr) {
43084137
43094138 // But, also identify the sender, and keep track of the contained jurisdiction root for this server
4310− Node* server = NodeList::getInstance()->nodeWithAddress(senderSockAddr);
4139+ SharedNodePointer server = NodeList::getInstance()->nodeWithAddress(senderSockAddr);
43114140
43124141 // parse the incoming stats datas stick it in a temporary object for now, while we
43134142 // determine which server it belongs to
@@ -4364,101 +4193,95 @@ int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLen · 50 unmodified lines
43644193 }
43654194
43664195 // Receive packets from other nodes/servers and decide what to do with them!
4367−void* Application::networkReceive(void* args) {
4196+void Application::processDatagrams() {
43684197 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
43694198 "Application::networkReceive()");
43704199
43714200 HifiSockAddr senderSockAddr;
43724201 ssize_t bytesReceived;
43734202
4374− Application* app = Application::getInstance();
4375− while (!app->_stopNetworkReceiveThread) {
4376− if (NodeList::getInstance()->getNodeSocket().hasPendingDatagrams() &&
4377− (bytesReceived = NodeList::getInstance()->getNodeSocket().readDatagram((char*) app->_incomingPacket,
4378− MAX_PACKET_SIZE,
4379− senderSockAddr.getAddressPointer(),
4380− senderSockAddr.getPortPointer()))) {
4381−
4382− app->_packetCount++;
4383− app->_bytesCount += bytesReceived;
4384−
4385− if (packetVersionMatch(app->_incomingPacket)) {
4386− // only process this packet if we have a match on the packet version
4387− switch (app->_incomingPacket[0]) {
4388− case PACKET_TYPE_TRANSMITTER_DATA_V2:
4389− // V2 = IOS transmitter app
4390− app->_myTransmitter.processIncomingData(app->_incomingPacket, bytesReceived);
4391−
4392− break;
4393− case PACKET_TYPE_MIXED_AUDIO:
4394− QMetaObject::invokeMethod(&app->_audio, "addReceivedAudioToBuffer", Qt::QueuedConnection,
4395− Q_ARG(QByteArray, QByteArray((char*) app->_incomingPacket, bytesReceived)));
4396− break;
4397−
4398− case PACKET_TYPE_PARTICLE_ADD_RESPONSE:
4399− // look up our ParticleEditHanders....
4400− ParticleEditHandle::handleAddResponse(app->_incomingPacket, bytesReceived);
4401− break;
4402−
4403− case PACKET_TYPE_PARTICLE_DATA:
4404− case PACKET_TYPE_VOXEL_DATA:
4405− case PACKET_TYPE_VOXEL_ERASE:
4406− case PACKET_TYPE_OCTREE_STATS:
4407− case PACKET_TYPE_ENVIRONMENT_DATA: {
4408− PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
4409− "Application::networkReceive()... _voxelProcessor.queueReceivedPacket()");
4410−
4411− bool wantExtraDebugging = app->getLogger()->extraDebugging();
4412− if (wantExtraDebugging && app->_incomingPacket[0] == PACKET_TYPE_VOXEL_DATA) {
4413− int numBytesPacketHeader = numBytesForPacketHeader(app->_incomingPacket);
4414− unsigned char* dataAt = app->_incomingPacket + numBytesPacketHeader;
4415− dataAt += sizeof(VOXEL_PACKET_FLAGS);
4416− VOXEL_PACKET_SEQUENCE sequence = (*(VOXEL_PACKET_SEQUENCE*)dataAt);
4417− dataAt += sizeof(VOXEL_PACKET_SEQUENCE);
4418− VOXEL_PACKET_SENT_TIME sentAt = (*(VOXEL_PACKET_SENT_TIME*)dataAt);
4419− dataAt += sizeof(VOXEL_PACKET_SENT_TIME);
4420− VOXEL_PACKET_SENT_TIME arrivedAt = usecTimestampNow();
4421− int flightTime = arrivedAt - sentAt;
4422−
4423− printf("got PACKET_TYPE_VOXEL_DATA, sequence:%d flightTime:%d\n", sequence, flightTime);
4424− }
4425−
4426− // add this packet to our list of voxel packets and process them on the voxel processing
4427− app->_voxelProcessor.queueReceivedPacket(senderSockAddr, app->_incomingPacket, bytesReceived);
4428− break;
4203+ while (NodeList::getInstance()->getNodeSocket().hasPendingDatagrams() &&
4204+ (bytesReceived = NodeList::getInstance()->getNodeSocket().readDatagram((char*) _incomingPacket,
4205+ MAX_PACKET_SIZE,
4206+ senderSockAddr.getAddressPointer(),
4207+ senderSockAddr.getPortPointer()))) {
4208+
4209+ _packetCount++;
4210+ _bytesCount += bytesReceived;
4211+
4212+ if (packetVersionMatch(_incomingPacket)) {
4213+ // only process this packet if we have a match on the packet version
4214+ switch (_incomingPacket[0]) {
4215+ case PACKET_TYPE_TRANSMITTER_DATA_V2:
4216+ // V2 = IOS transmitter app
4217+ _myTransmitter.processIncomingData(_incomingPacket, bytesReceived);
4218+
4219+ break;
4220+ case PACKET_TYPE_MIXED_AUDIO:
4221+ QMetaObject::invokeMethod(&_audio, "addReceivedAudioToBuffer", Qt::QueuedConnection,
4222+ Q_ARG(QByteArray, QByteArray((char*) _incomingPacket, bytesReceived)));
4223+ break;
4224+
4225+ case PACKET_TYPE_PARTICLE_ADD_RESPONSE:
4226+ // look up our ParticleEditHanders....
4227+ ParticleEditHandle::handleAddResponse(_incomingPacket, bytesReceived);
4228+ break;
4229+
4230+ case PACKET_TYPE_PARTICLE_DATA:
4231+ case PACKET_TYPE_VOXEL_DATA:
4232+ case PACKET_TYPE_VOXEL_ERASE:
4233+ case PACKET_TYPE_OCTREE_STATS:
4234+ case PACKET_TYPE_ENVIRONMENT_DATA: {
4235+ PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
4236+ "Application::networkReceive()... _voxelProcessor.queueReceivedPacket()");
4237+
4238+ bool wantExtraDebugging = getLogger()->extraDebugging();
4239+ if (wantExtraDebugging && _incomingPacket[0] == PACKET_TYPE_VOXEL_DATA) {
4240+ int numBytesPacketHeader = numBytesForPacketHeader(_incomingPacket);
4241+ unsigned char* dataAt = _incomingPacket + numBytesPacketHeader;
4242+ dataAt += sizeof(VOXEL_PACKET_FLAGS);
4243+ VOXEL_PACKET_SEQUENCE sequence = (*(VOXEL_PACKET_SEQUENCE*)dataAt);
4244+ dataAt += sizeof(VOXEL_PACKET_SEQUENCE);
4245+ VOXEL_PACKET_SENT_TIME sentAt = (*(VOXEL_PACKET_SENT_TIME*)dataAt);
4246+ dataAt += sizeof(VOXEL_PACKET_SENT_TIME);
4247+ VOXEL_PACKET_SENT_TIME arrivedAt = usecTimestampNow();
4248+ int flightTime = arrivedAt - sentAt;
4249+
4250+ printf("got PACKET_TYPE_VOXEL_DATA, sequence:%d flightTime:%d\n", sequence, flightTime);
44294251 }
4430− case PACKET_TYPE_BULK_AVATAR_DATA:
4431− NodeList::getInstance()->processBulkNodeData(senderSockAddr,
4432− app->_incomingPacket,
4433− bytesReceived);
4434− getInstance()->_bandwidthMeter.inputStream(BandwidthMeter::AVATARS).updateValue(bytesReceived);
4435− break;
4436− case PACKET_TYPE_AVATAR_URLS:
4437− processAvatarURLsMessage(app->_incomingPacket, bytesReceived);
4438− break;
4439− case PACKET_TYPE_AVATAR_FACE_VIDEO:
4440− processAvatarFaceVideoMessage(app->_incomingPacket, bytesReceived);
4441− break;
4442− case PACKET_TYPE_DATA_SERVER_GET:
4443− case PACKET_TYPE_DATA_SERVER_PUT:
4444− case PACKET_TYPE_DATA_SERVER_SEND:
4445− case PACKET_TYPE_DATA_SERVER_CONFIRM:
4446− DataServerClient::processMessageFromDataServer(app->_incomingPacket, bytesReceived);
4447− break;
4448− default:
4449− NodeList::getInstance()->processNodeData(senderSockAddr, app->_incomingPacket, bytesReceived);
4450− break;
4252+
4253+ // add this packet to our list of voxel packets and process them on the voxel processing
4254+ _voxelProcessor.queueReceivedPacket(senderSockAddr, _incomingPacket, bytesReceived);
4255+ break;
44514256 }
4257+ case PACKET_TYPE_METAVOXEL_DATA:
4258+ _metavoxels.processData(QByteArray((const char*) _incomingPacket, bytesReceived),
4259+ senderSockAddr);
4260+ break;
4261+ case PACKET_TYPE_BULK_AVATAR_DATA:
4262+ NodeList::getInstance()->processBulkNodeData(senderSockAddr,
4263+ _incomingPacket,
4264+ bytesReceived);
4265+ getInstance()->_bandwidthMeter.inputStream(BandwidthMeter::AVATARS).updateValue(bytesReceived);
4266+ break;
4267+ case PACKET_TYPE_AVATAR_URLS:
4268+ processAvatarURLsMessage(_incomingPacket, bytesReceived);
4269+ break;
4270+ case PACKET_TYPE_AVATAR_FACE_VIDEO:
4271+ processAvatarFaceVideoMessage(_incomingPacket, bytesReceived);
4272+ break;
4273+ case PACKET_TYPE_DATA_SERVER_GET:
4274+ case PACKET_TYPE_DATA_SERVER_PUT:
4275+ case PACKET_TYPE_DATA_SERVER_SEND:
4276+ case PACKET_TYPE_DATA_SERVER_CONFIRM:
4277+ DataServerClient::processMessageFromDataServer(_incomingPacket, bytesReceived);
4278+ break;
4279+ default:
4280+ NodeList::getInstance()->processNodeData(senderSockAddr, _incomingPacket, bytesReceived);
4281+ break;
44524282 }
4453− } else if (!app->_enableNetworkThread) {
4454− break;
44554283 }
44564284 }
4457−
4458− if (app->_enableNetworkThread) {
4459− pthread_exit(0);
4460− }
4461− return NULL;
44624285 }
44634286
44644287 void Application::packetSentNotification(ssize_t length) {
@@ -4475,14 +4298,12 @@ void Application::loadScript() { · 10 unmodified lines
44754298 QByteArray fileNameAscii = fileNameString.toLocal8Bit();
44764299 const char* fileName = fileNameAscii.data();
44774300
4478− printf("fileName:%s\n",fileName);
4479−
44804301 std::ifstream file(fileName, std::ios::in|std::ios::binary|std::ios::ate);
44814302 if(!file.is_open()) {
4482− printf("error loading file\n");
4303+ qDebug("Error loading file %s", fileName);
44834304 return;
44844305 }
4485− qDebug("loading file %s...\n", fileName);
4306+ qDebug("Loading file %s...", fileName);
44864307
44874308 // get file length....
44884309 unsigned long fileLength = file.tellg();
@@ -4539,3 +4360,47 @@ void Application::toggleLogDialog() { · 50 unmodified lines
45394360 _logDialog->close();
45404361 }
45414362 }
4363+
4364+
4365+void Application::initAvatarAndViewFrustum() {
4366+ updateAvatar(0.f);
4367+}
4368+
4369+QString Application::getLocalVoxelCacheFileName() {
4370+ QString fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
4371+ QDir logDir(fileName);
4372+ if (!logDir.exists(fileName)) {
4373+ logDir.mkdir(fileName);
4374+ }
4375+
4376+ fileName.append(QString("/hifi.voxelscache."));
4377+ fileName.append(_profile.getLastDomain());
4378+ fileName.append(QString(".svo"));
4379+
4380+ return fileName;
4381+}
4382+
4383+
4384+void Application::updateLocalOctreeCache(bool firstTime) {
4385+ // only do this if we've already got a persistThread or we're told this is the first time
4386+ if (firstTime || _persistThread) {
4387+
4388+ if (_persistThread) {
4389+ _persistThread->terminate();
4390+ _persistThread = NULL;
4391+ }
4392+
4393+ QString localVoxelCacheFileName = getLocalVoxelCacheFileName();
4394+ const int LOCAL_CACHE_PERSIST_INTERVAL = 1000 * 10; // every 10 seconds
4395+ _persistThread = new OctreePersistThread(_voxels.getTree(),
4396+ localVoxelCacheFileName.toLocal8Bit().constData(),LOCAL_CACHE_PERSIST_INTERVAL);
4397+
4398+ qDebug() << "updateLocalOctreeCache()... localVoxelCacheFileName=" << localVoxelCacheFileName;
4399+
4400+ if (_persistThread) {
4401+ _voxels.beginLoadingLocalVoxelCache(); // while local voxels are importing, don't do individual node VBO updates
4402+ connect(_persistThread, SIGNAL(loadCompleted()), &_voxels, SLOT(localVoxelCacheLoaded()));
4403+ _persistThread->initialize(true);
4404+ }
4405+ }
4406+}

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