History

Merge branch 'master' of https://github.com/highfidelity/hifi into 19734

samcake committed 12 years ago

Commit fca3a6a2 parents 35977fb d8a5f59192 files · +9602 −2725Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+34−10
@@ -323,8 +323,9 @@ void ScriptEngine::evaluate() { · 322 unmodified lines
323323
324324 if (_engine.hasUncaughtException()) {
325325 int line = _engine.uncaughtExceptionLineNumber();
326− qDebug() << "Uncaught exception at line" << line << ":" << result.toString();
327− emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + result.toString());
326+ qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();
327+ emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString());
328+ _engine.clearExceptions();
328329 }
329330 }
330331
@@ -333,7 +334,7 @@ QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileN · 2 unmodified lines
333334 bool hasUncaughtException = _engine.hasUncaughtException();
334335 if (hasUncaughtException) {
335336 int line = _engine.uncaughtExceptionLineNumber();
336− qDebug() << "Uncaught exception at line" << line << ": " << result.toString();
337+ qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ": " << result.toString();
337338 }
338339 emit evaluationFinished(result, hasUncaughtException);
339340 _engine.clearExceptions();
@@ -357,14 +358,15 @@ void ScriptEngine::run() { · 17 unmodified lines
357358 init();
358359 }
359360 _isRunning = true;
361+ _isFinished = false;
360362 emit runningStateChanged();
361363
362364 QScriptValue result = _engine.evaluate(_scriptContents);
363365 if (_engine.hasUncaughtException()) {
364366 int line = _engine.uncaughtExceptionLineNumber();
365−
366− qDebug() << "Uncaught exception at line" << line << ":" << result.toString();
367− emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + result.toString());
367+ qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString();
368+ emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString());
369+ _engine.clearExceptions();
368370 }
369371
370372 QElapsedTimer startTime;
@@ -467,13 +469,17 @@ void ScriptEngine::run() { · 96 unmodified lines
467469 _numAvatarSoundSentBytes = 0;
468470 }
469471 }
470−
472+
471473 QByteArray audioPacket = byteArrayWithPopulatedHeader(silentFrame
472474 ? PacketTypeSilentAudioFrame
473475 : PacketTypeMicrophoneAudioNoEcho);
474476
475477 QDataStream packetStream(&audioPacket, QIODevice::Append);
476478
479+ // pack a placeholder value for sequence number for now, will be packed when destination node is known
480+ int numPreSequenceNumberBytes = audioPacket.size();
481+ packetStream << (quint16)0;
482+
477483 // use the orientation and position of this avatar for the source of this audio
478484 packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3));
479485 glm::quat headOrientation = _avatarData->getHeadOrientation();
@@ -493,7 +499,19 @@ void ScriptEngine::run() { · 13 unmodified lines
493499 numAvailableSamples * sizeof(int16_t));
494500 }
495501
496− nodeList->broadcastToNodes(audioPacket, NodeSet() << NodeType::AudioMixer);
502+ // write audio packet to AudioMixer nodes
503+ NodeList* nodeList = NodeList::getInstance();
504+ foreach(const SharedNodePointer& node, nodeList->getNodeHash()) {
505+ // only send to nodes of type AudioMixer
506+ if (node->getType() == NodeType::AudioMixer) {
507+ // pack sequence number
508+ quint16 sequence = _outgoingScriptAudioSequenceNumbers[node->getUUID()]++;
509+ memcpy(audioPacket.data() + numPreSequenceNumberBytes, &sequence, sizeof(quint16));
510+
511+ // send audio packet
512+ nodeList->writeDatagram(audioPacket, node);
513+ }
514+ }
497515 }
498516 }
499517
@@ -504,8 +522,9 @@ void ScriptEngine::run() { · 4 unmodified lines
504522
505523 if (_engine.hasUncaughtException()) {
506524 int line = _engine.uncaughtExceptionLineNumber();
507− qDebug() << "Uncaught exception at line" << line << ":" << _engine.uncaughtException().toString();
508− emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + _engine.uncaughtException().toString());
525+ qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << _engine.uncaughtException().toString();
526+ emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + _engine.uncaughtException().toString());
527+ _engine.clearExceptions();
509528 }
510529 }
511530 emit scriptEnding();
@@ -665,5 +684,10 @@ void ScriptEngine::include(const QString& includeFile) { · 153 unmodified lines
665684 int line = _engine.uncaughtExceptionLineNumber();
666685 qDebug() << "Uncaught exception at (" << includeFile << ") line" << line << ":" << result.toString();
667686 emit errorMessage("Uncaught exception at (" + includeFile + ") line" + QString::number(line) + ":" + result.toString());
687+ _engine.clearExceptions();
668688 }
669689 }
690+
691+void ScriptEngine::nodeKilled(SharedNodePointer node) {
692+ _outgoingScriptAudioSequenceNumbers.remove(node->getUUID());
693+}