Showing the changes to interface/src/Application.cpp (1 of 15 files). Show all
Unified · Split
| @@ -109,7 +109,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 108 unmodified lines | |||
| 109 | _window(new QMainWindow(desktop())), | 109 | _window(new QMainWindow(desktop())), |
| 110 | _glWidget(new GLCanvas()), | 110 | _glWidget(new GLCanvas()), |
| 111 | _nodeThread(new QThread(this)), | 111 | _nodeThread(new QThread(this)), |
| 112 | _datagramProcessor(new DatagramProcessor()), | 112 | _datagramProcessor(), |
| 113 | _frameCount(0), | 113 | _frameCount(0), |
| 114 | _fps(120.0f), | 114 | _fps(120.0f), |
| 115 | _justStarted(true), | 115 | _justStarted(true), |
| @@ -174,20 +174,20 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 58 unmodified lines | |||
| 174 | listenPort = atoi(portStr); | 174 | listenPort = atoi(portStr); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | // start the nodeThread so its event loop is running | ||
| 178 | _nodeThread->start(); | ||
| 179 | |||
| 180 | // make sure the node thread is given highest priority | ||
| 181 | _nodeThread->setPriority(QThread::TimeCriticalPriority); | ||
| 182 | |||
| 177 | // put the NodeList and datagram processing on the node thread | 183 | // put the NodeList and datagram processing on the node thread |
| 178 | NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AGENT, listenPort); | 184 | NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AGENT, listenPort); |
| 179 | 185 | ||
| 180 | nodeList->moveToThread(_nodeThread); | 186 | nodeList->moveToThread(_nodeThread); |
| 181 | _datagramProcessor->moveToThread(_nodeThread); | 187 | _datagramProcessor.moveToThread(_nodeThread); |
| 182 | 188 | ||
| 183 | // connect the DataProcessor processDatagrams slot to the QUDPSocket readyRead() signal | 189 | // connect the DataProcessor processDatagrams slot to the QUDPSocket readyRead() signal |
| 184 | connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), _datagramProcessor, SLOT(processDatagrams())); | 190 | connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), &_datagramProcessor, SLOT(processDatagrams())); |
| 185 | |||
| 186 | // make sure the node thread is given highest priority | ||
| 187 | _nodeThread->setPriority(QThread::TimeCriticalPriority); | ||
| 188 | |||
| 189 | // start the nodeThread so its event loop is running | ||
| 190 | _nodeThread->start(); | ||
| 191 | 191 | ||
| 192 | // put the audio processing on a separate thread | 192 | // put the audio processing on a separate thread |
| 193 | QThread* audioThread = new QThread(this); | 193 | QThread* audioThread = new QThread(this); |
| @@ -231,12 +231,12 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 37 unmodified lines | |||
| 231 | #endif | 231 | #endif |
| 232 | 232 | ||
| 233 | // tell the NodeList instance who to tell the domain server we care about | 233 | // tell the NodeList instance who to tell the domain server we care about |
| 234 | const char nodeTypesOfInterest[] = {NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER, NODE_TYPE_VOXEL_SERVER, | 234 | nodeList->addSetOfNodeTypesToNodeInterestSet(QSet<NODE_TYPE>() << NODE_TYPE_AUDIO_MIXER << NODE_TYPE_AVATAR_MIXER |
| 235 | NODE_TYPE_PARTICLE_SERVER, NODE_TYPE_METAVOXEL_SERVER}; | 235 | << NODE_TYPE_VOXEL_SERVER << NODE_TYPE_PARTICLE_SERVER |
| 236 | nodeList->setNodeTypesOfInterest(nodeTypesOfInterest, sizeof(nodeTypesOfInterest)); | 236 | << NODE_TYPE_METAVOXEL_SERVER); |
| 237 | 237 | ||
| 238 | // move the silentNodeTimer to the _nodeThread | 238 | // move the silentNodeTimer to the _nodeThread |
| 239 | QTimer* silentNodeTimer = new QTimer(this); | 239 | QTimer* silentNodeTimer = new QTimer(); |
| 240 | connect(silentNodeTimer, SIGNAL(timeout()), nodeList, SLOT(removeSilentNodes())); | 240 | connect(silentNodeTimer, SIGNAL(timeout()), nodeList, SLOT(removeSilentNodes())); |
| 241 | silentNodeTimer->moveToThread(_nodeThread); | 241 | silentNodeTimer->moveToThread(_nodeThread); |
| 242 | silentNodeTimer->start(NODE_SILENCE_THRESHOLD_USECS / 1000); | 242 | silentNodeTimer->start(NODE_SILENCE_THRESHOLD_USECS / 1000); |
| @@ -282,17 +282,35 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 39 unmodified lines | |||
| 282 | Application::~Application() { | 282 | Application::~Application() { |
| 283 | 283 | ||
| 284 | qInstallMessageHandler(NULL); | 284 | qInstallMessageHandler(NULL); |
| 285 | 285 | ||
| 286 | // make sure we don't call the idle timer any more | 286 | // make sure we don't call the idle timer any more |
| 287 | delete idleTimer; | 287 | delete idleTimer; |
| 288 | 288 | ||
| 289 | Menu::getInstance()->saveSettings(); | ||
| 290 | |||
| 291 | _rearMirrorTools->saveSettings(_settings); | ||
| 292 | _settings->sync(); | ||
| 293 | |||
| 294 | // let the avatar mixer know we're out | ||
| 295 | NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1); | ||
| 296 | |||
| 289 | // ask the datagram processing thread to quit and wait until it is done | 297 | // ask the datagram processing thread to quit and wait until it is done |
| 290 | _nodeThread->thread()->quit(); | 298 | _nodeThread->quit(); |
| 291 | _nodeThread->thread()->wait(); | 299 | _nodeThread->wait(); |
| 292 | 300 | ||
| 293 | // ask the audio thread to quit and wait until it is done | 301 | // ask the audio thread to quit and wait until it is done |
| 294 | _audio.thread()->quit(); | 302 | _audio.thread()->quit(); |
| 295 | _audio.thread()->wait(); | 303 | _audio.thread()->wait(); |
| 304 | |||
| 305 | _voxelProcessor.terminate(); | ||
| 306 | _voxelHideShowThread.terminate(); | ||
| 307 | _voxelEditSender.terminate(); | ||
| 308 | _particleEditSender.terminate(); | ||
| 309 | if (_persistThread) { | ||
| 310 | _persistThread->terminate(); | ||
| 311 | _persistThread->deleteLater(); | ||
| 312 | _persistThread = NULL; | ||
| 313 | } | ||
| 296 | 314 | ||
| 297 | storeSizeAndPosition(); | 315 | storeSizeAndPosition(); |
| 298 | saveScripts(); | 316 | saveScripts(); |
| @@ -377,9 +395,6 @@ void Application::initializeGL() { · 78 unmodified lines | |||
| 377 | qDebug("Voxel parsing thread created."); | 395 | qDebug("Voxel parsing thread created."); |
| 378 | } | 396 | } |
| 379 | 397 | ||
| 380 | // call terminate before exiting | ||
| 381 | connect(this, SIGNAL(aboutToQuit()), SLOT(terminate())); | ||
| 382 | |||
| 383 | // call our timer function every second | 398 | // call our timer function every second |
| 384 | QTimer* timer = new QTimer(this); | 399 | QTimer* timer = new QTimer(this); |
| 385 | connect(timer, SIGNAL(timeout()), SLOT(timer())); | 400 | connect(timer, SIGNAL(timeout()), SLOT(timer())); |
| @@ -1328,11 +1343,11 @@ void Application::timer() { · 942 unmodified lines | |||
| 1328 | 1343 | ||
| 1329 | _fps = (float)_frameCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f); | 1344 | _fps = (float)_frameCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f); |
| 1330 | 1345 | ||
| 1331 | _packetsPerSecond = (float) _datagramProcessor->getPacketCount() / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f); | 1346 | _packetsPerSecond = (float) _datagramProcessor.getPacketCount() / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f); |
| 1332 | _bytesPerSecond = (float) _datagramProcessor->getByteCount() / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f); | 1347 | _bytesPerSecond = (float) _datagramProcessor.getByteCount() / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f); |
| 1333 | _frameCount = 0; | 1348 | _frameCount = 0; |
| 1334 | 1349 | ||
| 1335 | _datagramProcessor->resetCounters(); | 1350 | _datagramProcessor.resetCounters(); |
| 1336 | 1351 | ||
| 1337 | gettimeofday(&_timerStart, NULL); | 1352 | gettimeofday(&_timerStart, NULL); |
| 1338 | 1353 | ||
| @@ -1411,28 +1426,6 @@ void Application::idle() { · 72 unmodified lines | |||
| 1411 | } | 1426 | } |
| 1412 | } | 1427 | } |
| 1413 | 1428 | ||
| 1414 | void Application::terminate() { | ||
| 1415 | // Close serial port | ||
| 1416 | // close(serial_fd); | ||
| 1417 | |||
| 1418 | Menu::getInstance()->saveSettings(); | ||
| 1419 | _rearMirrorTools->saveSettings(_settings); | ||
| 1420 | _settings->sync(); | ||
| 1421 | |||
| 1422 | // let the avatar mixer know we're out | ||
| 1423 | NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1); | ||
| 1424 | |||
| 1425 | _voxelProcessor.terminate(); | ||
| 1426 | _voxelHideShowThread.terminate(); | ||
| 1427 | _voxelEditSender.terminate(); | ||
| 1428 | _particleEditSender.terminate(); | ||
| 1429 | if (_persistThread) { | ||
| 1430 | _persistThread->terminate(); | ||
| 1431 | _persistThread->deleteLater(); | ||
| 1432 | _persistThread = NULL; | ||
| 1433 | } | ||
| 1434 | } | ||
| 1435 | |||
| 1436 | void Application::checkBandwidthMeterClick() { | 1429 | void Application::checkBandwidthMeterClick() { |
| 1437 | // ... to be called upon button release | 1430 | // ... to be called upon button release |
| 1438 | 1431 | ||