Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 4 files). Show all
Unified · Split
| @@ -28,8 +28,6 @@ · 27 unmodified lines | |||
| 28 | #include "LocalVoxels.h" | 28 | #include "LocalVoxels.h" |
| 29 | #include "ScriptEngine.h" | 29 | #include "ScriptEngine.h" |
| 30 | 30 | ||
| 31 | const unsigned int VISUAL_DATA_CALLBACK_USECS = (1.0 / 60.0) * 1000 * 1000; | ||
| 32 | |||
| 33 | int ScriptEngine::_scriptNumber = 1; | 31 | int ScriptEngine::_scriptNumber = 1; |
| 34 | VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface; | 32 | VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface; |
| 35 | ParticlesScriptingInterface ScriptEngine::_particlesScriptingInterface; | 33 | ParticlesScriptingInterface ScriptEngine::_particlesScriptingInterface; |
| @@ -54,6 +52,7 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems, co · 18 unmodified lines | |||
| 54 | _avatarIdentityTimer(NULL), | 52 | _avatarIdentityTimer(NULL), |
| 55 | _avatarBillboardTimer(NULL), | 53 | _avatarBillboardTimer(NULL), |
| 56 | _timerFunctionMap(), | 54 | _timerFunctionMap(), |
| 55 | _avatarAudioBuffer(NULL), | ||
| 57 | _controllerScriptingInterface(controllerScriptingInterface), | 56 | _controllerScriptingInterface(controllerScriptingInterface), |
| 58 | _avatarData(NULL), | 57 | _avatarData(NULL), |
| 59 | _wantMenuItems(wantMenuItems), | 58 | _wantMenuItems(wantMenuItems), |
| @@ -77,9 +76,6 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems, co · 17 unmodified lines | |||
| 77 | _scriptNumber++; | 76 | _scriptNumber++; |
| 78 | } | 77 | } |
| 79 | 78 | ||
| 80 | ScriptEngine::~ScriptEngine() { | ||
| 81 | } | ||
| 82 | |||
| 83 | void ScriptEngine::setIsAvatar(bool isAvatar) { | 79 | void ScriptEngine::setIsAvatar(bool isAvatar) { |
| 84 | _isAvatar = isAvatar; | 80 | _isAvatar = isAvatar; |
| 85 | 81 | ||
| @@ -169,8 +165,8 @@ void ScriptEngine::init() { · 83 unmodified lines | |||
| 169 | _engine.globalObject().setProperty("TREE_SCALE", treeScaleValue); | 165 | _engine.globalObject().setProperty("TREE_SCALE", treeScaleValue); |
| 170 | 166 | ||
| 171 | // let the VoxelPacketSender know how frequently we plan to call it | 167 | // let the VoxelPacketSender know how frequently we plan to call it |
| 172 | _voxelsScriptingInterface.getVoxelPacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS); | 168 | _voxelsScriptingInterface.getVoxelPacketSender()->setProcessCallIntervalHint(SCRIPT_DATA_CALLBACK_USECS); |
| 173 | _particlesScriptingInterface.getParticlePacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS); | 169 | _particlesScriptingInterface.getParticlePacketSender()->setProcessCallIntervalHint(SCRIPT_DATA_CALLBACK_USECS); |
| 174 | 170 | ||
| 175 | } | 171 | } |
| 176 | 172 | ||
| @@ -228,7 +224,7 @@ void ScriptEngine::run() { · 51 unmodified lines | |||
| 228 | qint64 lastUpdate = usecTimestampNow(); | 224 | qint64 lastUpdate = usecTimestampNow(); |
| 229 | 225 | ||
| 230 | while (!_isFinished) { | 226 | while (!_isFinished) { |
| 231 | int usecToSleep = usecTimestamp(&startTime) + (thisFrame++ * VISUAL_DATA_CALLBACK_USECS) - usecTimestampNow(); | 227 | int usecToSleep = usecTimestamp(&startTime) + (thisFrame++ * SCRIPT_DATA_CALLBACK_USECS) - usecTimestampNow(); |
| 232 | if (usecToSleep > 0) { | 228 | if (usecToSleep > 0) { |
| 233 | usleep(usecToSleep); | 229 | usleep(usecToSleep); |
| 234 | } | 230 | } |
| @@ -268,6 +264,21 @@ void ScriptEngine::run() { · 33 unmodified lines | |||
| 268 | avatarPacket.append(_avatarData->toByteArray()); | 264 | avatarPacket.append(_avatarData->toByteArray()); |
| 269 | 265 | ||
| 270 | nodeList->broadcastToNodes(avatarPacket, NodeSet() << NodeType::AvatarMixer); | 266 | nodeList->broadcastToNodes(avatarPacket, NodeSet() << NodeType::AvatarMixer); |
| 267 | |||
| 268 | if (_avatarAudioBuffer && _numAvatarAudioBufferSamples > 0) { | ||
| 269 | // if have an avatar audio stream then send it out to our audio-mixer | ||
| 270 | QByteArray audioPacket = byteArrayWithPopulatedHeader(PacketTypeMicrophoneAudioNoEcho); | ||
| 271 | QDataStream packetStream(&audioPacket, QIODevice::Append); | ||
| 272 | |||
| 273 | // use the orientation and position of this avatar for the source of this audio | ||
| 274 | packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3)); | ||
| 275 | glm::quat headOrientation = _avatarData->getHeadOrientation(); | ||
| 276 | packetStream.writeRawData(reinterpret_cast<const char*>(&headOrientation), sizeof(glm::quat)); | ||
| 277 | packetStream.writeRawData(reinterpret_cast<const char*>(_avatarAudioBuffer), | ||
| 278 | _numAvatarAudioBufferSamples * sizeof(int16_t)); | ||
| 279 | |||
| 280 | nodeList->broadcastToNodes(audioPacket, NodeSet() << NodeType::AudioMixer); | ||
| 281 | } | ||
| 271 | } | 282 | } |
| 272 | 283 | ||
| 273 | qint64 now = usecTimestampNow(); | 284 | qint64 now = usecTimestampNow(); |