History

Merge branch 'master' of https://github.com/worklist/hifi

Philip Rosedale committed 12 years ago

Commit 89414eb2 parents 11eaef6 7d56dd57 files · +178 −108Browse files

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

Unified · Split

interface/src/Application.cpp+28−98
@@ -108,6 +108,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 107 unmodified lines
108108 QApplication(argc, argv),
109109 _window(new QMainWindow(desktop())),
110110 _glWidget(new GLCanvas()),
111+ _nodeThread(new QThread(this)),
112+ _datagramProcessor(new DatagramProcessor()),
111113 _frameCount(0),
112114 _fps(120.0f),
113115 _justStarted(true),
@@ -145,10 +147,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 31 unmodified lines
145147 _voxelHideShowThread(&_voxels),
146148 _voxelEditSender(this),
147149 _particleEditSender(this),
148− _packetCount(0),
149150 _packetsPerSecond(0),
150151 _bytesPerSecond(0),
151− _bytesCount(0),
152152 _recentMaxPackets(0),
153153 _resetRecentMaxPacketsSoon(true),
154154 _swatch(NULL),
@@ -173,11 +173,21 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 18 unmodified lines
173173 if (portStr) {
174174 listenPort = atoi(portStr);
175175 }
176−
176+
177+ // put the NodeList and datagram processing on the node thread
177178 NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AGENT, listenPort);
178−
179− // connect our processDatagrams slot to the QUDPSocket readyRead() signal
180− connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), SLOT(processDatagrams()));
179+
180+ nodeList->moveToThread(_nodeThread);
181+ _datagramProcessor->moveToThread(_nodeThread);
182+
183+ // connect the DataProcessor processDatagrams slot to the QUDPSocket readyRead() signal
184+ 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();
181191
182192 // put the audio processing on a separate thread
183193 QThread* audioThread = new QThread(this);
@@ -192,7 +202,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 8 unmodified lines
192202 connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer)));
193203 connect(nodeList, SIGNAL(nodeAdded(SharedNodePointer)), &_voxels, SLOT(nodeAdded(SharedNodePointer)));
194204 connect(nodeList, SIGNAL(nodeKilled(SharedNodePointer)), &_voxels, SLOT(nodeKilled(SharedNodePointer)));
195−
205+
196206 // read the ApplicationInfo.ini file for Name/Version/Domain information
197207 QSettings applicationInfo("resources/info/ApplicationInfo.ini", QSettings::IniFormat);
198208
@@ -225,8 +235,10 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 26 unmodified lines
225235 NODE_TYPE_PARTICLE_SERVER, NODE_TYPE_METAVOXEL_SERVER};
226236 nodeList->setNodeTypesOfInterest(nodeTypesOfInterest, sizeof(nodeTypesOfInterest));
227237
238+ // move the silentNodeTimer to the _nodeThread
228239 QTimer* silentNodeTimer = new QTimer(this);
229240 connect(silentNodeTimer, SIGNAL(timeout()), nodeList, SLOT(removeSilentNodes()));
241+ silentNodeTimer->moveToThread(_nodeThread);
230242 silentNodeTimer->start(NODE_SILENCE_THRESHOLD_USECS / 1000);
231243
232244 QString cachePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
@@ -273,6 +285,10 @@ Application::~Application() { · 40 unmodified lines
273285
274286 // make sure we don't call the idle timer any more
275287 delete idleTimer;
288+
289+ // ask the datagram processing thread to quit and wait until it is done
290+ _nodeThread->thread()->quit();
291+ _nodeThread->thread()->wait();
276292
277293 // ask the audio thread to quit and wait until it is done
278294 _audio.thread()->quit();
@@ -1312,11 +1328,12 @@ void Application::timer() { · 1033 unmodified lines
13121328 }
13131329
13141330 _fps = (float)_frameCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
1315− _packetsPerSecond = (float)_packetCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
1316− _bytesPerSecond = (float)_bytesCount / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
1331+
1332+ _packetsPerSecond = (float) _datagramProcessor->getPacketCount() / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
1333+ _bytesPerSecond = (float) _datagramProcessor->getByteCount() / ((float)diffclock(&_timerStart, &_timerEnd) / 1000.f);
13171334 _frameCount = 0;
1318− _packetCount = 0;
1319− _bytesCount = 0;
1335+
1336+ _datagramProcessor->resetCounters();
13201337
13211338 gettimeofday(&_timerStart, NULL);
13221339
@@ -4052,93 +4069,6 @@ int Application::parseOctreeStats(unsigned char* messageData, ssize_t messageLen · 2729 unmodified lines
40524069 return statsMessageLength;
40534070 }
40544071
4055−// Receive packets from other nodes/servers and decide what to do with them!
4056−void Application::processDatagrams() {
4057− PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
4058− "Application::networkReceive()");
4059−
4060− HifiSockAddr senderSockAddr;
4061− ssize_t bytesReceived;
4062−
4063− while (NodeList::getInstance()->getNodeSocket().hasPendingDatagrams() &&
4064− (bytesReceived = NodeList::getInstance()->getNodeSocket().readDatagram((char*) _incomingPacket,
4065− MAX_PACKET_SIZE,
4066− senderSockAddr.getAddressPointer(),
4067− senderSockAddr.getPortPointer()))) {
4068−
4069− _packetCount++;
4070− _bytesCount += bytesReceived;
4071−
4072− if (packetVersionMatch(_incomingPacket)) {
4073− // only process this packet if we have a match on the packet version
4074− switch (_incomingPacket[0]) {
4075− case PACKET_TYPE_TRANSMITTER_DATA_V2:
4076− // V2 = IOS transmitter app
4077− _myTransmitter.processIncomingData(_incomingPacket, bytesReceived);
4078−
4079− break;
4080− case PACKET_TYPE_MIXED_AUDIO:
4081− QMetaObject::invokeMethod(&_audio, "addReceivedAudioToBuffer", Qt::QueuedConnection,
4082− Q_ARG(QByteArray, QByteArray((char*) _incomingPacket, bytesReceived)));
4083− break;
4084−
4085− case PACKET_TYPE_PARTICLE_ADD_RESPONSE:
4086− // this will keep creatorTokenIDs to IDs mapped correctly
4087− Particle::handleAddParticleResponse(_incomingPacket, bytesReceived);
4088− break;
4089−
4090− case PACKET_TYPE_PARTICLE_DATA:
4091− case PACKET_TYPE_PARTICLE_ERASE:
4092− case PACKET_TYPE_VOXEL_DATA:
4093− case PACKET_TYPE_VOXEL_ERASE:
4094− case PACKET_TYPE_OCTREE_STATS:
4095− case PACKET_TYPE_ENVIRONMENT_DATA: {
4096− PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
4097− "Application::networkReceive()... _voxelProcessor.queueReceivedPacket()");
4098−
4099− bool wantExtraDebugging = getLogger()->extraDebugging();
4100− if (wantExtraDebugging && _incomingPacket[0] == PACKET_TYPE_VOXEL_DATA) {
4101− int numBytesPacketHeader = numBytesForPacketHeader(_incomingPacket);
4102− unsigned char* dataAt = _incomingPacket + numBytesPacketHeader;
4103− dataAt += sizeof(VOXEL_PACKET_FLAGS);
4104− VOXEL_PACKET_SEQUENCE sequence = (*(VOXEL_PACKET_SEQUENCE*)dataAt);
4105− dataAt += sizeof(VOXEL_PACKET_SEQUENCE);
4106− VOXEL_PACKET_SENT_TIME sentAt = (*(VOXEL_PACKET_SENT_TIME*)dataAt);
4107− dataAt += sizeof(VOXEL_PACKET_SENT_TIME);
4108− VOXEL_PACKET_SENT_TIME arrivedAt = usecTimestampNow();
4109− int flightTime = arrivedAt - sentAt;
4110−
4111− printf("got PACKET_TYPE_VOXEL_DATA, sequence:%d flightTime:%d\n", sequence, flightTime);
4112− }
4113−
4114− // add this packet to our list of voxel packets and process them on the voxel processing
4115− _voxelProcessor.queueReceivedPacket(senderSockAddr, _incomingPacket, bytesReceived);
4116− break;
4117− }
4118− case PACKET_TYPE_METAVOXEL_DATA:
4119− _metavoxels.processData(QByteArray((const char*) _incomingPacket, bytesReceived),
4120− senderSockAddr);
4121− break;
4122− case PACKET_TYPE_BULK_AVATAR_DATA:
4123− NodeList::getInstance()->processBulkNodeData(senderSockAddr,
4124− _incomingPacket,
4125− bytesReceived);
4126− getInstance()->_bandwidthMeter.inputStream(BandwidthMeter::AVATARS).updateValue(bytesReceived);
4127− break;
4128− case PACKET_TYPE_DATA_SERVER_GET:
4129− case PACKET_TYPE_DATA_SERVER_PUT:
4130− case PACKET_TYPE_DATA_SERVER_SEND:
4131− case PACKET_TYPE_DATA_SERVER_CONFIRM:
4132− DataServerClient::processMessageFromDataServer(_incomingPacket, bytesReceived);
4133− break;
4134− default:
4135− NodeList::getInstance()->processNodeData(senderSockAddr, _incomingPacket, bytesReceived);
4136− break;
4137− }
4138− }
4139− }
4140−}
4141−
41424072 void Application::packetSentNotification(ssize_t length) {
41434073 _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(length);
41444074 }

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