Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 6 files). Show all
Unified · Split
| @@ -44,8 +44,6 @@ · 43 unmodified lines | |||
| 44 | #include "MIDIEvent.h" | 44 | #include "MIDIEvent.h" |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | EntityScriptingInterface* ScriptEngine::_entityScriptingInterface; | ||
| 48 | |||
| 49 | static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ | 47 | static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ |
| 50 | qDebug() << "script:print()<<" << context->argument(0).toString(); | 48 | qDebug() << "script:print()<<" << context->argument(0).toString(); |
| 51 | QString message = context->argument(0).toString() | 49 | QString message = context->argument(0).toString() |
| @@ -73,13 +71,6 @@ void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputCon · 21 unmodified lines | |||
| 73 | out = qobject_cast<AbstractInputController*>(object.toQObject()); | 71 | out = qobject_cast<AbstractInputController*>(object.toQObject()); |
| 74 | } | 72 | } |
| 75 | 73 | ||
| 76 | EntityScriptingInterface* ScriptEngine::getEntityScriptingInterface() { | ||
| 77 | if (!_entityScriptingInterface) { | ||
| 78 | _entityScriptingInterface = new EntityScriptingInterface(); | ||
| 79 | } | ||
| 80 | return _entityScriptingInterface; | ||
| 81 | } | ||
| 82 | |||
| 83 | ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, | 74 | ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, |
| 84 | AbstractControllerScriptingInterface* controllerScriptingInterface) : | 75 | AbstractControllerScriptingInterface* controllerScriptingInterface) : |
| 85 | 76 | ||
| @@ -104,7 +95,6 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam · 18 unmodified lines | |||
| 104 | _isUserLoaded(false), | 95 | _isUserLoaded(false), |
| 105 | _arrayBufferClass(new ArrayBufferClass(this)) | 96 | _arrayBufferClass(new ArrayBufferClass(this)) |
| 106 | { | 97 | { |
| 107 | getEntityScriptingInterface(); | ||
| 108 | _allScriptsMutex.lock(); | 98 | _allScriptsMutex.lock(); |
| 109 | _allKnownScriptEngines.insert(this); | 99 | _allKnownScriptEngines.insert(this); |
| 110 | _allScriptsMutex.unlock(); | 100 | _allScriptsMutex.unlock(); |
| @@ -322,7 +312,8 @@ void ScriptEngine::init() { · 211 unmodified lines | |||
| 322 | 312 | ||
| 323 | auto sceneScriptingInterface = DependencyManager::set<SceneScriptingInterface>(); | 313 | auto sceneScriptingInterface = DependencyManager::set<SceneScriptingInterface>(); |
| 324 | 314 | ||
| 325 | _entityScriptingInterface->init(); | 315 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); |
| 316 | entityScriptingInterface->init(); | ||
| 326 | 317 | ||
| 327 | // register various meta-types | 318 | // register various meta-types |
| 328 | registerMetaTypes(this); | 319 | registerMetaTypes(this); |
| @@ -360,7 +351,7 @@ void ScriptEngine::init() { · 31 unmodified lines | |||
| 360 | registerGlobalObject("Script", this); | 351 | registerGlobalObject("Script", this); |
| 361 | registerGlobalObject("Audio", &AudioScriptingInterface::getInstance()); | 352 | registerGlobalObject("Audio", &AudioScriptingInterface::getInstance()); |
| 362 | registerGlobalObject("Controller", _controllerScriptingInterface); | 353 | registerGlobalObject("Controller", _controllerScriptingInterface); |
| 363 | registerGlobalObject("Entities", _entityScriptingInterface); | 354 | registerGlobalObject("Entities", entityScriptingInterface.data()); |
| 364 | registerGlobalObject("Quat", &_quatLibrary); | 355 | registerGlobalObject("Quat", &_quatLibrary); |
| 365 | registerGlobalObject("Vec3", &_vec3Library); | 356 | registerGlobalObject("Vec3", &_vec3Library); |
| 366 | registerGlobalObject("Uuid", &_uuidLibrary); | 357 | registerGlobalObject("Uuid", &_uuidLibrary); |
| @@ -478,6 +469,7 @@ void ScriptEngine::run() { · 111 unmodified lines | |||
| 478 | int thisFrame = 0; | 469 | int thisFrame = 0; |
| 479 | 470 | ||
| 480 | auto nodeList = DependencyManager::get<NodeList>(); | 471 | auto nodeList = DependencyManager::get<NodeList>(); |
| 472 | auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); | ||
| 481 | 473 | ||
| 482 | qint64 lastUpdate = usecTimestampNow(); | 474 | qint64 lastUpdate = usecTimestampNow(); |
| 483 | 475 | ||
| @@ -497,13 +489,13 @@ void ScriptEngine::run() { · 13 unmodified lines | |||
| 497 | break; | 489 | break; |
| 498 | } | 490 | } |
| 499 | 491 | ||
| 500 | if (!_isFinished && _entityScriptingInterface->getEntityPacketSender()->serversExist()) { | 492 | if (!_isFinished && entityScriptingInterface->getEntityPacketSender()->serversExist()) { |
| 501 | // release the queue of edit entity messages. | 493 | // release the queue of edit entity messages. |
| 502 | _entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages(); | 494 | entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages(); |
| 503 | 495 | ||
| 504 | // since we're in non-threaded mode, call process so that the packets are sent | 496 | // since we're in non-threaded mode, call process so that the packets are sent |
| 505 | if (!_entityScriptingInterface->getEntityPacketSender()->isThreaded()) { | 497 | if (!entityScriptingInterface->getEntityPacketSender()->isThreaded()) { |
| 506 | _entityScriptingInterface->getEntityPacketSender()->process(); | 498 | entityScriptingInterface->getEntityPacketSender()->process(); |
| 507 | } | 499 | } |
| 508 | } | 500 | } |
| 509 | 501 | ||
| @@ -630,13 +622,13 @@ void ScriptEngine::run() { · 120 unmodified lines | |||
| 630 | // kill the avatar identity timer | 622 | // kill the avatar identity timer |
| 631 | delete _avatarIdentityTimer; | 623 | delete _avatarIdentityTimer; |
| 632 | 624 | ||
| 633 | if (_entityScriptingInterface->getEntityPacketSender()->serversExist()) { | 625 | if (entityScriptingInterface->getEntityPacketSender()->serversExist()) { |
| 634 | // release the queue of edit entity messages. | 626 | // release the queue of edit entity messages. |
| 635 | _entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages(); | 627 | entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages(); |
| 636 | 628 | ||
| 637 | // since we're in non-threaded mode, call process so that the packets are sent | 629 | // since we're in non-threaded mode, call process so that the packets are sent |
| 638 | if (!_entityScriptingInterface->getEntityPacketSender()->isThreaded()) { | 630 | if (!entityScriptingInterface->getEntityPacketSender()->isThreaded()) { |
| 639 | _entityScriptingInterface->getEntityPacketSender()->process(); | 631 | entityScriptingInterface->getEntityPacketSender()->process(); |
| 640 | } | 632 | } |
| 641 | } | 633 | } |
| 642 | 634 | ||