History

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

Brad Hefta-Gaub committed 12 years ago

Commit d4331db2 parents 43da1ed bb41fe6386 files · +11197 −98919Browse files

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

Unified · Split

interface/src/Application.cpp+269−448
@@ -5,10 +5,16 @@ · 4 unmodified lines
5// Created by Andrzej Kapolka on 5/10/13.5// Created by Andrzej Kapolka on 5/10/13.
6// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.6// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
7 7
8#ifdef WIN32
9#include <Systime.h>
10#endif
11
8#include <sstream>12#include <sstream>
9 13
10#include <stdlib.h>14#include <stdlib.h>
11#include <cmath>15#include <cmath>
16#include <math.h>
17
12 18
13#include <glm/gtx/component_wise.hpp>19#include <glm/gtx/component_wise.hpp>
14#include <glm/gtx/quaternion.hpp>20#include <glm/gtx/quaternion.hpp>
@@ -55,7 +61,6 @@ · 40 unmodified lines
55#include "Menu.h"61#include "Menu.h"
56#include "Swatch.h"62#include "Swatch.h"
57#include "Util.h"63#include "Util.h"
58#include "devices/LeapManager.h"
59#include "devices/OculusManager.h"64#include "devices/OculusManager.h"
60#include "devices/TV3DManager.h"65#include "devices/TV3DManager.h"
61#include "renderer/ProgramObject.h"66#include "renderer/ProgramObject.h"
@@ -86,17 +91,16 @@ const float MIRROR_FULLSCREEN_DISTANCE = 0.35f; · 24 unmodified lines
86const float MIRROR_REARVIEW_DISTANCE = 0.65f;91const float MIRROR_REARVIEW_DISTANCE = 0.65f;
87const float MIRROR_REARVIEW_BODY_DISTANCE = 2.3f;92const float MIRROR_REARVIEW_BODY_DISTANCE = 2.3f;
88 93
89
90void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) {94void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) {
91 fprintf(stdout, "%s", message.toLocal8Bit().constData());95 QString messageWithNewLine = message + "\n";
92 Application::getInstance()->getLogger()->addMessage(message.toLocal8Bit().constData());96 fprintf(stdout, "%s", messageWithNewLine.toLocal8Bit().constData());
97 Application::getInstance()->getLogger()->addMessage(messageWithNewLine.toLocal8Bit().constData());
93}98}
94 99
95Application::Application(int& argc, char** argv, timeval &startup_time) :100Application::Application(int& argc, char** argv, timeval &startup_time) :
96 QApplication(argc, argv),101 QApplication(argc, argv),
97 _window(new QMainWindow(desktop())),102 _window(new QMainWindow(desktop())),
98 _glWidget(new GLCanvas()),103 _glWidget(new GLCanvas()),
99 _displayLevels(false),
100 _frameCount(0),104 _frameCount(0),
101 _fps(120.0f),105 _fps(120.0f),
102 _justStarted(true),106 _justStarted(true),
@@ -127,10 +131,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 24 unmodified lines
127 _lookingAwayFromOrigin(true),131 _lookingAwayFromOrigin(true),
128 _lookatTargetAvatar(NULL),132 _lookatTargetAvatar(NULL),
129 _lookatIndicatorScale(1.0f),133 _lookatIndicatorScale(1.0f),
130 _perfStatsOn(false),
131 _chatEntryOn(false),134 _chatEntryOn(false),
132 _audio(&_audioScope, STARTUP_JITTER_SAMPLES),135 _audio(&_audioScope, STARTUP_JITTER_SAMPLES),
133 _stopNetworkReceiveThread(false),136 _enableProcessVoxelsThread(true),
134 _voxelProcessor(),137 _voxelProcessor(),
135 _voxelHideShowThread(&_voxels),138 _voxelHideShowThread(&_voxels),
136 _voxelEditSender(this),139 _voxelEditSender(this),
@@ -143,7 +146,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 6 unmodified lines
143 _resetRecentMaxPacketsSoon(true),146 _resetRecentMaxPacketsSoon(true),
144 _swatch(NULL),147 _swatch(NULL),
145 _pasteMode(false),148 _pasteMode(false),
146 _logger(new FileLogger())149 _logger(new FileLogger()),
150 _persistThread(NULL)
147{151{
148 _applicationStartupTime = startup_time;152 _applicationStartupTime = startup_time;
149 153
@@ -156,7 +160,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 6 unmodified lines
156 // call Menu getInstance static method to set up the menu160 // call Menu getInstance static method to set up the menu
157 _window->setMenuBar(Menu::getInstance());161 _window->setMenuBar(Menu::getInstance());
158 162
159 qDebug("[VERSION] Build sequence: %i\n", BUILD_VERSION);163 qDebug("[VERSION] Build sequence: %i", BUILD_VERSION);
160 164
161 unsigned int listenPort = 0; // bind to an ephemeral port by default165 unsigned int listenPort = 0; // bind to an ephemeral port by default
162 const char** constArgv = const_cast<const char**>(argv);166 const char** constArgv = const_cast<const char**>(argv);
@@ -167,6 +171,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 4 unmodified lines
167 171
168 NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AGENT, listenPort);172 NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AGENT, listenPort);
169 173
174 // connect our processDatagrams slot to the QUDPSocket readyRead() signal
175 connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), SLOT(processDatagrams()));
176
170 // put the audio processing on a separate thread177 // put the audio processing on a separate thread
171 QThread* audioThread = new QThread(this);178 QThread* audioThread = new QThread(this);
172 179
@@ -175,13 +182,11 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 2 unmodified lines
175 182
176 audioThread->start();183 audioThread->start();
177 184
178 nodeList->addHook(&_voxels);185 connect(nodeList, SIGNAL(domainChanged(const QString&)), SLOT(domainChanged(const QString&)));
179 nodeList->addHook(this);
180 nodeList->addDomainListener(this);
181 nodeList->addDomainListener(&_voxels);
182 186
183 // network receive thread and voxel parsing thread are both controlled by the --nonblocking command line187 connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer)));
184 _enableProcessVoxelsThread = _enableNetworkThread = !cmdOptionExists(argc, constArgv, "--nonblocking");188 connect(nodeList, SIGNAL(nodeAdded(SharedNodePointer)), &_voxels, SLOT(nodeAdded(SharedNodePointer)));
189 connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), &_voxels, SLOT(nodeKilled(SharedNodePointer)));
185 190
186 // read the ApplicationInfo.ini file for Name/Version/Domain information191 // read the ApplicationInfo.ini file for Name/Version/Domain information
187 QSettings applicationInfo("resources/info/ApplicationInfo.ini", QSettings::IniFormat);192 QSettings applicationInfo("resources/info/ApplicationInfo.ini", QSettings::IniFormat);
@@ -210,7 +215,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 22 unmodified lines
210 215
211 // tell the NodeList instance who to tell the domain server we care about216 // 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,217 const char nodeTypesOfInterest[] = {NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER, NODE_TYPE_VOXEL_SERVER,
213 NODE_TYPE_PARTICLE_SERVER};218 NODE_TYPE_PARTICLE_SERVER, NODE_TYPE_METAVOXEL_SERVER};
214 nodeList->setNodeTypesOfInterest(nodeTypesOfInterest, sizeof(nodeTypesOfInterest));219 nodeList->setNodeTypesOfInterest(nodeTypesOfInterest, sizeof(nodeTypesOfInterest));
215 220
216 QTimer* silentNodeTimer = new QTimer(this);221 QTimer* silentNodeTimer = new QTimer(this);
@@ -250,6 +255,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 33 unmodified lines
250 255
251 // Set the sixense filtering256 // Set the sixense filtering
252 _sixenseManager.setFilter(Menu::getInstance()->isOptionChecked(MenuOption::FilterSixense));257 _sixenseManager.setFilter(Menu::getInstance()->isOptionChecked(MenuOption::FilterSixense));
258
253}259}
254 260
255Application::~Application() {261Application::~Application() {
@@ -264,9 +270,6 @@ Application::~Application() { · 8 unmodified lines
264 _audio.thread()->wait();270 _audio.thread()->wait();
265 271
266 storeSizeAndPosition();272 storeSizeAndPosition();
267 NodeList::getInstance()->removeHook(&_voxels);
268 NodeList::getInstance()->removeHook(this);
269 NodeList::getInstance()->removeDomainListener(this);
270 273
271 _sharedVoxelSystem.changeTree(new VoxelTree);274 _sharedVoxelSystem.changeTree(new VoxelTree);
272 275
@@ -275,7 +278,6 @@ Application::~Application() { · 2 unmodified lines
275 278
276 delete _logger;279 delete _logger;
277 delete _settings;280 delete _settings;
278 delete _followMode;
279 delete _glWidget;281 delete _glWidget;
280}282}
281 283
@@ -311,7 +313,7 @@ void Application::storeSizeAndPosition() { · 29 unmodified lines
311}313}
312 314
313void Application::initializeGL() {315void Application::initializeGL() {
314 qDebug( "Created Display Window.\n" );316 qDebug( "Created Display Window.");
315 317
316 // initialize glut for shape drawing; Qt apparently initializes it on OS X318 // initialize glut for shape drawing; Qt apparently initializes it on OS X
317 #ifndef __APPLE__319 #ifndef __APPLE__
@@ -319,23 +321,27 @@ void Application::initializeGL() { · 1 unmodified line
319 glutInit(&argc, 0);321 glutInit(&argc, 0);
320 #endif322 #endif
321 323
324 #ifdef WIN32
325 GLenum err = glewInit();
326 if (GLEW_OK != err) {
327 /* Problem: glewInit failed, something is seriously wrong. */
328 qDebug("Error: %s\n", glewGetErrorString(err));
329 }
330 qDebug("Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
331 #endif
332
333
322 // Before we render anything, let's set up our viewFrustumOffsetCamera with a sufficiently large334 // Before we render anything, let's set up our viewFrustumOffsetCamera with a sufficiently large
323 // field of view and near and far clip to make it interesting.335 // field of view and near and far clip to make it interesting.
324 //viewFrustumOffsetCamera.setFieldOfView(90.0);336 //viewFrustumOffsetCamera.setFieldOfView(90.0);
325 _viewFrustumOffsetCamera.setNearClip(0.1);337 _viewFrustumOffsetCamera.setNearClip(0.1f);
326 _viewFrustumOffsetCamera.setFarClip(500.0 * TREE_SCALE);338 _viewFrustumOffsetCamera.setFarClip(500.0f * TREE_SCALE);
327 339
328 initDisplay();340 initDisplay();
329 qDebug( "Initialized Display.\n" );341 qDebug( "Initialized Display.");
330 342
331 init();343 init();
332 qDebug( "Init() complete.\n" );344 qDebug( "init() complete.");
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 }
339 345
340 // create thread for parsing of voxel data independent of the main network and rendering threads346 // create thread for parsing of voxel data independent of the main network and rendering threads
341 _voxelProcessor.initialize(_enableProcessVoxelsThread);347 _voxelProcessor.initialize(_enableProcessVoxelsThread);
@@ -343,7 +349,7 @@ void Application::initializeGL() { · 1 unmodified line
343 _voxelHideShowThread.initialize(_enableProcessVoxelsThread);349 _voxelHideShowThread.initialize(_enableProcessVoxelsThread);
344 _particleEditSender.initialize(_enableProcessVoxelsThread);350 _particleEditSender.initialize(_enableProcessVoxelsThread);
345 if (_enableProcessVoxelsThread) {351 if (_enableProcessVoxelsThread) {
346 qDebug("Voxel parsing thread created.\n");352 qDebug("Voxel parsing thread created.");
347 }353 }
348 354
349 // call terminate before exiting355 // call terminate before exiting
@@ -363,9 +369,7 @@ void Application::initializeGL() { · 13 unmodified lines
363 if (_justStarted) {369 if (_justStarted) {
364 float startupTime = (usecTimestampNow() - usecTimestamp(&_applicationStartupTime)) / 1000000.0;370 float startupTime = (usecTimestampNow() - usecTimestamp(&_applicationStartupTime)) / 1000000.0;
365 _justStarted = false;371 _justStarted = false;
366 char title[50];372 qDebug("Startup time: %4.2f seconds.", startupTime);
367 sprintf(title, "Interface: %4.2f seconds\n", startupTime);
368 qDebug("%s", title);
369 const char LOGSTASH_INTERFACE_START_TIME_KEY[] = "interface-start-time";373 const char LOGSTASH_INTERFACE_START_TIME_KEY[] = "interface-start-time";
370 374
371 // ask the Logstash class to record the startup time375 // ask the Logstash class to record the startup time
@@ -465,7 +469,7 @@ void Application::paintGL() { · 93 unmodified lines
465 bool eyeRelativeCamera = false;469 bool eyeRelativeCamera = false;
466 if (_rearMirrorTools->getZoomLevel() == BODY) {470 if (_rearMirrorTools->getZoomLevel() == BODY) {
467 _mirrorCamera.setDistance(MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar.getScale());471 _mirrorCamera.setDistance(MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar.getScale());
468 _mirrorCamera.setTargetPosition(_myAvatar.getChestJointPosition());472 _mirrorCamera.setTargetPosition(_myAvatar.getChestPosition());
469 } else { // HEAD zoom level473 } else { // HEAD zoom level
470 _mirrorCamera.setDistance(MIRROR_REARVIEW_DISTANCE * _myAvatar.getScale());474 _mirrorCamera.setDistance(MIRROR_REARVIEW_DISTANCE * _myAvatar.getScale());
471 if (_myAvatar.getSkeletonModel().isActive() && _myAvatar.getHead().getFaceModel().isActive()) {475 if (_myAvatar.getSkeletonModel().isActive() && _myAvatar.getHead().getFaceModel().isActive()) {
@@ -672,9 +676,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 200 unmodified lines
672 _audioScope.inputPaused = !_audioScope.inputPaused;676 _audioScope.inputPaused = !_audioScope.inputPaused;
673 break;677 break;
674 case Qt::Key_L:678 case Qt::Key_L:
675 if (!isShifted && !isMeta) {679 if (isShifted) {
676 _displayLevels = !_displayLevels;
677 } else if (isShifted) {
678 Menu::getInstance()->triggerOption(MenuOption::LodTools);680 Menu::getInstance()->triggerOption(MenuOption::LodTools);
679 } else if (isMeta) {681 } else if (isMeta) {
680 Menu::getInstance()->triggerOption(MenuOption::Log);682 Menu::getInstance()->triggerOption(MenuOption::Log);
@@ -1017,6 +1019,9 @@ void Application::keyPressEvent(QKeyEvent* event) { · 336 unmodified lines
1017 case Qt::Key_Minus:1019 case Qt::Key_Minus:
1018 _myAvatar.decreaseSize();1020 _myAvatar.decreaseSize();
1019 break;1021 break;
1022 case Qt::Key_Equal:
1023 _myAvatar.resetSize();
1024 break;
1020 1025
1021 case Qt::Key_1:1026 case Qt::Key_1:
1022 case Qt::Key_2:1027 case Qt::Key_2:
@@ -1122,7 +1127,7 @@ void Application::mouseMoveEvent(QMouseEvent* event) { · 99 unmodified lines
1122 return;1127 return;
1123 }1128 }
1124 if (_isHoverVoxel) {1129 if (_isHoverVoxel) {
1125 _myAvatar.orbit(glm::vec3(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z) * (float)TREE_SCALE, deltaX, deltaY);1130 _myAvatar.orbit(getMouseVoxelWorldCoordinates(_hoverVoxel), deltaX, deltaY);
1126 return;1131 return;
1127 }1132 }
1128 }1133 }
@@ -1282,7 +1287,7 @@ void Application::wheelEvent(QWheelEvent* event) { · 153 unmodified lines
1282void Application::sendPingPackets() {1287void Application::sendPingPackets() {
1283 1288
1284 const char nodesToPing[] = {NODE_TYPE_VOXEL_SERVER, NODE_TYPE_PARTICLE_SERVER,1289 const char nodesToPing[] = {NODE_TYPE_VOXEL_SERVER, NODE_TYPE_PARTICLE_SERVER,
1285 NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER};1290 NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER, NODE_TYPE_METAVOXEL_SERVER};
1286 1291
1287 unsigned char pingPacket[MAX_PACKET_SIZE];1292 unsigned char pingPacket[MAX_PACKET_SIZE];
1288 int length = NodeList::getInstance()->fillPingPacket(pingPacket);1293 int length = NodeList::getInstance()->fillPingPacket(pingPacket);
@@ -1291,38 +1296,6 @@ void Application::sendPingPackets() { · 2 unmodified lines
1291 nodesToPing, sizeof(nodesToPing));1296 nodesToPing, sizeof(nodesToPing));
1292}1297}
1293 1298
1294void Application::sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data) {
1295 unsigned char packet[MAX_PACKET_SIZE];
1296 unsigned char* packetPosition = packet;
1297
1298 packetPosition += populateTypeAndVersion(packetPosition, PACKET_TYPE_AVATAR_FACE_VIDEO);
1299
1300 QByteArray rfcUUID = NodeList::getInstance()->getOwnerUUID().toRfc4122();
1301 memcpy(packetPosition, rfcUUID.constData(), rfcUUID.size());
1302 packetPosition += rfcUUID.size();
1303
1304 *(uint32_t*)packetPosition = frameCount;
1305 packetPosition += sizeof(uint32_t);
1306
1307 *(uint32_t*)packetPosition = data.size();
1308 packetPosition += sizeof(uint32_t);
1309
1310 uint32_t* offsetPosition = (uint32_t*)packetPosition;
1311 packetPosition += sizeof(uint32_t);
1312
1313 int headerSize = packetPosition - packet;
1314
1315 // break the data up into submessages of the maximum size (at least one, for zero-length packets)
1316 *offsetPosition = 0;
1317 do {
1318 int payloadSize = min(data.size() - (int)*offsetPosition, MAX_PACKET_SIZE - headerSize);
1319 memcpy(packetPosition, data.constData() + *offsetPosition, payloadSize);
1320 getInstance()->controlledBroadcastToNodes(packet, headerSize + payloadSize, &NODE_TYPE_AVATAR_MIXER, 1);
1321 *offsetPosition += payloadSize;
1322
1323 } while (*offsetPosition < data.size());
1324}
1325
1326// Every second, check the frame rates and other stuff1299// Every second, check the frame rates and other stuff
1327void Application::timer() {1300void Application::timer() {
1328 gettimeofday(&_timerEnd, NULL);1301 gettimeofday(&_timerEnd, NULL);
@@ -1340,16 +1313,12 @@ void Application::timer() { · 11 unmodified lines
1340 1313
1341 gettimeofday(&_timerStart, NULL);1314 gettimeofday(&_timerStart, NULL);
1342 1315
1343 // if we haven't detected gyros, check for them now
1344 if (!_serialHeadSensor.isActive()) {
1345 _serialHeadSensor.pair();
1346 }
1347
1348 // ask the node list to check in with the domain server1316 // ask the node list to check in with the domain server
1349 NodeList::getInstance()->sendDomainServerCheckIn();1317 NodeList::getInstance()->sendDomainServerCheckIn();
1350 1318
1351 // give the MyAvatar object position to the Profile so it can propagate to the data-server1319 // give the MyAvatar object position, orientation to the Profile so it can propagate to the data-server
1352 _profile.updatePosition(_myAvatar.getPosition());1320 _profile.updatePosition(_myAvatar.getPosition());
1321 _profile.updateOrientation(_myAvatar.getOrientation());
1353}1322}
1354 1323
1355static glm::vec3 getFaceVector(BoxFace face) {1324static glm::vec3 getFaceVector(BoxFace face) {
@@ -1369,6 +1338,7 @@ static glm::vec3 getFaceVector(BoxFace face) { · 13 unmodified lines
1369 case MIN_Z_FACE:1338 case MIN_Z_FACE:
1370 return glm::vec3(0, 0, -1);1339 return glm::vec3(0, 0, -1);
1371 1340
1341 default: // quiet windows warnings
1372 case MAX_Z_FACE:1342 case MAX_Z_FACE:
1373 return glm::vec3(0, 0, 1);1343 return glm::vec3(0, 0, 1);
1374 }1344 }
@@ -1418,7 +1388,6 @@ void Application::terminate() { · 43 unmodified lines
1418 // Close serial port1388 // Close serial port
1419 // close(serial_fd);1389 // close(serial_fd);
1420 1390
1421 LeapManager::terminate();
1422 Menu::getInstance()->saveSettings();1391 Menu::getInstance()->saveSettings();
1423 _rearMirrorTools->saveSettings(_settings);1392 _rearMirrorTools->saveSettings(_settings);
1424 _settings->sync();1393 _settings->sync();
@@ -1426,22 +1395,21 @@ void Application::terminate() { · 1 unmodified line
1426 // let the avatar mixer know we're out1395 // let the avatar mixer know we're out
1427 NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1);1396 NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1);
1428 1397
1429 if (_enableNetworkThread) {
1430 _stopNetworkReceiveThread = true;
1431 pthread_join(_networkReceiveThread, NULL);
1432 }
1433
1434 printf("");
1435 _voxelProcessor.terminate();1398 _voxelProcessor.terminate();
1436 _voxelHideShowThread.terminate();1399 _voxelHideShowThread.terminate();
1437 _voxelEditSender.terminate();1400 _voxelEditSender.terminate();
1438 _particleEditSender.terminate();1401 _particleEditSender.terminate();
1402 if (_persistThread) {
1403 _persistThread->terminate();
1404 _persistThread->deleteLater();
1405 _persistThread = NULL;
1406 }
1439}1407}
1440 1408
1441static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& dataBytes) {1409static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& dataBytes) {
1442 // record the packet for stats-tracking1410 // record the packet for stats-tracking
1443 Application::getInstance()->getBandwidthMeter()->inputStream(BandwidthMeter::AVATARS).updateValue(dataBytes);1411 Application::getInstance()->getBandwidthMeter()->inputStream(BandwidthMeter::AVATARS).updateValue(dataBytes);
1444 Node* avatarMixerNode = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);1412 SharedNodePointer avatarMixerNode = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
1445 if (avatarMixerNode) {1413 if (avatarMixerNode) {
1446 avatarMixerNode->recordBytesReceived(dataBytes);1414 avatarMixerNode->recordBytesReceived(dataBytes);
1447 }1415 }
@@ -1458,7 +1426,7 @@ static Avatar* processAvatarMessageHeader(unsigned char*& packetData, size_t& da · 10 unmodified lines
1458 dataBytes -= NUM_BYTES_RFC4122_UUID;1426 dataBytes -= NUM_BYTES_RFC4122_UUID;
1459 1427
1460 // make sure the node exists1428 // make sure the node exists
1461 Node* node = NodeList::getInstance()->nodeWithUUID(nodeUUID);1429 SharedNodePointer node = NodeList::getInstance()->nodeWithUUID(nodeUUID);
1462 if (!node || !node->getLinkedData()) {1430 if (!node || !node->getLinkedData()) {
1463 return NULL;1431 return NULL;
1464 }1432 }
@@ -1487,14 +1455,6 @@ void Application::processAvatarURLsMessage(unsigned char* packetData, size_t dat · 22 unmodified lines
1487 avatar->getUUID());1455 avatar->getUUID());
1488}1456}
1489 1457
1490void Application::processAvatarFaceVideoMessage(unsigned char* packetData, size_t dataBytes) {
1491 Avatar* avatar = processAvatarMessageHeader(packetData, dataBytes);
1492 if (!avatar) {
1493 return;
1494 }
1495 avatar->getHead().getVideoFace().processVideoMessage(packetData, dataBytes);
1496}
1497
1498void Application::checkBandwidthMeterClick() {1458void Application::checkBandwidthMeterClick() {
1499 // ... to be called upon button release1459 // ... to be called upon button release
1500 1460
@@ -1514,6 +1474,11 @@ void Application::setFullscreen(bool fullscreen) { · 13 unmodified lines
1514 (_window->windowState() & ~Qt::WindowFullScreen));1474 (_window->windowState() & ~Qt::WindowFullScreen));
1515}1475}
1516 1476
1477void Application::setEnable3DTVMode(bool enable3DTVMode) {
1478 resizeGL(_glWidget->width(),_glWidget->height());
1479}
1480
1481
1517void Application::setRenderVoxels(bool voxelRender) {1482void Application::setRenderVoxels(bool voxelRender) {
1518 _voxelEditSender.setShouldSend(voxelRender);1483 _voxelEditSender.setShouldSend(voxelRender);
1519 if (!voxelRender) {1484 if (!voxelRender) {
@@ -1617,10 +1582,9 @@ void Application::makeVoxel(glm::vec3 position, · 97 unmodified lines
1617 isDestructive);1582 isDestructive);
1618 }1583 }
1619 1584
1620const glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel) {1585glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVoxel) {
1621 return glm::vec3((_mouseVoxel.x + _mouseVoxel.s / 2.f) * TREE_SCALE,1586 return glm::vec3((mouseVoxel.x + mouseVoxel.s / 2.f) * TREE_SCALE, (mouseVoxel.y + mouseVoxel.s / 2.f) * TREE_SCALE,
1622 (_mouseVoxel.y + _mouseVoxel.s / 2.f) * TREE_SCALE,1587 (mouseVoxel.z + mouseVoxel.s / 2.f) * TREE_SCALE);
1623 (_mouseVoxel.z + _mouseVoxel.s / 2.f) * TREE_SCALE);
1624}1588}
1625 1589
1626const float NUDGE_PRECISION_MIN = 1 / pow(2.0, 12.0);1590const float NUDGE_PRECISION_MIN = 1 / pow(2.0, 12.0);
@@ -1707,9 +1671,9 @@ void Application::exportVoxels() { · 80 unmodified lines
1707 1671
1708void Application::importVoxels() {1672void Application::importVoxels() {
1709 if (_voxelImporter.exec()) {1673 if (_voxelImporter.exec()) {
1710 qDebug("[DEBUG] Import succedded.\n");1674 qDebug("[DEBUG] Import succeeded.");
1711 } else {1675 } else {
1712 qDebug("[DEBUG] Import failed.\n");1676 qDebug("[DEBUG] Import failed.");
1713 }1677 }
1714 1678
1715 // restore the main window's active state1679 // restore the main window's active state
@@ -1883,8 +1847,6 @@ void Application::init() { · 167 unmodified lines
1883 Qt::QueuedConnection);1847 Qt::QueuedConnection);
1884 }1848 }
1885 1849
1886 LeapManager::initialize();
1887
1888 gettimeofday(&_timerStart, NULL);1850 gettimeofday(&_timerStart, NULL);
1889 gettimeofday(&_lastTimeUpdated, NULL);1851 gettimeofday(&_lastTimeUpdated, NULL);
1890 1852
@@ -1892,7 +1854,7 @@ void Application::init() { · 1 unmodified line
1892 if (Menu::getInstance()->getAudioJitterBufferSamples() != 0) {1854 if (Menu::getInstance()->getAudioJitterBufferSamples() != 0) {
1893 _audio.setJitterBufferSamples(Menu::getInstance()->getAudioJitterBufferSamples());1855 _audio.setJitterBufferSamples(Menu::getInstance()->getAudioJitterBufferSamples());
1894 }1856 }
1895 qDebug("Loaded settings.\n");1857 qDebug("Loaded settings");
1896 1858
1897 if (!_profile.getUsername().isEmpty()) {1859 if (!_profile.getUsername().isEmpty()) {
1898 // we have a username for this avatar, ask the data-server for the mesh URL for this avatar1860 // we have a username for this avatar, ask the data-server for the mesh URL for this avatar
@@ -1926,10 +1888,6 @@ void Application::init() { · 27 unmodified lines
1926 _glWidget->width(),1888 _glWidget->width(),
1927 _glWidget->height());1889 _glWidget->height());
1928 1890
1929 _followMode = new QAction(this);
1930 connect(_followMode, SIGNAL(triggered()), this, SLOT(toggleFollowMode()));
1931 _pieMenu.addAction(_followMode);
1932
1933 _audio.init(_glWidget);1891 _audio.init(_glWidget);
1934 1892
1935 _rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect, _settings);1893 _rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect, _settings);
@@ -1937,6 +1895,9 @@ void Application::init() { · 1 unmodified line
1937 connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView()));1895 connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView()));
1938 connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));1896 connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));
1939 connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors()));1897 connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors()));
1898
1899
1900 updateLocalOctreeCache(true);
1940}1901}
1941 1902
1942void Application::closeMirrorView() {1903void Application::closeMirrorView() {
@@ -1967,7 +1928,7 @@ void Application::shrinkMirrorView() { · 24 unmodified lines
1967 1928
1968const float MAX_AVATAR_EDIT_VELOCITY = 1.0f;1929const float MAX_AVATAR_EDIT_VELOCITY = 1.0f;
1969const float MAX_VOXEL_EDIT_DISTANCE = 50.0f;1930const float MAX_VOXEL_EDIT_DISTANCE = 50.0f;
1970const float HEAD_SPHERE_RADIUS = 0.07;1931const float HEAD_SPHERE_RADIUS = 0.07f;
1971 1932
1972static QUuid DEFAULT_NODE_ID_REF;1933static QUuid DEFAULT_NODE_ID_REF;
1973 1934
@@ -1984,15 +1945,15 @@ void Application::updateLookatTargetAvatar(const glm::vec3& mouseRayOrigin, cons · 10 unmodified lines
1984Avatar* Application::findLookatTargetAvatar(const glm::vec3& mouseRayOrigin, const glm::vec3& mouseRayDirection,1945Avatar* Application::findLookatTargetAvatar(const glm::vec3& mouseRayOrigin, const glm::vec3& mouseRayDirection,
1985 glm::vec3& eyePosition, QUuid& nodeUUID = DEFAULT_NODE_ID_REF) {1946 glm::vec3& eyePosition, QUuid& nodeUUID = DEFAULT_NODE_ID_REF) {
1986 1947
1987 NodeList* nodeList = NodeList::getInstance();1948 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
1988 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
1989 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {1949 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
1990 Avatar* avatar = (Avatar*)node->getLinkedData();1950 Avatar* avatar = (Avatar*)node->getLinkedData();
1991 float distance;1951 float distance;
1952
1992 if (avatar->findRayIntersection(mouseRayOrigin, mouseRayDirection, distance)) {1953 if (avatar->findRayIntersection(mouseRayOrigin, mouseRayDirection, distance)) {
1993 // rescale to compensate for head embiggening1954 // rescale to compensate for head embiggening
1994 eyePosition = (avatar->getHead().calculateAverageEyePosition() - avatar->getHead().getScalePivot()) *1955 eyePosition = (avatar->getHead().calculateAverageEyePosition() - avatar->getHead().getScalePivot()) *
1995 (avatar->getScale() / avatar->getHead().getScale()) + avatar->getHead().getScalePivot();1956 (avatar->getScale() / avatar->getHead().getScale()) + avatar->getHead().getScalePivot();
1996 1957
1997 _lookatIndicatorScale = avatar->getHead().getScale();1958 _lookatIndicatorScale = avatar->getHead().getScale();
1998 _lookatOtherPosition = avatar->getHead().getPosition();1959 _lookatOtherPosition = avatar->getHead().getPosition();
@@ -2001,6 +1962,7 @@ Avatar* Application::findLookatTargetAvatar(const glm::vec3& mouseRayOrigin, con · 2 unmodified lines
2001 }1962 }
2002 }1963 }
2003 }1964 }
1965
2004 return NULL;1966 return NULL;
2005}1967}
2006 1968
@@ -2025,71 +1987,6 @@ void Application::renderLookatIndicator(glm::vec3 pointOfInterest) { · 18 unmodified lines
2025 renderCircle(haloOrigin, INDICATOR_RADIUS, IDENTITY_UP, NUM_SEGMENTS);1987 renderCircle(haloOrigin, INDICATOR_RADIUS, IDENTITY_UP, NUM_SEGMENTS);
2026}1988}
2027 1989
2028void maybeBeginFollowIndicator(bool& began) {
2029 if (!began) {
2030 Application::getInstance()->getGlowEffect()->begin();
2031 glLineWidth(5);
2032 glBegin(GL_LINES);
2033 began = true;
2034 }
2035}
2036
2037void Application::renderFollowIndicator() {
2038 NodeList* nodeList = NodeList::getInstance();
2039
2040 // initialize lazily so that we don't enable the glow effect unnecessarily
2041 bool began = false;
2042
2043 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); ++node) {
2044 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
2045 Avatar* avatar = (Avatar *) node->getLinkedData();
2046 Avatar* leader = NULL;
2047
2048 if (!avatar->getLeaderUUID().isNull()) {
2049 if (avatar->getLeaderUUID() == NodeList::getInstance()->getOwnerUUID()) {
2050 leader = &_myAvatar;
2051 } else {
2052 for (NodeList::iterator it = nodeList->begin(); it != nodeList->end(); ++it) {
2053 if(it->getUUID() == avatar->getLeaderUUID()
2054 && it->getType() == NODE_TYPE_AGENT) {
2055 leader = (Avatar*) it->getLinkedData();
2056 }
2057 }
2058 }
2059
2060 if (leader != NULL) {
2061 maybeBeginFollowIndicator(began);
2062 glColor3f(1.f, 0.f, 0.f);
2063 glVertex3f((avatar->getHead().getPosition().x + avatar->getPosition().x) / 2.f,
2064 (avatar->getHead().getPosition().y + avatar->getPosition().y) / 2.f,
2065 (avatar->getHead().getPosition().z + avatar->getPosition().z) / 2.f);
2066 glColor3f(0.f, 1.f, 0.f);
2067 glVertex3f((leader->getHead().getPosition().x + leader->getPosition().x) / 2.f,
2068 (leader->getHead().getPosition().y + leader->getPosition().y) / 2.f,
2069 (leader->getHead().getPosition().z + leader->getPosition().z) / 2.f);
2070 }
2071 }
2072 }
2073 }
2074
2075 if (_myAvatar.getLeadingAvatar() != NULL) {
2076 maybeBeginFollowIndicator(began);
2077 glColor3f(1.f, 0.f, 0.f);
2078 glVertex3f((_myAvatar.getHead().getPosition().x + _myAvatar.getPosition().x) / 2.f,
2079 (_myAvatar.getHead().getPosition().y + _myAvatar.getPosition().y) / 2.f,
2080 (_myAvatar.getHead().getPosition().z + _myAvatar.getPosition().z) / 2.f);
2081 glColor3f(0.f, 1.f, 0.f);
2082 glVertex3f((_myAvatar.getLeadingAvatar()->getHead().getPosition().x + _myAvatar.getLeadingAvatar()->getPosition().x) / 2.f,
2083 (_myAvatar.getLeadingAvatar()->getHead().getPosition().y + _myAvatar.getLeadingAvatar()->getPosition().y) / 2.f,
2084 (_myAvatar.getLeadingAvatar()->getHead().getPosition().z + _myAvatar.getLeadingAvatar()->getPosition().z) / 2.f);
2085 }
2086
2087 if (began) {
2088 glEnd();
2089 _glowEffect.end();
2090 }
2091}
2092
2093void Application::renderHighlightVoxel(VoxelDetail voxel) {1990void Application::renderHighlightVoxel(VoxelDetail voxel) {
2094 glDisable(GL_LIGHTING);1991 glDisable(GL_LIGHTING);
2095 glPushMatrix();1992 glPushMatrix();
@@ -2107,10 +2004,9 @@ void Application::renderHighlightVoxel(VoxelDetail voxel) { · 11 unmodified lines
2107void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm::vec3 mouseRayDirection) {2004void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm::vec3 mouseRayDirection) {
2108 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);2005 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
2109 PerformanceWarning warn(showWarnings, "Application::updateAvatars()");2006 PerformanceWarning warn(showWarnings, "Application::updateAvatars()");
2110 NodeList* nodeList = NodeList::getInstance();
2111 2007
2112 for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {2008 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
2113 node->lock();2009 QMutexLocker(&node->getMutex());
2114 if (node->getLinkedData()) {2010 if (node->getLinkedData()) {
2115 Avatar *avatar = (Avatar *)node->getLinkedData();2011 Avatar *avatar = (Avatar *)node->getLinkedData();
2116 if (!avatar->isInitialized()) {2012 if (!avatar->isInitialized()) {
@@ -2119,16 +2015,18 @@ void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm:: · 2 unmodified lines
2119 avatar->simulate(deltaTime, NULL);2015 avatar->simulate(deltaTime, NULL);
2120 avatar->setMouseRay(mouseRayOrigin, mouseRayDirection);2016 avatar->setMouseRay(mouseRayOrigin, mouseRayDirection);
2121 }2017 }
2122 node->unlock();
2123 }2018 }
2124 2019
2125 // simulate avatar fades2020 // simulate avatar fades
2126 for (vector<Avatar*>::iterator fade = _avatarFades.begin(); fade != _avatarFades.end(); fade++) {2021 for (vector<Avatar*>::iterator fade = _avatarFades.begin(); fade != _avatarFades.end(); fade++) {
2127 Avatar* avatar = *fade;2022 Avatar* avatar = *fade;
2128 const float SHRINK_RATE = 0.9f;2023 const float SHRINK_RATE = 0.9f;
2129 avatar->setNewScale(avatar->getNewScale() * SHRINK_RATE);2024
2130 const float MINIMUM_SCALE = 0.001f;2025 avatar->setTargetScale(avatar->getScale() * SHRINK_RATE);
2131 if (avatar->getNewScale() < MINIMUM_SCALE) {2026
2027 const float MIN_FADE_SCALE = 0.001f;
2028
2029 if (avatar->getTargetScale() < MIN_FADE_SCALE) {
2132 delete avatar;2030 delete avatar;
2133 _avatarFades.erase(fade--);2031 _avatarFades.erase(fade--);
2134 2032
@@ -2182,17 +2080,23 @@ void Application::updateMyAvatarLookAtPosition(glm::vec3& lookAtSpot, glm::vec3& · 47 unmodified lines
2182 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);2080 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
2183 PerformanceWarning warn(showWarnings, "Application::updateMyAvatarLookAtPosition()");2081 PerformanceWarning warn(showWarnings, "Application::updateMyAvatarLookAtPosition()");
2184 2082
2083 const float FAR_AWAY_STARE = TREE_SCALE;
2185 if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {2084 if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
2186 lookAtSpot = _myCamera.getPosition();2085 lookAtSpot = _myCamera.getPosition();
2187 2086
2087 } else if (_mouseHidden) {
2088 // if the mouse cursor is hidden, just look straight ahead
2089 glm::vec3 rayOrigin, rayDirection;
2090 _viewFrustum.computePickRay(0.5f, 0.5f, rayOrigin, rayDirection);
2091 lookAtSpot = rayOrigin + rayDirection * FAR_AWAY_STARE;
2092
2188 } else if (!_lookatTargetAvatar) {2093 } else if (!_lookatTargetAvatar) {
2189 if (_isHoverVoxel) {2094 if (_isHoverVoxel) {
2190 // Look at the hovered voxel2095 // Look at the hovered voxel
2191 lookAtSpot = getMouseVoxelWorldCoordinates(_hoverVoxel);2096 lookAtSpot = getMouseVoxelWorldCoordinates(_hoverVoxel);
2192 2097
2193 } else {2098 } else {
2194 // Just look in direction of the mouse ray2099 // Just look in direction of the mouse ray
2195 const float FAR_AWAY_STARE = TREE_SCALE;
2196 lookAtSpot = lookAtRayOrigin + lookAtRayDirection * FAR_AWAY_STARE;2100 lookAtSpot = lookAtRayOrigin + lookAtRayDirection * FAR_AWAY_STARE;
2197 }2101 }
2198 }2102 }
@@ -2264,7 +2168,6 @@ void Application::updateMouseVoxels(float deltaTime, glm::vec3& mouseRayOrigin, · 65 unmodified lines
2264 2168
2265 _mouseVoxel.s = 0.0f;2169 _mouseVoxel.s = 0.0f;
2266 bool wasInitialized = _mouseVoxelScaleInitialized;2170 bool wasInitialized = _mouseVoxelScaleInitialized;
2267 _mouseVoxelScaleInitialized = false;
2268 if (Menu::getInstance()->isVoxelModeActionChecked() &&2171 if (Menu::getInstance()->isVoxelModeActionChecked() &&
2269 (fabs(_myAvatar.getVelocity().x) +2172 (fabs(_myAvatar.getVelocity().x) +
2270 fabs(_myAvatar.getVelocity().y) +2173 fabs(_myAvatar.getVelocity().y) +
@@ -2345,6 +2248,7 @@ void Application::updateMouseVoxels(float deltaTime, glm::vec3& mouseRayOrigin, · 74 unmodified lines
2345 }2248 }
2346}2249}
2347 2250
2251
2348void Application::updateHandAndTouch(float deltaTime) {2252void Application::updateHandAndTouch(float deltaTime) {
2349 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);2253 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
2350 PerformanceWarning warn(showWarnings, "Application::updateHandAndTouch()");2254 PerformanceWarning warn(showWarnings, "Application::updateHandAndTouch()");
@@ -2364,9 +2268,6 @@ void Application::updateHandAndTouch(float deltaTime) { · 13 unmodified lines
2364void Application::updateLeap(float deltaTime) {2268void Application::updateLeap(float deltaTime) {
2365 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);2269 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
2366 PerformanceWarning warn(showWarnings, "Application::updateLeap()");2270 PerformanceWarning warn(showWarnings, "Application::updateLeap()");
2367
2368 LeapManager::enableFakeFingers(Menu::getInstance()->isOptionChecked(MenuOption::SimulateLeapHand));
2369 LeapManager::nextFrame();
2370}2271}
2371 2272
2372void Application::updateSixense(float deltaTime) {2273void Application::updateSixense(float deltaTime) {
@@ -2379,27 +2280,21 @@ void Application::updateSixense(float deltaTime) { · 6 unmodified lines
2379void Application::updateSerialDevices(float deltaTime) {2280void Application::updateSerialDevices(float deltaTime) {
2380 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);2281 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
2381 PerformanceWarning warn(showWarnings, "Application::updateSerialDevices()");2282 PerformanceWarning warn(showWarnings, "Application::updateSerialDevices()");
2382
2383 if (_serialHeadSensor.isActive()) {
2384 _serialHeadSensor.readData(deltaTime);
2385 }
2386}2283}
2387 2284
2388void Application::updateThreads(float deltaTime) {2285void Application::updateThreads(float deltaTime) {
2389 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);2286 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
2390 PerformanceWarning warn(showWarnings, "Application::updateThreads()");2287 PerformanceWarning warn(showWarnings, "Application::updateThreads()");
2391 2288
2392 // read incoming packets from network
2393 if (!_enableNetworkThread) {
2394 networkReceive(0);
2395 }
2396
2397 // parse voxel packets2289 // parse voxel packets
2398 if (!_enableProcessVoxelsThread) {2290 if (!_enableProcessVoxelsThread) {
2399 _voxelProcessor.threadRoutine();2291 _voxelProcessor.threadRoutine();
2400 _voxelHideShowThread.threadRoutine();2292 _voxelHideShowThread.threadRoutine();
2401 _voxelEditSender.threadRoutine();2293 _voxelEditSender.threadRoutine();
2402 _particleEditSender.threadRoutine();2294 _particleEditSender.threadRoutine();
2295 if (_persistThread) {
2296 _persistThread->threadRoutine();
2297 }
2403 }2298 }
2404}2299}
2405 2300
@@ -2445,7 +2340,7 @@ void Application::updateTransmitter(float deltaTime) { · 39 unmodified lines
2445 2340
2446 // no transmitter drive implies transmitter pick2341 // no transmitter drive implies transmitter pick
2447 if (!Menu::getInstance()->isOptionChecked(MenuOption::TransmitterDrive) && _myTransmitter.isConnected()) {2342 if (!Menu::getInstance()->isOptionChecked(MenuOption::TransmitterDrive) && _myTransmitter.isConnected()) {
2448 _transmitterPickStart = _myAvatar.getSkeleton().joint[AVATAR_JOINT_CHEST].position;2343 _transmitterPickStart = _myAvatar.getChestPosition();
2449 glm::vec3 direction = _myAvatar.getOrientation() *2344 glm::vec3 direction = _myAvatar.getOrientation() *
2450 glm::quat(glm::radians(_myTransmitter.getEstimatedRotation())) * IDENTITY_FRONT;2345 glm::quat(glm::radians(_myTransmitter.getEstimatedRotation())) * IDENTITY_FRONT;
2451 2346
@@ -2494,12 +2389,6 @@ void Application::updateCamera(float deltaTime) { · 42 unmodified lines
2494 glm::vec3 position = _faceshift.getHeadTranslation() * EYE_OFFSET_SCALE;2389 glm::vec3 position = _faceshift.getHeadTranslation() * EYE_OFFSET_SCALE;
2495 _myCamera.setEyeOffsetPosition(glm::vec3(position.x * xSign, position.y, -position.z));2390 _myCamera.setEyeOffsetPosition(glm::vec3(position.x * xSign, position.y, -position.z));
2496 updateProjectionMatrix();2391 updateProjectionMatrix();
2497
2498 } else if (_webcam.isActive()) {
2499 const float EYE_OFFSET_SCALE = 0.5f;
2500 glm::vec3 position = _webcam.getEstimatedPosition() * EYE_OFFSET_SCALE;
2501 _myCamera.setEyeOffsetPosition(glm::vec3(position.x * xSign, -position.y, position.z));
2502 updateProjectionMatrix();
2503 }2392 }
2504 }2393 }
2505 }2394 }
@@ -2611,8 +2500,8 @@ void Application::updateAvatar(float deltaTime) { · 105 unmodified lines
2611 _myAvatar.getHand().setPitchUpdate(0.f);2500 _myAvatar.getHand().setPitchUpdate(0.f);
2612 _pitchFromTouch = 0.0f;2501 _pitchFromTouch = 0.0f;
2613 2502
2614 // Update my avatar's state from gyros and/or webcam2503 // Update my avatar's state from gyros
2615 _myAvatar.updateFromGyrosAndOrWebcam(Menu::getInstance()->isOptionChecked(MenuOption::TurnWithHead));2504 _myAvatar.updateFromGyros(Menu::getInstance()->isOptionChecked(MenuOption::TurnWithHead));
2616 2505
2617 // Update head mouse from faceshift if active2506 // Update head mouse from faceshift if active
2618 if (_faceshift.isActive()) {2507 if (_faceshift.isActive()) {
@@ -2625,41 +2514,6 @@ void Application::updateAvatar(float deltaTime) { · 6 unmodified lines
2625 _headMouseY -= headVelocity.x * HEADMOUSE_FACESHIFT_PITCH_SCALE;2514 _headMouseY -= headVelocity.x * HEADMOUSE_FACESHIFT_PITCH_SCALE;
2626 }2515 }
2627 2516
2628 if (_serialHeadSensor.isActive()) {
2629
2630 // Grab latest readings from the gyros
2631 float measuredPitchRate = _serialHeadSensor.getLastPitchRate();
2632 float measuredYawRate = _serialHeadSensor.getLastYawRate();
2633
2634 // Update gyro-based mouse (X,Y on screen)
2635 const float MIN_MOUSE_RATE = 3.0;
2636 const float HORIZONTAL_PIXELS_PER_DEGREE = 2880.f / 45.f;
2637 const float VERTICAL_PIXELS_PER_DEGREE = 1800.f / 30.f;
2638 if (powf(measuredYawRate * measuredYawRate +
2639 measuredPitchRate * measuredPitchRate, 0.5) > MIN_MOUSE_RATE) {
2640 _headMouseX -= measuredYawRate * HORIZONTAL_PIXELS_PER_DEGREE * deltaTime;
2641 _headMouseY -= measuredPitchRate * VERTICAL_PIXELS_PER_DEGREE * deltaTime;
2642 }
2643
2644 const float MIDPOINT_OF_SCREEN = 0.5;
2645
2646 // Only use gyro to set lookAt if mouse hasn't selected an avatar
2647 if (!_lookatTargetAvatar) {
2648
2649 // Set lookAtPosition if an avatar is at the center of the screen
2650 glm::vec3 screenCenterRayOrigin, screenCenterRayDirection;
2651 _viewFrustum.computePickRay(MIDPOINT_OF_SCREEN, MIDPOINT_OF_SCREEN, screenCenterRayOrigin, screenCenterRayDirection);
2652
2653 glm::vec3 eyePosition;
2654 updateLookatTargetAvatar(screenCenterRayOrigin, screenCenterRayDirection, eyePosition);
2655 if (_lookatTargetAvatar) {
2656 glm::vec3 myLookAtFromMouse(eyePosition);
2657 _myAvatar.getHead().setLookAtPosition(myLookAtFromMouse);
2658 }
2659 }
2660
2661 }
2662
2663 // Constrain head-driven mouse to edges of screen2517 // Constrain head-driven mouse to edges of screen
2664 _headMouseX = glm::clamp(_headMouseX, 0, _glWidget->width());2518 _headMouseX = glm::clamp(_headMouseX, 0, _glWidget->width());
2665 _headMouseY = glm::clamp(_headMouseY, 0, _glWidget->height());2519 _headMouseY = glm::clamp(_headMouseY, 0, _glWidget->height());
@@ -2740,15 +2594,12 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 74 unmodified lines
2740 2594
2741 unsigned char voxelQueryPacket[MAX_PACKET_SIZE];2595 unsigned char voxelQueryPacket[MAX_PACKET_SIZE];
2742 2596
2743 NodeList* nodeList = NodeList::getInstance();
2744
2745 // Iterate all of the nodes, and get a count of how many voxel servers we have...2597 // Iterate all of the nodes, and get a count of how many voxel servers we have...
2746 int totalServers = 0;2598 int totalServers = 0;
2747 int inViewServers = 0;2599 int inViewServers = 0;
2748 int unknownJurisdictionServers = 0;2600 int unknownJurisdictionServers = 0;
2749 2601
2750 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {2602 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
2751
2752 // only send to the NodeTypes that are serverType2603 // only send to the NodeTypes that are serverType
2753 if (node->getActiveSocket() != NULL && node->getType() == serverType) {2604 if (node->getActiveSocket() != NULL && node->getType() == serverType) {
2754 totalServers++;2605 totalServers++;
@@ -2782,7 +2633,7 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 27 unmodified lines
2782 }2633 }
2783 2634
2784 if (wantExtraDebugging && unknownJurisdictionServers > 0) {2635 if (wantExtraDebugging && unknownJurisdictionServers > 0) {
2785 qDebug("Servers: total %d, in view %d, unknown jurisdiction %d \n",2636 qDebug("Servers: total %d, in view %d, unknown jurisdiction %d",
2786 totalServers, inViewServers, unknownJurisdictionServers);2637 totalServers, inViewServers, unknownJurisdictionServers);
2787 }2638 }
2788 2639
@@ -2803,10 +2654,12 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 14 unmodified lines
2803 }2654 }
2804 2655
2805 if (wantExtraDebugging && unknownJurisdictionServers > 0) {2656 if (wantExtraDebugging && unknownJurisdictionServers > 0) {
2806 qDebug("perServerPPS: %d perUnknownServer: %d\n", perServerPPS, perUnknownServer);2657 qDebug("perServerPPS: %d perUnknownServer: %d", perServerPPS, perUnknownServer);
2807 }2658 }
2808 2659
2809 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {2660 NodeList* nodeList = NodeList::getInstance();
2661
2662 foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {
2810 // only send to the NodeTypes that are serverType2663 // only send to the NodeTypes that are serverType
2811 if (node->getActiveSocket() != NULL && node->getType() == serverType) {2664 if (node->getActiveSocket() != NULL && node->getType() == serverType) {
2812 2665
@@ -2822,7 +2675,7 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 9 unmodified lines
2822 if (jurisdictions.find(nodeUUID) == jurisdictions.end()) {2675 if (jurisdictions.find(nodeUUID) == jurisdictions.end()) {
2823 unknownView = true; // assume it's in view2676 unknownView = true; // assume it's in view
2824 if (wantExtraDebugging) {2677 if (wantExtraDebugging) {
2825 qDebug() << "no known jurisdiction for node " << *node << ", assume it's visible.\n";2678 qDebug() << "no known jurisdiction for node " << *node << ", assume it's visible.";
2826 }2679 }
2827 } else {2680 } else {
2828 const JurisdictionMap& map = (jurisdictions)[nodeUUID];2681 const JurisdictionMap& map = (jurisdictions)[nodeUUID];
@@ -2843,7 +2696,7 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 14 unmodified lines
2843 }2696 }
2844 } else {2697 } else {
2845 if (wantExtraDebugging) {2698 if (wantExtraDebugging) {
2846 qDebug() << "Jurisdiction without RootCode for node " << *node << ". That's unusual!\n";2699 qDebug() << "Jurisdiction without RootCode for node " << *node << ". That's unusual!";
2847 }2700 }
2848 }2701 }
2849 }2702 }
@@ -2853,7 +2706,7 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 3 unmodified lines
2853 } else if (unknownView) {2706 } else if (unknownView) {
2854 if (wantExtraDebugging) {2707 if (wantExtraDebugging) {
2855 qDebug() << "no known jurisdiction for node " << *node << ", give it budget of "2708 qDebug() << "no known jurisdiction for node " << *node << ", give it budget of "
2856 << perUnknownServer << " to send us jurisdiction.\n";2709 << perUnknownServer << " to send us jurisdiction.";
2857 }2710 }
2858 2711
2859 // set the query's position/orientation to be degenerate in a manner that will get the scene quickly2712 // set the query's position/orientation to be degenerate in a manner that will get the scene quickly
@@ -2863,14 +2716,14 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 3 unmodified lines
2863 _voxelQuery.setCameraPosition(glm::vec3(-0.1,-0.1,-0.1));2716 _voxelQuery.setCameraPosition(glm::vec3(-0.1,-0.1,-0.1));
2864 const glm::quat OFF_IN_NEGATIVE_SPACE = glm::quat(-0.5, 0, -0.5, 1.0);2717 const glm::quat OFF_IN_NEGATIVE_SPACE = glm::quat(-0.5, 0, -0.5, 1.0);
2865 _voxelQuery.setCameraOrientation(OFF_IN_NEGATIVE_SPACE);2718 _voxelQuery.setCameraOrientation(OFF_IN_NEGATIVE_SPACE);
2866 _voxelQuery.setCameraNearClip(0.1);2719 _voxelQuery.setCameraNearClip(0.1f);
2867 _voxelQuery.setCameraFarClip(0.1);2720 _voxelQuery.setCameraFarClip(0.1f);
2868 if (wantExtraDebugging) {2721 if (wantExtraDebugging) {
2869 qDebug() << "Using 'minimal' camera position for node " << *node << "\n";2722 qDebug() << "Using 'minimal' camera position for node" << *node;
2870 }2723 }
2871 } else {2724 } else {
2872 if (wantExtraDebugging) {2725 if (wantExtraDebugging) {
2873 qDebug() << "Using regular camera position for node " << *node << "\n";2726 qDebug() << "Using regular camera position for node" << *node;
2874 }2727 }
2875 }2728 }
2876 _voxelQuery.setMaxOctreePacketsPerSecond(perUnknownServer);2729 _voxelQuery.setMaxOctreePacketsPerSecond(perUnknownServer);
@@ -2894,7 +2747,7 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node · 17 unmodified lines
2894 // make sure we still have an active socket2747 // make sure we still have an active socket
2895 if (node->getActiveSocket()) {2748 if (node->getActiveSocket()) {
2896 nodeList->getNodeSocket().writeDatagram((char*) voxelQueryPacket, packetLength,2749 nodeList->getNodeSocket().writeDatagram((char*) voxelQueryPacket, packetLength,
2897 node->getActiveSocket()->getAddress(), node->getActiveSocket()->getPort());2750 node->getActiveSocket()->getAddress(), node->getActiveSocket()->getPort());
2898 }2751 }
2899 2752
2900 // Feed number of bytes to corresponding channel of the bandwidth meter2753 // Feed number of bytes to corresponding channel of the bandwidth meter
@@ -3022,9 +2875,9 @@ void Application::setupWorldLight() { · 121 unmodified lines
3022 glm::vec3 sunDirection = getSunDirection();2875 glm::vec3 sunDirection = getSunDirection();
3023 GLfloat light_position0[] = { sunDirection.x, sunDirection.y, sunDirection.z, 0.0 };2876 GLfloat light_position0[] = { sunDirection.x, sunDirection.y, sunDirection.z, 0.0 };
3024 glLightfv(GL_LIGHT0, GL_POSITION, light_position0);2877 glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
3025 GLfloat ambient_color[] = { 0.7, 0.7, 0.8 };2878 GLfloat ambient_color[] = { 0.7f, 0.7f, 0.8f };
3026 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);2879 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
3027 GLfloat diffuse_color[] = { 0.8, 0.7, 0.7 };2880 GLfloat diffuse_color[] = { 0.8f, 0.7f, 0.7f };
3028 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);2881 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_color);
3029 2882
3030 glLightfv(GL_LIGHT0, GL_SPECULAR, WHITE_SPECULAR_COLOR);2883 glLightfv(GL_LIGHT0, GL_SPECULAR, WHITE_SPECULAR_COLOR);
@@ -3105,7 +2958,6 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { · 74 unmodified lines
3105 glEnable(GL_DEPTH_TEST);2958 glEnable(GL_DEPTH_TEST);
3106 2959
3107 // Enable to show line from me to the voxel I am touching2960 // Enable to show line from me to the voxel I am touching
3108 //renderLineToTouchedVoxel();
3109 //renderThrustAtVoxel(_voxelThrust);2961 //renderThrustAtVoxel(_voxelThrust);
3110 2962
3111 if (!selfAvatarOnly) {2963 if (!selfAvatarOnly) {
@@ -3253,12 +3105,6 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { · 141 unmodified lines
3253 }3105 }
3254 }3106 }
3255 3107
3256 {
3257 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
3258 "Application::displaySide() ... renderFollowIndicator...");
3259 renderFollowIndicator();
3260 }
3261
3262 // render transmitter pick ray, if non-empty3108 // render transmitter pick ray, if non-empty
3263 if (_transmitterPickStart != _transmitterPickEnd) {3109 if (_transmitterPickStart != _transmitterPickEnd) {
3264 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),3110 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
@@ -3291,10 +3137,10 @@ void Application::loadTranslatedViewMatrix(const glm::vec3& translation) { · 26 unmodified lines
3291 translation.z + _viewMatrixTranslation.z);3137 translation.z + _viewMatrixTranslation.z);
3292}3138}
3293 3139
3294void Application::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& near,3140void Application::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal,
3295 float& far, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const {3141 float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const {
3296 3142
3297 _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, near, far, nearClipPlane, farClipPlane);3143 _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
3298}3144}
3299 3145
3300void Application::displayOverlay() {3146void Application::displayOverlay() {
@@ -3326,8 +3172,7 @@ void Application::displayOverlay() { · 25 unmodified lines
3326 3172
3327 //noiseTest(_glWidget->width(), _glWidget->height());3173 //noiseTest(_glWidget->width(), _glWidget->height());
3328 3174
3329 if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)3175 if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)) {
3330 && USING_INVENSENSE_MPU9150) {
3331 // Display small target box at center or head mouse target that can also be used to measure LOD3176 // Display small target box at center or head mouse target that can also be used to measure LOD
3332 glColor3f(1.0, 1.0, 1.0);3177 glColor3f(1.0, 1.0, 1.0);
3333 glDisable(GL_LINE_SMOOTH);3178 glDisable(GL_LINE_SMOOTH);
@@ -3363,9 +3208,6 @@ void Application::displayOverlay() { · 29 unmodified lines
3363 }3208 }
3364 }3209 }
3365 3210
3366 // Show detected levels from the serial I/O ADC channel sensors
3367 if (_displayLevels) _serialHeadSensor.renderLevels(_glWidget->width(), _glWidget->height());
3368
3369 // Show hand transmitter data if detected3211 // Show hand transmitter data if detected
3370 if (_myTransmitter.isConnected()) {3212 if (_myTransmitter.isConnected()) {
3371 _myTransmitter.renderLevels(_glWidget->width(), _glWidget->height());3213 _myTransmitter.renderLevels(_glWidget->width(), _glWidget->height());
@@ -3385,14 +3227,14 @@ void Application::displayOverlay() { · 13 unmodified lines
3385 glPointSize(1.0f);3227 glPointSize(1.0f);
3386 char nodes[100];3228 char nodes[100];
3387 3229
3388 NodeList* nodeList = NodeList::getInstance();
3389 int totalAvatars = 0, totalServers = 0;3230 int totalAvatars = 0, totalServers = 0;
3390 3231
3391 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {3232 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
3392 node->getType() == NODE_TYPE_AGENT ? totalAvatars++ : totalServers++;3233 node->getType() == NODE_TYPE_AGENT ? totalAvatars++ : totalServers++;
3393 }3234 }
3235
3394 sprintf(nodes, "Servers: %d, Avatars: %d\n", totalServers, totalAvatars);3236 sprintf(nodes, "Servers: %d, Avatars: %d\n", totalServers, totalAvatars);
3395 drawtext(_glWidget->width() - 150, 20, 0.10, 0, 1.0, 0, nodes, 1, 0, 0);3237 drawtext(_glWidget->width() - 150, 20, 0.10f, 0, 1.0f, 0, nodes, 1, 0, 0);
3396 }3238 }
3397 3239
3398 // testing rendering coverage map3240 // testing rendering coverage map
@@ -3414,14 +3256,10 @@ void Application::displayOverlay() { · 15 unmodified lines
3414 char frameTimer[10];3256 char frameTimer[10];
3415 uint64_t mSecsNow = floor(usecTimestampNow() / 1000.0 + 0.5);3257 uint64_t mSecsNow = floor(usecTimestampNow() / 1000.0 + 0.5);
3416 sprintf(frameTimer, "%d\n", (int)(mSecsNow % 1000));3258 sprintf(frameTimer, "%d\n", (int)(mSecsNow % 1000));
3417 drawtext(_glWidget->width() - 100, _glWidget->height() - 20, 0.30, 0, 1.0, 0, frameTimer, 0, 0, 0);3259 drawtext(_glWidget->width() - 100, _glWidget->height() - 20, 0.30f, 0, 1.0f, 0, frameTimer, 0, 0, 0);
3418 drawtext(_glWidget->width() - 102, _glWidget->height() - 22, 0.30, 0, 1.0, 0, frameTimer, 1, 1, 1);3260 drawtext(_glWidget->width() - 102, _glWidget->height() - 22, 0.30f, 0, 1.0f, 0, frameTimer, 1, 1, 1);
3419 }3261 }
3420 3262
3421
3422 // render the webcam input frame
3423 _webcam.renderPreview(_glWidget->width(), _glWidget->height());
3424
3425 _palette.render(_glWidget->width(), _glWidget->height());3263 _palette.render(_glWidget->width(), _glWidget->height());
3426 3264
3427 QAction* paintColorAction = NULL;3265 QAction* paintColorAction = NULL;
@@ -3477,6 +3315,7 @@ void Application::displayOverlay() { · 49 unmodified lines
3477 glPopMatrix();3315 glPopMatrix();
3478}3316}
3479 3317
3318
3480void Application::displayStats() {3319void Application::displayStats() {
3481 int statsVerticalOffset = 8;3320 int statsVerticalOffset = 8;
3482 const int PELS_PER_LINE = 15;3321 const int PELS_PER_LINE = 15;
@@ -3490,8 +3329,8 @@ void Application::displayStats() { · 7 unmodified lines
3490 int pingAudio = 0, pingAvatar = 0, pingVoxel = 0, pingVoxelMax = 0;3329 int pingAudio = 0, pingAvatar = 0, pingVoxel = 0, pingVoxelMax = 0;
3491 3330
3492 NodeList* nodeList = NodeList::getInstance();3331 NodeList* nodeList = NodeList::getInstance();
3493 Node* audioMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER);3332 SharedNodePointer audioMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER);
3494 Node* avatarMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);3333 SharedNodePointer avatarMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
3495 3334
3496 pingAudio = audioMixerNode ? audioMixerNode->getPingMs() : 0;3335 pingAudio = audioMixerNode ? audioMixerNode->getPingMs() : 0;
3497 pingAvatar = avatarMixerNode ? avatarMixerNode->getPingMs() : 0;3336 pingAvatar = avatarMixerNode ? avatarMixerNode->getPingMs() : 0;
@@ -3500,7 +3339,8 @@ void Application::displayStats() { · 2 unmodified lines
3500 // Now handle voxel servers, since there could be more than one, we average their ping times3339 // Now handle voxel servers, since there could be more than one, we average their ping times
3501 unsigned long totalPingVoxel = 0;3340 unsigned long totalPingVoxel = 0;
3502 int voxelServerCount = 0;3341 int voxelServerCount = 0;
3503 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {3342
3343 foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {
3504 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {3344 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
3505 totalPingVoxel += node->getPingMs();3345 totalPingVoxel += node->getPingMs();
3506 voxelServerCount++;3346 voxelServerCount++;
@@ -3509,6 +3349,7 @@ void Application::displayStats() { · 2 unmodified lines
3509 }3349 }
3510 }3350 }
3511 }3351 }
3352
3512 if (voxelServerCount) {3353 if (voxelServerCount) {
3513 pingVoxel = totalPingVoxel/voxelServerCount;3354 pingVoxel = totalPingVoxel/voxelServerCount;
3514 }3355 }
@@ -3525,7 +3366,7 @@ void Application::displayStats() { · 10 unmodified lines
3525 sprintf(avatarStats, "Avatar: pos %.3f, %.3f, %.3f, vel %.1f, yaw = %.2f", avatarPos.x, avatarPos.y, avatarPos.z, glm::length(_myAvatar.getVelocity()), _myAvatar.getBodyYaw());3366 sprintf(avatarStats, "Avatar: pos %.3f, %.3f, %.3f, vel %.1f, yaw = %.2f", avatarPos.x, avatarPos.y, avatarPos.z, glm::length(_myAvatar.getVelocity()), _myAvatar.getBodyYaw());
3526 drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, avatarStats);3367 drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, avatarStats);
3527 3368
3528 Node* avatarMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);3369 SharedNodePointer avatarMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
3529 char avatarMixerStats[200];3370 char avatarMixerStats[200];
3530 if (avatarMixer) {3371 if (avatarMixer) {
3531 sprintf(avatarMixerStats, "Avatar Mixer: %.f kbps, %.f pps",3372 sprintf(avatarMixerStats, "Avatar Mixer: %.f kbps, %.f pps",
@@ -3656,25 +3497,6 @@ void Application::displayStats() { · 124 unmodified lines
3656 }3497 }
3657 statsVerticalOffset += PELS_PER_LINE;3498 statsVerticalOffset += PELS_PER_LINE;
3658 drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, (char*)voxelStats.str().c_str());3499 drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, (char*)voxelStats.str().c_str());
3659
3660
3661 // Leap data
3662 statsVerticalOffset += PELS_PER_LINE;
3663 drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, (char*)LeapManager::statusString().c_str());
3664
3665 if (_perfStatsOn) {
3666 // Get the PerfStats group details. We need to allocate and array of char* long enough to hold 1+groups
3667 char** perfStatLinesArray = new char*[PerfStat::getGroupCount()+1];
3668 int lines = PerfStat::DumpStats(perfStatLinesArray);
3669
3670 for (int line=0; line < lines; line++) {
3671 statsVerticalOffset += PELS_PER_LINE;
3672 drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, perfStatLinesArray[line]);
3673 delete perfStatLinesArray[line]; // we're responsible for cleanup
3674 perfStatLinesArray[line]=NULL;
3675 }
3676 delete []perfStatLinesArray; // we're responsible for cleanup
3677 }
3678}3500}
3679 3501
3680void Application::renderThrustAtVoxel(const glm::vec3& thrust) {3502void Application::renderThrustAtVoxel(const glm::vec3& thrust) {
@@ -3689,20 +3511,6 @@ void Application::renderThrustAtVoxel(const glm::vec3& thrust) { · 8 unmodified lines
3689 }3511 }
3690}3512}
3691 3513
3692void Application::renderLineToTouchedVoxel() {
3693 // Draw a teal line to the voxel I am currently dragging on
3694 if (_mousePressed) {
3695 glColor3f(0, 1, 1);
3696 glLineWidth(2.0f);
3697 glBegin(GL_LINES);
3698 glm::vec3 voxelTouched = getMouseVoxelWorldCoordinates(_mouseVoxelDragging);
3699 glVertex3f(voxelTouched.x, voxelTouched.y, voxelTouched.z);
3700 glm::vec3 headPosition = _myAvatar.getHeadJointPosition();
3701 glVertex3fv(&headPosition.x);
3702 glEnd();
3703 }
3704}
3705
3706 3514
3707glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) {3515glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) {
3708 float horizontalScale = _glWidget->width() / 2.0f;3516 float horizontalScale = _glWidget->width() / 2.0f;
@@ -3732,9 +3540,6 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { · 23 unmodified lines
3732 3540
3733// render the coverage map on screen3541// render the coverage map on screen
3734void Application::renderCoverageMapV2() {3542void Application::renderCoverageMapV2() {
3735
3736 //qDebug("renderCoverageMap()\n");
3737
3738 glDisable(GL_LIGHTING);3543 glDisable(GL_LIGHTING);
3739 glLineWidth(2.0);3544 glLineWidth(2.0);
3740 glBegin(GL_LINES);3545 glBegin(GL_LINES);
@@ -3778,8 +3583,6 @@ void Application::renderCoverageMapsV2Recursively(CoverageMapV2* map) { · 37 unmodified lines
3778// render the coverage map on screen3583// render the coverage map on screen
3779void Application::renderCoverageMap() {3584void Application::renderCoverageMap() {
3780 3585
3781 //qDebug("renderCoverageMap()\n");
3782
3783 glDisable(GL_LIGHTING);3586 glDisable(GL_LIGHTING);
3784 glLineWidth(2.0);3587 glLineWidth(2.0);
3785 glBegin(GL_LINES);3588 glBegin(GL_LINES);
@@ -3855,8 +3658,8 @@ void Application::renderAvatars(bool forceRenderHead, bool selfAvatarOnly) { · 69 unmodified lines
3855 // Render avatars of other nodes3658 // Render avatars of other nodes
3856 NodeList* nodeList = NodeList::getInstance();3659 NodeList* nodeList = NodeList::getInstance();
3857 3660
3858 for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {3661 foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {
3859 node->lock();3662 QMutexLocker(&node->getMutex());
3860 3663
3861 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {3664 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) {
3862 Avatar *avatar = (Avatar *)node->getLinkedData();3665 Avatar *avatar = (Avatar *)node->getLinkedData();
@@ -3866,8 +3669,6 @@ void Application::renderAvatars(bool forceRenderHead, bool selfAvatarOnly) { · 3 unmodified lines
3866 avatar->render(false);3669 avatar->render(false);
3867 avatar->setDisplayingLookatVectors(Menu::getInstance()->isOptionChecked(MenuOption::LookAtVectors));3670 avatar->setDisplayingLookatVectors(Menu::getInstance()->isOptionChecked(MenuOption::LookAtVectors));
3868 }3671 }
3869
3870 node->unlock();
3871 }3672 }
3872 3673
3873 // render avatar fades3674 // render avatar fades
@@ -4112,28 +3913,11 @@ void Application::eyedropperVoxelUnderCursor() { · 238 unmodified lines
4112 }3913 }
4113}3914}
4114 3915
4115void Application::toggleFollowMode() {
4116 glm::vec3 mouseRayOrigin, mouseRayDirection;
4117 _viewFrustum.computePickRay(_pieMenu.getX() / (float)_glWidget->width(),
4118 _pieMenu.getY() / (float)_glWidget->height(),
4119 mouseRayOrigin, mouseRayDirection);
4120 glm::vec3 eyePositionIgnored;
4121 QUuid nodeUUIDIgnored;
4122 Avatar* leadingAvatar = findLookatTargetAvatar(mouseRayOrigin, mouseRayDirection, eyePositionIgnored, nodeUUIDIgnored);
4123
4124 _myAvatar.follow(leadingAvatar);
4125}
4126
4127void Application::resetSensors() {3916void Application::resetSensors() {
4128 _headMouseX = _mouseX = _glWidget->width() / 2;3917 _headMouseX = _mouseX = _glWidget->width() / 2;
4129 _headMouseY = _mouseY = _glWidget->height() / 2;3918 _headMouseY = _mouseY = _glWidget->height() / 2;
4130 3919
4131 if (_serialHeadSensor.isActive()) {
4132 _serialHeadSensor.resetAverages();
4133 }
4134 _webcam.reset();
4135 _faceshift.reset();3920 _faceshift.reset();
4136 LeapManager::reset();
4137 3921
4138 if (OculusManager::isConnected()) {3922 if (OculusManager::isConnected()) {
4139 OculusManager::reset();3923 OculusManager::reset();
@@ -4184,13 +3968,13 @@ void Application::updateWindowTitle(){ · 44 unmodified lines
4184 title += _profile.getLastDomain();3968 title += _profile.getLastDomain();
4185 title += buildVersion;3969 title += buildVersion;
4186 3970
4187 qDebug("Application title set to: %s.\n", title.toStdString().c_str());3971 qDebug("Application title set to: %s", title.toStdString().c_str());
4188 _window->setWindowTitle(title);3972 _window->setWindowTitle(title);
4189}3973}
4190 3974
4191void Application::domainChanged(QString domain) {3975void Application::domainChanged(const QString& domainHostname) {
4192 // update the user's last domain in their Profile (which will propagate to data-server)3976 // update the user's last domain in their Profile (which will propagate to data-server)
4193 _profile.updateDomain(domain);3977 _profile.updateDomain(domainHostname);
4194 3978
4195 updateWindowTitle();3979 updateWindowTitle();
4196 3980
@@ -4201,13 +3985,13 @@ void Application::domainChanged(QString domain) { · 4 unmodified lines
4201 _voxelServerJurisdictions.clear();3985 _voxelServerJurisdictions.clear();
4202 _octreeServerSceneStats.clear();3986 _octreeServerSceneStats.clear();
4203 _particleServerJurisdictions.clear();3987 _particleServerJurisdictions.clear();
4204}
4205
4206void Application::nodeAdded(Node* node) {
4207 3988
3989 // reset our persist thread
3990 qDebug() << "Domain changed to" << domainHostname << ". Swapping persist cache.";
3991 updateLocalOctreeCache();
4208}3992}
4209 3993
4210void Application::nodeKilled(Node* node) {3994void Application::nodeKilled(SharedNodePointer node) {
4211 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {3995 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
4212 QUuid nodeUUID = node->getUUID();3996 QUuid nodeUUID = node->getUUID();
4213 // see if this is the first we've heard of this node...3997 // see if this is the first we've heard of this node...
@@ -4223,7 +4007,7 @@ void Application::nodeKilled(Node* node) { · 9 unmodified lines
4223 if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnVoxelServerChanges)) {4007 if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnVoxelServerChanges)) {
4224 VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE);4008 VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE);
4225 fade.voxelDetails = rootDetails;4009 fade.voxelDetails = rootDetails;
4226 const float slightly_smaller = 0.99;4010 const float slightly_smaller = 0.99f;
4227 fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;4011 fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;
4228 _voxelFades.push_back(fade);4012 _voxelFades.push_back(fade);
4229 }4013 }
@@ -4254,7 +4038,7 @@ void Application::nodeKilled(Node* node) { · 24 unmodified lines
4254 if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnVoxelServerChanges)) {4038 if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnVoxelServerChanges)) {
4255 VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE);4039 VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE);
4256 fade.voxelDetails = rootDetails;4040 fade.voxelDetails = rootDetails;
4257 const float slightly_smaller = 0.99;4041 const float slightly_smaller = 0.99f;
4258 fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;4042 fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;
4259 _voxelFades.push_back(fade);4043 _voxelFades.push_back(fade);
4260 }4044 }
@@ -4287,7 +4071,7 @@ void Application::trackIncomingVoxelPacket(unsigned char* messageData, ssize_t m · 26 unmodified lines
4287 const HifiSockAddr& senderSockAddr, bool wasStatsPacket) {4071 const HifiSockAddr& senderSockAddr, bool wasStatsPacket) {
4288 4072
4289 // Attempt to identify the sender from it's address.4073 // Attempt to identify the sender from it's address.
4290 Node* serverNode = NodeList::getInstance()->nodeWithAddress(senderSockAddr);4074 SharedNodePointer serverNode = NodeList::getInstance()->nodeWithAddress(senderSockAddr);
4291 if (serverNode) {4075 if (serverNode) {
4292 QUuid nodeUUID = serverNode->getUUID();4076 QUuid nodeUUID = serverNode->getUUID();
4293 4077
@@ -4304,7 +4088,7 @@ void Application::trackIncomingVoxelPacket(unsigned char* messageData, ssize_t m · 10 unmodified lines
4304int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLength, const HifiSockAddr& senderSockAddr) {4088int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLength, const HifiSockAddr& senderSockAddr) {
4305 4089
4306 // But, also identify the sender, and keep track of the contained jurisdiction root for this server4090 // But, also identify the sender, and keep track of the contained jurisdiction root for this server
4307 Node* server = NodeList::getInstance()->nodeWithAddress(senderSockAddr);4091 SharedNodePointer server = NodeList::getInstance()->nodeWithAddress(senderSockAddr);
4308 4092
4309 // parse the incoming stats datas stick it in a temporary object for now, while we4093 // parse the incoming stats datas stick it in a temporary object for now, while we
4310 // determine which server it belongs to4094 // determine which server it belongs to
@@ -4344,7 +4128,7 @@ int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLen · 33 unmodified lines
4344 if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnVoxelServerChanges)) {4128 if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnVoxelServerChanges)) {
4345 VoxelFade fade(VoxelFade::FADE_OUT, NODE_ADDED_RED, NODE_ADDED_GREEN, NODE_ADDED_BLUE);4129 VoxelFade fade(VoxelFade::FADE_OUT, NODE_ADDED_RED, NODE_ADDED_GREEN, NODE_ADDED_BLUE);
4346 fade.voxelDetails = rootDetails;4130 fade.voxelDetails = rootDetails;
4347 const float slightly_smaller = 0.99;4131 const float slightly_smaller = 0.99f;
4348 fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;4132 fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller;
4349 _voxelFades.push_back(fade);4133 _voxelFades.push_back(fade);
4350 }4134 }
@@ -4361,101 +4145,92 @@ int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLen · 10 unmodified lines
4361}4145}
4362 4146
4363// Receive packets from other nodes/servers and decide what to do with them!4147// Receive packets from other nodes/servers and decide what to do with them!
4364void* Application::networkReceive(void* args) {4148void Application::processDatagrams() {
4365 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),4149 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
4366 "Application::networkReceive()");4150 "Application::networkReceive()");
4367 4151
4368 HifiSockAddr senderSockAddr;4152 HifiSockAddr senderSockAddr;
4369 ssize_t bytesReceived;4153 ssize_t bytesReceived;
4370 4154
4371 Application* app = Application::getInstance();4155 while (NodeList::getInstance()->getNodeSocket().hasPendingDatagrams() &&
4372 while (!app->_stopNetworkReceiveThread) {4156 (bytesReceived = NodeList::getInstance()->getNodeSocket().readDatagram((char*) _incomingPacket,
4373 if (NodeList::getInstance()->getNodeSocket().hasPendingDatagrams() &&4157 MAX_PACKET_SIZE,
4374 (bytesReceived = NodeList::getInstance()->getNodeSocket().readDatagram((char*) app->_incomingPacket,4158 senderSockAddr.getAddressPointer(),
4375 MAX_PACKET_SIZE,4159 senderSockAddr.getPortPointer()))) {
4376 senderSockAddr.getAddressPointer(),4160
4377 senderSockAddr.getPortPointer()))) {4161 _packetCount++;
4378 4162 _bytesCount += bytesReceived;
4379 app->_packetCount++;4163
4380 app->_bytesCount += bytesReceived;4164 if (packetVersionMatch(_incomingPacket)) {
4381 4165 // only process this packet if we have a match on the packet version
4382 if (packetVersionMatch(app->_incomingPacket)) {4166 switch (_incomingPacket[0]) {
4383 // only process this packet if we have a match on the packet version4167 case PACKET_TYPE_TRANSMITTER_DATA_V2:
4384 switch (app->_incomingPacket[0]) {4168 // V2 = IOS transmitter app
4385 case PACKET_TYPE_TRANSMITTER_DATA_V2:4169 _myTransmitter.processIncomingData(_incomingPacket, bytesReceived);
4386 // V2 = IOS transmitter app4170
4387 app->_myTransmitter.processIncomingData(app->_incomingPacket, bytesReceived);4171 break;
4388 4172 case PACKET_TYPE_MIXED_AUDIO:
4389 break;4173 QMetaObject::invokeMethod(&_audio, "addReceivedAudioToBuffer", Qt::QueuedConnection,
4390 case PACKET_TYPE_MIXED_AUDIO:4174 Q_ARG(QByteArray, QByteArray((char*) _incomingPacket, bytesReceived)));
4391 QMetaObject::invokeMethod(&app->_audio, "addReceivedAudioToBuffer", Qt::QueuedConnection,4175 break;
4392 Q_ARG(QByteArray, QByteArray((char*) app->_incomingPacket, bytesReceived)));4176
4393 break;4177 case PACKET_TYPE_PARTICLE_ADD_RESPONSE:
4394 4178 // look up our ParticleEditHanders....
4395 case PACKET_TYPE_PARTICLE_ADD_RESPONSE:4179 ParticleEditHandle::handleAddResponse(_incomingPacket, bytesReceived);
4396 // look up our ParticleEditHanders....4180 break;
4397 ParticleEditHandle::handleAddResponse(app->_incomingPacket, bytesReceived);4181
4398 break;4182 case PACKET_TYPE_PARTICLE_DATA:
4399 4183 case PACKET_TYPE_VOXEL_DATA:
4400 case PACKET_TYPE_PARTICLE_DATA:4184 case PACKET_TYPE_VOXEL_ERASE:
4401 case PACKET_TYPE_VOXEL_DATA:4185 case PACKET_TYPE_OCTREE_STATS:
4402 case PACKET_TYPE_VOXEL_ERASE:4186 case PACKET_TYPE_ENVIRONMENT_DATA: {
4403 case PACKET_TYPE_OCTREE_STATS:4187 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
4404 case PACKET_TYPE_ENVIRONMENT_DATA: {4188 "Application::networkReceive()... _voxelProcessor.queueReceivedPacket()");
4405 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),4189
4406 "Application::networkReceive()... _voxelProcessor.queueReceivedPacket()");4190 bool wantExtraDebugging = getLogger()->extraDebugging();
4407 4191 if (wantExtraDebugging && _incomingPacket[0] == PACKET_TYPE_VOXEL_DATA) {
4408 bool wantExtraDebugging = app->getLogger()->extraDebugging();4192 int numBytesPacketHeader = numBytesForPacketHeader(_incomingPacket);
4409 if (wantExtraDebugging && app->_incomingPacket[0] == PACKET_TYPE_VOXEL_DATA) {4193 unsigned char* dataAt = _incomingPacket + numBytesPacketHeader;
4410 int numBytesPacketHeader = numBytesForPacketHeader(app->_incomingPacket);4194 dataAt += sizeof(VOXEL_PACKET_FLAGS);
4411 unsigned char* dataAt = app->_incomingPacket + numBytesPacketHeader;4195 VOXEL_PACKET_SEQUENCE sequence = (*(VOXEL_PACKET_SEQUENCE*)dataAt);
4412 dataAt += sizeof(VOXEL_PACKET_FLAGS);4196 dataAt += sizeof(VOXEL_PACKET_SEQUENCE);
4413 VOXEL_PACKET_SEQUENCE sequence = (*(VOXEL_PACKET_SEQUENCE*)dataAt);4197 VOXEL_PACKET_SENT_TIME sentAt = (*(VOXEL_PACKET_SENT_TIME*)dataAt);
4414 dataAt += sizeof(VOXEL_PACKET_SEQUENCE);4198 dataAt += sizeof(VOXEL_PACKET_SENT_TIME);
4415 VOXEL_PACKET_SENT_TIME sentAt = (*(VOXEL_PACKET_SENT_TIME*)dataAt);4199 VOXEL_PACKET_SENT_TIME arrivedAt = usecTimestampNow();
4416 dataAt += sizeof(VOXEL_PACKET_SENT_TIME);4200 int flightTime = arrivedAt - sentAt;
4417 VOXEL_PACKET_SENT_TIME arrivedAt = usecTimestampNow();4201
4418 int flightTime = arrivedAt - sentAt;4202 printf("got PACKET_TYPE_VOXEL_DATA, sequence:%d flightTime:%d\n", sequence, flightTime);
4419
4420 printf("got PACKET_TYPE_VOXEL_DATA, sequence:%d flightTime:%d\n", sequence, flightTime);
4421 }
4422
4423 // add this packet to our list of voxel packets and process them on the voxel processing
4424 app->_voxelProcessor.queueReceivedPacket(senderSockAddr, app->_incomingPacket, bytesReceived);
4425 break;
4426 }4203 }
4427 case PACKET_TYPE_BULK_AVATAR_DATA:4204
4428 NodeList::getInstance()->processBulkNodeData(senderSockAddr,4205 // add this packet to our list of voxel packets and process them on the voxel processing
4429 app->_incomingPacket,4206 _voxelProcessor.queueReceivedPacket(senderSockAddr, _incomingPacket, bytesReceived);
4430 bytesReceived);4207 break;
4431 getInstance()->_bandwidthMeter.inputStream(BandwidthMeter::AVATARS).updateValue(bytesReceived);
4432 break;
4433 case PACKET_TYPE_AVATAR_URLS:
4434 processAvatarURLsMessage(app->_incomingPacket, bytesReceived);
4435 break;
4436 case PACKET_TYPE_AVATAR_FACE_VIDEO:
4437 processAvatarFaceVideoMessage(app->_incomingPacket, bytesReceived);
4438 break;
4439 case PACKET_TYPE_DATA_SERVER_GET:
4440 case PACKET_TYPE_DATA_SERVER_PUT:
4441 case PACKET_TYPE_DATA_SERVER_SEND:
4442 case PACKET_TYPE_DATA_SERVER_CONFIRM:
4443 DataServerClient::processMessageFromDataServer(app->_incomingPacket, bytesReceived);
4444 break;
4445 default:
4446 NodeList::getInstance()->processNodeData(senderSockAddr, app->_incomingPacket, bytesReceived);
4447 break;
4448 }4208 }
4209 case PACKET_TYPE_METAVOXEL_DATA:
4210 _metavoxels.processData(QByteArray((const char*) _incomingPacket, bytesReceived),
4211 senderSockAddr);
4212 break;
4213 case PACKET_TYPE_BULK_AVATAR_DATA:
4214 NodeList::getInstance()->processBulkNodeData(senderSockAddr,
4215 _incomingPacket,
4216 bytesReceived);
4217 getInstance()->_bandwidthMeter.inputStream(BandwidthMeter::AVATARS).updateValue(bytesReceived);
4218 break;
4219 case PACKET_TYPE_AVATAR_URLS:
4220 processAvatarURLsMessage(_incomingPacket, bytesReceived);
4221 break;
4222 case PACKET_TYPE_DATA_SERVER_GET:
4223 case PACKET_TYPE_DATA_SERVER_PUT:
4224 case PACKET_TYPE_DATA_SERVER_SEND:
4225 case PACKET_TYPE_DATA_SERVER_CONFIRM:
4226 DataServerClient::processMessageFromDataServer(_incomingPacket, bytesReceived);
4227 break;
4228 default:
4229 NodeList::getInstance()->processNodeData(senderSockAddr, _incomingPacket, bytesReceived);
4230 break;
4449 }4231 }
4450 } else if (!app->_enableNetworkThread) {
4451 break;
4452 }4232 }
4453 }4233 }
4454
4455 if (app->_enableNetworkThread) {
4456 pthread_exit(0);
4457 }
4458 return NULL;
4459}4234}
4460 4235
4461void Application::packetSentNotification(ssize_t length) {4236void Application::packetSentNotification(ssize_t length) {
@@ -4472,14 +4247,12 @@ void Application::loadScript() { · 10 unmodified lines
4472 QByteArray fileNameAscii = fileNameString.toLocal8Bit();4247 QByteArray fileNameAscii = fileNameString.toLocal8Bit();
4473 const char* fileName = fileNameAscii.data();4248 const char* fileName = fileNameAscii.data();
4474 4249
4475 printf("fileName:%s\n",fileName);
4476
4477 std::ifstream file(fileName, std::ios::in|std::ios::binary|std::ios::ate);4250 std::ifstream file(fileName, std::ios::in|std::ios::binary|std::ios::ate);
4478 if(!file.is_open()) {4251 if(!file.is_open()) {
4479 printf("error loading file\n");4252 qDebug("Error loading file %s", fileName);
4480 return;4253 return;
4481 }4254 }
4482 qDebug("loading file %s...\n", fileName);4255 qDebug("Loading file %s...", fileName);
4483 4256
4484 // get file length....4257 // get file length....
4485 unsigned long fileLength = file.tellg();4258 unsigned long fileLength = file.tellg();
@@ -4536,3 +4309,51 @@ void Application::toggleLogDialog() { · 50 unmodified lines
4536 _logDialog->close();4309 _logDialog->close();
4537 }4310 }
4538}4311}
4312
4313
4314void Application::initAvatarAndViewFrustum() {
4315 updateAvatar(0.f);
4316}
4317
4318QString Application::getLocalVoxelCacheFileName() {
4319 QString fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
4320 QDir logDir(fileName);
4321 if (!logDir.exists(fileName)) {
4322 logDir.mkdir(fileName);
4323 }
4324
4325 fileName.append(QString("/hifi.voxelscache."));
4326 fileName.append(_profile.getLastDomain());
4327 fileName.append(QString(".svo"));
4328
4329 return fileName;
4330}
4331
4332
4333void Application::updateLocalOctreeCache(bool firstTime) {
4334 // only do this if we've already got a persistThread or we're told this is the first time
4335 if (firstTime || _persistThread) {
4336
4337 if (_persistThread) {
4338 _persistThread->terminate();
4339 _persistThread->deleteLater();
4340 _persistThread = NULL;
4341 }
4342
4343 QString localVoxelCacheFileName = getLocalVoxelCacheFileName();
4344 const int LOCAL_CACHE_PERSIST_INTERVAL = 1000 * 10; // every 10 seconds
4345
4346 if (!Menu::getInstance()->isOptionChecked(MenuOption::DisableLocalVoxelCache)) {
4347 _persistThread = new OctreePersistThread(_voxels.getTree(),
4348 localVoxelCacheFileName.toLocal8Bit().constData(),LOCAL_CACHE_PERSIST_INTERVAL);
4349
4350 qDebug() << "updateLocalOctreeCache()... localVoxelCacheFileName=" << localVoxelCacheFileName;
4351 }
4352
4353 if (_persistThread) {
4354 _voxels.beginLoadingLocalVoxelCache(); // while local voxels are importing, don't do individual node VBO updates
4355 connect(_persistThread, SIGNAL(loadCompleted()), &_voxels, SLOT(localVoxelCacheLoaded()));
4356 _persistThread->initialize(true);
4357 }
4358 }
4359}

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