History

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

ZappoMan committed 12 years ago

Commit 86556642 parents b113c2d d8a5f59142 files · +6171 −1613Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 142 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+34−10
@@ -314,8 +314,9 @@ void ScriptEngine::evaluate() { · 313 unmodified lines
314314
315315 if (_engine.hasUncaughtException()) {
316316 int line = _engine.uncaughtExceptionLineNumber();
317− qDebug() << "Uncaught exception at line" << line << ":" << result.toString();
318− emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + result.toString());
317+ qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();
318+ emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString());
319+ _engine.clearExceptions();
319320 }
320321 }
321322
@@ -324,7 +325,7 @@ QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileN · 2 unmodified lines
324325 bool hasUncaughtException = _engine.hasUncaughtException();
325326 if (hasUncaughtException) {
326327 int line = _engine.uncaughtExceptionLineNumber();
327− qDebug() << "Uncaught exception at line" << line << ": " << result.toString();
328+ qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ": " << result.toString();
328329 }
329330 emit evaluationFinished(result, hasUncaughtException);
330331 _engine.clearExceptions();
@@ -348,14 +349,15 @@ void ScriptEngine::run() { · 17 unmodified lines
348349 init();
349350 }
350351 _isRunning = true;
352+ _isFinished = false;
351353 emit runningStateChanged();
352354
353355 QScriptValue result = _engine.evaluate(_scriptContents);
354356 if (_engine.hasUncaughtException()) {
355357 int line = _engine.uncaughtExceptionLineNumber();
356−
357− qDebug() << "Uncaught exception at line" << line << ":" << result.toString();
358− emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + result.toString());
358+ qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();
359+ emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString());
360+ _engine.clearExceptions();
359361 }
360362
361363 QElapsedTimer startTime;
@@ -458,13 +460,17 @@ void ScriptEngine::run() { · 96 unmodified lines
458460 _numAvatarSoundSentBytes = 0;
459461 }
460462 }
461−
463+
462464 QByteArray audioPacket = byteArrayWithPopulatedHeader(silentFrame
463465 ? PacketTypeSilentAudioFrame
464466 : PacketTypeMicrophoneAudioNoEcho);
465467
466468 QDataStream packetStream(&audioPacket, QIODevice::Append);
467469
470+ // pack a placeholder value for sequence number for now, will be packed when destination node is known
471+ int numPreSequenceNumberBytes = audioPacket.size();
472+ packetStream << (quint16)0;
473+
468474 // use the orientation and position of this avatar for the source of this audio
469475 packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3));
470476 glm::quat headOrientation = _avatarData->getHeadOrientation();
@@ -484,7 +490,19 @@ void ScriptEngine::run() { · 13 unmodified lines
484490 numAvailableSamples * sizeof(int16_t));
485491 }
486492
487− nodeList->broadcastToNodes(audioPacket, NodeSet() << NodeType::AudioMixer);
493+ // write audio packet to AudioMixer nodes
494+ NodeList* nodeList = NodeList::getInstance();
495+ foreach(const SharedNodePointer& node, nodeList->getNodeHash()) {
496+ // only send to nodes of type AudioMixer
497+ if (node->getType() == NodeType::AudioMixer) {
498+ // pack sequence number
499+ quint16 sequence = _outgoingScriptAudioSequenceNumbers[node->getUUID()]++;
500+ memcpy(audioPacket.data() + numPreSequenceNumberBytes, &sequence, sizeof(quint16));
501+
502+ // send audio packet
503+ nodeList->writeDatagram(audioPacket, node);
504+ }
505+ }
488506 }
489507 }
490508
@@ -495,8 +513,9 @@ void ScriptEngine::run() { · 4 unmodified lines
495513
496514 if (_engine.hasUncaughtException()) {
497515 int line = _engine.uncaughtExceptionLineNumber();
498− qDebug() << "Uncaught exception at line" << line << ":" << _engine.uncaughtException().toString();
499− emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + _engine.uncaughtException().toString());
516+ qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << _engine.uncaughtException().toString();
517+ emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + _engine.uncaughtException().toString());
518+ _engine.clearExceptions();
500519 }
501520 }
502521 emit scriptEnding();
@@ -656,5 +675,10 @@ void ScriptEngine::include(const QString& includeFile) { · 153 unmodified lines
656675 int line = _engine.uncaughtExceptionLineNumber();
657676 qDebug() << "Uncaught exception at (" << includeFile << ") line" << line << ":" << result.toString();
658677 emit errorMessage("Uncaught exception at (" + includeFile + ") line" + QString::number(line) + ":" + result.toString());
678+ _engine.clearExceptions();
659679 }
660680 }
681+
682+void ScriptEngine::nodeKilled(SharedNodePointer node) {
683+ _outgoingScriptAudioSequenceNumbers.remove(node->getUUID());
684+}