Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 142 files). Show all
Unified · Split
| @@ -314,8 +314,9 @@ void ScriptEngine::evaluate() { · 313 unmodified lines | ||
| 314 | 314 | |
| 315 | 315 | if (_engine.hasUncaughtException()) { |
| 316 | 316 | 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(); | |
| 319 | 320 | } |
| 320 | 321 | } |
| 321 | 322 | |
| @@ -324,7 +325,7 @@ QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileN · 2 unmodified lines | ||
| 324 | 325 | bool hasUncaughtException = _engine.hasUncaughtException(); |
| 325 | 326 | if (hasUncaughtException) { |
| 326 | 327 | int line = _engine.uncaughtExceptionLineNumber(); |
| 327 | − qDebug() << "Uncaught exception at line" << line << ": " << result.toString(); | |
| 328 | + qDebug() << "Uncaught exception at (" << _fileNameString << ") line" << line << ": " << result.toString(); | |
| 328 | 329 | } |
| 329 | 330 | emit evaluationFinished(result, hasUncaughtException); |
| 330 | 331 | _engine.clearExceptions(); |
| @@ -348,14 +349,15 @@ void ScriptEngine::run() { · 17 unmodified lines | ||
| 348 | 349 | init(); |
| 349 | 350 | } |
| 350 | 351 | _isRunning = true; |
| 352 | + _isFinished = false; | |
| 351 | 353 | emit runningStateChanged(); |
| 352 | 354 | |
| 353 | 355 | QScriptValue result = _engine.evaluate(_scriptContents); |
| 354 | 356 | if (_engine.hasUncaughtException()) { |
| 355 | 357 | 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(); | |
| 359 | 361 | } |
| 360 | 362 | |
| 361 | 363 | QElapsedTimer startTime; |
| @@ -458,13 +460,17 @@ void ScriptEngine::run() { · 96 unmodified lines | ||
| 458 | 460 | _numAvatarSoundSentBytes = 0; |
| 459 | 461 | } |
| 460 | 462 | } |
| 461 | − | |
| 463 | + | |
| 462 | 464 | QByteArray audioPacket = byteArrayWithPopulatedHeader(silentFrame |
| 463 | 465 | ? PacketTypeSilentAudioFrame |
| 464 | 466 | : PacketTypeMicrophoneAudioNoEcho); |
| 465 | 467 | |
| 466 | 468 | QDataStream packetStream(&audioPacket, QIODevice::Append); |
| 467 | 469 | |
| 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 | + | |
| 468 | 474 | // use the orientation and position of this avatar for the source of this audio |
| 469 | 475 | packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3)); |
| 470 | 476 | glm::quat headOrientation = _avatarData->getHeadOrientation(); |
| @@ -484,7 +490,19 @@ void ScriptEngine::run() { · 13 unmodified lines | ||
| 484 | 490 | numAvailableSamples * sizeof(int16_t)); |
| 485 | 491 | } |
| 486 | 492 | |
| 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 | + } | |
| 488 | 506 | } |
| 489 | 507 | } |
| 490 | 508 | |
| @@ -495,8 +513,9 @@ void ScriptEngine::run() { · 4 unmodified lines | ||
| 495 | 513 | |
| 496 | 514 | if (_engine.hasUncaughtException()) { |
| 497 | 515 | 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(); | |
| 500 | 519 | } |
| 501 | 520 | } |
| 502 | 521 | emit scriptEnding(); |
| @@ -656,5 +675,10 @@ void ScriptEngine::include(const QString& includeFile) { · 153 unmodified lines | ||
| 656 | 675 | int line = _engine.uncaughtExceptionLineNumber(); |
| 657 | 676 | qDebug() << "Uncaught exception at (" << includeFile << ") line" << line << ":" << result.toString(); |
| 658 | 677 | emit errorMessage("Uncaught exception at (" + includeFile + ") line" + QString::number(line) + ":" + result.toString()); |
| 678 | + _engine.clearExceptions(); | |
| 659 | 679 | } |
| 660 | 680 | } |
| 681 | + | |
| 682 | +void ScriptEngine::nodeKilled(SharedNodePointer node) { | |
| 683 | + _outgoingScriptAudioSequenceNumbers.remove(node->getUUID()); | |
| 684 | +} | |