Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 497 files). Show all
Unified · Split
| @@ -17,9 +17,9 @@ · 16 unmodified lines | |||
| 17 | #include <QtNetwork/QNetworkReply> | 17 | #include <QtNetwork/QNetworkReply> |
| 18 | #include <QScriptEngine> | 18 | #include <QScriptEngine> |
| 19 | 19 | ||
| 20 | #include <AudioConstants.h> | ||
| 20 | #include <AudioEffectOptions.h> | 21 | #include <AudioEffectOptions.h> |
| 21 | #include <AudioInjector.h> | 22 | #include <AudioInjector.h> |
| 22 | #include <AudioRingBuffer.h> | ||
| 23 | #include <AvatarData.h> | 23 | #include <AvatarData.h> |
| 24 | #include <Bitstream.h> | 24 | #include <Bitstream.h> |
| 25 | #include <CollisionInfo.h> | 25 | #include <CollisionInfo.h> |
| @@ -28,22 +28,18 @@ · 2 unmodified lines | |||
| 28 | #include <NodeList.h> | 28 | #include <NodeList.h> |
| 29 | #include <PacketHeaders.h> | 29 | #include <PacketHeaders.h> |
| 30 | #include <UUID.h> | 30 | #include <UUID.h> |
| 31 | #include <VoxelConstants.h> | ||
| 32 | #include <VoxelDetail.h> | ||
| 33 | 31 | ||
| 34 | #include "AnimationObject.h" | 32 | #include "AnimationObject.h" |
| 35 | #include "ArrayBufferViewClass.h" | 33 | #include "ArrayBufferViewClass.h" |
| 36 | #include "DataViewClass.h" | 34 | #include "DataViewClass.h" |
| 37 | #include "EventTypes.h" | 35 | #include "EventTypes.h" |
| 38 | #include "MenuItemProperties.h" | 36 | #include "MenuItemProperties.h" |
| 39 | #include "LocalVoxels.h" | ||
| 40 | #include "ScriptEngine.h" | 37 | #include "ScriptEngine.h" |
| 41 | #include "TypedArrays.h" | 38 | #include "TypedArrays.h" |
| 42 | #include "XMLHttpRequestClass.h" | 39 | #include "XMLHttpRequestClass.h" |
| 43 | 40 | ||
| 44 | #include "MIDIEvent.h" | 41 | #include "MIDIEvent.h" |
| 45 | 42 | ||
| 46 | VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface; | ||
| 47 | EntityScriptingInterface ScriptEngine::_entityScriptingInterface; | 43 | EntityScriptingInterface ScriptEngine::_entityScriptingInterface; |
| 48 | 44 | ||
| 49 | static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ | 45 | static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ |
| @@ -198,10 +194,10 @@ void ScriptEngine::handleScriptDownload() { · 148 unmodified lines | |||
| 198 | qDebug() << "ERROR Loading file:" << reply->url().toString(); | 194 | qDebug() << "ERROR Loading file:" << reply->url().toString(); |
| 199 | emit errorLoadingScript(_fileNameString); | 195 | emit errorLoadingScript(_fileNameString); |
| 200 | } | 196 | } |
| 197 | |||
| 198 | reply->deleteLater(); | ||
| 201 | } | 199 | } |
| 202 | 200 | ||
| 203 | Q_SCRIPT_DECLARE_QMETAOBJECT(LocalVoxels, QString) | ||
| 204 | |||
| 205 | void ScriptEngine::init() { | 201 | void ScriptEngine::init() { |
| 206 | if (_isInitialized) { | 202 | if (_isInitialized) { |
| 207 | return; // only initialize once | 203 | return; // only initialize once |
| @@ -209,12 +205,9 @@ void ScriptEngine::init() { · 1 unmodified line | |||
| 209 | 205 | ||
| 210 | _isInitialized = true; | 206 | _isInitialized = true; |
| 211 | 207 | ||
| 212 | _voxelsScriptingInterface.init(); | ||
| 213 | |||
| 214 | // register various meta-types | 208 | // register various meta-types |
| 215 | registerMetaTypes(this); | 209 | registerMetaTypes(this); |
| 216 | registerMIDIMetaTypes(this); | 210 | registerMIDIMetaTypes(this); |
| 217 | registerVoxelMetaTypes(this); | ||
| 218 | registerEventTypes(this); | 211 | registerEventTypes(this); |
| 219 | registerMenuItemProperties(this); | 212 | registerMenuItemProperties(this); |
| 220 | registerAnimationTypes(this); | 213 | registerAnimationTypes(this); |
| @@ -237,9 +230,6 @@ void ScriptEngine::init() { · 16 unmodified lines | |||
| 237 | QScriptValue printConstructorValue = newFunction(debugPrint); | 230 | QScriptValue printConstructorValue = newFunction(debugPrint); |
| 238 | globalObject().setProperty("print", printConstructorValue); | 231 | globalObject().setProperty("print", printConstructorValue); |
| 239 | 232 | ||
| 240 | QScriptValue localVoxelsValue = scriptValueFromQMetaObject<LocalVoxels>(); | ||
| 241 | globalObject().setProperty("LocalVoxels", localVoxelsValue); | ||
| 242 | |||
| 243 | QScriptValue audioEffectOptionsConstructorValue = newFunction(AudioEffectOptions::constructor); | 233 | QScriptValue audioEffectOptionsConstructorValue = newFunction(AudioEffectOptions::constructor); |
| 244 | globalObject().setProperty("AudioEffectOptions", audioEffectOptionsConstructorValue); | 234 | globalObject().setProperty("AudioEffectOptions", audioEffectOptionsConstructorValue); |
| 245 | 235 | ||
| @@ -257,19 +247,14 @@ void ScriptEngine::init() { · 11 unmodified lines | |||
| 257 | registerGlobalObject("Uuid", &_uuidLibrary); | 247 | registerGlobalObject("Uuid", &_uuidLibrary); |
| 258 | registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data()); | 248 | registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data()); |
| 259 | 249 | ||
| 260 | registerGlobalObject("Voxels", &_voxelsScriptingInterface); | ||
| 261 | |||
| 262 | // constants | 250 | // constants |
| 263 | globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE))); | 251 | globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE))); |
| 264 | globalObject().setProperty("COLLISION_GROUP_ENVIRONMENT", newVariant(QVariant(COLLISION_GROUP_ENVIRONMENT))); | 252 | globalObject().setProperty("COLLISION_GROUP_ENVIRONMENT", newVariant(QVariant(COLLISION_GROUP_ENVIRONMENT))); |
| 265 | globalObject().setProperty("COLLISION_GROUP_AVATARS", newVariant(QVariant(COLLISION_GROUP_AVATARS))); | 253 | globalObject().setProperty("COLLISION_GROUP_AVATARS", newVariant(QVariant(COLLISION_GROUP_AVATARS))); |
| 266 | globalObject().setProperty("COLLISION_GROUP_VOXELS", newVariant(QVariant(COLLISION_GROUP_VOXELS))); | ||
| 267 | 254 | ||
| 268 | globalObject().setProperty("AVATAR_MOTION_OBEY_LOCAL_GRAVITY", newVariant(QVariant(AVATAR_MOTION_OBEY_LOCAL_GRAVITY))); | 255 | globalObject().setProperty("AVATAR_MOTION_OBEY_LOCAL_GRAVITY", newVariant(QVariant(AVATAR_MOTION_OBEY_LOCAL_GRAVITY))); |
| 269 | globalObject().setProperty("AVATAR_MOTION_OBEY_ENVIRONMENTAL_GRAVITY", newVariant(QVariant(AVATAR_MOTION_OBEY_ENVIRONMENTAL_GRAVITY))); | 256 | globalObject().setProperty("AVATAR_MOTION_OBEY_ENVIRONMENTAL_GRAVITY", newVariant(QVariant(AVATAR_MOTION_OBEY_ENVIRONMENTAL_GRAVITY))); |
| 270 | 257 | ||
| 271 | // let the VoxelPacketSender know how frequently we plan to call it | ||
| 272 | _voxelsScriptingInterface.getVoxelPacketSender()->setProcessCallIntervalHint(SCRIPT_DATA_CALLBACK_USECS); | ||
| 273 | } | 258 | } |
| 274 | 259 | ||
| 275 | QScriptValue ScriptEngine::registerGlobalObject(const QString& name, QObject* object) { | 260 | QScriptValue ScriptEngine::registerGlobalObject(const QString& name, QObject* object) { |
| @@ -379,18 +364,8 @@ void ScriptEngine::run() { · 103 unmodified lines | |||
| 379 | break; | 364 | break; |
| 380 | } | 365 | } |
| 381 | 366 | ||
| 382 | if (_voxelsScriptingInterface.getVoxelPacketSender()->serversExist()) { | ||
| 383 | // release the queue of edit voxel messages. | ||
| 384 | _voxelsScriptingInterface.getVoxelPacketSender()->releaseQueuedMessages(); | ||
| 385 | |||
| 386 | // since we're in non-threaded mode, call process so that the packets are sent | ||
| 387 | if (!_voxelsScriptingInterface.getVoxelPacketSender()->isThreaded()) { | ||
| 388 | _voxelsScriptingInterface.getVoxelPacketSender()->process(); | ||
| 389 | } | ||
| 390 | } | ||
| 391 | |||
| 392 | if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) { | 367 | if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) { |
| 393 | // release the queue of edit voxel messages. | 368 | // release the queue of edit entity messages. |
| 394 | _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); | 369 | _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); |
| 395 | 370 | ||
| 396 | // since we're in non-threaded mode, call process so that the packets are sent | 371 | // since we're in non-threaded mode, call process so that the packets are sent |
| @@ -401,7 +376,8 @@ void ScriptEngine::run() { · 4 unmodified lines | |||
| 401 | 376 | ||
| 402 | if (_isAvatar && _avatarData) { | 377 | if (_isAvatar && _avatarData) { |
| 403 | 378 | ||
| 404 | const int SCRIPT_AUDIO_BUFFER_SAMPLES = floor(((SCRIPT_DATA_CALLBACK_USECS * SAMPLE_RATE) / (1000 * 1000)) + 0.5); | 379 | const int SCRIPT_AUDIO_BUFFER_SAMPLES = floor(((SCRIPT_DATA_CALLBACK_USECS * AudioConstants::SAMPLE_RATE) |
| 380 | / (1000 * 1000)) + 0.5); | ||
| 405 | const int SCRIPT_AUDIO_BUFFER_BYTES = SCRIPT_AUDIO_BUFFER_SAMPLES * sizeof(int16_t); | 381 | const int SCRIPT_AUDIO_BUFFER_BYTES = SCRIPT_AUDIO_BUFFER_SAMPLES * sizeof(int16_t); |
| 406 | 382 | ||
| 407 | QByteArray avatarPacket = byteArrayWithPopulatedHeader(PacketTypeAvatarData); | 383 | QByteArray avatarPacket = byteArrayWithPopulatedHeader(PacketTypeAvatarData); |
| @@ -516,16 +492,6 @@ void ScriptEngine::run() { · 108 unmodified lines | |||
| 516 | // kill the avatar identity timer | 492 | // kill the avatar identity timer |
| 517 | delete _avatarIdentityTimer; | 493 | delete _avatarIdentityTimer; |
| 518 | 494 | ||
| 519 | if (_voxelsScriptingInterface.getVoxelPacketSender()->serversExist()) { | ||
| 520 | // release the queue of edit voxel messages. | ||
| 521 | _voxelsScriptingInterface.getVoxelPacketSender()->releaseQueuedMessages(); | ||
| 522 | |||
| 523 | // since we're in non-threaded mode, call process so that the packets are sent | ||
| 524 | if (!_voxelsScriptingInterface.getVoxelPacketSender()->isThreaded()) { | ||
| 525 | _voxelsScriptingInterface.getVoxelPacketSender()->process(); | ||
| 526 | } | ||
| 527 | } | ||
| 528 | |||
| 529 | if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) { | 495 | if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) { |
| 530 | // release the queue of edit entity messages. | 496 | // release the queue of edit entity messages. |
| 531 | _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); | 497 | _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); |
| @@ -641,6 +607,7 @@ void ScriptEngine::include(const QString& includeFile) { · 109 unmodified lines | |||
| 641 | QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); | 607 | QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); |
| 642 | loop.exec(); | 608 | loop.exec(); |
| 643 | includeContents = reply->readAll(); | 609 | includeContents = reply->readAll(); |
| 610 | reply->deleteLater(); | ||
| 644 | } else { | 611 | } else { |
| 645 | #ifdef _WIN32 | 612 | #ifdef _WIN32 |
| 646 | QString fileName = url.toString(); | 613 | QString fileName = url.toString(); |