Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 192 files). Show all
Unified · Split
| @@ -323,8 +323,9 @@ void ScriptEngine::evaluate() { · 322 unmodified lines | |||
| 323 | 323 | ||
| 324 | if (_engine.hasUncaughtException()) { | 324 | if (_engine.hasUncaughtException()) { |
| 325 | int line = _engine.uncaughtExceptionLineNumber(); | 325 | int line = _engine.uncaughtExceptionLineNumber(); |
| 326 | qDebug() << "Uncaught exception at line" << line << ":" << result.toString(); | 326 | qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString(); |
| 327 | emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + result.toString()); | 327 | emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString()); |
| 328 | _engine.clearExceptions(); | ||
| 328 | } | 329 | } |
| 329 | } | 330 | } |
| 330 | 331 | ||
| @@ -333,7 +334,7 @@ QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileN · 2 unmodified lines | |||
| 333 | bool hasUncaughtException = _engine.hasUncaughtException(); | 334 | bool hasUncaughtException = _engine.hasUncaughtException(); |
| 334 | if (hasUncaughtException) { | 335 | if (hasUncaughtException) { |
| 335 | int line = _engine.uncaughtExceptionLineNumber(); | 336 | int line = _engine.uncaughtExceptionLineNumber(); |
| 336 | qDebug() << "Uncaught exception at line" << line << ": " << result.toString(); | 337 | qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ": " << result.toString(); |
| 337 | } | 338 | } |
| 338 | emit evaluationFinished(result, hasUncaughtException); | 339 | emit evaluationFinished(result, hasUncaughtException); |
| 339 | _engine.clearExceptions(); | 340 | _engine.clearExceptions(); |
| @@ -357,14 +358,15 @@ void ScriptEngine::run() { · 17 unmodified lines | |||
| 357 | init(); | 358 | init(); |
| 358 | } | 359 | } |
| 359 | _isRunning = true; | 360 | _isRunning = true; |
| 361 | _isFinished = false; | ||
| 360 | emit runningStateChanged(); | 362 | emit runningStateChanged(); |
| 361 | 363 | ||
| 362 | QScriptValue result = _engine.evaluate(_scriptContents); | 364 | QScriptValue result = _engine.evaluate(_scriptContents); |
| 363 | if (_engine.hasUncaughtException()) { | 365 | if (_engine.hasUncaughtException()) { |
| 364 | int line = _engine.uncaughtExceptionLineNumber(); | 366 | int line = _engine.uncaughtExceptionLineNumber(); |
| 365 | 367 | qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << result.toString(); | |
| 366 | qDebug() << "Uncaught exception at line" << line << ":" << result.toString(); | 368 | emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + result.toString()); |
| 367 | emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + result.toString()); | 369 | _engine.clearExceptions(); |
| 368 | } | 370 | } |
| 369 | 371 | ||
| 370 | QElapsedTimer startTime; | 372 | QElapsedTimer startTime; |
| @@ -467,13 +469,17 @@ void ScriptEngine::run() { · 96 unmodified lines | |||
| 467 | _numAvatarSoundSentBytes = 0; | 469 | _numAvatarSoundSentBytes = 0; |
| 468 | } | 470 | } |
| 469 | } | 471 | } |
| 470 | 472 | ||
| 471 | QByteArray audioPacket = byteArrayWithPopulatedHeader(silentFrame | 473 | QByteArray audioPacket = byteArrayWithPopulatedHeader(silentFrame |
| 472 | ? PacketTypeSilentAudioFrame | 474 | ? PacketTypeSilentAudioFrame |
| 473 | : PacketTypeMicrophoneAudioNoEcho); | 475 | : PacketTypeMicrophoneAudioNoEcho); |
| 474 | 476 | ||
| 475 | QDataStream packetStream(&audioPacket, QIODevice::Append); | 477 | QDataStream packetStream(&audioPacket, QIODevice::Append); |
| 476 | 478 | ||
| 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 | |||
| 477 | // use the orientation and position of this avatar for the source of this audio | 483 | // use the orientation and position of this avatar for the source of this audio |
| 478 | packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3)); | 484 | packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3)); |
| 479 | glm::quat headOrientation = _avatarData->getHeadOrientation(); | 485 | glm::quat headOrientation = _avatarData->getHeadOrientation(); |
| @@ -493,7 +499,19 @@ void ScriptEngine::run() { · 13 unmodified lines | |||
| 493 | numAvailableSamples * sizeof(int16_t)); | 499 | numAvailableSamples * sizeof(int16_t)); |
| 494 | } | 500 | } |
| 495 | 501 | ||
| 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 | } | ||
| 497 | } | 515 | } |
| 498 | } | 516 | } |
| 499 | 517 | ||
| @@ -504,8 +522,9 @@ void ScriptEngine::run() { · 4 unmodified lines | |||
| 504 | 522 | ||
| 505 | if (_engine.hasUncaughtException()) { | 523 | if (_engine.hasUncaughtException()) { |
| 506 | int line = _engine.uncaughtExceptionLineNumber(); | 524 | int line = _engine.uncaughtExceptionLineNumber(); |
| 507 | qDebug() << "Uncaught exception at line" << line << ":" << _engine.uncaughtException().toString(); | 525 | qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ":" << _engine.uncaughtException().toString(); |
| 508 | emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + _engine.uncaughtException().toString()); | 526 | emit errorMessage("Uncaught exception at (" + _fileNameString + ") line" + QString::number(line) + ":" + _engine.uncaughtException().toString()); |
| 527 | _engine.clearExceptions(); | ||
| 509 | } | 528 | } |
| 510 | } | 529 | } |
| 511 | emit scriptEnding(); | 530 | emit scriptEnding(); |
| @@ -665,5 +684,10 @@ void ScriptEngine::include(const QString& includeFile) { · 153 unmodified lines | |||
| 665 | int line = _engine.uncaughtExceptionLineNumber(); | 684 | int line = _engine.uncaughtExceptionLineNumber(); |
| 666 | qDebug() << "Uncaught exception at (" << includeFile << ") line" << line << ":" << result.toString(); | 685 | qDebug() << "Uncaught exception at (" << includeFile << ") line" << line << ":" << result.toString(); |
| 667 | emit errorMessage("Uncaught exception at (" + includeFile + ") line" + QString::number(line) + ":" + result.toString()); | 686 | emit errorMessage("Uncaught exception at (" + includeFile + ") line" + QString::number(line) + ":" + result.toString()); |
| 687 | _engine.clearExceptions(); | ||
| 668 | } | 688 | } |
| 669 | } | 689 | } |
| 690 | |||
| 691 | void ScriptEngine::nodeKilled(SharedNodePointer node) { | ||
| 692 | _outgoingScriptAudioSequenceNumbers.remove(node->getUUID()); | ||
| 693 | } | ||