Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 80 files). Show all
Unified · Split
| @@ -351,6 +351,7 @@ void ScriptEngine::run() { · 350 unmodified lines | ||
| 351 | 351 | init(); |
| 352 | 352 | } |
| 353 | 353 | _isRunning = true; |
| 354 | + _isFinished = false; | |
| 354 | 355 | emit runningStateChanged(); |
| 355 | 356 | |
| 356 | 357 | QScriptValue result = _engine.evaluate(_scriptContents); |
| @@ -461,13 +462,17 @@ void ScriptEngine::run() { · 104 unmodified lines | ||
| 461 | 462 | _numAvatarSoundSentBytes = 0; |
| 462 | 463 | } |
| 463 | 464 | } |
| 464 | − | |
| 465 | + | |
| 465 | 466 | QByteArray audioPacket = byteArrayWithPopulatedHeader(silentFrame |
| 466 | 467 | ? PacketTypeSilentAudioFrame |
| 467 | 468 | : PacketTypeMicrophoneAudioNoEcho); |
| 468 | 469 | |
| 469 | 470 | QDataStream packetStream(&audioPacket, QIODevice::Append); |
| 470 | 471 | |
| 472 | + // pack a placeholder value for sequence number for now, will be packed when destination node is known | |
| 473 | + int numPreSequenceNumberBytes = audioPacket.size(); | |
| 474 | + packetStream << (quint16)0; | |
| 475 | + | |
| 471 | 476 | // use the orientation and position of this avatar for the source of this audio |
| 472 | 477 | packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3)); |
| 473 | 478 | glm::quat headOrientation = _avatarData->getHeadOrientation(); |
| @@ -487,7 +492,19 @@ void ScriptEngine::run() { · 13 unmodified lines | ||
| 487 | 492 | numAvailableSamples * sizeof(int16_t)); |
| 488 | 493 | } |
| 489 | 494 | |
| 490 | − nodeList->broadcastToNodes(audioPacket, NodeSet() << NodeType::AudioMixer); | |
| 495 | + // write audio packet to AudioMixer nodes | |
| 496 | + NodeList* nodeList = NodeList::getInstance(); | |
| 497 | + foreach(const SharedNodePointer& node, nodeList->getNodeHash()) { | |
| 498 | + // only send to nodes of type AudioMixer | |
| 499 | + if (node->getType() == NodeType::AudioMixer) { | |
| 500 | + // pack sequence number | |
| 501 | + quint16 sequence = _outgoingScriptAudioSequenceNumbers[node->getUUID()]++; | |
| 502 | + memcpy(audioPacket.data() + numPreSequenceNumberBytes, &sequence, sizeof(quint16)); | |
| 503 | + | |
| 504 | + // send audio packet | |
| 505 | + nodeList->writeDatagram(audioPacket, node); | |
| 506 | + } | |
| 507 | + } | |
| 491 | 508 | } |
| 492 | 509 | } |
| 493 | 510 | |
| @@ -663,3 +680,7 @@ void ScriptEngine::include(const QString& includeFile) { · 169 unmodified lines | ||
| 663 | 680 | _engine.clearExceptions(); |
| 664 | 681 | } |
| 665 | 682 | } |
| 683 | + | |
| 684 | +void ScriptEngine::nodeKilled(SharedNodePointer node) { | |
| 685 | + _outgoingScriptAudioSequenceNumbers.remove(node->getUUID()); | |
| 686 | +} | |